DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Managing filesystem types

The file allocation table

The file allocation table, or FAT, keeps track of the allocation of clusters on the disk.

A cluster is the smallest unit of allocation in the dosfs filesystem type. The BPB parameter ``sectors per cluster'' tells the size of a cluster in number-of-sectors. Each cluster has a corresponding entry in the FAT that describes its current usage:

FAT fields are 12 bits long in a FAT12 filesystem and 16 bits long in a FAT16 filesystem. A dosfs filesystem is either FAT12 or FAT16, depending on the size of the medium (12 bits if the disk contains fewer than 4087 clusters, 16 bits otherwise). FAT32 fields are 32 bits long. A filesystem is FAT32 if it has more than 65,526 clusters.

The first two fields in the FAT are always reserved. On IBM-compatible media, the first 8 bits of the first reserved FAT entry contain a copy of the media descriptor byte, which is also found in the BIOS parameter block in the boot sector. The second, third, and (if applicable) fourth bytes, which constitute the remainder of the first two reserved FAT fields, always contain 0X0FF.

When a DOS file is created or extended, disk sectors are assigned to it from the files area in powers of 2, known as ``allocation units'' or ``clusters''. The number of sectors per cluster for a given medium is defined in the BIOS parameter block and can be found at offset 0DH in the disk's boot sector. The IBM family of personal computers uses the following assignments:

Disk Type Power of 2   Sectors/Cluster
Single-sided floppy disk 0 = 1
Double-sided floppy disk 1 = 2
PC/AT fixed disk 2 = 4
PC/XT fixed disk 3 = 8

Aside from the first two reserved entries of the FAT, the remainder of the entries describe the usage of their corresponding disk clusters. The contents of the FAT fields are interpreted as follows:

FAT12 Value FAT16 Value FAT32 Value Meaning
000h 0000h 00000000h cluster available
FF0-FF6h FFF0-FFF6h 0FFFFFF0-0FFFFFF6h reserved cluster
FF7h FFF7h 0FFFFFF7h bad cluster, if not part of chain
FF8-FFFh FFF8h-FFFFh 0FFFFFF8h-0FFFFFFFh last cluster of file
XXXh XXXXh 0XXXXXXXh next cluster in file

At the computer manufacturer's option, two or more identical copies of the FAT can be maintained on each filesystem (called a ``volume'' in MS-DOS). All copies are updated simultaneously whenever files are extended or the directory is modified. If access to a sector in a FAT fails due to a read error, the other copies are tried until a successful disk read is obtained or all copies are exhausted. Thus, if one copy of the FAT becomes unreadable due to excessive wear or a software accident, the other(s) might still allow the files on the disk to be salvaged. As part of its procedure for checking the integrity of a disk, the fsck command compares the multiple copies (usually two) of the FAT to make sure they are both readable and consistent.


© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 22 April 2004