Commit | Line | Data |
---|---|---|
76797561 | 1 | /* |
fe32782c KM |
2 | * Copyright (c) 1980, 1986 The Regents of the University of California. |
3 | * All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms are permitted | |
6 | * provided that the above copyright notice and this paragraph are | |
7 | * duplicated in all such forms and that any documentation, | |
8 | * advertising materials, and other materials related to such | |
9 | * distribution and use acknowledge that the software was developed | |
10 | * by the University of California, Berkeley. The name of the | |
11 | * University may not be used to endorse or promote products derived | |
12 | * from this software without specific prior written permission. | |
13 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
14 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
15 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
76797561 DF |
16 | */ |
17 | ||
577b7874 | 18 | #ifndef lint |
dbf20d0a | 19 | static char sccsid[] = "@(#)pass4.c 5.8 (Berkeley) %G%"; |
fe32782c | 20 | #endif /* not lint */ |
577b7874 KM |
21 | |
22 | #include <sys/param.h> | |
72e5286b | 23 | #include <ufs/dinode.h> |
4d7f4685 | 24 | #include <ufs/fs.h> |
577b7874 KM |
25 | #include "fsck.h" |
26 | ||
27 | int pass4check(); | |
28 | ||
29 | pass4() | |
30 | { | |
82dc9a9e KM |
31 | register ino_t inumber; |
32 | register struct zlncnt *zlnp; | |
dbf20d0a | 33 | struct dinode *dp; |
577b7874 | 34 | struct inodesc idesc; |
82dc9a9e | 35 | int n; |
577b7874 KM |
36 | |
37 | bzero((char *)&idesc, sizeof(struct inodesc)); | |
38 | idesc.id_type = ADDR; | |
39 | idesc.id_func = pass4check; | |
40 | for (inumber = ROOTINO; inumber <= lastino; inumber++) { | |
41 | idesc.id_number = inumber; | |
42 | switch (statemap[inumber]) { | |
43 | ||
44 | case FSTATE: | |
993a756c | 45 | case DFOUND: |
577b7874 KM |
46 | n = lncntp[inumber]; |
47 | if (n) | |
48 | adjust(&idesc, (short)n); | |
49 | else { | |
82dc9a9e KM |
50 | for (zlnp = zlnhead; zlnp; zlnp = zlnp->next) |
51 | if (zlnp->zlncnt == inumber) { | |
1a02fd3a KM |
52 | zlnp->zlncnt = zlnhead->zlncnt; |
53 | zlnp = zlnhead; | |
54 | zlnhead = zlnhead->next; | |
569ec282 | 55 | free((char *)zlnp); |
577b7874 KM |
56 | clri(&idesc, "UNREF", 1); |
57 | break; | |
58 | } | |
59 | } | |
60 | break; | |
61 | ||
62 | case DSTATE: | |
63 | clri(&idesc, "UNREF", 1); | |
64 | break; | |
65 | ||
993a756c | 66 | case DCLEAR: |
dbf20d0a KM |
67 | dp = ginode(inumber); |
68 | if (dp->di_size == 0) { | |
69 | clri(&idesc, "ZERO LENGTH", 1); | |
70 | break; | |
71 | } | |
72 | /* fall through */ | |
993a756c | 73 | case FCLEAR: |
577b7874 KM |
74 | clri(&idesc, "BAD/DUP", 1); |
75 | break; | |
ea4448dc KM |
76 | |
77 | case USTATE: | |
78 | break; | |
79 | ||
80 | default: | |
81 | errexit("BAD STATE %d FOR INODE I=%d", | |
82 | statemap[inumber], inumber); | |
577b7874 KM |
83 | } |
84 | } | |
577b7874 KM |
85 | } |
86 | ||
87 | pass4check(idesc) | |
88 | register struct inodesc *idesc; | |
89 | { | |
62e6c152 | 90 | register struct dups *dlp; |
577b7874 KM |
91 | int nfrags, res = KEEPON; |
92 | daddr_t blkno = idesc->id_blkno; | |
93 | ||
94 | for (nfrags = idesc->id_numfrags; nfrags > 0; blkno++, nfrags--) { | |
569ec282 | 95 | if (chkrange(blkno, 1)) { |
577b7874 | 96 | res = SKIP; |
569ec282 | 97 | } else if (testbmap(blkno)) { |
62e6c152 KM |
98 | for (dlp = duplist; dlp; dlp = dlp->next) { |
99 | if (dlp->dup != blkno) | |
100 | continue; | |
101 | dlp->dup = duplist->dup; | |
102 | dlp = duplist; | |
103 | duplist = duplist->next; | |
569ec282 | 104 | free((char *)dlp); |
62e6c152 KM |
105 | break; |
106 | } | |
107 | if (dlp == 0) { | |
108 | clrbmap(blkno); | |
109 | n_blks--; | |
110 | } | |
577b7874 KM |
111 | } |
112 | } | |
113 | return (res); | |
114 | } |