forked from len0rd/rockbox
unmount function in preparation for MMC hotswap, more mutexing
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5536 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
93660701e6
commit
7414687c58
2 changed files with 35 additions and 1 deletions
|
|
@ -480,6 +480,33 @@ int fat_mount(IF_MV2(int volume,) IF_MV2(int drive,) int startsector)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_MULTIVOLUME
|
||||||
|
int fat_unmount(int volume, bool flush)
|
||||||
|
{
|
||||||
|
struct bpb* fat_bpb = &fat_bpbs[volume];
|
||||||
|
if(flush)
|
||||||
|
{
|
||||||
|
flush_fat(fat_bpb); /* the clean way, while still alive */
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ /* volume is not accessible any more, e.g. MMC removed */
|
||||||
|
int i;
|
||||||
|
mutex_lock(&cache_mutex);
|
||||||
|
for(i = 0;i < FAT_CACHE_SIZE;i++)
|
||||||
|
{
|
||||||
|
struct fat_cache_entry *fce = &fat_cache[i];
|
||||||
|
if(fce->inuse && fce->fat_vol == fat_bpb)
|
||||||
|
{
|
||||||
|
fce->inuse = false; /* discard all from that volume */
|
||||||
|
fce->dirty = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mutex_unlock(&cache_mutex);
|
||||||
|
}
|
||||||
|
fat_bpb->mounted = false;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void fat_recalc_free(IF_MV_NONVOID(int volume))
|
void fat_recalc_free(IF_MV_NONVOID(int volume))
|
||||||
{
|
{
|
||||||
#ifndef HAVE_MULTIVOLUME
|
#ifndef HAVE_MULTIVOLUME
|
||||||
|
|
@ -946,15 +973,21 @@ static int flush_fat(IF_MV_NONVOID(struct bpb* fat_bpb))
|
||||||
unsigned char *sec;
|
unsigned char *sec;
|
||||||
LDEBUGF("flush_fat()\n");
|
LDEBUGF("flush_fat()\n");
|
||||||
|
|
||||||
|
mutex_lock(&cache_mutex);
|
||||||
for(i = 0;i < FAT_CACHE_SIZE;i++)
|
for(i = 0;i < FAT_CACHE_SIZE;i++)
|
||||||
{
|
{
|
||||||
struct fat_cache_entry *fce = &fat_cache[i];
|
struct fat_cache_entry *fce = &fat_cache[i];
|
||||||
if(fce->inuse && fce->dirty)
|
if(fce->inuse
|
||||||
|
#ifdef HAVE_MULTIVOLUME
|
||||||
|
&& fce->fat_vol == fat_bpb
|
||||||
|
#endif
|
||||||
|
&& fce->dirty)
|
||||||
{
|
{
|
||||||
sec = fat_cache_sectors[i];
|
sec = fat_cache_sectors[i];
|
||||||
flush_fat_sector(fce, sec);
|
flush_fat_sector(fce, sec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mutex_unlock(&cache_mutex);
|
||||||
|
|
||||||
rc = update_fsinfo(IF_MV(fat_bpb));
|
rc = update_fsinfo(IF_MV(fat_bpb));
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,7 @@ struct fat_dir
|
||||||
|
|
||||||
extern void fat_init(void);
|
extern void fat_init(void);
|
||||||
extern int fat_mount(IF_MV2(int volume,) IF_MV2(int drive,) int startsector);
|
extern int fat_mount(IF_MV2(int volume,) IF_MV2(int drive,) int startsector);
|
||||||
|
extern int fat_unmount(int volume, bool flush);
|
||||||
extern void fat_size(IF_MV2(int volume,) unsigned int* size, unsigned int* free); // public for info
|
extern void fat_size(IF_MV2(int volume,) unsigned int* size, unsigned int* free); // public for info
|
||||||
extern void fat_recalc_free(IF_MV_NONVOID(int volume)); // public for debug info screen
|
extern void fat_recalc_free(IF_MV_NONVOID(int volume)); // public for debug info screen
|
||||||
extern int fat_create_dir(const char* name,
|
extern int fat_create_dir(const char* name,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue