Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin/gpt When displaying a single partition (gpt show -i ......



details:   https://anonhg.NetBSD.org/src/rev/486a85c7bf24
branches:  trunk
changeset: 997782:486a85c7bf24
user:      martin <martin%NetBSD.org@localhost>
date:      Tue Mar 26 11:23:55 2019 +0000

description:
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.

diffstat:

 sbin/gpt/show.c |  24 +++++++++++++++++++++---
 1 files changed, 21 insertions(+), 3 deletions(-)

diffs (48 lines):

diff -r 766ebd896979 -r 486a85c7bf24 sbin/gpt/show.c
--- a/sbin/gpt/show.c   Tue Mar 26 10:10:22 2019 +0000
+++ b/sbin/gpt/show.c   Tue Mar 26 11:23:55 2019 +0000
@@ -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 @@
        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 @@
        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);



Home | Main Index | Thread Index | Old Index