From 32138187f08d1f1dc03feb269f987982db76f3db Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Sat, 24 Sep 2005 20:14:51 -0400 Subject: [PATCH] Add fs->now to override time(0) in libext2fs If fs->now is non-zero, use that as the time instead of the system time when setting various filesystem fields (last modified time, last write time, etc.) Signed-off-by: "Theodore Ts'o" --- lib/ext2fs/ChangeLog | 8 ++++++++ lib/ext2fs/bb_inode.c | 4 ++-- lib/ext2fs/closefs.c | 2 +- lib/ext2fs/ext2fs.h | 3 ++- lib/ext2fs/initialize.c | 2 +- lib/ext2fs/mkdir.c | 2 +- lib/ext2fs/mkjournal.c | 2 +- lib/ext2fs/res_gdt.c | 4 ++-- 8 files changed, 18 insertions(+), 9 deletions(-) diff --git a/lib/ext2fs/ChangeLog b/lib/ext2fs/ChangeLog index 910bfc2..5e2530e 100644 --- a/lib/ext2fs/ChangeLog +++ b/lib/ext2fs/ChangeLog @@ -1,3 +1,11 @@ +2005-09-24 Theodore Ts'o + + * ext2fs.h, bb_inode.c, closefs.c, initialize.c, mkdir.c, + mkjournal.c, res_gdt.c: If fs->now is non-zero, use that + as the time instead of the system time when setting + various filesystem fields (last modified time, last write + time, etc.) + 2005-08-28 Matthias Andree * Fix compiler warnings about missing memcpy prototypes. diff --git a/lib/ext2fs/bb_inode.c b/lib/ext2fs/bb_inode.c index dd8e7c3..97a5608 100644 --- a/lib/ext2fs/bb_inode.c +++ b/lib/ext2fs/bb_inode.c @@ -124,9 +124,9 @@ errcode_t ext2fs_update_bb_inode(ext2_filsys fs, ext2_badblocks_list bb_list) if (retval) goto cleanup; - inode.i_atime = inode.i_mtime = time(0); + inode.i_atime = inode.i_mtime = fs->now ? fs->now : time(0); if (!inode.i_ctime) - inode.i_ctime = time(0); + inode.i_ctime = fs->now ? fs->now : time(0); inode.i_blocks = rec.bad_block_count * (fs->blocksize / 512); inode.i_size = rec.bad_block_count * fs->blocksize; diff --git a/lib/ext2fs/closefs.c b/lib/ext2fs/closefs.c index 8539a1c..6a15193 100644 --- a/lib/ext2fs/closefs.c +++ b/lib/ext2fs/closefs.c @@ -219,7 +219,7 @@ errcode_t ext2fs_flush(ext2_filsys fs) fs_state = fs->super->s_state; - fs->super->s_wtime = time(NULL); + fs->super->s_wtime = fs->now ? fs->now : time(NULL); fs->super->s_block_group_nr = 0; #ifdef EXT2FS_ENABLE_SWAPFS if (fs->flags & EXT2_FLAG_SWAP_BYTES) { diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h index 9c7eee2..c573af3 100644 --- a/lib/ext2fs/ext2fs.h +++ b/lib/ext2fs/ext2fs.h @@ -228,10 +228,11 @@ struct struct_ext2_filsys { struct ext2_super_block * orig_super; struct ext2_image_hdr * image_header; __u32 umask; + __u32 now; /* * Reserved for future expansion */ - __u32 reserved[8]; + __u32 reserved[7]; /* * Reserved for the use of the calling application. diff --git a/lib/ext2fs/initialize.c b/lib/ext2fs/initialize.c index 82cd9f1..5a0d100 100644 --- a/lib/ext2fs/initialize.c +++ b/lib/ext2fs/initialize.c @@ -168,7 +168,7 @@ errcode_t ext2fs_initialize(const char *name, int flags, } set_field(s_checkinterval, EXT2_DFL_CHECKINTERVAL); - super->s_mkfs_time = super->s_lastcheck = time(NULL); + super->s_mkfs_time = super->s_lastcheck = fs->now ? fs->now : time(NULL); super->s_creator_os = CREATOR_OS; diff --git a/lib/ext2fs/mkdir.c b/lib/ext2fs/mkdir.c index 81e7aea..45e6820 100644 --- a/lib/ext2fs/mkdir.c +++ b/lib/ext2fs/mkdir.c @@ -85,7 +85,7 @@ errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum, inode.i_blocks = fs->blocksize / 512; inode.i_block[0] = blk; inode.i_links_count = 2; - inode.i_ctime = inode.i_atime = inode.i_mtime = time(NULL); + inode.i_ctime = inode.i_atime = inode.i_mtime = fs->now ? fs->now : time(NULL); inode.i_size = fs->blocksize; /* diff --git a/lib/ext2fs/mkjournal.c b/lib/ext2fs/mkjournal.c index 76ed5cb..eb35013 100644 --- a/lib/ext2fs/mkjournal.c +++ b/lib/ext2fs/mkjournal.c @@ -229,7 +229,7 @@ static errcode_t write_journal_inode(ext2_filsys fs, ext2_ino_t journal_ino, inode.i_size += fs->blocksize * size; inode.i_blocks += (fs->blocksize / 512) * es.newblocks; - inode.i_mtime = inode.i_ctime = time(0); + inode.i_mtime = inode.i_ctime = fs->now ? fs->now : time(0); inode.i_links_count = 1; inode.i_mode = LINUX_S_IFREG | 0600; diff --git a/lib/ext2fs/res_gdt.c b/lib/ext2fs/res_gdt.c index 8b4ddca..c03f1da 100644 --- a/lib/ext2fs/res_gdt.c +++ b/lib/ext2fs/res_gdt.c @@ -116,7 +116,7 @@ errcode_t ext2fs_create_resize_inode(ext2_filsys fs) sb->s_feature_ro_compat |= EXT2_FEATURE_RO_COMPAT_LARGE_FILE; } - inode.i_ctime = time(0); + inode.i_ctime = fs->now ? fs->now : time(0); } for (rsv_off = 0, gdt_off = fs->desc_blocks, @@ -208,7 +208,7 @@ out_inode: inode.i_size); #endif if (inode_dirty) { - inode.i_atime = inode.i_mtime = time(0); + inode.i_atime = inode.i_mtime = fs->now ? fs->now : time(0); retval2 = ext2fs_write_inode(fs, EXT2_RESIZE_INO, &inode); if (!retval) retval = retval2; -- 1.8.3.1