]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
e2fsck: Fix and enhance superblock dates in future problem reports
authorTheodore Ts'o <tytso@mit.edu>
Sat, 8 Aug 2009 14:14:48 +0000 (10:14 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Sat, 8 Aug 2009 14:14:48 +0000 (10:14 -0400)
Fixed a bug where e2fsck would report that last mount time was in the
future when it was really the last write time that was in the future.

Also, since people can't seem to believe that (a) their distribution
has buggy init scripts, or (b) their CMOS/RTC clock or backup battery
is dead, print the incorrect time and the current system time.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
e2fsck/message.c
e2fsck/problem.c
e2fsck/super.c

index 3f859160c70b253a5879d5545ed3b759ccc340cc..77f975603fb0cd5a1578bd4bb5c0562af39794f7 100644 (file)
@@ -209,6 +209,24 @@ static void print_pathname(ext2_filsys fs, ext2_ino_t dir, ext2_ino_t ino)
        }
 }
 
+static void print_time(time_t t)
+{
+       const char *            time_str;
+       static int              do_gmt = -1;
+
+#ifdef __dietlibc__
+               /* The diet libc doesn't respect the TZ environemnt variable */
+               if (do_gmt == -1) {
+                       time_str = getenv("TZ");
+                       if (!time_str)
+                               time_str = "";
+                       do_gmt = !strcmp(time_str, "GMT0");
+               }
+#endif
+               time_str = asctime((do_gmt > 0) ? gmtime(&t) : localtime(&t));
+               printf("%.24s", time_str);
+}
+
 /*
  * This function handles the '@' expansion.  We allow recursive
  * expansion; an @ expression can contain further '@' and '%'
@@ -244,9 +262,7 @@ static _INLINE_ void expand_inode_expression(char ch,
 {
        struct ext2_inode       *inode;
        struct ext2_inode_large *large_inode;
-       const char *            time_str;
        time_t                  t;
-       static int              do_gmt = -1;
 
        if (!ctx || !ctx->inode)
                goto no_inode;
@@ -289,18 +305,7 @@ static _INLINE_ void expand_inode_expression(char ch,
                printf("0%o", inode->i_mode);
                break;
        case 'M':
-#ifdef __dietlibc__
-               /* The diet libc doesn't respect the TZ environemnt variable */
-               if (do_gmt == -1) {
-                       time_str = getenv("TZ");
-                       if (!time_str)
-                               time_str = "";
-                       do_gmt = !strcmp(time_str, "GMT0");
-               }
-#endif
-               t = inode->i_mtime;
-               time_str = asctime((do_gmt > 0) ? gmtime(&t) : localtime(&t));
-               printf("%.24s", time_str);
+               print_time(inode->i_mtime);
                break;
        case 'F':
                printf("%u", inode->i_faddr);
@@ -392,6 +397,8 @@ static _INLINE_ void expand_dirent_expression(ext2_filsys fs, char ch,
 static _INLINE_ void expand_percent_expression(ext2_filsys fs, char ch,
                                               struct problem_context *ctx)
 {
+       e2fsck_t e2fsck_ctx = fs ? (e2fsck_t) fs->priv_data : NULL;
+
        if (!ctx)
                goto no_context;
 
@@ -461,6 +468,12 @@ static _INLINE_ void expand_percent_expression(ext2_filsys fs, char ch,
        case 's':
                printf("%s", ctx->str ? ctx->str : "NULL");
                break;
+       case 't':
+               print_time((time_t) ctx->num);
+               break;
+       case 'T':
+               print_time(e2fsck_ctx ? e2fsck_ctx->now : time(0));
+               break;
        case 'X':
 #ifdef EXT2_NO_64_TYPE
                printf("0x%x", ctx->num);
index d6b345cfa131c3e0c2e10b4f700ae1b7a1e85b1e..fc325e9568812542838599b14c7554683718ed53 100644 (file)
@@ -334,12 +334,12 @@ static struct e2fsck_problem problem_table[] = {
 
        /* Last mount time is in the future */
        { PR_0_FUTURE_SB_LAST_MOUNT,
-         N_("@S last mount time is in the future.  "),
+         N_("@S last mount time (%t,\n\tnow = %T) is in the future.\n"),
          PROMPT_FIX, PR_NO_OK },
 
        /* Last write time is in the future */
        { PR_0_FUTURE_SB_LAST_WRITE,
-         N_("@S last write time is in the future.  "),
+         N_("@S last write time (%t,\n\tnow = %T) is in the future.\n"),
          PROMPT_FIX, PR_NO_OK },
 
        { PR_0_EXTERNAL_JOURNAL_HINT,
index ef29aa525cfdfb3da02d90cfe35c1aadda579220..22029674c9959790c8f5da346de1e72741a54a73 100644 (file)
@@ -831,7 +831,7 @@ void check_super_block(e2fsck_t ctx)
        }
        if (fs->super->s_wtime > (__u32) ctx->now) {
                pctx.num = fs->super->s_wtime;
-               problem = PR_0_FUTURE_SB_LAST_MOUNT;
+               problem = PR_0_FUTURE_SB_LAST_WRITE;
                if (fs->super->s_wtime <= (__u32) ctx->now + ctx->time_fudge)
                        problem = PR_0_FUTURE_SB_LAST_MOUNT_FUDGED;
                if (fix_problem(ctx, problem, &pctx)) {