File Allocation Table


This document will be surprisingly short. By now, you should already know what File Allocation Table is, how to use it, and where it is located. I can only add a couple of notes.

FAT is just an array of values. Values are either 12 or 16 or 32 bits wide. Indices start from zero. The very first value, FAT[0] is reserved and it contains the media description byte, sign-extended to the necessary width. Because of the way this byte is chosen, the resulting value falls right within the range of the reserved values in FAT. This entry is a symbolic representation of a boot sector and other reserved sectors. It is always followed by EOF. Thus, FAT[1]=EOF. This entry represents FAT itself. Therefore, the entries with the indices 2 through NumberOfClusters-1 are available. You should always watch for the cluster numbers that are out of range.

FAT disks usually contain two copies of FAT. The next copy of FAT immediately follows the previous one. In FAT12 and FAT16 systems all copies of FAT are kept in synch with each other, but only the first copy is ever read. Microsoft claims that the next copies of FAT are used when the first one is physically unusable, but it is not true for all versions of their systems. In FAT32 there exists a field in the BPB that tells which copy to use and whether to synchronize all copies.

Finally, data in FAT is stored in Intel little endian order. Note that the high four bits in FAT32 are reserved and should be masked out when reading from FAT. They should not be changed when writing to FAT either. It also concerns EOF and other special values. In FAT12, the entries are one and a half bytes long. So, use the following steps to read the value from FAT12:

Writing the value to FAT12: For FAT16 and FAT32 just multiply the cluster by the size of the FAT entry and use it as an offset in FAT. Don't forget to mask out the high four bits when working with FAT32.



Author:  Alex Verstak  3/10/1998