3 Root directory creation code.
5 Copyright (C) 2011-2013 Andrew Nayenko
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
27 static off_t rootdir_alignment(void)
29 return get_cluster_size();
32 static off_t rootdir_size(void)
34 return get_cluster_size();
37 static void init_label_entry(struct exfat_entry_label* label_entry)
39 memset(label_entry, 0, sizeof(struct exfat_entry_label));
40 label_entry->type = EXFAT_ENTRY_LABEL ^ EXFAT_ENTRY_VALID;
42 if (utf16_length(get_volume_label()) == 0)
45 memcpy(label_entry->name, get_volume_label(),
46 EXFAT_ENAME_MAX * sizeof(le16_t));
47 label_entry->length = utf16_length(get_volume_label());
48 label_entry->type |= EXFAT_ENTRY_VALID;
51 static void init_bitmap_entry(struct exfat_entry_bitmap* bitmap_entry)
53 memset(bitmap_entry, 0, sizeof(struct exfat_entry_bitmap));
54 bitmap_entry->type = EXFAT_ENTRY_BITMAP;
55 bitmap_entry->start_cluster = cpu_to_le32(EXFAT_FIRST_DATA_CLUSTER);
56 bitmap_entry->size = cpu_to_le64(cbm.get_size());
59 static void init_upcase_entry(struct exfat_entry_upcase* upcase_entry)
64 for (i = 0; i < sizeof(upcase_table); i++)
65 sum = ((sum << 31) | (sum >> 1)) + upcase_table[i];
67 memset(upcase_entry, 0, sizeof(struct exfat_entry_upcase));
68 upcase_entry->type = EXFAT_ENTRY_UPCASE;
69 upcase_entry->checksum = cpu_to_le32(sum);
70 upcase_entry->start_cluster = cpu_to_le32(
71 (get_position(&uct) - get_position(&cbm)) / get_cluster_size() +
72 EXFAT_FIRST_DATA_CLUSTER);
73 upcase_entry->size = cpu_to_le64(sizeof(upcase_table));
76 static int rootdir_write(struct exfat_dev* dev)
78 struct exfat_entry_label label_entry;
79 struct exfat_entry_bitmap bitmap_entry;
80 struct exfat_entry_upcase upcase_entry;
82 init_label_entry(&label_entry);
83 init_bitmap_entry(&bitmap_entry);
84 init_upcase_entry(&upcase_entry);
86 if (exfat_write(dev, &label_entry, sizeof(struct exfat_entry)) < 0)
88 if (exfat_write(dev, &bitmap_entry, sizeof(struct exfat_entry)) < 0)
90 if (exfat_write(dev, &upcase_entry, sizeof(struct exfat_entry)) < 0)
95 const struct fs_object rootdir =
97 .get_alignment = rootdir_alignment,
98 .get_size = rootdir_size,
99 .write = rootdir_write,