Understanding disks and file systems

Source: Internet
Author: User

File SystemIs built on the hard disk, so to understand the file system, you must first understand the basic composition of the Disk:

1. Physical Structure of the hard disk:

Hard Disks are mainly used for data storage at a large storage capacity and low price. Currently, hard disks are mainly divided into two types: 3.5-inch desktop hard disks and 2.5-inch notebook hard disks.Head, mechanical arm, spindle motor and disk DiskComposition:

650) This. length = 650; "src =" http://s3.51cto.com/wyfs02/M02/45/48/wKioL1PmJ-TxqI5JAAF6VrUHqwo083.jpg "Title =" 2215404_8_thumb.jpg "width =" 400 "Height =" 301 "border =" 0 "hspace =" 0 "vspace =" 0 "style =" Width: 400px; Height: 301px; "alt =" wKioL1PmJ-TxqI5JAAF6VrUHqwo083.jpg "/>

Data is mainly stored on disks. A hard disk has one or more disks. When reading and writing a hard disk, the disk is driven by the Spindle Motor to rotate at high speed. When the disk is rotated, if the head is kept in the same position, the head will draw a circular track on the disk. This circular track is calledTrack)To the center of the disk, multiple tracks can be drawn. The information on the hard disk is stored along this track. The tracks on the disk start from 0 in turn.

Each track is divided into equal arc segments, which are calledSector (sector)The number of sectors of the outer ring track is greater than the number of sectors of the inner ring track. The size of each sector is 512 bytes, and the sector is the minimum storage unit of the hard disk.

650) This. length = 650; "src =" http://s3.51cto.com/wyfs02/M02/45/49/wKioL1PmObvwKT-lAAEC0AInwc0251.jpg "Title =" qq20140809230422.png "width =" 300 "Height =" 236 "border =" 0 "hspace =" 0 "vspace =" 0 "style =" Width: 300px; Height: 236px; "alt =" wKioL1PmObvwKT-lAAEC0AInwc0251.jpg "/>

Tracks On all disksCylinder), The magnetic column is the minimum unit to separate the hard disk

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/45/49/wKiom1PmOzqQBvBTAAFXp7xYFjU837.jpg "Title =" qq20140809231525.png "alt =" wkiom1p1_qqbvbtaafxp7xyfju837.jpg "/>

2. Partition ):Logical boundaries of Hard Disks

When a hard disk is obtained, it cannot be used directly. The first thing to do is partitioning and formatting. partitions are used to create a file system. There are three types of partitions:Primary partition, extended partition and logical Partition

The 0th sector of the 0th track of a physical disk isMBR (Master Boot Record)Hard DiskMaster Boot Record;MBR does not belong to any partition, nor can it be read by disk operations provided by the operating system. However, it can be modified and overwritten by commands.

The first 446byte of MBR stores the bootloader information, and the last 64bytes stores the start and end cylindrical information of a partition every 16 bytes. The last two bytes are magic number, which indicates whether the MBR is valid.

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/45/49/wKiom1PmSN6QFAApAABnolRKCgQ048.jpg "Title =" qq20140810001257.png "alt =" wkiom1pmsn6qfaapaabnolrkcgq048.jpg "/>

A primary partition is also called a primary disk partition. The Boot information of the operating system must be stored in the primary partition. The primary partition is directly created on the hard disk and cannot be divided into other types of partitions; therefore, each primary partition is equivalent to a logical disk. Each hard disk can have up to four primary partitions.

Since each hard disk can only create four primary partitions, you can create oneExtended partition)Up to one extended partition can be created. Extended partitions cannot be formatted and used directly.Logical Partition)The logical partition is a continuous area on the hard disk. The difference is that each primary partition has its own independent boot block, but the logical partition does not, and the logical partition can have several

3. Format):Formatting is an operation to initialize a disk or disk partition.

Because each operating system operates different files in different ways, in order to store data, you need to format the disk or partition to become available to the operating system.File System)Formats:Low-level formatting and advanced formatting;Formatting will clear all data in the existing disk or partition.

Hard Disks are usually formatted at a low level when they are released. The so-called low-level formatting is to draw a blank hard disk from the magnetic channel and a cylindrical disk, then divide the track into sectors, and each sector is divided into the ID of the marked part, low-level formatting can only be performed on the entire hard disk, but not on a single partition.

Formatting refers to advanced formatting. Formatting refers to the creation of disks or partitions.File System

File SystemIs the method and data structure used by the operating system to identify the files on the storage device or partition; that is, the method to organize files on the storage device. From a system perspective, a file system is a system that organizes and allocates the space of file storage devices, stores and protects and searches stored files. The file system itself is just a software

In Linux, multiple file systems, such as ext2, ext3, and vfat, are allowed to coexist. By using the same I/O system call, you can operate on any file in Linux without considering the specific file system format. Further, you can perform file operations across file systems.

"Everything is a file"Is one of the basic philosophies of Unix/Linux. Not only ordinary files, directories, character devices, Block devices, sockets, etc. are treated as files in Unix/Linux. Although they have different types, they provide the same set of Operation interfaces.

Virtual File System (VFS)It is the key to implementing Linux features. VFS is the software layer in the Linux kernel and is used to provide file system interfaces for user space programs. It also provides an abstract function in the kernel, different file systems are allowed to coexist. All file systems in the system depend not only on VFS coexistence, but also on VFS collaboration

To support various actual file systems, VFS defines the basic and conceptual interfaces and data structures supported by all file systems; at the same time, the actual file system also provides the abstract interface and data structure expected by VFS, and maintains its own concepts, such as files and directories, in a form consistent with the definition of VFS. In other words, to be supported by Linux, an actual file system must provide an interface that complies with the VFS standard to work with the VFS system. The actual file system hides the specific implementation details under the same interface and data structure, so in the VFS layer and other parts of the kernel, all file systems are the same.

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/45/52/wKioL1PnKYeQjrG1AABtGAsznPI891.jpg "Title =" 3.jpg" alt = "wkiol1pnkyeqjrg1aabtgasznpi891.jpg"/>

For ext2 file systems, hard disks or partitions are first divided into multipleBlock, EachBlockThe block size is the same. The block size starts from 0. The typical size is 1024bytes or 4096 bytes. The size is determined when the file system is created. You can manually specify the size, but it cannot be changed after the file system is created; these blocks are grouped into multipleBlock group), Each block group has the same number of blocks.

Block is the region where the file content and data are recorded.Inode (index node)The inode records the information of "related attributes of the file and the block in which the file content is stored". In other words, apart from recording the attributes of the file, at the same time, you must have the pointer function, that is, point to the block where the file content is placed, so that the operating system can correctly obtain the file content, the following information is recorded by inode (more than that, of course ):

Owner and Group of the file)

Read/write/excute)

Type of the file)

The time when the file is created or the status changes (ctime), the last read time (atime), and the last modified time (mtime)

Capacity of the file

Define the flag of file features, such as setuid...

Pointer)

EachInodeThe node size, generally 128 bytes or 256 bytes. The total number of inode nodes, which is given during formatting. The inode number is counted from 1.

Each block group has a correspondingGroup Descriptor (group descriptor), These group descriptor are together and placed at the beginning of the blockSuper BlockIt is used to describe the overall information of the block group and store the block pointer, that is, the number of the block on the partition.

In the group descriptor of the block group, there is a block pointer pointing toBlock bitmap, Each bit in the block bitmap indicates a block. If the bit is 0, it indicates that there is data in the block. If the bit is 1, it indicates that the block is idle. Note that this block bitmap itself is exactly as small as one block. If the block size is s bytes, the block bitmap can only record 8 * s blocks (because one byte equals 8 bits, and one bit corresponds to one block ). That is to say, a block group can only be as large as 8 * S * s bytes.

In the group descriptor of the block group, another block pointer pointsInode bitmapThe bitmap is also as big as a block. The inode is not used, and each bit in it corresponds to an inode.

Another important block pointer in the block group's descriptor is pointing to the so-calledInode table. This inode table is more than one block. This inode table is formed by putting all inode in the block group together.

Super Block): Part of data starting from byte 1024 (the first byte at the beginning of the hard disk partition is byte 0. Because the minimum block size is 1024 bytes, the super block may be in Block 1 (the block size is exactly 1024 bytes), or block 0.

When the block size is greater than 1024bytes. Each ext2 file system must contain a super block, which stores a large amount of basic information about the file system, including the block size and the number of blocks contained in each group. At the same time, the system backs up the super block and stores the backup in the first block of the block group.

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/45/7E/wKiom1PobjHQ3cJiAACL33wu4EE827.jpg "Title =" 13486059_1.png "alt =" wkiom1pobjhq3cjiaacl33wu4ee827.jpg "/>

This article is from the "pole boy" blog, please be sure to keep this source http://wtime.blog.51cto.com/8829658/1538677

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.