-.\" $OpenBSD: disklabel.8,v 1.115 2015/05/19 18:50:39 sobrado Exp $
+.\" $OpenBSD: disklabel.8,v 1.116 2015/10/15 19:31:15 miod Exp $
.\" $NetBSD: disklabel.8,v 1.9 1995/03/18 14:54:38 cgd Exp $
.\"
.\" Copyright (c) 1987, 1988, 1991, 1993
.\"
.\" @(#)disklabel.8 8.2 (Berkeley) 4/19/94
.\"
-.Dd $Mdocdate: May 19 2015 $
+.Dd $Mdocdate: October 15 2015 $
.Dt DISKLABEL 8
.Os
.Sh NAME
.Op Fl nv
.Op Fl F Ns | Ns Fl f Ar file
.Ar disk Ar protofile
-.Pp
-.Nm disklabel
-.Fl B\ \&
-.Op Fl nv
-.Op Fl b Ar boot1
-.Ar disk
-.Op Ar disktype
-.Nm disklabel
-.Fl Bw
-.Op Fl nv
-.Op Fl b Ar boot1
-.Ar disk Ar disktype
-.Op Ar packid
-.Nm disklabel
-.Fl BR
-.Op Fl nv
-.Op Fl b Ar boot1
-.Op Fl F Ns | Ns Fl f Ar file
-.Ar disk Ar protofile
-.Op Ar disktype
.Sh DESCRIPTION
The
.Nm
See
.Sx AUTOMATIC DISK ALLOCATION ,
below.
-.It Fl B
-Install bootstrap code.
-Some architectures instead require bootstrap code installation to be
-done using an
-.Xr installboot 8
-type program, as described in
-.Xr boot 8 .
-.It Fl b Ar boot1
-Specify the primary boot program.
.It Fl c
Clear the system's in-core copy of the label and update it based on
the on-disk label.
are used to install bootstrap code on machines where the bootstrap is
part of the label.
.Pp
-When installing bootstrap code with the
-.Fl B
-flag, if the boot program name is not explicitly given with
-.Fl b Ar boot1 ,
-a standard boot program
-will be used.
-The standard boot programs are located in
-.Pa /usr/mdec .
-The name of the program is taken from the
-.Dq b0
-parameter of the
-.Xr disktab 5
-entry for the disk if
-.Ar disktype
-was given and its disktab entry exists and includes a b0 field.
-Otherwise, the boot program name is derived from the name of the
-disk.
-These names are of the form
-.Pa basename Ns boot .
-For example,
-.Pa /usr/mdec/sdboot
-if the disk device is
-.Em sd0 .
-.Pp
-The first of the three boot-installation forms is used to install
-bootstrap code without changing the existing label.
-It is essentially a read command with respect to the disk label itself
-and all options are related to the specification of the boot program
-as described previously.
-The final two forms are analogous to the basic write and restore versions
-except that they will install bootstrap code in addition to a new label.
-.Pp
Note that when a disk has no real
.Bx
disklabel, the kernel creates a
-/* $OpenBSD: disklabel.c,v 1.209 2015/10/11 04:36:22 deraadt Exp $ */
+/* $OpenBSD: disklabel.c,v 1.210 2015/10/15 19:31:15 miod Exp $ */
/*
* Copyright (c) 1987, 1993
#define BBSIZE 8192 /* size of boot area, with label */
#endif
-#ifndef NUMBOOT
-#define NUMBOOT 0
-#endif
-
char *dkname, *specname, *fstabfile;
char tmpfil[] = _PATH_TMPFILE;
char *mountpoints[MAXPARTITIONS];
struct disklabel lab;
char bootarea[BBSIZE];
-#if NUMBOOT > 0
-char namebuf[BBSIZE], *np = namebuf;
-int installboot; /* non-zero if we should install a boot program */
-char *bootbuf; /* pointer to buffer with remainder of boot prog */
-int bootsize; /* size of remaining boot program */
-char *xxboot; /* primary boot */
-char boot0[MAXPATHLEN];
-void setbootflag(struct disklabel *);
-#endif
-
enum {
- UNSPEC, EDIT, EDITOR, READ, RESTORE, WRITE, WRITEBOOT
+ UNSPEC, EDIT, EDITOR, READ, RESTORE, WRITE
} op = UNSPEC;
int aflag;
FILE *t;
char *autotable = NULL;
- while ((ch = getopt(argc, argv, "ABEf:F:hRb:cdenp:tT:vw")) != -1)
+ while ((ch = getopt(argc, argv, "AEf:F:hRcdenp:tT:vw")) != -1)
switch (ch) {
case 'A':
aflag = 1;
break;
-#if NUMBOOT > 0
- case 'B':
- installboot = 1;
- break;
- case 'b':
- xxboot = optarg;
- break;
-#endif
case 'R':
if (op != UNSPEC)
usage();
argc -= optind;
argv += optind;
-#if NUMBOOT > 0
- if (installboot) {
- if (op == UNSPEC)
- op = WRITEBOOT;
- } else {
- if (op == UNSPEC)
- op = READ;
- }
-#else
if (op == UNSPEC)
op = READ;
-#endif
if (argc < 1 || (fstabfile && !(op == EDITOR || op == RESTORE ||
aflag)))
if (argc < 2 || argc > 3)
usage();
readlabel(f);
-#if NUMBOOT > 0
- if (installboot && argc == 3)
- makelabel(argv[2], NULL, &lab);
-#endif
lp = makebootarea(bootarea, &lab);
*lp = lab;
if (!(t = fopen(argv[1], "r")))
if (error == 0)
error = writelabel(f, bootarea, lp);
break;
-#if NUMBOOT > 0
- case WRITEBOOT:
- {
- struct disklabel tlab;
-
- readlabel(f);
- tlab = lab;
- if (argc == 2)
- makelabel(argv[1], NULL, &lab);
- lp = makebootarea(bootarea, &lab);
- *lp = tlab;
- error = checklabel(&lab);
- if (error == 0)
- error = writelabel(f, bootarea, lp);
- break;
- }
-#endif
default:
break;
}
if (dp == NULL)
errx(1, "unknown disk type: %s", type);
*lp = *dp;
-#if NUMBOOT > 0
- /*
- * Set bootstrap name(s).
- * 1. If set from command line, use those,
- * 2. otherwise, check if disktab specifies them (b0 or b1),
- * 3. otherwise, makebootarea() will choose ones based on the name
- * of the disk special file. E.g. /dev/ra0 -> raboot, bootra
- */
- if (!xxboot && lp->d_boot0) {
- if (*lp->d_boot0 != '/')
- (void)snprintf(boot0, sizeof boot0, "%s%s",
- _PATH_BOOTDIR, lp->d_boot0);
- else
- (void)strlcpy(boot0, lp->d_boot0, sizeof boot0);
- xxboot = boot0;
- }
-#endif
/* d_packname is union d_boot[01], so zero */
memset(lp->d_packname, 0, sizeof(lp->d_packname));
if (name)
int
writelabel(int f, char *boot, struct disklabel *lp)
{
-#if NUMBOOT > 0
- setbootflag(lp);
-#endif
lp->d_magic = DISKMAGIC;
lp->d_magic2 = DISKMAGIC;
lp->d_checksum = 0;
lp->d_checksum = dkcksum(lp);
-#if NUMBOOT > 0
- if (installboot) {
- /*
- * First set the kernel disk label,
- * then write a label to the raw disk.
- * If the SDINFO ioctl fails because it is unimplemented,
- * keep going; otherwise, the kernel consistency checks
- * may prevent us from changing the current (in-core)
- * label.
- */
- if (!donothing) {
- if (ioctl(f, DIOCSDINFO, lp) < 0 &&
- errno != ENODEV && errno != ENOTTY) {
- l_perror("ioctl DIOCSDINFO");
- return (1);
- }
- }
- if (!donothing) {
- if (lseek(f, 0, SEEK_SET) < 0) {
- perror("lseek");
- return (1);
- }
- if (write(f, boot, lp->d_bbsize) != lp->d_bbsize) {
- perror("write");
- return (1);
- }
- }
- /*
- * Output the remainder of the disklabel
- */
- if (!donothing && bootbuf && write(f, bootbuf, bootsize) != bootsize) {
- perror("write");
- return(1);
- }
- } else
-#endif /* NUMBOOT > 0 */
if (!donothing) {
if (ioctl(f, DIOCWDINFO, lp) < 0) {
l_perror("ioctl DIOCWDINFO");
{
struct disklabel *lp;
char *p;
-#if NUMBOOT > 0
- char *dkbasename;
- int b;
- struct stat sb;
-#endif
/* XXX */
if (dp->d_secsize == 0) {
lp = (struct disklabel *)
(boot + (LABELSECTOR * dp->d_secsize) + LABELOFFSET);
memset(lp, 0, sizeof *lp);
-#if NUMBOOT > 0
- /*
- * If we are not installing a boot program but we are installing a
- * label on disk then we must read the current bootarea so we don't
- * clobber the existing boot.
- */
- if (!installboot)
- return (lp);
- /*
- * We are installing a boot program. Determine the name(s) and
- * read them into the appropriate places in the boot area.
- */
- if (!xxboot) {
- dkbasename = np;
- if ((p = strrchr(dkname, '/')) == NULL)
- p = dkname;
- else
- p++;
- while (*p && !isdigit((unsigned char)*p))
- *np++ = *p++;
- *np++ = '\0';
-
- (void)snprintf(np, namebuf + sizeof namebuf - np,
- "%s%sboot", _PATH_BOOTDIR, dkbasename);
- if (access(np, F_OK) < 0 && dkbasename[0] == 'r')
- dkbasename++;
- xxboot = np;
- (void)snprintf(xxboot,
- namebuf + sizeof namebuf - np,
- "%s%sboot", _PATH_BOOTDIR, dkbasename);
- np += strlen(xxboot) + 1;
- }
- if (verbose)
- warnx("bootstrap: xxboot = %s", xxboot);
-
- /*
- * For NUMBOOT > 0 architectures (vax)
- * up to d_bbsize bytes of ``xxboot'' go in bootarea, the rest
- * is remembered and written later following the bootarea.
- */
- b = open(xxboot, O_RDONLY);
- if (b < 0)
- err(4, "%s", xxboot);
- if (read(b, boot, (int)dp->d_bbsize) < 0)
- err(4, "%s", xxboot);
- (void)fstat(b, &sb);
- bootsize = (int)sb.st_size - dp->d_bbsize;
- if (bootsize > 0) {
- /* XXX assume d_secsize is a power of two */
- bootsize = (bootsize + dp->d_secsize-1) & ~(dp->d_secsize-1);
- bootbuf = malloc((size_t)bootsize);
- if (bootbuf == NULL)
- err(4, "%s", xxboot);
- if (read(b, bootbuf, bootsize) < 0) {
- free(bootbuf);
- err(4, "%s", xxboot);
- }
- }
- (void)close(b);
-#endif
/*
* Make sure no part of the bootstrap is written in the area
* reserved for the label.
return (errors > 0);
}
-#if NUMBOOT > 0
-/*
- * If we are installing a boot program that doesn't fit in d_bbsize
- * we need to mark those partitions that the boot overflows into.
- * This allows newfs to prevent creation of a filesystem where it might
- * clobber bootstrap code.
- */
-void
-setbootflag(struct disklabel *lp)
-{
- struct partition *pp;
- int i, errors = 0;
- u_int64_t bend;
- char part;
-
- if (bootbuf == NULL)
- return;
-
- bend = (u_int64_t)bootsize / lp->d_secsize;
- for (i = 0; i < lp->d_npartitions; 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 (bend <= DL_GETPOFFSET(pp)) {
- /* Boot blocks end before this partition starts. */
- if (pp->p_fstype == FS_BOOT)
- pp->p_fstype = FS_UNUSED;
- 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)
- errx(4, "cannot install boot program");
-}
-#endif
-
int
cmplabel(struct disklabel *lp1, struct disklabel *lp2)
{
"\n");
fprintf(stderr,
" disklabel -R [-nv] [-F|-f file] disk protofile\t\t(restore)\n\n");
-#if NUMBOOT > 0
- fprintf(stderr,
- " disklabel -B [-nv] [-b boot1] disk [disktype]\t\t(boot)\n");
- fprintf(stderr,
- " disklabel -Bw [-nv] [-b boot1] disk disktype [packid]\t"
- "(boot+write)\n");
- fprintf(stderr,
- " disklabel -BR [-nv] [-F|-f file ] [-b boot1] disk protofile\t\t"
- "(boot+restore)\n\n");
-#endif
fprintf(stderr,
"`disk' may be of the form: sd0 or /dev/rsd0%c.\n", 'a'+RAW_PART);
fprintf(stderr,