4

The following diagram displays the layout of a "cylinder group" (which I believe is generally called a block group now) and seems to depict that each block group has its own inode table:

cylinder groups

However, the book The Linux Programming Interface has this statement about inode tables:

A file system’s i-node table contains one i-node (short for index node) for each file residing in the file system.

This implies there is one inode table for the entire filesystem, not one per block group.

So is there:

  • one inode table for the entire filesystem
  • one inode table per block group which tracks only inodes in that group
  • one inode table for the entire filesystem that is backed up into groups (similar to how superblocks backed up across groups)
  • something else ??

Note its possible I'm mixing some stuff between ext2/3 and ext4, it isn't always clear from what I read online which is being covered.

Thanks.

1 Answer 1

3

The canonical ext4 documentation is now part of the kernel documentation. Referring to that, the answer to your question is option 2,

one inode table per block group which tracks only inodes in that group

The inode tables themselves are described in the inode description:

The inode table is a linear array of struct ext4_inode. The table is sized to have enough blocks to store at least sb.s_inode_size * sb.s_inodes_per_group bytes. The number of the block group containing an inode can be calculated as (inode_number - 1) / sb.s_inodes_per_group, and the offset into the group’s table is (inode_number - 1) % sb.s_inodes_per_group. There is no inode 0.

This confirms that each inode table describes the inodes in the corresponding group.

The overall layout of a block group is given in the layout section. It matches your diagram, but as you suspect, there can indeed be multiple block groups, each with their own data structures used to describe their contents (not the contents of the whole file system).

There is an additional quirk in ext4: flexible block groups. When this feature is enabled, multiple block groups can be merged into one, and all their inode tables are stored in the first block group. This means that a block group’s pointers to its inode tables (and other data structures) can point outside the block group!

3
  • This is exactly what I was looking for. Thank you.
    – Dave
    Dec 13, 2019 at 18:53
  • Follow up question: If the inode table only tracks inodes within a given block group, how does the filesystem/kernel know which block group to read into when a file is requested? I get that once the block group is known the inode table is searched for the inode which will have the pointer needed into the data blocks in that group, but since a filesystem is a collection of block groups there must be something pointing from a filename to a block group.
    – Dave
    Dec 13, 2019 at 21:42
  • This is mostly addressed in the second quote above: directory entries give each file’s inode number, and inode numbers cover the whole range of inodes, divided linearly by block group. The sentence starting with “The number of the block group containing an inode ...” gives the exact process. Dec 14, 2019 at 10:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .