From 1f3ad14a5ad5df3ac4012d41ef5d76411cd8fff3 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Thu, 14 Apr 2005 14:07:53 -0400 Subject: [PATCH] Use a centrally stored current time for "now" which can be overridden using the E2FSCK_TIME environment variable, for better reproducibility for regression tests. --- e2fsck/ChangeLog | 8 ++++++++ e2fsck/e2fsck.c | 7 +++++++ e2fsck/e2fsck.h | 2 ++ e2fsck/journal.c | 2 +- e2fsck/pass1.c | 15 ++++++++++----- e2fsck/pass1b.c | 2 +- e2fsck/pass2.c | 2 +- e2fsck/pass3.c | 4 ++-- e2fsck/pass4.c | 2 +- e2fsck/super.c | 4 ++-- e2fsck/unix.c | 11 +++++------ 11 files changed, 40 insertions(+), 19 deletions(-) diff --git a/e2fsck/ChangeLog b/e2fsck/ChangeLog index a4e3cf3..7317628 100644 --- a/e2fsck/ChangeLog +++ b/e2fsck/ChangeLog @@ -1,3 +1,11 @@ +2005-04-14 Theodore Ts'o + + * e2fsck.c, e2fsck.h, journal.c, pass1.c, pass1b.c, pass2.c, + pass3.c, pass4.c, super.c, unix.c: Use a centrally stored + current time for "now" which can be overridden using the + E2FSCK_TIME environment variable, for better + reproducibility for regression tests. + 2005-04-06 Theodore Ts'o * pass1.c (e2fsck_pass1): If the superblock last mount time (not diff --git a/e2fsck/e2fsck.c b/e2fsck/e2fsck.c index 2a84c51..7d2ccf6 100644 --- a/e2fsck/e2fsck.c +++ b/e2fsck/e2fsck.c @@ -21,6 +21,7 @@ errcode_t e2fsck_allocate_context(e2fsck_t *ret) { e2fsck_t context; errcode_t retval; + char *time_env; retval = ext2fs_get_mem(sizeof(struct e2fsck_struct), &context); if (retval) @@ -30,6 +31,12 @@ errcode_t e2fsck_allocate_context(e2fsck_t *ret) context->process_inode_size = 256; context->ext_attr_ver = 2; + + time_env = getenv("E2FSCK_TIME"); + if (time_env) + context->now = strtoul(time_env, NULL, 0); + else + context->now = time(0); *ret = context; return 0; diff --git a/e2fsck/e2fsck.h b/e2fsck/e2fsck.h index 6dec935..898b9a3 100644 --- a/e2fsck/e2fsck.h +++ b/e2fsck/e2fsck.h @@ -322,6 +322,8 @@ struct e2fsck_struct { int fs_ext_attr_inodes; int fs_ext_attr_blocks; + time_t now; + int ext_attr_ver; /* diff --git a/e2fsck/journal.c b/e2fsck/journal.c index eb4b38d..a5f156c 100644 --- a/e2fsck/journal.c +++ b/e2fsck/journal.c @@ -939,7 +939,7 @@ void e2fsck_move_ext3_journal(e2fsck_t ctx) ext2fs_mark_super_dirty(fs); fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY; inode.i_links_count = 0; - inode.i_dtime = time(0); + inode.i_dtime = ctx->now; if ((retval = ext2fs_write_inode(fs, ino, &inode)) != 0) goto err_out; diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c index 33729ee..4595cbc 100644 --- a/e2fsck/pass1.c +++ b/e2fsck/pass1.c @@ -597,7 +597,7 @@ void e2fsck_pass1(e2fsck_t ctx) */ if (!LINUX_S_ISDIR(inode->i_mode)) { if (fix_problem(ctx, PR_1_ROOT_NO_DIR, &pctx)) { - inode->i_dtime = time(0); + inode->i_dtime = ctx->now; inode->i_links_count = 0; ext2fs_icount_store(ctx->inode_link_info, ino, 0); @@ -691,7 +691,7 @@ void e2fsck_pass1(e2fsck_t ctx) inode->i_dtime < ctx->fs->super->s_inodes_count) { if (fix_problem(ctx, PR_1_LOW_DTIME, &pctx)) { inode->i_dtime = inode->i_links_count ? - 0 : time(0); + 0 : ctx->now; e2fsck_write_inode(ctx, ino, inode, "pass1"); } @@ -705,7 +705,7 @@ void e2fsck_pass1(e2fsck_t ctx) if (!inode->i_dtime && inode->i_mode) { if (fix_problem(ctx, PR_1_ZERO_DTIME, &pctx)) { - inode->i_dtime = time(0); + inode->i_dtime = ctx->now; e2fsck_write_inode(ctx, ino, inode, "pass1"); } @@ -876,6 +876,11 @@ void e2fsck_pass1(e2fsck_t ctx) ctx->flags |= E2F_FLAG_ABORT; return; } + e2fsck_read_inode(ctx, EXT2_RESIZE_INO, inode, + "recreate inode"); + inode->i_mtime = ctx->now; + e2fsck_write_inode(ctx, EXT2_RESIZE_INO, inode, + "recreate inode"); fs->block_map = save_bmap; ctx->flags &= ~E2F_FLAG_RESIZE_INODE; } @@ -1422,7 +1427,7 @@ static void check_blocks(e2fsck_t ctx, struct problem_context *pctx, if (pb.clear) { inode->i_links_count = 0; ext2fs_icount_store(ctx->inode_link_info, ino, 0); - inode->i_dtime = time(0); + inode->i_dtime = ctx->now; dirty_inode++; ext2fs_unmark_inode_bitmap(ctx->inode_dir_map, ino); ext2fs_unmark_inode_bitmap(ctx->inode_reg_map, ino); @@ -1455,7 +1460,7 @@ static void check_blocks(e2fsck_t ctx, struct problem_context *pctx, if (fix_problem(ctx, PR_1_ZERO_LENGTH_DIR, pctx)) { inode->i_links_count = 0; ext2fs_icount_store(ctx->inode_link_info, ino, 0); - inode->i_dtime = time(0); + inode->i_dtime = ctx->now; dirty_inode++; ext2fs_unmark_inode_bitmap(ctx->inode_dir_map, ino); ext2fs_unmark_inode_bitmap(ctx->inode_reg_map, ino); diff --git a/e2fsck/pass1b.c b/e2fsck/pass1b.c index 527ead8..733c027 100644 --- a/e2fsck/pass1b.c +++ b/e2fsck/pass1b.c @@ -595,7 +595,7 @@ static void delete_file(e2fsck_t ctx, ext2_ino_t ino, /* Inode may have changed by block_iterate, so reread it */ e2fsck_read_inode(ctx, ino, &inode, "delete_file"); inode.i_links_count = 0; - inode.i_dtime = time(0); + inode.i_dtime = ctx->now; if (inode.i_file_acl && (fs->super->s_feature_compat & EXT2_FEATURE_COMPAT_EXT_ATTR)) { count = 1; diff --git a/e2fsck/pass2.c b/e2fsck/pass2.c index 69599ff..52fdcba 100644 --- a/e2fsck/pass2.c +++ b/e2fsck/pass2.c @@ -1097,7 +1097,7 @@ static void deallocate_inode(e2fsck_t ctx, ext2_ino_t ino, char* block_buf) ext2fs_icount_store(ctx->inode_link_info, ino, 0); e2fsck_read_inode(ctx, ino, &inode, "deallocate_inode"); inode.i_links_count = 0; - inode.i_dtime = time(0); + inode.i_dtime = ctx->now; e2fsck_write_inode(ctx, ino, &inode, "deallocate_inode"); clear_problem_context(&pctx); pctx.ino = ino; diff --git a/e2fsck/pass3.c b/e2fsck/pass3.c index a92c890..66ffc46 100644 --- a/e2fsck/pass3.c +++ b/e2fsck/pass3.c @@ -222,7 +222,7 @@ static void check_root(e2fsck_t ctx) memset(&inode, 0, sizeof(inode)); inode.i_mode = 040755; inode.i_size = fs->blocksize; - inode.i_atime = inode.i_ctime = inode.i_mtime = time(0); + inode.i_atime = inode.i_ctime = inode.i_mtime = ctx->now; inode.i_links_count = 2; inode.i_blocks = fs->blocksize / 512; inode.i_block[0] = blk; @@ -470,7 +470,7 @@ ext2_ino_t e2fsck_get_lost_and_found(e2fsck_t ctx, int fix) memset(&inode, 0, sizeof(inode)); inode.i_mode = 040700; inode.i_size = fs->blocksize; - inode.i_atime = inode.i_ctime = inode.i_mtime = time(0); + inode.i_atime = inode.i_ctime = inode.i_mtime = ctx->now; inode.i_links_count = 2; inode.i_blocks = fs->blocksize / 512; inode.i_block[0] = blk; diff --git a/e2fsck/pass4.c b/e2fsck/pass4.c index a9e49f1..985e8f6 100644 --- a/e2fsck/pass4.c +++ b/e2fsck/pass4.c @@ -45,7 +45,7 @@ static int disconnect_inode(e2fsck_t ctx, ext2_ino_t i) if (fix_problem(ctx, PR_4_ZERO_LEN_INODE, &pctx)) { ext2fs_icount_store(ctx->inode_link_info, i, 0); inode.i_links_count = 0; - inode.i_dtime = time(0); + inode.i_dtime = ctx->now; e2fsck_write_inode(ctx, i, &inode, "disconnect_inode"); /* diff --git a/e2fsck/super.c b/e2fsck/super.c index 294cd80..0855fb5 100644 --- a/e2fsck/super.c +++ b/e2fsck/super.c @@ -298,7 +298,7 @@ static int release_orphan_inodes(e2fsck_t ctx) if (!inode.i_links_count) { ext2fs_inode_alloc_stats2(fs, ino, -1, LINUX_S_ISDIR(inode.i_mode)); - inode.i_dtime = time(0); + inode.i_dtime = ctx->now; } else { inode.i_dtime = 0; } @@ -346,7 +346,7 @@ void check_resize_inode(e2fsck_t ctx) } } - /* Read the resizde inode */ + /* Read the resize inode */ pctx.ino = EXT2_RESIZE_INO; retval = ext2fs_read_inode(fs, EXT2_RESIZE_INO, &inode); if (retval) { diff --git a/e2fsck/unix.c b/e2fsck/unix.c index a8ac53d..2b6e476 100644 --- a/e2fsck/unix.c +++ b/e2fsck/unix.c @@ -256,7 +256,6 @@ static void check_if_skip(e2fsck_t ctx) unsigned int reason_arg = 0; long next_check; int batt = is_on_batt(); - time_t now = time(0); if ((ctx->options & E2F_OPT_FORCE) || bad_blocks_file || cflag || swapfs) @@ -276,11 +275,11 @@ static void check_if_skip(e2fsck_t ctx) (unsigned) fs->super->s_max_mnt_count*2)) reason = 0; } else if (fs->super->s_checkinterval && - ((now - fs->super->s_lastcheck) >= + ((ctx->now - fs->super->s_lastcheck) >= fs->super->s_checkinterval)) { reason = _(" has gone %u days without being checked"); - reason_arg = (now - fs->super->s_lastcheck)/(3600*24); - if (batt && ((now - fs->super->s_lastcheck) < + reason_arg = (ctx->now - fs->super->s_lastcheck)/(3600*24); + if (batt && ((ctx->now - fs->super->s_lastcheck) < fs->super->s_checkinterval*2)) reason = 0; } @@ -302,7 +301,7 @@ static void check_if_skip(e2fsck_t ctx) next_check = 1; } if (fs->super->s_checkinterval && - ((now - fs->super->s_lastcheck) >= fs->super->s_checkinterval)) + ((ctx->now - fs->super->s_lastcheck) >= fs->super->s_checkinterval)) next_check = 1; if (next_check <= 5) { if (next_check == 1) @@ -1155,7 +1154,7 @@ restart: } else sb->s_state &= ~EXT2_VALID_FS; sb->s_mnt_count = 0; - sb->s_lastcheck = time(NULL); + sb->s_lastcheck = ctx->now; ext2fs_mark_super_dirty(fs); } } -- 1.8.3.1