bozo: Introduce bnode_Wait()
[openafs.git] / src / vfsck / pass3.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
27 #ifdef AFS_VFSINCL_ENV
28 #include <sys/vnode.h>
29 #ifdef    AFS_SUN5_ENV
30 #include <sys/fs/ufs_inode.h>
31 #include <sys/fs/ufs_fs.h>
32 #define _KERNEL
33 #include <sys/fs/ufs_fsdir.h>
34 #undef _KERNEL
35 #include <sys/fs/ufs_mount.h>
36 #else
37 #include <ufs/inode.h>
38 #include <ufs/fs.h>
39 #endif
40 #else /* AFS_VFSINCL_ENV */
41 #include <sys/inode.h>
42 #ifdef  AFS_HPUX_ENV
43 #define LONGFILENAMES   1
44 #include <sys/sysmacros.h>
45 #include <sys/ino.h>
46 #endif
47 #include <sys/fs.h>
48 #endif /* AFS_VFSINCL_ENV */
49
50 #include <afs/osi_inode.h>
51 #include "fsck.h"
52
53 int pass2check();
54
55 pass3()
56 {
57     struct dinode *dp;
58     struct inodesc idesc;
59     ino_t inumber, orphan;
60     int loopcnt;
61
62     memset(&idesc, 0, sizeof(struct inodesc));
63     idesc.id_type = DATA;
64     for (inumber = ROOTINO; inumber <= lastino; inumber++) {
65 #if defined(ACLS) && defined(AFS_HPUX_ENV)
66         if (statemap[inumber] & HASCINODE) {
67             if ((dp = ginode(inumber)) == NULL)
68                 break;
69             /*
70              * Make sure di_contin is not out of range and then
71              * check and make sure that the inode #di_contin
72              * is a continuation inode that has not already been
73              * referenced.
74              */
75             if ((dp->di_contin < ROOTINO || dp->di_contin > maxino)
76                 || ((statemap[dp->di_contin] & STATE) != CSTATE)) {
77                 /*  this is an error which must be cleared by hand. */
78                 pfatal("BAD CONTINUATION INODE NUMBER ");
79                 printf(" I=%u ", inumber);
80                 if (reply("CLEAR") == 1) {
81                     dp->di_contin = 0;
82                     inodirty();
83                 }
84             } else {
85                 statemap[dp->di_contin] = CRSTATE;
86             }
87         }
88         if ((statemap[inumber] & STATE) == DSTATE) {
89 #else /* no ACLS */
90         if (statemap[inumber] == DSTATE) {
91 #endif /* ACLS */
92             pathp = pathname;
93             *pathp++ = '?';
94             *pathp = '\0';
95             idesc.id_func = findino;
96             idesc.id_name = "..";
97             idesc.id_parent = inumber;
98             loopcnt = 0;
99             do {
100                 orphan = idesc.id_parent;
101                 if (orphan < ROOTINO || orphan > maxino)
102                     break;
103                 dp = ginode(orphan);
104                 idesc.id_parent = 0;
105                 idesc.id_number = orphan;
106                 if ((ckinode(dp, &idesc) & FOUND) == 0)
107                     break;
108                 if (loopcnt >= sblock.fs_cstotal.cs_ndir)
109                     break;
110                 loopcnt++;
111 #if defined(ACLS) && defined(AFS_HPUX_ENV)
112             } while ((statemap[idesc.id_parent] & STATE) == DSTATE);
113 #else /* no ACLS */
114             } while (statemap[idesc.id_parent] == DSTATE);
115 #endif /* ACLS */
116             if (linkup(orphan, idesc.id_parent) == 1) {
117                 idesc.id_func = pass2check;
118                 idesc.id_number = lfdir;
119                 descend(&idesc, orphan);
120             }
121         }
122     }
123 }