summaryrefslogtreecommitdiff
path: root/sbin/disklabel
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1997-10-20 07:09:44 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1997-10-20 07:09:44 +0000
commitfd3e27ce29bd081ebf5e967a0bc9806f6ddaee64 (patch)
treebe31cc904499f9b789d1439a7288153ca9e982a3 /sbin/disklabel
parenta7e7884b29d7b8341731943e68f1fe821d68bc7a (diff)
format the "print" units better, in all cases
Diffstat (limited to 'sbin/disklabel')
-rw-r--r--sbin/disklabel/disklabel.c62
-rw-r--r--sbin/disklabel/editor.c21
2 files changed, 58 insertions, 25 deletions
diff --git a/sbin/disklabel/disklabel.c b/sbin/disklabel/disklabel.c
index 016090c6dff..ae5a22daebd 100644
--- a/sbin/disklabel/disklabel.c
+++ b/sbin/disklabel/disklabel.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disklabel.c,v 1.44 1997/10/17 07:30:03 deraadt Exp $ */
+/* $OpenBSD: disklabel.c,v 1.45 1997/10/20 07:09:41 deraadt 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.44 1997/10/17 07:30:03 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: disklabel.c,v 1.45 1997/10/20 07:09:41 deraadt Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -123,7 +123,8 @@ void l_perror __P((char *));
struct disklabel *readlabel __P((int));
struct disklabel *makebootarea __P((char *, struct disklabel *, int));
void display __P((FILE *, struct disklabel *));
-void display_partition __P((FILE *, struct disklabel *, int, char));
+void display_partition __P((FILE *, struct disklabel *, int, char, int));
+int width_partition __P((struct disklabel *, int));
int editor __P((struct disklabel *, int));
int edit __P((struct disklabel *, int));
int editit __P((void));
@@ -832,35 +833,59 @@ makebootarea(boot, dp, f)
return (lp);
}
+int
+width_partition(lp, unit)
+ struct disklabel *lp;
+{
+ unit = toupper(unit);
+ switch (unit) {
+ case 'K':
+ return 10;
+ }
+ return 8;
+}
+
/*
* Display a particular partion.
*/
void
-display_partition(f, lp, i, unit)
+display_partition(f, lp, i, unit, width)
FILE *f;
struct disklabel *lp;
int i;
char unit;
+ int width;
{
struct partition *pp = &lp->d_partitions[i];
- double p_size;
+ double p_size, p_offset;
- unit = tolower(unit);
+ if (width == 0)
+ width = 8;
+ unit = toupper(unit);
switch (unit) {
- case 'b':
+ case 'B':
p_size = (double)pp->p_size * lp->d_secsize;
+ p_offset = (double)pp->p_offset * lp->d_secsize;
break;
- case 'c':
+ case 'C':
p_size = (double)pp->p_size / lp->d_secpercyl;
+ p_offset = (double)pp->p_offset / lp->d_secpercyl;
break;
- case 'k':
+ case 'K':
p_size = (double)pp->p_size / (1024 / lp->d_secsize);
+ p_offset = (double)pp->p_offset / (1024 / lp->d_secsize);
+ break;
+
+ case 'M':
+ p_size = (double)pp->p_size / ((1024*1024) / lp->d_secsize);
+ p_offset = (double)pp->p_offset / ((1024*1024) / lp->d_secsize);
break;
- case 'm':
- p_size = (double)pp->p_size / (1048576 / lp->d_secsize);
+ case 'G':
+ p_size = (double)pp->p_size / ((1024*1024*1024) / lp->d_secsize);
+ p_offset = (double)pp->p_offset / ((1024*1024*1024) / lp->d_secsize);
break;
default:
@@ -870,11 +895,11 @@ display_partition(f, lp, i, unit)
if (pp->p_size) {
if (p_size < 0)
- fprintf(f, " %c: %8u %8u ", 'a' + i,
- pp->p_size, pp->p_offset);
+ fprintf(f, " %c: %*u %*u ", 'a' + i,
+ width, pp->p_size, width, pp->p_offset);
else
- fprintf(f, " %c: %8.2f%c %8u ", 'a' + i,
- p_size, unit, pp->p_offset);
+ fprintf(f, " %c: %*.1lf%c %*.1lf%c ", 'a' + i,
+ width-1, p_size, unit, width-1, p_offset, unit);
if ((unsigned) pp->p_fstype < FSMAXTYPES)
fprintf(f, "%8.8s", fstypenames[pp->p_fstype]);
else
@@ -921,6 +946,7 @@ display(f, lp)
struct disklabel *lp;
{
int i, j;
+ int width;
fprintf(f, "# %s:\n", specname);
if ((unsigned) lp->d_type < DKMAXTYPES)
@@ -960,10 +986,12 @@ display(f, lp)
for (j = 0; j <= i; j++)
fprintf(f, "%d ", lp->d_drivedata[j]);
fprintf(f, "\n\n%d partitions:\n", lp->d_npartitions);
+ width = width_partition(lp, 0);
fprintf(f,
- "# size offset fstype [fsize bsize cpg]\n");
+ "# %*.*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, i, 0);
+ display_partition(f, lp, i, 0, width);
fflush(f);
}
diff --git a/sbin/disklabel/editor.c b/sbin/disklabel/editor.c
index cea43ae91ea..e5b323d0248 100644
--- a/sbin/disklabel/editor.c
+++ b/sbin/disklabel/editor.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: editor.c,v 1.20 1997/10/20 06:26:53 millert Exp $ */
+/* $OpenBSD: editor.c,v 1.21 1997/10/20 07:09:43 deraadt Exp $ */
/*
* Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -31,7 +31,7 @@
*/
#ifndef lint
-static char rcsid[] = "$OpenBSD: editor.c,v 1.20 1997/10/20 06:26:53 millert Exp $";
+static char rcsid[] = "$OpenBSD: editor.c,v 1.21 1997/10/20 07:09:43 deraadt Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -84,7 +84,9 @@ static u_int32_t ending_sector;
/* from disklabel.c */
int checklabel __P((struct disklabel *));
void display __P((FILE *, struct disklabel *));
-void display_partition __P((FILE *, struct disklabel *, int, char));
+void display_partition __P((FILE *, struct disklabel *, int, char, int));
+int width_partition __P((struct disklabel *, int));
+
struct disklabel *readlabel __P((int));
struct disklabel *makebootarea __P((char *, struct disklabel *, int));
int writelabel __P((int, char *, struct disklabel *));
@@ -883,6 +885,7 @@ editor_display(lp, freep, unit)
char unit;
{
int i;
+ int width;
printf("device: %s\n", specname);
printf("type: %s\n", dktypenames[lp->d_type]);
@@ -897,9 +900,11 @@ editor_display(lp, freep, unit)
printf("free sectors: %u\n", *freep);
printf("rpm: %ld\n", (long)lp->d_rpm);
printf("\n%d partitions:\n", lp->d_npartitions);
- printf("# size offset fstype [fsize bsize cpg]\n");
+ width = width_partition(lp, unit);
+ printf("# %*.*s %*.*s fstype [fsize bsize cpg]\n",
+ width, width, "size", width, width, "offset");
for (i = 0; i < lp->d_npartitions; i++)
- display_partition(stdout, lp, i, unit);
+ display_partition(stdout, lp, i, unit, width);
}
/*
@@ -1286,8 +1291,8 @@ has_overlap(lp, freep, resolve)
printf("\nError, partitions %c and %c overlap:\n",
'a' + i, 'a' + j);
puts(" size offset fstype [fsize bsize cpg]");
- display_partition(stdout, lp, i, 0);
- display_partition(stdout, lp, j, 0);
+ display_partition(stdout, lp, i, 0, 0);
+ display_partition(stdout, lp, j, 0, 0);
/* Did they ask us to resolve it ourselves? */
if (resolve != 1) {
@@ -1721,7 +1726,7 @@ find_bounds(lp)
if (numchunks > 1) {
printf("# size offset fstype [fsize bsize cpg]\n");
for (i = 0; i < lp->d_npartitions; i++)
- display_partition(stdout, lp, i, 0);
+ display_partition(stdout, lp, i, 0, 0);
puts("Several chunks of unused or BSD space exist, which one is for OpenBSD?");
if (ourchunk != -1)
printf("It looks like the OpenBSD portion is chunk "