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"
21 #include "afs/sysincludes.h" /* Standard vendor system headers */
25 #include <netinet/in.h>
28 #include "h/hashing.h"
30 #if !defined(AFS_HPUX110_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN60_ENV)
31 #include <netinet/in_var.h>
32 #endif /* ! AFS_HPUX110_ENV */
33 #endif /* !defined(UKERNEL) */
35 #include "afsincludes.h" /* Afs-based standard headers */
36 #include "afs/afs_stats.h" /* afs statistics */
38 #if defined(AFS_SUN56_ENV)
40 #include <inet/common.h>
41 #if defined(AFS_SUN58_ENV)
42 #include <netinet/ip6.h>
47 #if defined(AFS_AIX_ENV)
48 #include <sys/fp_io.h>
51 char *afs_cv2string(char *ttp, afs_uint32 aval)
53 register char *tp = ttp;
57 AFS_STATCNT(afs_cv2string);
72 int afs_strcasecmp(char *s1, char *s2)
79 if (c1 >= 'A' && c1 <= 'Z') c1 += 0x20;
80 if (c2 >= 'A' && c2 <= 'Z') c2 += 0x20;
88 char *afs_strcat(char *s1, char *s2)
96 while ((*s1++ = *s2++))
101 char *afs_strchr(char *s, int c)
111 char *afs_strdup(char *s)
117 n = (char *) afs_osi_Alloc(cc);
124 void print_internet_address(char *preamble, struct srvAddr *sa,
125 char *postamble, int flag)
127 register struct server *aserver = sa->server;
131 AFS_STATCNT(print_internet_address);
132 address = ntohl(sa->sa_ip);
133 if (aserver->flags & SRVR_MULTIHOMED) {
134 if (flag == 1) { /* server down mesg */
135 if (!(aserver->flags & SRVR_ISDOWN))
136 ptr = " (multi-homed address; other same-host interfaces maybe up)\n";
138 ptr = " (all multi-homed ip addresses down for the server)\n";
139 } else if (flag == 2) { /* server up mesg */
140 ptr = " (multi-homed address; other same-host interfaces may still be down)\n";
143 afs_warn("%s%d.%d.%d.%d in cell %s%s%s",
144 preamble, (address >> 24), (address >> 16) & 0xff, (address >> 8) & 0xff, (address) & 0xff,
145 aserver->cell->cellName, postamble, ptr);
146 afs_warnuser("%s%d.%d.%d.%d in cell %s%s%s",
147 preamble, (address >> 24), (address >> 16) & 0xff, (address >> 8) & 0xff, (address) & 0xff,
148 aserver->cell->cellName, postamble, ptr);
150 } /*print_internet_address*/
155 * this code badly needs to be cleaned up... too many ugly ifdefs.
159 void afs_warn(char *a, long b, long c, long d, long e, long f,
160 long g, long h, long i, long j)
162 void afs_warn(a,b,c,d,e,f,g,h,i,j)
164 long b,c,d,e,f,g,h,i,j;
167 AFS_STATCNT(afs_warn);
169 if (afs_showflags & GAGCONSOLE)
171 #if defined(AFS_AIX_ENV)
174 /* cf. console_printf() in oncplus/kernext/nfs/serv/shared.c */
175 if (fp_open("/dev/console",O_WRONLY|O_NOCTTY|O_NDELAY,
176 0666,0,FP_SYS,&fd) == 0) {
181 sprintf(buf, a,b,c,d,e,f,g,h,i,j);
183 fp_write(fd, buf, len, 0, UIO_SYSSPACE, &count);
187 printf(a,b,c,d,e,f,g,h,i,j);
193 void afs_warnuser(char *a, long b, long c, long d, long e, long f,
194 long g, long h, long i, long j)
196 void afs_warnuser(a,b,c,d,e,f,g,h,i,j)
198 long b,c,d,e,f,g,h,i,j;
201 AFS_STATCNT(afs_warnuser);
202 if (afs_showflags & GAGUSER)
204 #ifdef AFS_GLOBAL_SUNLOCK
205 int haveGlock = ISAFS_GLOCK();
208 #endif /* AFS_GLOBAL_SUNLOCK */
210 uprintf(a,b,c,d,e,f,g,h,i,j);
212 #ifdef AFS_GLOBAL_SUNLOCK
215 #endif /* AFS_GLOBAL_SUNLOCK */
220 /* run everywhere, checking locks */
221 void afs_CheckLocks(void)
225 afs_warn("Looking for locked data structures.\n");
226 afs_warn("conn %x, volume %x, user %x, cell %x, server %x\n",
227 afs_xconn, afs_xvolume, afs_xuser, afs_xcell, afs_xserver);
229 register struct vcache *tvc;
230 AFS_STATCNT(afs_CheckLocks);
232 for(i=0;i<VCSIZE;i++) {
233 for(tvc = afs_vhashT[i]; tvc; tvc=tvc->hnext) {
235 if (VREFCOUNT(tvc) > 1)
236 #else /* AFS_OSF_ENV */
239 afs_warn("Stat cache entry at %x is held\n", tvc);
240 if (CheckLock(&tvc->lock))
241 afs_warn("Stat entry at %x is locked\n", tvc);
246 register struct dcache *tdc;
247 for (i=0;i<afs_cacheFiles;i++) {
248 tdc = afs_indexTable[i];
251 afs_warn("Disk entry %d at %x is held\n", i, tdc);
253 if (afs_indexFlags[i] & IFDataMod)
254 afs_warn("Disk entry %d at %x has IFDataMod flag set.\n", i, tdc);
261 for (i=0;i<NSERVERS;i++) {
262 for (ts = afs_servers[i]; ts; ts=ts->next) {
263 if (ts->flags & SRVR_ISDOWN)
264 printf("Server entry %x is marked down\n", ts);
265 for (sa = ts->addr; sa; sa = sa->next_sa) {
266 for (tc = sa->conns; tc; tc=tc->next) {
268 afs_warn("conn at %x (server %x) is held\n", tc, sa->sa_ip);
276 for (i=0;i<NVOLS;i++) {
277 for (tv = afs_volumes[i]; tv; tv=tv->next) {
278 if (CheckLock(&tv->lock))
279 afs_warn("volume at %x is locked\n", tv);
281 afs_warn("volume at %x is held\n", tv);
288 for (i=0;i<NUSERS;i++) {
289 for (tu = afs_users[i]; tu; tu=tu->next) {
290 if (tu->refCount) printf("user at %x is held\n", tu);
300 AFS_STATCNT(afs_noop);
310 AFS_STATCNT(afs_badop);
311 osi_Panic("afs bad vnode op");
316 * afs_data_pointer_to_int32() - returns least significant afs_int32 of the
317 * given data pointer, without triggering "cast truncates pointer"
318 * warnings. We use this where we explicitly don't care whether a
319 * pointer is truncated -- it loses information where a pointer is
320 * larger than an afs_int32.
323 afs_int32 afs_data_pointer_to_int32(const void *p)
326 afs_int32 i32[sizeof(void *)/sizeof(afs_int32)];
330 int i32_sub; /* subscript of least significant afs_int32 in ip.i32[] */
335 /* used to determine the byte order of the system */
338 char c[sizeof(int)/sizeof(char)];
344 /* little-endian system */
347 /* big-endian system */
348 i32_sub = (sizeof ip.i32 / sizeof ip.i32[0]) - 1;
353 return ip.i32[i32_sub];