2.3 Compound File FAT Sectors
The FAT is the main allocator for space within a compound file. Every sector in the file is represented within the FAT in some fashion, including those sectors that are unallocated (free). The FAT is a sector chain that is made up of one or more FAT sectors.
Figure 11: Sectors of a FAT array
The FAT is an array of sector numbers that represent the allocation of space within the file, grouped into FAT sectors. Each stream is represented in the FAT by a sector chain, in much the same fashion as a FAT file system.
The set of FAT sectors can be considered together as a single array. Each entry in that array contains the sector number of the next sector in the chain, and this sector number can be used as an index into the FAT array to continue along the chain.
Special values are reserved for chain terminators (ENDOFCHAIN = 0xFFFFFFFE), free sectors (FREESECT = 0xFFFFFFFF), and sectors that contain storage for FAT sectors (FATSECT = 0xFFFFFFFD) or DIFAT Sectors (DIFSECT = 0xFFFFFFC), which are not chained in the same way as the others.
The locations of FAT sectors are read from the DIFAT. The FAT is represented in itself, but not by a chain. A special reserved sector number (FATSECT = 0xFFFFFFFD) is used to mark sectors that are allocated to the FAT.
A sector number can be converted into a byte offset into the file by using the following formula: (sector number + 1) x Sector Size. This implies that sector #0 of the file begins at byte offset Sector Size, not at 0.
The detailed FAT sector structure is specified below.
Next Sector in Chain (variable)
Next Sector in Chain (variable): This field specifies the next sector number in a chain of sectors.
If Header Major Version is 3, there MUST be 128 fields specified to fill a 512-byte sector.
If Header Major Version is 4, there MUST be 1,024 fields specified to fill a 4,096-byte sector.
The last FAT sector can have more entries that span past the actual size of the compound file. In this case, the entries that cover past end-of-file MUST be marked with FREESECT (0xFFFFFFFF). The size of a compound file is determined by the index of the last non-free FAT array entry. If the last FAT sector contains an entry FAT[N] != FREESECT (0xFFFFFFFF), the file size MUST be at least (N + 1) x (Sector Size) bytes in length.
DIFAT Sectors (DIFSECT = 0xFFFFFFC), which are not chained in the same way as the others.
Sectors that contain storage for FAT sectors (FATSECT = 0xFFFFFFFD).
Chain terminators (ENDOFCHAIN = 0xFFFFFFFE).
Free sectors (FREESECT = 0xFFFFFFFF).