1 /* $NetBSD: pass4.c,v 1.15 2006/09/01 19:52:48 perseant Exp $ */
4 * Copyright (c) 1980, 1986, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/param.h>
34 #include <sys/mount.h>
35 #include <ufs/ufs/inode.h>
39 #define panic call_panic
40 #include <ufs/lfs/lfs.h>
54 extern SEGUSE
*seg_table
;
56 static int check_orphan(struct inodesc
*idp
);
59 check_orphan(struct inodesc
*idp
)
62 ino_t inumber
= idp
->id_number
;
64 for (zlnp
= orphead
; zlnp
; zlnp
= zlnp
->next
) {
65 if (zlnp
->zlncnt
== inumber
) {
66 /* Swap this with head */
67 zlnp
->zlncnt
= orphead
->zlncnt
;
69 orphead
= orphead
->next
;
72 clri(idp
, "PROPERLY ORPHANED", 1);
84 struct ufs1_dinode
*dp
;
88 memset(&idesc
, 0, sizeof(struct inodesc
));
90 idesc
.id_func
= pass4check
;
91 for (inumber
= ROOTINO
; inumber
<= lastino
; inumber
++) {
92 idesc
.id_number
= inumber
;
93 switch (statemap
[inumber
]) {
99 adjust(&idesc
, (short) n
);
101 for (zlnp
= zlnhead
; zlnp
; zlnp
= zlnp
->next
)
102 if (zlnp
->zlncnt
== inumber
) {
103 zlnp
->zlncnt
= zlnhead
->zlncnt
;
105 zlnhead
= zlnhead
->next
;
107 clri(&idesc
, "UNREF", 1);
114 clri(&idesc
, "UNREF", 1);
118 if (check_orphan(&idesc
))
120 dp
= ginode(inumber
);
121 if (dp
->di_size
== 0) {
122 const char * msg
= (lncntp
[inumber
] ?
123 "ZERO LENGTH" : "UNREF ZERO LENGTH");
124 clri(&idesc
, msg
, 1);
127 clri(&idesc
, "BAD/DUP", 1);
131 if (check_orphan(&idesc
))
133 clri(&idesc
, "BAD/DUP", 1);
140 err(EEXIT
, "BAD STATE %d FOR INODE I=%llu\n",
141 statemap
[inumber
], (unsigned long long)inumber
);
147 pass4check(struct inodesc
* idesc
)
150 int ndblks
, res
= KEEPON
;
151 daddr_t blkno
= idesc
->id_blkno
;
156 sn
= dtosn(fs
, blkno
);
157 for (ndblks
= fragstofsb(fs
, idesc
->id_numfrags
); ndblks
> 0; blkno
++, ndblks
--) {
158 if (chkrange(blkno
, 1)) {
160 } else if (testbmap(blkno
) || preen
) {
161 for (dlp
= duplist
; dlp
; dlp
= dlp
->next
) {
162 if (dlp
->dup
!= blkno
)
164 dlp
->dup
= duplist
->dup
;
166 duplist
= duplist
->next
;
172 LFS_SEGENTRY(sup
, fs
, sn
, bp
);
173 sup
->su_nbytes
-= fsbtob(fs
, 1);
175 seg_table
[sn
].su_nbytes
-= fsbtob(fs
, 1);