summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2002-05-09 22:57:54 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2002-05-09 22:57:54 +0000
commit8083e7a227706951d22a0feec1bb5d7efa5d9a3b (patch)
tree42663d5e171b372ce623825ad3fd793abcc34f5a
parent114fce01dd992e1547ef3ce21f954c4f2666c047 (diff)
downloadrockbox-8083e7a227706951d22a0feec1bb5d7efa5d9a3b.zip
rockbox-8083e7a227706951d22a0feec1bb5d7efa5d9a3b.tar.gz
rockbox-8083e7a227706951d22a0feec1bb5d7efa5d9a3b.tar.bz2
rockbox-8083e7a227706951d22a0feec1bb5d7efa5d9a3b.tar.xz
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
-rw-r--r--firmware/drivers/fat.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c
index c663c5d..f3d6f61 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;