xref: /netbsd/sbin/fsck_ffs/utilities.c (revision c4a72b64)
1 /*	$NetBSD: utilities.c,v 1.34 2002/09/28 20:11:06 dbj Exp $	*/
2 
3 /*
4  * Copyright (c) 1980, 1986, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *	This product includes software developed by the University of
18  *	California, Berkeley and its contributors.
19  * 4. Neither the name of the University nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  */
35 
36 #include <sys/cdefs.h>
37 #ifndef lint
38 #if 0
39 static char sccsid[] = "@(#)utilities.c	8.6 (Berkeley) 5/19/95";
40 #else
41 __RCSID("$NetBSD: utilities.c,v 1.34 2002/09/28 20:11:06 dbj Exp $");
42 #endif
43 #endif /* not lint */
44 
45 #include <sys/param.h>
46 #include <sys/time.h>
47 
48 #include <ufs/ufs/dinode.h>
49 #include <ufs/ufs/dir.h>
50 #include <ufs/ffs/fs.h>
51 #include <ufs/ffs/ffs_extern.h>
52 #include <ufs/ufs/ufs_bswap.h>
53 
54 #include <ctype.h>
55 #include <err.h>
56 #include <stdio.h>
57 #include <stdlib.h>
58 #include <string.h>
59 #include <unistd.h>
60 
61 #include "fsutil.h"
62 #include "fsck.h"
63 #include "extern.h"
64 
65 long	diskreads, totalreads;	/* Disk cache statistics */
66 
67 static void rwerror __P((char *, ufs_daddr_t));
68 
69 extern int returntosingle;
70 
71 int
72 ftypeok(dp)
73 	struct dinode *dp;
74 {
75 	switch (iswap16(dp->di_mode) & IFMT) {
76 
77 	case IFDIR:
78 	case IFREG:
79 	case IFBLK:
80 	case IFCHR:
81 	case IFLNK:
82 	case IFSOCK:
83 	case IFIFO:
84 		return (1);
85 
86 	default:
87 		if (debug)
88 			printf("bad file type 0%o\n", iswap16(dp->di_mode));
89 		return (0);
90 	}
91 }
92 
93 int
94 reply(question)
95 	char *question;
96 {
97 	int persevere;
98 	char c;
99 
100 	if (preen)
101 		pfatal("INTERNAL ERROR: GOT TO reply()");
102 	persevere = !strcmp(question, "CONTINUE");
103 	printf("\n");
104 	if (!persevere && (nflag || fswritefd < 0)) {
105 		printf("%s? no\n\n", question);
106 		resolved = 0;
107 		return (0);
108 	}
109 	if (yflag || (persevere && nflag)) {
110 		printf("%s? yes\n\n", question);
111 		return (1);
112 	}
113 	do	{
114 		printf("%s? [yn] ", question);
115 		(void) fflush(stdout);
116 		c = getc(stdin);
117 		while (c != '\n' && getc(stdin) != '\n') {
118 			if (feof(stdin)) {
119 				resolved = 0;
120 				return (0);
121 			}
122 		}
123 	} while (c != 'y' && c != 'Y' && c != 'n' && c != 'N');
124 	printf("\n");
125 	if (c == 'y' || c == 'Y')
126 		return (1);
127 	resolved = 0;
128 	return (0);
129 }
130 
131 /*
132  * Malloc buffers and set up cache.
133  */
134 void
135 bufinit()
136 {
137 	struct bufarea *bp;
138 	long bufcnt, i;
139 	char *bufp;
140 
141 	pbp = pdirbp = (struct bufarea *)0;
142 	bufp = malloc((unsigned int)sblock->fs_bsize);
143 	if (bufp == 0)
144 		errx(EEXIT, "cannot allocate buffer pool");
145 	cgblk.b_un.b_buf = bufp;
146 	initbarea(&cgblk);
147 	bufp = malloc((unsigned int)APPLEUFS_LABEL_SIZE);
148 	if (bufp == 0)
149 		errx(EEXIT, "cannot allocate buffer pool");
150 	appleufsblk.b_un.b_buf = bufp;
151 	initbarea(&appleufsblk);
152 	bufhead.b_next = bufhead.b_prev = &bufhead;
153 	bufcnt = MAXBUFSPACE / sblock->fs_bsize;
154 	if (bufcnt < MINBUFS)
155 		bufcnt = MINBUFS;
156 	for (i = 0; i < bufcnt; i++) {
157 		bp = (struct bufarea *)malloc(sizeof(struct bufarea));
158 		bufp = malloc((unsigned int)sblock->fs_bsize);
159 		if (bp == NULL || bufp == NULL) {
160 			if (i >= MINBUFS)
161 				break;
162 			errx(EEXIT, "cannot allocate buffer pool");
163 		}
164 		bp->b_un.b_buf = bufp;
165 		bp->b_prev = &bufhead;
166 		bp->b_next = bufhead.b_next;
167 		bufhead.b_next->b_prev = bp;
168 		bufhead.b_next = bp;
169 		initbarea(bp);
170 	}
171 	bufhead.b_size = i;	/* save number of buffers */
172 }
173 
174 /*
175  * Manage a cache of directory blocks.
176  */
177 struct bufarea *
178 getdatablk(blkno, size)
179 	ufs_daddr_t blkno;
180 	long size;
181 {
182 	struct bufarea *bp;
183 
184 	for (bp = bufhead.b_next; bp != &bufhead; bp = bp->b_next)
185 		if (bp->b_bno == fsbtodb(sblock, blkno))
186 			goto foundit;
187 	for (bp = bufhead.b_prev; bp != &bufhead; bp = bp->b_prev)
188 		if ((bp->b_flags & B_INUSE) == 0)
189 			break;
190 	if (bp == &bufhead)
191 		errx(EEXIT, "deadlocked buffer pool");
192 	getblk(bp, blkno, size);
193 	/* fall through */
194 foundit:
195 	totalreads++;
196 	bp->b_prev->b_next = bp->b_next;
197 	bp->b_next->b_prev = bp->b_prev;
198 	bp->b_prev = &bufhead;
199 	bp->b_next = bufhead.b_next;
200 	bufhead.b_next->b_prev = bp;
201 	bufhead.b_next = bp;
202 	bp->b_flags |= B_INUSE;
203 	return (bp);
204 }
205 
206 void
207 getblk(bp, blk, size)
208 	struct bufarea *bp;
209 	ufs_daddr_t blk;
210 	long size;
211 {
212 	ufs_daddr_t dblk;
213 
214 	dblk = fsbtodb(sblock, blk);
215 	if (bp->b_bno != dblk) {
216 		flush(fswritefd, bp);
217 		diskreads++;
218 		bp->b_errs = bread(fsreadfd, bp->b_un.b_buf, dblk, size);
219 		bp->b_bno = dblk;
220 		bp->b_size = size;
221 	}
222 }
223 
224 void
225 flush(fd, bp)
226 	int fd;
227 	struct bufarea *bp;
228 {
229 	int i, j;
230 	struct csum *ccsp;
231 
232 	if (!bp->b_dirty)
233 		return;
234 	if (bp->b_errs != 0)
235 		pfatal("WRITING %sZERO'ED BLOCK %d TO DISK\n",
236 		    (bp->b_errs == bp->b_size / dev_bsize) ? "" : "PARTIALLY ",
237 		    bp->b_bno);
238 	bp->b_dirty = 0;
239 	bp->b_errs = 0;
240 	bwrite(fd, bp->b_un.b_buf, bp->b_bno, (long)bp->b_size);
241 	if (bp != &sblk)
242 		return;
243 	for (i = 0, j = 0; i < sblock->fs_cssize; i += sblock->fs_bsize, j++) {
244 		int size = sblock->fs_cssize - i < sblock->fs_bsize ?
245 			sblock->fs_cssize - i : sblock->fs_bsize;
246 		ccsp = (struct csum *)((char *)sblock->fs_csp + i);
247 		if (needswap)
248 			ffs_csum_swap(ccsp, ccsp, size);
249 		bwrite(fswritefd, (char *)ccsp,
250 		    fsbtodb(sblock, sblock->fs_csaddr + j * sblock->fs_frag),
251 		    size);
252 		if (needswap)
253 			ffs_csum_swap(ccsp, ccsp, size);
254 	}
255 }
256 
257 static void
258 rwerror(mesg, blk)
259 	char *mesg;
260 	ufs_daddr_t blk;
261 {
262 
263 	if (preen == 0)
264 		printf("\n");
265 	pfatal("CANNOT %s: BLK %d", mesg, blk);
266 	if (reply("CONTINUE") == 0)
267 		exit(EEXIT);
268 }
269 
270 void
271 ckfini()
272 {
273 	struct bufarea *bp, *nbp;
274 	int ofsmodified, cnt = 0;
275 
276 	if (fswritefd < 0) {
277 		(void)close(fsreadfd);
278 		return;
279 	}
280 	flush(fswritefd, &sblk);
281 	if (havesb && sblk.b_bno != SBOFF / dev_bsize &&
282 	    !preen && reply("UPDATE STANDARD SUPERBLOCK")) {
283 		sblk.b_bno = SBOFF / dev_bsize;
284 		sbdirty();
285 		flush(fswritefd, &sblk);
286 	}
287 	flush(fswritefd, &appleufsblk);
288 	free(appleufsblk.b_un.b_buf);
289 	flush(fswritefd, &cgblk);
290 	free(cgblk.b_un.b_buf);
291 	for (bp = bufhead.b_prev; bp && bp != &bufhead; bp = nbp) {
292 		cnt++;
293 		flush(fswritefd, bp);
294 		nbp = bp->b_prev;
295 		free(bp->b_un.b_buf);
296 		free((char *)bp);
297 	}
298 	if (bufhead.b_size != cnt)
299 		errx(EEXIT, "Panic: lost %d buffers", bufhead.b_size - cnt);
300 	pbp = pdirbp = (struct bufarea *)0;
301 	if (markclean && (sblock->fs_clean & FS_ISCLEAN) == 0) {
302 		/*
303 		 * Mark the file system as clean, and sync the superblock.
304 		 */
305 		if (preen)
306 			pwarn("MARKING FILE SYSTEM CLEAN\n");
307 		else if (!reply("MARK FILE SYSTEM CLEAN"))
308 			markclean = 0;
309 		if (markclean) {
310 			sblock->fs_clean = FS_ISCLEAN;
311 			sbdirty();
312 			ofsmodified = fsmodified;
313 			flush(fswritefd, &sblk);
314 #if LITE2BORKEN
315 			fsmodified = ofsmodified;
316 #endif
317 			if (!preen)
318 				printf(
319 				    "\n***** FILE SYSTEM MARKED CLEAN *****\n");
320 		}
321 	}
322 	if (debug)
323 		printf("cache missed %ld of %ld (%d%%)\n", diskreads,
324 		    totalreads, (int)(diskreads * 100 / totalreads));
325 	(void)close(fsreadfd);
326 	(void)close(fswritefd);
327 }
328 
329 int
330 bread(fd, buf, blk, size)
331 	int fd;
332 	char *buf;
333 	ufs_daddr_t blk;
334 	long size;
335 {
336 	char *cp;
337 	int i, errs;
338 	off_t offset;
339 
340 	offset = blk;
341 	offset *= dev_bsize;
342 	if (lseek(fd, offset, 0) < 0)
343 		rwerror("SEEK", blk);
344 	else if (read(fd, buf, (int)size) == size)
345 		return (0);
346 	rwerror("READ", blk);
347 	if (lseek(fd, offset, 0) < 0)
348 		rwerror("SEEK", blk);
349 	errs = 0;
350 	memset(buf, 0, (size_t)size);
351 	printf("THE FOLLOWING DISK SECTORS COULD NOT BE READ:");
352 	for (cp = buf, i = 0; i < size; i += secsize, cp += secsize) {
353 		if (read(fd, cp, (int)secsize) != secsize) {
354 			(void)lseek(fd, offset + i + secsize, 0);
355 			if (secsize != dev_bsize && dev_bsize != 1)
356 				printf(" %ld (%ld),",
357 				    (blk * dev_bsize + i) / secsize,
358 				    blk + i / dev_bsize);
359 			else
360 				printf(" %ld,", blk + i / dev_bsize);
361 			errs++;
362 		}
363 	}
364 	printf("\n");
365 	return (errs);
366 }
367 
368 void
369 bwrite(fd, buf, blk, size)
370 	int fd;
371 	char *buf;
372 	ufs_daddr_t blk;
373 	long size;
374 {
375 	int i;
376 	char *cp;
377 	off_t offset;
378 
379 	if (fd < 0)
380 		return;
381 	offset = blk;
382 	offset *= dev_bsize;
383 	if (lseek(fd, offset, 0) < 0)
384 		rwerror("SEEK", blk);
385 	else if (write(fd, buf, (int)size) == size) {
386 		fsmodified = 1;
387 		return;
388 	}
389 	rwerror("WRITE", blk);
390 	if (lseek(fd, offset, 0) < 0)
391 		rwerror("SEEK", blk);
392 	printf("THE FOLLOWING SECTORS COULD NOT BE WRITTEN:");
393 	for (cp = buf, i = 0; i < size; i += dev_bsize, cp += dev_bsize)
394 		if (write(fd, cp, (int)dev_bsize) != dev_bsize) {
395 			(void)lseek(fd, offset + i + dev_bsize, 0);
396 			printf(" %ld,", blk + i / dev_bsize);
397 		}
398 	printf("\n");
399 	return;
400 }
401 
402 /*
403  * allocate a data block with the specified number of fragments
404  */
405 ufs_daddr_t
406 allocblk(frags)
407 	long frags;
408 {
409 	int i, j, k, cg, baseblk;
410 	struct cg *cgp = cgrp;
411 
412 	if (frags <= 0 || frags > sblock->fs_frag)
413 		return (0);
414 	for (i = 0; i < maxfsblock - sblock->fs_frag; i += sblock->fs_frag) {
415 		for (j = 0; j <= sblock->fs_frag - frags; j++) {
416 			if (testbmap(i + j))
417 				continue;
418 			for (k = 1; k < frags; k++)
419 				if (testbmap(i + j + k))
420 					break;
421 			if (k < frags) {
422 				j += k;
423 				continue;
424 			}
425 			cg = dtog(sblock, i + j);
426 			getblk(&cgblk, cgtod(sblock, cg), sblock->fs_cgsize);
427 			memcpy(cgp, cgblk.b_un.b_cg, sblock->fs_cgsize);
428 			if ((doswap && !needswap) || (!doswap && needswap))
429 				swap_cg(cgblk.b_un.b_cg, cgp);
430 			if (!cg_chkmagic(cgp, 0))
431 				pfatal("CG %d: ALLOCBLK: BAD MAGIC NUMBER\n",
432 				    cg);
433 			baseblk = dtogd(sblock, i + j);
434 			for (k = 0; k < frags; k++) {
435 				setbmap(i + j + k);
436 				clrbit(cg_blksfree(cgp, 0), baseblk + k);
437 			}
438 			n_blks += frags;
439 			if (frags == sblock->fs_frag)
440 				cgp->cg_cs.cs_nbfree--;
441 			else
442 				cgp->cg_cs.cs_nffree -= frags;
443 			cgdirty();
444 			return (i + j);
445 		}
446 	}
447 	return (0);
448 }
449 
450 /*
451  * Free a previously allocated block
452  */
453 void
454 freeblk(blkno, frags)
455 	ufs_daddr_t blkno;
456 	long frags;
457 {
458 	struct inodesc idesc;
459 
460 	idesc.id_blkno = blkno;
461 	idesc.id_numfrags = frags;
462 	(void)pass4check(&idesc);
463 }
464 
465 /*
466  * Find a pathname
467  */
468 void
469 getpathname(namebuf, curdir, ino)
470 	char *namebuf;
471 	ino_t curdir, ino;
472 {
473 	int len;
474 	char *cp;
475 	struct inodesc idesc;
476 	static int busy = 0;
477 
478 	if (curdir == ino && ino == ROOTINO) {
479 		(void)strcpy(namebuf, "/");
480 		return;
481 	}
482 	if (busy ||
483 	    (statemap[curdir] != DSTATE && statemap[curdir] != DFOUND)) {
484 		(void)strcpy(namebuf, "?");
485 		return;
486 	}
487 	busy = 1;
488 	memset(&idesc, 0, sizeof(struct inodesc));
489 	idesc.id_type = DATA;
490 	idesc.id_fix = IGNORE;
491 	cp = &namebuf[MAXPATHLEN - 1];
492 	*cp = '\0';
493 	if (curdir != ino) {
494 		idesc.id_parent = curdir;
495 		goto namelookup;
496 	}
497 	while (ino != ROOTINO) {
498 		idesc.id_number = ino;
499 		idesc.id_func = findino;
500 		idesc.id_name = "..";
501 		if ((ckinode(ginode(ino), &idesc) & FOUND) == 0)
502 			break;
503 	namelookup:
504 		idesc.id_number = idesc.id_parent;
505 		idesc.id_parent = ino;
506 		idesc.id_func = findname;
507 		idesc.id_name = namebuf;
508 		if ((ckinode(ginode(idesc.id_number), &idesc)&FOUND) == 0)
509 			break;
510 		len = strlen(namebuf);
511 		cp -= len;
512 		memmove(cp, namebuf, (size_t)len);
513 		*--cp = '/';
514 		if (cp < &namebuf[MAXNAMLEN])
515 			break;
516 		ino = idesc.id_number;
517 	}
518 	busy = 0;
519 	if (ino != ROOTINO)
520 		*--cp = '?';
521 	memmove(namebuf, cp, (size_t)(&namebuf[MAXPATHLEN] - cp));
522 }
523 
524 void
525 catch(sig)
526 	int sig;
527 {
528 	if (!doinglevel2) {
529 		markclean = 0;
530 		ckfini();
531 	}
532 	exit(12);
533 }
534 
535 /*
536  * When preening, allow a single quit to signal
537  * a special exit after filesystem checks complete
538  * so that reboot sequence may be interrupted.
539  */
540 void
541 catchquit(sig)
542 	int sig;
543 {
544 	printf("returning to single-user after file system check\n");
545 	returntosingle = 1;
546 	(void)signal(SIGQUIT, SIG_DFL);
547 }
548 
549 /*
550  * Ignore a single quit signal; wait and flush just in case.
551  * Used by child processes in preen.
552  */
553 void
554 voidquit(sig)
555 	int sig;
556 {
557 
558 	sleep(1);
559 	(void)signal(SIGQUIT, SIG_IGN);
560 	(void)signal(SIGQUIT, SIG_DFL);
561 }
562 
563 /*
564  * determine whether an inode should be fixed.
565  */
566 int
567 dofix(idesc, msg)
568 	struct inodesc *idesc;
569 	char *msg;
570 {
571 
572 	switch (idesc->id_fix) {
573 
574 	case DONTKNOW:
575 		if (idesc->id_type == DATA)
576 			direrror(idesc->id_number, msg);
577 		else
578 			pwarn("%s", msg);
579 		if (preen) {
580 			printf(" (SALVAGED)\n");
581 			idesc->id_fix = FIX;
582 			return (ALTERED);
583 		}
584 		if (reply("SALVAGE") == 0) {
585 			idesc->id_fix = NOFIX;
586 			return (0);
587 		}
588 		idesc->id_fix = FIX;
589 		return (ALTERED);
590 
591 	case FIX:
592 		return (ALTERED);
593 
594 	case NOFIX:
595 	case IGNORE:
596 		return (0);
597 
598 	default:
599 		errx(EEXIT, "UNKNOWN INODESC FIX MODE %d", idesc->id_fix);
600 	}
601 	/* NOTREACHED */
602 	return (0);
603 }
604 
605 void
606 copyback_cg(blk)
607 	struct bufarea *blk;
608 {
609 
610 	memcpy(blk->b_un.b_cg, cgrp, sblock->fs_cgsize);
611 	if (needswap)
612 		swap_cg(cgrp, blk->b_un.b_cg);
613 }
614 
615 void
616 swap_cg(o, n)
617 	struct cg *o, *n;
618 {
619 	int i;
620 	u_int32_t *n32, *o32;
621 	u_int16_t *n16, *o16;
622 
623 	n->cg_firstfield = bswap32(o->cg_firstfield);
624 	n->cg_magic = bswap32(o->cg_magic);
625 	n->cg_time = bswap32(o->cg_time);
626 	n->cg_cgx = bswap32(o->cg_cgx);
627 	n->cg_ncyl = bswap16(o->cg_ncyl);
628 	n->cg_niblk = bswap16(o->cg_niblk);
629 	n->cg_ndblk = bswap32(o->cg_ndblk);
630 	n->cg_cs.cs_ndir = bswap32(o->cg_cs.cs_ndir);
631 	n->cg_cs.cs_nbfree = bswap32(o->cg_cs.cs_nbfree);
632 	n->cg_cs.cs_nifree = bswap32(o->cg_cs.cs_nifree);
633 	n->cg_cs.cs_nffree = bswap32(o->cg_cs.cs_nffree);
634 	n->cg_rotor = bswap32(o->cg_rotor);
635 	n->cg_frotor = bswap32(o->cg_frotor);
636 	n->cg_irotor = bswap32(o->cg_irotor);
637 	n->cg_btotoff = bswap32(o->cg_btotoff);
638 	n->cg_boff = bswap32(o->cg_boff);
639 	n->cg_iusedoff = bswap32(o->cg_iusedoff);
640 	n->cg_freeoff = bswap32(o->cg_freeoff);
641 	n->cg_nextfreeoff = bswap32(o->cg_nextfreeoff);
642 	n->cg_clustersumoff = bswap32(o->cg_clustersumoff);
643 	n->cg_clusteroff = bswap32(o->cg_clusteroff);
644 	n->cg_nclusterblks = bswap32(o->cg_nclusterblks);
645 	for (i=0; i < MAXFRAG; i++)
646 		n->cg_frsum[i] = bswap32(o->cg_frsum[i]);
647 
648 	if (sblock->fs_postblformat == FS_42POSTBLFMT) { /* old format */
649 		struct ocg *on, *oo;
650 		int j;
651 		on = (struct ocg *)n;
652 		oo = (struct ocg *)o;
653 		for(i = 0; i < 8; i++) {
654 			on->cg_frsum[i] = bswap32(oo->cg_frsum[i]);
655 		}
656 		for(i = 0; i < 32; i++) {
657 			on->cg_btot[i] = bswap32(oo->cg_btot[i]);
658 			for (j = 0; j < 8; j++)
659 				on->cg_b[i][j] = bswap16(oo->cg_b[i][j]);
660 		}
661 		memmove(on->cg_iused, oo->cg_iused, 256);
662 		on->cg_magic = bswap32(oo->cg_magic);
663 	} else {  /* new format */
664 		if (n->cg_magic == CG_MAGIC) {
665 			n32 = (u_int32_t*)((u_int8_t*)n + n->cg_btotoff);
666 			o32 = (u_int32_t*)((u_int8_t*)o + n->cg_btotoff);
667 			n16 = (u_int16_t*)((u_int8_t*)n + n->cg_boff);
668 			o16 = (u_int16_t*)((u_int8_t*)o + n->cg_boff);
669 		} else {
670 			n32 = (u_int32_t*)((u_int8_t*)n + o->cg_btotoff);
671 			o32 = (u_int32_t*)((u_int8_t*)o + o->cg_btotoff);
672 			n16 = (u_int16_t*)((u_int8_t*)n + o->cg_boff);
673 			o16 = (u_int16_t*)((u_int8_t*)o + o->cg_boff);
674 		}
675 		for (i=0; i < sblock->fs_cpg; i++)
676 			n32[i] = bswap32(o32[i]);
677 
678 		for (i=0; i < sblock->fs_cpg * sblock->fs_nrpos; i++)
679 			n16[i] = bswap16(o16[i]);
680 
681 		if (n->cg_magic == CG_MAGIC) {
682 			n32 = (u_int32_t*)((u_int8_t*)n + n->cg_clustersumoff);
683 			o32 = (u_int32_t*)((u_int8_t*)o + n->cg_clustersumoff);
684 		} else {
685 			n32 = (u_int32_t*)((u_int8_t*)n + o->cg_clustersumoff);
686 			o32 = (u_int32_t*)((u_int8_t*)o + o->cg_clustersumoff);
687 		}
688 		for (i = 1; i < sblock->fs_contigsumsize + 1; i++)
689 			n32[i] = bswap32(o32[i]);
690 	}
691 }
692 
693 void
694 infohandler(int sig)
695 {
696 	got_siginfo = 1;
697 }
698 
699