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