diff options
author | Jin Qian <jinqian@google.com> | 2017-08-28 14:44:14 -0700 |
---|---|---|
committer | Tao Bao <tbao@google.com> | 2017-09-27 14:48:53 -0700 |
commit | 51663e0d2aa2958b5ef590299b2018a2ae01d256 (patch) | |
tree | 58feb7cf12b645aed9ba899874491ec8c32b7bc7 | |
parent | c6b07d180118a87e21e932f4b0a2f019a77ed861 (diff) | |
download | e2fsprogs-51663e0d2aa2958b5ef590299b2018a2ae01d256.tar.gz |
mke2fs, libext2fs: make filesystem image reproducibleoreo-mr1-dev
Override fs->now with env E2FSPROGS_FAKE_TIME
Override hash seed with -E hash_seed=<uuid>
Bug: 64994964
Change-Id: If1af7e990b5bf2939a7d5f2a9986406e12c294e9
(cherry picked from commit 3164c7644fd096a1ed88cdbe888fca0702ef7415)
-rw-r--r-- | lib/ext2fs/initialize.c | 6 | ||||
-rw-r--r-- | lib/ext2fs/openfs.c | 6 | ||||
-rw-r--r-- | misc/mke2fs.c | 22 |
3 files changed, 33 insertions, 1 deletions
diff --git a/lib/ext2fs/initialize.c b/lib/ext2fs/initialize.c index 99fedcd3..dbe798b2 100644 --- a/lib/ext2fs/initialize.c +++ b/lib/ext2fs/initialize.c @@ -107,6 +107,7 @@ errcode_t ext2fs_initialize(const char *name, int flags, char *buf = 0; char c; double reserved_ratio; + char *time_env; if (!param || !ext2fs_blocks_count(param)) return EXT2_ET_INVALID_ARGUMENT; @@ -123,6 +124,11 @@ errcode_t ext2fs_initialize(const char *name, int flags, #ifdef WORDS_BIGENDIAN fs->flags |= EXT2_FLAG_SWAP_BYTES; #endif + + time_env = getenv("E2FSPROGS_FAKE_TIME"); + if (time_env) + fs->now = strtoul(time_env, NULL, 0); + io_flags = IO_FLAG_RW; if (flags & EXT2_FLAG_EXCLUSIVE) io_flags |= IO_FLAG_EXCLUSIVE; diff --git a/lib/ext2fs/openfs.c b/lib/ext2fs/openfs.c index ba39e010..94d0ef1c 100644 --- a/lib/ext2fs/openfs.c +++ b/lib/ext2fs/openfs.c @@ -126,6 +126,7 @@ errcode_t ext2fs_open2(const char *name, const char *io_options, struct ext2_group_desc *gdp; int j; #endif + char *time_env; EXT2_CHECK_MAGIC(manager, EXT2_ET_MAGIC_IO_MANAGER); @@ -139,6 +140,11 @@ errcode_t ext2fs_open2(const char *name, const char *io_options, /* don't overwrite sb backups unless flag is explicitly cleared */ fs->flags |= EXT2_FLAG_MASTER_SB_ONLY; fs->umask = 022; + + time_env = getenv("E2FSPROGS_FAKE_TIME"); + if (time_env) + fs->now = strtoul(time_env, NULL, 0); + retval = ext2fs_get_mem(strlen(name)+1, &fs->device_name); if (retval) goto cleanup; diff --git a/misc/mke2fs.c b/misc/mke2fs.c index ed10cc4a..9ba16b91 100644 --- a/misc/mke2fs.c +++ b/misc/mke2fs.c @@ -105,6 +105,7 @@ static int proceed_delay = -1; static blk64_t dev_size; static struct ext2_super_block fs_param; +static __u32 zero_buf[4]; static char *fs_uuid = NULL; static char *creator_os; static char *volume_label; @@ -833,6 +834,19 @@ static void parse_extended_opts(struct ext2_super_block *param, continue; } param->s_desc_size = desc_size; + } else if (strcmp(token, "hash_seed") == 0) { + if (!arg) { + r_usage++; + badopt = token; + continue; + } + if (uuid_parse(arg, + (unsigned char *)param->s_hash_seed) != 0) { + fprintf(stderr, + _("Invalid hash seed: %s\n"), arg); + r_usage++; + continue; + } } else if (strcmp(token, "offset") == 0) { if (!arg) { r_usage++; @@ -2944,7 +2958,13 @@ int main (int argc, char *argv[]) free(hash_alg_str); fs->super->s_def_hash_version = (hash_alg >= 0) ? hash_alg : EXT2_HASH_HALF_MD4; - uuid_generate((unsigned char *) fs->super->s_hash_seed); + + if (memcmp(fs_param.s_hash_seed, zero_buf, + sizeof(fs_param.s_hash_seed)) != 0) { + memcpy(fs->super->s_hash_seed, fs_param.s_hash_seed, + sizeof(fs->super->s_hash_seed)); + } else + uuid_generate((unsigned char *) fs->super->s_hash_seed); /* * Periodic checks can be enabled/disabled via config file. |