4

I am searching for the answer, what is the theoretical minimum size for a FAT12 volume?

There is only requirements that embedded and normal systems should recognize it on a pen drive as legal file system. Small size as possible without filesystem driver crash. Even if only 1 data sector - that will be perfect! So what is the minimum legal size?

Thank You,

3 Answers3

2

Minimum working system (on windows and mac os) with 1Kb of free space

is 7 sectors x 512bytes = 3.5Kb

1 sector - boot sector

2 sectors - fat1 + fat2 tables

2 sectors - root directory (32 entries)

2 sectors - at least one cluster of data

Denikin
  • 21
2

The minimum size for a FAT12 volume is 2560 bytes.

You can find this information in the Microsoft Extensible Firmware Initiative FAT32 File System Specification, Version 1.03

  • 1 sector of 512 bytes for the BIOS Parameter Block (BPB). In the specification on page 8

The first important data structure on a FAT volume is called the BPB (BIOS Parameter Block), which is located in the first sector of the volume in the Reserved Region. This sector is sometimes called the “boot sector” or the “reserved sector” or the “0th sector,” but the important fact is simply that it is the first sector of the volume.

and on page 9 describing the BPB_BytsPerSec field in the BPB structure:

This value may take on only the following values: 512, 1024, 2048 or 4096.

  • 1 sector of 512 bytes for the File Allocation Table (FAT). On page 10 describing the BPB_NumFATs:

The count of FAT data structures on the volume. This field should always contain the value 2 for any FAT volume of any type. Although any value greater than or equal to 1 is perfectly valid

and BPB_FATSz16 field in the BPB structure:

This field is the FAT12/FAT16 16-bit count of sectors occupied by ONE FAT.

  • 2 sectors of 512 bytes each for the Root Directory Array. On page 9 describing BPB_RootEntCnt :

For FAT12 and FAT16 volumes, this field contains the count of 32-byte directory entries in the root directory. For FAT32 volumes, this field must be set to 0. For FAT12 and FAT16 volumes, this value should always specify a count that when multiplied by 32 results in an even multiple of BPB_BytsPerSec

The smallest possible value that fits that criteria is 32 since 32*32 = 1024 = smallest even multiple of 512 (smallest possible bytes per sector value)

  • 1 cluster = 1 sector of 512 bytes for the Data Region. One page 9 describing the BPB_SecPerClus field:

Number of sectors per allocation unit. This value must be a power of 2 that is greater than 0. The legal values are 1, 2, 4, 8, 16, 32, 64, and 128

That makes 5 sectors of 512 bytes each totaling 2560 bytes.

For further information I suggest you look at the Microsoft Extensible Firmware Initiative FAT32 File System Specification yourself.

I tested it too. Here you see the hexdump of the filesystem. I mounted the volume, created a file named "test" and saved it containing the ascii string "Hello, World!".

00000000: 0000 0054 4553 5420 2020 2000 0201 0100  ...TEST    .....
00000010: 0120 0005 00F8 0100 0000 0000 0000 0000  . ..............
00000020: 0000 0000 8000 29DA F34C 3C4E 4F20 4E41  ......)..L<NO NA
00000030: 4D45 2020 2020 4641 5431 3220 2020 0000  ME    FAT12   ..
00000040: 0000 0000 0000 0000 0000 0000 0000 0000  ................
*
000001b0: 0000 0000 0000 0000 EFBE ADDE 0000 8000  ................
000001c0: 0000 EE00 0000 0100 0000 0400 0000 0000  ................
000001d0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000001e0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
000001f0: 0000 0000 0000 0000 0000 0000 0000 55AA  ..............U.
00000200: F8FF FFFF 0F00 0000 0000 0000 0000 0000  ................
00000210: 0000 0000 0000 0000 0000 0000 0000 0000  ................
*
00000400: 4174 0065 0073 0074 0000 000F 0032 FFFF  At.e.s.t.....2..
00000410: FFFF FFFF FFFF FFFF FFFF 0000 FFFF FFFF  ................
00000420: 5445 5354 2020 2020 2020 2020 0040 6185  TEST        .@a.
00000430: CA58 CA58 0000 6185 CA58 0200 0E00 0000  .X.X..a..X......
00000440: 0000 0000 0000 0000 0000 0000 0000 0000  ................
*
00000800: 4865 6C6C 6F2C 2057 6F72 6C64 210A 0000  Hello, World!...
00000810: 0000 0000 0000 0000 0000 0000 0000 0000  ................
*
000009f0: 0000 0000 0000 0000 0000 0000 0000 0000  ................

You can reproduce the binary form with

echo "BCJNGGRAp7MAAAD4CQAAAFRFU1QgICAgAAIBAQABIAAFAPgBAAEA4IAAKdrzTDxOTyBOQU1FKwBQRkFUMTIzAAgnAA8CAP9bQO++rd6aAWAAAO4AAACwAR8EgAEgf1Wq+P///w86ACAPAgD/tvcAQXQAZQBzAHQAAAAPADL/AQAgAAANAAQdBAACAKAAQGGFyljKWAAACAA/AgAOBQL/tg8CAP/p70hlbGxvLCBXb3JsZCEKCQL/21AAAAAAAAAAAACW9XUG" | base64 -d | lz4 -d > smallest.fat
2

mkfs.vfat, if you limit it to one FAT (-f 1) and 16 root directory entries (-r 16), still insists on a minimum of 33792 bytes (66 sectors × 512 bytes), although it uses only 10 sectors for the filesystem (56 sectors remain for data).

The filesystem remains mountable if you truncate it to 10 sectors, although attempting to write to such a truncated fs will result in the filesystem driver complaining.

You might have some luck with adjusting the filesystem structures with a hex editor, to properly shrink it to around 11 sectors...

grawity
  • 501,077