1
0
Fork 0
forked from len0rd/rockbox

Greg's improved fat_cache_sector() function, now updates the second FAT

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2814 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Linus Nielsen Feltzing 2002-11-09 09:23:43 +00:00
parent 81449d9642
commit 4382c68b3f

View file

@ -392,40 +392,50 @@ static void *cache_fat_sector(int fatsector)
{ {
int secnum = fatsector + fat_bpb.bpb_rsvdseccnt; int secnum = fatsector + fat_bpb.bpb_rsvdseccnt;
int cache_index = secnum & FAT_CACHE_MASK; int cache_index = secnum & FAT_CACHE_MASK;
struct fat_cache_entry *fce = &fat_cache[cache_index];
unsigned char *sectorbuf = &fat_cache_sectors[cache_index][0];
/* Delete the cache entry if it isn't the sector we want */ /* Delete the cache entry if it isn't the sector we want */
if(fat_cache[cache_index].inuse && if(fce->inuse && fce->secnum != secnum)
fat_cache[cache_index].secnum != secnum)
{ {
/* Write back if it is dirty */ /* Write back if it is dirty */
if(fat_cache[cache_index].dirty) if(fce->dirty)
{ {
if(ata_write_sectors(fat_cache[cache_index].secnum + if(ata_write_sectors(fce->secnum+fat_bpb.startsector, 1,
fat_bpb.startsector, 1, sectorbuf))
fat_cache_sectors[cache_index]))
{ {
panicf("cache_fat_sector() - Could not write sector %d\n", panicf("cache_fat_sector() - Could not write sector %d\n",
secnum); secnum);
} }
if(fat_bpb.bpb_numfats > 1)
{
/* Write to the second FAT */
if(ata_write_sectors(fce->secnum+fat_bpb.startsector+
fat_bpb.fatsize, 1, sectorbuf))
{
panicf("cache_fat_sector() - Could not write sector %d\n",
secnum + fat_bpb.fatsize);
}
}
} }
fat_cache[cache_index].secnum = 8; /* Normally an unused sector */ fce->secnum = 8; /* Normally an unused sector */
fat_cache[cache_index].dirty = false; fce->dirty = false;
fat_cache[cache_index].inuse = false; fce->inuse = false;
} }
/* Load the sector if it is not cached */ /* Load the sector if it is not cached */
if(!fat_cache[cache_index].inuse) if(!fce->inuse)
{ {
if(ata_read_sectors(secnum + fat_bpb.startsector,1, if(ata_read_sectors(secnum + fat_bpb.startsector,1,
fat_cache_sectors[cache_index])) sectorbuf))
{ {
DEBUGF( "cache_fat_sector() - Could not read sector %d\n", secnum); DEBUGF( "cache_fat_sector() - Could not read sector %d\n", secnum);
return NULL; return NULL;
} }
fat_cache[cache_index].inuse = true; fce->inuse = true;
fat_cache[cache_index].secnum = secnum; fce->secnum = secnum;
} }
return fat_cache_sectors[cache_index]; return sectorbuf;
} }
static int find_free_cluster(int startcluster) static int find_free_cluster(int startcluster)