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
This commit is contained in:
Linus Nielsen Feltzing 2002-05-09 22:57:54 +00:00
parent 114fce01dd
commit 8083e7a227

View file

@ -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 */
@ -424,21 +431,30 @@ 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 )