diff options
author | ae <ae@FreeBSD.org> | 2010-11-22 10:08:33 +0000 |
---|---|---|
committer | ae <ae@FreeBSD.org> | 2010-11-22 10:08:33 +0000 |
commit | 0723f36d4d9569b65652e3b5672fc6458828ad16 (patch) | |
tree | 16c5d4d2d0226aa638bb4546a1a03ba51b6666a3 | |
parent | 1ea5ca6b7b7703d74273c5694ee948eab6935204 (diff) | |
download | FreeBSD-src-0723f36d4d9569b65652e3b5672fc6458828ad16.zip FreeBSD-src-0723f36d4d9569b65652e3b5672fc6458828ad16.tar.gz |
Always dump partition labels with `gpart backup`, but `gpart restore`
does restore them only when -l option is specified [1]. Make number of
entries field in backup format optional. Document -l and -r options of
`gpart show` action.
Suggested by: pjd [1]
MFC after: 1 week
-rw-r--r-- | sbin/geom/class/part/geom_part.c | 35 | ||||
-rw-r--r-- | sbin/geom/class/part/gpart.8 | 26 |
2 files changed, 32 insertions, 29 deletions
diff --git a/sbin/geom/class/part/geom_part.c b/sbin/geom/class/part/geom_part.c index 55a95e5..2b56b29 100644 --- a/sbin/geom/class/part/geom_part.c +++ b/sbin/geom/class/part/geom_part.c @@ -100,10 +100,8 @@ struct g_command PUBSYM(class_commands)[] = { G_OPT_SENTINEL }, "[-b start] [-s size] -t type [-i index] [-l label] [-f flags] geom" }, - { "backup", 0, gpart_backup, { - { 'l', "backup_labels", NULL, G_TYPE_BOOL}, - G_OPT_SENTINEL }, - "[-l] geom" + { "backup", 0, gpart_backup, G_NULL_OPTS, + "geom" }, { "bootcode", 0, gpart_bootcode, { { 'b', GPART_PARAM_BOOTCODE, G_VAL_OPTIONAL, G_TYPE_STRING }, @@ -175,9 +173,10 @@ struct g_command PUBSYM(class_commands)[] = { }, { "restore", 0, gpart_restore, { { 'F', "force", NULL, G_TYPE_BOOL }, + { 'l', "restore_labels", NULL, G_TYPE_BOOL }, { 'f', "flags", GPART_FLAGS, G_TYPE_STRING }, G_OPT_SENTINEL }, - "[-F] [-f flags] provider [...]" + "[-lF] [-f flags] provider [...]" }, { "recover", 0, gpart_issue, { { 'f', "flags", GPART_FLAGS, G_TYPE_STRING }, @@ -678,7 +677,7 @@ gpart_backup(struct gctl_req *req, unsigned int fl __unused) const char *s, *scheme; off_t sector, end; off_t length, secsz; - int error, labels, i, windex, wblocks, wtype; + int error, i, windex, wblocks, wtype; if (gctl_get_int(req, "nargs") != 1) errx(EXIT_FAILURE, "Invalid number of arguments."); @@ -696,7 +695,6 @@ gpart_backup(struct gctl_req *req, unsigned int fl __unused) s = gctl_get_ascii(req, "arg0"); if (s == NULL) abort(); - labels = gctl_get_int(req, "backup_labels"); gp = find_geom(classp, s); if (gp == NULL) errx(EXIT_FAILURE, "No such geom: %s.", s); @@ -734,14 +732,12 @@ gpart_backup(struct gctl_req *req, unsigned int fl __unused) length = end - sector + 1; } s = find_provcfg(pp, "label"); - printf("%-*s %*s %*jd %*jd", + printf("%-*s %*s %*jd %*jd %s %s\n", windex, find_provcfg(pp, "index"), wtype, find_provcfg(pp, "type"), wblocks, (intmax_t)sector, - wblocks, (intmax_t)length); - if (labels && s != NULL) - printf(" %s", s); - printf(" %s\n", fmtattrib(pp)); + wblocks, (intmax_t)length, + (s != NULL) ? s: "", fmtattrib(pp)); } geom_deletetree(&mesh); } @@ -769,7 +765,7 @@ gpart_restore(struct gctl_req *req, unsigned int fl __unused) struct ggeom *gp; const char *s, *flags, *errstr, *label; char **ap, *argv[6], line[BUFSIZ], *pline; - int error, forced, i, l, nargs, created; + int error, forced, i, l, nargs, created, rl; intmax_t n; nargs = gctl_get_int(req, "nargs"); @@ -778,6 +774,7 @@ gpart_restore(struct gctl_req *req, unsigned int fl __unused) forced = gctl_get_int(req, "force"); flags = gctl_get_ascii(req, "flags"); + rl = gctl_get_int(req, "restore_labels"); s = gctl_get_ascii(req, "class"); if (s == NULL) abort(); @@ -829,19 +826,21 @@ gpart_restore(struct gctl_req *req, unsigned int fl __unused) break; l = ap - &argv[0]; label = pline = NULL; - if (l == 2) { /* create table */ + if (l == 1 || l == 2) { /* create table */ if (created) errx(EXIT_FAILURE, "Incorrect backup format."); - n = atoi(argv[1]); + if (l == 2) + n = strtoimax(argv[1], NULL, 0); for (i = 0; i < nargs; i++) { s = gctl_get_ascii(req, "arg%d", i); r = gctl_get_handle(); - n = strtoimax(argv[1], NULL, 0); gctl_ro_param(r, "class", -1, classp->lg_name); gctl_ro_param(r, "verb", -1, "create"); gctl_ro_param(r, "scheme", -1, argv[0]); - gctl_ro_param(r, "entries", sizeof(n), &n); + if (l == 2) + gctl_ro_param(r, "entries", + sizeof(n), &n); gctl_ro_param(r, "flags", -1, "restore"); gctl_ro_param(r, "arg0", -1, s); errstr = gctl_issue(r); @@ -877,7 +876,7 @@ gpart_restore(struct gctl_req *req, unsigned int fl __unused) gctl_ro_param(r, "type", -1, argv[1]); gctl_ro_param(r, "start", -1, argv[2]); gctl_ro_param(r, "size", -1, argv[3]); - if (label != NULL) + if (rl != 0 && label != NULL) gctl_ro_param(r, "label", -1, argv[4]); gctl_ro_param(r, "arg0", -1, s); error = gpart_autofill(r); diff --git a/sbin/geom/class/part/gpart.8 b/sbin/geom/class/part/gpart.8 index ef303bf..7bea24b 100644 --- a/sbin/geom/class/part/gpart.8 +++ b/sbin/geom/class/part/gpart.8 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd November 20, 2010 +.Dd November 22, 2010 .Dt GPART 8 .Os .Sh NAME @@ -94,7 +94,6 @@ utility: .\" ==== BACKUP ==== .Nm .Cm backup -.Op Fl l .Ar geom .\" ==== BOOTCODE ==== .Nm @@ -149,7 +148,7 @@ utility: .\" ==== RESTORE ==== .Nm .Cm restore -.Op Fl F +.Op Fl lF .Op Fl f Ar flags .Ar provider .Op Ar ... @@ -163,6 +162,7 @@ utility: .\" ==== SHOW ==== .Nm .Cm show +.Op Fl lr .Op Ar geom ... .\" ==== UNDO ==== .Nm @@ -225,12 +225,6 @@ about its use. Dump a partition table to standard output in special format used by .Cm restore action. -.Pp -Additional options include: -.Bl -tag -width 10n -.It Fl l -Dump partition labels for partitioning schemes that support them. -.El .\" ==== BOOTCODE ==== .It Cm bootcode Embed bootstrap code into the partitioning scheme's metadata on the @@ -439,6 +433,8 @@ Additional options include: Destroy partition table on the given .Ar provider before doing restore. +.It Fl l +Restore partition labels for partitioning schemes that support them. .It Fl f Ar flags Additional operational flags. See the section entitled @@ -466,6 +462,14 @@ about its use. .It Cm show Show the current partition information of the specified geoms or all geoms if none are specified. +Additional options include: +.Bl -tag -width 10n +.It Fl l +For partition schemes that support partition labels print them +instead of partition type. +.It Fl r +Show raw partition type instead of symbolic name. +.El .\" ==== UNDO ==== .It Cm undo Revert any pending changes for geom @@ -819,13 +823,13 @@ After having created all required partitions, embed bootstrap code into them. Create backup of partition table from .Pa da0 .Bd -literal -offset indent -/sbin/gpart backup -l da0 > da0.backup +/sbin/gpart backup da0 > da0.backup .Ed .Pp Restore partition table from backup to .Pa da0 .Bd -literal -offset indent -/sbin/gpart restore da0 < /mnt/da0.backup +/sbin/gpart restore -l da0 < /mnt/da0.backup .Ed .Pp Clone partition table from |