Linux File System is the heart of the Linux system and provides hierarchical directories and files. The file system divides the disk space into a group of every 1024 bytes, which is called a block (also, 512 bytes are used as a block, such as SCOXENIX ). The maximum number of blocks from 0 to the entire disk.
The entire block can be divided into four parts. Block 0 is called a boot block, and the file system does not need this block. Block 1 is called a dedicated block, which contains a lot of information, the disk size and the size of the other two parts of the whole block are displayed. From Block 2, it is an I-node table. The I-node table contains I-nodes, and the number of blocks in the table is variable. We will discuss it later. An I-node table is followed by an idle storage block (Data Storage block), which can be used to store file content.
The logical structure of a file is very different from that of a physical structure. The logical structure is the file you see after you press the cat command. You can get the volume stream that represents the file content. The physical structure is the storage format of files stored on disks. Users think that their files are frontier streams, but in fact the files may not be stored on the disk in the form of frontier. Files larger than one block are usually stored on the disk in a scattered manner. However, when a user accesses a file, the linux File System extracts each block in the correct order to provide the user with the logical structure of the file.
Of course, there must be a table somewhere in the linux system, telling the file system how to convert the physical structure to the logical structure. This involves the I node. An I node is a 64-byte table that contains information about a file, including the file size, file owner, and file access permission, as well as common files, directory files, or special files. The most important one in I node is the disk address table.
This table has 13 block numbers. The first 10 block numbers are the storage addresses of the first 10 blocks. The 10 block numbers can provide a logical structure of up to 10 long files, and the files will obtain the corresponding block numbers in the order they appear in the disk address table. What if there are more than 10 files? The first item in the disk Address Table provides a block number, which indicates that the block number contains 11th block numbers. At this point, this method supports up to 266 files (272384 bytes ). If the number of files is larger than 266, a block number is provided for the first item in the disk address table. The block number indicated by this block number contains 12th block numbers, each block number of the 256 block numbers points out another block. The block contains 256 block numbers, which are used to obtain the content of the file. The addressing method for the disk address and the 13th index items is similar to that for the 12th items, but the multi-level indirect index is used.
In this way, in linux, the maximum length of a file is 16842762 bytes, that is, 17246988288 bytes. Fortunately, the maximum length of a file in Linux (generally 1 to 2 MB bytes) with more practical restrictions, users will not accidentally create a file that uses up all blocks of the entire disk area.
The file system converts a file name to an I node. A directory is actually a file containing a directory table: for each file in the directory, there is an entry in the directory table, which contains the file name and the corresponding I-node number of the file. When a user clicks catxxx, the file system searches for the entry item named xxx in the current directory table to obtain the I node number corresponding to file xxx, then, you can obtain the block containing the file xxx.