Whamcloud - gitweb
Add fs->now to override time(0) in libext2fs
authorTheodore Ts'o <tytso@mit.edu>
Sun, 25 Sep 2005 00:14:51 +0000 (20:14 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Sun, 25 Sep 2005 00:14:51 +0000 (20:14 -0400)
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>
lib/ext2fs/ChangeLog
lib/ext2fs/bb_inode.c
lib/ext2fs/closefs.c
lib/ext2fs/ext2fs.h
lib/ext2fs/initialize.c
lib/ext2fs/mkdir.c
lib/ext2fs/mkjournal.c
lib/ext2fs/res_gdt.c

index 910bfc2..5e2530e 100644 (file)
@@ -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.
index dd8e7c3..97a5608 100644 (file)
@@ -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;
 
index 8539a1c..6a15193 100644 (file)
@@ -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) {
index 9c7eee2..c573af3 100644 (file)
@@ -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.
index 82cd9f1..5a0d100 100644 (file)
@@ -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;
 
index 81e7aea..45e6820 100644 (file)
@@ -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;
 
        /*
index 76ed5cb..eb35013 100644 (file)
@@ -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;
 
index 8b4ddca..c03f1da 100644 (file)
@@ -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;