From: Theodore Ts'o Date: Fri, 14 Nov 2008 22:42:27 +0000 (-0500) Subject: tune2fs: Update the block group checksums when changing the UUID X-Git-Tag: v1.41.4~45 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9d4a4dc2870c46c74f815ec2bebe10b4701accf2;p=thirdparty%2Fe2fsprogs.git tune2fs: Update the block group checksums when changing the UUID Since the block group checksums depend on the UUID, we need to update the block group checksums when setting the UUID. We only do so if all of the checksums are correct, however. Signed-off-by: "Theodore Ts'o" --- diff --git a/misc/tune2fs.c b/misc/tune2fs.c index a130c14b6..b29b34439 100644 --- a/misc/tune2fs.c +++ b/misc/tune2fs.c @@ -1610,6 +1610,22 @@ retry_open: add_journal(fs); if (U_flag) { + int set_csum = 0; + dgrp_t i; + + if (sb->s_feature_ro_compat & + EXT4_FEATURE_RO_COMPAT_GDT_CSUM) { + /* + * Determine if the block group checksums are + * correct so we know whether or not to set + * them later on. + */ + for (i = 0; i < fs->group_desc_count; i++) + if (!ext2fs_group_desc_csum_verify(fs, i)) + break; + if (i >= fs->group_desc_count) + set_csum = 1; + } if ((strcasecmp(new_UUID, "null") == 0) || (strcasecmp(new_UUID, "clear") == 0)) { uuid_clear(sb->s_uuid); @@ -1621,6 +1637,11 @@ retry_open: com_err(program_name, 0, _("Invalid UUID format\n")); exit(1); } + if (set_csum) { + for (i = 0; i < fs->group_desc_count; i++) + ext2fs_group_desc_csum_set(fs, i); + fs->flags &= ~EXT2_FLAG_SUPER_ONLY; + } ext2fs_mark_super_dirty(fs); } if (I_flag) {