From: Darrick J. Wong <darrick.wong@xxxxxxxxxx> Introduce type-specific printing functions to xfs_db to print an xfs_timestamp instead of open-coding the timestamp decoding. This is needed to stay ahead of changes that we're going to make to xfs_timestamp_t in the following patches. Signed-off-by: Darrick J. Wong <darrick.wong@xxxxxxxxxx> --- db/field.c | 8 ++++--- db/fprint.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++------------- db/fprint.h | 2 ++ db/inode.c | 5 ++-- 4 files changed, 60 insertions(+), 22 deletions(-) diff --git a/db/field.c b/db/field.c index aa0154d82eb7..f0316aeb4a86 100644 --- a/db/field.c +++ b/db/field.c @@ -334,8 +334,8 @@ const ftattr_t ftattrtab[] = { FTARG_SIGNED, NULL, NULL }, { FLDT_INT8D, "int8d", fp_num, "%d", SI(bitsz(int8_t)), FTARG_SIGNED, NULL, NULL }, - { FLDT_NSEC, "nsec", fp_num, "%09d", SI(bitsz(int32_t)), FTARG_SIGNED, - NULL, NULL }, + { FLDT_NSEC, "nsec", fp_nsec, NULL, SI(bitsz(xfs_timestamp_t)), + FTARG_SIGNED, NULL, NULL }, { FLDT_QCNT, "qcnt", fp_num, "%llu", SI(bitsz(xfs_qcnt_t)), 0, NULL, NULL }, { FLDT_QWARNCNT, "qwarncnt", fp_num, "%u", SI(bitsz(xfs_qwarncnt_t)), 0, @@ -347,8 +347,8 @@ const ftattr_t ftattrtab[] = { { FLDT_SYMLINK_CRC, "symlink", NULL, (char *)symlink_crc_flds, symlink_size, FTARG_SIZE, NULL, symlink_crc_flds }, - { FLDT_TIME, "time", fp_time, NULL, SI(bitsz(int32_t)), FTARG_SIGNED, - NULL, NULL }, + { FLDT_TIME, "time", fp_time, NULL, SI(bitsz(xfs_timestamp_t)), + FTARG_SIGNED, NULL, NULL }, { FLDT_TIMESTAMP, "timestamp", NULL, (char *)timestamp_flds, SI(bitsz(xfs_timestamp_t)), 0, NULL, timestamp_flds }, { FLDT_UINT1, "uint1", fp_num, "%u", SI(1), 0, NULL, NULL }, diff --git a/db/fprint.c b/db/fprint.c index c9d07e1bca7e..feec02c5de99 100644 --- a/db/fprint.c +++ b/db/fprint.c @@ -112,22 +112,22 @@ fp_sarray( return 1; } -/*ARGSUSED*/ int fp_time( - void *obj, - int bit, - int count, - char *fmtstr, - int size, - int arg, - int base, - int array) + void *obj, + int bit, + int count, + char *fmtstr, + int size, + int arg, + int base, + int array) { - int bitpos; - char *c; - int i; - time_t t; + xfs_timestamp_t *ts; + int bitpos; + char *c; + int i; + time_t t; ASSERT(bitoffs(bit) == 0); for (i = 0, bitpos = bit; @@ -135,10 +135,47 @@ fp_time( i++, bitpos += size) { if (array) dbprintf("%d:", i + base); - t = (time_t)getbitval((char *)obj + byteize(bitpos), 0, - sizeof(int32_t) * 8, BVSIGNED); + + ts = obj + byteize(bitpos); + t = (int)be32_to_cpu(ts->t_sec); + c = ctime(&t); dbprintf("%24.24s", c); + + if (i < count - 1) + dbprintf(" "); + } + return 1; +} + +int +fp_nsec( + void *obj, + int bit, + int count, + char *fmtstr, + int size, + int arg, + int base, + int array) +{ + xfs_timestamp_t *ts; + unsigned int nsec; + int bitpos; + int i; + + ASSERT(bitoffs(bit) == 0); + for (i = 0, bitpos = bit; + i < count && !seenint(); + i++, bitpos += size) { + if (array) + dbprintf("%d:", i + base); + + ts = obj + byteize(bitpos); + nsec = (int)be32_to_cpu(ts->t_nsec); + + dbprintf("%u", nsec); + if (i < count - 1) dbprintf(" "); } diff --git a/db/fprint.h b/db/fprint.h index c958dca0ed92..bfeed15ca7c4 100644 --- a/db/fprint.h +++ b/db/fprint.h @@ -15,6 +15,8 @@ extern int fp_sarray(void *obj, int bit, int count, char *fmtstr, int size, int arg, int base, int array); extern int fp_time(void *obj, int bit, int count, char *fmtstr, int size, int arg, int base, int array); +extern int fp_nsec(void *obj, int bit, int count, char *fmtstr, int size, + int arg, int base, int array); extern int fp_uuid(void *obj, int bit, int count, char *fmtstr, int size, int arg, int base, int array); extern int fp_crc(void *obj, int bit, int count, char *fmtstr, int size, diff --git a/db/inode.c b/db/inode.c index f13150c96aa9..cc0e680aadea 100644 --- a/db/inode.c +++ b/db/inode.c @@ -179,10 +179,9 @@ const field_t inode_v3_flds[] = { }; -#define TOFF(f) bitize(offsetof(xfs_timestamp_t, t_ ## f)) const field_t timestamp_flds[] = { - { "sec", FLDT_TIME, OI(TOFF(sec)), C1, 0, TYP_NONE }, - { "nsec", FLDT_NSEC, OI(TOFF(nsec)), C1, 0, TYP_NONE }, + { "sec", FLDT_TIME, OI(0), C1, 0, TYP_NONE }, + { "nsec", FLDT_NSEC, OI(0), C1, 0, TYP_NONE }, { NULL } };