Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / vfsck / pass1b.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_OSF_ENV
27 #include <sys/vnode.h>
28 #include <sys/mount.h>
29 #include <ufs/inode.h>
30 #include <ufs/fs.h>
31 #define _BSD
32 #define _KERNEL
33 #include <ufs/dir.h>
34 #undef _KERNEL
35 #undef _BSD
36 #else /* AFS_OSF_ENV */
37 #ifdef AFS_VFSINCL_ENV
38 #include <sys/vnode.h>
39 #ifdef AFS_SUN5_ENV
40 #include <sys/fs/ufs_inode.h>
41 #include <sys/fs/ufs_fs.h>
42 #define _KERNEL
43 #include <sys/fs/ufs_fsdir.h>
44 #undef _KERNEL
45 #include <sys/fs/ufs_mount.h>
46 #else
47 #include <ufs/inode.h>
48 #include <ufs/fs.h>
49 #endif
50 #else /* AFS_VFSINCL_ENV */
51 #include <sys/inode.h>
52 #ifdef AFS_HPUX_ENV
53 #define LONGFILENAMES 1
54 #include <sys/sysmacros.h>
55 #include <sys/ino.h>
56 #endif
57 #include <sys/fs.h>
58 #endif /* AFS_VFSINCL_ENV */
59 #endif /* AFS_OSF_ENV */
60
61 #include "fsck.h"
62
63 int pass1bcheck();
64 static struct dups *duphead;
65
66 pass1b()
67 {
68 int c, i;
69 struct dinode *dp;
70 struct inodesc idesc;
71 ino_t inumber;
72
73 memset(&idesc, 0, sizeof(struct inodesc));
74 idesc.id_type = ADDR;
75 idesc.id_func = pass1bcheck;
76 duphead = duplist;
77 inumber = 0;
78 for (c = 0; c < sblock.fs_ncg; c++) {
79 for (i = 0; i < sblock.fs_ipg; i++, inumber++) {
80 if (inumber < ROOTINO)
81 continue;
82 dp = ginode(inumber);
83 if (dp == NULL)
84 continue;
85 idesc.id_number = inumber;
86 #ifdef AFS_SUN5_ENV
87 idesc.id_fix = DONTKNOW;
88 #endif
89 #if defined(ACLS) && defined(AFS_HPUX_ENV)
90 if (((statemap[inumber] & STATE) != USTATE) &&
91 #else /* not ACLS */
92 if (statemap[inumber] != USTATE &&
93 #endif /* ACLS */
94 (ckinode(dp, &idesc) & STOP))
95 return;
96 }
97 }
98 }
99
100 pass1bcheck(idesc)
101 struct inodesc *idesc;
102 {
103 struct dups *dlp;
104 int nfrags, res = KEEPON;
105 daddr_t blkno = idesc->id_blkno;
106
107 for (nfrags = idesc->id_numfrags; nfrags > 0; blkno++, nfrags--) {
108 if (chkrange(blkno, 1))
109 res = SKIP;
110 for (dlp = duphead; dlp; dlp = dlp->next) {
111 if (dlp->dup == blkno) {
112 blkerror(idesc->id_number, "DUP", blkno);
113 dlp->dup = duphead->dup;
114 duphead->dup = blkno;
115 duphead = duphead->next;
116 }
117 if (dlp == muldup)
118 break;
119 }
120 if (muldup == 0 || duphead == muldup->next)
121 return (STOP);
122 }
123 return (res);
124 }