Source: Offset Address calculation formula for pure natural FAT1 tables
First the FAT table generally has two, the other one for backup. Natural two tables are close to each other, as long as calculated the offset of the FAT1 table and the size of the fat table can be offset by the FAT2 table. Pure Natural The offset address of the FAT1 table is calculated as follows [4]:
FAT1 Table offset = number of reserved sectors * Bytes per sector
As shown in Figure 2, in this example, the offset of the FAT1 table = 1016 * B = 520192 = 0x7f000. Similarly:
Offset of FAT2 table = size of Fat1+fat table = (number of reserved sectors + FAT table sectors) * Number of bytes per sector
In this example, the offset of the FAT2 table = (1016 + 7684) * B = 4454400 = 0x43f800. Using the program described in the previous article, you can read out the contents of the two fat tables, in general the contents of the two tables should be exactly the same. I read the first fat table from the beginning of the content, as shown in Figure 3:
Figure 3 Fat table start part content
4, Fat table items before analyzing fat table to explain the composition of fat. The Fat table is the file allocation table (Allocation). The FAT32 file table is a table of table items, each of which consists of a 32-bit binary, whose value corresponds to the use of the corresponding cluster, such as the 2nd table entry corresponds to the use of cluster 2nd, the 3rd table item corresponds to the use of cluster 3rd, and so on. (Exceptions are No. 0 and 1th, as explained below). The meaning of the corresponding numeric value for each table item is shown in table 1 [2]:
Table Item Value |
corresponding meanings |
0x00000000 |
Free clusters, which means available |
0x00000001 |
Preserving clusters |
0x00000002-0x0fffffef |
The cluster that is occupied, whose value points to the next cluster number |
0x0ffffff0-0x0ffffff6 |
Reserved values |
0x0ffffff7 |
Bad cluster |
0x0ffffff8-0x0fffffff |
The last cluster of a file |
Table 1 Table Item numeric meanings
The specific rules for each entry are as follows: If the cluster is the last cluster of the file, the value entered is 0X0FFFFFFF, and if the cluster is not the last cluster of the file, the value filled in is the next cluster number that the file occupies (so we can see that the file is saved as a cluster chain in FAT32). Below we are based on the actual situation, figure 3 to analyze the meaning of fat table.
Fat table Item No. 0 (0x00000000~0x00000003): 0x0fffff8
Fat table Item 1th (0x00000004~0x00000007): 0xFFFFFFFF
These two items do not represent the use of any cluster, but the table header of the Fat table, characterizing the media description, is a fixed value, so 0x00 and 0x01 are not the two clusters, the cluster number of the subscript starting from 2. The 1th list entries may be used to record dirty flags to indicate that the file system has not been unloaded properly or that there is an error on the disk surface. Next
Fat table Item 2nd (0X00000008~0X0000000B): 0x0fffffff
The 2nd item stores the usage of the 2nd cluster, usually the 2nd cluster stores the root directory of the file system. Although the location of the root directory is no longer rigidly fixed in the FAT32 file system, it can be stored in any cluster that can be addressed within the partition, although the root directory is usually the oldest (formatted) Table of contents. So, what we see is basically the first cluster in the root directory next to FAT2, which is the 1th cluster in the sequence of clusters (that is, cluster 2nd). At the same time, the FAT32 file system looks at the root directory as a normal data file, all without the limit of the number of directory items, can allocate empty clusters when needed, store more directory entries [1].
The value of this entry is 0X0FFFFFFF, which indicates that the root directory is occupied and occupies only 1 clusters.
Fat Table 3rd ...
Here is a little digression, the smallest unit of FAT32 format file allocation is the cluster. Which means you're storing an actual size.1kBFile, then the storage space it occupies is still1The cluster (converted here to size is8*512b = 4KB)。 The author of a practical example to illustrate: in the U disk to put a8BSize of the Temp.txt file, and then view the file properties when it finds that its footprint is4KB, in accordance with the theory that we speak above.
Figure 4 Size and footprint of temp.txt
Looked at the next space is almost, then this article about the Fat table part to this end. In fact, there is not much content, I think of where to drag, nonsense of some other things. The rest of the data section will be left in the next article. In the same way, some of the contents of this article are the author's own thinking and even speculation, if there is a wrong place to welcome correct, lest fraught (laughter).