death to register
[openafs.git] / src / vfsck / pass4.c
1 /*
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.
16  */
17
18 #include <afsconfig.h>
19 #include <afs/param.h>
20
21
22 #define VICE
23 #include <sys/param.h>
24 #include <sys/time.h>
25 #ifdef  AFS_OSF_ENV
26 #include <sys/vnode.h>
27 #include <sys/mount.h>
28 #include <ufs/inode.h>
29 #include <ufs/fs.h>
30 #define _BSD
31 #define _KERNEL
32 #include <ufs/dir.h>
33 #undef  _KERNEL
34 #undef  _BSD
35 #include <stdio.h>
36 #else /* AFS_OSF_ENV */
37 #ifdef AFS_VFSINCL_ENV
38 #include <sys/vnode.h>
39 #ifdef    AFS_SUN5_ENV
40 #include <stdio.h>
41 #include <unistd.h>
42 #include <sys/fs/ufs_inode.h>
43 #include <sys/fs/ufs_fs.h>
44 #define _KERNEL
45 #include <sys/fs/ufs_fsdir.h>
46 #undef _KERNEL
47 #include <sys/fs/ufs_mount.h>
48 #else
49 #include <ufs/inode.h>
50 #include <ufs/fs.h>
51 #endif
52 #else /* AFS_VFSINCL_ENV */
53 #include <sys/inode.h>
54 #ifdef  AFS_HPUX_ENV
55 #include <ctype.h>
56 #define LONGFILENAMES   1
57 #include <sys/sysmacros.h>
58 #include <sys/ino.h>
59 #endif
60 #include <sys/fs.h>
61 #endif /* AFS_VFSINCL_ENV */
62 #endif /* AFS_OSF_ENV */
63 #include <afs/osi_inode.h>
64
65 #include "fsck.h"
66
67 int pass4check();
68
69 pass4()
70 {
71     ino_t inumber;
72     struct zlncnt *zlnp;
73     struct inodesc idesc;
74     int n;
75 #if defined(ACLS) && defined(AFS_HPUX_ENV)
76     struct dinode *dp;
77 #endif /* ACLS */
78
79
80     memset(&idesc, 0, sizeof(struct inodesc));
81     idesc.id_type = ADDR;
82     idesc.id_func = pass4check;
83     for (inumber = ROOTINO; inumber <= lastino; inumber++) {
84         idesc.id_number = inumber;
85 #if defined(ACLS) && defined(AFS_HPUX_ENV)
86         switch (statemap[inumber] & STATE) {
87 #else /* no ACLS */
88         switch (statemap[inumber]) {
89 #endif /* ACLS */
90
91         case FSTATE:
92         case DFOUND:
93             n = lncntp[inumber];
94             if (n)
95                 adjust(&idesc, (short)n);
96             else {
97                 for (zlnp = zlnhead; zlnp; zlnp = zlnp->next)
98                     if (zlnp->zlncnt == inumber) {
99                         zlnp->zlncnt = zlnhead->zlncnt;
100                         zlnp = zlnhead;
101                         zlnhead = zlnhead->next;
102                         free((char *)zlnp);
103                         clri(&idesc, "UNREF", 1);
104                         break;
105                     }
106             }
107             break;
108
109 #ifdef VICE
110         case VSTATE:
111             nViceFiles++;
112             break;
113 #endif /* VICE */
114
115         case DSTATE:
116             clri(&idesc, "UNREF", 1);
117             break;
118
119         case DCLEAR:
120         case FCLEAR:
121             clri(&idesc, "BAD/DUP", 1);
122             break;
123
124         case USTATE:
125             break;
126
127 #if defined(ACLS) && defined(AFS_HPUX_ENV)
128             /* 
129              * UNreferenced continuation inode 
130              */
131         case CSTATE:
132             clri(&idesc, "UNREF", 2);
133             break;
134
135             /* 
136              * referenced continuation inode 
137              */
138         case CRSTATE:
139             if ((dp = ginode(inumber)) == NULL)
140                 break;
141             if (dp->di_nlink != 1)
142                 if (!qflag) {
143                     pwarn("BAD LINK COUNT IN CONTINUATION INODE ");
144                     pwarn("I=%u (%ld should be %ld)", inumber, dp->di_nlink,
145                           1);
146                     if (preen)
147 #ifdef VICE
148                         vprintf(" (CORRECTED)\n");
149 #else
150                         printf(" (CORRECTED)\n");
151 #endif /* VICE */
152                     else {
153                         if (reply("CORRECT") == 0)
154                             continue;
155                     }
156                     dp->di_nlink = 1;
157                     inodirty();
158                 }
159             break;
160 #endif /* ACLS */
161
162         default:
163             errexit("BAD STATE %d FOR INODE I=%d", statemap[inumber],
164                     inumber);
165         }
166     }
167 }
168
169 pass4check(idesc)
170      struct inodesc *idesc;
171 {
172     struct dups *dlp;
173     int nfrags, res = KEEPON;
174     daddr_t blkno = idesc->id_blkno;
175
176     for (nfrags = idesc->id_numfrags; nfrags > 0; blkno++, nfrags--) {
177         if (chkrange(blkno, 1)) {
178             res = SKIP;
179         } else if (testbmap(blkno)) {
180             for (dlp = duplist; dlp; dlp = dlp->next) {
181                 if (dlp->dup != blkno)
182                     continue;
183                 dlp->dup = duplist->dup;
184                 dlp = duplist;
185                 duplist = duplist->next;
186                 free((char *)dlp);
187                 break;
188             }
189             if (dlp == 0) {
190                 clrbmap(blkno);
191                 n_blks--;
192             }
193         }
194     }
195     return (res);
196 }