diff options
author | 1999-03-01 01:50:45 +0000 | |
---|---|---|
committer | 1999-03-01 01:50:45 +0000 | |
commit | 5362a39544e2e5dbe2eaaa1d1e1e2f38e597cc0e (patch) | |
tree | 6b8e75e42fa03dd114911fc7dfbaa70a6bdaf4b6 | |
parent | typo: .su -> .au (diff) | |
download | wireguard-openbsd-5362a39544e2e5dbe2eaaa1d1e1e2f38e597cc0e.tar.xz wireguard-openbsd-5362a39544e2e5dbe2eaaa1d1e1e2f38e597cc0e.zip |
Change undocumented '-p' flag to '-d' and document. Also document '-v'.
Make 'disklabel -ed' not overwrite your label if you make no changes
in the editor (added a cmplabel function to compare two labels).
-rw-r--r-- | sbin/disklabel/disklabel.8 | 38 | ||||
-rw-r--r-- | sbin/disklabel/disklabel.c | 58 | ||||
-rw-r--r-- | sbin/disklabel/editor.c | 6 |
3 files changed, 77 insertions, 25 deletions
diff --git a/sbin/disklabel/disklabel.8 b/sbin/disklabel/disklabel.8 index 5a946633c97..614dc413f11 100644 --- a/sbin/disklabel/disklabel.8 +++ b/sbin/disklabel/disklabel.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: disklabel.8,v 1.23 1998/12/15 01:20:28 aaron Exp $ +.\" $OpenBSD: disklabel.8,v 1.24 1999/03/01 01:50:45 millert Exp $ .\" $NetBSD: disklabel.8,v 1.9 1995/03/18 14:54:38 cgd Exp $ .\" .\" Copyright (c) 1987, 1988, 1991, 1993 @@ -45,39 +45,46 @@ .Nd read and write disk pack label .Sh SYNOPSIS .Nm disklabel -.Op Fl r .Op Fl n +.Op Fl d Li \&| Fl r .Op Fl t +.Op Fl v .Ar disk .Nm disklabel .Fl w -.Op Fl r .Op Fl n +.Op Fl d Li \&| Fl r +.Op Fl v .Ar disk Ar disktype .Oo Ar packid Oc .Nm disklabel .Fl e -.Op Fl r .Op Fl n +.Op Fl d Li \&| Fl r +.Op Fl v .Ar disk .Nm disklabel .Fl E -.Op Fl r .Op Fl n +.Op Fl d Li \&| Fl r +.Op Fl v .Ar disk .Nm disklabel .Fl R .Op Fl r .Op Fl n +.Op Fl v .Ar disk Ar protofile .Nm disklabel .Op Fl NW .Op Fl n +.Op Fl v .Ar disk .sp .Nm disklabel .Fl B .Op Fl n +.Op Fl v .Oo .Fl b Ar boot1 .Op Fl s Ar boot2 @@ -88,6 +95,7 @@ .Fl w .Fl B .Op Fl n +.Op Fl v .Oo .Fl b Ar boot1 .Op Fl s Ar boot2 @@ -98,6 +106,7 @@ .Fl R .Fl B .Op Fl n +.Op Fl v .Oo .Fl b Ar boot1 .Op Fl s Ar boot2 @@ -134,6 +143,25 @@ These variants are described later. In all cases you can specify .Fl n to operate in no change mode to avoid committing any permanent changes. +The +.Fl v +flag can be used to make +.Nm +be more verbose about what it is doing. +.Pp +When reading or editing a label, you may also specify the +.Fl d +option to use the +.Em default +label. This ignores any existing +.Ox +partitions on the disk. Note that this option will only work for +disks that are capable of reporting their geometry, such as SCSI, +IDE, and ESDI. Also note that the +.Fl d +flag may not be used in conjuction with the +.Fl r +flag. .Pp The first form of the command (read) is used to examine the label on the named disk drive (e.g. sd0 or diff --git a/sbin/disklabel/disklabel.c b/sbin/disklabel/disklabel.c index a24469a0019..4dc40d15064 100644 --- a/sbin/disklabel/disklabel.c +++ b/sbin/disklabel/disklabel.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disklabel.c,v 1.57 1999/01/12 04:48:25 aaron Exp $ */ +/* $OpenBSD: disklabel.c,v 1.58 1999/03/01 01:50:45 millert Exp $ */ /* $NetBSD: disklabel.c,v 1.30 1996/03/14 19:49:24 ghudson Exp $ */ /* @@ -44,7 +44,7 @@ static char copyright[] = #endif /* not lint */ #ifndef lint -static char rcsid[] = "$OpenBSD: disklabel.c,v 1.57 1999/01/12 04:48:25 aaron Exp $"; +static char rcsid[] = "$OpenBSD: disklabel.c,v 1.58 1999/03/01 01:50:45 millert Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -107,7 +107,7 @@ enum { UNSPEC, EDIT, EDITOR, READ, RESTORE, SETWRITEABLE, WRITE, WRITEBOOT } op = UNSPEC; -int pflag; +int dflag; int rflag; int tflag; int nwflag; @@ -135,6 +135,7 @@ char *skip __P((char *)); char *word __P((char *)); int getasciilabel __P((FILE *, struct disklabel *)); int checklabel __P((struct disklabel *)); +int cmplabel __P((struct disklabel *, struct disklabel *)); void setbootflag __P((struct disklabel *)); void usage __P((void)); u_short dkcksum __P((struct disklabel *)); @@ -148,7 +149,7 @@ main(argc, argv) struct disklabel *lp; FILE *t; - while ((ch = getopt(argc, argv, "BENRWb:enprs:tvw")) != -1) + while ((ch = getopt(argc, argv, "BENRWb:denrs:tvw")) != -1) switch (ch) { #if NUMBOOT > 0 case 'B': @@ -163,11 +164,6 @@ main(argc, argv) break; #endif #endif - case 'E': - if (op != UNSPEC) - usage(); - op = EDITOR; - break; case 'N': if (op != UNSPEC) usage(); @@ -185,13 +181,18 @@ main(argc, argv) writeable = 1; op = SETWRITEABLE; break; + case 'd': + ++dflag; + break; case 'e': if (op != UNSPEC) usage(); op = EDIT; break; - case 'p': - ++pflag; + case 'E': + if (op != UNSPEC) + usage(); + op = EDITOR; break; case 'r': ++rflag; @@ -231,7 +232,7 @@ main(argc, argv) op = READ; #endif - if (argc < 1) + if (argc < 1 || (rflag && dflag)) usage(); dkname = argv[0]; @@ -399,7 +400,6 @@ writelabel(f, boot, lp) #endif lp->d_magic = DISKMAGIC; lp->d_magic2 = DISKMAGIC; - lp->d_checksum = 0; lp->d_checksum = dkcksum(lp); if (rflag) { #ifdef DOSLABEL @@ -716,7 +716,7 @@ readlabel(f) } warnx(msg); return(NULL); - } else if (pflag) { + } else if (dflag) { lp = &lab; if (ioctl(f, DIOCGPDINFO, lp) < 0) err(4, "ioctl DIOCGPDINFO"); @@ -1151,6 +1151,12 @@ edit(lp, f) } memset(&label, 0, sizeof(label)); if (getasciilabel(fp, &label)) { + if (cmplabel(lp, &label) == 0) { + puts("No changes."); + fclose(fp); + (void) unlink(tmpfil); + return (0); + } *lp = label; if (writelabel(f, bootarea, lp) == 0) { fclose(fp); @@ -1684,6 +1690,24 @@ setbootflag(lp) } #endif +int +cmplabel(lp1, lp2) + struct disklabel *lp1; + struct disklabel *lp2; +{ + struct disklabel lab1 = *lp1; + struct disklabel lab2 = *lp2; + + /* We don't compare these fields */ + lab1.d_magic = lab2.d_magic; + lab1.d_magic2 = lab2.d_magic2; + lab1.d_checksum = lab2.d_checksum; + lab1.d_bbsize = lab2.d_bbsize; + lab1.d_sbsize = lab2.d_sbsize; + + return (memcmp(&lab1, &lab2, sizeof(struct disklabel))); +} + void usage() { @@ -1699,13 +1723,13 @@ usage() fprintf(stderr, "usage:\n"); fprintf(stderr, - " disklabel [-nv] [-r] [-t] disk%s (read)\n", + " disklabel [-nv] [-r|-d] [-t] disk%s (read)\n", blank); fprintf(stderr, - " disklabel [-nv] [-r] -e disk%s (edit)\n", + " disklabel [-nv] [-r|-d] -e disk%s (edit)\n", blank); fprintf(stderr, - " disklabel [-nv] [-r] -E disk%s (simple editor)\n", + " disklabel [-nv] [-r|-d] -E disk%s (simple editor)\n", blank); fprintf(stderr, " disklabel [-nv] [-r]%s -R disk proto (restore)\n", diff --git a/sbin/disklabel/editor.c b/sbin/disklabel/editor.c index eafd1055fa6..63f96946ad4 100644 --- a/sbin/disklabel/editor.c +++ b/sbin/disklabel/editor.c @@ -1,7 +1,7 @@ -/* $OpenBSD: editor.c,v 1.45 1998/10/11 20:49:17 millert Exp $ */ +/* $OpenBSD: editor.c,v 1.46 1999/03/01 01:50:45 millert Exp $ */ /* - * Copyright (c) 1997-1998 Todd C. Miller <Todd.Miller@courtesan.com> + * Copyright (c) 1997-1999 Todd C. Miller <Todd.Miller@courtesan.com> * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -28,7 +28,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: editor.c,v 1.45 1998/10/11 20:49:17 millert Exp $"; +static char rcsid[] = "$OpenBSD: editor.c,v 1.46 1999/03/01 01:50:45 millert Exp $"; #endif /* not lint */ #include <sys/types.h> |