Lines Matching refs:ef
33 static uint64_t rootdir_size(const struct exfat* ef) in rootdir_size() argument
36 uint32_t clusters_max = le32_to_cpu(ef->sb->cluster_count); in rootdir_size()
37 cluster_t rootdir_cluster = le32_to_cpu(ef->sb->rootdir_cluster); in rootdir_size()
49 if (CLUSTER_INVALID(*ef->sb, rootdir_cluster)) in rootdir_size()
55 rootdir_cluster = exfat_next_cluster(ef, ef->root, rootdir_cluster); in rootdir_size()
60 return (uint64_t) clusters * CLUSTER_SIZE(*ef->sb); in rootdir_size()
84 static void parse_options(struct exfat* ef, const char* options) in parse_options() argument
89 ef->dmask = get_int_option(options, "dmask", 8, opt_umask); in parse_options()
90 ef->fmask = get_int_option(options, "fmask", 8, opt_umask); in parse_options()
92 ef->uid = get_int_option(options, "uid", 10, geteuid()); in parse_options()
93 ef->gid = get_int_option(options, "gid", 10, getegid()); in parse_options()
95 ef->noatime = exfat_match_option(options, "noatime"); in parse_options()
100 ef->repair = EXFAT_REPAIR_ASK; in parse_options()
103 ef->repair = EXFAT_REPAIR_YES; in parse_options()
106 ef->repair = EXFAT_REPAIR_NO; in parse_options()
111 static bool verify_vbr_checksum(const struct exfat* ef, void* sector) in verify_vbr_checksum() argument
113 off_t sector_size = SECTOR_SIZE(*ef->sb); in verify_vbr_checksum()
117 if (exfat_pread(ef->dev, sector, sector_size, 0) < 0) in verify_vbr_checksum()
125 if (exfat_pread(ef->dev, sector, sector_size, i * sector_size) < 0) in verify_vbr_checksum()
133 if (exfat_pread(ef->dev, sector, sector_size, i * sector_size) < 0) in verify_vbr_checksum()
143 if (!EXFAT_REPAIR(invalid_vbr_checksum, ef, sector, vbr_checksum)) in verify_vbr_checksum()
149 static int commit_super_block(const struct exfat* ef) in commit_super_block() argument
151 if (exfat_pwrite(ef->dev, ef->sb, sizeof(struct exfat_super_block), 0) < 0) in commit_super_block()
156 return exfat_fsync(ef->dev); in commit_super_block()
159 int exfat_soil_super_block(const struct exfat* ef) in exfat_soil_super_block() argument
161 if (ef->ro) in exfat_soil_super_block()
164 ef->sb->volume_state = cpu_to_le16( in exfat_soil_super_block()
165 le16_to_cpu(ef->sb->volume_state) | EXFAT_STATE_MOUNTED); in exfat_soil_super_block()
166 return commit_super_block(ef); in exfat_soil_super_block()
169 static void exfat_free(struct exfat* ef) in exfat_free() argument
171 exfat_close(ef->dev); /* first of all, close the descriptor */ in exfat_free()
172 ef->dev = NULL; /* struct exfat_dev is freed by exfat_close() */ in exfat_free()
173 free(ef->root); in exfat_free()
174 ef->root = NULL; in exfat_free()
175 free(ef->zero_cluster); in exfat_free()
176 ef->zero_cluster = NULL; in exfat_free()
177 free(ef->cmap.chunk); in exfat_free()
178 ef->cmap.chunk = NULL; in exfat_free()
179 free(ef->upcase); in exfat_free()
180 ef->upcase = NULL; in exfat_free()
181 free(ef->sb); in exfat_free()
182 ef->sb = NULL; in exfat_free()
185 int exfat_mount(struct exfat* ef, const char* spec, const char* options) in exfat_mount() argument
191 memset(ef, 0, sizeof(struct exfat)); in exfat_mount()
193 parse_options(ef, options); in exfat_mount()
201 ef->dev = exfat_open(spec, mode); in exfat_mount()
202 if (ef->dev == NULL) in exfat_mount()
204 if (exfat_get_mode(ef->dev) == EXFAT_MODE_RO) in exfat_mount()
207 ef->ro = -1; in exfat_mount()
209 ef->ro = 1; in exfat_mount()
212 ef->sb = malloc(sizeof(struct exfat_super_block)); in exfat_mount()
213 if (ef->sb == NULL) in exfat_mount()
216 exfat_free(ef); in exfat_mount()
219 memset(ef->sb, 0, sizeof(struct exfat_super_block)); in exfat_mount()
221 if (exfat_pread(ef->dev, ef->sb, sizeof(struct exfat_super_block), 0) < 0) in exfat_mount()
224 exfat_free(ef); in exfat_mount()
227 if (memcmp(ef->sb->oem_name, "EXFAT ", 8) != 0) in exfat_mount()
235 exfat_free(ef); in exfat_mount()
239 if (ef->sb->sector_bits < 9) in exfat_mount()
241 exfat_error("too small sector size: 2^%hhd", ef->sb->sector_bits); in exfat_mount()
242 exfat_free(ef); in exfat_mount()
246 if ((int) ef->sb->sector_bits + (int) ef->sb->spc_bits > 25) in exfat_mount()
249 ef->sb->sector_bits, ef->sb->spc_bits); in exfat_mount()
250 exfat_free(ef); in exfat_mount()
253 ef->zero_cluster = malloc(CLUSTER_SIZE(*ef->sb)); in exfat_mount()
254 if (ef->zero_cluster == NULL) in exfat_mount()
257 exfat_free(ef); in exfat_mount()
261 if (!verify_vbr_checksum(ef, ef->zero_cluster)) in exfat_mount()
263 exfat_free(ef); in exfat_mount()
266 memset(ef->zero_cluster, 0, CLUSTER_SIZE(*ef->sb)); in exfat_mount()
267 if (ef->sb->version.major != 1 || ef->sb->version.minor != 0) in exfat_mount()
270 ef->sb->version.major, ef->sb->version.minor); in exfat_mount()
271 exfat_free(ef); in exfat_mount()
274 if (ef->sb->fat_count != 1) in exfat_mount()
276 exfat_error("unsupported FAT count: %hhu", ef->sb->fat_count); in exfat_mount()
277 exfat_free(ef); in exfat_mount()
280 if (le64_to_cpu(ef->sb->sector_count) * SECTOR_SIZE(*ef->sb) > in exfat_mount()
281 (uint64_t) exfat_get_size(ef->dev)) in exfat_mount()
287 le64_to_cpu(ef->sb->sector_count), SECTOR_SIZE(*ef->sb), in exfat_mount()
288 exfat_get_size(ef->dev)); in exfat_mount()
290 if ((off_t) le32_to_cpu(ef->sb->cluster_count) * CLUSTER_SIZE(*ef->sb) > in exfat_mount()
291 exfat_get_size(ef->dev)) in exfat_mount()
295 le32_to_cpu(ef->sb->cluster_count), CLUSTER_SIZE(*ef->sb), in exfat_mount()
296 exfat_get_size(ef->dev)); in exfat_mount()
297 exfat_free(ef); in exfat_mount()
300 if (le16_to_cpu(ef->sb->volume_state) & EXFAT_STATE_MOUNTED) in exfat_mount()
303 ef->root = malloc(sizeof(struct exfat_node)); in exfat_mount()
304 if (ef->root == NULL) in exfat_mount()
307 exfat_free(ef); in exfat_mount()
310 memset(ef->root, 0, sizeof(struct exfat_node)); in exfat_mount()
311 ef->root->attrib = EXFAT_ATTRIB_DIR; in exfat_mount()
312 ef->root->start_cluster = le32_to_cpu(ef->sb->rootdir_cluster); in exfat_mount()
313 ef->root->fptr_cluster = ef->root->start_cluster; in exfat_mount()
314 ef->root->name[0] = cpu_to_le16('\0'); in exfat_mount()
315 ef->root->valid_size = ef->root->size = rootdir_size(ef); in exfat_mount()
316 if (ef->root->size == 0) in exfat_mount()
318 exfat_free(ef); in exfat_mount()
322 ef->root->mtime = 0; in exfat_mount()
323 ef->root->atime = 0; in exfat_mount()
325 exfat_get_node(ef->root); in exfat_mount()
327 rc = exfat_cache_directory(ef, ef->root); in exfat_mount()
330 if (ef->upcase == NULL) in exfat_mount()
335 if (ef->cmap.chunk == NULL) in exfat_mount()
344 exfat_put_node(ef, ef->root); in exfat_mount()
345 exfat_reset_cache(ef); in exfat_mount()
346 exfat_free(ef); in exfat_mount()
350 static void finalize_super_block(struct exfat* ef) in finalize_super_block() argument
352 if (ef->ro) in finalize_super_block()
355 ef->sb->volume_state = cpu_to_le16( in finalize_super_block()
356 le16_to_cpu(ef->sb->volume_state) & ~EXFAT_STATE_MOUNTED); in finalize_super_block()
360 if (ef->sb->allocated_percent != 0xff) in finalize_super_block()
364 free = exfat_count_free_clusters(ef); in finalize_super_block()
365 total = le32_to_cpu(ef->sb->cluster_count); in finalize_super_block()
366 ef->sb->allocated_percent = ((total - free) * 100 + total / 2) / total; in finalize_super_block()
369 commit_super_block(ef); /* ignore return code */ in finalize_super_block()
372 void exfat_unmount(struct exfat* ef) in exfat_unmount() argument
374 exfat_flush_nodes(ef); /* ignore return code */ in exfat_unmount()
375 exfat_flush(ef); /* ignore return code */ in exfat_unmount()
376 exfat_put_node(ef, ef->root); in exfat_unmount()
377 exfat_reset_cache(ef); in exfat_unmount()
378 finalize_super_block(ef); in exfat_unmount()
379 exfat_free(ef); /* will close the descriptor */ in exfat_unmount()