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