]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
tune2fs: update overhead when toggling journal feature
authorJan Kara <jack@suse.cz>
Mon, 14 Jun 2021 21:28:30 +0000 (23:28 +0200)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 6 Jul 2021 23:55:09 +0000 (19:55 -0400)
When adding or removing journal from a filesystem, we also need to add /
remove journal blocks from overhead stored in the superblock.  Otherwise
total number of blocks in the filesystem as reported by statfs(2) need
not match reality and could lead to odd results like negative number of
used blocks reported by df(1).

Fixes: 9046b4dfd0ce ("mke2fs: set overhead in super block")
Signed-off-by: Jan Kara <jack@suse.cz>
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
misc/tune2fs.c

index f739f16cd62b1f8e6775bccfcb97331bd5b48558..4200104ee0b1e95d8e7122616df145e78adf4199 100644 (file)
@@ -393,6 +393,8 @@ static errcode_t remove_journal_inode(ext2_filsys fs)
                                _("while clearing journal inode"));
                        return retval;
                }
+               fs->super->s_overhead_clusters -=
+                       EXT2FS_NUM_B2C(fs, EXT2_I_SIZE(&inode) / fs->blocksize);
                memset(&inode, 0, sizeof(inode));
                ext2fs_mark_bb_dirty(fs);
                fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
@@ -1611,8 +1613,12 @@ static int add_journal(ext2_filsys fs)
                        com_err(program_name, retval, "%s",
                                _("\n\twhile trying to create journal file"));
                        return retval;
-               } else
-                       fputs(_("done\n"), stdout);
+               }
+               fs->super->s_overhead_clusters += EXT2FS_NUM_B2C(fs,
+                       jparams.num_journal_blocks + jparams.num_fc_blocks);
+               ext2fs_mark_super_dirty(fs);
+               fputs(_("done\n"), stdout);
+
                /*
                 * If the filesystem wasn't mounted, we need to force
                 * the block group descriptors out.