diff options
author | Linus Nielsen Feltzing <linus@haxx.se> | 2002-05-09 22:57:54 +0000 |
---|---|---|
committer | Linus Nielsen Feltzing <linus@haxx.se> | 2002-05-09 22:57:54 +0000 |
commit | 8083e7a227706951d22a0feec1bb5d7efa5d9a3b (patch) | |
tree | 42663d5e171b372ce623825ad3fd793abcc34f5a /firmware | |
parent | 114fce01dd992e1547ef3ce21f954c4f2666c047 (diff) | |
download | rockbox-8083e7a227706951d22a0feec1bb5d7efa5d9a3b.tar.gz rockbox-8083e7a227706951d22a0feec1bb5d7efa5d9a3b.zip |
get_next_cluster forgot to byteswap the FAT entry, among others
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@527 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/drivers/fat.c | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c index c663c5d937..f3d6f6145c 100644 --- a/firmware/drivers/fat.c +++ b/firmware/drivers/fat.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include "fat.h" | 28 | #include "fat.h" |
29 | #include "ata.h" | 29 | #include "ata.h" |
30 | #include "debug.h" | 30 | #include "debug.h" |
31 | #include "system.h" | ||
31 | 32 | ||
32 | #define BYTES2INT16(array,pos) \ | 33 | #define BYTES2INT16(array,pos) \ |
33 | (array[pos] | (array[pos+1] << 8 )) | 34 | (array[pos] | (array[pos+1] << 8 )) |
@@ -142,6 +143,12 @@ struct fat_cache_entry fat_cache[FAT_CACHE_SIZE]; | |||
142 | static unsigned char lastsector[SECTOR_SIZE]; | 143 | static unsigned char lastsector[SECTOR_SIZE]; |
143 | static unsigned char lastsector2[SECTOR_SIZE]; | 144 | static unsigned char lastsector2[SECTOR_SIZE]; |
144 | 145 | ||
146 | static unsigned int swap_fat_entry(unsigned int entry) | ||
147 | { | ||
148 | SWAB32(entry); | ||
149 | return entry; | ||
150 | } | ||
151 | |||
145 | static int sec2cluster(unsigned int sec) | 152 | static int sec2cluster(unsigned int sec) |
146 | { | 153 | { |
147 | if ( sec < fat_bpb.firstdatasector ) | 154 | if ( sec < fat_bpb.firstdatasector ) |
@@ -339,20 +346,20 @@ static void *cache_fat_sector(int secnum) | |||
339 | /* Write back if it is dirty */ | 346 | /* Write back if it is dirty */ |
340 | if(fat_cache[cache_index].dirty) | 347 | if(fat_cache[cache_index].dirty) |
341 | { | 348 | { |
342 | if(ata_write_sectors(secnum + fat_bpb.bpb_rsvdseccnt + | 349 | if(ata_write_sectors(secnum + fat_bpb.startsector, 1, sec)) |
343 | fat_bpb.startsector, 1, sec)) | ||
344 | { | 350 | { |
345 | panic("cache_fat_sector() - Could" | 351 | panic("cache_fat_sector() - Could" |
346 | " not write sector %d\n", | 352 | " not write sector %d\n", |
347 | secnum); | 353 | secnum); |
348 | } | 354 | } |
349 | } | 355 | } |
356 | #endif | ||
350 | free(sec); | 357 | free(sec); |
351 | 358 | ||
352 | fat_cache[cache_index].ptr = NULL; | 359 | fat_cache[cache_index].ptr = NULL; |
353 | fat_cache[cache_index].secnum = 8; /* Normally an unused sector */ | 360 | fat_cache[cache_index].secnum = 8; /* Normally an unused sector */ |
354 | fat_cache[cache_index].dirty = 0; | 361 | fat_cache[cache_index].dirty = 0; |
355 | #endif | 362 | sec = NULL; |
356 | } | 363 | } |
357 | 364 | ||
358 | /* Load the sector if it is not cached */ | 365 | /* Load the sector if it is not cached */ |
@@ -364,7 +371,7 @@ static void *cache_fat_sector(int secnum) | |||
364 | DEBUGF( "cache_fat_sector() - Out of memory\n"); | 371 | DEBUGF( "cache_fat_sector() - Out of memory\n"); |
365 | return NULL; | 372 | return NULL; |
366 | } | 373 | } |
367 | if(ata_read_sectors(secnum+fat_bpb.startsector,1,sec)) | 374 | if(ata_read_sectors(secnum + fat_bpb.startsector,1,sec)) |
368 | { | 375 | { |
369 | DEBUGF( "cache_fat_sector() - Could" | 376 | DEBUGF( "cache_fat_sector() - Could" |
370 | " not read sector %d\n", | 377 | " not read sector %d\n", |
@@ -424,22 +431,31 @@ static int read_entry(int entry) | |||
424 | thisfatentoffset = fatoffset % fat_bpb.bpb_bytspersec; | 431 | thisfatentoffset = fatoffset % fat_bpb.bpb_bytspersec; |
425 | 432 | ||
426 | /* Load the sector if it is not cached */ | 433 | /* Load the sector if it is not cached */ |
434 | debugf("Loading FAT sector %d\n", thisfatsecnum); | ||
427 | sec = cache_fat_sector(thisfatsecnum); | 435 | sec = cache_fat_sector(thisfatsecnum); |
428 | if(!sec) | 436 | if(!sec) |
429 | { | 437 | { |
430 | DEBUGF( "update_entry() - Could not cache sector %d\n", | 438 | DEBUGF( "read_entry() - Could not cache sector %d\n", |
431 | thisfatsecnum); | 439 | thisfatsecnum); |
432 | return -1; | 440 | return -1; |
433 | } | 441 | } |
434 | 442 | ||
435 | val = sec[thisfatentoffset/sizeof(int)]; | 443 | val = sec[thisfatentoffset/sizeof(int)]; |
444 | |||
445 | val = SWAB32(val); | ||
446 | |||
436 | return val; | 447 | return val; |
437 | } | 448 | } |
438 | 449 | ||
439 | static int get_next_cluster(unsigned int cluster) | 450 | static int get_next_cluster(unsigned int cluster) |
440 | { | 451 | { |
441 | int next_cluster = read_entry(cluster); | 452 | int next_cluster; |
442 | 453 | ||
454 | debugf("get_next_cluster(%d)\n", cluster); | ||
455 | next_cluster = read_entry(cluster); | ||
456 | |||
457 | debugf("next cluster is %d\n", next_cluster); | ||
458 | |||
443 | /* is this last cluster in chain? */ | 459 | /* is this last cluster in chain? */ |
444 | if ( next_cluster >= 0x0ffffff8 ) | 460 | if ( next_cluster >= 0x0ffffff8 ) |
445 | return 0; | 461 | return 0; |