diff options
author | Otto Moerbeek <otto@cvs.openbsd.org> | 2004-09-28 17:57:47 +0000 |
---|---|---|
committer | Otto Moerbeek <otto@cvs.openbsd.org> | 2004-09-28 17:57:47 +0000 |
commit | d2790164cfa9528e029d3c46ec77d8de39b16fb3 (patch) | |
tree | edb6741e96f990f36257fca65d53c7eab25ba619 /sbin/disklabel | |
parent | 50297b24366d5fd9607bc2e12eb1b870cf73fedf (diff) |
Tidy disklabel output for todays big disks. Based on a diff from f
at obiit dot org in PR 3847. ok tedu@ deraadt@ millert@
Diffstat (limited to 'sbin/disklabel')
-rw-r--r-- | sbin/disklabel/disklabel.c | 65 | ||||
-rw-r--r-- | sbin/disklabel/dkcksum.c | 5 | ||||
-rw-r--r-- | sbin/disklabel/editor.c | 33 | ||||
-rw-r--r-- | sbin/disklabel/extern.h | 14 |
4 files changed, 47 insertions, 70 deletions
diff --git a/sbin/disklabel/disklabel.c b/sbin/disklabel/disklabel.c index b3b050f180d..c3bf4576506 100644 --- a/sbin/disklabel/disklabel.c +++ b/sbin/disklabel/disklabel.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disklabel.c,v 1.91 2004/09/18 23:23:17 deraadt Exp $ */ +/* $OpenBSD: disklabel.c,v 1.92 2004/09/28 17:57:46 otto 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.91 2004/09/18 23:23:17 deraadt Exp $"; +static const char rcsid[] = "$OpenBSD: disklabel.c,v 1.92 2004/09/28 17:57:46 otto Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -121,22 +121,15 @@ void makedisktab(FILE *, struct disklabel *); void makelabel(char *, char *, struct disklabel *); 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 *, char); -void display_partition(FILE *, struct disklabel *, char **, int, char, int); -int width_partition(struct disklabel *, int); -int editor(struct disklabel *, int, char *, char *); int edit(struct disklabel *, int); int editit(void); char *skip(char *); char *word(char *); int getasciilabel(FILE *, struct disklabel *); -int checklabel(struct disklabel *); int cmplabel(struct disklabel *, struct disklabel *); void setbootflag(struct disklabel *); void usage(void); -u_short dkcksum(struct disklabel *); +u_int32_t getnum(char *, u_int32_t, u_int32_t, const char **); int main(int argc, char *argv[]) @@ -972,29 +965,16 @@ makedisktab(FILE *f, struct disklabel *lp) (void)fflush(f); } -int -width_partition(struct disklabel *lp, int unit) -{ - unit = toupper(unit); - switch (unit) { - case 'K': - return 10; - } - return 8; -} - /* * Display a particular partition. */ void display_partition(FILE *f, struct disklabel *lp, char **mp, int i, - char unit, int width) + char unit) { volatile struct partition *pp = &lp->d_partitions[i]; double p_size, p_offset; - if (width == 0) - width = 8; unit = toupper(unit); p_size = -1.0; /* no conversion by default */ p_offset = 0.0; @@ -1027,49 +1007,51 @@ display_partition(FILE *f, struct disklabel *lp, char **mp, int i, if (pp->p_size) { if (p_size < 0) - fprintf(f, " %c: %*u %*u ", 'a' + i, - width, pp->p_size, width, pp->p_offset); + fprintf(f, " %c: %13u %13u ", 'a' + i, + pp->p_size, pp->p_offset); else - fprintf(f, " %c: %*.1f%c %*.1f%c ", 'a' + i, - width-1, p_size, unit, width-1, p_offset, unit); + fprintf(f, " %c: %12.*f%c %12.*f%c ", 'a' + i, + unit == 'B' ? 0 : 1, p_size, unit, + unit == 'B' ? 0 : 1, p_offset, unit); if ((unsigned) pp->p_fstype < FSMAXTYPES) - fprintf(f, "%8.8s", fstypenames[pp->p_fstype]); + fprintf(f, "%6.6s", fstypenames[pp->p_fstype]); else - fprintf(f, "%8d", pp->p_fstype); + fprintf(f, "%6d", pp->p_fstype); switch (pp->p_fstype) { case FS_UNUSED: /* XXX */ - fprintf(f, " %5u %5u %5.5s ", + fprintf(f, " %5u %5u %5.5s ", pp->p_fsize, pp->p_fsize * pp->p_frag, ""); break; case FS_BSDFFS: - fprintf(f, " %5u %5u %5hu ", + fprintf(f, " %5u %5u %5hu ", pp->p_fsize, pp->p_fsize * pp->p_frag, pp->p_cpg); break; default: - fprintf(f, "%22.22s", ""); + fprintf(f, "%20.20s", ""); break; } if (mp != NULL) { if (mp[i] != NULL) - fprintf(f, " # %s", mp[i]); + fprintf(f, "# %s", mp[i]); } else if (lp->d_secpercyl) { - fprintf(f, "\t# (Cyl. %4u", + fprintf(f, "# Cyl %5u", pp->p_offset / lp->d_secpercyl); if (pp->p_offset % lp->d_secpercyl) putc('*', f); else putc(' ', f); - fprintf(f, "- %u", + fprintf(f, "-%6u", (pp->p_offset + pp->p_size + lp->d_secpercyl - 1) / lp->d_secpercyl - 1); if ((pp->p_offset + pp->p_size) % lp->d_secpercyl) putc('*', f); - putc(')', f); + else + putc(' ', f); } putc('\n', f); } @@ -1079,7 +1061,6 @@ void display(FILE *f, struct disklabel *lp, char unit) { int i, j; - int width; fprintf(f, "# %s:\n", specname); if ((unsigned) lp->d_type < DKMAXTYPES) @@ -1118,12 +1099,10 @@ display(FILE *f, struct disklabel *lp, char unit) for (j = 0; j <= i; j++) fprintf(f, "%d ", lp->d_drivedata[j]); fprintf(f, "\n\n%hu partitions:\n", lp->d_npartitions); - width = width_partition(lp, 0); - fprintf(f, - "# %*.*s %*.*s fstype [fsize bsize cpg]\n", - width, width, "size", width, width, "offset"); + fprintf(f, "# %13.13s %13.13s fstype [fsize bsize cpg]\n", + "size", "offset"); for (i = 0; i < lp->d_npartitions; i++) - display_partition(f, lp, NULL, i, unit, width); + display_partition(f, lp, NULL, i, unit); fflush(f); } diff --git a/sbin/disklabel/dkcksum.c b/sbin/disklabel/dkcksum.c index f55e5c66bd3..fdb6dea7221 100644 --- a/sbin/disklabel/dkcksum.c +++ b/sbin/disklabel/dkcksum.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dkcksum.c,v 1.6 2003/07/02 21:22:10 deraadt Exp $ */ +/* $OpenBSD: dkcksum.c,v 1.7 2004/09/28 17:57:46 otto Exp $ */ /* $NetBSD: dkcksum.c,v 1.6 1995/03/18 14:54:42 cgd Exp $ */ /*- @@ -34,12 +34,13 @@ #if 0 static char sccsid[] = "@(#)dkcksum.c 8.1 (Berkeley) 6/5/93"; #else -static char rcsid[] = "$OpenBSD: dkcksum.c,v 1.6 2003/07/02 21:22:10 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: dkcksum.c,v 1.7 2004/09/28 17:57:46 otto Exp $"; #endif #endif /* not lint */ #include <sys/types.h> #include <sys/disklabel.h> +#include <stdio.h> #include "extern.h" u_short diff --git a/sbin/disklabel/editor.c b/sbin/disklabel/editor.c index 3daa3dc2895..4f4d791a3c2 100644 --- a/sbin/disklabel/editor.c +++ b/sbin/disklabel/editor.c @@ -1,4 +1,4 @@ -/* $OpenBSD: editor.c,v 1.94 2004/08/03 09:30:12 otto Exp $ */ +/* $OpenBSD: editor.c,v 1.95 2004/09/28 17:57:46 otto 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.94 2004/08/03 09:30:12 otto Exp $"; +static char rcsid[] = "$OpenBSD: editor.c,v 1.95 2004/09/28 17:57:46 otto Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -44,6 +44,7 @@ static char rcsid[] = "$OpenBSD: editor.c,v 1.94 2004/08/03 09:30:12 otto Exp $" #include <stdlib.h> #include <unistd.h> +#include "extern.h" #include "pathnames.h" /* flags for getuint() */ @@ -67,7 +68,6 @@ struct mountinfo { }; void edit_parms(struct disklabel *, u_int32_t *); -int editor(struct disklabel *, int, char *, char *); void editor_add(struct disklabel *, char **, u_int32_t *, char *); void editor_change(struct disklabel *, u_int32_t *, char *); void editor_countfree(struct disklabel *, u_int32_t *); @@ -106,21 +106,6 @@ static u_int32_t starting_sector; static u_int32_t ending_sector; static int expert; -/* from disklabel.c */ -int checklabel(struct disklabel *); -void display(FILE *, struct disklabel *, char); -void display_partition(FILE *, struct disklabel *, char **, int, char, int); -int width_partition(struct disklabel *, int); - -struct disklabel *readlabel(int); -struct disklabel *makebootarea(char *, struct disklabel *, int); -int writelabel(int, char *, struct disklabel *); -extern char *bootarea, *specname; -extern int donothing; -#ifdef DOSLABEL -extern struct dos_partition *dosdp; /* DOS partition, if found */ -#endif - /* * Simple partition editor. Primarily intended for new labels. */ @@ -803,7 +788,6 @@ void editor_display(struct disklabel *lp, char **mp, u_int32_t *freep, char unit) { int i; - int width; printf("device: %s\n", specname); printf("type: %s\n", dktypenames[lp->d_type]); @@ -818,11 +802,10 @@ editor_display(struct disklabel *lp, char **mp, u_int32_t *freep, char unit) printf("free sectors: %u\n", *freep); printf("rpm: %hu\n", lp->d_rpm); printf("\n%hu partitions:\n", lp->d_npartitions); - width = width_partition(lp, unit); - printf("# %*.*s %*.*s fstype [fsize bsize cpg]\n", - width, width, "size", width, width, "offset"); + printf("# %13.13s %13.13s fstype [fsize bsize cpg]\n", + "size", "offset"); for (i = 0; i < lp->d_npartitions; i++) - display_partition(stdout, lp, mp, i, unit, width); + display_partition(stdout, lp, mp, i, unit); } /* @@ -1197,8 +1180,8 @@ has_overlap(struct disklabel *lp, u_int32_t *freep, int resolve) printf("\nError, partitions %c and %c overlap:\n", 'a' + i, 'a' + j); puts(" size offset fstype [fsize bsize cpg]"); - display_partition(stdout, lp, NULL, i, 0, 0); - display_partition(stdout, lp, NULL, j, 0, 0); + display_partition(stdout, lp, NULL, i, 0); + display_partition(stdout, lp, NULL, j, 0); /* Did they ask us to resolve it ourselves? */ if (resolve != 1) { diff --git a/sbin/disklabel/extern.h b/sbin/disklabel/extern.h index 6fe05e7a94a..788407665d5 100644 --- a/sbin/disklabel/extern.h +++ b/sbin/disklabel/extern.h @@ -15,4 +15,18 @@ */ u_short dkcksum(struct disklabel *); +int checklabel(struct disklabel *); +void display(FILE *, struct disklabel *, char); +void display_partition(FILE *, struct disklabel *, char **, int, char); +struct disklabel *readlabel(int); +struct disklabel *makebootarea(char *, struct disklabel *, int); +int editor(struct disklabel *, int, char *, char *); + +int writelabel(int, char *, struct disklabel *); +extern char bootarea[], *specname; +extern int donothing; + +#ifdef DOSLABEL +extern struct dos_partition *dosdp; /* DOS partition, if found */ +#endif |