xref: /freebsd/sbin/newfs/newfs.c (revision df7f5d4de4592a8948a25ce01e5bddfbb7ce39dc)
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 char sccsid[] = "@(#)newfs.c	8.13 (Berkeley) 5/1/95";
36 #endif /* not lint */
37 
38 #ifndef lint
39 static char copyright[] =
40 "@(#) Copyright (c) 1983, 1989, 1993, 1994\n\
41 	The Regents of the University of California.  All rights reserved.\n";
42 #endif /* not lint */
43 
44 /*
45  * newfs: friendly front end to mkfs
46  */
47 #include <sys/param.h>
48 #include <sys/stat.h>
49 #include <sys/ioctl.h>
50 #include <sys/disklabel.h>
51 #include <sys/file.h>
52 #include <sys/mount.h>
53 
54 #include <ufs/ufs/dir.h>
55 #include <ufs/ufs/dinode.h>
56 #include <ufs/ffs/fs.h>
57 #include <ufs/ufs/ufsmount.h>
58 
59 #include <ctype.h>
60 #include <errno.h>
61 #include <paths.h>
62 #include <stdio.h>
63 #include <stdlib.h>
64 #include <string.h>
65 #include <syslog.h>
66 #include <unistd.h>
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	1024
98 #define	DFL_BLKSIZE	8192
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 16 cylinders
104  * per group.
105  */
106 #define	DESCPG		16	/* desired fs_cpg */
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 escentially 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 
157 #define NTRACKS		1	/* number of heads */
158 
159 #define NSECTORS	4096	/* number of sectors */
160 
161 int	mfs;			/* run as the memory based filesystem */
162 int	Nflag;			/* run without writing file system */
163 int	Oflag;			/* format as an 4.3BSD file system */
164 int	fssize;			/* file system size */
165 int	ntracks = NTRACKS;	/* # tracks/cylinder */
166 int	nsectors = NSECTORS;	/* # sectors/track */
167 int	nphyssectors;		/* # sectors/track including spares */
168 int	secpercyl;		/* sectors per cylinder */
169 int	trackspares = -1;	/* spare sectors per track */
170 int	cylspares = -1;		/* spare sectors per cylinder */
171 int	sectorsize;		/* bytes/sector */
172 int	realsectorsize;		/* bytes/sector in hardware */
173 int	rpm;			/* revolutions/minute of drive */
174 int	interleave;		/* hardware sector interleave */
175 int	trackskew = -1;		/* sector 0 skew, per track */
176 int	headswitch;		/* head switch time, usec */
177 int	trackseek;		/* track-to-track seek, usec */
178 int	fsize = 0;		/* fragment size */
179 int	bsize = 0;		/* block size */
180 int	cpg = DESCPG;		/* cylinders/cylinder group */
181 int	cpgflg;			/* cylinders/cylinder group flag was given */
182 int	minfree = MINFREE;	/* free space threshold */
183 int	opt = DEFAULTOPT;	/* optimization preference (space or time) */
184 int	density;		/* number of bytes per inode */
185 int	maxcontig = 0;		/* max contiguous blocks to allocate */
186 int	rotdelay = ROTDELAY;	/* rotational delay between blocks */
187 int	maxbpg;			/* maximum blocks per file in a cyl group */
188 int	nrpos = NRPOS;		/* # of distinguished rotational positions */
189 int	bbsize = BBSIZE;	/* boot block size */
190 int	sbsize = SBSIZE;	/* superblock size */
191 int	mntflags = MNT_ASYNC;	/* flags to be passed to mount */
192 int	t_or_u_flag = 0;	/* user has specified -t or -u */
193 u_long	memleft;		/* virtual memory available */
194 caddr_t	membase;		/* start address of memory based filesystem */
195 char	*filename;
196 #ifdef COMPAT
197 char	*disktype;
198 int	unlabeled;
199 #endif
200 
201 char	device[MAXPATHLEN];
202 char	*progname;
203 
204 int
205 main(argc, argv)
206 	int argc;
207 	char *argv[];
208 {
209 	extern char *optarg;
210 	extern int optind;
211 	register int ch;
212 	register struct partition *pp;
213 	register struct disklabel *lp;
214 	struct disklabel *getdisklabel();
215 	struct partition oldpartition;
216 	struct stat st;
217 	struct statfs *mp;
218 	int fsi, fso, len, n;
219 	char *cp, *s1, *s2, *special, *opstring, buf[BUFSIZ];
220 #ifdef MFS
221 	struct vfsconf vfc;
222 	int error;
223 #endif
224 
225 	if (progname = strrchr(*argv, '/'))
226 		++progname;
227 	else
228 		progname = *argv;
229 
230 	if (strstr(progname, "mfs")) {
231 		mfs = 1;
232 		Nflag++;
233 	}
234 
235 	opstring = mfs ?
236 	    "NF:T:a:b:c:d:e:f:i:m:o:s:" :
237 	    "NOS:T:a:b:c:d:e:f:i:k:l:m:n:o:p:r:s:t:u:x:";
238 	while ((ch = getopt(argc, argv, opstring)) != EOF)
239 		switch (ch) {
240 		case 'N':
241 			Nflag = 1;
242 			break;
243 		case 'O':
244 			Oflag = 1;
245 			break;
246 		case 'S':
247 			if ((sectorsize = atoi(optarg)) <= 0)
248 				fatal("%s: bad sector size", optarg);
249 			break;
250 #ifdef COMPAT
251 		case 'T':
252 			disktype = optarg;
253 			break;
254 #endif
255 		case 'F':
256 			filename = optarg;
257 			break;
258 		case 'a':
259 			if ((maxcontig = atoi(optarg)) <= 0)
260 				fatal("%s: bad maximum contiguous blocks\n",
261 				    optarg);
262 			break;
263 		case 'b':
264 			if ((bsize = atoi(optarg)) < MINBSIZE)
265 				fatal("%s: bad block size", optarg);
266 			break;
267 		case 'c':
268 			if ((cpg = atoi(optarg)) <= 0)
269 				fatal("%s: bad cylinders/group", optarg);
270 			cpgflg++;
271 			break;
272 		case 'd':
273 			if ((rotdelay = atoi(optarg)) < 0)
274 				fatal("%s: bad rotational delay\n", optarg);
275 			break;
276 		case 'e':
277 			if ((maxbpg = atoi(optarg)) <= 0)
278 		fatal("%s: bad blocks per file in a cylinder group\n",
279 				    optarg);
280 			break;
281 		case 'f':
282 			if ((fsize = atoi(optarg)) <= 0)
283 				fatal("%s: bad fragment size", optarg);
284 			break;
285 		case 'i':
286 			if ((density = atoi(optarg)) <= 0)
287 				fatal("%s: bad bytes per inode\n", optarg);
288 			break;
289 		case 'k':
290 			if ((trackskew = atoi(optarg)) < 0)
291 				fatal("%s: bad track skew", optarg);
292 			break;
293 		case 'l':
294 			if ((interleave = atoi(optarg)) <= 0)
295 				fatal("%s: bad interleave", optarg);
296 			break;
297 		case 'm':
298 			if ((minfree = atoi(optarg)) < 0 || minfree > 99)
299 				fatal("%s: bad free space %%\n", optarg);
300 			break;
301 		case 'n':
302 			if ((nrpos = atoi(optarg)) < 0)
303 				fatal("%s: bad rotational layout count\n",
304 				    optarg);
305 			if (nrpos == 0)
306 				nrpos = 1;
307 			break;
308 		case 'o':
309 			if (mfs)
310 				getmntopts(optarg, mopts, &mntflags, 0);
311 			else {
312 				if (strcmp(optarg, "space") == 0)
313 					opt = FS_OPTSPACE;
314 				else if (strcmp(optarg, "time") == 0)
315 					opt = FS_OPTTIME;
316 				else
317 	fatal("%s: unknown optimization preference: use `space' or `time'.");
318 			}
319 			break;
320 		case 'p':
321 			if ((trackspares = atoi(optarg)) < 0)
322 				fatal("%s: bad spare sectors per track",
323 				    optarg);
324 			break;
325 		case 'r':
326 			if ((rpm = atoi(optarg)) <= 0)
327 				fatal("%s: bad revolutions/minute\n", optarg);
328 			break;
329 		case 's':
330 			if ((fssize = atoi(optarg)) <= 0)
331 				fatal("%s: bad file system size", optarg);
332 			break;
333 		case 't':
334 			t_or_u_flag++;
335 			if ((ntracks = atoi(optarg)) < 0)
336 				fatal("%s: bad total tracks", optarg);
337 			break;
338 		case 'u':
339 			t_or_u_flag++;
340 			if ((nsectors = atoi(optarg)) < 0)
341 				fatal("%s: bad sectors/track", optarg);
342 			break;
343 		case 'x':
344 			if ((cylspares = atoi(optarg)) < 0)
345 				fatal("%s: bad spare sectors per cylinder",
346 				    optarg);
347 			break;
348 		case '?':
349 		default:
350 			usage();
351 		}
352 	argc -= optind;
353 	argv += optind;
354 
355 	if (argc != 2 && (mfs || argc != 1))
356 		usage();
357 
358 	special = argv[0];
359 	cp = strrchr(special, '/');
360 	if (cp == 0) {
361 		/*
362 		 * No path prefix; try /dev/r%s then /dev/%s.
363 		 */
364 		(void)sprintf(device, "%sr%s", _PATH_DEV, special);
365 		if (stat(device, &st) == -1)
366 			(void)sprintf(device, "%s%s", _PATH_DEV, special);
367 		special = device;
368 	}
369 	if (Nflag) {
370 		fso = -1;
371 	} else {
372 		fso = open(special, O_WRONLY);
373 		if (fso < 0)
374 			fatal("%s: %s", special, strerror(errno));
375 
376 		/* Bail if target special is mounted */
377 		n = getmntinfo(&mp, MNT_NOWAIT);
378 		if (n == 0)
379 			fatal("%s: getmntinfo: %s", special, strerror(errno));
380 
381 		len = sizeof(_PATH_DEV) - 1;
382 		s1 = special;
383 		if (strncmp(_PATH_DEV, s1, len) == 0)
384 			s1 += len;
385 
386 		while (--n >= 0) {
387 			s2 = mp->f_mntfromname;
388 			if (strncmp(_PATH_DEV, s2, len) == 0) {
389 				s2 += len - 1;
390 				*s2 = 'r';
391 			}
392 			if (strcmp(s1, s2) == 0 || strcmp(s1, &s2[1]) == 0)
393 				fatal("%s is mounted on %s",
394 				    special, mp->f_mntonname);
395 			++mp;
396 		}
397 	}
398 	if (mfs && disktype != NULL) {
399 		lp = (struct disklabel *)getdiskbyname(disktype);
400 		if (lp == NULL)
401 			fatal("%s: unknown disk type", disktype);
402 		pp = &lp->d_partitions[1];
403 	} else {
404 		fsi = open(special, O_RDONLY);
405 		if (fsi < 0)
406 			fatal("%s: %s", special, strerror(errno));
407 		if (fstat(fsi, &st) < 0)
408 			fatal("%s: %s", special, strerror(errno));
409 		if ((st.st_mode & S_IFMT) != S_IFCHR && !mfs)
410 			printf("%s: %s: not a character-special device\n",
411 			    progname, special);
412 		cp = strchr(argv[0], '\0') - 1;
413 		if (cp == (char *)-1 ||
414 		    (*cp < 'a' || *cp > 'h') && !isdigit(*cp))
415 			fatal("%s: can't figure out file system partition",
416 			    argv[0]);
417 #ifdef COMPAT
418 		if (!mfs && disktype == NULL)
419 			disktype = argv[1];
420 #endif
421 		lp = getdisklabel(special, fsi);
422 		if (isdigit(*cp))
423 			pp = &lp->d_partitions[0];
424 		else
425 			pp = &lp->d_partitions[*cp - 'a'];
426 		if (pp->p_size == 0)
427 			fatal("%s: `%c' partition is unavailable",
428 			    argv[0], *cp);
429 		if (pp->p_fstype == FS_BOOT)
430 			fatal("%s: `%c' partition overlaps boot program",
431 			      argv[0], *cp);
432 	}
433 	if (fssize == 0)
434 		fssize = pp->p_size;
435 	if (fssize > pp->p_size && !mfs)
436 	       fatal("%s: maximum file system size on the `%c' partition is %d",
437 			argv[0], *cp, pp->p_size);
438 	if (rpm == 0) {
439 		rpm = lp->d_rpm;
440 		if (rpm <= 0)
441 			rpm = 3600;
442 	}
443 	if (ntracks == 0) {
444 		ntracks = lp->d_ntracks;
445 		if (ntracks <= 0)
446 			fatal("%s: no default #tracks", argv[0]);
447 	}
448 	if (nsectors == 0) {
449 		nsectors = lp->d_nsectors;
450 		if (nsectors <= 0)
451 			fatal("%s: no default #sectors/track", argv[0]);
452 	}
453 	if (sectorsize == 0) {
454 		sectorsize = lp->d_secsize;
455 		if (sectorsize <= 0)
456 			fatal("%s: no default sector size", argv[0]);
457 	}
458 	if (trackskew == -1) {
459 		trackskew = lp->d_trackskew;
460 		if (trackskew < 0)
461 			trackskew = 0;
462 	}
463 	if (interleave == 0) {
464 		interleave = lp->d_interleave;
465 		if (interleave <= 0)
466 			interleave = 1;
467 	}
468 	if (fsize == 0) {
469 		fsize = pp->p_fsize;
470 		if (fsize <= 0)
471 			fsize = MAX(DFL_FRAGSIZE, lp->d_secsize);
472 	}
473 	if (bsize == 0) {
474 		bsize = pp->p_frag * pp->p_fsize;
475 		if (bsize <= 0)
476 			bsize = MIN(DFL_BLKSIZE, 8 * fsize);
477 	}
478 	/*
479 	 * Maxcontig sets the default for the maximum number of blocks
480 	 * that may be allocated sequentially. With filesystem clustering
481 	 * it is possible to allocate contiguous blocks up to the maximum
482 	 * transfer size permitted by the controller or buffering.
483 	 */
484 	if (maxcontig == 0)
485 		maxcontig = MAX(1, MAXPHYS / bsize - 1);
486 	if (density == 0)
487 		density = NFPI * fsize;
488 	if (minfree < MINFREE && opt != FS_OPTSPACE) {
489 		fprintf(stderr, "Warning: changing optimization to space ");
490 		fprintf(stderr, "because minfree is less than %d%%\n", MINFREE);
491 		opt = FS_OPTSPACE;
492 	}
493 	if (trackspares == -1) {
494 		trackspares = lp->d_sparespertrack;
495 		if (trackspares < 0)
496 			trackspares = 0;
497 	}
498 	nphyssectors = nsectors + trackspares;
499 	if (cylspares == -1) {
500 		cylspares = lp->d_sparespercyl;
501 		if (cylspares < 0)
502 			cylspares = 0;
503 	}
504 	secpercyl = nsectors * ntracks - cylspares;
505 	/*
506 	 * Only complain if -t or -u have been specified; the default
507 	 * case (4096 sectors per cylinder) is intented to disagree
508 	 * with the disklabel.
509 	 */
510 	if (t_or_u_flag && secpercyl != lp->d_secpercyl)
511 		fprintf(stderr, "%s (%d) %s (%lu)\n",
512 			"Warning: calculated sectors per cylinder", secpercyl,
513 			"disagrees with disk label", lp->d_secpercyl);
514 	if (maxbpg == 0)
515 		maxbpg = MAXBLKPG(bsize);
516 	headswitch = lp->d_headswitch;
517 	trackseek = lp->d_trkseek;
518 #ifdef notdef /* label may be 0 if faked up by kernel */
519 	bbsize = lp->d_bbsize;
520 	sbsize = lp->d_sbsize;
521 #endif
522 	oldpartition = *pp;
523 #ifdef tahoe
524 	realsectorsize = sectorsize;
525 	if (sectorsize != DEV_BSIZE) {		/* XXX */
526 		int secperblk = DEV_BSIZE / sectorsize;
527 
528 		sectorsize = DEV_BSIZE;
529 		nsectors /= secperblk;
530 		nphyssectors /= secperblk;
531 		secpercyl /= secperblk;
532 		fssize /= secperblk;
533 		pp->p_size /= secperblk;
534 	}
535 #else
536 	realsectorsize = sectorsize;
537 	if (sectorsize != DEV_BSIZE) {		/* XXX */
538 		int secperblk = sectorsize / DEV_BSIZE;
539 
540 		sectorsize = DEV_BSIZE;
541 		nsectors *= secperblk;
542 		nphyssectors *= secperblk;
543 		secpercyl *= secperblk;
544 		fssize *= secperblk;
545 		pp->p_size *= secperblk;
546 	}
547 #endif
548 	mkfs(pp, special, fsi, fso);
549 #ifdef tahoe
550 	if (realsectorsize != DEV_BSIZE)
551 		pp->p_size *= DEV_BSIZE / realsectorsize;
552 #else
553 	if (realsectorsize != DEV_BSIZE)
554 		pp->p_size /= realsectorsize /DEV_BSIZE;
555 #endif
556 	if (!Nflag)
557 		close(fso);
558 	close(fsi);
559 #ifdef MFS
560 	if (mfs) {
561 		struct mfs_args args;
562 
563 		sprintf(buf, "mfs:%d", getpid());
564 		args.fspec = buf;
565 		args.export.ex_root = -2;
566 		if (mntflags & MNT_RDONLY)
567 			args.export.ex_flags = MNT_EXRDONLY;
568 		else
569 			args.export.ex_flags = 0;
570 		args.base = membase;
571 		args.size = fssize * sectorsize;
572 
573 		error = getvfsbyname("mfs", &vfc);
574 		if (error && vfsisloadable("mfs")) {
575 			if (vfsload("mfs"))
576 				fatal("vfsload(mfs)");
577 			endvfsent();	/* flush cache */
578 			error = getvfsbyname("mfs", &vfc);
579 		}
580 		if (error)
581 			fatal("mfs filesystem not available");
582 
583 		if (mount(vfc.vfc_name, argv[1], mntflags, &args) < 0)
584 			fatal("%s: %s", argv[1], strerror(errno));
585 		if(filename) {
586 			munmap(membase,fssize * sectorsize);
587 		}
588 	}
589 #endif
590 	exit(0);
591 }
592 
593 #ifdef COMPAT
594 char lmsg[] = "%s: can't read disk label; disk type must be specified";
595 #else
596 char lmsg[] = "%s: can't read disk label";
597 #endif
598 
599 struct disklabel *
600 getdisklabel(s, fd)
601 	char *s;
602 	int fd;
603 {
604 	static struct disklabel lab;
605 
606 	if (ioctl(fd, DIOCGDINFO, (char *)&lab) < 0) {
607 #ifdef COMPAT
608 		if (disktype) {
609 			struct disklabel *lp, *getdiskbyname();
610 
611 			unlabeled++;
612 			lp = getdiskbyname(disktype);
613 			if (lp == NULL)
614 				fatal("%s: unknown disk type", disktype);
615 			return (lp);
616 		}
617 #endif
618 		warn("ioctl (GDINFO)");
619 		fatal(lmsg, s);
620 	}
621 	return (&lab);
622 }
623 
624 /*VARARGS*/
625 void
626 #if __STDC__
627 fatal(const char *fmt, ...)
628 #else
629 fatal(fmt, va_alist)
630 	char *fmt;
631 	va_dcl
632 #endif
633 {
634 	va_list ap;
635 
636 #if __STDC__
637 	va_start(ap, fmt);
638 #else
639 	va_start(ap);
640 #endif
641 	if (fcntl(STDERR_FILENO, F_GETFL) < 0) {
642 		openlog(progname, LOG_CONS, LOG_DAEMON);
643 		vsyslog(LOG_ERR, fmt, ap);
644 		closelog();
645 	} else {
646 		vwarnx(fmt, ap);
647 	}
648 	va_end(ap);
649 	exit(1);
650 	/*NOTREACHED*/
651 }
652 
653 usage()
654 {
655 	if (mfs) {
656 		fprintf(stderr,
657 		    "usage: %s [ -fsoptions ] special-device mount-point\n",
658 			progname);
659 	} else
660 		fprintf(stderr,
661 		    "usage: %s [ -fsoptions ] special-device%s\n",
662 		    progname,
663 #ifdef COMPAT
664 		    " [device-type]");
665 #else
666 		    "");
667 #endif
668 	fprintf(stderr, "where fsoptions are:\n");
669 	fprintf(stderr,
670 	    "\t-N do not create file system, just print out parameters\n");
671 	fprintf(stderr, "\t-O create a 4.3BSD format filesystem\n");
672 	fprintf(stderr, "\t-S sector size\n");
673 #ifdef COMPAT
674 	fprintf(stderr, "\t-T disktype\n");
675 #endif
676 	fprintf(stderr, "\t-a maximum contiguous blocks\n");
677 	fprintf(stderr, "\t-b block size\n");
678 	fprintf(stderr, "\t-c cylinders/group\n");
679 	fprintf(stderr, "\t-d rotational delay between contiguous blocks\n");
680 	fprintf(stderr, "\t-e maximum blocks per file in a cylinder group\n");
681 	fprintf(stderr, "\t-f frag size\n");
682 	fprintf(stderr, "\t-i number of bytes per inode\n");
683 	fprintf(stderr, "\t-k sector 0 skew, per track\n");
684 	fprintf(stderr, "\t-l hardware sector interleave\n");
685 	fprintf(stderr, "\t-m minimum free space %%\n");
686 	fprintf(stderr, "\t-n number of distinguished rotational positions\n");
687 	fprintf(stderr, "\t-o optimization preference (`space' or `time')\n");
688 	fprintf(stderr, "\t-p spare sectors per track\n");
689 	fprintf(stderr, "\t-s file system size (sectors)\n");
690 	fprintf(stderr, "\t-r revolutions/minute\n");
691 	fprintf(stderr, "\t-t tracks/cylinder\n");
692 	fprintf(stderr, "\t-u sectors/track\n");
693 	fprintf(stderr, "\t-x spare sectors per cylinder\n");
694 	exit(1);
695 }
696