Developer | Microsoft, SCP, IBM, Compaq, Digital Research |
---|---|
Full name | File Allocation Table: FAT12 (12-bit version), FAT16/FAT16B/FAT16X (16-bit versions), FAT32/FAT32X (32-bit version with 28 bits used) |
Introduced | FAT12: August 1980 (QDOS) FAT16: August 1984 (IBM PC DOS 3.0) FAT16B: November 1987 (Compaq MS-DOS 3.31) FAT16X: August 1995 (Windows 95) FAT32/FAT32X: August 1996 (Windows 95 OSR2) |
Partition identifier | MBR/EBR: FAT12: 0x01 H:0x11/0x8D S:0xC1/0xD1 FAT16: 0x04 H:0x14/0x90 S:0xC4/0xD4 FAT16B: 0x06 H:0x16/0x92 S:0xC6/0xD6 FAT16X: 0x0E H:0x1E/0x9A S:0xCE FAT32: 0x0B H:0x1B/0x97 S:0xCB FAT32X: 0x0C H:0x1C/0x98 S:0xCC Logical sectored FAT12/FAT16: 0x08 0x11 0x14 0x24 0x56 0xE5 0xF2 BDP: EBD0A0A2-B9E5-4433-87C0-68B6B72699C7 |
Structures | |
Directory contents | Table |
File allocation | Linked list |
Bad blocks | Cluster tagging |
Limits | |
Max file size | 4,294,967,295 bytes (4 GB - 1)[1] |
Max number of files | FAT12: 4,068 for 8 KB clusters FAT16: 65,460 for 32 KB clusters FAT32: 268,173,300 for 32 KB clusters |
Max filename length | 8.3 filename, or 255 UTF-16 characters when using LFN |
Max volume size | FAT12: 32 MB (256 MB for 64 KB clusters) FAT16: 2 GB (4 GB for 64 KB clusters) FAT32: 2 TB (16 TB for 4 KB sectors) |
Features | |
Dates recorded | Modified date/time, creation date/time (DOS 7.0 and higher only), access date (only available with ACCDATE enabled),[2] deletion date/time (only with DELWATCH 2) |
Date range | 1980-01-01 to 2107-12-31 |
Date resolution | 2 seconds for last modified time, 10 ms for creation time, 1 day for access date |
Forks | Not natively |
Attributes | Read-only, Hidden, System, Volume, Directory, Archive |
File system permissions | FAT12/FAT16: Global/Directory/File-based passwords for Read, Write, Delete, Execute access rights only with DR-DOS, FlexOS, PalmDOS, Novell DOS, OpenDOS, Multiuser DOS and REAL/32 (Execute only with FlexOS), World/Group/Owner file permissions only with multiuser security FAT32: Partial, only with DR-DOS and REAL/32 |
Transparent compression | FAT12/FAT16: Per-volume, SuperStor, Stacker, DoubleSpace, DriveSpace FAT32: No |
Transparent encryption | FAT12/FAT16: Per-volume only with DR-DOS FAT32: No |
File Allocation Table (FAT) is the name of a computer file system architecture and a family of industry standard file systems utilizing it.
The FAT file system is technically relatively simple yet robust. It offers reasonably good performance even in light-weight implementations and is therefore widely adopted and supported by virtually all existing operating systems for personal computers. This makes it a well-suited format for data exchange between computers and devices of most any type and age from the early 1980s up to the present.
Originally designed in the late 1970s for use on floppy disks, it was soon adapted and used almost universally on hard disks throughout the DOS and Windows 9x eras for two decades. With the introduction of more powerful computers and operating systems its use on hard drives has since started to decline, but it continues to be used on many computer systems.
Today, FAT file systems are still commonly found on floppy disks, solid-state memory cards, flash memory cards, and on many portable and embedded devices.
The name of the file system originates from the file system's prominent usage of an index table, the FAT, statically allocated at the time of formatting. The FAT represents a map of so called clusters, individually allocatable blocks of one or more contiguous logical sectors into which the volume's storage area is equally divided by the number of FAT entries. Ascending cluster numbers address logically subsequent blocks of storage space on the volume, while the cluster number also works as an index into the FAT at the same time. Very low and very high cluster numbers are reserved to mark free, special purpose, defective or otherwise unusable areas of the volume's image in the map. The remaining cluster values correspond with allocatable blocks. Files and directories are organized in cluster chains, where allocated clusters are indicated by a non-zero value in the corresponding entry in the FAT. If a file spawns over more than one cluster, the corresponding entry in the FAT works as pointer to the next used cluster in the chain, whereas any reserved value indicates the end of a file's cluster chain.
As disk drives have evolved, the maximum number of clusters has significantly increased, and so the number of bits used to identify each cluster has grown. The successive major versions of the FAT format are named after the number of table element bits: 12 (FAT12), 16 (FAT16), and 32 (FAT32). Each of these variants is still in use. The FAT standard has also been expanded in other ways while generally preserving backward compatibility with existing software.
Contents |
The FAT file system is technically simple yet robust. It offers reasonable performance even in light-weight implementations and is therefore widely adopted and supported by virtually all existing operating systems for personal computers. This makes it a useful format for solid-state memory cards and a convenient way to share data between operating systems.
FAT file systems are commonly found on floppy disks, memory cards, flash memory cards and are supported by most portable devices such as PDAs, digital cameras, camcorders, media players, or mobile phones.
FAT was also commonly used on hard disks throughout the DOS and Windows 9x eras, but its use on hard drives has declined since the introduction of Windows XP, which primarily uses the newer NTFS. FAT is still used in hard drives expected to be used both in Windows and Linux environments.
Due to its long history of usage on desktops and portable computers meanwhile spanning over more than three decades and its frequent use in embedded solutions, the FAT filesystem is still the most widespread filesystem worldwide.
For floppy disks, the FAT has been standardized as ECMA-107[3] and ISO/IEC 9293.[4] These standards cover FAT12 and FAT16 with only short 8.3 filename support; long filenames with VFAT are partially patented.[5]
Designed and coded by Marc McDonald, Microsoft Stand-alone Disk BASIC introduced the FAT in 1977 with 8-bit table elements, produced for NCR's 8-bit 8080 file system. The FAT, born during one of a series of discussions between McDonald and Bill Gates, was used in a stand-alone version of Microsoft BASIC for the 8086 chip in 1979 and eventually in the M-DOS operating system. The Microsoft BASIC version supported three FATs.
In 1980, while borrowing Microsoft's FAT concept for Seattle Computer Products' 86-DOS, Tim Paterson extended the table elements to 12 bits for his implementation of FAT12, whereas the 8-bit file system precursor was not supported by 86-DOS. 86-DOS supported 8-inch floppy drives and later evolved into MS-DOS/PC DOS.[6][7][8]
IBM PC DOS 1.0, released with the original IBM Personal Computer in 1981, supported single-sided 5.25-inch floppy drives (media ID 0xFE and 0xFC), and PC DOS 1.1 added double-sided support (0xFF and 0xFD). Neither of these versions had a BIOS Parameter Block (BPB). The BPB was introduced in PC DOS 2.0. PC DOS 1.0 directory entries included only one date, the last modified date. PC DOS 1.1 added the last modified time. PC DOS 1.x file attributes included a hidden bit and system bit, with the remaining six bits undefined. PC DOS 2.0 added read-only, volume label, subdirectory and archive attribute bits.
Designed as a file system for floppy disks, FAT12 limited cluster addresses to 12-bit values, which not only limited the cluster count to 4084,[3][9][10] but made FAT manipulation tricky with the PC's 8-bit and 16-bit registers. (The literature also mentions a limit 4078.[11][12]) The disk's size is stored as a 16-bit count of sectors, which limited the size to 32 MB. FAT12 was used by several manufacturers with different physical formats, but a typical floppy disk at the time was 5.25-inch, single-sided, 40 tracks, with 8 sectors per track, resulting in a capacity of 160 KB for both the system areas and files. The FAT12 limitations exceeded this capacity by a factor of ten or more.
By convention, all the control structures were organized to fit inside the first track, thus avoiding head movement during read and write operations, although this varied depending on the manufacturer and physical format of the disk. At the time FAT12 was introduced, DOS did not support hierarchical directories, and the maximum number of files was typically limited to a few dozen. Hierarchical directories were introduced in MS-DOS version 2.0.[13]
A limitation which was not addressed until much later was that any bad sector in the control structures area, track 0, could prevent the disk from being usable. The DOS formatting tool rejected such disks completely. Bad sectors were allowed only in the file area, where they made the entire containing cluster unusable. FAT12 remains in use on all common floppy disks, including 1.44 MB and later 2.88 MB disks.
The PC XT was the first PC with a hard drive from IBM, and MS-DOS 2.0 supported that hard drive with FAT12.
In 1984, IBM released the PC AT, which featured a 20 MB hard disk. Microsoft introduced MS-DOS 3.0 in parallel. Cluster addresses were increased to 16-bit, allowing for up to 65,524 clusters per volume, and consequently much greater file system sizes, at least in theory. However, the maximum possible number of sectors and the maximum (partition, rather than disk) size of 32 MB did not change. Therefore, although cluster addresses were 16 bits, this format was not what today is commonly understood as FAT16. A partition type hex. 04
indicates this form of FAT16 with less than 65536 sectors (less than 32 MB for sector size 512).
With the initial implementation of FAT16 not actually providing for larger partition sizes than FAT12, the early benefit of FAT16 was to enable the use of smaller clusters, making disk usage more efficient, particularly for files several hundred bytes in size, which were far more common at the time.
MS-DOS 2.x hard disks larger than 15 MB are incompatible with later versions of MS-DOS.[14] A 20 MB hard disk formatted under MS-DOS 3.0 was not accessible by the older MS-DOS 2.0 because MS-DOS 2.0 did not support version 3.0's FAT16. MS-DOS 3.0 could still access MS-DOS 2.0 style 8 KB-cluster partitions under 15 MB. MS-DOS 3.0 also introduced support for high-density 1.2 MB 5.25" diskettes, which notably had 15 sectors per track, hence more space for the FATs.
When harddisks grew larger and the FAT12 and FAT16 filesystem implementation in MS-DOS / PC DOS did not provided means to take advantage of the extra storage, several manufacturers developed their own FAT variants to address the problem in their MS-DOS OEM issues.
Some vendors (AST and NEC) supported eight instead of the standard four primary partition entries in their custom extended Master Boot Record (MBR) and adapted MS-DOS to use more than a single primary partition.
Other vendors worked around the volume size limits imposed by the 16-bit sector entries and arithmetics by increasing the size of the sectors the filesystem dealt with, thereby blowing up dimensions.
These so called logical sectors were larger (up to 8192 bytes) than the physical sector size (still typically 512 bytes) as expected by the ROM-BIOS INT 13h or the disk drive hardware. The DOS-BIOS or System BIOS would then combine multiple physical sectors into logical sectors for the filesystem to work with. These changes were transparent to the filesystem implementation in the DOS kernel, since on this abstraction level volumes had always been a series of logically addressable sectors (starting with logical sector 0) independent of the physical location of the volume on the physical medium and its geometry. The underlying DOS-BIOS translated these logical sectors into physical sectors according to partitioning information and the drive's physical geometry.
The drawback of this approach was a less memory-efficient sector buffering and deblocking in the DOS-BIOS thereby causing a significantly increased memory consumption of the DOS data structures. Since older DOS versions were not flexible enough to work with these logical geometries, the OEMs had to introduce new partition IDs for their FAT variants in order to hide them from off-the-shelf issues of MS-DOS and PC DOS. Known partition IDs for logical sectored FATs include: 0x08 (Commodore MS-DOS 3.x), 0x11 (Leading Edge MS-DOS 3.x), 0x14 (AST MS-DOS 3.x), 0x24 (NEC MS-DOS 3.30), 0x56 (AT&T MS-DOS 3.x), 0xE5 (Tandy MS-DOS), 0xF2 (Sperry IT MS-DOS 3.x, Unisys MS-DOS 3.3 — also used by Digital Research DOS Plus 2.1).
While non-standard and sub-optimal these FAT variants are perfectly valid according to the specifications of the filesystem. Therefore, even if default issues of MS-DOS and PC DOS were not able to cope with them, most of these vendor specific FAT12 and FAT16 variants can be mounted by more flexible filesystem implementations in operating systems such as DR-DOS simply by changing the partition ID to one of the recognized types. Also, if they no longer need to be recognized by their original operating systems, existing partitions can be "converted" into FAT12 and FAT16 volumes more compliant with newer versions of MS-DOS/PC DOS 5.0, which don't support sector sizes different from 512 bytes, by switching to a BPB with 32-bit entry for the number of sectors, as introduced since DOS 3.31 (see below), keeping the cluster size and reducing the logical sector size in the BPB down to 512 bytes while at the same time blowing up the other parameters accordingly.
Apart from improving the structure of the FAT file system itself, a parallel development allowing an increase in the maximum possible FAT size was the introduction of multiple FAT partitions on a hard disk. To allow the use of more FAT partitions in a compatible way, a new partition type was introduced (in MS-DOS 3.2, January 1986), the extended partition (EBR), which is a container for an additional partition called logical drive and optionally another extended partition containing the next logical drive, and so on. The MBR of a hard disk can either define up to four primary partitions, or an extended partition in addition to up to three primary partitions.
Finally in November 1987, Compaq MS-DOS 3.31 (an modified OEM version of MS-DOS 3.3 released by Compaq with their machines) introduced what today is simply known as the FAT16 format, with the expansion of the 16-bit disk sector count to 32 bits in the BPB. Although the on-disk changes were minor, the entire DOS disk driver had to be converted to use 32-bit sector numbers, a task complicated by the fact that it was written in 16-bit assembly language. The result was initially called the DOS 3.31 Large File System. Microsoft's dskprobe
tool refers to type 06
as BigFAT,[15] whereas some older versions of FDISK described it as BIGDOS. It is also known as FAT16B.
Since older versions of DOS could not cope with more than 65535 sectors, it was also necessary to introduce a new partition type for this format in order to hide it from pre-DOS 3.31 issues of DOS. While the original form of FAT16 with less than 65536 sectors had a partition type hex. 04
, a type 06
indicates 65536 or more sectors. In addition to this changed partition ID and the expansion of the disk drivers format to cope with more than 65535, the only other difference between the original FAT16 and the FAT16B format is the usage of the newer BPB with 32-bit sector entry, so that newer operating systems can cope also with the original FAT16 format without any necessary changes. If partitions to be used by pre-DOS 3.31 issues of DOS need to be created by modern tools, the only criteria theoretically necessary to meet are a sector count of less than 65536 and the usage of the old partition ID. In practice, however, type 0x01 and 0x04 partitions should not be physically located outside the first 32 MB of the disk due to other restrictions in MS-DOS 2.x, which could not cope with them otherwise.
In 1988 the FAT16B improvement became more generally available through DR DOS 3.31, MS-DOS 4.0 and OS/2 1.1. The limit on partition size was dictated by the 8-bit signed count of sectors per cluster, which originally had a maximum power-of-two value of 64. With the standard hard disk sector size of 512 bytes, this gives a maximum of 32 KB clusters, thereby fixing the "definitive" limit for the FAT16 partition size at 2 GB for sector size 512. On magneto-optical media, which can have 1 or 2 KB sectors instead of 0.5 KB, this size limit is proportionally larger.
Much later, Windows NT increased the maximum cluster size to 64 KB by considering the sectors-per-cluster count as unsigned. However, the resulting format was not compatible with any other FAT implementation of the time, and it generated greater internal fragmentation. Windows 98, SE and ME also supported reading and writing this variant, but its disk utilities did not work with it and some FCB services are not available for such volumes. This contributes to a confusing compatibility situation.
Prior to 1995 versions of DOS accessed the disk via CHS addressing only. When MS-DOS 7.0 / Windows 95 introduced LBA disk access, partitions could start being physically located outside the first ca. 8 GB of this disk and thereby out of the reach of the traditional CHS addressing scheme. Partitions partially or fully located beyond the CHS barrier therefore had to be hidded from non-LBA-enabled operating systems by using the new partion type hex. 0E
in the partition table instead. FAT16 partitions using this partition type are also named FAT16X. The only difference compared to previous FAT16 partitions is the fact that some CHS-related geometry entries in the BPB record, namely the number of sectors per track and the number of heads, may contain no or misleading values and should not be used.
The number of root directory entries available for FAT12 and FAT16 is determined when the volume is formatted, and is stored in a 16-bit field. For a given number RDE
and sector size SS
the number RDS
of root directory sectors is RDS=ceil((RDE×32)/SS)
, and RDE
is normally chosen to fill these sectors, i.e., RDE*32=RDS*SS
. FAT12 and FAT16 media typically use 512 root directory entries on non-floppy media.[16] Some third-party tools like mkdosfs allow the user to set this parameter.[17]
One of the user experience goals for the designers of Windows 95 was the ability to use long filenames (LFNs—up to 255 UTF-16 code points long), in addition to classic 8.3 filenames. For backward compatibility LFNs were implemented as an optional extension on top of the existing FAT file system structures using a workaround in the way directory entries are laid out (see below).
This transparent method to store long file names in the existing FAT file systems without altering their data structures is usually known as VFAT (for "Virtual FAT") after the Windows 95 virtual device driver. (A driver named VFAT appeared before Windows 95, in Windows for Workgroups 3.11, but this older version was only used for implementing 32-bit file access and did not support long file names.)
In Windows NT, support for VFAT long filenames started from version 3.5.
Non VFAT-enabled operating systems can still access the files under their short file name alias without restrictions, however, the associated long file names may get lost, when files with long file names are copied under non VFAT-aware operating systems.
OS/2 added long filename support to FAT using extended attributes (EA) before the introduction of VFAT; thus, VFAT long filenames are invisible to OS/2, and EA long filenames are invisible to Windows.
In order to overcome the size limit of FAT16, while at the same time allowing DOS real mode code to handle the format, and without reducing available conventional memory unnecessarily, Microsoft expanded the cluster size yet again, calling the new revision FAT32. Cluster values are represented by 32-bit numbers, of which 28 bits are used to hold the cluster number. The boot sector uses a 32-bit field for the sector count, limiting the FAT32 volume size to 2 TB for sector size of 512 bytes and 16 TB for sector size of 4,096 bytes.[18][19]
FAT32 was introduced with MS-DOS 7.1 / Windows 95 OSR2, although reformatting was needed to use it, and DriveSpace 3 (the version that came with Windows 95 OSR2 and Windows 98) never supported it. Windows 98 introduced a utility to convert existing hard disks from FAT16 to FAT32 without loss of data. In the NT line, native support for FAT32 arrived in Windows 2000. A free FAT32 driver for Windows NT 4.0 was available from Winternals, a company later acquired by Microsoft. Since the acquisition the driver is no longer officially available. The first version of DR-DOS to natively support FAT32 and LBA access was OEM DR-DOS 7.04 in 1999. Since 1998, the dynamically loadable DRFAT32 driver could be used to enable FAT32 support in older issues down to 3.31. PC DOS introduced native FAT32 support with OEM PC DOS 7.10 in 2003.
The maximum possible size for a file on a FAT32 volume is 4 GB minus 1 byte or 4 294 967 295 (232−1) bytes. This limit is a consequence of the file length entry in the directory table and would also affect huge FAT16 partitions with a sufficient sector size.[1] Video applications, large databases, and some other software easily exceed this limit. Larger files require another filesystem.
As with previous filesystems, the design of the FAT32 filesystem does not include direct built-in support for long filenames, but FAT32 volumes can optionally hold VFAT long filenames in addition to short filenames in exactly the same way as VFAT long filenames have been optionally implemented for FAT12 and FAT16 volumes.
Two partition types have been reserved for FAT32 partitions, hex. 0B
and 0C
. The latter type is also named FAT32X in order to indicate usage of LBA disk access instead of CHS. On such partitions, some CHS-related geometry entries in the EBPB record, namely the number of sectors per track and the number of heads, may contain no or misleading values and should not be used.
For most purposes, the NTFS file system is superior to FAT in terms of features and reliability; its main drawbacks are the size overhead for small volumes and the very limited support by anything other than the NT-based versions of Windows, since the exact specification is a trade secret of Microsoft. The availability of NTFS-3G since mid 2006 has led to much improved NTFS support in Unix-like operating systems, considerably alleviating this concern. It is still not possible to use NTFS in DOS-like operating systems without third-party drivers, which in turn makes it difficult to use a DOS floppy for recovery purposes. Microsoft provided a recovery console to work around this issue, but for security reasons it severely limited what could be done through the Recovery Console by default. The movement of recovery utilities to boot CDs based on BartPE or Linux (with NTFS-3G) is finally eroding this drawback.
FAT is still the normal file system for removable media (with the exception of CDs and DVDs), with FAT12 used on floppies, and FAT16 or FAT32 on most other removable media (such as flash memory cards for digital cameras and USB flash drives).
FATX is a slightly modified version of the FAT filesystem, and is designed for Microsoft's Xbox video game console hard disk drive and memory cards.[20][21] On-disk datestamps differ slightly between FAT and FATX: in FAT, the epoch is 1980; in FATX, the epoch is 2000. On the Xbox 360, the epoch is 1980.[22]
exFAT is an incompatible, proprietary and patent protected replacement for FAT file systems that was introduced with Windows Embedded CE 6.0. The MBR partition type is 0x07 (the same as for IFS, HPFS, NTFS, etc.). exFAT is intended to be used on flash drives (such as SDXC and Memory Stick XC), where FAT is used today. It offers little practical benefits over FAT32 for volumes smaller than 2 TB and file sizes between 64 KB and 4 GB, but makes data exchange more difficult, since many existing operating systems do not technically or cannot legally support exFAT.
Contents | Boot Sector | FS Information Sector (FAT32 only) | More reserved sectors (optional) | File Allocation Table #1 | File Allocation Table #2 | Root Directory (FAT12/FAT16 only) | Data Region (for files and directories) ... (To end of partition or disk) |
---|---|---|---|---|---|---|---|
Size in sectors | (number of reserved sectors) | (number of FATs) * (sectors per FAT) | (number of root entries*32) / (bytes per sector) | (number of clusters) * (sectors per cluster) |
A FAT file system is composed of four different sections.
FAT uses little endian format for entries in the header and the FAT(s). It is possible to allocate more FAT sectors than necessary for the number of clusters. The end of the last FAT sector can be unused if there are no corresponding clusters. The total number of sectors (as noted in the boot record) can be larger than the number of sectors used by data (clusters × sectors per cluster), FATs (number of FATs × sectors per FAT), and hidden sectors including the boot sector: this would result in unused sectors at the end of the volume. If a partition contains more sectors than the total number of sectors occupied by the file system it would also result in unused sectors at the end of the volume.
On non-partitioned devices, e.g., floppy disks, the Boot Sector (VBR) is the first sector. For partitioned devices such as hard drives, the first sector is the Master Boot Record defining partitions, while the first sector of partitions formatted with a FAT file system is again the Boot Sector.
Common structure of the first 11 bytes used by most FAT versions for IBM compatible x86-machines since DOS 2.0 are:
Byte Offset | Length (bytes) | Description |
---|---|---|
0x00 | 3 | Jump instruction. If the boot sector has a valid signature residing in the last two bytes of the boot sector (tested by most boot loaders residing in the System BIOS or the MBR), this instruction will be executed and will skip past the rest of the (non-executable) header if the partition is booted from. See Volume Boot Record.
Valid x86-bootable disks must start with either a short jump followed by a NOP ( |
0x03 | 8 | OEM Name (padded with spaces 0x20). This value determines in which system the disk was formatted. MS-DOS/PC DOS (since 3.0), Windows 95/98/SE/ME and OS/2 check this field to determine which other parts of the boot record can be relied on and how to interpret them. Setting the OEM label to arbitrary or bogus values may cause MS-DOS, PC DOS and OS/2 to not recognize the volume properly and cause data corruption on writes.[23][24] Common examples are IBM␠␠3.3 , MSDOS5.0 , MSWIN4.1 , mkdosfs␠ , and FreeDOS␠ . Some vendors store licensing info or access keys in this entry. The Volume Tracker in Windows 95/98/SE/ME will overwrite the OEM label with ?????IHC signatures (a left-over from ␠OGACIHC for "Chicago") even on a seemingly read-only disk access (such as "DIR A:") if the medium is not write-protected. Given the dependency on certain values explained above, this may, depending on the BPB format used, cause MS-DOS/PC DOS, Windows 95/98/SE/ME and OS/2 to no longer recognize the medium and throwing error messages despite the fact that the medium is not actually defective and can still be read on other operating systems.[25] |
0x0B | varies | BIOS Parameter Block (13, 19, 21 or 25 bytes), Extended BIOS Parameter Block (32 or 51 bytes) or FAT32 Extended BIOS Parameter Block (79 bytes); size and contents varies between operating systems and versions, see below |
varies | varies | File system and operating system specific boot code; often starts immediately behind [E]BPB, but sometimes additional "private" boot loader data is stored between the end of the [E]BPB and the start of the boot code. |
0x1FE | 2 | Boot sector signature; 0x55 0xAA .[9] This signature indicates an IBM PC compatible boot code and is tested by most boot loaders residing in the System BIOS or the MBR before passing execution to the boot sector's boot code. Since this signature is not present on all FAT-formatted disks (f.e. not on old or non-x86-bootable disks), operating systems must not rely on this signature to be present when logging in volumes (MS-DOS, PC DOS and DR-DOS do not).
This signature must be located at fixed sector offset 0x1FE for sector sizes 512 or higher. If the physical sector size is larger, it may be repeated at the end of the physical sector. Ataris will assume a disk to be Atari 68000 bootable if the checksum over the whole 512-bytes boot sector equals 0x1234. If the boot loader code is IBM compatible, it is important to ensure that the checksum over the boot sector does not match this magic value by accident. If this would happen to be the case, changing an unused bit (f.e. before or after the boot code area) can be used to ensure this condition is not met. |
FAT-formatted Atari floppies have a very similar boot sector layout:
Byte Offset | Length (bytes) | Description |
---|---|---|
0x00 | 2 | Jump instruction. Original Atari boot sectors start with a 68000 BRA.S instruction 60 xx hex. For compatibility with PC operating systems, Atari formatted disks since TOS 1.4 start with E9 xx hex. instead. |
0x02 | 6 | OEM Name (padded with spaces 0x20), e.g. "Loader" on volumes containing an Atari boot loader. See OEM Name precautions for PC formatted disks above. Note the different offset and length of this entry compared to the entry on PC formatted disks. |
0x08 | 3 | Disk serial number, used by Ataris to detect a disk change. (Windows 9x Volume Tracker will always store "IHC" here on non-write-protected floppy disks; see above.) This value must be changed if the disk contents is externally changed, otherwise Ataris may not recognize the change on re-insertion. This entry overlaps the OEM Name field on PC formatted disks. For maximum compatibility, it may be necessary to match certain patterns here; see above. |
0x0B | 19 | DOS 3.0 BIOS Parameter Block |
0x1E | varies | Private boot sector data |
varies | varies | File system and operating system specific Atari boot code. No assumptions must be made in regard to the load position of the code, which must be relocatable. If the loading of an operating system fails, the code can return to the Atari XIOS with an 68000 RTS (opcode 0x4E75) instruction and all registers unaltered. |
0x1FE | 2 | Checksum. The 16-bit checksum over the whole 512-bytes boot sector including this word must match the magic value 0x1234 in order to indicate an Atari 68000 executable boot sector code. This checksum entry can be used to align the checksum accordingly. If the logical sector size is larger than 512 bytes, the remainder is not included in the checksum and is typically zero-filled. Since some PC operating systems erroneously do not accept FAT formatted floppies if the 55 AA signature is not present here, it is advisable to place the 55 AA here (and add a IBM compatible boot loader or stub) and use an unused word in the private data or the boot code area or the serial number in order to ensure that the checksum 0x1234 is either matched (if actually Atari bootable) or not matched. |
Common structure of the first 25 bytes of the BIOS Parameter Block (BPB) used by FAT versions since DOS 2.0 are (bytes at sector offset 0x0B to 0x17 are stored since DOS 2.0, but not always used before DOS 3.2, values at 0x18 to 0x1B are used since DOS 3.0):
Sector Offset | BPB Offset | Length (bytes) | Description |
---|---|---|---|
0x0B | 0x00 | 2 | Bytes per logical sector in powers of two; the most common value is 512. Some OSes don't support other sector sizes. For simplicity and maximum performance, the logical sector size is often identical to a disk's physical sector size, but can be larger or smaller in some scenarios. The minimum allowed value for non-bootable FAT12/FAT16 volumes with up to 65535 logical sectors is 32 bytes, or 64 bytes for more than 65534 logical sectors. The minimum practical value is 128. Some pre-DOS 3.31 OEM versions of DOS used logical sector sizes up to 8192 bytes for logical sectored FATs. Atari GEMDOS supports logical sector sizes between 512 and 4096.
Floppy drives and controllers use physical sector sizes of 128 bytes, 256 bytes, 512 bytes and 1024 bytes. Some magneto-optical drives used sector sizes of 1024 and 2048 bytes. In 2005 some hard disks used sector sizes of 1024 bytes instead of the default 512 bytes.[26] Advanced Format hard disks use 4096 bytes per sector since 2010, but will also be able to emulate 512 byte sectors for a transitional period. |
0x0D | 0x02 | 1 | Logical sectors per cluster. Allowed values are powers of two from 1 to 128. MS-DOS/PC DOS and Windows 95 support a maximum cluster size of 32 KB only. Windows 98/SE/ME partially support a cluster size of 64 KB as well, but some FCB services are not available on such disks and various applications fail to work. The Windows NT family and some alternative DOS versions fully support 64 KB clusters. For DOS-based operating systems, the maximum cluster size remains at 32 KB or 64 KB even for sector sizes larger than 512 bytes. |
0x0E | 0x03 | 2 | Reserved logical sector count. The number of logical sectors before the first FAT in the file system image. At least 1 for this sector, usually 32 for FAT32. |
0x10 | 0x05 | 1 | Number of file allocation tables. Almost always 2; RAM disks might use 1. Most versions of MS-DOS/PC DOS do not support more than 2 FATs. |
0x11 | 0x06 | 2 | Maximum number of FAT12 or FAT16 root directory entries. 0 for FAT32, where the root directory is stored in ordinary data clusters. |
0x13 | 0x08 | 2 | Total logical sectors (if zero, use 4 byte value at offset 0x20) |
0x15 | 0x0A | 1 | Media descriptor:[27]
This value must reflect the media descriptor stored (in the entry for cluster 0) in the first byte of each copy of the FAT. Certain operating systems before DOS 3.2 (86-DOS, MS-DOS/PC DOS 1.x and MSX-DOS version 1.0) ignore the boot sector parameters altogether and use the media descriptor value from the first byte of the FAT to choose among internally pre-defined parameter templates. On removable drives, DR-DOS will assume the presence of a BPB if this value is >= 0xF0, whereas for fixed disks, it must be 0xF8 to assume the presence of a BPB. |
0x16 | 0x0B | 2 | Logical sectors per File Allocation Table for FAT12/FAT16, 0 for FAT32 (cf. offset 0x24 below) |
DOS 3.0 BPB:
Sector Offset | BPB Offset | Length (bytes) | Description |
---|---|---|---|
0x0B | 0x00 | 13 | DOS 2.0 BPB; see above |
0x18 | 0x0D | 2 | Sectors per track for disks with CHS geometry,[9] e.g., 15 for a 1.20 MB floppy. |
0x1A | 0x0F | 2 | Number of heads for disks with CHS geometry,[9] e.g., 2 for a double sided floppy. |
0x1C | 0x11 | 2 | Count of hidden sectors preceding the partition that contains this FAT volume. This field should always be zero on media that are not partitioned. This DOS 3.0 entry is incompatible with BPBs since DOS 3.31. |
DOS 3.2 BPB:
Sector Offset | BPB Offset | Length (bytes) | Description |
---|---|---|---|
0x0B | 0x00 | 19 | DOS 3.0 BPB; see above |
0x1E | 0x13 | 2 | Total logical sectors including hidden sectors. This DOS 3.2 entry is incompatible with BPBs since DOS 3.31. |
DOS 3.31 BPB:
Sector Offset | BPB Offset | Length (bytes) | Description |
---|---|---|---|
0x0B | 0x00 | 13 | DOS 2.0 BPB; see above |
0x18 | 0x0D | 2 | Sectors per track for disks with CHS geometry,[9] e.g., 18 for a 1.44 MB floppy. Unused for drives, which don't support CHS access any more. |
0x1A | 0x0F | 2 | Number of heads for disks with CHS geometry,[9] e.g., 2 for a double sided floppy. Unused for drives, which don't support CHS access any more. |
0x1C | 0x11 | 4 | Count of hidden sectors preceding the partition that contains this FAT volume. This field should always be zero on media that are not partitioned. This DOS 3.31 entry is incompatible with a similar entry in DOS 3.0-3.3 BPBs. |
0x20 | 0x15 | 4 | Total logical sectors (if greater than 65535; otherwise, see offset 0x13). This DOS 3.31 entry is incompatible with a similar entry at offset 0x1E in DOS 3.2-3.3 BPBs. |
A simple formula translates a given cluster number CN
to a logical sector number LSN
:[3]
SSA=RSC+FN×SF+ceil((32×RDE)/SS)
, where the reserved sector count RSC
is stored at offset 0x0E, the FAT number FN
at offset 0x10, the sectors per FAT SF
at offset 0x16 (FAT12/FAT16) or 0x24 (FAT32), the root directory entries RDE
at offset 0x11, the sector size SS
at offset 0x0B, and ceil(x)
rounds up to a whole number.LSN=SSA+(CN-2)×SC
, where the sectors per cluster SC
are stored at offset 0x0D.A translation of CHS to LSN
is also simple: LSN=SPT×(HN+(NOS×TN))+SN-1
, where the sectors per track SPT
are stored at offset 0x18, and the number of sides NOS
at offset 0x1A. Track number TN
, head number HN
, and sector number SN
correspond to Cylinder-head-sector: the formula gives the known CHS to LBA translation.
Further structure used by FAT12 and FAT16 since OS/2 1.0 and DOS 4.0, also known as Extended BIOS Parameter Block (EBPB) (bytes below sector offset 0x24 are the same as for the DOS 3.31 BPB):
Sector Offset | EBPB Offset | Length (bytes) | Description |
---|---|---|---|
0x0B | 0x00 | 25 | DOS 3.31 BPB; see above |
0x24 | 0x19 | 1 | Physical drive number (0x00 for (first) removable media, 0x80 for (first) fixed disk as per INT 13h). Allowed values for possible physical drives depending on BIOS are 0x00-0x7E and 0x80-0xFE. Values 0x7F and 0xFF are reserved for internal purposes such as remote or ROM disk boot and should never occur on disk. Some boot loaders such as the MS-DOS/PC DOS boot loader use this value when loading the operating system, others ignore it altogether or use the drive number provided in the DL register by the underlying boot loader (f.e. with many BIOSes and MBRs). The entry is sometimes changed by SYS tools or it can be dynamically fixed up by the prior bootstrap loader in order to force the boot sector code to load the operating system from alternative physical disks than the default. |
0x25 | 0x1A | 1 | Reserved; in some DOS boot code used as INT 13h current head high byte for the assumed 16-bit word at 0x24; also used by boot managers to communicate a drive letter assigned to a partition to operating systems such as OS/2 by setting bit 7 and specifying the drive number in bits 6-0 (C: = value 0, D: = value 1, ...); in Windows NT used for CHKDSK flags (bits 7-2 always cleared, bit 1: disk I/O errors encountered, possible bad sectors, run surface scan on next boot, bit 0: volume is "dirty" and was not properly unmounted before shutdown, run CHKDSK on next boot).[29] Should be set to 0 by formating tools. See also: Bitflags in the second cluster entry in the FAT. |
0x26 | 0x1B | 1 | Extended boot signature. (Should be 0x29[27] to indicate that an EBPB with the following 3 entries exists. Can be 0x28 on some OS/2 1.0-1.1 and European MS-DOS 4.0 disks indicating an earlier form of the EBPB format with only the serial number following.) |
0x27 | 0x1C | 4 | Volume ID (serial number) |
0x2B | 0x20 | 11 | Volume Label, padded with blanks (0x20), e.g., "NO␠NAME␠␠␠␠ "
Software changing the directory volume label in the filesystem should also update this entry, but not all software does. This volume label is typically displayed in partitioning tools since it is accessible without mounting the volume. Supported since OS/2 1.2 and MS-DOS 4.0 and higher. |
0x36 | 0x2B | 8 | File system type, padded with blanks (0x20), e.g. "FAT12␠␠␠ ", "FAT16␠␠␠ ", "FAT␠␠␠␠␠ "
This entry is meant for display purposes only and must not be used by the operating system to identify the type of the filesystem. Nevertheless, it is sometimes used for identification purposes by third-party software and therefore the values should not differ from those officially used. Supported since OS/2 1.2 and MS-DOS 4.0 and higher. |
The boot sector is portrayed here as found on e.g. an OS/2 1.3 boot diskette. Earlier versions used a shorter BIOS Parameter Block and their boot code would start earlier (for example at offset 0x2B in OS/2 1.1).
In essence FAT32 inserts 28 bytes, followed by the remaining 26 EBPB bytes as shown above for FAT12 and FAT16:
Sector Offset | FAT32 EBPB Offset | Length (bytes) | Description |
---|---|---|---|
0x0B | 0x00 | 25 | DOS 3.31 BPB; see above |
0x24 | 0x19 | 4 | Logical sectors per file allocation table |
0x28 | 0x1D | 2 | Mirroring flags (bits 3-0: active FAT number minus 1, if bit 7 set. If bit 7 is clear, all FATs are mirrored as usual. Other bits reserved and should be 0.) |
0x2A | 0x1F | 2 | Version (defined as 0.0) |
0x2C | 0x21 | 4 | Cluster number of root directory start, typically 2 (first cluster[13]) if it contains no bad sector. |
0x30 | 0x25 | 2 | Logical sector number of FS Information Sector, typically 1, i.e., the second of the three FAT32 boot sectors. |
0x32 | 0x27 | 2 | First logical sector number of a copy of the three FAT32 boot sectors, typically 6.[9] |
0x34 | 0x29 | 12 | Reserved (must be initialized to 0 by formatting tools) |
0x40 | 0x35 | 1 | Cf. 0x24 for FAT12/FAT16 (Physical Drive Number) |
0x41 | 0x36 | 1 | Cf. 0x25 for FAT12/FAT16 |
0x42 | 0x37 | 1 | Cf. 0x26 for FAT12/FAT16 (Extended boot signature, 0x29) |
0x43 | 0x38 | 4 | Cf. 0x27 for FAT12/FAT16 (Volume ID) |
0x47 | 0x3C | 11 | Cf. 0x2B for FAT12/FAT16 (Volume Label) |
0x52 | 0x47 | 8 | Cf. 0x36 for FAT12/FAT16 (File system type, padded with blanks (0x20), e.g. "FAT32␠␠␠ ") |
The implementation of FAT used in MS-DOS for the Apricot PC had a different boot sector layout, to accommodate that computer's non-IBM compatible BIOS. The jump instruction and OEM name were omitted, and the MS-DOS file system parameters (offsets 0x0B–0x17 in the standard sector) were located at offset 0x50. Later versions of Apricot MS-DOS gained the ability to read and write disks with the standard boot sector in addition to those with the Apricot one.
DOS Plus on the BBC Master 512 did not use conventional boot sectors at all. Data disks omitted the boot sector and began with a single copy of the FAT (the first byte of the FAT was used to determine disk capacity) while boot disks began with a miniature ADFS file system containing the boot loader, followed by a single FAT. It could also access standard PC disks formatted to 180 KB or 360 KB, again using the first byte of the FAT to determine the capacity.
The "FS Information Sector" was introduced in FAT32[30] for speeding up access times of certain operations (in particular, getting the amount of free space). It is located at a sector number specified in the boot record at position 0x30 (usually sector 1, immediately after the boot record).
Byte Offset | Length (bytes) | Description |
---|---|---|
0x00 | 4 | FS information sector signature (0x52 0x52 0x61 0x41 = "RRaA ") |
0x04 | 480 | Reserved (byte values are 0x00) |
0x1E4 | 4 | FS information sector signature (0x72 0x72 0x41 0x61 = "rrAa ") |
0x1E8 | 4 | Number of free clusters on the drive, or -1 if unknown |
0x1EC | 4 | Number of the most recently allocated cluster |
0x1F0 | 12 | Reserved (byte values are 0x00) |
0x1FC | 4 | FS information sector signature (0x00 0x00 0x55 0xAA )[9] |
A partition is divided up into identically sized clusters, small blocks of contiguous space. Cluster sizes vary depending on the type of FAT file system being used and the size of the partition, typically cluster sizes lie somewhere between 2 KB and 32 KB. Each file may occupy one or more of these clusters depending on its size; thus, a file is represented by a chain of these clusters (referred to as a singly linked list). However these clusters are not necessarily stored adjacent to one another on the disk's surface but are often instead fragmented throughout the Data Region.
The File Allocation Table (FAT) is a list of entries that map to each cluster on the partition. Each entry records one of five things:
The first two entries in a FAT store special values: The first entry holds the media descriptor (which is also copied to the boot sector, offset 0x15 since DOS 2.0). The remaining 4 bits (if FAT12), 8 bits (if FAT16) or 20 bits (if FAT32) of this entry are 1.
The second entry stores the end-of-cluster-chain marker. The high order two bits of this entry are sometimes, in the case of FAT16 and FAT32, used for dirty volume management: high order bit 1: last shutdown was clean; next highest bit 1: during the previous mount no disk I/O errors were detected.[28]
Because the first two FAT entries store special values, there is no cluster 0 or 1. The first data cluster (after the root directory if FAT12/FAT16) is cluster 2.[13]
FAT entry values:
FAT12 | FAT16 | FAT32 | Description |
---|---|---|---|
0x000 | 0x0000 | 0x00000000 | Free Cluster; also used by DOS to refer to the parent directory starting cluster in ".." entries for subdirectories of the root directory on FAT12/FAT16 volumes. |
0x001 | 0x0001 | 0x00000001 | Reserved for internal purposes; MS-DOS/PC DOS use this cluster value as a temporary non-free cluster indicator while constructing cluster chains during file allocation (only seen on disk if there is a crash or power failure in the middle of this process). |
0x002-0xFEF | 0x0002-0xFFEF | 0x00000002-0x0FFFFFEF | Used cluster; value points to next cluster |
0xFF0-0xFF5 | 0xFFF0-0xFFF5 | 0x0FFFFFF0-0x0FFFFFF5 | Reserved in some contexts[11] or also used[3][9][10] |
0xFF6 | 0xFFF6 | 0x0FFFFFF6 | Reserved; do not use[3][9][10][27] |
0xFF7 | 0xFFF7 | 0x0FFFFFF7 | Bad sector in cluster or reserved cluster |
0xFF8-0xFFF | 0xFFF8-0xFFFF | 0x0FFFFFF8-0x0FFFFFFF | Last cluster in file (EOC) |
Despite its name FAT32 uses only 28 bits of the 32 possible bits. The upper 4 bits are usually zero (as indicated in the table above) but are reserved and should be left untouched. A standard conformant FAT32 filesystem driver or maintenance tool should not rely on the upper 4 bits to be zero and strip them off before evaluating the cluster number in order to cope with possible future expansions where these bits may be used for other purposes. They must not be cleared by the file system driver when allocating new clusters, but should be cleared during a reformat.
Each version of the FAT file system uses a different size for FAT entries. Smaller numbers result in a smaller FAT, but waste space in large partitions by needing to allocate in large clusters. The FAT12 file system uses 12 bits per FAT entry, thus two entries span 3 bytes. It is consistently little-endian: if you consider the 3 bytes as one little-endian 24-bit number, the 12 least significant bits are the first entry and the 12 most significant bits are the second.
A directory table is a special type of file that represents a directory (also known as a folder). Each file or directory stored within it is represented by a 32-byte entry in the table. Each entry records the name, extension, attributes (archive, directory, hidden, read-only, system and volume), the date and time of last modification, the address of the first cluster of the file/directory's data and finally the size of the file/directory. Aside from the Root Directory Table in FAT12 and FAT16 file systems, which occupies the special Root Directory Region location, all Directory Tables are stored in the Data Region. The actual number of entries in a directory stored in the Data Region can grow by adding another cluster to the chain in the FAT.
The FAT file system itself does not impose any limits on the depth of a subdirectory tree for as long as there are free clusters available to allocate the subdirectories, however, the Current Directory Structure under MS-DOS/PC DOS limits the absolute path of a directory to 66 characters (including the drive letter, but excluding the zero delimiter), thereby limiting the maximum supported depth of subdirectories to 32, whatever occurs earlier. Concurrent DOS, Multiuser DOS and DR DOS 3.31 - 6.0 (up to including the 1992-11 updates) do not store absolute paths to working directories internally and therefore do not show this limitation. The same applies to Atari GEMDOS, but the Atari Desktop does not support more than 8 sub-directory levels. Most applications aware of this extension support paths up to at least 128 bytes. PalmDOS, DR DOS 6.0 (since BDOS 7.1) and higher, Novell DOS, and OpenDOS sport a MS-DOS-compatible CDS and therefore have the same length limits as MS-DOS/PC DOS.
Note that before each entry there can be "fake entries" to support the Long File Name. (See further down the article).
Legal characters for DOS file names include the following:
A
–Z
0
–9
! # $ % & ' ( ) - @ ^ _ ` { } ~
This excludes the following ASCII characters:
" * / : < > ? \ |
+ , . ; = []
a
–z
A
–Z
. Allowed in long file names.The following additional characters are allowed on Atari's GEMDOS, but should be avoided for compatibility with MS-DOS/PC DOS:
" + , ; < = > [ ] |
The semicolon (;) should be avoided in filenames under DR DOS 3.31 and higher, PalmDOS, Novell DOS, OpenDOS, Concurrent DOS, Multiuser DOS, System Manager and REAL/32, because it may conflict with the syntax to specify file and directory passwords: "...\DIRSPEC.EXT;DIRPWD\FILESPEC.EXT;FILEPWD". The operating system will strip off one or two semicolons and pending passwords from the filenames before storing them on disk. (The command processor 4DOS uses semicolons for include lists and requires the semicolon to be doubled for password protected files with any commands supporting wildcards.)
The @-character is used for filelists by many DR-DOS, PalmDOS, Novell DOS, OpenDOS and Multiuser DOS, System Manager and REAL/32 commands as well as by 4DOS and may therefore sometimes be difficult to use in filenames.
Under Multiuser DOS and REAL/32, the exclamation mark (!) is not a valid filename character since it is used to separate multiple commands in a single command line.
The DOS file names are in the current OEM character set: this can have surprising effects if characters handled in one way for a given code page are interpreted differently for another code page (DOS command CHCP) with respect to lower and upper case, sorting, or validity as file name character.
Directory entries, both in the Root Directory Region and in subdirectories, are of the following format (see also 8.3 filename):
Byte Offset | Length (bytes) | Description | ||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0x00 | 8 | Short file name (padded with spaces)
The first byte can have the following special values:
|
||||||||||||||||||||||||||||||||||||||||||
0x08 | 3 | Short file extension (padded with spaces) | ||||||||||||||||||||||||||||||||||||||||||
0x0B | 1 | File Attributes
Under DR DOS 6.0 and higher, including PalmDOS, Novell DOS and OpenDOS, the volume attribute is set for deleted files for as long as they are still pending for possible undeletion under DELWATCH. An attribute combination of 0x0F is used to designate a VFAT long file name entry since MS-DOS 7.0. Older versions of DOS can mistake this for a directory volume label, as they take the first entry with volume attribute set as volume label. Since volume labels normally don't have the system attribute set at the same time, it is possible to distinguish between volume labels and VFAT LFN entries. The attribute combination 0x0F could occasionally also occur as part of a valid DELWATCHed file, however on FAT12 and FAT16 volumes, VFAT LFN entries always have the cluster value at 0x1A set to 0x0000 and the length entry at 0x1C is never 0x00000000, whereas the entry at 0x1A is always non-zero for DELWATCHed files (with the possible exception of zero-length files indicated by 0x00000000 at 0x1C). This check does not work on FAT32 volumes. |
||||||||||||||||||||||||||||||||||||||||||
0x0C | 1 |
|
||||||||||||||||||||||||||||||||||||||||||
0x0D | 1 |
Double usage for create time ms and file char is not conflictive, since the creation time is no longer important for deleted files. |
||||||||||||||||||||||||||||||||||||||||||
0x0E | 2 |
If bits 15-11 > 23 or bits 10-5 > 59 or bits 4-0 > 29 here, or when bits 12-0 at offset 0x14 hold an access bitmap and this is not a FAT32 volume or a volume using OS/2 Extended Attributes, then this entry actually holds a password hash, otherwise it can be assumed to be a file creation time. |
||||||||||||||||||||||||||||||||||||||||||
0x10 | 2 |
|
||||||||||||||||||||||||||||||||||||||||||
0x12 | 2 |
The usage for the owner-IDs of existing files and last modified date stamp for deleted files is not conflictive because they are never used at the same time. The usage of the last modified date stamp for deleted files and access date is also not conflictive since access dates are no longer important for deleted files, however, owner-IDs and access dates cannot be used at the same time. |
||||||||||||||||||||||||||||||||||||||||||
0x14 | 2 |
|
||||||||||||||||||||||||||||||||||||||||||
0x16 | 2 |
|
||||||||||||||||||||||||||||||||||||||||||
0x18 | 2 |
|
||||||||||||||||||||||||||||||||||||||||||
0x1A | 2 | Start of file in clusters in FAT12 and FAT16. Low 2 bytes of first cluster in FAT32. Entries with the Volume Label flag, subdirectory ".." pointing to FAT12/FAT16 root, and empty files with size 0 should have first cluster 0.
VFAT LFN entries also have this entry set to 0; on FAT12 and FAT16 volumes this can be used as part of a detection mechanism to distinguish between DELWATCHed files and VFAT LFNs; see above. |
||||||||||||||||||||||||||||||||||||||||||
0x1C | 4 | File size in bytes. Entries with the Volume Label or Subdirectory flag set should have a size of 0.
VFAT LFN entries never store the value 0x00000000 here. This can be used as part of a detection mechanism to distinguish between DELWATCHed files and VFAT LFNs; see above. |
Long File Names (LFN) are stored on a FAT file system using a trick—adding (possibly multiple) additional entries into the directory before the normal file entry. The additional entries are marked with the Volume Label, System, Hidden, and Read Only attributes (yielding 0x0F), which is a combination that is not expected in the MS-DOS environment, and therefore ignored by MS-DOS programs and third-party utilities. Notably, a directory containing only volume labels is considered as empty and is allowed to be deleted; such a situation appears if files created with long names are deleted from plain DOS. This method is very similar to the DELWATCH method to utilize the volume attribute to hide deleted files for possible future undeletion since DR DOS 6.0 (1991) and higher.
Older versions of DOS mistake LFN names in the root directory for the volume label, and are likely to display an incorrect label.
Each phony entry can contain up to 13 UTF-16 characters (26 bytes) by using fields in the record which contain file size or time stamps (but not the starting cluster field, for compatibility with disk utilities, the starting cluster field is set to a value of 0. See 8.3 filename for additional explanations). Up to 20 of these 13-character entries may be chained, supporting a maximum length of 255 UTF-16 characters.[31]
After the last UTF-16 character, a 0x00 0x00 is added. The remaining unused characters are filled with 0xFF 0xFF.
LFN entries use the following format:
Byte Offset | Length (bytes) | Description |
---|---|---|
0x00 | 1 | Sequence Number (bit 6: last logical, first physical LFN entry, bit 5: 0; bits 4-0: number 0x01..0x14 (0x1F), deleted entry: 0xE5) |
0x01 | 10 | Name characters (five UTF-16 characters) |
0x0B | 1 | Attributes (always 0x0F) |
0x0C | 1 | Type (always 0x00 for VFAT LFN, other values reserved for future use; for special usage of bits 4 and 3 in SFNs see below) |
0x0D | 1 | Checksum of DOS file name |
0x0E | 12 | Name characters (six UTF-16 characters) |
0x1A | 2 | First cluster (always 0x0000) |
0x1C | 4 | Name characters (two UTF-16 characters) |
If there are multiple LFN entries, required to represent a file name, firstly comes the last LFN entry (the last part of the filename). The sequence number also has bit 6 (0x40) set (this means the last LFN entry, however it's the first entry seen when reading the directory file). The last LFN entry has the largest sequence number which decreases in following entries. The first LFN entry has sequence number 1. A value of 0xE5 is used to indicate that the entry is deleted.
On FAT12 and FAT16 volumes, testing for the values at 0x1A to be zero and at 0x1C to be non-zero can be used to distinguish between VFAT LFNs and DELWATCHed files.
For example if we have filename "File with very long filename.ext" it would be formatted like this:
Sequence number | Entry data |
---|---|
0x43 | "me.ext" |
0x02 | "y long filena" |
0x01 | "File with ver" |
??? | Normal 8.3 entry |
A checksum also allows verification of whether a long file name matches the 8.3 name; such a mismatch could occur if a file was deleted and re-created using DOS in the same directory position. The checksum is calculated using the algorithm below. (Note that pFcbName is a pointer to the name as it appears in a regular directory entry, i.e. the first eight characters are the filename, and the last three are the extension. The dot is implicit. Any unused space in the filename is padded with space characters (ASCII 0x20). For example, "Readme.txt" would be "README␠␠TXT"
.)
unsigned char lfn_checksum(const unsigned char *pFcbName) { int i; unsigned char sum=0; for (i=11; i; i--) sum = ((sum & 1) << 7) + (sum >> 1) + *pFcbName++; return sum; }
If a filename contains only lowercase letters, or is a combination of a lowercase basename with an uppercase extension, or vice-versa; and has no special characters, and fits within the 8.3 limits, a VFAT entry is not created on Windows NT and later versions of Windows such as XP. Instead, two bits in byte 0x0C of the directory entry are used to indicate that the filename should be considered as entirely or partially lowercase. Specifically, bit 4 means lowercase extension and bit 3 lowercase basename, which allows for combinations such as "example.TXT
" or "HELLO.txt
" but not "Mixed.txt
". Few other operating systems support it. This creates a backwards-compatibility problem with older Windows versions (95, 98, ME) that see all-uppercase filenames if this extension has been used, and therefore can change the name of a file when it is transported between OSes, such as on a USB flash drive. Current 2.6.x versions of Linux will recognize this extension when reading (source: kernel 2.6.18 /fs/fat/dir.c and fs/vfat/namei.c); the mount option shortname determines whether this feature is used when writing.[32]
Before Microsoft added support for long filenames and creation/access time stamps, bytes 0x0C–0x15 of the directory entry were used by alternative operating systems to store additional metadata, most notably the operating systems of the Digital Research family stored file passwords, access rights, owner-IDs, and file deletion data in there in a backwards compatible way. While Microsoft's newer extensions are not fully compatible with these extensions by default, most of them can coexist in third-party FAT implementations (at least on FAT12 and FAT16 volumes). Therefore they have been incorporated into the table above. Some other extensions, which are not compatible with Microsoft's extensions, include:
Byte Offset | Length (bytes) | System | Description |
---|---|---|---|
0x0C | 2 | RISC OS | File type, 0x0000–0x0FFF |
0x0C | 4 | Petrov DOSFS | File load address |
0x0E | 2 | ANDOS | File address in the memory |
0x10 | 4 | Petrov DOSFS | File execution address |
The FAT12, FAT16, FAT16B, and FAT32 variants of the FAT file systems have clear limits based on the number of clusters and the number of sectors per cluster (1, 2, 4, ..., 128). For the typical value of 512 bytes per sector:
FAT12 requirements : 3 sectors on each copy of FAT for every 1,024 clusters FAT16 requirements : 1 sector on each copy of FAT for every 256 clusters FAT32 requirements : 1 sector on each copy of FAT for every 128 clusters FAT12 range : 1 to 4,084 clusters : 1 to 12 sectors per copy of FAT FAT16 range : 4,085 to 65,524 clusters : 16 to 256 sectors per copy of FAT FAT32 range : 65,525 to 268,435,444 clusters : 512 to 2,097,152 sectors per copy of FAT FAT12 minimum : 1 sector per cluster × 1 clusters = 512 bytes (0.5 KB) FAT16 minimum : 1 sector per cluster × 4,085 clusters = 2,091,520 bytes (2,043 KB) FAT32 minimum : 1 sector per cluster × 65,525 clusters = 33,548,800 bytes (32,763 KB) FAT12 maximum : 64 sectors per cluster × 4,084 clusters = 133,824,512 bytes (≈ 127 MB) [FAT12 maximum : 128 sectors per cluster × 4,084 clusters = 267,694,024 bytes (≈ 255 MB)] FAT16 maximum : 64 sectors per cluster × 65,524 clusters = 2,147,090,432 bytes (≈2,047 MB) [FAT16 maximum : 128 sectors per cluster × 65,524 clusters = 4,294,180,864 bytes (≈4,095 MB)] FAT32 maximum : 8 sectors per cluster × 268,435,444 clusters = 1,099,511,578,624 bytes (≈1,024 GB) FAT32 maximum : 16 sectors per cluster × 268,173,557 clusters = 2,196,877,778,944 bytes (≈2,046 GB) [FAT32 maximum : 32 sectors per cluster × 134,152,181 clusters = 2,197,949,333,504 bytes (≈2,047 GB)] [FAT32 maximum : 64 sectors per cluster × 67,092,469 clusters = 2,198,486,024,192 bytes (≈2,047 GB)] [FAT32 maximum : 128 sectors per cluster × 33,550,325 clusters = 2,198,754,099,200 bytes (≈2,047 GB)]
Legend: 268435444+3 is hex. 0FFF FFF7
, because FAT32 version 0 uses only 28 bits in the 32bit cluster numbers, cluster numbers hex. 0FFF FFF7
up to 0FFF FFFF
flag bad clusters or the end of a file, cluster number 0 flags a free cluster, and cluster number 1 is not used.[13] Likewise 65524+3 is hex. FFF7
for FAT16, and 4084+3 is hex. FF7
for FAT12. The number of sectors per cluster is a power of 2 fitting in a single byte, the smallest value is 1 (hex. 01
), the biggest value is 128 (hex. 80
). Lines in square brackets indicate the unusual cluster size 128, and for FAT32 the bigger than necessary cluster sizes 32 or 64.[18]
Because each FAT32 entry occupies 32bits (4 bytes) the maximal number of clusters (268435444) requires 2097152 FAT sectors for a sector size of 512 bytes. 2097152 is hex. 200000
, and storing this value needs more than two bytes. Therefore FAT32 introduced a new 32bit value in the FAT32 boot sector immediately following the 32bit value for the total number of sectors introduced in the "BigFAT" variant of FAT16.
The boot record extensions introduced with DOS 4.0 start with a magic 40 (hex. 28
) or 41 (hex. 29
). Typically FAT drivers look only at the number of clusters to distinguish FAT12, FAT16, and FAT32: the human readable strings identifying the FAT variant in the boot record are ignored, because they exist only for media formatted with DOS 4.0 or later.
Determining the number of directory entries per cluster is straight forward, each entry occupies 32 bytes, this results in 16 entries per sector for a sector size of 512 bytes. The DOS 5 RD/RMDIR command removes the initial "." (this directory) and ".." (parent directory) entries in subdirectories directly, therefore sector size 32 on a RAM disk is possible for FAT12, but requires 2 or more sectors per cluster. A FAT12 boot sector without the DOS 4 extensions needs 29 bytes before the first unnecessary "BigFAT" 32bit number of hidden sectors, this leaves three bytes for the (on a RAM disk unused) boot code and the magic hex. 55AA at the end of all boot sectors. On Windows NT the smallest supported sector size is 128.
On Windows NT operating systems the format command options /A:128K
and /A:256K
correspond to the maximal cluster size hex. 80
(128) with a sector size 1024 and 2048, respectively. For the common sector size 512 /A:64K
yields 128 sectors per cluster.
Both editions of ECMA 107[3] specify a Max Cluster Number MAX
determined by the formula MAX=1+trunc((TS-SSA)/SC)
, and reserve cluster numbers MAX+1
up to 4086 (hex. FF6
, FAT12) and later 65526 (hex. FFF6
, FAT16) for future standardization.
Microsoft's EFI FAT32 specification[9] states that any FAT file system with less than 4085 clusters is FAT12, else any FAT file system with less than 65525 clusters is FAT16, and otherwise it is FAT32. The entry for cluster 0 at the beginning of the FAT must be identical to the media descriptor byte found in the BPB, whereas the entry for cluster 1 reflects the end-of-chain value used by the formatter for cluster chains (0xFFF, 0xFFFF or 0x0FFFFFFF). The entries for cluster numbers 0 and 1 end at a byte boundary even for FAT12, e.g., hex. F9FFFF
for media descriptor hex. F9
. On FAT16 and FAT32, but not on FAT12 volumes, the two most-significant bits of the entry for cluster 1 may hold bitflags regarding the volume status (bit 15 respectively bit 27 cleared: volume is "dirty" and was not properly unmounted before shutdown, run CHKDSK on next boot; bit 14 respectively bit 26 cleared: disk I/O errors encountered, possible bad sectors, run surface scan on next boot). These bitflags are not supported by all operating systems.
The first data cluster is 2,[13] and consequently the last cluster MAX
gets number MAX+1
. This results in data cluster numbers 2...4085 (hex. FF5
) for FAT12, 2...65525 (hex. FFF5
) for FAT16, and 2...268435445 (hex. 0FFF FFF5
) for FAT32.
The only available values reserved for future standardization are therefore hex. FF6
(FAT12) and hex. FFF6
(FAT16). As noted below "less than 4085" is also used for Linux implemementations,[10] or as Microsoft's FAT specification puts it:[9]
when it says <, it does not mean <=. Note also that the numbers are correct. The first number for FAT12 is 4085; the second number for FAT16 is 65525. These numbers and the ‘<’ signs are not wrong.
The FAT file system does not contain built-in mechanisms which prevent newly written files from becoming scattered across the partition.[33] On volumes, where files are created and deleted frequently or their lengths often changed, the medium will become increasingly fragmented over time.
While the design of the FAT file system does not cause any organizational overhead in disk structures or reduce the amount of free storage space with increased amounts of fragmentation, as it occurs with external fragmentation, the time required to read and write fragmented files will increase as the operating system will have to follow the cluster chains in the FAT (with parts having to be loaded into memory first in particular on large volumes) and read the corresponding data physically scattered over the whole medium reducing chances for the low-level block device driver to perform multi-sector disk I/O or initiate larger DMA transfers, thereby effectively increasing I/O protocol overhead as well as arm movement and head settle times inside the disk drive. Also, file operations will become slower with growing fragmentation as it takes increasingly longer for the operating system to find files or free clusters.
Other file systems, e.g. HPFS or exFAT, use free space bitmaps that indicate used and available clusters, which could then be quickly looked up in order to find free contiguous areas. Another solution is the linkage of all free clusters into one or more lists (as is done in Unix file systems). Instead, the FAT has to be scanned as an array to find free clusters, which can lead to performance penalties with large disks.
In fact, seeking for files in large subdirectories or computing the free disk space on FAT volumes is one of the most resource intensive operations, as it requires reading the entire FAT linearly. Since the total amount of clusters and the size of their entries in the FAT was still small on FAT12 and FAT16 volumes, this could still be tolerated on FAT12 and FAT16 volumes most of the time, considering that the introduction of more sophisticated disk structures would have also increased the complexity and memory footprint of real-mode operating systems with their minimum total memory requirements of 128 KB or less (such as with DOS) for which FAT has been designed and optimized originally.
With the introduction of FAT32, long seek times became more apparent, particularly on very large volumes. A possible justification suggested by Microsoft's Raymond Chen for limiting the maximum size of FAT32 partitions created on Windows was the time required to perform a "DIR" operation, which always displays the free disk space as the last line.[34] Displaying this line took longer and longer as the number of clusters increased. FAT32 therefore introduced a special filesystem information sector where the previously computed amount of free space is preserved over power cycles, so that the free space counter needs to be recalculated only when a removable FAT32 formatted medium gets ejected without first unmounting it or if the system is switched off without properly shutting down the operating system, a problem mostly visible with pre-ATX-style PCs, on plain DOS systems and some battery-powered consumer products.
With the huge cluster sizes (16 KB, 32 KB, 64 KB) forced by larger FAT partitions, internal fragmentation in form of disk space waste by file slack due to cluster overhang (as files are rarely exact multiples of cluster size) starts to be a problem as well, especially when there are a great many small files.
Various optimizations and tweaks to the implementation of FAT filesystem drivers, block device drivers and disk tools have been devised to overcome most of the performance bottlenecks in the filesystem's inherit design without having to change the layout of the on-disk structures. They can be divided into on-line and off-line methods and work by trying to avoid fragmentation in the file system in the first place, deploying methods to better cope with existing fragmentation, and by reordering and optimizing the on-disk structures. With optimizations in place, the performance on FAT volumes can often reach that of more sophisticated filesystems in practical scenarios, while at the same time retaining the advantage of being accessible even on very small or old systems.
Since DOS 3.3 the operating system provides means to improve the performance of file operatings with FASTOPEN by keeping track of the position of recently opened files or directories in various forms of lists (MS-DOS/PC DOS) or hash tables (DR-DOS), which can reduce file seek and open times significantly. Special care must be taken when using such mechanisms in conjunction with disk defragmentation software, bypassing the file system.
Windows NT will allocate disk space to files on FAT in advance, selecting large contiguous areas, but in case of a failure, files which were being appended will appear larger than they were ever written into, with a lot of random data at the end.
Other high-level mechanisms may read in and process larger amounts or even the complete FAT either systematically on startup or on demand when needed and thereby dynamically build up in-memory tree representations of the disk structures different from the on-disk FAT structure. This may, on volumes with many free clusters, occupy even less memory than an image of the FAT itself. In particular on highly fragmented or filled volumes, seeks become much faster than with linear scans over the actual FAT, even if an image of the FAT would be stored in memory. Also, operating on the logically high level of files and cluster-chains instead of on sector or track level, it becomes possible to avoid some degree of file fragmentation in the first place or to carry out local file defragmentation and reordering of directory entries based on their names or access patterns in the background.
Some of the perceived problems with fragmentation of FAT file systems also result from performance limitations of the underlying block device drivers, which become more visible the lesser memory is available for sector buffering and track blocking/deblocking:
While the single-tasking DOS had provisions for multi-sector reads and track blocking/deblocking, the operating system and the traditional PC hard disk architecture (only one outstanding input/output request at a time and no DMA transfers) originally did not contain mechanisms which could alleviate fragmentation by asynchronously prefetching next data while the application was processing the previous chunks. Such features became available later. Later DOS versions also provided built-in support for look-ahead sector buffering and came with dynamically loadable disk caching programs working on physical or logical sector level, often utilizing EMS or XMS memory and sometimes providing adaptive caching mechanisms.
Write-behind caching was often not enabled by default with Microsoft software (if present) given the problem of data loss in case of a power failure or crash, made easier by the lack of hardware protection between applications and the system.
Due to the widespread use of FAT formatted media since its introduction many operating systems have provided support for FAT and subsequently VFAT and FAT32 through official or third-party file system handlers. For example, Linux, FreeBSD, BeOS and JNode provide inbuilt support for FAT. Early Linux distributions also supported a format known as UMSDOS, a FAT variant with Unix file attributes (such as long file name and access permissions) stored in a separate file called “--linux-.---
”. UMSDOS fell into disuse after VFAT was released and it is not enabled by default in Linux kernels from version 2.5.7 onwards.[35] Mac OS 9 and Mac OS X also support FAT file systems on volumes other than the boot disk. AmigaOS supports FAT through the CrossDOS file system.
A free Windows-based FAT32 formatter is available that overcomes many of the arbitrary limitations imposed by Microsoft.[36]
The FAT file system itself is not designed for supporting Alternate Data Streams (ADS), but some operating systems that heavily depend on them have devised various methods for handling them in FAT drives. Such methods either store the additional information in extra files and directories (Mac OS), or give new semantics to previously unused fields of the FAT on-disk data structures (OS/2 and Windows NT).
Mac OS using PC Exchange stores its various dates, file attributes and long filenames in a hidden file called FINDER.DAT, and resource forks (a common Mac OS ADS) in a subdirectory called RESOURCE.FRK, in every directory where they are used. From PC Exchange 2.1 onwards, they store the Mac OS long filenames as standard FAT long filenames and convert FAT filenames longer than 31 characters to unique 31-character filenames, which can then be made visible to Macintosh applications.
Mac OS X stores resource forks and metadata (file attributes, other ADS) in a hidden file with a name constructed from the owner filename prefixed with "._", and Finder stores some folder and file metadata in a hidden file called ".DS Store".
OS/2 heavily depends on extended attributes (EAs) and stores them in a hidden file called "EA DATA. SF" in the root directory of the FAT12 or FAT16 volume. This file is indexed by 2 previously reserved bytes in the file's (or directory's) directory entry. In the FAT32 format, these bytes hold the upper 16 bits of the starting cluster number of the file or directory, hence making it difficult to store EAs on FAT32. Extended attributes are accessible via the Workplace Shell desktop, through REXX scripts, and many system GUI and command-line utilities (such as 4OS2).[37]
To accommodate its OS/2 subsystem, Windows NT supports the handling of extended attributes in HPFS, NTFS, and FAT. It stores EAs on FAT and HPFS using exactly the same scheme as OS/2, but does not support any other kind of ADS as held on NTFS volumes. Trying to copy a file with any ADS other than EAs from an NTFS volume to a FAT or HPFS volume gives a warning message with the names of the ADSs that will be lost.
Windows 2000 onward acts exactly as Windows NT, except that it ignores EAs when copying to FAT32 without any warning (but shows the warning for other ADSs, like "Macintosh Finder Info" and "Macintosh Resource Fork").
Microsoft applied for, and was granted, a series of patents for key parts of the FAT file system in the mid-1990s. Being almost universally compatible and well-understood, FAT is frequently chosen as an interchange format for flash media used in digital cameras and PDAs.
On December 3, 2003 Microsoft announced[38] it would be offering licenses for use of its FAT specification and "associated intellectual property", at the cost of a US$0.25 royalty per unit sold, with a $250,000 maximum royalty per license agreement.[39]
To this end, Microsoft cited four patents on the FAT file system as the basis of its intellectual property claims. All four pertain to long-filename extensions to FAT first seen in Windows 95:
Many technical commentators have concluded that these patents only cover FAT implementations that include support for long filenames, and that removable solid-state media and consumer devices only using short names would be unaffected.
Additionally, in the EFI FAT32 specification[9] Microsoft specifically grants a number of rights, which many readers have interpreted as permitting operating system vendors to implement FAT.
Microsoft is not the only company to have applied for patents for parts of the FAT file system. Other patents affecting FAT include:
As there was widespread call for these patents to be re-examined, the Public Patent Foundation (PUBPAT) submitted evidence to the US Patent and Trade Office (USPTO) disputing the validity of these patents, including prior art references from Xerox and IBM. The USPTO acknowledged that the evidence raised "substantial new question[s] of patentability," and opened an investigation into the validity of Microsoft's FAT patents.[44]
On 2004-09-30 the USPTO rejected all claims of U.S. Patent 5,579,517, based primarily on evidence provided by PUBPAT. Dan Ravicher, the foundation's executive director, said, "The Patent Office has simply confirmed what we already knew for some time now, Microsoft's FAT patent is bogus."
According to the PUBPAT press release, "Microsoft still has the opportunity to respond to the Patent Office's rejection. Typically, third-party requests for re-examination, like the one filed by PUBPAT, are successful in having the subject patent either narrowed or completely revoked roughly 70% of the time."
On 2005-10-05 the Patent Office announced that, following the re-examination process, it had again rejected all claims of patent 5,579,517, and it additionally found U.S. Patent 5,758,352 invalid on the grounds that the patent had incorrect assignees.
Finally, on 2006-01-10 the Patent Office ruled that features of Microsoft's implementation of the FAT system were "novel and non-obvious", reversing both earlier non-final decisions.[45]
In February 2009, Microsoft filed a patent infringement lawsuit against TomTom alleging that the device maker's products infringe on patents related to FAT32 filesystem. As some TomTom products are based on Linux, this marked the first time that Microsoft tried to enforce its patents against the Linux platform.[46] The lawsuit was settled out of court the following month with an agreement that Microsoft be given access to four of TomTom's patents, that TomTom will drop support for the FAT32 filesystem from its products, and that in return Microsoft not seek legal action against TomTom for the five year duration of the settlement agreement.[47]
In October 2010, Microsoft filed a patent infringement lawsuit against Motorola alleging several patents (including two of the FAT32 filesystem patents) were not licensed for use in the Android operating system.[48] They also submitted a complaint to the ITC.[49]
Developers of open source software have designed methods intended to circumvent Microsoft's patents.[50]
|
|