pass4.c revision 1.3 1 1.3 perseant /* $NetBSD: pass4.c,v 1.3 2000/05/23 01:48:55 perseant Exp $ */
2 1.1 perseant
3 1.1 perseant /*
4 1.1 perseant * Copyright (c) 1980, 1986, 1993
5 1.1 perseant * The Regents of the University of California. All rights reserved.
6 1.1 perseant *
7 1.1 perseant * Redistribution and use in source and binary forms, with or without
8 1.1 perseant * modification, are permitted provided that the following conditions
9 1.1 perseant * are met:
10 1.1 perseant * 1. Redistributions of source code must retain the above copyright
11 1.1 perseant * notice, this list of conditions and the following disclaimer.
12 1.1 perseant * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 perseant * notice, this list of conditions and the following disclaimer in the
14 1.1 perseant * documentation and/or other materials provided with the distribution.
15 1.1 perseant * 3. All advertising materials mentioning features or use of this software
16 1.1 perseant * must display the following acknowledgement:
17 1.1 perseant * This product includes software developed by the University of
18 1.1 perseant * California, Berkeley and its contributors.
19 1.1 perseant * 4. Neither the name of the University nor the names of its contributors
20 1.1 perseant * may be used to endorse or promote products derived from this software
21 1.1 perseant * without specific prior written permission.
22 1.1 perseant *
23 1.1 perseant * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 1.1 perseant * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.1 perseant * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.1 perseant * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 1.1 perseant * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.1 perseant * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.1 perseant * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.1 perseant * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.1 perseant * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.1 perseant * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.1 perseant * SUCH DAMAGE.
34 1.1 perseant */
35 1.1 perseant
36 1.1 perseant #include <sys/param.h>
37 1.1 perseant #include <sys/time.h>
38 1.1 perseant #include <ufs/ufs/dinode.h>
39 1.1 perseant #include <sys/mount.h>
40 1.1 perseant #include <ufs/lfs/lfs.h>
41 1.1 perseant #include <stdlib.h>
42 1.1 perseant #include <string.h>
43 1.1 perseant
44 1.1 perseant #include "fsutil.h"
45 1.1 perseant #include "fsck.h"
46 1.1 perseant #include "extern.h"
47 1.1 perseant
48 1.1 perseant void
49 1.1 perseant pass4()
50 1.1 perseant {
51 1.3 perseant register ino_t inumber;
52 1.1 perseant register struct zlncnt *zlnp;
53 1.3 perseant struct dinode *dp;
54 1.3 perseant struct inodesc idesc;
55 1.3 perseant int n;
56 1.1 perseant
57 1.1 perseant memset(&idesc, 0, sizeof(struct inodesc));
58 1.1 perseant idesc.id_type = ADDR;
59 1.1 perseant idesc.id_func = pass4check;
60 1.1 perseant for (inumber = ROOTINO; inumber <= lastino; inumber++) {
61 1.1 perseant idesc.id_number = inumber;
62 1.1 perseant switch (statemap[inumber]) {
63 1.1 perseant
64 1.1 perseant case FSTATE:
65 1.1 perseant case DFOUND:
66 1.1 perseant n = lncntp[inumber];
67 1.1 perseant if (n)
68 1.1 perseant adjust(&idesc, (short)n);
69 1.1 perseant else {
70 1.1 perseant for (zlnp = zlnhead; zlnp; zlnp = zlnp->next)
71 1.1 perseant if (zlnp->zlncnt == inumber) {
72 1.1 perseant zlnp->zlncnt = zlnhead->zlncnt;
73 1.1 perseant zlnp = zlnhead;
74 1.1 perseant zlnhead = zlnhead->next;
75 1.1 perseant free((char *)zlnp);
76 1.1 perseant clri(&idesc, "UNREF", 1);
77 1.1 perseant break;
78 1.1 perseant }
79 1.1 perseant }
80 1.1 perseant break;
81 1.1 perseant
82 1.1 perseant case DSTATE:
83 1.1 perseant clri(&idesc, "UNREF", 1);
84 1.1 perseant break;
85 1.1 perseant
86 1.1 perseant case DCLEAR:
87 1.1 perseant dp = ginode(inumber);
88 1.1 perseant if (dp->di_size == 0) {
89 1.1 perseant clri(&idesc, "ZERO LENGTH", 1);
90 1.1 perseant break;
91 1.1 perseant }
92 1.1 perseant /* fall through */
93 1.1 perseant case FCLEAR:
94 1.1 perseant clri(&idesc, "BAD/DUP", 1);
95 1.1 perseant break;
96 1.1 perseant
97 1.1 perseant case USTATE:
98 1.1 perseant break;
99 1.1 perseant
100 1.1 perseant default:
101 1.1 perseant errexit("BAD STATE %d FOR INODE I=%d",
102 1.3 perseant statemap[inumber], inumber);
103 1.1 perseant }
104 1.1 perseant }
105 1.1 perseant }
106 1.1 perseant
107 1.1 perseant int
108 1.3 perseant pass4check(struct inodesc * idesc)
109 1.1 perseant {
110 1.1 perseant register struct dups *dlp;
111 1.3 perseant int nfrags, res = KEEPON;
112 1.3 perseant daddr_t blkno = idesc->id_blkno;
113 1.1 perseant
114 1.1 perseant for (nfrags = idesc->id_numfrags; nfrags > 0; blkno++, nfrags--) {
115 1.1 perseant if (chkrange(blkno, 1)) {
116 1.1 perseant res = SKIP;
117 1.1 perseant } else if (testbmap(blkno)) {
118 1.1 perseant for (dlp = duplist; dlp; dlp = dlp->next) {
119 1.1 perseant if (dlp->dup != blkno)
120 1.1 perseant continue;
121 1.1 perseant dlp->dup = duplist->dup;
122 1.1 perseant dlp = duplist;
123 1.1 perseant duplist = duplist->next;
124 1.1 perseant free((char *)dlp);
125 1.1 perseant break;
126 1.1 perseant }
127 1.1 perseant if (dlp == 0) {
128 1.1 perseant clrbmap(blkno);
129 1.1 perseant n_blks--;
130 1.1 perseant }
131 1.1 perseant }
132 1.1 perseant }
133 1.1 perseant return (res);
134 1.1 perseant }
135