大家好,欢迎来到IT知识分享网。
1. 简介
2. 结构
3. extent
/* * This is the extent on-disk structure. * It's used at the bottom of the tree. */ struct ext4_extent {
__le32 ee_block; /* first logical block extent covers */ __le16 ee_len; /* number of blocks covered by extent */ __le16 ee_start_hi; /* high 16 bits of physical block */ __le32 ee_start_lo; /* low 32 bits of physical block */ }; /* * This is index on-disk structure. * It's used at all the levels except the bottom. */ struct ext4_extent_idx {
__le32 ei_block; /* index covers logical blocks from 'block' */ __le32 ei_leaf_lo; /* pointer to the physical block of the next * * level. leaf or next index could be there */ __le16 ei_leaf_hi; /* high 16 bits of physical block */ __u16 ei_unused; }; /* * Each block (leaves and indexes), even inode-stored has header. */ struct ext4_extent_header {
__le16 eh_magic; /* probably will support different formats */ __le16 eh_entries; /* number of valid entries */ __le16 eh_max; /* capacity of store in entries */ __le16 eh_depth; /* has tree real underlying blocks? */ __le32 eh_generation; /* generation of the tree */ };
4. 示例
遍历硬盘所有文件。
- 获取GDT信息,GDT在Block 2,偏移为1。
- 读取Inode Table block号。
- 读取Inode Table
根据ext4_extent获取ee_start_hi=0x2426,此Block对应根目录的内容。
- 获取根目录信息
上述信息记录的是ext4_dir_entry_2结构信息
参考结构体,解决inode和文件/文件夹名如下:
- 检索小文文件
abc.txt的Inode为13,Inode Table Block为0x426,那么13对应的实际偏移应该是:
0x4264096 + 12256= # 因为inode是从1开始的,所以13应对的偏移为12
上面256的数据即为ext4_inode结构体(相关结构体的详细描述见Linux内核代码),绿线框12Byte即为ext4_extent。
可以获取Inode13对应的内容Block为1,对应的地址为0x8601,获取内容如下,正是写入的内容。
- 检索大文件
file.txt为1GB的文件,其Inode为12。计算其ext4_inode偏移为:
0x4264096 + 11256= # 因为inode是从1开始的,所以12应对的偏移为11
红线对应的内容为ext4_extent_header,eh_entries为1表示当前只有1项有效,eh_depth为1,表示有子项,则当前内容为ext4_extent_idx。
解析ext4_extent_idx结构体,指向的物理块地址为0x3fbf01,这个块上描述的就是ext4_extent_header+大量的ext4_extent。
上图绿线为ext4_extent_header,后面的红线及其他的都是ext4_extent。
- 检索目录
qerdir目录的Inode为,通过sb.Inodes_per_group=8192,可以(+8191)/8192=17,偏移为%8192=1。再通过GDT中记录的Group17对应的Inode table at – 。
上图红线对应ext4_extent即为目录的内容信息,其物理块地址为0x82020,其内容如下,只有bbb.txt一个文件,符合预期。
bbb.txt对应的Inode为0x20003(131075)。
其对应的Inode table中ext4_extent如下,其物理地址为0x88001:
0x88001的内容如下,符合预期:
5. 总结
6. 代码
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://haidsoft.com/127971.html