From patchwork Thu Nov 14 21:06:33 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Turner X-Patchwork-Id: 291375 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id A6B552C00A0 for ; Fri, 15 Nov 2013 08:07:15 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757799Ab3KNVGm (ORCPT ); Thu, 14 Nov 2013 16:06:42 -0500 Received: from mailbigip.dreamhost.com ([208.97.132.5]:57184 "EHLO homiemail-a101.g.dreamhost.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1757150Ab3KNVGf (ORCPT ); Thu, 14 Nov 2013 16:06:35 -0500 Received: from homiemail-a101.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a101.g.dreamhost.com (Postfix) with ESMTP id 73ED3117E06C; Thu, 14 Nov 2013 13:06:35 -0800 (PST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=novalis.org; h=message-id:subject :from:to:cc:date:in-reply-to:references:content-type :mime-version:content-transfer-encoding; q=dns; s=novalis.org; b=G9aGJVjcjbqAylmDBDKFmAwVRTep2T0YiQDc2QT1PKAdZ7/zUl9+QdzBJN89w RnAR9TFWHDe39WK1vJo/n3kwpoR9wD2+9AbumR0trtqgpucGxPlPOacwchn5jzUi scblk4gYGuY4YAiuMCONzLio5VFadcJ43WkbSiBkVEnQ/k= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=novalis.org; h=message-id :subject:from:to:cc:date:in-reply-to:references:content-type :mime-version:content-transfer-encoding; s=novalis.org; bh=r/Nb8 JFIoBEJnVXqimvfFGKobmY=; b=IXex/HEW+aA1nrhLFXa64fcUFWiht7xufWg8x 5n5cKUsz9zaCR3PpAug+J+ejmWAw+0cRp/ssSCHINueM2PrpFtMS5JOLwahNl7ZU rDTPr1jryrS8sxWaga9jqTVgL2sVZuAgLCtYlpu8L+uUm14AHMNNEsZrQZ9owaS2 IFWFmM= Received: from [10.0.1.4] (ool-4579628d.dyn.optonline.net [69.121.98.141]) (using SSLv3 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: novalis@novalis.org) by homiemail-a101.g.dreamhost.com (Postfix) with ESMTPSA id AB835117E06A; Thu, 14 Nov 2013 13:06:34 -0800 (PST) Message-ID: <1384463193.1957.27.camel@chiang> Subject: [PATCH v6] e2fsck: Correct ext4 dates generated by old kernels. From: David Turner To: Mark Harris Cc: Andreas Dilger , Theodore Ts'o , Jan Kara , Ext4 Developers List , Linux Kernel Mailing List Date: Thu, 14 Nov 2013 16:06:33 -0500 In-Reply-To: References: <1383808590.23882.13.camel@chiang> <20131107160341.GA3850@quack.suse.cz> <1383864864.23882.33.camel@chiang> <20131107231445.GG2054@quack.suse.cz> <1383866807.23882.41.camel@chiang> <1383981551.8994.27.camel@chiang> <1384070214.8994.47.camel@chiang> <20131112003018.GA30281@thunk.org> <6DE0AF86-98E6-4DE9-BB7F-40FB32E1BC26@dilger.ca> <1384326020.8994.186.camel@chiang> <276FA06E-1EE0-4FB4-94E1-B6D9F05F0B5B@dilger.ca> <1384418641.1957.1.camel@chiang> X-Mailer: Evolution 3.6.4-0ubuntu1 Mime-Version: 1.0 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Not sure what the official subject line format is for revising only one of N patches, so I'm trying this one. Let me now if it is wrong. On Thu, 2013-11-14 at 02:15 -0800, Mark Harris wrote: > > + * mis-encoded. > > + */ > > +#define EXT4_EXTRA_NEGATIVE_DATE_CUTOFF 5 * (1ULL << 32) > > Wouldn't 2242 be 0x200000000ULL, i.e. 2 * (1ULL << 32)? Actually, it would be 2 * (1LL << 32), because we later use it in a comparison with a signed value. --- 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 --- e2fsck/pass1.c | 41 +++++++++++++++++++++++++++++++++++++++++ e2fsck/problem.c | 4 ++++ e2fsck/problem.h | 4 ++++ 3 files changed, 49 insertions(+) diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c index ab23e42..e19855f 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 with years in the range 2310..2378 are actually + * pre-1970 dates mis-encoded. + */ +#define EXT4_EXTRA_NEGATIVE_DATE_CUTOFF 2 * (1LL << 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,29 @@ 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, repair it. + */ + 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; + + if (CHECK_INODE_EXTRA_NEGATIVE_EPOCH(inode, atime)) + inode->i_atime_extra &= ~EXT4_EPOCH_MASK; + if (CHECK_INODE_EXTRA_NEGATIVE_EPOCH(inode, ctime)) + inode->i_ctime_extra &= ~EXT4_EPOCH_MASK; + if (CHECK_INODE_EXTRA_NEGATIVE_EPOCH(inode, mtime)) + 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 */