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