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