1 /* 2 * Copyright (c) 1983, 1989, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. All advertising materials mentioning features or use of this software 14 * must display the following acknowledgement: 15 * This product includes software developed by the University of 16 * California, Berkeley and its contributors. 17 * 4. Neither the name of the University nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34 #ifndef lint 35 static const char copyright[] = 36 "@(#) Copyright (c) 1983, 1989, 1993, 1994\n\ 37 The Regents of the University of California. All rights reserved.\n"; 38 #endif /* not lint */ 39 40 #ifndef lint 41 #if 0 42 static char sccsid[] = "@(#)newfs.c 8.13 (Berkeley) 5/1/95"; 43 #endif 44 static const char rcsid[] = 45 "$Id: newfs.c,v 1.26 1998/10/17 04:19:29 jkh Exp $"; 46 #endif /* not lint */ 47 48 /* 49 * newfs: friendly front end to mkfs 50 */ 51 #include <sys/param.h> 52 #include <sys/stat.h> 53 #include <sys/disklabel.h> 54 #include <sys/file.h> 55 #include <sys/mount.h> 56 57 #include <ufs/ufs/dir.h> 58 #include <ufs/ufs/dinode.h> 59 #include <ufs/ffs/fs.h> 60 #include <ufs/ufs/ufsmount.h> 61 62 #include <ctype.h> 63 #include <err.h> 64 #include <errno.h> 65 #include <paths.h> 66 #include <stdio.h> 67 #include <stdlib.h> 68 #include <string.h> 69 #include <syslog.h> 70 #include <unistd.h> 71 72 #ifdef MFS 73 #include <sys/types.h> 74 #include <sys/mman.h> 75 #endif 76 77 #if __STDC__ 78 #include <stdarg.h> 79 #else 80 #include <varargs.h> 81 #endif 82 83 #include "mntopts.h" 84 85 struct mntopt mopts[] = { 86 MOPT_STDOPTS, 87 MOPT_ASYNC, 88 { NULL }, 89 }; 90 91 #if __STDC__ 92 void fatal(const char *fmt, ...); 93 #else 94 void fatal(); 95 #endif 96 97 #define COMPAT /* allow non-labeled disks */ 98 99 /* 100 * The following two constants set the default block and fragment sizes. 101 * Both constants must be a power of 2 and meet the following constraints: 102 * MINBSIZE <= DESBLKSIZE <= MAXBSIZE 103 * sectorsize <= DESFRAGSIZE <= DESBLKSIZE 104 * DESBLKSIZE / DESFRAGSIZE <= 8 105 */ 106 #define DFL_FRAGSIZE 1024 107 #define DFL_BLKSIZE 8192 108 109 /* 110 * Cylinder groups may have up to many cylinders. The actual 111 * number used depends upon how much information can be stored 112 * on a single cylinder. The default is to use 16 cylinders 113 * per group. 114 */ 115 #define DESCPG 16 /* desired fs_cpg */ 116 117 /* 118 * Once upon a time... 119 * ROTDELAY gives the minimum number of milliseconds to initiate 120 * another disk transfer on the same cylinder. It is used in 121 * determining the rotationally optimal layout for disk blocks 122 * within a file; the default of fs_rotdelay is 4ms. 123 * 124 * ...but now we make this 0 to disable the rotdelay delay because 125 * modern drives with read/write-behind achieve higher performance 126 * without the delay. 127 */ 128 #define ROTDELAY 0 129 130 /* 131 * MAXBLKPG determines the maximum number of data blocks which are 132 * placed in a single cylinder group. The default is one indirect 133 * block worth of data blocks. 134 */ 135 #define MAXBLKPG(bsize) ((bsize) / sizeof(daddr_t)) 136 137 /* 138 * Each file system has a number of inodes statically allocated. 139 * We allocate one inode slot per NFPI fragments, expecting this 140 * to be far more than we will ever need. 141 */ 142 #define NFPI 4 143 144 /* 145 * Once upon a time... 146 * For each cylinder we keep track of the availability of blocks at different 147 * rotational positions, so that we can lay out the data to be picked 148 * up with minimum rotational latency. NRPOS is the default number of 149 * rotational positions that we distinguish. With NRPOS of 8 the resolution 150 * of our summary information is 2ms for a typical 3600 rpm drive. 151 * 152 * ...but now we make this 1 (which essentially disables the rotational 153 * position table because modern drives with read-ahead and write-behind do 154 * better without the rotational position table. 155 */ 156 #define NRPOS 1 /* number distinct rotational positions */ 157 158 /* 159 * About the same time as the above, we knew what went where on the disks. 160 * no longer so, so kill the code which finds the different platters too... 161 * We do this by saying one head, with a lot of sectors on it. 162 * The number of sectors are used to determine the size of a cyl-group. 163 * Kirk suggested one or two meg per "cylinder" so we say two. 164 */ 165 166 #define NTRACKS 1 /* number of heads */ 167 168 #define NSECTORS 4096 /* number of sectors */ 169 170 int mfs; /* run as the memory based filesystem */ 171 int Nflag; /* run without writing file system */ 172 int Oflag; /* format as an 4.3BSD file system */ 173 int fssize; /* file system size */ 174 int ntracks = NTRACKS; /* # tracks/cylinder */ 175 int nsectors = NSECTORS; /* # sectors/track */ 176 int nphyssectors; /* # sectors/track including spares */ 177 int secpercyl; /* sectors per cylinder */ 178 int trackspares = -1; /* spare sectors per track */ 179 int cylspares = -1; /* spare sectors per cylinder */ 180 int sectorsize; /* bytes/sector */ 181 int realsectorsize; /* bytes/sector in hardware */ 182 int rpm; /* revolutions/minute of drive */ 183 int interleave; /* hardware sector interleave */ 184 int trackskew = -1; /* sector 0 skew, per track */ 185 int headswitch; /* head switch time, usec */ 186 int trackseek; /* track-to-track seek, usec */ 187 int fsize = 0; /* fragment size */ 188 int bsize = 0; /* block size */ 189 int cpg = DESCPG; /* cylinders/cylinder group */ 190 int cpgflg; /* cylinders/cylinder group flag was given */ 191 int minfree = MINFREE; /* free space threshold */ 192 int opt = DEFAULTOPT; /* optimization preference (space or time) */ 193 int density; /* number of bytes per inode */ 194 int maxcontig = 0; /* max contiguous blocks to allocate */ 195 int rotdelay = ROTDELAY; /* rotational delay between blocks */ 196 int maxbpg; /* maximum blocks per file in a cyl group */ 197 int nrpos = NRPOS; /* # of distinguished rotational positions */ 198 int bbsize = BBSIZE; /* boot block size */ 199 int sbsize = SBSIZE; /* superblock size */ 200 int mntflags = MNT_ASYNC; /* flags to be passed to mount */ 201 int t_or_u_flag = 0; /* user has specified -t or -u */ 202 u_long memleft; /* virtual memory available */ 203 caddr_t membase; /* start address of memory based filesystem */ 204 char *filename; 205 #ifdef COMPAT 206 char *disktype; 207 int unlabeled; 208 #endif 209 210 char device[MAXPATHLEN]; 211 char *progname; 212 213 extern void mkfs __P((struct partition *, char *, int, int)); 214 static void usage __P((void)); 215 216 int 217 main(argc, argv) 218 int argc; 219 char *argv[]; 220 { 221 register int ch; 222 register struct partition *pp; 223 register struct disklabel *lp; 224 struct disklabel mfsfakelabel; 225 struct disklabel *getdisklabel(); 226 struct partition oldpartition; 227 struct stat st; 228 struct statfs *mp; 229 int fsi, fso, len, n, vflag; 230 char *cp, *s1, *s2, *special, *opstring; 231 #ifdef MFS 232 struct vfsconf vfc; 233 int error; 234 char buf[BUFSIZ]; 235 #endif 236 237 vflag = 0; 238 if ((progname = strrchr(*argv, '/'))) 239 ++progname; 240 else 241 progname = *argv; 242 243 if (strstr(progname, "mfs")) { 244 mfs = 1; 245 Nflag++; 246 } 247 248 opstring = mfs ? 249 "NF:T:a:b:c:d:e:f:i:m:o:s:" : 250 "NOS:T:a:b:c:d:e:f:i:k:l:m:n:o:p:r:s:t:u:vx"; 251 while ((ch = getopt(argc, argv, opstring)) != -1) 252 switch (ch) { 253 case 'N': 254 Nflag = 1; 255 break; 256 case 'O': 257 Oflag = 1; 258 break; 259 case 'S': 260 if ((sectorsize = atoi(optarg)) <= 0) 261 fatal("%s: bad sector size", optarg); 262 break; 263 #ifdef COMPAT 264 case 'T': 265 disktype = optarg; 266 break; 267 #endif 268 case 'F': 269 filename = optarg; 270 break; 271 case 'a': 272 if ((maxcontig = atoi(optarg)) <= 0) 273 fatal("%s: bad maximum contiguous blocks", 274 optarg); 275 break; 276 case 'b': 277 if ((bsize = atoi(optarg)) < MINBSIZE) 278 fatal("%s: bad block size", optarg); 279 break; 280 case 'c': 281 if ((cpg = atoi(optarg)) <= 0) 282 fatal("%s: bad cylinders/group", optarg); 283 cpgflg++; 284 break; 285 case 'd': 286 if ((rotdelay = atoi(optarg)) < 0) 287 fatal("%s: bad rotational delay", optarg); 288 break; 289 case 'e': 290 if ((maxbpg = atoi(optarg)) <= 0) 291 fatal("%s: bad blocks per file in a cylinder group", 292 optarg); 293 break; 294 case 'f': 295 if ((fsize = atoi(optarg)) <= 0) 296 fatal("%s: bad fragment size", optarg); 297 break; 298 case 'i': 299 if ((density = atoi(optarg)) <= 0) 300 fatal("%s: bad bytes per inode", optarg); 301 break; 302 case 'k': 303 if ((trackskew = atoi(optarg)) < 0) 304 fatal("%s: bad track skew", optarg); 305 break; 306 case 'l': 307 if ((interleave = atoi(optarg)) <= 0) 308 fatal("%s: bad interleave", optarg); 309 break; 310 case 'm': 311 if ((minfree = atoi(optarg)) < 0 || minfree > 99) 312 fatal("%s: bad free space %%", optarg); 313 break; 314 case 'n': 315 if ((nrpos = atoi(optarg)) < 0) 316 fatal("%s: bad rotational layout count", 317 optarg); 318 if (nrpos == 0) 319 nrpos = 1; 320 break; 321 case 'o': 322 if (mfs) 323 getmntopts(optarg, mopts, &mntflags, 0); 324 else { 325 if (strcmp(optarg, "space") == 0) 326 opt = FS_OPTSPACE; 327 else if (strcmp(optarg, "time") == 0) 328 opt = FS_OPTTIME; 329 else 330 fatal("%s: unknown optimization preference: use `space' or `time'"); 331 } 332 break; 333 case 'p': 334 if ((trackspares = atoi(optarg)) < 0) 335 fatal("%s: bad spare sectors per track", 336 optarg); 337 break; 338 case 'r': 339 if ((rpm = atoi(optarg)) <= 0) 340 fatal("%s: bad revolutions/minute", optarg); 341 break; 342 case 's': 343 if ((fssize = atoi(optarg)) <= 0) 344 fatal("%s: bad file system size", optarg); 345 break; 346 case 't': 347 t_or_u_flag++; 348 if ((ntracks = atoi(optarg)) < 0) 349 fatal("%s: bad total tracks", optarg); 350 break; 351 case 'u': 352 t_or_u_flag++; 353 if ((nsectors = atoi(optarg)) < 0) 354 fatal("%s: bad sectors/track", optarg); 355 break; 356 case 'v': 357 vflag = 1; 358 break; 359 case 'x': 360 if ((cylspares = atoi(optarg)) < 0) 361 fatal("%s: bad spare sectors per cylinder", 362 optarg); 363 break; 364 case '?': 365 default: 366 usage(); 367 } 368 argc -= optind; 369 argv += optind; 370 371 if (argc != 2 && (mfs || argc != 1)) 372 usage(); 373 374 special = argv[0]; 375 /* Copy the NetBSD way of faking up a disk label */ 376 if (mfs && !strcmp(special, "swap")) { 377 /* 378 * it's an MFS, mounted on "swap." fake up a label. 379 * XXX XXX XXX 380 */ 381 fso = -1; /* XXX; normally done below. */ 382 383 memset(&mfsfakelabel, 0, sizeof(mfsfakelabel)); 384 mfsfakelabel.d_secsize = 512; 385 mfsfakelabel.d_nsectors = 64; 386 mfsfakelabel.d_ntracks = 16; 387 mfsfakelabel.d_ncylinders = 16; 388 mfsfakelabel.d_secpercyl = 1024; 389 mfsfakelabel.d_secperunit = 16384; 390 mfsfakelabel.d_rpm = 3600; 391 mfsfakelabel.d_interleave = 1; 392 mfsfakelabel.d_npartitions = 1; 393 mfsfakelabel.d_partitions[0].p_size = 16384; 394 mfsfakelabel.d_partitions[0].p_fsize = 1024; 395 mfsfakelabel.d_partitions[0].p_frag = 8; 396 mfsfakelabel.d_partitions[0].p_cpg = 16; 397 398 lp = &mfsfakelabel; 399 pp = &mfsfakelabel.d_partitions[0]; 400 401 goto havelabel; 402 } 403 404 cp = strrchr(special, '/'); 405 if (cp == 0) { 406 /* 407 * No path prefix; try /dev/r%s then /dev/%s. 408 */ 409 (void)sprintf(device, "%sr%s", _PATH_DEV, special); 410 if (stat(device, &st) == -1) 411 (void)sprintf(device, "%s%s", _PATH_DEV, special); 412 special = device; 413 } 414 if (Nflag) { 415 fso = -1; 416 } else { 417 fso = open(special, O_WRONLY); 418 if (fso < 0) 419 fatal("%s: %s", special, strerror(errno)); 420 421 /* Bail if target special is mounted */ 422 n = getmntinfo(&mp, MNT_NOWAIT); 423 if (n == 0) 424 fatal("%s: getmntinfo: %s", special, strerror(errno)); 425 426 len = sizeof(_PATH_DEV) - 1; 427 s1 = special; 428 if (strncmp(_PATH_DEV, s1, len) == 0) 429 s1 += len; 430 431 while (--n >= 0) { 432 s2 = mp->f_mntfromname; 433 if (strncmp(_PATH_DEV, s2, len) == 0) { 434 s2 += len - 1; 435 *s2 = 'r'; 436 } 437 if (strcmp(s1, s2) == 0 || strcmp(s1, &s2[1]) == 0) 438 fatal("%s is mounted on %s", 439 special, mp->f_mntonname); 440 ++mp; 441 } 442 } 443 if (mfs && disktype != NULL) { 444 lp = (struct disklabel *)getdiskbyname(disktype); 445 if (lp == NULL) 446 fatal("%s: unknown disk type", disktype); 447 pp = &lp->d_partitions[1]; 448 } else { 449 fsi = open(special, O_RDONLY); 450 if (fsi < 0) 451 fatal("%s: %s", special, strerror(errno)); 452 if (fstat(fsi, &st) < 0) 453 fatal("%s: %s", special, strerror(errno)); 454 if ((st.st_mode & S_IFMT) != S_IFCHR && !mfs) 455 printf("%s: %s: not a character-special device\n", 456 progname, special); 457 cp = strchr(argv[0], '\0'); 458 if (cp == argv[0]) 459 fatal("null special file name"); 460 cp--; 461 if (!vflag && (*cp < 'a' || *cp > 'h') && !isdigit(*cp)) 462 fatal("%s: can't figure out file system partition", 463 argv[0]); 464 #ifdef COMPAT 465 if (!mfs && disktype == NULL) 466 disktype = argv[1]; 467 #endif 468 lp = getdisklabel(special, fsi); 469 if (vflag || isdigit(*cp)) 470 pp = &lp->d_partitions[0]; 471 else 472 pp = &lp->d_partitions[*cp - 'a']; 473 if (pp->p_size == 0) 474 fatal("%s: `%c' partition is unavailable", 475 argv[0], *cp); 476 if (pp->p_fstype == FS_BOOT) 477 fatal("%s: `%c' partition overlaps boot program", 478 argv[0], *cp); 479 } 480 havelabel: 481 if (fssize == 0) 482 fssize = pp->p_size; 483 if (fssize > pp->p_size && !mfs) 484 fatal("%s: maximum file system size on the `%c' partition is %d", 485 argv[0], *cp, pp->p_size); 486 if (rpm == 0) { 487 rpm = lp->d_rpm; 488 if (rpm <= 0) 489 rpm = 3600; 490 } 491 if (ntracks == 0) { 492 ntracks = lp->d_ntracks; 493 if (ntracks <= 0) 494 fatal("%s: no default #tracks", argv[0]); 495 } 496 if (nsectors == 0) { 497 nsectors = lp->d_nsectors; 498 if (nsectors <= 0) 499 fatal("%s: no default #sectors/track", argv[0]); 500 } 501 if (sectorsize == 0) { 502 sectorsize = lp->d_secsize; 503 if (sectorsize <= 0) 504 fatal("%s: no default sector size", argv[0]); 505 } 506 if (trackskew == -1) { 507 trackskew = lp->d_trackskew; 508 if (trackskew < 0) 509 trackskew = 0; 510 } 511 if (interleave == 0) { 512 interleave = lp->d_interleave; 513 if (interleave <= 0) 514 interleave = 1; 515 } 516 if (fsize == 0) { 517 fsize = pp->p_fsize; 518 if (fsize <= 0) 519 fsize = MAX(DFL_FRAGSIZE, lp->d_secsize); 520 } 521 if (bsize == 0) { 522 bsize = pp->p_frag * pp->p_fsize; 523 if (bsize <= 0) 524 bsize = MIN(DFL_BLKSIZE, 8 * fsize); 525 } 526 /* 527 * Maxcontig sets the default for the maximum number of blocks 528 * that may be allocated sequentially. With filesystem clustering 529 * it is possible to allocate contiguous blocks up to the maximum 530 * transfer size permitted by the controller or buffering. 531 */ 532 if (maxcontig == 0) 533 maxcontig = MAX(1, MAXPHYS / bsize - 1); 534 if (density == 0) 535 density = NFPI * fsize; 536 if (minfree < MINFREE && opt != FS_OPTSPACE) { 537 fprintf(stderr, "Warning: changing optimization to space "); 538 fprintf(stderr, "because minfree is less than %d%%\n", MINFREE); 539 opt = FS_OPTSPACE; 540 } 541 if (trackspares == -1) { 542 trackspares = lp->d_sparespertrack; 543 if (trackspares < 0) 544 trackspares = 0; 545 } 546 nphyssectors = nsectors + trackspares; 547 if (cylspares == -1) { 548 cylspares = lp->d_sparespercyl; 549 if (cylspares < 0) 550 cylspares = 0; 551 } 552 secpercyl = nsectors * ntracks - cylspares; 553 /* 554 * Only complain if -t or -u have been specified; the default 555 * case (4096 sectors per cylinder) is intended to disagree 556 * with the disklabel. 557 */ 558 if (t_or_u_flag && secpercyl != lp->d_secpercyl) 559 fprintf(stderr, "%s (%d) %s (%lu)\n", 560 "Warning: calculated sectors per cylinder", secpercyl, 561 "disagrees with disk label", (u_long)lp->d_secpercyl); 562 if (maxbpg == 0) 563 maxbpg = MAXBLKPG(bsize); 564 headswitch = lp->d_headswitch; 565 trackseek = lp->d_trkseek; 566 #ifdef notdef /* label may be 0 if faked up by kernel */ 567 bbsize = lp->d_bbsize; 568 sbsize = lp->d_sbsize; 569 #endif 570 oldpartition = *pp; 571 #ifdef tahoe 572 realsectorsize = sectorsize; 573 if (sectorsize != DEV_BSIZE) { /* XXX */ 574 int secperblk = DEV_BSIZE / sectorsize; 575 576 sectorsize = DEV_BSIZE; 577 nsectors /= secperblk; 578 nphyssectors /= secperblk; 579 secpercyl /= secperblk; 580 fssize /= secperblk; 581 pp->p_size /= secperblk; 582 } 583 #else 584 realsectorsize = sectorsize; 585 if (sectorsize != DEV_BSIZE) { /* XXX */ 586 int secperblk = sectorsize / DEV_BSIZE; 587 588 sectorsize = DEV_BSIZE; 589 nsectors *= secperblk; 590 nphyssectors *= secperblk; 591 secpercyl *= secperblk; 592 fssize *= secperblk; 593 pp->p_size *= secperblk; 594 } 595 #endif 596 mkfs(pp, special, fsi, fso); 597 #ifdef tahoe 598 if (realsectorsize != DEV_BSIZE) 599 pp->p_size *= DEV_BSIZE / realsectorsize; 600 #else 601 if (realsectorsize != DEV_BSIZE) 602 pp->p_size /= realsectorsize /DEV_BSIZE; 603 #endif 604 if (!Nflag && bcmp(pp, &oldpartition, sizeof(oldpartition))) 605 rewritelabel(special, fso, lp); 606 if (!Nflag) 607 close(fso); 608 close(fsi); 609 #ifdef MFS 610 if (mfs) { 611 struct mfs_args args; 612 613 sprintf(buf, "mfs:%d", getpid()); 614 args.fspec = buf; 615 args.export.ex_root = -2; 616 if (mntflags & MNT_RDONLY) 617 args.export.ex_flags = MNT_EXRDONLY; 618 else 619 args.export.ex_flags = 0; 620 args.base = membase; 621 args.size = fssize * sectorsize; 622 623 error = getvfsbyname("mfs", &vfc); 624 if (error && vfsisloadable("mfs")) { 625 if (vfsload("mfs")) 626 fatal("vfsload(mfs)"); 627 endvfsent(); /* flush cache */ 628 error = getvfsbyname("mfs", &vfc); 629 } 630 if (error) 631 fatal("mfs filesystem not available"); 632 633 if (mount(vfc.vfc_name, argv[1], mntflags, &args) < 0) 634 fatal("%s: %s", argv[1], strerror(errno)); 635 if(filename) { 636 munmap(membase,fssize * sectorsize); 637 } 638 } 639 #endif 640 exit(0); 641 } 642 643 #ifdef COMPAT 644 char lmsg[] = "%s: can't read disk label; disk type must be specified"; 645 #else 646 char lmsg[] = "%s: can't read disk label"; 647 #endif 648 649 struct disklabel * 650 getdisklabel(s, fd) 651 char *s; 652 int fd; 653 { 654 static struct disklabel lab; 655 656 if (ioctl(fd, DIOCGDINFO, (char *)&lab) < 0) { 657 #ifdef COMPAT 658 if (disktype) { 659 struct disklabel *lp, *getdiskbyname(); 660 661 unlabeled++; 662 lp = getdiskbyname(disktype); 663 if (lp == NULL) 664 fatal("%s: unknown disk type", disktype); 665 return (lp); 666 } 667 #endif 668 warn("ioctl (GDINFO)"); 669 fatal(lmsg, s); 670 } 671 return (&lab); 672 } 673 674 rewritelabel(s, fd, lp) 675 char *s; 676 int fd; 677 register struct disklabel *lp; 678 { 679 #ifdef COMPAT 680 if (unlabeled) 681 return; 682 #endif 683 lp->d_checksum = 0; 684 lp->d_checksum = dkcksum(lp); 685 if (ioctl(fd, DIOCWDINFO, (char *)lp) < 0) { 686 warn("ioctl (WDINFO)"); 687 fatal("%s: can't rewrite disk label", s); 688 } 689 } 690 691 /*VARARGS*/ 692 void 693 #if __STDC__ 694 fatal(const char *fmt, ...) 695 #else 696 fatal(fmt, va_alist) 697 char *fmt; 698 va_dcl 699 #endif 700 { 701 va_list ap; 702 703 #if __STDC__ 704 va_start(ap, fmt); 705 #else 706 va_start(ap); 707 #endif 708 if (fcntl(STDERR_FILENO, F_GETFL) < 0) { 709 openlog(progname, LOG_CONS, LOG_DAEMON); 710 vsyslog(LOG_ERR, fmt, ap); 711 closelog(); 712 } else { 713 vwarnx(fmt, ap); 714 } 715 va_end(ap); 716 exit(1); 717 /*NOTREACHED*/ 718 } 719 720 static void 721 usage() 722 { 723 if (mfs) { 724 fprintf(stderr, 725 "usage: %s [ -fsoptions ] special-device mount-point\n", 726 progname); 727 } else 728 fprintf(stderr, 729 "usage: %s [ -fsoptions ] special-device%s\n", 730 progname, 731 #ifdef COMPAT 732 " [device-type]"); 733 #else 734 ""); 735 #endif 736 fprintf(stderr, "where fsoptions are:\n"); 737 fprintf(stderr, 738 "\t-N do not create file system, just print out parameters\n"); 739 fprintf(stderr, "\t-O create a 4.3BSD format filesystem\n"); 740 fprintf(stderr, "\t-S sector size\n"); 741 #ifdef COMPAT 742 fprintf(stderr, "\t-T disktype\n"); 743 #endif 744 fprintf(stderr, "\t-a maximum contiguous blocks\n"); 745 fprintf(stderr, "\t-b block size\n"); 746 fprintf(stderr, "\t-c cylinders/group\n"); 747 fprintf(stderr, "\t-d rotational delay between contiguous blocks\n"); 748 fprintf(stderr, "\t-e maximum blocks per file in a cylinder group\n"); 749 fprintf(stderr, "\t-f frag size\n"); 750 fprintf(stderr, "\t-i number of bytes per inode\n"); 751 fprintf(stderr, "\t-k sector 0 skew, per track\n"); 752 fprintf(stderr, "\t-l hardware sector interleave\n"); 753 fprintf(stderr, "\t-m minimum free space %%\n"); 754 fprintf(stderr, "\t-n number of distinguished rotational positions\n"); 755 fprintf(stderr, "\t-o optimization preference (`space' or `time')\n"); 756 fprintf(stderr, "\t-p spare sectors per track\n"); 757 fprintf(stderr, "\t-s file system size (sectors)\n"); 758 fprintf(stderr, "\t-r revolutions/minute\n"); 759 fprintf(stderr, "\t-t tracks/cylinder\n"); 760 fprintf(stderr, "\t-u sectors/track\n"); 761 fprintf(stderr, 762 "\t-v do not attempt to determine partition name from device name\n"); 763 fprintf(stderr, "\t-x spare sectors per cylinder\n"); 764 exit(1); 765 } 766