summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkrw <krw@openbsd.org>2014-05-05 16:33:34 +0000
committerkrw <krw@openbsd.org>2014-05-05 16:33:34 +0000
commit038e2c8c4c6e84ba24f0eb4a219bbd5ac61e0ba6 (patch)
tree946cabdf62597465f92ae132e32c5cac585ca702
parentwork-around the same location being reinstalled thru a different path (diff)
downloadwireguard-openbsd-038e2c8c4c6e84ba24f0eb4a219bbd5ac61e0ba6.tar.xz
wireguard-openbsd-038e2c8c4c6e84ba24f0eb4a219bbd5ac61e0ba6.zip
Enhance reading of saved ascii labels (-R) to process mountpoint
information if present. Can be used with -F/-f options to create an fstab from the saved label. ok otto@
-rw-r--r--sbin/disklabel/disklabel.89
-rw-r--r--sbin/disklabel/disklabel.c47
2 files changed, 46 insertions, 10 deletions
diff --git a/sbin/disklabel/disklabel.8 b/sbin/disklabel/disklabel.8
index 85c87b4c828..ce80cccbe8d 100644
--- a/sbin/disklabel/disklabel.8
+++ b/sbin/disklabel/disklabel.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: disklabel.8,v 1.108 2013/08/14 08:39:30 jmc Exp $
+.\" $OpenBSD: disklabel.8,v 1.109 2014/05/05 16:33:34 krw Exp $
.\" $NetBSD: disklabel.8,v 1.9 1995/03/18 14:54:38 cgd Exp $
.\"
.\" Copyright (c) 1987, 1988, 1991, 1993
@@ -33,7 +33,7 @@
.\"
.\" @(#)disklabel.8 8.2 (Berkeley) 4/19/94
.\"
-.Dd $Mdocdate: August 14 2013 $
+.Dd $Mdocdate: May 5 2014 $
.Dt DISKLABEL 8
.Os
.Sh NAME
@@ -61,6 +61,7 @@
.Nm disklabel
.Fl R
.Op Fl nv
+.Op Fl F Ns | Ns Fl f Ar file
.Ar disk Ar protofile
.Pp
.Nm disklabel
@@ -79,6 +80,7 @@
.Fl BR
.Op Fl nv
.Op Fl b Ar boot1
+.Op Fl F Ns | Ns Fl f Ar file
.Ar disk Ar protofile
.Op Ar disktype
.Sh DESCRIPTION
@@ -158,9 +160,10 @@ The entries will be written using disklabel UIDs.
The
.Fl F
flag is only valid when used in conjunction with the
+.Fl A ,
.Fl E
or
-.Fl A
+.Fl R
flags.
If
.Ar file
diff --git a/sbin/disklabel/disklabel.c b/sbin/disklabel/disklabel.c
index a567876d0e8..e3daa538332 100644
--- a/sbin/disklabel/disklabel.c
+++ b/sbin/disklabel/disklabel.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disklabel.c,v 1.194 2014/04/23 11:49:25 otto Exp $ */
+/* $OpenBSD: disklabel.c,v 1.195 2014/05/05 16:33:34 krw Exp $ */
/*
* Copyright (c) 1987, 1993
@@ -210,7 +210,8 @@ main(int argc, char *argv[])
op = READ;
#endif
- if (argc < 1 || (fstabfile && !(op == EDITOR || aflag)))
+ if (argc < 1 || (fstabfile && !(op == EDITOR || op == RESTORE ||
+ aflag)))
usage();
dkname = argv[0];
@@ -256,8 +257,14 @@ main(int argc, char *argv[])
err(4, "%s", argv[1]);
error = getasciilabel(t, lp);
bzero(lp->d_uid, sizeof(lp->d_uid));
- if (error == 0)
+ if (error == 0) {
error = writelabel(f, bootarea, lp);
+ if (error == 0) {
+ if (ioctl(f, DIOCGDINFO, &lab) < 0)
+ err(4, "ioctl DIOCGDINFO");
+ mpsave(&lab);
+ }
+ }
fclose(t);
break;
case WRITE:
@@ -1008,18 +1015,37 @@ getasciilabel(FILE *f, struct disklabel *lp)
char **cpp, *cp;
const char *errstr;
struct partition *pp;
- char *tp, *s, line[BUFSIZ];
+ char *mp, *tp, *s, line[BUFSIZ];
+ char **omountpoints = NULL;
int lineno = 0, errors = 0;
u_int32_t v, fsize;
u_int64_t lv;
+ unsigned int part;
lp->d_version = 1;
lp->d_bbsize = BBSIZE; /* XXX */
lp->d_sbsize = SBSIZE; /* XXX */
+
+ if (!(omountpoints = calloc(MAXPARTITIONS, sizeof(char *))))
+ errx(4, "out of memory");
+
+ mpcopy(omountpoints, mountpoints);
+ for (part = 0; part < MAXPARTITIONS; part++) {
+ free(mountpoints[part]);
+ mountpoints[part] = NULL;
+ }
+
while (fgets(line, sizeof(line), f)) {
lineno++;
- if ((cp = strpbrk(line, "#\r\n")))
+ mp = NULL;
+ if ((cp = strpbrk(line, "\r\n")))
+ *cp = '\0';
+ if ((cp = strpbrk(line, "#"))) {
*cp = '\0';
+ mp = skip(cp+1);
+ if (mp && *mp != '/')
+ mp = NULL;
+ }
cp = skip(line);
if (cp == NULL)
continue;
@@ -1250,6 +1276,8 @@ getasciilabel(FILE *f, struct disklabel *lp)
default:
break;
}
+ if (mp)
+ mountpoints[part] = strdup(mp);
continue;
}
warnx("line %d: unknown field: %s", lineno, cp);
@@ -1258,6 +1286,11 @@ getasciilabel(FILE *f, struct disklabel *lp)
;
}
errors += checklabel(lp);
+
+ if (errors > 0)
+ mpcopy(mountpoints, omountpoints);
+ mpfree(omountpoints);
+
return (errors > 0);
}
@@ -1443,7 +1476,7 @@ usage(void)
" disklabel -E [-Acdnv] [-F|-f file] disk\t\t(simple editor)"
"\n");
fprintf(stderr,
- " disklabel -R [-nv] disk protofile\t\t(restore)\n\n");
+ " disklabel -R [-nv] [-F|-f file] disk protofile\t\t(restore)\n\n");
#if NUMBOOT > 0
fprintf(stderr,
" disklabel -B [-nv] [-b boot1] disk [disktype]\t\t(boot)\n");
@@ -1451,7 +1484,7 @@ usage(void)
" disklabel -Bw [-nv] [-b boot1] disk disktype [packid]\t"
"(boot+write)\n");
fprintf(stderr,
- " disklabel -BR [-nv] [-b boot1] disk protofile\t\t"
+ " disklabel -BR [-nv] [-F|-f file ] [-b boot1] disk protofile\t\t"
"(boot+restore)\n\n");
#endif
fprintf(stderr,