Storage organization structure of FAT32 file system (i)

Source: Internet
Author: User
Tags closing tag

The physical structure of the disk. With a more in-depth understanding of the logical structure and storage structure, we discuss the storage organization structure of the FAT32 file system in detail.

When it comes to the organizational structure of the file system, we should immediately realize. This refers to the structure of the filesystem within the same partition, and on this topic we are fully able to do everything outside of the partition.

To analyze the storage structure of the FAT32 file system, we set up a real file system: Insert the USB stick into the computer and format the USB stick into the FAT32 partition format:

Based on the built-in USB FAT32 file system, the following sections are presented separately from the file system.

Partition Boot Sector DBR

Open the USB flash drive with Winhex Demo Sample for example:

This is the FAT32 partition boot record, as defined by the following:

Offset 00h:3 byte of jump instruction EB 58 90, skip the following BPB and Extensions BPB section

Offset 03h:8 bytes of hard disk partition type text character name: 4D 4F, 2E 30 that is: MSDOS5.0

Offset 0bh:25 bytes of the partition block (BPB), subdivided for example the following:

Offset 0BH: Sector bytes 00 02 that is 0x0200,512 bytes

Offset 0DH: Number of sectors per cluster 08 that contains 8 sectors per cluster

Offset 0EH: Number of reserved sectors 24 00 that is 36 sectors reserved

Offset 10h:fat 02-Two Fat table

Offset 11H: unused 00 00

Offset 13H: unused 00 00

Offset 15H: Media type F8 local hard drive

Offset 16H: unused 00 00

Offset 18H: Number of sectors per track 3F 00 i.e. 63 sectors per track

Offset 1AH: Head number FF 00 i.e. 255 heads

Offset 1CH: Number of hidden sectors 1F = 8,064 hidden Sectors

Offset 20H: Total disk sector number F0 77 00 is a total of 7,860,352 sectors (7860352*512=4024500224. Because my USB stick is 4G)

An extended partition reference block (extended BPB) that offsets the 24h:52 byte. Segments such as the following:

Offset 24h:fat table occupy sector number EE 1D 00 00 i.e. FAT table 7,662 sectors

Offset 28H: unused 00 00 00 00

Offset 2CH: Root folder entry cluster number 02 00 00 00 That is, the root folder starts from cluster No. 02

Offset 30H: File System Information Sector Code 01 00 is Sector 1

Offset 32H: The location of the backup boot sector 06 00 is the 6th sector (7th sector). We can also see from the Winhex that the contents of sector 6th are the same as the contents of the number No. 0 boot sector.

Offset 34H: unused 00 00 00 00 00 00 00 00 00 00 00 00

Offset 40H: Physical Disk number 00

Offset 41H: Unused 00

Offset 42H: Extended boot flag 29 i.e. 0x29

Offset 43H: Disk serial number F1 2A 27 04 is usually a random number

Offset 47H: Volume label ASCII 4E 4F 4E 45 4D 20 20 20 20 No NAME

Offset 52H: File system format ASCII 46 41 54 33 32 20 20 20 i.e. FAT32

Offset 5AH: Partition boot code 420 bytes:

33c98ed1bcf47b8ec18ed9bd007c884e028a5640b408cd137305b9ffff8af166

0fb6c640660fb6d180e23ff7e286cdc0ed0641660fb7c966f7e1668946f8837e1

6007538837e2a007732668b461c6683c00cbb0080b90100e82b00e94803a0fa7db

47d8bf0ac84c074173cff7409b40ebb0700cd10ebeea0fb7debe5a0f97debe0

98cd16cd196660663b46f80f824a00666a0066500653666810000100807e02000f8

52000b441bbaa558a5640cd130f821c0081fb55aa0f851400f6c1010f840d00fe4

602b4428a56408bf4cd13b0f96658665866586658eb2a6633d2660fb74e1866f7f1

fec28aca668bd066c1ea10f7761a86d68a56408ae8c0e4060accb80102cd13666

10f8254ff81c300026640490f8571ffc34e544c445220202020202000000000000000

00000000000000000000000000000000000000000000000000000000000000000000000

00000000000000d0a52656d6f7665206469736b73206f72206f74686572206d656469

612eff0d0a4469736b206572726f72ff0d0a507265737320616e79206b657920746f2

0726573746172740d0a0000000000accbd80000

Offset 1FEH: Active sector end sign (AA)

The boot sector introduction to this section ends.

file allocation table fat

Brief introduction:

Fat tables (file allocation tables) are a chain structure introduced in the FAT file system for indexing and positioning of disk data. In the FAT file system, the storage of files is carried out according to the cluster-chained data structure developed by the fat table. At the same time, the FAT file system abstracts the folders used to organize the data into files, simplifying the management of the data.

Positioning of the FAT1 table position:

When we introduced the partition boot record earlier, we mentioned that the number of reserved sectors was stored at offset 0EH. This number of reserved sectors refers to the number of all sectors in the current partition between the DBR and the Fat table (including DBR but not the Fat table). Therefore, we are able to locate the starting offset where the fat table is located, that is, 24h*200h=4800h. We post 4800H portions of the content such as the following:

Obviously there is no mistake, this is where we store the FAT1, just not currently stored files, so fat is simpler.

Positioning of the FAT2 table position:

When we introduced the partition boot record, we mentioned that the number of sectors occupied by the fat table is stored at offset 24H, and we know that the FAT2 is adjacent to FAT1, so it is very easy to get the offset address of the FAT2 storage location: FAT1 Start offset address +fat1 size = 4800h+1deeh*200h=3c2400h, we post some of the contents of 3c2400h such as the following:

Obviously there is no mistake, this is the location we FAT2 stored, content and FAT1 the same.

Characteristics of fat tables:

Fat tables consist of a series of fat table items of equal size. It has for example the following characteristics:
The cluster address of each cluster in the FAT32, recorded in a fat table using 32bit (4 bytes). All byte positions in the Fat table are divided in 4-byte units, and address numbering is 0 for all divided positions. Address No. 0 and address 1th are reserved by the system and store special logo content.

Start from address 2nd. Each address corresponds to a cluster number in the data area, and the address number in the FAT table is the same as the cluster number in the data area. We call these addresses in fat as FAT table entries, and the values recorded in fat table entries are called Fat table entry values.
When the file system is created, that is, when it is formatted, the space allocated to the fat area is emptied, and a specific value is written to the No. 0 and 1th table entries in FAT1 and FAT2. Because the root folder is also created at the same time as the file system is created, a cluster space is allocated for the root folder, usually cluster 2nd. Therefore, the corresponding 2nd Fat table entry for cluster 2nd will also be written to a closing tag.
Suppose a cluster is not allocated for use. The FAT table entry value within the corresponding FAT table entry is populated with 0. Indicates that the corresponding cluster of the FAT table entry is not allocated for use.


When a cluster is already allocated, its corresponding FAT table key value is the cluster number of the next storage location for the file. Assuming that the file ends in the cluster, a file end tag is recorded in its fat table entry, for FAT32. The FAT table entry value that represents the end of the file is 0x0fffffff.
Assuming a cluster has bad sectors, the entire cluster is marked as a bad cluster with the FAT table entry value 0X0FFFFFF7. No longer used, the bad cluster tag is recorded in its corresponding fat table entry.


Because the cluster number starts at 2. Therefore, table No. 0 and table 1th of the Fat table do not correspond to any cluster.

FAT32 the value of table No. 0 is always "f8ffff0f". Table 1th entries may be used to record dirty flags. To indicate that the file system is not properly unloaded or that there is an error on the disk surface. Just this value doesn't seem to matter, so we just have to understand it. Under normal circumstances, the value of table 1th is "FFFFFFFF" or "ffffff0f".


When you create a new file in the file system, assume that the newly created file occupies only one cluster. The corresponding FAT table entry for the cluster to which it is allocated will be written to the closing tag. Assuming that the newly created file is not just a cluster, it writes the cluster number of the next cluster that it allocates to the corresponding fat table entry for each cluster it occupies, and writes the closing tag in the corresponding FAT table entry for the last cluster.


When you create a new folder, only a cluster of space is allocated for it, and the closing tag is written to the corresponding fat table entry. When the folder grows beyond the size of a cluster. A cluster will continue to be assigned to it in the spare space. A fat bracelet is established in the fat table to describe the clusters it occupies.
When a file or folder is deleted, their corresponding fat table entries are emptied and set to 0 to indicate that their corresponding cluster is in an unassigned state.

Root Folder Area

Brief introduction:

In the FAT32 file system, the location of the root folder is no longer rigidly fixed and can be stored in an addressable cluster within a partition, except that the root folder is usually the oldest (formatted) folder table. So, what we're seeing is basically the first cluster of root folders 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 folder as a normal data file, all without the limit of the number of folder items, to allocate empty clusters when needed, and to store many other folder items.

Start offset address positioning:

Root folder Start sector = number of reserved sectors +fatx2+ (start cluster-2) x number of sectors per cluster. Before we introduce the partition boot record, it is mentioned that the root folder is saved at offset 2CH The starting cluster number is 2, so the root folder starting sector is 24h+1deeh*2h+ (2-2) *8h=3c00h, that is, the offset address 3c00h*200h=780000h is obtained, We post some of the contents of 780000H at the following example:

A folder item in the folder area occupies 32 bytes, which can be a long file name folder item, a file folder item, a subfolder item, and so on.

Folder items in short file name format

For folder items in short file name format. The significance of its parameters is as follows:

According to the definition of the parameters, we will analyze the folder item. 5F. 00 00 00 00 00 00. (3F), and then the

The initial 11 bytes of the 5F 46 41 54 33 32 20 is the volume label test_fat32; the 12th byte 08 indicates that the current folder item is a volume label, 第23-24 Byte 19 95 is 9519H, is the recent change time: 19 points 40 minutes 50 seconds; 第25-26 Word Section 3F is 3f10h, is the latest modification date: August 16, 2011;

Folder items in long file name format

An important feature of FAT32 is the full support for long file names. The long file name is still recorded in the folder item.

For the low version of the OS or program to correctly read the long file name file, the system itself to create a full minister file name file a corresponding short file name, so that the corresponding data can be used to address the long file name, can also be used to address the short file name.

An OS or program that does not support long file names ignores long file name fields that it finds illegal, while an OS or program that supports long file names is recorded and edited with long filenames, and hidden short file names.

When you create a long file name file, the system will voluntarily add the corresponding short file name. Its principles are as follows:
(1), take long file name of the first 6 characters plus "to" form a short file name. The extension does not change.


(2), assuming that the file name already exists. The number after the symbol "~" is incremented until 5.


The implementation of a long file name depends on the 12th byte attribute byte of the folder item, when the value of this byte is 0FH, the system that supports the long file name is based on the long file name, and only the system that supports short file names will feel an exception and ignore it.

The system splits the long file name in 13-character units. Each group occupies a folder item. Therefore, it is possible for a file to require multiple folder entries, in which case the individual folder items of the long file name are sorted in reverse order in the folder table to avoid confusion with other file names.


Characters in long file names are encoded in Unicode form, with each character occupying 2 bytes of space. Its folder items are defined as:

Here is the folder entry for the long File name folder abcdefghijklmnopqrstuvwxyz1234567890 that I created:

Storage organization structure of FAT32 file system (i)

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.