Personal understanding of Ext2 file System storage architecture in Linux

Source: Internet
Author: User

After a few days of reading the Ext2 file system and the VFS section of the deep understanding of the Linux kernel, a little understanding of the storage structure of the point file in memory, but always confused the actual storage on the hard disk, especially the storage of the folder.

The structure of the Save folder is very simple, there is no index of all the files in this folder, read a few times the book, can not understand the folder structure on the hard disk storage, can only be based on the example of the online experiment. (The process refers to Http://blog.chinaunix.net/u1/48373/showart_1210707.html's blog)

First show that you want to allocate a space, format it as a ext2 partition, and do the file and folder operations on that space.

DD If=/dev/zero of=disk bs=1m count=1 #创建1MB的空间 and populated with 0

MKFS.EXT2 disk #格式化为ext2分区, you can see the block size of 1024byte from the output information

Mount-o Loop disk/mnt/#挂载分区

Then go to the mounted directory and start creating files and folders.

Test.txt (content is hello)

Create Test1.txt (content is hello1)

Create Folder Test

In folder test, create the file Test2.txt (content is Hello2)

Create file Test3.txt (content is Hello3)

You can then uninstall the file, open the disk file with the 16 editor, and view the ext2 file save format.

When you open the disk file, jump to the address 0x800 (the first block is left as a boot block, followed by a super block of block Group 0), which is the group descriptor for block group 0.

Based on the structure of the group descriptor, the block number of the first Index node table block begins at the 9th byte. 4 bytes from this beginning (all Little-endian) is the block number of the first Index node table block. This is 8. According to the calculation, its 16 address is 0x2000.

Because the root directory of the filesystem is always the second of the index nodes, each index node size is fixed and is 128 bytes (0x80). That is, the address 0x2080 is the index node (inode) of the root directory. Depending on the structure of the index node, you can find that the root data block number is 0x18, which is the address 0x6000.

At 0x6000, you can see all the directories and files created under the root directory. That is, the contents of the EXT2 folder structure ext2_dir_entry_2, not the folder itself, but the information (including the directory) of all the files in the folder, where the first inode field is the index node number of the file (folder).

In addition to a folder and a file that you just created, there are Lost+find folders and. and. Folders (which represent this folder and the parent folder, respectively). Through the first field of the directory structure, you can find the inode of the file (folder) that you want to find, then look for the node in the Index node table and find the data storage location (i_blocks field) of the node, then compute the address of the assigned block and read the actual data.

Depending on the structure of the directory, locating the Test.txt index node offset is 0x0d. Then, the Test.txt index node address is 0x2000+0x80* (0x0d-0x01) =0x2600. The pointer to the data block found at this point is 0x27 (address 0x9c00).

Go to 0x9c00 and you'll see the data in there hello.

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.