diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/drivers/fat.c | 40 |
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 | ||
431 | static int find_free_cluster(int startcluster) | 441 | static int find_free_cluster(int startcluster) |