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