All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Turner <novalis@novalis.org>
To: Andreas Dilger <adilger@dilger.ca>
Cc: Mark Harris <mhlk@osj.us>, Theodore Ts'o <tytso@mit.edu>,
	Jan Kara <jack@suse.cz>,
	Ext4 Developers List <linux-ext4@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: [PATCH v7 2/2] debugfs: Decode {a,c,cr,m}time_extra fields in stat
Date: Sat, 07 Dec 2013 15:02:45 -0500	[thread overview]
Message-ID: <1386446565.10748.6.camel@chiang> (raw)
In-Reply-To: <B3592308-F3D8-4887-AF52-812EA988410E@dilger.ca>

Decodes post-2038 dates correctly on on machines with a 64-bit time_t.
When decoding dates from xtime+xtime_extra fields, we assume that
these dates are in the correct format (i.e. pre-1970 dates have
xtime_extra low bits == 0 instead of 3).  So uncorrected pre-1970
dates will be displayed as post-2310 dates.  This is because we don't
want our filesystem debugging tools to silently correct data errors.

Signed-off-by: David Turner <novalis@novalis.org>
---
 debugfs/debugfs.c | 22 ++++++++++++++++++----
 debugfs/debugfs.h |  2 +-
 debugfs/util.c    |  7 +++----
 3 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/debugfs/debugfs.c b/debugfs/debugfs.c
index 8c32eff..aa2f972 100644
--- a/debugfs/debugfs.c
+++ b/debugfs/debugfs.c
@@ -37,6 +37,8 @@ extern char *optarg;
 #include "../version.h"
 #include "jfs_user.h"
 
+#include "extra_epoch.h"
+
 #ifndef BUFSIZ
 #define BUFSIZ 8192
 #endif
@@ -718,6 +720,14 @@ static void dump_extents(FILE *f, const char
*prefix, ext2_ino_t ino,
 		fprintf(f, "\n");
 }
 
+char* inode_time_to_string(__s32 xtime, __u32 xtime_extra) {
+	time_t time = (time_t) xtime;
+	if (sizeof(time_t) > 4) {
+		time += (xtime_extra & EXT4_EPOCH_MASK) << 32;
+	}
+	return time_to_string(time);
+}
+
 void internal_dump_inode(FILE *out, const char *prefix,
 			 ext2_ino_t inode_num, struct ext2_inode *inode,
 			 int do_dump_blocks)
@@ -791,16 +801,20 @@ void internal_dump_inode(FILE *out, const char
*prefix,
 	if (is_large_inode && large_inode->i_extra_isize >= 24) {
 		fprintf(out, "%s ctime: 0x%08x:%08x -- %s", prefix,
 			inode->i_ctime, large_inode->i_ctime_extra,
-			time_to_string(inode->i_ctime));
+			inode_time_to_string(inode->i_ctime,
+					     large_inode->i_ctime_extra));
 		fprintf(out, "%s atime: 0x%08x:%08x -- %s", prefix,
 			inode->i_atime, large_inode->i_atime_extra,
-			time_to_string(inode->i_atime));
+			inode_time_to_string(inode->i_atime,
+					     large_inode->i_atime_extra));
 		fprintf(out, "%s mtime: 0x%08x:%08x -- %s", prefix,
 			inode->i_mtime, large_inode->i_mtime_extra,
-			time_to_string(inode->i_mtime));
+			inode_time_to_string(inode->i_mtime,
+					     large_inode->i_mtime_extra));
 		fprintf(out, "%scrtime: 0x%08x:%08x -- %s", prefix,
 			large_inode->i_crtime, large_inode->i_crtime_extra,
-			time_to_string(large_inode->i_crtime));
+			inode_time_to_string(large_inode->i_crtime,
+					     large_inode->i_crtime_extra));
 	} else {
 		fprintf(out, "%sctime: 0x%08x -- %s", prefix, inode->i_ctime,
 			time_to_string(inode->i_ctime));
diff --git a/debugfs/debugfs.h b/debugfs/debugfs.h
index 45175cf..a02f29c 100644
--- a/debugfs/debugfs.h
+++ b/debugfs/debugfs.h
@@ -33,7 +33,7 @@ extern int check_fs_not_open(char *name);
 extern int check_fs_read_write(char *name);
 extern int check_fs_bitmaps(char *name);
 extern ext2_ino_t string_to_inode(char *str);
-extern char *time_to_string(__u32);
+extern char *time_to_string(time_t);
 extern time_t string_to_time(const char *);
 extern unsigned long parse_ulong(const char *str, const char *cmd,
 				 const char *descr, int *err);
diff --git a/debugfs/util.c b/debugfs/util.c
index cf3a6c6..a60aec7 100644
--- a/debugfs/util.c
+++ b/debugfs/util.c
@@ -187,13 +187,12 @@ int check_fs_bitmaps(char *name)
 }
 
 /*
- * This function takes a __u32 time value and converts it to a string,
- * using ctime
+ * This function takes a time_t time value and converts it to a string,
+ * using asctime
  */
-char *time_to_string(__u32 cl)
+char *time_to_string(time_t t)
 {
 	static int	do_gmt = -1;
-	time_t		t = (time_t) cl;
 	const char	*tz;
 
 	if (do_gmt == -1) {
-- 
1.8.1.2




  parent reply	other threads:[~2013-12-07 20:02 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-07  7:16 [PATCH] ext4: Fix reading of extended tv_sec (bug 23732) David Turner
2013-11-07 16:03 ` Jan Kara
2013-11-07 22:54   ` [PATCH v2] " David Turner
2013-11-07 23:14     ` Jan Kara
2013-11-07 23:26       ` [PATCH v3] " David Turner
2013-11-08  5:17         ` Theodore Ts'o
2013-11-08 21:37         ` Andreas Dilger
2013-11-09  7:19           ` [PATCH] ext4: explain encoding of 34-bit a,c,mtime values David Turner
2013-11-09  7:19             ` David Turner
2013-11-09 23:51             ` Mark Harris
2013-11-09 23:51               ` Mark Harris
2013-11-10  7:56               ` David Turner
2013-11-12  0:30                 ` Theodore Ts'o
2013-11-12 21:35                   ` Andreas Dilger
2013-11-13  7:00                     ` [PATCH v4 1/2] ext4: Fix handling of extended tv_sec (bug 23732) David Turner
2013-11-13  8:19                       ` Darrick J. Wong
2013-11-13  7:00                     ` [PATCH v4 2/2] e2fsck: Correct ext4 dates generated by old kernels David Turner
2013-11-13  7:56                       ` Andreas Dilger
2013-11-14  8:38                         ` [PATCH v5 1/2] ext4: Fix handling of extended tv_sec (bug 23732) David Turner
2013-11-14  8:44                         ` [PATCH v5 2/2] e2fsck: Correct ext4 dates generated by old kernels David Turner
2013-11-14 10:15                           ` Mark Harris
2013-11-14 21:06                             ` [PATCH v6] " David Turner
2013-11-29 21:54                               ` David Turner
2013-11-29 22:11                                 ` Andreas Dilger
2013-12-07 20:02                                   ` [PATCH v7 1/2] " David Turner
2013-12-07 22:33                                     ` Andreas Dilger
2013-12-08  0:53                                     ` Theodore Ts'o
2013-12-08  2:58                                       ` David Turner
2013-12-08  3:21                                         ` Theodore Ts'o
2013-12-07 20:02                                   ` David Turner [this message]
2013-11-12 23:03                   ` [PATCH] ext4: explain encoding of 34-bit a,c,mtime values Darrick J. Wong
2013-11-13  2:36                     ` David Turner
2014-01-22  6:22                   ` Darrick J. Wong
2014-02-11  5:12                     ` David Turner
2014-02-11  7:07                       ` Andreas Dilger
2014-02-14  3:47                         ` [PATCH v8 1/2] ext4: Fix handling of extended tv_sec (bug 23732) David Turner
2014-02-14  3:47                         ` [PATCH v8 2/2] e2fsck: Correct ext4 dates generated by old kernels David Turner
2014-02-14  5:40                           ` Andreas Dilger
2014-02-14 22:11                             ` Darrick J. Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1386446565.10748.6.camel@chiang \
    --to=novalis@novalis.org \
    --cc=adilger@dilger.ca \
    --cc=jack@suse.cz \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhlk@osj.us \
    --cc=tytso@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.