bsdlabel.c revision 37865
1/*
2 * Copyright (c) 1987, 1993
3 *	The Regents of the University of California.  All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Symmetric Computer Systems.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 *    must display the following acknowledgement:
18 *	This product includes software developed by the University of
19 *	California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 *    may be used to endorse or promote products derived from this software
22 *    without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37#ifndef lint
38static const char copyright[] =
39"@(#) Copyright (c) 1987, 1993\n\
40	The Regents of the University of California.  All rights reserved.\n";
41#endif /* not lint */
42
43#ifndef lint
44#if 0
45static char sccsid[] = "@(#)disklabel.c	8.2 (Berkeley) 1/7/94";
46/* from static char sccsid[] = "@(#)disklabel.c	1.2 (Symmetric) 11/28/85"; */
47#endif
48static const char rcsid[] =
49	"$Id: disklabel.c,v 1.16 1998/07/20 11:34:06 bde Exp $";
50#endif /* not lint */
51
52#include <sys/param.h>
53#include <sys/errno.h>
54#include <sys/file.h>
55#include <sys/stat.h>
56#include <sys/wait.h>
57#define DKTYPENAMES
58#include <sys/disklabel.h>
59#include <ufs/ffs/fs.h>
60#include <unistd.h>
61#include <string.h>
62#include <stdio.h>
63#include <stdlib.h>
64#include <signal.h>
65#include <stdarg.h>
66#include <ctype.h>
67#include <err.h>
68#include "pathnames.h"
69
70/*
71 * Disklabel: read and write disklabels.
72 * The label is usually placed on one of the first sectors of the disk.
73 * Many machines also place a bootstrap in the same area,
74 * in which case the label is embedded in the bootstrap.
75 * The bootstrap source must leave space at the proper offset
76 * for the label on such machines.
77 */
78
79#ifdef tahoe
80#define RAWPARTITION	'a'
81#else
82#define RAWPARTITION	'c'
83#endif
84
85#ifndef BBSIZE
86#define	BBSIZE	8192			/* size of boot area, with label */
87#endif
88
89#ifdef tahoe
90#define	NUMBOOT	0
91#else
92#if defined(hp300) || defined(hp800)
93#define	NUMBOOT	1
94#else
95#define	NUMBOOT	2
96#endif
97#endif
98
99void	makelabel	__P((char *, char *, struct disklabel *));
100int	writelabel	__P((int, char *, struct disklabel *));
101void	l_perror	__P((char *));
102struct disklabel * readlabel __P((int));
103struct disklabel * makebootarea __P((char *, struct disklabel *, int));
104void	display		__P((FILE *, struct disklabel *));
105int	edit		__P((struct disklabel *, int));
106int	editit		__P((void));
107char *	skip		__P((char *));
108char *	word		__P((char *));
109int	getasciilabel	__P((FILE *, struct disklabel *));
110int	checklabel	__P((struct disklabel *));
111void	setbootflag	__P((struct disklabel *));
112void	Warning		(char *, ...);
113void	usage		__P((void));
114extern	u_short dkcksum __P((struct disklabel *));
115struct disklabel * getvirginlabel __P((void));
116
117#define	DEFEDITOR	_PATH_VI
118#define	streq(a,b)	(strcmp(a,b) == 0)
119
120char	*dkname;
121char	*specname;
122char	tmpfil[] = _PATH_TMP;
123
124char	namebuf[BBSIZE], *np = namebuf;
125struct	disklabel lab;
126struct	disklabel *readlabel(), *makebootarea();
127char	bootarea[BBSIZE];
128
129#if NUMBOOT > 0
130int	installboot;	/* non-zero if we should install a boot program */
131char	*bootbuf;	/* pointer to buffer with remainder of boot prog */
132int	bootsize;	/* size of remaining boot program */
133char	*xxboot;	/* primary boot */
134char	*bootxx;	/* secondary boot */
135char	boot0[MAXPATHLEN];
136char	boot1[MAXPATHLEN];
137#endif
138
139enum	{
140	UNSPEC, EDIT, NOWRITE, READ, RESTORE, WRITE, WRITEABLE, WRITEBOOT
141} op = UNSPEC;
142
143int	rflag;
144
145#ifdef DEBUG
146int	debug;
147#define OPTIONS	"BNRWb:ders:w"
148#else
149#define OPTIONS	"BNRWb:ers:w"
150#endif
151
152int
153main(argc, argv)
154	int argc;
155	char *argv[];
156{
157	register struct disklabel *lp;
158	FILE *t;
159	int ch, f, flag, error = 0;
160	char *name = 0;
161
162	while ((ch = getopt(argc, argv, OPTIONS)) != -1)
163		switch (ch) {
164#if NUMBOOT > 0
165			case 'B':
166				++installboot;
167				break;
168			case 'b':
169				xxboot = optarg;
170				break;
171#if NUMBOOT > 1
172			case 's':
173				bootxx = optarg;
174				break;
175#endif
176#endif
177			case 'N':
178				if (op != UNSPEC)
179					usage();
180				op = NOWRITE;
181				break;
182			case 'R':
183				if (op != UNSPEC)
184					usage();
185				op = RESTORE;
186				break;
187			case 'W':
188				if (op != UNSPEC)
189					usage();
190				op = WRITEABLE;
191				break;
192			case 'e':
193				if (op != UNSPEC)
194					usage();
195				op = EDIT;
196				break;
197			case 'r':
198				++rflag;
199				break;
200			case 'w':
201				if (op != UNSPEC)
202					usage();
203				op = WRITE;
204				break;
205#ifdef DEBUG
206			case 'd':
207				debug++;
208				break;
209#endif
210			case '?':
211			default:
212				usage();
213		}
214	argc -= optind;
215	argv += optind;
216#if NUMBOOT > 0
217	if (installboot) {
218		rflag++;
219		if (op == UNSPEC)
220			op = WRITEBOOT;
221	} else {
222		if (op == UNSPEC)
223			op = READ;
224		xxboot = bootxx = 0;
225	}
226#else
227	if (op == UNSPEC)
228		op = READ;
229#endif
230	if (argc < 1)
231		usage();
232
233	dkname = argv[0];
234	if (dkname[0] != '/') {
235		(void)sprintf(np, "%sr%s%c", _PATH_DEV, dkname, RAWPARTITION);
236		specname = np;
237		np += strlen(specname) + 1;
238	} else
239		specname = dkname;
240	f = open(specname, op == READ ? O_RDONLY : O_RDWR);
241	if (f < 0 && errno == ENOENT && dkname[0] != '/') {
242		(void)sprintf(specname, "%sr%s", _PATH_DEV, dkname);
243		np = namebuf + strlen(specname) + 1;
244		f = open(specname, op == READ ? O_RDONLY : O_RDWR);
245	}
246	if (f < 0)
247		err(4, "%s", specname);
248
249	switch(op) {
250
251	case EDIT:
252		if (argc != 1)
253			usage();
254		lp = readlabel(f);
255		error = edit(lp, f);
256		break;
257
258	case NOWRITE:
259		flag = 0;
260		if (ioctl(f, DIOCWLABEL, (char *)&flag) < 0)
261			err(4, "ioctl DIOCWLABEL");
262		break;
263
264	case READ:
265		if (argc != 1)
266			usage();
267		lp = readlabel(f);
268		display(stdout, lp);
269		error = checklabel(lp);
270		break;
271
272	case RESTORE:
273#if NUMBOOT > 0
274		if (installboot && argc == 3) {
275			makelabel(argv[2], 0, &lab);
276			argc--;
277
278			/*
279			 * We only called makelabel() for its side effect
280			 * of setting the bootstrap file names.  Discard
281			 * all changes to `lab' so that all values in the
282			 * final label come from the ASCII label.
283			 */
284			bzero((char *)&lab, sizeof(lab));
285		}
286#endif
287		if (argc != 2)
288			usage();
289		if (!(t = fopen(argv[1], "r")))
290			err(4, "%s", argv[1]);
291		if (!getasciilabel(t, &lab))
292			exit(1);
293		lp = makebootarea(bootarea, &lab, f);
294		*lp = lab;
295		error = writelabel(f, bootarea, lp);
296		break;
297
298	case WRITE:
299		if (argc == 3) {
300			name = argv[2];
301			argc--;
302		}
303		if (argc != 2)
304			usage();
305		makelabel(argv[1], name, &lab);
306		lp = makebootarea(bootarea, &lab, f);
307		*lp = lab;
308		if (checklabel(lp) == 0)
309			error = writelabel(f, bootarea, lp);
310		break;
311
312	case WRITEABLE:
313		flag = 1;
314		if (ioctl(f, DIOCWLABEL, (char *)&flag) < 0)
315			err(4, "ioctl DIOCWLABEL");
316		break;
317
318#if NUMBOOT > 0
319	case WRITEBOOT:
320	{
321		struct disklabel tlab;
322
323		lp = readlabel(f);
324		tlab = *lp;
325		if (argc == 2)
326			makelabel(argv[1], 0, &lab);
327		lp = makebootarea(bootarea, &lab, f);
328		*lp = tlab;
329		if (checklabel(lp) == 0)
330			error = writelabel(f, bootarea, lp);
331		break;
332	}
333#endif
334	}
335	exit(error);
336}
337
338/*
339 * Construct a prototype disklabel from /etc/disktab.  As a side
340 * effect, set the names of the primary and secondary boot files
341 * if specified.
342 */
343void
344makelabel(type, name, lp)
345	char *type, *name;
346	register struct disklabel *lp;
347{
348	register struct disklabel *dp;
349
350	if (strcmp(type, "auto") == 0)
351		dp = getvirginlabel();
352	else
353		dp = getdiskbyname(type);
354	if (dp == NULL)
355		errx(1, "%s: unknown disk type", type);
356	*lp = *dp;
357#if NUMBOOT > 0
358	/*
359	 * Set bootstrap name(s).
360	 * 1. If set from command line, use those,
361	 * 2. otherwise, check if disktab specifies them (b0 or b1),
362	 * 3. otherwise, makebootarea() will choose ones based on the name
363	 *    of the disk special file. E.g. /dev/ra0 -> raboot, bootra
364	 */
365	if (!xxboot && lp->d_boot0) {
366		if (*lp->d_boot0 != '/')
367			(void)sprintf(boot0, "%s/%s",
368				      _PATH_BOOTDIR, lp->d_boot0);
369		else
370			(void)strcpy(boot0, lp->d_boot0);
371		xxboot = boot0;
372	}
373#if NUMBOOT > 1
374	if (!bootxx && lp->d_boot1) {
375		if (*lp->d_boot1 != '/')
376			(void)sprintf(boot1, "%s/%s",
377				      _PATH_BOOTDIR, lp->d_boot1);
378		else
379			(void)strcpy(boot1, lp->d_boot1);
380		bootxx = boot1;
381	}
382#endif
383#endif
384	/* d_packname is union d_boot[01], so zero */
385	bzero(lp->d_packname, sizeof(lp->d_packname));
386	if (name)
387		(void)strncpy(lp->d_packname, name, sizeof(lp->d_packname));
388}
389
390int
391writelabel(f, boot, lp)
392	int f;
393	char *boot;
394	register struct disklabel *lp;
395{
396#ifdef vax
397	register int i;
398#endif
399	int flag;
400
401	setbootflag(lp);
402	lp->d_magic = DISKMAGIC;
403	lp->d_magic2 = DISKMAGIC;
404	lp->d_checksum = 0;
405	lp->d_checksum = dkcksum(lp);
406	if (rflag) {
407		/*
408		 * First set the kernel disk label,
409		 * then write a label to the raw disk.
410		 * If the SDINFO ioctl fails because it is unimplemented,
411		 * keep going; otherwise, the kernel consistency checks
412		 * may prevent us from changing the current (in-core)
413		 * label.
414		 */
415		if (ioctl(f, DIOCSDINFO, lp) < 0 &&
416		    errno != ENODEV && errno != ENOTTY) {
417			l_perror("ioctl DIOCSDINFO");
418			return (1);
419		}
420		(void)lseek(f, (off_t)0, SEEK_SET);
421		/*
422		 * write enable label sector before write (if necessary),
423		 * disable after writing.
424		 */
425		flag = 1;
426		if (ioctl(f, DIOCWLABEL, &flag) < 0)
427			warn("ioctl DIOCWLABEL");
428		if (write(f, boot, lp->d_bbsize) != lp->d_bbsize) {
429			warn("write");
430			return (1);
431		}
432#if NUMBOOT > 0
433		/*
434		 * Output the remainder of the disklabel
435		 */
436		if (bootbuf && write(f, bootbuf, bootsize) != bootsize) {
437			warn("write");
438			return(1);
439		}
440#endif
441		flag = 0;
442		(void) ioctl(f, DIOCWLABEL, &flag);
443	} else if (ioctl(f, DIOCWDINFO, lp) < 0) {
444		l_perror("ioctl DIOCWDINFO");
445		return (1);
446	}
447#ifdef vax
448	if (lp->d_type == DTYPE_SMD && lp->d_flags & D_BADSECT) {
449		daddr_t alt;
450
451		alt = lp->d_ncylinders * lp->d_secpercyl - lp->d_nsectors;
452		for (i = 1; i < 11 && i < lp->d_nsectors; i += 2) {
453			(void)lseek(f, (off_t)((alt + i) * lp->d_secsize),
454			    SEEK_SET);
455			if (write(f, boot, lp->d_secsize) < lp->d_secsize)
456				warn("alternate label %d write", i/2);
457		}
458	}
459#endif
460	return (0);
461}
462
463void
464l_perror(s)
465	char *s;
466{
467	switch (errno) {
468
469	case ESRCH:
470		warnx("%s: no disk label on disk;", s);
471		fprintf(stderr,
472			"use \"disklabel -r\" to install initial label\n");
473		break;
474
475	case EINVAL:
476		warnx("%s: label magic number or checksum is wrong!", s);
477		fprintf(stderr, "(disklabel or kernel is out of date?)\n");
478		break;
479
480	case EBUSY:
481		warnx("%s: open partition would move or shrink", s);
482		break;
483
484	case EXDEV:
485		warnx(
486 "%s: labeled partition or 'a' partition must start at beginning of disk", s);
487		break;
488
489	default:
490		warn((char *)NULL);
491		break;
492	}
493}
494
495/*
496 * Fetch disklabel for disk.
497 * Use ioctl to get label unless -r flag is given.
498 */
499struct disklabel *
500readlabel(f)
501	int f;
502{
503	register struct disklabel *lp;
504
505	if (rflag) {
506		if (read(f, bootarea, BBSIZE) < BBSIZE)
507			err(4, "%s", specname);
508		for (lp = (struct disklabel *)bootarea;
509		    lp <= (struct disklabel *)(bootarea + BBSIZE - sizeof(*lp));
510		    lp = (struct disklabel *)((char *)lp + 16))
511			if (lp->d_magic == DISKMAGIC &&
512			    lp->d_magic2 == DISKMAGIC)
513				break;
514		if (lp > (struct disklabel *)(bootarea+BBSIZE-sizeof(*lp)) ||
515		    lp->d_magic != DISKMAGIC || lp->d_magic2 != DISKMAGIC ||
516		    dkcksum(lp) != 0)
517			errx(1,
518	    "bad pack magic number (label is damaged, or pack is unlabeled)");
519	} else {
520		lp = &lab;
521		if (ioctl(f, DIOCGDINFO, lp) < 0)
522			err(4, "ioctl DIOCGDINFO");
523	}
524	return (lp);
525}
526
527/*
528 * Construct a bootarea (d_bbsize bytes) in the specified buffer ``boot''
529 * Returns a pointer to the disklabel portion of the bootarea.
530 */
531struct disklabel *
532makebootarea(boot, dp, f)
533	char *boot;
534	register struct disklabel *dp;
535	int f;
536{
537	struct disklabel *lp;
538	register char *p;
539	int b;
540#if NUMBOOT > 0
541	char *dkbasename;
542	struct stat sb;
543#ifdef __i386__
544	char *tmpbuf;
545	int i, found;
546#endif /* i386 */
547#endif
548
549	/* XXX */
550	if (dp->d_secsize == 0) {
551		dp->d_secsize = DEV_BSIZE;
552		dp->d_bbsize = BBSIZE;
553	}
554	lp = (struct disklabel *)
555		(boot + (LABELSECTOR * dp->d_secsize) + LABELOFFSET);
556	bzero((char *)lp, sizeof *lp);
557#if NUMBOOT > 0
558	/*
559	 * If we are not installing a boot program but we are installing a
560	 * label on disk then we must read the current bootarea so we don't
561	 * clobber the existing boot.
562	 */
563	if (!installboot) {
564		if (rflag) {
565			if (read(f, boot, BBSIZE) < BBSIZE)
566				err(4, "%s", specname);
567			bzero((char *)lp, sizeof *lp);
568		}
569		return (lp);
570	}
571	/*
572	 * We are installing a boot program.  Determine the name(s) and
573	 * read them into the appropriate places in the boot area.
574	 */
575	if (!xxboot || !bootxx) {
576		dkbasename = np;
577		if ((p = rindex(dkname, '/')) == NULL)
578			p = dkname;
579		else
580			p++;
581		while (*p && !isdigit(*p))
582			*np++ = *p++;
583		*np++ = '\0';
584
585		if (!xxboot) {
586			(void)sprintf(np, "%s/%sboot",
587				      _PATH_BOOTDIR, dkbasename);
588			if (access(np, F_OK) < 0 && dkbasename[0] == 'r')
589				dkbasename++;
590			xxboot = np;
591			(void)sprintf(xxboot, "%s/%sboot",
592				      _PATH_BOOTDIR, dkbasename);
593			np += strlen(xxboot) + 1;
594		}
595#if NUMBOOT > 1
596		if (!bootxx) {
597			(void)sprintf(np, "%s/boot%s",
598				      _PATH_BOOTDIR, dkbasename);
599			if (access(np, F_OK) < 0 && dkbasename[0] == 'r')
600				dkbasename++;
601			bootxx = np;
602			(void)sprintf(bootxx, "%s/boot%s",
603				      _PATH_BOOTDIR, dkbasename);
604			np += strlen(bootxx) + 1;
605		}
606#endif
607	}
608#ifdef DEBUG
609	if (debug)
610		fprintf(stderr, "bootstraps: xxboot = %s, bootxx = %s\n",
611			xxboot, bootxx ? bootxx : "NONE");
612#endif
613
614	/*
615	 * Strange rules:
616	 * 1. One-piece bootstrap (hp300/hp800)
617	 *	up to d_bbsize bytes of ``xxboot'' go in bootarea, the rest
618	 *	is remembered and written later following the bootarea.
619	 * 2. Two-piece bootstraps (vax/i386?/mips?)
620	 *	up to d_secsize bytes of ``xxboot'' go in first d_secsize
621	 *	bytes of bootarea, remaining d_bbsize-d_secsize filled
622	 *	from ``bootxx''.
623	 */
624	b = open(xxboot, O_RDONLY);
625	if (b < 0)
626		err(4, "%s", xxboot);
627#if NUMBOOT > 1
628#ifdef __i386__
629	/*
630	 * XXX Botch alert.
631	 * The i386 has the so-called fdisk table embedded into the
632	 * primary bootstrap.  We take care to not clobber it, but
633	 * only if it does already contain some data.  (Otherwise,
634	 * the xxboot provides a template.)
635	 */
636	if ((tmpbuf = (char *)malloc((int)dp->d_secsize)) == 0)
637		err(4, "%s", xxboot);
638	memcpy((void *)tmpbuf, (void *)boot, (int)dp->d_secsize);
639#endif /* i386 */
640	if (read(b, boot, (int)dp->d_secsize) < 0)
641		err(4, "%s", xxboot);
642	(void)close(b);
643#ifdef __i386__
644	for (i = DOSPARTOFF, found = 0;
645	     !found && i < DOSPARTOFF + NDOSPART*sizeof(struct dos_partition);
646	     i++)
647		found = tmpbuf[i] != 0;
648	if (found)
649		memcpy((void *)&boot[DOSPARTOFF],
650		       (void *)&tmpbuf[DOSPARTOFF],
651		       NDOSPART * sizeof(struct dos_partition));
652	free(tmpbuf);
653#endif /* i386 */
654	b = open(bootxx, O_RDONLY);
655	if (b < 0)
656		err(4, "%s", bootxx);
657	if (fstat(b, &sb) != 0)
658		err(4, "%s", bootxx);
659	if (dp->d_secsize + sb.st_size > dp->d_bbsize)
660		errx(4, "%s too large", bootxx);
661	if (read(b, &boot[dp->d_secsize],
662		 (int)(dp->d_bbsize-dp->d_secsize)) < 0)
663		err(4, "%s", bootxx);
664#else
665	if (read(b, boot, (int)dp->d_bbsize) < 0)
666		err(4, "%s", xxboot);
667	if (fstat(b, &sb) != 0)
668		err(4, "%s", xxboot);
669	bootsize = (int)sb.st_size - dp->d_bbsize;
670	if (bootsize > 0) {
671		/* XXX assume d_secsize is a power of two */
672		bootsize = (bootsize + dp->d_secsize-1) & ~(dp->d_secsize-1);
673		bootbuf = (char *)malloc((size_t)bootsize);
674		if (bootbuf == 0)
675			err(4, "%s", xxboot);
676		if (read(b, bootbuf, bootsize) < 0) {
677			free(bootbuf);
678			err(4, "%s", xxboot);
679		}
680	}
681#endif
682	(void)close(b);
683#endif
684	/*
685	 * Make sure no part of the bootstrap is written in the area
686	 * reserved for the label.
687	 */
688	for (p = (char *)lp; p < (char *)lp + sizeof(struct disklabel); p++)
689		if (*p)
690			errx(2, "bootstrap doesn't leave room for disk label");
691	return (lp);
692}
693
694void
695display(f, lp)
696	FILE *f;
697	register struct disklabel *lp;
698{
699	register int i, j;
700	register struct partition *pp;
701
702	fprintf(f, "# %s:\n", specname);
703	if ((unsigned) lp->d_type < DKMAXTYPES)
704		fprintf(f, "type: %s\n", dktypenames[lp->d_type]);
705	else
706		fprintf(f, "type: %u\n", lp->d_type);
707	fprintf(f, "disk: %.*s\n", (int)sizeof(lp->d_typename),
708		lp->d_typename);
709	fprintf(f, "label: %.*s\n", (int)sizeof(lp->d_packname),
710		lp->d_packname);
711	fprintf(f, "flags:");
712	if (lp->d_flags & D_REMOVABLE)
713		fprintf(f, " removeable");
714	if (lp->d_flags & D_ECC)
715		fprintf(f, " ecc");
716	if (lp->d_flags & D_BADSECT)
717		fprintf(f, " badsect");
718	fprintf(f, "\n");
719	fprintf(f, "bytes/sector: %lu\n", (u_long)lp->d_secsize);
720	fprintf(f, "sectors/track: %lu\n", (u_long)lp->d_nsectors);
721	fprintf(f, "tracks/cylinder: %lu\n", (u_long)lp->d_ntracks);
722	fprintf(f, "sectors/cylinder: %lu\n", (u_long)lp->d_secpercyl);
723	fprintf(f, "cylinders: %lu\n", (u_long)lp->d_ncylinders);
724	fprintf(f, "sectors/unit: %lu\n", (u_long)lp->d_secperunit);
725	fprintf(f, "rpm: %u\n", lp->d_rpm);
726	fprintf(f, "interleave: %u\n", lp->d_interleave);
727	fprintf(f, "trackskew: %u\n", lp->d_trackskew);
728	fprintf(f, "cylinderskew: %u\n", lp->d_cylskew);
729	fprintf(f, "headswitch: %lu\t\t# milliseconds\n",
730	    (u_long)lp->d_headswitch);
731	fprintf(f, "track-to-track seek: %ld\t# milliseconds\n",
732	    (u_long)lp->d_trkseek);
733	fprintf(f, "drivedata: ");
734	for (i = NDDATA - 1; i >= 0; i--)
735		if (lp->d_drivedata[i])
736			break;
737	if (i < 0)
738		i = 0;
739	for (j = 0; j <= i; j++)
740		fprintf(f, "%lu ", (u_long)lp->d_drivedata[j]);
741	fprintf(f, "\n\n%u partitions:\n", lp->d_npartitions);
742	fprintf(f,
743	    "#        size   offset    fstype   [fsize bsize bps/cpg]\n");
744	pp = lp->d_partitions;
745	for (i = 0; i < lp->d_npartitions; i++, pp++) {
746		if (pp->p_size) {
747			fprintf(f, "  %c: %8lu %8lu  ", 'a' + i,
748			   (u_long)pp->p_size, (u_long)pp->p_offset);
749			if ((unsigned) pp->p_fstype < FSMAXTYPES)
750				fprintf(f, "%8.8s", fstypenames[pp->p_fstype]);
751			else
752				fprintf(f, "%8d", pp->p_fstype);
753			switch (pp->p_fstype) {
754
755			case FS_UNUSED:				/* XXX */
756				fprintf(f, "    %5lu %5lu %5.5s ",
757				    (u_long)pp->p_fsize,
758				    (u_long)(pp->p_fsize * pp->p_frag), "");
759				break;
760
761			case FS_BSDFFS:
762				fprintf(f, "    %5lu %5lu %5u ",
763				    (u_long)pp->p_fsize,
764				    (u_long)(pp->p_fsize * pp->p_frag),
765				    pp->p_cpg);
766				break;
767
768			case FS_BSDLFS:
769				fprintf(f, "    %5lu %5lu %5d",
770				    (u_long)pp->p_fsize,
771				    (u_long)(pp->p_fsize * pp->p_frag),
772				    pp->p_cpg);
773				break;
774
775			default:
776				fprintf(f, "%20.20s", "");
777				break;
778			}
779			fprintf(f, "\t# (Cyl. %4lu",
780			    (u_long)(pp->p_offset / lp->d_secpercyl));
781			if (pp->p_offset % lp->d_secpercyl)
782			    putc('*', f);
783			else
784			    putc(' ', f);
785			fprintf(f, "- %lu",
786			    (u_long)((pp->p_offset + pp->p_size +
787			    lp->d_secpercyl - 1) /
788			    lp->d_secpercyl - 1));
789			if (pp->p_size % lp->d_secpercyl)
790			    putc('*', f);
791			fprintf(f, ")\n");
792		}
793	}
794	fflush(f);
795}
796
797int
798edit(lp, f)
799	struct disklabel *lp;
800	int f;
801{
802	register int c, fd;
803	struct disklabel label;
804	FILE *fp;
805
806	if ((fd = mkstemp(tmpfil)) == -1 ||
807	    (fp = fdopen(fd, "w")) == NULL) {
808		warnx("can't create %s", tmpfil);
809		return (1);
810	}
811	display(fp, lp);
812	fclose(fp);
813	for (;;) {
814		if (!editit())
815			break;
816		fp = fopen(tmpfil, "r");
817		if (fp == NULL) {
818			warnx("can't reopen %s for reading", tmpfil);
819			break;
820		}
821		bzero((char *)&label, sizeof(label));
822		if (getasciilabel(fp, &label)) {
823			*lp = label;
824			if (writelabel(f, bootarea, lp) == 0) {
825				fclose(fp);
826				(void) unlink(tmpfil);
827				return (0);
828			}
829		}
830		fclose(fp);
831		printf("re-edit the label? [y]: "); fflush(stdout);
832		c = getchar();
833		if (c != EOF && c != (int)'\n')
834			while (getchar() != (int)'\n')
835				;
836		if  (c == (int)'n')
837			break;
838	}
839	(void) unlink(tmpfil);
840	return (1);
841}
842
843int
844editit()
845{
846	register int pid, xpid;
847	int stat, omask;
848	extern char *getenv();
849
850	omask = sigblock(sigmask(SIGINT)|sigmask(SIGQUIT)|sigmask(SIGHUP));
851	while ((pid = fork()) < 0) {
852		extern int errno;
853
854		if (errno == EPROCLIM) {
855			warnx("you have too many processes");
856			return(0);
857		}
858		if (errno != EAGAIN) {
859			warn("fork");
860			return(0);
861		}
862		sleep(1);
863	}
864	if (pid == 0) {
865		register char *ed;
866
867		sigsetmask(omask);
868		setgid(getgid());
869		setuid(getuid());
870		if ((ed = getenv("EDITOR")) == (char *)0)
871			ed = DEFEDITOR;
872		execlp(ed, ed, tmpfil, 0);
873		err(1, "%s", ed);
874	}
875	while ((xpid = wait(&stat)) >= 0)
876		if (xpid == pid)
877			break;
878	sigsetmask(omask);
879	return(!stat);
880}
881
882char *
883skip(cp)
884	register char *cp;
885{
886
887	while (*cp != '\0' && isspace(*cp))
888		cp++;
889	if (*cp == '\0' || *cp == '#')
890		return ((char *)NULL);
891	return (cp);
892}
893
894char *
895word(cp)
896	register char *cp;
897{
898	register char c;
899
900	while (*cp != '\0' && !isspace(*cp) && *cp != '#')
901		cp++;
902	if ((c = *cp) != '\0') {
903		*cp++ = '\0';
904		if (c != '#')
905			return (skip(cp));
906	}
907	return ((char *)NULL);
908}
909
910/*
911 * Read an ascii label in from fd f,
912 * in the same format as that put out by display(),
913 * and fill in lp.
914 */
915int
916getasciilabel(f, lp)
917	FILE	*f;
918	register struct disklabel *lp;
919{
920	register char **cpp, *cp;
921	register struct partition *pp;
922	char *tp, *s, line[BUFSIZ];
923	int v, lineno = 0, errors = 0;
924
925	lp->d_bbsize = BBSIZE;				/* XXX */
926	lp->d_sbsize = SBSIZE;				/* XXX */
927	while (fgets(line, sizeof(line) - 1, f)) {
928		lineno++;
929		if ((cp = index(line,'\n')) != 0)
930			*cp = '\0';
931		cp = skip(line);
932		if (cp == NULL)
933			continue;
934		tp = index(cp, ':');
935		if (tp == NULL) {
936			fprintf(stderr, "line %d: syntax error\n", lineno);
937			errors++;
938			continue;
939		}
940		*tp++ = '\0', tp = skip(tp);
941		if (streq(cp, "type")) {
942			if (tp == NULL)
943				tp = "unknown";
944			cpp = dktypenames;
945			for (; cpp < &dktypenames[DKMAXTYPES]; cpp++)
946				if ((s = *cpp) && streq(s, tp)) {
947					lp->d_type = cpp - dktypenames;
948					goto next;
949				}
950			v = atoi(tp);
951			if ((unsigned)v >= DKMAXTYPES)
952				fprintf(stderr, "line %d:%s %d\n", lineno,
953				    "Warning, unknown disk type", v);
954			lp->d_type = v;
955			continue;
956		}
957		if (streq(cp, "flags")) {
958			for (v = 0; (cp = tp) && *cp != '\0';) {
959				tp = word(cp);
960				if (streq(cp, "removeable"))
961					v |= D_REMOVABLE;
962				else if (streq(cp, "ecc"))
963					v |= D_ECC;
964				else if (streq(cp, "badsect"))
965					v |= D_BADSECT;
966				else {
967					fprintf(stderr,
968					    "line %d: %s: bad flag\n",
969					    lineno, cp);
970					errors++;
971				}
972			}
973			lp->d_flags = v;
974			continue;
975		}
976		if (streq(cp, "drivedata")) {
977			register int i;
978
979			for (i = 0; (cp = tp) && *cp != '\0' && i < NDDATA;) {
980				lp->d_drivedata[i++] = atoi(cp);
981				tp = word(cp);
982			}
983			continue;
984		}
985		if (sscanf(cp, "%d partitions", &v) == 1) {
986			if (v == 0 || (unsigned)v > MAXPARTITIONS) {
987				fprintf(stderr,
988				    "line %d: bad # of partitions\n", lineno);
989				lp->d_npartitions = MAXPARTITIONS;
990				errors++;
991			} else
992				lp->d_npartitions = v;
993			continue;
994		}
995		if (tp == NULL)
996			tp = "";
997		if (streq(cp, "disk")) {
998			strncpy(lp->d_typename, tp, sizeof (lp->d_typename));
999			continue;
1000		}
1001		if (streq(cp, "label")) {
1002			strncpy(lp->d_packname, tp, sizeof (lp->d_packname));
1003			continue;
1004		}
1005		if (streq(cp, "bytes/sector")) {
1006			v = atoi(tp);
1007			if (v <= 0 || (v % DEV_BSIZE) != 0) {
1008				fprintf(stderr,
1009				    "line %d: %s: bad sector size\n",
1010				    lineno, tp);
1011				errors++;
1012			} else
1013				lp->d_secsize = v;
1014			continue;
1015		}
1016		if (streq(cp, "sectors/track")) {
1017			v = atoi(tp);
1018			if (v <= 0) {
1019				fprintf(stderr, "line %d: %s: bad %s\n",
1020				    lineno, tp, cp);
1021				errors++;
1022			} else
1023				lp->d_nsectors = v;
1024			continue;
1025		}
1026		if (streq(cp, "sectors/cylinder")) {
1027			v = atoi(tp);
1028			if (v <= 0) {
1029				fprintf(stderr, "line %d: %s: bad %s\n",
1030				    lineno, tp, cp);
1031				errors++;
1032			} else
1033				lp->d_secpercyl = v;
1034			continue;
1035		}
1036		if (streq(cp, "tracks/cylinder")) {
1037			v = atoi(tp);
1038			if (v <= 0) {
1039				fprintf(stderr, "line %d: %s: bad %s\n",
1040				    lineno, tp, cp);
1041				errors++;
1042			} else
1043				lp->d_ntracks = v;
1044			continue;
1045		}
1046		if (streq(cp, "cylinders")) {
1047			v = atoi(tp);
1048			if (v <= 0) {
1049				fprintf(stderr, "line %d: %s: bad %s\n",
1050				    lineno, tp, cp);
1051				errors++;
1052			} else
1053				lp->d_ncylinders = v;
1054			continue;
1055		}
1056		if (streq(cp, "sectors/unit")) {
1057			v = atoi(tp);
1058			if (v <= 0) {
1059				fprintf(stderr, "line %d: %s: bad %s\n",
1060				    lineno, tp, cp);
1061				errors++;
1062			} else
1063				lp->d_secperunit = v;
1064			continue;
1065		}
1066		if (streq(cp, "rpm")) {
1067			v = atoi(tp);
1068			if (v <= 0) {
1069				fprintf(stderr, "line %d: %s: bad %s\n",
1070				    lineno, tp, cp);
1071				errors++;
1072			} else
1073				lp->d_rpm = v;
1074			continue;
1075		}
1076		if (streq(cp, "interleave")) {
1077			v = atoi(tp);
1078			if (v <= 0) {
1079				fprintf(stderr, "line %d: %s: bad %s\n",
1080				    lineno, tp, cp);
1081				errors++;
1082			} else
1083				lp->d_interleave = v;
1084			continue;
1085		}
1086		if (streq(cp, "trackskew")) {
1087			v = atoi(tp);
1088			if (v < 0) {
1089				fprintf(stderr, "line %d: %s: bad %s\n",
1090				    lineno, tp, cp);
1091				errors++;
1092			} else
1093				lp->d_trackskew = v;
1094			continue;
1095		}
1096		if (streq(cp, "cylinderskew")) {
1097			v = atoi(tp);
1098			if (v < 0) {
1099				fprintf(stderr, "line %d: %s: bad %s\n",
1100				    lineno, tp, cp);
1101				errors++;
1102			} else
1103				lp->d_cylskew = v;
1104			continue;
1105		}
1106		if (streq(cp, "headswitch")) {
1107			v = atoi(tp);
1108			if (v < 0) {
1109				fprintf(stderr, "line %d: %s: bad %s\n",
1110				    lineno, tp, cp);
1111				errors++;
1112			} else
1113				lp->d_headswitch = v;
1114			continue;
1115		}
1116		if (streq(cp, "track-to-track seek")) {
1117			v = atoi(tp);
1118			if (v < 0) {
1119				fprintf(stderr, "line %d: %s: bad %s\n",
1120				    lineno, tp, cp);
1121				errors++;
1122			} else
1123				lp->d_trkseek = v;
1124			continue;
1125		}
1126		if ('a' <= *cp && *cp <= 'z' && cp[1] == '\0') {
1127			unsigned part = *cp - 'a';
1128
1129			if (part > lp->d_npartitions) {
1130				fprintf(stderr,
1131				    "line %d: bad partition name\n", lineno);
1132				errors++;
1133				continue;
1134			}
1135			pp = &lp->d_partitions[part];
1136#define NXTNUM(n) { \
1137	if (tp == NULL) { \
1138		fprintf(stderr, "line %d: too few numeric fields\n", lineno); \
1139		errors++; \
1140		break; \
1141	} else { \
1142		cp = tp, tp = word(cp); \
1143		if (tp == NULL) \
1144			tp = cp; \
1145		(n) = atoi(cp); \
1146	} \
1147     }
1148
1149			NXTNUM(v);
1150			if (v < 0) {
1151				fprintf(stderr,
1152				    "line %d: %s: bad partition size\n",
1153				    lineno, cp);
1154				errors++;
1155			} else
1156				pp->p_size = v;
1157			NXTNUM(v);
1158			if (v < 0) {
1159				fprintf(stderr,
1160				    "line %d: %s: bad partition offset\n",
1161				    lineno, cp);
1162				errors++;
1163			} else
1164				pp->p_offset = v;
1165			cp = tp, tp = word(cp);
1166			cpp = fstypenames;
1167			for (; cpp < &fstypenames[FSMAXTYPES]; cpp++)
1168				if ((s = *cpp) && streq(s, cp)) {
1169					pp->p_fstype = cpp - fstypenames;
1170					goto gottype;
1171				}
1172			if (isdigit(*cp))
1173				v = atoi(cp);
1174			else
1175				v = FSMAXTYPES;
1176			if ((unsigned)v >= FSMAXTYPES) {
1177				fprintf(stderr, "line %d: %s %s\n", lineno,
1178				    "Warning, unknown filesystem type", cp);
1179				v = FS_UNUSED;
1180			}
1181			pp->p_fstype = v;
1182	gottype:
1183
1184			switch (pp->p_fstype) {
1185
1186			case FS_UNUSED:				/* XXX */
1187				NXTNUM(pp->p_fsize);
1188				if (pp->p_fsize == 0)
1189					break;
1190				NXTNUM(v);
1191				pp->p_frag = v / pp->p_fsize;
1192				break;
1193
1194			case FS_BSDFFS:
1195				NXTNUM(pp->p_fsize);
1196				if (pp->p_fsize == 0)
1197					break;
1198				NXTNUM(v);
1199				pp->p_frag = v / pp->p_fsize;
1200				NXTNUM(pp->p_cpg);
1201				break;
1202
1203			case FS_BSDLFS:
1204				NXTNUM(pp->p_fsize);
1205				if (pp->p_fsize == 0)
1206					break;
1207				NXTNUM(v);
1208				pp->p_frag = v / pp->p_fsize;
1209				NXTNUM(pp->p_cpg);
1210				break;
1211
1212			default:
1213				break;
1214			}
1215			continue;
1216		}
1217		fprintf(stderr, "line %d: %s: Unknown disklabel field\n",
1218		    lineno, cp);
1219		errors++;
1220	next:
1221		;
1222	}
1223	errors += checklabel(lp);
1224	return (errors == 0);
1225}
1226
1227/*
1228 * Check disklabel for errors and fill in
1229 * derived fields according to supplied values.
1230 */
1231int
1232checklabel(lp)
1233	register struct disklabel *lp;
1234{
1235	register struct partition *pp;
1236	int i, errors = 0;
1237	char part;
1238
1239	if (lp->d_secsize == 0) {
1240		fprintf(stderr, "sector size 0\n");
1241		return (1);
1242	}
1243	if (lp->d_nsectors == 0) {
1244		fprintf(stderr, "sectors/track 0\n");
1245		return (1);
1246	}
1247	if (lp->d_ntracks == 0) {
1248		fprintf(stderr, "tracks/cylinder 0\n");
1249		return (1);
1250	}
1251	if  (lp->d_ncylinders == 0) {
1252		fprintf(stderr, "cylinders/unit 0\n");
1253		errors++;
1254	}
1255	if (lp->d_rpm == 0)
1256		Warning("revolutions/minute 0");
1257	if (lp->d_secpercyl == 0)
1258		lp->d_secpercyl = lp->d_nsectors * lp->d_ntracks;
1259	if (lp->d_secperunit == 0)
1260		lp->d_secperunit = lp->d_secpercyl * lp->d_ncylinders;
1261	if (lp->d_bbsize == 0) {
1262		fprintf(stderr, "boot block size 0\n");
1263		errors++;
1264	} else if (lp->d_bbsize % lp->d_secsize)
1265		Warning("boot block size %% sector-size != 0");
1266	if (lp->d_sbsize == 0) {
1267		fprintf(stderr, "super block size 0\n");
1268		errors++;
1269	} else if (lp->d_sbsize % lp->d_secsize)
1270		Warning("super block size %% sector-size != 0");
1271	if (lp->d_npartitions > MAXPARTITIONS)
1272		Warning("number of partitions (%lu) > MAXPARTITIONS (%d)",
1273		    (u_long)lp->d_npartitions, MAXPARTITIONS);
1274	for (i = 0; i < lp->d_npartitions; i++) {
1275		part = 'a' + i;
1276		pp = &lp->d_partitions[i];
1277		if (pp->p_size == 0 && pp->p_offset != 0)
1278			Warning("partition %c: size 0, but offset %lu",
1279			    part, (u_long)pp->p_offset);
1280#ifdef notdef
1281		if (pp->p_size % lp->d_secpercyl)
1282			Warning("partition %c: size %% cylinder-size != 0",
1283			    part);
1284		if (pp->p_offset % lp->d_secpercyl)
1285			Warning("partition %c: offset %% cylinder-size != 0",
1286			    part);
1287#endif
1288		if (pp->p_offset > lp->d_secperunit) {
1289			fprintf(stderr,
1290			    "partition %c: offset past end of unit\n", part);
1291			errors++;
1292		}
1293		if (pp->p_offset + pp->p_size > lp->d_secperunit) {
1294			fprintf(stderr,
1295			"partition %c: partition extends past end of unit\n",
1296			    part);
1297			errors++;
1298		}
1299	}
1300	for (; i < MAXPARTITIONS; i++) {
1301		part = 'a' + i;
1302		pp = &lp->d_partitions[i];
1303		if (pp->p_size || pp->p_offset)
1304			Warning("unused partition %c: size %d offset %lu",
1305			    'a' + i, pp->p_size, (u_long)pp->p_offset);
1306	}
1307	return (errors);
1308}
1309
1310/*
1311 * When operating on a "virgin" disk, try getting an initial label
1312 * from the associated device driver.  This might work for all device
1313 * drivers that are able to fetch some initial device parameters
1314 * without even having access to a (BSD) disklabel, like SCSI disks,
1315 * most IDE drives, or vn devices.
1316 *
1317 * The device name must be given in its "canonical" form.
1318 */
1319struct disklabel *
1320getvirginlabel(void)
1321{
1322	static struct disklabel lab;
1323	char namebuf[BBSIZE];
1324	int f;
1325
1326	if (dkname[0] == '/') {
1327		warnx("\"auto\" requires the usage of a canonical disk name");
1328		return (NULL);
1329	}
1330	(void)snprintf(namebuf, BBSIZE, "%sr%s", _PATH_DEV, dkname);
1331	if ((f = open(namebuf, O_RDONLY)) == -1) {
1332		warn("cannot open %s", namebuf);
1333		return (NULL);
1334	}
1335	if (ioctl(f, DIOCGDINFO, &lab) < 0) {
1336		warn("ioctl DIOCGDINFO");
1337		close(f);
1338		return (NULL);
1339	}
1340	close(f);
1341	lab.d_boot0 = NULL;
1342	lab.d_boot1 = NULL;
1343	return (&lab);
1344}
1345
1346/*
1347 * If we are installing a boot program that doesn't fit in d_bbsize
1348 * we need to mark those partitions that the boot overflows into.
1349 * This allows newfs to prevent creation of a filesystem where it might
1350 * clobber bootstrap code.
1351 */
1352void
1353setbootflag(lp)
1354	register struct disklabel *lp;
1355{
1356	register struct partition *pp;
1357	int i, errors = 0;
1358	char part;
1359	u_long boffset;
1360
1361	if (bootbuf == 0)
1362		return;
1363	boffset = bootsize / lp->d_secsize;
1364	for (i = 0; i < lp->d_npartitions; i++) {
1365		part = 'a' + i;
1366		pp = &lp->d_partitions[i];
1367		if (pp->p_size == 0)
1368			continue;
1369		if (boffset <= pp->p_offset) {
1370			if (pp->p_fstype == FS_BOOT)
1371				pp->p_fstype = FS_UNUSED;
1372		} else if (pp->p_fstype != FS_BOOT) {
1373			if (pp->p_fstype != FS_UNUSED) {
1374				fprintf(stderr,
1375					"boot overlaps used partition %c\n",
1376					part);
1377				errors++;
1378			} else {
1379				pp->p_fstype = FS_BOOT;
1380				Warning("boot overlaps partition %c, %s",
1381					part, "marked as FS_BOOT");
1382			}
1383		}
1384	}
1385	if (errors)
1386		errx(4, "cannot install boot program");
1387}
1388
1389/*VARARGS1*/
1390void
1391Warning(char *fmt, ...)
1392{
1393	va_list ap;
1394
1395	fprintf(stderr, "Warning, ");
1396	va_start(ap, fmt);
1397	vfprintf(stderr, fmt, ap);
1398	fprintf(stderr, "\n");
1399	va_end(ap);
1400}
1401
1402void
1403usage()
1404{
1405#if NUMBOOT > 0
1406	fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
1407		"usage: disklabel [-r] disk",
1408		"\t\t(to read label)",
1409		"       disklabel -w [-r] disk type [ packid ]",
1410		"\t\t(to write label with existing boot program)",
1411		"       disklabel -e [-r] disk",
1412		"\t\t(to edit label)",
1413		"       disklabel -R [-r] disk protofile",
1414		"\t\t(to restore label with existing boot program)",
1415#if NUMBOOT > 1
1416		"       disklabel -B [ -b boot1 [ -s boot2 ] ] disk [ type ]",
1417		"\t\t(to install boot program with existing label)",
1418		"       disklabel -w -B [ -b boot1 [ -s boot2 ] ] disk type [ packid ]",
1419		"\t\t(to write label and boot program)",
1420		"       disklabel -R -B [ -b boot1 [ -s boot2 ] ] disk protofile [ type ]",
1421		"\t\t(to restore label and boot program)",
1422#else
1423		"       disklabel -B [ -b bootprog ] disk [ type ]",
1424		"\t\t(to install boot program with existing on-disk label)",
1425		"       disklabel -w -B [ -b bootprog ] disk type [ packid ]",
1426		"\t\t(to write label and install boot program)",
1427		"       disklabel -R -B [ -b bootprog ] disk protofile [ type ]",
1428		"\t\t(to restore label and install boot program)",
1429#endif
1430		"       disklabel [-NW] disk",
1431		"\t\t(to write disable/enable label)");
1432#else
1433	fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
1434		"usage: disklabel [-r] disk", "(to read label)",
1435		"       disklabel -w [-r] disk type [ packid ]",
1436		"\t\t(to write label)",
1437		"       disklabel -e [-r] disk",
1438		"\t\t(to edit label)",
1439		"       disklabel -R [-r] disk protofile",
1440		"\t\t(to restore label)",
1441		"       disklabel [-NW] disk",
1442		"\t\t(to write disable/enable label)");
1443#endif
1444	exit(1);
1445}
1446