diff options
author | ae <ae@FreeBSD.org> | 2011-03-08 21:36:42 +0000 |
---|---|---|
committer | ae <ae@FreeBSD.org> | 2011-03-08 21:36:42 +0000 |
commit | 29f710efbb2475e233763401e1ba3322fd9f4d38 (patch) | |
tree | 4855b71e45e2ccf68690c605a4bcfffc91dac0c2 /sbin/geom/class | |
parent | b08ae7587e7200f5b010dfdb2d3c994ade3271b4 (diff) | |
download | FreeBSD-src-29f710efbb2475e233763401e1ba3322fd9f4d38.zip FreeBSD-src-29f710efbb2475e233763401e1ba3322fd9f4d38.tar.gz |
Add -p option to `gpart show` command to show provider's names of
partitions instead of partition's indexes. This may be useful with
GPT partitioning scheme or EBR without GEOM_PART_EBR_COMPAT option.
MFC after: 2 weeks
Diffstat (limited to 'sbin/geom/class')
-rw-r--r-- | sbin/geom/class/part/geom_part.c | 48 | ||||
-rw-r--r-- | sbin/geom/class/part/gpart.8 | 6 |
2 files changed, 40 insertions, 14 deletions
diff --git a/sbin/geom/class/part/geom_part.c b/sbin/geom/class/part/geom_part.c index 2da09cc..a302934 100644 --- a/sbin/geom/class/part/geom_part.c +++ b/sbin/geom/class/part/geom_part.c @@ -83,7 +83,7 @@ static void gpart_bootcode(struct gctl_req *, unsigned int); static void *gpart_bootfile_read(const char *, ssize_t *); static void gpart_issue(struct gctl_req *, unsigned int); static void gpart_show(struct gctl_req *, unsigned int); -static void gpart_show_geom(struct ggeom *, const char *); +static void gpart_show_geom(struct ggeom *, const char *, int); static int gpart_show_hasopt(struct gctl_req *, const char *, const char *); static void gpart_write_partcode(struct ggeom *, int, void *, ssize_t); static void gpart_write_partcode_vtoc8(struct ggeom *, int, void *); @@ -153,8 +153,9 @@ struct g_command PUBSYM(class_commands)[] = { { "show", 0, gpart_show, { { 'l', "show_label", NULL, G_TYPE_BOOL }, { 'r', "show_rawtype", NULL, G_TYPE_BOOL }, + { 'p', "show_providers", NULL, G_TYPE_BOOL }, G_OPT_SENTINEL }, - "[-lr] [geom ...]" + "[-lrp] [geom ...]" }, { "undo", 0, gpart_issue, G_NULL_OPTS, "geom" @@ -543,13 +544,13 @@ done: } static void -gpart_show_geom(struct ggeom *gp, const char *element) +gpart_show_geom(struct ggeom *gp, const char *element, int show_providers) { struct gprovider *pp; const char *s, *scheme; off_t first, last, sector, end; off_t length, secsz; - int idx, wblocks, wname; + int idx, wblocks, wname, wmax; scheme = find_geomcfg(gp, "scheme"); s = find_geomcfg(gp, "first"); @@ -560,7 +561,21 @@ gpart_show_geom(struct ggeom *gp, const char *element) s = find_geomcfg(gp, "state"); if (s != NULL && *s != 'C') s = NULL; - wname = strlen(gp->lg_name); + wmax = strlen(gp->lg_name); + if (show_providers) { + LIST_FOREACH(pp, &gp->lg_provider, lg_provider) { + wname = strlen(pp->lg_name); + if (wname > wmax) + wmax = wname; + } + } else { + /* In some cases width of index can be greater than + * length of provider's name. + */ + if (wblocks > wmax) + wmax = wblocks; + } + wname = wmax; pp = LIST_FIRST(&gp->lg_consumer)->lg_provider; secsz = pp->lg_sectorsize; printf("=>%*jd %*jd %*s %s (%s)%s\n", @@ -594,10 +609,18 @@ gpart_show_geom(struct ggeom *gp, const char *element) (intmax_t)(sector - first), wname, "", fmtsize((sector - first) * secsz)); } - printf(" %*jd %*jd %*d %s %s (%s)\n", - wblocks, (intmax_t)sector, wblocks, (intmax_t)length, - wname, idx, find_provcfg(pp, element), - fmtattrib(pp), fmtsize(pp->lg_mediasize)); + if (show_providers) { + printf(" %*jd %*jd %*s %s %s (%s)\n", + wblocks, (intmax_t)sector, wblocks, + (intmax_t)length, wname, pp->lg_name, + find_provcfg(pp, element), fmtattrib(pp), + fmtsize(pp->lg_mediasize)); + } else + printf(" %*jd %*jd %*d %s %s (%s)\n", + wblocks, (intmax_t)sector, wblocks, + (intmax_t)length, wname, idx, + find_provcfg(pp, element), fmtattrib(pp), + fmtsize(pp->lg_mediasize)); first = end + 1; } if (first <= last) { @@ -630,7 +653,7 @@ gpart_show(struct gctl_req *req, unsigned int fl __unused) struct gclass *classp; struct ggeom *gp; const char *element, *name; - int error, i, nargs; + int error, i, nargs, show_providers; element = NULL; if (gpart_show_hasopt(req, "show_label", element)) @@ -651,19 +674,20 @@ gpart_show(struct gctl_req *req, unsigned int fl __unused) geom_deletetree(&mesh); errx(EXIT_FAILURE, "Class %s not found.", name); } + show_providers = gctl_get_int(req, "show_providers"); nargs = gctl_get_int(req, "nargs"); if (nargs > 0) { for (i = 0; i < nargs; i++) { name = gctl_get_ascii(req, "arg%d", i); gp = find_geom(classp, name); if (gp != NULL) - gpart_show_geom(gp, element); + gpart_show_geom(gp, element, show_providers); else errx(EXIT_FAILURE, "No such geom: %s.", name); } } else { LIST_FOREACH(gp, &classp->lg_geom, lg_geom) { - gpart_show_geom(gp, element); + gpart_show_geom(gp, element, show_providers); } } geom_deletetree(&mesh); diff --git a/sbin/geom/class/part/gpart.8 b/sbin/geom/class/part/gpart.8 index d261135..43adf27 100644 --- a/sbin/geom/class/part/gpart.8 +++ b/sbin/geom/class/part/gpart.8 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd January 28, 2011 +.Dd March 9, 2011 .Dt GPART 8 .Os .Sh NAME @@ -162,7 +162,7 @@ utility: .\" ==== SHOW ==== .Nm .Cm show -.Op Fl lr +.Op Fl lrp .Op Ar geom ... .\" ==== UNDO ==== .Nm @@ -468,6 +468,8 @@ Additional options include: .It Fl l For partition schemes that support partition labels print them instead of partition type. +.It Fl p +Show provider names instead of partition indexes. .It Fl r Show raw partition type instead of symbolic name. .El |