summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2002-11-09 09:23:43 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2002-11-09 09:23:43 +0000
commit4382c68b3f1fbecb7bf731f02909bee09ec52102 (patch)
tree6af5b65993258bafb3dff066e5f022583b1e163f
parent81449d96421edd1fcd22c288102b7f192e7e7cd4 (diff)
downloadrockbox-4382c68b3f1fbecb7bf731f02909bee09ec52102.zip
rockbox-4382c68b3f1fbecb7bf731f02909bee09ec52102.tar.gz
rockbox-4382c68b3f1fbecb7bf731f02909bee09ec52102.tar.bz2
rockbox-4382c68b3f1fbecb7bf731f02909bee09ec52102.tar.xz
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
-rw-r--r--firmware/drivers/fat.c40
1 files changed, 25 insertions, 15 deletions
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c
index 860e47d..47bfd1a 100644
--- a/firmware/drivers/fat.c
+++ b/firmware/drivers/fat.c
@@ -392,40 +392,50 @@ static void *cache_fat_sector(int fatsector)
{
int secnum = fatsector + fat_bpb.bpb_rsvdseccnt;
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 */
- if(fat_cache[cache_index].inuse &&
- fat_cache[cache_index].secnum != secnum)
+ if(fce->inuse && fce->secnum != secnum)
{
/* Write back if it is dirty */
- if(fat_cache[cache_index].dirty)
+ if(fce->dirty)
{
- if(ata_write_sectors(fat_cache[cache_index].secnum +
- fat_bpb.startsector, 1,
- fat_cache_sectors[cache_index]))
+ if(ata_write_sectors(fce->secnum+fat_bpb.startsector, 1,
+ sectorbuf))
{
panicf("cache_fat_sector() - Could not write sector %d\n",
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 */
- fat_cache[cache_index].dirty = false;
- fat_cache[cache_index].inuse = false;
+ fce->secnum = 8; /* Normally an unused sector */
+ fce->dirty = false;
+ fce->inuse = false;
}
-
+
/* 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,
- fat_cache_sectors[cache_index]))
+ sectorbuf))
{
DEBUGF( "cache_fat_sector() - Could not read sector %d\n", secnum);
return NULL;
}
- fat_cache[cache_index].inuse = true;
- fat_cache[cache_index].secnum = secnum;
+ fce->inuse = true;
+ fce->secnum = secnum;
}
- return fat_cache_sectors[cache_index];
+ return sectorbuf;
}
static int find_free_cluster(int startcluster)