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