如何读取和遍历 inode
我已经在 EXT2 文件系统中打开了超级块和组描述符,但我不知道如何读取根目录或其中的文件...
这是我得到的一些内容
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);
,但下一部分没有似乎有效...
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'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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不完全确定你在问什么,但这里是:
要读取目录的内容,你基本上需要查看其指针块内部,查看指针指定的磁盘上的相应块,然后读取在那里找到的内容以获取目录中文件的描述。
这是一个相当高水平的建议,但其余的实际上归结为破坏系统结构本身的细节。
我建议您查看第 4 章:
https://www.nongnu.org /ext2-doc/ext2.html
另外,请确保您清楚与您的案例相关的具体结构,这些结构应该在作业中的某个位置为您提供...
I'm not totally sure what you're asking, but here goes:
To read the contents of the directory, you'll basically need to look inside its 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:
https://www.nongnu.org/ext2-doc/ext2.html
Also make sure you're clear on the specific structs concerned in your case, which should be provided for you somewhere in the assignment...
块组描述符是遍历 ext 文件系统所需的全部。超级块为您提供有关文件系统的一般信息以及块组描述符 (BGD) 的位置。一旦进入 BGD,您就可以获得有关文件系统内每个块组的信息。
要查找根目录,您需要查看第一个块组,并检查第二个 inode;也称为索引节点号 2。这可以从第一个索引节点的位置 + sizeof(inode) 得出。反过来,第一个 inode 的位置可以在第一个块组的 BGD 条目内找到。
如果您需要更多信息,请告诉我。
The Block Group Descriptor is all you need to traverse an ext file system. The superblock gives you general information about the file system, as well as the location of the block group descriptor (BGD). Once inside the BGD, you have information about each and every block group inside the file system.
To look for the root directory, then you need to look into the FIRST block group, and inspect the second inode; otherwise known as inode number 2. This can be reached from the the location of the first inode, + sizeof(inode). In turn, the location of the first inode can be found inside the BGD entry for the first block group.
Let me know if you need more info.