How the Inode works in Linux

Source: Internet
Author: User

When partitioning and formatting partitions, the entire partition is divided into two parts, the Inode and data block (where the actual data is placed in the data region), which is the unique identifier (directory, archive) file in a file system. When you need to access this file, you must first locate and read the inode of the file. Inode stores a number of important parameters of the file, where the unique identity is called Inumber, other information is created time (ctime), modification Time (mtime), file size, owner, attribution user group, read and write permissions, data block number and other information


So the document is composed of two parts:

1. Meta Data: Inode table (index node tables)

2, data content: Data block (block)


The inode contains meta information for the file, specifically the following:

* Number of bytes in the file

* User ID of the owner of the file

* The group ID of the file

* file read, write, execute permissions

* File timestamp, total three: CTime refers to the time when the inode was last changed, mtime refers to the time when the file content was last changed, atime refers to the time when the file was last opened.

* Number of links, that is, how many filenames point to this inode

* Location of File data block



The file system starts with the inode and block planning, and unless reformatted, the inode and block will not change after they are fixed. Each inode and block are numbered with their own, and the inode is the attribute of the record file, a file occupies an inode, and the block code where the file data resides is recorded. Block is the actual record of the contents of the file, if the file is too large will occupy more than block.


Since each inode and block have their own number, and each file will occupy the location of the data block in the Inode,inode, so you can brake ah, if you can find the inode of the file, you can find the data placed in the file block number, You will be able to find the time data for the file. Therefore, the inode has the function of pointers, and in the inode structure, there is not only one pointer, but there are many.

In the Inode table, the 第1-12 block pointer is treated as a direct block pointer, because a pointer can only point to a block block, so if a block block has 4 K of storage space, then the use of direct block pointers to the maximum number of files can not exceed 48K, then need to use the indirect block pointer, or double indirect block pointers, or triple indirect block pointer.

Direct block pointer

The direct block pointer is the number of block blocks directly recorded in the Inode, directly pointing to block blocks,

If a file's attributes and permissions data is placed in the INODE4 number, and this inode records the actual location of the file data placement Point 2,7,13,15 the four block numbers, the operating system can then arrange the reading order of the disk, you can directly read the contents of four blocks, The data is read as shown

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/85/38/wKioL1edbISBeYJzAAEjwJTB_4o298.png "title=" 4.png " alt= "Wkiol1edbisbeyjzaaejwjtb_4o298.png"/>


Indirect block pointers

Indirect block pointers, in fact, and direct block pointers are similar, they are pointers, just direct block Pointer direct to the block block is stored in the file data, and the indirect block pointer is to point to the block block continues to use as a pointer block, so the indirect pointer to the block block is stored pointer information, It will continue to point to the file data stored in the next block block.


Double indirect block pointer

Understanding the indirect pointer block, then the double indirect pointer block is easy to understand, it is on the basis of the indirect pointer block is also used as a pointer to block the second point, so that you can point to a more block block.


Triple Indirect Block pointer

The triple indirect block pointer is the same as the double, but the third point of the block is also used as a pointer block as a pointer, so you can execute the block blocks that have been followed.

Previously mentioned that the use of direct block pointers to the maximum number of files can not exceed 48K, assuming that a pointer block requires 4 bytes, a block block has 4 K of storage space, then a block block can store 1024 pointer blocks, so the indirect block pointer to the file maximum can be stored 1024*4k= 4M files, and so on the use of double indirect block pointers to file maximum storage space is 1024*1024*4k=4g, using the triple indirect block pointer to the maximum amount of storage space can reach 1024*1024*1024*4k=4t.


INODE table Structure:

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= "http ://s1.51cto.com/wyfs02/m01/85/39/wkiom1edbjlcyqwqaagqc8vu-5e929.png "title=" 1.PNG "alt=" Wkiom1edbjlcyqwqaagqc8vu-5e929.png "/>

Catalog Files:

Ordinary files are composed of Indoe+block, under the Linux directory is also a file, then the directory file is what structure, directory file structure is very simple, is a series of directory items (dirent) list. Each directory entry consists of two parts: the file name of the included file, and the inode number that corresponds to the file name. Find the Inode information of the file in the directory through the catalog item, then we can find the block blocks and data information of the file.

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= "http ://s2.51cto.com/wyfs02/m01/85/38/wkiol1edblug0l8yaaeoltfla9c419.png "title=" 2.PNG "alt=" Wkiol1edblug0l8yaaeoltfla9c419.png "/>

In the file system, users can use the DF command to see the total number of inode and the number of uses for each disk partition.

Command: Df-i

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= "http ://s1.51cto.com/wyfs02/m01/85/38/wkiol1edbxyricbvaaanq-6nyta388.png "title=" 5.PNG "alt=" Wkiol1edbxyricbvaaanq-6nyta388.png "/>

Because the inode also occupies a certain amount of disk space, when the inode use space is exhausted, even if the disk still has storage space can not be used! All when the disk display still has free space, but the use of the hint of insufficient space, it is possible that the inode is used to complete the result.


This article is from the "I ' m Groot" blog, so be sure to keep this source http://groot.blog.51cto.com/11448219/1832283

How the Inode works in Linux

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.