pass1b.c revision 1.15
1/*	$OpenBSD: pass1b.c,v 1.15 2007/06/25 19:59:55 otto Exp $	*/
2/*	$NetBSD: pass1b.c,v 1.10 1996/09/23 16:18:37 christos Exp $	*/
3
4/*
5 * Copyright (c) 1980, 1986, 1993
6 *	The Regents of the University of California.  All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 *    may be used to endorse or promote products derived from this software
18 *    without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33#ifndef lint
34#if 0
35static char sccsid[] = "@(#)pass1b.c	8.1 (Berkeley) 6/5/93";
36#else
37static const char rcsid[] = "$OpenBSD: pass1b.c,v 1.15 2007/06/25 19:59:55 otto Exp $";
38#endif
39#endif /* not lint */
40
41#include <sys/param.h>
42#include <sys/time.h>
43#include <ufs/ufs/dinode.h>
44#include <ufs/ffs/fs.h>
45
46#include <stdio.h>
47#include <string.h>
48#include "fsck.h"
49#include "extern.h"
50
51static int	pass1bcheck(struct inodesc *);
52static struct dups *duphead;
53
54static ino_t info_inumber;
55
56static int
57pass1b_info(char *buf, size_t buflen)
58{
59	return (snprintf(buf, buflen, "phase 1b, inode %d/%d",
60	    info_inumber, sblock.fs_ipg * sblock.fs_ncg) > 0);
61}
62
63void
64pass1b(void)
65{
66	int c, i;
67	union dinode *dp;
68	struct inodesc idesc;
69	ino_t inumber;
70
71	memset(&idesc, 0, sizeof(struct inodesc));
72	idesc.id_type = ADDR;
73	idesc.id_func = pass1bcheck;
74	duphead = duplist;
75	inumber = 0;
76	info_fn = pass1b_info;
77	for (c = 0; c < sblock.fs_ncg; c++) {
78		for (i = 0; i < sblock.fs_ipg; i++, inumber++) {
79			info_inumber = inumber;
80			if (inumber < ROOTINO)
81				continue;
82			dp = ginode(inumber);
83			if (dp == NULL)
84				continue;
85			idesc.id_number = inumber;
86			if (statemap[inumber] != USTATE &&
87			    (ckinode(dp, &idesc) & STOP))
88				return;
89		}
90	}
91	info_fn = NULL;
92}
93
94static int
95pass1bcheck(struct inodesc *idesc)
96{
97	struct dups *dlp;
98	int nfrags, res = KEEPON;
99	daddr64_t blkno = idesc->id_blkno;
100
101	for (nfrags = idesc->id_numfrags; nfrags > 0; blkno++, nfrags--) {
102		if (chkrange(blkno, 1))
103			res = SKIP;
104		for (dlp = duphead; dlp; dlp = dlp->next) {
105			if (dlp->dup == blkno) {
106				blkerror(idesc->id_number, "DUP", blkno);
107				dlp->dup = duphead->dup;
108				duphead->dup = blkno;
109				duphead = duphead->next;
110			}
111			if (dlp == muldup)
112				break;
113		}
114		if (muldup == 0 || duphead == muldup->next)
115			return (STOP);
116	}
117	return (res);
118}
119