summaryrefslogtreecommitdiff
path: root/firmware
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 /firmware
parent81449d96421edd1fcd22c288102b7f192e7e7cd4 (diff)
downloadrockbox-4382c68b3f1fbecb7bf731f02909bee09ec52102.tar.gz
rockbox-4382c68b3f1fbecb7bf731f02909bee09ec52102.zip
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
Diffstat (limited to 'firmware')
-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 860e47df00..47bfd1afef 100644
--- a/firmware/drivers/fat.c
+++ b/firmware/drivers/fat.c
@@ -392,40 +392,50 @@ static void *cache_fat_sector(int fatsector)
392{ 392{
393 int secnum = fatsector + fat_bpb.bpb_rsvdseccnt; 393 int secnum = fatsector + fat_bpb.bpb_rsvdseccnt;
394 int cache_index = secnum & FAT_CACHE_MASK; 394 int cache_index = secnum & FAT_CACHE_MASK;
395 struct fat_cache_entry *fce = &fat_cache[cache_index];
396 unsigned char *sectorbuf = &fat_cache_sectors[cache_index][0];
395 397
396 /* Delete the cache entry if it isn't the sector we want */ 398 /* Delete the cache entry if it isn't the sector we want */
397 if(fat_cache[cache_index].inuse && 399 if(fce->inuse && fce->secnum != secnum)
398 fat_cache[cache_index].secnum != secnum)
399 { 400 {
400 /* Write back if it is dirty */ 401 /* Write back if it is dirty */
401 if(fat_cache[cache_index].dirty) 402 if(fce->dirty)
402 { 403 {
403 if(ata_write_sectors(fat_cache[cache_index].secnum + 404 if(ata_write_sectors(fce->secnum+fat_bpb.startsector, 1,
404 fat_bpb.startsector, 1, 405 sectorbuf))
405 fat_cache_sectors[cache_index]))
406 { 406 {
407 panicf("cache_fat_sector() - Could not write sector %d\n", 407 panicf("cache_fat_sector() - Could not write sector %d\n",
408 secnum); 408 secnum);
409 } 409 }
410 if(fat_bpb.bpb_numfats > 1)
411 {
412 /* Write to the second FAT */
413 if(ata_write_sectors(fce->secnum+fat_bpb.startsector+
414 fat_bpb.fatsize, 1, sectorbuf))
415 {
416 panicf("cache_fat_sector() - Could not write sector %d\n",
417 secnum + fat_bpb.fatsize);
418 }
419 }
410 } 420 }
411 fat_cache[cache_index].secnum = 8; /* Normally an unused sector */ 421 fce->secnum = 8; /* Normally an unused sector */
412 fat_cache[cache_index].dirty = false; 422 fce->dirty = false;
413 fat_cache[cache_index].inuse = false; 423 fce->inuse = false;
414 } 424 }
415 425
416 /* Load the sector if it is not cached */ 426 /* Load the sector if it is not cached */
417 if(!fat_cache[cache_index].inuse) 427 if(!fce->inuse)
418 { 428 {
419 if(ata_read_sectors(secnum + fat_bpb.startsector,1, 429 if(ata_read_sectors(secnum + fat_bpb.startsector,1,
420 fat_cache_sectors[cache_index])) 430 sectorbuf))
421 { 431 {
422 DEBUGF( "cache_fat_sector() - Could not read sector %d\n", secnum); 432 DEBUGF( "cache_fat_sector() - Could not read sector %d\n", secnum);
423 return NULL; 433 return NULL;
424 } 434 }
425 fat_cache[cache_index].inuse = true; 435 fce->inuse = true;
426 fat_cache[cache_index].secnum = secnum; 436 fce->secnum = secnum;
427 } 437 }
428 return fat_cache_sectors[cache_index]; 438 return sectorbuf;
429} 439}
430 440
431static int find_free_cluster(int startcluster) 441static int find_free_cluster(int startcluster)