Module Name:    src
Committed By:   martin
Date:           Tue Mar 26 11:23:55 UTC 2019

Modified Files:
        src/sbin/gpt: show.c

Log Message:
When displaying a single partition (gpt show -i ...) display offset
and size in sectors (instead of the totally confusing bytes),
followed by the humanized byte offset/size.

This makes the numbers match the "gpt show" or "gpt show -a"
output.


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/sbin/gpt/show.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/gpt/show.c
diff -u src/sbin/gpt/show.c:1.43 src/sbin/gpt/show.c:1.44
--- src/sbin/gpt/show.c:1.43	Sun Mar 24 13:45:35 2019
+++ src/sbin/gpt/show.c	Tue Mar 26 11:23:55 2019
@@ -33,7 +33,7 @@
 __FBSDID("$FreeBSD: src/sbin/gpt/show.c,v 1.14 2006/06/22 22:22:32 marcel Exp $");
 #endif
 #ifdef __RCSID
-__RCSID("$NetBSD: show.c,v 1.43 2019/03/24 13:45:35 martin Exp $");
+__RCSID("$NetBSD: show.c,v 1.44 2019/03/26 11:23:55 martin Exp $");
 #endif
 
 #include <sys/bootblock.h>
@@ -186,6 +186,24 @@ show(gpt_t gpt, int xshow)
 	return 0;
 }
 
+static void
+gpt_show_sec_num(const char *prompt, int64_t secsize, off_t num)
+{
+#ifdef HN_AUTOSCALE
+	char human_num[5];
+	if (humanize_number(human_num, sizeof(human_num),
+	    (int64_t)num*secsize,
+	    "", HN_AUTOSCALE, HN_NOSPACE|HN_B) < 0)
+		human_num[0] = '\0';
+#endif
+	printf("%s: %" PRIu64, prompt, (uint64_t)num);
+#ifdef HN_AUTOSCALE
+	if (human_num[0] != '\0')
+		printf(" (%s)", human_num);
+#endif
+	printf("\n");
+}
+
 static int
 show_one(gpt_t gpt, unsigned int entry)
 {
@@ -204,8 +222,8 @@ show_one(gpt_t gpt, unsigned int entry)
 	ent = m->map_data;
 
 	printf("Details for index %d:\n", entry);
-	gpt_show_num("Start", (uintmax_t)(m->map_start * gpt->secsz));
-	gpt_show_num("Size", (uintmax_t)(m->map_size * gpt->secsz));
+	gpt_show_sec_num("Start", gpt->secsz, m->map_start);
+	gpt_show_sec_num("Size", gpt->secsz, m->map_size);
 
 	gpt_uuid_snprintf(s1, sizeof(s1), "%s", ent->ent_type);
 	gpt_uuid_snprintf(s2, sizeof(s2), "%d", ent->ent_type);

Reply via email to