anitazha / rpms / ndctl

Forked from rpms/ndctl a year ago
Clone
e0018b
From e8b5b191a55b7be671abf2c6d5d10db6edd8c1fb Mon Sep 17 00:00:00 2001
e0018b
From: Dan Williams <dan.j.williams@intel.com>
e0018b
Date: Thu, 28 Apr 2022 15:10:16 -0700
e0018b
Subject: [PATCH 157/217] util: Pretty print terabytes
e0018b
e0018b
CXL capacities are such that gigabytes are too small of a unit for
e0018b
displaying capacities. Add terabyte support to the display_size()
e0018b
helper.
e0018b
e0018b
Link: https://lore.kernel.org/r/165118381648.1676208.1686584406206186723.stgit@dwillia2-desk3.amr.corp.intel.com
e0018b
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
e0018b
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
e0018b
---
e0018b
 util/json.c | 15 +++++++++++++--
e0018b
 1 file changed, 13 insertions(+), 2 deletions(-)
e0018b
e0018b
diff --git a/util/json.c b/util/json.c
e0018b
index ebdf8d9..1d5c6bc 100644
e0018b
--- a/util/json.c
e0018b
+++ b/util/json.c
e0018b
@@ -37,11 +37,16 @@ static int display_size(struct json_object *jobj, struct printbuf *pbuf,
e0018b
 
e0018b
 			c = snprintf(buf, sizeof(buf), "\"%ld.%02ld MiB",
e0018b
 					cMiB/100 , cMiB % 100);
e0018b
-		} else {
e0018b
+		} else if (bytes < 2*SZ_1T) {
e0018b
 			long cGiB = (bytes * 200LL / SZ_1G+1) /2;
e0018b
 
e0018b
 			c = snprintf(buf, sizeof(buf), "\"%ld.%02ld GiB",
e0018b
 					cGiB/100 , cGiB % 100);
e0018b
+		} else {
e0018b
+			long cTiB = (bytes * 200LL / SZ_1T+1) /2;
e0018b
+
e0018b
+			c = snprintf(buf, sizeof(buf), "\"%ld.%02ld TiB",
e0018b
+					cTiB/100 , cTiB % 100);
e0018b
 		}
e0018b
 
e0018b
 		/* JEDEC */
e0018b
@@ -50,12 +55,18 @@ static int display_size(struct json_object *jobj, struct printbuf *pbuf,
e0018b
 
e0018b
 			snprintf(buf + c, sizeof(buf) - c, " (%ld.%02ld MB)\"",
e0018b
 					cMB/100, cMB % 100);
e0018b
-		} else {
e0018b
+		} else if (bytes < 2*SZ_1T) {
e0018b
 			long cGB  = (bytes / (1000000000LL/200LL) + 1) / 2;
e0018b
 
e0018b
 			snprintf(buf + c, sizeof(buf) - c, " (%ld.%02ld GB)\"",
e0018b
 					cGB/100 , cGB % 100);
e0018b
+		} else {
e0018b
+			long cTB  = (bytes / (1000000000000LL/200LL) + 1) / 2;
e0018b
+
e0018b
+			snprintf(buf + c, sizeof(buf) - c, " (%ld.%02ld TB)\"",
e0018b
+					cTB/100 , cTB % 100);
e0018b
 		}
e0018b
+
e0018b
 	}
e0018b
 
e0018b
 	return printbuf_memappend(pbuf, buf, strlen(buf));
e0018b
-- 
e0018b
2.27.0
e0018b