From 9d4a4dc2870c46c74f815ec2bebe10b4701accf2 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Fri, 14 Nov 2008 17:42:27 -0500 Subject: [PATCH] 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" --- misc/tune2fs.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/misc/tune2fs.c b/misc/tune2fs.c index a130c14..b29b344 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) { -- 1.8.3.1