Hard disk read and write principle

Source: Internet
Author: User

Transferred from: http://blog.csdn.net/hguisu/article/details/7408047

The type of hard disk is mainly SCSI, IDE, and now popular SATA, and so on, any kind of hard disk production must be a certain standard, with the corresponding standard upgrade, hard disk production technology is also upgrading; for example, SCSI standards have gone through SCSI-1, SCSI-2, SCSI-3 , which we often see on the server Web site Ultral-160 is based on the SCSI-3 standard, the IDE follows the ATA standard, and the current popular SATA is the ATA standard upgrade version; IDE is the interface device, and SATA is the serial port, SATA was developed to replace the IDE;

We know that the information is stored on the hard drive, and it is not visible that there is anything in it, only some platters. Assuming that you enlarge the disc with a microscope, you will see the uneven surface of the platter, the convex place is magnetized, the concave place is not magnetized, the raised place represents the number 1 (magnetization is 1), the concave place represents the number 0. Therefore, the hard disk can be binary to store representations of text, pictures and other information.

1, the composition of the hard disk

Hard disk We must not be unfamiliar, we can liken it to our computer storage data and information of the large warehouse. Generally speaking, no matter what kind of hard disk, it is composed of platters, head, disc spindle, control motor, head controller, data converter, interface, cache and so on.

Floor plan:

Stereoscopic diagram

All platters are fixed on a rotating shaft, which is the disc spindle. All platters are absolutely parallel, with a head on each disc's storage surface, and the distance between the head and the platter is smaller than the diameter of the head hair. All heads are attached to a head controller, and the head controller is responsible for the motion of each head. The head can move along the radius of the disc, (actually oblique tangential motion), each head must also be coaxial at the same moment, that is, looking down from the top, all the heads are overlapping at any time (although there is already a multi-head independent technology, can not be limited by this). The disc rotates at a high speed at thousands of rpm, so that the head can read and write data to the specified position on the platter.



Since the hard drive is a high precision device, dust is the enemy, so it must be completely sealed.

2, the working principle of hard disk

The hard disk is logically divided into tracks, cylinders, and sectors.

Each disc of the hard disk has a read-write head and partition of the disk surface area.


The head near the surface of the spindle contact, that is, the smallest line speed place, is a special area, it does not store any data, known as the start-stop or landing area (Landingzone), outside the start and stop area is the data area. In the outer ring, the furthest away from the spindle is the "0" track, where the hard disk data is stored from the outer ring. So, how does the head find the position of the "0" track? There is also a component called "0" track detector, which is used to complete the initial positioning of the hard disk. The "0" track is so important that many hard drives are scrapped just because the "0" track is damaged, which is a pity.
Early hard drives need to run a program called parking before each shutdown, and the effect is to get the head back to the start-stop area. Modern hard drives have been designed to abandon this small, albeit uncomplicated, but unpleasant flaw. When the hard drive is not working, the head stays in the start-stop area and the disk spins when it needs to read and write data from the hard disk. When the rotational speed reaches the rated high speed, the head is lifted by the airflow generated by the disc rotation, and the head is moved to the area where the disc is stored.
The spinning of the disc is quite strong enough to hold the head up and keep a small distance from the disc. The smaller the distance, the higher the sensitivity of the magnetic head to read and write data, and the higher the requirements for the parts of the hard disk. Early-design disk drives keep the heads flying a few microns above the disk surface. Some designs later reduced the flying height of the head on the disc to about 0.1μm~0.5μm, now reaching 0.005μm~0.01μm, which is only 1 per thousand of the diameter of the human hair.
The air flow can not only disengage the head from the opening surface, but also keep it close enough to the surface of the disk, and closely follow the rolling motion of the disks, so that the head flight is in a strictly controlled state. The head must be flown above the disk surface, rather than touching the disc surface, which avoids scratching the magnetic coating and, more importantly, does not allow the magnetic coating to damage the head.
However, the head also can not be too far away from the disk surface, otherwise, can not make the disk surface to achieve strong enough magnetization, difficult to read shavings on the magnetization flip (magnetic pole conversion form, is the way the actual record data on the disk).


Hard disk drive head of low flying height, fast speed, once a small dust into the hard disk seal cavity, or once the head and disk collision, it can cause data loss, forming a bad block, and even caused the head and disk damage. Therefore, the hard disk system seal must be reliable, in non-professional conditions can not open the hard disk sealing chamber, otherwise, the dust will accelerate the damage of the hard disk. In addition, the hard drive head of the seeking servo motor using voice coil rotary or linear motion stepper motor, in the servo tracking adjustment to accurately track the disc's track, so the hard disk work without impact collision, when moving should be handled with care.
This kind of hard disk is usedWinchest (Winchester)Technology-made hard drives, so also known as Wen Pan, are currently used by most hard drives.

3, disc, track, cylinder and sector

Hard disk reading and writing is closely related to the sector. Before talking about the sector and the principles of Read and write, say "Disk", "track", and "cylinder" related to the sector.
1. Disk surface
Hard disk disks are generally made of aluminum alloy substrate, high-speed hard disk may also be made of glass substrate. Each disc of the hard disk has two disk faces (Side), that is, the upper and lower disk surface, usually each disk surface will be used, can store data, become a valid disc, there are very few hard disk face number is singular. Each of these effective discs has a disk face number, numbered sequentially from top to bottom, starting with "0". In the hard disk system, the disk face number is also called magnetic number one, because each effective disk face has a corresponding read and write head. Hard disk disc group in 2~14 tablets, usually have two or three platters, so the panel number (magnetic number one) for 0~3 or 0~5.

2. Track
The disk is divided into concentric circles when formatted, and these concentric circles are called tracks (track). Tracks are numbered sequentially from 0 in the outward order. Each disk of the hard drive has 300~1 024 tracks and more tracks on each side of the new high-capacity hard drive. The information is recorded in the form of a burst of pulses in which the concentric circles are not continuously recorded data, but are divided into segments of arcs that have the same angular velocity as the arcs. Because the radial length is not the same, therefore, the line speed is not the same, the outer ring line speed is larger than the inner ring line speed, that is, the same speed, the outer ring in the same time period, the circular arc length is larger than the circle across the arc length. Each arc is called a sector, and the sector is numbered starting with "1", and the data in each sector is read out or written as a unit. A standard 3.5-inch hard disk face typically has hundreds of to thousands of tracks. The track is "see" missing, but a special form on the disk magnetization of some magnetized areas, in the format of the disk has been planned.

3. Cylinder surface
The same track on all disks forms a cylinder, usually called a cylinder (Cylinder), and the head on each cylinder is numbered from top to bottom, starting with "0". The reading/writing of the data is done by cylinder, that is, the head read/write data first in the same cylinder from the "0" head to operate, in turn, down in the same cylinder on the different disk surface is the head of the operation, only in the same cylinder all the heads of all read/write completed after the head is transferred to the next cylinder (concentric circle of the cylinder face), Since the selected head can only be switched electronically, the selected cylinder must be mechanically switched. The electronic switch is quite fast, much faster than the mechanical head moving towards the adjacent track, so the reading/writing of the data is performed on the cylinder rather than on the disk surface. That is, once a track is full of data, it is written on the next face of the same cylinder, and a cylinder is full before moving to the next sector to begin writing data . Reading data is also done in this way, which improves the read/write efficiency of the hard drive.
The number of cylinders (or the number of tracks per disk) of a hard drive depends on the width of each track (as well as on the size of the head), and also on the size of the distance between tracks determined by the positioning mechanism.

4. Sectors
The operating system stores information on the hard disk as a sector (Sector), with 512 bytes of data and some additional information per sector. A sector has two main parts: The identifier that stores the data location and the data segment where the data is stored.


The first major part of a sector is the identifier. The identifier, which is the sector header, consists of three digits that comprise the three-dimensional address of the sector:

Disc Number: The Head (or disc) where the sector is located

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

Sector code: The position on the track. also called a block number. determines the position of the data on the disc circle.

The header also includes a field that shows whether the sector can reliably store the data, or whether a tag has been found that is not appropriate for a failure. Some hard disk controllers also have an indicator in the sector header that directs the disk to a replacement sector or track when an error occurs in the original sector. Finally, the sector header is terminated with a cyclic redundancy check (CRC) value, which is used by the controller to verify the readout of the sector header, ensuring accuracy.

The second major part of the sector is the data segment that stores the data, which can be divided into data and data-protection error-Correcting codes (ECC). During initial preparation, the computer fills this section with 512 virtual information bytes (the place where the actual data is stored) and ECC numbers corresponding to these virtual information bytes.

5. The request to complete the visit process:

Determine the disk address (cylinder number, magnetic number, Sector code), memory address (source/mesh):

When data needs to be read from disk, the system will pass the logical address of the data to the disk, and the control circuit of the disk will translate the logical address into the physical address according to the addressing logic, that is, determine which track and which sector the data is to be read.

In order to read the data in this sector, the head needs to be placed above this sector in order to achieve this:

1) First must find the cylinder, that is, the head needs to move to the corresponding track, this process is called Seek , the time spent is called seek time,

2) The target sector is then rotated to the head, that is, the disk rotation rotates the target sector under the head. The time spent in this process is called rotational time.

That is, a request for a visit (read/write) The completion process consists of three actions:
1) Seek (time): Move the head to the specified track
2) rotation delay (time): Waits for the specified sector to be rotated from the head
3) data Transfer (time): The actual transmission between the disk and memory

Therefore, the time required to read the sector data (a piece of data) on disk:

ti/o=tseek +tla + n *tWM

which

Tseek for Seek time

TLA is rotation time

TWM for transfer time

4, the disk read and write principle

When the system stores the files on disk, in the manner of cylinder, head, and sector, i.e. all sectors that are first under the first head of the 1th track (that is, the first track of the 1th disc), and then the next head of the same cylinder, ..., a cylinder is stored full and then pushed to the next cylinder until the contents of the file are written to disk.

(The record of the file is stored on the same disk group, it should be placed on a cylinder first, and then stored sequentially on the adjacent cylinder, corresponding to the same cylinder, it should be stored in the order of the disk surface.) )

(from top to bottom, then from outside to inside.) The reading/writing of the data is carried out on the cylinder, not on the face of the disc, first)

The system also reads the data in the same order. read out the data by telling the disk controller to read out the cylinder number, the number of magnets, and the sector area code (three components of the physical address) of the sector. The disk controller directly steps the head assembly into the corresponding cylinder, selecting the corresponding head and waiting for the required sector to move to the head. When the sector arrives, the disk controller reads the header of each sector, compares the address information in these headers with the expected check-out head and cylinder number (i.e. seek), and then looks for the required sector code. When the disk controller finds the sector header, it decides whether to convert the write circuit or read the data and tail records depending on whether the task is a write sector or a read sector. When a sector is found, the disk controller must post-process information for that sector before continuing to look for the next sector. If the data is read, the controller calculates the ECC code for this data, and then compares the ECC code with the recorded ECC code. If the data is written, the controller calculates the ECC code for this data, which is stored with the data. The disk continues to rotate while the controller makes the necessary processing of the data in this sector.

5, the principle of local and disk pre-reading

Due to the characteristics of the storage media, the disk itself is much slower than main memory, coupled with mechanical movement, disk access speed is often one of the hundreds of of main memory, so in order to improve efficiency, to minimize disk I/O. To do this, the disk is often not read strictly on-demand, but is read-ahead every time, even if only one byte is required, and the disk starts from this location, sequentially reading a certain length of data into memory. The rationale for this is the well-known local principle in computer science:

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

The data that is required during the program run is usually relatively centralized.

Due to the high efficiency of disk sequential reads (no seek time required and minimal rotational time), pre-reading can improve I/O efficiency for programs with locality.

The length of the read-ahead is generally the integer multiple of the page. Page is the logical block of Computer Management memory, hardware and operating system tend to divide main memory and disk storage area into contiguous size equal blocks, each storage block is called a page (in many operating systems, the page size is usually 4k), main memory and disk in the page to exchange data. When the program to read the data is not in main memory, will trigger a page fault, the system will send a read signal to the disk, the disk will find the starting position of the data and sequentially read one or several pages back into memory, and then return unexpectedly, the program continues to run.

6, the generation of disk fragmentation

As the saying goes, a picture wins thousands of words, first with a acsii code diagram to explain why the disk fragments.


The above ASCII graph indicates the disk file system, because there is no data file on it, so I represent him as 0.

On the top and left sides of the graph are a-Z 26 letters, which is used to locate the specific location of each data byte, such as the 1th row 1 column is the aa,26 row 26 column is ZZ.

We create a new file, and, of course, our file system has changed, and now it's



: The Table of Contents (TOC) occupies the first four rows, where each file is stored in the TOC.
In, the TOC includes a file named Hello.txt, whose specific content is "Hello, World", where the position in the system is AE to LE.

Then create a new file



, our newly created file Bye.txt clings to the first file hello.txt.

In fact, this is the most ideal system structure, if you put your files in accordance with the expression of one next to each other, tightly affixed together, then read them will be very easy and rapid, this is because the drive in the slowest (relatively) is the transmission arm, less displacement some, The time it takes to read the file data is faster.

But that's exactly what the problem is. Now I want to add some exclamation points to the "Hello, World" to express my strong feelings, now the problem is: on such a system, the file is located in the row there is no place for me to put these exclamation points, because bye.txt occupy the rest of the position.

Now there are two ways to choose, but none of them is perfect.

1. We delete the file from the original location, re-build a file to re-write "Hello, world!!." – This inadvertently extends the time for the file system to read and write.

2. Breaking the file is to write an exclamation point in another empty place, which is "beheaded" – the idea is good, fast and convenient, but it also means slowing down the time to read the next new file.

If you have no idea of the text above,



The method described here is like the way our windows systems are stored, each file is next to each other, but if one of the files is to be changed, it means that the next data will be placed in the rest of the disk.

If this file is deleted, it will leave a space in the system, and over time, our filesystem will become fragmented, and fragments are created.

Try to simply point to the MM listening to the hard drive read and write principle simplified version



The structure of the hard disk is not much to say, our usual computer data are on the track, roughly the same as the disc. Reading is done by the head.



As we all know, our data are stored on the track of the disk sector in the form of information, which is read and written by the rocker-arm control head from the outside of the disk surface. So the external data reads much faster than the inside data.



In fact, most of our files are broken, when the file is not broken, rocker arm only need to find 1 tracks and read by the head, only 1 times can be read successfully, but if the file is broken into 11, then the rocker arm to look for 11 times the track head for 11 reads to complete reading this file , the reading time becomes verbose when it is not broken.

As a result, disk fragmentation is often one of the most important factors in slowing down the system, and the Vista home team is also planning to add disk defragmentation capabilities to future versions of Vista optimizer.

7, hard disk capacity and partition size calculation

In the Linux system, 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 * = 8225280 bytes
Device Boot Start End Bloc KS 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+ linux
/dev/hda6 3826 5100 10241406 Linux
/ DEV/HDA7 5101 5198 787153+-linux swap/solaris
/dev/hda8 5199 6657 11719386 linux
/dev/hda9 6658 7751 878 7523+/dev/hda10 linux
9729 15888253+ 7752 linux
   
    heads is disk face;
  &NB Sp Sectors is a sector,
    cylinders is cylinder,
    Each sector size is 512byte, which is 0.5K;

From the above example, we found that the hard disk has 255 disk faces, there are 63 sectors, 9,729 cylinders, so the entire hard disk volume conversion formula should be:
Number of magnetic faces * number of sectors * size of each sector 512 * number of cylinders = hard disk volume (unit bytes)
So in this case the size of the disk should be calculated as follows:
  255 x [x] x 9729 = 80023749120 bytes
Hint: Because the hard disk manufacturer and operating system conversion is not the same, the hard disk manufacturers to 10 of the method to convert, and the operating system is based on 2 binary system to convert, so in conversion to M or G, different algorithm results are not the same, so our hard disk is sometimes labeled 80G, under the operating system to see a few m;
In the example above, the hard drive manufacturer algorithm and operating system arithmetic compare:
HDD Manufacturers: 80023749120 bytes = 80023749.120 K = 80023.749120 M (convert to large unit, divided by 1000 each time)
Operating system: 80023749120 bytes = 78148192.5 K = 76316.594238281 M (convert to large unit, divided by 1024 each time)
When we look at the size of the partition, we can use the algorithm provided by the manufacturer to simply calculate the size of the partition, moving the decimal point forward six bits is the size of G, for example, the size of hda1 is about 6.144831G;

Hard disk read and write principle

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.