]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_db: report bigtime format timestamps
authorDarrick J. Wong <darrick.wong@oracle.com>
Fri, 20 Nov 2020 22:03:28 +0000 (17:03 -0500)
committerEric Sandeen <sandeen@sandeen.net>
Fri, 20 Nov 2020 22:03:28 +0000 (17:03 -0500)
Report the large format timestamps in a human-readable manner if it is
possible to do so without loss of information.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
db/fprint.c
db/inode.c
db/sb.c

index 72ed55fb5874dc29f4b474725790e0036ea5828d..65accfda3fe41b36d6a48506f74d2a156c0e0bf8 100644 (file)
@@ -112,6 +112,35 @@ fp_sarray(
        return 1;
 }
 
+static void
+fp_time64(
+       time64_t                sec)
+{
+       time_t                  tt = sec;
+       time64_t                tt_sec = tt;
+       char                    *c;
+
+       /*
+        * Stupid time_t shenanigans -- POSIX.1-2017 only requires that this
+        * type represent a time in seconds.  Since we have no idea if our
+        * time64_t filesystem timestamps can actually be represented by the C
+        * library, we resort to converting the input value from time64_t to
+        * time_t and back to time64_t to check for information loss.  If so,
+        * we print the raw value; otherwise we print a human-readable value.
+        */
+       if (tt_sec != sec)
+               goto raw;
+
+       c = ctime(&tt);
+       if (!c)
+               goto raw;
+
+       dbprintf("%24.24s", c);
+       return;
+raw:
+       dbprintf("%lld", sec);
+}
+
 int
 fp_time(
        void                    *obj,
@@ -138,7 +167,7 @@ fp_time(
                ts = obj + byteize(bitpos);
                tv = libxfs_inode_from_disk_ts(obj, *ts);
 
-               dbprintf("%24.24s", tv.tv_sec);
+               fp_time64(tv.tv_sec);
 
                if (i < count - 1)
                        dbprintf(" ");
@@ -191,7 +220,8 @@ fp_qtimer(
        int                     base,
        int                     array)
 {
-       uint32_t                sec;
+       struct xfs_disk_dquot   *ddq = obj;
+       time64_t                sec;
        __be32                  *t;
        int                     bitpos;
        int                     i;
@@ -204,9 +234,16 @@ fp_qtimer(
                        dbprintf("%d:", i + base);
 
                t = obj + byteize(bitpos);
-               sec = be32_to_cpu(*t);
+               sec = libxfs_dquot_from_disk_ts(ddq, *t);
 
-               dbprintf("%u", sec);
+               /*
+                * Display the raw value if it's the default grace expiration
+                * period (root dquot) or if the quota has not expired.
+                */
+               if (ddq->d_id == 0 || sec == 0)
+                       dbprintf("%lld", sec);
+               else
+                       fp_time64(sec);
 
                if (i < count - 1)
                        dbprintf(" ");
index a75667d66f13c0e4ab18738d606cf0b3567cc9b1..3453c08907ee59fcc4fc2b5c8b7364709867e489 100644 (file)
@@ -175,10 +175,12 @@ const field_t     inode_v3_flds[] = {
        { "dax", FLDT_UINT1,
          OI(COFF(flags2) + bitsz(uint64_t) - XFS_DIFLAG2_DAX_BIT - 1), C1,
          0, TYP_NONE },
+       { "bigtime", FLDT_UINT1,
+         OI(COFF(flags2) + bitsz(uint64_t) - XFS_DIFLAG2_BIGTIME_BIT - 1), C1,
+         0, TYP_NONE },
        { NULL }
 };
 
-
 const field_t  timestamp_flds[] = {
        { "sec", FLDT_TIME, OI(0), C1, 0, TYP_NONE },
        { "nsec", FLDT_NSEC, OI(0), C1, 0, TYP_NONE },
diff --git a/db/sb.c b/db/sb.c
index e3b1fe0b2e6ecee28dfe35f12bdf83d919273644..d09f653dcedf4979722830664974a9ac20ca9abc 100644 (file)
--- a/db/sb.c
+++ b/db/sb.c
@@ -689,6 +689,8 @@ version_string(
                strcat(s, ",REFLINK");
        if (xfs_sb_version_hasinobtcounts(sbp))
                strcat(s, ",INOBTCNT");
+       if (xfs_sb_version_hasbigtime(sbp))
+               strcat(s, ",BIGTIME");
        return s;
 }