我正在尝试编辑一些inode数据。但是,当我读取任何inode时,我只能得到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“命令得到的不同inode编号进行了测试,并用"stat filename”验证了数据。但是,组描述符是正确的,inode表的位置(使用dumpe2fs验证)也是正确的。
我还尝试使用"lde“工具(lde -i 15 /dev/sdb1)获取inode信息。它还会给出无效数据。请让我知道我在这里错过了什么。
提前谢谢你,马利哈
发布于 2010-12-06 04:13:39
BLOCK_SIZE是正确的吗?我将验证偏移量计算结果是否与使用od显示的结果一致。
https://stackoverflow.com/questions/4360867
复制相似问题