From 2ee402b3d082da097a6b78e68b4e1a2011e7e837 Mon Sep 17 00:00:00 2001 From: martin Date: Sun, 24 Mar 2019 13:45:35 +0000 Subject: [PATCH] Make the "show" subcommand accept -b startsec to identify a partition (very usefull for scripts and other robotic callers). --- sbin/gpt/gpt.8 | 8 +++++--- sbin/gpt/show.c | 22 ++++++++++++++++++++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/sbin/gpt/gpt.8 b/sbin/gpt/gpt.8 index 31fb743d73be..e5d59a608a24 100644 --- a/sbin/gpt/gpt.8 +++ b/sbin/gpt/gpt.8 @@ -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 @@ See above for a description of these options. 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 @@ They may be used by .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 @@ option the GPT partition type is displayed as an UUID instead of in a 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 --git a/sbin/gpt/show.c b/sbin/gpt/show.c index 28e99936fcce..d52d83d0fcae 100644 --- a/sbin/gpt/show.c +++ b/sbin/gpt/show.c @@ -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 @@ -317,8 +317,10 @@ cmd_show(gpt_t gpt, int argc, char *argv[]) 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 @@ cmd_show(gpt_t gpt, int argc, char *argv[]) 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 @@ cmd_show(gpt_t gpt, int argc, char *argv[]) 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); }