Table of Contents
i node in Linux

What is i node in linux

Jun 28, 2022 pm 05:23 PM
linux

In Linux, the i-node is a 64-byte long table; the i-node contains information about a file, including the file size, file owner, file access permission method, and whether the file is ordinary Files, directory files, special files, etc., the most important item in the i-node is the disk address table.

What is i node in linux

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

i node in Linux

i node is a 64-byte long table that contains information about a file, including file size, file owner, and file access permissions method, and whether the file is an ordinary file, a directory file, or a special file, etc.

The Linux file system is the heart of the Linux system, providing hierarchical directories and files. The file system divides the disk space into groups of 1024 bytes, called blocks (there are also blocks of 512 bytes, such as SCOXENIX). Numbered from 0 to the maximum number of blocks for the entire disk.

All blocks can be divided into four parts. Block 0 is called the boot block, which is not used by the file system; Block 1 is called the private block. The private block contains a lot of information, including the disk size and other information about all blocks. Two portions of size. Starting from block 2 is the i-node table, which contains i-nodes. The number of blocks in the table is variable, which will be discussed later. After the i-node table is a free storage block (data storage block), which can be used to store file content.

The logical structure and physical structure of a file are very different. The logical structure is the file that the user sees after typing the cat command. The user can get a character stream representing the file content. The physical structure is how the file is actually stored on disk. Users think that their files are frontier character streams, but in fact the files may not be stored on the disk in a frontier manner. Files longer than one block are usually stored scattered on the disk. However, when a user accesses a file, the Linux file system will take out each block in the correct order and provide the user with the logical structure of the file.

Of course, there must be a table somewhere in the Linux system that tells the file system how to convert the physical structure into a logical structure. This involves the i node.

The i node is a 64-byte long table that contains information about a file, including file size, file owner, file access permission method, and whether the file is an ordinary file or a directory file. Or special files, etc.. The most important item in the i-node is the disk address table.

There are 13 block numbers in this table. The first 10 block numbers are the storage addresses of the first 10 blocks of the file. These 10 block numbers can give the logical structure of a file that is at most 10 blocks long. The file will obtain the corresponding blocks in the order in which the block numbers appear in the disk address table. What happens when the file is longer than 10 blocks? The 11th item in the disk address table gives a block number. The block pointed to by this block number contains 256 block numbers. So far, this method satisfies files longer than 266 blocks. (272384 bytes). If the file is larger than 266 blocks, item 12 of the disk address table gives a block number. The block pointed to by this block number contains 256 block numbers. Each of these 256 block numbers points to a block, and the block contains 256 block numbers, these block numbers are used to retrieve the contents of the file. The index addressing method of item 13 in the disk address is similar to item 12, except that there is one more level of indirect index.

In this way, in the Linux system, the maximum length of the file is 16842762 blocks, that is, 17246988288 bytes. Fortunately, the Linux system has added a more practical limit to the maximum length of the file (generally 1 to 2M bytes) , so that the user does not accidentally create a file that uses up all the blocks of the entire disk area.

inode

When it comes to inode, we have to first introduce the overall structure of the hard disk. The hard disk contains multiple hard disk platters. The hard disk platters are round. Each hard disk platter has a magnetic head (Head) that can read and write. When this head is fixed and the hard disk platter rotates once, the track it follows is a track. (Track). The set of the same track numbers of all platters in the hard disk is called a cylinder. Each track is divided into many areas, and each area is called a sector. A sector is the smallest storage physical quantity of a hard disk. The storage capacity of a sector is approximately 512 bytes (approximately 0.5K).

After knowing the general structure of the hard disk, let’s talk about how to partition the hard disk. The smallest unit for hard disk partitioning is the magnetic column. After partitioning, it is naturally formatted. When formatting in Linux, you must consider Block and inode. Block is easy to understand. It is the smallest unit that the disk can record. It is composed of several sectors, so the size is usually n*512Bytes, such as 4K.

So what is inode? Block is the area that records the contents of the file, and inode records the attributes of the file and the information in which Block it is placed. Therefore, each file will occupy an inode. When the Linux system wants to find a file, it will first search the inode table to find the file's attributes and data storage location, and then search for the Block where the data is stored and retrieve the data. The number of inodes has been set at the beginning. The setting method is usually "hard disk size/one capacity". It is better for this capacity to be larger than the Block. For example, if the Block is set to 4K just now, then the capacity can be set to about 8K. . Therefore, if a 1GB hard disk is divided into 8K inodes, there will be 131072 inodes. The size of an inode is 128Byte. In this way, we can clearly know that after a partition is formatted as a file system, it will basically have two large blocks: the inode table and the data area, and one is used to record the attribute information of the file. The Block block stored with the file is used to record the contents of the file.

After creating a file, an inode and a block will be created at the same time. The inode stores the attribute information of the file, but does not include the file name, and stores the pointer to the address of the block where the corresponding data is located; block To store file data, each block can store at most one file. When a block cannot be stored, the next block will be occupied.

The file name, file attributes, and file content of a file in Linux are stored separately: the file name is stored in the directory entry (i.e. dentry), and the file attributes are stored in the inode. Under normal circumstances, each inode occupies 128Bity disk space, file content is stored in data blocks.

You can use mkfs.ext3 -b to set the block size. Each block can store up to one file, so generally the block size setting should be based on the application settings of our server. If this server It is mostly used to store many small files, so you can set the block size smaller so as not to waste space. However, when large data is stored, you need to set the block size larger, which can reduce the impact on the data. The number of disk block reads can also reduce the recording burden of inodes.

The larger the block, the fewer inodes, which are suitable for file systems that store large files; the smaller the block, the more inodes, which are suitable for file systems that store many but small files.

When the system is running, the inode and block will synchronize the memory and the disk after modification. The content we list using ls -li is the temporary storage in the memory, so sometimes the system shuts down abnormally. Causes block and inode out of synchronization problems.

Recommended learning: Linux video tutorial

The above is the detailed content of What is i node in linux. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1655
14
PHP Tutorial
1253
29
C# Tutorial
1227
24
Linux Architecture: Unveiling the 5 Basic Components Linux Architecture: Unveiling the 5 Basic Components Apr 20, 2025 am 12:04 AM

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

vscode terminal usage tutorial vscode terminal usage tutorial Apr 15, 2025 pm 10:09 PM

vscode built-in terminal is a development tool that allows running commands and scripts within the editor to simplify the development process. How to use vscode terminal: Open the terminal with the shortcut key (Ctrl/Cmd). Enter a command or run the script. Use hotkeys (such as Ctrl L to clear the terminal). Change the working directory (such as the cd command). Advanced features include debug mode, automatic code snippet completion, and interactive command history.

How to check the warehouse address of git How to check the warehouse address of git Apr 17, 2025 pm 01:54 PM

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

Where to write code in vscode Where to write code in vscode Apr 15, 2025 pm 09:54 PM

Writing code in Visual Studio Code (VSCode) is simple and easy to use. Just install VSCode, create a project, select a language, create a file, write code, save and run it. The advantages of VSCode include cross-platform, free and open source, powerful features, rich extensions, and lightweight and fast.

How to run java code in notepad How to run java code in notepad Apr 16, 2025 pm 07:39 PM

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

What is the main purpose of Linux? What is the main purpose of Linux? Apr 16, 2025 am 12:19 AM

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

vscode Previous Next Shortcut Key vscode Previous Next Shortcut Key Apr 15, 2025 pm 10:51 PM

VS Code One-step/Next step shortcut key usage: One-step (backward): Windows/Linux: Ctrl ←; macOS: Cmd ←Next step (forward): Windows/Linux: Ctrl →; macOS: Cmd →

vscode terminal command cannot be used vscode terminal command cannot be used Apr 15, 2025 pm 10:03 PM

Causes and solutions for the VS Code terminal commands not available: The necessary tools are not installed (Windows: WSL; macOS: Xcode command line tools) Path configuration is wrong (add executable files to PATH environment variables) Permission issues (run VS Code as administrator) Firewall or proxy restrictions (check settings, unrestrictions) Terminal settings are incorrect (enable use of external terminals) VS Code installation is corrupt (reinstall or update) Terminal configuration is incompatible (try different terminal types or commands) Specific environment variables are missing (set necessary environment variables)

See all articles