+2005-04-14 Theodore Ts'o <tytso@mit.edu>
+
+ * 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 <tytso@mit.edu>
* pass1.c (e2fsck_pass1): If the superblock last mount time (not
{
e2fsck_t context;
errcode_t retval;
+ char *time_env;
retval = ext2fs_get_mem(sizeof(struct e2fsck_struct), &context);
if (retval)
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;
int fs_ext_attr_inodes;
int fs_ext_attr_blocks;
+ time_t now;
+
int ext_attr_ver;
/*
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;
*/
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);
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");
}
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");
}
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;
}
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);
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);
/* 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;
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;
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;
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;
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");
/*
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;
}
}
}
- /* Read the resizde inode */
+ /* Read the resize inode */
pctx.ino = EXT2_RESIZE_INO;
retval = ext2fs_read_inode(fs, EXT2_RESIZE_INO, &inode);
if (retval) {
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)
(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;
}
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)
} 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);
}
}