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

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