summaryrefslogtreecommitdiff
path: root/sbin/disklabel
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2008-06-25 18:31:08 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2008-06-25 18:31:08 +0000
commitb52c1e0569b6404fa06f234919c30a954dc36dba (patch)
tree8f358d834e803ecfe038723eebd7a7b65e29fe6b /sbin/disklabel
parente242505846af2ed2dd01ac39c4cb8bb2a88ac8f5 (diff)
In interactive mode, always suggest offsets and sizes inside the
OpenBSD area and change the 'p' command to only print the boundaries and size of the OpenBSD area and the free space within that area. Introduce a 'l' command to print the header only. With krw@; ok krw@ deraadt@; jmc@ for the man page bits
Diffstat (limited to 'sbin/disklabel')
-rw-r--r--sbin/disklabel/disklabel.88
-rw-r--r--sbin/disklabel/disklabel.c125
-rw-r--r--sbin/disklabel/editor.c69
-rw-r--r--sbin/disklabel/extern.h4
4 files changed, 130 insertions, 76 deletions
diff --git a/sbin/disklabel/disklabel.8 b/sbin/disklabel/disklabel.8
index 9e92b50c7a0..bbf26455669 100644
--- a/sbin/disklabel/disklabel.8
+++ b/sbin/disklabel/disklabel.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: disklabel.8,v 1.68 2008/04/06 20:18:54 krw Exp $
+.\" $OpenBSD: disklabel.8,v 1.69 2008/06/25 18:31:07 otto Exp $
.\" $NetBSD: disklabel.8,v 1.9 1995/03/18 14:54:38 cgd Exp $
.\"
.\" Copyright (c) 1987, 1988, 1991, 1993
@@ -33,7 +33,7 @@
.\"
.\" @(#)disklabel.8 8.2 (Berkeley) 4/19/94
.\"
-.Dd $Mdocdate: April 6 2008 $
+.Dd $Mdocdate: June 25 2008 $
.Dt DISKLABEL 8
.Os
.Sh NAME
@@ -355,6 +355,8 @@ thinks (the
geometry is simply what the label said before
.Nm
made any changes).
+.It Cm l Op Ar unit
+Print the disk label header.
.It Cm M
Display this manual page.
.It Cm m Op Ar part
@@ -377,7 +379,7 @@ was invoked with the
.Fl f
flag.
.It Cm p Op Ar unit
-Print the current disk label.
+Print the current partition list.
If a
.Em unit
is given, the size and offsets are displayed in terms of the
diff --git a/sbin/disklabel/disklabel.c b/sbin/disklabel/disklabel.c
index 21782ce453d..e2c3e40b8a3 100644
--- a/sbin/disklabel/disklabel.c
+++ b/sbin/disklabel/disklabel.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disklabel.c,v 1.129 2008/06/25 15:26:43 reyk Exp $ */
+/* $OpenBSD: disklabel.c,v 1.130 2008/06/25 18:31:07 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.129 2008/06/25 15:26:43 reyk Exp $";
+static const char rcsid[] = "$OpenBSD: disklabel.c,v 1.130 2008/06/25 18:31:07 otto Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -274,7 +274,7 @@ main(int argc, char *argv[])
if (tflag)
makedisktab(stdout, lp);
else
- display(stdout, lp, NULL, print_unit, 0, 0);
+ display(stdout, lp, NULL, print_unit, 1);
error = checklabel(lp);
break;
case RESTORE:
@@ -752,7 +752,7 @@ makebootarea(char *boot, struct disklabel *dp, int f)
/* XXX assume d_secsize is a power of two */
bootsize = (bootsize + dp->d_secsize-1) & ~(dp->d_secsize-1);
bootbuf = (char *)malloc((size_t)bootsize);
- if (bootbuf == 0)
+ if (bootbuf == NULL)
err(4, "%s", xxboot);
if (read(b, bootbuf, bootsize) < 0) {
free(bootbuf);
@@ -940,17 +940,13 @@ display_partition(FILE *f, struct disklabel *lp, char **mp, int i,
}
void
-display(FILE *f, struct disklabel *lp, char **mp, char unit, int edit,
- u_int64_t fr)
+display(FILE *f, struct disklabel *lp, char **mp, char unit, int all)
{
int i, j;
double d;
unit = toupper(unit);
- if (edit)
- fprintf(f, "device: %s\n", specname);
- else
- fprintf(f, "# %s:\n", specname);
+ fprintf(f, "# %s:\n", specname);
if ((unsigned) lp->d_type < DKMAXTYPES)
fprintf(f, "type: %s\n", dktypenames[lp->d_type]);
@@ -958,14 +954,13 @@ display(FILE *f, struct disklabel *lp, char **mp, char unit, int edit,
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);
- if (!edit) {
- 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, "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);
@@ -978,38 +973,30 @@ display(FILE *f, struct disklabel *lp, char **mp, char unit, int edit,
fprintf(f, "total bytes: %.*f%c\n", unit == 'B' ? 0 : 1,
d, unit);
- if (edit) {
- d = scale(fr, unit, lp);
- if (d < 0)
- fprintf(f, "free sectors: %llu\n", fr);
- else
- fprintf(f, "free bytes: %.*f%c\n", unit == 'B' ? 0 : 1,
- d, unit);
- }
fprintf(f, "rpm: %hu\n", lp->d_rpm);
- if (!edit) {
- 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");
+ 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) {
+ 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);
}
- 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);
}
@@ -1026,7 +1013,7 @@ edit(struct disklabel *lp, int f)
warn("%s", tmpfil);
return (1);
}
- display(fp, lp, NULL, 0, 0, 0);
+ display(fp, lp, NULL, 0, 1);
fprintf(fp, "\n# Notes:\n");
fprintf(fp,
"# Up to 16 partitions are valid, named from 'a' to 'p'. Partition 'a' is\n"
@@ -1590,29 +1577,41 @@ setbootflag(struct disklabel *lp)
{
struct partition *pp;
int i, errors = 0;
- u_long boffset;
+ daddr64_t bend;
char part;
- if (bootbuf == 0)
+ if (bootbuf == NULL)
return;
- boffset = bootsize / lp->d_secsize;
+
+ bend = bootsize / lp->d_secsize;
for (i = 0; i < lp->d_npartitions; i++) {
- part = 'a' + i;
+ if (i == RAW_PART)
+ /* It will *ALWAYS* overlap 'c'. */
+ continue;
pp = &lp->d_partitions[i];
if (DL_GETPSIZE(pp) == 0)
+ /* Partition is unused. */
continue;
- if (boffset <= DL_GETPOFFSET(pp)) {
+ if (bend <= DL_GETPOFFSET(pp)) {
+ /* Boot blocks end before this partition starts. */
if (pp->p_fstype == FS_BOOT)
pp->p_fstype = FS_UNUSED;
- } else if (pp->p_fstype != FS_BOOT) {
- if (pp->p_fstype != FS_UNUSED) {
- warnx("boot overlaps used partition %c", part);
- errors++;
- } else {
- pp->p_fstype = FS_BOOT;
- warnx("warning, boot overlaps partition %c, %s",
- part, "marked as FS_BOOT");
- }
+ continue;
+ }
+
+ part = 'a' + i;
+ switch (pp->p_fstype) {
+ case FS_BOOT: /* Already marked. */
+ break;
+ case FS_UNUSED: /* Mark. */
+ pp->p_fstype = FS_BOOT;
+ warnx("warning, boot overlaps partition %c, %s",
+ part, "marked as FS_BOOT");
+ break;
+ default:
+ warnx("boot overlaps used partition %c", part);
+ errors++;
+ break;
}
}
if (errors)
diff --git a/sbin/disklabel/editor.c b/sbin/disklabel/editor.c
index 1e24d1fed4a..0f7852d048b 100644
--- a/sbin/disklabel/editor.c
+++ b/sbin/disklabel/editor.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: editor.c,v 1.167 2008/04/13 15:54:59 krw Exp $ */
+/* $OpenBSD: editor.c,v 1.168 2008/06/25 18:31:07 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.167 2008/04/13 15:54:59 krw Exp $";
+static char rcsid[] = "$OpenBSD: editor.c,v 1.168 2008/06/25 18:31:07 otto Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -93,6 +93,7 @@ void set_geometry(struct disklabel *, struct disklabel *, struct disklabel *,
char *);
void zero_partitions(struct disklabel *);
u_int64_t max_partition_size(struct disklabel *, int);
+void display_edit(struct disklabel *, char **, char, u_int64_t);
static u_int64_t starting_sector;
static u_int64_t ending_sector;
@@ -282,10 +283,14 @@ editor(struct disklabel *lp, int f, char *dev, char *fstabfile)
break;
case 'p':
- display(stdout, &label, mountpoints, arg ? *arg : 0, 1,
+ display_edit(&label, mountpoints, arg ? *arg : 0,
editor_countfree(&label));
break;
+ case 'l':
+ display(stdout, &label, mountpoints, arg ? *arg : 0, 0);
+ break;
+
case 'M': {
sig_t opipe = signal(SIGPIPE, SIG_IGN);
char *pager, *cmd = NULL;
@@ -367,7 +372,7 @@ editor(struct disklabel *lp, int f, char *dev, char *fstabfile)
if ((fp = fopen(arg, "w")) == NULL) {
warn("cannot open %s", arg);
} else {
- display(fp, &label, NULL, 0, 0, 0);
+ display(fp, &label, NULL, 0, 1) ;
(void)fclose(fp);
}
break;
@@ -1309,10 +1314,18 @@ free_chunks(struct disklabel *lp)
}
for (i = 0; spp[i] != NULL; i++) {
start = DL_GETPOFFSET(spp[i]) + DL_GETPSIZE(spp[i]);
+ if (start < starting_sector)
+ start = starting_sector;
+ else if (start > ending_sector)
+ start = ending_sector;
if (spp[i + 1] != NULL)
stop = DL_GETPOFFSET(spp[i+1]);
else
stop = ending_sector;
+ if (stop < starting_sector)
+ stop = starting_sector;
+ else if (stop > ending_sector)
+ stop = ending_sector;
if (start < stop) {
chunks[numchunks].start = start;
chunks[numchunks].stop = stop;
@@ -1411,7 +1424,13 @@ editor_help(char *arg)
switch (*arg) {
case 'p':
puts(
-"The 'p' command prints the current disk label. By default, it prints the\n"
+"The 'p' command prints the current partitions. By default, it prints size\n"
+"and offset in sectors (a sector is usually 512 bytes). The 'p' command\n"
+"takes an optional units argument. Possible values are 'b' for bytes, 'c'\n"
+"for cylinders, 'k' for kilobytes, 'm' for megabytes, and 'g' for gigabytes.\n");
+ case 'l':
+ puts(
+"The 'l' command prints the header of the disk label. By default, it prints\n"
"size and offset in sectors (a sector is usually 512 bytes). The 'p' command\n"
"takes an optional units argument. Possible values are 'b' for bytes, 'c'\n"
"for cylinders, 'k' for kilobytes, 'm' for megabytes, and 'g' for gigabytes.\n");
@@ -1545,15 +1564,16 @@ editor_help(char *arg)
puts("Available commands:");
puts(
" ? [command] - show help n [part] - set mount point\n"
-" a [part] - add partition p [unit] - print label\n"
+" a [part] - add partition p [unit] - print partitions\n"
" b - set OpenBSD boundaries q - quit & save changes\n"
" c [part] - change partition size r - display free space\n"
" D - reset label to default s [path] - save label to file\n"
" d [part] - delete partition u - undo last change\n"
" e - edit drive parameters w - write label to disk\n"
" g [d|u] - [d]isk or [u]ser geometry X - toggle expert mode\n"
-" M - disklabel(8) man page x - exit w/o saving changes\n"
-" m [part] - modify partition z - delete all partitions\n"
+" l [unit] - print disk label header x - exit w/o saving changes\n"
+" M - disklabel(8) man page z - delete all partitions\n"
+" m [part] - modify partition\n"
"\n"
"Suffixes can be used to indicate units other than sectors:\n"
"\t'b' (bytes), 'k' (kilobytes), 'm' (megabytes), 'g' (gigabytes)\n"
@@ -2025,3 +2045,36 @@ max_partition_size(struct disklabel *lp, int partno)
}
return (maxsize);
}
+
+void
+psize(daddr64_t sz, char unit, struct disklabel *lp)
+{
+ double d = scale(sz, unit, lp);
+ if (d < 0)
+ printf("%llu", sz);
+ else
+ printf("%.*f%c", unit == 'B' ? 0 : 1, d, unit);
+}
+
+void
+display_edit(struct disklabel *lp, char **mp, char unit, u_int64_t fr)
+{
+ int i;
+
+ unit = toupper(unit);
+
+ printf("OpenBSD area: ");
+ psize(starting_sector, unit, lp);
+ printf("-");
+ psize(ending_sector, unit, lp);
+ printf("; size: ");
+ psize(ending_sector - starting_sector, unit, lp);
+ printf("; free: ");
+ psize(fr, unit, lp);
+
+ printf("\n# %16.16s %16.16s fstype [fsize bsize cpg]\n",
+ "size", "offset");
+ for (i = 0; i < lp->d_npartitions; i++)
+ display_partition(stdout, lp, mp, i, unit);
+}
+
diff --git a/sbin/disklabel/extern.h b/sbin/disklabel/extern.h
index cfdb17df0e0..d13adb4cad9 100644
--- a/sbin/disklabel/extern.h
+++ b/sbin/disklabel/extern.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: extern.h,v 1.6 2007/06/08 18:42:17 otto Exp $ */
+/* $OpenBSD: extern.h,v 1.7 2008/06/25 18:31:07 otto Exp $ */
/*
* Copyright (c) 2003 Theo de Raadt <deraadt@openbsd.org>
@@ -19,7 +19,7 @@
u_short dkcksum(struct disklabel *);
int checklabel(struct disklabel *);
double scale(u_int64_t, char, struct disklabel *);
-void display(FILE *, struct disklabel *, char **, char, int, u_int64_t);
+void display(FILE *, struct disklabel *, char **, char, int);
void display_partition(FILE *, struct disklabel *, char **, int, char);
struct disklabel *readlabel(int);