Commit | Line | Data |
---|---|---|
c018628f | 1 | /* |
ec7b02f7 KM |
2 | * Copyright (c) 1983, 1989 The Regents of the University of California. |
3 | * All rights reserved. | |
4 | * | |
70ab3c27 | 5 | * %sccs.include.redist.c% |
c018628f DF |
6 | */ |
7 | ||
8 | #ifndef lint | |
558b3a30 | 9 | static char sccsid[] = "@(#)newfs.c 6.29 (Berkeley) %G%"; |
ec7b02f7 | 10 | #endif /* not lint */ |
c018628f | 11 | |
a54c0b3f | 12 | #ifndef lint |
ec7b02f7 KM |
13 | char copyright[] = |
14 | "@(#) Copyright (c) 1983, 1989 Regents of the University of California.\n\ | |
15 | All rights reserved.\n"; | |
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 | |
a54c0b3f | 36 | #include <stdio.h> |
8485bb11 | 37 | #include <ctype.h> |
fcc01f65 KB |
38 | #include <string.h> |
39 | #include <stdlib.h> | |
7abf8d65 | 40 | #include <paths.h> |
a54c0b3f | 41 | |
e99c53de CT |
42 | #if __STDC__ |
43 | void fatal(const char *fmt, ...); | |
44 | #else | |
45 | void fatal(); | |
46 | #endif | |
47 | ||
fcc01f65 | 48 | #define COMPAT /* allow non-labeled disks */ |
f24e4d82 | 49 | |
8485bb11 KM |
50 | /* |
51 | * The following two constants set the default block and fragment sizes. | |
52 | * Both constants must be a power of 2 and meet the following constraints: | |
53 | * MINBSIZE <= DESBLKSIZE <= MAXBSIZE | |
54 | * sectorsize <= DESFRAGSIZE <= DESBLKSIZE | |
55 | * DESBLKSIZE / DESFRAGSIZE <= 8 | |
56 | */ | |
57 | #define DFL_FRAGSIZE 1024 | |
58 | #define DFL_BLKSIZE 8192 | |
59 | ||
60 | /* | |
38f1cd11 | 61 | * Cylinder groups may have up to many cylinders. The actual |
8485bb11 | 62 | * number used depends upon how much information can be stored |
38f1cd11 | 63 | * on a single cylinder. The default is to use 16 cylinders |
8485bb11 KM |
64 | * per group. |
65 | */ | |
66 | #define DESCPG 16 /* desired fs_cpg */ | |
89241117 | 67 | |
8485bb11 KM |
68 | /* |
69 | * MINFREE gives the minimum acceptable percentage of file system | |
70 | * blocks which may be free. If the freelist drops below this level | |
71 | * only the superuser may continue to allocate blocks. This may | |
72 | * be set to 0 if no reserve of free blocks is deemed necessary, | |
73 | * however throughput drops by fifty percent if the file system | |
74 | * is run at between 90% and 100% full; thus the default value of | |
75 | * fs_minfree is 10%. With 10% free space, fragmentation is not a | |
76 | * problem, so we choose to optimize for time. | |
77 | */ | |
78 | #define MINFREE 10 | |
79 | #define DEFAULTOPT FS_OPTTIME | |
80 | ||
81 | /* | |
82 | * ROTDELAY gives the minimum number of milliseconds to initiate | |
83 | * another disk transfer on the same cylinder. It is used in | |
84 | * determining the rotationally optimal layout for disk blocks | |
85 | * within a file; the default of fs_rotdelay is 4ms. | |
86 | */ | |
87 | #define ROTDELAY 4 | |
88 | ||
89 | /* | |
90 | * MAXCONTIG sets the default for the maximum number of blocks | |
91 | * that may be allocated sequentially. Since UNIX drivers are | |
92 | * not capable of scheduling multi-block transfers, this defaults | |
93 | * to 1 (ie no contiguous blocks are allocated). | |
94 | */ | |
95 | #define MAXCONTIG 1 | |
96 | ||
3d632f12 KM |
97 | /* |
98 | * MAXBLKPG determines the maximum number of data blocks which are | |
99 | * placed in a single cylinder group. The default is one indirect | |
100 | * block worth of data blocks. | |
101 | */ | |
102 | #define MAXBLKPG(bsize) ((bsize) / sizeof(daddr_t)) | |
103 | ||
8485bb11 KM |
104 | /* |
105 | * Each file system has a number of inodes statically allocated. | |
ec7b02f7 | 106 | * We allocate one inode slot per NFPI fragments, expecting this |
8485bb11 KM |
107 | * to be far more than we will ever need. |
108 | */ | |
ec7b02f7 | 109 | #define NFPI 4 |
8485bb11 | 110 | |
38f1cd11 KM |
111 | /* |
112 | * For each cylinder we keep track of the availability of blocks at different | |
113 | * rotational positions, so that we can lay out the data to be picked | |
114 | * up with minimum rotational latency. NRPOS is the default number of | |
115 | * rotational positions that we distinguish. With NRPOS of 8 the resolution | |
116 | * of our summary information is 2ms for a typical 3600 rpm drive. | |
117 | */ | |
118 | #define NRPOS 8 /* number distinct rotational positions */ | |
119 | ||
120 | ||
822f4068 | 121 | int mfs; /* run as the memory based filesystem */ |
8485bb11 | 122 | int Nflag; /* run without writing file system */ |
a54c0b3f | 123 | int fssize; /* file system size */ |
a54c0b3f SL |
124 | int ntracks; /* # tracks/cylinder */ |
125 | int nsectors; /* # sectors/track */ | |
a20edd44 | 126 | int nphyssectors; /* # sectors/track including spares */ |
8485bb11 | 127 | int secpercyl; /* sectors per cylinder */ |
a20edd44 KM |
128 | int trackspares = -1; /* spare sectors per track */ |
129 | int cylspares = -1; /* spare sectors per cylinder */ | |
a54c0b3f | 130 | int sectorsize; /* bytes/sector */ |
c5d3fd78 MK |
131 | #ifdef tahoe |
132 | int realsectorsize; /* bytes/sector in hardware */ | |
133 | #endif | |
c6003316 | 134 | int rpm; /* revolutions/minute of drive */ |
a20edd44 KM |
135 | int interleave; /* hardware sector interleave */ |
136 | int trackskew = -1; /* sector 0 skew, per track */ | |
137 | int headswitch; /* head switch time, usec */ | |
138 | int trackseek; /* track-to-track seek, usec */ | |
187d180d MK |
139 | int fsize = 0; /* fragment size */ |
140 | int bsize = 0; /* block size */ | |
8485bb11 | 141 | int cpg = DESCPG; /* cylinders/cylinder group */ |
f40b03d9 | 142 | int cpgflg; /* cylinders/cylinder group flag was given */ |
8485bb11 KM |
143 | int minfree = MINFREE; /* free space threshold */ |
144 | int opt = DEFAULTOPT; /* optimization preference (space or time) */ | |
ec7b02f7 | 145 | int density; /* number of bytes per inode */ |
8485bb11 KM |
146 | int maxcontig = MAXCONTIG; /* max contiguous blocks to allocate */ |
147 | int rotdelay = ROTDELAY; /* rotational delay between blocks */ | |
3d632f12 | 148 | int maxbpg; /* maximum blocks per file in a cyl group */ |
38f1cd11 | 149 | int nrpos = NRPOS; /* # of distinguished rotational positions */ |
c5d3fd78 MK |
150 | int bbsize = BBSIZE; /* boot block size */ |
151 | int sbsize = SBSIZE; /* superblock size */ | |
822f4068 | 152 | int mntflags; /* flags to be passed to mount */ |
ec7b02f7 KM |
153 | u_long memleft; /* virtual memory available */ |
154 | caddr_t membase; /* start address of memory based filesystem */ | |
f24e4d82 | 155 | #ifdef COMPAT |
894fc092 | 156 | char *disktype; |
fcc01f65 | 157 | int unlabeled; |
f24e4d82 | 158 | #endif |
8485bb11 | 159 | |
a54c0b3f | 160 | char device[MAXPATHLEN]; |
ec7b02f7 | 161 | char *progname; |
a54c0b3f | 162 | |
a54c0b3f | 163 | main(argc, argv) |
1b8b6e44 | 164 | int argc; |
a54c0b3f SL |
165 | char *argv[]; |
166 | { | |
fcc01f65 KB |
167 | extern char *optarg; |
168 | extern int optind; | |
169 | register int ch; | |
a54c0b3f | 170 | register struct partition *pp; |
8485bb11 KM |
171 | register struct disklabel *lp; |
172 | struct disklabel *getdisklabel(); | |
173 | struct partition oldpartition; | |
a54c0b3f | 174 | struct stat st; |
8485bb11 | 175 | int fsi, fso; |
fcc01f65 | 176 | char *cp, *special, *opstring, buf[BUFSIZ]; |
a54c0b3f | 177 | |
fcc01f65 KB |
178 | if (progname = rindex(*argv, '/')) |
179 | ++progname; | |
180 | else | |
ec7b02f7 | 181 | progname = *argv; |
fcc01f65 | 182 | |
6bab0c78 | 183 | if (strstr(progname, "mfs")) { |
fcc01f65 | 184 | mfs = 1; |
ec7b02f7 | 185 | Nflag++; |
ec7b02f7 | 186 | } |
a54c0b3f | 187 | |
fcc01f65 KB |
188 | opstring = "F:NS:T:a:b:c:d:e:f:i:k:l:m:n:o:p:r:s:t:u:x:"; |
189 | if (!mfs) | |
190 | opstring += 2; /* -F is mfs only */ | |
191 | ||
192 | while ((ch = getopt(argc, argv, opstring)) != EOF) | |
193 | switch(ch) { | |
194 | case 'F': | |
195 | if ((mntflags = atoi(optarg)) == 0) | |
196 | fatal("%s: bad mount flags", optarg); | |
197 | break; | |
198 | case 'N': | |
199 | Nflag++; | |
200 | break; | |
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 | ||
300 | if (argc != 2 && (mfs || argc != 1)) | |
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 | } | |
8485bb11 KM |
314 | if (!Nflag) { |
315 | fso = open(special, O_WRONLY); | |
fcc01f65 KB |
316 | if (fso < 0) |
317 | fatal("%s: %s", special, strerror(errno)); | |
8485bb11 KM |
318 | } else |
319 | fso = -1; | |
320 | fsi = open(special, O_RDONLY); | |
fcc01f65 KB |
321 | if (fsi < 0) |
322 | fatal("%s: %s", special, strerror(errno)); | |
323 | if (fstat(fsi, &st) < 0) | |
324 | fatal("%s: %s", special, strerror(errno)); | |
ea6170ef MK |
325 | if ((st.st_mode & S_IFMT) != S_IFCHR && !mfs) |
326 | printf("%s: %s: not a character-special device\n", | |
327 | progname, special); | |
a54c0b3f | 328 | cp = index(argv[0], '\0') - 1; |
8485bb11 | 329 | if (cp == 0 || (*cp < 'a' || *cp > 'h') && !isdigit(*cp)) |
a54c0b3f | 330 | fatal("%s: can't figure out file system partition", argv[0]); |
f24e4d82 | 331 | #ifdef COMPAT |
894fc092 KM |
332 | if (!mfs && disktype == NULL) |
333 | disktype = argv[1]; | |
f24e4d82 | 334 | #endif |
894fc092 | 335 | lp = getdisklabel(special, fsi); |
8485bb11 KM |
336 | if (isdigit(*cp)) |
337 | pp = &lp->d_partitions[0]; | |
338 | else | |
339 | pp = &lp->d_partitions[*cp - 'a']; | |
340 | if (pp->p_size == 0) | |
341 | fatal("%s: `%c' partition is unavailable", argv[0], *cp); | |
342 | if (fssize == 0) | |
a54c0b3f | 343 | fssize = pp->p_size; |
822f4068 | 344 | if (fssize > pp->p_size && !mfs) |
8485bb11 KM |
345 | fatal("%s: maximum file system size on the `%c' partition is %d", |
346 | argv[0], *cp, pp->p_size); | |
347 | if (rpm == 0) { | |
348 | rpm = lp->d_rpm; | |
349 | if (rpm <= 0) | |
6181c540 | 350 | rpm = 3600; |
a54c0b3f SL |
351 | } |
352 | if (ntracks == 0) { | |
8485bb11 KM |
353 | ntracks = lp->d_ntracks; |
354 | if (ntracks <= 0) | |
6181c540 | 355 | fatal("%s: no default #tracks", argv[0]); |
a54c0b3f | 356 | } |
8485bb11 KM |
357 | if (nsectors == 0) { |
358 | nsectors = lp->d_nsectors; | |
359 | if (nsectors <= 0) | |
6181c540 | 360 | fatal("%s: no default #sectors/track", argv[0]); |
8485bb11 | 361 | } |
a54c0b3f | 362 | if (sectorsize == 0) { |
8485bb11 KM |
363 | sectorsize = lp->d_secsize; |
364 | if (sectorsize <= 0) | |
6181c540 | 365 | fatal("%s: no default sector size", argv[0]); |
a54c0b3f | 366 | } |
a20edd44 KM |
367 | if (trackskew == -1) { |
368 | trackskew = lp->d_trackskew; | |
369 | if (trackskew < 0) | |
6181c540 | 370 | trackskew = 0; |
a20edd44 KM |
371 | } |
372 | if (interleave == 0) { | |
373 | interleave = lp->d_interleave; | |
374 | if (interleave <= 0) | |
6181c540 | 375 | interleave = 1; |
a20edd44 | 376 | } |
a54c0b3f SL |
377 | if (fsize == 0) { |
378 | fsize = pp->p_fsize; | |
8485bb11 KM |
379 | if (fsize <= 0) |
380 | fsize = MAX(DFL_FRAGSIZE, lp->d_secsize); | |
a54c0b3f | 381 | } |
8485bb11 KM |
382 | if (bsize == 0) { |
383 | bsize = pp->p_frag * pp->p_fsize; | |
384 | if (bsize <= 0) | |
385 | bsize = MIN(DFL_BLKSIZE, 8 * fsize); | |
c6003316 | 386 | } |
ec7b02f7 KM |
387 | if (density == 0) |
388 | density = NFPI * fsize; | |
75e589fc | 389 | if (minfree < 10 && opt != FS_OPTSPACE) { |
8485bb11 KM |
390 | fprintf(stderr, "Warning: changing optimization to space "); |
391 | fprintf(stderr, "because minfree is less than 10%%\n"); | |
75e589fc KM |
392 | opt = FS_OPTSPACE; |
393 | } | |
a20edd44 KM |
394 | if (trackspares == -1) { |
395 | trackspares = lp->d_sparespertrack; | |
396 | if (trackspares < 0) | |
6181c540 | 397 | trackspares = 0; |
a20edd44 KM |
398 | } |
399 | nphyssectors = nsectors + trackspares; | |
400 | if (cylspares == -1) { | |
401 | cylspares = lp->d_sparespercyl; | |
402 | if (cylspares < 0) | |
6181c540 | 403 | cylspares = 0; |
a20edd44 KM |
404 | } |
405 | secpercyl = nsectors * ntracks - cylspares; | |
8485bb11 | 406 | if (secpercyl != lp->d_secpercyl) |
fcc01f65 | 407 | fprintf(stderr, "%s (%d) %s (%lu)\n", |
8485bb11 KM |
408 | "Warning: calculated sectors per cylinder", secpercyl, |
409 | "disagrees with disk label", lp->d_secpercyl); | |
c9b3f9df KM |
410 | if (maxbpg == 0) |
411 | maxbpg = MAXBLKPG(bsize); | |
a20edd44 KM |
412 | headswitch = lp->d_headswitch; |
413 | trackseek = lp->d_trkseek; | |
e1b3345a KB |
414 | /* Reno fix: label may be 0 if faked up by kernel */ |
415 | #ifdef notdef | |
756884f0 | 416 | #ifdef notdef /* label may be 0 if faked up by kernel */ |
c5d3fd78 MK |
417 | bbsize = lp->d_bbsize; |
418 | sbsize = lp->d_sbsize; | |
e1b3345a | 419 | #endif |
756884f0 | 420 | #endif |
8485bb11 | 421 | oldpartition = *pp; |
c5d3fd78 MK |
422 | #ifdef tahoe |
423 | realsectorsize = sectorsize; | |
187d180d | 424 | if (sectorsize != DEV_BSIZE) { /* XXX */ |
c5d3fd78 MK |
425 | int secperblk = DEV_BSIZE / sectorsize; |
426 | ||
427 | sectorsize = DEV_BSIZE; | |
428 | nsectors /= secperblk; | |
429 | nphyssectors /= secperblk; | |
430 | secpercyl /= secperblk; | |
431 | fssize /= secperblk; | |
432 | pp->p_size /= secperblk; | |
433 | } | |
434 | #endif | |
8485bb11 | 435 | mkfs(pp, special, fsi, fso); |
c5d3fd78 MK |
436 | #ifdef tahoe |
437 | if (realsectorsize != DEV_BSIZE) | |
438 | pp->p_size *= DEV_BSIZE / realsectorsize; | |
439 | #endif | |
8485bb11 KM |
440 | if (!Nflag && bcmp(pp, &oldpartition, sizeof(oldpartition))) |
441 | rewritelabel(special, fso, lp); | |
ec7b02f7 KM |
442 | if (!Nflag) |
443 | close(fso); | |
444 | close(fsi); | |
5358b44e | 445 | #ifdef MFS |
822f4068 | 446 | if (mfs) { |
5358b44e KB |
447 | struct mfs_args args; |
448 | ||
822f4068 | 449 | sprintf(buf, "mfs:%d", getpid()); |
ec7b02f7 KM |
450 | args.name = buf; |
451 | args.base = membase; | |
452 | args.size = fssize * sectorsize; | |
fcc01f65 KB |
453 | if (mount(MOUNT_MFS, argv[1], mntflags, &args) < 0) |
454 | fatal("%s: %s", argv[1], strerror(errno)); | |
ec7b02f7 | 455 | } |
5358b44e | 456 | #endif |
a54c0b3f SL |
457 | exit(0); |
458 | } | |
459 | ||
f24e4d82 | 460 | #ifdef COMPAT |
894fc092 | 461 | char lmsg[] = "%s: can't read disk label; disk type must be specified"; |
f24e4d82 | 462 | #else |
894fc092 KM |
463 | char lmsg[] = "%s: can't read disk label"; |
464 | #endif | |
465 | ||
8485bb11 KM |
466 | struct disklabel * |
467 | getdisklabel(s, fd) | |
468 | char *s; | |
f24e4d82 | 469 | int fd; |
a54c0b3f | 470 | { |
8485bb11 KM |
471 | static struct disklabel lab; |
472 | ||
473 | if (ioctl(fd, DIOCGDINFO, (char *)&lab) < 0) { | |
894fc092 KM |
474 | #ifdef COMPAT |
475 | if (disktype) { | |
756884f0 | 476 | struct disklabel *lp, *getdiskbyname(); |
894fc092 | 477 | |
fcc01f65 | 478 | unlabeled++; |
756884f0 MK |
479 | lp = getdiskbyname(disktype); |
480 | if (lp == NULL) | |
481 | fatal("%s: unknown disk type", disktype); | |
482 | return (lp); | |
894fc092 KM |
483 | } |
484 | #endif | |
fcc01f65 KB |
485 | (void)fprintf(stderr, |
486 | "%s: ioctl (GDINFO): %s\n", progname, strerror(errno)); | |
894fc092 | 487 | fatal(lmsg, s); |
8485bb11 KM |
488 | } |
489 | return (&lab); | |
490 | } | |
491 | ||
492 | rewritelabel(s, fd, lp) | |
493 | char *s; | |
a54c0b3f | 494 | int fd; |
8485bb11 KM |
495 | register struct disklabel *lp; |
496 | { | |
f24e4d82 | 497 | #ifdef COMPAT |
fcc01f65 | 498 | if (unlabeled) |
f24e4d82 MK |
499 | return; |
500 | #endif | |
8485bb11 KM |
501 | lp->d_checksum = 0; |
502 | lp->d_checksum = dkcksum(lp); | |
503 | if (ioctl(fd, DIOCWDINFO, (char *)lp) < 0) { | |
fcc01f65 KB |
504 | (void)fprintf(stderr, |
505 | "%s: ioctl (WDINFO): %s\n", progname, strerror(errno)); | |
8485bb11 | 506 | fatal("%s: can't rewrite disk label", s); |
a54c0b3f | 507 | } |
bf8f0524 MK |
508 | #if vax |
509 | if (lp->d_type == DTYPE_SMD && lp->d_flags & D_BADSECT) { | |
510 | register i; | |
c5d3fd78 | 511 | int cfd; |
bf8f0524 | 512 | daddr_t alt; |
c5d3fd78 MK |
513 | char specname[64]; |
514 | char blk[1024]; | |
866736b4 | 515 | char *cp; |
c5d3fd78 MK |
516 | |
517 | /* | |
518 | * Make name for 'c' partition. | |
519 | */ | |
520 | strcpy(specname, s); | |
521 | cp = specname + strlen(specname) - 1; | |
522 | if (!isdigit(*cp)) | |
523 | *cp = 'c'; | |
524 | cfd = open(specname, O_WRONLY); | |
fcc01f65 KB |
525 | if (cfd < 0) |
526 | fatal("%s: %s", specname, strerror(errno)); | |
c5d3fd78 MK |
527 | bzero(blk, sizeof(blk)); |
528 | *(struct disklabel *)(blk + LABELOFFSET) = *lp; | |
bf8f0524 MK |
529 | alt = lp->d_ncylinders * lp->d_secpercyl - lp->d_nsectors; |
530 | for (i = 1; i < 11 && i < lp->d_nsectors; i += 2) { | |
756884f0 MK |
531 | if (lseek(cfd, (off_t)(alt + i) * lp->d_secsize, |
532 | L_SET) == -1) | |
fcc01f65 KB |
533 | fatal("lseek to badsector area: %s", |
534 | strerror(errno)); | |
535 | if (write(cfd, blk, lp->d_secsize) < lp->d_secsize) | |
536 | fprintf(stderr, | |
537 | "%s: alternate label %d write: %s\n", | |
538 | progname, i/2, strerror(errno)); | |
8485bb11 | 539 | } |
ec7b02f7 | 540 | close(cfd); |
8485bb11 | 541 | } |
bf8f0524 | 542 | #endif |
a54c0b3f SL |
543 | } |
544 | ||
545 | /*VARARGS*/ | |
e99c53de CT |
546 | void |
547 | #if __STDC__ | |
548 | fatal(const char *fmt, ...) | |
549 | #else | |
550 | fatal(fmt, va_alist) | |
a54c0b3f | 551 | char *fmt; |
e99c53de CT |
552 | va_dcl |
553 | #endif | |
a54c0b3f | 554 | { |
fcc01f65 | 555 | va_list ap; |
a54c0b3f | 556 | |
e99c53de | 557 | #if __STDC__ |
fcc01f65 | 558 | va_start(ap, fmt); |
e99c53de CT |
559 | #else |
560 | va_start(ap); | |
561 | #endif | |
562 | fprintf(stderr, "%s: ", progname); | |
fcc01f65 KB |
563 | (void)vfprintf(stderr, fmt, ap); |
564 | va_end(ap); | |
a54c0b3f | 565 | putc('\n', stderr); |
fcc01f65 KB |
566 | exit(1); |
567 | } | |
568 | ||
569 | usage() | |
570 | { | |
571 | if (mfs) { | |
572 | fprintf(stderr, | |
573 | "usage: mfs [ -fsoptions ] special-device mount-point\n"); | |
574 | } else | |
575 | fprintf(stderr, | |
576 | "usage: newfs [ -fsoptions ] special-device%s\n", | |
577 | #ifdef COMPAT | |
578 | " [device-type]"); | |
579 | #else | |
580 | ""); | |
581 | #endif | |
582 | fprintf(stderr, "where fsoptions are:\n"); | |
583 | fprintf(stderr, | |
584 | "\t-N do not create file system, just print out parameters\n"); | |
585 | fprintf(stderr, "\t-S sector size\n"); | |
586 | #ifdef COMPAT | |
587 | fprintf(stderr, "\t-T disktype\n"); | |
588 | #endif | |
589 | fprintf(stderr, "\t-a maximum contiguous blocks\n"); | |
590 | fprintf(stderr, "\t-b block size\n"); | |
591 | fprintf(stderr, "\t-c cylinders/group\n"); | |
592 | fprintf(stderr, "\t-d rotational delay between contiguous blocks\n"); | |
593 | fprintf(stderr, "\t-e maximum blocks per file in a cylinder group\n"); | |
594 | fprintf(stderr, "\t-f frag size\n"); | |
595 | fprintf(stderr, "\t-i number of bytes per inode\n"); | |
596 | fprintf(stderr, "\t-k sector 0 skew, per track\n"); | |
597 | fprintf(stderr, "\t-l hardware sector interleave\n"); | |
598 | fprintf(stderr, "\t-m minimum free space %%\n"); | |
599 | fprintf(stderr, "\t-n number of distinguished rotational positions\n"); | |
600 | fprintf(stderr, "\t-o optimization preference (`space' or `time')\n"); | |
601 | fprintf(stderr, "\t-p spare sectors per track\n"); | |
602 | fprintf(stderr, "\t-s file system size (sectors)\n"); | |
603 | fprintf(stderr, "\t-r revolutions/minute\n"); | |
604 | fprintf(stderr, "\t-t tracks/cylinder\n"); | |
605 | fprintf(stderr, "\t-u sectors/track\n"); | |
606 | fprintf(stderr, "\t-x spare sectors per cylinder\n"); | |
607 | exit(1); | |
a54c0b3f | 608 | } |