]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
libext2fs: precompute FS UUID checksum seed
authorDarrick J. Wong <djwong@us.ibm.com>
Mon, 30 Jul 2012 22:44:04 +0000 (18:44 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 30 Jul 2012 22:44:04 +0000 (18:44 -0400)
Precompute the FS UUID checksum seed that is used for all metadata
checksumming operations and store it in ext2_filsys.

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
e2fsck/super.c
lib/ext2fs/ext2fs.h
lib/ext2fs/openfs.c
misc/mke2fs.c

index 160991d6d3126be1c887b86da7dbde64f28bedee..a5e8005b3a8a50ba361acad22cd8ccffe5d8e839 100644 (file)
@@ -716,6 +716,7 @@ void check_super_block(e2fsck_t ctx)
        if (!(ctx->options & E2F_OPT_READONLY) && uuid_is_null(sb->s_uuid)) {
                if (fix_problem(ctx, PR_0_ADD_UUID, &pctx)) {
                        uuid_generate(sb->s_uuid);
+                       ext2fs_init_csum_seed(fs);
                        fs->flags |= EXT2_FLAG_DIRTY;
                        fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY;
                }
index 0728999f7975b1023ce30c3ee2e3fedfb57c375c..ed8f0bd0ab7d2e93b4bef5c76d6607e0b801dc25 100644 (file)
@@ -271,6 +271,9 @@ struct struct_ext2_filsys {
 
        /* progress operation functions */
        struct ext2fs_progress_ops *progress_ops;
+
+       /* Precomputed FS UUID checksum for seeding other checksums */
+       __u32 csum_seed;
 };
 
 #if EXT2_FLAT_INCLUDES
@@ -1431,6 +1434,7 @@ extern errcode_t ext2fs_write_bb_FILE(ext2_badblocks_list bb_list,
 
 
 /* inline functions */
+extern void ext2fs_init_csum_seed(ext2_filsys fs);
 extern errcode_t ext2fs_get_mem(unsigned long size, void *ptr);
 extern errcode_t ext2fs_get_memalign(unsigned long size,
                                     unsigned long align, void *ptr);
@@ -1483,6 +1487,16 @@ extern int ext2fs_fstat(int fd, ext2fs_struct_stat *buf);
 
 #ifndef EXT2_CUSTOM_MEMORY_ROUTINES
 #include <string.h>
+_INLINE_ void ext2fs_init_csum_seed(ext2_filsys fs)
+{
+       if (!EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
+                                       EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
+               return;
+
+       fs->csum_seed = ext2fs_crc32c_le(~0, fs->super->s_uuid,
+                                        sizeof(fs->super->s_uuid));
+}
+
 /*
  *  Allocate memory
  */
index fbe9acdeee01053eff0f762c489714cbed514851..3675518f3890a31b376a609e47248d37188512a1 100644 (file)
@@ -315,6 +315,8 @@ errcode_t ext2fs_open2(const char *name, const char *io_options,
                retval = EXT2_ET_CORRUPT_SUPERBLOCK;
                goto cleanup;
        }
+       /* Precompute the FS UUID to seed other checksums */
+       ext2fs_init_csum_seed(fs);
 
        /*
         * Read group descriptors
index 01b2111b09b5a25c719e41900d84bbc7ecc2fc3c..94db901a9b3e7ee1d742697fac1aa8ad87b07c15 100644 (file)
@@ -2323,6 +2323,7 @@ int main (int argc, char *argv[])
                }
        } else
                uuid_generate(fs->super->s_uuid);
+       ext2fs_init_csum_seed(fs);
 
        /*
         * Initialize the directory index variables