Blame SOURCES/0157-util-Pretty-print-terabytes.patch

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