How to recognize FAT12/FAT16/FAT32 ?

Programming, for all ages and all languages.
Post Reply
User avatar
trinopoty
Member
Member
Posts: 87
Joined: Wed Feb 09, 2011 2:21 am
Location: Raipur, India

How to recognize FAT12/FAT16/FAT32 ?

Post by trinopoty »

This may be a silly question.
How do I tell if a partition is formatted with FAT12/FAT16/FAT32 by analyzing the first sector of the partition (in software) ?
I do not need any code examples, just the principle to use.
Always give a difficult task to a lazy person. He will find an easy way to do it.
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: How to recognize FAT12/FAT16/FAT32 ?

Post by egos »

FAT12/FAT16 - by number of clusters (size of file data area div cluster size).
FAT32 - by specific BPB+ structure.
If you have seen bad English in my words, tell me what's wrong, please.
User avatar
iansjack
Member
Member
Posts: 4685
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: How to recognize FAT12/FAT16/FAT32 ?

Post by iansjack »

In a bit more detail: http://homepage.ntlworld.com/jonathan.d ... idths.html

(Isn't Google wonderful.)
User avatar
trinopoty
Member
Member
Posts: 87
Joined: Wed Feb 09, 2011 2:21 am
Location: Raipur, India

Re: How to recognize FAT12/FAT16/FAT32 ?

Post by trinopoty »

I tried searching on google (with different keywords).
Always give a difficult task to a lazy person. He will find an easy way to do it.
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: How to recognize FAT12/FAT16/FAT32 ?

Post by egos »

iansjack wrote:In a bit more detail: http://homepage.ntlworld.com/jonathan.d ... idths.html
Cluster xF6h is incorrect. Value xF6h is used to mark reserved clusters in many extensions. FAT Spec. says that max count of clusters is xF4h (xF6h-2).
If you have seen bad English in my words, tell me what's wrong, please.
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: How to recognize FAT12/FAT16/FAT32 ?

Post by qw »

The [url=http://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-923143f3456c/fatgen103.doc]Microsoft Extensible Firmware Initiative FAT32 File System Specification[/url] wrote:

Code: Select all

if (CountofClusters < 4085) {
    /* Volume is FAT12 */
} else if (CountofClusters < 65525) {
    /* Volume is FAT16 */
} else {
    /* Volume is FAT32 */
}
This is the one and only way that FAT type is determined.
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: How to recognize FAT12/FAT16/FAT32 ?

Post by egos »

Yes, but FAT32 BPB+ differs from FAT12/FAT16 BPB+. It's not true that FAT12/FAT16 can have FAT32 BPB+. So when you have detected FAT32 you additionally can check condition "number of clusters > 0FFF4h".
If you have seen bad English in my words, tell me what's wrong, please.
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: How to recognize FAT12/FAT16/FAT32 ?

Post by qw »

To know the specific BPB+ structure, you need to know the exact FAT version first.

FAT32 can be distinguished from FAT12/16 by the number of entries in the root directory (word at offset 17 in the BPB) and/or the size of one FAT (word at offset 22) which are always zero on FAT32 and always non-zero on FAT12/16.

If this tells you that the file system is FAT32 but the number of clusters is below 65525, then the volume is corrupt.

The FAT version is not determined by the file system type (eight-byte string at offset 54).
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: How to recognize FAT12/FAT16/FAT32 ?

Post by egos »

Hobbes wrote:To know the specific BPB+ structure, you need to know the exact FAT version first.
No, I can detect this primarily.
If you have seen bad English in my words, tell me what's wrong, please.
Post Reply