Whamcloud - gitweb
E2fsck: fix future times in the superblock's last mount or last write fields
authorTheodore Ts'o <tytso@mit.edu>
Sun, 25 Sep 2005 01:59:45 +0000 (21:59 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Sun, 25 Sep 2005 01:59:45 +0000 (21:59 -0400)
Detect if the superblock's last mount field or last write field is in
the future, and offer to fix if so.  (Addresses Debian Bug #327580)

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
e2fsck/ChangeLog
e2fsck/journal.c
e2fsck/problem.c
e2fsck/problem.h
e2fsck/super.c
e2fsck/unix.c
tests/ChangeLog
tests/f_dup_resize/script

index deec7ea..b7da9b6 100644 (file)
@@ -1,3 +1,10 @@
+2005-09-24  Theodore Ts'o  <tytso@mit.edu>
+
+       * super.c (check_super_block), problem.c, problem.h: Detect if the
+               superblock's last mount field or last write field is in
+               the future, and offer to fix if so.  (Addresses Debian Bug
+               #327580)
+
 2005-07-25  Theodore Ts'o  <tytso@mit.edu>
 
        * unix.c (main): Fix a use-after-free bug of the e2fsck context
index a5f156c..0a53cc7 100644 (file)
@@ -827,6 +827,7 @@ int e2fsck_run_ext3_journal(e2fsck_t ctx)
                fatal_error(ctx, 0);
        }
        ctx->fs->priv_data = ctx;
+       ctx->fs->now = ctx->now;
 
        /* Set the superblock flags */
        e2fsck_clear_recover(ctx, recover_retval);
index c2e5076..357bd8d 100644 (file)
@@ -332,6 +332,16 @@ static const struct e2fsck_problem problem_table[] = {
          N_("Resize @i not valid.  "),
          PROMPT_RECREATE, 0 },
 
+       /* Last mount time is in the future */
+       { PR_0_FUTURE_SB_LAST_MOUNT,
+         N_("@S last mount time is in the future.  "),
+         PROMPT_FIX, 0 },
+
+       /* Last write time is in the future */
+       { PR_0_FUTURE_SB_LAST_WRITE,
+         N_("@S last write time is in the future.  "),
+         PROMPT_FIX, 0 },
+
        /* Pass 1 errors */
        
        /* Pass 1: Checking inodes, blocks, and sizes */
index 0e39a29..9614d1c 100644 (file)
@@ -184,6 +184,12 @@ struct problem_context {
 /* Resize inode invalid */
 #define PR_0_RESIZE_INODE_INVALID              0x000030
 
+/* Last mount time is in the future */
+#define PR_0_FUTURE_SB_LAST_MOUNT              0x000031
+
+/* Last write time is in the future */
+#define PR_0_FUTURE_SB_LAST_WRITE              0x000032
+
 /*
  * Pass 1 errors
  */
index 0855fb5..d886bbd 100644 (file)
@@ -705,6 +705,25 @@ void check_super_block(e2fsck_t ctx)
                ext2fs_mark_super_dirty(fs);
        }
 
+       /* 
+        * Check to see if the superblock last mount time or last
+        * write time is in the future.
+        */
+       if (fs->super->s_mtime > ctx->now) {
+               pctx.num = fs->super->s_mtime;
+               if (fix_problem(ctx, PR_0_FUTURE_SB_LAST_MOUNT, &pctx)) {
+                       fs->super->s_mtime = ctx->now;
+                       ext2fs_mark_super_dirty(fs);
+               }
+       }
+       if (fs->super->s_wtime > ctx->now) {
+               pctx.num = fs->super->s_wtime;
+               if (fix_problem(ctx, PR_0_FUTURE_SB_LAST_WRITE, &pctx)) {
+                       fs->super->s_wtime = ctx->now;
+                       ext2fs_mark_super_dirty(fs);
+               }
+       }
+
        /*
         * Move the ext3 journal file, if necessary.
         */
index 6cbcb10..5f1aaa2 100644 (file)
@@ -943,6 +943,7 @@ restart:
        }
        ctx->fs = fs;
        fs->priv_data = ctx;
+       fs->now = ctx->now;
        sb = fs->super;
        if (sb->s_rev_level > E2FSCK_CURRENT_REV) {
                com_err(ctx->program_name, EXT2_ET_REV_TOO_HIGH,
index a3522c2..2c2813b 100644 (file)
@@ -1,3 +1,9 @@
+2005-09-24  Theodore Ts'o  <tytso@mit.edu>
+
+       * f_dup_resize: Set the current time to in debugfs to a value
+               which avoids triggering the "s_mtime in the future"
+               warning from e2fsck.
+
 2005-08-08  Theodore Ts'o  <tytso@mit.edu>
 
        * test_config, test_script.in, d_loaddump, f_dup_resize,
index ed374fe..7a5214c 100644 (file)
@@ -9,6 +9,7 @@ $DEBUGFS -w $TMPFILE << EOF > /dev/null 2>&1
 freeb 4 4
 freeb 8195 4
 write $TEST_DATA debugfs
+set_current_time 200504110000
 set_inode_field debugfs mtime 200504110000
 q
 EOF