Aman Deep Gautam
Aman Deep Gautam

Reputation: 8787

data pointers in inode data structure

I have gone through the code of inode in linux kernel code but I am unable to figure where are the data pointers in inode. I know that there are 15 pointers [0-14] out of which 12 are direct, 1 single indirect, 1 double indirect and 1 triple indirect.

Can some one please locate these data members. Also please specify how you located these as I have searched on google many time with different key words but all in vain.

Upvotes: 3

Views: 3228

Answers (2)

Peter Teoh
Peter Teoh

Reputation: 6753

As explained here:

http://computer-forensics.sans.org/blog/2010/12/20/digital-forensics-understanding-ext4-part-1-extents

Ext4 uses extents instead of block pointers to track the file content.

If you are interested in ext3/ext2 datastructure where content pointer are used:

http://www.slashroot.in/how-does-file-deletion-work-linux

has many good diagrams to elaborate it. And here:

http://mcgrewsecurity.com/training/extx.pdf

at page 16 has examples of the details of "block pointers" (which are basically block numbers, or offset values relative to the start of the disk image, 1 block usually 512 bytes).

If you want to walk the filesystem phyiscally, say for a ext3 formatted hard drive, see this:

http://wiki.sleuthkit.org/index.php?title=FS_Analysis

but you can always use just "dd" command to do everything, just need to know where to start reading and stop reading, and input for the dd command is usually a replica of the harddisk image itself, for many reasons.

Upvotes: 4

Dmytro Sirenko
Dmytro Sirenko

Reputation: 5083

It is up to a specific file system to access its data, so there's no "data pointers" in general (some file systems may be virtual, that means generating their data on the fly or retrieving it from network).

If you're interested in ext4, you can look up the ext4-specific inode structure (struct ext4_inode) in fs/ext4/ext4.h, where data of an inode is indeed referenced by indices of 12 direct blocks, 1 of single indirection, 1 of double indirection and 1 of triple indirection.

This means that blocks [0..11] of an inode's data have numbers e4inode->i_block[0/1/.../11], whereas e4inode->i_block[12] is a number of a block which is filled with data block numbers itself (so it holds indices of inode's data blocks in range [12, 12 + fs->block_size / sizeof(__le32)]. The same trick is applied to i_block[13], only it holds double-indirected indices (blocks filled with indices of blocks that hold list of blocks holding the actual data) starting from index 12 + fs->block_size / sizeof(__le32), and i_block[14] holds triple indirected indices.

Upvotes: 4

Related Questions