Linux file system

Source: Internet
Author: User

I. What is a file system

A file system is a method and data structure used by the operating system to explicitly store files on a storage device (common disk, also a NAND flash-based SSD) or partition, that is, the method of organizing files on a storage device. In short, it is to be able to easily from the hard disk and other hardware devices to manage the operation of the system of data.


Second, the Linux file system

Linux supports a variety of file systems, common with ext2,ext3,ext4,btrfs and many others.

1. Supported file systems

The reason why Linux can support so many file systems is that it already contains a wide variety of file system information in the kernel.

We can check the file system supported by the Linux ls-l/lib/modules/$ (uname-r)/kernel/fs.

650) this.width=650; "src=" http://s4.51cto.com/wyfs02/M00/7E/94/wKiom1cEvvThN-fAAAECyXJdImM752.jpg "title=" 1.JPG " Width= "610" height= "123" border= "0" hspace= "0" vspace= "0" style= "width:610px;height:123px;" alt= " Wkiom1cevvthn-faaaecyxjdimm752.jpg "/>

You can see the modules that contain multiple file systems in this directory.

Another command can view the file systems that have been loaded into the in-memory support: # Cat/proc/filesystems

650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M01/7E/90/wKioL1cEwOawClB2AACZBG0k13Y016.jpg "title=" ah. jpg " alt= "Wkiol1cewoawclb2aaczbg0k13y016.jpg"/>

So how does Linux identify a variety of file systems? Let's take a look.

2. Linux VFS

VFS, virtual file swicth.The function is to use standard UNIX system calls to read and write different file systems on different physical media. Vfsis a can letOpen (), read (), write ()such as system calls do not care about the underlying storage media and file system type can work on the adhesive layer. In theLinux under, throughVfs, an abstract generic access interface masks the difference between the underlying file system and the physical medium. each type of file system code hides the details of the implementation. Therefore, for the VFS layer andKernelother parts of the system, each type of filesystem looks the same. WholeVfscan be used to indicate

650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M01/7E/95/wKiom1cEyKfRZ05UAAKV0nUE82k585.jpg "title=" 6.jpg " Width= "height=" border= "0" hspace= "0" vspace= "0" style= "width:600px;height:500px;" alt= " Wkiom1ceykfrz05uaakv0nue82k585.jpg "/>

3. Linux Ext File System

The operating system's file data includes, in addition to the actual content, a variety of other data, such as permissions, owner, genus, called metadata. File systems typically store these two types of data separately. Linux stores metadata in the Inode, where the actual data is located in data block, and the file system plans the Inode and data block at the very beginning of the format, so that unless reformatting or changing the file system size, the inode and the data Block will not change after it is fixed. In addition, when the Ext file system is formatted, it is differentiated into multiple block groups, each containing a separate inode/block/superblock, and so on.


1) Inode table

These basic properties are 1, the owner of the file and the group

2, the size of the file

3. File access Mode (Read,write,execute)

4. When the file was created or changed in status

5. Time of last read/modify

6, the definition of file characteristics of the flag (setuid, etc.)

7, the real data point (i.e. where the data block)

In addition, the number and size of the inode is also fixed in the format.

The main features of the inode are: each inode size is 128bytes

Each file can occupy only one inode the number of files stored is related to the number of inode

The system needs to find the inode first, and analyze the permissions and the user, if it is compliant to let the user read the actual data content.

(the file information contained in the Inode can be viewed by stat filename)



2) data block (blocks)

Data block is the content used to store the actual data.

He has the following characteristics: 1, block size in the format is determined, and each block has a number

2, each block can only hold one file of data, a file can occupy more than one block

3, therefore, if the block is set too large, it will cause wasted space


In addition to the inode and data block, we also need to know the following names:


3) Superblock (Super block): He is the place to record information about the entire file system, no superblock, there is no file system, the general size of 1024bytes,superblock information can be viewed with the command dumpe2fs.

It records information such as: 1, block and inode total

2. Number of unused and used Inode/block

3, block and inode size (block for 1k,2k,4k,inode 128bytes)

4, File system mount time, the last time the data was written, the last time to check the disk (fsck) and other information about the file system.

5, a Validbit value, if this file system is mounted, the value is 0, if not mounted, the value is 1.

4) file System Description (filesystem description)

The block number used to describe the start and end of each block group, and a description of the block number between each section (Superblock,bitmap,inodemap,data block).


5) block Bitmap (block table) and Inode bitmap (inode table)

Block bitmap is used to record which block has been used for which block is useless.

Similarly, Inode bitmap is used to record Inode table.


Here is a diagram showing the relationship of the above name:

650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M00/7E/94/wKioL1cE3eTQvPPsAAE06i-AVW8745.jpg "title=" 7.jpg " Width= "575" height= "289" border= "0" hspace= "0" vspace= "0" style= "WIDTH:575PX;HEIGHT:289PX;" alt= " Wkiol1ce3etqvppsaae06i-avw8745.jpg "/>


Now specify how Linux reads the files:

Example: The root user reads the/etc/fstab file

Since the Linux directory tree reads are always started from the root directory, the system passes the mounted information to find the inode of the mount point (usually the topmost inode number of a filesystem starts at 2), at which point the inode information and contents of the root directory can be obtained and read according to this inode (requires R , x permissions) root directory of the file name data within the block, and find the inode number of/etc directory, find/etc block blocks, read (need to have r,x permission) block blocks content, find content has fstab and its inode number, find Fstab inode, The Fstab file is located in the block blocks, with (r,x) permissions, you can access and read the contents of the file.

Note: The file name is stored in the block





The Inode diagram for soft links and hard links:

Soft links are similar to shortcuts in Windows.

A hard link is equal to the number of connections plus one, even if the source file is deleted, only the number of connections is reduced by one.

650) this.width=650; "src=" http://s4.51cto.com/wyfs02/M02/7E/95/wKioL1cE8ofwuMmTAAE2Vqwpefo574.jpg "title=" 8.jpg " alt= "Wkiol1ce8ofwummtaae2vqwpefo574.jpg"/>





Note: 1. When the source data is deleted, the soft link becomes invalid.

2, but hard link does not, because the hard link is equivalent to the backup of the source data, even if the source data is deleted, can also be accessed normally.

3, it is important to note that hard links can not be linked to the directory, and on different file systems can not be linked, so the soft link instead of more extensive.




Reference: "Bird's Linux Private cuisine"





























This article is from the "11095819" blog, please be sure to keep this source http://11105819.blog.51cto.com/11095819/1761042

Linux file system

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.