Analysis of inode and inode in Linux

Source: Internet
Author: User

Analysis of inode and inode in Linux

To say inode, we have to start with the physical format of the hard disk. The minimum storage unit of the hard disk is sector, that is, sector. Each sector stores 512 bytes. Generally, a file system has its own minimum read/write unit, which is a block. Generally, there are several types of data, such as 1KB, 2KB, and 4KB. Currently, the most common type is 4KB, that is to say, eight consecutive sector form a block.

The specific data of a file is stored in a block. Therefore, if we want to find these blocks, we need to store their metadata. So we have inode, also known as an index node, we can use stat filename to view inode information of a file, it mainly includes the number of bytes of the file, the UID of the file, the GID of the file, the read and write permissions of the file, the timestamp of the file, the number of links of the file, and the location of the file block. It is worth noting that each file must have an inode. Therefore, inode may be used up. If the disk is not full at this time, the file cannot be re-created on the disk. We can use the-I parameter of ls to view the specific inode value.

Because inode stores certain data information, inode also needs to occupy a certain amount of disk space. When formatting the hard disk, the operating system automatically divides the hard disk into two areas, one is the data area, one is the inode area. The size of each inode node, usually 128 bytes or 256 bytes. The total number of inode nodes is provided during formatting. Generally, an inode is set if there is no 1 kb or 2 kb.

In * nix, a directory is also a file, and its structure is very simple. It is a list of directory items, which consists of two parts: the file name included, and the inode number corresponding to the file name. When each directory is created, two directory items are generated by default. and .. the former inode number is the inode Number of the current directory, which is equivalent to the hard link of the current directory, while the latter inode number is the inode Number of the parent directory of the current directory, which is equivalent to the hard link of the parent directory, therefore, the total number of hard links in any directory is always equal to 2 plus the total number of its subdirectories. The subdirectories here contain hidden directories, here 2 is the hard link of the parent directory and under the current directory. hard link.

If both the source and target files point to the same inode, they are hard links to each other. The inode information contains a number of links, which records the total number of file names pointing to the inode, if we delete a file name, the number of links in the inode node will be reduced by 1. When the value is reduced to 0, the system will reclaim the inode number and the corresponding block area.

If the file name contains special characters and is difficult to delete, we can directly Delete the inode value to delete the file. If the file is moved or renamed, the file name is changed without affecting the inode number. After opening a file, the system will use inode to identify the file. It does not consider the file name. Therefore, the system cannot obtain the file name from inode, but it can find the inode from the file name.

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.