Linux File System architecture

Source: Internet
Author: User

different file systems have different ways of storing files, so their structure is different. This article is about the architecture of Linux's most traditional file system EXT2 .

The main components of the EXT2 file system are:inodetable (inode table),data block(information block) ,superblock(Super block),filesystem description(file system description),inode Bitmap(inode table),block bitmap(block table) and so on.

in theEXT2File system, the file's permissions, properties and the contents of the file are stored separately, the permissions and properties of the file are stored in theInodeand the contents of the file are stored in theBlockthe. Inodeand theBlockare fixed at the time of formatting (that is, file system creation). EachInodeis the size of128bytes(Ext4with theXFScan set256bytes), each file occupies only oneInode, so the number of files that can be created in the file systemInodeof the quantity concerned. Blockhave a1k,2kand the4kthree sizes, so when the file content size exceedsBlockthe size requires multipleBlockto store it.

each inode and block is numbered. the inode not only stores the permissions and attributes of the file, but also stores The number of all blocks stored in the file , so as long as the inode of the file is found can be based on Inode recorded in the Block all the contents of the file are stored at once. Block data are all read out. Here's a picture of Brother Bird:

Here's the problem, record aBlockNumber Required4bytesthe space, if a file is larger then the need forBlockthe number is more, butInodeonly128bytesAh, how can I record so manyBlockWhat's the number? Actually, not all of them.Blocknumbers are recorded directly in theInodewhen the file is occupied by theBlockwhen the number is higher, the system will come up with someBlockdedicated to documenting the contents of a fileBlockthe number, and thenInodejust record these .Blockcan read the contents of the fileBlocknumber of the. EXT2putInodein the recordBlokthe numbered area is defined as AA direct, an indirect, a double indirect, and a three-indirect record area, here is also the bird Brother's diagram to illustrate:

you can still find all the blocks that store the file contents According to the Inode !

However, because the size of the area in the inode that holds the block number is fixed,theinode can store the block the number of numbers is fixed, and the block size is fixed, so that is, in a known block size file system, The maximum size of the file is fixed!

sinceBlockthe size has1K,2Kand the4Kthree types, so should we choose a bigger one or a little bit better? Due to aBlockcan only store the contents of one document, no matter how small a file, it will occupy at least oneBlockof space, so ifBlockthe space is very large, but there are a lot of small files in the system, it will waste a lot of space. If you putBlockis very small, but there are many large files in the system, then a file needs to be stored in a number ofBlock, it takes more than one to read the contents of a fileBlockread in, andInodeneed to record theBlockA lot of numbers, the system also needs to come up with moreBlockto record the contents of a fileBlocknumber, which is wasted in both time and space. So,Blockthe size of the system, or it needs to be determined based on the expected usage of the filesystem.

Now let's briefly introduce EXT File System structure Other components:

(1) superblock: size = 1024bytes block inode inode/block

(2) Filesystem description: a block number describing the start and end of each block group(described below) , and a description of each segment ( inode table,data block , etc.) is between the block numbers respectively.

(3) Inode bitmap: Records which inode is unused and which is already in use.

(4) block bitmap: Records which blocks are unused and which are already in use.

In addition, the In EXT3 and EXT4 , a chunk is also planned to log records of file modifications so that the problem can be detected quickly when a file system problem occurs.

If the file system is large, the number of Inode and block will be very large, not easy to manage, so EXT When formatting is basically divided into multiple block groups, each chunk group has all the components described above (can be viewed from The print results of the instruction DUMPE2FS), it looks like (pictured borrowed from bird brother):

I know that. EXT2 the structure of the file system, file creation, query, modification, deletion of the specific experience of what process, including what details, we can clearly know!

when the file system is formatted, EXT File System family in the process of format processing of all /inode/block/meta data and other structures are pre-planned and allocated, the system can be directly used in the future, do not need to be dynamically configured. The problem with this approach is that formatting takes a long time to format when the file system is large. And the new journaled file system XFS makes up for this deficiency, its inode and block are only used when the system needs to be allocated dynamically, so the format process is very fast, suitable for large file systems.

Linux File System architecture

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.