Post by JJPost by wolfgang kernyes, we better stick to "count of clusters" for determination even some
handmade formatting variants may fail on this.
* 2nd byte of the VBR is 3A,3C,3E or >=5c. it may give a hint to format
* consecutive FAT-entry checks (like you did manually)
* root size limit could be an indication too.
The maximum cluster size for FAT16 is still confusing, though. At least for
me.
https://en.wikipedia.org/wiki/File_Allocation_Table#Initial_FAT16
In "Initial FAT16" section, it states that the maximum clusters is 65524.
However, in the "FAT16" right side floating section, it says 65536 which is
incorrect because cluster number 0x0000, 0x0001, and 0xFFF0-0xFFFF, are not
for data cluster numbers. Theorically, the maximum is 65536 minus 18, or
65518.
In below archived Windows XP Resource Kit article: (long URL warning)
<https://web.archive.org/web/20060307082555/http://www.microsoft.com/technet/prodtechnol/winxppro/reskit/c13621675.mspx#EACBIAA>
In "Maximum Sizes on FAT16 Volumes" section, it also states that the maximum
is 65524. But this value is also beyond the theorical limit above.
Adding to the confusion, in "Maximum Sizes on FAT32 Volumes" section, it
states that the minimum cluster number is 65527. So if that's the case, what
happen to FAT file systems if they end up having 65525 to 65526? Should it
be FAT16, FAT32, or shouldn't exist at all?
there are exact limits defined, but not every formatting tool knows it.
M$ FAT specs say:
• For 512 byte sector sized media: if volume size is < 512 MB, the
volume is formatted
FAT16 else it is formatted FAT32. It is possible to override the default
FAT type selection.
The below tables are used by the Microsoft Corporation FAT format
utility - an entry in these
tables is selected based on the size of the volume in 512 byte sectors
(the value that will go
in BPB_TotSec16 or BPB_TotSec32), and the value that this table sets is the
BPB_SecPerClus value:
struct DSKSZTOSECPERCLUS {
DWORD DiskSize;
BYTE SecPerClusVal;
};
/*
*This is the table for FAT16 drives. NOTE that this table includes
* entries for disk sizes larger than 512 MB even though typically
* only the entries for disks < 512 MB in size are used.
* The way this table is accessed is to look for the first entry
* in the table for which the disk size is less than or equal
* to the DiskSize field in that table entry. For this table to
* work properly BPB_RsvdSecCnt must be 1, BPB_NumFATs
* must be 2, and BPB_RootEntCnt must be 512. Any of these values
* being different may require the first table entries DiskSize value
* to be changed otherwise the cluster count may be to low for FAT16.
*/
DSKSZTOSECPERCLUS DskTableFAT16 [] = {
{8400, 0}, /* disks up to 4.1 MB, the 0 value for SecPerClusVal trips an
error */
{32680, 2}, /* disks up to 16 MB, 1k cluster */
{262144, 4}, /* disks up to 128 MB, 2k cluster */
{524288, 8}, /* disks up to 256 MB, 4k cluster */
{1048576, 16}, /* disks up to 512 MB, 8k cluster */
/* The entries after this point are not used unless FAT16 is forced */
{2097152, 32}, /* disks up to 1 GB, 16k cluster */
{4194304, 64}, /* disks up to 2 GB, 32k cluster */
{0xFFFFFFFF, 0} /*any disk greater than 2GB, 0 value for SecPerClusVal
trips an error */
};
/*
* This is the table for FAT32 drives. NOTE that this table includes
* entries for disk sizes smaller than 512 MB even though typically
* only the entries for disks >= 512 MB in size are used.
* The way this table is accessed is to look for the first entry
* in the table for which the disk size is less than or equal
* to the DiskSize field in that table entry. For this table to
* work properly BPB_RsvdSecCnt must be 32, and BPB_NumFATs
* must be 2. Any of these values being different may require the first
* table entries DiskSize value to be changed otherwise the cluster count
* may be to low for FAT32.
*/
DSKSZTOSECPERCLUS DskTableFAT32 [] = {
{66600, 0}, /* disks up to 32.5 MB, the 0 value for SecPerClusVal trips
an error */
{532480, 1}, /* disks up to 260 MB, .5k cluster */
{16777216, 8}, /* disks up to 8 GB, 4k cluster */
{33554432, 16}, /* disks up to 16 GB, 8k cluster */
{67108864, 32}, /* disks up to 32 GB, 16k cluster */
{0xFFFFFFFF, 64}/* disks greater than 32GB, 32k cluster */
};
Given a disk size and a FAT type of FAT16 or FAT32, the above determines the
BPB_SecPerClus value.
...
The FAT type is determined solely by the count of clusters on the volume
(CountOfClusters).
The following steps describe the computation of the count of clusters:
1. First, determine the count of sectors occupied by the root directory:
RootDirSectors = ((BPB_RootEntCnt * 32) + (BPB_BytsPerSec – 1)) /
BPB_BytsPerSec
Note that on a FAT32 volume, the BPB_RootEntCnt value is always 0.
Therefore, on a
FAT32 volume, RootDirSectors is always 0.
2. Next, determine the count of sectors in the data region of the volume:
If(BPB_FATSz16 != 0)
FATSz = BPB_FATSz16;
Else
FATSz = BPB_FATSz32;
If(BPB_TotSec16 != 0)
TotSec = BPB_TotSec16;
Else
TotSec = BPB_TotSec32;
DataSec = TotSec – (BPB_ResvdSecCnt + (BPB_NumFATs * FATSz) +
RootDirSectors);
3. Lastly, determine the count of clusters as:
CountofClusters = DataSec / BPB_SecPerClus;
</>
confusing ? :) another M$ white paper tells cluster count limits to
be <= f4 0ff4 fff4 (total, including first two)
__
wolfgang