2026-07-20 14:37:57
#TIL that the #FAT #filesystem doesn't really store anywhere whether it's #FAT12, #FAT16 and #FAT32. What you're supposed to do is to look at the number of clusters, and determine which range it falls into. More specifically, you're supposed to look at the partition size and divide it by the number of sectors per cluster (which is stored in consistent position irrespective of FAT type).
The obvious implication of that is that the volume sizes are limited by possible cluster size ranges. There's some overlap here, though: you get more clusters (and therefore use a "longer" FAT) by using a smaller cluster size, or fewer clusters by using a larger cluster size.
https://elm-chan.org/docs/fat_e.html#fat_determination
However, there's a curious trick: there's a 16-bit "FAT size" field that indicates how many sectors are used for FAT on FAT12/FAT16 filesystems. On FAT32 this field is zero (there is a separate field for 32-bit FAT size there), and apparently some tools recognize the filesystem as FAT32 in that case, irrespective of number of clusters. This is what mkfs.vfat does when you force FAT32 on a small block device.
https://github.com/torvalds/linux/blob/1590cf0329716306e948a8fc29f1d3ee87d3989f/fs/fat/inode.c#L1675-L1680
Why did I learn all this? Because a friend tried to make a very small EFI partition and was surprised it didn't work. I was compelled to get to a bottom of this!