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