Source-Changes-HG archive

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

[src/trunk]: src/sbin/gpt Add a -a flag to the show command, so we can displa...



details:   https://anonhg.NetBSD.org/src/rev/e75ba1120df4
branches:  trunk
changeset: 342504:e75ba1120df4
user:      martin <martin%NetBSD.org@localhost>
date:      Fri Dec 25 10:59:56 2015 +0000

description:
Add a -a flag to the show command, so we can display the full GPT with
all information in one go.

diffstat:

 sbin/gpt/gpt.8  |   12 ++-
 sbin/gpt/show.c |  210 +++++++++++++++++++++++++++++++++++++------------------
 2 files changed, 151 insertions(+), 71 deletions(-)

diffs (truncated from 316 to 300 lines):

diff -r 82aa5a7b8982 -r e75ba1120df4 sbin/gpt/gpt.8
--- a/sbin/gpt/gpt.8    Fri Dec 25 08:22:28 2015 +0000
+++ b/sbin/gpt/gpt.8    Fri Dec 25 10:59:56 2015 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: gpt.8,v 1.43 2015/12/06 09:36:57 wiz Exp $
+.\" $NetBSD: gpt.8,v 1.44 2015/12/25 10:59:56 martin Exp $
 .\"
 .\" Copyright (c) 2002 Marcel Moolenaar
 .\" All rights reserved.
@@ -26,7 +26,7 @@
 .\"
 .\" $FreeBSD: src/sbin/gpt/gpt.8,v 1.17 2006/06/22 22:22:32 marcel Exp $
 .\"
-.Dd December 6, 2015
+.Dd December 25, 2015
 .Dt GPT 8
 .Os
 .Sh NAME
@@ -523,7 +523,7 @@
 .Nx
 code in the future.
 .\" ==== show ====
-.It Nm Ic show Oo Fl glu Oc Oo Fl i Ar index Oc
+.It Nm Ic show Oo Fl glu Oc Oo Fl i Ar index Oc Oo Fl a Oc
 The
 .Ic show
 command displays the current partitioning on the listed devices and gives
@@ -544,8 +544,14 @@
 .Fl i
 option, all the details of a particular GPT partition will be displayed.
 The format of this display is subject to change.
+With the
+.Fl a
+option, all information for all GPT partitions (just like with
+.Fl i Ar index )
+will be printed.
 None of the options have any effect on non-GPT partitions.
 The order of precedence for the options are:
+.Fl a ,
 .Fl i ,
 .Fl l ,
 .Fl g ,
diff -r 82aa5a7b8982 -r e75ba1120df4 sbin/gpt/show.c
--- a/sbin/gpt/show.c   Fri Dec 25 08:22:28 2015 +0000
+++ b/sbin/gpt/show.c   Fri Dec 25 10:59:56 2015 +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.31 2015/12/06 00:39:26 christos Exp $");
+__RCSID("$NetBSD: show.c,v 1.32 2015/12/25 10:59:56 martin Exp $");
 #endif
 
 #include <sys/types.h>
@@ -52,12 +52,13 @@
 static int cmd_show(gpt_t, int, char *[]);
 
 static const char *showhelp[] = {
-       "[-glu] [-i index]",
+       "[-glu] [-i index] [-a]",
 };
 
 #define SHOW_UUID  1
 #define SHOW_GUID  2
 #define SHOW_LABEL 4
+#define SHOW_ALL   8
 
 struct gpt_cmd c_show = {
        "show",
@@ -68,17 +69,86 @@
 
 #define usage() gpt_usage(NULL, &c_show)
 
-static int
-show(gpt_t gpt, int show)
+static void
+print_part_type(int map_type, int flags, void *map_data, off_t map_start)
 {
        off_t start;
-       map_t m, p;
+       map_t p;
        struct mbr *mbr;
        struct gpt_ent *ent;
        unsigned int i;
        char buf[128], *b = buf;
        uint8_t utfbuf[__arraycount(ent->ent_name) * 3 + 1];
 
+       switch (map_type) {
+       case MAP_TYPE_UNUSED:
+               printf("Unused");
+               break;
+       case MAP_TYPE_MBR:
+               if (map_start != 0)
+                       printf("Extended ");
+               printf("MBR");
+               break;
+       case MAP_TYPE_PRI_GPT_HDR:
+               printf("Pri GPT header");
+               break;
+       case MAP_TYPE_SEC_GPT_HDR:
+               printf("Sec GPT header");
+               break;
+       case MAP_TYPE_PRI_GPT_TBL:
+               printf("Pri GPT table");
+               break;
+       case MAP_TYPE_SEC_GPT_TBL:
+               printf("Sec GPT table");
+               break;
+       case MAP_TYPE_MBR_PART:
+               p = map_data;
+               if (p->map_start != 0)
+                       printf("Extended ");
+               printf("MBR part ");
+               mbr = p->map_data;
+               for (i = 0; i < 4; i++) {
+                       start = le16toh(mbr->mbr_part[i].part_start_hi);
+                       start = (start << 16) +
+                           le16toh(mbr->mbr_part[i].part_start_lo);
+                       if (map_start == p->map_start + start)
+                               break;
+               }
+               printf("%d", mbr->mbr_part[i].part_typ);
+               break;
+       case MAP_TYPE_GPT_PART:
+               printf("GPT part ");
+               ent = map_data;
+               if (flags & SHOW_LABEL) {
+                       utf16_to_utf8(ent->ent_name, utfbuf,
+                           sizeof(utfbuf));
+                       b = (char *)utfbuf;
+               } else if (flags & SHOW_GUID) {
+                       gpt_uuid_snprintf( buf, sizeof(buf), "%d",
+                           ent->ent_guid);
+               } else if (flags & SHOW_UUID) {
+                       gpt_uuid_snprintf(buf, sizeof(buf),
+                           "%d", ent->ent_type);
+               } else {
+                       gpt_uuid_snprintf(buf, sizeof(buf), "%ls",
+                           ent->ent_type);
+               }
+               printf("- %s", b);
+               break;
+       case MAP_TYPE_PMBR:
+               printf("PMBR");
+               break;
+       default:
+               printf("Unknown %#x", map_type);
+               break;
+       }
+}
+
+static int
+show(gpt_t gpt, int show)
+{
+       map_t m;
+
        printf("  %*s", gpt->lbawidth, "start");
        printf("  %*s", gpt->lbawidth, "size");
        printf("  index  contents\n");
@@ -95,68 +165,7 @@
                        printf("     ");
                putchar(' ');
                putchar(' ');
-               switch (m->map_type) {
-               case MAP_TYPE_UNUSED:
-                       printf("Unused");
-                       break;
-               case MAP_TYPE_MBR:
-                       if (m->map_start != 0)
-                               printf("Extended ");
-                       printf("MBR");
-                       break;
-               case MAP_TYPE_PRI_GPT_HDR:
-                       printf("Pri GPT header");
-                       break;
-               case MAP_TYPE_SEC_GPT_HDR:
-                       printf("Sec GPT header");
-                       break;
-               case MAP_TYPE_PRI_GPT_TBL:
-                       printf("Pri GPT table");
-                       break;
-               case MAP_TYPE_SEC_GPT_TBL:
-                       printf("Sec GPT table");
-                       break;
-               case MAP_TYPE_MBR_PART:
-                       p = m->map_data;
-                       if (p->map_start != 0)
-                               printf("Extended ");
-                       printf("MBR part ");
-                       mbr = p->map_data;
-                       for (i = 0; i < 4; i++) {
-                               start = le16toh(mbr->mbr_part[i].part_start_hi);
-                               start = (start << 16) +
-                                   le16toh(mbr->mbr_part[i].part_start_lo);
-                               if (m->map_start == p->map_start + start)
-                                       break;
-                       }
-                       printf("%d", mbr->mbr_part[i].part_typ);
-                       break;
-               case MAP_TYPE_GPT_PART:
-                       printf("GPT part ");
-                       ent = m->map_data;
-                       if (show & SHOW_LABEL) {
-                               utf16_to_utf8(ent->ent_name, utfbuf,
-                                   sizeof(utfbuf));
-                               b = (char *)utfbuf;
-                       } else if (show & SHOW_GUID) {
-                               gpt_uuid_snprintf( buf, sizeof(buf), "%d",
-                                   ent->ent_guid);
-                       } else if (show & SHOW_UUID) {
-                               gpt_uuid_snprintf(buf, sizeof(buf),
-                                   "%d", ent->ent_type);
-                       } else {
-                               gpt_uuid_snprintf(buf, sizeof(buf), "%ls",
-                                   ent->ent_type);
-                       }
-                       printf("- %s", b);
-                       break;
-               case MAP_TYPE_PMBR:
-                       printf("PMBR");
-                       break;
-               default:
-                       printf("Unknown %#x", m->map_type);
-                       break;
-               }
+               print_part_type(m->map_type, show, m->map_data, m->map_start);
                putchar('\n');
                m = m->map_next;
        }
@@ -208,14 +217,76 @@
 }
 
 static int
+show_all(gpt_t gpt)
+{
+       map_t m;
+       struct gpt_ent *ent;
+       char s1[128], s2[128];
+       uint8_t utfbuf[__arraycount(ent->ent_name) * 3 + 1];
+#define PFX "                                 "
+
+       printf("  %*s", gpt->lbawidth, "start");
+       printf("  %*s", gpt->lbawidth, "size");
+       printf("  index  contents\n");
+
+       m = map_first(gpt);
+       while (m != NULL) {
+               printf("  %*llu", gpt->lbawidth, (long long)m->map_start);
+               printf("  %*llu", gpt->lbawidth, (long long)m->map_size);
+               putchar(' ');
+               putchar(' ');
+               if (m->map_index > 0) {
+                       printf("%5d  ", m->map_index);
+                       print_part_type(m->map_type, 0, m->map_data,
+                           m->map_start);
+                       putchar('\n');
+
+                       ent = m->map_data;
+
+                       gpt_uuid_snprintf(s1, sizeof(s1), "%s", ent->ent_type);
+                       gpt_uuid_snprintf(s2, sizeof(s2), "%d", ent->ent_type);
+                       if (strcmp(s1, s2) == 0)
+                               strlcpy(s1, "unknown", sizeof(s1));
+                       printf(PFX "Type: %s (%s)\n", s1, s2);
+
+                       gpt_uuid_snprintf(s2, sizeof(s1), "%d", ent->ent_guid);
+                       printf(PFX "GUID: %s\n", s2);
+
+                       utf16_to_utf8(ent->ent_name, utfbuf, sizeof(utfbuf));
+                       printf(PFX "Label: %s\n", (char *)utfbuf);
+
+                       printf(PFX "Attributes: ");
+                       if (ent->ent_attr == 0) {
+                               printf("None\n");
+                       } else  {       
+                               char buf[1024];
+
+                               printf("%s\n", gpt_attr_list(buf, sizeof(buf),
+                                   ent->ent_attr));
+                       }
+               } else {
+                       printf("       ");
+                       print_part_type(m->map_type, 0, m->map_data,
+                           m->map_start);
+                       putchar('\n');
+               }
+               m = m->map_next;
+       }
+       return 0;
+}
+
+static int
 cmd_show(gpt_t gpt, int argc, char *argv[])
 {
        int ch;
        int xshow = 0;
        unsigned int entry = 0;
 
-       while ((ch = getopt(argc, argv, "gi:lu")) != -1) {
+       while ((ch = getopt(argc, argv, "gi:lua")) != -1) {



Home | Main Index | Thread Index | Old Index