Page 1 of 1

fat filesystem

Posted: Sun Mar 23, 2008 3:08 pm
by vishal
how does windows determine that a disk has the FAT12 or FAT16 or FAT32 filesystem?

Posted: Sun Mar 23, 2008 3:14 pm
by Pyrofan1
The partition table

Posted: Sun Mar 23, 2008 3:26 pm
by JJeronimo
Pyrofan1 wrote:The partition table
I don't think so...
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

Posted: Sun Mar 23, 2008 3:51 pm
by Pyrofan1
I don't think so...
I'm sure it is. FAT12 has 0x01 as a partition identifier, FAT16 has 0x04, 0x06 or 0x0E and FAT32 has 0x0B or 0x0C.

Posted: Sun Mar 23, 2008 4:23 pm
by JJeronimo
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.
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...)

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

Posted: Sun Mar 23, 2008 4:45 pm
by lukem95
your being rather rude to someone that is trying to help you.

And floppys can have different FS's, commonly FAT12.

Posted: Sun Mar 23, 2008 7:19 pm
by JJeronimo
lukem95 wrote:your being rather rude to someone that is trying to help you.
It wasn't me who asked the question in the first place... (neither you, but that doesn't matter now...)
And floppies can have different FS's, commonly FAT12.
Of course.
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

Posted: Mon Mar 24, 2008 3:08 am
by Ready4Dis
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.

Posted: Tue Mar 25, 2008 3:58 pm
by vishal
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 ?

Posted: Tue Mar 25, 2008 5:56 pm
by JJeronimo
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 ?
See the FAT spec. They explain everything there.

http://www.nondot.org/sabre/os/files/Fi ... Format.pdf

JJ

Posted: Wed Mar 26, 2008 12:34 am
by Ready4Dis
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 ?
Well, as mentioned above, everything is in the specs. However, here is a short rundown of how my code works (abridged)

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.

Posted: Wed Mar 26, 2008 2:15 am
by vishal
yeah it is given in the specifications and i missed it...sorry

thanks all of you for your help