1 /* $NetBSD: pass0.c,v 1.30 2007/10/08 21:39:49 ad Exp $ */
4 * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Konrad E. Schroder <perseant@hhhh.org>.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 * Copyright (c) 1980, 1986, 1993
33 * The Regents of the University of California. All rights reserved.
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
38 * 1. Redistributions of source code must retain the above copyright
39 * notice, this list of conditions and the following disclaimer.
40 * 2. Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
43 * 3. Neither the name of the University nor the names of its contributors
44 * may be used to endorse or promote products derived from this software
45 * without specific prior written permission.
47 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
48 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 #include <sys/types.h>
61 #include <sys/param.h>
64 #include <sys/mount.h>
66 #include <ufs/ufs/inode.h>
67 #include <ufs/ufs/dir.h>
69 #include <ufs/lfs/lfs.h>
87 extern int fake_cleanseg
;
90 * Pass 0. Check the LFS partial segments for valid checksums, correcting
91 * if necessary. Also check for valid offsets for inode and finfo blocks.
94 * XXX more could be done here---consistency between inode-held blocks and
95 * finfo blocks, for one thing.
98 #define dbshift (fs->lfs_bshift - fs->lfs_blktodb)
106 struct ubuf
*bp
, *cbp
;
107 ino_t ino
, plastino
, nextino
, lowfreeino
, freehd
;
112 * Check the inode free list for inuse inodes, and cycles.
113 * Make sure that all free inodes are in fact on the list.
115 visited
= ecalloc(maxino
, sizeof(*visited
));
118 LFS_CLEANERINFO(cip
, fs
, cbp
);
119 freehd
= ino
= cip
->free_head
;
123 if (lowfreeino
> ino
)
126 pwarn("OUT OF RANGE INO %llu ON FREE LIST\n",
127 (unsigned long long)ino
);
131 pwarn("INO %llu ALREADY FOUND ON FREE LIST\n",
132 (unsigned long long)ino
);
133 if (preen
|| reply("FIX") == 1) {
134 /* plastino can't be zero */
135 LFS_IENTRY(ifp
, fs
, plastino
, bp
);
136 ifp
->if_nextfree
= 0;
142 LFS_IENTRY(ifp
, fs
, ino
, bp
);
143 nextino
= ifp
->if_nextfree
;
144 daddr
= ifp
->if_daddr
;
147 pwarn("INO %llu WITH DADDR 0x%llx ON FREE LIST\n",
148 (unsigned long long)ino
, (long long) daddr
);
149 if (preen
|| reply("FIX") == 1) {
154 LFS_IENTRY(ifp
, fs
, plastino
, bp
);
155 ifp
->if_nextfree
= nextino
;
168 * Make sure all free inodes were found on the list
170 for (ino
= maxino
- 1; ino
> ROOTINO
; --ino
) {
174 LFS_IENTRY(ifp
, fs
, ino
, bp
);
179 pwarn("INO %llu FREE BUT NOT ON FREE LIST\n",
180 (unsigned long long)ino
);
181 if (preen
|| reply("FIX") == 1) {
182 assert(ino
!= freehd
);
183 ifp
->if_nextfree
= freehd
;
189 /* If freelist was empty, this is the tail */
196 LFS_CLEANERINFO(cip
, fs
, cbp
);
197 if (cip
->free_head
!= freehd
) {
198 /* They've already given us permission for this change */
199 cip
->free_head
= freehd
;
202 if (freehd
!= fs
->lfs_freehd
) {
203 pwarn("FREE LIST HEAD IN SUPERBLOCK SHOULD BE %d (WAS %d)\n",
204 (int)fs
->lfs_freehd
, (int)freehd
);
205 if (preen
|| reply("FIX")) {
206 fs
->lfs_freehd
= freehd
;
210 if (cip
->free_tail
!= plastino
) {
211 pwarn("FREE LIST TAIL SHOULD BE %llu (WAS %llu)\n",
212 (unsigned long long)plastino
,
213 (unsigned long long)cip
->free_tail
);
214 if (preen
|| reply("FIX")) {
215 cip
->free_tail
= plastino
;
221 LFS_SYNC_CLEANERINFO(cip
, fs
, cbp
, writeit
);
225 if (fs
->lfs_freehd
== 0) {
226 pwarn("%sree list head is 0x0\n", preen
? "f" : "F");
227 if (preen
|| reply("FIX"))