aboutsummaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorMarcel Moolenaar <marcel@FreeBSD.org>2008-06-13 00:04:10 +0000
committerMarcel Moolenaar <marcel@FreeBSD.org>2008-06-13 00:04:10 +0000
commit5a96f8396d4a58be9ddcbda01dfb848ec08a874d (patch)
tree580c63b061591f93c55ad59c63db8847dbbfbaa6 /sbin
parent98fbfcd632344551e7a44a56448703b1274f540d (diff)
downloadsrc-5a96f8396d4a58be9ddcbda01dfb848ec08a874d.tar.gz
src-5a96f8396d4a58be9ddcbda01dfb848ec08a874d.zip
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.
Notes
Notes: svn path=/head/; revision=179769
Diffstat (limited to 'sbin')
-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 58dbc3c1c07a..87be834da809 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);