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