Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

File Allocation Table (FAT) file system format

The File Allocation Table (FAT) is widely used a file sytem and is the default file system for DOS and Windows.

There are multiple known variants or derivatives of FAT, such as:

  • (original) 8-bit FAT
  • FAT-12
  • FAT-16
  • FAT-32
  • exFAT

Overview

A FAT file system consists of:

  • One or more reserved sectors
    • a boot record (or boot sector)
    • file system informartion for FAT-32
  • One or more cluster block allocation tables
  • Root directory data for FAT-12 and FAT-16
  • File and directory data

Note that FAT-32 stores the root directory as part of the file and directory data.

Characteristics

CharacteristicsDescription
Byte orderlittle-endian
Date and time valuesFAT date and time
Character stringsA narrow character Single Byte Character (SBC) ASCII string

Terminology

TermDescription
Hidden sectorsThe sectors stored before the FAT volume, such as those used to store a parition table

Determing the FAT format version

To distinguish between FAT-12, FAT-16 and FAT-32, compute the number of clusters in the data area:

data_area_size = total_number_of_sectors - (number_of_reserved_sectors + (
    number_of_allocation_tables * allocation_table_size) + size_of_root_directory)
number_of_clusters = round down (data_area_size / sectors_per_cluster)
  • FAT-12 is used if the number of clusters is less than 4085
  • FAT-16 is used if the number of clusters is less than 65525
  • FAT-32 is used otherwise

Boot record

The boot record is stored in the first sector of the volume.

FAT-12 and FAT-16 boot record

The FAT-12 and FAT-16 boot record is at least 512 bytes in size and consists of:

OffsetSizeValueDescription
03"\xeb\x3c\x90"Boot entry point (JMP +62, NOP)
38File system signature (or OEM name)
112Bytes per sector, which must be 512, 1024, 2048 or 4096
131Sectors per cluster block, which must be 1, 2, 4, 8, 16, 32, 64 or 128
142Number of reserved sectors (reserved region), which starts at the first sector of the volume (sector 0) and must be 1 or more (typically 1 or 32)
161Number of cluster block allocation tables, which must be 1 or more (typically 2)
172Number of root directory entries
192Total number of sectors (16-bit)
211Media descriptor
222Cluster block allocation table size (16-bit) in number of sectors
242Number of sectors per track
262Number of heads
284Number of hidden sectors
324Total number of sectors (32-bit)
361Drive number
3710Unknown (reserved for Windows NT)
381Extended boot signature
If extended boot signature == 0x29
394Volume serial number, which can be derived from the system current date and time
4311Volume label, which contains a narrow character string or "NO\x20NAME\x20\x20\x20\x20" if not set
548"FAT12\x20\x20\x20" or "FAT16\x20\x20\x20"File system hint, which is informational and not required
If extended boot signature != 0x29
3923Unknown
Common
62448Used for boot code
5102"\x55\xaa"Sector signature

Note that the sector signature must be set at offset 512 but in addition can be set in the last 2 bytes of the sector.

FAT-32 boot record

The FAT-32 boot record is at least 512 bytes in size and consists of:

OffsetSizeValueDescription
03"\xeb\x58\x90"Boot entry point (JMP +90, NOP)
38File system signature (or OEM name)
112Bytes per sector, which must be 512, 1024, 2048 or 4096
131Sectors per cluster block, which must be 1, 2, 4, 8, 16, 32, 64 or 128
142Number of reserved sectors (reserved region), which starts at the first sector of the volume (sector 0) and must be 1 or more (typically 1 or 32)
161Number of cluster block allocation tables, which must be 1 or more (typically 2)
1720Number of root directory entries, which must be 0 for FAT-32
1920Total number of sectors (16-bit), which must be 0 for FAT-32
211Media descriptor
2220Cluster block allocation table size (16-bit) in number of sectors, which must be 0 for FAT-32
242Number of sectors per track
262Number of heads
284Number of hidden sectors
324Total number of sectors (32-bit)
364Cluster block allocation table size (32-bit) in number of sectors, which must be non 0 for FAT-32
402Extended flags
4210Format revision minor number
4310Format revision major number
444Root directory start cluster
482File system information (FSINFO) sector number
502Boot record sector number
52120Unknown (reserved)
641Drive number
6510Unknown (reserved for Windows NT)
661Extended boot signature
If extended boot signature == 0x29
674Volume serial number, which can be derived from the system current date and time
7111Volume label, which contains a narrow character string or "NO\x20NAME\x20\x20\x20\x20" if not set
828"FAT32\x20\x20\x20"File system hint, which is informational and not required
If extended boot signature != 0x29
6723Unknown
Common
90420Used for boot code
5102"\x55\xaa"Sector signature

Note that the sector signature must be set at offset 512 but in addition can be set in the last 2 bytes of the sector.

OEM names

ValueDescription
"MSWIN4.1"
"MSDOS 5.0"

Media descriptors

ValueIdentifierDescription
0xe5
0xed
0xee
0xef
0xf0removable media
0xf4
0xf5
0xf8fixed (non-removable) media
0xf9
0xfa
0xfb
0xfc
0xfd
0xfe
0xff

Cluster block allocation table

A cluster block allocation table consists of:

  • One ore more cluster block allocation table entries

FAT 12 cluster block allocation table entry

A FAT 12 cluster block allocation table entry is 12 bits in size and consists of:

OffsetSizeValueDescription
012 bitsData cluster number

Where the data cluster number has the following meanings:

Value(s)Description
0x000Unused (free) cluster
0x001Unknown (invalid)
0x002 - 0xfefUsed cluster
0xff0 - 0xff6Reserved
0xff7Bad cluster
0xff8 - 0xfffEnd of cluster chain

FAT 16 cluster block allocation table entry

A FAT 16 cluster block allocation table entry is 16 bits in size and consists of:

OffsetSizeValueDescription
016 bitsData cluster number

Where the data cluster number has the following meanings:

Value(s)Description
0x0000Unused (free) cluster
0x0001Unknown (invalid)
0x0002 - 0xffefUsed cluster
0xfff0 - 0xfff6Reserved
0xfff7Bad cluster
0xfff8 - 0xffffEnd of cluster chain

FAT 32 cluster block allocation table entry

A FAT 32 cluster block allocation table entry is 32 bits in size and consists of:

OffsetSizeValueDescription
032 bitsData cluster number

Note that only the lower 28-bits are used

Where the data cluster number has the following meanings:

Value(s)Description
0x00000000Unused (free) cluster
0x00000001Unknown (invalid)
0x00000002 - 0x0fffffefUsed cluster
0x0ffffff0 - 0x0ffffff6Reserved
0x0ffffff7Bad cluster
0x0ffffff8 - 0x0fffffffEnd of cluster chain
0x10000000 - 0xffffffffUnknown

Directory

A directory consists of:

  • self (“.”) directory entry (not used in root directory)
  • parent (“..”) directory entry (not used in root directory)
  • Zero or more directory entries
  • Terminator directory entry

Directory entry

Determining the root directory location

first_allocation_table_offset = number_of_reserved_sectors * bytes_per_sector

FAT-12 and FAT-16 root directory

root_directory_start_offset = first_allocation_table_offset + (
    number_of_allocation_tables * allocation_table_size * bytes_per_sector)
first_cluster_offset = directory_start_sector + (number_of_root_directory_entries * 32)

FAT-32 root directory

first_cluster_offset = first_allocation_table_sector + (
    number_of_allocation_tables * allocation_table_size * bytes_per_sector)
root_directory_start_offset = first_cluster_sector + (
    (root_directory_cluster - 2) * number_of_sectors_per_cluster)

FAT-12 and FAT-16 directory entry

A FAT-12 and FAT-16 directory entry is 32 bytes in size and consists of:

OffsetSizeValueDescription
08Name, which is padded with spaces and the first character can have a special meaning
83Extension, which is padded with spaces
111File attribute flags
121Flags
131Creation time fraction of seconds, which contains fraction of 2-seconds in 10 ms intervals
142Creation time
162Creation date
182Last access date
202Unknown (OS/2 extended attribute)
222Last modification time
242Last modification date
262Data stream start cluster
284Data stream data size

FAT-32 directory entry

A FAT-32 directory entry is 32 bytes in size and consists of:

OffsetSizeValueDescription
08Name, which is padded with spaces and the first character can have a special meaning
83Extension, which is padded with spaces
111File attribute flags
121Flags
131Creation time fraction of seconds, which contains fraction of 2-seconds in 10 ms intervals
142Creation time
162Creation date
182Last access date
202Data stream data size, which contains the upper 16-bit of the value
222Last modification time
242Last modification date
262Data stream start cluster, which contains the lower 16-bit of the value
284Data stream data size

Short (or 8.3) file name

A FAT short (or 8.3) file name is stored in an OEM character set (codepage). The first character can have a special meaning.

Valid FAT short file name characters are:

ValueDescription
'A-Z'Upper case character
'0-9'Numeric character
' 'Space, where trailing spaces are considered padding and therefore ignored
'.'Dot, with the exception of "." and "..", where trailing dot characters are ignored
'!'Exclamation mark
'#'Hash
'$'Dollar sign
'%'Percent sign
'&'Ampersand
'''Single quote
'('Left parenthesis
')'Right parenthesis
'-'Hyphen
'@'At sign
'^'Caret
'_'Underscore
'`'Grave accent
'{'Left curly brace
'}'Right curly brace
'~'Tilde
0x80 - 0xffExtended ASCII character, which are codepage dependent

Note that other characters such as plus sign (‘+’) have been observed in FAT short file names.

First character

ValueDescription
0x00Last (or terminator) directory entry
0x01 - 0x13VFAT long file name directory entry
0x05Directory entry pending deallocation (deprecated since DOS 3.0) or substitution of a 0xe5 value
0x41 - 0x54Last VFAT long file name directory entry
0xe5Unallocated directory entry

File attribute flags

ValueDescription
0x01Read-only
0x02Hidden
0x04System
0x08Is volume label
0x10Is directory
0x20Archive
0x40Is device
0x80Unused (reserved)

Flags

ValueDescription
0x01Data is EFS encrypted
0x02Data contains large EFS header
0x08Name should be represented in lower case
0x10Extension should be represented in lower case

VFAT long file name entry

VFAT long file names entries are stored in directory entries. Multiple VFAT long file name entries can be used to store a single long file name, where the highest (last) sequence number is stored first. A maximum of 20 VFAT long file name entries can be used to store a long file name of 255 UCS-2 characters.

VFAT long file names are stored using UCS-2 little-endian, which allows for unpaired Unicode surrogates such as “U+d800” and “U+dc00”

VFAT long file name entries are stored before the directory entry containing the short file name and additional file entry information.

A VFAT long file name entry is 32 bytes in size and consists of:

OffsetSizeValueDescription
01Sequence number
110First name segment string, which contains 5 UCS-2 string characters
1110x0fUnknown (attributes)
1210x00Unknown (type)
131Checksum of the short (8.3) file name
1412Second name segment string, which contains 6 UCS-2 string characters
2620Unknown (first cluster)
284Third name segment string, which contains 2 UCS-2 string characters

Note that unused characters in the VFAT long file segment strings after the end-of-string character (0x0000) are padded with 0xffff.

VFAT long file name sequence number

OffsetSizeValueDescription
05 bitsNumber
0.51 bit0Unknown (reserved)
0.61 bit0Unknown (last logical, first physical LFN entry)
0.71 bit0Unknown

References