Organization of the File Allocation Table
The File Allocation Table is a map of all the clusters that make up the data area of the volume. The FAT does not “know” the location of the first cluster that has been allocated to a given file. It does not even know the name of any files. That information is stored in the directory.
As described in the section above, the directory entry for each file contains a value called a cluster address. This is a pointer to the first entry in the File Allocation Table for a given file. This FAT entry in turn points to the first cluster in the volume’s data area that has been allocated to the file.
If the file has been allocated more than one cluster, then the FAT table entry will contain the address of the second cluster (which is also the index number of the second cluster’s entry in the FAT table). The second cluster entry points to the third, and so forth. A FAT entry like this forms a linked list commonly called a cluster chain.
Figure - File Allocation Table and Directory Entry relationship illustrates the relationship between the directory entry and the FAT.
In the figure above, the directory entry for a file points to the 40th entry in the FAT table. The 40th entry points to the 41st, the 41st to the 46th; the 46th is not a pointer, as the entry contains a special end-of-cluster-chain marker. This means that the 41st cluster is the final cluster allocated to the file.
Other entries in the FAT area illustrated in the figure above are either not allocated to a file, or allocated to a file whose cluster chain is terminated by the 43rd entry.
To summarize, a cluster’s entry in the File Allocation Table typically contains a pointer to the entry for the next cluster in a file’s cluster chain.
Other values that can be stored in a cluster’s entry in the FAT are special markers for:
- End-of-cluster-chain: this cluster is the final cluster for a file.
- Cluster-not-allocated (free cluster mark): no file is using this cluster.
- Damaged-cluster: this cluster cannot be used.
NOTE: Updating the FAT table is time consuming, but updating it frequently is very important. If the FAT table gets out of sync with its files, files and directories can become corrupted, resulting in the loss of data (see Optional Journaling System).