fat filesystem

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
vishal
Posts: 17
Joined: Sun Nov 11, 2007 3:30 pm

fat filesystem

Post by vishal »

how does windows determine that a disk has the FAT12 or FAT16 or FAT32 filesystem?
Pyrofan1
Member
Member
Posts: 234
Joined: Sun Apr 29, 2007 1:13 am

Post by Pyrofan1 »

The partition table
JJeronimo
Member
Member
Posts: 202
Joined: Wed Oct 18, 2006 3:29 pm

Post 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
Pyrofan1
Member
Member
Posts: 234
Joined: Sun Apr 29, 2007 1:13 am

Post 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.
JJeronimo
Member
Member
Posts: 202
Joined: Wed Oct 18, 2006 3:29 pm

Post 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
User avatar
lukem95
Member
Member
Posts: 536
Joined: Fri Aug 03, 2007 6:03 am
Location: Cambridge, UK

Post by lukem95 »

your being rather rude to someone that is trying to help you.

And floppys can have different FS's, commonly FAT12.
~ Lukem95 [ Cake ]
Release: 0.08b
Image
JJeronimo
Member
Member
Posts: 202
Joined: Wed Oct 18, 2006 3:29 pm

Post 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
Ready4Dis
Member
Member
Posts: 571
Joined: Sat Nov 18, 2006 9:11 am

Post 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.
vishal
Posts: 17
Joined: Sun Nov 11, 2007 3:30 pm

Post 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 ?
JJeronimo
Member
Member
Posts: 202
Joined: Wed Oct 18, 2006 3:29 pm

Post 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
Ready4Dis
Member
Member
Posts: 571
Joined: Sat Nov 18, 2006 9:11 am

Post 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.
vishal
Posts: 17
Joined: Sun Nov 11, 2007 3:30 pm

Post by vishal »

yeah it is given in the specifications and i missed it...sorry

thanks all of you for your help
Post Reply