Hard disk storage principle

Source: Internet
Author: User

Transfer from http://blog.sina.com.cn/s/blog_625985cb0100ymsr.html

Hard drives are one of the most commonly used memory on your computer today. As we all know, computers are magical because they have the ability to process data at high speed. This data is stored on the hard drive as a file. However, computers are not as smart as people. When reading the corresponding file, you must give the corresponding rules. This is the concept of partitioning. A partition is essentially a format for a hard disk. When we create the partition, we have set the physical parameters of the hard disk, specified the hard disk master boot record (that is, the master boot record, generally referred to as MBR) and the location of the boot record backup. The information required for the file system and other operating systems to manage the hard drive is implemented by a later advanced format, the Format command.

Faces, tracks, and sectors

After the hard disk is partitioned, it is divided into polygons (Side), tracks, and sectors (Sector). It is important to note that these are just virtual concepts, not really on the hard drive to draw tracks. First from the face, the hard disk is generally composed of a piece or a few pieces of circular film superimposed. We say that each circular film has two "faces", and these two faces are used to store data. According to the number of faces, which is called 0-side, 1-face, 2-side ... Since each face is proprietary to a read-write head, it is also commonly used for 0 head, 1 head ... Call it. According to the hard disk capacity and specifications, hard disk surface number (or the number of head) is not necessarily the same, less than 2 side, more than dozens of sides. Tracks with the same track number on each face are combined, called a cylinder (Cylinder) (1). Figure

Above we mentioned the concept of the track. So what exactly is a track? Since the disk is rotated, the data that is written continuously is arranged on a circumference. We call this circle a track. (2) If the read-write head moves a distance along the radius of the circular film, the data written later is arranged on another track. Depending on the specifications of the hard disk, the number of tracks can range from hundreds of to thousands of, a track can hold several kilobytes of data, and the host read and write often do not need to read and write so much, so, the track is divided into several paragraphs, each section is called a sector. A sector typically holds 512 bytes of data. Sectors also need to be numbered, sectors in the same track, called 1 sectors, 2 sectors, respectively.

The computer reads and writes to the hard disk, is in the efficiency consideration, is takes the sector as the basic unit. Even if the computer only needs a byte stored on the hard disk, it must read all 512 bytes in the sector of the byte in memory at once, and then use the desired byte. However, in the above, we also mentioned that the hard disk above, track, Sector division surface is not visible any traces, although the head can be based on the radius of a track to align the track, but how to find in the end-to-end sector in a circle of the desired sector? Originally, each sector is not only composed of 512 bytes, the data accessed by the computer before and after the two ends, there are some other specific data, which constitutes a sector of the boundary mark, the flag contains sector numbers and other information. The computer relies on these flags to identify sectors

Data structure of the hard disk

In the previous section, we talked about the general principle of storing data on a hard disk. In order to gain a deeper understanding of the hard drive, we must also have a simple understanding of the data structure of the hard disk. The data on the hard disk can be broadly divided into 5 parts according to its different characteristics and functions: MBR, DBR, fat, dir and data. Let's take a look at each:

1. MBR area

The MBR (main boot record master boot recording area) is located on the 0 track 0 cylinder 1 sector of the entire hard drive. However, in a total of 512 bytes of the main boot sector, the MBR occupies only 446 of these bytes, the other 64 bytes are given to the DPT (disk Partition table hard disk partition table) (see table), and the last two bytes "55,aa" is the end of the partition flag. This whole constitutes the main boot sector of the hard disk. Figure

The Master boot record contains a series of parameters and a boot program for the hard disk. The primary role of the hard disk bootstrapper is to check that the partition table is correct and boot the operating system on the partition that has the activation flag after the system hardware completes the self-test, and give control to the startup program. The MBR is made up of partitioner (such as Fdisk. EXE), it does not rely on any operating system, and the hard drive boot program can also be changed to achieve multi-system coexistence.

Below, let's take a look at the master boot record in an example to make it more intuitive:

Example: 0B FE BF FC 3F xx xx, 7E, BB 00

Here we can see that the first "80" is a partition of the activation flag, indicating that the system is bootable; "01 01 00" indicates that the partition begins with the first magnetic number 01, the beginning of the sector area code is 01, the beginning of the cylinder number is xx; "0B" indicates that the system type of the partition is FAT32, and the other more commonly FAT16), (NTFS), "FE BF FC" indicates that the partition end of the magnetic number is 254, the partition end of the sector area code is 63, the partition end of the cylinder number is 764; "3F 00 00 00" means that the relative sector area code for the first sector is a quarter; "7E-BB 00" Indicates that the total number of sectors is 12289622.

2. DBR Zone

DBR (Dos boot record) is the meaning of the operating system boot record area. It is typically located on the hard disk's 0 track 1 cylinder 1 sector, which is the first sector that the operating system can access directly, including a bootstrap and a sub-parameter record table called BPB (Bios Parameter Block). The main task of the bootloader is that when the MBR takes control of the system to it, it is judged that the first two files of this partition and the directory are the boot files of the operating system (in DOS, for example, IO). SYS and MSDOS. SYS). If it is determined to exist, read it into memory and give control to the file. The BPB parameter block records important parameters such as the start sector, end sector, file storage format, hard disk media descriptor, root directory size, fat count, allocation unit size, and so on for the sub-region. DBR is made up of the advanced formatter (that is, format. COM and other programs).

3. Fat Zone

Behind the DBR is the area of fat (file Allocation table) that we are more familiar with. Before explaining the concept of a file allocation table, let's talk about the concept of cluster (Cluster). When a file occupies disk space, the base unit is not a byte but a cluster. In general, the floppy disk per cluster is 1 sectors, the number of disk per cluster sector and the total size of the hard disk capacity, it may be 4, 8, 16, 32, 64 ...

The data of the same file does not necessarily reside in a contiguous area of the disk, but is often divided into segments that are stored like a chain. This type of storage is called chained storage of files. Since the connection information (i.e. fat) between the segment and segment is kept on the hard disk, the operating system is always able to accurately find the location of each segment and read it correctly when reading the file.

To achieve chained storage of files, the hard disk must accurately record which clusters have been consumed by the file, and must indicate the cluster number of the next cluster that stores the successor for each occupied cluster. For the last cluster of a file, indicate that there are no subsequent clusters in this cluster. These are saved by the Fat table, which has many table entries, each of which records a cluster of information. Because fat is important for file management, FAT has a backup that builds the same fat after the original fat. All items in the initial fat are marked as "unoccupied", but if the disk is partially damaged, the formatter detects the damaged cluster, and the corresponding entry is "Bad cluster", which is no longer used when the file is saved. Fat has the same number of items as the total number of clusters on the hard disk, and each item occupies a number of bytes to match the total number of clusters, because the cluster number needs to be stored. There are several formats for fat, the most common being FAT16 and FAT32.

4. Dir Zone

DIR (directory) is the root area, followed by the second Fat table (the Fat table that is backed up), records the starting unit of each file (directory) in the root directory, the properties of the file, and so on. When locating the file location, the operating system can know the exact location and size of the file on the hard disk based on the starting unit in Dir, combined with the fat table.

5. Data area

The data area is where the data is stored in a real sense, after the Dir area, occupying most of the data space on the hard disk.

Disk's file system
Often listen to the experts talk about FAT16, FAT32, NTFS and other nouns, friends may vaguely know that this is the meaning of the file system. But what does it mean for so many file systems? Today, we come together to learn:

1. What is a file system?
The so-called file system, which is the structure of the operating system to organize, store, and name files. The difference between a disk or partition and the file system it includes is important, and most applications are based on file systems and do not work on different file systems.

2. File System Big Family
There are many commonly used file systems, MS-DOS and Windows 3.x use the FAT16 file system, Windows 98 by default also uses Fat16,windows 98 and me to support FAT16, FAT32 two file systems simultaneously, Windows NT supports FAT16, NTFS two file systems, Windows 2000 can support FAT16, FAT32, NTFS three file systems, Linux can support a variety of file systems, such as FAT16, FAT32, NTFS, Minix, ext, ext2, Xiafs, HPFS, VFAT, etc., but Linux generally uses the ext2 file system. The following is a brief introduction to these file systems:

(1) FAT16
The full name of fat is "file Allocation table (filesystem)", which was first applied to MS-dos in 1982. The main advantage of the FAT file system is that it can allow access to multiple operating systems, such as MS-DOS, Windows 3.x, Windows 9x, Windows NT, and OS/2. This file system follows the 8.3 naming convention when it is used (that is, a file name of up to 8 characters with an extension of 3 characters).

(2) VFAT
VFAT is the meaning of "Extended file allocation table system", which is mainly used in Windows 95. It extends the FAT16 file system, provides support for long filenames, filenames up to 255 characters, VFAT still has extensions, and supports file date and time attributes, preserves file creation date/time for each file, the date/time when the file was last modified, and the date when the file was last opened/ Three date/time of the time.

(3) FAT32
FAT32 is primarily used in Windows 98 systems, which can enhance disk performance and increase free disk space. Because the size of one cluster is much smaller than FAT16, it can save disk space compared to FAT16. And it supports more than 2G of partition size. Friends from the schedule can be seen FAT16 and FAT32 a difference.

(4) HPFS
High-performance file system. OS/2 's high Performance file system (HPFS) overcomes the disadvantage that the FAT file system is not suitable for high-end operating systems, HPFS supports long filenames, and is more error-correcting than the FAT file system. Windows NT also supports HPFS, making it easier to transition from OS/2 to Windows NT. HPFS and NTFS have many of the same features, including long filenames, but with poor reliability.

(5) Ntfs
NTFS is an advanced file system dedicated to the Windows nt/2000 operating system that supports file system failure recovery, especially large storage media, long filenames. The main weakness of NTFS is that it can only be recognized by Windows nt/2000, although it may read the files of the FAT file system and the HPFS file system, but its files cannot be accessed by the FAT file system and the HPFS file system, so compatibility is problematic.

Ext2
This is the most used file system in Linux because it is designed specifically for Linux, with the fastest speed and minimum CPU usage. The ext2 can be used for standard block devices, such as hard disks, and also on removable storage devices such as floppy disks. Now there is a new generation of Linux file systems such as SGI's XFS, ReiserFS, ext3 file systems, and so forth.

Summary: Although the above author introduced 6 kinds of file system, but the dominant position is FAT16/32, NTFS and other few, the most use of course is FAT32. As long as you right-click a drive's properties in My computer, you can see the file system you are using in the General option (figure).

Hard disk storage 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.