From: Theodore Ts'o Date: Thu, 4 Aug 2022 19:18:15 +0000 (-0400) Subject: resize2fs: fix to respect the environment variable E2FSPROGS_FAKE_TIME X-Git-Tag: v1.46.6-rc1~47 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=0288b1fd6909e92e3668dde8f1f6401fdabd1494;p=tools%2Fe2fsprogs.git resize2fs: fix to respect the environment variable E2FSPROGS_FAKE_TIME When performing an off-line resize, if an inode's block map needs to be updated, resize2fs will update the inode's ctime. In addition, if inode numbers need to be renumbered due to the file system shrinking forcing the inode table to be shrunk, any directories which need to be modified will have their ctime and mtime updated. If the E2FSPROGS_FAkE_TIME environment variable is set, when the file system is opened, fs->now will be set to this value, and resize2fs needs to use it instead of calling time(0) to get their current time. Addresses-Google-Bug: 230874381 Signed-off-by: Theodore Ts'o --- diff --git a/resize/resize2fs.c b/resize/resize2fs.c index 916b1f4..cfc81fc 100644 --- a/resize/resize2fs.c +++ b/resize/resize2fs.c @@ -2266,7 +2266,8 @@ static errcode_t inode_scan_and_fix(ext2_resize_t rfs) if (inode->i_flags & EXT4_EA_INODE_FL) update_ea_inode_refs = 1; else - inode->i_ctime = time(0); + inode->i_ctime = rfs->old_fs->now ? + rfs->old_fs->now : time(0); retval = ext2fs_write_inode_full(rfs->old_fs, new_inode, inode, inode_size); @@ -2419,7 +2420,8 @@ static int check_and_change_inodes(ext2_ino_t dir, /* Update the directory mtime and ctime */ retval = ext2fs_read_inode(is->rfs->old_fs, dir, &inode); if (retval == 0) { - inode.i_mtime = inode.i_ctime = time(0); + inode.i_mtime = inode.i_ctime = is->rfs->old_fs->now ? + is->rfs->old_fs->now : time(0); is->err = ext2fs_write_inode(is->rfs->old_fs, dir, &inode); if (is->err) return ret | DIRENT_ABORT;