Lines Matching refs:mount

74 #define cluster_for_offset(offset, mount) \
75 ((offset) / ((mount)->block_size * (mount)->cluster_size))
77 #define offset_from_cluster(offset, mount) \
78 ((offset) % ((mount)->block_size * (mount)->cluster_size))
80 #define cluster_to_block(cluster, mount) \
81 ((mount)->clusters_start + (((cluster) - 2) * (mount)->cluster_size))
83 #define cluster_entry_size(mount) \
84 ((mount)->fat_type == FAT_TYPE_FAT16 ? sizeof(uint16_t) : sizeof(uint32_t))
86 #define fat_block_for_cluster(cluster, mount) \
87 ((cluster) * cluster_entry_size(mount) / (mount)->block_size)
89 #define fat_offset_for_cluster(cluster, mount) \
90 ((cluster) * cluster_entry_size(mount) % (mount)->block_size)
158 acquire_or_read(struct fat_mount *mount, struct fs_cache *cache,
173 err = mount->ata_rw28_binding->rpc_tx_vtbl.read_dma(mount->ata_rw28_binding,
191 acquire_block(struct fat_mount *mount, size_t block, uint8_t **data)
193 return acquire_or_read(mount, mount->block_cache,
194 block, data, block, mount->block_size);
198 release_block(struct fat_mount *mount, size_t block)
200 return fs_cache_release(mount->block_cache, block);
204 acquire_cluster(struct fat_mount *mount, uint32_t cluster, uint8_t **data)
206 return acquire_or_read(mount, mount->cluster_cache, cluster, data,
207 cluster_to_block(cluster, mount),
208 mount->block_size * mount->cluster_size);
212 release_cluster(struct fat_mount *mount, uint32_t cluster)
214 return fs_cache_release(mount->cluster_cache, cluster);
225 dirsearch_wipe(struct fat_dirsearch *search, struct fat_mount *mount)
229 if (!search->parent_direntry && mount->fat_type == FAT_TYPE_FAT16) {
231 err = release_block(mount, search->data_key);
234 err = release_cluster(mount, search->data_key);
245 next_cluster(struct fat_mount *mount, uint32_t cluster, uint32_t *rescluster)
251 size_t cluster_fat_block = fat_block_for_cluster(cluster, mount)+mount->fat_start;
252 size_t cluster_fat_offset = fat_offset_for_cluster(cluster, mount);
258 err = acquire_block(mount, cluster_fat_block, &data);
265 if (mount->fat_type == FAT_TYPE_FAT16) {
273 err = release_block(mount, cluster_fat_block);
325 next_f16_rootdir_block(struct fat_mount *mount, struct fat_dirsearch *search,
331 assert(mount->fat_type == FAT_TYPE_FAT16);
334 size_t search_end = fat_bpb_rtc_rd(&mount->bpb);
341 size_t block_index = bytes_offset / mount->block_size;
342 size_t block_offset = bytes_offset % mount->block_size;
350 size_t block = mount->rootdir_start + block_index;
355 err = acquire_block(mount, block, &new_data);
362 err = release_block(mount, search->data_key);
364 release_block(mount, block);
379 next_subdir_block(struct fat_mount *mount, struct fat_dirsearch *search,
384 assert(search->parent_direntry || mount->fat_type == FAT_TYPE_FAT32);
388 size_t block_index = bytes_offset / mount->block_size;
389 size_t cluster_index = block_index / mount->cluster_size;
391 (mount->block_size * mount->cluster_size);
401 if (mount->fat_type == FAT_TYPE_FAT32) {
407 cluster = mount->rootdir_cluster;
412 cluster < mount->last_cluster_start && clsidx > 0;
415 err = next_cluster(mount, cluster, &cluster);
421 if (cluster >= mount->last_cluster_start) {
427 err = acquire_cluster(mount, cluster, &new_data);
434 err = release_cluster(mount, search->data_key);
450 read_next_direntry(struct fat_mount *mount, struct fat_dirsearch *search,
463 mount->fat_type == FAT_TYPE_FAT16;
465 err = next_f16_rootdir_block(mount, search, &entry_data);
468 err = next_subdir_block(mount, search, &entry_data);
542 find_path(struct fat_mount *mount, const char *path,
578 err = read_next_direntry(mount, &search, dosfn, lfn_data,
581 dirsearch_wipe(&search, mount);
634 dirsearch_wipe(&search, mount);
642 openhandle(struct fat_mount *mount, const char *path, struct fat_handle_common *handle)
647 err = find_path(mount, path, handle->dirent_data);
667 struct fat_mount *mount = st;
675 err = openhandle(mount, path, &handle->h);
715 struct fat_mount *mount = st;
741 size_t cluster_index = cluster_for_offset(offset, mount);
742 size_t cluster_offset = offset_from_cluster(offset, mount);
748 size_t cluster_remainder = mount->cluster_size * mount->block_size - cluster_offset;
761 if (mount->fat_type == FAT_TYPE_FAT32) {
765 err = next_cluster(mount, cluster, &cluster);
771 assert(cluster < mount->last_cluster_start);
775 err = acquire_cluster(mount, cluster, &data);
780 err = release_cluster(mount, cluster);
907 struct fat_mount *mount = st;
921 err = openhandle(mount, path, &new_handle->h);
951 struct fat_mount *mount = st;
962 err = read_next_direntry(mount, &handle->search, dosfn, lfn_data,
1018 struct fat_mount *mount = st;
1021 dirsearch_wipe(&handle->search, mount);
1050 struct fat_mount *mount = st;
1053 mount->bind_err = err;
1057 mount->ahci_binding = b;
1077 struct fat_mount *mount = (struct fat_mount*) st;
1080 mount->ata_rw28_binding = b;
1126 FAT_DEBUG_F("got mount for port %zu, offset %zu", port, startblock);
1128 struct fat_mount *mount = calloc(1, sizeof(struct fat_mount));
1129 if (!mount) {
1132 mount->fat_type = type;
1133 mount->startblock = startblock;
1138 err = ahci_init(port, ahci_init_cb, mount, get_default_waitset());
1143 while (!mount->ahci_binding && err_is_ok(mount->bind_err)) {
1146 if (err_is_fail(mount->bind_err)) {
1147 err = mount->bind_err;
1156 get_default_waitset(), mount->ahci_binding);
1161 mount->ata_rw28_binding = (struct ata_rw28_binding*)ahci_ata_rw28_binding;
1162 ata_rw28_rpc_client_init(mount->ata_rw28_binding);
1173 mount,
1180 while(mount->ata_rw28_binding == NULL) {
1189 err = mount->ata_rw28_binding->rpc_tx_vtbl.read_dma_block(mount->ata_rw28_binding,
1190 mount->startblock, mount->bootsec_data, &size);
1211 if (memcmp(mount->bootsec_data+0x1FE, "\x55\xAA", 2) != 0) {
1213 " got 0x%02x 0x%02x", mount->bootsec_data[0x1FE],
1214 mount->bootsec_data[0x1FF]);
1218 fat_bpb_initialize(&mount->bpb, (mackerel_addr_t)&mount->bootsec_data);
1219 mount->block_size = fat_bpb_bps_rd(&mount->bpb);
1220 mount->cluster_size = fat_bpb_spc_rd(&mount->bpb);
1221 mount->fat_start = mount->startblock + fat_bpb_rsvs_rd(&mount->bpb);
1222 size_t ssc = fat_bpb_ssc_rd(&mount->bpb), lsc = fat_bpb_lsc_rd(&mount->bpb);
1229 mount->block_count = ssc;
1232 mount->block_count = lsc;
1239 DUMP_DEV(fat_bpb, &mount->bpb, 4096);
1242 if (mount->fat_type == FAT_TYPE_FAT16) {
1243 fat16_ebpb_initialize(&mount->ebpb.f16, (char*)&mount->bootsec_data);
1245 DUMP_DEV(fat16_ebpb, &mount->ebpb.f16, 4096);
1247 uint8_t signature = fat16_ebpb_ebs_rd(&mount->ebpb.f16);
1257 mount->fat_size = fat_bpb_spf_rd(&mount->bpb);
1258 mount->rootdir_start = mount->fat_start +
1259 fat_bpb_fatc_rd(&mount->bpb) * mount->fat_size;
1260 mount->clusters_start = mount->rootdir_start +
1261 CEIL_DIV(fat_bpb_rtc_rd(&mount->bpb) * fat_direntry_size,
1262 fat_bpb_bps_rd(&mount->bpb));
1263 mount->last_cluster_start = 0xfff8;
1266 fat32_ebpb_initialize(&mount->ebpb.f32, (char*)&mount->bootsec_data);
1268 DUMP_DEV(fat32_ebpb, &mount->ebpb.f32, 4096);
1270 uint8_t signature = fat32_ebpb_ebs_rd(&mount->ebpb.f32);
1276 mount->fat_size = fat32_ebpb_spf_rd(&mount->ebpb.f32);
1277 mount->rootdir_cluster = fat32_ebpb_rtst_rd(&mount->ebpb.f32);
1278 mount->clusters_start = mount->fat_start +
1279 fat_bpb_fatc_rd(&mount->bpb) * mount->fat_size;
1280 mount->last_cluster_start = 0xfffffff8;
1282 size_t fs_info_sector = fat32_ebpb_fsis_rd(&mount->ebpb.f32);
1283 if (fs_info_sector <= 0 || fs_info_sector >= mount->block_count) {
1286 mount->block_count);
1290 mount->ata_rw28_binding->rpc_tx_vtbl.read_dma_block(mount->ata_rw28_binding,
1291 mount->startblock + fs_info_sector, reply.buffer ,
1316 FAT_DEBUG("dumping mount variables");
1317 #define D(v) printf("%-18s %zu\n", #v ":", mount-> v )
1329 err = fs_cache_init(1<<7, 1<<8, &mount->block_cache);
1333 err = fs_cache_init(1<<7, 1<<8, &mount->cluster_cache);
1339 *retst = mount;
1343 if (mount->block_cache) {
1344 fs_cache_free(mount->block_cache);
1346 if (mount->cluster_cache) {
1347 fs_cache_free(mount->cluster_cache);
1365 errval_t err2 = ahci_close(mount->ahci_binding, MKCLOSURE(ahci_close_cb, &closed));
1368 event_dispatch(mount->ahci_binding->waitset);
1374 free(mount);