The convention in this document: the number of "0x" with prefix is a 16-way number. Any other numbers that have no prefix "0x" are 10 credits. All code snippets in this document are used in 'c' language. However, there is no strict compliance with its code input specification and grammar. Some code snippets in this document use 32-bit and 16-bit data elements. We assume that you are a programmer who knows how to convert 32-bit data into 16-bit data (guaranteed data is not lost). At the same time, it must be noted that all data types are unsigned. Do not use a symbolic integer data to perform the calculations required to make a FAT table, as this calculated result is incorrect to some FAT systems. General Concepts (suitable for all types of FAT file systems) All FAT file systems are initially developed for IBM PC architecture. It is important to: The data structure of the FAT file system on disk is "small end" (a data storage organization form). Let's take a look at a 32-bit FAT entry, which is stored on disk in 4 8-bit bytes ----- The first byte is Byte [0], the last one is Byte [4] ------ The following shows a 32-bit data, from 00 ID, until 31. (00 is the least important one)
Byte [3] 3 3 2 2 2 2 2 2 1 0 9 8 7 6 5 4
Byte [2] 2 2 2 2 1 1 1 1 3 2 1 0 9 8 7 6
Byte [1] 1 1 1 1 1 1 0 0 5 4 3 2 1 0 9 8
Byte [0] 0 0 0 0 0 0 0 0 7 6 5 4 3 2 1 0
If you use the machine based on "big end", some of the above principles is very important. Because you want to exchange data with the disk, you must convert between the big end and the small end.
A FAT file system consists of the following four basic districts, they are:
0 --- Reserved Area 1 --- FAT Region 2 - Root Catalog Zone (there is no existence in the FAT32 system) 3 --- File and Directory Data Area
Start sector and bpb (Bios Parameter Block)
In the FAT system, a very important data structure that is first encountered is BPB (BIOS paramere block), which is placed in the first sector of the reserved area. This sector is also called "start sector", "reserved sector" or "0nd sector", and it is important that it is in the first sector of the system. With the FAT file system, it is often confused. In the MS-DOS 1.x version, there is no BPB structure in the boot sector. In the first version of the FAT file system, only two different forms, one supports single-sided, a floppy disk that supports double-sided 360k 5.25-Inch. To determine the type of file system on the disk, you must view the first byte of the FAT table (lower 8 bits of FAT [0]). The judgment method of the above media type has been replaced by a BPB structure to a start-up sector in MS-DOS 2.x, and an old-fashioned method (by viewing the first byte of the FAT) has No longer supported. All FAT systems have a BPB structure placed in the boot sector. This will bring us the first level of confusion of FAT system types: what is the BPB structure? The BPB structure in the MS-DOS 2.x boot sector is strictly limited to the size of the FAT system cannot be greater than 65,536 sectors (32MB, 512 bytes per sector). This limitation is due to the "Total Sectors" field in the FAT table is a 16-bit domain. This limitation is corrected in MS-DOS 3.x, modifying the BPB structure to enable the total number of sectors supported by 32-bit fields. The change in the next BPB occurs under Windows 95 operating system, while FAT32 is introduced. FAT16 limits the maximum size of the FAT table and the size of the maximum available cluster cannot exceed 2GB (assuming that the disk is 512 bytes per sector). FAT32 modifies the limit of this disk capacity such that the FAT system can exist on a disk having a capacity greater than 2GB only a zone. The FAT32's BPB structure is perfectly compatible with the FAT12 / FAT16 BPB structure and adds a domain -bpb_totsec32. They start from offset 36 or FAT12 / FAT16 or FAT32, and different (see the discussion about FAT type). Here, the associated point is that the BPB structure in the FAT system start sector should always contain a new BPB domain so that FAT12 / FAT16 or FAT32 can be used. In this way, it is guaranteed that the FAT file system has the best compatibility, but also guarantees that all FAT systems can distinguish, so that you can better support file systems. Because there is always all defined domains. Note: In the following description, all domains named by BPB_ are part of BPB. All domains named by BS_ are part of the boot sector and are not bpb. The starting portion of the 0 sector of a FAT file system is shown below, which contains the BPB structure.
From here, the BPB structure / start sector of FAT12 and FAT16 starts and FAT32 is different. The first table below shows the structure after the FAT12 and FAT16 start sector shift 36: