Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Does anyone have any C code for reading the FAT? At the moment, I've read in the FAT but am stuck trying to figure out how to work with it. The main problem is that it's on a FAT12 and that means that each cluster entry is 12 bits. The code I've tried is a bit like this:
FATable is a buffer containing all the sectors of the FAT. Unfortunately, the results from this are confusing, to say the least. The first four entries are all -1, others are 0, some are numbers. I'm really confused .
char * FAT;
int getFatEntry(int i)
{
int offsetbyte = (i >> 1) * 3
int sign = i & 1;
int data;
// NOTE: i have not tested the decoding here. It might not work.
if (sign) == 0
{
data = FAT[offsetbyte] + ( (FAT[offsetbyte+1] & 0xf) << 8) & 0xfff;
} else {
data = (FAT[offsetbyte+1] + (FAT[offsetbyte+2] << 8) ) >> 4;
}
return(data);
}
You should check with the FAT page in the wiki - it tells you everything you need.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]