Home | History | Annotate | Line # | Download | only in newfs
newfs.c revision 1.47
      1  1.47     lukem /*	$NetBSD: newfs.c,v 1.47 2001/09/06 02:16:01 lukem Exp $	*/
      2  1.18       cgd 
      3   1.1       cgd /*
      4  1.10   mycroft  * Copyright (c) 1983, 1989, 1993, 1994
      5  1.10   mycroft  *	The Regents of the University of California.  All rights reserved.
      6   1.1       cgd  *
      7   1.1       cgd  * Redistribution and use in source and binary forms, with or without
      8   1.1       cgd  * modification, are permitted provided that the following conditions
      9   1.1       cgd  * are met:
     10   1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     11   1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     12   1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     14   1.1       cgd  *    documentation and/or other materials provided with the distribution.
     15   1.1       cgd  * 3. All advertising materials mentioning features or use of this software
     16   1.1       cgd  *    must display the following acknowledgement:
     17   1.1       cgd  *	This product includes software developed by the University of
     18   1.1       cgd  *	California, Berkeley and its contributors.
     19   1.1       cgd  * 4. Neither the name of the University nor the names of its contributors
     20   1.1       cgd  *    may be used to endorse or promote products derived from this software
     21   1.1       cgd  *    without specific prior written permission.
     22   1.1       cgd  *
     23   1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24   1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25   1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26   1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27   1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28   1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29   1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30   1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31   1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32   1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33   1.1       cgd  * SUCH DAMAGE.
     34   1.1       cgd  */
     35   1.1       cgd 
     36  1.25  christos #include <sys/cdefs.h>
     37   1.1       cgd #ifndef lint
     38  1.25  christos __COPYRIGHT("@(#) Copyright (c) 1983, 1989, 1993, 1994\n\
     39  1.25  christos 	The Regents of the University of California.  All rights reserved.\n");
     40   1.1       cgd #endif /* not lint */
     41   1.1       cgd 
     42   1.1       cgd #ifndef lint
     43  1.18       cgd #if 0
     44  1.27     lukem static char sccsid[] = "@(#)newfs.c	8.13 (Berkeley) 5/1/95";
     45  1.18       cgd #else
     46  1.47     lukem __RCSID("$NetBSD: newfs.c,v 1.47 2001/09/06 02:16:01 lukem Exp $");
     47  1.18       cgd #endif
     48   1.1       cgd #endif /* not lint */
     49   1.1       cgd 
     50   1.1       cgd /*
     51   1.1       cgd  * newfs: friendly front end to mkfs
     52   1.1       cgd  */
     53   1.1       cgd #include <sys/param.h>
     54   1.1       cgd #include <sys/stat.h>
     55   1.1       cgd #include <sys/ioctl.h>
     56   1.1       cgd #include <sys/disklabel.h>
     57   1.1       cgd #include <sys/file.h>
     58   1.1       cgd #include <sys/mount.h>
     59  1.19   thorpej #include <sys/sysctl.h>
     60  1.30  drochner #include <sys/wait.h>
     61   1.1       cgd 
     62  1.10   mycroft #include <ufs/ufs/dir.h>
     63  1.27     lukem #include <ufs/ufs/dinode.h>
     64  1.32      fvdl #include <ufs/ufs/ufsmount.h>
     65  1.10   mycroft #include <ufs/ffs/fs.h>
     66  1.10   mycroft 
     67  1.10   mycroft #include <ctype.h>
     68  1.37      tron #include <disktab.h>
     69   1.1       cgd #include <errno.h>
     70  1.10   mycroft #include <paths.h>
     71   1.1       cgd #include <stdio.h>
     72  1.10   mycroft #include <stdlib.h>
     73   1.1       cgd #include <string.h>
     74  1.10   mycroft #include <syslog.h>
     75  1.10   mycroft #include <unistd.h>
     76  1.30  drochner #include <signal.h>
     77  1.25  christos #include <err.h>
     78  1.20   thorpej #include <util.h>
     79  1.10   mycroft 
     80  1.10   mycroft #include "mntopts.h"
     81  1.25  christos #include "dkcksum.h"
     82  1.25  christos #include "extern.h"
     83  1.10   mycroft 
     84  1.10   mycroft struct mntopt mopts[] = {
     85  1.10   mycroft 	MOPT_STDOPTS,
     86  1.10   mycroft 	MOPT_ASYNC,
     87  1.22       cgd 	MOPT_UPDATE,
     88  1.23       tls 	MOPT_NOATIME,
     89  1.10   mycroft 	{ NULL },
     90  1.10   mycroft };
     91  1.10   mycroft 
     92  1.40    simonb static struct disklabel *getdisklabel(char *, int);
     93  1.40    simonb static void rewritelabel(char *, int, struct disklabel *);
     94  1.43     lukem static int strsuftoi(const char *, const char *, int, int);
     95  1.40    simonb static void usage(void);
     96  1.40    simonb int main(int, char *[]);
     97   1.1       cgd 
     98   1.1       cgd #define	COMPAT			/* allow non-labeled disks */
     99   1.1       cgd 
    100   1.1       cgd /*
    101   1.1       cgd  * The following two constants set the default block and fragment sizes.
    102   1.1       cgd  * Both constants must be a power of 2 and meet the following constraints:
    103   1.1       cgd  *	MINBSIZE <= DESBLKSIZE <= MAXBSIZE
    104   1.1       cgd  *	sectorsize <= DESFRAGSIZE <= DESBLKSIZE
    105   1.1       cgd  *	DESBLKSIZE / DESFRAGSIZE <= 8
    106   1.1       cgd  */
    107   1.1       cgd #define	DFL_FRAGSIZE	1024
    108   1.1       cgd #define	DFL_BLKSIZE	8192
    109   1.1       cgd 
    110   1.1       cgd /*
    111  1.43     lukem  * Default sector size.
    112  1.43     lukem  */
    113  1.43     lukem #define DFL_SECSIZE	512
    114  1.43     lukem 
    115  1.43     lukem /*
    116   1.1       cgd  * Cylinder groups may have up to many cylinders. The actual
    117   1.1       cgd  * number used depends upon how much information can be stored
    118   1.1       cgd  * on a single cylinder. The default is to use 16 cylinders
    119   1.1       cgd  * per group.
    120   1.1       cgd  */
    121   1.1       cgd #define	DESCPG		16	/* desired fs_cpg */
    122   1.1       cgd 
    123   1.1       cgd /*
    124   1.1       cgd  * ROTDELAY gives the minimum number of milliseconds to initiate
    125   1.1       cgd  * another disk transfer on the same cylinder. It is used in
    126   1.1       cgd  * determining the rotationally optimal layout for disk blocks
    127  1.13   mycroft  * within a file; the default of fs_rotdelay is 0ms.
    128   1.1       cgd  */
    129  1.13   mycroft #define ROTDELAY	0
    130   1.1       cgd 
    131   1.1       cgd /*
    132   1.1       cgd  * MAXBLKPG determines the maximum number of data blocks which are
    133   1.1       cgd  * placed in a single cylinder group. The default is one indirect
    134   1.1       cgd  * block worth of data blocks.
    135   1.1       cgd  */
    136   1.1       cgd #define MAXBLKPG(bsize)	((bsize) / sizeof(daddr_t))
    137   1.1       cgd 
    138   1.1       cgd /*
    139   1.1       cgd  * Each file system has a number of inodes statically allocated.
    140   1.1       cgd  * We allocate one inode slot per NFPI fragments, expecting this
    141   1.1       cgd  * to be far more than we will ever need.
    142   1.1       cgd  */
    143   1.1       cgd #define	NFPI		4
    144   1.1       cgd 
    145   1.1       cgd /*
    146   1.1       cgd  * For each cylinder we keep track of the availability of blocks at different
    147   1.1       cgd  * rotational positions, so that we can lay out the data to be picked
    148   1.1       cgd  * up with minimum rotational latency.  NRPOS is the default number of
    149   1.1       cgd  * rotational positions that we distinguish.  With NRPOS of 8 the resolution
    150  1.13   mycroft  * of our summary information is 2ms for a typical 3600 rpm drive.  Caching
    151  1.13   mycroft  * and zoning pretty much defeats rotational optimization, so we now use a
    152  1.13   mycroft  * default of 1.
    153   1.1       cgd  */
    154  1.13   mycroft #define	NRPOS		1	/* number distinct rotational positions */
    155   1.1       cgd 
    156   1.1       cgd 
    157   1.1       cgd int	mfs;			/* run as the memory based filesystem */
    158   1.1       cgd int	Nflag;			/* run without writing file system */
    159  1.10   mycroft int	Oflag;			/* format as an 4.3BSD file system */
    160   1.1       cgd int	fssize;			/* file system size */
    161   1.1       cgd int	ntracks;		/* # tracks/cylinder */
    162   1.1       cgd int	nsectors;		/* # sectors/track */
    163   1.1       cgd int	nphyssectors;		/* # sectors/track including spares */
    164   1.1       cgd int	secpercyl;		/* sectors per cylinder */
    165   1.1       cgd int	trackspares = -1;	/* spare sectors per track */
    166   1.1       cgd int	cylspares = -1;		/* spare sectors per cylinder */
    167   1.1       cgd int	sectorsize;		/* bytes/sector */
    168   1.1       cgd int	rpm;			/* revolutions/minute of drive */
    169   1.1       cgd int	interleave;		/* hardware sector interleave */
    170   1.1       cgd int	trackskew = -1;		/* sector 0 skew, per track */
    171   1.1       cgd int	fsize = 0;		/* fragment size */
    172   1.1       cgd int	bsize = 0;		/* block size */
    173   1.1       cgd int	cpg = DESCPG;		/* cylinders/cylinder group */
    174   1.1       cgd int	cpgflg;			/* cylinders/cylinder group flag was given */
    175   1.1       cgd int	minfree = MINFREE;	/* free space threshold */
    176   1.1       cgd int	opt = DEFAULTOPT;	/* optimization preference (space or time) */
    177   1.1       cgd int	density;		/* number of bytes per inode */
    178  1.36   mycroft int	maxcontig = 0;		/* max contiguous blocks to allocate */
    179   1.1       cgd int	rotdelay = ROTDELAY;	/* rotational delay between blocks */
    180   1.1       cgd int	maxbpg;			/* maximum blocks per file in a cyl group */
    181   1.1       cgd int	nrpos = NRPOS;		/* # of distinguished rotational positions */
    182  1.47     lukem int	avgfilesize = AVFILESIZ;/* expected average file size */
    183  1.47     lukem int	avgfpdir = AFPDIR;	/* expected number of files per directory */
    184   1.1       cgd int	bbsize = BBSIZE;	/* boot block size */
    185   1.1       cgd int	sbsize = SBSIZE;	/* superblock size */
    186  1.10   mycroft int	mntflags = MNT_ASYNC;	/* flags to be passed to mount */
    187   1.1       cgd u_long	memleft;		/* virtual memory available */
    188   1.1       cgd caddr_t	membase;		/* start address of memory based filesystem */
    189  1.43     lukem int	needswap;		/* Filesystem not in native byte order */
    190   1.1       cgd #ifdef COMPAT
    191   1.1       cgd char	*disktype;
    192   1.1       cgd int	unlabeled;
    193   1.1       cgd #endif
    194   1.1       cgd 
    195   1.1       cgd char	device[MAXPATHLEN];
    196   1.1       cgd 
    197  1.10   mycroft int
    198  1.40    simonb main(int argc, char *argv[])
    199   1.1       cgd {
    200  1.25  christos 	struct partition *pp;
    201  1.25  christos 	struct disklabel *lp;
    202  1.14       cgd 	struct disklabel mfsfakelabel;
    203   1.1       cgd 	struct partition oldpartition;
    204   1.1       cgd 	struct stat st;
    205  1.10   mycroft 	struct statfs *mp;
    206  1.43     lukem 	int ch, fsi, fso, len, maxpartitions, n, Fflag, Zflag;
    207  1.43     lukem 	char *cp, *endp, *s1, *s2, *special;
    208  1.43     lukem 	const char *opstring;
    209  1.43     lukem 	long long llsize;
    210  1.30  drochner #ifdef MFS
    211  1.30  drochner 	char mountfromname[100];
    212  1.30  drochner 	pid_t pid, res;
    213  1.30  drochner 	struct statfs sf;
    214  1.30  drochner 	int status;
    215  1.30  drochner #endif
    216   1.1       cgd 
    217  1.43     lukem 	cp = NULL;
    218  1.43     lukem 	fsi = fso = -1;
    219  1.43     lukem 	Fflag = Zflag = 0;
    220  1.42       cgd 	if (strstr(getprogname(), "mfs")) {
    221   1.1       cgd 		mfs = 1;
    222   1.1       cgd 		Nflag++;
    223   1.1       cgd 	}
    224   1.1       cgd 
    225  1.19   thorpej 	maxpartitions = getmaxpartitions();
    226  1.19   thorpej 	if (maxpartitions > 26)
    227  1.25  christos 		errx(1, "insane maxpartitions value %d", maxpartitions);
    228  1.19   thorpej 
    229  1.10   mycroft 	opstring = mfs ?
    230  1.47     lukem 	    "NT:a:b:c:d:e:f:g:h:i:m:o:s:" :
    231  1.47     lukem 	    "B:FNOS:T:Za:b:c:d:e:f:g:h:i:k:l:m:n:o:p:r:s:t:u:x:";
    232  1.26     lukem 	while ((ch = getopt(argc, argv, opstring)) != -1)
    233  1.10   mycroft 		switch (ch) {
    234  1.33    bouyer 		case 'B':
    235  1.33    bouyer 			if (strcmp(optarg, "be") == 0) {
    236  1.33    bouyer #if BYTE_ORDER == LITTLE_ENDIAN
    237  1.33    bouyer 				needswap = 1;
    238  1.33    bouyer #endif
    239  1.33    bouyer 			} else if (strcmp(optarg, "le") == 0) {
    240  1.33    bouyer #if BYTE_ORDER == BIG_ENDIAN
    241  1.33    bouyer 				needswap = 1;
    242  1.33    bouyer #endif
    243  1.33    bouyer 			} else
    244  1.33    bouyer 				usage();
    245  1.33    bouyer 			break;
    246  1.43     lukem 		case 'F':
    247  1.43     lukem 			Fflag = 1;
    248  1.43     lukem 			break;
    249  1.10   mycroft 		case 'N':
    250  1.10   mycroft 			Nflag = 1;
    251   1.1       cgd 			break;
    252  1.10   mycroft 		case 'O':
    253  1.10   mycroft 			Oflag = 1;
    254   1.1       cgd 			break;
    255   1.1       cgd 		case 'S':
    256  1.43     lukem 			sectorsize = strsuftoi("sector size",
    257  1.43     lukem 			    optarg, 1, INT_MAX);
    258   1.1       cgd 			break;
    259   1.1       cgd #ifdef COMPAT
    260   1.1       cgd 		case 'T':
    261   1.1       cgd 			disktype = optarg;
    262   1.1       cgd 			break;
    263   1.1       cgd #endif
    264  1.43     lukem 		case 'Z':
    265  1.43     lukem 			Zflag = 1;
    266  1.43     lukem 			break;
    267   1.1       cgd 		case 'a':
    268  1.43     lukem 			maxcontig = strsuftoi("maximum contiguous blocks",
    269  1.43     lukem 			    optarg, 1, INT_MAX);
    270   1.1       cgd 			break;
    271   1.1       cgd 		case 'b':
    272  1.43     lukem 			bsize = strsuftoi("block size",
    273  1.43     lukem 			    optarg, MINBSIZE, INT_MAX);
    274   1.1       cgd 			break;
    275   1.1       cgd 		case 'c':
    276  1.43     lukem 			cpg = strsuftoi("cylinders per group",
    277  1.43     lukem 			    optarg, 1, INT_MAX);
    278   1.1       cgd 			cpgflg++;
    279   1.1       cgd 			break;
    280   1.1       cgd 		case 'd':
    281  1.43     lukem 			rotdelay = strsuftoi("rotational delay",
    282  1.43     lukem 			    optarg, 0, INT_MAX);
    283   1.1       cgd 			break;
    284   1.1       cgd 		case 'e':
    285  1.43     lukem 			maxbpg = strsuftoi(
    286  1.43     lukem 			    "blocks per file in a cylinder group",
    287  1.43     lukem 			    optarg, 1, INT_MAX);
    288   1.1       cgd 			break;
    289   1.1       cgd 		case 'f':
    290  1.43     lukem 			fsize = strsuftoi("fragment size",
    291  1.43     lukem 			    optarg, 1, INT_MAX);
    292   1.1       cgd 			break;
    293  1.47     lukem 		case 'g':
    294  1.47     lukem 			avgfilesize = strsuftoi("average file size",
    295  1.47     lukem 			    optarg, 1, INT_MAX);
    296  1.47     lukem 			break;
    297  1.47     lukem 		case 'h':
    298  1.47     lukem 			avgfpdir = strsuftoi("expected files per directory",
    299  1.47     lukem 			    optarg, 1, INT_MAX);
    300  1.47     lukem 			break;
    301   1.1       cgd 		case 'i':
    302  1.43     lukem 			density = strsuftoi("bytes per inode",
    303  1.43     lukem 			    optarg, 1, INT_MAX);
    304   1.1       cgd 			break;
    305   1.1       cgd 		case 'k':
    306  1.43     lukem 			trackskew = strsuftoi("track skew",
    307  1.43     lukem 			    optarg, 0, INT_MAX);
    308   1.1       cgd 			break;
    309   1.1       cgd 		case 'l':
    310  1.43     lukem 			interleave = strsuftoi("interleave",
    311  1.43     lukem 			    optarg, 1, INT_MAX);
    312   1.1       cgd 			break;
    313   1.1       cgd 		case 'm':
    314  1.43     lukem 			minfree = strsuftoi("free space %",
    315  1.43     lukem 			    optarg, 0, 99);
    316   1.1       cgd 			break;
    317   1.1       cgd 		case 'n':
    318  1.43     lukem 			nrpos = strsuftoi("rotational layout count",
    319  1.43     lukem 			    optarg, 1, INT_MAX);
    320   1.1       cgd 			break;
    321   1.1       cgd 		case 'o':
    322  1.10   mycroft 			if (mfs)
    323  1.27     lukem 				getmntopts(optarg, mopts, &mntflags, 0);
    324  1.10   mycroft 			else {
    325  1.10   mycroft 				if (strcmp(optarg, "space") == 0)
    326  1.10   mycroft 					opt = FS_OPTSPACE;
    327  1.10   mycroft 				else if (strcmp(optarg, "time") == 0)
    328  1.10   mycroft 					opt = FS_OPTTIME;
    329  1.10   mycroft 				else
    330  1.25  christos 				    errx(1, "%s %s",
    331  1.25  christos 					"unknown optimization preference: ",
    332  1.25  christos 					"use `space' or `time'.");
    333  1.10   mycroft 			}
    334   1.1       cgd 			break;
    335   1.1       cgd 		case 'p':
    336  1.43     lukem 			trackspares = strsuftoi("spare sectors per track",
    337  1.43     lukem 			    optarg, 0, INT_MAX);
    338   1.1       cgd 			break;
    339   1.1       cgd 		case 'r':
    340  1.43     lukem 			rpm = strsuftoi("revolutions per minute",
    341  1.43     lukem 			    optarg, 1, INT_MAX);
    342   1.1       cgd 			break;
    343   1.1       cgd 		case 's':
    344  1.43     lukem 			llsize = strtoll(optarg, &endp, 10);
    345  1.43     lukem 			if (endp[0] != '\0' && endp[1] != '\0')
    346  1.43     lukem 				llsize = -1;
    347  1.43     lukem 			else {
    348  1.43     lukem 				int	ssiz;
    349  1.43     lukem 
    350  1.43     lukem 				ssiz = (sectorsize ? sectorsize : DFL_SECSIZE);
    351  1.43     lukem 				switch (tolower((unsigned char)endp[0])) {
    352  1.43     lukem 				case 'b':
    353  1.43     lukem 					llsize /= ssiz;
    354  1.43     lukem 					break;
    355  1.43     lukem 				case 'k':
    356  1.43     lukem 					llsize *= 1024 / ssiz;
    357  1.43     lukem 					break;
    358  1.43     lukem 				case 'm':
    359  1.43     lukem 					llsize *= 1024 * 1024 / ssiz;
    360  1.43     lukem 					break;
    361  1.43     lukem 				case 'g':
    362  1.43     lukem 					llsize *= 1024 * 1024 * 1024 / ssiz;
    363  1.43     lukem 					break;
    364  1.43     lukem 				case '\0':
    365  1.43     lukem 				case 's':
    366  1.43     lukem 					break;
    367  1.43     lukem 				default:
    368  1.43     lukem 					llsize = -1;
    369  1.41    simonb 				}
    370  1.41    simonb 			}
    371  1.43     lukem 			if (llsize > INT_MAX)
    372  1.43     lukem 				errx(1, "file system size `%s' is too large.",
    373  1.43     lukem 				    optarg);
    374  1.43     lukem 			if (llsize <= 0)
    375  1.43     lukem 				errx(1,
    376  1.43     lukem 			    "`%s' is not a valid number for file system size.",
    377  1.43     lukem 				    optarg);
    378  1.43     lukem 			fssize = (int)llsize;
    379   1.1       cgd 			break;
    380   1.1       cgd 		case 't':
    381  1.43     lukem 			ntracks = strsuftoi("total tracks",
    382  1.43     lukem 			    optarg, 1, INT_MAX);
    383   1.1       cgd 			break;
    384   1.1       cgd 		case 'u':
    385  1.43     lukem 			nsectors = strsuftoi("sectors per track",
    386  1.43     lukem 			    optarg, 1, INT_MAX);
    387   1.1       cgd 			break;
    388   1.1       cgd 		case 'x':
    389  1.43     lukem 			cylspares = strsuftoi("spare sectors per cylinder",
    390  1.43     lukem 			    optarg, 0, INT_MAX);
    391   1.1       cgd 			break;
    392   1.1       cgd 		case '?':
    393   1.1       cgd 		default:
    394   1.1       cgd 			usage();
    395   1.1       cgd 		}
    396   1.1       cgd 	argc -= optind;
    397   1.1       cgd 	argv += optind;
    398   1.1       cgd 
    399   1.1       cgd 	if (argc != 2 && (mfs || argc != 1))
    400   1.1       cgd 		usage();
    401   1.1       cgd 
    402   1.1       cgd 	special = argv[0];
    403  1.43     lukem 	if ((mfs && !strcmp(special, "swap")) || Fflag) {
    404  1.14       cgd 		/*
    405  1.43     lukem 		 * it's an MFS mounted on "swap" or a file system image;
    406  1.43     lukem 		 * fake up a label.		XXX
    407  1.14       cgd 		 */
    408  1.43     lukem 		if (!sectorsize)
    409  1.43     lukem 			sectorsize = DFL_SECSIZE;
    410  1.43     lukem 
    411  1.43     lukem 		if (Fflag && (stat(special, &st) != -1 && !S_ISREG(st.st_mode)))
    412  1.43     lukem 			errx(1, "%s is not a regular file", special);
    413  1.43     lukem 		if (Fflag && !Nflag) {	/* creating image in a regular file */
    414  1.44     lukem 			if (fssize == 0)
    415  1.44     lukem 				errx(1, "need to specify size when using -F");
    416  1.43     lukem 			fso = open(special, O_RDWR | O_CREAT | O_TRUNC, 0777);
    417  1.43     lukem 			if (fso == -1)
    418  1.43     lukem 				err(1, "can't open file %s", special);
    419  1.44     lukem 			if ((fsi = dup(fso)) == -1)
    420  1.44     lukem 				err(1, "can't dup(2) image fd");
    421  1.43     lukem 			if (ftruncate(fso, (off_t)fssize * sectorsize) == -1)
    422  1.43     lukem 				err(1, "can't resize %s to %d",
    423  1.43     lukem 				    special, fssize);
    424  1.43     lukem 
    425  1.43     lukem 			if (Zflag) {	/* pre-zero the file */
    426  1.43     lukem 				char	*buf;
    427  1.45     lukem 				int	bufsize, i;
    428  1.45     lukem 				off_t	bufrem;
    429  1.45     lukem 				struct statfs sfs;
    430  1.45     lukem 
    431  1.45     lukem 				if (fstatfs(fso, &sfs) == -1) {
    432  1.45     lukem 					warn("can't fstatfs `%s'", special);
    433  1.45     lukem 					bufsize = 8192;
    434  1.45     lukem 				} else
    435  1.45     lukem 					bufsize = sfs.f_iosize;
    436  1.43     lukem 
    437  1.45     lukem 				if ((buf = calloc(1, bufsize)) == NULL)
    438  1.43     lukem 					err(1, "can't malloc buffer of %d",
    439  1.45     lukem 					bufsize);
    440  1.45     lukem 				bufrem = fssize * sectorsize;
    441  1.43     lukem 				printf(
    442  1.45     lukem     "Creating file system image in `%s', size %lld bytes, in %d byte chunks.\n",
    443  1.45     lukem 				    special, (long long)bufrem, bufsize);
    444  1.45     lukem 				while (bufrem > 0) {
    445  1.45     lukem 					i = write(fso, buf,
    446  1.45     lukem 					    MIN(bufsize, bufrem));
    447  1.45     lukem 					if (i == -1)
    448  1.45     lukem 						err(1, "writing image");
    449  1.45     lukem 					bufrem -= i;
    450  1.43     lukem 				}
    451  1.43     lukem 			}
    452  1.43     lukem 
    453  1.43     lukem 		}
    454  1.14       cgd 
    455  1.14       cgd 		memset(&mfsfakelabel, 0, sizeof(mfsfakelabel));
    456  1.43     lukem 		mfsfakelabel.d_secsize = sectorsize;
    457  1.43     lukem 		mfsfakelabel.d_nsectors = 64;	/* these 3 add up to 16MB */
    458  1.14       cgd 		mfsfakelabel.d_ntracks = 16;
    459  1.14       cgd 		mfsfakelabel.d_ncylinders = 16;
    460  1.43     lukem 		mfsfakelabel.d_secpercyl =
    461  1.43     lukem 		    mfsfakelabel.d_nsectors * mfsfakelabel.d_ntracks;
    462  1.43     lukem 		mfsfakelabel.d_secperunit =
    463  1.43     lukem 		    mfsfakelabel.d_ncylinders * mfsfakelabel.d_secpercyl;
    464  1.14       cgd 		mfsfakelabel.d_rpm = 3600;
    465  1.14       cgd 		mfsfakelabel.d_interleave = 1;
    466  1.14       cgd 		mfsfakelabel.d_npartitions = 1;
    467  1.43     lukem 		mfsfakelabel.d_partitions[0].p_size = mfsfakelabel.d_secperunit;
    468  1.14       cgd 		mfsfakelabel.d_partitions[0].p_fsize = 1024;
    469  1.14       cgd 		mfsfakelabel.d_partitions[0].p_frag = 8;
    470  1.14       cgd 		mfsfakelabel.d_partitions[0].p_cpg = 16;
    471  1.14       cgd 
    472  1.14       cgd 		lp = &mfsfakelabel;
    473  1.14       cgd 		pp = &mfsfakelabel.d_partitions[0];
    474  1.14       cgd 
    475  1.14       cgd 		goto havelabel;
    476  1.14       cgd 	}
    477  1.11   mycroft 	cp = strrchr(special, '/');
    478  1.43     lukem 	if (cp == NULL) {
    479   1.1       cgd 		/*
    480   1.1       cgd 		 * No path prefix; try /dev/r%s then /dev/%s.
    481   1.1       cgd 		 */
    482  1.43     lukem 		(void)snprintf(device, sizeof(device), "%sr%s",
    483  1.43     lukem 		    _PATH_DEV, special);
    484   1.1       cgd 		if (stat(device, &st) == -1)
    485  1.34   mycroft 			(void)snprintf(device, sizeof(device), "%s%s",
    486  1.34   mycroft 			    _PATH_DEV, special);
    487   1.1       cgd 		special = device;
    488   1.1       cgd 	}
    489  1.10   mycroft 	if (Nflag) {
    490  1.10   mycroft 		fso = -1;
    491  1.10   mycroft 	} else {
    492   1.1       cgd 		fso = open(special, O_WRONLY);
    493   1.1       cgd 		if (fso < 0)
    494  1.28     enami 			err(1, "%s: open", special);
    495  1.10   mycroft 
    496  1.10   mycroft 		/* Bail if target special is mounted */
    497  1.10   mycroft 		n = getmntinfo(&mp, MNT_NOWAIT);
    498  1.10   mycroft 		if (n == 0)
    499  1.28     enami 			err(1, "%s: getmntinfo", special);
    500  1.10   mycroft 
    501  1.10   mycroft 		len = sizeof(_PATH_DEV) - 1;
    502  1.10   mycroft 		s1 = special;
    503  1.10   mycroft 		if (strncmp(_PATH_DEV, s1, len) == 0)
    504  1.10   mycroft 			s1 += len;
    505  1.10   mycroft 
    506  1.10   mycroft 		while (--n >= 0) {
    507  1.10   mycroft 			s2 = mp->f_mntfromname;
    508  1.10   mycroft 			if (strncmp(_PATH_DEV, s2, len) == 0) {
    509  1.10   mycroft 				s2 += len - 1;
    510  1.10   mycroft 				*s2 = 'r';
    511  1.10   mycroft 			}
    512  1.10   mycroft 			if (strcmp(s1, s2) == 0 || strcmp(s1, &s2[1]) == 0)
    513  1.25  christos 				errx(1, "%s is mounted on %s",
    514  1.10   mycroft 				    special, mp->f_mntonname);
    515  1.10   mycroft 			++mp;
    516  1.10   mycroft 		}
    517  1.10   mycroft 	}
    518  1.10   mycroft 	if (mfs && disktype != NULL) {
    519  1.10   mycroft 		lp = (struct disklabel *)getdiskbyname(disktype);
    520  1.10   mycroft 		if (lp == NULL)
    521  1.25  christos 			errx(1, "%s: unknown disk type", disktype);
    522  1.10   mycroft 		pp = &lp->d_partitions[1];
    523  1.10   mycroft 	} else {
    524  1.10   mycroft 		fsi = open(special, O_RDONLY);
    525  1.10   mycroft 		if (fsi < 0)
    526  1.28     enami 			err(1, "%s: open", special);
    527  1.10   mycroft 		if (fstat(fsi, &st) < 0)
    528  1.28     enami 			err(1, "%s: fstat", special);
    529  1.15   mycroft 		if (!S_ISCHR(st.st_mode) && !mfs)
    530  1.25  christos 			warnx("%s: not a character-special device", special);
    531  1.11   mycroft 		cp = strchr(argv[0], '\0') - 1;
    532  1.25  christos 		if (cp == 0 || ((*cp < 'a' || *cp > ('a' + maxpartitions - 1))
    533  1.25  christos 		    && !isdigit(*cp)))
    534  1.25  christos 			errx(1, "can't figure out file system partition");
    535   1.1       cgd #ifdef COMPAT
    536  1.10   mycroft 		if (!mfs && disktype == NULL)
    537  1.10   mycroft 			disktype = argv[1];
    538   1.1       cgd #endif
    539  1.10   mycroft 		lp = getdisklabel(special, fsi);
    540  1.10   mycroft 		if (isdigit(*cp))
    541  1.10   mycroft 			pp = &lp->d_partitions[0];
    542  1.10   mycroft 		else
    543  1.10   mycroft 			pp = &lp->d_partitions[*cp - 'a'];
    544  1.10   mycroft 		if (pp->p_size == 0)
    545  1.25  christos 			errx(1, "`%c' partition is unavailable", *cp);
    546  1.10   mycroft 		if (pp->p_fstype == FS_BOOT)
    547  1.25  christos 			errx(1, "`%c' partition overlaps boot program", *cp);
    548  1.10   mycroft 	}
    549  1.43     lukem 
    550  1.43     lukem  havelabel:
    551   1.1       cgd 	if (fssize == 0)
    552   1.1       cgd 		fssize = pp->p_size;
    553  1.43     lukem 	if (fssize > pp->p_size && !mfs && !Fflag)
    554  1.25  christos 		errx(1, "maximum file system size on the `%c' partition is %d",
    555  1.25  christos 		    *cp, pp->p_size);
    556   1.1       cgd 	if (rpm == 0) {
    557   1.1       cgd 		rpm = lp->d_rpm;
    558   1.1       cgd 		if (rpm <= 0)
    559   1.1       cgd 			rpm = 3600;
    560   1.1       cgd 	}
    561   1.1       cgd 	if (ntracks == 0) {
    562   1.1       cgd 		ntracks = lp->d_ntracks;
    563   1.1       cgd 		if (ntracks <= 0)
    564  1.25  christos 			errx(1, "no default #tracks");
    565   1.1       cgd 	}
    566   1.1       cgd 	if (nsectors == 0) {
    567   1.1       cgd 		nsectors = lp->d_nsectors;
    568   1.1       cgd 		if (nsectors <= 0)
    569  1.25  christos 			errx(1, "no default #sectors/track");
    570   1.1       cgd 	}
    571   1.1       cgd 	if (sectorsize == 0) {
    572   1.1       cgd 		sectorsize = lp->d_secsize;
    573   1.1       cgd 		if (sectorsize <= 0)
    574  1.25  christos 			errx(1, "no default sector size");
    575   1.1       cgd 	}
    576   1.1       cgd 	if (trackskew == -1) {
    577   1.1       cgd 		trackskew = lp->d_trackskew;
    578   1.1       cgd 		if (trackskew < 0)
    579   1.1       cgd 			trackskew = 0;
    580   1.1       cgd 	}
    581   1.1       cgd 	if (interleave == 0) {
    582   1.1       cgd 		interleave = lp->d_interleave;
    583   1.1       cgd 		if (interleave <= 0)
    584   1.1       cgd 			interleave = 1;
    585   1.1       cgd 	}
    586   1.1       cgd 	if (fsize == 0) {
    587   1.1       cgd 		fsize = pp->p_fsize;
    588   1.1       cgd 		if (fsize <= 0)
    589   1.1       cgd 			fsize = MAX(DFL_FRAGSIZE, lp->d_secsize);
    590   1.1       cgd 	}
    591   1.1       cgd 	if (bsize == 0) {
    592   1.1       cgd 		bsize = pp->p_frag * pp->p_fsize;
    593   1.1       cgd 		if (bsize <= 0)
    594   1.1       cgd 			bsize = MIN(DFL_BLKSIZE, 8 * fsize);
    595  1.38  wrstuden 	}
    596  1.38  wrstuden 	if (cpgflg == 0) {
    597  1.38  wrstuden 		if (pp->p_cpg != 0)
    598  1.38  wrstuden 			cpg = pp->p_cpg;
    599   1.1       cgd 	}
    600  1.10   mycroft 	/*
    601  1.10   mycroft 	 * Maxcontig sets the default for the maximum number of blocks
    602  1.10   mycroft 	 * that may be allocated sequentially. With filesystem clustering
    603  1.10   mycroft 	 * it is possible to allocate contiguous blocks up to the maximum
    604  1.10   mycroft 	 * transfer size permitted by the controller or buffering.
    605  1.10   mycroft 	 */
    606  1.10   mycroft 	if (maxcontig == 0)
    607  1.27     lukem 		maxcontig = MAX(1, MIN(MAXPHYS, MAXBSIZE) / bsize);
    608   1.1       cgd 	if (density == 0)
    609   1.1       cgd 		density = NFPI * fsize;
    610   1.8       cgd 	if (minfree < MINFREE && opt != FS_OPTSPACE) {
    611  1.25  christos 		warnx("%s %s %d%%", "Warning: changing optimization to space",
    612  1.25  christos 		    "because minfree is less than", MINFREE);
    613   1.1       cgd 		opt = FS_OPTSPACE;
    614   1.1       cgd 	}
    615   1.1       cgd 	if (trackspares == -1) {
    616   1.1       cgd 		trackspares = lp->d_sparespertrack;
    617   1.1       cgd 		if (trackspares < 0)
    618   1.1       cgd 			trackspares = 0;
    619   1.1       cgd 	}
    620   1.1       cgd 	nphyssectors = nsectors + trackspares;
    621   1.1       cgd 	if (cylspares == -1) {
    622   1.1       cgd 		cylspares = lp->d_sparespercyl;
    623   1.1       cgd 		if (cylspares < 0)
    624   1.1       cgd 			cylspares = 0;
    625   1.1       cgd 	}
    626   1.1       cgd 	secpercyl = nsectors * ntracks - cylspares;
    627   1.1       cgd 	if (secpercyl != lp->d_secpercyl)
    628  1.25  christos 		warnx("%s (%d) %s (%u)\n",
    629   1.1       cgd 			"Warning: calculated sectors per cylinder", secpercyl,
    630   1.1       cgd 			"disagrees with disk label", lp->d_secpercyl);
    631   1.1       cgd 	if (maxbpg == 0)
    632   1.1       cgd 		maxbpg = MAXBLKPG(bsize);
    633   1.1       cgd #ifdef notdef /* label may be 0 if faked up by kernel */
    634   1.1       cgd 	bbsize = lp->d_bbsize;
    635   1.1       cgd 	sbsize = lp->d_sbsize;
    636   1.1       cgd #endif
    637   1.1       cgd 	oldpartition = *pp;
    638   1.1       cgd 	mkfs(pp, special, fsi, fso);
    639  1.43     lukem 	if (!Nflag && memcmp(pp, &oldpartition, sizeof(oldpartition)) && !Fflag)
    640   1.1       cgd 		rewritelabel(special, fso, lp);
    641   1.1       cgd 	if (!Nflag)
    642   1.1       cgd 		close(fso);
    643   1.1       cgd 	close(fsi);
    644   1.1       cgd #ifdef MFS
    645   1.1       cgd 	if (mfs) {
    646   1.1       cgd 		struct mfs_args args;
    647   1.1       cgd 
    648  1.30  drochner 		switch (pid = fork()) {
    649  1.30  drochner 		case -1:
    650  1.30  drochner 			perror("mfs");
    651  1.30  drochner 			exit(10);
    652  1.30  drochner 		case 0:
    653  1.34   mycroft 			(void)snprintf(mountfromname, sizeof(mountfromname),
    654  1.34   mycroft 			    "mfs:%d", getpid());
    655  1.30  drochner 			break;
    656  1.30  drochner 		default:
    657  1.34   mycroft 			(void)snprintf(mountfromname, sizeof(mountfromname),
    658  1.34   mycroft 			    "mfs:%d", pid);
    659  1.30  drochner 			for (;;) {
    660  1.30  drochner 				/*
    661  1.30  drochner 				 * spin until the mount succeeds
    662  1.30  drochner 				 * or the child exits
    663  1.30  drochner 				 */
    664  1.30  drochner 				usleep(1);
    665  1.30  drochner 
    666  1.30  drochner 				/*
    667  1.30  drochner 				 * XXX Here is a race condition: another process
    668  1.30  drochner 				 * can mount a filesystem which hides our
    669  1.30  drochner 				 * ramdisk before we see the success.
    670  1.30  drochner 				 */
    671  1.30  drochner 				if (statfs(argv[1], &sf) < 0)
    672  1.30  drochner 					err(88, "statfs %s", argv[1]);
    673  1.30  drochner 				if (!strcmp(sf.f_mntfromname, mountfromname) &&
    674  1.30  drochner 				    !strncmp(sf.f_mntonname, argv[1],
    675  1.30  drochner 					     MNAMELEN) &&
    676  1.30  drochner 				    !strcmp(sf.f_fstypename, "mfs"))
    677  1.30  drochner 					exit(0);
    678  1.30  drochner 
    679  1.30  drochner 				res = waitpid(pid, &status, WNOHANG);
    680  1.30  drochner 				if (res == -1)
    681  1.30  drochner 					err(11, "waitpid");
    682  1.30  drochner 				if (res != pid)
    683  1.30  drochner 					continue;
    684  1.31  drochner 				if (WIFEXITED(status)) {
    685  1.31  drochner 					if (WEXITSTATUS(status) == 0)
    686  1.31  drochner 						exit(0);
    687  1.30  drochner 					errx(1, "%s: mount: %s", argv[1],
    688  1.30  drochner 					     strerror(WEXITSTATUS(status)));
    689  1.31  drochner 				} else
    690  1.30  drochner 					errx(11, "abnormal termination");
    691  1.30  drochner 			}
    692  1.30  drochner 			/* NOTREACHED */
    693  1.30  drochner 		}
    694  1.30  drochner 
    695  1.30  drochner 		(void) setsid();
    696  1.30  drochner 		(void) close(0);
    697  1.30  drochner 		(void) close(1);
    698  1.30  drochner 		(void) close(2);
    699  1.30  drochner 		(void) chdir("/");
    700  1.30  drochner 
    701  1.30  drochner 		args.fspec = mountfromname;
    702  1.10   mycroft 		args.export.ex_root = -2;
    703  1.10   mycroft 		if (mntflags & MNT_RDONLY)
    704  1.10   mycroft 			args.export.ex_flags = MNT_EXRDONLY;
    705  1.10   mycroft 		else
    706  1.10   mycroft 			args.export.ex_flags = 0;
    707   1.1       cgd 		args.base = membase;
    708   1.1       cgd 		args.size = fssize * sectorsize;
    709   1.1       cgd 		if (mount(MOUNT_MFS, argv[1], mntflags, &args) < 0)
    710  1.30  drochner 			exit(errno); /* parent prints message */
    711   1.1       cgd 	}
    712   1.1       cgd #endif
    713   1.1       cgd 	exit(0);
    714   1.1       cgd }
    715   1.1       cgd 
    716   1.1       cgd #ifdef COMPAT
    717  1.39        is const char lmsg[] = "%s: can't read disk label; disk type must be specified";
    718   1.1       cgd #else
    719  1.39        is const char lmsg[] = "%s: can't read disk label";
    720   1.1       cgd #endif
    721   1.1       cgd 
    722  1.25  christos static struct disklabel *
    723  1.40    simonb getdisklabel(char *s, volatile int fd)
    724  1.40    simonb /* XXX why is fs volatile?! */
    725   1.1       cgd {
    726   1.1       cgd 	static struct disklabel lab;
    727   1.1       cgd 
    728  1.24       tls 	if (ioctl(fd, DIOCGDINFO, &lab) < 0) {
    729   1.1       cgd #ifdef COMPAT
    730   1.1       cgd 		if (disktype) {
    731  1.25  christos 			struct disklabel *lp;
    732   1.1       cgd 
    733   1.1       cgd 			unlabeled++;
    734   1.1       cgd 			lp = getdiskbyname(disktype);
    735   1.1       cgd 			if (lp == NULL)
    736  1.25  christos 				errx(1, "%s: unknown disk type", disktype);
    737   1.1       cgd 			return (lp);
    738   1.1       cgd 		}
    739   1.1       cgd #endif
    740  1.10   mycroft 		warn("ioctl (GDINFO)");
    741  1.25  christos 		errx(1, lmsg, s);
    742   1.1       cgd 	}
    743   1.1       cgd 	return (&lab);
    744   1.1       cgd }
    745   1.1       cgd 
    746  1.25  christos static void
    747  1.40    simonb rewritelabel(char *s, volatile int fd, struct disklabel *lp)
    748  1.40    simonb /* XXX why is fd volatile?! */
    749   1.1       cgd {
    750   1.1       cgd #ifdef COMPAT
    751   1.1       cgd 	if (unlabeled)
    752   1.1       cgd 		return;
    753   1.1       cgd #endif
    754   1.1       cgd 	lp->d_checksum = 0;
    755   1.1       cgd 	lp->d_checksum = dkcksum(lp);
    756   1.1       cgd 	if (ioctl(fd, DIOCWDINFO, (char *)lp) < 0) {
    757  1.10   mycroft 		warn("ioctl (WDINFO)");
    758  1.25  christos 		errx(1, "%s: can't rewrite disk label", s);
    759   1.1       cgd 	}
    760  1.35      matt #if __vax__
    761   1.1       cgd 	if (lp->d_type == DTYPE_SMD && lp->d_flags & D_BADSECT) {
    762  1.25  christos 		int i;
    763   1.1       cgd 		int cfd;
    764   1.1       cgd 		daddr_t alt;
    765   1.1       cgd 		char specname[64];
    766   1.1       cgd 		char blk[1024];
    767   1.1       cgd 		char *cp;
    768   1.1       cgd 
    769   1.1       cgd 		/*
    770   1.1       cgd 		 * Make name for 'c' partition.
    771   1.1       cgd 		 */
    772   1.1       cgd 		strcpy(specname, s);
    773   1.1       cgd 		cp = specname + strlen(specname) - 1;
    774   1.1       cgd 		if (!isdigit(*cp))
    775   1.1       cgd 			*cp = 'c';
    776   1.1       cgd 		cfd = open(specname, O_WRONLY);
    777   1.1       cgd 		if (cfd < 0)
    778  1.28     enami 			err(1, "%s: open", specname);
    779  1.11   mycroft 		memset(blk, 0, sizeof(blk));
    780   1.1       cgd 		*(struct disklabel *)(blk + LABELOFFSET) = *lp;
    781   1.1       cgd 		alt = lp->d_ncylinders * lp->d_secpercyl - lp->d_nsectors;
    782   1.1       cgd 		for (i = 1; i < 11 && i < lp->d_nsectors; i += 2) {
    783  1.17       cgd 			off_t offset;
    784  1.17       cgd 
    785  1.17       cgd 			offset = alt + i;
    786  1.17       cgd 			offset *= lp->d_secsize;
    787  1.17       cgd 			if (lseek(cfd, offset, SEEK_SET) == -1)
    788  1.25  christos 				err(1, "lseek to badsector area: ");
    789   1.1       cgd 			if (write(cfd, blk, lp->d_secsize) < lp->d_secsize)
    790  1.10   mycroft 				warn("alternate label %d write", i/2);
    791   1.1       cgd 		}
    792   1.1       cgd 		close(cfd);
    793   1.1       cgd 	}
    794   1.1       cgd #endif
    795   1.1       cgd }
    796   1.1       cgd 
    797  1.43     lukem static int
    798  1.43     lukem strsuftoi(const char *desc, const char *arg, int min, int max)
    799  1.43     lukem {
    800  1.43     lukem 	long long result;
    801  1.43     lukem 	char	*ep;
    802  1.43     lukem 
    803  1.43     lukem 	errno = 0;
    804  1.43     lukem 	result = strtoll(arg, &ep, 10);
    805  1.43     lukem 	if (ep[0] != '\0' && ep[1] != '\0')
    806  1.43     lukem 		errx(1, "%s `%s' is not a valid number.", desc, arg);
    807  1.43     lukem 	switch (tolower((unsigned char)ep[0])) {
    808  1.43     lukem 	case '\0':
    809  1.43     lukem 	case 'b':
    810  1.43     lukem 		break;
    811  1.43     lukem 	case 'k':
    812  1.43     lukem 		result <<= 10;
    813  1.43     lukem 		break;
    814  1.43     lukem 	case 'm':
    815  1.43     lukem 		result <<= 20;
    816  1.43     lukem 		break;
    817  1.43     lukem 	case 'g':
    818  1.43     lukem 		result <<= 30;
    819  1.43     lukem 		break;
    820  1.43     lukem 	default:
    821  1.43     lukem 		errx(1, "`%s' is not a valid suffix for %s.", ep, desc);
    822  1.43     lukem 	}
    823  1.43     lukem 	if (result < min)
    824  1.43     lukem 		errx(1, "%s `%s' (%lld) is less than minimum (%d).",
    825  1.43     lukem 		    desc, arg, result, min);
    826  1.43     lukem 	if (result > max)
    827  1.43     lukem 		errx(1, "%s `%s' (%lld) is greater than maximum (%d).",
    828  1.43     lukem 		    desc, arg, result, max);
    829  1.43     lukem 	return ((int)result);
    830  1.43     lukem }
    831  1.43     lukem 
    832  1.25  christos static void
    833  1.40    simonb usage(void)
    834   1.1       cgd {
    835  1.43     lukem 
    836   1.1       cgd 	if (mfs) {
    837   1.1       cgd 		fprintf(stderr,
    838  1.43     lukem 		    "usage: %s [ fsoptions ] special-device mount-point\n",
    839  1.42       cgd 			getprogname());
    840   1.1       cgd 	} else
    841   1.1       cgd 		fprintf(stderr,
    842  1.43     lukem 		    "usage: %s [ fsoptions ] special-device%s\n",
    843  1.42       cgd 		    getprogname(),
    844   1.1       cgd #ifdef COMPAT
    845   1.1       cgd 		    " [device-type]");
    846   1.1       cgd #else
    847   1.1       cgd 		    "");
    848   1.1       cgd #endif
    849   1.1       cgd 	fprintf(stderr, "where fsoptions are:\n");
    850  1.43     lukem 	if (!mfs) {
    851  1.43     lukem 		fprintf(stderr,
    852  1.43     lukem 			"\t-B byteorder\tbyte order (`be' or `le')\n");
    853  1.43     lukem 		fprintf(stderr,
    854  1.43     lukem 			"\t-F\t\tcreate file system image in regular file\n");
    855  1.43     lukem 	}
    856  1.43     lukem 	fprintf(stderr, "\t-N\t\tdo not create file system, "
    857  1.43     lukem 			"just print out parameters\n");
    858  1.43     lukem 	if (!mfs) {
    859  1.43     lukem 		fprintf(stderr,
    860  1.43     lukem 			"\t-O\t\tcreate a 4.3BSD format filesystem\n");
    861  1.43     lukem 		fprintf(stderr,
    862  1.43     lukem 			"\t-S secsize\tsector size\n");
    863  1.43     lukem 	}
    864   1.1       cgd #ifdef COMPAT
    865  1.43     lukem 	fprintf(stderr, "\t-T disktype\tdisk type\n");
    866   1.1       cgd #endif
    867  1.43     lukem 	if (!mfs)
    868  1.43     lukem 		fprintf(stderr,
    869  1.43     lukem 			"\t-Z\t\tpre-zero the image file (with -F)\n");
    870  1.43     lukem 	fprintf(stderr, "\t-a maxcontig\tmaximum contiguous blocks\n");
    871  1.43     lukem 	fprintf(stderr, "\t-b bsize\tblock size\n");
    872  1.43     lukem 	fprintf(stderr, "\t-c cpg\t\tcylinders/group\n");
    873  1.43     lukem 	fprintf(stderr, "\t-d rotdelay\trotational delay between "
    874  1.43     lukem 			"contiguous blocks\n");
    875  1.43     lukem 	fprintf(stderr, "\t-e maxbpg\tmaximum blocks per file "
    876  1.43     lukem 			"in a cylinder group\n");
    877  1.43     lukem 	fprintf(stderr, "\t-f fsize\tfragment size\n");
    878  1.47     lukem 	fprintf(stderr, "\t-g average file size\n");
    879  1.47     lukem 	fprintf(stderr, "\t-h average files per directory\n");
    880  1.43     lukem 	fprintf(stderr, "\t-i density\tnumber of bytes per inode\n");
    881  1.43     lukem 	if (!mfs) {
    882  1.43     lukem 		fprintf(stderr,
    883  1.43     lukem 			"\t-k trackskew\tsector 0 skew, per track\n");
    884  1.43     lukem 		fprintf(stderr,
    885  1.43     lukem 			"\t-l interleave\thardware sector interleave\n");
    886  1.43     lukem 	}
    887  1.43     lukem 	fprintf(stderr, "\t-m minfree\tminimum free space %%\n");
    888  1.43     lukem 	if (!mfs)
    889  1.43     lukem 		fprintf(stderr,
    890  1.43     lukem 			"\t-n nrpos\tnumber of distinguished "
    891  1.43     lukem 			"rotational positions\n");
    892  1.43     lukem 	fprintf(stderr, "\t-o optim\toptimization preference "
    893  1.43     lukem 			"(`space' or `time')\n");
    894  1.43     lukem 	if (!mfs)
    895  1.43     lukem 		fprintf(stderr,
    896  1.43     lukem 			"\t-p trackspares\tspare sectors per track\n");
    897  1.43     lukem 	fprintf(stderr, "\t-s fssize\tfile system size (sectors)\n");
    898  1.43     lukem 	if (!mfs) {
    899  1.43     lukem 		fprintf(stderr,
    900  1.43     lukem 			"\t-r rpm\t\trevolutions/minute\n");
    901  1.43     lukem 		fprintf(stderr,
    902  1.43     lukem 			"\t-t ntracks\ttracks/cylinder\n");
    903  1.43     lukem 		fprintf(stderr,
    904  1.43     lukem 			"\t-u nsectors\tsectors/track\n");
    905  1.43     lukem 		fprintf(stderr,
    906  1.43     lukem 			"\t-x cylspares\tspare sectors per cylinder\n");
    907  1.43     lukem 	}
    908   1.1       cgd 	exit(1);
    909   1.1       cgd }
    910