FAT (File Allocation Table)

FAT12, FAT16 and FAT32 (with VFAT long names) are the simplest and most widely supported file systems: floppy disks, SD cards up to 32 GB, USB sticks, camera media and the UEFI system partition. Dating from 1977-1996, they remain ubiquitous for removable media, with FAT32 limited to 4 GiB files and replaced by exFAT on larger flash cards.

Overview

FAT divides the volume into clusters and tracks each cluster’s successor in a File Allocation Table, kept in two copies. A file is a chain of clusters starting from a number stored in a 32-byte directory entry. The three variants differ in table entry width (12, 16 or 28 usable bits of 32). FAT12 and FAT16 have a fixed root directory; FAT32 keeps the root in the data area and adds an FSInfo sector. Long file names are stored as extra UTF-16 directory entries (VFAT) alongside an 8.3 short name.

History

  • Created in 1977 by Bill Gates and Marc McDonald for Microsoft Standalone Disk BASIC; FAT12 shipped with MS-DOS and 86-DOS in 1980-81.
  • FAT16 arrived with MS-DOS 3.x/4.0 and larger disks; FAT32 was introduced with Windows 95 OSR2 in 1996.
  • VFAT long file names were added in Windows 95.

Structures

Offsets are in bytes from the start of the structure named in each heading. Field names are descriptive and are not an official specification. Fixed-width integers are shown as u/i (unsigned/signed) followed by bit width and byte order.

Read Fs Info Free Count

OffsetSizeTypeFieldNotes
0x04u32 LE–
0x1E44u32 LE–
0x1E84u32 LEFree

Build Entry

OffsetSizeTypeFieldNotes
0xB1u8Attributes
0xD1u8Created
0xE2u16 LECreated
0x102u16 LECreated
0x122u16 LEAccessed
0x142u16 LE–
0x162u16 LEModified
0x182u16 LEModified
0x1A2u16 LECluster
0x1C4u32 LESize

Entry Cluster

OffsetSizeTypeFieldNotes
position + 202u16 LE–
position + 262u16 LECluster

Enumerate Lost Entries

OffsetSizeTypeFieldNotes
0xD1u8Created
0xE2u16 LECreated
0x102u16 LECreated
0x162u16 LEModified
0x182u16 LEModified

Parse Entries

OffsetSizeTypeFieldNotes
position + 111u8Attributes
position + 121u8–
position + 262u16 LE–

Try Parse

OffsetSizeTypeFieldNotes
0x01u8–
0x38bytesOem Name
0xB2u16 LEBytes Per Sector
0xD1u8Sectors Per Cluster
0xE2u16 LEReserved
0x101u8Fats
0x112u16 LERoot Entries
0x132u16 LETotal
0x151u8Edia
0x162u16 LEFat Size
0x204u32 LETotal
0x244u32 LEFat Size
0x282u16 LEExtended Flags
0x2C4u32 LERoot Cluster
0x302u16 LEFs Info
0x322u16 LEBackup
0x1FE1u8Has Boot Signature
0x1FF1u8–
(extended + 3)4u32 LESerial
extended + 21u8–
extended + 711bytesLabel

Get

OffsetSizeTypeFieldNotes
(int)position2u16 LEBad Cluster
position + 11u8Value

Other fields read

Read inOffsetSizeTypeFieldNotes
Assemble Long Nameentry + offset + k * 22u16 LEUnit
Get(int)(position % PageSize)4u32 LE–

Constants

Fat File System

NameValueTypeNotes
EntrySize32int
FreeCountThreshold4 * 1024 * 1024uint
AttrReadOnly0x01byte
AttrHidden0x02byte
AttrSystem0x04byte
AttrVolumeLabel0x08byte
AttrDirectory0x10byte
AttrArchive0x20byte
AttrLongName0x0Fbyte
DeletedMarker0xE5byte

Fat Table

NameValueTypeNotes
PageSize64 * 1024int

Implementation limits

ClassNameValueNotes
Fat File SystemMaxDirectoryBytes4L * 1024 * 1024
Fat File SystemMaxDeletedDirectoryBytes2L * 1024 * 1024
Fat File SystemMaxLostFolders100_000
Fat File SystemMaxLongNameEntries20
Fat TableMaxCachedPages1024

Fat Type

NameValue
Fat12(next)
Fat16(next)
Fat32(next)

Signatures and magic strings referenced

TextWhere checked
. Enumerate Lost Entries
.. Enumerate Lost Entries
Structures and constants were extracted from the implementation. Prose sections are a summary from public sources; verify details before relying on them.