我如何读取和遍历的inode [英] How do I read and traverse inodes

查看:681
本文介绍了我如何读取和遍历的inode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开了一个ext2文件系统的超级块和组描述符,但我不知道如何例如在阅读它的根目录或文件...

下面是一些我得到了什么

  FD =打开(的/ dev / sdb2,O_RDONLY);
lseek的(FD,超大,SEEK_SET);
阅读(FD,和放大器; super_block的,超大);
lseek的(FD,4096,SEEK_SET);
阅读(FD,和放大器; groupDesc​​,DescriptSize);

不过这下一部分似乎不工作...

  lseek的(FD,super_block.s_log_block_size * groupDesc​​.bg_inode_table,SEEK_SET);
了lseek(FD,InodeSize *(EXT2_ROOT_INO-1),SEEK_CUR);
阅读(FD,和放大器;根,InodeSize);


解决方案

我不完全清楚你问什么,但这里有云:

要读取目录的内容,你基本上需要看它里面的指针块,看由指针指定的磁盘对应的块,读发现那里的内容来获取文件的说明目录

这是一个pretty高层次的建议,但剩下的其实就是要与系统结构本身的细节搞混。

我建议你看这4章:
http://www.nongnu.org/ext2-doc/ext2.html

,并且确保你在担心你的情况特殊结构,它应该为你的地方在分配中提供清晰...

I've opened the super-block and group descriptor in an EXT2 filesystem, but I don't know how to read for instance the root directory or files in it...

Here's some of what i got

fd=open("/dev/sdb2", O_RDONLY);
lseek(fd, SuperSize, SEEK_SET);
read(fd, &super_block, SuperSize);
lseek(fd, 4096, SEEK_SET);
read(fd, &groupDesc, DescriptSize);

but this next part doesn't seem to work...

lseek(fd, super_block.s_log_block_size*groupDesc.bg_inode_table, SEEK_SET);
lseek(fd, InodeSize*(EXT2_ROOT_INO-1), SEEK_CUR);
read(fd, &root, InodeSize);

解决方案

I'm not totally clear what you're asking, but here goes:

To read the contents of the directory, you'll basically need to look inside it's pointer block, look at the corresponding blocks on disk specified by the pointers, and read the contents found there to get descriptions of the files in the directory.

That's a pretty high level suggestion, but the rest really comes down to mucking with the details of the system structures themselves.

I'd recommend looking at chapter 4 of this : http://www.nongnu.org/ext2-doc/ext2.html

and also make sure you're clear on the specific structs concerned in your case, which should be provided for you somewhere in the assignment...

这篇关于我如何读取和遍历的inode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆