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" <tytso@mit.edu>
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 <tytso@mit.edu>
+
+ * 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 <matthias.andree@gmx.de>
* 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 @@
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 @@
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 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 @@
}
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 @@
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 @@
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 @@
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 @@
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;