Commit | Line | Data |
---|---|---|
76797561 | 1 | /* |
fe32782c KM |
2 | * Copyright (c) 1980, 1986 The Regents of the University of California. |
3 | * All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms are permitted | |
6 | * provided that the above copyright notice and this paragraph are | |
7 | * duplicated in all such forms and that any documentation, | |
8 | * advertising materials, and other materials related to such | |
9 | * distribution and use acknowledge that the software was developed | |
10 | * by the University of California, Berkeley. The name of the | |
11 | * University may not be used to endorse or promote products derived | |
12 | * from this software without specific prior written permission. | |
13 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
14 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
15 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
76797561 DF |
16 | */ |
17 | ||
eb93b62a | 18 | #ifndef lint |
a5880917 | 19 | static char sccsid[] = "@(#)setup.c 5.26 (Berkeley) %G%"; |
fe32782c | 20 | #endif /* not lint */ |
eb93b62a | 21 | |
c7aed003 | 22 | #define DKTYPENAMES |
eb93b62a | 23 | #include <sys/param.h> |
72e5286b | 24 | #include <ufs/dinode.h> |
5c175a19 | 25 | #include <ufs/fs.h> |
eb93b62a | 26 | #include <sys/stat.h> |
c7aed003 KM |
27 | #include <sys/ioctl.h> |
28 | #include <sys/disklabel.h> | |
29 | #include <sys/file.h> | |
7beeecfc | 30 | #include <machine/endian.h> |
c7aed003 | 31 | #include <ctype.h> |
eb93b62a KM |
32 | #include "fsck.h" |
33 | ||
569ec282 | 34 | struct bufarea asblk; |
adc5a10c | 35 | #define altsblock (*asblk.b_un.b_fs) |
c7aed003 KM |
36 | #define POWEROF2(num) (((num) & ((num) - 1)) == 0) |
37 | ||
be894f48 KM |
38 | /* |
39 | * The size of a cylinder group is calculated by CGSIZE. The maximum size | |
40 | * is limited by the fact that cylinder groups are at most one block. | |
41 | * Its size is derived from the size of the maps maintained in the | |
42 | * cylinder group and the (struct cg) size. | |
43 | */ | |
44 | #define CGSIZE(fs) \ | |
45 | /* base cg */ (sizeof(struct cg) + \ | |
46 | /* blktot size */ (fs)->fs_cpg * sizeof(long) + \ | |
47 | /* blks size */ (fs)->fs_cpg * (fs)->fs_nrpos * sizeof(short) + \ | |
48 | /* inode map */ howmany((fs)->fs_ipg, NBBY) + \ | |
49 | /* block map */ howmany((fs)->fs_cpg * (fs)->fs_spc / NSPF(fs), NBBY)) | |
50 | ||
d35d4c2b | 51 | char *malloc(), *calloc(); |
c7aed003 | 52 | char *index(); |
d35d4c2b | 53 | struct disklabel *getdisklabel(); |
eb93b62a KM |
54 | |
55 | setup(dev) | |
56 | char *dev; | |
57 | { | |
58 | dev_t rootdev; | |
569ec282 KM |
59 | long cg, size, asked, i, j; |
60 | long bmapsize; | |
d35d4c2b | 61 | struct disklabel *lp; |
eb93b62a | 62 | struct stat statb; |
c7aed003 | 63 | struct fs proto; |
eb93b62a | 64 | |
55f8bbd7 | 65 | havesb = 0; |
eb93b62a KM |
66 | if (stat("/", &statb) < 0) |
67 | errexit("Can't stat root\n"); | |
68 | rootdev = statb.st_dev; | |
69 | if (stat(dev, &statb) < 0) { | |
cfbff64d | 70 | perror(dev); |
7718c0e6 | 71 | printf("Can't stat %s\n", dev); |
eb93b62a KM |
72 | return (0); |
73 | } | |
569ec282 KM |
74 | if ((statb.st_mode & S_IFMT) != S_IFBLK && |
75 | (statb.st_mode & S_IFMT) != S_IFCHR && | |
76 | reply("file is not a block or character device; OK") == 0) | |
77 | return (0); | |
eb93b62a KM |
78 | if (rootdev == statb.st_rdev) |
79 | hotroot++; | |
569ec282 | 80 | if ((fsreadfd = open(dev, O_RDONLY)) < 0) { |
cfbff64d | 81 | perror(dev); |
7718c0e6 | 82 | printf("Can't open %s\n", dev); |
eb93b62a KM |
83 | return (0); |
84 | } | |
85 | if (preen == 0) | |
86 | printf("** %s", dev); | |
569ec282 KM |
87 | if (nflag || (fswritefd = open(dev, O_WRONLY)) < 0) { |
88 | fswritefd = -1; | |
eb93b62a KM |
89 | if (preen) |
90 | pfatal("NO WRITE ACCESS"); | |
91 | printf(" (NO WRITE)"); | |
92 | } | |
93 | if (preen == 0) | |
94 | printf("\n"); | |
569ec282 | 95 | fsmodified = 0; |
eb93b62a | 96 | lfdir = 0; |
eb93b62a | 97 | initbarea(&sblk); |
7beeecfc | 98 | initbarea(&asblk); |
d35d4c2b KM |
99 | sblk.b_un.b_buf = malloc(SBSIZE); |
100 | asblk.b_un.b_buf = malloc(SBSIZE); | |
101 | if (sblk.b_un.b_buf == NULL || asblk.b_un.b_buf == NULL) | |
adc5a10c | 102 | errexit("cannot allocate space for superblock\n"); |
569ec282 | 103 | if (lp = getdisklabel((char *)NULL, fsreadfd)) |
55f8bbd7 | 104 | dev_bsize = secsize = lp->d_secsize; |
7beeecfc KM |
105 | else |
106 | dev_bsize = secsize = DEV_BSIZE; | |
eb93b62a | 107 | /* |
c7aed003 | 108 | * Read in the superblock, looking for alternates if necessary |
eb93b62a | 109 | */ |
c7aed003 | 110 | if (readsb(1) == 0) { |
569ec282 | 111 | if (bflag || preen || calcsb(dev, fsreadfd, &proto) == 0) |
c7aed003 KM |
112 | return(0); |
113 | if (reply("LOOK FOR ALTERNATE SUPERBLOCKS") == 0) | |
114 | return (0); | |
115 | for (cg = 0; cg < proto.fs_ncg; cg++) { | |
116 | bflag = fsbtodb(&proto, cgsblock(&proto, cg)); | |
117 | if (readsb(0) != 0) | |
118 | break; | |
119 | } | |
120 | if (cg >= proto.fs_ncg) { | |
121 | printf("%s %s\n%s %s\n%s %s\n", | |
122 | "SEARCH FOR ALTERNATE SUPER-BLOCK", | |
123 | "FAILED. YOU MUST USE THE", | |
124 | "-b OPTION TO FSCK TO SPECIFY THE", | |
125 | "LOCATION OF AN ALTERNATE", | |
126 | "SUPER-BLOCK TO SUPPLY NEEDED", | |
127 | "INFORMATION; SEE fsck(8)."); | |
128 | return(0); | |
129 | } | |
130 | pwarn("USING ALTERNATE SUPERBLOCK AT %d\n", bflag); | |
131 | } | |
569ec282 KM |
132 | maxfsblock = sblock.fs_size; |
133 | maxino = sblock.fs_ncg * sblock.fs_ipg; | |
d9f38d60 KM |
134 | /* |
135 | * Check and potentially fix certain fields in the super block. | |
136 | */ | |
137 | if (sblock.fs_optim != FS_OPTTIME && sblock.fs_optim != FS_OPTSPACE) { | |
138 | pfatal("UNDEFINED OPTIMIZATION IN SUPERBLOCK"); | |
139 | if (reply("SET TO DEFAULT") == 1) { | |
140 | sblock.fs_optim = FS_OPTTIME; | |
141 | sbdirty(); | |
142 | } | |
143 | } | |
144 | if ((sblock.fs_minfree < 0 || sblock.fs_minfree > 99)) { | |
145 | pfatal("IMPOSSIBLE MINFREE=%d IN SUPERBLOCK", | |
146 | sblock.fs_minfree); | |
147 | if (reply("SET TO DEFAULT") == 1) { | |
148 | sblock.fs_minfree = 10; | |
149 | sbdirty(); | |
150 | } | |
151 | } | |
d4af1a46 | 152 | if (sblock.fs_interleave < 1) { |
d4af1a46 | 153 | sblock.fs_interleave); |
43171015 | 154 | sblock.fs_interleave = 1; |
d4af1a46 | 155 | sbdirty(); |
7beeecfc KM |
156 | dirty(&asblk); |
157 | } | |
d4af1a46 KM |
158 | } |
159 | if (sblock.fs_npsect < sblock.fs_nsect) { | |
d4af1a46 | 160 | sblock.fs_npsect); |
43171015 | 161 | sblock.fs_npsect = sblock.fs_nsect; |
d4af1a46 | 162 | sbdirty(); |
7beeecfc KM |
163 | dirty(&asblk); |
164 | } | |
165 | } | |
a747b5d4 KM |
166 | if (cvtflag) { |
167 | if (sblock.fs_postblformat == FS_42POSTBLFMT) { | |
168 | /* | |
169 | * Requested to convert from old format to new format | |
170 | */ | |
171 | if (preen) | |
172 | pwarn("CONVERTING TO NEW FILE SYSTEM FORMAT\n"); | |
173 | else if (!reply("CONVERT TO NEW FILE SYSTEM FORMAT")) | |
174 | return(0); | |
7beeecfc KM |
175 | sblock.fs_postblformat = FS_DYNAMICPOSTBLFMT; |
176 | sblock.fs_nrpos = 8; | |
177 | sblock.fs_postbloff = | |
178 | (char *)(&sblock.fs_opostbl[0][0]) - | |
179 | (char *)(&sblock.fs_link); | |
180 | sblock.fs_rotbloff = &sblock.fs_space[0] - | |
181 | (u_char *)(&sblock.fs_link); | |
be894f48 KM |
182 | sblock.fs_cgsize = |
183 | fragroundup(&sblock, CGSIZE(&sblock)); | |
7beeecfc KM |
184 | /* |
185 | * Planning now for future expansion. | |
186 | */ | |
187 | # if (BYTE_ORDER == BIG_ENDIAN) | |
188 | sblock.fs_qbmask.val[0] = 0; | |
189 | sblock.fs_qbmask.val[1] = ~sblock.fs_bmask; | |
190 | sblock.fs_qfmask.val[0] = 0; | |
191 | sblock.fs_qfmask.val[1] = ~sblock.fs_fmask; | |
192 | # endif /* BIG_ENDIAN */ | |
193 | # if (BYTE_ORDER == LITTLE_ENDIAN) | |
194 | sblock.fs_qbmask.val[0] = ~sblock.fs_bmask; | |
195 | sblock.fs_qbmask.val[1] = 0; | |
196 | sblock.fs_qfmask.val[0] = ~sblock.fs_fmask; | |
197 | sblock.fs_qfmask.val[1] = 0; | |
198 | # endif /* LITTLE_ENDIAN */ | |
199 | sbdirty(); | |
200 | dirty(&asblk); | |
a747b5d4 KM |
201 | } else if (sblock.fs_postblformat == FS_DYNAMICPOSTBLFMT) { |
202 | /* | |
203 | * Requested to convert from new format to old format | |
204 | */ | |
205 | if (sblock.fs_nrpos != 8 || sblock.fs_ipg > 2048 || | |
206 | sblock.fs_cpg > 32 || sblock.fs_cpc > 16) { | |
207 | printf( | |
208 | "PARAMETERS OF CURRENT FILE SYSTEM DO NOT\n\t"); | |
209 | errexit( | |
210 | "ALLOW CONVERSION TO OLD FILE SYSTEM FORMAT\n"); | |
211 | } | |
212 | if (preen) | |
213 | pwarn("CONVERTING TO OLD FILE SYSTEM FORMAT\n"); | |
214 | else if (!reply("CONVERT TO OLD FILE SYSTEM FORMAT")) | |
215 | return(0); | |
216 | sblock.fs_postblformat = FS_42POSTBLFMT; | |
be894f48 KM |
217 | sblock.fs_cgsize = fragroundup(&sblock, |
218 | sizeof(struct ocg) + howmany(sblock.fs_fpg, NBBY)); | |
a747b5d4 KM |
219 | sbdirty(); |
220 | dirty(&asblk); | |
221 | } else { | |
222 | errexit("UNKNOWN FILE SYSTEM FORMAT\n"); | |
7beeecfc | 223 | } |
7beeecfc KM |
224 | } |
225 | if (asblk.b_dirty) { | |
569ec282 KM |
226 | bcopy((char *)&sblock, (char *)&altsblock, |
227 | (int)sblock.fs_sbsize); | |
228 | flush(fswritefd, &asblk); | |
d4af1a46 | 229 | } |
eb93b62a KM |
230 | /* |
231 | * read in the summary info. | |
232 | */ | |
05d069d3 | 233 | asked = 0; |
eb93b62a KM |
234 | for (i = 0, j = 0; i < sblock.fs_cssize; i += sblock.fs_bsize, j++) { |
235 | size = sblock.fs_cssize - i < sblock.fs_bsize ? | |
236 | sblock.fs_cssize - i : sblock.fs_bsize; | |
237 | sblock.fs_csp[j] = (struct csum *)calloc(1, (unsigned)size); | |
569ec282 | 238 | if (bread(fsreadfd, (char *)sblock.fs_csp[j], |
eb93b62a | 239 | fsbtodb(&sblock, sblock.fs_csaddr + j * sblock.fs_frag), |
05d069d3 KM |
240 | size) != 0 && !asked) { |
241 | pfatal("BAD SUMMARY INFORMATION"); | |
242 | if (reply("CONTINUE") == 0) | |
243 | errexit(""); | |
244 | asked++; | |
245 | } | |
eb93b62a KM |
246 | } |
247 | /* | |
248 | * allocate and initialize the necessary maps | |
249 | */ | |
569ec282 KM |
250 | bmapsize = roundup(howmany(maxfsblock, NBBY), sizeof(short)); |
251 | blockmap = calloc((unsigned)bmapsize, sizeof (char)); | |
eb93b62a | 252 | if (blockmap == NULL) { |
569ec282 | 253 | printf("cannot alloc %d bytes for blockmap\n", bmapsize); |
eb93b62a KM |
254 | goto badsb; |
255 | } | |
569ec282 | 256 | statemap = calloc((unsigned)(maxino + 1), sizeof(char)); |
eb93b62a | 257 | if (statemap == NULL) { |
569ec282 | 258 | printf("cannot alloc %d bytes for statemap\n", maxino + 1); |
eb93b62a KM |
259 | goto badsb; |
260 | } | |
569ec282 | 261 | lncntp = (short *)calloc((unsigned)(maxino + 1), sizeof(short)); |
eb93b62a KM |
262 | if (lncntp == NULL) { |
263 | printf("cannot alloc %d bytes for lncntp\n", | |
569ec282 | 264 | (maxino + 1) * sizeof(short)); |
eb93b62a KM |
265 | goto badsb; |
266 | } | |
a5880917 KM |
267 | numdirs = sblock.fs_cstotal.cs_ndir; |
268 | listmax = numdirs + 10; | |
269 | inpsort = (struct inoinfo **)calloc((unsigned)listmax, | |
270 | sizeof(struct inoinfo *)); | |
271 | inphead = (struct inoinfo **)calloc((unsigned)numdirs, | |
272 | sizeof(struct inoinfo *)); | |
273 | if (inpsort == NULL || inphead == NULL) { | |
274 | printf("cannot alloc %d bytes for inphead\n", | |
275 | numdirs * sizeof(struct inoinfo *)); | |
276 | goto badsb; | |
277 | } | |
adc5a10c | 278 | bufinit(); |
eb93b62a KM |
279 | return (1); |
280 | ||
281 | badsb: | |
282 | ckfini(); | |
283 | return (0); | |
c7aed003 KM |
284 | } |
285 | ||
286 | /* | |
287 | * Read in the super block and its summary info. | |
288 | */ | |
289 | readsb(listerr) | |
290 | int listerr; | |
291 | { | |
55f8bbd7 | 292 | daddr_t super = bflag ? bflag : SBOFF / dev_bsize; |
c7aed003 | 293 | |
569ec282 | 294 | if (bread(fsreadfd, (char *)&sblock, super, (long)SBSIZE) != 0) |
c7aed003 KM |
295 | return (0); |
296 | sblk.b_bno = super; | |
297 | sblk.b_size = SBSIZE; | |
298 | /* | |
299 | * run a few consistency checks of the super block | |
300 | */ | |
301 | if (sblock.fs_magic != FS_MAGIC) | |
302 | { badsb(listerr, "MAGIC NUMBER WRONG"); return (0); } | |
303 | if (sblock.fs_ncg < 1) | |
304 | { badsb(listerr, "NCG OUT OF RANGE"); return (0); } | |
7beeecfc | 305 | if (sblock.fs_cpg < 1) |
c7aed003 KM |
306 | { badsb(listerr, "CPG OUT OF RANGE"); return (0); } |
307 | if (sblock.fs_ncg * sblock.fs_cpg < sblock.fs_ncyl || | |
308 | (sblock.fs_ncg - 1) * sblock.fs_cpg >= sblock.fs_ncyl) | |
309 | { badsb(listerr, "NCYL LESS THAN NCG*CPG"); return (0); } | |
310 | if (sblock.fs_sbsize > SBSIZE) | |
311 | { badsb(listerr, "SIZE PREPOSTEROUSLY LARGE"); return (0); } | |
55f8bbd7 MK |
312 | /* |
313 | * Compute block size that the filesystem is based on, | |
314 | * according to fsbtodb, and adjust superblock block number | |
315 | * so we can tell if this is an alternate later. | |
316 | */ | |
55f8bbd7 MK |
317 | super *= dev_bsize; |
318 | dev_bsize = sblock.fs_fsize / fsbtodb(&sblock, 1); | |
319 | sblk.b_bno = super / dev_bsize; | |
c7aed003 KM |
320 | /* |
321 | * Set all possible fields that could differ, then do check | |
322 | * of whole super block against an alternate super block. | |
323 | * When an alternate super-block is specified this check is skipped. | |
324 | */ | |
7beeecfc | 325 | getblk(&asblk, cgsblock(&sblock, sblock.fs_ncg - 1), sblock.fs_sbsize); |
d35d4c2b | 326 | if (asblk.b_errs) |
7beeecfc | 327 | return (0); |
55f8bbd7 MK |
328 | if (bflag) { |
329 | havesb = 1; | |
c7aed003 | 330 | return (1); |
55f8bbd7 | 331 | } |
c7aed003 KM |
332 | altsblock.fs_link = sblock.fs_link; |
333 | altsblock.fs_rlink = sblock.fs_rlink; | |
334 | altsblock.fs_time = sblock.fs_time; | |
335 | altsblock.fs_cstotal = sblock.fs_cstotal; | |
336 | altsblock.fs_cgrotor = sblock.fs_cgrotor; | |
337 | altsblock.fs_fmod = sblock.fs_fmod; | |
338 | altsblock.fs_clean = sblock.fs_clean; | |
339 | altsblock.fs_ronly = sblock.fs_ronly; | |
340 | altsblock.fs_flags = sblock.fs_flags; | |
341 | altsblock.fs_maxcontig = sblock.fs_maxcontig; | |
342 | altsblock.fs_minfree = sblock.fs_minfree; | |
343 | altsblock.fs_optim = sblock.fs_optim; | |
344 | altsblock.fs_rotdelay = sblock.fs_rotdelay; | |
345 | altsblock.fs_maxbpg = sblock.fs_maxbpg; | |
346 | bcopy((char *)sblock.fs_csp, (char *)altsblock.fs_csp, | |
347 | sizeof sblock.fs_csp); | |
348 | bcopy((char *)sblock.fs_fsmnt, (char *)altsblock.fs_fsmnt, | |
349 | sizeof sblock.fs_fsmnt); | |
cfbff64d MK |
350 | bcopy((char *)sblock.fs_sparecon, (char *)altsblock.fs_sparecon, |
351 | sizeof sblock.fs_sparecon); | |
7beeecfc KM |
352 | /* |
353 | * The following should not have to be copied. | |
354 | */ | |
355 | altsblock.fs_fsbtodb = sblock.fs_fsbtodb; | |
356 | altsblock.fs_interleave = sblock.fs_interleave; | |
357 | altsblock.fs_npsect = sblock.fs_npsect; | |
358 | altsblock.fs_nrpos = sblock.fs_nrpos; | |
cfbff64d MK |
359 | if (bcmp((char *)&sblock, (char *)&altsblock, (int)sblock.fs_sbsize)) { |
360 | badsb(listerr, | |
361 | "VALUES IN SUPER BLOCK DISAGREE WITH THOSE IN FIRST ALTERNATE"); | |
362 | return (0); | |
363 | } | |
55f8bbd7 | 364 | havesb = 1; |
c7aed003 | 365 | return (1); |
eb93b62a KM |
366 | } |
367 | ||
c7aed003 KM |
368 | badsb(listerr, s) |
369 | int listerr; | |
eb93b62a KM |
370 | char *s; |
371 | { | |
372 | ||
c7aed003 KM |
373 | if (!listerr) |
374 | return; | |
eb93b62a KM |
375 | if (preen) |
376 | printf("%s: ", devname); | |
c7aed003 KM |
377 | pfatal("BAD SUPER BLOCK: %s\n", s); |
378 | } | |
379 | ||
380 | /* | |
381 | * Calculate a prototype superblock based on information in the disk label. | |
382 | * When done the cgsblock macro can be calculated and the fs_ncg field | |
383 | * can be used. Do NOT attempt to use other macros without verifying that | |
384 | * their needed information is available! | |
385 | */ | |
386 | calcsb(dev, devfd, fs) | |
387 | char *dev; | |
388 | int devfd; | |
389 | register struct fs *fs; | |
390 | { | |
391 | register struct disklabel *lp; | |
392 | register struct partition *pp; | |
393 | register char *cp; | |
c7aed003 KM |
394 | int i; |
395 | ||
396 | cp = index(dev, '\0') - 1; | |
397 | if (cp == (char *)-1 || (*cp < 'a' || *cp > 'h') && !isdigit(*cp)) { | |
398 | pfatal("%s: CANNOT FIGURE OUT FILE SYSTEM PARTITION\n", dev); | |
399 | return (0); | |
400 | } | |
401 | lp = getdisklabel(dev, devfd); | |
402 | if (isdigit(*cp)) | |
403 | pp = &lp->d_partitions[0]; | |
404 | else | |
405 | pp = &lp->d_partitions[*cp - 'a']; | |
406 | if (pp->p_fstype != FS_BSDFFS) { | |
55f8bbd7 | 407 | pfatal("%s: NOT LABELED AS A BSD FILE SYSTEM (%s)\n", |
c7aed003 KM |
408 | dev, pp->p_fstype < FSMAXTYPES ? |
409 | fstypenames[pp->p_fstype] : "unknown"); | |
410 | return (0); | |
411 | } | |
569ec282 | 412 | bzero((char *)fs, sizeof(struct fs)); |
c7aed003 KM |
413 | fs->fs_fsize = pp->p_fsize; |
414 | fs->fs_frag = pp->p_frag; | |
415 | fs->fs_cpg = pp->p_cpg; | |
416 | fs->fs_size = pp->p_size; | |
417 | fs->fs_ntrak = lp->d_ntracks; | |
418 | fs->fs_nsect = lp->d_nsectors; | |
419 | fs->fs_spc = lp->d_secpercyl; | |
420 | fs->fs_nspf = fs->fs_fsize / lp->d_secsize; | |
421 | fs->fs_sblkno = roundup( | |
422 | howmany(lp->d_bbsize + lp->d_sbsize, fs->fs_fsize), | |
423 | fs->fs_frag); | |
424 | fs->fs_cgmask = 0xffffffff; | |
425 | for (i = fs->fs_ntrak; i > 1; i >>= 1) | |
426 | fs->fs_cgmask <<= 1; | |
427 | if (!POWEROF2(fs->fs_ntrak)) | |
428 | fs->fs_cgmask <<= 1; | |
429 | fs->fs_cgoffset = roundup( | |
430 | howmany(fs->fs_nsect, NSPF(fs)), fs->fs_frag); | |
431 | fs->fs_fpg = (fs->fs_cpg * fs->fs_spc) / NSPF(fs); | |
432 | fs->fs_ncg = howmany(fs->fs_size / fs->fs_spc, fs->fs_cpg); | |
433 | for (fs->fs_fsbtodb = 0, i = NSPF(fs); i > 1; i >>= 1) | |
434 | fs->fs_fsbtodb++; | |
55f8bbd7 | 435 | dev_bsize = lp->d_secsize; |
c7aed003 KM |
436 | return (1); |
437 | } | |
438 | ||
c7aed003 KM |
439 | struct disklabel * |
440 | getdisklabel(s, fd) | |
441 | char *s; | |
442 | int fd; | |
443 | { | |
444 | static struct disklabel lab; | |
445 | ||
446 | if (ioctl(fd, DIOCGDINFO, (char *)&lab) < 0) { | |
919c85da MK |
447 | if (s == NULL) |
448 | return ((struct disklabel *)NULL); | |
cfbff64d | 449 | pwarn(""); |
c7aed003 | 450 | perror("ioctl (GDINFO)"); |
cfbff64d | 451 | errexit("%s: can't read disk label", s); |
c7aed003 KM |
452 | } |
453 | return (&lab); | |
454 | } |