I. Introduction to the logical structure of the hard disk
1. Hard Disk Parameters
So far, the hard disk parameters are commonly referred to as the old CHS (cylinder/head/sector) parameters. Why are these parameters used? What are their meanings? What are their values?
A long time ago, when the disk capacity was very small, people used a structure similar to a floppy disk to produce hard disks. that is, each track of a hard disk has the same number of sectors. the so-called 3D Parameter (Disk geometry) is generated ). this includes the number of cores (heads), cylinders, sectors, and corresponding addressing methods.
Where:
The number of magnetic heads (heads) indicates that the hard disk has a total of several heads, that is, the number of disks with a maximum size of 255 (stored in 8 binary bits );
Cylinders indicates the number of tracks on each disk of the hard disk. The maximum value is 1023 (which is stored in 10 binary bits );
The number of sectors (sectors) indicates that each track has several sectors. The maximum value is 63 (6 binary bit storage ).
Each slice is generally 512 bytes. Theoretically, this is not necessary, but it seems that there is no other value.
Therefore, the maximum disk capacity is:
255*1023*63*512/1048576 = 8024 GB (1 m = 1048576 bytes) or hard disk vendor commonly used units:
255*1023*63*512/1000000 = 8414 GB (1 m = 1000000 bytes)
In the CHS addressing mode, the value ranges from 0 to heads-1, 0 to cylinders-1, and 1 to sectors (starting from 1 ).
2. introduction to basic INT 13 H calls
The bios int 13 H call is an interrupted call of the basic input and output of the disk provided by the BIOS. It can reset, read/write, verify, locate, and diagnose the disk (including the hard disk and floppy disk, formatting and other functions. it uses the CHS addressing mode, so it can access a hard disk of about 8 GB at the maximum (if not specified in this Article, the unit is 1 MB = 1048576 bytes ).
3. Introduction to modern hard disk structures
In an old hard disk, because the number of sectors of each track is equal, the record density of the external track is much lower than that of the internal track, which wastes a lot of disk space (the same as that of a floppy disk ). in order to solve this problem and further increase the hard disk capacity, people use an equi-density structure to produce hard disks. that is to say, the sector of the outer ring track is more than that of the inner ring track. after this structure is used, the hard disk no longer has actual 3D parameters, and the addressing mode is changed to linear addressing, that is, addressing is performed in units of sectors.
To be compatible with old 3D addressing software (such as biosint13h), an address translator is installed inside the hard disk controller, it translates old 3D parameters into new linear parameters. this is why there are multiple options for the 3D parameters of the hard disk (different working modes correspond to different 3D parameters, such as LBA, large, and normal ).
4. Introduction to extended INT 13 H
Although modern hard disks have adopted linear addressing, due to the limitations of int13h, programs that use the bios int 13 H Interface, such as DOS, can only access hard disk space of less than 8 GB. to break this restriction, Microsoft and other companies have developed extended INT 13 H (Extended int13h) and used linear addressing to access hard disks. Therefore, they have broken through the 8g limitation, it also supports removable media (such as removable hard disks.
II. Introduction to the boot sector structure
1. Composition of Boot Sector
The boot sector is the first sector of the hard disk. It consists of three parts: MBR (masterboot record), DPT (Disk Partition Table), and Boot Record ID.
MBR, also known as the Master Boot Record, occupies the first 446 bytes (0 to 0x1bd) of the boot sector and stores the system's Master Boot Program (which is responsible for loading and running from the active partitionSystem Boot Program).
DPT indicates that the primary Partition Table occupies 64 bytes (0x1be to 0x1fd) and records the basic partition information of the disk. the primary Partition Table is divided into four partition items, each of which is 16 bytes and records the information of each primary partition respectively (therefore, a maximum of four primary partitions can be created ).
The Boot Record ID indicates that the boot zone mark occupies two bytes (0x1fe and0x1ff). For a valid boot zone, it is equal to 0xaa55, which indicates whether the boot zone is valid.
The detailed structure of the boot sector is shown in:
0000 | ------------------------------------------- |
|
|
| Master Boot Record |
|
|
| Master Boot Record (446 bytes) |
|
|
|
01bd |
01be | ---------------------------------------------------- |
|
01cd | partition information 1 (16 bytes) |
01ce | ---------------------------------------------------- |
|
01dd | partition information 2 (16 bytes) |
01de | ---------------------------------------------------- |
|
01ed | partition information 3 (16 bytes) |
01ee | ---------------------------------------------------- |
|
01fd | partition information 4 (16 bytes) |
| ------------------------------------------------------ |
| 01fe | 01ff |
| 55 | AA |
| ------------------------------------------------------ |
2. Introduction to partition table structure
A partition table consists of four partition items. The structure of each item is as follows:
Byte state: partition status, 0 = inactive, 0x80 = activated (note this option)
Byte starthead: Start head number of the partition
Word startsc: Start slice and Cylinder Number of the partition. The lowest 6 bits of the base byte are the sector numbers,
The 2-digit height is the 9th and 10th digits of the cylinder number, and the 8-digit height is the 8-digit lower part of the cylinder number.
Byte type: partition type, such as 0x0b = FAT32, 0x83 = Linux, etc,
00 indicates that this item is not used, 07 = NTFS
Byte endhead: the end head of the partition.
Word endsc: End sector and Cylinder Number of the partition, which are defined in the same way as before.
DWORD relative: Address of the partition relative sector in linear addressing mode
(The basic partition is an absolute address)
DWORD sectors: partition size (total number of sectors)
Note: in DOS/Windows systems, basic partitions must be divided by cylindrical units (sectors * Heads sectors), for example, for hard disks with CHS of 764/255/63, the minimum partition size is 255*63*512/1048576 = 7.844 MB.
3. Introduction to extended partitions
Because the primary Partition Table can only be divided into four partitions and cannot meet the requirements, an extended partition format is designed. basically, extended partition information is stored in the form of a linked list, but there are some special points. first, there must be a basic extended partition item in the primary partition table. All the extended partitions belong to it, that is, the space of all other extended partitions must be included in this basic extended partition. for DoS/Windows, the extended partition type is 0x05. all other extended partitions except the basic extended partitions are stored in the form of a linked list. The data items of the last extended partition are recorded in the Partition Table of the previous extended partition, but the space of the two extended partitions does not overlap.
An extended partition is similar to a complete hard disk and can be used only after further partitioning. however, each extended partition can only have one other partition. this partition is a logical disk in the DOS/Windows environment. therefore, the partition table of each extended partition (also stored in the first sector of the extended partition) can have at most two partition data items (including the data items of the next extended partition ).