2001-06-15 22:49:37 +04:00
|
|
|
/* $NetBSD: disklabel.c,v 1.98 2001/06/15 18:49:37 nonaka Exp $ */
|
1995-03-18 17:54:19 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1994-06-24 17:48:17 +04:00
|
|
|
* Copyright (c) 1987, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Symmetric Computer Systems.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1997-07-01 02:51:27 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifndef lint
|
1997-07-01 02:51:27 +04:00
|
|
|
__COPYRIGHT("@(#) Copyright (c) 1987, 1993\n\
|
|
|
|
The Regents of the University of California. All rights reserved.\n");
|
2000-12-24 08:59:11 +03:00
|
|
|
#endif /* not lint */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
#ifndef lint
|
1995-03-18 17:54:19 +03:00
|
|
|
#if 0
|
1997-09-16 06:43:59 +04:00
|
|
|
static char sccsid[] = "@(#)disklabel.c 8.4 (Berkeley) 5/4/95";
|
1994-06-24 17:48:17 +04:00
|
|
|
/* from static char sccsid[] = "@(#)disklabel.c 1.2 (Symmetric) 11/28/85"; */
|
1995-03-18 17:54:19 +03:00
|
|
|
#else
|
2001-06-15 22:49:37 +04:00
|
|
|
__RCSID("$NetBSD: disklabel.c,v 1.98 2001/06/15 18:49:37 nonaka Exp $");
|
1995-03-18 17:54:19 +03:00
|
|
|
#endif
|
2000-12-24 08:59:11 +03:00
|
|
|
#endif /* not lint */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/ioctl.h>
|
1994-06-24 17:48:17 +04:00
|
|
|
#include <sys/stat.h>
|
1994-12-05 23:15:31 +03:00
|
|
|
#include <sys/wait.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#define DKTYPENAMES
|
1998-11-12 19:19:47 +03:00
|
|
|
#define FSTYPENAMES
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <sys/disklabel.h>
|
1994-09-30 05:33:15 +03:00
|
|
|
|
1997-09-16 06:43:59 +04:00
|
|
|
#include <ufs/ufs/dinode.h>
|
1994-06-24 17:48:17 +04:00
|
|
|
#include <ufs/ffs/fs.h>
|
1994-09-30 05:33:15 +03:00
|
|
|
|
|
|
|
#include <ctype.h>
|
1994-09-23 02:03:52 +04:00
|
|
|
#include <err.h>
|
1995-06-27 03:17:26 +04:00
|
|
|
#include <errno.h>
|
1994-06-24 17:48:17 +04:00
|
|
|
#include <unistd.h>
|
1995-06-27 03:17:26 +04:00
|
|
|
#include <signal.h>
|
1994-06-24 17:48:17 +04:00
|
|
|
#include <string.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <stdio.h>
|
1994-09-30 05:33:15 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
1997-09-25 09:08:28 +04:00
|
|
|
#include <util.h>
|
1997-07-01 02:51:27 +04:00
|
|
|
|
1999-01-19 09:24:08 +03:00
|
|
|
#include <disktab.h>
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
#include "pathnames.h"
|
1997-03-09 02:46:08 +03:00
|
|
|
#include "extern.h"
|
1997-07-01 02:51:27 +04:00
|
|
|
#include "dkcksum.h"
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Disklabel: read and write disklabels.
|
|
|
|
* The label is usually placed on one of the first sectors of the disk.
|
1994-06-24 17:48:17 +04:00
|
|
|
* Many machines also place a bootstrap in the same area,
|
1993-03-21 12:45:37 +03:00
|
|
|
* in which case the label is embedded in the bootstrap.
|
|
|
|
* The bootstrap source must leave space at the proper offset
|
|
|
|
* for the label on such machines.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef BBSIZE
|
|
|
|
#define BBSIZE 8192 /* size of boot area, with label */
|
|
|
|
#endif
|
|
|
|
|
1994-06-24 17:48:17 +04:00
|
|
|
#ifndef NUMBOOT
|
|
|
|
#define NUMBOOT 0
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define DEFEDITOR _PATH_VI
|
|
|
|
|
1996-10-02 17:49:44 +04:00
|
|
|
static char *dkname;
|
1999-07-21 21:56:34 +04:00
|
|
|
static char tmpfil[MAXPATHLEN];
|
1996-10-02 17:49:44 +04:00
|
|
|
|
|
|
|
static char namebuf[BBSIZE], *np = namebuf;
|
|
|
|
static struct disklabel lab;
|
2000-12-24 10:08:02 +03:00
|
|
|
|
|
|
|
char bootarea[BBSIZE];
|
|
|
|
char *specname;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-06-24 17:48:17 +04:00
|
|
|
|
|
|
|
#if NUMBOOT > 0
|
1996-10-02 17:49:44 +04:00
|
|
|
static int installboot; /* non-zero if we should install a boot program */
|
|
|
|
static char *bootbuf; /* pointer to buffer with remainder of boot prog */
|
|
|
|
static int bootsize; /* size of remaining boot program */
|
|
|
|
static char *xxboot; /* primary boot */
|
|
|
|
static char *bootxx; /* secondary boot */
|
|
|
|
static char boot0[MAXPATHLEN];
|
1997-07-10 12:30:47 +04:00
|
|
|
#if NUMBOOT > 1
|
1996-10-02 17:49:44 +04:00
|
|
|
static char boot1[MAXPATHLEN];
|
2000-12-24 08:59:11 +03:00
|
|
|
#endif /* NUMBOOT > 1 */
|
|
|
|
#endif /* NUMBOOT > 0 */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1996-10-02 17:49:44 +04:00
|
|
|
static enum {
|
1997-03-09 02:46:08 +03:00
|
|
|
UNSPEC, EDIT, READ, RESTORE, SETWRITEABLE, WRITE, WRITEBOOT, INTERACT
|
1994-06-24 17:48:17 +04:00
|
|
|
} op = UNSPEC;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2000-12-24 10:08:02 +03:00
|
|
|
static int rflag;
|
|
|
|
static int tflag;
|
|
|
|
int Cflag;
|
|
|
|
static int Iflag;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
1996-10-02 17:49:44 +04:00
|
|
|
static int debug;
|
2000-05-31 18:13:48 +04:00
|
|
|
#define OPTIONS "BCINRWb:def:irs:tw"
|
2000-12-24 08:59:11 +03:00
|
|
|
#else /* ! DEBUG */
|
2000-05-31 18:13:48 +04:00
|
|
|
#define OPTIONS "BCINRWb:ef:irs:tw"
|
2000-12-24 08:59:11 +03:00
|
|
|
#endif /* ! DEBUG */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2000-01-31 19:01:06 +03:00
|
|
|
#ifdef USE_MBR
|
2000-12-24 08:59:11 +03:00
|
|
|
static struct mbr_partition *dosdp; /* i386 DOS partition, if found */
|
|
|
|
static int mbrpt_nobsd; /*
|
|
|
|
* MBR partition table exists,
|
|
|
|
* but no BSD partition
|
|
|
|
*/
|
|
|
|
static struct mbr_partition *readmbr(int);
|
|
|
|
#endif /* USE_MBR */
|
|
|
|
|
1997-10-18 01:29:36 +04:00
|
|
|
#ifdef __arm32__
|
2000-12-24 08:59:11 +03:00
|
|
|
static u_int filecore_partition_offset;
|
|
|
|
static u_int get_filecore_partition(int);
|
|
|
|
static int filecore_checksum(u_char *);
|
1997-10-18 01:29:36 +04:00
|
|
|
#endif /* __arm32__ */
|
2000-12-24 08:59:11 +03:00
|
|
|
|
2000-01-31 19:01:06 +03:00
|
|
|
#if defined(USE_MBR) || (defined(__arm32__) && defined(notyet))
|
2000-12-24 08:59:11 +03:00
|
|
|
static void confirm(const char *);
|
1998-03-25 03:03:19 +03:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2000-12-24 08:59:11 +03:00
|
|
|
int main(int, char *[]);
|
|
|
|
|
|
|
|
static void makedisktab(FILE *, struct disklabel *);
|
|
|
|
static void makelabel(const char *, const char *,
|
|
|
|
struct disklabel *);
|
|
|
|
static void l_perror(const char *);
|
|
|
|
static struct disklabel *readlabel(int);
|
|
|
|
static struct disklabel *makebootarea(char *, struct disklabel *, int);
|
|
|
|
static int edit(struct disklabel *, int);
|
|
|
|
static int editit(void);
|
|
|
|
static char *skip(char *);
|
|
|
|
static char *word(char *);
|
|
|
|
static int getasciilabel(FILE *, struct disklabel *);
|
1997-07-01 02:51:27 +04:00
|
|
|
#if NUMBOOT > 0
|
2000-12-24 08:59:11 +03:00
|
|
|
static void setbootflag(struct disklabel *);
|
1997-07-01 02:51:27 +04:00
|
|
|
#endif
|
2000-12-24 08:59:11 +03:00
|
|
|
static void usage(void);
|
1994-12-05 23:15:31 +03:00
|
|
|
|
1994-09-30 05:33:15 +03:00
|
|
|
int
|
2000-12-24 08:59:11 +03:00
|
|
|
main(int argc, char *argv[])
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-09-30 05:33:15 +03:00
|
|
|
struct disklabel *lp;
|
2000-12-24 08:59:11 +03:00
|
|
|
FILE *t;
|
|
|
|
int ch, f, writeable, error;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2000-12-24 08:59:11 +03:00
|
|
|
error = 0;
|
1994-09-23 02:03:52 +04:00
|
|
|
while ((ch = getopt(argc, argv, OPTIONS)) != -1)
|
1993-03-21 12:45:37 +03:00
|
|
|
switch (ch) {
|
1994-06-24 17:48:17 +04:00
|
|
|
#if NUMBOOT > 0
|
1994-09-30 05:33:15 +03:00
|
|
|
case 'B':
|
|
|
|
++installboot;
|
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
xxboot = optarg;
|
|
|
|
break;
|
1994-06-24 17:48:17 +04:00
|
|
|
#if NUMBOOT > 1
|
1994-09-30 05:33:15 +03:00
|
|
|
case 's':
|
|
|
|
bootxx = optarg;
|
|
|
|
break;
|
2000-12-24 08:59:11 +03:00
|
|
|
#endif /* NUMBOOT > 1 */
|
|
|
|
#endif /* NUMBOOT > 0 */
|
1996-06-29 19:50:16 +04:00
|
|
|
case 'C':
|
|
|
|
++Cflag;
|
|
|
|
break;
|
2000-05-31 18:13:48 +04:00
|
|
|
case 'I':
|
|
|
|
++Iflag;
|
|
|
|
break;
|
1994-09-30 05:33:15 +03:00
|
|
|
case 'N':
|
|
|
|
if (op != UNSPEC)
|
|
|
|
usage();
|
|
|
|
writeable = 0;
|
|
|
|
op = SETWRITEABLE;
|
|
|
|
break;
|
|
|
|
case 'R':
|
|
|
|
if (op != UNSPEC)
|
|
|
|
usage();
|
|
|
|
op = RESTORE;
|
|
|
|
break;
|
|
|
|
case 'W':
|
|
|
|
if (op != UNSPEC)
|
|
|
|
usage();
|
|
|
|
writeable = 1;
|
|
|
|
op = SETWRITEABLE;
|
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
if (op != UNSPEC)
|
|
|
|
usage();
|
|
|
|
op = EDIT;
|
|
|
|
break;
|
1999-01-19 09:24:08 +03:00
|
|
|
case 'f':
|
|
|
|
if (setdisktab(optarg) == -1)
|
|
|
|
usage();
|
|
|
|
break;
|
1997-03-09 02:46:08 +03:00
|
|
|
case 'i':
|
|
|
|
if (op != UNSPEC)
|
|
|
|
usage();
|
|
|
|
op = INTERACT;
|
|
|
|
break;
|
1996-10-02 17:49:44 +04:00
|
|
|
case 't':
|
|
|
|
++tflag;
|
|
|
|
break;
|
1994-09-30 05:33:15 +03:00
|
|
|
case 'r':
|
|
|
|
++rflag;
|
|
|
|
break;
|
|
|
|
case 'w':
|
|
|
|
if (op != UNSPEC)
|
|
|
|
usage();
|
|
|
|
op = WRITE;
|
|
|
|
break;
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifdef DEBUG
|
1994-09-30 05:33:15 +03:00
|
|
|
case 'd':
|
|
|
|
debug++;
|
|
|
|
break;
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif
|
1994-09-30 05:33:15 +03:00
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
1994-09-30 05:33:15 +03:00
|
|
|
|
1994-06-24 17:48:17 +04:00
|
|
|
#if NUMBOOT > 0
|
|
|
|
if (installboot) {
|
|
|
|
rflag++;
|
|
|
|
if (op == UNSPEC)
|
|
|
|
op = WRITEBOOT;
|
|
|
|
} else {
|
|
|
|
if (op == UNSPEC)
|
|
|
|
op = READ;
|
|
|
|
}
|
2000-12-24 08:59:11 +03:00
|
|
|
#else /* NUMBOOT <= 0 */
|
1993-03-21 12:45:37 +03:00
|
|
|
if (op == UNSPEC)
|
|
|
|
op = READ;
|
2000-12-24 08:59:11 +03:00
|
|
|
#endif /* NUMBOOT <= 0 */
|
1994-09-30 05:33:15 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
if (argc < 1)
|
|
|
|
usage();
|
|
|
|
|
2000-10-09 03:32:50 +04:00
|
|
|
if (Iflag && op != EDIT && op != INTERACT)
|
2000-05-31 18:13:48 +04:00
|
|
|
usage();
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
dkname = argv[0];
|
1997-09-25 09:08:28 +04:00
|
|
|
f = opendisk(dkname, op == READ ? O_RDONLY : O_RDWR, np, MAXPATHLEN, 0);
|
|
|
|
specname = np;
|
|
|
|
np += strlen(specname) + 1;
|
1993-03-21 12:45:37 +03:00
|
|
|
if (f < 0)
|
1994-09-23 02:03:52 +04:00
|
|
|
err(4, "%s", specname);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2000-01-31 19:01:06 +03:00
|
|
|
#ifdef USE_MBR
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Check for presence of DOS partition table in
|
1993-12-06 12:37:30 +03:00
|
|
|
* master boot record. Return pointer to NetBSD/i386
|
1998-03-02 19:26:47 +03:00
|
|
|
* partition, if present.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
dosdp = readmbr(f);
|
2001-06-15 22:49:37 +04:00
|
|
|
if (dosdp) {
|
|
|
|
dosdp->mbrp_start = le32toh(dosdp->mbrp_start);
|
|
|
|
dosdp->mbrp_size = le32toh(dosdp->mbrp_size);
|
|
|
|
}
|
2000-12-24 08:59:11 +03:00
|
|
|
#endif /* USE_MBR */
|
|
|
|
|
1997-10-18 01:29:36 +04:00
|
|
|
#ifdef __arm32__
|
|
|
|
/*
|
|
|
|
* Check for the presence of a RiscOS filecore boot block
|
|
|
|
* indicating an ADFS file system on the disc.
|
|
|
|
* Return the offset to the NetBSD part of the disc if
|
|
|
|
* this can be determined.
|
|
|
|
* This routine will terminate disklabel if the disc
|
|
|
|
* is found to be ADFS only.
|
|
|
|
*/
|
|
|
|
filecore_partition_offset = get_filecore_partition(f);
|
|
|
|
#endif /* __arm32__ */
|
2000-12-24 08:59:11 +03:00
|
|
|
|
1994-09-30 05:33:15 +03:00
|
|
|
switch (op) {
|
1994-06-24 17:48:17 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
case EDIT:
|
|
|
|
if (argc != 1)
|
|
|
|
usage();
|
|
|
|
lp = readlabel(f);
|
|
|
|
error = edit(lp, f);
|
|
|
|
break;
|
1994-06-24 17:48:17 +04:00
|
|
|
|
1997-03-09 02:46:08 +03:00
|
|
|
case INTERACT:
|
|
|
|
if (argc != 1)
|
|
|
|
usage();
|
|
|
|
lp = readlabel(f);
|
|
|
|
/*
|
|
|
|
* XXX: Fill some default values so checklabel does not fail
|
|
|
|
*/
|
|
|
|
if (lp->d_bbsize == 0)
|
|
|
|
lp->d_bbsize = BBSIZE;
|
|
|
|
if (lp->d_sbsize == 0)
|
|
|
|
lp->d_sbsize = SBSIZE;
|
|
|
|
interact(lp, f);
|
|
|
|
break;
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
case READ:
|
|
|
|
if (argc != 1)
|
|
|
|
usage();
|
|
|
|
lp = readlabel(f);
|
1996-10-02 17:49:44 +04:00
|
|
|
if (tflag)
|
|
|
|
makedisktab(stdout, lp);
|
1999-05-03 13:45:01 +04:00
|
|
|
else {
|
2000-12-24 10:08:02 +03:00
|
|
|
showinfo(stdout, lp, specname);
|
|
|
|
showpartitions(stdout, lp, Cflag);
|
1999-05-03 13:45:01 +04:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
error = checklabel(lp);
|
|
|
|
break;
|
1994-06-24 17:48:17 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
case RESTORE:
|
1994-09-30 05:33:15 +03:00
|
|
|
if (argc < 2 || argc > 3)
|
|
|
|
usage();
|
1994-06-24 17:48:17 +04:00
|
|
|
#if NUMBOOT > 0
|
1994-09-30 05:33:15 +03:00
|
|
|
if (installboot && argc == 3)
|
|
|
|
makelabel(argv[2], (char *)0, &lab);
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif
|
1994-06-24 17:48:17 +04:00
|
|
|
lp = makebootarea(bootarea, &lab, f);
|
|
|
|
if (!(t = fopen(argv[1], "r")))
|
1994-09-23 02:03:52 +04:00
|
|
|
err(4, "%s", argv[1]);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (getasciilabel(t, lp))
|
|
|
|
error = writelabel(f, bootarea, lp);
|
|
|
|
break;
|
1994-06-24 17:48:17 +04:00
|
|
|
|
1994-09-30 05:33:15 +03:00
|
|
|
case SETWRITEABLE:
|
|
|
|
if (ioctl(f, DIOCWLABEL, (char *)&writeable) < 0)
|
|
|
|
err(4, "ioctl DIOCWLABEL");
|
|
|
|
break;
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
case WRITE:
|
1994-09-30 05:33:15 +03:00
|
|
|
if (argc < 2 || argc > 3)
|
1993-03-21 12:45:37 +03:00
|
|
|
usage();
|
1994-09-30 05:33:15 +03:00
|
|
|
makelabel(argv[1], argc == 3 ? argv[2] : (char *)0, &lab);
|
1994-06-24 17:48:17 +04:00
|
|
|
lp = makebootarea(bootarea, &lab, f);
|
1993-03-21 12:45:37 +03:00
|
|
|
*lp = lab;
|
|
|
|
if (checklabel(lp) == 0)
|
|
|
|
error = writelabel(f, bootarea, lp);
|
1999-04-09 14:06:18 +04:00
|
|
|
else
|
|
|
|
error = 1;
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
1994-06-24 17:48:17 +04:00
|
|
|
|
|
|
|
case WRITEBOOT:
|
1997-07-01 02:51:27 +04:00
|
|
|
#if NUMBOOT > 0
|
1994-06-24 17:48:17 +04:00
|
|
|
{
|
|
|
|
struct disklabel tlab;
|
|
|
|
|
|
|
|
lp = readlabel(f);
|
|
|
|
tlab = *lp;
|
|
|
|
if (argc == 2)
|
1994-09-30 05:33:15 +03:00
|
|
|
makelabel(argv[1], (char *)0, &lab);
|
1994-06-24 17:48:17 +04:00
|
|
|
lp = makebootarea(bootarea, &lab, f);
|
|
|
|
*lp = tlab;
|
|
|
|
if (checklabel(lp) == 0)
|
|
|
|
error = writelabel(f, bootarea, lp);
|
1999-04-09 14:06:18 +04:00
|
|
|
else
|
|
|
|
error = 1;
|
1994-06-24 17:48:17 +04:00
|
|
|
break;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2000-12-24 08:59:11 +03:00
|
|
|
#endif /* NUMBOOT > 0 */
|
|
|
|
|
1996-10-02 17:49:44 +04:00
|
|
|
case UNSPEC:
|
|
|
|
usage();
|
2000-12-24 08:59:11 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1999-04-09 14:06:18 +04:00
|
|
|
exit(error);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Construct a prototype disklabel from /etc/disktab. As a side
|
|
|
|
* effect, set the names of the primary and secondary boot files
|
|
|
|
* if specified.
|
|
|
|
*/
|
1996-10-02 17:49:44 +04:00
|
|
|
static void
|
2000-12-24 08:59:11 +03:00
|
|
|
makelabel(const char *type, const char *name, struct disklabel *lp)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-09-30 05:33:15 +03:00
|
|
|
struct disklabel *dp;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
dp = getdiskbyname(type);
|
1994-09-23 02:03:52 +04:00
|
|
|
if (dp == NULL)
|
|
|
|
errx(1, "unknown disk type: %s", type);
|
1993-03-21 12:45:37 +03:00
|
|
|
*lp = *dp;
|
2000-12-24 08:59:11 +03:00
|
|
|
|
1994-06-24 17:48:17 +04:00
|
|
|
#if NUMBOOT > 0
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1994-06-24 17:48:17 +04:00
|
|
|
* 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
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
if (!xxboot && lp->d_boot0) {
|
|
|
|
if (*lp->d_boot0 != '/')
|
1994-06-24 17:48:17 +04:00
|
|
|
(void)sprintf(boot0, "%s/%s",
|
|
|
|
_PATH_BOOTDIR, lp->d_boot0);
|
1993-03-21 12:45:37 +03:00
|
|
|
else
|
|
|
|
(void)strcpy(boot0, lp->d_boot0);
|
|
|
|
xxboot = boot0;
|
|
|
|
}
|
2000-12-24 08:59:11 +03:00
|
|
|
|
1994-06-24 17:48:17 +04:00
|
|
|
#if NUMBOOT > 1
|
1993-03-21 12:45:37 +03:00
|
|
|
if (!bootxx && lp->d_boot1) {
|
|
|
|
if (*lp->d_boot1 != '/')
|
1994-06-24 17:48:17 +04:00
|
|
|
(void)sprintf(boot1, "%s/%s",
|
|
|
|
_PATH_BOOTDIR, lp->d_boot1);
|
1993-03-21 12:45:37 +03:00
|
|
|
else
|
|
|
|
(void)strcpy(boot1, lp->d_boot1);
|
|
|
|
bootxx = boot1;
|
|
|
|
}
|
2000-12-24 08:59:11 +03:00
|
|
|
#endif /* NUMBOOT > 1 */
|
|
|
|
#endif /* NUMBOOT > 0 */
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/* d_packname is union d_boot[01], so zero */
|
1996-10-02 17:49:44 +04:00
|
|
|
(void) memset(lp->d_packname, 0, sizeof(lp->d_packname));
|
1993-03-21 12:45:37 +03:00
|
|
|
if (name)
|
|
|
|
(void)strncpy(lp->d_packname, name, sizeof(lp->d_packname));
|
|
|
|
}
|
|
|
|
|
2000-01-31 19:01:06 +03:00
|
|
|
#if defined(USE_MBR) || (defined(__arm32__) && defined(notyet))
|
1998-03-02 19:26:47 +03:00
|
|
|
static void
|
2000-12-24 08:59:11 +03:00
|
|
|
confirm(const char *txt)
|
1998-03-02 19:26:47 +03:00
|
|
|
{
|
2000-12-24 08:59:11 +03:00
|
|
|
int first, ch;
|
1998-03-02 19:26:47 +03:00
|
|
|
|
1998-03-25 03:03:19 +03:00
|
|
|
(void) printf("%s? [n]: ", txt);
|
1998-03-02 19:26:47 +03:00
|
|
|
(void) fflush(stdout);
|
|
|
|
first = ch = getchar();
|
|
|
|
while (ch != '\n' && ch != EOF)
|
|
|
|
ch = getchar();
|
|
|
|
if (first != 'y' && first != 'Y')
|
|
|
|
exit(0);
|
|
|
|
}
|
2000-12-24 08:59:11 +03:00
|
|
|
#endif /* USE_MBR || __arm32__ && notyet */
|
1998-03-02 19:26:47 +03:00
|
|
|
|
1997-03-09 02:46:08 +03:00
|
|
|
int
|
2000-12-24 08:59:11 +03:00
|
|
|
writelabel(int f, const char *boot, struct disklabel *lp)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2000-12-24 08:59:11 +03:00
|
|
|
int writeable;
|
|
|
|
off_t sectoffset;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2000-12-24 08:59:11 +03:00
|
|
|
sectoffset = 0;
|
1994-06-24 17:48:17 +04:00
|
|
|
#if NUMBOOT > 0
|
|
|
|
setbootflag(lp);
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
lp->d_magic = DISKMAGIC;
|
|
|
|
lp->d_magic2 = DISKMAGIC;
|
|
|
|
lp->d_checksum = 0;
|
|
|
|
lp->d_checksum = dkcksum(lp);
|
1997-10-20 00:45:42 +04:00
|
|
|
|
|
|
|
#ifdef __sparc__
|
|
|
|
/* Let the kernel deal with SunOS disklabel compatibility */
|
1999-09-17 22:30:33 +04:00
|
|
|
if (0)
|
2000-12-24 08:59:11 +03:00
|
|
|
#else /* ! __sparc__ */
|
2000-05-31 18:13:48 +04:00
|
|
|
if (rflag || Iflag)
|
2000-12-24 08:59:11 +03:00
|
|
|
#endif /* ! __sparc__ */
|
1999-09-17 22:30:33 +04:00
|
|
|
{
|
2000-01-31 19:01:06 +03:00
|
|
|
#ifdef USE_MBR
|
1994-07-21 01:22:03 +04:00
|
|
|
struct partition *pp = &lp->d_partitions[2];
|
1994-09-30 05:33:15 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
2001-01-03 09:55:30 +03:00
|
|
|
* If NetBSD/i386 DOS partition is missing, or if
|
1993-03-21 12:45:37 +03:00
|
|
|
* the label to be written is not within partition,
|
|
|
|
* prompt first. Need to allow this in case operator
|
|
|
|
* wants to convert the drive for dedicated use.
|
|
|
|
*/
|
1998-03-02 19:26:47 +03:00
|
|
|
if (dosdp) {
|
2000-05-26 01:23:37 +04:00
|
|
|
if (dosdp->mbrp_start != pp->p_offset) {
|
|
|
|
printf("NetBSD slice at %u, "
|
|
|
|
"partition C at %u\n", dosdp->mbrp_start,
|
|
|
|
pp->p_offset);
|
1998-03-25 03:03:19 +03:00
|
|
|
confirm("Write outside MBR partition");
|
2000-05-26 01:23:37 +04:00
|
|
|
}
|
1998-08-04 15:52:52 +04:00
|
|
|
sectoffset = (off_t)pp->p_offset * lp->d_secsize;
|
1993-03-21 12:45:37 +03:00
|
|
|
} else {
|
1998-03-02 19:26:47 +03:00
|
|
|
if (mbrpt_nobsd)
|
1998-08-04 15:52:52 +04:00
|
|
|
confirm("Erase the previous contents"
|
|
|
|
" of the disk");
|
1994-07-21 01:22:03 +04:00
|
|
|
sectoffset = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2000-12-24 08:59:11 +03:00
|
|
|
#endif /* USE_MBR */
|
|
|
|
|
1997-10-18 01:29:36 +04:00
|
|
|
#ifdef __arm32__
|
1998-03-25 03:03:19 +03:00
|
|
|
/* XXX */
|
1998-08-04 15:52:52 +04:00
|
|
|
sectoffset = (off_t)filecore_partition_offset * DEV_BSIZE;
|
1997-10-18 01:29:36 +04:00
|
|
|
#endif /* __arm32__ */
|
2000-12-24 08:59:11 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* 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 (ioctl(f, DIOCSDINFO, lp) < 0 &&
|
|
|
|
errno != ENODEV && errno != ENOTTY) {
|
|
|
|
l_perror("ioctl DIOCSDINFO");
|
1994-06-24 17:48:17 +04:00
|
|
|
return (1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-09-30 05:33:15 +03:00
|
|
|
if (lseek(f, sectoffset, SEEK_SET) < 0) {
|
|
|
|
perror("lseek");
|
|
|
|
return (1);
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* write enable label sector before write (if necessary),
|
|
|
|
* disable after writing.
|
|
|
|
*/
|
1994-09-30 05:33:15 +03:00
|
|
|
writeable = 1;
|
|
|
|
if (ioctl(f, DIOCWLABEL, &writeable) < 0)
|
1993-03-21 12:45:37 +03:00
|
|
|
perror("ioctl DIOCWLABEL");
|
2000-12-24 08:59:11 +03:00
|
|
|
|
1995-03-23 02:48:49 +03:00
|
|
|
#ifdef __alpha__
|
|
|
|
/*
|
|
|
|
* The Alpha requires that the boot block be checksummed.
|
1999-04-05 06:50:52 +04:00
|
|
|
* The NetBSD/alpha disklabel.h provides a macro to do it.
|
1995-03-23 02:48:49 +03:00
|
|
|
*/
|
|
|
|
{
|
2000-12-24 08:59:11 +03:00
|
|
|
struct boot_block *bb;
|
1999-04-05 06:50:52 +04:00
|
|
|
|
2000-12-24 08:59:11 +03:00
|
|
|
bb = (struct boot_block *)boot;
|
1999-04-05 06:50:52 +04:00
|
|
|
CHECKSUM_BOOT_BLOCK(bb, &bb->bb_cksum);
|
1995-03-23 02:48:49 +03:00
|
|
|
}
|
2000-12-24 08:59:11 +03:00
|
|
|
#endif /* __alpha__ */
|
1997-10-20 00:45:42 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
if (write(f, boot, lp->d_bbsize) != lp->d_bbsize) {
|
|
|
|
perror("write");
|
|
|
|
return (1);
|
|
|
|
}
|
2000-12-24 08:59:11 +03:00
|
|
|
|
1994-06-24 17:48:17 +04:00
|
|
|
#if NUMBOOT > 0
|
|
|
|
/*
|
|
|
|
* Output the remainder of the disklabel
|
|
|
|
*/
|
|
|
|
if (bootbuf && write(f, bootbuf, bootsize) != bootsize) {
|
|
|
|
perror("write");
|
2000-12-24 08:59:11 +03:00
|
|
|
return (1);
|
1994-06-24 17:48:17 +04:00
|
|
|
}
|
2000-12-24 08:59:11 +03:00
|
|
|
#endif /* NUMBOOT > 0 */
|
1996-06-29 19:50:16 +04:00
|
|
|
|
1995-03-20 02:37:56 +03:00
|
|
|
writeable = 0;
|
|
|
|
if (ioctl(f, DIOCWLABEL, &writeable) < 0)
|
|
|
|
perror("ioctl DIOCWLABEL");
|
1995-03-22 12:14:34 +03:00
|
|
|
} else {
|
|
|
|
if (ioctl(f, DIOCWDINFO, lp) < 0) {
|
|
|
|
l_perror("ioctl DIOCWDINFO");
|
|
|
|
return (1);
|
|
|
|
}
|
1995-03-20 02:37:56 +03:00
|
|
|
}
|
2000-12-24 08:59:11 +03:00
|
|
|
|
1996-10-02 17:49:44 +04:00
|
|
|
#ifdef __vax__
|
1994-06-24 17:48:17 +04:00
|
|
|
if (lp->d_type == DTYPE_SMD && lp->d_flags & D_BADSECT) {
|
2000-12-24 08:59:11 +03:00
|
|
|
daddr_t alt;
|
|
|
|
int i;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
alt = lp->d_ncylinders * lp->d_secpercyl - lp->d_nsectors;
|
|
|
|
for (i = 1; i < 11 && i < lp->d_nsectors; i += 2) {
|
1998-08-04 15:52:52 +04:00
|
|
|
(void)lseek(f, (off_t)(alt + i) * lp->d_secsize,
|
1994-06-24 17:48:17 +04:00
|
|
|
SEEK_SET);
|
1994-09-23 02:03:52 +04:00
|
|
|
if (write(f, boot, lp->d_secsize) < lp->d_secsize)
|
|
|
|
warn("alternate label %d write", i/2);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
2000-12-24 08:59:11 +03:00
|
|
|
#endif /* __vax__ */
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1996-10-02 17:49:44 +04:00
|
|
|
static void
|
2000-12-24 08:59:11 +03:00
|
|
|
l_perror(const char *s)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
|
1994-09-23 02:03:52 +04:00
|
|
|
switch (errno) {
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
case ESRCH:
|
1994-09-23 02:03:52 +04:00
|
|
|
warnx("%s: No disk label on disk;\n"
|
2000-05-31 18:13:48 +04:00
|
|
|
"use \"disklabel -I\" to install initial label", s);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EINVAL:
|
1994-09-23 02:03:52 +04:00
|
|
|
warnx("%s: Label magic number or checksum is wrong!\n"
|
|
|
|
"(disklabel or kernel is out of date?)", s);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EBUSY:
|
1994-09-23 02:03:52 +04:00
|
|
|
warnx("%s: Open partition would move or shrink", s);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EXDEV:
|
1998-08-04 15:52:52 +04:00
|
|
|
warnx("%s: Labeled partition or 'a' partition must start"
|
|
|
|
" at beginning of disk", s);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1994-09-23 02:03:52 +04:00
|
|
|
warn("%s", s);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-01-31 19:01:06 +03:00
|
|
|
#ifdef USE_MBR
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Fetch DOS partition table from disk.
|
|
|
|
*/
|
1999-01-28 01:04:51 +03:00
|
|
|
static struct mbr_partition *
|
2000-12-24 08:59:11 +03:00
|
|
|
readmbr(int f)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2000-12-24 08:59:11 +03:00
|
|
|
struct mbr_partition *dp;
|
|
|
|
static char mbr[DEV_BSIZE];
|
|
|
|
u_int16_t *mbrmagicp;
|
|
|
|
int part;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2000-12-24 08:59:11 +03:00
|
|
|
dp = (struct mbr_partition *)&mbr[MBR_PARTOFF];
|
1999-01-28 01:04:51 +03:00
|
|
|
if (lseek(f, (off_t)MBR_BBSECTOR * DEV_BSIZE, SEEK_SET) < 0 ||
|
2001-03-29 16:18:32 +04:00
|
|
|
read(f, mbr, sizeof(mbr)) != sizeof(mbr)) {
|
|
|
|
warn("can't read master boot record");
|
|
|
|
return (0);
|
|
|
|
}
|
2001-01-03 09:55:30 +03:00
|
|
|
|
1999-10-11 09:28:04 +04:00
|
|
|
#if !defined(__i386__)
|
|
|
|
/* avoid alignment error */
|
|
|
|
memcpy(mbr, &mbr[MBR_PARTOFF], NMBRPART * sizeof(*dp));
|
|
|
|
dp = (struct mbr_partition *)mbr;
|
2000-12-24 08:59:11 +03:00
|
|
|
#endif /* ! __i386__ */
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Don't (yet) know disk geometry (BIOS), use
|
1993-12-06 12:37:30 +03:00
|
|
|
* partition table to find NetBSD/i386 partition, and obtain
|
1993-03-21 12:45:37 +03:00
|
|
|
* disklabel from there.
|
|
|
|
*/
|
1994-09-30 05:33:15 +03:00
|
|
|
/* Check if table is valid. */
|
1999-01-28 01:04:51 +03:00
|
|
|
mbrmagicp = (u_int16_t *)(&mbr[MBR_MAGICOFF]);
|
|
|
|
if (*mbrmagicp != MBR_MAGIC)
|
|
|
|
return (0);
|
1994-09-30 05:33:15 +03:00
|
|
|
/* Find NetBSD partition. */
|
1999-01-28 01:04:51 +03:00
|
|
|
for (part = 0; part < NMBRPART; part++) {
|
|
|
|
if (dp[part].mbrp_typ == MBR_PTYPE_NETBSD)
|
1994-09-30 05:33:15 +03:00
|
|
|
return (&dp[part]);
|
|
|
|
}
|
1998-03-02 19:26:47 +03:00
|
|
|
#ifdef COMPAT_386BSD_MBRPART
|
|
|
|
/* didn't find it -- look for 386BSD partition */
|
1999-01-28 01:04:51 +03:00
|
|
|
for (part = 0; part < NMBRPART; part++) {
|
|
|
|
if (dp[part].mbrp_typ == MBR_PTYPE_386BSD) {
|
1998-03-25 02:47:28 +03:00
|
|
|
warnx("old BSD partition ID!");
|
1994-09-30 05:33:15 +03:00
|
|
|
return (&dp[part]);
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2000-12-24 08:59:11 +03:00
|
|
|
#endif /* COMPAT_386BSD_MBRPART */
|
1998-03-02 19:26:47 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Table doesn't contain a partition for us. Keep a flag
|
|
|
|
* remembering us to warn before it is destroyed.
|
|
|
|
*/
|
|
|
|
mbrpt_nobsd = 1;
|
1994-09-30 05:33:15 +03:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2000-12-24 08:59:11 +03:00
|
|
|
#endif /* USE_MBR */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-18 01:29:36 +04:00
|
|
|
#ifdef __arm32__
|
|
|
|
/*
|
1998-06-08 00:33:22 +04:00
|
|
|
* static int filecore_checksum(u_char *bootblock)
|
1997-10-18 01:29:36 +04:00
|
|
|
*
|
|
|
|
* Calculates the filecore boot block checksum. This is used to validate
|
1998-06-08 00:33:22 +04:00
|
|
|
* a filecore boot block on the disk. If a boot block is validated then
|
1997-10-18 01:29:36 +04:00
|
|
|
* it is used to locate the partition table. If the boot block is not
|
1998-06-08 00:33:22 +04:00
|
|
|
* validated, it is assumed that the whole disk is NetBSD.
|
|
|
|
*
|
|
|
|
* The basic algorithm is:
|
|
|
|
*
|
|
|
|
* for (each byte in block, excluding checksum) {
|
|
|
|
* sum += byte;
|
|
|
|
* if (sum > 255)
|
|
|
|
* sum -= 255;
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* That's equivalent to summing all of the bytes in the block
|
|
|
|
* (excluding the checksum byte, of course), then calculating the
|
|
|
|
* checksum as "cksum = sum - ((sum - 1) / 255) * 255)". That
|
|
|
|
* expression may or may not yield a faster checksum function,
|
|
|
|
* but it's easier to reason about.
|
|
|
|
*
|
|
|
|
* Note that if you have a block filled with bytes of a single
|
|
|
|
* value "X" (regardless of that value!) and calculate the cksum
|
|
|
|
* of the block (excluding the checksum byte), you will _always_
|
|
|
|
* end up with a checksum of X. (Do the math; that can be derived
|
|
|
|
* from the checksum calculation function!) That means that
|
|
|
|
* blocks which contain bytes which all have the same value will
|
|
|
|
* always checksum properly. That's a _very_ unlikely occurence
|
|
|
|
* (probably impossible, actually) for a valid filecore boot block,
|
|
|
|
* so we treat such blocks as invalid.
|
1997-10-18 01:29:36 +04:00
|
|
|
*/
|
1998-06-08 00:33:22 +04:00
|
|
|
static int
|
2000-12-24 08:59:11 +03:00
|
|
|
filecore_checksum(u_char *bootblock)
|
1997-10-18 01:29:36 +04:00
|
|
|
{
|
2000-12-24 08:59:11 +03:00
|
|
|
u_char byte0, accum_diff;
|
|
|
|
u_int sum;
|
|
|
|
int i;
|
2001-01-03 09:55:30 +03:00
|
|
|
|
1997-10-18 01:29:36 +04:00
|
|
|
sum = 0;
|
1998-06-08 00:33:22 +04:00
|
|
|
accum_diff = 0;
|
|
|
|
byte0 = bootblock[0];
|
1997-10-18 01:29:36 +04:00
|
|
|
|
1998-06-08 00:33:22 +04:00
|
|
|
/*
|
|
|
|
* Sum the contents of the block, keeping track of whether
|
|
|
|
* or not all bytes are the same. If 'accum_diff' ends up
|
|
|
|
* being zero, all of the bytes are, in fact, the same.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < 511; ++i) {
|
|
|
|
sum += bootblock[i];
|
|
|
|
accum_diff |= bootblock[i] ^ byte0;
|
|
|
|
}
|
1997-10-18 01:29:36 +04:00
|
|
|
|
1998-06-08 00:33:22 +04:00
|
|
|
/*
|
|
|
|
* Check to see if the checksum byte is the same as the
|
|
|
|
* rest of the bytes, too. (Note that if all of the bytes
|
|
|
|
* are the same except the checksum, a checksum compare
|
|
|
|
* won't succeed, but that's not our problem.)
|
|
|
|
*/
|
|
|
|
accum_diff |= bootblock[i] ^ byte0;
|
1997-10-18 01:29:36 +04:00
|
|
|
|
1998-06-08 00:33:22 +04:00
|
|
|
/* All bytes in block are the same; call it invalid. */
|
|
|
|
if (accum_diff == 0)
|
|
|
|
return (-1);
|
1997-10-18 01:29:36 +04:00
|
|
|
|
1998-06-08 00:33:22 +04:00
|
|
|
return (sum - ((sum - 1) / 255) * 255);
|
1997-10-18 01:29:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fetch filecore bootblock from disk and analyse it
|
|
|
|
*/
|
|
|
|
static u_int
|
2000-12-24 08:59:11 +03:00
|
|
|
get_filecore_partition(int f)
|
1997-10-18 01:29:36 +04:00
|
|
|
{
|
2000-12-24 08:59:11 +03:00
|
|
|
struct filecore_bootblock *fcbb;
|
|
|
|
static char bb[DEV_BSIZE];
|
|
|
|
u_int offset;
|
1997-10-18 01:29:36 +04:00
|
|
|
|
|
|
|
if (lseek(f, (off_t)FILECORE_BOOT_SECTOR * DEV_BSIZE, SEEK_SET) < 0 ||
|
2001-01-03 09:57:57 +03:00
|
|
|
read(f, bb, sizeof(bb)) != sizeof(bb))
|
1997-10-18 01:29:36 +04:00
|
|
|
err(4, "can't read filecore boot block");
|
1998-03-25 02:45:31 +03:00
|
|
|
fcbb = (struct filecore_bootblock *)bb;
|
1997-10-18 01:29:36 +04:00
|
|
|
|
|
|
|
/* Check if table is valid. */
|
|
|
|
if (filecore_checksum(bb) != fcbb->checksum)
|
1998-03-25 02:45:31 +03:00
|
|
|
return (0);
|
1997-10-18 01:29:36 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for NetBSD/arm32 (RiscBSD) partition marker.
|
|
|
|
* If found the NetBSD disklabel location is easy.
|
|
|
|
*/
|
|
|
|
offset = (fcbb->partition_cyl_low + (fcbb->partition_cyl_high << 8))
|
|
|
|
* fcbb->heads * fcbb->secspertrack;
|
|
|
|
if (fcbb->partition_type == PARTITION_FORMAT_RISCBSD)
|
1998-03-25 02:45:31 +03:00
|
|
|
return (offset);
|
1997-10-18 01:29:36 +04:00
|
|
|
else if (fcbb->partition_type == PARTITION_FORMAT_RISCIX) {
|
2000-12-24 08:59:11 +03:00
|
|
|
struct riscix_partition_table *riscix_part;
|
|
|
|
int loop;
|
1998-03-25 02:45:31 +03:00
|
|
|
|
1997-10-18 01:29:36 +04:00
|
|
|
/*
|
1998-03-25 02:45:31 +03:00
|
|
|
* Read the RISCiX partition table and search for the
|
|
|
|
* first partition named "RiscBSD", "NetBSD", or "Empty:"
|
|
|
|
*
|
|
|
|
* XXX is use of 'Empty:' really desirable?! -- cgd
|
1997-10-18 01:29:36 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (lseek(f, (off_t)offset * DEV_BSIZE, SEEK_SET) < 0 ||
|
2001-01-03 09:57:57 +03:00
|
|
|
read(f, bb, sizeof(bb)) != sizeof(bb))
|
1997-10-18 01:29:36 +04:00
|
|
|
err(4, "can't read riscix partition table");
|
1998-03-25 02:45:31 +03:00
|
|
|
riscix_part = (struct riscix_partition_table *)bb;
|
1997-10-18 01:29:36 +04:00
|
|
|
|
|
|
|
for (loop = 0; loop < NRISCIX_PARTITIONS; ++loop) {
|
1998-03-25 02:45:31 +03:00
|
|
|
if (strcmp(riscix_part->partitions[loop].rp_name,
|
|
|
|
"RiscBSD") == 0 ||
|
|
|
|
strcmp(riscix_part->partitions[loop].rp_name,
|
|
|
|
"NetBSD") == 0 ||
|
|
|
|
strcmp(riscix_part->partitions[loop].rp_name,
|
|
|
|
"Empty:") == 0) {
|
1997-10-18 01:29:36 +04:00
|
|
|
offset = riscix_part->partitions[loop].rp_start;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (loop == NRISCIX_PARTITIONS) {
|
|
|
|
/*
|
|
|
|
* Valid filecore boot block, RISCiX partition table
|
1998-03-25 02:45:31 +03:00
|
|
|
* but no NetBSD partition. We should leave this
|
|
|
|
* disc alone.
|
1997-10-18 01:29:36 +04:00
|
|
|
*/
|
1998-08-04 15:52:52 +04:00
|
|
|
errx(4, "cannot label: no NetBSD partition found"
|
|
|
|
" in RISCiX partition table");
|
1997-10-18 01:29:36 +04:00
|
|
|
}
|
1998-03-25 02:45:31 +03:00
|
|
|
return (offset);
|
1997-10-18 01:29:36 +04:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Valid filecore boot block and no non-ADFS partition.
|
2001-01-03 09:55:30 +03:00
|
|
|
* This means that the whole disc is allocated for ADFS
|
1997-10-18 01:29:36 +04:00
|
|
|
* so do not trash ! If the user really wants to put a
|
|
|
|
* NetBSD disklabel on the disc then they should remove
|
|
|
|
* the filecore boot block first with dd.
|
|
|
|
*/
|
1998-08-04 15:52:52 +04:00
|
|
|
errx(4, "cannot label: filecore-only disk"
|
|
|
|
" (no non-ADFS partition)");
|
1997-10-18 01:29:36 +04:00
|
|
|
}
|
1998-03-25 02:45:31 +03:00
|
|
|
return (0);
|
1997-10-18 01:29:36 +04:00
|
|
|
}
|
|
|
|
#endif /* __arm32__ */
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Fetch disklabel for disk.
|
|
|
|
* Use ioctl to get label unless -r flag is given.
|
|
|
|
*/
|
1996-10-02 17:49:44 +04:00
|
|
|
static struct disklabel *
|
2000-12-24 08:59:11 +03:00
|
|
|
readlabel(int f)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-09-30 05:33:15 +03:00
|
|
|
struct disklabel *lp;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2000-05-31 18:13:48 +04:00
|
|
|
if (rflag || Iflag) {
|
2000-12-24 08:59:11 +03:00
|
|
|
char *msg;
|
|
|
|
off_t sectoffset;
|
|
|
|
|
|
|
|
msg = NULL;
|
|
|
|
sectoffset = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2000-01-31 19:01:06 +03:00
|
|
|
#ifdef USE_MBR
|
1998-03-02 19:26:47 +03:00
|
|
|
if (dosdp)
|
1999-01-28 01:04:51 +03:00
|
|
|
sectoffset = (off_t)dosdp->mbrp_start * DEV_BSIZE;
|
2000-12-24 08:59:11 +03:00
|
|
|
#endif /* USE_MBR */
|
|
|
|
|
1997-10-18 01:29:36 +04:00
|
|
|
#ifdef __arm32__
|
1998-03-25 03:03:19 +03:00
|
|
|
/* XXX */
|
1998-08-04 15:52:52 +04:00
|
|
|
sectoffset = (off_t)filecore_partition_offset * DEV_BSIZE;
|
1997-10-18 01:29:36 +04:00
|
|
|
#endif /* __arm32__ */
|
2000-12-24 08:59:11 +03:00
|
|
|
|
1994-09-30 05:33:15 +03:00
|
|
|
if (lseek(f, sectoffset, SEEK_SET) < 0 ||
|
2001-01-03 09:57:57 +03:00
|
|
|
read(f, bootarea, BBSIZE) != BBSIZE)
|
1994-09-23 02:03:52 +04:00
|
|
|
err(4, "%s", specname);
|
2001-01-08 05:19:58 +03:00
|
|
|
|
|
|
|
msg = "no disklabel";
|
1993-03-21 12:45:37 +03:00
|
|
|
for (lp = (struct disklabel *)bootarea;
|
|
|
|
lp <= (struct disklabel *)(bootarea + BBSIZE - sizeof(*lp));
|
1994-09-30 05:33:15 +03:00
|
|
|
lp = (struct disklabel *)((char *)lp + sizeof(long))) {
|
1993-03-21 12:45:37 +03:00
|
|
|
if (lp->d_magic == DISKMAGIC &&
|
1994-09-30 05:33:15 +03:00
|
|
|
lp->d_magic2 == DISKMAGIC) {
|
|
|
|
if (lp->d_npartitions <= MAXPARTITIONS &&
|
|
|
|
dkcksum(lp) == 0)
|
|
|
|
return (lp);
|
|
|
|
msg = "disk label corrupted";
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2001-01-08 05:19:58 +03:00
|
|
|
if (msg != NULL && !Iflag)
|
2000-07-07 16:29:09 +04:00
|
|
|
errx(1, "%s", msg);
|
2000-05-31 18:13:48 +04:00
|
|
|
/*
|
|
|
|
* There was no label on the disk. Get the fictious one
|
|
|
|
* as a basis for initialisation.
|
|
|
|
*/
|
|
|
|
lp = makebootarea(bootarea, &lab, f);
|
2001-01-08 05:19:58 +03:00
|
|
|
if (ioctl(f, DIOCGDINFO, lp) < 0 &&
|
|
|
|
ioctl(f, DIOCGDEFLABEL, lp) < 0)
|
|
|
|
errx(1, "could not get initial label");
|
1993-03-21 12:45:37 +03:00
|
|
|
} else {
|
|
|
|
lp = &lab;
|
|
|
|
if (ioctl(f, DIOCGDINFO, lp) < 0)
|
1994-09-23 02:03:52 +04:00
|
|
|
err(4, "ioctl DIOCGDINFO");
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
return (lp);
|
|
|
|
}
|
|
|
|
|
1994-06-24 17:48:17 +04:00
|
|
|
/*
|
|
|
|
* Construct a bootarea (d_bbsize bytes) in the specified buffer ``boot''
|
|
|
|
* Returns a pointer to the disklabel portion of the bootarea.
|
|
|
|
*/
|
1996-10-02 17:49:44 +04:00
|
|
|
static struct disklabel *
|
2000-12-24 08:59:11 +03:00
|
|
|
makebootarea(char *boot, struct disklabel *dp, int f)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
struct disklabel *lp;
|
2000-12-24 08:59:11 +03:00
|
|
|
char *p;
|
1994-06-24 17:48:17 +04:00
|
|
|
#if NUMBOOT > 0
|
2000-12-24 08:59:11 +03:00
|
|
|
int b;
|
|
|
|
char *dkbasename;
|
1996-10-02 17:49:44 +04:00
|
|
|
# if NUMBOOT <= 1
|
2000-12-24 08:59:11 +03:00
|
|
|
struct stat sb;
|
1996-10-02 17:49:44 +04:00
|
|
|
# endif
|
2000-12-24 08:59:11 +03:00
|
|
|
#endif /* NUMBOOT > 0 */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-06-24 17:48:17 +04:00
|
|
|
/* XXX */
|
|
|
|
if (dp->d_secsize == 0) {
|
|
|
|
dp->d_secsize = DEV_BSIZE;
|
|
|
|
dp->d_bbsize = BBSIZE;
|
|
|
|
}
|
|
|
|
lp = (struct disklabel *)
|
|
|
|
(boot + (LABELSECTOR * dp->d_secsize) + LABELOFFSET);
|
2000-08-15 02:37:08 +04:00
|
|
|
(void) memset(lp, 0, sizeof(*lp));
|
2000-12-24 08:59:11 +03:00
|
|
|
|
1999-06-03 05:58:51 +04:00
|
|
|
#ifdef SAVEBOOTAREA
|
|
|
|
/*
|
|
|
|
* We must read the current bootarea so we don't clobber the
|
|
|
|
* existing boot block, if any.
|
|
|
|
*/
|
2000-05-31 18:13:48 +04:00
|
|
|
if (rflag || Iflag) {
|
2000-12-24 08:59:11 +03:00
|
|
|
off_t sectoffset;
|
1999-06-03 05:58:51 +04:00
|
|
|
|
2000-12-24 08:59:11 +03:00
|
|
|
sectoffset = 0;
|
1999-06-03 05:58:51 +04:00
|
|
|
if (lseek(f, sectoffset, SEEK_SET) < 0 ||
|
2001-01-03 09:57:57 +03:00
|
|
|
read(f, boot, BBSIZE) != BBSIZE)
|
1999-06-03 05:58:51 +04:00
|
|
|
err(4, "%s", specname);
|
2000-08-15 02:37:08 +04:00
|
|
|
(void) memset(lp, 0, sizeof(*lp));
|
1999-06-03 05:58:51 +04:00
|
|
|
}
|
2000-12-24 08:59:11 +03:00
|
|
|
#endif /* SAVEBOOTAREA */
|
|
|
|
|
1994-06-24 17:48:17 +04:00
|
|
|
#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) {
|
2000-05-31 18:13:48 +04:00
|
|
|
if (rflag || Iflag) {
|
2000-12-24 08:59:11 +03:00
|
|
|
off_t sectoffset;
|
1998-03-26 04:35:17 +03:00
|
|
|
|
2000-12-24 08:59:11 +03:00
|
|
|
sectoffset = 0;
|
2000-01-31 19:01:06 +03:00
|
|
|
#ifdef USE_MBR
|
1998-03-26 04:35:17 +03:00
|
|
|
if (dosdp)
|
1999-01-28 01:04:51 +03:00
|
|
|
sectoffset = (off_t)dosdp->mbrp_start * DEV_BSIZE;
|
2000-12-24 08:59:11 +03:00
|
|
|
#endif /* USE_MBR */
|
|
|
|
|
1998-03-26 04:35:17 +03:00
|
|
|
#ifdef __arm32__
|
|
|
|
/* XXX */
|
1998-08-04 15:52:52 +04:00
|
|
|
sectoffset = (off_t)filecore_partition_offset
|
|
|
|
* DEV_BSIZE;
|
1998-03-26 04:35:17 +03:00
|
|
|
#endif /* __arm32__ */
|
2000-12-24 08:59:11 +03:00
|
|
|
|
1998-03-26 04:35:17 +03:00
|
|
|
if (lseek(f, sectoffset, SEEK_SET) < 0 ||
|
2001-01-03 09:57:57 +03:00
|
|
|
read(f, boot, BBSIZE) != BBSIZE)
|
1994-09-23 02:03:52 +04:00
|
|
|
err(4, "%s", specname);
|
2000-08-15 02:37:08 +04:00
|
|
|
(void) memset(lp, 0, sizeof(*lp));
|
1994-06-24 17:48:17 +04:00
|
|
|
}
|
|
|
|
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 || !bootxx) {
|
1993-03-21 12:45:37 +03:00
|
|
|
dkbasename = np;
|
1994-09-23 18:26:58 +04:00
|
|
|
if ((p = strrchr(dkname, '/')) == NULL)
|
1993-03-21 12:45:37 +03:00
|
|
|
p = dkname;
|
|
|
|
else
|
|
|
|
p++;
|
|
|
|
while (*p && !isdigit(*p))
|
|
|
|
*np++ = *p++;
|
|
|
|
*np++ = '\0';
|
|
|
|
|
1994-06-24 17:48:17 +04:00
|
|
|
if (!xxboot) {
|
|
|
|
(void)sprintf(np, "%s/%sboot",
|
|
|
|
_PATH_BOOTDIR, dkbasename);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (access(np, F_OK) < 0 && dkbasename[0] == 'r')
|
|
|
|
dkbasename++;
|
|
|
|
xxboot = np;
|
1994-06-24 17:48:17 +04:00
|
|
|
(void)sprintf(xxboot, "%s/%sboot",
|
|
|
|
_PATH_BOOTDIR, dkbasename);
|
1993-03-21 12:45:37 +03:00
|
|
|
np += strlen(xxboot) + 1;
|
|
|
|
}
|
1994-06-24 17:48:17 +04:00
|
|
|
#if NUMBOOT > 1
|
|
|
|
if (!bootxx) {
|
|
|
|
(void)sprintf(np, "%s/boot%s",
|
|
|
|
_PATH_BOOTDIR, dkbasename);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (access(np, F_OK) < 0 && dkbasename[0] == 'r')
|
|
|
|
dkbasename++;
|
|
|
|
bootxx = np;
|
1994-06-24 17:48:17 +04:00
|
|
|
(void)sprintf(bootxx, "%s/boot%s",
|
|
|
|
_PATH_BOOTDIR, dkbasename);
|
1993-03-21 12:45:37 +03:00
|
|
|
np += strlen(bootxx) + 1;
|
|
|
|
}
|
2000-12-24 08:59:11 +03:00
|
|
|
#endif /* NUMBOOT > 1 */
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2000-12-24 08:59:11 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (debug)
|
1994-09-23 02:03:52 +04:00
|
|
|
warnx("bootstraps: xxboot = %s, bootxx = %s", xxboot,
|
|
|
|
bootxx ? bootxx : "NONE");
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif
|
|
|
|
|
1994-06-24 17:48:17 +04:00
|
|
|
/*
|
|
|
|
* Strange rules:
|
|
|
|
* 1. One-piece bootstrap (hp300/hp800)
|
|
|
|
* up to d_bbsize bytes of ``xxboot'' go in bootarea, the rest
|
|
|
|
* is remembered and written later following the bootarea.
|
|
|
|
* 2. Two-piece bootstraps (vax/i386?/mips?)
|
|
|
|
* up to d_secsize bytes of ``xxboot'' go in first d_secsize
|
|
|
|
* bytes of bootarea, remaining d_bbsize-d_secsize filled
|
|
|
|
* from ``bootxx''.
|
|
|
|
*/
|
1993-03-21 12:45:37 +03:00
|
|
|
b = open(xxboot, O_RDONLY);
|
|
|
|
if (b < 0)
|
1994-09-23 02:03:52 +04:00
|
|
|
err(4, "%s", xxboot);
|
1994-06-24 17:48:17 +04:00
|
|
|
#if NUMBOOT > 1
|
1993-03-21 12:45:37 +03:00
|
|
|
if (read(b, boot, (int)dp->d_secsize) < 0)
|
1994-09-23 02:03:52 +04:00
|
|
|
err(4, "%s", xxboot);
|
1994-06-24 17:48:17 +04:00
|
|
|
(void)close(b);
|
1993-03-21 12:45:37 +03:00
|
|
|
b = open(bootxx, O_RDONLY);
|
|
|
|
if (b < 0)
|
1994-09-23 02:03:52 +04:00
|
|
|
err(4, "%s", bootxx);
|
1998-08-04 15:52:52 +04:00
|
|
|
if (read(b, &boot[dp->d_secsize],
|
|
|
|
(int)(dp->d_bbsize-dp->d_secsize)) < 0)
|
1994-09-23 02:03:52 +04:00
|
|
|
err(4, "%s", bootxx);
|
2000-12-24 08:59:11 +03:00
|
|
|
#else /* NUMBOOT <= 1 */
|
1994-06-24 17:48:17 +04:00
|
|
|
if (read(b, boot, (int)dp->d_bbsize) < 0)
|
1994-09-23 02:03:52 +04:00
|
|
|
err(4, "%s", xxboot);
|
1994-06-24 17:48:17 +04:00
|
|
|
(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 = (char *)malloc((size_t)bootsize);
|
|
|
|
if (bootbuf == 0)
|
1994-09-23 02:03:52 +04:00
|
|
|
err(4, "%s", xxboot);
|
1994-06-24 17:48:17 +04:00
|
|
|
if (read(b, bootbuf, bootsize) < 0) {
|
|
|
|
free(bootbuf);
|
1994-09-23 02:03:52 +04:00
|
|
|
err(4, "%s", xxboot);
|
1994-06-24 17:48:17 +04:00
|
|
|
}
|
|
|
|
}
|
2000-12-24 08:59:11 +03:00
|
|
|
#endif /* NUMBOOT <= 1 */
|
1993-03-21 12:45:37 +03:00
|
|
|
(void)close(b);
|
2000-12-24 08:59:11 +03:00
|
|
|
#endif /* NUMBOOT > 0 */
|
|
|
|
|
1994-06-24 17:48:17 +04:00
|
|
|
/*
|
|
|
|
* Make sure no part of the bootstrap is written in the area
|
|
|
|
* reserved for the label.
|
|
|
|
*/
|
1993-03-21 12:45:37 +03:00
|
|
|
for (p = (char *)lp; p < (char *)lp + sizeof(struct disklabel); p++)
|
1994-09-23 02:03:52 +04:00
|
|
|
if (*p)
|
|
|
|
errx(2, "Bootstrap doesn't leave room for disk label");
|
1993-03-21 12:45:37 +03:00
|
|
|
return (lp);
|
|
|
|
}
|
|
|
|
|
1996-10-02 17:49:44 +04:00
|
|
|
static void
|
2000-12-24 08:59:11 +03:00
|
|
|
makedisktab(FILE *f, struct disklabel *lp)
|
1996-10-02 17:49:44 +04:00
|
|
|
{
|
2000-12-24 08:59:11 +03:00
|
|
|
int i;
|
|
|
|
const char *did;
|
1996-10-02 17:49:44 +04:00
|
|
|
struct partition *pp;
|
|
|
|
|
2000-12-24 08:59:11 +03:00
|
|
|
did = "\\\n\t:";
|
1996-10-02 17:49:44 +04:00
|
|
|
(void) fprintf(f, "%.*s|Automatically generated label:\\\n\t:dt=",
|
1997-07-01 02:51:27 +04:00
|
|
|
(int) sizeof(lp->d_typename), lp->d_typename);
|
1996-10-02 17:49:44 +04:00
|
|
|
if ((unsigned) lp->d_type < DKMAXTYPES)
|
|
|
|
(void) fprintf(f, "%s:", dktypenames[lp->d_type]);
|
|
|
|
else
|
|
|
|
(void) fprintf(f, "unknown%d:", lp->d_type);
|
|
|
|
|
|
|
|
(void) fprintf(f, "se#%d:", lp->d_secsize);
|
|
|
|
(void) fprintf(f, "ns#%d:", lp->d_nsectors);
|
|
|
|
(void) fprintf(f, "nt#%d:", lp->d_ntracks);
|
|
|
|
(void) fprintf(f, "sc#%d:", lp->d_secpercyl);
|
|
|
|
(void) fprintf(f, "nc#%d:", lp->d_ncylinders);
|
|
|
|
|
1999-04-29 23:12:07 +04:00
|
|
|
if ((lp->d_secpercyl * lp->d_ncylinders) != lp->d_secperunit) {
|
|
|
|
(void) fprintf(f, "%ssu#%d:", did, lp->d_secperunit);
|
|
|
|
did = "";
|
|
|
|
}
|
1996-10-02 17:49:44 +04:00
|
|
|
if (lp->d_rpm != 3600) {
|
|
|
|
(void) fprintf(f, "%srm#%d:", did, lp->d_rpm);
|
|
|
|
did = "";
|
|
|
|
}
|
|
|
|
if (lp->d_interleave != 1) {
|
|
|
|
(void) fprintf(f, "%sil#%d:", did, lp->d_interleave);
|
|
|
|
did = "";
|
|
|
|
}
|
|
|
|
if (lp->d_trackskew != 0) {
|
|
|
|
(void) fprintf(f, "%ssk#%d:", did, lp->d_trackskew);
|
|
|
|
did = "";
|
|
|
|
}
|
|
|
|
if (lp->d_cylskew != 0) {
|
|
|
|
(void) fprintf(f, "%scs#%d:", did, lp->d_cylskew);
|
|
|
|
did = "";
|
|
|
|
}
|
|
|
|
if (lp->d_headswitch != 0) {
|
|
|
|
(void) fprintf(f, "%shs#%d:", did, lp->d_headswitch);
|
|
|
|
did = "";
|
|
|
|
}
|
|
|
|
if (lp->d_trkseek != 0) {
|
|
|
|
(void) fprintf(f, "%sts#%d:", did, lp->d_trkseek);
|
|
|
|
did = "";
|
|
|
|
}
|
|
|
|
#ifdef notyet
|
|
|
|
(void) 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++)
|
|
|
|
(void) fprintf(f, "%d ", lp->d_drivedata[j]);
|
2000-12-24 08:59:11 +03:00
|
|
|
#endif /* notyet */
|
1996-10-02 17:49:44 +04:00
|
|
|
pp = lp->d_partitions;
|
|
|
|
for (i = 0; i < lp->d_npartitions; i++, pp++) {
|
|
|
|
if (pp->p_size) {
|
|
|
|
char c = 'a' + i;
|
|
|
|
(void) fprintf(f, "\\\n\t:");
|
|
|
|
(void) fprintf(f, "p%c#%d:", c, pp->p_size);
|
|
|
|
(void) fprintf(f, "o%c#%d:", c, pp->p_offset);
|
|
|
|
if (pp->p_fstype != FS_UNUSED) {
|
|
|
|
if ((unsigned) pp->p_fstype < FSMAXTYPES)
|
2001-01-03 09:55:30 +03:00
|
|
|
(void) fprintf(f, "t%c=%s:", c,
|
1996-10-02 17:49:44 +04:00
|
|
|
fstypenames[pp->p_fstype]);
|
|
|
|
else
|
|
|
|
(void) fprintf(f, "t%c=unknown%d:",
|
|
|
|
c, pp->p_fstype);
|
|
|
|
}
|
|
|
|
switch (pp->p_fstype) {
|
|
|
|
|
|
|
|
case FS_UNUSED:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FS_BSDFFS:
|
1999-06-04 01:15:49 +04:00
|
|
|
case FS_BSDLFS:
|
Make BSDLFS a EXT2FS-like filesystem, that is, dont print or parse the cpg
field.
According to disklabel.h, its LFS semantics are "segment shift" (log2(segment
size)), but in the code it is used nowhere, and there are even plans to
allow non-poweroftwo segment sizes, so it won't ever work.
While at this, simplify the disktab-like output routine... here, currently,
BSDFFS, BSDLFS, EX2FS and ADOS do the same, so don't duplicate the code.
1999-06-04 23:02:34 +04:00
|
|
|
case FS_EX2FS:
|
1999-06-04 01:15:49 +04:00
|
|
|
case FS_ADOS:
|
1996-10-02 17:49:44 +04:00
|
|
|
(void) fprintf(f, "b%c#%d:", c,
|
|
|
|
pp->p_fsize * pp->p_frag);
|
|
|
|
(void) fprintf(f, "f%c#%d:", c, pp->p_fsize);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
(void) fprintf(f, "\n");
|
|
|
|
(void) fflush(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-12-24 08:59:11 +03:00
|
|
|
edit(struct disklabel *lp, int f)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
struct disklabel label;
|
1999-07-21 21:56:34 +04:00
|
|
|
const char *tmpdir;
|
2000-12-24 08:59:11 +03:00
|
|
|
int first, ch, fd;
|
|
|
|
FILE *fp;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1999-07-21 21:56:34 +04:00
|
|
|
if ((tmpdir = getenv("TMPDIR")) == NULL)
|
|
|
|
tmpdir = _PATH_TMP;
|
2000-08-15 02:37:08 +04:00
|
|
|
(void)snprintf(tmpfil, sizeof(tmpfil), "%s/%s", tmpdir, TMPFILE);
|
1997-03-16 08:25:38 +03:00
|
|
|
if ((fd = mkstemp(tmpfil)) == -1 || (fp = fdopen(fd, "w")) == NULL) {
|
1994-09-23 02:03:52 +04:00
|
|
|
warn("%s", tmpfil);
|
1993-03-21 12:45:37 +03:00
|
|
|
return (1);
|
|
|
|
}
|
1997-03-16 08:25:38 +03:00
|
|
|
(void)fchmod(fd, 0600);
|
2000-12-24 10:08:02 +03:00
|
|
|
showinfo(fp, lp, specname);
|
|
|
|
showpartitions(fp, lp, Cflag);
|
1997-03-16 08:25:38 +03:00
|
|
|
(void) fclose(fp);
|
1993-03-21 12:45:37 +03:00
|
|
|
for (;;) {
|
|
|
|
if (!editit())
|
|
|
|
break;
|
1997-03-16 08:25:38 +03:00
|
|
|
fp = fopen(tmpfil, "r");
|
|
|
|
if (fp == NULL) {
|
1994-09-23 02:03:52 +04:00
|
|
|
warn("%s", tmpfil);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
}
|
1996-10-02 17:49:44 +04:00
|
|
|
(void) memset(&label, 0, sizeof(label));
|
1997-03-16 08:25:38 +03:00
|
|
|
if (getasciilabel(fp, &label)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
*lp = label;
|
|
|
|
if (writelabel(f, bootarea, lp) == 0) {
|
|
|
|
(void) unlink(tmpfil);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
1996-10-02 17:49:44 +04:00
|
|
|
(void) printf("re-edit the label? [y]: ");
|
|
|
|
(void) fflush(stdout);
|
1994-09-30 05:33:15 +03:00
|
|
|
first = ch = getchar();
|
|
|
|
while (ch != '\n' && ch != EOF)
|
|
|
|
ch = getchar();
|
|
|
|
if (first == 'n' || first == 'N')
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
}
|
1995-01-30 23:14:10 +03:00
|
|
|
(void)unlink(tmpfil);
|
1993-03-21 12:45:37 +03:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
1996-10-02 17:49:44 +04:00
|
|
|
static int
|
2000-12-24 08:59:11 +03:00
|
|
|
editit(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-09-30 05:33:15 +03:00
|
|
|
int pid, xpid;
|
1995-04-30 02:42:07 +04:00
|
|
|
int stat;
|
1995-03-21 21:48:41 +03:00
|
|
|
sigset_t sigset, osigset;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1995-03-21 21:48:41 +03:00
|
|
|
sigemptyset(&sigset);
|
|
|
|
sigaddset(&sigset, SIGINT);
|
|
|
|
sigaddset(&sigset, SIGQUIT);
|
|
|
|
sigaddset(&sigset, SIGHUP);
|
|
|
|
sigprocmask(SIG_BLOCK, &sigset, &osigset);
|
1993-03-21 12:45:37 +03:00
|
|
|
while ((pid = fork()) < 0) {
|
|
|
|
if (errno != EAGAIN) {
|
1995-04-30 02:42:07 +04:00
|
|
|
sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0);
|
1994-09-23 02:03:52 +04:00
|
|
|
warn("fork");
|
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
sleep(1);
|
|
|
|
}
|
|
|
|
if (pid == 0) {
|
2000-05-27 23:01:13 +04:00
|
|
|
const char *ed;
|
|
|
|
char *buf;
|
|
|
|
int retval;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1995-04-30 02:42:07 +04:00
|
|
|
sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0);
|
1993-03-21 12:45:37 +03:00
|
|
|
setgid(getgid());
|
|
|
|
setuid(getuid());
|
|
|
|
if ((ed = getenv("EDITOR")) == (char *)0)
|
|
|
|
ed = DEFEDITOR;
|
2000-05-27 23:01:13 +04:00
|
|
|
/*
|
|
|
|
* Use system(3) in case someone's editor is "editor arg1 arg2".
|
|
|
|
*/
|
|
|
|
asprintf(&buf, "%s %s", ed, tmpfil);
|
|
|
|
retval = system(buf);
|
|
|
|
if (retval == -1)
|
|
|
|
perror(ed);
|
|
|
|
exit(retval);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
while ((xpid = wait(&stat)) >= 0)
|
|
|
|
if (xpid == pid)
|
|
|
|
break;
|
1995-04-30 02:42:07 +04:00
|
|
|
sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0);
|
2000-12-24 08:59:11 +03:00
|
|
|
return (!stat);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1996-10-02 17:49:44 +04:00
|
|
|
static char *
|
2000-12-24 08:59:11 +03:00
|
|
|
skip(char *cp)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
|
1994-09-30 05:33:15 +03:00
|
|
|
cp += strspn(cp, " \t");
|
|
|
|
if (*cp == '\0')
|
|
|
|
return (NULL);
|
1993-03-21 12:45:37 +03:00
|
|
|
return (cp);
|
|
|
|
}
|
|
|
|
|
1996-10-02 17:49:44 +04:00
|
|
|
static char *
|
2000-12-24 08:59:11 +03:00
|
|
|
word(char *cp)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2000-12-24 08:59:11 +03:00
|
|
|
|
1996-08-10 22:54:48 +04:00
|
|
|
if (cp == NULL || *cp == '\0')
|
|
|
|
return (NULL);
|
1994-09-30 05:33:15 +03:00
|
|
|
|
|
|
|
cp += strcspn(cp, " \t");
|
|
|
|
if (*cp == '\0')
|
|
|
|
return (NULL);
|
|
|
|
*cp++ = '\0';
|
|
|
|
cp += strspn(cp, " \t");
|
|
|
|
if (*cp == '\0')
|
|
|
|
return (NULL);
|
|
|
|
return (cp);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read an ascii label in from fd f,
|
1999-05-03 13:45:01 +04:00
|
|
|
* in the same format as that put out by showinfo() and showpartitions(),
|
1993-03-21 12:45:37 +03:00
|
|
|
* and fill in lp.
|
|
|
|
*/
|
1996-10-02 17:49:44 +04:00
|
|
|
static int
|
2000-12-24 08:59:11 +03:00
|
|
|
getasciilabel(FILE *f, struct disklabel *lp)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1998-07-26 16:00:43 +04:00
|
|
|
const char *const *cpp, *s;
|
1994-09-30 05:33:15 +03:00
|
|
|
struct partition *pp;
|
2000-12-24 08:59:11 +03:00
|
|
|
char *cp;
|
|
|
|
char *tp, line[BUFSIZ];
|
|
|
|
int v, lineno, errors;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2000-12-24 08:59:11 +03:00
|
|
|
lineno = 0;
|
|
|
|
errors = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
lp->d_bbsize = BBSIZE; /* XXX */
|
|
|
|
lp->d_sbsize = SBSIZE; /* XXX */
|
|
|
|
while (fgets(line, sizeof(line) - 1, f)) {
|
|
|
|
lineno++;
|
1996-10-02 17:49:44 +04:00
|
|
|
if ((cp = strpbrk(line, "#\r\n")) != NULL)
|
1993-03-21 12:45:37 +03:00
|
|
|
*cp = '\0';
|
|
|
|
cp = skip(line);
|
1996-08-10 22:54:48 +04:00
|
|
|
if (cp == NULL) /* blank line or comment line */
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
1996-08-10 22:54:48 +04:00
|
|
|
tp = strchr(cp, ':'); /* everything has a colon in it */
|
1993-03-21 12:45:37 +03:00
|
|
|
if (tp == NULL) {
|
1994-09-23 02:03:52 +04:00
|
|
|
warnx("line %d: syntax error", lineno);
|
1993-03-21 12:45:37 +03:00
|
|
|
errors++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
*tp++ = '\0', tp = skip(tp);
|
1994-09-30 05:33:15 +03:00
|
|
|
if (!strcmp(cp, "type")) {
|
1993-03-21 12:45:37 +03:00
|
|
|
if (tp == NULL)
|
|
|
|
tp = "unknown";
|
|
|
|
cpp = dktypenames;
|
|
|
|
for (; cpp < &dktypenames[DKMAXTYPES]; cpp++)
|
2000-08-15 02:37:08 +04:00
|
|
|
if ((s = *cpp) && !strcasecmp(s, tp)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
lp->d_type = cpp - dktypenames;
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
v = atoi(tp);
|
|
|
|
if ((unsigned)v >= DKMAXTYPES)
|
1994-09-23 02:03:52 +04:00
|
|
|
warnx("line %d: warning, unknown disk type: %s",
|
|
|
|
lineno, tp);
|
1993-03-21 12:45:37 +03:00
|
|
|
lp->d_type = v;
|
|
|
|
continue;
|
|
|
|
}
|
1994-09-30 05:33:15 +03:00
|
|
|
if (!strcmp(cp, "flags")) {
|
1993-03-21 12:45:37 +03:00
|
|
|
for (v = 0; (cp = tp) && *cp != '\0';) {
|
|
|
|
tp = word(cp);
|
2000-08-15 02:37:08 +04:00
|
|
|
if (!strcasecmp(cp, "removable"))
|
1993-03-21 12:45:37 +03:00
|
|
|
v |= D_REMOVABLE;
|
2000-08-15 02:37:08 +04:00
|
|
|
else if (!strcasecmp(cp, "ecc"))
|
1993-03-21 12:45:37 +03:00
|
|
|
v |= D_ECC;
|
2000-08-15 02:37:08 +04:00
|
|
|
else if (!strcasecmp(cp, "badsect"))
|
1993-03-21 12:45:37 +03:00
|
|
|
v |= D_BADSECT;
|
|
|
|
else {
|
1994-09-23 02:03:52 +04:00
|
|
|
warnx("line %d: bad flag: %s",
|
1993-03-21 12:45:37 +03:00
|
|
|
lineno, cp);
|
|
|
|
errors++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lp->d_flags = v;
|
|
|
|
continue;
|
|
|
|
}
|
1994-09-30 05:33:15 +03:00
|
|
|
if (!strcmp(cp, "drivedata")) {
|
|
|
|
int i;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
for (i = 0; (cp = tp) && *cp != '\0' && i < NDDATA;) {
|
|
|
|
lp->d_drivedata[i++] = atoi(cp);
|
|
|
|
tp = word(cp);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (sscanf(cp, "%d partitions", &v) == 1) {
|
|
|
|
if (v == 0 || (unsigned)v > MAXPARTITIONS) {
|
1994-09-23 02:03:52 +04:00
|
|
|
warnx("line %d: bad # of partitions", lineno);
|
1993-03-21 12:45:37 +03:00
|
|
|
lp->d_npartitions = MAXPARTITIONS;
|
|
|
|
errors++;
|
|
|
|
} else
|
|
|
|
lp->d_npartitions = v;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (tp == NULL)
|
|
|
|
tp = "";
|
1994-09-30 05:33:15 +03:00
|
|
|
if (!strcmp(cp, "disk")) {
|
2000-08-15 02:37:08 +04:00
|
|
|
strncpy(lp->d_typename, tp, sizeof(lp->d_typename));
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
}
|
1994-09-30 05:33:15 +03:00
|
|
|
if (!strcmp(cp, "label")) {
|
2000-08-15 02:37:08 +04:00
|
|
|
strncpy(lp->d_packname, tp, sizeof(lp->d_packname));
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
}
|
1994-09-30 05:33:15 +03:00
|
|
|
if (!strcmp(cp, "bytes/sector")) {
|
1993-03-21 12:45:37 +03:00
|
|
|
v = atoi(tp);
|
|
|
|
if (v <= 0 || (v % 512) != 0) {
|
1994-09-23 02:03:52 +04:00
|
|
|
warnx("line %d: bad %s: %s", lineno, cp, tp);
|
1993-03-21 12:45:37 +03:00
|
|
|
errors++;
|
|
|
|
} else
|
|
|
|
lp->d_secsize = v;
|
|
|
|
continue;
|
|
|
|
}
|
1994-09-30 05:33:15 +03:00
|
|
|
if (!strcmp(cp, "sectors/track")) {
|
1993-03-21 12:45:37 +03:00
|
|
|
v = atoi(tp);
|
|
|
|
if (v <= 0) {
|
1994-09-23 02:03:52 +04:00
|
|
|
warnx("line %d: bad %s: %s", lineno, cp, tp);
|
1993-03-21 12:45:37 +03:00
|
|
|
errors++;
|
|
|
|
} else
|
|
|
|
lp->d_nsectors = v;
|
|
|
|
continue;
|
|
|
|
}
|
1994-09-30 05:33:15 +03:00
|
|
|
if (!strcmp(cp, "sectors/cylinder")) {
|
1993-03-21 12:45:37 +03:00
|
|
|
v = atoi(tp);
|
|
|
|
if (v <= 0) {
|
1994-09-23 02:03:52 +04:00
|
|
|
warnx("line %d: bad %s: %s", lineno, cp, tp);
|
1993-03-21 12:45:37 +03:00
|
|
|
errors++;
|
|
|
|
} else
|
|
|
|
lp->d_secpercyl = v;
|
|
|
|
continue;
|
|
|
|
}
|
1994-09-30 05:33:15 +03:00
|
|
|
if (!strcmp(cp, "tracks/cylinder")) {
|
1993-03-21 12:45:37 +03:00
|
|
|
v = atoi(tp);
|
|
|
|
if (v <= 0) {
|
1994-09-23 02:03:52 +04:00
|
|
|
warnx("line %d: bad %s: %s", lineno, cp, tp);
|
1993-03-21 12:45:37 +03:00
|
|
|
errors++;
|
|
|
|
} else
|
|
|
|
lp->d_ntracks = v;
|
|
|
|
continue;
|
|
|
|
}
|
1994-09-30 05:33:15 +03:00
|
|
|
if (!strcmp(cp, "cylinders")) {
|
1993-03-21 12:45:37 +03:00
|
|
|
v = atoi(tp);
|
|
|
|
if (v <= 0) {
|
1994-09-23 02:03:52 +04:00
|
|
|
warnx("line %d: bad %s: %s", lineno, cp, tp);
|
1993-03-21 12:45:37 +03:00
|
|
|
errors++;
|
|
|
|
} else
|
|
|
|
lp->d_ncylinders = v;
|
|
|
|
continue;
|
|
|
|
}
|
1996-03-14 22:49:24 +03:00
|
|
|
if (!strcmp(cp, "total sectors")) {
|
|
|
|
v = atoi(tp);
|
|
|
|
if (v <= 0) {
|
|
|
|
warnx("line %d: bad %s: %s", lineno, cp, tp);
|
|
|
|
errors++;
|
|
|
|
} else
|
|
|
|
lp->d_secperunit = v;
|
|
|
|
continue;
|
|
|
|
}
|
1994-09-30 05:33:15 +03:00
|
|
|
if (!strcmp(cp, "rpm")) {
|
1993-03-21 12:45:37 +03:00
|
|
|
v = atoi(tp);
|
|
|
|
if (v <= 0) {
|
1994-09-23 02:03:52 +04:00
|
|
|
warnx("line %d: bad %s: %s", lineno, cp, tp);
|
1993-03-21 12:45:37 +03:00
|
|
|
errors++;
|
|
|
|
} else
|
|
|
|
lp->d_rpm = v;
|
|
|
|
continue;
|
|
|
|
}
|
1994-09-30 05:33:15 +03:00
|
|
|
if (!strcmp(cp, "interleave")) {
|
1993-03-21 12:45:37 +03:00
|
|
|
v = atoi(tp);
|
|
|
|
if (v <= 0) {
|
1994-09-23 02:03:52 +04:00
|
|
|
warnx("line %d: bad %s: %s", lineno, cp, tp);
|
1993-03-21 12:45:37 +03:00
|
|
|
errors++;
|
|
|
|
} else
|
|
|
|
lp->d_interleave = v;
|
|
|
|
continue;
|
|
|
|
}
|
1994-09-30 05:33:15 +03:00
|
|
|
if (!strcmp(cp, "trackskew")) {
|
1993-03-21 12:45:37 +03:00
|
|
|
v = atoi(tp);
|
|
|
|
if (v < 0) {
|
1994-09-23 02:03:52 +04:00
|
|
|
warnx("line %d: bad %s: %s", lineno, cp, tp);
|
1993-03-21 12:45:37 +03:00
|
|
|
errors++;
|
|
|
|
} else
|
|
|
|
lp->d_trackskew = v;
|
|
|
|
continue;
|
|
|
|
}
|
1994-09-30 05:33:15 +03:00
|
|
|
if (!strcmp(cp, "cylinderskew")) {
|
1993-03-21 12:45:37 +03:00
|
|
|
v = atoi(tp);
|
|
|
|
if (v < 0) {
|
1994-09-23 02:03:52 +04:00
|
|
|
warnx("line %d: bad %s: %s", lineno, cp, tp);
|
1993-03-21 12:45:37 +03:00
|
|
|
errors++;
|
|
|
|
} else
|
|
|
|
lp->d_cylskew = v;
|
|
|
|
continue;
|
|
|
|
}
|
1994-09-30 05:33:15 +03:00
|
|
|
if (!strcmp(cp, "headswitch")) {
|
1993-03-21 12:45:37 +03:00
|
|
|
v = atoi(tp);
|
|
|
|
if (v < 0) {
|
1994-09-23 02:03:52 +04:00
|
|
|
warnx("line %d: bad %s: %s", lineno, cp, tp);
|
1993-03-21 12:45:37 +03:00
|
|
|
errors++;
|
|
|
|
} else
|
|
|
|
lp->d_headswitch = v;
|
|
|
|
continue;
|
|
|
|
}
|
1994-09-30 05:33:15 +03:00
|
|
|
if (!strcmp(cp, "track-to-track seek")) {
|
1993-03-21 12:45:37 +03:00
|
|
|
v = atoi(tp);
|
|
|
|
if (v < 0) {
|
1994-09-23 02:03:52 +04:00
|
|
|
warnx("line %d: bad %s: %s", lineno, cp, tp);
|
1993-03-21 12:45:37 +03:00
|
|
|
errors++;
|
|
|
|
} else
|
|
|
|
lp->d_trkseek = v;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ('a' <= *cp && *cp <= 'z' && cp[1] == '\0') {
|
|
|
|
unsigned part = *cp - 'a';
|
|
|
|
|
|
|
|
if (part > lp->d_npartitions) {
|
1994-09-23 02:03:52 +04:00
|
|
|
warnx("line %d: bad partition name: %s",
|
|
|
|
lineno, cp);
|
1993-03-21 12:45:37 +03:00
|
|
|
errors++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
pp = &lp->d_partitions[part];
|
2000-12-24 08:59:11 +03:00
|
|
|
|
1996-06-29 19:50:16 +04:00
|
|
|
#define _CHECKLINE \
|
1996-08-10 22:54:48 +04:00
|
|
|
if (tp == NULL || *tp == '\0') { \
|
1994-09-30 05:33:15 +03:00
|
|
|
warnx("line %d: too few fields", lineno); \
|
|
|
|
errors++; \
|
|
|
|
break; \
|
1996-06-29 19:50:16 +04:00
|
|
|
}
|
2000-12-24 08:59:11 +03:00
|
|
|
|
|
|
|
#define NXTNUM(n) do { \
|
1996-06-29 19:50:16 +04:00
|
|
|
_CHECKLINE \
|
1996-08-10 22:54:48 +04:00
|
|
|
cp = tp, tp = word(cp), (n) = (cp != NULL ? atoi(cp) : 0); \
|
2000-12-24 08:59:11 +03:00
|
|
|
} while (/* CONSTCOND */ 0)
|
|
|
|
|
|
|
|
#define NXTXNUM(n) do { \
|
|
|
|
char *ptr; \
|
|
|
|
int m; \
|
|
|
|
\
|
1996-06-29 19:50:16 +04:00
|
|
|
_CHECKLINE \
|
|
|
|
cp = tp, tp = word(cp); \
|
1998-08-04 15:52:52 +04:00
|
|
|
m = (int)strtol(cp, &ptr, 10); \
|
1996-06-29 19:50:16 +04:00
|
|
|
if (*ptr == '\0') \
|
|
|
|
(n) = m; \
|
|
|
|
else { \
|
|
|
|
if (*ptr++ != '/') { \
|
|
|
|
warnx("line %d: invalid format", lineno); \
|
|
|
|
errors++; \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
(n) = m * lp->d_secpercyl; \
|
1998-08-04 15:52:52 +04:00
|
|
|
m = (int)strtol(ptr, &ptr, 10); \
|
1996-06-29 19:50:16 +04:00
|
|
|
if (*ptr++ != '/') { \
|
|
|
|
warnx("line %d: invalid format", lineno); \
|
|
|
|
errors++; \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
(n) += m * lp->d_nsectors; \
|
1998-08-04 15:52:52 +04:00
|
|
|
m = (int)strtol(ptr, &ptr, 10); \
|
1996-06-29 19:50:16 +04:00
|
|
|
(n) += m; \
|
|
|
|
} \
|
2000-12-24 08:59:11 +03:00
|
|
|
} while (/* CONSTCOND */ 0)
|
|
|
|
|
1996-06-29 19:50:16 +04:00
|
|
|
NXTXNUM(v);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (v < 0) {
|
1994-09-23 02:03:52 +04:00
|
|
|
warnx("line %d: bad partition size: %s",
|
1993-03-21 12:45:37 +03:00
|
|
|
lineno, cp);
|
|
|
|
errors++;
|
|
|
|
} else
|
|
|
|
pp->p_size = v;
|
1996-06-29 19:50:16 +04:00
|
|
|
NXTXNUM(v);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (v < 0) {
|
1994-09-23 02:03:52 +04:00
|
|
|
warnx("line %d: bad partition offset: %s",
|
1993-03-21 12:45:37 +03:00
|
|
|
lineno, cp);
|
|
|
|
errors++;
|
|
|
|
} else
|
|
|
|
pp->p_offset = v;
|
1998-08-04 15:52:52 +04:00
|
|
|
/* can't use word() here because of blanks
|
|
|
|
in fstypenames[] */
|
2001-01-03 09:55:30 +03:00
|
|
|
cp = tp;
|
1993-03-21 12:45:37 +03:00
|
|
|
cpp = fstypenames;
|
1997-10-13 13:53:26 +04:00
|
|
|
for (; cpp < &fstypenames[FSMAXTYPES]; cpp++) {
|
|
|
|
s = *cpp;
|
|
|
|
if (s == NULL ||
|
1998-08-04 15:52:52 +04:00
|
|
|
(cp[strlen(s)] != ' ' &&
|
|
|
|
cp[strlen(s)] != '\t' &&
|
1997-10-13 13:53:26 +04:00
|
|
|
cp[strlen(s)] != '\0'))
|
|
|
|
continue;
|
|
|
|
if (!memcmp(s, cp, strlen(s))) {
|
1993-03-21 12:45:37 +03:00
|
|
|
pp->p_fstype = cpp - fstypenames;
|
1997-10-13 13:53:26 +04:00
|
|
|
tp += strlen(s);
|
|
|
|
if (*tp == '\0')
|
|
|
|
tp = NULL;
|
|
|
|
else {
|
|
|
|
tp += strspn(tp, " \t");
|
|
|
|
if (*tp == '\0')
|
|
|
|
tp = NULL;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
goto gottype;
|
|
|
|
}
|
1997-10-13 13:53:26 +04:00
|
|
|
}
|
|
|
|
tp = word(cp);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (isdigit(*cp))
|
|
|
|
v = atoi(cp);
|
|
|
|
else
|
|
|
|
v = FSMAXTYPES;
|
|
|
|
if ((unsigned)v >= FSMAXTYPES) {
|
1998-08-04 15:52:52 +04:00
|
|
|
warnx("line %d: warning, unknown"
|
|
|
|
" filesystem type: %s",
|
1994-09-23 02:03:52 +04:00
|
|
|
lineno, cp);
|
1993-03-21 12:45:37 +03:00
|
|
|
v = FS_UNUSED;
|
|
|
|
}
|
|
|
|
pp->p_fstype = v;
|
2000-12-24 08:59:11 +03:00
|
|
|
gottype:
|
1993-03-21 12:45:37 +03:00
|
|
|
switch (pp->p_fstype) {
|
|
|
|
|
|
|
|
case FS_UNUSED: /* XXX */
|
|
|
|
NXTNUM(pp->p_fsize);
|
|
|
|
if (pp->p_fsize == 0)
|
|
|
|
break;
|
|
|
|
NXTNUM(v);
|
|
|
|
pp->p_frag = v / pp->p_fsize;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FS_BSDFFS:
|
1999-06-04 00:59:04 +04:00
|
|
|
case FS_ADOS:
|
1993-03-21 12:45:37 +03:00
|
|
|
NXTNUM(pp->p_fsize);
|
|
|
|
if (pp->p_fsize == 0)
|
|
|
|
break;
|
|
|
|
NXTNUM(v);
|
|
|
|
pp->p_frag = v / pp->p_fsize;
|
|
|
|
NXTNUM(pp->p_cpg);
|
|
|
|
break;
|
Make BSDLFS a EXT2FS-like filesystem, that is, dont print or parse the cpg
field.
According to disklabel.h, its LFS semantics are "segment shift" (log2(segment
size)), but in the code it is used nowhere, and there are even plans to
allow non-poweroftwo segment sizes, so it won't ever work.
While at this, simplify the disktab-like output routine... here, currently,
BSDFFS, BSDLFS, EX2FS and ADOS do the same, so don't duplicate the code.
1999-06-04 23:02:34 +04:00
|
|
|
case FS_BSDLFS:
|
2000-01-18 03:02:28 +03:00
|
|
|
NXTNUM(pp->p_fsize);
|
|
|
|
if (pp->p_fsize == 0)
|
|
|
|
break;
|
|
|
|
NXTNUM(v);
|
|
|
|
pp->p_frag = v / pp->p_fsize;
|
|
|
|
NXTNUM(pp->p_sgs);
|
|
|
|
break;
|
1997-10-13 13:53:26 +04:00
|
|
|
case FS_EX2FS:
|
|
|
|
NXTNUM(pp->p_fsize);
|
|
|
|
if (pp->p_fsize == 0)
|
|
|
|
break;
|
|
|
|
NXTNUM(v);
|
|
|
|
pp->p_frag = v / pp->p_fsize;
|
|
|
|
break;
|
1993-03-21 12:45:37 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
1994-09-23 02:03:52 +04:00
|
|
|
warnx("line %d: unknown field: %s", lineno, cp);
|
1993-03-21 12:45:37 +03:00
|
|
|
errors++;
|
2000-12-24 08:59:11 +03:00
|
|
|
next:
|
1993-03-21 12:45:37 +03:00
|
|
|
;
|
|
|
|
}
|
|
|
|
errors += checklabel(lp);
|
|
|
|
return (errors == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check disklabel for errors and fill in
|
|
|
|
* derived fields according to supplied values.
|
|
|
|
*/
|
1997-03-09 02:46:08 +03:00
|
|
|
int
|
2000-12-24 08:59:11 +03:00
|
|
|
checklabel(struct disklabel *lp)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-09-30 05:33:15 +03:00
|
|
|
struct partition *pp;
|
2000-12-24 08:59:11 +03:00
|
|
|
int i, errors;
|
|
|
|
char part;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2000-12-24 08:59:11 +03:00
|
|
|
errors = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
if (lp->d_secsize == 0) {
|
1994-09-23 02:03:52 +04:00
|
|
|
warnx("sector size %d", lp->d_secsize);
|
1993-03-21 12:45:37 +03:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
if (lp->d_nsectors == 0) {
|
1994-09-23 02:03:52 +04:00
|
|
|
warnx("sectors/track %d", lp->d_nsectors);
|
1993-03-21 12:45:37 +03:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
if (lp->d_ntracks == 0) {
|
1994-09-23 02:03:52 +04:00
|
|
|
warnx("tracks/cylinder %d", lp->d_ntracks);
|
1993-03-21 12:45:37 +03:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
if (lp->d_ncylinders == 0) {
|
1994-09-23 02:03:52 +04:00
|
|
|
warnx("cylinders/unit %d", lp->d_ncylinders);
|
1993-03-21 12:45:37 +03:00
|
|
|
errors++;
|
|
|
|
}
|
|
|
|
if (lp->d_rpm == 0)
|
1994-09-23 02:03:52 +04:00
|
|
|
warnx("warning, revolutions/minute %d", lp->d_rpm);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (lp->d_secpercyl == 0)
|
|
|
|
lp->d_secpercyl = lp->d_nsectors * lp->d_ntracks;
|
|
|
|
if (lp->d_secperunit == 0)
|
|
|
|
lp->d_secperunit = lp->d_secpercyl * lp->d_ncylinders;
|
1996-10-02 17:49:44 +04:00
|
|
|
#ifdef __i386__notyet__
|
1999-01-28 01:04:51 +03:00
|
|
|
if (dosdp && lp->d_secperunit > dosdp->mbrp_start + dosdp->mbrp_size) {
|
1994-09-23 02:03:52 +04:00
|
|
|
warnx("exceeds DOS partition size");
|
1993-03-21 12:45:37 +03:00
|
|
|
errors++;
|
1999-01-28 01:04:51 +03:00
|
|
|
lp->d_secperunit = dosdp->mbrp_start + dosdp->mbrp_size;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
/* XXX should also check geometry against BIOS's idea */
|
2000-12-24 08:59:11 +03:00
|
|
|
#endif /* __i386__notyet__ */
|
1998-03-25 03:03:19 +03:00
|
|
|
#ifdef __arm32__notyet__
|
|
|
|
/* XXX similar code as for i386 */
|
2000-12-24 08:59:11 +03:00
|
|
|
#endif /* __arm32__notyet__ */
|
1993-03-21 12:45:37 +03:00
|
|
|
if (lp->d_bbsize == 0) {
|
1994-09-23 02:03:52 +04:00
|
|
|
warnx("boot block size %d", lp->d_bbsize);
|
1993-03-21 12:45:37 +03:00
|
|
|
errors++;
|
|
|
|
} else if (lp->d_bbsize % lp->d_secsize)
|
1994-09-23 02:03:52 +04:00
|
|
|
warnx("warning, boot block size %% sector-size != 0");
|
1993-03-21 12:45:37 +03:00
|
|
|
if (lp->d_sbsize == 0) {
|
1994-09-23 02:03:52 +04:00
|
|
|
warnx("super block size %d", lp->d_sbsize);
|
1993-03-21 12:45:37 +03:00
|
|
|
errors++;
|
|
|
|
} else if (lp->d_sbsize % lp->d_secsize)
|
1994-09-23 02:03:52 +04:00
|
|
|
warnx("warning, super block size %% sector-size != 0");
|
1993-03-21 12:45:37 +03:00
|
|
|
if (lp->d_npartitions > MAXPARTITIONS)
|
1994-09-23 02:03:52 +04:00
|
|
|
warnx("warning, number of partitions (%d) > MAXPARTITIONS (%d)",
|
1993-03-21 12:45:37 +03:00
|
|
|
lp->d_npartitions, MAXPARTITIONS);
|
|
|
|
for (i = 0; i < lp->d_npartitions; i++) {
|
|
|
|
part = 'a' + i;
|
|
|
|
pp = &lp->d_partitions[i];
|
|
|
|
if (pp->p_size == 0 && pp->p_offset != 0)
|
1994-09-23 02:03:52 +04:00
|
|
|
warnx("warning, partition %c: size 0, but offset %d",
|
1993-03-21 12:45:37 +03:00
|
|
|
part, pp->p_offset);
|
1999-01-21 14:58:00 +03:00
|
|
|
#ifdef STRICT_CYLINDER_ALIGNMENT
|
|
|
|
if (pp->p_offset % lp->d_secpercyl) {
|
1998-08-04 15:52:52 +04:00
|
|
|
warnx("warning, partition %c:"
|
|
|
|
" offset %% cylinder-size != 0",
|
1993-03-21 12:45:37 +03:00
|
|
|
part);
|
1999-01-21 14:58:00 +03:00
|
|
|
errors++;
|
|
|
|
}
|
2000-12-24 08:59:11 +03:00
|
|
|
#endif /* STRICT_CYLINDER_ALIGNMENT */
|
1993-03-21 12:45:37 +03:00
|
|
|
if (pp->p_offset > lp->d_secperunit) {
|
1994-09-23 02:03:52 +04:00
|
|
|
warnx("partition %c: offset past end of unit", part);
|
1993-03-21 12:45:37 +03:00
|
|
|
errors++;
|
|
|
|
}
|
|
|
|
if (pp->p_offset + pp->p_size > lp->d_secperunit) {
|
1998-08-04 15:52:52 +04:00
|
|
|
warnx("partition %c: partition extends"
|
|
|
|
" past end of unit",
|
1993-03-21 12:45:37 +03:00
|
|
|
part);
|
|
|
|
errors++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (; i < MAXPARTITIONS; i++) {
|
|
|
|
part = 'a' + i;
|
|
|
|
pp = &lp->d_partitions[i];
|
|
|
|
if (pp->p_size || pp->p_offset)
|
1994-09-23 02:03:52 +04:00
|
|
|
warnx("warning, unused partition %c: size %d offset %d",
|
1993-03-21 12:45:37 +03:00
|
|
|
'a' + i, pp->p_size, pp->p_offset);
|
|
|
|
}
|
|
|
|
return (errors);
|
|
|
|
}
|
|
|
|
|
1994-06-24 17:48:17 +04:00
|
|
|
#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.
|
|
|
|
*/
|
1996-10-02 17:49:44 +04:00
|
|
|
static void
|
2000-12-24 08:59:11 +03:00
|
|
|
setbootflag(struct disklabel *lp)
|
1994-06-24 17:48:17 +04:00
|
|
|
{
|
1994-09-30 05:33:15 +03:00
|
|
|
struct partition *pp;
|
2000-12-24 08:59:11 +03:00
|
|
|
int i, errors;
|
|
|
|
char part;
|
|
|
|
u_long boffset;
|
1994-06-24 17:48:17 +04:00
|
|
|
|
2000-12-24 08:59:11 +03:00
|
|
|
errors = 0;
|
1994-06-24 17:48:17 +04:00
|
|
|
if (bootbuf == 0)
|
|
|
|
return;
|
|
|
|
boffset = bootsize / lp->d_secsize;
|
|
|
|
for (i = 0; i < lp->d_npartitions; i++) {
|
|
|
|
part = 'a' + i;
|
|
|
|
pp = &lp->d_partitions[i];
|
|
|
|
if (pp->p_size == 0)
|
|
|
|
continue;
|
|
|
|
if (boffset <= pp->p_offset) {
|
|
|
|
if (pp->p_fstype == FS_BOOT)
|
|
|
|
pp->p_fstype = FS_UNUSED;
|
|
|
|
} else if (pp->p_fstype != FS_BOOT) {
|
|
|
|
if (pp->p_fstype != FS_UNUSED) {
|
1994-09-23 02:03:52 +04:00
|
|
|
warnx("boot overlaps used partition %c",
|
|
|
|
part);
|
1994-06-24 17:48:17 +04:00
|
|
|
errors++;
|
|
|
|
} else {
|
|
|
|
pp->p_fstype = FS_BOOT;
|
1994-09-23 02:03:52 +04:00
|
|
|
warnx("warning, boot overlaps partition %c, %s",
|
|
|
|
part, "marked as FS_BOOT");
|
1994-06-24 17:48:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1994-09-23 02:03:52 +04:00
|
|
|
if (errors)
|
|
|
|
errx(4, "cannot install boot program");
|
1994-06-24 17:48:17 +04:00
|
|
|
}
|
2000-12-24 08:59:11 +03:00
|
|
|
#endif /* NUMBOOT > 0 */
|
1994-06-24 17:48:17 +04:00
|
|
|
|
1996-10-02 17:49:44 +04:00
|
|
|
static void
|
2000-12-24 08:59:11 +03:00
|
|
|
usage(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1996-10-02 17:49:44 +04:00
|
|
|
static const struct {
|
|
|
|
char *name;
|
|
|
|
char *expn;
|
|
|
|
} usages[] = {
|
2000-10-11 00:24:49 +04:00
|
|
|
{ "[-rt] [-C] disk",
|
1996-10-02 17:49:44 +04:00
|
|
|
"(to read label)" },
|
2000-10-11 00:24:49 +04:00
|
|
|
{ "-w [-r] [-f disktab] disk type [ packid ]",
|
1998-01-01 07:38:43 +03:00
|
|
|
#if NUMBOOT > 0
|
|
|
|
"(to write label with existing boot program)"
|
|
|
|
#else
|
|
|
|
"(to write label)"
|
|
|
|
#endif
|
|
|
|
},
|
2000-10-11 00:24:49 +04:00
|
|
|
{ "-e [-r] [-I] [-C] disk",
|
1996-10-02 17:49:44 +04:00
|
|
|
"(to edit label)" },
|
2000-10-11 00:24:49 +04:00
|
|
|
{ "-i [-I] [-r] disk",
|
1998-01-01 07:38:43 +03:00
|
|
|
"(to create a label interactively)" },
|
2000-10-11 00:24:49 +04:00
|
|
|
{ "-R [-r] disk protofile",
|
1998-01-01 07:38:43 +03:00
|
|
|
#if NUMBOOT > 0
|
|
|
|
"(to restore label with existing boot program)"
|
|
|
|
#else
|
|
|
|
"(to restore label)"
|
|
|
|
#endif
|
|
|
|
},
|
|
|
|
#if NUMBOOT > 0
|
1996-10-02 17:49:44 +04:00
|
|
|
# if NUMBOOT > 1
|
2000-10-11 00:24:49 +04:00
|
|
|
{ "-B [-f disktab] [ -b xxboot [ -s bootxx ] ] disk [ type ]",
|
1996-10-02 17:49:44 +04:00
|
|
|
"(to install boot program with existing label)" },
|
2000-10-11 00:24:49 +04:00
|
|
|
{ "-w -B [-f disktab] [ -b xxboot [ -s bootxx ] ] disk type [ packid ]",
|
1996-10-02 17:49:44 +04:00
|
|
|
"(to write label and boot program)" },
|
2000-10-11 00:24:49 +04:00
|
|
|
{ "-R -B [-f disktab] [ -b xxboot [ -s bootxx ] ] disk protofile [ type ]",
|
1996-10-02 17:49:44 +04:00
|
|
|
"(to restore label and boot program)" },
|
|
|
|
# else
|
2000-10-11 00:24:49 +04:00
|
|
|
{ "-B [-f disktab] [ -b bootprog ] disk [ type ]",
|
1996-10-21 01:59:36 +04:00
|
|
|
"(to install boot program with existing on-disk label)" },
|
2000-10-11 00:24:49 +04:00
|
|
|
{ "-w -B [-f disktab] [ -b bootprog ] disk type [ packid ]",
|
1996-10-02 17:49:44 +04:00
|
|
|
"(to write label and install boot program)" },
|
2000-10-11 00:24:49 +04:00
|
|
|
{ "-R -B [-f disktab] [ -b bootprog ] disk protofile [ type ]",
|
1996-10-02 17:49:44 +04:00
|
|
|
"(to restore label and install boot program)" },
|
1998-01-01 07:38:43 +03:00
|
|
|
# endif
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif
|
2000-10-11 00:24:49 +04:00
|
|
|
{ "[-NW] disk",
|
1996-10-02 17:49:44 +04:00
|
|
|
"(to write disable/enable label)" },
|
|
|
|
{ NULL,
|
|
|
|
NULL }
|
1998-01-01 07:38:43 +03:00
|
|
|
};
|
1996-10-02 17:49:44 +04:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; usages[i].name; i++) {
|
|
|
|
(void) fputs(i ? "or " : "Usage: ", stderr);
|
2001-02-20 01:48:57 +03:00
|
|
|
(void) fprintf(stderr, "%s %s", getprogname(), usages[i].name);
|
1996-10-02 17:49:44 +04:00
|
|
|
(void) fputs("\n\t", stderr);
|
2001-02-20 01:48:57 +03:00
|
|
|
(void) fprintf(stderr, "%s %s", getprogname(), usages[i].expn);
|
1996-10-02 17:49:44 +04:00
|
|
|
(void) fputs("\n", stderr);
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
exit(1);
|
|
|
|
}
|