Source-Changes-HG archive

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

[src/trunk]: src/sbin/gpt Make the "show" subcommand accept -b startsec to id...



details:   https://anonhg.NetBSD.org/src/rev/a67244e0abaa
branches:  trunk
changeset: 449803:a67244e0abaa
user:      martin <martin%NetBSD.org@localhost>
date:      Sun Mar 24 13:45:35 2019 +0000

description:
Make the "show" subcommand accept -b startsec to identify a partition
(very usefull for scripts and other robotic callers).

diffstat:

 sbin/gpt/gpt.8  |   8 +++++---
 sbin/gpt/show.c |  22 ++++++++++++++++++++--
 2 files changed, 25 insertions(+), 5 deletions(-)

diffs (89 lines):

diff -r f61d1e7f81ff -r a67244e0abaa sbin/gpt/gpt.8
--- a/sbin/gpt/gpt.8    Sun Mar 24 13:31:31 2019 +0000
+++ b/sbin/gpt/gpt.8    Sun Mar 24 13:45:35 2019 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: gpt.8,v 1.64 2019/03/24 13:31:00 martin Exp $
+.\" $NetBSD: gpt.8,v 1.65 2019/03/24 13:45:35 martin Exp $
 .\"
 .\" Copyright (c) 2002 Marcel Moolenaar
 .\" All rights reserved.
@@ -466,7 +466,7 @@
 Partitions are removed by clearing the partition type.
 No other information is changed.
 .\" ==== resize ====
-.It Nm Ic resize [ Fl i Ar index | Fl b Ar startsec ] Oo Fl a Ar alignment Oc \
+.It Nm Ic resize Oo Fl i Ar index Oc Oo Fl b Ar startsec Oc Oo Fl a Ar alignment Oc \
 Oo Fl s Ar size Oc
 The
 .Ic resize
@@ -592,7 +592,7 @@
 .Nx
 in the future.
 .\" ==== show ====
-.It Nm Ic show Oo Fl aglu Oc Oo Fl i Ar index Oc
+.It Nm Ic show Oo Fl aglu Oc Oo Fl i Ar index Oc Oo Fl b Ar startsec Oc
 The
 .Ic show
 command displays the current partitioning on the listed devices and gives
@@ -611,6 +611,8 @@
 user friendly form.
 With the
 .Fl i
+or the
+.Fl b
 option, all the details of a particular GPT partition will be displayed.
 The format of this display is subject to change.
 With the
diff -r f61d1e7f81ff -r a67244e0abaa sbin/gpt/show.c
--- a/sbin/gpt/show.c   Sun Mar 24 13:31:31 2019 +0000
+++ b/sbin/gpt/show.c   Sun Mar 24 13:45:35 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.42 2019/03/03 03:20:42 jnemeth Exp $");
+__RCSID("$NetBSD: show.c,v 1.43 2019/03/24 13:45:35 martin Exp $");
 #endif
 
 #include <sys/bootblock.h>
@@ -317,8 +317,10 @@
        int ch;
        int xshow = 0;
        unsigned int entry = 0;
+       off_t start = 0;
+       map_t m;
 
-       while ((ch = getopt(argc, argv, "gi:lua")) != -1) {
+       while ((ch = getopt(argc, argv, "gi:b:lua")) != -1) {
                switch(ch) {
                case 'a':
                        xshow |= SHOW_ALL;
@@ -330,6 +332,10 @@
                        if (gpt_uint_get(gpt, &entry) == -1)
                                return usage();
                        break;
+               case 'b':
+                       if (gpt_human_get(gpt, &start) == -1)
+                               return usage();
+                       break;
                case 'l':
                        xshow |= SHOW_LABEL;
                        break;
@@ -350,5 +356,17 @@
        if (xshow & SHOW_ALL)
                return show_all(gpt);
 
+       if (start > 0) {
+               for (m = map_first(gpt); m != NULL; m = m->map_next) {
+                       if (m->map_type != MAP_TYPE_GPT_PART ||
+                           m->map_index < 1)
+                               continue;
+                       if (start != m->map_start)
+                               continue;
+                       entry = m->map_index;
+                       break;
+               }
+       }
+
        return entry > 0 ? show_one(gpt, entry) : show(gpt, xshow);
 }



Home | Main Index | Thread Index | Old Index