FAT32 File System detailed

Source: Internet
Author: User
Tags reserved

The hard disk is used to store data, which is stored on the hard disk as a file for ease of use and management. Any operating system has its own file management system, and different file systems have their own different logical organization mode. For example: The common file system has fat,ntfs,ext,ufs,hfs+ and so on. The article in the post of the author will talk about it, so let's learn about the Windows-based FAT32 file system.

The FAT32 file system consists of DBR and its reserved sector, FAT1,FAT2 and data four parts, with the following figure:

These structures are created when the partition is formatted, and the meanings are explained as follows:

DBR and its reserved sectors: The meaning of DBR is the DOS boot record, also known as the operating system boot record, there are often some reserved sectors after DBR.

Fat1:fat meaning is the file allocation table, FAT32 generally have two parts fat,fat1 is the first, is also the main fat.

FAT2:FAT2 is the second file allocation table for FAT32 and a backup of FAT1.

Data:data, which is the data area, is the primary area of the FAT32 file system, which contains the directory area.


I. Analysis of DBR in the FAT32 file system

The DBR of the FAT32 file system consists of 5 parts, namely jump instruction, OEM code, BPB, boot program and end sign. The following figure is a complete FAT32 file system for DBR.

Jump instruction: itself occupies 2 bytes It jumps the program execution process to the bootloader.

OEM Code: This section accounts for 8 bytes, and its content is specifically arranged by the OEM manufacturer who created the file system.

Bpb:fat32 's BPB, which starts with the 12th byte of DBR, takes up 79 bytes and records important information about the file system, each of which is explained in the following table:

The FAT32 file system arranges a file system Information sector in the reserved sector of the DBR to record the number of free clusters in the data area and the cluster number of the next free cluster, which is typically in sector 1th of the partition, that is, a sector immediately following the DBR, as follows:

The parameters are explained as follows:

Bootloader code: The FAT32 dbr bootloader consumes 420 bytes and is useless for partitions that do not have an operating system installed.

End flag: The end sign of DBR is the same as the end sign of MBR,EBR, which is "AA".


Analysis of fat Table of FAT32 file system

The contents of FAT1 are as follows:

Because there is not too much data written after the partition is formatted, there are very few fat entries.

FAT table structure and function

1, FAT32 files generally have two copies of fat, they are created by the formatter when the partition is formatted, FAT1 is the main, FAT2 is a backup.

2, FAT1 after the DBR, its specific address is specified in the BPB parameter of DBR, FAT2 followed by FAT1.

3, Fat table is composed of fat table items, we put fat table term for short fat term, each fat item occupies 4 bytes.

4, each FAT item has a fixed number, this number starts from 0.

5. The first two fat entries of the Fat table are reserved for the file system, the No. 0 fat is the media type, and the 1th number is the file system error flag.

6. Each cluster in the data area of the partition is mapped to the only fat item in the Fat table, because the fat and 1th fat of No. 0 are consumed by the system, and the user's data starts with the number 2nd fat record.

7. If a file occupies many clusters, the first FAT entry records the number of the next FAT item (both cluster number), and if the file is closed, it is denoted by "0F FF FF FF".

8, after the partition format, the user file is stored in a cluster in the data area, a file occupies at least one cluster.

9, the main role of fat is to indicate the partition storage of media and the use of clusters.


The method for locating the fat absolute position is as follows:

1, first from the MBR partition table to know the starting sector of the partition, offset to this sector.

2. From the BPB of DBR, we know the number of reserved sectors of DBR, the number of fat table and the size of fat table.

3, so fat1= partition starting sector +DBR reserved sector, fat2= partition start Sector +DBR reserved Sector +FAT1.


Analysis of data area of FAT32 file system

The location of the data area is behind FAT2, and the specific positioning method is as follows;

1, through the MBR of the partition table information to know the starting position of the partition.

2, through the partition of DBR to know the number of reserved fan zone DBR and fat table size, fat table number.

3, through the above information can find the starting position of the data area, root = Data area of the starting sector + (cluster size * *).


The class capacity of the data area consists mainly of three parts: the root directory, the subdirectory, and the file contents. The data area is stored in "clusters", and cluster 2nd is allocated to the root directory for use.

Root directory is positioned as: root = partition start Sector +DBR reserved sector + (FAT table *) + (cluster size * *)

In the FAT32 file system, files and directories under the partition root are placed in the root zone, files and directories in subdirectories are placed in subdirectories, and no 32 bytes are a directory entry, and each directory entry records a directory or file (or possibly multiple directory entries that record a file or directory). As shown in the figure above is a catalog item.

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

Volume Label directory entry: The label is the name of the partition, can be created when the partition is formatted, or can be arbitrarily modified, the length is 11 bytes.

“.” and ".." Catalog entry: "." Represents the current directory, "..." Represents a previous level of directory. These two directory entries are in subdirectories.

Short file name directory entry: The so-called short file name "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 a directory entry.

The parameters for short filenames are explained as follows:

The way in which time is expressed is as follows:

The dates are expressed in the following ways:

Long File name directory entry: Because the short file name "8.3" format is far from satisfying the real needs, so there is a long file name, the long file name is actually the file name is segmented, divided into several short filenames to store.

Long filenames follow the three processing principles when staging storage:

1, the system takes a long file name of the first 6 characters plus "to" form a short name, its extension is unchanged;

2, if the name of the file already exists, then the symbol "~" after the number automatically increased;

3, if there is illegal Windows characters in the file name, the following underscore "_" instead;

4. Long file name directory entries are recorded in flashbacks, as shown above.

As follows: explanation of the parameters of the long file name directory


FAT32 File System Summary

The above content has simply introduced the FAT32 file system, the following according to locate a file to learn more about how the FAT32 file system is stored data.

1, according to disk NO. 0 sector MBR partition table to know the starting position of the partition, both DBR;

2, according to the BPB recorded in DBR, the number of DBR reserved sectors, fat size, fat number;

3, according to the above information can calculate the starting position of the data, data area = partition starting Sector +DBR reserved sector + (FAT table);

4, the absolute location of the root directory is calculated, Root = The data area of the starting sector + (cluster size * *);

5, according to the directory entry information in the root directory, the root directory of the files and sub-directories and other corresponding clusters;

6, according to the file's cluster number can find the absolute sector of the file content;

7. If a file occupies multiple clusters, you will need to know the cluster number of the next data cluster according to the Fat table.

7, if the directory entry under the root directory is a subdirectory, then according to the subdirectory of the file directory entry to know the contents of the file cluster number;

8, if there are subdirectories in subdirectories, then according to this method has been looking down.


At this point FAT32 file system company finished, hope to those who like the bottom of the data to help friends.


Author: Dunch

tel:18911808630



This article is from the Dunch blog, so 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.