bsdlabel.c revision 38384
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.17 1998/07/25 16:19:10 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) || defined(__alpha__) 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#ifdef __alpha__ 402 /* 403 * Generate the bootblock checksum for the SRM console. 404 */ 405 u_long *p, sum; 406 int i; 407#endif 408 409 setbootflag(lp); 410 lp->d_magic = DISKMAGIC; 411 lp->d_magic2 = DISKMAGIC; 412 lp->d_checksum = 0; 413 lp->d_checksum = dkcksum(lp); 414 if (rflag) { 415 /* 416 * First set the kernel disk label, 417 * then write a label to the raw disk. 418 * If the SDINFO ioctl fails because it is unimplemented, 419 * keep going; otherwise, the kernel consistency checks 420 * may prevent us from changing the current (in-core) 421 * label. 422 */ 423 if (ioctl(f, DIOCSDINFO, lp) < 0 && 424 errno != ENODEV && errno != ENOTTY) { 425 l_perror("ioctl DIOCSDINFO"); 426 return (1); 427 } 428 (void)lseek(f, (off_t)0, SEEK_SET); 429 /* 430 * write enable label sector before write (if necessary), 431 * disable after writing. 432 */ 433 flag = 1; 434 435#ifdef __alpha__ 436 for (p = (u_long *)boot, i = 0, sum = 0; i < 63; i++) 437 sum += p[i]; 438 p[63] = sum; 439#endif 440 441 if (ioctl(f, DIOCWLABEL, &flag) < 0) 442 warn("ioctl DIOCWLABEL"); 443 if (write(f, boot, lp->d_bbsize) != lp->d_bbsize) { 444 warn("write"); 445 return (1); 446 } 447#if NUMBOOT > 0 448 /* 449 * Output the remainder of the disklabel 450 */ 451 if (bootbuf && write(f, bootbuf, bootsize) != bootsize) { 452 warn("write"); 453 return(1); 454 } 455#endif 456 flag = 0; 457 (void) ioctl(f, DIOCWLABEL, &flag); 458 } else if (ioctl(f, DIOCWDINFO, lp) < 0) { 459 l_perror("ioctl DIOCWDINFO"); 460 return (1); 461 } 462#ifdef vax 463 if (lp->d_type == DTYPE_SMD && lp->d_flags & D_BADSECT) { 464 daddr_t alt; 465 466 alt = lp->d_ncylinders * lp->d_secpercyl - lp->d_nsectors; 467 for (i = 1; i < 11 && i < lp->d_nsectors; i += 2) { 468 (void)lseek(f, (off_t)((alt + i) * lp->d_secsize), 469 SEEK_SET); 470 if (write(f, boot, lp->d_secsize) < lp->d_secsize) 471 warn("alternate label %d write", i/2); 472 } 473 } 474#endif 475 return (0); 476} 477 478void 479l_perror(s) 480 char *s; 481{ 482 switch (errno) { 483 484 case ESRCH: 485 warnx("%s: no disk label on disk;", s); 486 fprintf(stderr, 487 "use \"disklabel -r\" to install initial label\n"); 488 break; 489 490 case EINVAL: 491 warnx("%s: label magic number or checksum is wrong!", s); 492 fprintf(stderr, "(disklabel or kernel is out of date?)\n"); 493 break; 494 495 case EBUSY: 496 warnx("%s: open partition would move or shrink", s); 497 break; 498 499 case EXDEV: 500 warnx( 501 "%s: labeled partition or 'a' partition must start at beginning of disk", s); 502 break; 503 504 default: 505 warn((char *)NULL); 506 break; 507 } 508} 509 510/* 511 * Fetch disklabel for disk. 512 * Use ioctl to get label unless -r flag is given. 513 */ 514struct disklabel * 515readlabel(f) 516 int f; 517{ 518 register struct disklabel *lp; 519 520 if (rflag) { 521 if (read(f, bootarea, BBSIZE) < BBSIZE) 522 err(4, "%s", specname); 523 for (lp = (struct disklabel *)bootarea; 524 lp <= (struct disklabel *)(bootarea + BBSIZE - sizeof(*lp)); 525 lp = (struct disklabel *)((char *)lp + 16)) 526 if (lp->d_magic == DISKMAGIC && 527 lp->d_magic2 == DISKMAGIC) 528 break; 529 if (lp > (struct disklabel *)(bootarea+BBSIZE-sizeof(*lp)) || 530 lp->d_magic != DISKMAGIC || lp->d_magic2 != DISKMAGIC || 531 dkcksum(lp) != 0) 532 errx(1, 533 "bad pack magic number (label is damaged, or pack is unlabeled)"); 534 } else { 535 lp = &lab; 536 if (ioctl(f, DIOCGDINFO, lp) < 0) 537 err(4, "ioctl DIOCGDINFO"); 538 } 539 return (lp); 540} 541 542/* 543 * Construct a bootarea (d_bbsize bytes) in the specified buffer ``boot'' 544 * Returns a pointer to the disklabel portion of the bootarea. 545 */ 546struct disklabel * 547makebootarea(boot, dp, f) 548 char *boot; 549 register struct disklabel *dp; 550 int f; 551{ 552 struct disklabel *lp; 553 register char *p; 554 int b; 555#if NUMBOOT > 0 556 char *dkbasename; 557 struct stat sb; 558#ifdef __i386__ 559 char *tmpbuf; 560 int i, found; 561#endif /* i386 */ 562#endif 563 564 /* XXX */ 565 if (dp->d_secsize == 0) { 566 dp->d_secsize = DEV_BSIZE; 567 dp->d_bbsize = BBSIZE; 568 } 569 lp = (struct disklabel *) 570 (boot + (LABELSECTOR * dp->d_secsize) + LABELOFFSET); 571 bzero((char *)lp, sizeof *lp); 572#if NUMBOOT > 0 573 /* 574 * If we are not installing a boot program but we are installing a 575 * label on disk then we must read the current bootarea so we don't 576 * clobber the existing boot. 577 */ 578 if (!installboot) { 579 if (rflag) { 580 if (read(f, boot, BBSIZE) < BBSIZE) 581 err(4, "%s", specname); 582 bzero((char *)lp, sizeof *lp); 583 } 584 return (lp); 585 } 586 /* 587 * We are installing a boot program. Determine the name(s) and 588 * read them into the appropriate places in the boot area. 589 */ 590 if (!xxboot || !bootxx) { 591 dkbasename = np; 592 if ((p = rindex(dkname, '/')) == NULL) 593 p = dkname; 594 else 595 p++; 596 while (*p && !isdigit(*p)) 597 *np++ = *p++; 598 *np++ = '\0'; 599 600 if (!xxboot) { 601 (void)sprintf(np, "%s/%sboot", 602 _PATH_BOOTDIR, dkbasename); 603 if (access(np, F_OK) < 0 && dkbasename[0] == 'r') 604 dkbasename++; 605 xxboot = np; 606 (void)sprintf(xxboot, "%s/%sboot", 607 _PATH_BOOTDIR, dkbasename); 608 np += strlen(xxboot) + 1; 609 } 610#if NUMBOOT > 1 611 if (!bootxx) { 612 (void)sprintf(np, "%s/boot%s", 613 _PATH_BOOTDIR, dkbasename); 614 if (access(np, F_OK) < 0 && dkbasename[0] == 'r') 615 dkbasename++; 616 bootxx = np; 617 (void)sprintf(bootxx, "%s/boot%s", 618 _PATH_BOOTDIR, dkbasename); 619 np += strlen(bootxx) + 1; 620 } 621#endif 622 } 623#ifdef DEBUG 624 if (debug) 625 fprintf(stderr, "bootstraps: xxboot = %s, bootxx = %s\n", 626 xxboot, bootxx ? bootxx : "NONE"); 627#endif 628 629 /* 630 * Strange rules: 631 * 1. One-piece bootstrap (hp300/hp800) 632 * up to d_bbsize bytes of ``xxboot'' go in bootarea, the rest 633 * is remembered and written later following the bootarea. 634 * 2. Two-piece bootstraps (vax/i386?/mips?) 635 * up to d_secsize bytes of ``xxboot'' go in first d_secsize 636 * bytes of bootarea, remaining d_bbsize-d_secsize filled 637 * from ``bootxx''. 638 */ 639 b = open(xxboot, O_RDONLY); 640 if (b < 0) 641 err(4, "%s", xxboot); 642#if NUMBOOT > 1 643#ifdef __i386__ 644 /* 645 * XXX Botch alert. 646 * The i386 has the so-called fdisk table embedded into the 647 * primary bootstrap. We take care to not clobber it, but 648 * only if it does already contain some data. (Otherwise, 649 * the xxboot provides a template.) 650 */ 651 if ((tmpbuf = (char *)malloc((int)dp->d_secsize)) == 0) 652 err(4, "%s", xxboot); 653 memcpy((void *)tmpbuf, (void *)boot, (int)dp->d_secsize); 654#endif /* i386 */ 655 if (read(b, boot, (int)dp->d_secsize) < 0) 656 err(4, "%s", xxboot); 657 (void)close(b); 658#ifdef __i386__ 659 for (i = DOSPARTOFF, found = 0; 660 !found && i < DOSPARTOFF + NDOSPART*sizeof(struct dos_partition); 661 i++) 662 found = tmpbuf[i] != 0; 663 if (found) 664 memcpy((void *)&boot[DOSPARTOFF], 665 (void *)&tmpbuf[DOSPARTOFF], 666 NDOSPART * sizeof(struct dos_partition)); 667 free(tmpbuf); 668#endif /* i386 */ 669 b = open(bootxx, O_RDONLY); 670 if (b < 0) 671 err(4, "%s", bootxx); 672 if (fstat(b, &sb) != 0) 673 err(4, "%s", bootxx); 674 if (dp->d_secsize + sb.st_size > dp->d_bbsize) 675 errx(4, "%s too large", bootxx); 676 if (read(b, &boot[dp->d_secsize], 677 (int)(dp->d_bbsize-dp->d_secsize)) < 0) 678 err(4, "%s", bootxx); 679#else 680#ifdef __alpha__ 681 { 682 683 /* 684 * On the alpha, the primary bootstrap starts at the 685 * second sector of the boot area. The first sector 686 * contains the label and must be edited to contain the 687 * size and location of the primary bootstrap. 688 */ 689 int n = read(b, boot + dp->d_secsize, (int)dp->d_bbsize); 690 u_long *lp; 691 if (n < 0) 692 err(4, "%s", xxboot); 693 lp = (u_long *) (boot + 480); 694 lp[0] = (n + dp->d_secsize - 1) / dp->d_secsize; 695 lp[1] = 1; /* start at sector 1 */ 696 lp[2] = 0; /* flags (must be zero) */ 697 } 698#else 699 if (read(b, boot, (int)dp->d_bbsize) < 0) 700 err(4, "%s", xxboot); 701#endif 702 if (fstat(b, &sb) != 0) 703 err(4, "%s", xxboot); 704 bootsize = (int)sb.st_size - dp->d_bbsize; 705 if (bootsize > 0) { 706 /* XXX assume d_secsize is a power of two */ 707 bootsize = (bootsize + dp->d_secsize-1) & ~(dp->d_secsize-1); 708 bootbuf = (char *)malloc((size_t)bootsize); 709 if (bootbuf == 0) 710 err(4, "%s", xxboot); 711 if (read(b, bootbuf, bootsize) < 0) { 712 free(bootbuf); 713 err(4, "%s", xxboot); 714 } 715 } 716#endif 717 (void)close(b); 718#endif 719 /* 720 * Make sure no part of the bootstrap is written in the area 721 * reserved for the label. 722 */ 723 for (p = (char *)lp; p < (char *)lp + sizeof(struct disklabel); p++) 724 if (*p) 725 errx(2, "bootstrap doesn't leave room for disk label"); 726 return (lp); 727} 728 729void 730display(f, lp) 731 FILE *f; 732 register struct disklabel *lp; 733{ 734 register int i, j; 735 register struct partition *pp; 736 737 fprintf(f, "# %s:\n", specname); 738 if ((unsigned) lp->d_type < DKMAXTYPES) 739 fprintf(f, "type: %s\n", dktypenames[lp->d_type]); 740 else 741 fprintf(f, "type: %u\n", lp->d_type); 742 fprintf(f, "disk: %.*s\n", (int)sizeof(lp->d_typename), 743 lp->d_typename); 744 fprintf(f, "label: %.*s\n", (int)sizeof(lp->d_packname), 745 lp->d_packname); 746 fprintf(f, "flags:"); 747 if (lp->d_flags & D_REMOVABLE) 748 fprintf(f, " removeable"); 749 if (lp->d_flags & D_ECC) 750 fprintf(f, " ecc"); 751 if (lp->d_flags & D_BADSECT) 752 fprintf(f, " badsect"); 753 fprintf(f, "\n"); 754 fprintf(f, "bytes/sector: %lu\n", (u_long)lp->d_secsize); 755 fprintf(f, "sectors/track: %lu\n", (u_long)lp->d_nsectors); 756 fprintf(f, "tracks/cylinder: %lu\n", (u_long)lp->d_ntracks); 757 fprintf(f, "sectors/cylinder: %lu\n", (u_long)lp->d_secpercyl); 758 fprintf(f, "cylinders: %lu\n", (u_long)lp->d_ncylinders); 759 fprintf(f, "sectors/unit: %lu\n", (u_long)lp->d_secperunit); 760 fprintf(f, "rpm: %u\n", lp->d_rpm); 761 fprintf(f, "interleave: %u\n", lp->d_interleave); 762 fprintf(f, "trackskew: %u\n", lp->d_trackskew); 763 fprintf(f, "cylinderskew: %u\n", lp->d_cylskew); 764 fprintf(f, "headswitch: %lu\t\t# milliseconds\n", 765 (u_long)lp->d_headswitch); 766 fprintf(f, "track-to-track seek: %ld\t# milliseconds\n", 767 (u_long)lp->d_trkseek); 768 fprintf(f, "drivedata: "); 769 for (i = NDDATA - 1; i >= 0; i--) 770 if (lp->d_drivedata[i]) 771 break; 772 if (i < 0) 773 i = 0; 774 for (j = 0; j <= i; j++) 775 fprintf(f, "%lu ", (u_long)lp->d_drivedata[j]); 776 fprintf(f, "\n\n%u partitions:\n", lp->d_npartitions); 777 fprintf(f, 778 "# size offset fstype [fsize bsize bps/cpg]\n"); 779 pp = lp->d_partitions; 780 for (i = 0; i < lp->d_npartitions; i++, pp++) { 781 if (pp->p_size) { 782 fprintf(f, " %c: %8lu %8lu ", 'a' + i, 783 (u_long)pp->p_size, (u_long)pp->p_offset); 784 if ((unsigned) pp->p_fstype < FSMAXTYPES) 785 fprintf(f, "%8.8s", fstypenames[pp->p_fstype]); 786 else 787 fprintf(f, "%8d", pp->p_fstype); 788 switch (pp->p_fstype) { 789 790 case FS_UNUSED: /* XXX */ 791 fprintf(f, " %5lu %5lu %5.5s ", 792 (u_long)pp->p_fsize, 793 (u_long)(pp->p_fsize * pp->p_frag), ""); 794 break; 795 796 case FS_BSDFFS: 797 fprintf(f, " %5lu %5lu %5u ", 798 (u_long)pp->p_fsize, 799 (u_long)(pp->p_fsize * pp->p_frag), 800 pp->p_cpg); 801 break; 802 803 case FS_BSDLFS: 804 fprintf(f, " %5lu %5lu %5d", 805 (u_long)pp->p_fsize, 806 (u_long)(pp->p_fsize * pp->p_frag), 807 pp->p_cpg); 808 break; 809 810 default: 811 fprintf(f, "%20.20s", ""); 812 break; 813 } 814 fprintf(f, "\t# (Cyl. %4lu", 815 (u_long)(pp->p_offset / lp->d_secpercyl)); 816 if (pp->p_offset % lp->d_secpercyl) 817 putc('*', f); 818 else 819 putc(' ', f); 820 fprintf(f, "- %lu", 821 (u_long)((pp->p_offset + pp->p_size + 822 lp->d_secpercyl - 1) / 823 lp->d_secpercyl - 1)); 824 if (pp->p_size % lp->d_secpercyl) 825 putc('*', f); 826 fprintf(f, ")\n"); 827 } 828 } 829 fflush(f); 830} 831 832int 833edit(lp, f) 834 struct disklabel *lp; 835 int f; 836{ 837 register int c, fd; 838 struct disklabel label; 839 FILE *fp; 840 841 if ((fd = mkstemp(tmpfil)) == -1 || 842 (fp = fdopen(fd, "w")) == NULL) { 843 warnx("can't create %s", tmpfil); 844 return (1); 845 } 846 display(fp, lp); 847 fclose(fp); 848 for (;;) { 849 if (!editit()) 850 break; 851 fp = fopen(tmpfil, "r"); 852 if (fp == NULL) { 853 warnx("can't reopen %s for reading", tmpfil); 854 break; 855 } 856 bzero((char *)&label, sizeof(label)); 857 if (getasciilabel(fp, &label)) { 858 *lp = label; 859 if (writelabel(f, bootarea, lp) == 0) { 860 fclose(fp); 861 (void) unlink(tmpfil); 862 return (0); 863 } 864 } 865 fclose(fp); 866 printf("re-edit the label? [y]: "); fflush(stdout); 867 c = getchar(); 868 if (c != EOF && c != (int)'\n') 869 while (getchar() != (int)'\n') 870 ; 871 if (c == (int)'n') 872 break; 873 } 874 (void) unlink(tmpfil); 875 return (1); 876} 877 878int 879editit() 880{ 881 register int pid, xpid; 882 int stat, omask; 883 extern char *getenv(); 884 885 omask = sigblock(sigmask(SIGINT)|sigmask(SIGQUIT)|sigmask(SIGHUP)); 886 while ((pid = fork()) < 0) { 887 extern int errno; 888 889 if (errno == EPROCLIM) { 890 warnx("you have too many processes"); 891 return(0); 892 } 893 if (errno != EAGAIN) { 894 warn("fork"); 895 return(0); 896 } 897 sleep(1); 898 } 899 if (pid == 0) { 900 register char *ed; 901 902 sigsetmask(omask); 903 setgid(getgid()); 904 setuid(getuid()); 905 if ((ed = getenv("EDITOR")) == (char *)0) 906 ed = DEFEDITOR; 907 execlp(ed, ed, tmpfil, 0); 908 err(1, "%s", ed); 909 } 910 while ((xpid = wait(&stat)) >= 0) 911 if (xpid == pid) 912 break; 913 sigsetmask(omask); 914 return(!stat); 915} 916 917char * 918skip(cp) 919 register char *cp; 920{ 921 922 while (*cp != '\0' && isspace(*cp)) 923 cp++; 924 if (*cp == '\0' || *cp == '#') 925 return ((char *)NULL); 926 return (cp); 927} 928 929char * 930word(cp) 931 register char *cp; 932{ 933 register char c; 934 935 while (*cp != '\0' && !isspace(*cp) && *cp != '#') 936 cp++; 937 if ((c = *cp) != '\0') { 938 *cp++ = '\0'; 939 if (c != '#') 940 return (skip(cp)); 941 } 942 return ((char *)NULL); 943} 944 945/* 946 * Read an ascii label in from fd f, 947 * in the same format as that put out by display(), 948 * and fill in lp. 949 */ 950int 951getasciilabel(f, lp) 952 FILE *f; 953 register struct disklabel *lp; 954{ 955 register char **cpp, *cp; 956 register struct partition *pp; 957 char *tp, *s, line[BUFSIZ]; 958 int v, lineno = 0, errors = 0; 959 960 lp->d_bbsize = BBSIZE; /* XXX */ 961 lp->d_sbsize = SBSIZE; /* XXX */ 962 while (fgets(line, sizeof(line) - 1, f)) { 963 lineno++; 964 if ((cp = index(line,'\n')) != 0) 965 *cp = '\0'; 966 cp = skip(line); 967 if (cp == NULL) 968 continue; 969 tp = index(cp, ':'); 970 if (tp == NULL) { 971 fprintf(stderr, "line %d: syntax error\n", lineno); 972 errors++; 973 continue; 974 } 975 *tp++ = '\0', tp = skip(tp); 976 if (streq(cp, "type")) { 977 if (tp == NULL) 978 tp = "unknown"; 979 cpp = dktypenames; 980 for (; cpp < &dktypenames[DKMAXTYPES]; cpp++) 981 if ((s = *cpp) && streq(s, tp)) { 982 lp->d_type = cpp - dktypenames; 983 goto next; 984 } 985 v = atoi(tp); 986 if ((unsigned)v >= DKMAXTYPES) 987 fprintf(stderr, "line %d:%s %d\n", lineno, 988 "Warning, unknown disk type", v); 989 lp->d_type = v; 990 continue; 991 } 992 if (streq(cp, "flags")) { 993 for (v = 0; (cp = tp) && *cp != '\0';) { 994 tp = word(cp); 995 if (streq(cp, "removeable")) 996 v |= D_REMOVABLE; 997 else if (streq(cp, "ecc")) 998 v |= D_ECC; 999 else if (streq(cp, "badsect")) 1000 v |= D_BADSECT; 1001 else { 1002 fprintf(stderr, 1003 "line %d: %s: bad flag\n", 1004 lineno, cp); 1005 errors++; 1006 } 1007 } 1008 lp->d_flags = v; 1009 continue; 1010 } 1011 if (streq(cp, "drivedata")) { 1012 register int i; 1013 1014 for (i = 0; (cp = tp) && *cp != '\0' && i < NDDATA;) { 1015 lp->d_drivedata[i++] = atoi(cp); 1016 tp = word(cp); 1017 } 1018 continue; 1019 } 1020 if (sscanf(cp, "%d partitions", &v) == 1) { 1021 if (v == 0 || (unsigned)v > MAXPARTITIONS) { 1022 fprintf(stderr, 1023 "line %d: bad # of partitions\n", lineno); 1024 lp->d_npartitions = MAXPARTITIONS; 1025 errors++; 1026 } else 1027 lp->d_npartitions = v; 1028 continue; 1029 } 1030 if (tp == NULL) 1031 tp = ""; 1032 if (streq(cp, "disk")) { 1033 strncpy(lp->d_typename, tp, sizeof (lp->d_typename)); 1034 continue; 1035 } 1036 if (streq(cp, "label")) { 1037 strncpy(lp->d_packname, tp, sizeof (lp->d_packname)); 1038 continue; 1039 } 1040 if (streq(cp, "bytes/sector")) { 1041 v = atoi(tp); 1042 if (v <= 0 || (v % DEV_BSIZE) != 0) { 1043 fprintf(stderr, 1044 "line %d: %s: bad sector size\n", 1045 lineno, tp); 1046 errors++; 1047 } else 1048 lp->d_secsize = v; 1049 continue; 1050 } 1051 if (streq(cp, "sectors/track")) { 1052 v = atoi(tp); 1053 if (v <= 0) { 1054 fprintf(stderr, "line %d: %s: bad %s\n", 1055 lineno, tp, cp); 1056 errors++; 1057 } else 1058 lp->d_nsectors = v; 1059 continue; 1060 } 1061 if (streq(cp, "sectors/cylinder")) { 1062 v = atoi(tp); 1063 if (v <= 0) { 1064 fprintf(stderr, "line %d: %s: bad %s\n", 1065 lineno, tp, cp); 1066 errors++; 1067 } else 1068 lp->d_secpercyl = v; 1069 continue; 1070 } 1071 if (streq(cp, "tracks/cylinder")) { 1072 v = atoi(tp); 1073 if (v <= 0) { 1074 fprintf(stderr, "line %d: %s: bad %s\n", 1075 lineno, tp, cp); 1076 errors++; 1077 } else 1078 lp->d_ntracks = v; 1079 continue; 1080 } 1081 if (streq(cp, "cylinders")) { 1082 v = atoi(tp); 1083 if (v <= 0) { 1084 fprintf(stderr, "line %d: %s: bad %s\n", 1085 lineno, tp, cp); 1086 errors++; 1087 } else 1088 lp->d_ncylinders = v; 1089 continue; 1090 } 1091 if (streq(cp, "sectors/unit")) { 1092 v = atoi(tp); 1093 if (v <= 0) { 1094 fprintf(stderr, "line %d: %s: bad %s\n", 1095 lineno, tp, cp); 1096 errors++; 1097 } else 1098 lp->d_secperunit = v; 1099 continue; 1100 } 1101 if (streq(cp, "rpm")) { 1102 v = atoi(tp); 1103 if (v <= 0) { 1104 fprintf(stderr, "line %d: %s: bad %s\n", 1105 lineno, tp, cp); 1106 errors++; 1107 } else 1108 lp->d_rpm = v; 1109 continue; 1110 } 1111 if (streq(cp, "interleave")) { 1112 v = atoi(tp); 1113 if (v <= 0) { 1114 fprintf(stderr, "line %d: %s: bad %s\n", 1115 lineno, tp, cp); 1116 errors++; 1117 } else 1118 lp->d_interleave = v; 1119 continue; 1120 } 1121 if (streq(cp, "trackskew")) { 1122 v = atoi(tp); 1123 if (v < 0) { 1124 fprintf(stderr, "line %d: %s: bad %s\n", 1125 lineno, tp, cp); 1126 errors++; 1127 } else 1128 lp->d_trackskew = v; 1129 continue; 1130 } 1131 if (streq(cp, "cylinderskew")) { 1132 v = atoi(tp); 1133 if (v < 0) { 1134 fprintf(stderr, "line %d: %s: bad %s\n", 1135 lineno, tp, cp); 1136 errors++; 1137 } else 1138 lp->d_cylskew = v; 1139 continue; 1140 } 1141 if (streq(cp, "headswitch")) { 1142 v = atoi(tp); 1143 if (v < 0) { 1144 fprintf(stderr, "line %d: %s: bad %s\n", 1145 lineno, tp, cp); 1146 errors++; 1147 } else 1148 lp->d_headswitch = v; 1149 continue; 1150 } 1151 if (streq(cp, "track-to-track seek")) { 1152 v = atoi(tp); 1153 if (v < 0) { 1154 fprintf(stderr, "line %d: %s: bad %s\n", 1155 lineno, tp, cp); 1156 errors++; 1157 } else 1158 lp->d_trkseek = v; 1159 continue; 1160 } 1161 if ('a' <= *cp && *cp <= 'z' && cp[1] == '\0') { 1162 unsigned part = *cp - 'a'; 1163 1164 if (part > lp->d_npartitions) { 1165 fprintf(stderr, 1166 "line %d: bad partition name\n", lineno); 1167 errors++; 1168 continue; 1169 } 1170 pp = &lp->d_partitions[part]; 1171#define NXTNUM(n) { \ 1172 if (tp == NULL) { \ 1173 fprintf(stderr, "line %d: too few numeric fields\n", lineno); \ 1174 errors++; \ 1175 break; \ 1176 } else { \ 1177 cp = tp, tp = word(cp); \ 1178 if (tp == NULL) \ 1179 tp = cp; \ 1180 (n) = atoi(cp); \ 1181 } \ 1182 } 1183 1184 NXTNUM(v); 1185 if (v < 0) { 1186 fprintf(stderr, 1187 "line %d: %s: bad partition size\n", 1188 lineno, cp); 1189 errors++; 1190 } else 1191 pp->p_size = v; 1192 NXTNUM(v); 1193 if (v < 0) { 1194 fprintf(stderr, 1195 "line %d: %s: bad partition offset\n", 1196 lineno, cp); 1197 errors++; 1198 } else 1199 pp->p_offset = v; 1200 cp = tp, tp = word(cp); 1201 cpp = fstypenames; 1202 for (; cpp < &fstypenames[FSMAXTYPES]; cpp++) 1203 if ((s = *cpp) && streq(s, cp)) { 1204 pp->p_fstype = cpp - fstypenames; 1205 goto gottype; 1206 } 1207 if (isdigit(*cp)) 1208 v = atoi(cp); 1209 else 1210 v = FSMAXTYPES; 1211 if ((unsigned)v >= FSMAXTYPES) { 1212 fprintf(stderr, "line %d: %s %s\n", lineno, 1213 "Warning, unknown filesystem type", cp); 1214 v = FS_UNUSED; 1215 } 1216 pp->p_fstype = v; 1217 gottype: 1218 1219 switch (pp->p_fstype) { 1220 1221 case FS_UNUSED: /* XXX */ 1222 NXTNUM(pp->p_fsize); 1223 if (pp->p_fsize == 0) 1224 break; 1225 NXTNUM(v); 1226 pp->p_frag = v / pp->p_fsize; 1227 break; 1228 1229 case FS_BSDFFS: 1230 NXTNUM(pp->p_fsize); 1231 if (pp->p_fsize == 0) 1232 break; 1233 NXTNUM(v); 1234 pp->p_frag = v / pp->p_fsize; 1235 NXTNUM(pp->p_cpg); 1236 break; 1237 1238 case FS_BSDLFS: 1239 NXTNUM(pp->p_fsize); 1240 if (pp->p_fsize == 0) 1241 break; 1242 NXTNUM(v); 1243 pp->p_frag = v / pp->p_fsize; 1244 NXTNUM(pp->p_cpg); 1245 break; 1246 1247 default: 1248 break; 1249 } 1250 continue; 1251 } 1252 fprintf(stderr, "line %d: %s: Unknown disklabel field\n", 1253 lineno, cp); 1254 errors++; 1255 next: 1256 ; 1257 } 1258 errors += checklabel(lp); 1259 return (errors == 0); 1260} 1261 1262/* 1263 * Check disklabel for errors and fill in 1264 * derived fields according to supplied values. 1265 */ 1266int 1267checklabel(lp) 1268 register struct disklabel *lp; 1269{ 1270 register struct partition *pp; 1271 int i, errors = 0; 1272 char part; 1273 1274 if (lp->d_secsize == 0) { 1275 fprintf(stderr, "sector size 0\n"); 1276 return (1); 1277 } 1278 if (lp->d_nsectors == 0) { 1279 fprintf(stderr, "sectors/track 0\n"); 1280 return (1); 1281 } 1282 if (lp->d_ntracks == 0) { 1283 fprintf(stderr, "tracks/cylinder 0\n"); 1284 return (1); 1285 } 1286 if (lp->d_ncylinders == 0) { 1287 fprintf(stderr, "cylinders/unit 0\n"); 1288 errors++; 1289 } 1290 if (lp->d_rpm == 0) 1291 Warning("revolutions/minute 0"); 1292 if (lp->d_secpercyl == 0) 1293 lp->d_secpercyl = lp->d_nsectors * lp->d_ntracks; 1294 if (lp->d_secperunit == 0) 1295 lp->d_secperunit = lp->d_secpercyl * lp->d_ncylinders; 1296 if (lp->d_bbsize == 0) { 1297 fprintf(stderr, "boot block size 0\n"); 1298 errors++; 1299 } else if (lp->d_bbsize % lp->d_secsize) 1300 Warning("boot block size %% sector-size != 0"); 1301 if (lp->d_sbsize == 0) { 1302 fprintf(stderr, "super block size 0\n"); 1303 errors++; 1304 } else if (lp->d_sbsize % lp->d_secsize) 1305 Warning("super block size %% sector-size != 0"); 1306 if (lp->d_npartitions > MAXPARTITIONS) 1307 Warning("number of partitions (%lu) > MAXPARTITIONS (%d)", 1308 (u_long)lp->d_npartitions, MAXPARTITIONS); 1309 for (i = 0; i < lp->d_npartitions; i++) { 1310 part = 'a' + i; 1311 pp = &lp->d_partitions[i]; 1312 if (pp->p_size == 0 && pp->p_offset != 0) 1313 Warning("partition %c: size 0, but offset %lu", 1314 part, (u_long)pp->p_offset); 1315#ifdef notdef 1316 if (pp->p_size % lp->d_secpercyl) 1317 Warning("partition %c: size %% cylinder-size != 0", 1318 part); 1319 if (pp->p_offset % lp->d_secpercyl) 1320 Warning("partition %c: offset %% cylinder-size != 0", 1321 part); 1322#endif 1323 if (pp->p_offset > lp->d_secperunit) { 1324 fprintf(stderr, 1325 "partition %c: offset past end of unit\n", part); 1326 errors++; 1327 } 1328 if (pp->p_offset + pp->p_size > lp->d_secperunit) { 1329 fprintf(stderr, 1330 "partition %c: partition extends past end of unit\n", 1331 part); 1332 errors++; 1333 } 1334 } 1335 for (; i < MAXPARTITIONS; i++) { 1336 part = 'a' + i; 1337 pp = &lp->d_partitions[i]; 1338 if (pp->p_size || pp->p_offset) 1339 Warning("unused partition %c: size %d offset %lu", 1340 'a' + i, pp->p_size, (u_long)pp->p_offset); 1341 } 1342 return (errors); 1343} 1344 1345/* 1346 * When operating on a "virgin" disk, try getting an initial label 1347 * from the associated device driver. This might work for all device 1348 * drivers that are able to fetch some initial device parameters 1349 * without even having access to a (BSD) disklabel, like SCSI disks, 1350 * most IDE drives, or vn devices. 1351 * 1352 * The device name must be given in its "canonical" form. 1353 */ 1354struct disklabel * 1355getvirginlabel(void) 1356{ 1357 static struct disklabel lab; 1358 char namebuf[BBSIZE]; 1359 int f; 1360 1361 if (dkname[0] == '/') { 1362 warnx("\"auto\" requires the usage of a canonical disk name"); 1363 return (NULL); 1364 } 1365 (void)snprintf(namebuf, BBSIZE, "%sr%s", _PATH_DEV, dkname); 1366 if ((f = open(namebuf, O_RDONLY)) == -1) { 1367 warn("cannot open %s", namebuf); 1368 return (NULL); 1369 } 1370 if (ioctl(f, DIOCGDINFO, &lab) < 0) { 1371 warn("ioctl DIOCGDINFO"); 1372 close(f); 1373 return (NULL); 1374 } 1375 close(f); 1376 lab.d_boot0 = NULL; 1377 lab.d_boot1 = NULL; 1378 return (&lab); 1379} 1380 1381/* 1382 * If we are installing a boot program that doesn't fit in d_bbsize 1383 * we need to mark those partitions that the boot overflows into. 1384 * This allows newfs to prevent creation of a filesystem where it might 1385 * clobber bootstrap code. 1386 */ 1387void 1388setbootflag(lp) 1389 register struct disklabel *lp; 1390{ 1391 register struct partition *pp; 1392 int i, errors = 0; 1393 char part; 1394 u_long boffset; 1395 1396 if (bootbuf == 0) 1397 return; 1398 boffset = bootsize / lp->d_secsize; 1399 for (i = 0; i < lp->d_npartitions; i++) { 1400 part = 'a' + i; 1401 pp = &lp->d_partitions[i]; 1402 if (pp->p_size == 0) 1403 continue; 1404 if (boffset <= pp->p_offset) { 1405 if (pp->p_fstype == FS_BOOT) 1406 pp->p_fstype = FS_UNUSED; 1407 } else if (pp->p_fstype != FS_BOOT) { 1408 if (pp->p_fstype != FS_UNUSED) { 1409 fprintf(stderr, 1410 "boot overlaps used partition %c\n", 1411 part); 1412 errors++; 1413 } else { 1414 pp->p_fstype = FS_BOOT; 1415 Warning("boot overlaps partition %c, %s", 1416 part, "marked as FS_BOOT"); 1417 } 1418 } 1419 } 1420 if (errors) 1421 errx(4, "cannot install boot program"); 1422} 1423 1424/*VARARGS1*/ 1425void 1426Warning(char *fmt, ...) 1427{ 1428 va_list ap; 1429 1430 fprintf(stderr, "Warning, "); 1431 va_start(ap, fmt); 1432 vfprintf(stderr, fmt, ap); 1433 fprintf(stderr, "\n"); 1434 va_end(ap); 1435} 1436 1437void 1438usage() 1439{ 1440#if NUMBOOT > 0 1441 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", 1442 "usage: disklabel [-r] disk", 1443 "\t\t(to read label)", 1444 " disklabel -w [-r] disk type [ packid ]", 1445 "\t\t(to write label with existing boot program)", 1446 " disklabel -e [-r] disk", 1447 "\t\t(to edit label)", 1448 " disklabel -R [-r] disk protofile", 1449 "\t\t(to restore label with existing boot program)", 1450#if NUMBOOT > 1 1451 " disklabel -B [ -b boot1 [ -s boot2 ] ] disk [ type ]", 1452 "\t\t(to install boot program with existing label)", 1453 " disklabel -w -B [ -b boot1 [ -s boot2 ] ] disk type [ packid ]", 1454 "\t\t(to write label and boot program)", 1455 " disklabel -R -B [ -b boot1 [ -s boot2 ] ] disk protofile [ type ]", 1456 "\t\t(to restore label and boot program)", 1457#else 1458 " disklabel -B [ -b bootprog ] disk [ type ]", 1459 "\t\t(to install boot program with existing on-disk label)", 1460 " disklabel -w -B [ -b bootprog ] disk type [ packid ]", 1461 "\t\t(to write label and install boot program)", 1462 " disklabel -R -B [ -b bootprog ] disk protofile [ type ]", 1463 "\t\t(to restore label and install boot program)", 1464#endif 1465 " disklabel [-NW] disk", 1466 "\t\t(to write disable/enable label)"); 1467#else 1468 fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n", 1469 "usage: disklabel [-r] disk", "(to read label)", 1470 " disklabel -w [-r] disk type [ packid ]", 1471 "\t\t(to write label)", 1472 " disklabel -e [-r] disk", 1473 "\t\t(to edit label)", 1474 " disklabel -R [-r] disk protofile", 1475 "\t\t(to restore label)", 1476 " disklabel [-NW] disk", 1477 "\t\t(to write disable/enable label)"); 1478#endif 1479 exit(1); 1480} 1481