Inode nodes in Linux

Source: Internet
Author: User

I. BACKGROUND

Traditional disk and file system applications, a partition can only be formatted as a file system, so we can say that a filesystem is a partition. But because of the use of new technologies, such as LVM and floppy disk arrays (software RAID), which we often hear, these technologies can format a partition as multiple file systems (such as LVM), and also be able to synthesize multiple partitions into a filesystem (lvm,raid), which we can often call A data that can be mounted is a file system instead of a partition.

So how does the file system work? This is related to the operating system's data. The newer operating system's file data, in addition to the actual contents of The file, usually contains a lot of attributes, such as the Linux operating system file permissions (RWX) and file attributes (owner, group, time parameters, etc.). The file system typically stores the two parts of the data in separate blocks, and the metadata is stored in the Inode table, and the data is stored in the data block. There are many metadata content for each file, including file type, permissions, number of links, and each file has its own metadata table, which contains a description of each file.


Ii. Brief meaning of Inode and block

Inode: Records the metadata of a file, a file occupies an inode, while recording the block number of the file's data;

Block: The actual record of the contents of the file, if the file is too large, will occupy more than block.


Iii. How the Inode works

Since each inode and block are numbered, each file occupies a block number in which the file data is stored in a inode,inode. So, what we can know is that if we can find the inode of the file, then we will naturally know the block number of the file lock to hold the data and, of course, can read the actual data of the file.


Let's illustrate this in the following illustration:

Assuming that/dir1/a has XXX data, there are yyy data in the dir1/b

There is an index table in the system (Inode table),The Index table is a separate one for each partition, with a node table in each partition, a node number and metadata, and pointers when accessingDir1the time, because/dir1is a folder that needs to be accessed first/root, while the root is in the node number2the location,2numbered nodes have many directories under it, and the root has its own pointer to the data block, which has two parts, one for the subdirectory, the other for the subdirectory's node number, and the root in its subdirectory to find/dir1file, assuming/dir1the node number corresponding to the file is1000, it will return toInode tableThe table finds that the node number is1000, the pointer points to the original data, assuming/dir1in the catalogAthe node number of the file is20000,Bthe node number of the file is20001, and return toInodetable, find the pointer number to2000point to his data block, the contents of which are stored in the data block.Xxx.

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/85/3D/wKioL1ed3QmBGNvTAAB3zoBHqto198.png "title=" 1.png " alt= "Wkiol1ed3qmbgnvtaab3zobhqto198.png"/>

Iv. structure of the Inode table

Inode to record a lot of data, but only 128byte, and Inode records to spend 4byte, if a file has 400MB and each block is 4KB, then at least 100,000 block number records. What's the inode with so much information to record? For this reason we set the Inode record block number to 12 direct, one indirect, one double indirect and one triple indirect.

As shown in the following:

Direct pointer: Number 1-12, each point to a data block, block block size of 4k, can hold up to 12*4k=48k files, if the file within 48k, you can use the direct pointer to find the location of the data block.

Indirect pointers: Pointers do not directly point to the data, but instead point to a pointer data block, the pointer data block size is also 4k, but the pointer data block is not the data but the address, assuming that the 4k pointer data block inside the pointer is stored in 4Byte, a pointer can be stored 4 bytes, So you can store 1024 pointers, 1024 pointers can point to 1024 data blocks, so the data size to point to is 1024*4k=4096k=4m.

Double Indirect pointer: the so-called double indirect pointer, is that it in the process of pointing to the data through the two pointer data block, according to the indirect pointer , we can not be difficult to draw a double indirect pointer to the size of the data is 1024*1024*4k=4g

Triple Indirect pointer: the so-called double indirect pointer, that is, in the process of pointing to the data through the three pointer data block, according to the indirect pointer, we can not be difficult to draw a double indirect pointer to the size of the data is 1024*1024*1024*4K=4T

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/85/3D/wKioL1ed3zmzDZfZAAIclazCWYg714.png "title=" 2.png " alt= "Wkiol1ed3zmzdzfzaaiclazcwyg714.png"/> the lookup of the block: If the data block is small, a pointer to the data block is OK, if the data block is found to be large, call the following indirect pointer directly. These things are for 32-bit systems.

V. View inode node number

The number of the nodes is randomly assigned by the system.

Ls-l: View index number

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/85/3D/wKioL1ed4rnjBLMBAAAScl1mdkY980.png "title=" 4.png " alt= "Wkiol1ed4rnjblmbaaascl1mdky980.png"/>


in the node numbers are different in one partition, and different partition nodes may be the same

The same node number in a partition that means it's the same file.

For example:

Create a new link with a file b,a and B have the same node number, stating that A and B are the same file

In addition to their names, the rest of the properties are consistent, including metadata, which is hard links

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/85/3D/wKioL1ed46KQcVV_AAAZQW6vtbs900.png "title=" 5.png " alt= "Wkiol1ed46kqcvv_aaazqw6vtbs900.png"/>


Df-i View the maximum number of nodes in a directory

If you report a disk full error during the work, it may not be true that the disk is really pretty, or it may be that the inode is exhausted.

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/85/3D/wKiom1ed47zT0H4JAAAYy_GNdwU672.png "title=" 6.png " alt= "Wkiom1ed47zt0h4jaaayy_gndwu672.png"/>








Inode nodes 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.