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