Unveiling the I/O parameter of the FAT32 File System Disk

Source: Internet
Author: User

Windows 98 introduces the FAT32 file system, which completely solves many problems existing in the fat16 file system. The so-called FAT32 file system uses 32-bit data to describe the distribution of disk clusters. The traditional disk management uses 16 binary bits (2 bytes) to describe a cluster. By analyzing the operating system structure, we can know that the FAT32 file system does not simply convert the fat table to 32 bits (4 bytes are used to describe a cluster ), it brings about changes in disk I/O parameters, partitions, and FDT tables and other aspects of the file system. To thoroughly understand how the FAT32 file system modifies disk I/O parameters, this article analyzes the structure of the FAT32 file system and reveals the algorithm for storing and managing files in the FAT32 file system. Understanding the disk I/o PARAMETERS OF THE FAT32 file system can not only master the method of directly accessing disk files, but also provide the operating system functions at a higher level.


FAT32 File System Changes to the primary Boot Sector

The primary Boot Sector is a disk-controlled data storage area exclusive to the hard disk. Its primary function is to store data related to hard disk partitions. It is usually located in the hard disk's 0-head, 0-cylinder, and 1-sector. Because the primary Boot Sector stores data related to the hard disk partition, it is also called the partition sector. Partition data is crucial to the hard disk. The loss or damage of partition data will make the Logical Disk on the hard disk unrecognizable by the system, and of course the files and data stored on the disk cannot be accessed.

According to the analysis of the primary Boot Sector of the FAT32 file system, the primary Boot Sector of the FAT32 file system is compatible with the primary Boot Sector of the fat16 file system, extended the features of the FAT32 file system.
The extension of the data structure of the partition table by the primary Boot Sector of the FAT32 file system is limited to three types of 32-bit partitions, the three added partition types are 0bh, 0ch, and 0eh, which are used to describe the three partitions of the FAT32 file system. For extended partitions, a type flag 0fh is added, indicating windows
98. 0bh indicates that the partition is FAT32, and the maximum partition capacity can reach 2047 GB. 0ch indicates the same meaning as 0bh, but the extended logical block address (LBA) is used for int13h commands) the value 0 eh indicates the same meaning as 06h, but the extended logical block address (LBA) method is used for the INT 13 H command. The value 0 FH indicates the same meaning as 05h (extended partition ), but for int
The 13 H command uses the extended logical block address method. The extended logical block address is used to support large-capacity hard disks with a capacity of more than 8 GB.

After the file system is converted to FAT32, the type mark of the partition changes to 0bh, 0ch, and 0eh. These new types are not recognized by the original fat16 file system, so when the user uses the MS-DOS Operating System of the floppy disk to start the system, the machine can not identify the partition data of the hard disk, of course, can not access the hard disk data.

Partition Boot Sector of the FAT32 File System
In Windows 98, when the file system is converted from fat16 to FAT32, the function and function of the Partition Boot Sector remain unchanged, however, considering the features of the FAT32 File System and the problems existing in the fat16 file system, the operating system expands the Partition Boot Sector of the FAT32 file system.

1. Expand the number of sectors occupied by the Partition Boot Sector from one sector to six
The core function of the Partition Boot Sector is to load the files that start the operating system through disk read/write parameters. In order to make file loading more flexible, the FAT32 file system uses the "active" FDT table, we need to re-design the boot program code for the Partition Boot Sector, taking into account the amount of the boot program code and reserve the appropriate margin for future development, the FAT32 file system expands the number of sectors occupied by the Partition Boot Sector from one sector to six, and Windows 98 uses the first three sectors as the system's Partition Boot Sector, the remaining three sectors are not used yet.

2. Dual-Partition Boot Sector
Based on the study on the functions and functions of the Partition Boot Sector, we know that the Partition Boot Sector plays a vital role in operating system startup and disk file access. If the boot program code is damaged, the operating system cannot be started normally. If the disk read/write parameters are damaged, the files stored on the disk cannot be read or written normally.

Due to the importance of Partition Boot Sector, the FAT32 file system uses the operating system's experience in processing fat tables and retains two Partition Boot sectors on the disk, at startup, the operating system can compare two boot sectors to select the correct Boot Sector to guide the system. Because the system no longer modifies the program and data of the boot sector during the normal operation of the disk, the possibility of damage to the Boot Sector of the backup partition is very small.

Extended disk I/O parameters in the FAT32 File System
The disk read/write parameters of the FAT32 file system are partially compatible with the disk read/write parameters of the fat16 file system. To meet the requirements of the FAT32 file system, the disk read/write parameters are appropriately expanded, the number of bytes used is also extended from the 58 bytes of the fat16 File System to 87 bytes. the disk read/write parameters of the FAT32 File System occupy the space from the sector offset of H to H, the specific meanings of each parameter are shown in table 1.

In addition, the first sector of the Partition Boot Sector is used as the identification sector for storing the relevant parameters of the file system. Apart from storing the identification information (rraa and rraa) of the sector, the file system information is also stored at the 1e8h offset. The sector offset address is 1e8h ~ The four bytes of 1 ebh store the number of unused clusters on the Logical Disk, it is usually used to quickly calculate the remaining space of a logical disk (a typical operation is to list the "available disk space" parameter on the resource manager status bar), while 1ech ~ 1efh
The four bytes indicate the cluster number of the idle cluster that can be allocated to the file in the logical drive, in this way, the operating system can directly obtain the remaining disk space and the assigned cluster number without accessing the fat table.

The 3rd sectors of the Partition Boot Sector store the program code of the last part of the boot system.

Table 1 read/write table of the FAT32 File System Disk

No.

Start offset address

Number of characters

Yi

1

03 h

8

The version number of the operating system.

2

0bh

2

The number of bytes per slice.

3

0dh

1

Number of sectors per cluster.

4

0eh

2

Number of sectors retained by the operating system.

5

10 h

1

The number of fat tables.

6

11 h

2

Store the number of directory items that can be registered in the root directory of the system in fat16. FAT32 is used to indicate whether the system uses the FAT32 file system. The value of objective H indicates that the disk uses the FAT32 file system.

7

13 H

2

The value is 00 h, reserved for compatibility, not used.

8

15 h

1

Disk media flag. The hard disk is f8.

9

16

2

Not used. The value is 00 H.

10

18 h

2

The number of sectors of each track.

11

1ah

2

Disk Head.

12

1ch

4

Number of hidden sectors before partitioning.

13

20 h

4

The total number of sectors in the Logical Disk.

14

24 h

4

The number of sectors occupied by each fat table.

15

28 h

2

Fat table image flag. If the value is 0, the system saves two copies of the backup fat table. If the value is 1, the system only saves one copy of the fat table.

16

2ah

2

The primary and secondary versions of the file system (retained ).

17

2ch

4

The starting cluster number of the disk root directory.

18

30 h

2

The sector ID of the file system parameter, usually located in the next sector of the boot sector.

19

32 h

2

Back up the logical sector ID of the Partition Boot Sector.

20

34 h

12

Reserved, not used.

21

40 h

2

The physical drive letter of the disk.

22

42 h

1

Disk read/write parameter extension flag with a value of 29 H.

23

43 H

4

The serial number of the disk volume.

24

47 h

11

Disk volume number.

25

52 h

8

The ID (FAT32) of the file system ).

FAT32 File System Disk I/O parameter instance
Figure 1 lists the disk read/write parameter instances of a FAT32 file system. Based on the I/O parameters listed in Table 1, we can know that the Logical Disk has a total of 2076417 (1faf01h) sectors, 51 (33 H) sectors are reserved for the operating system. Each cluster consists of 8 sectors, each of which has 63 (003fh) sectors, and the system has two fat tables that mirror each other, each fat table occupies 2028 (07ech) sectors, and the starting cluster number of the fdt table is 2nd clusters (00000002 H ), the backup Partition Boot Sector is stored in the storage space starting from 6th logical sectors. The Disk File System ID is FAT32.

Figure 1 FAT32 File System I/O parameter instance

------- Basic Concepts

Data Storage

Data is stored in the hard disk in the cluster space unit, so no matter what the file size is, unless it is a multiple of the cluster size, otherwise, the last cluster occupied by the file will produce more or less space. these spaces cannot be used by other files.

For example, if a 64 kB file is stored in a 64 kB partition, the cluster can be fully used. If the file is only 63kb, it also occupies a cluster, which wastes 1 kb of space. If the file to be stored is kb, two clusters are required to save the file. The wasted space is kb. However, when the cluster size of a partition is 4 kb, the storage space of files storing 65kb is only 3 kb. It can be seen that the smaller the cluster size, the less space wasted, and the higher the utilization of hard disk space.

Data is stored on hard disks in cluster units.
Cluster configuration
Commonly used file clusters in Windows 9x/me systems are in the fat16 or FAT32 format.
For example, a m hard disk space can be configured in several ways:
Cluster size = 4kb: 256 MB/4kb = 655356 Clusters
Cluster size = 8kb: 256 MB/8kb = 32768 Clusters
Cluster size = 16 KB: 256 MB/16 KB = 16384 Clusters
Cluster size = 32kb: 256 MB/32kb = 8192 Clusters
Although the NTFS file system exclusive to Windows NT/2000/XP uses clustering to store data, it is obviously different from fat16/FAT32. When the partition space is larger than 2 GB, the cluster size is kept at 4 kb regardless of the size of the hard disk. Because the cluster capacity is small, no matter what type of files are stored, it will not waste too much hard disk space, which also greatly improves the space utilization of the entire hard disk.

What is a cluster?

The file system is the interface between the operating system and the drive. When the operating system requests to read a file from the hard disk, it will request the corresponding file system (fat16/32/NTFs) to open the file. A sector is the smallest physical storage unit on a disk. However, the operating system cannot address a large number of sectors. Therefore, the operating system combines adjacent sectors to form a cluster, then, manage the cluster. Each cluster can contain 2, 4, 8, 16, 32, or 64 sectors. Obviously, a cluster is the logical concept used by the operating system, rather than the physical characteristics of the disk.

To better manage disk space and read data from the hard disk, the operating system requires that only one file can be placed in a cluster, it can only be an integer multiple of the Cluster. If the actual file size is smaller than one cluster, it also occupies the space of one cluster. Therefore, the space occupied by a file is slightly larger than the actual size of the file. In a few cases, the actual size of the file is exactly an integer multiple of the cluster, the actual size of the file will be exactly the same as the occupied space.

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.