diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/drivers/fat.c | 35 | ||||
-rw-r--r-- | firmware/export/fat.h | 1 |
2 files changed, 35 insertions, 1 deletions
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c index 85bd525eff..c989c86f84 100644 --- a/firmware/drivers/fat.c +++ b/firmware/drivers/fat.c | |||
@@ -480,6 +480,33 @@ int fat_mount(IF_MV2(int volume,) IF_MV2(int drive,) int startsector) | |||
480 | return 0; | 480 | return 0; |
481 | } | 481 | } |
482 | 482 | ||
483 | #ifdef HAVE_MULTIVOLUME | ||
484 | int fat_unmount(int volume, bool flush) | ||
485 | { | ||
486 | struct bpb* fat_bpb = &fat_bpbs[volume]; | ||
487 | if(flush) | ||
488 | { | ||
489 | flush_fat(fat_bpb); /* the clean way, while still alive */ | ||
490 | } | ||
491 | else | ||
492 | { /* volume is not accessible any more, e.g. MMC removed */ | ||
493 | int i; | ||
494 | mutex_lock(&cache_mutex); | ||
495 | for(i = 0;i < FAT_CACHE_SIZE;i++) | ||
496 | { | ||
497 | struct fat_cache_entry *fce = &fat_cache[i]; | ||
498 | if(fce->inuse && fce->fat_vol == fat_bpb) | ||
499 | { | ||
500 | fce->inuse = false; /* discard all from that volume */ | ||
501 | fce->dirty = false; | ||
502 | } | ||
503 | } | ||
504 | mutex_unlock(&cache_mutex); | ||
505 | } | ||
506 | fat_bpb->mounted = false; | ||
507 | } | ||
508 | #endif | ||
509 | |||
483 | void fat_recalc_free(IF_MV_NONVOID(int volume)) | 510 | void fat_recalc_free(IF_MV_NONVOID(int volume)) |
484 | { | 511 | { |
485 | #ifndef HAVE_MULTIVOLUME | 512 | #ifndef HAVE_MULTIVOLUME |
@@ -946,15 +973,21 @@ static int flush_fat(IF_MV_NONVOID(struct bpb* fat_bpb)) | |||
946 | unsigned char *sec; | 973 | unsigned char *sec; |
947 | LDEBUGF("flush_fat()\n"); | 974 | LDEBUGF("flush_fat()\n"); |
948 | 975 | ||
976 | mutex_lock(&cache_mutex); | ||
949 | for(i = 0;i < FAT_CACHE_SIZE;i++) | 977 | for(i = 0;i < FAT_CACHE_SIZE;i++) |
950 | { | 978 | { |
951 | struct fat_cache_entry *fce = &fat_cache[i]; | 979 | struct fat_cache_entry *fce = &fat_cache[i]; |
952 | if(fce->inuse && fce->dirty) | 980 | if(fce->inuse |
981 | #ifdef HAVE_MULTIVOLUME | ||
982 | && fce->fat_vol == fat_bpb | ||
983 | #endif | ||
984 | && fce->dirty) | ||
953 | { | 985 | { |
954 | sec = fat_cache_sectors[i]; | 986 | sec = fat_cache_sectors[i]; |
955 | flush_fat_sector(fce, sec); | 987 | flush_fat_sector(fce, sec); |
956 | } | 988 | } |
957 | } | 989 | } |
990 | mutex_unlock(&cache_mutex); | ||
958 | 991 | ||
959 | rc = update_fsinfo(IF_MV(fat_bpb)); | 992 | rc = update_fsinfo(IF_MV(fat_bpb)); |
960 | if (rc < 0) | 993 | if (rc < 0) |
diff --git a/firmware/export/fat.h b/firmware/export/fat.h index 2f1c7be0a8..d7a5d0ded3 100644 --- a/firmware/export/fat.h +++ b/firmware/export/fat.h | |||
@@ -76,6 +76,7 @@ struct fat_dir | |||
76 | 76 | ||
77 | extern void fat_init(void); | 77 | extern void fat_init(void); |
78 | extern int fat_mount(IF_MV2(int volume,) IF_MV2(int drive,) int startsector); | 78 | extern int fat_mount(IF_MV2(int volume,) IF_MV2(int drive,) int startsector); |
79 | extern int fat_unmount(int volume, bool flush); | ||
79 | extern void fat_size(IF_MV2(int volume,) unsigned int* size, unsigned int* free); // public for info | 80 | extern void fat_size(IF_MV2(int volume,) unsigned int* size, unsigned int* free); // public for info |
80 | extern void fat_recalc_free(IF_MV_NONVOID(int volume)); // public for debug info screen | 81 | extern void fat_recalc_free(IF_MV_NONVOID(int volume)); // public for debug info screen |
81 | extern int fat_create_dir(const char* name, | 82 | extern int fat_create_dir(const char* name, |