3 * exFAT file system implementation library.
5 * Created by Andrew Nayenko on 22.10.09.
6 * This software is distributed under the GNU General Public License
7 * version 3 or any later.
15 #define _XOPEN_SOURCE /* for tzset() in Linux */
18 static uint64_t rootdir_size(const struct exfat* ef)
20 uint64_t clusters = 0;
21 cluster_t rootdir_cluster = le32_to_cpu(ef->sb->rootdir_cluster);
23 while (!CLUSTER_INVALID(rootdir_cluster))
26 /* root directory cannot be contiguous because there is no flag
28 rootdir_cluster = exfat_next_cluster(ef, ef->root, rootdir_cluster);
30 return clusters * CLUSTER_SIZE(*ef->sb);
33 int exfat_mount(struct exfat* ef, const char* spec)
37 ef->sb = malloc(sizeof(struct exfat_super_block));
40 exfat_error("memory allocation failed");
44 ef->fd = open(spec, O_RDWR);
48 exfat_error("failed to open `%s'", spec);
52 exfat_read_raw(ef->sb, sizeof(struct exfat_super_block), 0, ef->fd);
53 if (memcmp(ef->sb->oem_name, "EXFAT ", 8) != 0)
57 exfat_error("exFAT file system is not found");
64 ef->root = malloc(sizeof(struct exfat_node));
69 exfat_error("failed to allocate root node");
72 memset(ef->root, 0, sizeof(struct exfat_node));
73 ef->root->flags = EXFAT_ATTRIB_DIR;
74 ef->root->start_cluster = le32_to_cpu(ef->sb->rootdir_cluster);
75 ef->root->name[0] = cpu_to_le16('\0');
76 ef->root->size = rootdir_size(ef);
77 /* exFAT does not have time attributes for the root directory */
80 /* always keep at least 1 reference to the root node */
81 exfat_get_node(ef->root);
86 void exfat_unmount(struct exfat* ef)
88 exfat_put_node(ef->root);
89 exfat_reset_cache(ef);