开发者

Reading inode returns invalid data

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_tes开发者_C百科t1,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


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


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); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜