cinodeext2

how to print indirect block in ext2


I'm trying to print all the single indirect blocks in an ext2 file system. I can print the direct blocks easy enough (0-11) but I don't understand how to get to the single indirect blocks, and later the double and triple indirect blocks. If I look at the value of ino->i_block[12] how do I use that to get to where it points to? I'm sure I'm missing something easy here


Solution

  • An inode in EXT2 is 128 bytes long, and contains many different fields.

    the i_size field indicates the number of bytes stored in the file, i.e., the file's length. the i_block array is an array of 15 block numbers.

    The first 12 entries in the array (i_block[0] through i_block[11]) contain the block numbers of direct blocks: they name data blocks that contain the first 12 blocks worth of the file's content.

    The 13th entry in the array (i_block[12]) contains the block number of a singly indirect block: it names a block that contains an array of 4 byte block numbers; each of these blocks contains additional file contents.

    The 14th entry in the array (i_block[13]) contains the block number of a doubly indirect block: it names a block that contains an array of 4-byte block numbers, each of these blocks in a singly indirect block, that contains an array of 4-byte block numbers of direct blocks. The 15th entry in the array (i_block[14]) contains the block number of a triple indirection block.