Implement the -l and -r options for gpart show.
The -l option changes the output to show the partition label, if applicable and when present. The -r option changes the output to show the raw (i.e. scheme-specific) partition types.
This commit is contained in:
parent
98fbfcd632
commit
5a96f8396d
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=179769
@ -108,7 +108,12 @@ struct g_command PUBSYM(class_commands)[] = {
|
||||
G_OPT_SENTINEL },
|
||||
"geom", NULL
|
||||
},
|
||||
{ "show", 0, gpart_show, G_NULL_OPTS, NULL, "[geom ...]" },
|
||||
{ "show", 0, gpart_show, {
|
||||
{ 'l', "show_label", NULL, G_TYPE_BOOL },
|
||||
{ 'r', "show_rawtype", NULL, G_TYPE_BOOL },
|
||||
G_OPT_SENTINEL },
|
||||
NULL, "[-lr] [geom ...]"
|
||||
},
|
||||
{ "undo", 0, NULL, G_NULL_OPTS, "geom", NULL },
|
||||
G_CMD_SENTINEL
|
||||
};
|
||||
@ -202,7 +207,7 @@ fmtsize(long double rawsz)
|
||||
}
|
||||
|
||||
static void
|
||||
gpart_show_geom(struct ggeom *gp)
|
||||
gpart_show_geom(struct ggeom *gp, const char *element)
|
||||
{
|
||||
struct gprovider *pp;
|
||||
const char *s, *scheme;
|
||||
@ -242,7 +247,7 @@ gpart_show_geom(struct ggeom *gp)
|
||||
printf(" %*llu %*llu %*d %s (%s)\n",
|
||||
wblocks, sector, wblocks, end - sector,
|
||||
wname, idx,
|
||||
find_provcfg(pp, "type"), fmtsize(pp->lg_mediasize));
|
||||
find_provcfg(pp, element), fmtsize(pp->lg_mediasize));
|
||||
first = end;
|
||||
}
|
||||
if (first <= last) {
|
||||
@ -254,15 +259,36 @@ gpart_show_geom(struct ggeom *gp)
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
static int
|
||||
gpart_show_hasopt(struct gctl_req *req, const char *opt, const char *elt)
|
||||
{
|
||||
|
||||
if (!gctl_get_int(req, opt))
|
||||
return (0);
|
||||
|
||||
if (elt != NULL)
|
||||
errx(EXIT_FAILURE, "-l and -r are mutually exclusive");
|
||||
|
||||
return (1);
|
||||
}
|
||||
|
||||
static void
|
||||
gpart_show(struct gctl_req *req, unsigned int fl __unused)
|
||||
{
|
||||
struct gmesh mesh;
|
||||
struct gclass *classp;
|
||||
struct ggeom *gp;
|
||||
const char *name;
|
||||
const char *element, *name;
|
||||
int error, i, nargs;
|
||||
|
||||
element = NULL;
|
||||
if (gpart_show_hasopt(req, "show_label", element))
|
||||
element = "label";
|
||||
if (gpart_show_hasopt(req, "show_rawtype", element))
|
||||
element = "rawtype";
|
||||
if (element == NULL)
|
||||
element = "type";
|
||||
|
||||
name = gctl_get_ascii(req, "class");
|
||||
if (name == NULL)
|
||||
abort();
|
||||
@ -280,13 +306,13 @@ gpart_show(struct gctl_req *req, unsigned int fl __unused)
|
||||
name = gctl_get_ascii(req, "arg%d", i);
|
||||
gp = find_geom(classp, name);
|
||||
if (gp != NULL)
|
||||
gpart_show_geom(gp);
|
||||
gpart_show_geom(gp, element);
|
||||
else
|
||||
errx(EXIT_FAILURE, "No such geom: %s.", name);
|
||||
}
|
||||
} else {
|
||||
LIST_FOREACH(gp, &classp->lg_geom, lg_geom) {
|
||||
gpart_show_geom(gp);
|
||||
gpart_show_geom(gp, element);
|
||||
}
|
||||
}
|
||||
geom_deletetree(&mesh);
|
||||
|
Loading…
Reference in New Issue
Block a user