1762b846cSJohn Scipione /*
2dae266a8SJohn Scipione * Copyright 2011, Jérôme Duval, korli@users.berlios.de.
3762b846cSJohn Scipione * Copyright 2014 Haiku, Inc. All rights reserved.
4762b846cSJohn Scipione *
5762b846cSJohn Scipione * Distributed under the terms of the MIT License.
6762b846cSJohn Scipione *
7762b846cSJohn Scipione * Authors:
8dae266a8SJohn Scipione * Jérôme Duval, korli@users.berlios.de
9762b846cSJohn Scipione * John Scipione, jscipione@gmail.com
10762b846cSJohn Scipione */
11762b846cSJohn Scipione
12762b846cSJohn Scipione
13762b846cSJohn Scipione #include "Utility.h"
14762b846cSJohn Scipione
15762b846cSJohn Scipione #include <stdio.h>
16762b846cSJohn Scipione #include <stdlib.h>
17762b846cSJohn Scipione #include <string.h>
18762b846cSJohn Scipione
19762b846cSJohn Scipione #include <Errors.h>
20762b846cSJohn Scipione
21ebd3bcdbSJohn Scipione #include "convertutf.h"
22762b846cSJohn Scipione
23762b846cSJohn Scipione
24762b846cSJohn Scipione status_t
get_volume_name(struct exfat_entry * entry,char * name,size_t length)25dae266a8SJohn Scipione get_volume_name(struct exfat_entry* entry, char* name, size_t length)
26762b846cSJohn Scipione {
27dae266a8SJohn Scipione if (entry == NULL || name == NULL)
28762b846cSJohn Scipione return B_BAD_VALUE;
29762b846cSJohn Scipione
30dae266a8SJohn Scipione if (entry->type == EXFAT_ENTRY_TYPE_NOT_IN_USE)
31*65e832b7SJérôme Duval strlcpy(name, "", length);
32dae266a8SJohn Scipione else if (entry->type == EXFAT_ENTRY_TYPE_LABEL) {
33ebd3bcdbSJohn Scipione ssize_t utf8Length = utf16le_to_utf8(entry->volume_label.name,
34ebd3bcdbSJohn Scipione entry->volume_label.length, name, length);
35ebd3bcdbSJohn Scipione if (utf8Length < 0)
36ebd3bcdbSJohn Scipione return (status_t)utf8Length;
37762b846cSJohn Scipione } else
38762b846cSJohn Scipione return B_NAME_NOT_FOUND;
39762b846cSJohn Scipione
40762b846cSJohn Scipione return B_OK;
41762b846cSJohn Scipione }
42dae266a8SJohn Scipione
43dae266a8SJohn Scipione
44dae266a8SJohn Scipione void
get_default_volume_name(off_t partitionSize,char * name,size_t length)453472fc55SJohn Scipione get_default_volume_name(off_t partitionSize, char* name, size_t length)
46dae266a8SJohn Scipione {
47dae266a8SJohn Scipione off_t divisor = 1ULL << 40;
48dae266a8SJohn Scipione char unit = 'T';
493472fc55SJohn Scipione if (partitionSize < divisor) {
50dae266a8SJohn Scipione divisor = 1UL << 30;
51dae266a8SJohn Scipione unit = 'G';
523472fc55SJohn Scipione if (partitionSize < divisor) {
53dae266a8SJohn Scipione divisor = 1UL << 20;
54dae266a8SJohn Scipione unit = 'M';
55dae266a8SJohn Scipione }
56dae266a8SJohn Scipione }
57dae266a8SJohn Scipione
583472fc55SJohn Scipione double size = double((10 * partitionSize + divisor - 1) / divisor);
59dae266a8SJohn Scipione // %g in the kernel does not support precision...
60dae266a8SJohn Scipione
61dae266a8SJohn Scipione snprintf(name, length, "%g%ciB ExFAT Volume", size / 10, unit);
62dae266a8SJohn Scipione }
63