FAT Clusters

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.
Post Reply
User avatar
Nessphoro
Member
Member
Posts: 308
Joined: Sat Apr 30, 2011 12:50 am

FAT Clusters

Post 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.
User avatar
miker00lz
Member
Member
Posts: 144
Joined: Wed Dec 08, 2010 3:16 am
Location: St. Louis, MO USA

Re: FAT Clusters

Post 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.
User avatar
Nessphoro
Member
Member
Posts: 308
Joined: Sat Apr 30, 2011 12:50 am

Re: FAT Clusters

Post by Nessphoro »

Indeed, I have
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: FAT Clusters

Post by Combuster »

The cluster size is not normally the same as the sector size.
"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 ]
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: FAT Clusters

Post by egos »

That's right. FirstSectorOfCluster38=2063+(38-2)*SectorsPerCluster where 2063 is first sector of data area.
If you have seen bad English in my words, tell me what's wrong, please.
User avatar
Nessphoro
Member
Member
Posts: 308
Joined: Sat Apr 30, 2011 12:50 am

Re: FAT Clusters

Post by Nessphoro »

Ah, thanks that was the problem, the cluster size was 8 sectors.
Post Reply