3 Root directory creation code.
5 Free exFAT implementation.
6 Copyright (C) 2011-2018 Andrew Nayenko
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 static off_t
rootdir_alignment(void)
31 return get_cluster_size();
34 static off_t
rootdir_size(void)
36 return get_cluster_size();
39 static void init_label_entry(struct exfat_entry_label
* label_entry
)
41 memset(label_entry
, 0, sizeof(struct exfat_entry_label
));
42 label_entry
->type
= EXFAT_ENTRY_LABEL
^ EXFAT_ENTRY_VALID
;
44 if (utf16_length(get_volume_label()) == 0)
47 memcpy(label_entry
->name
, get_volume_label(),
48 EXFAT_ENAME_MAX
* sizeof(le16_t
));
49 label_entry
->length
= utf16_length(get_volume_label());
50 label_entry
->type
|= EXFAT_ENTRY_VALID
;
53 static void init_bitmap_entry(struct exfat_entry_bitmap
* bitmap_entry
)
55 memset(bitmap_entry
, 0, sizeof(struct exfat_entry_bitmap
));
56 bitmap_entry
->type
= EXFAT_ENTRY_BITMAP
;
57 bitmap_entry
->start_cluster
= cpu_to_le32(EXFAT_FIRST_DATA_CLUSTER
);
58 bitmap_entry
->size
= cpu_to_le64(cbm
.get_size());
61 static void init_upcase_entry(struct exfat_entry_upcase
* upcase_entry
)
66 for (i
= 0; i
< sizeof(upcase_table
); i
++)
67 sum
= ((sum
<< 31) | (sum
>> 1)) + upcase_table
[i
];
69 memset(upcase_entry
, 0, sizeof(struct exfat_entry_upcase
));
70 upcase_entry
->type
= EXFAT_ENTRY_UPCASE
;
71 upcase_entry
->checksum
= cpu_to_le32(sum
);
72 upcase_entry
->start_cluster
= cpu_to_le32(
73 (get_position(&uct
) - get_position(&cbm
)) / get_cluster_size() +
74 EXFAT_FIRST_DATA_CLUSTER
);
75 upcase_entry
->size
= cpu_to_le64(sizeof(upcase_table
));
78 static int rootdir_write(struct exfat_dev
* dev
)
80 struct exfat_entry_label label_entry
;
81 struct exfat_entry_bitmap bitmap_entry
;
82 struct exfat_entry_upcase upcase_entry
;
84 init_label_entry(&label_entry
);
85 init_bitmap_entry(&bitmap_entry
);
86 init_upcase_entry(&upcase_entry
);
88 if (exfat_write(dev
, &label_entry
, sizeof(struct exfat_entry
)) < 0)
90 if (exfat_write(dev
, &bitmap_entry
, sizeof(struct exfat_entry
)) < 0)
92 if (exfat_write(dev
, &upcase_entry
, sizeof(struct exfat_entry
)) < 0)
97 const struct fs_object rootdir
=
99 .get_alignment
= rootdir_alignment
,
100 .get_size
= rootdir_size
,
101 .write
= rootdir_write
,