Commit | Line | Data |
---|---|---|
76797561 DF |
1 | /* |
2 | * Copyright (c) 1980 Regents of the University of California. | |
3 | * All rights reserved. The Berkeley software License Agreement | |
4 | * specifies the terms and conditions for redistribution. | |
5 | */ | |
6 | ||
577b7874 | 7 | #ifndef lint |
ea4448dc | 8 | static char sccsid[] = "@(#)pass4.c 5.3 (Berkeley) %G%"; |
76797561 | 9 | #endif not lint |
577b7874 KM |
10 | |
11 | #include <sys/param.h> | |
12 | #include <sys/inode.h> | |
13 | #include <sys/fs.h> | |
14 | #include "fsck.h" | |
15 | ||
16 | int pass4check(); | |
17 | ||
18 | pass4() | |
19 | { | |
82dc9a9e KM |
20 | register ino_t inumber; |
21 | register struct zlncnt *zlnp; | |
577b7874 | 22 | struct inodesc idesc; |
82dc9a9e | 23 | int n; |
577b7874 KM |
24 | |
25 | bzero((char *)&idesc, sizeof(struct inodesc)); | |
26 | idesc.id_type = ADDR; | |
27 | idesc.id_func = pass4check; | |
28 | for (inumber = ROOTINO; inumber <= lastino; inumber++) { | |
29 | idesc.id_number = inumber; | |
30 | switch (statemap[inumber]) { | |
31 | ||
32 | case FSTATE: | |
993a756c | 33 | case DFOUND: |
577b7874 KM |
34 | n = lncntp[inumber]; |
35 | if (n) | |
36 | adjust(&idesc, (short)n); | |
37 | else { | |
82dc9a9e KM |
38 | for (zlnp = zlnhead; zlnp; zlnp = zlnp->next) |
39 | if (zlnp->zlncnt == inumber) { | |
1a02fd3a KM |
40 | zlnp->zlncnt = zlnhead->zlncnt; |
41 | zlnp = zlnhead; | |
42 | zlnhead = zlnhead->next; | |
43 | free(zlnp); | |
577b7874 KM |
44 | clri(&idesc, "UNREF", 1); |
45 | break; | |
46 | } | |
47 | } | |
48 | break; | |
49 | ||
50 | case DSTATE: | |
51 | clri(&idesc, "UNREF", 1); | |
52 | break; | |
53 | ||
993a756c KM |
54 | case DCLEAR: |
55 | case FCLEAR: | |
577b7874 KM |
56 | clri(&idesc, "BAD/DUP", 1); |
57 | break; | |
ea4448dc KM |
58 | |
59 | case USTATE: | |
60 | break; | |
61 | ||
62 | default: | |
63 | errexit("BAD STATE %d FOR INODE I=%d", | |
64 | statemap[inumber], inumber); | |
577b7874 KM |
65 | } |
66 | } | |
577b7874 KM |
67 | } |
68 | ||
69 | pass4check(idesc) | |
70 | register struct inodesc *idesc; | |
71 | { | |
62e6c152 | 72 | register struct dups *dlp; |
577b7874 KM |
73 | int nfrags, res = KEEPON; |
74 | daddr_t blkno = idesc->id_blkno; | |
75 | ||
76 | for (nfrags = idesc->id_numfrags; nfrags > 0; blkno++, nfrags--) { | |
62e6c152 | 77 | if (outrange(blkno, 1)) { |
577b7874 | 78 | res = SKIP; |
62e6c152 KM |
79 | } else if (getbmap(blkno)) { |
80 | for (dlp = duplist; dlp; dlp = dlp->next) { | |
81 | if (dlp->dup != blkno) | |
82 | continue; | |
83 | dlp->dup = duplist->dup; | |
84 | dlp = duplist; | |
85 | duplist = duplist->next; | |
1a02fd3a | 86 | free(dlp); |
62e6c152 KM |
87 | break; |
88 | } | |
89 | if (dlp == 0) { | |
90 | clrbmap(blkno); | |
91 | n_blks--; | |
92 | } | |
577b7874 KM |
93 | } |
94 | } | |
95 | return (res); | |
96 | } |