Page 1 of 1

FAT Clusters

Posted: Sun Sep 04, 2011 6:02 pm
by Nessphoro
While writing a driver for FAT32 file system I have stumbled upon a problem,

It goes as the following, lets assume I have a file called "text.txt" and it contains some data, now,
It is the the root directory so we just need to read the cluster that is defined in the EBPB( it is 2), which maps to 2063'rd sector, so far so good,
Now we found the the file's entry,
54 45 58 54 20 20 20 20 54 58 54 20 00 00 62 7E 24 3F 24 3F 00 00 62 7E 24 3F 26 00 AB 0B 00 00
TEXT TXT ..b~$?$?..b~$?&.«...

As we can see, the cluster of the file is 0x26(Highlighted), now cluster 0x26 should map to 2063+(38-2)=2099 which is, in fact, wrong,
because I can clearly see that the file doesn't even start until sector 2351.

What am I doing wrong?

Best regards,

Ness

P.S. Linux reads the file fine.

Re: FAT Clusters

Posted: Sun Sep 04, 2011 10:40 pm
by miker00lz
not sure exactly what the deal is with your specific problem, but don't forget to take into account the high 16 bits of the first cluster number when using FAT32, which is at offset 20 decimal in the directory entry. in the case of your TEST.TXT file, however that field is zero.

Re: FAT Clusters

Posted: Mon Sep 05, 2011 12:06 am
by Nessphoro
Indeed, I have

Re: FAT Clusters

Posted: Mon Sep 05, 2011 4:05 am
by Combuster
The cluster size is not normally the same as the sector size.

Re: FAT Clusters

Posted: Mon Sep 05, 2011 8:21 am
by egos
That's right. FirstSectorOfCluster38=2063+(38-2)*SectorsPerCluster where 2063 is first sector of data area.

Re: FAT Clusters

Posted: Mon Sep 05, 2011 3:43 pm
by Nessphoro
Ah, thanks that was the problem, the cluster size was 8 sectors.