In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "what is the use of inode in Linux", the content is simple and clear, hoping to help you solve your doubts, the following let the editor lead you to study and learn "what is the use of inode in Linux" this article.
What is inode used for?
Inode is the area used to store file meta-information. It is called "Index Node" in Chinese.
Background knowledge about inode
Let's review some of the contents of the file store first. We know that files are stored on the hard disk, and the smallest storage unit of the hard disk, also known as the sector, is 512 bytes in size.
When the operating system reads information on the hard disk, it reads multiple sectors at once, which are also called blocks. Typically, the size of the block is 4KB, about the size of eight sectors. It is important to note that the blocks read are contiguous spaces.
At this time, we can know that the file is stored in a "block", just like when we write a C language program, we know that when we declare an array, we will not only store the values in the array, but also store the corresponding array information, such as the first address of the array, the file type, the length of the array, and so on. Similarly, we need to find a place to store the meta-information of the file. Similar to the information related to the creation of the file, the length of the file, and so on. And this place, we call it inode.
Content stored in inode
Inode contains the meta-information of the stored file, which contains these contents:
The number of bytes in the file.
ID of the creator of the file.
The Group ID of the file.
Read and write permissions of the file.
The relevant timestamp of the file. There are three details: ctime-- > inode last change time; mtime-- > file content last change time; atime-- > file last opened time.
Number of links
Block location of file data
Inode number
After seeing the above storage content for the first time, I think everyone will have more or less the same question, since inode stores information about files, why not store file names. The reason is that file names are not the standard for the Unix/Linux operating system to identify different files.
The operating system identifies different files by inode numbers.
In the Unix/Linux system, the user layer name opens the file through the file name, and the system level mainly uses three steps to open the file:
Find the corresponding inode number according to the file name.
Get inode information by inode number.
According to the inode information, the block in which the file data is stored is found and the data is left alone.
The special function of inode
The separation of inode numbers and file names in the Unix/Linux system leads to some special phenomena in the system:
To delete the inode node is to delete the file. Some files may not be deleted correctly, so we can delete the file directly by deleting the corresponding inode node.
Move the file or rename the file without changing the inode number, just changing the file name.
Generally speaking, the system can not get the file name through the inode number. When a file is opened, the system then uses inode to identify the file, regardless of the file name.
Because of the existence of the inode number, the system can be updated without shutting down the software. The system identifies the running file through the inode number. In the process of updating, the file has the same file name and the new inode exists, without affecting the currently running file. The old inode will be recycled the next time the software is opened, and the file name will automatically point to the new inode number.
Inode space occupancy problem
Since the data is also stored in the hard disk, inode must also take up the hard disk space. When formatting the hard disk, the operating system automatically divides the hard disk into two areas:
Data area
Inode table
The data area mainly stores file data, while the inode table area stores inode information.
In particular, the size of the area occupied by inode is given by the operating system when the disk is formatted. The consequence of this is that the data area is obviously not used up, but you can no longer access the data, and because the inode table area is full, you can no longer store new files on disk.
Catalog file
We know that in Unix/Linux, any resource exists in the form of a file. So is the catalogue. When we open a directory, we actually open a directory file. The structure of the directory file is a list.
Directory entry = included file name + corresponding inode number.
Hard links and soft links
On what is a hard link and what is a soft link, I will not repeat it in this blog post, only from the point of view of inode.
From the point of view of inode number, multiple file names are allowed to point to the same inode number in Unix/Linux system. At this time, if you delete one of the file names, the access of the other file name will not be affected. At the same time, if you open the file through one file name and make changes, the other file names can be shared to the changes when opened. Then call this "hard link". In Linux, we can create hard links through the ln command.
To sum up, in inode, there is a storage item called "number of links" that records the total number of file names that only want that inode. If you create a file name by hard link to point to a file, the number of links in the corresponding inode data field of the file will be + 1, and vice versa. When this value is 0, no file name points to the inode by default, and the inode number is recycled and the corresponding block area is recycled.
And the corresponding soft link, assume that there are files An and B, B is the soft link of A. At this time, the inode numbers of An and B are different because they are different files, but! The content of B is the path of A, and when reading B, the system automatically accesses A, so no matter which file is opened, it accesses file A. At this point, file B is called the "soft link" or "symbolic link" of file A.
On Unix/Linux systems, we can create soft links through the ln-s command.
Summary and small supplement
From the above description, we know that inode is like the pointer domain in the C language, which records a variety of information and directs us to the correct file location to read the information we need. (not exactly, of course.)
When you create a directory in the Unix/Linux system, two directory entries are automatically generated:
. Catalogue
.. Catalogue
These two directories can be observed through the ls-al command. The inode number of ".directory" is the inode number of the current directory, which is equivalent to the hard link of the current directory, while ".." The inode number of the directory is the inode number of the parent directory of the current directory, which is equivalent to the hard link of the parent directory. Total number of directory hard links = 2 + total number of subdirectories (including hidden files).
The above is all the content of this article "what is the use of inode in Linux?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.