[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1384418641.1957.1.camel@chiang>
Date: Thu, 14 Nov 2013 03:44:01 -0500
From: David Turner <novalis@...alis.org>
To: Andreas Dilger <adilger@...ger.ca>
Cc: Theodore Ts'o <tytso@....edu>, Mark Harris <mhlk@....us>,
Jan Kara <jack@...e.cz>,
Ext4 Developers List <linux-ext4@...r.kernel.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: [PATCH v5 2/2] e2fsck: Correct ext4 dates generated by old kernels.
(apologies if this is a dup -- my mail client crashed and I don't see
this one in the lkml archives)
--
Older kernels on 64-bit machines would incorrectly encode pre-1970
ext4 dates as post-2311 dates. Detect and correct this (assuming the
current date is before 2242).
Signed-off-by: David Turner <novalis@...alis.org>
---
e2fsck/pass1.c | 38 ++++++++++++++++++++++++++++++++++++++
e2fsck/problem.c | 4 ++++
e2fsck/problem.h | 4 ++++
3 files changed, 46 insertions(+)
diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c
index ab23e42..b5ae885 100644
--- a/e2fsck/pass1.c
+++ b/e2fsck/pass1.c
@@ -348,6 +348,24 @@ fix:
EXT2_INODE_SIZE(sb), "pass1");
}
+#define EXT4_EPOCH_BITS 2
+#define EXT4_EPOCH_MASK ((1 << EXT4_EPOCH_BITS) - 1)
+
+static int check_inode_extra_negative_epoch(__u32 xtime, __u32 extra) {
+ return (xtime & (1 << 31)) != 0 &&
+ (extra & EXT4_EPOCH_MASK) == EXT4_EPOCH_MASK;
+}
+
+#define CHECK_INODE_EXTRA_NEGATIVE_EPOCH(inode, xtime) \
+ check_inode_extra_negative_epoch(inode->i_##xtime, \
+ inode->i_##xtime##_extra)
+
+/* When today's date is earlier than 2242, we assume that atimes,
+ * ctimes, and mtimes greater than 2242 are actually pre-1970 dates
+ * mis-encoded.
+ */
+#define EXT4_EXTRA_NEGATIVE_DATE_CUTOFF 5 * (1ULL << 32)
+
static void check_inode_extra_space(e2fsck_t ctx, struct problem_context *pctx)
{
struct ext2_super_block *sb = ctx->fs->super;
@@ -388,6 +406,26 @@ static void check_inode_extra_space(e2fsck_t ctx, struct problem_context *pctx)
/* it seems inode has an extended attribute(s) in body */
check_ea_in_inode(ctx, pctx);
}
+
+ /*
+ * If the inode's extended atime (ctime, mtime) is stored in
+ * the old, invalid format, the inode is corrupt.
+ */
+ if (sizeof(time_t) > 4 && ctx->now < EXT4_EXTRA_NEGATIVE_DATE_CUTOFF &&
+ CHECK_INODE_EXTRA_NEGATIVE_EPOCH(inode, atime) ||
+ CHECK_INODE_EXTRA_NEGATIVE_EPOCH(inode, ctime) ||
+ CHECK_INODE_EXTRA_NEGATIVE_EPOCH(inode, mtime)) {
+
+ if (!fix_problem(ctx, PR_1_EA_TIME_OUT_OF_RANGE, pctx))
+ return;
+
+ inode->i_atime_extra &= ~EXT4_EPOCH_MASK;
+ inode->i_ctime_extra &= ~EXT4_EPOCH_MASK;
+ inode->i_mtime_extra &= ~EXT4_EPOCH_MASK;
+ e2fsck_write_inode_full(ctx, pctx->ino, pctx->inode,
+ EXT2_INODE_SIZE(sb), "pass1");
+ }
+
}
/*
diff --git a/e2fsck/problem.c b/e2fsck/problem.c
index 897693a..b212d00 100644
--- a/e2fsck/problem.c
+++ b/e2fsck/problem.c
@@ -1018,6 +1018,10 @@ static struct e2fsck_problem problem_table[] = {
N_("@i %i, end of extent exceeds allowed value\n\t(logical @b %c, physical @b %b, len %N)\n"),
PROMPT_CLEAR, 0 },
+ /* Timestamp(s) on inode beyond 2310-04-04 are likely pre-1970 dates. */
+ { PR_1_EA_TIME_OUT_OF_RANGE,
+ N_("Timestamp(s) on @i %i beyond 2310-04-04 are likely pre-1970 dates.\n"),
+ PROMPT_FIX | PR_PREEN_OK | PR_NO_OK, 0 },
/* Pass 1b errors */
diff --git a/e2fsck/problem.h b/e2fsck/problem.h
index ae1ed26..3710638 100644
--- a/e2fsck/problem.h
+++ b/e2fsck/problem.h
@@ -593,6 +593,10 @@ struct problem_context {
#define PR_1_EXTENT_INDEX_START_INVALID 0x01006D
#define PR_1_EXTENT_END_OUT_OF_BOUNDS 0x01006E
+
+/* Timestamp(s) on inode beyond 2310-04-04 are likely pre-1970 dates. */
+#define PR_1_EA_TIME_OUT_OF_RANGE 0x01006F
+
/*
* Pass 1b errors
*/
--
1.8.1.2
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists