Merge branch 'vendor/LIBARCHIVE'
[dragonfly.git] / sbin / newfs / newfs.c
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  * @(#) Copyright (c) 1983, 1989, 1993, 1994 The Regents of the University of California.  All rights reserved.
34  * @(#)newfs.c  8.13 (Berkeley) 5/1/95
35  * $FreeBSD: src/sbin/newfs/newfs.c,v 1.30.2.9 2003/05/13 12:03:55 joerg Exp $
36  * $DragonFly: src/sbin/newfs/newfs.c,v 1.17 2007/06/19 19:18:20 dillon Exp $
37  */
38
39 /*
40  * newfs: friendly front end to mkfs
41  */
42 #include <sys/param.h>
43 #include <sys/stat.h>
44 #include <sys/diskslice.h>
45 #include <sys/file.h>
46 #include <sys/mount.h>
47
48 #include <vfs/ufs/dir.h>
49 #include <vfs/ufs/dinode.h>
50 #include <vfs/ufs/fs.h>
51 #include <vfs/ufs/ufsmount.h>
52
53 #include <ctype.h>
54 #include <err.h>
55 #include <errno.h>
56 #include <paths.h>
57 #include <stdio.h>
58 #include <stdlib.h>
59 #include <string.h>
60 #include <syslog.h>
61 #include <unistd.h>
62 #include <disktab.h>
63
64 #ifdef MFS
65 #include <sys/types.h>
66 #include <sys/mman.h>
67 #endif
68
69 #if __STDC__
70 #include <stdarg.h>
71 #else
72 #include <varargs.h>
73 #endif
74
75 #include "mntopts.h"
76 #include "defs.h"
77
78 struct mntopt mopts[] = {
79         MOPT_STDOPTS,
80         MOPT_ASYNC,
81         MOPT_NULL,
82 };
83
84 void    fatal(const char *fmt, ...);
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    2048
96 #define DFL_BLKSIZE     16384
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 as many as possible
102  * cylinders per group.
103  */
104 #define DESCPG          65536   /* desired fs_cpg ("infinity") */
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 essentially 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 #define NTRACKS         1       /* number of heads */
155 #define NSECTORS        4096    /* number of sectors */
156
157 int     mfs;                    /* run as the memory based filesystem */
158 char    *mfs_mtpt;              /* mount point for mfs          */
159 struct stat mfs_mtstat;         /* stat prior to mount          */
160 int     Nflag;                  /* run without writing file system */
161 int     Oflag;                  /* format as an 4.3BSD file system */
162 int     Cflag;                  /* copy underlying filesystem (mfs only) */
163 int     Uflag;                  /* enable soft updates for 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     avgfilesize = AVFILESIZ;/* expected average file size */
190 int     avgfilesperdir = AFPDIR;/* expected number of files per directory */
191 int     bbsize = BBSIZE;        /* boot block size */
192 int     sbsize = SBSIZE;        /* superblock size */
193 int     mntflags = MNT_ASYNC;   /* flags to be passed to mount */
194 int     t_or_u_flag = 0;        /* user has specified -t or -u */
195 u_long  memleft;                /* virtual memory available */
196 caddr_t membase;                /* start address of memory based filesystem */
197 char    *filename;
198 #ifdef COMPAT
199 char    *disktype;
200 int     unlabeled;
201 #endif
202
203 char    mfsdevname[256];
204 char    *progname;
205
206 static void usage(void);
207 static void mfsintr(int signo);
208
209 int
210 main(int argc, char **argv)
211 {
212         int ch;
213         struct disktab geom;            /* disk geometry data */
214         struct stat st;
215         struct statfs *mp;
216         int fsi = -1, fso = -1, len, n, vflag;
217         char *s1, *s2, *special;
218         const char *opstring;
219 #ifdef MFS
220         struct vfsconf vfc;
221         int error;
222 #endif
223
224         bzero(&geom, sizeof(geom));
225         vflag = 0;
226         if ((progname = strrchr(*argv, '/')))
227                 ++progname;
228         else
229                 progname = *argv;
230
231         if (strstr(progname, "mfs")) {
232                 mfs = 1;
233                 Nflag++;
234         }
235
236         opstring = mfs ?
237             "NCF:T:Ua:b:c:d:e:f:g:h:i:m:o:s:v" :
238             "NOS:T:Ua:b:c:d:e:f:g:h:i:k:l:m:n:o:p:r:s:t:u:vx:";
239         while ((ch = getopt(argc, argv, opstring)) != -1) {
240                 switch (ch) {
241                 case 'N':
242                         Nflag = 1;
243                         break;
244                 case 'O':
245                         Oflag = 1;
246                         break;
247                 case 'C':
248                         Cflag = 1;      /* MFS only */
249                         break;
250                 case 'S':
251                         if ((sectorsize = atoi(optarg)) <= 0)
252                                 fatal("%s: bad sector size", optarg);
253                         break;
254 #ifdef COMPAT
255                 case 'T':
256                         disktype = optarg;
257                         break;
258 #endif
259                 case 'F':
260                         filename = optarg;
261                         break;
262                 case 'U':
263                         Uflag = 1;
264                         break;
265                 case 'a':
266                         if ((maxcontig = atoi(optarg)) <= 0)
267                                 fatal("%s: bad maximum contiguous blocks",
268                                     optarg);
269                         break;
270                 case 'b':
271                         if ((bsize = atoi(optarg)) < MINBSIZE)
272                                 fatal("%s: bad block size", optarg);
273                         break;
274                 case 'c':
275                         if ((cpg = atoi(optarg)) <= 0)
276                                 fatal("%s: bad cylinders/group", optarg);
277                         cpgflg++;
278                         break;
279                 case 'd':
280                         if ((rotdelay = atoi(optarg)) < 0)
281                                 fatal("%s: bad rotational delay", optarg);
282                         break;
283                 case 'e':
284                         if ((maxbpg = atoi(optarg)) <= 0)
285                 fatal("%s: bad blocks per file in a cylinder group",
286                                     optarg);
287                         break;
288                 case 'f':
289                         if ((fsize = atoi(optarg)) <= 0)
290                                 fatal("%s: bad fragment size", optarg);
291                         break;
292                 case 'g':
293                         if ((avgfilesize = atoi(optarg)) <= 0)
294                                 fatal("%s: bad average file size", optarg);
295                         break;
296                 case 'h':
297                         if ((avgfilesperdir = atoi(optarg)) <= 0)
298                                 fatal("%s: bad average files per dir", optarg);
299                         break;
300                 case 'i':
301                         if ((density = atoi(optarg)) <= 0)
302                                 fatal("%s: bad bytes per inode", optarg);
303                         break;
304                 case 'k':
305                         if ((trackskew = atoi(optarg)) < 0)
306                                 fatal("%s: bad track skew", optarg);
307                         break;
308                 case 'l':
309                         if ((interleave = atoi(optarg)) <= 0)
310                                 fatal("%s: bad interleave", optarg);
311                         break;
312                 case 'm':
313                         if ((minfree = atoi(optarg)) < 0 || minfree > 99)
314                                 fatal("%s: bad free space %%", optarg);
315                         break;
316                 case 'n':
317                         if ((nrpos = atoi(optarg)) < 0)
318                                 fatal("%s: bad rotational layout count",
319                                     optarg);
320                         if (nrpos == 0)
321                                 nrpos = 1;
322                         break;
323                 case 'o':
324                         if (mfs)
325                                 getmntopts(optarg, mopts, &mntflags, 0);
326                         else {
327                                 if (strcmp(optarg, "space") == 0)
328                                         opt = FS_OPTSPACE;
329                                 else if (strcmp(optarg, "time") == 0)
330                                         opt = FS_OPTTIME;
331                                 else
332         fatal("%s: unknown optimization preference: use `space' or `time'", optarg);
333                         }
334                         break;
335                 case 'p':
336                         if ((trackspares = atoi(optarg)) < 0)
337                                 fatal("%s: bad spare sectors per track",
338                                     optarg);
339                         break;
340                 case 'r':
341                         if ((rpm = atoi(optarg)) <= 0)
342                                 fatal("%s: bad revolutions/minute", optarg);
343                         break;
344                 case 's':
345                         if ((fssize = atoi(optarg)) <= 0)
346                                 fatal("%s: bad file system size", optarg);
347                         break;
348                 case 't':
349                         t_or_u_flag++;
350                         if ((ntracks = atoi(optarg)) < 0)
351                                 fatal("%s: bad total tracks", optarg);
352                         break;
353                 case 'u':
354                         t_or_u_flag++;
355                         if ((nsectors = atoi(optarg)) < 0)
356                                 fatal("%s: bad sectors/track", optarg);
357                         break;
358                 case 'v':
359                         vflag = 1;
360                         break;
361                 case 'x':
362                         if ((cylspares = atoi(optarg)) < 0)
363                                 fatal("%s: bad spare sectors per cylinder",
364                                     optarg);
365                         break;
366                 case '?':
367                 default:
368                         usage();
369                 }
370         }
371         argc -= optind;
372         argv += optind;
373
374         if (argc != 2 && (mfs || argc != 1))
375                 usage();
376
377         special = argv[0];
378         /* Copy the NetBSD way of faking up a disk label */
379         if (mfs && !strcmp(special, "swap")) {
380                 /* 
381                  * it's an MFS, mounted on "swap."  fake up a label.
382                  * XXX XXX XXX
383                  */
384                 fso = -1;       /* XXX; normally done below. */
385
386                 geom.d_media_blksize = 512;
387                 geom.d_nheads = 16;
388                 geom.d_secpertrack = 64;
389                 /* geom.d_ncylinders not used */
390                 geom.d_secpercyl = 1024;
391                 geom.d_media_blocks = 16384;
392                 geom.d_rpm = 3600;
393                 geom.d_interleave = 1;
394
395                 goto havelabel;
396         }
397
398         /*
399          * If we can't stat the device and the path is relative, try
400          * prepending /dev.
401          */
402         if (stat(special, &st) < 0 && special[0] && special[0] != '/')
403                 asprintf(&special, "/dev/%s", special);
404
405         if (Nflag) {
406                 fso = -1;
407         } else {
408                 fso = open(special, O_WRONLY);
409                 if (fso < 0)
410                         fatal("%s: %s", special, strerror(errno));
411
412                 /* Bail if target special is mounted */
413                 n = getmntinfo(&mp, MNT_NOWAIT);
414                 if (n == 0)
415                         fatal("%s: getmntinfo: %s", special, strerror(errno));
416
417                 len = sizeof(_PATH_DEV) - 1;
418                 s1 = special;
419                 if (strncmp(_PATH_DEV, s1, len) == 0)
420                         s1 += len;
421
422                 while (--n >= 0) {
423                         s2 = mp->f_mntfromname;
424                         if (strncmp(_PATH_DEV, s2, len) == 0) {
425                                 s2 += len - 1;
426                                 *s2 = 'r';
427                         }
428                         if (strcmp(s1, s2) == 0 || strcmp(s1, &s2[1]) == 0)
429                                 fatal("%s is mounted on %s",
430                                     special, mp->f_mntonname);
431                         ++mp;
432                 }
433         }
434         if (mfs && disktype != NULL) {
435                 struct disktab *dt;
436
437                 if ((dt = getdisktabbyname(disktype)) == NULL)
438                         fatal("%s: unknown disk type", disktype);
439                 geom = *dt;
440         } else {
441                 struct partinfo pinfo;
442
443                 if (special[0] == 0)
444                         fatal("null special file name");
445                 fsi = open(special, O_RDONLY);
446                 if (fsi < 0)
447                         fatal("%s: %s", special, strerror(errno));
448                 if (fstat(fsi, &st) < 0)
449                         fatal("%s: %s", special, strerror(errno));
450                 if ((st.st_mode & S_IFMT) != S_IFCHR && !mfs && !vflag)
451                         printf("%s: %s: not a character-special device\n",
452                             progname, special);
453 #ifdef COMPAT
454                 if (!mfs && disktype == NULL)
455                         disktype = argv[1];
456 #endif
457                 if (ioctl(fsi, DIOCGPART, &pinfo) < 0) {
458                         if (!vflag) {
459                                 fatal("%s: unable to retrieve geometry "
460                                       "information", argv[0]);
461                         }
462                         /*
463                          * fake up geometry data
464                          */
465                         geom.d_media_blksize = 512;
466                         geom.d_nheads = 16;
467                         geom.d_secpertrack = 64;
468                         geom.d_secpercyl = 1024;
469                         geom.d_media_blocks = st.st_size / 
470                                               geom.d_media_blksize;
471                         geom.d_media_size = geom.d_media_blocks *
472                                             geom.d_media_blksize;
473                         /* geom.d_ncylinders not used */
474                 } else {
475                         /*
476                          * extract geometry from pinfo
477                          */
478                         geom.d_media_blksize = pinfo.media_blksize;
479                         geom.d_nheads = pinfo.d_nheads;
480                         geom.d_secpertrack = pinfo.d_secpertrack;
481                         geom.d_secpercyl = pinfo.d_secpercyl;
482                         /* geom.d_ncylinders not used */
483                         geom.d_media_blocks = pinfo.media_blocks;
484                         geom.d_media_size = pinfo.media_size;
485                 }
486                 if (geom.d_media_blocks == 0 || geom.d_media_size == 0) {
487                         fatal("%s: is unavailable", argv[0]);
488                 }
489                 printf("%s: media size %6.2fMB\n",
490                         argv[0], geom.d_media_size / 1024.0 / 1024.0);
491                 if (geom.d_media_size / 512 >= 0x80000000ULL)
492                         fatal("%s: media size is too large for newfs to handle",
493                               argv[0]);
494         }
495 havelabel:
496         if (fssize == 0)
497                 fssize = geom.d_media_blocks;
498         if ((uint32_t)fssize > geom.d_media_blocks && !mfs) {
499                fatal("%s: maximum file system size is %lld blocks",
500                      argv[0], geom.d_media_blocks);
501         }
502         if (rpm == 0) {
503                 rpm = geom.d_rpm;
504                 if (rpm <= 0)
505                         rpm = 3600;
506         }
507         if (ntracks == 0) {
508                 ntracks = geom.d_nheads;
509                 if (ntracks <= 0)
510                         fatal("%s: no default #tracks", argv[0]);
511         }
512         if (nsectors == 0) {
513                 nsectors = geom.d_secpertrack;
514                 if (nsectors <= 0)
515                         fatal("%s: no default #sectors/track", argv[0]);
516         }
517         if (sectorsize == 0) {
518                 sectorsize = geom.d_media_blksize;
519                 if (sectorsize <= 0)
520                         fatal("%s: no default sector size", argv[0]);
521         }
522         if (trackskew == -1) {
523                 trackskew = geom.d_trackskew;
524                 if (trackskew < 0)
525                         trackskew = 0;
526         }
527         if (interleave == 0) {
528                 interleave = geom.d_interleave;
529                 if (interleave <= 0)
530                         interleave = 1;
531         }
532         if (fsize == 0)
533                 fsize = MAX(DFL_FRAGSIZE, geom.d_media_blksize);
534         if (bsize == 0)
535                 bsize = MIN(DFL_BLKSIZE, 8 * fsize);
536         /*
537          * Maxcontig sets the default for the maximum number of blocks
538          * that may be allocated sequentially. With filesystem clustering
539          * it is possible to allocate contiguous blocks up to the maximum
540          * transfer size permitted by the controller or buffering.
541          */
542         if (maxcontig == 0)
543                 maxcontig = MAX(1, MAXPHYS / bsize - 1);
544         if (density == 0)
545                 density = NFPI * fsize;
546         if (minfree < MINFREE && opt != FS_OPTSPACE) {
547                 fprintf(stderr, "Warning: changing optimization to space ");
548                 fprintf(stderr, "because minfree is less than %d%%\n", MINFREE);
549                 opt = FS_OPTSPACE;
550         }
551         if (trackspares == -1)
552                 trackspares = 0;
553         nphyssectors = nsectors + trackspares;
554         if (cylspares == -1)
555                 cylspares = 0;
556         secpercyl = nsectors * ntracks - cylspares;
557         /*
558          * Only complain if -t or -u have been specified; the default
559          * case (4096 sectors per cylinder) is intended to disagree
560          * with the disklabel.
561          */
562         if (t_or_u_flag && (uint32_t)secpercyl != geom.d_secpercyl)
563                 fprintf(stderr, "%s (%d) %s (%u)\n",
564                         "Warning: calculated sectors per cylinder", secpercyl,
565                         "disagrees with disk label", geom.d_secpercyl);
566         if (maxbpg == 0)
567                 maxbpg = MAXBLKPG(bsize);
568         headswitch = geom.d_headswitch;
569         trackseek = geom.d_trkseek;
570         realsectorsize = sectorsize;
571         if (sectorsize != DEV_BSIZE) {          /* XXX */
572                 int secperblk = sectorsize / DEV_BSIZE;
573
574                 sectorsize = DEV_BSIZE;
575                 nsectors *= secperblk;
576                 nphyssectors *= secperblk;
577                 secpercyl *= secperblk;
578                 fssize *= secperblk;
579         }
580         if (mfs) {
581                 mfs_mtpt = argv[1];
582                 if (
583                     stat(mfs_mtpt, &mfs_mtstat) < 0 ||
584                     !S_ISDIR(mfs_mtstat.st_mode)
585                 ) {
586                         fatal("mount point not dir: %s", mfs_mtpt);
587                 }
588         }
589         mkfs(special, fsi, fso, (Cflag && mfs) ? argv[1] : NULL);
590
591         /*
592          * NOTE: Newfs no longer accesses or attempts to update the
593          * filesystem disklabel.
594          */
595         if (!Nflag)
596                 close(fso);
597         close(fsi);
598 #ifdef MFS
599         if (mfs) {
600                 struct mfs_args args;
601                 int udev;
602
603                 snprintf(mfsdevname, sizeof(mfsdevname), "/dev/mfs%d",
604                         getpid());
605                 args.fspec = mfsdevname;
606                 args.export.ex_root = -2;
607                 if (mntflags & MNT_RDONLY)
608                         args.export.ex_flags = MNT_EXRDONLY;
609                 else
610                         args.export.ex_flags = 0;
611                 args.base = membase;
612                 args.size = fssize * sectorsize;
613
614                 error = getvfsbyname("mfs", &vfc);
615                 if (error && vfsisloadable("mfs")) {
616                         if (vfsload("mfs"))
617                                 fatal("vfsload(mfs)");
618                         endvfsent();    /* flush cache */
619                         error = getvfsbyname("mfs", &vfc);
620                 }
621                 if (error)
622                         fatal("mfs filesystem not available");
623
624                 udev = (253 << 8) | (getpid() & 255) | 
625                         ((getpid() & ~0xFF) << 8);
626                 if (mknod(mfsdevname, S_IFCHR | 0700, udev) < 0)
627                         printf("Warning: unable to create %s\n", mfsdevname);
628                 signal(SIGINT, mfsintr);
629                 if (mount(vfc.vfc_name, argv[1], mntflags, &args) < 0)
630                         fatal("%s: %s", argv[1], strerror(errno));
631                 signal(SIGINT, SIG_DFL);
632                 mfsintr(SIGINT);
633         }
634 #endif
635         exit(0);
636 }
637
638 #ifdef MFS
639
640 static void
641 mfsintr(__unused int signo)
642 {
643         if (filename)
644                 munmap(membase, fssize * sectorsize);
645         remove(mfsdevname);
646 }
647
648 #endif
649
650 /*VARARGS*/
651 void
652 fatal(const char *fmt, ...)
653 {
654         va_list ap;
655
656         va_start(ap, fmt);
657         if (fcntl(STDERR_FILENO, F_GETFL) < 0) {
658                 openlog(progname, LOG_CONS, LOG_DAEMON);
659                 vsyslog(LOG_ERR, fmt, ap);
660                 closelog();
661         } else {
662                 vwarnx(fmt, ap);
663         }
664         va_end(ap);
665         exit(1);
666         /*NOTREACHED*/
667 }
668
669 static void
670 usage(void)
671 {
672         if (mfs) {
673                 fprintf(stderr,
674                     "usage: %s [ -fsoptions ] special-device mount-point\n",
675                         progname);
676         } else
677                 fprintf(stderr,
678                     "usage: %s [ -fsoptions ] special-device%s\n",
679                     progname,
680 #ifdef COMPAT
681                     " [device-type]");
682 #else
683                     "");
684 #endif
685         fprintf(stderr, "where fsoptions are:\n");
686         fprintf(stderr, "\t-C (mfs) Copy the underlying filesystem to the MFS mount\n");
687         fprintf(stderr,
688             "\t-N do not create file system, just print out parameters\n");
689         fprintf(stderr, "\t-O create a 4.3BSD format filesystem\n");
690         fprintf(stderr, "\t-S sector size\n");
691 #ifdef COMPAT
692         fprintf(stderr, "\t-T disktype\n");
693 #endif
694         fprintf(stderr, "\t-U enable soft updates\n");
695         fprintf(stderr, "\t-a maximum contiguous blocks\n");
696         fprintf(stderr, "\t-b block size\n");
697         fprintf(stderr, "\t-c cylinders/group\n");
698         fprintf(stderr, "\t-d rotational delay between contiguous blocks\n");
699         fprintf(stderr, "\t-e maximum blocks per file in a cylinder group\n");
700         fprintf(stderr, "\t-f frag size\n");
701         fprintf(stderr, "\t-g average file size\n");
702         fprintf(stderr, "\t-h average files per directory\n");
703         fprintf(stderr, "\t-i number of bytes per inode\n");
704         fprintf(stderr, "\t-k sector 0 skew, per track\n");
705         fprintf(stderr, "\t-l hardware sector interleave\n");
706         fprintf(stderr, "\t-m minimum free space %%\n");
707         fprintf(stderr, "\t-n number of distinguished rotational positions\n");
708         fprintf(stderr, "\t-o optimization preference (`space' or `time')\n");
709         fprintf(stderr, "\t-p spare sectors per track\n");
710         fprintf(stderr, "\t-s file system size (sectors)\n");
711         fprintf(stderr, "\t-r revolutions/minute\n");
712         fprintf(stderr, "\t-t tracks/cylinder\n");
713         fprintf(stderr, "\t-u sectors/track\n");
714         fprintf(stderr,
715         "\t-v do not attempt to determine partition name from device name\n");
716         fprintf(stderr, "\t-x spare sectors per cylinder\n");
717         exit(1);
718 }