Make the "show" subcommand accept -b startsec to identify a partition

(very usefull for scripts and other robotic callers).
This commit is contained in:
martin 2019-03-24 13:45:35 +00:00
parent 2ebf5b677a
commit 2ee402b3d0
2 changed files with 25 additions and 5 deletions

View File

@ -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 .\" Copyright (c) 2002 Marcel Moolenaar
.\" All rights reserved. .\" All rights reserved.
@ -466,7 +466,7 @@ See above for a description of these options.
Partitions are removed by clearing the partition type. Partitions are removed by clearing the partition type.
No other information is changed. No other information is changed.
.\" ==== resize ==== .\" ==== 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 Oo Fl s Ar size Oc
The The
.Ic resize .Ic resize
@ -592,7 +592,7 @@ They may be used by
.Nx .Nx
in the future. in the future.
.\" ==== show ==== .\" ==== 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 The
.Ic show .Ic show
command displays the current partitioning on the listed devices and gives 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. user friendly form.
With the With the
.Fl i .Fl i
or the
.Fl b
option, all the details of a particular GPT partition will be displayed. option, all the details of a particular GPT partition will be displayed.
The format of this display is subject to change. The format of this display is subject to change.
With the With the

View File

@ -33,7 +33,7 @@
__FBSDID("$FreeBSD: src/sbin/gpt/show.c,v 1.14 2006/06/22 22:22:32 marcel Exp $"); __FBSDID("$FreeBSD: src/sbin/gpt/show.c,v 1.14 2006/06/22 22:22:32 marcel Exp $");
#endif #endif
#ifdef __RCSID #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 #endif
#include <sys/bootblock.h> #include <sys/bootblock.h>
@ -317,8 +317,10 @@ cmd_show(gpt_t gpt, int argc, char *argv[])
int ch; int ch;
int xshow = 0; int xshow = 0;
unsigned int entry = 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) { switch(ch) {
case 'a': case 'a':
xshow |= SHOW_ALL; xshow |= SHOW_ALL;
@ -330,6 +332,10 @@ cmd_show(gpt_t gpt, int argc, char *argv[])
if (gpt_uint_get(gpt, &entry) == -1) if (gpt_uint_get(gpt, &entry) == -1)
return usage(); return usage();
break; break;
case 'b':
if (gpt_human_get(gpt, &start) == -1)
return usage();
break;
case 'l': case 'l':
xshow |= SHOW_LABEL; xshow |= SHOW_LABEL;
break; break;
@ -350,5 +356,17 @@ cmd_show(gpt_t gpt, int argc, char *argv[])
if (xshow & SHOW_ALL) if (xshow & SHOW_ALL)
return show_all(gpt); 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); return entry > 0 ? show_one(gpt, entry) : show(gpt, xshow);
} }