Understanding Linux Inode

Source: Internet
Author: User
Tags parent directory

Understanding Linux Inode

?

?

1. Origin and role of the Inode 2. What content is contained in the Inode table 3. How the file system reads file 4 through the inode. A special type of existence: Hard link 5. Structure of the catalog file

?

?
1. The origin and function of the inode
?
When the hard disk creates a file system, the sector of the Physical disk (512 bytes) is created as a "block" of multiple sectors (currently 4KB, or 8 sectors). When the operating system reads data from the disk, the head reads the data from the block. To quickly find data, you must specifically partition a dedicated area on disk to store the "index" of data to facilitate quick data discovery. The "index" of this data region is called the Inode (Index node).

Picture from Ma brother Education Ma Yongliang lecture ppt, painting of the comparison abstract, but that is the meaning, anyway I can not draw out good.
?

?
2. What content is included in the Inode table?

?
The contents of the inode contain the file size, permissions, genus, timestamp, data block pointers. The stat command in the Linux system allows you to view the Inode information for a file.
?

[[email protected] ~]# stat abc  File: ‘abc’  Size: 0           Blocks: 0          IO Block: 4096   regular empty fileDevice: 802h/2050d  Inode: 50350850    Links: 1Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)Access: 2018-01-14 13:52:33.155811474 +0800Modify: 2018-01-14 13:52:14.461811925 +0800Change: 2018-01-14 13:52:14.461811925 +0800 Birth: -[[email protected] ~]#

?

File: File name
Size: File size
Blocks: Number of file contents occupied blocks
IO Block: File system block Size
Inode:inode number
Links: Number of times a file has been hard linked
Access: (0644/-rw-r--r--): File owner, group, other group permissions
Uid: The user ID number of the file owner
Gid: ID Number of the genus Group
access:2018-01-14 13:52:33.155811474 +0800: File access time
modify:2018-01-14 13:52:14.461811925 +0800: File modification Time
change:2018-01-14 13:52:14.461811925 +0800: File change time

In the above information, access time is updated when the file is read. When you modify a file, the modify information changes. When you modify a file, you are bound to open the file, so access information is also updated. If you modify the file by using output redirection, access information is not updated.
When the change occurs, the time is updated as long as the file metadata changes.

?

3. How the file system reads files through the Inode
?
?

?
When the system reads the file, it finds the corresponding inode number through the filename, then finds the Inode information by the number, and finally finds the corresponding block according to the data pointer in the Inode information and completes the operation of reading the file.
?
? For various files, the data pointer location holds the content differently.
?

    • ? normal file, the data pointer points directly to the data block.
    • Symbolic link file: The space in which the data pointer is stored is the access path to the real file.
    • Device file: The space in which the data pointer is stored is the device number (major, minor).


      4, a special type of existence: Hard link
      ?
      ? In general, the file name and Inode are one by one correspondence, but a hard link allows different filenames to point to the same inode number under the same disk partition .
      ?
      ? This means that the same file can be accessed through a different path and does not occupy the inode number much. And as long as the number of hard links is not 0, the file will persist. Deleting any of the file names does not affect the files.


      5, the structure of the directory file

      For catalogs, according to the philosophy of Linux, directories are also files. Access to the directory is to open the directory (requires X permission to enter). If you use LS to view the directory

      [[email protected] tmp]# ll -id /tmp33574984 drwxrwxrwt. 10 root root 165 Jan 14 20:21 /tmp[[email protected] tmp]#

A directory consists of a series of catalog items, each of which contains the file name and the inode number corresponding to the file.

After the catalog is created, two directories are created under the directory. and.., which represents the parent directory of the current directory and the current directory, respectively. The inode of the former is the inode number of the current directory, so the number of hard links is at least 2 for the catalog file.

Understanding Linux Inode

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.