Hard disk layout for EXT2 file system

Source: Internet
Author: User
Tags file system relative system log

This paper mainly describes the more popular Linux ext2 file system on the hard disk partition of the detailed layout. The next version of the Ext2 file system plus log support is the Ext3 file system, it and the Ext2 file system in the hard disk layout is the same, the difference is only the ext3 file system on the hard disk a special Ino de (can be understood as a special file), to record the file system log, Also known as the journal. Since this article does not discuss log files, the contents of this article are applicable to both ext2 and ext3.

1. Preface

The source code for this article is the Ext3 file system in the Linux kernel. In order to facilitate reader access to the source code, some of the key technical terms in this article are used in the kernel source code used in English words, without the use of the corresponding Chinese translation. (This method is appropriate, but also ask readers to advise.) )

2, a rough description

For ext2 file systems, hard disk partitions are first divided into blocks, and each block on a ext2 file system is the same size, but for different ext2 file systems, the block size can vary. The typical block size is 1024 bytes or 4096 bytes. This size is determined when the Ext2 file system is created, it can be specified by the system administrator, or the file system creator can automatically select a reasonable value based on the size of the hard disk partition. These blocks are grouped together into several large block groups. How many blocks in each block group are fixed.

Each block group corresponds to a group descriptor, and these group descriptor are clustered together at the beginning of the hard disk partition, following the Super block. The so-called super block, we have to discuss below. There are several important block pointers in this descriptor. The block pointer we are talking about here refers to the block number on the hard disk partition, for example, the value of the pointer is 0, we say it points to block 0 on the hard disk partition, the pointer value is 1023, and we say it points to block 1023 on the hard disk partition. We notice that the block count on a hard disk partition starts at 0, and that this count is global for this hard disk partition.

In Group descriptor of Block Group, where a block pointer points to each bit in the block Bitmap,block bitmap of this block group represents a block, if the bit is 0, indicating that there is data in the block, and that if the bit is 1, it is idle. Note that the block bitmap itself is just as large as a block. Assuming the block size is S bytes, the block bitmap can only record 8*s blocks (because one byte equals 8 bits and one bit corresponds to a block). That is to say, a block group can only have 8*s*s bytes so large.

In the group descriptor of Block Group, another block pointer points to the Inode bitmap, and the bitmap is just as big as a block, with each bit corresponding to an inode. An inode on a hard disk is roughly relative to a file or directory on the file system. As for the inode, we'll talk more about it below.

Another important block pointer in the descriptor of block group refers to the so-called Inode table. This inode table is larger than one block. This inode table is formed with all the inode that is gathered in this block group.

The most critical information recorded in an inode is where the user data in the inode is stored. As we mentioned earlier, an inode is roughly relative to a file in the file system, so the content of the user file is stored somewhere, which is an inode to answer. An inode answers this question by providing a series of block pointers. These block pointers point to the block, which holds the contents of the user's file.

2.1 Review

Now let's look back. The hard disk partition is first divided into many blocks. These blocks are grouped together and divided into groups, which are block group. Each block group has a group descriptor. All these descriptor are gathered together at the beginning of the hard disk partition, followed by the Super block. From Group descriptor we can find the Inode table and block bitmap of this block group and so on through the block pointer. From the Inode table, we can see the inode. From an inode, we can then find the blocks that hold the user's data through the block pointer inside it. We would also like to mention that the block pointer is not allowed to wander around. The block bitmap and Inode bitmap of a block group, and the Inode table, are stored sequentially at the beginning of the group, and the blocks that hold the user data are immediately behind them. After one block group ends, another block group starts again.

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.