How Inode works and soft and hard links

Source: Internet
Author: User

inode working principle and soft connection, hard link


Inode:


In a Linux file system, no matter what type of file is saved in the disk partition, the system assigns a number called the index node, which is referred to as the Inode


The Inode stores many parameters of the file:

File type, permissions. Uid,gid, belong to the master, belong to the group

Number of links (pointing to the number of path names for this file name)

The size of the file and the different timestamps

Data pointer to a file on disk

....


In Linux, the inode number in the metadata (the Inode is part of the file metadata but does not contain a file name, the inode number is the index node number) is the unique identifier of the file and not the filename. File name is only for the convenience of people's memory and use, the system or program through the inode number to find the correct file data block, the system to obtain the file content process is as follows:


650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/85/37/wKioL1edW0ng7SoqAAAPufXmUFc455.png "title=" Inode.png "alt=" Wkiol1edw0ng7soqaaapufxmufc455.png "/>


How the Inode works:


The file is composed of metadata and data content, the metadata is stored in the Inode table, and the data content is stored in the data block

In the Inode table in addition to the metadata, there are pointers, the pointer is the path of the data block


Direct pointer: The direct pointer has 12, points to 12 data blocks, the data block is generally the default 4k, so the direct pointer to the

is less than the 12*4k=48k file


Indirect pointer: In the Inode table, the direct pointer is the indirect pointer, and the indirect pointer points to a data block, but this block

Does not store the data, but as a data block pointer, each pointer size is 4 bytes, so a block of data can be stored 4096/4=1024 data block pointers, the same data block pointer will point to a 4k size data block, the last indirect pointer

Can point to a file size of 1024*4k=4096k=4m


Double indirect pointer: After the indirect pointer, the double indirect pointer can be as understanding as the indirect pointer, but the last point of the content of the data block as a block pointer, so that can point to a file size of 1024*1024*4k=4g



The following, and so on, is the same principle.




650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M02/85/3A/wKiom1edmHHyk4AvAAH3oEH8HGc415.png-wh_500x0-wm_3 -wmp_4-s_3264293738.png "title=" multi-point. png "alt=" wkiom1edmhhyk4avaah3oeh8hgc415.png-wh_50 "/>


650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M01/85/3A/wKioL1edmFDAG6fmAAEJs3al2Ro059.png-wh_500x0-wm_3 -wmp_4-s_4047286606.png "title=" direct pointer. png "style=" Float:none; "alt=" Wkiol1edmfdag6fmaaejs3al2ro059.png-wh_50 "/>


650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M02/85/3A/wKiom1edmE_TzVY6AADTo6_-Dqk277.png-wh_500x0-wm_3 -wmp_4-s_1086401152.png "style=" Float:none; "title=" Jianie.png "alt=" wkiom1edme_tzvy6aadto6_-dqk277.png-wh_50 "/ >



Hard Links: can be understood as a different name for a file


Characteristics:

1. hard-link files have the same inode and data block (date block)

2. Only files that already exist can be created

3. Deleting a hard-link file does not affect other files that have the same inode number

4. Cannot create hard links across file systems

5. The directory cannot be created, only the file can be created

6. Creating a hard link increases the number of links, and deleting a link reduces the number of links

Figure A


650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/85/38/wKiom1eda9OwF5vaAAGNqlDcjoQ154.png "title=" should be. png " alt= "Wkiom1eda9owf5vaaagnqldcjoq154.png"/>

Figure II

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/85/38/wKioL1edZNKDX7tQAADq_wHYzpU778.png "title=" vv.png "alt=" Wkiol1edznkdx7tqaadq_whyzpu778.png "/>


Soft Link: A shortcut that can be understood as a file


Characteristics:

    1. The soft link file has its own file attributes and permissions, etc.

2. You can create a soft connection to a nonexistent file or directory

3. Soft connections can be created across file systems

4. When you create a soft connection, the number of links does not increase

5. Deleting a soft link file does not affect the source file, but if the source file is deleted, its soft link file becomes red and the content cannot be accessed

650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M02/85/38/wKiom1eda_bClmhNAAOYAKGLQuU333.png "title=" soft. png " alt= "Wkiom1eda_bclmhnaaoyakglquu333.png"/>


File access diagram:


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/85/39/wKiom1edbXyzec8RAAB-yrS2qW8203.png "title=" hint. png "alt=" Wkiom1edbxyzec8raab-yrs2qw8203.png "/>


Summarize the differences between hard links and soft connection files:


1. the source file and the hard link file inode number is the same file, but the file name is not the same, so the Size property and other information are the same

But the source file and the soft link file inode number is different, is two files, so the size, attributes and so on are not the same

2. When viewing the detailed properties of the file, it is indicated that the soft connection is a link file (example C->b), and the hard link file is not, so we can think that the link file and source file are completely equal, and the soft connection can be understood as a shortcut to the source file.

3. The number of linked files changes, the number of links to the soft link file will not change, and the number of links to hard linked files will change

4. Soft connection is not restricted by file system, hard link can only be in the same file system

5. When a source file is moved from one directory to another, accessing the hard link file is not affected, and accessing the soft link file will cause an error.



How Inode works and soft and hard links

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.