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