btrfs: [] on the end of a struct field is a variable length array.
[haiku.git] / src / add-ons / kernel / file_systems / exfat / Utility.cpp
blob98f6104fe903e4ad0a05a18e433444fc015109be
1 /*
2 * Copyright 2011, Jérôme Duval, korli@users.berlios.de.
3 * Copyright 2014 Haiku, Inc. All rights reserved.
5 * Distributed under the terms of the MIT License.
7 * Authors:
8 * Jérôme Duval, korli@users.berlios.de
9 * John Scipione, jscipione@gmail.com
13 #include "Utility.h"
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
19 #include <Errors.h>
21 #include "convertutf.h"
24 status_t
25 get_volume_name(struct exfat_entry* entry, char* name, size_t length)
27 if (entry == NULL || name == NULL)
28 return B_BAD_VALUE;
30 if (entry->type == EXFAT_ENTRY_TYPE_NOT_IN_USE)
31 name = "";
32 else if (entry->type == EXFAT_ENTRY_TYPE_LABEL) {
33 ssize_t utf8Length = utf16le_to_utf8(entry->volume_label.name,
34 entry->volume_label.length, name, length);
35 if (utf8Length < 0)
36 return (status_t)utf8Length;
37 } else
38 return B_NAME_NOT_FOUND;
40 return B_OK;
44 void
45 get_default_volume_name(off_t partitionSize, char* name, size_t length)
47 off_t divisor = 1ULL << 40;
48 char unit = 'T';
49 if (partitionSize < divisor) {
50 divisor = 1UL << 30;
51 unit = 'G';
52 if (partitionSize < divisor) {
53 divisor = 1UL << 20;
54 unit = 'M';
58 double size = double((10 * partitionSize + divisor - 1) / divisor);
59 // %g in the kernel does not support precision...
61 snprintf(name, length, "%g%ciB ExFAT Volume", size / 10, unit);