From 4efae606bf3159f2134fa29a5ad78fb9f6331f92 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Sat, 24 Sep 2005 21:56:38 -0400 Subject: [PATCH] New debugfs command: set_current_time Generalize the time parsing code and move it to util.c:string_to_time(). Add new command, set_current_time, which sets the time used to set the filesystems's time fields. Signed-off-by: "Theodore Ts'o" --- debugfs/ChangeLog | 8 ++++++++ debugfs/debug_cmds.ct | 3 +++ debugfs/debugfs.c | 28 +++++++++++++++++++++++++--- debugfs/debugfs.h | 1 + debugfs/lsdel.c | 2 +- debugfs/set_fields.c | 31 ++++++++----------------------- debugfs/util.c | 36 ++++++++++++++++++++++++++++++++++++ 7 files changed, 82 insertions(+), 27 deletions(-) diff --git a/debugfs/ChangeLog b/debugfs/ChangeLog index dd96b58db..f92dc8026 100644 --- a/debugfs/ChangeLog +++ b/debugfs/ChangeLog @@ -1,3 +1,11 @@ +2005-09-24 Theodore Ts'o + + * set_fields.c (parse_time), util.c (string_to_time), debugfs.c + (do_set_current_time): Generalize the time parsing code + and move it to util.c:string_to_time(). Add new command, + set_current_time, which sets the time used to set the + filesystems's time fields. + 2005-09-06 Theodore Ts'o * set_fields.c: Fix set_inode_field so it can properly set the diff --git a/debugfs/debug_cmds.ct b/debugfs/debug_cmds.ct index 06e6fe164..a3d3e2dfe 100644 --- a/debugfs/debug_cmds.ct +++ b/debugfs/debug_cmds.ct @@ -148,5 +148,8 @@ request do_imap, "Calculate the location of an inode", request do_dump_unused, "Dump unused blocks", dump_unused; +request do_set_current_time, "Set current time to use when setting filesystme fields", + set_current_time; + end; diff --git a/debugfs/debugfs.c b/debugfs/debugfs.c index c2baee97a..20d1f4bf2 100644 --- a/debugfs/debugfs.c +++ b/debugfs/debugfs.c @@ -1295,7 +1295,8 @@ void do_write(int argc, char *argv[]) ext2fs_inode_alloc_stats2(current_fs, newfile, +1, 0); memset(&inode, 0, sizeof(inode)); inode.i_mode = (statbuf.st_mode & ~LINUX_S_IFMT) | LINUX_S_IFREG; - inode.i_atime = inode.i_ctime = inode.i_mtime = time(NULL); + inode.i_atime = inode.i_ctime = inode.i_mtime = + current_fs->now ? current_fs->now : time(0); inode.i_links_count = 1; inode.i_size = statbuf.st_size; if (debugfs_write_new_inode(newfile, &inode, argv[0])) { @@ -1382,7 +1383,8 @@ void do_mknod(int argc, char *argv[]) ext2fs_mark_ib_dirty(current_fs); memset(&inode, 0, sizeof(inode)); inode.i_mode = mode; - inode.i_atime = inode.i_ctime = inode.i_mtime = time(NULL); + inode.i_atime = inode.i_ctime = inode.i_mtime = + current_fs->now ? current_fs->now : time(0); if ((major < 256) && (minor < 256)) { inode.i_block[0] = major*256+minor; inode.i_block[1] = 0; @@ -1454,7 +1456,7 @@ static void kill_file_by_inode(ext2_ino_t inode) if (debugfs_read_inode(inode, &inode_buf, 0)) return; - inode_buf.i_dtime = time(NULL); + inode_buf.i_dtime = current_fs->now ? current_fs->now : time(0); if (debugfs_write_inode(inode, &inode_buf, 0)) return; if (!ext2fs_inode_has_valid_blocks(&inode_buf)) @@ -1697,7 +1699,27 @@ void do_imap(int argc, char *argv[]) } +void do_set_current_time(int argc, char *argv[]) +{ + ext2_ino_t ino; + unsigned long group, block, block_nr, offset; + time_t now; + + if (common_args_process(argc, argv, 2, 2, argv[0], + "