summaryrefslogtreecommitdiffstats
path: root/sbin/geom
diff options
context:
space:
mode:
authormarcel <marcel@FreeBSD.org>2008-06-13 00:04:10 +0000
committermarcel <marcel@FreeBSD.org>2008-06-13 00:04:10 +0000
commit94a61263f938428d2e1f7a0763797c136a20bfdf (patch)
tree580c63b061591f93c55ad59c63db8847dbbfbaa6 /sbin/geom
parentb1b1537c3d474d5b29f0cb82e3fb84a6ba0e798f (diff)
downloadFreeBSD-src-94a61263f938428d2e1f7a0763797c136a20bfdf.zip
FreeBSD-src-94a61263f938428d2e1f7a0763797c136a20bfdf.tar.gz
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.
Diffstat (limited to 'sbin/geom')
-rw-r--r--sbin/geom/class/part/geom_part.c38
1 files changed, 32 insertions, 6 deletions
diff --git a/sbin/geom/class/part/geom_part.c b/sbin/geom/class/part/geom_part.c
index 58dbc3c..87be834 100644
--- a/sbin/geom/class/part/geom_part.c
+++ b/sbin/geom/class/part/geom_part.c
@@ -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);
OpenPOWER on IntegriCloud