2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 * afs_util.c - miscellaneous AFS client utility functions
15 #include <afsconfig.h>
16 #include "afs/param.h"
20 #include "afs/sysincludes.h" /* Standard vendor system headers */
23 #if !defined(AFS_LINUX20_ENV)
26 #include <netinet/in.h>
29 #include "h/hashing.h"
31 #if !defined(AFS_HPUX110_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN60_ENV)
32 #include <netinet/in_var.h>
33 #endif /* ! AFS_HPUX110_ENV */
34 #endif /* !defined(UKERNEL) */
36 #include "afsincludes.h" /* Afs-based standard headers */
37 #include "afs/afs_stats.h" /* afs statistics */
39 #ifdef AFS_LINUX20_ENV
40 #include "afs/afs_md5.h" /* For MD5 inodes - Linux only */
43 #if defined(AFS_SUN56_ENV)
45 #include <inet/common.h>
46 #if defined(AFS_SUN58_ENV)
47 #include <netinet/ip6.h>
52 #if defined(AFS_AIX_ENV)
53 #include <sys/fp_io.h>
56 afs_int32 afs_new_inum = 0;
60 afs_cv2string(char *ttp, afs_uint32 aval)
62 register char *tp = ttp;
66 AFS_STATCNT(afs_cv2string);
82 #ifndef afs_strcasecmp
84 afs_strcasecmp(char *s1, char *s2)
91 if (c1 >= 'A' && c1 <= 'Z')
93 if (c2 >= 'A' && c2 <= 'Z')
105 afs_strcat(char *s1, char *s2)
112 while ((*s1++ = *s2++));
117 #ifdef AFS_OBSD34_ENV
119 afs_strcpy(char *s1, char *s2)
124 while ((*s1++ = *s2++) != '\0');
131 afs_strchr(char *s, int c)
143 afs_strrchr(char *s, int c)
162 n = (char *)afs_osi_Alloc(cc);
170 print_internet_address(char *preamble, struct srvAddr *sa, char *postamble,
173 register struct server *aserver = sa->server;
177 AFS_STATCNT(print_internet_address);
178 address = ntohl(sa->sa_ip);
179 if (aserver->flags & SRVR_MULTIHOMED) {
180 if (flag == 1) { /* server down mesg */
181 if (!(aserver->flags & SRVR_ISDOWN))
183 " (multi-homed address; other same-host interfaces maybe up)\n";
185 ptr = " (all multi-homed ip addresses down for the server)\n";
186 } else if (flag == 2) { /* server up mesg */
188 " (multi-homed address; other same-host interfaces may still be down)\n";
191 afs_warn("%s%d.%d.%d.%d in cell %s%s%s", preamble, (address >> 24),
192 (address >> 16) & 0xff, (address >> 8) & 0xff, (address) & 0xff,
193 aserver->cell->cellName, postamble, ptr);
194 afs_warnuser("%s%d.%d.%d.%d in cell %s%s%s", preamble, (address >> 24),
195 (address >> 16) & 0xff, (address >> 8) & 0xff,
196 (address) & 0xff, aserver->cell->cellName, postamble, ptr);
198 } /*print_internet_address */
202 /* run everywhere, checking locks */
208 afs_warn("Looking for locked data structures.\n");
209 afs_warn("conn %lx, volume %lx, user %lx, cell %lx, server %lx\n", &afs_xconn,
210 &afs_xvolume, &afs_xuser, &afs_xcell, &afs_xserver);
212 register struct vcache *tvc;
213 AFS_STATCNT(afs_CheckLocks);
215 for (i = 0; i < VCSIZE; i++) {
216 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
217 if (tvc->f.states & CVInit) continue;
218 #ifdef AFS_DARWIN80_ENV
219 if (vnode_isinuse(AFSTOV(tvc), 0))
223 afs_warn("Stat cache entry at %x is held\n", tvc);
224 if (CheckLock(&tvc->lock))
225 afs_warn("Stat entry at %x is locked\n", tvc);
230 register struct dcache *tdc;
231 for (i = 0; i < afs_cacheFiles; i++) {
232 tdc = afs_indexTable[i];
235 afs_warn("Disk entry %d at %x is held\n", i, tdc);
237 if (afs_indexFlags[i] & IFDataMod)
238 afs_warn("Disk entry %d at %x has IFDataMod flag set.\n", i,
246 for (i = 0; i < NSERVERS; i++) {
247 for (ts = afs_servers[i]; ts; ts = ts->next) {
248 if (ts->flags & SRVR_ISDOWN)
249 printf("Server entry %lx is marked down\n", (unsigned long)ts);
250 for (sa = ts->addr; sa; sa = sa->next_sa) {
251 for (tc = sa->conns; tc; tc = tc->next) {
253 afs_warn("conn at %x (server %x) is held\n", tc,
262 for (i = 0; i < NVOLS; i++) {
263 for (tv = afs_volumes[i]; tv; tv = tv->next) {
264 if (CheckLock(&tv->lock))
265 afs_warn("volume at %x is locked\n", tv);
267 afs_warn("volume at %x is held\n", tv);
274 for (i = 0; i < NUSERS; i++) {
275 for (tu = afs_users[i]; tu; tu = tu->next) {
277 printf("user at %lx is held\n", (unsigned long)tu);
288 AFS_STATCNT(afs_noop);
295 AFS_STATCNT(afs_badop);
296 osi_Panic("afs bad vnode op");
301 * afs_data_pointer_to_int32() - returns least significant afs_int32 of the
302 * given data pointer, without triggering "cast truncates pointer"
303 * warnings. We use this where we explicitly don't care whether a
304 * pointer is truncated -- it loses information where a pointer is
305 * larger than an afs_int32.
309 afs_data_pointer_to_int32(const void *p)
312 afs_int32 i32[sizeof(void *) / sizeof(afs_int32)];
316 int i32_sub; /* subscript of least significant afs_int32 in ip.i32[] */
321 /* used to determine the byte order of the system */
324 char c[sizeof(int) / sizeof(char)];
330 /* little-endian system */
333 /* big-endian system */
334 i32_sub = (sizeof ip.i32 / sizeof ip.i32[0]) - 1;
339 return ip.i32[i32_sub];
342 #ifdef AFS_LINUX20_ENV
344 afs_int32 afs_calc_inum (afs_int32 volume, afs_int32 vnode)
346 afs_int32 ino, vno = vnode;
352 AFS_MD5_Update(&ct, &volume, 4);
353 AFS_MD5_Update(&ct, &vnode, 4);
354 AFS_MD5_Final(digest, &ct);
355 memcpy(&ino, digest, sizeof(afs_int32));
356 ino ^= (ino ^ vno) & 1;
358 ino = (volume << 16) + vnode;
360 ino &= 0x7fffffff; /* Assumes 32 bit ino_t ..... */
366 afs_int32 afs_calc_inum (afs_int32 volume, afs_int32 vnode)
368 return (volume << 16) + vnode;