newfs.c revision 1.62 1 1.62 scw /* $NetBSD: newfs.c,v 1.62 2002/12/12 11:40:17 scw 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.62 scw __RCSID("$NetBSD: newfs.c,v 1.62 2002/12/12 11:40:17 scw 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/ioctl.h>
55 1.1 cgd #include <sys/disklabel.h>
56 1.1 cgd #include <sys/file.h>
57 1.1 cgd #include <sys/mount.h>
58 1.19 thorpej #include <sys/sysctl.h>
59 1.30 drochner #include <sys/wait.h>
60 1.1 cgd
61 1.10 mycroft #include <ufs/ufs/dir.h>
62 1.27 lukem #include <ufs/ufs/dinode.h>
63 1.32 fvdl #include <ufs/ufs/ufsmount.h>
64 1.10 mycroft #include <ufs/ffs/fs.h>
65 1.10 mycroft
66 1.10 mycroft #include <ctype.h>
67 1.37 tron #include <disktab.h>
68 1.54 simonb #include <err.h>
69 1.1 cgd #include <errno.h>
70 1.54 simonb #include <grp.h>
71 1.10 mycroft #include <paths.h>
72 1.54 simonb #include <pwd.h>
73 1.54 simonb #include <signal.h>
74 1.1 cgd #include <stdio.h>
75 1.10 mycroft #include <stdlib.h>
76 1.1 cgd #include <string.h>
77 1.10 mycroft #include <syslog.h>
78 1.10 mycroft #include <unistd.h>
79 1.20 thorpej #include <util.h>
80 1.10 mycroft
81 1.10 mycroft #include "mntopts.h"
82 1.25 christos #include "dkcksum.h"
83 1.25 christos #include "extern.h"
84 1.10 mycroft
85 1.10 mycroft struct mntopt mopts[] = {
86 1.10 mycroft MOPT_STDOPTS,
87 1.10 mycroft MOPT_ASYNC,
88 1.22 cgd MOPT_UPDATE,
89 1.60 christos MOPT_GETARGS,
90 1.23 tls MOPT_NOATIME,
91 1.10 mycroft { NULL },
92 1.10 mycroft };
93 1.10 mycroft
94 1.40 simonb static struct disklabel *getdisklabel(char *, int);
95 1.40 simonb static void rewritelabel(char *, int, struct disklabel *);
96 1.54 simonb static gid_t mfs_group(const char *);
97 1.54 simonb static uid_t mfs_user(const char *);
98 1.43 lukem static int strsuftoi(const char *, const char *, int, int);
99 1.40 simonb static void usage(void);
100 1.40 simonb int main(int, char *[]);
101 1.1 cgd
102 1.1 cgd #define COMPAT /* allow non-labeled disks */
103 1.1 cgd
104 1.1 cgd /*
105 1.1 cgd * The following two constants set the default block and fragment sizes.
106 1.1 cgd * Both constants must be a power of 2 and meet the following constraints:
107 1.1 cgd * MINBSIZE <= DESBLKSIZE <= MAXBSIZE
108 1.1 cgd * sectorsize <= DESFRAGSIZE <= DESBLKSIZE
109 1.1 cgd * DESBLKSIZE / DESFRAGSIZE <= 8
110 1.1 cgd */
111 1.53 augustss /*
112 1.53 augustss * For file systems smaller than SMALL_FSSIZE we use the S_DFL_* defaults,
113 1.53 augustss * otherwise if less than MEDIUM_FSSIZE use M_DFL_*, otherwise use
114 1.53 augustss * L_DFL_*.
115 1.53 augustss */
116 1.54 simonb #define SMALL_FSSIZE (20*1024*2)
117 1.53 augustss #define S_DFL_FRAGSIZE 512
118 1.53 augustss #define S_DFL_BLKSIZE 4096
119 1.54 simonb #define MEDIUM_FSSIZE (1000*1024*2)
120 1.53 augustss #define M_DFL_FRAGSIZE 1024
121 1.53 augustss #define M_DFL_BLKSIZE 8192
122 1.53 augustss #define L_DFL_FRAGSIZE 2048
123 1.53 augustss #define L_DFL_BLKSIZE 16384
124 1.1 cgd
125 1.1 cgd /*
126 1.43 lukem * Default sector size.
127 1.43 lukem */
128 1.54 simonb #define DFL_SECSIZE 512
129 1.43 lukem
130 1.43 lukem /*
131 1.1 cgd * Cylinder groups may have up to many cylinders. The actual
132 1.1 cgd * number used depends upon how much information can be stored
133 1.1 cgd * on a single cylinder. The default is to use 16 cylinders
134 1.1 cgd * per group.
135 1.1 cgd */
136 1.51 lukem #define DESCPG 65536 /* desired fs_cpg ("infinity") */
137 1.1 cgd
138 1.1 cgd /*
139 1.1 cgd * ROTDELAY gives the minimum number of milliseconds to initiate
140 1.1 cgd * another disk transfer on the same cylinder. It is used in
141 1.1 cgd * determining the rotationally optimal layout for disk blocks
142 1.13 mycroft * within a file; the default of fs_rotdelay is 0ms.
143 1.1 cgd */
144 1.54 simonb #define ROTDELAY 0
145 1.1 cgd
146 1.1 cgd /*
147 1.1 cgd * MAXBLKPG determines the maximum number of data blocks which are
148 1.1 cgd * placed in a single cylinder group. The default is one indirect
149 1.1 cgd * block worth of data blocks.
150 1.1 cgd */
151 1.54 simonb #define MAXBLKPG(bsize) ((bsize) / sizeof(daddr_t))
152 1.1 cgd
153 1.1 cgd /*
154 1.1 cgd * Each file system has a number of inodes statically allocated.
155 1.1 cgd * We allocate one inode slot per NFPI fragments, expecting this
156 1.1 cgd * to be far more than we will ever need.
157 1.1 cgd */
158 1.1 cgd #define NFPI 4
159 1.1 cgd
160 1.1 cgd /*
161 1.1 cgd * For each cylinder we keep track of the availability of blocks at different
162 1.1 cgd * rotational positions, so that we can lay out the data to be picked
163 1.1 cgd * up with minimum rotational latency. NRPOS is the default number of
164 1.1 cgd * rotational positions that we distinguish. With NRPOS of 8 the resolution
165 1.13 mycroft * of our summary information is 2ms for a typical 3600 rpm drive. Caching
166 1.13 mycroft * and zoning pretty much defeats rotational optimization, so we now use a
167 1.13 mycroft * default of 1.
168 1.1 cgd */
169 1.13 mycroft #define NRPOS 1 /* number distinct rotational positions */
170 1.1 cgd
171 1.1 cgd
172 1.1 cgd int mfs; /* run as the memory based filesystem */
173 1.1 cgd int Nflag; /* run without writing file system */
174 1.10 mycroft int Oflag; /* format as an 4.3BSD file system */
175 1.1 cgd int fssize; /* file system size */
176 1.1 cgd int ntracks; /* # tracks/cylinder */
177 1.1 cgd int nsectors; /* # sectors/track */
178 1.1 cgd int nphyssectors; /* # sectors/track including spares */
179 1.1 cgd int secpercyl; /* sectors per cylinder */
180 1.1 cgd int trackspares = -1; /* spare sectors per track */
181 1.1 cgd int cylspares = -1; /* spare sectors per cylinder */
182 1.1 cgd int sectorsize; /* bytes/sector */
183 1.1 cgd int rpm; /* revolutions/minute of drive */
184 1.1 cgd int interleave; /* hardware sector interleave */
185 1.1 cgd int trackskew = -1; /* sector 0 skew, per track */
186 1.1 cgd int fsize = 0; /* fragment size */
187 1.1 cgd int bsize = 0; /* block size */
188 1.1 cgd int cpg = DESCPG; /* cylinders/cylinder group */
189 1.1 cgd int cpgflg; /* cylinders/cylinder group flag was given */
190 1.1 cgd int minfree = MINFREE; /* free space threshold */
191 1.1 cgd int opt = DEFAULTOPT; /* optimization preference (space or time) */
192 1.1 cgd int density; /* number of bytes per inode */
193 1.36 mycroft int maxcontig = 0; /* max contiguous blocks to allocate */
194 1.1 cgd int rotdelay = ROTDELAY; /* rotational delay between blocks */
195 1.1 cgd int maxbpg; /* maximum blocks per file in a cyl group */
196 1.1 cgd int nrpos = NRPOS; /* # of distinguished rotational positions */
197 1.47 lukem int avgfilesize = AVFILESIZ;/* expected average file size */
198 1.47 lukem int avgfpdir = AFPDIR; /* expected number of files per directory */
199 1.1 cgd int bbsize = BBSIZE; /* boot block size */
200 1.1 cgd int sbsize = SBSIZE; /* superblock size */
201 1.10 mycroft int mntflags = MNT_ASYNC; /* flags to be passed to mount */
202 1.1 cgd u_long memleft; /* virtual memory available */
203 1.1 cgd caddr_t membase; /* start address of memory based filesystem */
204 1.43 lukem int needswap; /* Filesystem not in native byte order */
205 1.1 cgd #ifdef COMPAT
206 1.1 cgd char *disktype;
207 1.1 cgd int unlabeled;
208 1.1 cgd #endif
209 1.61 dbj char *appleufs_volname = 0; /* Apple UFS volume name */
210 1.61 dbj int isappleufs = 0;
211 1.1 cgd
212 1.1 cgd char device[MAXPATHLEN];
213 1.1 cgd
214 1.10 mycroft int
215 1.40 simonb main(int argc, char *argv[])
216 1.1 cgd {
217 1.25 christos struct partition *pp;
218 1.25 christos struct disklabel *lp;
219 1.14 cgd struct disklabel mfsfakelabel;
220 1.1 cgd struct partition oldpartition;
221 1.10 mycroft struct statfs *mp;
222 1.58 lukem int ch, fsi, fso, len, maxpartitions, n, Fflag, Iflag, Zflag;
223 1.43 lukem char *cp, *endp, *s1, *s2, *special;
224 1.43 lukem const char *opstring;
225 1.43 lukem long long llsize;
226 1.53 augustss int dfl_fragsize, dfl_blksize;
227 1.30 drochner #ifdef MFS
228 1.30 drochner char mountfromname[100];
229 1.30 drochner pid_t pid, res;
230 1.30 drochner struct statfs sf;
231 1.56 lukem int status;
232 1.56 lukem #endif
233 1.54 simonb mode_t mfsmode;
234 1.54 simonb uid_t mfsuid;
235 1.54 simonb gid_t mfsgid;
236 1.1 cgd
237 1.43 lukem cp = NULL;
238 1.43 lukem fsi = fso = -1;
239 1.58 lukem Fflag = Iflag = Zflag = 0;
240 1.42 cgd if (strstr(getprogname(), "mfs")) {
241 1.1 cgd mfs = 1;
242 1.54 simonb mfsmode = 01777; /* default mode for a /tmp-type directory */
243 1.54 simonb mfsuid = 0; /* user root */
244 1.54 simonb mfsgid = 0; /* group wheel */
245 1.1 cgd Nflag++;
246 1.1 cgd }
247 1.1 cgd
248 1.19 thorpej maxpartitions = getmaxpartitions();
249 1.19 thorpej if (maxpartitions > 26)
250 1.25 christos errx(1, "insane maxpartitions value %d", maxpartitions);
251 1.19 thorpej
252 1.10 mycroft opstring = mfs ?
253 1.54 simonb "NT:a:b:c:d:e:f:g:h:i:m:o:p:s:u:" :
254 1.61 dbj "B:FINOS:T:Za:b:c:d:e:f:g:h:i:k:l:m:n:o:p:r:s:t:u:v:x:";
255 1.26 lukem while ((ch = getopt(argc, argv, opstring)) != -1)
256 1.10 mycroft switch (ch) {
257 1.33 bouyer case 'B':
258 1.33 bouyer if (strcmp(optarg, "be") == 0) {
259 1.33 bouyer #if BYTE_ORDER == LITTLE_ENDIAN
260 1.33 bouyer needswap = 1;
261 1.33 bouyer #endif
262 1.33 bouyer } else if (strcmp(optarg, "le") == 0) {
263 1.33 bouyer #if BYTE_ORDER == BIG_ENDIAN
264 1.33 bouyer needswap = 1;
265 1.33 bouyer #endif
266 1.33 bouyer } else
267 1.33 bouyer usage();
268 1.33 bouyer break;
269 1.43 lukem case 'F':
270 1.43 lukem Fflag = 1;
271 1.43 lukem break;
272 1.58 lukem case 'I':
273 1.58 lukem Iflag = 1;
274 1.58 lukem break;
275 1.10 mycroft case 'N':
276 1.10 mycroft Nflag = 1;
277 1.1 cgd break;
278 1.10 mycroft case 'O':
279 1.10 mycroft Oflag = 1;
280 1.1 cgd break;
281 1.1 cgd case 'S':
282 1.43 lukem sectorsize = strsuftoi("sector size",
283 1.43 lukem optarg, 1, INT_MAX);
284 1.1 cgd break;
285 1.1 cgd #ifdef COMPAT
286 1.1 cgd case 'T':
287 1.1 cgd disktype = optarg;
288 1.1 cgd break;
289 1.1 cgd #endif
290 1.43 lukem case 'Z':
291 1.43 lukem Zflag = 1;
292 1.43 lukem break;
293 1.1 cgd case 'a':
294 1.43 lukem maxcontig = strsuftoi("maximum contiguous blocks",
295 1.43 lukem optarg, 1, INT_MAX);
296 1.1 cgd break;
297 1.1 cgd case 'b':
298 1.43 lukem bsize = strsuftoi("block size",
299 1.50 lukem optarg, MINBSIZE, MAXBSIZE);
300 1.1 cgd break;
301 1.1 cgd case 'c':
302 1.43 lukem cpg = strsuftoi("cylinders per group",
303 1.43 lukem optarg, 1, INT_MAX);
304 1.1 cgd cpgflg++;
305 1.1 cgd break;
306 1.1 cgd case 'd':
307 1.43 lukem rotdelay = strsuftoi("rotational delay",
308 1.43 lukem optarg, 0, INT_MAX);
309 1.1 cgd break;
310 1.1 cgd case 'e':
311 1.43 lukem maxbpg = strsuftoi(
312 1.43 lukem "blocks per file in a cylinder group",
313 1.43 lukem optarg, 1, INT_MAX);
314 1.1 cgd break;
315 1.1 cgd case 'f':
316 1.43 lukem fsize = strsuftoi("fragment size",
317 1.50 lukem optarg, 1, MAXBSIZE);
318 1.1 cgd break;
319 1.47 lukem case 'g':
320 1.54 simonb if (mfs)
321 1.54 simonb mfsgid = mfs_group(optarg);
322 1.54 simonb else {
323 1.54 simonb avgfilesize = strsuftoi("average file size",
324 1.54 simonb optarg, 1, INT_MAX);
325 1.54 simonb }
326 1.47 lukem break;
327 1.47 lukem case 'h':
328 1.47 lukem avgfpdir = strsuftoi("expected files per directory",
329 1.47 lukem optarg, 1, INT_MAX);
330 1.47 lukem break;
331 1.1 cgd case 'i':
332 1.43 lukem density = strsuftoi("bytes per inode",
333 1.43 lukem optarg, 1, INT_MAX);
334 1.1 cgd break;
335 1.1 cgd case 'k':
336 1.43 lukem trackskew = strsuftoi("track skew",
337 1.43 lukem optarg, 0, INT_MAX);
338 1.1 cgd break;
339 1.1 cgd case 'l':
340 1.43 lukem interleave = strsuftoi("interleave",
341 1.43 lukem optarg, 1, INT_MAX);
342 1.1 cgd break;
343 1.1 cgd case 'm':
344 1.43 lukem minfree = strsuftoi("free space %",
345 1.43 lukem optarg, 0, 99);
346 1.1 cgd break;
347 1.1 cgd case 'n':
348 1.43 lukem nrpos = strsuftoi("rotational layout count",
349 1.43 lukem optarg, 1, INT_MAX);
350 1.1 cgd break;
351 1.1 cgd case 'o':
352 1.10 mycroft if (mfs)
353 1.27 lukem getmntopts(optarg, mopts, &mntflags, 0);
354 1.10 mycroft else {
355 1.10 mycroft if (strcmp(optarg, "space") == 0)
356 1.10 mycroft opt = FS_OPTSPACE;
357 1.10 mycroft else if (strcmp(optarg, "time") == 0)
358 1.10 mycroft opt = FS_OPTTIME;
359 1.10 mycroft else
360 1.25 christos errx(1, "%s %s",
361 1.25 christos "unknown optimization preference: ",
362 1.25 christos "use `space' or `time'.");
363 1.10 mycroft }
364 1.1 cgd break;
365 1.1 cgd case 'p':
366 1.54 simonb if (mfs) {
367 1.54 simonb if ((mfsmode = strtol(optarg, NULL, 8)) <= 0)
368 1.54 simonb errx(1, "bad mode `%s'", optarg);
369 1.54 simonb } else {
370 1.54 simonb trackspares = strsuftoi(
371 1.54 simonb "spare sectors per track", optarg, 0,
372 1.54 simonb INT_MAX);
373 1.54 simonb }
374 1.1 cgd break;
375 1.1 cgd case 'r':
376 1.43 lukem rpm = strsuftoi("revolutions per minute",
377 1.43 lukem optarg, 1, INT_MAX);
378 1.1 cgd break;
379 1.1 cgd case 's':
380 1.43 lukem llsize = strtoll(optarg, &endp, 10);
381 1.43 lukem if (endp[0] != '\0' && endp[1] != '\0')
382 1.43 lukem llsize = -1;
383 1.43 lukem else {
384 1.43 lukem int ssiz;
385 1.43 lukem
386 1.43 lukem ssiz = (sectorsize ? sectorsize : DFL_SECSIZE);
387 1.43 lukem switch (tolower((unsigned char)endp[0])) {
388 1.43 lukem case 'b':
389 1.43 lukem llsize /= ssiz;
390 1.43 lukem break;
391 1.43 lukem case 'k':
392 1.43 lukem llsize *= 1024 / ssiz;
393 1.43 lukem break;
394 1.43 lukem case 'm':
395 1.43 lukem llsize *= 1024 * 1024 / ssiz;
396 1.43 lukem break;
397 1.43 lukem case 'g':
398 1.43 lukem llsize *= 1024 * 1024 * 1024 / ssiz;
399 1.43 lukem break;
400 1.43 lukem case '\0':
401 1.43 lukem case 's':
402 1.43 lukem break;
403 1.43 lukem default:
404 1.43 lukem llsize = -1;
405 1.41 simonb }
406 1.41 simonb }
407 1.43 lukem if (llsize > INT_MAX)
408 1.43 lukem errx(1, "file system size `%s' is too large.",
409 1.43 lukem optarg);
410 1.43 lukem if (llsize <= 0)
411 1.43 lukem errx(1,
412 1.43 lukem "`%s' is not a valid number for file system size.",
413 1.43 lukem optarg);
414 1.43 lukem fssize = (int)llsize;
415 1.1 cgd break;
416 1.1 cgd case 't':
417 1.43 lukem ntracks = strsuftoi("total tracks",
418 1.43 lukem optarg, 1, INT_MAX);
419 1.1 cgd break;
420 1.1 cgd case 'u':
421 1.54 simonb if (mfs)
422 1.54 simonb mfsuid = mfs_user(optarg);
423 1.54 simonb else {
424 1.54 simonb nsectors = strsuftoi("sectors per track",
425 1.54 simonb optarg, 1, INT_MAX);
426 1.54 simonb }
427 1.1 cgd break;
428 1.61 dbj case 'v':
429 1.61 dbj appleufs_volname = optarg;
430 1.61 dbj if (strchr(appleufs_volname, ':') || strchr(appleufs_volname, '/'))
431 1.61 dbj errx(1,"Apple UFS volume name cannot contain ':' or '/'");
432 1.61 dbj if (appleufs_volname[0] == '\0')
433 1.61 dbj errx(1,"Apple UFS volume name cannot be zero length");
434 1.61 dbj isappleufs = 1;
435 1.61 dbj break;
436 1.1 cgd case 'x':
437 1.43 lukem cylspares = strsuftoi("spare sectors per cylinder",
438 1.43 lukem optarg, 0, INT_MAX);
439 1.1 cgd break;
440 1.1 cgd case '?':
441 1.1 cgd default:
442 1.1 cgd usage();
443 1.1 cgd }
444 1.1 cgd argc -= optind;
445 1.1 cgd argv += optind;
446 1.60 christos if (mntflags & MNT_GETARGS)
447 1.60 christos goto doit;
448 1.1 cgd
449 1.1 cgd if (argc != 2 && (mfs || argc != 1))
450 1.1 cgd usage();
451 1.1 cgd
452 1.1 cgd special = argv[0];
453 1.49 lukem if (Fflag || mfs) {
454 1.14 cgd /*
455 1.49 lukem * it's a file system image or an MFS, so fake up a label.
456 1.49 lukem * XXX
457 1.14 cgd */
458 1.43 lukem if (!sectorsize)
459 1.43 lukem sectorsize = DFL_SECSIZE;
460 1.43 lukem
461 1.43 lukem if (Fflag && !Nflag) { /* creating image in a regular file */
462 1.44 lukem if (fssize == 0)
463 1.44 lukem errx(1, "need to specify size when using -F");
464 1.43 lukem fso = open(special, O_RDWR | O_CREAT | O_TRUNC, 0777);
465 1.43 lukem if (fso == -1)
466 1.43 lukem err(1, "can't open file %s", special);
467 1.44 lukem if ((fsi = dup(fso)) == -1)
468 1.44 lukem err(1, "can't dup(2) image fd");
469 1.48 lukem /* XXXLUKEM: only ftruncate() regular files ? */
470 1.43 lukem if (ftruncate(fso, (off_t)fssize * sectorsize) == -1)
471 1.43 lukem err(1, "can't resize %s to %d",
472 1.43 lukem special, fssize);
473 1.43 lukem
474 1.43 lukem if (Zflag) { /* pre-zero the file */
475 1.43 lukem char *buf;
476 1.45 lukem int bufsize, i;
477 1.45 lukem off_t bufrem;
478 1.45 lukem struct statfs sfs;
479 1.45 lukem
480 1.45 lukem if (fstatfs(fso, &sfs) == -1) {
481 1.45 lukem warn("can't fstatfs `%s'", special);
482 1.45 lukem bufsize = 8192;
483 1.45 lukem } else
484 1.45 lukem bufsize = sfs.f_iosize;
485 1.43 lukem
486 1.45 lukem if ((buf = calloc(1, bufsize)) == NULL)
487 1.43 lukem err(1, "can't malloc buffer of %d",
488 1.45 lukem bufsize);
489 1.45 lukem bufrem = fssize * sectorsize;
490 1.43 lukem printf(
491 1.45 lukem "Creating file system image in `%s', size %lld bytes, in %d byte chunks.\n",
492 1.45 lukem special, (long long)bufrem, bufsize);
493 1.45 lukem while (bufrem > 0) {
494 1.45 lukem i = write(fso, buf,
495 1.45 lukem MIN(bufsize, bufrem));
496 1.45 lukem if (i == -1)
497 1.45 lukem err(1, "writing image");
498 1.45 lukem bufrem -= i;
499 1.43 lukem }
500 1.43 lukem }
501 1.43 lukem
502 1.43 lukem }
503 1.14 cgd
504 1.14 cgd memset(&mfsfakelabel, 0, sizeof(mfsfakelabel));
505 1.43 lukem mfsfakelabel.d_secsize = sectorsize;
506 1.43 lukem mfsfakelabel.d_nsectors = 64; /* these 3 add up to 16MB */
507 1.14 cgd mfsfakelabel.d_ntracks = 16;
508 1.14 cgd mfsfakelabel.d_ncylinders = 16;
509 1.43 lukem mfsfakelabel.d_secpercyl =
510 1.43 lukem mfsfakelabel.d_nsectors * mfsfakelabel.d_ntracks;
511 1.43 lukem mfsfakelabel.d_secperunit =
512 1.43 lukem mfsfakelabel.d_ncylinders * mfsfakelabel.d_secpercyl;
513 1.49 lukem mfsfakelabel.d_rpm = 10000;
514 1.14 cgd mfsfakelabel.d_interleave = 1;
515 1.14 cgd mfsfakelabel.d_npartitions = 1;
516 1.43 lukem mfsfakelabel.d_partitions[0].p_size = mfsfakelabel.d_secperunit;
517 1.14 cgd mfsfakelabel.d_partitions[0].p_fsize = 1024;
518 1.14 cgd mfsfakelabel.d_partitions[0].p_frag = 8;
519 1.14 cgd mfsfakelabel.d_partitions[0].p_cpg = 16;
520 1.14 cgd
521 1.14 cgd lp = &mfsfakelabel;
522 1.14 cgd pp = &mfsfakelabel.d_partitions[0];
523 1.49 lukem } else { /* !Fflag && !mfs */
524 1.49 lukem fsi = opendisk(special, O_RDONLY, device, sizeof(device), 0);
525 1.49 lukem special = device;
526 1.49 lukem if (fsi < 0)
527 1.49 lukem err(1, "%s: open for read", special);
528 1.49 lukem
529 1.49 lukem if (Nflag) {
530 1.49 lukem fso = -1;
531 1.49 lukem } else {
532 1.49 lukem fso = open(special, O_WRONLY);
533 1.49 lukem if (fso < 0)
534 1.49 lukem err(1, "%s: open for write", special);
535 1.49 lukem
536 1.49 lukem /* Bail if target special is mounted */
537 1.49 lukem n = getmntinfo(&mp, MNT_NOWAIT);
538 1.49 lukem if (n == 0)
539 1.49 lukem err(1, "%s: getmntinfo", special);
540 1.49 lukem
541 1.49 lukem len = sizeof(_PATH_DEV) - 1;
542 1.49 lukem s1 = special;
543 1.49 lukem if (strncmp(_PATH_DEV, s1, len) == 0)
544 1.49 lukem s1 += len;
545 1.49 lukem
546 1.49 lukem while (--n >= 0) {
547 1.49 lukem s2 = mp->f_mntfromname;
548 1.49 lukem if (strncmp(_PATH_DEV, s2, len) == 0) {
549 1.49 lukem s2 += len - 1;
550 1.49 lukem *s2 = 'r';
551 1.49 lukem }
552 1.49 lukem if (strcmp(s1, s2) == 0 ||
553 1.49 lukem strcmp(s1, &s2[1]) == 0)
554 1.49 lukem errx(1, "%s is mounted on %s",
555 1.49 lukem special, mp->f_mntonname);
556 1.49 lukem ++mp;
557 1.10 mycroft }
558 1.10 mycroft }
559 1.11 mycroft cp = strchr(argv[0], '\0') - 1;
560 1.25 christos if (cp == 0 || ((*cp < 'a' || *cp > ('a' + maxpartitions - 1))
561 1.25 christos && !isdigit(*cp)))
562 1.25 christos errx(1, "can't figure out file system partition");
563 1.1 cgd #ifdef COMPAT
564 1.49 lukem if (disktype == NULL)
565 1.10 mycroft disktype = argv[1];
566 1.1 cgd #endif
567 1.10 mycroft lp = getdisklabel(special, fsi);
568 1.10 mycroft if (isdigit(*cp))
569 1.10 mycroft pp = &lp->d_partitions[0];
570 1.10 mycroft else
571 1.10 mycroft pp = &lp->d_partitions[*cp - 'a'];
572 1.10 mycroft if (pp->p_size == 0)
573 1.25 christos errx(1, "`%c' partition is unavailable", *cp);
574 1.61 dbj if (pp->p_fstype == FS_APPLEUFS)
575 1.61 dbj isappleufs = 1;
576 1.61 dbj if (isappleufs) {
577 1.61 dbj if (!Iflag && (pp->p_fstype != FS_APPLEUFS))
578 1.61 dbj errx(1, "`%c' partition type is not `Apple UFS'", *cp);
579 1.61 dbj } else {
580 1.61 dbj if (!Iflag && (pp->p_fstype != FS_BSDFFS))
581 1.61 dbj errx(1, "`%c' partition type is not `4.2BSD'", *cp);
582 1.61 dbj }
583 1.49 lukem } /* !Fflag && !mfs */
584 1.43 lukem
585 1.1 cgd if (fssize == 0)
586 1.1 cgd fssize = pp->p_size;
587 1.43 lukem if (fssize > pp->p_size && !mfs && !Fflag)
588 1.25 christos errx(1, "maximum file system size on the `%c' partition is %d",
589 1.25 christos *cp, pp->p_size);
590 1.1 cgd if (rpm == 0) {
591 1.1 cgd rpm = lp->d_rpm;
592 1.1 cgd if (rpm <= 0)
593 1.1 cgd rpm = 3600;
594 1.1 cgd }
595 1.1 cgd if (ntracks == 0) {
596 1.1 cgd ntracks = lp->d_ntracks;
597 1.1 cgd if (ntracks <= 0)
598 1.25 christos errx(1, "no default #tracks");
599 1.1 cgd }
600 1.1 cgd if (nsectors == 0) {
601 1.1 cgd nsectors = lp->d_nsectors;
602 1.1 cgd if (nsectors <= 0)
603 1.25 christos errx(1, "no default #sectors/track");
604 1.1 cgd }
605 1.1 cgd if (sectorsize == 0) {
606 1.1 cgd sectorsize = lp->d_secsize;
607 1.1 cgd if (sectorsize <= 0)
608 1.25 christos errx(1, "no default sector size");
609 1.1 cgd }
610 1.1 cgd if (trackskew == -1) {
611 1.1 cgd trackskew = lp->d_trackskew;
612 1.1 cgd if (trackskew < 0)
613 1.1 cgd trackskew = 0;
614 1.1 cgd }
615 1.1 cgd if (interleave == 0) {
616 1.1 cgd interleave = lp->d_interleave;
617 1.1 cgd if (interleave <= 0)
618 1.1 cgd interleave = 1;
619 1.1 cgd }
620 1.53 augustss
621 1.53 augustss if (fssize < SMALL_FSSIZE) {
622 1.53 augustss dfl_fragsize = S_DFL_FRAGSIZE;
623 1.53 augustss dfl_blksize = S_DFL_BLKSIZE;
624 1.53 augustss } else if (fssize < MEDIUM_FSSIZE) {
625 1.53 augustss dfl_fragsize = M_DFL_FRAGSIZE;
626 1.53 augustss dfl_blksize = M_DFL_BLKSIZE;
627 1.53 augustss } else {
628 1.53 augustss dfl_fragsize = L_DFL_FRAGSIZE;
629 1.53 augustss dfl_blksize = L_DFL_BLKSIZE;
630 1.53 augustss }
631 1.53 augustss
632 1.1 cgd if (fsize == 0) {
633 1.1 cgd fsize = pp->p_fsize;
634 1.1 cgd if (fsize <= 0)
635 1.53 augustss fsize = MAX(dfl_fragsize, lp->d_secsize);
636 1.1 cgd }
637 1.1 cgd if (bsize == 0) {
638 1.1 cgd bsize = pp->p_frag * pp->p_fsize;
639 1.1 cgd if (bsize <= 0)
640 1.53 augustss bsize = MIN(dfl_blksize, 8 * fsize);
641 1.1 cgd }
642 1.10 mycroft /*
643 1.10 mycroft * Maxcontig sets the default for the maximum number of blocks
644 1.10 mycroft * that may be allocated sequentially. With filesystem clustering
645 1.10 mycroft * it is possible to allocate contiguous blocks up to the maximum
646 1.10 mycroft * transfer size permitted by the controller or buffering.
647 1.10 mycroft */
648 1.10 mycroft if (maxcontig == 0)
649 1.27 lukem maxcontig = MAX(1, MIN(MAXPHYS, MAXBSIZE) / bsize);
650 1.1 cgd if (density == 0)
651 1.1 cgd density = NFPI * fsize;
652 1.8 cgd if (minfree < MINFREE && opt != FS_OPTSPACE) {
653 1.25 christos warnx("%s %s %d%%", "Warning: changing optimization to space",
654 1.25 christos "because minfree is less than", MINFREE);
655 1.1 cgd opt = FS_OPTSPACE;
656 1.1 cgd }
657 1.1 cgd if (trackspares == -1) {
658 1.1 cgd trackspares = lp->d_sparespertrack;
659 1.1 cgd if (trackspares < 0)
660 1.1 cgd trackspares = 0;
661 1.1 cgd }
662 1.1 cgd nphyssectors = nsectors + trackspares;
663 1.1 cgd if (cylspares == -1) {
664 1.1 cgd cylspares = lp->d_sparespercyl;
665 1.1 cgd if (cylspares < 0)
666 1.1 cgd cylspares = 0;
667 1.1 cgd }
668 1.1 cgd secpercyl = nsectors * ntracks - cylspares;
669 1.1 cgd if (secpercyl != lp->d_secpercyl)
670 1.59 soren warnx("%s (%d) %s (%u)",
671 1.1 cgd "Warning: calculated sectors per cylinder", secpercyl,
672 1.1 cgd "disagrees with disk label", lp->d_secpercyl);
673 1.1 cgd if (maxbpg == 0)
674 1.1 cgd maxbpg = MAXBLKPG(bsize);
675 1.1 cgd #ifdef notdef /* label may be 0 if faked up by kernel */
676 1.1 cgd bbsize = lp->d_bbsize;
677 1.1 cgd sbsize = lp->d_sbsize;
678 1.1 cgd #endif
679 1.1 cgd oldpartition = *pp;
680 1.54 simonb mkfs(pp, special, fsi, fso, mfsmode, mfsuid, mfsgid);
681 1.43 lukem if (!Nflag && memcmp(pp, &oldpartition, sizeof(oldpartition)) && !Fflag)
682 1.1 cgd rewritelabel(special, fso, lp);
683 1.1 cgd if (!Nflag)
684 1.1 cgd close(fso);
685 1.1 cgd close(fsi);
686 1.1 cgd #ifdef MFS
687 1.1 cgd if (mfs) {
688 1.1 cgd struct mfs_args args;
689 1.1 cgd
690 1.30 drochner switch (pid = fork()) {
691 1.30 drochner case -1:
692 1.30 drochner perror("mfs");
693 1.30 drochner exit(10);
694 1.30 drochner case 0:
695 1.34 mycroft (void)snprintf(mountfromname, sizeof(mountfromname),
696 1.34 mycroft "mfs:%d", getpid());
697 1.30 drochner break;
698 1.30 drochner default:
699 1.34 mycroft (void)snprintf(mountfromname, sizeof(mountfromname),
700 1.34 mycroft "mfs:%d", pid);
701 1.30 drochner for (;;) {
702 1.30 drochner /*
703 1.30 drochner * spin until the mount succeeds
704 1.30 drochner * or the child exits
705 1.30 drochner */
706 1.30 drochner usleep(1);
707 1.30 drochner
708 1.30 drochner /*
709 1.30 drochner * XXX Here is a race condition: another process
710 1.30 drochner * can mount a filesystem which hides our
711 1.30 drochner * ramdisk before we see the success.
712 1.30 drochner */
713 1.30 drochner if (statfs(argv[1], &sf) < 0)
714 1.30 drochner err(88, "statfs %s", argv[1]);
715 1.30 drochner if (!strcmp(sf.f_mntfromname, mountfromname) &&
716 1.30 drochner !strncmp(sf.f_mntonname, argv[1],
717 1.30 drochner MNAMELEN) &&
718 1.30 drochner !strcmp(sf.f_fstypename, "mfs"))
719 1.30 drochner exit(0);
720 1.30 drochner
721 1.30 drochner res = waitpid(pid, &status, WNOHANG);
722 1.30 drochner if (res == -1)
723 1.30 drochner err(11, "waitpid");
724 1.30 drochner if (res != pid)
725 1.30 drochner continue;
726 1.31 drochner if (WIFEXITED(status)) {
727 1.31 drochner if (WEXITSTATUS(status) == 0)
728 1.31 drochner exit(0);
729 1.30 drochner errx(1, "%s: mount: %s", argv[1],
730 1.30 drochner strerror(WEXITSTATUS(status)));
731 1.31 drochner } else
732 1.30 drochner errx(11, "abnormal termination");
733 1.30 drochner }
734 1.30 drochner /* NOTREACHED */
735 1.30 drochner }
736 1.30 drochner
737 1.30 drochner (void) setsid();
738 1.30 drochner (void) close(0);
739 1.30 drochner (void) close(1);
740 1.30 drochner (void) close(2);
741 1.30 drochner (void) chdir("/");
742 1.30 drochner
743 1.30 drochner args.fspec = mountfromname;
744 1.10 mycroft args.export.ex_root = -2;
745 1.10 mycroft if (mntflags & MNT_RDONLY)
746 1.10 mycroft args.export.ex_flags = MNT_EXRDONLY;
747 1.10 mycroft else
748 1.10 mycroft args.export.ex_flags = 0;
749 1.1 cgd args.base = membase;
750 1.1 cgd args.size = fssize * sectorsize;
751 1.60 christos doit:
752 1.60 christos if (mount(MOUNT_MFS, argv[1], mntflags, &args) < 0) {
753 1.60 christos if (mntflags & MNT_GETARGS)
754 1.60 christos err(1, "mount `%s' failed", argv[1]);
755 1.30 drochner exit(errno); /* parent prints message */
756 1.60 christos }
757 1.60 christos if (mntflags & MNT_GETARGS)
758 1.60 christos printf("base=%p, size=%ld\n", args.base, args.size);
759 1.1 cgd }
760 1.1 cgd #endif
761 1.1 cgd exit(0);
762 1.1 cgd }
763 1.1 cgd
764 1.1 cgd #ifdef COMPAT
765 1.39 is const char lmsg[] = "%s: can't read disk label; disk type must be specified";
766 1.1 cgd #else
767 1.39 is const char lmsg[] = "%s: can't read disk label";
768 1.1 cgd #endif
769 1.1 cgd
770 1.25 christos static struct disklabel *
771 1.40 simonb getdisklabel(char *s, volatile int fd)
772 1.40 simonb /* XXX why is fs volatile?! */
773 1.1 cgd {
774 1.1 cgd static struct disklabel lab;
775 1.1 cgd
776 1.24 tls if (ioctl(fd, DIOCGDINFO, &lab) < 0) {
777 1.1 cgd #ifdef COMPAT
778 1.1 cgd if (disktype) {
779 1.25 christos struct disklabel *lp;
780 1.1 cgd
781 1.1 cgd unlabeled++;
782 1.1 cgd lp = getdiskbyname(disktype);
783 1.1 cgd if (lp == NULL)
784 1.25 christos errx(1, "%s: unknown disk type", disktype);
785 1.1 cgd return (lp);
786 1.1 cgd }
787 1.1 cgd #endif
788 1.10 mycroft warn("ioctl (GDINFO)");
789 1.25 christos errx(1, lmsg, s);
790 1.1 cgd }
791 1.1 cgd return (&lab);
792 1.1 cgd }
793 1.1 cgd
794 1.25 christos static void
795 1.40 simonb rewritelabel(char *s, volatile int fd, struct disklabel *lp)
796 1.40 simonb /* XXX why is fd volatile?! */
797 1.1 cgd {
798 1.1 cgd #ifdef COMPAT
799 1.1 cgd if (unlabeled)
800 1.1 cgd return;
801 1.1 cgd #endif
802 1.1 cgd lp->d_checksum = 0;
803 1.1 cgd lp->d_checksum = dkcksum(lp);
804 1.1 cgd if (ioctl(fd, DIOCWDINFO, (char *)lp) < 0) {
805 1.57 thorpej if (errno == ESRCH)
806 1.57 thorpej return;
807 1.10 mycroft warn("ioctl (WDINFO)");
808 1.25 christos errx(1, "%s: can't rewrite disk label", s);
809 1.1 cgd }
810 1.35 matt #if __vax__
811 1.1 cgd if (lp->d_type == DTYPE_SMD && lp->d_flags & D_BADSECT) {
812 1.25 christos int i;
813 1.1 cgd int cfd;
814 1.1 cgd daddr_t alt;
815 1.62 scw off_t loff;
816 1.1 cgd char specname[64];
817 1.1 cgd char blk[1024];
818 1.1 cgd char *cp;
819 1.1 cgd
820 1.1 cgd /*
821 1.1 cgd * Make name for 'c' partition.
822 1.1 cgd */
823 1.1 cgd strcpy(specname, s);
824 1.1 cgd cp = specname + strlen(specname) - 1;
825 1.1 cgd if (!isdigit(*cp))
826 1.1 cgd *cp = 'c';
827 1.1 cgd cfd = open(specname, O_WRONLY);
828 1.1 cgd if (cfd < 0)
829 1.28 enami err(1, "%s: open", specname);
830 1.62 scw if ((loff = getlabeloffset()) < 0)
831 1.62 scw err(1, "getlabeloffset()");
832 1.11 mycroft memset(blk, 0, sizeof(blk));
833 1.62 scw *(struct disklabel *)(blk + loff) = *lp;
834 1.1 cgd alt = lp->d_ncylinders * lp->d_secpercyl - lp->d_nsectors;
835 1.1 cgd for (i = 1; i < 11 && i < lp->d_nsectors; i += 2) {
836 1.17 cgd off_t offset;
837 1.17 cgd
838 1.17 cgd offset = alt + i;
839 1.17 cgd offset *= lp->d_secsize;
840 1.17 cgd if (lseek(cfd, offset, SEEK_SET) == -1)
841 1.25 christos err(1, "lseek to badsector area: ");
842 1.1 cgd if (write(cfd, blk, lp->d_secsize) < lp->d_secsize)
843 1.10 mycroft warn("alternate label %d write", i/2);
844 1.1 cgd }
845 1.1 cgd close(cfd);
846 1.1 cgd }
847 1.1 cgd #endif
848 1.1 cgd }
849 1.1 cgd
850 1.54 simonb static gid_t
851 1.54 simonb mfs_group(const char *gname)
852 1.54 simonb {
853 1.54 simonb struct group *gp;
854 1.54 simonb
855 1.54 simonb if (!(gp = getgrnam(gname)) && !isdigit((unsigned char)*gname))
856 1.54 simonb errx(1, "unknown gname %s", gname);
857 1.54 simonb return gp ? gp->gr_gid : atoi(gname);
858 1.54 simonb }
859 1.54 simonb
860 1.54 simonb static uid_t
861 1.54 simonb mfs_user(const char *uname)
862 1.54 simonb {
863 1.54 simonb struct passwd *pp;
864 1.54 simonb
865 1.54 simonb if (!(pp = getpwnam(uname)) && !isdigit((unsigned char)*uname))
866 1.54 simonb errx(1, "unknown user %s", uname);
867 1.54 simonb return pp ? pp->pw_uid : atoi(uname);
868 1.54 simonb }
869 1.54 simonb
870 1.43 lukem static int
871 1.43 lukem strsuftoi(const char *desc, const char *arg, int min, int max)
872 1.43 lukem {
873 1.43 lukem long long result;
874 1.43 lukem char *ep;
875 1.43 lukem
876 1.43 lukem errno = 0;
877 1.43 lukem result = strtoll(arg, &ep, 10);
878 1.43 lukem if (ep[0] != '\0' && ep[1] != '\0')
879 1.43 lukem errx(1, "%s `%s' is not a valid number.", desc, arg);
880 1.43 lukem switch (tolower((unsigned char)ep[0])) {
881 1.43 lukem case '\0':
882 1.43 lukem case 'b':
883 1.43 lukem break;
884 1.43 lukem case 'k':
885 1.43 lukem result <<= 10;
886 1.43 lukem break;
887 1.43 lukem case 'm':
888 1.43 lukem result <<= 20;
889 1.43 lukem break;
890 1.43 lukem case 'g':
891 1.43 lukem result <<= 30;
892 1.43 lukem break;
893 1.43 lukem default:
894 1.43 lukem errx(1, "`%s' is not a valid suffix for %s.", ep, desc);
895 1.43 lukem }
896 1.43 lukem if (result < min)
897 1.43 lukem errx(1, "%s `%s' (%lld) is less than minimum (%d).",
898 1.43 lukem desc, arg, result, min);
899 1.43 lukem if (result > max)
900 1.43 lukem errx(1, "%s `%s' (%lld) is greater than maximum (%d).",
901 1.43 lukem desc, arg, result, max);
902 1.43 lukem return ((int)result);
903 1.43 lukem }
904 1.43 lukem
905 1.54 simonb #define NEWFS 1
906 1.54 simonb #define MFS_MOUNT 2
907 1.54 simonb #define BOTH NEWFS | MFS_MOUNT
908 1.54 simonb
909 1.54 simonb struct help_strings {
910 1.54 simonb int flags;
911 1.54 simonb const char *str;
912 1.54 simonb } const help_strings[] = {
913 1.54 simonb { NEWFS, "-B byteorder\tbyte order (`be' or `le')" },
914 1.54 simonb { NEWFS, "-F \t\tcreate file system image in regular file" },
915 1.58 lukem { NEWFS, "-I \t\tdo not check that the file system type is '4.2BSD'" },
916 1.54 simonb { BOTH, "-N \t\tdo not create file system, just print out "
917 1.54 simonb "parameters" },
918 1.54 simonb { NEWFS, "-O \t\tcreate a 4.3BSD format filesystem" },
919 1.54 simonb { NEWFS, "-S secsize\tsector size" },
920 1.54 simonb #ifdef COMPAT
921 1.54 simonb { NEWFS, "-T disktype\tdisk type" },
922 1.54 simonb #endif
923 1.54 simonb { NEWFS, "-Z \t\tpre-zero the image file (with -F)" },
924 1.54 simonb { BOTH, "-a maxcontig\tmaximum contiguous blocks" },
925 1.54 simonb { BOTH, "-b bsize\tblock size" },
926 1.54 simonb { BOTH, "-c cpg\t\tcylinders/group" },
927 1.54 simonb { BOTH, "-d rotdelay\trotational delay between contiguous "
928 1.54 simonb "blocks" },
929 1.54 simonb { BOTH, "-e maxbpg\tmaximum blocks per file in a cylinder group"
930 1.54 simonb },
931 1.54 simonb { BOTH, "-f fsize\tfrag size" },
932 1.54 simonb { NEWFS, "-g avgfilesize\taverage file size" },
933 1.54 simonb { MFS_MOUNT, "-g groupname\tgroup name of mount point" },
934 1.54 simonb { BOTH, "-h avgfpdir\taverage files per directory" },
935 1.54 simonb { BOTH, "-i density\tnumber of bytes per inode" },
936 1.54 simonb { NEWFS, "-k trackskew\tsector 0 skew, per track" },
937 1.54 simonb { NEWFS, "-l interleave\thardware sector interleave" },
938 1.54 simonb { BOTH, "-m minfree\tminimum free space %%" },
939 1.54 simonb { NEWFS, "-n nrpos\tnumber of distinguished rotational "
940 1.54 simonb "positions" },
941 1.54 simonb { BOTH, "-o optim\toptimization preference (`space' or `time')"
942 1.54 simonb },
943 1.54 simonb { NEWFS, "-p tracksparse\tspare sectors per track" },
944 1.54 simonb { MFS_MOUNT, "-p perm\t\tpermissions (in octal)" },
945 1.54 simonb { BOTH, "-s fssize\tfile system size (sectors)" },
946 1.54 simonb { NEWFS, "-r rpm\t\trevolutions/minute" },
947 1.54 simonb { NEWFS, "-t ntracks\ttracks/cylinder" },
948 1.54 simonb { NEWFS, "-u nsectors\tsectors/track" },
949 1.54 simonb { MFS_MOUNT, "-u username\tuser name of mount point" },
950 1.61 dbj { NEWFS, "-v volname\tApple UFS volume name" },
951 1.54 simonb { NEWFS, "-x cylspares\tspare sectors per cylinder" },
952 1.54 simonb { 0, NULL }
953 1.54 simonb };
954 1.54 simonb
955 1.25 christos static void
956 1.40 simonb usage(void)
957 1.1 cgd {
958 1.54 simonb int match;
959 1.54 simonb const struct help_strings *hs;
960 1.43 lukem
961 1.1 cgd if (mfs) {
962 1.1 cgd fprintf(stderr,
963 1.43 lukem "usage: %s [ fsoptions ] special-device mount-point\n",
964 1.42 cgd getprogname());
965 1.1 cgd } else
966 1.1 cgd fprintf(stderr,
967 1.43 lukem "usage: %s [ fsoptions ] special-device%s\n",
968 1.42 cgd getprogname(),
969 1.1 cgd #ifdef COMPAT
970 1.1 cgd " [device-type]");
971 1.1 cgd #else
972 1.1 cgd "");
973 1.1 cgd #endif
974 1.1 cgd fprintf(stderr, "where fsoptions are:\n");
975 1.54 simonb
976 1.54 simonb match = mfs ? MFS_MOUNT : NEWFS;
977 1.54 simonb for (hs = help_strings; hs->flags != 0; hs++)
978 1.54 simonb if (hs->flags & match)
979 1.54 simonb fprintf(stderr, "\t%s\n", hs->str);
980 1.1 cgd exit(1);
981 1.1 cgd }
982