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@xxxxxxxxxxx> --- 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 -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html