File I node in Linux

Source: Internet
Author: User

The Linux file system is the heart of the Linux system and provides a hierarchy of directories and files. The file system divides disk space into a group of 1024 bytes, called blocks (also useful for 512-byte chunks, such as: Scoxenix). The maximum number of blocks from 0 to the entire disk.

All blocks can be divided into four parts, block 0 is called the boot block, the file system does not use the block, Block 1 is called a private block, the private block contains a lot of information, including the size of the disk and the other two parts of the whole block size. Starting with Block 2 is the I node table, the I node table contains I nodes, the number of blocks of the table is variable, and will be discussed later. The I node table is followed by an idle storage block ( data storage block) that can be used to hold the file contents.

The logical structure and physical structure of a file are very different, and the logical structure is the file that users see when they typed in the Cat command, and the user gets a stream of characters that represents the contents of the file. The physical structure is the storage format in which files are actually stored on disk. Users consider their files to be a stream of characters in the frontier, but in fact the files may not be stored on the disk in the form of a frontier, and files longer than one piece will usually be stored on the disc in a fragmented manner. However, when the user accesses the file, the Linux file system will remove the blocks in the correct order, providing the user with the logical structure of the file.

Of course, somewhere in the Linux system there must be a table that tells the file system how to convert the physical structure to 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, and whether the file is a normal file, a directory file, or a special file. One of the most important items in the I node is the disk Address table.

There are 13 block numbers in the table. The first 10 block numbers are the storage address of the first 10 blocks of the file. These 10 block numbers give a logical structure of up to 10 long files, which will take the block number in the order in which they appear in the Disk Address table. What happens when a file is longer than 10 blocks? The 11th item in the Disk Address table gives a block number, which indicates that the block contains 256 block numbers, so that this method satisfies a file (272384 bytes) of up to 266 blocks. If the file is larger than 266 blocks, the disk Address table of the 12th item gives a block number, the block number indicates that the block contains 256 block numbers, the 256 block number of each block number is also indicated a piece, the block contains 256 block numbers, these block numbers are used to fetch the contents of a file. The disk address and the 13th index are addressed in a similar way to item 12th, just a multiple-level indirect index.

Thus, the maximum length of a file in a Linux system is 16842762 blocks, or 17246988288 bytes, and it is fortunate that the Linux system adds a more realistic limit to the maximum length of the file (typically 1 to 2M bytes), so that the user does not inadvertently create a file that runs out of all blocks of the entire disk area.

The way the file system converts file names to I nodes is actually quite straightforward. A directory is actually a file that contains a table of contents: For each file in the directory, there is a entry in the catalog table, and the entry contains the file name and the I node number corresponding to the file. When the user catxxx, the file system looks for the entry in the current catalog table named XXX, obtains the I node number corresponding to the file xxx, and then begins to take the block containing the contents of the file XXX.

File I node in Linux

Related Article

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.