FAT’s maximum file size

fat16fat32filesystems

From what I understand, FAT32 uses a 32 bit number for each file to store its file size (and thus FAT32 is limited at ~4GiB files). In FAT each file has a root directory entry, and these entries are what store the value for the file size. This page shows the directory entry's structure for FAT32. This resource suggests that FAT12 uses a 25 bit value for file size, and FAT16 a 31 bit value.

Is the information in the second linked resource correct? If not, what is the true maximum file size for FAT12 and FAT16? If it is true, then why is an irregular number of bits used to store file size for these file systems?

EDIT: Why is it that they are restricted by volume size, whereas FAT32 has a set size? Is it because the file size that it stores is bigger than any supported volume size, or do FAT12 and FAT16 not use a file size as a field in the directory entry?

Best Answer

File size on FAT is stored in a 32-bit field.

On FAT32 the field is treated as unsigned allowing for files up to 4294967294 bytes (apparently 4294967295 is not allowed for some reason, possiblly "-1" was used as a flag somewhere).

On FAT16 the field is limited to the range of a signed 32-bit number. I expect the reason for this is legacy code that was written back when 2GB would have been considered an insane size for a file. FAT16 filesystems beyond 2GB were an oddity anyway*.

AIUI on FAT12 the file size is limited to 32MB (not 32KB!) not because of any limitation specific to file size, but simply because that is the maximum size of the volume and you can't have a file bigger than the volume. The same would apply to early versions of FAT16.

* The version of FAT16 used by DOS 4 through windows 95 was limited to 64 sectors per cluster which on typical 512 byte sectors meant a roughly 2GiB volume size. NT doubled the maximum sectors per cluster allowing ~4GiB volumes with 512 byte sectors and 98 added support for reading/writing but not creating or repairing such volulems. Bigger volumes were theoretically possible if the underlying device had bigger sectors but I have seen no evidence that this actually happend in practice.

Related Question