【问题标题】:Reading inode returns invalid data读取 inode 返回无效数据
【发布时间】:2011-05-20 15:20:30
【问题描述】:

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

//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”命令获得的不同 inode 编号进行了测试,并使用“stat filename”验证了数据。然而,组描述符是正确的,inode 表的位置也是正确的(使用 dumpe2fs 验证)。

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

提前致谢, 马里哈

【问题讨论】:

    标签: c inode ext2


    【解决方案1】:

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

    【讨论】:

    • 我使用 BLOCK_SIZE 作为: ((EXT2_MIN_BLOCK_SIZE)
    • 什么文件以fd打开?它是原始设备,还是设备上的分区? *grpdesc 看起来还好吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-16
    • 2022-01-27
    • 2021-12-10
    • 2019-08-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多