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