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