• Home
  • Raw
  • Download

Lines Matching refs:fat

188 fat_clear_cl_head(struct fat_descriptor *fat, cl_t cl)  in fat_clear_cl_head()  argument
190 bitmap_clear(&fat->headbitmap, cl); in fat_clear_cl_head()
194 fat_is_cl_head(struct fat_descriptor *fat, cl_t cl) in fat_is_cl_head() argument
196 return (bitmap_get(&fat->headbitmap, cl)); in fat_is_cl_head()
200 fat_is_cl_head_in_range(struct fat_descriptor *fat, cl_t cl) in fat_is_cl_head_in_range() argument
202 return (!(bitmap_none_in_range(&fat->headbitmap, cl))); in fat_is_cl_head_in_range()
206 fat_get_head_count(struct fat_descriptor *fat) in fat_get_head_count() argument
208 return (bitmap_count(&fat->headbitmap)); in fat_get_head_count()
217 fat_get_fat12_ptr(struct fat_descriptor *fat, cl_t cl) in fat_get_fat12_ptr() argument
219 return (fat->fatbuf + ((cl + (cl >> 1)))); in fat_get_fat12_ptr()
223 fat_get_fat12_next(struct fat_descriptor *fat, cl_t cl) in fat_get_fat12_next() argument
228 p = fat_get_fat12_ptr(fat, cl); in fat_get_fat12_next()
242 fat_set_fat12_next(struct fat_descriptor *fat, cl_t cl, cl_t nextcl) in fat_set_fat12_next() argument
249 p = fat_get_fat12_ptr(fat, cl); in fat_set_fat12_next()
274 fat_get_fat16_ptr(struct fat_descriptor *fat, cl_t cl) in fat_get_fat16_ptr() argument
276 return (fat->fatbuf + (cl << 1)); in fat_get_fat16_ptr()
280 fat_get_fat16_next(struct fat_descriptor *fat, cl_t cl) in fat_get_fat16_next() argument
285 p = fat_get_fat16_ptr(fat, cl); in fat_get_fat16_next()
295 fat_set_fat16_next(struct fat_descriptor *fat, cl_t cl, cl_t nextcl) in fat_set_fat16_next() argument
302 p = fat_get_fat16_ptr(fat, cl); in fat_set_fat16_next()
313 fat_get_fat32_ptr(struct fat_descriptor *fat, cl_t cl) in fat_get_fat32_ptr() argument
315 return (fat->fatbuf + (cl << 2)); in fat_get_fat32_ptr()
319 fat_get_fat32_next(struct fat_descriptor *fat, cl_t cl) in fat_get_fat32_next() argument
324 p = fat_get_fat32_ptr(fat, cl); in fat_get_fat32_next()
334 fat_set_fat32_next(struct fat_descriptor *fat, cl_t cl, cl_t nextcl) in fat_set_fat32_next() argument
341 p = fat_get_fat32_ptr(fat, cl); in fat_set_fat32_next()
349 fat_get_iosize(struct fat_descriptor *fat, off_t address) in fat_get_iosize() argument
352 if (address == fat->fat32_lastaddr) { in fat_get_iosize()
353 return (fat->fatsize & ((off_t)fat32_cache_chunk_size - 1)); in fat_get_iosize()
360 fat_flush_fat32_cache_entry(struct fat_descriptor *fat, in fat_flush_fat32_cache_entry() argument
367 fd = fd_of_(fat); in fat_flush_fat32_cache_entry()
372 writesize = fat_get_iosize(fat, entry->addr); in fat_flush_fat32_cache_entry()
374 fat_addr = fat->fat32_offset + entry->addr; in fat_flush_fat32_cache_entry()
386 fat_get_fat32_cache_entry(struct fat_descriptor *fat, off_t addr, in fat_get_fat32_cache_entry() argument
396 first = TAILQ_FIRST(&fat->fat32_cache_head); in fat_get_fat32_cache_entry()
401 TAILQ_FOREACH(entry, &fat->fat32_cache_head, entries) { in fat_get_fat32_cache_entry()
408 TAILQ_REMOVE(&fat->fat32_cache_head, entry, entries); in fat_get_fat32_cache_entry()
409 TAILQ_INSERT_HEAD(&fat->fat32_cache_head, entry, entries); in fat_get_fat32_cache_entry()
419 entry = TAILQ_LAST(&fat->fat32_cache_head, cachehead); in fat_get_fat32_cache_entry()
420 TAILQ_REMOVE(&fat->fat32_cache_head, entry, entries); in fat_get_fat32_cache_entry()
421 if (fat_flush_fat32_cache_entry(fat, entry) != FSOK) { in fat_get_fat32_cache_entry()
425 rwsize = fat_get_iosize(fat, addr); in fat_get_fat32_cache_entry()
426 fat_addr = fat->fat32_offset + addr; in fat_get_fat32_cache_entry()
428 fd = fd_of_(fat); in fat_get_fat32_cache_entry()
437 TAILQ_INSERT_HEAD(&fat->fat32_cache_head, entry, entries); in fat_get_fat32_cache_entry()
443 fat_get_fat32_cached_ptr(struct fat_descriptor *fat, cl_t cl, bool writing) in fat_get_fat32_cached_ptr() argument
449 entry = fat_get_fat32_cache_entry(fat, addr, writing); in fat_get_fat32_cached_ptr()
461 fat_get_fat32_cached_next(struct fat_descriptor *fat, cl_t cl) in fat_get_fat32_cached_next() argument
466 p = fat_get_fat32_cached_ptr(fat, cl, false); in fat_get_fat32_cached_next()
479 fat_set_fat32_cached_next(struct fat_descriptor *fat, cl_t cl, cl_t nextcl) in fat_set_fat32_cached_next() argument
486 p = fat_get_fat32_cached_ptr(fat, cl, true); in fat_set_fat32_cached_next()
495 cl_t fat_get_cl_next(struct fat_descriptor *fat, cl_t cl) in fat_get_cl_next() argument
498 if (!valid_cl(fat, cl)) { in fat_get_cl_next()
503 return (fat->get(fat, cl)); in fat_get_cl_next()
506 int fat_set_cl_next(struct fat_descriptor *fat, cl_t cl, cl_t nextcl) in fat_set_cl_next() argument
514 if (!valid_cl(fat, cl)) { in fat_set_cl_next()
519 return (fat->set(fat, cl, nextcl)); in fat_set_cl_next()
523 boot_of_(struct fat_descriptor *fat) { in boot_of_() argument
525 return (fat->boot); in boot_of_()
529 fat_get_boot(struct fat_descriptor *fat) { in fat_get_boot() argument
531 return (boot_of_(fat)); in fat_get_boot()
535 fd_of_(struct fat_descriptor *fat) in fd_of_() argument
537 return (fat->fd); in fd_of_()
541 fat_get_fd(struct fat_descriptor * fat) in fat_get_fd() argument
543 return (fd_of_(fat)); in fat_get_fd()
550 fat_is_valid_cl(struct fat_descriptor *fat, cl_t cl) in fat_is_valid_cl() argument
553 return (valid_cl(fat, cl)); in fat_is_valid_cl()
557 valid_cl(struct fat_descriptor *fat, cl_t cl) in valid_cl() argument
559 const struct bootblock *boot = boot_of_(fat); in valid_cl()
645 cleardirty(struct fat_descriptor *fat) in cleardirty() argument
653 boot = boot_of_(fat); in cleardirty()
654 fd = fd_of_(fat); in cleardirty()
695 _readfat(struct fat_descriptor *fat) in _readfat() argument
704 boot = boot_of_(fat); in _readfat()
705 fd = fd_of_(fat); in _readfat()
706 fat->fatsize = boot->FATsecs * boot->bpbBytesPerSec; in _readfat()
711 fat->is_mmapped = false; in _readfat()
712 fat->use_cache = false; in _readfat()
716 fat->fatbuf = mmap(NULL, fat->fatsize, in _readfat()
718 MAP_SHARED, fd_of_(fat), off); in _readfat()
719 if (fat->fatbuf != MAP_FAILED) { in _readfat()
720 fat->is_mmapped = true; in _readfat()
735 fat->fatsize >= fat32_cache_size) { in _readfat()
737 fat->use_cache = true; in _readfat()
739 fat->fat32_offset = boot->bpbResSectors * boot->bpbBytesPerSec; in _readfat()
740 fat->fat32_lastaddr = fat->fatsize & ~(fat32_cache_chunk_size); in _readfat()
742 readsize = fat->fatsize; in _readfat()
744 fat->fatbuf = malloc(readsize); in _readfat()
745 if (fat->fatbuf == NULL) { in _readfat()
754 if ((size_t)read(fd, fat->fatbuf, readsize) != readsize) { in _readfat()
763 if (fat->use_cache) { in _readfat()
764 TAILQ_INIT(&fat->fat32_cache_head); in _readfat()
773 entry[i].chunk = &fat->fatbuf[entry[i].addr]; in _readfat()
774 TAILQ_INSERT_TAIL(&fat->fat32_cache_head, in _readfat()
777 fat->fat32_cache_allentries = entry; in _readfat()
783 free(fat->fatbuf); in _readfat()
784 fat->fatbuf = NULL; in _readfat()
789 releasefat(struct fat_descriptor *fat) in releasefat() argument
791 if (fat->is_mmapped) { in releasefat()
792 munmap(fat->fatbuf, fat->fatsize); in releasefat()
794 if (fat->use_cache) { in releasefat()
795 free(fat->fat32_cache_allentries); in releasefat()
796 fat->fat32_cache_allentries = NULL; in releasefat()
798 free(fat->fatbuf); in releasefat()
800 fat->fatbuf = NULL; in releasefat()
801 bitmap_dtor(&fat->headbitmap); in releasefat()
810 struct fat_descriptor *fat; in readfat() local
817 fat = calloc(1, sizeof(struct fat_descriptor)); in readfat()
818 if (fat == NULL) { in readfat()
823 fat->fd = fs; in readfat()
824 fat->boot = boot; in readfat()
826 if (!_readfat(fat)) { in readfat()
827 free(fat); in readfat()
830 buffer = fat->fatbuf; in readfat()
835 fat->get = fat_get_fat12_next; in readfat()
836 fat->set = fat_set_fat12_next; in readfat()
839 fat->get = fat_get_fat16_next; in readfat()
840 fat->set = fat_set_fat16_next; in readfat()
843 if (fat->is_mmapped || !fat->use_cache) { in readfat()
844 fat->get = fat_get_fat32_next; in readfat()
845 fat->set = fat_set_fat32_next; in readfat()
847 fat->get = fat_get_fat32_cached_next; in readfat()
848 fat->set = fat_set_fat32_cached_next; in readfat()
853 releasefat(fat); in readfat()
854 free(fat); in readfat()
858 if (bitmap_ctor(&fat->headbitmap, boot->NumClusters, in readfat()
862 releasefat(fat); in readfat()
863 free(fat); in readfat()
967 nextcl = fat_get_cl_next(fat, cl); in readfat()
975 if (fat_is_cl_head(fat, cl)) { in readfat()
976 fat_clear_cl_head(fat, cl); in readfat()
980 if (fat_is_cl_head(fat, cl)) { in readfat()
981 fat_clear_cl_head(fat, cl); in readfat()
984 } else if (!valid_cl(fat, nextcl) && nextcl < CLUST_RSRVD) { in readfat()
990 ret |= fat_set_cl_next(fat, cl, CLUST_EOF); in readfat()
993 } else if (valid_cl(fat, nextcl)) { in readfat()
994 if (fat_is_cl_head(fat, nextcl)) { in readfat()
995 fat_clear_cl_head(fat, nextcl); in readfat()
1000 ret |= fat_set_cl_next(fat, cl, CLUST_EOF); in readfat()
1009 releasefat(fat); in readfat()
1010 free(fat); in readfat()
1013 *fp = fat; in readfat()
1036 checkchain(struct fat_descriptor *fat, cl_t head, size_t *chainsize) in checkchain() argument
1047 assert(valid_cl(fat, head)); in checkchain()
1048 assert(fat_is_cl_head(fat, head)); in checkchain()
1053 fat_clear_cl_head(fat, head); in checkchain()
1071 for (next_cl = fat_get_cl_next(fat, current_cl); in checkchain()
1072 valid_cl(fat, next_cl); in checkchain()
1073 prev_cl = current_cl, current_cl = next_cl, next_cl = fat_get_cl_next(fat, current_cl)) in checkchain()
1100 next_cl & boot_of_(fat)->ClustMask); in checkchain()
1112 return (fat_set_cl_next(fat, current_cl, next_cl) | FSFATMOD); in checkchain()
1122 clearchain(struct fat_descriptor *fat, cl_t head) in clearchain() argument
1125 struct bootblock *boot = boot_of_(fat); in clearchain()
1129 while (valid_cl(fat, current_cl)) { in clearchain()
1130 next_cl = fat_get_cl_next(fat, current_cl); in clearchain()
1131 (void)fat_set_cl_next(fat, current_cl, CLUST_FREE); in clearchain()
1142 copyfat(struct fat_descriptor *fat, int n) in copyfat() argument
1150 fd = fd_of_(fat); in copyfat()
1151 boot = boot_of_(fat); in copyfat()
1153 blobs = howmany(fat->fatsize, fat32_cache_size); in copyfat()
1154 tailsize = fat->fatsize % fat32_cache_size; in copyfat()
1160 src_off = fat->fat32_offset; in copyfat()
1170 (size_t)read(fd, fat->fatbuf, rwsize) != rwsize) && in copyfat()
1177 (size_t)write(fd, fat->fatbuf, rwsize) != rwsize) && in copyfat()
1190 writefat(struct fat_descriptor *fat) in writefat() argument
1199 boot = boot_of_(fat); in writefat()
1200 fd = fd_of_(fat); in writefat()
1202 if (fat->use_cache) { in writefat()
1209 TAILQ_FOREACH(entry, &fat->fat32_cache_head, entries) { in writefat()
1210 if (fat_flush_fat32_cache_entry(fat, entry) != FSOK) { in writefat()
1222 if (copyfat(fat, i) != FSOK) in writefat()
1226 writesz = fat->fatsize; in writefat()
1228 for (i = fat->is_mmapped ? 1 : 0; i < boot->bpbFATs; i++) { in writefat()
1232 (size_t)write(fd, fat->fatbuf, writesz) != writesz) && in writefat()
1247 checklost(struct fat_descriptor *fat) in checklost() argument
1255 dosfs = fd_of_(fat); in checklost()
1256 boot = boot_of_(fat); in checklost()
1263 chains = fat_get_head_count(fat); in checklost()
1272 !fat_is_cl_head_in_range(fat, head)) { in checklost()
1276 if (fat_is_cl_head(fat, head)) { in checklost()
1277 ret = checkchain(fat, head, &chainlength); in checklost()
1282 mod |= ret = reconnect(fat, head, in checklost()
1288 clearchain(fat, head); in checklost()
1311 (boot->NumFree && fat_get_cl_next(fat, boot->FSNext) != CLUST_FREE))) { in checklost()
1317 if (fat_get_cl_next(fat, head) == CLUST_FREE) { in checklost()