FS#55 - FAT start address

Attached to Project: Rockbox
Opened by Anonymous Submitter - Sunday, 16 June 2002, 13:12 GMT
Last edited by Björn Stenberg (zagor) - Monday, 17 June 2002, 09:22 GMT
Task Type Bugs
Status Closed
Assigned To No-one
Operating System
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 0%
Votes 0
Private No



I have been snooping around your code to look at the
reusability it, and found one error in the FAT calulation.
The FAT start sector was not included in these
In my case, the FAT looked corrupt.
The first cluster could be read(since the fileentry
contains the location of the first sector), but as soon as
the next cluster had checked inside the FAT, it failed.
By making the below adjustment, I could get it running:


static int read_entry(int entry)
unsigned long *sec;
int fatoffset;
int thisfatsecnum;
int thisfatentoffset;
int val = -1;

fatoffset = entry * 4;

// OLD
thisfatsecnum = fatoffset / fat_bpb.bpb_bytspersec +

// NEW
thisfatsecnum = (fatoffset / fat_bpb.bpb_bytspersec) +
fat_bpb.bpb_rsvdseccnt + fat_bpb.startsector ;
// END

thisfatentoffset = fatoffset % fat_bpb.bpb_bytspersec;

/* Load the sector if it is not cached */
sec = cache_fat_sector(thisfatsecnum);
DEBUGF( "read_entry() - Could not cache sector %
return -1;

val = sec[thisfatentoffset/sizeof(int)];

val = SWAB32(val);

return val;

I disabled the FAT caching for me to get all this running.

Well, thats my contribution. Great project you are doing!


This task depends upon

Closed by  Björn Stenberg (zagor)
Monday, 17 June 2002, 09:22 GMT
Reason for closing:  
Comment by Björn Stenberg (zagor) - Monday, 17 June 2002, 09:22 GMT

This is not a bug.

'startsector' is used in the cache_fat_sector() function, so
it should not be added to 'thisfatsecnum'. Only if you
disable caching will you need to change this code.