fat filesystem
fat filesystem
how does windows determine that a disk has the FAT12 or FAT16 or FAT32 filesystem?
I don't think so...Pyrofan1 wrote:The partition table
According to their specification, you have to compute the count of data clusters on the filesystem to discover the FAT type.
From the FAT code I've read so far, though, looks like people tend to just interpret an ASCII string that appears in the FAT superblock (aka boot sector) that is (often) set to the current FAT type...
According to them, this is not the correct way...
http://www.nondot.org/sabre/os/files/Fi ... Format.pdf
JJ
First of all, thanks you for informing me that each FAT type has it's own PT identifier... (not that I didn't know... this doesn't prove anything either...)Pyrofan1 wrote:I'm sure it is. FAT12 has 0x01 as a partition identifier, FAT16 has 0x04, 0x06 or 0x0E and FAT32 has 0x0B or 0x0C.
Next, the only thing I'm sure is that you didn't read the rest of my post...
Anyway, what if the FS is on a floppy? Floppies do not have a partition ID....... Isn't it?
JJ
It wasn't me who asked the question in the first place... (neither you, but that doesn't matter now...)lukem95 wrote:your being rather rude to someone that is trying to help you.
Of course.And floppies can have different FS's, commonly FAT12.
The partition table ID value can be a hint to the filesystem type in the same way that a file extension can be a hint to the file type. You can always, however, analyze the partition to confirm that the FS type is that one (as you can do it to confirm the file type against the extension)... In fact, if you are in a floppy disk, that's the only way you can find out what type of FS is in it, since there are no "partition IDs". The same holds if you are behind an abstraction barrier that doesn't allow you to easily determine the partition ID.
If you already know it's FAT, the correct way to determine the size of the FAT entries is to compute the number of data clusters and compare it to reference values.
JJ
Yes, that is the correct way according to the microsoft specs. The way I determine it (which may or may not always work, and is from an old Fat driver that may or may/not make it into my new rewrite) is to check the BPB FatSize, if it's 0, that means they are using the 32-bit Fat size in the Fat32 structure, so we can assume Fat32 here. If that fails, I then figure out the Cluster cound and check it's size to determine file system type.
See the FAT spec. They explain everything there.vishal wrote:how does windows compute the number of clusters ?
does it read from the Bios Parameter block or does some calculation from the size of the FAT table ?
http://www.nondot.org/sabre/os/files/Fi ... Format.pdf
JJ
Well, as mentioned above, everything is in the specs. However, here is a short rundown of how my code works (abridged)vishal wrote:how does windows compute the number of clusters ?
does it read from the Bios Parameter block or does some calculation from the size of the FAT table ?
Code: Select all
if (BPB->ToatlSectors16)
TotalSectors = BPB->TotalSectors16;
else
{
TotalSectors = Fat32->TotalSectors32;
FatType = 32;
}
if (BPB->FatSectors16)
FatSect = BPB->FatSectors16;
else
{
FatSect = BPB->FatSectors32;
FatType = 32;
}
if (FatType!=32)
{
RootSect = RootEntryCount*32;
//Lets round UP to the nearest sector now ;)
RootSect = (RootSect+BPB->BytesPerSector-1)/BPB->BytesPerSector;
DataSect = TotalSectors - (BPB->ReserevedSectors + BPB->FatCount*FatSect + RootSect);
Clusters = DataSect / BPB->SectorsPerCluster;
if (Clusters < 40958) //Fat 12
FatType = 12;
else if (Clusters < 65525) //Fat16
FatType = 16;
else //Fat32
FatType = 32;
}
Feel free to use in whole or in part. I also do some other checks at the beginning, like checking for a valid # of fat tables (I only allow 1 or 2, no more), check SectorsPerCluster to make sure it's a power of 2 (although, I support non-power of 2's just in case), maybe a few checks to make sure it's a valid BPB, etc. Anyways, this will give you the disk type that you are looking for.