diff options
author | Ted Unangst <tedu@cvs.openbsd.org> | 2003-02-13 00:10:40 +0000 |
---|---|---|
committer | Ted Unangst <tedu@cvs.openbsd.org> | 2003-02-13 00:10:40 +0000 |
commit | 05cf4c1d2b4898a1161171744765e3263767a7f9 (patch) | |
tree | 431cdff7fc625f0afc47cfcaa2e88a3e17f4ab81 /sbin/disklabel | |
parent | b45ec15417d08cc99919929e7bcf18ed0c2d7bdb (diff) |
add support for printing disklabels in units other than sectors from
the cmdline
based on a patch by mho at mho.nu
ok and input by millert@
Diffstat (limited to 'sbin/disklabel')
-rw-r--r-- | sbin/disklabel/disklabel.8 | 9 | ||||
-rw-r--r-- | sbin/disklabel/disklabel.c | 26 | ||||
-rw-r--r-- | sbin/disklabel/editor.c | 8 |
3 files changed, 29 insertions, 14 deletions
diff --git a/sbin/disklabel/disklabel.8 b/sbin/disklabel/disklabel.8 index 7cd7e2dea83..0d7e79e13e2 100644 --- a/sbin/disklabel/disklabel.8 +++ b/sbin/disklabel/disklabel.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: disklabel.8,v 1.48 2003/02/01 16:29:52 jmc Exp $ +.\" $OpenBSD: disklabel.8,v 1.49 2003/02/13 00:10:39 tedu Exp $ .\" $NetBSD: disklabel.8,v 1.9 1995/03/18 14:54:38 cgd Exp $ .\" .\" Copyright (c) 1987, 1988, 1991, 1993 @@ -47,6 +47,7 @@ .Nm disklabel .Op Fl n .Op Fl cd Li \&| Fl r +.Op Fl p Ar unit .Op Fl t .Op Fl v .Ar disk @@ -187,6 +188,12 @@ flag. If .Ar tempfile already exists, it will be overwritten. +.It Fl p Ar unit +Print partition sizes and offsets in +.Ar unit +instead of sectors. +Valid units are b(ytes), c(ylinders), k(ilobytes), m(egabytes) and +g(igabytes). .It Fl t Format the label as a .Xr disktab 5 diff --git a/sbin/disklabel/disklabel.c b/sbin/disklabel/disklabel.c index 62df3e87813..0b48cb6d26e 100644 --- a/sbin/disklabel/disklabel.c +++ b/sbin/disklabel/disklabel.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disklabel.c,v 1.77 2003/02/05 19:13:58 deraadt Exp $ */ +/* $OpenBSD: disklabel.c,v 1.78 2003/02/13 00:10:39 tedu Exp $ */ /* * Copyright (c) 1987, 1993 @@ -43,7 +43,7 @@ static const char copyright[] = #endif /* not lint */ #ifndef lint -static const char rcsid[] = "$OpenBSD: disklabel.c,v 1.77 2003/02/05 19:13:58 deraadt Exp $"; +static const char rcsid[] = "$OpenBSD: disklabel.c,v 1.78 2003/02/13 00:10:39 tedu Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -125,7 +125,7 @@ int writelabel(int, char *, struct disklabel *); void l_perror(char *); struct disklabel *readlabel(int); struct disklabel *makebootarea(char *, struct disklabel *, int); -void display(FILE *, struct disklabel *); +void display(FILE *, struct disklabel *, char); void display_partition(FILE *, struct disklabel *, char **, int, char, int); int width_partition(struct disklabel *, int); int editor(struct disklabel *, int, char *, char *); @@ -148,9 +148,10 @@ main(argc, argv) int ch, f, writeable, error = 0; char *fstabfile = NULL; struct disklabel *lp; + char print_unit = 0; FILE *t; - while ((ch = getopt(argc, argv, "BEFf:NRWb:cdenrs:tvw")) != -1) + while ((ch = getopt(argc, argv, "BEFf:NRWb:cdenp:rs:tvw")) != -1) switch (ch) { #if NUMBOOT > 0 case 'B': @@ -212,6 +213,12 @@ main(argc, argv) usage(); op = WRITE; break; + case 'p': + if (strchr("bckmg", optarg[0]) == NULL || + optarg[1] != '\0') + usage(); + print_unit = optarg[0]; + break; case 'n': donothing++; break; @@ -284,7 +291,7 @@ main(argc, argv) if (tflag) makedisktab(stdout, lp); else - display(stdout, lp); + display(stdout, lp, print_unit); error = checklabel(lp); break; case RESTORE: @@ -1089,9 +1096,10 @@ display_partition(f, lp, mp, i, unit, width) } void -display(f, lp) +display(f, lp, unit) FILE *f; struct disklabel *lp; + char unit; { int i, j; int width; @@ -1139,7 +1147,7 @@ display(f, lp) "# %*.*s %*.*s fstype [fsize bsize cpg]\n", width, width, "size", width, width, "offset"); for (i = 0; i < lp->d_npartitions; i++) - display_partition(f, lp, NULL, i, 0, width); + display_partition(f, lp, NULL, i, unit, width); fflush(f); } @@ -1158,7 +1166,7 @@ edit(lp, f) warn("%s", tmpfil); return (1); } - display(fp, lp); + display(fp, lp, 0); fprintf(fp, "\n# Notes:\n"); fprintf(fp, "# Up to 16 partitions are valid, named from 'a' to 'p'. Partition 'a' is\n" @@ -1758,7 +1766,7 @@ usage() fprintf(stderr, "usage:\n"); fprintf(stderr, - " disklabel [-nv] [-r|-cd] [-t] disk%s (read)\n", + " disklabel [-nv] [-r|-cd] [-p unit] [-t] disk%s (read)\n", blank); fprintf(stderr, " disklabel [-nv] [-r|-cd] -e disk%s (edit)\n", diff --git a/sbin/disklabel/editor.c b/sbin/disklabel/editor.c index 583747ee0ba..97db754ef58 100644 --- a/sbin/disklabel/editor.c +++ b/sbin/disklabel/editor.c @@ -1,4 +1,4 @@ -/* $OpenBSD: editor.c,v 1.81 2002/06/09 08:13:05 todd Exp $ */ +/* $OpenBSD: editor.c,v 1.82 2003/02/13 00:10:39 tedu Exp $ */ /* * Copyright (c) 1997-2000 Todd C. Miller <Todd.Miller@courtesan.com> @@ -28,7 +28,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: editor.c,v 1.81 2002/06/09 08:13:05 todd Exp $"; +static char rcsid[] = "$OpenBSD: editor.c,v 1.82 2003/02/13 00:10:39 tedu Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -119,7 +119,7 @@ static int expert; /* from disklabel.c */ int checklabel(struct disklabel *); -void display(FILE *, struct disklabel *); +void display(FILE *, struct disklabel *, char); void display_partition(FILE *, struct disklabel *, char **, int, char, int); int width_partition(struct disklabel *, int); @@ -385,7 +385,7 @@ editor(lp, f, dev, fstabfile) if ((fp = fopen(arg, "w")) == NULL) { warn("cannot open %s", arg); } else { - display(fp, &label); + display(fp, &label, 0); (void)fclose(fp); } break; |