For example, the file I'm scanning for has the path, "/test0/child0/file0". I'm able to successfully find inodes/direntries containing information referring to the directories "test0" and "child0", but I do not find any dir_entry in the data blocks referred by child0's inode, in fact, child0's inode is marked valid in the group bitmap, but contains nothing useful as a hexdump of the area on the disk image where that inode should be contains all zeroes.
output of test program:
Code: Select all
Inode:
mode: 0x41ED
Block[0]: 835
Dirent: test0
inode: 155649
rec_len: 40
name_len: 5
file_type: 2
Inode:
mode: 0x41ED
Block[0]: 632832
Dirent: child0
inode: 155650
rec_len: 4072
name_len: 6
file_type: 2
Error: NULL Inode.
Code: Select all
ext2_inode *
ext2_get_inode(u32 inode_num)
{
ext2_inode *r_ino;
struct ext2_group_desc *gd;
size_t r;
size_t ino_sz;
long inode_disk_addr;
u32 *i_bitmap;
u32 inode_in_group;
u32 group;
int bm_index, bm_offset;
ino_sz = sizeof(ext2_inode);
group = (inode_num - 1) / EXT2_INODES_PER_GROUP(sb);
gd = ext2_get_group_desc(group);
r_ino = (ext2_inode *)calloc(1, ino_sz);
i_bitmap = ext2_get_data_block(gd->bg_inode_bitmap);
if (i_bitmap == NULL)
{
printf("Error: finding bitmap.\n");
goto out;
}
inode_in_group = (inode_num-1) % EXT2_INODES_PER_GROUP(sb);
bm_index = EXT2_GRP_BM_INDEX(inode_in_group);
bm_offset = EXT2_GRP_BM_OFFSET(inode_in_group);
if (!(i_bitmap[bm_index] & (1 << bm_offset)))
{
printf("Error: Inode not valid, %u\n", inode_num);
goto out;
}
inode_disk_addr = PART_START;
inode_disk_addr += (long)gd->bg_inode_table * EXT2_BLOCK_SIZE(sb);
inode_disk_addr += (long)(ino_sz * inode_in_group);
fseek(f, inode_disk_addr, SEEK_SET);
r = fread(r_ino, ino_sz, 1, f);
if (!r)
{
printf("Error: Reading inode, %u\n", inode_num);
goto out;
}
return r_ino;
out:
return NULL;
}