summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2011-04-16 11:44:42 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2011-04-16 11:44:42 +0000
commitd1c3acc006eee5f6b9d7c68915583fcf0330a65b (patch)
tree0ba78afde6b3a316b6ac9d988f9e0a606ad5b9f5 /sbin
parent39dbe65589e6038eed99aff70e371e9995e7cea0 (diff)
Add '-F'. Same as '-f' but uses DUIDs when writing the mount point
information to the specified file. After every label write, read the label to get current UID info. Some internal code cleanup with no intended functional change. ok deraadt@
Diffstat (limited to 'sbin')
-rw-r--r--sbin/disklabel/disklabel.814
-rw-r--r--sbin/disklabel/disklabel.c20
-rw-r--r--sbin/disklabel/editor.c113
-rw-r--r--sbin/disklabel/extern.h7
4 files changed, 89 insertions, 65 deletions
diff --git a/sbin/disklabel/disklabel.8 b/sbin/disklabel/disklabel.8
index 2559c278287..1d8684ae5e1 100644
--- a/sbin/disklabel/disklabel.8
+++ b/sbin/disklabel/disklabel.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: disklabel.8,v 1.94 2010/09/23 17:16:01 jmc Exp $
+.\" $OpenBSD: disklabel.8,v 1.95 2011/04/16 11:44:41 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: September 23 2010 $
+.Dd $Mdocdate: April 16 2011 $
.Dt DISKLABEL 8
.Os
.Sh NAME
@@ -60,7 +60,7 @@
.Fl E
.Op Fl c | d
.Op Fl Anv
-.Op Fl f Ar tempfile
+.Op Fl f | F Ar tempfile
.Ar disk
.Nm disklabel
.Fl R
@@ -172,10 +172,16 @@ The
.Fl f
flag is only valid when used in conjunction with the
.Fl E
-flag.
+or
+.Fl A
+flags.
If
.Ar tempfile
already exists, it will be overwritten.
+.It Fl F Ar tempfile
+The same as
+.Fl f
+except that UIDs are written instead of disk device names.
.It Fl h
Print partition sizes in human readable format.
.It Fl N
diff --git a/sbin/disklabel/disklabel.c b/sbin/disklabel/disklabel.c
index 6325350fe6a..b3bc9a965a1 100644
--- a/sbin/disklabel/disklabel.c
+++ b/sbin/disklabel/disklabel.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disklabel.c,v 1.175 2010/12/13 01:01:41 marco Exp $ */
+/* $OpenBSD: disklabel.c,v 1.176 2011/04/16 11:44:41 krw Exp $ */
/*
* Copyright (c) 1987, 1993
@@ -99,6 +99,7 @@ int aflag;
int cflag;
int dflag;
int tflag;
+int uidflag;
int verbose;
int donothing;
char print_unit;
@@ -123,7 +124,7 @@ main(int argc, char *argv[])
struct disklabel *lp;
FILE *t;
- while ((ch = getopt(argc, argv, "ABEf:hNRWb:cdenp:s:tvw")) != -1)
+ while ((ch = getopt(argc, argv, "ABEf:F:hNRWb:cdenp:s:tvw")) != -1)
switch (ch) {
case 'A':
++aflag;
@@ -171,6 +172,11 @@ main(int argc, char *argv[])
break;
case 'f':
fstabfile = optarg;
+ uidflag = 0;
+ break;
+ case 'F':
+ fstabfile = optarg;
+ ++uidflag;
break;
case 'h':
print_unit = '*';
@@ -237,7 +243,7 @@ main(int argc, char *argv[])
if (argc != 1)
usage();
readlabel(f);
- error = editor(&lab, f);
+ error = editor(f);
break;
case READ:
if (argc != 1)
@@ -430,8 +436,12 @@ writelabel(int f, char *boot, struct disklabel *lp)
}
#endif
/* Finally, write out any mount point information. */
- if (!donothing)
+ if (!donothing) {
+ /* First refresh our copy of the current label to get UID. */
+ if (ioctl(f, DIOCGDINFO, &lab) < 0)
+ err(4, "ioctl DIOCGDINFO");
mpsave(lp);
+ }
return (0);
}
@@ -1473,7 +1483,7 @@ usage(void)
fprintf(stderr,
" disklabel -e [-c | -d] [-Anv] disk\t\t\t(edit)\n");
fprintf(stderr,
- " disklabel -E [-c | -d] [-Anv] [-f tempfile] disk\t\t(simple editor)\n");
+ " disklabel -E [-c | -d] [-Anv] [-f | -F tempfile] disk\t(simple editor)\n");
fprintf(stderr,
" disklabel -R [-nv] disk protofile\t\t\t(restore)\n");
fprintf(stderr,
diff --git a/sbin/disklabel/editor.c b/sbin/disklabel/editor.c
index 04b96829101..eb3bd1b357b 100644
--- a/sbin/disklabel/editor.c
+++ b/sbin/disklabel/editor.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: editor.c,v 1.250 2011/03/05 06:50:41 krw Exp $ */
+/* $OpenBSD: editor.c,v 1.251 2011/04/16 11:44:41 krw Exp $ */
/*
* Copyright (c) 1997-2000 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -157,9 +157,9 @@ static int overlap;
* Simple partition editor.
*/
int
-editor(struct disklabel *lp, int f)
+editor(int f)
{
- struct disklabel origlabel, lastlabel, tmplabel, label = *lp;
+ struct disklabel origlabel, lastlabel, tmplabel, newlab = lab;
struct disklabel *disk_geop = NULL;
struct partition *pp;
FILE *fp;
@@ -175,32 +175,32 @@ editor(struct disklabel *lp, int f)
errx(4, "out of memory");
/* Don't allow disk type of "unknown" */
- getdisktype(&label, "You need to specify a type for this disk.", specname);
+ getdisktype(&newlab, "You need to specify a type for this disk.", specname);
/* Get the on-disk geometries if possible */
get_geometry(f, &disk_geop);
/* How big is the OpenBSD portion of the disk? */
- find_bounds(&label);
+ find_bounds(&newlab);
/* Make sure there is no partition overlap. */
- if (has_overlap(&label))
+ if (has_overlap(&newlab))
errx(1, "can't run when there is partition overlap.");
/* If we don't have a 'c' partition, create one. */
- pp = &label.d_partitions[RAW_PART];
- if (label.d_npartitions < 3 || DL_GETPSIZE(pp) == 0) {
+ pp = &newlab.d_partitions[RAW_PART];
+ if (newlab.d_npartitions < 3 || DL_GETPSIZE(pp) == 0) {
puts("No 'c' partition found, adding one that spans the disk.");
- if (label.d_npartitions < 3)
- label.d_npartitions = 3;
+ if (newlab.d_npartitions < 3)
+ newlab.d_npartitions = 3;
DL_SETPOFFSET(pp, 0);
- DL_SETPSIZE(pp, DL_GETDSIZE(&label));
+ DL_SETPSIZE(pp, DL_GETDSIZE(&newlab));
pp->p_fstype = FS_UNUSED;
pp->p_fragblock = pp->p_cpg = 0;
}
#ifdef SUN_CYLCHECK
- if (label.d_flags & D_VENDOR) {
+ if (newlab.d_flags & D_VENDOR) {
puts("This platform requires that partition offsets/sizes "
"be on cylinder boundaries.\n"
"Partition offsets/sizes will be rounded to the "
@@ -209,15 +209,15 @@ editor(struct disklabel *lp, int f)
#endif
/* Set d_bbsize and d_sbsize as necessary */
- if (label.d_bbsize == 0)
- label.d_bbsize = BBSIZE;
- if (label.d_sbsize == 0)
- label.d_sbsize = SBSIZE;
+ if (newlab.d_bbsize == 0)
+ newlab.d_bbsize = BBSIZE;
+ if (newlab.d_sbsize == 0)
+ newlab.d_sbsize = SBSIZE;
/* Save the (U|u)ndo labels and mountpoints. */
mpcopy(origmountpoints, mountpoints);
- origlabel = label;
- lastlabel = label;
+ origlabel = newlab;
+ lastlabel = newlab;
puts("Label editor (enter '?' for help at any prompt)");
for (;;) {
@@ -237,7 +237,7 @@ editor(struct disklabel *lp, int f)
* changes but decides not to.
*/
tmplabel = lastlabel;
- lastlabel = label;
+ lastlabel = newlab;
mpcopy(tmpmountpoints, omountpoints);
mpcopy(omountpoints, mountpoints);
}
@@ -249,26 +249,26 @@ editor(struct disklabel *lp, int f)
break;
case 'A':
- if (ioctl(f, DIOCGPDINFO, &label) == 0) {
+ if (ioctl(f, DIOCGPDINFO, &newlab) == 0) {
aflag = 1;
- editor_allocspace(&label);
+ editor_allocspace(&newlab);
} else
- label = lastlabel;
+ newlab = lastlabel;
break;
case 'a':
- editor_add(&label, arg);
+ editor_add(&newlab, arg);
break;
case 'b':
- set_bounds(&label);
+ set_bounds(&newlab);
break;
case 'c':
- editor_change(&label, arg);
+ editor_change(&newlab, arg);
break;
case 'D':
- if (ioctl(f, DIOCGPDINFO, &label) == 0) {
+ if (ioctl(f, DIOCGPDINFO, &newlab) == 0) {
dflag = 1;
for (i=0; i<MAXPARTITIONS; i++) {
free(mountpoints[i]);
@@ -279,23 +279,23 @@ editor(struct disklabel *lp, int f)
break;
case 'd':
- editor_delete(&label, arg);
+ editor_delete(&newlab, arg);
break;
case 'e':
- edit_parms(&label);
+ edit_parms(&newlab);
break;
case 'g':
- set_geometry(&label, disk_geop, lp, arg);
+ set_geometry(&newlab, disk_geop, &lab, arg);
break;
case 'i':
- set_duid(&label);
+ set_duid(&newlab);
break;
case 'm':
- editor_modify(&label, arg);
+ editor_modify(&newlab, arg);
break;
case 'n':
@@ -304,15 +304,16 @@ editor(struct disklabel *lp, int f)
"without the -f flag.\n", stderr);
break;
}
- editor_name(&label, arg);
+ editor_name(&newlab, arg);
break;
case 'p':
- display_edit(&label, arg ? *arg : 0, editor_countfree(&label));
+ display_edit(&newlab, arg ? *arg : 0,
+ editor_countfree(&newlab));
break;
case 'l':
- display(stdout, &label, arg ? *arg : 0, 0);
+ display(stdout, &newlab, arg ? *arg : 0, 0);
break;
case 'M': {
@@ -341,8 +342,6 @@ editor(struct disklabel *lp, int f)
puts("In no change mode, not writing label.");
goto done;
}
- /* Save mountpoint info if there is any. */
- mpsave(&label);
/*
* If we haven't changed the original label, and it
@@ -352,8 +351,10 @@ editor(struct disklabel *lp, int f)
* exit without further questions.
*/
if (!dflag && !aflag &&
- memcmp(lp, &label, sizeof(label)) == 0) {
+ memcmp(&lab, &newlab, sizeof(newlab)) == 0) {
puts("No label changes.");
+ /* Save mountpoint info. */
+ mpsave(&newlab);
goto done;
}
do {
@@ -362,8 +363,8 @@ editor(struct disklabel *lp, int f)
"y");
} while (arg && tolower(*arg) != 'y' && tolower(*arg) != 'n');
if (arg && tolower(*arg) == 'y') {
- if (writelabel(f, bootarea, &label) == 0) {
- *lp = label;
+ if (writelabel(f, bootarea, &newlab) == 0) {
+ newlab = lab; /* lab now has UID info */
goto done;
}
warnx("unable to write label");
@@ -375,7 +376,7 @@ editor(struct disklabel *lp, int f)
case 'R':
if (aflag && !overlap)
- editor_resize(&label, arg);
+ editor_resize(&newlab, arg);
else
fputs("Resize only implemented for auto "
"allocated labels\n", stderr);
@@ -385,7 +386,7 @@ editor(struct disklabel *lp, int f)
struct diskchunk *chunks;
int i;
/* Display free space. */
- chunks = free_chunks(&label);
+ chunks = free_chunks(&newlab);
for (i = 0; chunks[i].start != 0 || chunks[i].stop != 0;
i++)
fprintf(stderr, "Free sectors: %16llu - %16llu "
@@ -393,7 +394,7 @@ editor(struct disklabel *lp, int f)
chunks[i].start, chunks[i].stop - 1,
chunks[i].stop - chunks[i].start);
fprintf(stderr, "Total free sectors: %llu.\n",
- editor_countfree(&label));
+ editor_countfree(&newlab));
break;
}
@@ -408,7 +409,7 @@ editor(struct disklabel *lp, int f)
if ((fp = fopen(arg, "w")) == NULL) {
warn("cannot open %s", arg);
} else {
- display(fp, &label, 0, 1);
+ display(fp, &newlab, 0, 1);
(void)fclose(fp);
}
break;
@@ -418,10 +419,10 @@ editor(struct disklabel *lp, int f)
* If we allow 'U' repeatedly, information would be lost. This way
* multiple 'U's followed by 'u' would undo the 'U's.
*/
- if (memcmp(&label, &origlabel, sizeof(label)) ||
+ if (memcmp(&newlab, &origlabel, sizeof(newlab)) ||
!mpequal(mountpoints, origmountpoints)) {
- tmplabel = label;
- label = origlabel;
+ tmplabel = newlab;
+ newlab = origlabel;
lastlabel = tmplabel;
mpcopy(tmpmountpoints, mountpoints);
mpcopy(mountpoints, origmountpoints);
@@ -431,8 +432,8 @@ editor(struct disklabel *lp, int f)
break;
case 'u':
- tmplabel = label;
- label = lastlabel;
+ tmplabel = newlab;
+ newlab = lastlabel;
lastlabel = tmplabel;
mpcopy(tmpmountpoints, mountpoints);
mpcopy(mountpoints, omountpoints);
@@ -447,11 +448,11 @@ editor(struct disklabel *lp, int f)
}
/* Write label to disk. */
- if (writelabel(f, bootarea, &label) != 0)
+ if (writelabel(f, bootarea, &newlab) != 0)
warnx("unable to write label");
else {
dflag = aflag = 0;
- *lp = label;
+ newlab = lab; /* lab now has UID info */
}
break;
@@ -466,7 +467,7 @@ editor(struct disklabel *lp, int f)
break;
case 'z':
- zero_partitions(&label);
+ zero_partitions(&newlab);
break;
case '\n':
@@ -481,7 +482,7 @@ editor(struct disklabel *lp, int f)
* If no changes were made to label or mountpoints, then
* restore undo info.
*/
- if (memcmp(&label, &lastlabel, sizeof(label)) == 0 &&
+ if (memcmp(&newlab, &lastlabel, sizeof(newlab)) == 0 &&
(mpequal(mountpoints, omountpoints))) {
lastlabel = tmplabel;
mpcopy(omountpoints, tmpmountpoints);
@@ -1830,7 +1831,13 @@ mpsave(struct disklabel *lp)
}
/* Convert specname to bdev */
- if (strncmp(_PATH_DEV, specname, sizeof(_PATH_DEV) - 1) == 0 &&
+ if (uidflag) {
+ snprintf(bdev, sizeof(bdev),
+ "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx.%c",
+ lab.d_uid[0], lab.d_uid[1], lab.d_uid[2], lab.d_uid[3],
+ lab.d_uid[4], lab.d_uid[5], lab.d_uid[6], lab.d_uid[7],
+ specname[strlen(specname)-1]);
+ } else if (strncmp(_PATH_DEV, specname, sizeof(_PATH_DEV) - 1) == 0 &&
specname[sizeof(_PATH_DEV) - 1] == 'r') {
snprintf(bdev, sizeof(bdev), "%s%s", _PATH_DEV,
&specname[sizeof(_PATH_DEV)]);
diff --git a/sbin/disklabel/extern.h b/sbin/disklabel/extern.h
index 4880a57b0bf..b1eb77cbb98 100644
--- a/sbin/disklabel/extern.h
+++ b/sbin/disklabel/extern.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: extern.h,v 1.21 2010/11/24 14:15:31 jsing Exp $ */
+/* $OpenBSD: extern.h,v 1.22 2011/04/16 11:44:41 krw Exp $ */
/*
* Copyright (c) 2003 Theo de Raadt <deraadt@openbsd.org>
@@ -29,14 +29,15 @@ int duid_parse(struct disklabel *, char *);
void readlabel(int);
struct disklabel *makebootarea(char *, struct disklabel *, int);
-int editor(struct disklabel *, int);
+int editor(int);
void editor_allocspace(struct disklabel *);
void mpsave(struct disklabel *);
int writelabel(int, char *, struct disklabel *);
extern char bootarea[], *specname, *fstabfile;
extern char *mountpoints[MAXPARTITIONS];
-extern int aflag, dflag;
+extern int aflag, dflag, uidflag;
extern int donothing;
extern int verbose;
extern char print_unit;
+extern struct disklabel lab;