summaryrefslogtreecommitdiff
path: root/sbin/disklabel
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2009-03-28 16:27:25 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2009-03-28 16:27:25 +0000
commit582b4c19db095f3d6bedf1c879707d8499d2b661 (patch)
tree2b22d5d14bb444e2a044767c8cc81919bf8fbe17 /sbin/disklabel
parent3095199658e2d3029559180a61e3418d506d1f96 (diff)
Move some output under the control of the '-v' flag. In particular only
display the partition info by default as is done in the E(ditor). The physical info is now only displayed if '-v' is specified. ok deraadt@
Diffstat (limited to 'sbin/disklabel')
-rw-r--r--sbin/disklabel/disklabel.c123
-rw-r--r--sbin/disklabel/editor.c10
-rw-r--r--sbin/disklabel/extern.h6
3 files changed, 78 insertions, 61 deletions
diff --git a/sbin/disklabel/disklabel.c b/sbin/disklabel/disklabel.c
index 364ad3606d7..f1cc4fd36d3 100644
--- a/sbin/disklabel/disklabel.c
+++ b/sbin/disklabel/disklabel.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disklabel.c,v 1.141 2009/03/28 14:03:42 deraadt Exp $ */
+/* $OpenBSD: disklabel.c,v 1.142 2009/03/28 16:27:24 krw Exp $ */
/*
* Copyright (c) 1987, 1993
@@ -39,7 +39,7 @@ static const char copyright[] =
#endif /* not lint */
#ifndef lint
-static const char rcsid[] = "$OpenBSD: disklabel.c,v 1.141 2009/03/28 14:03:42 deraadt Exp $";
+static const char rcsid[] = "$OpenBSD: disklabel.c,v 1.142 2009/03/28 16:27:24 krw Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -292,7 +292,8 @@ main(int argc, char *argv[])
if (tflag)
makedisktab(stdout, lp);
else
- display(stdout, lp, NULL, print_unit, 1);
+ display(stdout, lp, NULL, print_unit,
+ (verbose ? SHOW_PHYSINFO : 0) | SHOW_PARTINFO);
error = checklabel(lp);
break;
case RESTORE:
@@ -596,20 +597,24 @@ findopenbsd(int f, off_t mbroff, struct dos_partition **first, int *n)
}
switch (dp[part].dp_typ) {
case DOSPTYP_OPENBSD:
- fprintf(stderr, "# Inside MBR partition %d: "
- "type %02X start %u size %u\n",
- part, dp[part].dp_typ,
- letoh32(dp[part].dp_start), letoh32(dp[part].dp_size));
+ if (verbose)
+ fprintf(stderr, "# Inside MBR partition %d: "
+ "type %02X start %u size %u\n",
+ part, dp[part].dp_typ,
+ letoh32(dp[part].dp_start),
+ letoh32(dp[part].dp_size));
bcopy(&dp[part], &res, sizeof(struct dos_partition));
res.dp_start =
htole32((off_t)letoh32(res.dp_start) + mbroff);
return (&res);
case DOSPTYP_EXTEND:
case DOSPTYP_EXTENDL:
- fprintf(stderr, "# Extended partition %d: "
- "type %02X start %u size %u\n",
- part, dp[part].dp_typ,
- letoh32(dp[part].dp_start), letoh32(dp[part].dp_size));
+ if (verbose)
+ fprintf(stderr, "# Extended partition %d: "
+ "type %02X start %u size %u\n",
+ part, dp[part].dp_typ,
+ letoh32(dp[part].dp_start),
+ letoh32(dp[part].dp_size));
start = letoh32(dp[part].dp_start) + mbroff;
p = findopenbsd(f, start, NULL, n);
if (p != NULL)
@@ -1011,63 +1016,69 @@ display_partition(FILE *f, struct disklabel *lp, char **mp, int i,
}
void
-display(FILE *f, struct disklabel *lp, char **mp, char unit, int all)
+display(FILE *f, struct disklabel *lp, char **mp, char unit, int opts)
{
int i, j;
double d;
unit = toupper(unit);
- fprintf(f, "# %s:\n", specname);
- if ((unsigned) lp->d_type < DKMAXTYPES)
- fprintf(f, "type: %s\n", dktypenames[lp->d_type]);
- else
- fprintf(f, "type: %d\n", lp->d_type);
- fprintf(f, "disk: %.*s\n", (int)sizeof(lp->d_typename), lp->d_typename);
- fprintf(f, "label: %.*s\n", (int)sizeof(lp->d_packname), lp->d_packname);
- fprintf(f, "flags:");
- if (lp->d_flags & D_BADSECT)
- fprintf(f, " badsect");
- if (lp->d_flags & D_VENDOR)
- fprintf(f, " vendor");
- putc('\n', f);
-
- fprintf(f, "bytes/sector: %u\n", lp->d_secsize);
- fprintf(f, "sectors/track: %u\n", lp->d_nsectors);
- fprintf(f, "tracks/cylinder: %u\n", lp->d_ntracks);
- fprintf(f, "sectors/cylinder: %u\n", lp->d_secpercyl);
- fprintf(f, "cylinders: %u\n", lp->d_ncylinders);
- d = scale(DL_GETDSIZE(lp), unit, lp);
- if (d < 0)
- fprintf(f, "total sectors: %llu\n", DL_GETDSIZE(lp));
- else
- fprintf(f, "total bytes: %.*f%c\n", unit == 'B' ? 0 : 1,
- d, unit);
-
- fprintf(f, "rpm: %hu\n", lp->d_rpm);
- fprintf(f, "interleave: %hu\n", lp->d_interleave);
- fprintf(f, "trackskew: %hu\n", lp->d_trackskew);
- fprintf(f, "cylinderskew: %hu\n", lp->d_cylskew);
- fprintf(f, "headswitch: %u\t\t# microseconds\n",
- lp->d_headswitch);
- fprintf(f, "track-to-track seek: %u\t# microseconds\n",
- lp->d_trkseek);
- fprintf(f, "drivedata: ");
- for (i = NDDATA - 1; i >= 0; i--)
- if (lp->d_drivedata[i])
- break;
- if (i < 0)
- i = 0;
- for (j = 0; j <= i; j++)
- fprintf(f, "%d ", lp->d_drivedata[j]);
- fprintf(f, "\n");
- if (all) {
+ if (opts & SHOW_PHYSINFO) {
+ fprintf(f, "# %s:\n", specname);
+ if ((unsigned) lp->d_type < DKMAXTYPES)
+ fprintf(f, "type: %s\n", dktypenames[lp->d_type]);
+ else
+ fprintf(f, "type: %d\n", lp->d_type);
+ fprintf(f, "disk: %.*s\n", (int)sizeof(lp->d_typename),
+ lp->d_typename);
+ fprintf(f, "label: %.*s\n", (int)sizeof(lp->d_packname),
+ lp->d_packname);
+ fprintf(f, "flags:");
+ if (lp->d_flags & D_BADSECT)
+ fprintf(f, " badsect");
+ if (lp->d_flags & D_VENDOR)
+ fprintf(f, " vendor");
+ putc('\n', f);
+
+ fprintf(f, "bytes/sector: %u\n", lp->d_secsize);
+ fprintf(f, "sectors/track: %u\n", lp->d_nsectors);
+ fprintf(f, "tracks/cylinder: %u\n", lp->d_ntracks);
+ fprintf(f, "sectors/cylinder: %u\n", lp->d_secpercyl);
+ fprintf(f, "cylinders: %u\n", lp->d_ncylinders);
+ d = scale(DL_GETDSIZE(lp), unit, lp);
+ if (d < 0)
+ fprintf(f, "total sectors: %llu\n", DL_GETDSIZE(lp));
+ else
+ fprintf(f, "total bytes: %.*f%c\n", unit == 'B' ? 0 : 1,
+ d, unit);
+
+ fprintf(f, "rpm: %hu\n", lp->d_rpm);
+ fprintf(f, "interleave: %hu\n", lp->d_interleave);
+ fprintf(f, "trackskew: %hu\n", lp->d_trackskew);
+ fprintf(f, "cylinderskew: %hu\n", lp->d_cylskew);
+ fprintf(f, "headswitch: %u\t\t# microseconds\n",
+ lp->d_headswitch);
+ fprintf(f, "track-to-track seek: %u\t# microseconds\n",
+ lp->d_trkseek);
+ fprintf(f, "drivedata: ");
+ for (i = NDDATA - 1; i >= 0; i--)
+ if (lp->d_drivedata[i])
+ break;
+ if (i < 0)
+ i = 0;
+ for (j = 0; j <= i; j++)
+ fprintf(f, "%d ", lp->d_drivedata[j]);
+ fprintf(f, "\n");
+ }
+
+ if (opts & SHOW_PARTINFO) {
fprintf(f, "\n%hu partitions:\n", lp->d_npartitions);
fprintf(f, "# %16.16s %16.16s fstype [fsize bsize cpg]\n",
"size", "offset");
for (i = 0; i < lp->d_npartitions; i++)
display_partition(f, lp, mp, i, unit);
}
+
fflush(f);
}
diff --git a/sbin/disklabel/editor.c b/sbin/disklabel/editor.c
index eb2a37ec8c4..4b7fa017bb8 100644
--- a/sbin/disklabel/editor.c
+++ b/sbin/disklabel/editor.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: editor.c,v 1.179 2009/03/28 16:18:50 krw Exp $ */
+/* $OpenBSD: editor.c,v 1.180 2009/03/28 16:27:24 krw Exp $ */
/*
* Copyright (c) 1997-2000 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -17,7 +17,7 @@
*/
#ifndef lint
-static char rcsid[] = "$OpenBSD: editor.c,v 1.179 2009/03/28 16:18:50 krw Exp $";
+static char rcsid[] = "$OpenBSD: editor.c,v 1.180 2009/03/28 16:27:24 krw Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -288,7 +288,8 @@ editor(struct disklabel *lp, int f, char *dev, char *fstabfile, int aflag)
break;
case 'l':
- display(stdout, &label, mountpoints, arg ? *arg : 0, 0);
+ display(stdout, &label, mountpoints, arg ? *arg : 0,
+ SHOW_PHYSINFO);
break;
case 'M': {
@@ -372,7 +373,8 @@ editor(struct disklabel *lp, int f, char *dev, char *fstabfile, int aflag)
if ((fp = fopen(arg, "w")) == NULL) {
warn("cannot open %s", arg);
} else {
- display(fp, &label, NULL, 0, 1) ;
+ display(fp, &label, NULL, 0, SHOW_PHYSINFO |
+ SHOW_PARTINFO);
(void)fclose(fp);
}
break;
diff --git a/sbin/disklabel/extern.h b/sbin/disklabel/extern.h
index b30e1fdd5b2..74daf49ee80 100644
--- a/sbin/disklabel/extern.h
+++ b/sbin/disklabel/extern.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: extern.h,v 1.9 2009/03/22 19:01:32 krw Exp $ */
+/* $OpenBSD: extern.h,v 1.10 2009/03/28 16:27:24 krw Exp $ */
/*
* Copyright (c) 2003 Theo de Raadt <deraadt@openbsd.org>
@@ -16,6 +16,10 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+/* Display options. */
+#define SHOW_PHYSINFO 0x1
+#define SHOW_PARTINFO 0x2
+
u_short dkcksum(struct disklabel *);
int checklabel(struct disklabel *);
double scale(u_int64_t, char, struct disklabel *);