|
exFAT - File Allocation Table (FAT)
File Allocation Table (FAT) may contain 1 or 2 FATs, as defined in NumberOfFats field. ActiveFat field in VolumeFlags in the Main Boot Sector determines which FAT is active.
The first cluster is cluster 2, as in FAT32. Each FatEntry represents one cluster.
In exFAT, FAT is not used for tracking an allocation; an Allocation Bitmap is used for this purpose. FAT is only used for keeping chains of clusters of fragmented files. If a file is not fragmented, FAT table does not need to be updated. A Stream Extensions Directory Entry should be consulted to determine if the FAT chain is valid or not. If FAT chain is not valid, it does not need to be zeroed.
| | | | | | | Media type (should be 0xFFFFFFF8) | | | | | | | | | | | | | | | FatEntry[ClusterCount + 1] | | | | |
|
Valid values of FAT entries: - 0x00000002 — ClusterCount +1 (max 0xFFFFFFF6) — next cluster in the chain
- 0xFFFFFFF7 — bad cluster
- 0xFFFFFFF8 — media descriptor
- 0xFFFFFFFF — end of file (EOF mark)
Value 0x00000000 does not mean the cluster is free, it is an undefined value. The second FAT table (presents only in TexFAT) is located immediately after the first one and has the same size.
Cluster Heap
The cluster heap is a set of clusters which hold data in exFAT. It contains: - Root Directory
- Files
- Directories
- Bitmap Allocation Table
- UP-Case Table
The allocation status of clusters in cluster heap is tracked by Bitmap Allocation Table which itself located inside the cluster heap.
从上述描述可以知道,exFAT 在很多方面都像 FAT32。它的 FAT 表项(簇号)都是 32 位的,所以,它不是 FAT64。它可以看成是改进型的 FAT32。
与 FAT32 不同,exFAT 的 FAT 表是专门用来服务于“文件碎片”的。FAT32 的文件分配表还用于跟踪空间的分配情况。在 exFAT 中,开辟了新的 “职能部门”—— Bitmap Allocation Table ——用于跟踪空间分配情况。文件无碎片时,可以不更新对应的 FAT 表项。这意味着,当文件无碎片时,FAT 表里面的原有记录,可能是错的,不能反映真实的分配情况。
我觉得还是更新了好。一个连续的文件,更新一下 FAT 表,也不会造成多大的性能损失。好处是确保 FAT 表能够反映真实分配情况。这样,第三方工具恢复误删的文件,成功的可能性就大一些。 Bitmap Allocation Table 只对提升性能有用。一个精简的文件系统,不需要 Bitmap Allocation Table,就是说,原先的 FAT32 的那种处理,就算是可以了。
再一个细节的讨论,就是有关“0xFFFFFFFF — end of file (EOF mark)” 的。这是文件的最后一簇,它没有后续的簇号,因此,使用了 0xFFFFFFFF 来当作结束的标志。但是,这个结束标志带来的信息却仅仅是 “结束”而已,没能提供更加有用的信息。在设计某个新的文件系统时,如果用该文件的起始簇号来取代此处的 0xFFFFFFFF,则能够提供有价值的信息。就是说,当遇到起始簇号时,就认为到达了文件的结尾,这完全能够清晰地表明文件“结束”了。这样做的好处是,第三方恢复工具能够从一个 chain 的随便某个簇号开始,顺藤摸瓜,最终能找到起始簇号。如果是以 0xFFFFFFFF 结束,则无法方便快捷地找到起始簇号(需要遍历整个 FAT 表,才能找到起始簇号)。
|