Skip to content

Commit

Permalink
Add -p option to gpart show command to show provider's names of
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bu7cher committed Mar 8, 2011
1 parent b08ae75 commit 29f710e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 14 deletions.
48 changes: 36 additions & 12 deletions sbin/geom/class/part/geom_part.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -543,13 +544,13 @@ gpart_autofill(struct gctl_req *req)
}

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");
Expand All @@ -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",
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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))
Expand All @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions sbin/geom/class/part/gpart.8
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd January 28, 2011
.Dd March 9, 2011
.Dt GPART 8
.Os
.Sh NAME
Expand Down Expand Up @@ -162,7 +162,7 @@ utility:
.\" ==== SHOW ====
.Nm
.Cm show
.Op Fl lr
.Op Fl lrp
.Op Ar geom ...
.\" ==== UNDO ====
.Nm
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 29f710e

Please sign in to comment.