newfs.c revision 1.32 1 /* $NetBSD: newfs.c,v 1.32 1998/03/01 02:20:33 fvdl Exp $ */
2
3 /*
4 * Copyright (c) 1983, 1989, 1993, 1994
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 */
35
36 #include <sys/cdefs.h>
37 #ifndef lint
38 __COPYRIGHT("@(#) Copyright (c) 1983, 1989, 1993, 1994\n\
39 The Regents of the University of California. All rights reserved.\n");
40 #endif /* not lint */
41
42 #ifndef lint
43 #if 0
44 static char sccsid[] = "@(#)newfs.c 8.13 (Berkeley) 5/1/95";
45 #else
46 __RCSID("$NetBSD: newfs.c,v 1.32 1998/03/01 02:20:33 fvdl Exp $");
47 #endif
48 #endif /* not lint */
49
50 /*
51 * newfs: friendly front end to mkfs
52 */
53 #include <sys/param.h>
54 #include <sys/stat.h>
55 #include <sys/ioctl.h>
56 #include <sys/disklabel.h>
57 #include <sys/file.h>
58 #include <sys/mount.h>
59 #include <sys/sysctl.h>
60 #include <sys/wait.h>
61
62 #include <ufs/ufs/dir.h>
63 #include <ufs/ufs/dinode.h>
64 #include <ufs/ufs/ufsmount.h>
65 #include <ufs/ffs/fs.h>
66
67 #include <ctype.h>
68 #include <errno.h>
69 #include <paths.h>
70 #include <stdio.h>
71 #include <stdlib.h>
72 #include <string.h>
73 #include <syslog.h>
74 #include <unistd.h>
75 #include <signal.h>
76 #include <err.h>
77 #include <util.h>
78
79 #include "mntopts.h"
80 #include "dkcksum.h"
81 #include "extern.h"
82
83 struct mntopt mopts[] = {
84 MOPT_STDOPTS,
85 MOPT_ASYNC,
86 MOPT_UPDATE,
87 MOPT_NOATIME,
88 { NULL },
89 };
90
91 static struct disklabel *getdisklabel __P((char *, int));
92 static void rewritelabel __P((char *, int, struct disklabel *));
93 static void usage __P((void));
94 int main __P((int, char *[]));
95
96 #define COMPAT /* allow non-labeled disks */
97
98 /*
99 * The following two constants set the default block and fragment sizes.
100 * Both constants must be a power of 2 and meet the following constraints:
101 * MINBSIZE <= DESBLKSIZE <= MAXBSIZE
102 * sectorsize <= DESFRAGSIZE <= DESBLKSIZE
103 * DESBLKSIZE / DESFRAGSIZE <= 8
104 */
105 #define DFL_FRAGSIZE 1024
106 #define DFL_BLKSIZE 8192
107
108 /*
109 * Cylinder groups may have up to many cylinders. The actual
110 * number used depends upon how much information can be stored
111 * on a single cylinder. The default is to use 16 cylinders
112 * per group.
113 */
114 #define DESCPG 16 /* desired fs_cpg */
115
116 /*
117 * ROTDELAY gives the minimum number of milliseconds to initiate
118 * another disk transfer on the same cylinder. It is used in
119 * determining the rotationally optimal layout for disk blocks
120 * within a file; the default of fs_rotdelay is 0ms.
121 */
122 #define ROTDELAY 0
123
124 /*
125 * MAXBLKPG determines the maximum number of data blocks which are
126 * placed in a single cylinder group. The default is one indirect
127 * block worth of data blocks.
128 */
129 #define MAXBLKPG(bsize) ((bsize) / sizeof(daddr_t))
130
131 /*
132 * Each file system has a number of inodes statically allocated.
133 * We allocate one inode slot per NFPI fragments, expecting this
134 * to be far more than we will ever need.
135 */
136 #define NFPI 4
137
138 /*
139 * For each cylinder we keep track of the availability of blocks at different
140 * rotational positions, so that we can lay out the data to be picked
141 * up with minimum rotational latency. NRPOS is the default number of
142 * rotational positions that we distinguish. With NRPOS of 8 the resolution
143 * of our summary information is 2ms for a typical 3600 rpm drive. Caching
144 * and zoning pretty much defeats rotational optimization, so we now use a
145 * default of 1.
146 */
147 #define NRPOS 1 /* number distinct rotational positions */
148
149
150 int mfs; /* run as the memory based filesystem */
151 int Nflag; /* run without writing file system */
152 int Oflag; /* format as an 4.3BSD file system */
153 int fssize; /* file system size */
154 int ntracks; /* # tracks/cylinder */
155 int nsectors; /* # sectors/track */
156 int nphyssectors; /* # sectors/track including spares */
157 int secpercyl; /* sectors per cylinder */
158 int trackspares = -1; /* spare sectors per track */
159 int cylspares = -1; /* spare sectors per cylinder */
160 int sectorsize; /* bytes/sector */
161 int rpm; /* revolutions/minute of drive */
162 int interleave; /* hardware sector interleave */
163 int trackskew = -1; /* sector 0 skew, per track */
164 int headswitch; /* head switch time, usec */
165 int trackseek; /* track-to-track seek, usec */
166 int fsize = 0; /* fragment size */
167 int bsize = 0; /* block size */
168 int cpg = DESCPG; /* cylinders/cylinder group */
169 int cpgflg; /* cylinders/cylinder group flag was given */
170 int minfree = MINFREE; /* free space threshold */
171 int opt = DEFAULTOPT; /* optimization preference (space or time) */
172 int density; /* number of bytes per inode */
173 int maxcontig = 8; /* max contiguous blocks to allocate */
174 int rotdelay = ROTDELAY; /* rotational delay between blocks */
175 int maxbpg; /* maximum blocks per file in a cyl group */
176 int nrpos = NRPOS; /* # of distinguished rotational positions */
177 int bbsize = BBSIZE; /* boot block size */
178 int sbsize = SBSIZE; /* superblock size */
179 int mntflags = MNT_ASYNC; /* flags to be passed to mount */
180 u_long memleft; /* virtual memory available */
181 caddr_t membase; /* start address of memory based filesystem */
182 #ifdef COMPAT
183 char *disktype;
184 int unlabeled;
185 #endif
186
187 char device[MAXPATHLEN];
188 extern char *__progname;
189
190 int
191 main(argc, argv)
192 int argc;
193 char *argv[];
194 {
195 int ch;
196 struct partition *pp;
197 struct disklabel *lp;
198 struct disklabel mfsfakelabel;
199 struct partition oldpartition;
200 struct stat st;
201 struct statfs *mp;
202 int fsi = 0, fso, len, n, maxpartitions;
203 char *cp = NULL, *s1, *s2, *special, *opstring;
204 #ifdef MFS
205 char mountfromname[100];
206 pid_t pid, res;
207 struct statfs sf;
208 int status;
209 #endif
210
211 if (strstr(__progname, "mfs")) {
212 mfs = 1;
213 Nflag++;
214 }
215
216 maxpartitions = getmaxpartitions();
217 if (maxpartitions > 26)
218 errx(1, "insane maxpartitions value %d", maxpartitions);
219
220 opstring = mfs ?
221 "NT:a:b:c:d:e:f:i:m:o:s:" :
222 "NOS:T:a:b:c:d:e:f:i:k:l:m:n:o:p:r:s:t:u:x:";
223 while ((ch = getopt(argc, argv, opstring)) != -1)
224 switch (ch) {
225 case 'N':
226 Nflag = 1;
227 break;
228 case 'O':
229 Oflag = 1;
230 break;
231 case 'S':
232 if ((sectorsize = atoi(optarg)) <= 0)
233 errx(1, "%s: bad sector size", optarg);
234 break;
235 #ifdef COMPAT
236 case 'T':
237 disktype = optarg;
238 break;
239 #endif
240 case 'a':
241 if ((maxcontig = atoi(optarg)) <= 0)
242 errx(1, "%s: bad maximum contiguous blocks",
243 optarg);
244 break;
245 case 'b':
246 if ((bsize = atoi(optarg)) < MINBSIZE)
247 errx(1, "%s: bad block size", optarg);
248 break;
249 case 'c':
250 if ((cpg = atoi(optarg)) <= 0)
251 errx(1, "%s: bad cylinders/group", optarg);
252 cpgflg++;
253 break;
254 case 'd':
255 if ((rotdelay = atoi(optarg)) < 0)
256 errx(1, "%s: bad rotational delay", optarg);
257 break;
258 case 'e':
259 if ((maxbpg = atoi(optarg)) <= 0)
260 errx(1, "%s: bad blocks per file in a cylinder group",
261 optarg);
262 break;
263 case 'f':
264 if ((fsize = atoi(optarg)) <= 0)
265 errx(1, "%s: bad fragment size", optarg);
266 break;
267 case 'i':
268 if ((density = atoi(optarg)) <= 0)
269 errx(1, "%s: bad bytes per inode", optarg);
270 break;
271 case 'k':
272 if ((trackskew = atoi(optarg)) < 0)
273 errx(1, "%s: bad track skew", optarg);
274 break;
275 case 'l':
276 if ((interleave = atoi(optarg)) <= 0)
277 errx(1, "%s: bad interleave", optarg);
278 break;
279 case 'm':
280 if ((minfree = atoi(optarg)) < 0 || minfree > 99)
281 errx(1, "%s: bad free space %%", optarg);
282 break;
283 case 'n':
284 if ((nrpos = atoi(optarg)) <= 0)
285 errx(1, "%s: bad rotational layout count",
286 optarg);
287 break;
288 case 'o':
289 if (mfs)
290 getmntopts(optarg, mopts, &mntflags, 0);
291 else {
292 if (strcmp(optarg, "space") == 0)
293 opt = FS_OPTSPACE;
294 else if (strcmp(optarg, "time") == 0)
295 opt = FS_OPTTIME;
296 else
297 errx(1, "%s %s",
298 "unknown optimization preference: ",
299 "use `space' or `time'.");
300 }
301 break;
302 case 'p':
303 if ((trackspares = atoi(optarg)) < 0)
304 errx(1, "%s: bad spare sectors per track",
305 optarg);
306 break;
307 case 'r':
308 if ((rpm = atoi(optarg)) <= 0)
309 errx(1, "%s: bad revolutions/minute", optarg);
310 break;
311 case 's':
312 if ((fssize = atoi(optarg)) <= 0)
313 errx(1, "%s: bad file system size", optarg);
314 break;
315 case 't':
316 if ((ntracks = atoi(optarg)) <= 0)
317 errx(1, "%s: bad total tracks", optarg);
318 break;
319 case 'u':
320 if ((nsectors = atoi(optarg)) <= 0)
321 errx(1, "%s: bad sectors/track", optarg);
322 break;
323 case 'x':
324 if ((cylspares = atoi(optarg)) < 0)
325 errx(1, "%s: bad spare sectors per cylinder",
326 optarg);
327 break;
328 case '?':
329 default:
330 usage();
331 }
332 argc -= optind;
333 argv += optind;
334
335 if (argc != 2 && (mfs || argc != 1))
336 usage();
337
338 special = argv[0];
339 if (mfs && !strcmp(special, "swap")) {
340 /*
341 * it's an MFS, mounted on "swap." fake up a label.
342 * XXX XXX XXX
343 */
344 fso = -1; /* XXX; normally done below. */
345
346 memset(&mfsfakelabel, 0, sizeof(mfsfakelabel));
347 mfsfakelabel.d_secsize = 512;
348 mfsfakelabel.d_nsectors = 64;
349 mfsfakelabel.d_ntracks = 16;
350 mfsfakelabel.d_ncylinders = 16;
351 mfsfakelabel.d_secpercyl = 1024;
352 mfsfakelabel.d_secperunit = 16384;
353 mfsfakelabel.d_rpm = 3600;
354 mfsfakelabel.d_interleave = 1;
355 mfsfakelabel.d_npartitions = 1;
356 mfsfakelabel.d_partitions[0].p_size = 16384;
357 mfsfakelabel.d_partitions[0].p_fsize = 1024;
358 mfsfakelabel.d_partitions[0].p_frag = 8;
359 mfsfakelabel.d_partitions[0].p_cpg = 16;
360
361 lp = &mfsfakelabel;
362 pp = &mfsfakelabel.d_partitions[0];
363
364 goto havelabel;
365 }
366 cp = strrchr(special, '/');
367 if (cp == 0) {
368 /*
369 * No path prefix; try /dev/r%s then /dev/%s.
370 */
371 (void)sprintf(device, "%sr%s", _PATH_DEV, special);
372 if (stat(device, &st) == -1)
373 (void)sprintf(device, "%s%s", _PATH_DEV, special);
374 special = device;
375 }
376 if (Nflag) {
377 fso = -1;
378 } else {
379 fso = open(special, O_WRONLY);
380 if (fso < 0)
381 err(1, "%s: open", special);
382
383 /* Bail if target special is mounted */
384 n = getmntinfo(&mp, MNT_NOWAIT);
385 if (n == 0)
386 err(1, "%s: getmntinfo", special);
387
388 len = sizeof(_PATH_DEV) - 1;
389 s1 = special;
390 if (strncmp(_PATH_DEV, s1, len) == 0)
391 s1 += len;
392
393 while (--n >= 0) {
394 s2 = mp->f_mntfromname;
395 if (strncmp(_PATH_DEV, s2, len) == 0) {
396 s2 += len - 1;
397 *s2 = 'r';
398 }
399 if (strcmp(s1, s2) == 0 || strcmp(s1, &s2[1]) == 0)
400 errx(1, "%s is mounted on %s",
401 special, mp->f_mntonname);
402 ++mp;
403 }
404 }
405 if (mfs && disktype != NULL) {
406 lp = (struct disklabel *)getdiskbyname(disktype);
407 if (lp == NULL)
408 errx(1, "%s: unknown disk type", disktype);
409 pp = &lp->d_partitions[1];
410 } else {
411 fsi = open(special, O_RDONLY);
412 if (fsi < 0)
413 err(1, "%s: open", special);
414 if (fstat(fsi, &st) < 0)
415 err(1, "%s: fstat", special);
416 if (!S_ISCHR(st.st_mode) && !mfs)
417 warnx("%s: not a character-special device", special);
418 cp = strchr(argv[0], '\0') - 1;
419 if (cp == 0 || ((*cp < 'a' || *cp > ('a' + maxpartitions - 1))
420 && !isdigit(*cp)))
421 errx(1, "can't figure out file system partition");
422 #ifdef COMPAT
423 if (!mfs && disktype == NULL)
424 disktype = argv[1];
425 #endif
426 lp = getdisklabel(special, fsi);
427 if (isdigit(*cp))
428 pp = &lp->d_partitions[0];
429 else
430 pp = &lp->d_partitions[*cp - 'a'];
431 if (pp->p_size == 0)
432 errx(1, "`%c' partition is unavailable", *cp);
433 if (pp->p_fstype == FS_BOOT)
434 errx(1, "`%c' partition overlaps boot program", *cp);
435 }
436 havelabel:
437 if (fssize == 0)
438 fssize = pp->p_size;
439 if (fssize > pp->p_size && !mfs)
440 errx(1, "maximum file system size on the `%c' partition is %d",
441 *cp, pp->p_size);
442 if (rpm == 0) {
443 rpm = lp->d_rpm;
444 if (rpm <= 0)
445 rpm = 3600;
446 }
447 if (ntracks == 0) {
448 ntracks = lp->d_ntracks;
449 if (ntracks <= 0)
450 errx(1, "no default #tracks");
451 }
452 if (nsectors == 0) {
453 nsectors = lp->d_nsectors;
454 if (nsectors <= 0)
455 errx(1, "no default #sectors/track");
456 }
457 if (sectorsize == 0) {
458 sectorsize = lp->d_secsize;
459 if (sectorsize <= 0)
460 errx(1, "no default sector size");
461 }
462 if (trackskew == -1) {
463 trackskew = lp->d_trackskew;
464 if (trackskew < 0)
465 trackskew = 0;
466 }
467 if (interleave == 0) {
468 interleave = lp->d_interleave;
469 if (interleave <= 0)
470 interleave = 1;
471 }
472 if (fsize == 0) {
473 fsize = pp->p_fsize;
474 if (fsize <= 0)
475 fsize = MAX(DFL_FRAGSIZE, lp->d_secsize);
476 }
477 if (bsize == 0) {
478 bsize = pp->p_frag * pp->p_fsize;
479 if (bsize <= 0)
480 bsize = MIN(DFL_BLKSIZE, 8 * fsize);
481 }
482 /*
483 * Maxcontig sets the default for the maximum number of blocks
484 * that may be allocated sequentially. With filesystem clustering
485 * it is possible to allocate contiguous blocks up to the maximum
486 * transfer size permitted by the controller or buffering.
487 */
488 if (maxcontig == 0)
489 maxcontig = MAX(1, MIN(MAXPHYS, MAXBSIZE) / bsize);
490 if (density == 0)
491 density = NFPI * fsize;
492 if (minfree < MINFREE && opt != FS_OPTSPACE) {
493 warnx("%s %s %d%%", "Warning: changing optimization to space",
494 "because minfree is less than", MINFREE);
495 opt = FS_OPTSPACE;
496 }
497 if (trackspares == -1) {
498 trackspares = lp->d_sparespertrack;
499 if (trackspares < 0)
500 trackspares = 0;
501 }
502 nphyssectors = nsectors + trackspares;
503 if (cylspares == -1) {
504 cylspares = lp->d_sparespercyl;
505 if (cylspares < 0)
506 cylspares = 0;
507 }
508 secpercyl = nsectors * ntracks - cylspares;
509 if (secpercyl != lp->d_secpercyl)
510 warnx("%s (%d) %s (%u)\n",
511 "Warning: calculated sectors per cylinder", secpercyl,
512 "disagrees with disk label", lp->d_secpercyl);
513 if (maxbpg == 0)
514 maxbpg = MAXBLKPG(bsize);
515 headswitch = lp->d_headswitch;
516 trackseek = lp->d_trkseek;
517 #ifdef notdef /* label may be 0 if faked up by kernel */
518 bbsize = lp->d_bbsize;
519 sbsize = lp->d_sbsize;
520 #endif
521 oldpartition = *pp;
522 mkfs(pp, special, fsi, fso);
523 if (!Nflag && memcmp(pp, &oldpartition, sizeof(oldpartition)))
524 rewritelabel(special, fso, lp);
525 if (!Nflag)
526 close(fso);
527 close(fsi);
528 #ifdef MFS
529 if (mfs) {
530 struct mfs_args args;
531
532 switch (pid = fork()) {
533 case -1:
534 perror("mfs");
535 exit(10);
536 case 0:
537 sprintf(mountfromname, "mfs:%d", getpid());
538 break;
539 default:
540 sprintf(mountfromname, "mfs:%d", pid);
541 for (;;) {
542 /*
543 * spin until the mount succeeds
544 * or the child exits
545 */
546 usleep(1);
547
548 /*
549 * XXX Here is a race condition: another process
550 * can mount a filesystem which hides our
551 * ramdisk before we see the success.
552 */
553 if (statfs(argv[1], &sf) < 0)
554 err(88, "statfs %s", argv[1]);
555 if (!strcmp(sf.f_mntfromname, mountfromname) &&
556 !strncmp(sf.f_mntonname, argv[1],
557 MNAMELEN) &&
558 !strcmp(sf.f_fstypename, "mfs"))
559 exit(0);
560
561 res = waitpid(pid, &status, WNOHANG);
562 if (res == -1)
563 err(11, "waitpid");
564 if (res != pid)
565 continue;
566 if (WIFEXITED(status)) {
567 if (WEXITSTATUS(status) == 0)
568 exit(0);
569 errx(1, "%s: mount: %s", argv[1],
570 strerror(WEXITSTATUS(status)));
571 } else
572 errx(11, "abnormal termination");
573 }
574 /* NOTREACHED */
575 }
576
577 (void) setsid();
578 (void) close(0);
579 (void) close(1);
580 (void) close(2);
581 (void) chdir("/");
582
583 args.fspec = mountfromname;
584 args.export.ex_root = -2;
585 if (mntflags & MNT_RDONLY)
586 args.export.ex_flags = MNT_EXRDONLY;
587 else
588 args.export.ex_flags = 0;
589 args.base = membase;
590 args.size = fssize * sectorsize;
591 if (mount(MOUNT_MFS, argv[1], mntflags, &args) < 0)
592 exit(errno); /* parent prints message */
593 }
594 #endif
595 exit(0);
596 }
597
598 #ifdef COMPAT
599 char lmsg[] = "%s: can't read disk label; disk type must be specified";
600 #else
601 char lmsg[] = "%s: can't read disk label";
602 #endif
603
604 static struct disklabel *
605 getdisklabel(s, fd)
606 char *s;
607 volatile int fd;
608 {
609 static struct disklabel lab;
610
611 if (ioctl(fd, DIOCGDINFO, &lab) < 0) {
612 #ifdef COMPAT
613 if (disktype) {
614 struct disklabel *lp;
615
616 unlabeled++;
617 lp = getdiskbyname(disktype);
618 if (lp == NULL)
619 errx(1, "%s: unknown disk type", disktype);
620 return (lp);
621 }
622 #endif
623 warn("ioctl (GDINFO)");
624 errx(1, lmsg, s);
625 }
626 return (&lab);
627 }
628
629 static void
630 rewritelabel(s, fd, lp)
631 char *s;
632 volatile int fd;
633 struct disklabel *lp;
634 {
635 #ifdef COMPAT
636 if (unlabeled)
637 return;
638 #endif
639 lp->d_checksum = 0;
640 lp->d_checksum = dkcksum(lp);
641 if (ioctl(fd, DIOCWDINFO, (char *)lp) < 0) {
642 warn("ioctl (WDINFO)");
643 errx(1, "%s: can't rewrite disk label", s);
644 }
645 #if vax
646 if (lp->d_type == DTYPE_SMD && lp->d_flags & D_BADSECT) {
647 int i;
648 int cfd;
649 daddr_t alt;
650 char specname[64];
651 char blk[1024];
652 char *cp;
653
654 /*
655 * Make name for 'c' partition.
656 */
657 strcpy(specname, s);
658 cp = specname + strlen(specname) - 1;
659 if (!isdigit(*cp))
660 *cp = 'c';
661 cfd = open(specname, O_WRONLY);
662 if (cfd < 0)
663 err(1, "%s: open", specname);
664 memset(blk, 0, sizeof(blk));
665 *(struct disklabel *)(blk + LABELOFFSET) = *lp;
666 alt = lp->d_ncylinders * lp->d_secpercyl - lp->d_nsectors;
667 for (i = 1; i < 11 && i < lp->d_nsectors; i += 2) {
668 off_t offset;
669
670 offset = alt + i;
671 offset *= lp->d_secsize;
672 if (lseek(cfd, offset, SEEK_SET) == -1)
673 err(1, "lseek to badsector area: ");
674 if (write(cfd, blk, lp->d_secsize) < lp->d_secsize)
675 warn("alternate label %d write", i/2);
676 }
677 close(cfd);
678 }
679 #endif
680 }
681
682 static void
683 usage()
684 {
685 if (mfs) {
686 fprintf(stderr,
687 "usage: %s [ -fsoptions ] special-device mount-point\n",
688 __progname);
689 } else
690 fprintf(stderr,
691 "usage: %s [ -fsoptions ] special-device%s\n",
692 __progname,
693 #ifdef COMPAT
694 " [device-type]");
695 #else
696 "");
697 #endif
698 fprintf(stderr, "where fsoptions are:\n");
699 fprintf(stderr,
700 "\t-N do not create file system, just print out parameters\n");
701 fprintf(stderr, "\t-O create a 4.3BSD format filesystem\n");
702 fprintf(stderr, "\t-S sector size\n");
703 #ifdef COMPAT
704 fprintf(stderr, "\t-T disktype\n");
705 #endif
706 fprintf(stderr, "\t-a maximum contiguous blocks\n");
707 fprintf(stderr, "\t-b block size\n");
708 fprintf(stderr, "\t-c cylinders/group\n");
709 fprintf(stderr, "\t-d rotational delay between contiguous blocks\n");
710 fprintf(stderr, "\t-e maximum blocks per file in a cylinder group\n");
711 fprintf(stderr, "\t-f frag size\n");
712 fprintf(stderr, "\t-i number of bytes per inode\n");
713 fprintf(stderr, "\t-k sector 0 skew, per track\n");
714 fprintf(stderr, "\t-l hardware sector interleave\n");
715 fprintf(stderr, "\t-m minimum free space %%\n");
716 fprintf(stderr, "\t-n number of distinguished rotational positions\n");
717 fprintf(stderr, "\t-o optimization preference (`space' or `time')\n");
718 fprintf(stderr, "\t-p spare sectors per track\n");
719 fprintf(stderr, "\t-s file system size (sectors)\n");
720 fprintf(stderr, "\t-r revolutions/minute\n");
721 fprintf(stderr, "\t-t tracks/cylinder\n");
722 fprintf(stderr, "\t-u sectors/track\n");
723 fprintf(stderr, "\t-x spare sectors per cylinder\n");
724 exit(1);
725 }
726