setup.c revision 86514
1/*
2 * Copyright (c) 1980, 1986, 1993
3 *	The Regents of the University of California.  All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 *    must display the following acknowledgement:
15 *	This product includes software developed by the University of
16 *	California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 *    may be used to endorse or promote products derived from this software
19 *    without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#ifndef lint
35#if 0
36static const char sccsid[] = "@(#)setup.c	8.10 (Berkeley) 5/9/95";
37#endif
38static const char rcsid[] =
39  "$FreeBSD: head/sbin/fsck_ffs/setup.c 86514 2001-11-17 23:48:21Z iedowse $";
40#endif /* not lint */
41
42#define DKTYPENAMES
43#include <sys/param.h>
44#include <sys/stat.h>
45#include <sys/disklabel.h>
46#include <sys/file.h>
47#include <sys/sysctl.h>
48
49#include <ufs/ufs/dinode.h>
50#include <ufs/ffs/fs.h>
51
52#include <ctype.h>
53#include <err.h>
54#include <errno.h>
55#include <string.h>
56
57#include "fsck.h"
58
59struct bufarea asblk;
60#define altsblock (*asblk.b_un.b_fs)
61#define POWEROF2(num)	(((num) & ((num) - 1)) == 0)
62
63static void badsb __P((int listerr, char *s));
64static int calcsb __P((char *dev, int devfd, struct fs *fs));
65static struct disklabel *getdisklabel __P((char *s, int fd));
66
67/*
68 * Read in a superblock finding an alternate if necessary.
69 * Return 1 if successful, 0 if unsuccessful, -1 if filesystem
70 * is already clean (preen mode only).
71 */
72int
73setup(dev)
74	char *dev;
75{
76	long cg, asked, i, j;
77	long bmapsize;
78	off_t sizepb;
79	struct stat statb;
80	struct fs proto;
81	size_t size;
82
83	havesb = 0;
84	fswritefd = -1;
85	cursnapshot = 0;
86	if (stat(dev, &statb) < 0) {
87		printf("Can't stat %s: %s\n", dev, strerror(errno));
88		if (bkgrdflag) {
89			unlink(snapname);
90			bkgrdflag = 0;
91		}
92		return (0);
93	}
94	if ((statb.st_mode & S_IFMT) != S_IFCHR &&
95	    (statb.st_mode & S_IFMT) != S_IFBLK) {
96		if (bkgrdflag != 0 && (statb.st_flags & SF_SNAPSHOT) == 0) {
97			unlink(snapname);
98			printf("background fsck lacks a snapshot\n");
99			exit(EEXIT);
100		}
101		if ((statb.st_flags & SF_SNAPSHOT) != 0 && cvtlevel == 0) {
102			cursnapshot = statb.st_ino;
103		} else {
104			if (cvtlevel == 0 ||
105			    (statb.st_flags & SF_SNAPSHOT) == 0) {
106				if (preen && bkgrdflag) {
107					unlink(snapname);
108					bkgrdflag = 0;
109				}
110				pfatal("%s is not a disk device", dev);
111				if (reply("CONTINUE") == 0) {
112					if (bkgrdflag) {
113						unlink(snapname);
114						bkgrdflag = 0;
115					}
116					return (0);
117				}
118			} else {
119				if (bkgrdflag) {
120					unlink(snapname);
121					bkgrdflag = 0;
122				}
123				pfatal("cannot convert a snapshot");
124				exit(EEXIT);
125			}
126		}
127	}
128	if ((fsreadfd = open(dev, O_RDONLY)) < 0) {
129		if (bkgrdflag) {
130			unlink(snapname);
131			bkgrdflag = 0;
132		}
133		printf("Can't open %s: %s\n", dev, strerror(errno));
134		return (0);
135	}
136	if (bkgrdflag) {
137		unlink(snapname);
138		size = MIBSIZE;
139		if (sysctlnametomib("vfs.ffs.adjrefcnt", adjrefcnt, &size) < 0||
140		    sysctlnametomib("vfs.ffs.adjblkcnt", adjblkcnt, &size) < 0||
141		    sysctlnametomib("vfs.ffs.freefiles", freefiles, &size) < 0||
142		    sysctlnametomib("vfs.ffs.freedirs", freedirs, &size) < 0 ||
143		    sysctlnametomib("vfs.ffs.freeblks", freeblks, &size) < 0) {
144			pfatal("kernel lacks background fsck support\n");
145			exit(EEXIT);
146		}
147		cmd.version = FFS_CMD_VERSION;
148		cmd.handle = fsreadfd;
149		fswritefd = -1;
150	}
151	if (preen == 0)
152		printf("** %s", dev);
153	if (bkgrdflag == 0 &&
154	    (nflag || (fswritefd = open(dev, O_WRONLY)) < 0)) {
155		fswritefd = -1;
156		if (preen)
157			pfatal("NO WRITE ACCESS");
158		printf(" (NO WRITE)");
159	}
160	if (preen == 0)
161		printf("\n");
162	/*
163	 * Read in the superblock, looking for alternates if necessary
164	 */
165	if (readsb(1) == 0) {
166		skipclean = 0;
167		if (bflag || preen || calcsb(dev, fsreadfd, &proto) == 0)
168			return(0);
169		if (reply("LOOK FOR ALTERNATE SUPERBLOCKS") == 0)
170			return (0);
171		for (cg = 0; cg < proto.fs_ncg; cg++) {
172			bflag = fsbtodb(&proto, cgsblock(&proto, cg));
173			if (readsb(0) != 0)
174				break;
175		}
176		if (cg >= proto.fs_ncg) {
177			printf("%s %s\n%s %s\n%s %s\n",
178				"SEARCH FOR ALTERNATE SUPER-BLOCK",
179				"FAILED. YOU MUST USE THE",
180				"-b OPTION TO FSCK TO SPECIFY THE",
181				"LOCATION OF AN ALTERNATE",
182				"SUPER-BLOCK TO SUPPLY NEEDED",
183				"INFORMATION; SEE fsck(8).");
184			bflag = 0;
185			return(0);
186		}
187		pwarn("USING ALTERNATE SUPERBLOCK AT %d\n", bflag);
188		bflag = 0;
189	}
190	if (skipclean && preen && sblock.fs_clean) {
191		pwarn("FILESYSTEM CLEAN; SKIPPING CHECKS\n");
192		return (-1);
193	}
194	maxfsblock = sblock.fs_size;
195	maxino = sblock.fs_ncg * sblock.fs_ipg;
196	/*
197	 * Check and potentially fix certain fields in the super block.
198	 */
199	if (sblock.fs_optim != FS_OPTTIME && sblock.fs_optim != FS_OPTSPACE) {
200		pfatal("UNDEFINED OPTIMIZATION IN SUPERBLOCK");
201		if (reply("SET TO DEFAULT") == 1) {
202			sblock.fs_optim = FS_OPTTIME;
203			sbdirty();
204		}
205	}
206	if ((sblock.fs_minfree < 0 || sblock.fs_minfree > 99)) {
207		pfatal("IMPOSSIBLE MINFREE=%d IN SUPERBLOCK",
208			sblock.fs_minfree);
209		if (reply("SET TO DEFAULT") == 1) {
210			sblock.fs_minfree = 10;
211			sbdirty();
212		}
213	}
214	if (sblock.fs_interleave < 1 ||
215	    sblock.fs_interleave > sblock.fs_nsect) {
216		pfatal("IMPOSSIBLE INTERLEAVE=%d IN SUPERBLOCK",
217			sblock.fs_interleave);
218		sblock.fs_interleave = 1;
219		if (preen)
220			printf(" (FIXED)\n");
221		if (preen || reply("SET TO DEFAULT") == 1) {
222			sbdirty();
223			dirty(&asblk);
224		}
225	}
226	if (sblock.fs_npsect < sblock.fs_nsect ||
227	    sblock.fs_npsect > sblock.fs_nsect*2) {
228		pfatal("IMPOSSIBLE NPSECT=%d IN SUPERBLOCK",
229			sblock.fs_npsect);
230		sblock.fs_npsect = sblock.fs_nsect;
231		if (preen)
232			printf(" (FIXED)\n");
233		if (preen || reply("SET TO DEFAULT") == 1) {
234			sbdirty();
235			dirty(&asblk);
236		}
237	}
238	if (sblock.fs_inodefmt >= FS_44INODEFMT) {
239		newinofmt = 1;
240	} else {
241		sblock.fs_qbmask = ~sblock.fs_bmask;
242		sblock.fs_qfmask = ~sblock.fs_fmask;
243		/* This should match the kernel limit in ffs_oldfscompat(). */
244		sblock.fs_maxfilesize = (u_int64_t)1 << 39;
245		newinofmt = 0;
246	}
247	/*
248	 * Convert to new inode format.
249	 */
250	if (cvtlevel >= 2 && sblock.fs_inodefmt < FS_44INODEFMT) {
251		if (preen)
252			pwarn("CONVERTING TO NEW INODE FORMAT\n");
253		else if (!reply("CONVERT TO NEW INODE FORMAT"))
254			return(0);
255		doinglevel2++;
256		sblock.fs_inodefmt = FS_44INODEFMT;
257		sizepb = sblock.fs_bsize;
258		sblock.fs_maxfilesize = sblock.fs_bsize * NDADDR - 1;
259		for (i = 0; i < NIADDR; i++) {
260			sizepb *= NINDIR(&sblock);
261			sblock.fs_maxfilesize += sizepb;
262		}
263		sblock.fs_maxsymlinklen = MAXSYMLINKLEN;
264		sblock.fs_qbmask = ~sblock.fs_bmask;
265		sblock.fs_qfmask = ~sblock.fs_fmask;
266		sbdirty();
267		dirty(&asblk);
268	}
269	/*
270	 * Convert to new cylinder group format.
271	 */
272	if (cvtlevel >= 1 && sblock.fs_postblformat == FS_42POSTBLFMT) {
273		if (preen)
274			pwarn("CONVERTING TO NEW CYLINDER GROUP FORMAT\n");
275		else if (!reply("CONVERT TO NEW CYLINDER GROUP FORMAT"))
276			return(0);
277		doinglevel1++;
278		sblock.fs_postblformat = FS_DYNAMICPOSTBLFMT;
279		sblock.fs_nrpos = 8;
280		sblock.fs_postbloff =
281		    (char *)(&sblock.fs_opostbl[0][0]) -
282		    (char *)(&sblock.fs_firstfield);
283		sblock.fs_rotbloff = &sblock.fs_space[0] -
284		    (u_char *)(&sblock.fs_firstfield);
285		sblock.fs_cgsize =
286			fragroundup(&sblock, CGSIZE(&sblock));
287		sbdirty();
288		dirty(&asblk);
289	}
290	if (asblk.b_dirty && !bflag) {
291		memmove(&altsblock, &sblock, (size_t)sblock.fs_sbsize);
292		flush(fswritefd, &asblk);
293	}
294	/*
295	 * read in the summary info.
296	 */
297	asked = 0;
298	sblock.fs_csp = calloc(1, sblock.fs_cssize);
299	for (i = 0, j = 0; i < sblock.fs_cssize; i += sblock.fs_bsize, j++) {
300		size = sblock.fs_cssize - i < sblock.fs_bsize ?
301		    sblock.fs_cssize - i : sblock.fs_bsize;
302		if (bread(fsreadfd, (char *)sblock.fs_csp + i,
303		    fsbtodb(&sblock, sblock.fs_csaddr + j * sblock.fs_frag),
304		    size) != 0 && !asked) {
305			pfatal("BAD SUMMARY INFORMATION");
306			if (reply("CONTINUE") == 0) {
307				ckfini(0);
308				exit(EEXIT);
309			}
310			asked++;
311		}
312	}
313	/*
314	 * allocate and initialize the necessary maps
315	 */
316	bmapsize = roundup(howmany(maxfsblock, NBBY), sizeof(short));
317	blockmap = calloc((unsigned)bmapsize, sizeof (char));
318	if (blockmap == NULL) {
319		printf("cannot alloc %u bytes for blockmap\n",
320		    (unsigned)bmapsize);
321		goto badsb;
322	}
323	inostathead = calloc((unsigned)(sblock.fs_ncg),
324	    sizeof(struct inostatlist));
325	if (inostathead == NULL) {
326		printf("cannot alloc %u bytes for inostathead\n",
327		    (unsigned)(sizeof(struct inostatlist) * (sblock.fs_ncg)));
328		goto badsb;
329	}
330	numdirs = sblock.fs_cstotal.cs_ndir;
331	dirhash = numdirs;
332	if (numdirs == 0) {
333		printf("numdirs is zero, try using an alternate superblock\n");
334		goto badsb;
335	}
336	inplast = 0;
337	listmax = numdirs + 10;
338	inpsort = (struct inoinfo **)calloc((unsigned)listmax,
339	    sizeof(struct inoinfo *));
340	inphead = (struct inoinfo **)calloc((unsigned)numdirs,
341	    sizeof(struct inoinfo *));
342	if (inpsort == NULL || inphead == NULL) {
343		printf("cannot alloc %u bytes for inphead\n",
344		    (unsigned)numdirs * sizeof(struct inoinfo *));
345		goto badsb;
346	}
347	bufinit();
348	if (sblock.fs_flags & FS_DOSOFTDEP)
349		usedsoftdep = 1;
350	else
351		usedsoftdep = 0;
352	return (1);
353
354badsb:
355	ckfini(0);
356	return (0);
357}
358
359/*
360 * Read in the super block and its summary info.
361 */
362int
363readsb(listerr)
364	int listerr;
365{
366	ufs_daddr_t super = bflag ? bflag : SBOFF / dev_bsize;
367
368	if (bread(fsreadfd, (char *)&sblock, super, (long)SBSIZE) != 0)
369		return (0);
370	sblk.b_bno = super;
371	sblk.b_size = SBSIZE;
372	/*
373	 * run a few consistency checks of the super block
374	 */
375	if (sblock.fs_magic != FS_MAGIC)
376		{ badsb(listerr, "MAGIC NUMBER WRONG"); return (0); }
377	if (sblock.fs_ncg < 1)
378		{ badsb(listerr, "NCG OUT OF RANGE"); return (0); }
379	if (sblock.fs_cpg < 1)
380		{ badsb(listerr, "CPG OUT OF RANGE"); return (0); }
381	if (sblock.fs_ncg * sblock.fs_cpg < sblock.fs_ncyl ||
382	    (sblock.fs_ncg - 1) * sblock.fs_cpg >= sblock.fs_ncyl)
383		{ badsb(listerr, "NCYL LESS THAN NCG*CPG"); return (0); }
384	if (sblock.fs_sbsize > SBSIZE)
385		{ badsb(listerr, "SIZE PREPOSTEROUSLY LARGE"); return (0); }
386	/*
387	 * Compute block size that the filesystem is based on,
388	 * according to fsbtodb, and adjust superblock block number
389	 * so we can tell if this is an alternate later.
390	 */
391	super *= dev_bsize;
392	dev_bsize = sblock.fs_fsize / fsbtodb(&sblock, 1);
393	sblk.b_bno = super / dev_bsize;
394	if (bflag) {
395		havesb = 1;
396		return (1);
397	}
398	/*
399	 * Set all possible fields that could differ, then do check
400	 * of whole super block against an alternate super block.
401	 * When an alternate super-block is specified this check is skipped.
402	 */
403	getblk(&asblk, cgsblock(&sblock, sblock.fs_ncg - 1), sblock.fs_sbsize);
404	if (asblk.b_errs)
405		return (0);
406	altsblock.fs_firstfield = sblock.fs_firstfield;
407	altsblock.fs_unused_1 = sblock.fs_unused_1;
408	altsblock.fs_time = sblock.fs_time;
409	altsblock.fs_cstotal = sblock.fs_cstotal;
410	altsblock.fs_cgrotor = sblock.fs_cgrotor;
411	altsblock.fs_fmod = sblock.fs_fmod;
412	altsblock.fs_clean = sblock.fs_clean;
413	altsblock.fs_ronly = sblock.fs_ronly;
414	altsblock.fs_flags = sblock.fs_flags;
415	altsblock.fs_maxcontig = sblock.fs_maxcontig;
416	altsblock.fs_minfree = sblock.fs_minfree;
417	altsblock.fs_optim = sblock.fs_optim;
418	altsblock.fs_rotdelay = sblock.fs_rotdelay;
419	altsblock.fs_maxbpg = sblock.fs_maxbpg;
420	memmove(altsblock.fs_ocsp, sblock.fs_ocsp, sizeof sblock.fs_ocsp);
421	altsblock.fs_csp = sblock.fs_csp;
422	altsblock.fs_maxcluster = sblock.fs_maxcluster;
423	altsblock.fs_contigdirs = sblock.fs_contigdirs;
424	altsblock.fs_avgfilesize = sblock.fs_avgfilesize;
425	altsblock.fs_avgfpdir = sblock.fs_avgfpdir;
426	altsblock.fs_pendingblocks = sblock.fs_pendingblocks;
427	altsblock.fs_pendinginodes = sblock.fs_pendinginodes;
428	memmove(altsblock.fs_fsmnt, sblock.fs_fsmnt, sizeof sblock.fs_fsmnt);
429	memmove(altsblock.fs_snapinum, sblock.fs_snapinum,
430		sizeof sblock.fs_snapinum);
431	memmove(altsblock.fs_sparecon,
432		sblock.fs_sparecon, sizeof sblock.fs_sparecon);
433	/*
434	 * The following should not have to be copied.
435	 */
436	altsblock.fs_fsbtodb = sblock.fs_fsbtodb;
437	altsblock.fs_interleave = sblock.fs_interleave;
438	altsblock.fs_npsect = sblock.fs_npsect;
439	altsblock.fs_nrpos = sblock.fs_nrpos;
440	altsblock.fs_state = sblock.fs_state;
441	altsblock.fs_qbmask = sblock.fs_qbmask;
442	altsblock.fs_qfmask = sblock.fs_qfmask;
443	altsblock.fs_state = sblock.fs_state;
444	altsblock.fs_maxfilesize = sblock.fs_maxfilesize;
445	if (memcmp(&sblock, &altsblock, (int)sblock.fs_sbsize)) {
446		if (debug) {
447			long *nlp, *olp, *endlp;
448
449			printf("superblock mismatches\n");
450			nlp = (long *)&altsblock;
451			olp = (long *)&sblock;
452			endlp = olp + (sblock.fs_sbsize / sizeof *olp);
453			for ( ; olp < endlp; olp++, nlp++) {
454				if (*olp == *nlp)
455					continue;
456				printf(
457				    "offset %d, original %ld, alternate %ld\n",
458				    olp - (long *)&sblock, *olp, *nlp);
459			}
460		}
461		badsb(listerr,
462		"VALUES IN SUPER BLOCK DISAGREE WITH THOSE IN FIRST ALTERNATE");
463		return (0);
464	}
465	havesb = 1;
466	return (1);
467}
468
469static void
470badsb(listerr, s)
471	int listerr;
472	char *s;
473{
474
475	if (!listerr)
476		return;
477	if (preen)
478		printf("%s: ", cdevname);
479	pfatal("BAD SUPER BLOCK: %s\n", s);
480}
481
482void
483sblock_init()
484{
485	struct disklabel *lp;
486
487	fswritefd = -1;
488	fsmodified = 0;
489	lfdir = 0;
490	initbarea(&sblk);
491	initbarea(&asblk);
492	sblk.b_un.b_buf = malloc(SBSIZE);
493	asblk.b_un.b_buf = malloc(SBSIZE);
494	if (sblk.b_un.b_buf == NULL || asblk.b_un.b_buf == NULL)
495		errx(EEXIT, "cannot allocate space for superblock");
496	if ((lp = getdisklabel(NULL, fsreadfd)))
497		dev_bsize = secsize = lp->d_secsize;
498	else
499		dev_bsize = secsize = DEV_BSIZE;
500}
501
502/*
503 * Calculate a prototype superblock based on information in the disk label.
504 * When done the cgsblock macro can be calculated and the fs_ncg field
505 * can be used. Do NOT attempt to use other macros without verifying that
506 * their needed information is available!
507 */
508static int
509calcsb(dev, devfd, fs)
510	char *dev;
511	int devfd;
512	register struct fs *fs;
513{
514	register struct disklabel *lp;
515	register struct partition *pp;
516	register char *cp;
517	int i;
518
519	cp = strchr(dev, '\0') - 1;
520	if (cp == (char *)-1 || ((*cp < 'a' || *cp > 'h') && !isdigit(*cp))) {
521		pfatal("%s: CANNOT FIGURE OUT FILE SYSTEM PARTITION\n", dev);
522		return (0);
523	}
524	lp = getdisklabel(dev, devfd);
525	if (isdigit(*cp))
526		pp = &lp->d_partitions[0];
527	else
528		pp = &lp->d_partitions[*cp - 'a'];
529	if (pp->p_fstype != FS_BSDFFS) {
530		pfatal("%s: NOT LABELED AS A BSD FILE SYSTEM (%s)\n",
531			dev, pp->p_fstype < FSMAXTYPES ?
532			fstypenames[pp->p_fstype] : "unknown");
533		return (0);
534	}
535	if (pp->p_fsize == 0 || pp->p_frag == 0 ||
536	    pp->p_cpg == 0 || pp->p_size == 0) {
537		pfatal("%s: %s: type %s fsize %d, frag %d, cpg %d, size %d\n",
538		    dev, "INCOMPLETE LABEL", fstypenames[pp->p_fstype],
539		    pp->p_fsize, pp->p_frag, pp->p_cpg, pp->p_size);
540		return (0);
541	}
542	memset(fs, 0, sizeof(struct fs));
543	fs->fs_fsize = pp->p_fsize;
544	fs->fs_frag = pp->p_frag;
545	fs->fs_cpg = pp->p_cpg;
546	fs->fs_size = pp->p_size;
547	fs->fs_ntrak = lp->d_ntracks;
548	fs->fs_nsect = lp->d_nsectors;
549	fs->fs_spc = lp->d_secpercyl;
550	fs->fs_nspf = fs->fs_fsize / lp->d_secsize;
551	fs->fs_sblkno = roundup(
552		howmany(lp->d_bbsize + lp->d_sbsize, fs->fs_fsize),
553		fs->fs_frag);
554	fs->fs_cgmask = 0xffffffff;
555	for (i = fs->fs_ntrak; i > 1; i >>= 1)
556		fs->fs_cgmask <<= 1;
557	if (!POWEROF2(fs->fs_ntrak))
558		fs->fs_cgmask <<= 1;
559	fs->fs_cgoffset = roundup(
560		howmany(fs->fs_nsect, NSPF(fs)), fs->fs_frag);
561	fs->fs_fpg = (fs->fs_cpg * fs->fs_spc) / NSPF(fs);
562	fs->fs_ncg = howmany(fs->fs_size / fs->fs_spc, fs->fs_cpg);
563	for (fs->fs_fsbtodb = 0, i = NSPF(fs); i > 1; i >>= 1)
564		fs->fs_fsbtodb++;
565	dev_bsize = lp->d_secsize;
566	return (1);
567}
568
569static struct disklabel *
570getdisklabel(s, fd)
571	char *s;
572	int	fd;
573{
574	static struct disklabel lab;
575
576	if (ioctl(fd, DIOCGDINFO, (char *)&lab) < 0) {
577		if (s == NULL)
578			return ((struct disklabel *)NULL);
579		pwarn("ioctl (GCINFO): %s\n", strerror(errno));
580		errx(EEXIT, "%s: can't read disk label", s);
581	}
582	return (&lab);
583}
584