Read/write principles of Hard Disks

Source: Internet
Author: User

Hard Disks are mainly SCSI, IDE, and popular SATA; any hard disk must be produced according to certain standards; with the upgrade of the corresponding standards, hard Disk production technology is also upgrading; such as SCSI standards have gone through the SCSI-1, SCSI-2, SCSI-3; which we often see in the server site is based on Ultral-160 standards; the IDE follows the ATA standard, while the popular Sata is the upgraded version of the ATA standard. The IDE is a parallel device, while the Sata is a serial port. The development purpose of Sata is to replace the IDE;

We know that the information is stored in the hard disk, and we can't see anything in it, but some disks. If you use a microscope to enlarge the disc, you will see the uneven surface of the disc. The raised area is magnetized, And the concave area is not magnetized; the raised area represents the number 1 (the magnetization is 1), and the concave area represents the number 0. Therefore, the hard disk can store information such as text and images in binary format.

1. Hard Disk Composition

Hard drives are no stranger to everyone. We can regard them as a big warehouse for storing data and information on our computers. Generally, either hard disk is composed of disk, Head, disk spindle, control motor, head controller, data converter, interface, cache, and other parts.

Plan:

Stereoscopy

All the disks are fixed on a rotating axis, which is the disk spindle. All disks are absolutely parallel. There is a head on the storage surface of each disk. The distance between the head and the disk is smaller than the diameter of the hair silk. All heads are connected to one head controller, and the head Controller is responsible for the movement of each head. The head can be moved along the radius of the disc. (actually, it is a oblique movement.) each head must be coaxial at the same time, that is, from top to bottom, all heads are overlapped at any time (however, multiple heads are already available independently, but not limited to this ). The disk is rotated at a high speed at the speed of thousands to tens of thousands per minute, so that the head can read and write data at the specified position on the disk.

Because the hard disk is a high-precision device and the dust is its enemy, it must be completely sealed.

2. Working Principle of the hard disk

Hard Disks are logically divided into tracks, cylinders, and sectors.

Each disk has a read/write head on each side of the hard disk.

The head is close to the contact surface of the spindle, that is, the place with the smallest wire speed. It is a special area that does not store any data. It is called the start/stop zone or the landing zone. The start/stop zone is the data zone. In the outermost ring, the farthest place from the spindle is the "0" track, and the storage of Hard Disk Data starts from the outermost ring. Then, how does the head locate the position of the "0" track? There is also a component named "0" track detector in the hard disk, which is used to complete the initial positioning of the hard disk. The "0" track is so important that many hard disks are scrapped only because the "0" track is damaged. This is a pity.
A program called parking needs to be run before each shutdown of a hard disk in the early days. Its function is to let the head back to the start and stop area. The Design of Modern hard drives has abandoned this small defect that is not complex but unpleasant. When the hard disk does not work, the head stays in the Start and Stop area. When you need to read and write data from the hard disk, the disk starts to rotate. When the rotation speed reaches the rated high speed, the head will be lifted by the airflow generated by disk rotation, then the head will move to the area where the disk is stored.
The airflow generated by disk rotation is strong enough to hold the head and keep a tiny distance from the disk surface. The smaller the distance, the higher the sensitivity of the head to read and write data, of course, the higher the requirements for each part of the hard disk. The disk drive was designed to keep the head flying several microns above the disk. Later, some designs reduced the flying height of the head on the disk to about 0.1 μm ~ 0.5 μm, the current level has reached 0.005 μm ~ 0.01 μM, which is only 1‰ of the diameter of human hair.
The airflow not only separates the head from the opening surface, but also keeps it close enough to the disk surface, closely following the ups and downs of the disk surface, so that the head flight is strictly controlled. The head must fly above the disk surface rather than touching the disk surface. This position can avoid scratches on the magnetic coating, and more importantly, prevent the magnetic coating from damaging the head.
However, the head cannot be too far away from the disk surface. Otherwise, the disk surface cannot be magnetization enough, and it is difficult to read the magnetization of the disk (pole conversion form, is the method of actually recording data on the disk ).

The floating height of the hard drive head is low and the speed is fast. Once a small amount of dust enters the hard drive sealing cavity, or if the head and the disk body collide, data may be lost, the formation of Bad blocks may even cause damage to the head and disk. Therefore, the hard disk system must be sealed reliably. In non-professional circumstances, it is absolutely impossible to enable the hard disk sealed cavity. Otherwise, the damage to the hard disk will be accelerated after dust enters. In addition, the track-seeking servo motor of the hard drive head mostly uses the audio ring rotation or linear motion stepping motor to precisely track the track of the disc under the adjustment of the Servo Tracking, when the hard disk is working, do not have an impact collision. Be careful when moving it.
This type of hard disk is usedWinchester (Winchester)Hard Disks manufactured by technology are also called warm disks. Currently, most hard disks use this technology.3. disc, track, cylinder, and fan Area

Hard disk read/write is closely related to the sector. Before talking about the sector and read/write principles, let's talk about the "disk", "track", and "Cylinder" related to the fan area ".
1. Disk Surface
Hard Disk disks are generally made of aluminum alloy materials as substrates, and high-speed hard disks may also be made of glass as substrates. Each disk on the hard disk hasTwo sides ),That is, the upper and lower disks are usually used on each disk. data can be stored as valid disks. There are also a few hard disk disks with a singular number. Each valid disk has a disk number, which is numbered from top to bottom from "0" in sequence. In the hard disk system, the disk number is also called the head number, because each valid disk has a corresponding read/write head. The disk group of the hard disk is 2 ~ 14 pieces, usually 2 ~ Three disks, so the disk number (head number) is 0 ~ 3 or 0 ~ 5.

2. Track
The disk is divided into many concentric circles during formatting. These concentric circle tracks are called tracks ). The track starts from 0 in sequence. Each disk on the hard disk has 300 ~ 1 024 channels, with more tracks on each side of the new large-capacity hard drive. Information is recorded in these tracks in the form of a pulse string. These concentric circles are not continuously recorded data, but are divided into arcs in the middle segment. These ARCs share the same angular velocity. Because the radial length is different, the line speed is also different. The line speed of the outer ring is higher than that of the inner ring. That is, at the same speed, the outer ring is in the same time period, the length of the arc to be crossed is larger than that of the arc to be crossed by the inner ring. Each section of an arc is called a slice. The Slice starts from "1" and the data in each slice is read or written as a unit at the same time. A standard 3.5-inch hard disk usually has hundreds to thousands of tracks. The track is invisible. It is only some of the magnetized areas on the disk surface that are magnetized in special forms. It has been planned during disk formatting.

3. cylindrical
A cylinder is a cylinder formed by the same track on all disks. The head of each cylinder starts from "0" from top to bottom. Data reading/writing is performed by a cylindrical disk, that is, when the magnetic head reads/writes data, the operation starts from the "0" head in the same cylindrical disk, perform operations on different disk surfaces of the same cylinder, that is, the head, only after all the heads in the same cylinder have been read/written is the head transferred to the next cylinder (the cylinder inside the concentric circle), because the selected head only needs to be switched electronically, the selected cylinder must be mechanically switched. The electronic switching speed is much faster than that of the mechanical head moving towards the adjacent track. Therefore, data reading/writing is performed by the cylinder instead of by the disk. That is to say, when a track is full of data, it is written on the next disk of the same cylinder,After a cylindrical column is fully written, data is written to the next sector.. This method also improves the read/write efficiency of the hard disk.
The number of columns on a hard drive (or the number of tracks on each disk) depends on the width and width of each track (also related to the size of the head ), it also depends on the gap between tracks determined by the positioning mechanism.

4. Sector
The operating system stores information on the hard disk in the form of a sector (sector). Each sector contains 512 bytes of data and other information. One slice has two main parts: the identifier of the location where the data is stored and the data segment where the data is stored.


The first major part of a sector is the identifier. The identifier is the Sector Header mark, which contains three numbers that constitute the three-dimensional address of the sector:

Disk ID: The head (or disk) of the slice)

Cylinder Number: track to determine the radial direction of the head.

Sector number: the location on the track.It is also called a block number.The position of the data in the disc circle is determined.

The header also contains a field that shows whether the slice can store data reliably or whether a fault has been found and thus is not suitable for use. Some hard drive controllers also record indicators in the Sector Header, which can guide the disk to the replacement sector or track when an error occurs in the original sector. Finally, the Sector Header Mark ends with the cyclic redundancy check (CRC) value for the Controller to check the reading status of the Sector Header mark to ensure accuracy.
The second major part of the slice is the data segment that stores data, which can be divided into data and the Error Correction Code (ECC) that protects the data ). During the initial preparation, the computer fills in this section with 512 virtual information bytes (actual data storage location) and ECC numbers corresponding to these virtual information bytes.

5. Complete the disk access request process:

Determine the disk address (cylindrical number, head number, sector number), memory address (Source/object ):

When data needs to be read from the disk, the system will pass the data Logical Address to the disk. the disk control circuit translates the logical address into a physical address according to the addressing logic, determine the track and sector of the data to be read.

To read data from this sector, you need to place the head above this sector to achieve this:

1) First, the cylinder must be located, that is, the head must be moved to the corresponding track,This process is called seekingThe time consumed is called the seek time,

2) then the target sector is rotated to the bottom of the head, that is, the disk is rotated to the bottom of the head. The time consumed in this process is called the rotation time.

The process of completing a disk access request (read/write) consists of three actions:
1) Seek (time): Move the head to locate the specified track
2) Rotation delay (time): waiting for the specified sector to rotate from the bottom of the head
3) data transmission (time): the actual data transmission between disk and memory

Therefore, it takes time to read sector data (one piece of data) on the disk:

TI/O =TSeek +TLa + N *TWm

Where:

Tseek is the seek time

Tla indicates the rotation time.

TWM indicates the transmission time.

4. disk read/write principles

When the system stores files on a disk, it uses the cylindrical, Head, and sector method, that is, the first Magnetic Head of the 1st track (that is, the first Magnetic Track of the 1st disk) and then the next head of the same cylinder ,......, After a cylindrical storage is full, it is pushed to the next cylindrical until all the file content is written to the disk.

(The file records are stored on the same disk group. They should be first concentrated on one cylinder, and then stored sequentially on the adjacent cylinder, corresponding to the same cylinder, it should be stored in the order of disks .)

(From top to bottom, and then from outside to inside. Read/write data by cylindrical rather than disk. First)
The system also reads data in the same order. When reading data, the disk controller is notified to read the cylindrical number, head number, and fan area number of the slice (three parts of the physical address. The disk controller directly moves the head parts to the corresponding cylinder, selects the corresponding head, and waits for the required sector to move to the bottom of the head. When the slice arrives, the disk controller reads the header mark of each slice, compares the address information in the header mark with the head and the cylinder number to be detected (that is, seek), and then, find the required fan area number. When the disk controller finds this sector header, it determines whether to convert the write circuit or read data and tail records based on whether the task is to write a sector or read a sector. After a sector is found, the disk controller must post-process the information of the sector before continuing to search for the next sector. If the data is read, the Controller calculates the ECC code of the data, and then compares the ECC code with the recorded ECC code. If the data is written, the Controller calculates the ECC code of the data and stores it together with the data. The disk continues to rotate when the controller processes the data in this sector as necessary.

5. Local principle and disk pre-read

Because of the characteristics of the storage medium, the access to the disk itself is much slower than the primary storage, coupled with the cost of mechanical movement, the access speed of the disk is often one of the primary storage, so in order to improve efficiency, minimize disk I/O. To achieve this goal, the disk is usually not read strictly on demand, but preread every time. Even if only one byte is required, the disk starts from this location, read data of a certain length in sequence into the memory. This theory is based on the well-known local principle in Computer Science:

When a data is used, the data nearby it is usually used immediately.

The data required during the program running is usually concentrated.

Because sequential disk reading is highly efficient (with little rotation time required without seeking time), preread can improve I/O efficiency for local programs.

The preread length is generally an integer multiple of the page. Pages are logical blocks for computer memory management. Hardware and operating systems often divide primary and disk storage areas into contiguous blocks of the same size, each block is called a page (in many operating systems, the page size is usually 4 K). The primary storage and disk exchange data in pages. When the data to be read by the program is not in the primary storage, a page missing exception is triggered, and the system sends a disk reading signal to the disk, the disk finds the starting position of the data and reads one or more pages consecutively into the memory. If an exception is returned, the program continues to run.

6. Generation of disk fragments

As the saying goes, a chart is better than a thousand words. First, an acⅱ code diagram is used to explain why disk fragments are generated.

The ASCII diagram above indicates the disk file system. Since there is no data file above, I have expressed it as 0.
There are 26 letters A-Z on the top and left of the graph, which is used to locate the specific location of each data byte. For example, the value of column 1 in row 1st is AA and that of column 26 in row 26 is ZZ.
We create a new file. Of course, our file system has changed.

: "Content table" (TOC) occupies the first four rows and stores each file in the TOC in the system.
In TOC, a file named hello.txt is stored in the file "Hello, world". The location in the system is AE to le.
Next, create a new file.


The new file bye.txt is attached to the first file hello.txt.
In fact, this is the most ideal system structure. If you put all your files together as shown, reading them will be very easy and fast, because the slowest (relatively) movement in the hard disk is the drive arm, with less displacement, the time for reading file data is faster.
However, this is the problem. Now I want to add some exclamation points after "Hello, world" to express my strong feelings. Now the problem is: on this system, there is no place for the document to let me put this exclamation point, because bye.txt occupies the rest.
There are two methods to choose from, but none of them are perfect.
1. delete the file from the original location, create a new file, and write "Hello, world!" again !!". -This inadvertently extended the reading and writing time of the file system.
2. to break a file, you just need to write an exclamation point in another blank place, that is, a different place.-This idea is good, fast, and convenient. However, this also means that reading the next new file is greatly slowed down.
If you have no idea about the above text,

The method 2 mentioned here is like the storage method of our windows system. Every file is adjacent, but if one of the files needs to be changed, this means that the data will be stored in other spare parts of the disk.
If this file is deleted, spaces will be left in the system. Over time, our file system will become fragmented and fragments will be generated.

Try to make it simple and give a brief explanation of the hard disk read/write principles of mm.


The structure of the hard disk is not much said. The data on our computers usually exists on the track, which is roughly the same as that on the CD. Reading is carried out by the head.

We all know that our data is stored on the track of the disk sector in the form of information, and the hard disk reading is read and written from the outside of the disk to the inside by the rocker head. therefore, the external data reading speed is much faster than the internal data.

In fact, most of our files are broken. When the files are not broken, the rocker only needs to find one track and read it from the head. Only one time is required to read the files; however, if the file is broken into 11 parts, the rocker side needs to search for the 11-time track head for 11 reads to complete the file. The reading time becomes lengthy when the file is not broken.

Therefore, disk fragmentation is often one of the important factors to slow down the system. The Vista Home team also plans to add the disk fragmentation feature in the later versions of Vista master optimization.

7. Hard disk capacity and partition Size Calculation

In Linux, to calculate the hard disk capacity and partition size, we first view the hard disk information through fdsik-l:
Disk/dev/hda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 Cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Device boot start end blocks ID system
/Dev/hda1*1 765 6144831 7 HPFs/NTFS
/Dev/hda2 766 2805 16386300 C w95 FAT32 (LBA)
/Dev/hda3 2806 9729 55617030 5 extended
/Dev/hda5 2806 3825 8193118 + 83 Linux
/Dev/hda6 3826 5100 10241406 83 Linux
/Dev/hda7 5101 5198 787153 + 82 Linux swap/Solaris
/Dev/hda8 5199 6657 11719386 83 Linux
/Dev/hda9 6658 7751 8787523 + 83 Linux
/Dev/hda10 7752 9729 15888253 + 83 Linux
Where
Heads is a disk;
Sectors is a sector;
Cylinders is a cylinders;
The size of each slice is 512 bytes, that is, 0.5 kb;

Through the above example, we found that the hard disk has 255 disk faces, 63 sectors, and 9729 cylinders. Therefore, the entire hard disk volume conversion formula should be:
Number of magnetic surfaces * number of sectors * size of each sector 512 * Number of cylinders = hard disk volume (unit: bytes)
Therefore, the disk size in this example should be calculated as follows:
255x63x512x9729 = 80023749120 bytes
Tip: Hard Disk manufacturers and Operating System Conversion are not the same, hard disk manufacturers use a 10-digit method to convert, while the operating system uses a 2-digit system to convert, so when converting to m or G, the results of different algorithms are different. Therefore, our hard disk is sometimes labeled as 80 GB, which is a few MB in the operating system;
In the above example, the hard disk manufacturers algorithm and operating system arithmetic comparison:
Hard Disk manufacturers: 80023749120 bytes = 80023749.120 K = 80023.749120 M (convert to large units, divide each time by 1000)
Operating System: 80023749120 bytes = 78148192.5 K = 76316.594238281 M (conversion to large units, divided by 1024 each time)
When viewing the partition size, we can use the algorithm provided by the manufacturer to calculate the partition size. Moving the decimal point forward by six digits is the Size expressed in g; for example, hda1 is about 6.144831 GB in size;

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.