On 2026-10-28T05:50:47, Ana Bobillo <[email protected]> wrote: > fs: ext4: fix the block group of an inode in the write path > > Inode numbers start at 1, so the block group of inode n is > (n - 1) / s_inodes_per_group, as ext4fs_read_inode() computes it. The > write path computes n / s_inodes_per_group instead, in > ext4fs_delete_file(), for the new and the parent inode in > ext4fs_write(), and in ext4fs_get_new_inode_no(). For the last inode > of a group this gives the next group: ext4fs_delete_file() then clears > a bit in the byte before that group's inode bitmap and zeroes an inode > in the wrong inode table, and for the last group of the filesystem > the index is past the end of fs->inode_bmaps[] and the group > descriptor table. > > Add ext4fs_inode_to_group(), next to ext4fs_blk_to_group(), which > computes the group that way, and use it in all four places. The inode > numbers given to ext4fs_delete_file() and taken as the parent inode > come from directory entries on disk, so it also checks the inode as > Linux ext4_valid_inum() does: one past the inode count or the last > block group, or a reserved inode other than the root, such as the > journal's, is reported and refused rather than having its blocks > released and its inode zeroed. > > When ext4fs_get_new_inode_no() finds no free inode after the last one > it allocated, it goes on past the last group's inode bitmap. Make it > stop at the inode count instead. > > Signed-off-by: Ana Bobillo <[email protected]> > > fs/ext4/ext4_common.c | 49 +++++++++++++++++++++++++++++++++++++++++++++---- > fs/ext4/ext4_common.h | 1 + > fs/ext4/ext4_write.c | 17 ++++++++++++----- > 3 files changed, 58 insertions(+), 9 deletions(-)
Reviewed-by: Simon Glass <[email protected]>
