Basic concepts of Linux file system

Source: Internet
Author: User
Tags comparison table
Linux file system: records the overall information of this filesystem, including the total amount, usage, and remaining amount of inodeblock, as well as file system formats and related information such as inode: records file attributes, a file Linux file system
Linux file system involves several basic concepts
Superblock: records the overall information of this filesystem, including the total inode/block, usage, remaining amount, and file system format and related information.
Inode: records the attributes of a file. a file occupies one inode and records the block number of the data in this file.
Block: actually records the file content. if the file is too large, it will occupy multiple blocks.
Inode and block are numbered. you can find the inode of a file to find the block where the file is stored.

These file systems are collectively referred to as Indexed file systems.
Unlike indexing, the FAT file system uses a storage system similar to a linked list.

This file system cannot directly obtain the file size. when the block of a file is scattered, the file reading performance will be reduced, that's why we have the saying "disk fragmentation.
Note: In fact, if the file size in Linux is large and the block size of the file content is scattered, the reading performance will be reduced. In this case, you can back up the files in the file system, format the file system, and restore the files back.
Ext2 file system
All inode and blocks have been planned for the file system at the beginning, unless the file system size is reformatted or changed
The Ext2 file system is formatted into multiple block groups. each block group has its own superblock/inode/block. For example


Data block:
The block size supported by Ext2 is 1 K, 2 K, and 4 K.
Block size: 1KB, 2KB, 4KB
Maximum size of a single file: 16 GB 256 GB 2 TB
Maximum file system capacity: 2 TB, 8 TB, 16 TB

In principle, the number and size of data blcok are determined only during formatting.
Each data block can only store the content of one file. it can be said that the storage space used by a file is measured in data block.

Inode table:
Inode records the pointer of the access mode (r/w/x), owner, group, file size, ctime, atime, mtime, setuid, setgid, and file content.
Each inode is 128 bytes in size.
Each file occupies only one inode. Therefore, the total number of files created by the file system is related to the number of inode, and the number and size of inode are specified during formatting.
Because inode is limited in size and the number of blocks in a file may be large, in order to use a limited space to record large block numbers, therefore, the file system divides the inode record block number into 12 direct record areas, 1 indirect record area, 1 dual indirect record area, and 1 three indirect record area. (Each data block number requires 4 bytes of space)

The indirect record area uses a data block as the record area for recording the block number.
In this way, in a file system with a block size of 1 K, the maximum number of data block numbers that an inode can record is: 12 + 1 K/4 + 1 K/4*1 K/4 + 1 K/4*1 K/4*1 K/4 = 16 M, therefore, when the block size of an inode is 1 K, the maximum file size that can be recorded is 16 GB.
(Because the Ext2 file system has a limit on blocks larger than 2 K, the above algorithm is not applicable to blocks of 2 K and 4 K size)

Super block:
Record the information of the entire file system: the size and total number of blocks and inode, and the Mount time of the file system.
Since the file system should have only one super block, in fact, except the first block group must contain the super block, the super block in other block groups is only the first backup.

FileSystem Description ):
Record the start and end block numbers of each block group, and indicate the block numbers between each block segment (superblock, block bitmap, inode bitmap, and data block.
You can use dumpe2fs to view this part of information.

Block bitmap ):
Record whether each block is empty.
When creating a file, search for an empty block and update it to non-empty. when deleting the file, update the unused block to null.

Inode comparison table (inode bitmap ):
Similar to block bitmap, it records whether each inode is in use.

To query information about a file system, run the dumpe2fs command.

Directory storage in the file system
The Directory stores the same files.
When creating a directory, the file system allocates an inode and at least one data block to it (so in a file system with a block size of 4 K, most directories are 4096 in size ), inode records directory permissions, attributes, data block numbers, and other information. data block records the names of all files/directories under the Directory and the corresponding inode numbers.
You can use ls-I to view the inode number of a file in a directory.

To create a file, follow these steps:
Make sure that you have the w and x permissions on the directory where the file is located.
No inode is found in inode bitmap and file-related information is written.
Locate unused blocks in block bitmap and write the file content to update the block number information in inode.
Update inode bitmap and block bitmap, and then update superblock content

Journaling Filesystem)
The Ext2 file system writes inode to the block before creating a file. Therefore, if the creation operation is interrupted after inode is written, data inconsistency may occur.
When the system starts the system, it determines whether data inconsistency exists based on the information in the super block. you can use the e2fsck command to check the data inconsistency status. This check is very time-consuming.
To avoid inconsistent data, a log file system is introduced.

A log file system introduces a log block that records file creation or modification operations.
To create a log file system, follow these steps:
Preparation: first, record the file operations in the logging block.
Actual operation: Write file permission and other information, write file content
End: The operation has been marked in the logging block.
In this case, if a problem occurs during file operations, you can directly query the log to get a specific error and then fix it.

The Ext3 file system is a log file system, which is an upgraded version of Ext2.
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.