summaryrefslogtreecommitdiff
path: root/firmware/drivers
diff options
context:
space:
mode:
authorJörg Hohensohn <hohensoh@rockbox.org>2005-01-05 00:09:04 +0000
committerJörg Hohensohn <hohensoh@rockbox.org>2005-01-05 00:09:04 +0000
commit7414687c58ed7a1dab4a04687acceaeb5af8314d (patch)
tree409900d3826e6262a562bc41f767b760ea9923ae /firmware/drivers
parent93660701e633547dedcd1099501f2ac6d7f44fee (diff)
downloadrockbox-7414687c58ed7a1dab4a04687acceaeb5af8314d.tar.gz
rockbox-7414687c58ed7a1dab4a04687acceaeb5af8314d.zip
unmount function in preparation for MMC hotswap, more mutexing
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5536 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/drivers')
-rw-r--r--firmware/drivers/fat.c35
1 files changed, 34 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
484int 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
483void fat_recalc_free(IF_MV_NONVOID(int volume)) 510void 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)