Detailed description of FAT32 File System

Source: Internet
Author: User

Hard Disks are used to store data. For ease of use and management, the data is stored in the hard disk as files. Any operating system has its own file management system, and different file systems have different logical organization methods. For example, common file systems include FAT, NTFS, EXT, UFS, HFS +, and so on. I will talk about the FAT32 File System Based on Windows in the following articles.

The FAT32 file system consists of DBR and Its reserved sector, FAT1, FAT2, and DATA. Its Mechanism is as follows:

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/140110/0423306442-0.jpg "title =" 1.png" alt = "wKioL1LLT7nxfthkAAArvJ7ngmE694.jpg"/>

These structures are created when the partition is formatted. The meanings are as follows:

DBR and Its reserved sectors: DBR indicates a DOS Boot Record, also known as an operating system Boot Record. After DBR, there are usually some reserved sectors.

FAT1: FAT indicates a file allocation table. FAT32 generally has two copies of FAT, and FAT1 is the first copy, which is also the primary FAT.

FAT2: FAT2 is the second File Allocation Table of FAT32 and is also a backup of fat1.

DATA: DATA is the main area of the FAT32 file system, including the directory area.


I. Analyze the DBR OF THE FAT32 File System

The dbr of the FAT32 file system consists of five parts: Jump command, OEM code, BPB, Bootstrap program, and end sign. Such as DBR of a complete FAT32 file system.

650) this. length = 650; "src =" http://www.bkjia.com/uploads/allimg/140110/042330DX-1.jpg "title =" 2.png" width = "500" height = "357" border = "0" hspace = "0" vspace = "0" style = "width: 500px; height: 357px; "alt =" wKiom1LLUHGgknhHAAGkc-UgO5Q090.jpg "/>

Jump command: It takes 2 bytes to jump the program execution process to the pilot program.

OEM code: This part occupies 8 bytes, and its content is arranged by the OEM who created the file system.

BPB: The BPB of FAT32 starts from the 12th bytes of DBR and occupies 79 bytes. It records important information about the file system. The parameters are described as follows:

650) this. length = 650; "src =" http://www.bkjia.com/uploads/allimg/140110/04233024P-2.jpg "title =" 3.png" width = "700" height = "139" border = "0" hspace = "0" vspace = "0" style = "width: 700px; height: 139px; "alt =" wKioL1LLUOyRCx8vAAB2zWiNedE813.jpg "/>

650) this. length = 650; "src =" http://www.bkjia.com/uploads/allimg/140110/04233064L-3.jpg "title =" 4.png" width = "700" height = "211" border = "0" hspace = "0" vspace = "0" style = "width: 700px; height: 211px; "alt =" wKiom1LLe2DwevFzAACqRwFUOUY487.jpg "/>

The FAT32 file system arranges a file system information sector in the reserved sector of DBR to record the number of idle clusters in the Data zone and the cluster number of the next idle cluster, this slice is generally located in the No. 1 slice of the partition, that is, the slice following DBR, which is as follows:

650) this. length = 650; "src =" http://www.bkjia.com/uploads/allimg/140110/0423302459-4.jpg "title =" 5.png" width = "500" height = "435" border = "0" hspace = "0" vspace = "0" style = "width: 500px; height: 435px; "alt =" wKiom1LLUZOQTvOJAAF1cveUbmw760.jpg "/>

The parameters are described as follows:

650) this. length = 650; "src =" http://www.bkjia.com/uploads/allimg/140110/0423303C7-5.jpg "title =" 6.png" width = "700" height = "213" border = "0" hspace = "0" vspace = "0" style = "width: 700px; height: pixel PX; "alt =" wKioL1LLUayjqXzeAAB_VWKMAuo360.jpg "/>

Bootstrap code: FAT32 DBR Bootstrap occupies 420 bytes, Which is useless for partitions without operating systems installed.

Ending MARK: The ending mark of DBR is the same as that of mbr and ebr, which is "55 AA ".


Ii. Analyze the fat table of the FAT32 File System

The content of FAT1 is as follows:

Since partition formatting does not write too much data, there are very few FAT items.

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/140110/0423304242-6.jpg "title =" 7.png" alt = "wKiom1LLUnaTOkgJAACCopPnP58159.jpg"/>

Structure and Function of the FAT table

1. FAT32 files generally have two copies of FAT, which are created by the formatting program during partition formatting. FAT1 is the master, and FAT2 is the backup.

2. FAT1 follows DBR. The specific address is specified by DBR's BPB parameter, and FAT2 follows fat1.

3. The FAT table consists of FAT table items. We refer to FAT table items for short. Each FAT item occupies 4 bytes.

4. Each FAT item has a fixed number, which starts from 0.

5. The first two FAT items in the FAT table are reserved by the file system. FAT 0 is the media type, and FAT 1 is the file system error mark.

6. Each cluster in the partitioned data area is mapped to the unique FAT item in the FAT table, because FAT 0 and FAT 1 are occupied by the system, user data is recorded starting from FAT 2.

7. If a file occupies many clusters, the first FAT item records the number of the next FAT item, which is a cluster number.) If the file ends, it is represented by "0F FF.

8. After partitioning and formatting, user files are stored in the data zone in clusters. A file occupies at least one cluster.

9. The main function of FAT is to indicate the storage medium and cluster usage of the partition.


The method for locating the absolute position of FAT is as follows:

1. First, find the starting sector of the partition from the MBR Partition Table and offset it to this sector.

2. Find the number of reserved sectors of DBR, the number of FAT tables, and the size of the FAT table from dbr bpb.

3. Therefore, FAT1 = partition start sector + DBR reserved sector, FAT2 = partition start sector + DBR reserved sector + FAT1.


3. analyze the data zone of the FAT32 File System

The data zone is located behind FAT2. The specific Positioning method is as follows;

1. Obtain the start position of the partition based on the partition table information in the MBR.

2. Know the number of reserved sectors of DBR, the size of the FAT table, and the number of FAT tables through DBR in the partition.

3. You can find the starting position of the Data zone through the above information. The root directory is the starting sector of the Data zone + the cluster size * 2 ).


The category of the data area consists of the root directory, sub-directories, and file content. In the data area, clusters are stored in units. Cluster 2 is allocated to the root directory.

Root directory: root directory = partition start sector + DBR reserved sector + FAT table * 2) + cluster size * 2)

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/140110/042330D07-7.jpg "title =" 8.png" alt = "wKiom1LLWxKSM0PwAACNLrmNTVc897.jpg"/>

In the FAT32 file system, all the files and directories under the root directory of the partition are placed in the root directory, and all the files and directories in the subdirectories are placed in the subdirectory area, and each 32 bytes is not a directory item. Each directory item records one directory or file, or multiple directory items record one file or directory ), as shown in.

In the FAT32 file system, directory items can be divided into four categories: volume label directory items, "." and ".." directory items, short file name directory items, long file name directory items.

Volume label directory item: the volume label is the name of the partition. It can be created when the partition is formatted or modified at will. The length is 11 bytes.

"." And "..." directory items: "." indicates the current directory, and ".." indicates the previous directory. These two directory items exist in multiple subdirectories.

Short file name directory item: the so-called short file name is in the "8.3" format of the file name, this format supports the main file name cannot exceed 8 bytes, the extension cannot exceed 3 bytes. The short file name directory is always stored in one directory.

Parameters for short file names are described as follows:

650) this. length = 650; "src =" http://www.bkjia.com/uploads/allimg/140110/0423301329-8.jpg "title =" 9.png" width = "462" height = "350" border = "0" hspace = "0" vspace = "0" style = "width: 462px; height: 350px; "alt =" wKioL1LLZaryRrZbAAEU013v_ho125.jpg "/>

The time expression is as follows:

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/140110/04233054G-9.jpg "title =" 10.png" alt = "wKioL1LLaIKhSRWBAABJ-d63uVU365.jpg"/>

The expression of date is as follows:

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/140110/0423306159-10.jpg "title =" 11.png" alt = "wKiom1LLaM7AfCeHAABJ0UIbWsc692.jpg"/>

Long file name directory item: Because the short file name "8.3" format is far from meeting the actual needs, so there is a long file name, long file name is actually to segment the file name, it is divided into several short file names for storage.

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/140110/042330O54-11.jpg "title =" 14.png" alt = "wKiom1LLdkTjJJoeAAChWw_qpQo810.jpg"/>

When storing long file names in segments, follow these three processing principles:

1. Add "~ 1 "to form a short file name with the same extension;

2. If a file with this name already exists, the symbol "~" The number is automatically increased;

3. If the file name contains invalid windows characters, the following line is marked;

4. Directory items with long file names are recorded in reverse mode, for example.

The following is an explanation of the parameters of the long file name directory.

650) this. length = 650; "src =" http://www.bkjia.com/uploads/allimg/140110/0423302051-12.jpg "title =" 12.png" width = "500" height = "95" border = "0" hspace = "0" vspace = "0" style = "width: 500px; height: 95px; "alt =" wKioL1LLbN3DTdvXAABXaWgL6jM246.jpg "/>

650) this. length = 650; "src =" http://www.bkjia.com/uploads/allimg/140110/0423303U4-13.jpg "title =" 13.png" width = "500" height = "77" border = "0" hspace = "0" vspace = "0" style = "width: 500px; height: 77px; "alt =" wKioL1LLbKOxoS_oAABFm_xFUtY021.jpg "/>


FAT32 File System Summary

The above content has briefly introduced the FAT32 file system. The following describes in detail how the FAT32 file system stores data based on a specific file.

1. the start position of the partition is determined based on the MBR Partition Table of the disk No. 0 sector, which is DBR;

2. Based on the BPB record information in DBR, we know the number of reserved sectors, FAT size, and FAT number of DBR;

3. Based on the above information, the starting position of the data can be calculated. The data zone = the starting sector of the partition + DBR reserved sector + FAT table * 2 );

4. Calculate the absolute location of the root directory. The root directory = the starting sector of the data area + cluster size * 2 );

5. According to the directory item information in the root directory, it is known that the files and subdirectories in the root directory correspond to clusters;

6. Find the absolute sector of the file content based on the file cluster number;

7. If a file occupies multiple clusters, you need to know the cluster number of the next data cluster based on the FAT table item.

7. If the directory item in the root directory is a subdirectory, the cluster number of the file content will be known Based on the file directory item in the subdirectory;

8. If there are subdirectories in the subdirectory, keep searching for them based on this method.


Now, the FAT32 File System has been simplified and I hope it will help those who like the underlying data.


Author: Deng Qi

TEL: 18911808630



This article is from "Deng Qi's Blog" Blog, please be sure to keep this source http://dengqi.blog.51cto.com/5685776/1349327

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.