读取 inode 返回无效数据

发布于 2024-10-06 18:54:17 字数 1008 浏览 0 评论 0原文

我正在尝试编辑一些索引节点数据。但是,当我读取任何索引节点时,我只得到零或无效数据。 以下是我正在做的主要步骤:

//reading, say inode number 15 - it belongs to group 0, and it's a valid inode  
int inode_no=15
//buffer to hold inode structure  
struct ext2_inode inode_buffer_test1;
//points to the start of group descriptor structure. It is correct, I have validated the results with dumpe2fs.  
struct ext2_group_desc *grpdesc;  
//file descriptor of a device file holding ext2 FS, opened in O_RDONLY mode  
int fd; 

...

lseek64(fd,(long long)grpdesc[0].bg_inode_table*BLOCK_SIZE + sizeof(struct ext2_inode)*(inode_no-1),SEEK_SET);  
read(fd,&inode_buffer_test1,sizeof(struct ext2_inode));  
printf("file size=%d, blocks=%d\n",inode_buffer_test1.i_size,inode_buffer_test1.i_blocks);  

我得到的只是零或有时其他 inode 的无效数据。我已经使用从“ls -i filename”命令获得的不同索引节点号进行了测试,并使用“stat filename”验证了数据。然而,组描述符是正确的,inode 表的位置也是正确的(使用 dumpe2fs 进行验证)。

我还尝试使用“lde”工具(lde -i 15 /dev/sdb1)获取inode信息。它还提供无效数据。请让我知道我在这里缺少什么。

提前致谢, 马利哈

I am trying to edit some inode data. However, when I read any inode, I only get zeros or invalid data.
Here are the main steps of what I am doing:

//reading, say inode number 15 - it belongs to group 0, and it's a valid inode  
int inode_no=15
//buffer to hold inode structure  
struct ext2_inode inode_buffer_test1;
//points to the start of group descriptor structure. It is correct, I have validated the results with dumpe2fs.  
struct ext2_group_desc *grpdesc;  
//file descriptor of a device file holding ext2 FS, opened in O_RDONLY mode  
int fd; 

...

lseek64(fd,(long long)grpdesc[0].bg_inode_table*BLOCK_SIZE + sizeof(struct ext2_inode)*(inode_no-1),SEEK_SET);  
read(fd,&inode_buffer_test1,sizeof(struct ext2_inode));  
printf("file size=%d, blocks=%d\n",inode_buffer_test1.i_size,inode_buffer_test1.i_blocks);  

All I get is zero or some times invalid data for other inodes. I have tested with different inode numbers got from "ls -i filename" command and verified the data with "stat filename". The group descriptor, however, is correct and so is the location of the inode table (verified using dumpe2fs).

I have also tried to get inode information using the "lde" tool (lde -i 15 /dev/sdb1). It also gives invalid data. Please let me know what I am missing here.

Thanks in advance,
Maliha

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风尘浪孓 2024-10-13 18:54:17

BLOCK_SIZE 正确吗?我将验证偏移计算是否与使用 od 显示的内容相对应。

Is BLOCK_SIZE correct? I'd verify that the offset calculation corresponds to what is shown using od.

牵你的手,一向走下去 2024-10-13 18:54:17

在版本 < 的 Ext2 文件系统中1、Inode的固定大小为128字节,等于sizeof(struct ext2_inode)

但对于版本 >= 1,inode 大小由超级块 s_inode_size 中的字段给出。

假设 sb 是 struct ext2_super_block 类型。

所以这应该有效

lseek64(fd,(long long)grpdesc[0].bg_inode_table*BLOCK_SIZE + sb.s_inode_size*(inode_no-1),SEEK_SET); 

In Ext2 File systems with version < 1, Inode have a fixed size of 128 bytes which equal to sizeof(struct ext2_inode).

But for versions >= 1, inode size is given by field in superblock s_inode_size.

Let's say sb is of type struct ext2_super_block.

So this should work

lseek64(fd,(long long)grpdesc[0].bg_inode_table*BLOCK_SIZE + sb.s_inode_size*(inode_no-1),SEEK_SET); 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文