From 8083e7a227706951d22a0feec1bb5d7efa5d9a3b Mon Sep 17 00:00:00 2001 From: Linus Nielsen Feltzing Date: Thu, 9 May 2002 22:57:54 +0000 Subject: 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 --- firmware/drivers/fat.c | 28 ++++++++++++++++++++++------ 1 file 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 @@ #include "fat.h" #include "ata.h" #include "debug.h" +#include "system.h" #define BYTES2INT16(array,pos) \ (array[pos] | (array[pos+1] << 8 )) @@ -142,6 +143,12 @@ struct fat_cache_entry fat_cache[FAT_CACHE_SIZE]; static unsigned char lastsector[SECTOR_SIZE]; static unsigned char lastsector2[SECTOR_SIZE]; +static unsigned int swap_fat_entry(unsigned int entry) +{ + SWAB32(entry); + return entry; +} + static int sec2cluster(unsigned int sec) { if ( sec < fat_bpb.firstdatasector ) @@ -339,20 +346,20 @@ static void *cache_fat_sector(int secnum) /* Write back if it is dirty */ if(fat_cache[cache_index].dirty) { - if(ata_write_sectors(secnum + fat_bpb.bpb_rsvdseccnt + - fat_bpb.startsector, 1, sec)) + if(ata_write_sectors(secnum + fat_bpb.startsector, 1, sec)) { panic("cache_fat_sector() - Could" " not write sector %d\n", secnum); } } +#endif free(sec); fat_cache[cache_index].ptr = NULL; fat_cache[cache_index].secnum = 8; /* Normally an unused sector */ fat_cache[cache_index].dirty = 0; -#endif + sec = NULL; } /* Load the sector if it is not cached */ @@ -364,7 +371,7 @@ static void *cache_fat_sector(int secnum) DEBUGF( "cache_fat_sector() - Out of memory\n"); return NULL; } - if(ata_read_sectors(secnum+fat_bpb.startsector,1,sec)) + if(ata_read_sectors(secnum + fat_bpb.startsector,1,sec)) { DEBUGF( "cache_fat_sector() - Could" " not read sector %d\n", @@ -424,22 +431,31 @@ static int read_entry(int entry) thisfatentoffset = fatoffset % fat_bpb.bpb_bytspersec; /* Load the sector if it is not cached */ + debugf("Loading FAT sector %d\n", thisfatsecnum); sec = cache_fat_sector(thisfatsecnum); if(!sec) { - DEBUGF( "update_entry() - Could not cache sector %d\n", + DEBUGF( "read_entry() - Could not cache sector %d\n", thisfatsecnum); return -1; } val = sec[thisfatentoffset/sizeof(int)]; + + val = SWAB32(val); + return val; } static int get_next_cluster(unsigned int cluster) { - int next_cluster = read_entry(cluster); + int next_cluster; + debugf("get_next_cluster(%d)\n", cluster); + next_cluster = read_entry(cluster); + + debugf("next cluster is %d\n", next_cluster); + /* is this last cluster in chain? */ if ( next_cluster >= 0x0ffffff8 ) return 0; -- cgit v1.2.3