amd64-update-20040202
[openafs.git] / src / afs / afs_pioctl.c
index e9b108f..bc2eb22 100644 (file)
@@ -1,27 +1,34 @@
 /*
  * Copyright 2000, International Business Machines Corporation and others.
  * All Rights Reserved.
- * 
+ *
  * This software has been released under the terms of the IBM Public
  * License.  For details, see the LICENSE file in the top-level source
  * directory or online at http://www.openafs.org/dl/license10.html
  */
 
 #include <afsconfig.h>
-#include "../afs/param.h"
+#include "afs/param.h"
 
-RCSID("$Header$");
+RCSID
+    ("$Header$");
 
-#include "../afs/sysincludes.h"        /* Standard vendor system headers */
-#include "../afs/afsincludes.h"        /* Afs-based standard headers */
-#include "../afs/afs_stats.h"   /* afs statistics */
-#include "../afs/vice.h"
-#include "../rx/rx_globals.h"
+#include "afs/sysincludes.h"   /* Standard vendor system headers */
+#ifdef AFS_OBSD_ENV
+#include "h/syscallargs.h"
+#endif
+#ifdef AFS_FBSD50_ENV
+#include "h/sysproto.h"
+#endif
+#include "afsincludes.h"       /* Afs-based standard headers */
+#include "afs/afs_stats.h"     /* afs statistics */
+#include "afs/vice.h"
+#include "rx/rx_globals.h"
 
 struct VenusFid afs_rootFid;
-afs_int32 afs_waitForever=0;
+afs_int32 afs_waitForever = 0;
 short afs_waitForeverCount = 0;
-afs_int32 afs_showflags = GAGUSER | GAGCONSOLE;   /* show all messages */
+afs_int32 afs_showflags = GAGUSER | GAGCONSOLE;        /* show all messages */
 
 #define DECL_PIOCTL(x) static int x(struct vcache *avc, int afun, struct vrequest *areq, \
        char *ain, char *aout, afs_int32 ainSize, afs_int32 *aoutSize, \
@@ -82,91 +89,105 @@ DECL_PIOCTL(PRxStatPeer);
 DECL_PIOCTL(PPrefetchFromTape);
 DECL_PIOCTL(PResidencyCmd);
 
+/*
+ * A macro that says whether we're going to need HandleClientContext().
+ * This is currently used only by the nfs translator.
+ */
+#if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)
+#define AFS_NEED_CLIENTCONTEXT
+#endif
+
 /* Prototypes for private routines */
-static int HandleClientContext(struct afs_ioctl *ablob, int *com, 
-       struct AFS_UCRED **acred, struct AFS_UCRED *credp);
-int HandleIoctl(register struct vcache *avc, register afs_int32 acom, struct afs_ioctl *adata);
-int afs_HandlePioctl(struct vcache *avc, afs_int32 acom, 
-       register struct afs_ioctl *ablob, int afollow, struct AFS_UCRED **acred);
-static int Prefetch(char *apath, struct afs_ioctl *adata, int afollow, struct AFS_UCRED *acred);
-
-
-static int (*(VpioctlSw[]))() = {
-  PBogus,                      /* 0 */
-  PSetAcl,                     /* 1 */
-  PGetAcl,                     /* 2 */
-  PSetTokens,                  /* 3 */
-  PGetVolumeStatus,            /* 4 */
-  PSetVolumeStatus,            /* 5 */
-  PFlush,                      /* 6 */
-  PBogus,                      /* 7 */
-  PGetTokens,                  /* 8 */
-  PUnlog,                      /* 9 */
-  PCheckServers,               /* 10 */
-  PCheckVolNames,              /* 11 */
-  PCheckAuth,                  /* 12 */
-  PBogus,                      /* 13 -- used to be quick check time */
-  PFindVolume,         /* 14*/
-  PBogus,                      /* 15 -- prefetch is now special-cased; see pioctl code! */
-  PBogus,                      /* 16 -- used to be testing code */
-  PNoop,                       /* 17 -- used to be enable group */
-  PNoop,                       /* 18 -- used to be disable group */
-  PBogus,                      /* 19 -- used to be list group */
-  PViceAccess,         /* 20 */
-  PUnlog,                      /* 21 -- unlog *is* unpag in this system */
-  PGetFID,                     /* 22 -- get file ID */
-  PBogus,                      /* 23 -- used to be waitforever */
-  PSetCacheSize,               /* 24 */
-  PRemoveCallBack,             /* 25 -- flush only the callback */
-  PNewCell,                    /* 26 */
-  PListCells,                  /* 27 */
-  PRemoveMount,                /* 28 -- delete mount point */
-  PNewStatMount,               /* 29 -- new style mount point stat */
-  PGetFileCell,                /* 30 -- get cell name for input file */
-  PGetWSCell,                  /* 31 -- get cell name for workstation */
-  PMariner,                    /* 32 - set/get mariner host */
-  PGetUserCell,                /* 33 -- get cell name for user */
-  PVenusLogging,               /* 34 -- Enable/Disable logging */
-  PGetCellStatus,              /* 35 */
-  PSetCellStatus,              /* 36 */
-  PFlushVolumeData,            /* 37 -- flush all data from a volume */
-  PSetSysName,         /* 38 - Set system name */
-  PExportAfs,                  /* 39 - Export Afs to remote nfs clients */
-  PGetCacheSize,               /* 40 - get cache size and usage */
-  PGetVnodeXStatus,            /* 41 - get vcache's special status */
-  PSetSPrefs33,                /* 42 - Set CM Server preferences... */
-  PGetSPrefs,                  /* 43 - Get CM Server preferences... */
-  PGag,                         /* 44 - turn off/on all CM messages */
-  PTwiddleRx,                   /* 45 - adjust some RX params       */
-  PSetSPrefs,                  /* 46 - Set CM Server preferences... */
-  PStoreBehind,                /* 47 - set degree of store behind to be done */
-  PGCPAGs,                     /* 48 - disable automatic pag gc-ing */
-  PGetInitParams,              /* 49 - get initial cm params */
-  PGetCPrefs,                  /* 50 - get client interface addresses */
-  PSetCPrefs,                  /* 51 - set client interface addresses */
-  PFlushMount,                 /* 52 - flush mount symlink data */
-  PRxStatProc,                 /* 53 - control process RX statistics */
-  PRxStatPeer,                 /* 54 - control peer RX statistics */
-  PGetRxkcrypt,                        /* 55 -- Get rxkad encryption flag */
-  PSetRxkcrypt,                        /* 56 -- Set rxkad encryption flag */
-  PBogus,                      /* 57 -- arla: set file prio */
-  PBogus,                      /* 58 -- arla: fallback getfh */
-  PBogus,                      /* 59 -- arla: fallback fhopen */
-  PBogus,                      /* 60 -- arla: controls xfsdebug */
-  PBogus,                      /* 61 -- arla: controls arla debug */
-  PBogus,                      /* 62 -- arla: debug interface */
-  PBogus,                      /* 63 -- arla: print xfs status */
-  PBogus,                      /* 64 -- arla: force cache check */
-  PBogus,                      /* 65 -- arla: break callback */
-  PPrefetchFromTape,            /* 66 -- MR-AFS: prefetch file from tape */
-  PResidencyCmd,                /* 67 -- MR-AFS: generic commnd interface */
-  PBogus,                      /* 68 -- arla: fetch stats */
+#ifdef AFS_NEED_CLIENTCONTEXT
+static int HandleClientContext(struct afs_ioctl *ablob, int *com,
+                              struct AFS_UCRED **acred,
+                              struct AFS_UCRED *credp);
+#endif
+int HandleIoctl(register struct vcache *avc, register afs_int32 acom,
+               struct afs_ioctl *adata);
+int afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
+                    register struct afs_ioctl *ablob, int afollow,
+                    struct AFS_UCRED **acred);
+static int Prefetch(char *apath, struct afs_ioctl *adata, int afollow,
+                   struct AFS_UCRED *acred);
+
+
+static int (*(VpioctlSw[])) () = {
+    PBogus,                    /* 0 */
+       PSetAcl,                /* 1 */
+       PGetAcl,                /* 2 */
+       PSetTokens,             /* 3 */
+       PGetVolumeStatus,       /* 4 */
+       PSetVolumeStatus,       /* 5 */
+       PFlush,                 /* 6 */
+       PBogus,                 /* 7 */
+       PGetTokens,             /* 8 */
+       PUnlog,                 /* 9 */
+       PCheckServers,          /* 10 */
+       PCheckVolNames,         /* 11 */
+       PCheckAuth,             /* 12 */
+       PBogus,                 /* 13 -- used to be quick check time */
+       PFindVolume,            /* 14 */
+       PBogus,                 /* 15 -- prefetch is now special-cased; see pioctl code! */
+       PBogus,                 /* 16 -- used to be testing code */
+       PNoop,                  /* 17 -- used to be enable group */
+       PNoop,                  /* 18 -- used to be disable group */
+       PBogus,                 /* 19 -- used to be list group */
+       PViceAccess,            /* 20 */
+       PUnlog,                 /* 21 -- unlog *is* unpag in this system */
+       PGetFID,                /* 22 -- get file ID */
+       PBogus,                 /* 23 -- used to be waitforever */
+       PSetCacheSize,          /* 24 */
+       PRemoveCallBack,        /* 25 -- flush only the callback */
+       PNewCell,               /* 26 */
+       PListCells,             /* 27 */
+       PRemoveMount,           /* 28 -- delete mount point */
+       PNewStatMount,          /* 29 -- new style mount point stat */
+       PGetFileCell,           /* 30 -- get cell name for input file */
+       PGetWSCell,             /* 31 -- get cell name for workstation */
+       PMariner,               /* 32 - set/get mariner host */
+       PGetUserCell,           /* 33 -- get cell name for user */
+       PVenusLogging,          /* 34 -- Enable/Disable logging */
+       PGetCellStatus,         /* 35 */
+       PSetCellStatus,         /* 36 */
+       PFlushVolumeData,       /* 37 -- flush all data from a volume */
+       PSetSysName,            /* 38 - Set system name */
+       PExportAfs,             /* 39 - Export Afs to remote nfs clients */
+       PGetCacheSize,          /* 40 - get cache size and usage */
+       PGetVnodeXStatus,       /* 41 - get vcache's special status */
+       PSetSPrefs33,           /* 42 - Set CM Server preferences... */
+       PGetSPrefs,             /* 43 - Get CM Server preferences... */
+       PGag,                   /* 44 - turn off/on all CM messages */
+       PTwiddleRx,             /* 45 - adjust some RX params       */
+       PSetSPrefs,             /* 46 - Set CM Server preferences... */
+       PStoreBehind,           /* 47 - set degree of store behind to be done */
+       PGCPAGs,                /* 48 - disable automatic pag gc-ing */
+       PGetInitParams,         /* 49 - get initial cm params */
+       PGetCPrefs,             /* 50 - get client interface addresses */
+       PSetCPrefs,             /* 51 - set client interface addresses */
+       PFlushMount,            /* 52 - flush mount symlink data */
+       PRxStatProc,            /* 53 - control process RX statistics */
+       PRxStatPeer,            /* 54 - control peer RX statistics */
+       PGetRxkcrypt,           /* 55 -- Get rxkad encryption flag */
+       PSetRxkcrypt,           /* 56 -- Set rxkad encryption flag */
+       PBogus,                 /* 57 -- arla: set file prio */
+       PBogus,                 /* 58 -- arla: fallback getfh */
+       PBogus,                 /* 59 -- arla: fallback fhopen */
+       PBogus,                 /* 60 -- arla: controls xfsdebug */
+       PBogus,                 /* 61 -- arla: controls arla debug */
+       PBogus,                 /* 62 -- arla: debug interface */
+       PBogus,                 /* 63 -- arla: print xfs status */
+       PBogus,                 /* 64 -- arla: force cache check */
+       PBogus,                 /* 65 -- arla: break callback */
+       PPrefetchFromTape,      /* 66 -- MR-AFS: prefetch file from tape */
+       PResidencyCmd,          /* 67 -- MR-AFS: generic commnd interface */
+       PBogus,                 /* 68 -- arla: fetch stats */
 };
 
-static int (*(CpioctlSw[]))() = {
-  PBogus,                      /* 0 */
-  PNewAlias,                   /* 1 -- create new cell alias */
-  PListAliases,                        /* 2 -- list cell aliases */
+static int (*(CpioctlSw[])) () = {
+    PBogus,                    /* 0 */
+       PNewAlias,              /* 1 -- create new cell alias */
+       PListAliases,           /* 2 -- list cell aliases */
 };
 
 #define PSetClientContext 99   /*  Special pioctl to setup caller's creds  */
@@ -175,10 +196,10 @@ int afs_nobody = NFS_NOBODY;
 static void
 afs_ioctl32_to_afs_ioctl(const struct afs_ioctl32 *src, struct afs_ioctl *dst)
 {
-       dst->in       = (char *)(unsigned long)src->in;
-       dst->out      = (char *)(unsigned long)src->out;
-       dst->in_size  = src->in_size;
-       dst->out_size = src->out_size;
+    dst->in = (char *)(unsigned long)src->in;
+    dst->out = (char *)(unsigned long)src->out;
+    dst->in_size = src->in_size;
+    dst->out_size = src->out_size;
 }
 
 /*
@@ -189,183 +210,199 @@ afs_ioctl32_to_afs_ioctl(const struct afs_ioctl32 *src, struct afs_ioctl *dst)
 static int
 copyin_afs_ioctl(caddr_t cmarg, struct afs_ioctl *dst)
 {
-       int code;
+    int code;
+#if defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)
+    struct afs_ioctl32 dst32;
+
+    if (!(IS64U)) {
+       AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
+       if (!code)
+           afs_ioctl32_to_afs_ioctl(&dst32, dst);
+       return code;
+    }
+#endif /* defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL) */
+
 
 #if defined(AFS_HPUX_64BIT_ENV)
-       struct afs_ioctl32 dst32;
+    struct afs_ioctl32 dst32;
 
-       if (is_32bit(u.u_procp))        /* is_32bit() in proc_iface.h */
-       {
-               AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code);
-               if (!code)
-                       afs_ioctl32_to_afs_ioctl(&dst32, dst);
-               return code;
-       }
+    if (is_32bit(u.u_procp)) { /* is_32bit() in proc_iface.h */
+       AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
+       if (!code)
+           afs_ioctl32_to_afs_ioctl(&dst32, dst);
+       return code;
+    }
 #endif /* defined(AFS_HPUX_64BIT_ENV) */
 
 #if defined(AFS_SUN57_64BIT_ENV)
-       struct afs_ioctl32 dst32;
+    struct afs_ioctl32 dst32;
 
-       if (get_udatamodel() == DATAMODEL_ILP32) {
-               AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code);
-               if (!code)
-                       afs_ioctl32_to_afs_ioctl(&dst32, dst);
-               return code;
-       }
+    if (get_udatamodel() == DATAMODEL_ILP32) {
+       AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
+       if (!code)
+           afs_ioctl32_to_afs_ioctl(&dst32, dst);
+       return code;
+    }
 #endif /* defined(AFS_SUN57_64BIT_ENV) */
 
 #if defined(AFS_SGI_ENV) && (_MIPS_SZLONG==64)
-       struct afs_ioctl32 dst32;
+    struct afs_ioctl32 dst32;
 
-       if (!ABI_IS_64BIT(get_current_abi()))
-       {
-               AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code);
-               if (!code)
-                       afs_ioctl32_to_afs_ioctl(&dst32, dst);
-               return code;
-       }
+    if (!ABI_IS_64BIT(get_current_abi())) {
+       AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
+       if (!code)
+           afs_ioctl32_to_afs_ioctl(&dst32, dst);
+       return code;
+    }
 #endif /* defined(AFS_SGI_ENV) && (_MIPS_SZLONG==64) */
 
-#if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV)
-       struct afs_ioctl32 dst32;
+#if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV) && !defined(AFS_AMD64_LINUX20_ENV)
+    struct afs_ioctl32 dst32;
 
 #ifdef AFS_SPARC64_LINUX24_ENV
-        if (current->thread.flags & SPARC_FLAG_32BIT)
-#elif AFS_SPARC64_LINUX20_ENV
-       if (current->tss.flags & SPARC_FLAG_32BIT) 
+    if (current->thread.flags & SPARC_FLAG_32BIT)
+#elif defined(AFS_SPARC64_LINUX20_ENV)
+    if (current->tss.flags & SPARC_FLAG_32BIT)
+#elif defined(AFS_AMD64_LINUX20_ENV)
+    if (current->thread.flags & THREAD_IA32)
 #else
 #error Not done for this linux type
-#endif /* AFS_SPARC64_LINUX20_ENV */
-         {
-               AFS_COPYIN(cmarg, (caddr_t) &dst32, sizeof dst32, code);
-               if (!code)
-                       afs_ioctl32_to_afs_ioctl(&dst32, dst);
-               return code;
-       }
+#endif
+    {
+       AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
+       if (!code)
+           afs_ioctl32_to_afs_ioctl(&dst32, dst);
+       return code;
+    }
 #endif /* defined(AFS_LINUX_64BIT_KERNEL) */
 
-       AFS_COPYIN(cmarg, (caddr_t) dst, sizeof *dst, code);
-       return code;
+    AFS_COPYIN(cmarg, (caddr_t) dst, sizeof *dst, code);
+    return code;
+}
+
+int
+HandleIoctl(register struct vcache *avc, register afs_int32 acom,
+           struct afs_ioctl *adata)
+{
+    register afs_int32 code;
+
+    code = 0;
+    AFS_STATCNT(HandleIoctl);
+
+    switch (acom & 0xff) {
+    case 1:
+       avc->states |= CSafeStore;
+       avc->asynchrony = 0;
+       break;
+
+       /* case 2 used to be abort store, but this is no longer provided,
+        * since it is impossible to implement under normal Unix.
+        */
+
+    case 3:{
+           /* return the name of the cell this file is open on */
+           register struct cell *tcell;
+           register afs_int32 i;
+
+           tcell = afs_GetCell(avc->fid.Cell, READ_LOCK);
+           if (tcell) {
+               i = strlen(tcell->cellName) + 1;        /* bytes to copy out */
+
+               if (i > adata->out_size) {
+                   /* 0 means we're not interested in the output */
+                   if (adata->out_size != 0)
+                       code = EFAULT;
+               } else {
+                   /* do the copy */
+                   AFS_COPYOUT(tcell->cellName, adata->out, i, code);
+               }
+               afs_PutCell(tcell, READ_LOCK);
+           } else
+               code = ENOTTY;
+       }
+       break;
+
+    case 49:                   /* VIOC_GETINITPARAMS */
+       if (adata->out_size < sizeof(struct cm_initparams)) {
+           code = EFAULT;
+       } else {
+           AFS_COPYOUT(&cm_initParams, adata->out,
+                       sizeof(struct cm_initparams), code);
+       }
+       break;
+
+    default:
+
+       code = EINVAL;
+#ifdef AFS_AIX51_ENV
+       code = ENOSYS;
+#endif
+       break;
+    }
+    return code;               /* so far, none implemented */
 }
 
-int HandleIoctl(register struct vcache *avc, register afs_int32 acom, struct afs_ioctl *adata)
-{
-       register afs_int32 code;
-       
-       code = 0;
-       AFS_STATCNT(HandleIoctl);
-       
-       switch(acom & 0xff) {
-       case 1:
-        avc->states |= CSafeStore;
-        avc->asynchrony = 0;
-        break;
-        
-        /* case 2 used to be abort store, but this is no longer provided,
-           since it is impossible to implement under normal Unix.
-           */
-        
-       case 3: {
-        /* return the name of the cell this file is open on */
-        register struct cell *tcell;
-        register afs_int32 i;
-        
-        tcell = afs_GetCell(avc->fid.Cell, READ_LOCK);
-        if (tcell) {
-          i = strlen(tcell->cellName) + 1;    /* bytes to copy out */
-
-          if (i > adata->out_size) {
-            /* 0 means we're not interested in the output */
-            if (adata->out_size != 0) code = EFAULT;
-          }
-          else {
-            /* do the copy */
-            AFS_COPYOUT(tcell->cellName, adata->out, i, code);
-          }
-          afs_PutCell(tcell, READ_LOCK);
-        }
-        else code = ENOTTY;
-       }
-        break;
-        
-     case 49: /* VIOC_GETINITPARAMS */
-        if (adata->out_size < sizeof(struct cm_initparams)) {
-            code = EFAULT;
-        }
-        else {
-            AFS_COPYOUT(&cm_initParams, adata->out,
-                        sizeof(struct cm_initparams), code);
-        }
-        break;
-        
-       default:
-
-        code = EINVAL;
-        break;
-       }
-       return code;            /* so far, none implemented */
-     }
-     
-     
+
 #ifdef AFS_AIX_ENV
 /* For aix we don't temporarily bypass ioctl(2) but rather do our
  * thing directly in the vnode layer call, VNOP_IOCTL; thus afs_ioctl
  * is now called from afs_gn_ioctl.
  */
-int afs_ioctl(struct   vcache *tvc, int        cmd, int        arg)
-{
-  struct afs_ioctl data;
-  int error = 0;
-  
-  AFS_STATCNT(afs_ioctl);
-  if (((cmd >> 8) & 0xff) == 'V') {
-    /* This is a VICEIOCTL call */
-    AFS_COPYIN(arg, (caddr_t) &data, sizeof(data), error);
-    if (error)
-      return(error);
-    error = HandleIoctl(tvc, cmd, &data);
-    return(error);
-  } else {
-    /* No-op call; just return. */
-    return(ENOTTY);
-  }
+int
+afs_ioctl(struct vcache *tvc, int cmd, int arg)
+{
+    struct afs_ioctl data;
+    int error = 0;
+
+    AFS_STATCNT(afs_ioctl);
+    if (((cmd >> 8) & 0xff) == 'V') {
+       /* This is a VICEIOCTL call */
+       AFS_COPYIN(arg, (caddr_t) & data, sizeof(data), error);
+       if (error)
+           return (error);
+       error = HandleIoctl(tvc, cmd, &data);
+       return (error);
+    } else {
+       /* No-op call; just return. */
+       return (ENOTTY);
+    }
 }
 #endif /* AFS_AIX_ENV */
 
 #if defined(AFS_SGI_ENV)
-afs_ioctl(OSI_VN_DECL(tvc), int cmd, void * arg, int flag, cred_t *cr, rval_t *rvalp
+afs_ioctl(OSI_VN_DECL(tvc), int cmd, void *arg, int flag, cred_t * cr,
+         rval_t * rvalp
 #ifdef AFS_SGI65_ENV
-         , struct vopbd *vbds
-#endif
-         )
-{
-  struct afs_ioctl data;
-  int error = 0;
-  int locked;
-
-  OSI_VN_CONVERT(tvc);
-  
-  AFS_STATCNT(afs_ioctl);
-  if (((cmd >> 8) & 0xff) == 'V') {
-    /* This is a VICEIOCTL call */
-    error = copyin_afs_ioctl(arg, &data);
-    if (error)
-      return(error);
-    locked = ISAFS_GLOCK();
-    if (!locked)
-       AFS_GLOCK();
-    error = HandleIoctl(tvc, cmd, &data);
-    if (!locked)
-       AFS_GUNLOCK();
-    return(error);
-  } else {
-    /* No-op call; just return. */
-    return(ENOTTY);
-  }
+         , struct vopbd * vbds
+#endif
+    )
+{
+    struct afs_ioctl data;
+    int error = 0;
+    int locked;
+
+    OSI_VN_CONVERT(tvc);
+
+    AFS_STATCNT(afs_ioctl);
+    if (((cmd >> 8) & 0xff) == 'V') {
+       /* This is a VICEIOCTL call */
+       error = copyin_afs_ioctl(arg, &data);
+       if (error)
+           return (error);
+       locked = ISAFS_GLOCK();
+       if (!locked)
+           AFS_GLOCK();
+       error = HandleIoctl(tvc, cmd, &data);
+       if (!locked)
+           AFS_GUNLOCK();
+       return (error);
+    } else {
+       /* No-op call; just return. */
+       return (ENOTTY);
+    }
 }
 #endif /* AFS_SGI_ENV */
 
-
 /* unlike most calls here, this one uses u.u_error to return error conditions,
    since this is really an intercepted chapter 2 call, rather than a vnode
    interface call.
@@ -374,16 +411,28 @@ afs_ioctl(OSI_VN_DECL(tvc), int cmd, void * arg, int flag, cred_t *cr, rval_t *r
 #ifndef AFS_HPUX102_ENV
 #if !defined(AFS_SGI_ENV)
 #ifdef AFS_AIX32_ENV
+#ifdef AFS_AIX51_ENV
+#ifdef __64BIT__
+kioctl(fdes, com, arg, ext, arg2, arg3)
+#else /* __64BIT__ */
+kioctl32(fdes, com, arg, ext, arg2, arg3)
+#endif /* __64BIT__ */
+     caddr_t arg2, arg3;
+#else
 kioctl(fdes, com, arg, ext)
+#endif
      int fdes, com;
      caddr_t arg, ext;
 {
-  struct a {
-    int fd, com;
-    caddr_t arg, ext;
-  } u_uap, *uap = &u_uap;
+    struct a {
+       int fd, com;
+       caddr_t arg, ext;
+#ifdef AFS_AIX51_ENV
+       caddr_t arg2, arg3;
+#endif
+    } u_uap, *uap = &u_uap;
 #else
-#ifdef AFS_SUN5_ENV
+#if defined(AFS_SUN5_ENV)
 
 struct afs_ioctl_sys {
     int fd;
@@ -391,294 +440,304 @@ struct afs_ioctl_sys {
     int arg;
 };
 
-afs_xioctl (uap, rvp) 
-    struct afs_ioctl_sys *uap;
-    rval_t *rvp;
+afs_xioctl(uap, rvp)
+     struct afs_ioctl_sys *uap;
+     rval_t *rvp;
 {
-#else
-#ifdef AFS_OSF_ENV
-afs_xioctl (p, args, retval)
-        struct proc *p;
-        void *args;
-        long *retval;
+#elif defined(AFS_OSF_ENV)
+afs_xioctl(p, args, retval)
+     struct proc *p;
+     void *args;
+     long *retval;
 {
     struct a {
-        long fd;
-        u_long com;
-        caddr_t arg;
+       long fd;
+       u_long com;
+       caddr_t arg;
     } *uap = (struct a *)args;
-#else /* AFS_OSF_ENV */
-#if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
+#elif defined(AFS_FBSD50_ENV)
+#define arg data
+int
+afs_xioctl(td, uap, retval)
+     struct thread *td;
+     register struct ioctl_args *uap;
+     register_t *retval;
+{
+    struct proc *p = td->td_proc;
+#elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
 struct ioctl_args {
-        int fd;
-        u_long com;
-        caddr_t arg;
+    int fd;
+    u_long com;
+    caddr_t arg;
 };
-afs_xioctl(p, uap, retval) 
-        struct proc *p; 
-        register struct ioctl_args *uap;
-        register_t *retval;
+
+int
+afs_xioctl(p, uap, retval)
+     struct proc *p;
+     register struct ioctl_args *uap;
+     register_t *retval;
 {
-#else
-#ifdef AFS_LINUX22_ENV
+#elif defined(AFS_LINUX22_ENV)
 struct afs_ioctl_sys {
     unsigned int com;
     unsigned long arg;
 };
-asmlinkage int afs_xioctl(struct inode *ip, struct file *fp,
-                         unsigned int com, unsigned long arg)
+asmlinkage int
+afs_xioctl(struct inode *ip, struct file *fp, unsigned int com,
+          unsigned long arg)
 {
     struct afs_ioctl_sys ua, *uap = &ua;
 #else
-int afs_xioctl (void) 
-    {
-      register struct a {
+int
+afs_xioctl(void)
+{
+    register struct a {
        int fd;
        int com;
        caddr_t arg;
-      } *uap = (struct a *)u.u_ap;
-#endif /* AFS_LINUX22_ENV */
-#endif /* AFS_DARWIN_ENV || AFS_FBSD_ENV */
-#endif /* AFS_OSF_ENV */
-#endif /* AFS_SUN5_ENV */
+    } *uap = (struct a *)u.u_ap;
+#endif /* AFS_SUN5_ENV */
 #endif
-#ifndef AFS_LINUX22_ENV
-#if    defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV)
-      struct file *fd;
-#else
-      register struct file *fd;
-#endif
-#endif
-#if defined(AFS_FBSD_ENV)
-      register struct filedesc *fdp;
-#endif
-      register struct vcache *tvc;
-      register int ioctlDone = 0, code = 0;
-      
-      AFS_STATCNT(afs_xioctl);
-#if defined(AFS_FBSD_ENV)
-        fdp=p->p_fd;
-        if ((u_int)uap->fd >= fdp->fd_nfiles ||
-            (fd = fdp->fd_ofiles[uap->fd]) == NULL)
-                return EBADF;
-        if ((fd->f_flag & (FREAD | FWRITE)) == 0)
-                return EBADF;
-#else
-#if defined(AFS_DARWIN_ENV)
-        if ((code=fdgetf(p, uap->fd, &fd)))
-           return code;
-#else
-#ifdef AFS_LINUX22_ENV
+#if defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV)
+    struct file *fd;
+#elif !defined(AFS_LINUX22_ENV)
+    register struct file *fd;
+#endif
+#if defined(AFS_XBSD_ENV)
+    register struct filedesc *fdp;
+#endif
+    register struct vcache *tvc;
+    register int ioctlDone = 0, code = 0;
+
+    AFS_STATCNT(afs_xioctl);
+#if defined(AFS_XBSD_ENV)
+    fdp = p->p_fd;
+    if ((u_int) uap->fd >= fdp->fd_nfiles
+       || (fd = fdp->fd_ofiles[uap->fd]) == NULL)
+       return EBADF;
+    if ((fd->f_flag & (FREAD | FWRITE)) == 0)
+       return EBADF;
+#elif defined(AFS_DARWIN_ENV)
+    if ((code = fdgetf(p, uap->fd, &fd)))
+       return code;
+#elif defined(AFS_LINUX22_ENV)
     ua.com = com;
     ua.arg = arg;
-#else
-#ifdef AFS_AIX32_ENV
-      uap->fd = fdes;
-      uap->com = com;
-      uap->arg = arg;
-      if (setuerror(getf(uap->fd, &fd))) {
+#elif defined(AFS_AIX32_ENV)
+    uap->fd = fdes;
+    uap->com = com;
+    uap->arg = arg;
+#ifdef AFS_AIX51_ENV
+    uap->arg2 = arg2;
+    uap->arg3 = arg3;
+#endif
+    if (setuerror(getf(uap->fd, &fd))) {
        return -1;
     }
-#else
-#ifdef  AFS_OSF_ENV
+#elif defined(AFS_OSF_ENV)
     fd = NULL;
     if (code = getf(&fd, uap->fd, FILE_FLAGS_NULL, &u.u_file_state))
-        return code;
-#else   /* AFS_OSF_ENV */
-#ifdef AFS_SUN5_ENV
-#if defined(AFS_SUN57_ENV)
-       fd = getf(uap->fd);
-        if (!fd) return(EBADF);
-#elif defined(AFS_SUN54_ENV)
-      fd = GETF(uap->fd);
-      if (!fd) return(EBADF);
-#else
-      if (code = getf(uap->fd, &fd)) {
-         return (code);
-      }
-#endif
+       return code;
+#elif defined(AFS_SUN5_ENV)
+# if defined(AFS_SUN57_ENV)
+    fd = getf(uap->fd);
+    if (!fd)
+       return (EBADF);
+# elif defined(AFS_SUN54_ENV)
+    fd = GETF(uap->fd);
+    if (!fd)
+       return (EBADF);
+# else
+    if (code = getf(uap->fd, &fd)) {
+       return (code);
+    }
+# endif        /* AFS_SUN57_ENV */
 #else
-      fd = getf(uap->fd);
-      if (!fd) return;
-#endif
-#endif
+    fd = getf(uap->fd);
+    if (!fd)
+       return (EBADF);
 #endif
-#endif
-#endif
-#endif
-      /* first determine whether this is any sort of vnode */
-#ifdef AFS_LINUX22_ENV
-      tvc = VTOAFS(ip);
-      {
+    /* first determine whether this is any sort of vnode */
+#if defined(AFS_LINUX22_ENV)
+    tvc = VTOAFS(ip);
+    {
 #else
-#ifdef AFS_SUN5_ENV
-      if (fd->f_vnode->v_type == VREG || fd->f_vnode->v_type == VDIR) {
+#ifdef AFS_SUN5_ENV
+    if (fd->f_vnode->v_type == VREG || fd->f_vnode->v_type == VDIR) {
 #else
-      if (fd->f_type == DTYPE_VNODE) {
+    if (fd->f_type == DTYPE_VNODE) {
 #endif
        /* good, this is a vnode; next see if it is an AFS vnode */
 #if    defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV)
        tvc = VTOAFS(fd->f_vnode);      /* valid, given a vnode */
+#elif defined(AFS_OBSD_ENV)
+       tvc =
+           IsAfsVnode((struct vnode *)fd->
+                      f_data) ? VTOAFS((struct vnode *)fd->f_data) : NULL;
 #else
-       tvc = VTOAFS((struct vnode*)fd->f_data);        /* valid, given a vnode */
+       tvc = VTOAFS((struct vnode *)fd->f_data);       /* valid, given a vnode */
 #endif
 #endif /* AFS_LINUX22_ENV */
        if (tvc && IsAfsVnode(AFSTOV(tvc))) {
 #ifdef AFS_DEC_ENV
-         tvc = VTOAFS(afs_gntovn((struct gnode *) tvc));
-         if (!tvc) {   /* shouldn't happen with held gnodes */
-           u.u_error = ENOENT;
-           return;
-         }
-#endif
-         /* This is an AFS vnode */
-         if (((uap->com >> 8) & 0xff) == 'V') {
-           register struct afs_ioctl *datap;
-           AFS_GLOCK();
-           datap = (struct afs_ioctl *) osi_AllocSmallSpace(AFS_SMALLOCSIZ);
-           AFS_COPYIN((char *)uap->arg, (caddr_t) datap, sizeof (struct afs_ioctl), code);
-           if (code) {
-             osi_FreeSmallSpace(datap);
-             AFS_GUNLOCK();
-#if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
-              return code;
-#else 
+           tvc = VTOAFS(afs_gntovn((struct gnode *)tvc));
+           if (!tvc) {         /* shouldn't happen with held gnodes */
+               u.u_error = ENOENT;
+               return;
+           }
+#endif
+           /* This is an AFS vnode */
+           if (((uap->com >> 8) & 0xff) == 'V') {
+               register struct afs_ioctl *datap;
+               AFS_GLOCK();
+               datap =
+                   (struct afs_ioctl *)osi_AllocSmallSpace(AFS_SMALLOCSIZ);
+               AFS_COPYIN((char *)uap->arg, (caddr_t) datap,
+                          sizeof(struct afs_ioctl), code);
+               if (code) {
+                   osi_FreeSmallSpace(datap);
+                   AFS_GUNLOCK();
+#if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
+                   return code;
+#else
 #if    defined(AFS_SUN5_ENV)
 #ifdef AFS_SUN54_ENV
-             releasef(uap->fd);
+                   releasef(uap->fd);
 #else
-             releasef(fd);
+                   releasef(fd);
 #endif
-             return (EFAULT);
+                   return (EFAULT);
 #else
 #ifdef AFS_OSF_ENV
 #ifdef AFS_OSF30_ENV
-             FP_UNREF_ALWAYS(fd);
+                   FP_UNREF_ALWAYS(fd);
 #else
-              FP_UNREF(fd);
+                   FP_UNREF(fd);
 #endif
-              return code;
-#else  /* AFS_OSF_ENV */
+                   return code;
+#else /* AFS_OSF_ENV */
 #ifdef AFS_AIX41_ENV
-             ufdrele(uap->fd);
+                   ufdrele(uap->fd);
 #endif
 #ifdef AFS_LINUX22_ENV
-             return -code;
+                   return -code;
 #else
-             setuerror(code);
-             return;
+                   setuerror(code);
+                   return;
 #endif
 #endif
 #endif
 #endif
-           }
-           code = HandleIoctl(tvc, uap->com, datap);
-           osi_FreeSmallSpace(datap);
-           AFS_GUNLOCK();
-           ioctlDone = 1;
+               }
+               code = HandleIoctl(tvc, uap->com, datap);
+               osi_FreeSmallSpace(datap);
+               AFS_GUNLOCK();
+               ioctlDone = 1;
 #ifdef AFS_AIX41_ENV
-           ufdrele(uap->fd);
+               ufdrele(uap->fd);
 #endif
 #ifdef AFS_OSF_ENV
 #ifdef AFS_OSF30_ENV
-             FP_UNREF_ALWAYS(fd);
+               FP_UNREF_ALWAYS(fd);
 #else
-              FP_UNREF(fd);
+               FP_UNREF(fd);
 #endif
 #endif
-         }
+           }
 #if defined(AFS_LINUX22_ENV)
-         else 
-           code = EINVAL;
+           else
+               code = EINVAL;
 #endif
        }
-      }
+    }
 
-      if (!ioctlDone) {
+    if (!ioctlDone) {
 #ifdef AFS_AIX41_ENV
-         ufdrele(uap->fd);
-         code = okioctl(fdes, com, arg, ext);
-         return code;
-#else
+       ufdrele(uap->fd);
+#ifdef AFS_AIX51_ENV
+#ifdef __64BIT__
+       code = okioctl(fdes, com, arg, ext, arg2, arg3);
+#else /* __64BIT__ */
+       code = okioctl32(fdes, com, arg, ext, arg2, arg3);
+#endif /* __64BIT__ */
+#else /* !AFS_AIX51_ENV */
+       code = okioctl(fdes, com, arg, ext);
+#endif /* AFS_AIX51_ENV */
+       return code;
+#else /* !AFS_AIX41_ENV */
 #ifdef AFS_AIX32_ENV
-         okioctl(fdes, com, arg, ext);
-#else
-#if    defined(AFS_SUN5_ENV)
+       okioctl(fdes, com, arg, ext);
+#elif defined(AFS_SUN5_ENV)
 #if defined(AFS_SUN57_ENV)
        releasef(uap->fd);
 #elif defined(AFS_SUN54_ENV)
-         RELEASEF(uap->fd);
-#else
-          releasef(fd);
-#endif
-          code = ioctl(uap, rvp);
-#else
-#if defined(AFS_FBSD_ENV)
-        return ioctl(p, uap);
-#else
-#if defined(AFS_DARWIN_ENV) 
-        return ioctl(p, uap, retval);
-#else
-#ifdef  AFS_OSF_ENV
-         code = ioctl(p, args, retval);
+       RELEASEF(uap->fd);
+#else
+       releasef(fd);
+#endif
+       code = ioctl(uap, rvp);
+#elif defined(AFS_FBSD50_ENV)
+       return ioctl(td, uap);
+#elif defined(AFS_FBSD_ENV)
+       return ioctl(p, uap);
+#elif defined(AFS_OBSD_ENV)
+       code = sys_ioctl(p, uap, retval);
+#elif defined(AFS_DARWIN_ENV)
+       return ioctl(p, uap, retval);
+#elif defined(AFS_OSF_ENV)
+       code = ioctl(p, args, retval);
 #ifdef AFS_OSF30_ENV
-         FP_UNREF_ALWAYS(fd);
+       FP_UNREF_ALWAYS(fd);
 #else
-         FP_UNREF(fd);
-#endif
-         return code;
-#else   /* AFS_OSF_ENV */
-#ifndef AFS_LINUX22_ENV
-          ioctl();
-#endif
-#endif
-#endif
-#endif
+       FP_UNREF(fd);
 #endif
+       return code;
+#elif !defined(AFS_LINUX22_ENV)
+       ioctl();
 #endif
 #endif
-      }
+    }
 #ifdef AFS_SUN5_ENV
-      if (ioctlDone)
+    if (ioctlDone)
 #ifdef AFS_SUN54_ENV
-         releasef(uap->fd);
+       releasef(uap->fd);
 #else
-         releasef(fd);
+       releasef(fd);
 #endif
-      return (code);
+    return (code);
 #else
 #ifdef AFS_LINUX22_ENV
-      return -code;
+    return -code;
 #else
-#if defined(KERNEL_HAVE_SETUERROR)
-      if (!getuerror())
-         setuerror(code);
+#if defined(KERNEL_HAVE_UERROR)
+    if (!getuerror())
+       setuerror(code);
 #if    defined(AFS_AIX32_ENV) && !defined(AFS_AIX41_ENV)
-      return (getuerror() ? -1 : u.u_ioctlrv);
+    return (getuerror()? -1 : u.u_ioctlrv);
 #else
-      return getuerror() ? -1 : 0;
+    return getuerror()? -1 : 0;
 #endif
 #endif
 #endif /* AFS_LINUX22_ENV */
-#endif /* AFS_SUN5_ENV */
-#if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
-      return (code);
+#endif /* AFS_SUN5_ENV */
+#if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
+    return (code);
 #endif
-    }
+}
 #endif /* AFS_SGI_ENV */
 #endif /* AFS_HPUX102_ENV */
-  
+
 #if defined(AFS_SGI_ENV)
   /* "pioctl" system call entry point; just pass argument to the parameterized
-                call below */
+   * call below */
 struct pioctlargs {
-       char            *path;
-       sysarg_t        cmd;
-       caddr_t         cmarg;
-       sysarg_t        follow;
+    char *path;
+    sysarg_t cmd;
+    caddr_t cmarg;
+    sysarg_t follow;
 };
 int
-afs_pioctl(struct pioctlargs *uap, rval_t *rvp)
+afs_pioctl(struct pioctlargs *uap, rval_t * rvp)
 {
     int code;
 
@@ -692,45 +751,63 @@ afs_pioctl(struct pioctlargs *uap, rval_t *rvp)
     return u.u_error;
 #endif
 }
-#endif /* AFS_SGI_ENV */
 
-#ifdef AFS_OSF_ENV
+#elif defined(AFS_OSF_ENV)
 afs_pioctl(p, args, retval)
-        struct proc *p;
-        void *args;
-        int *retval;
+     struct proc *p;
+     void *args;
+     int *retval;
 {
     struct a {
-        char    *path;
-        int     cmd;
-        caddr_t cmarg;
-        int     follow;
-    } *uap = (struct a *) args;
+       char *path;
+       int cmd;
+       caddr_t cmarg;
+       int follow;
+    } *uap = (struct a *)args;
 
     AFS_STATCNT(afs_pioctl);
     return (afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow));
 }
 
-#else  /* AFS_OSF_ENV */
-#if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
+#elif defined(AFS_FBSD50_ENV)
+int
+afs_pioctl(td, args, retval)
+     struct thread *td;
+     void *args;
+     int *retval;
+{
+    struct a {
+       char *path;
+       int cmd;
+       caddr_t cmarg;
+       int follow;
+    } *uap = (struct a *)args;
+
+    AFS_STATCNT(afs_pioctl);
+    return (afs_syscall_pioctl
+           (uap->path, uap->cmd, uap->cmarg, uap->follow, td->td_ucred));
+}
+
+#elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
+int
 afs_pioctl(p, args, retval)
-        struct proc *p;
-        void *args;
-        int *retval;
+     struct proc *p;
+     void *args;
+     int *retval;
 {
     struct a {
-        char    *path;
-        int     cmd;
-        caddr_t cmarg;
-        int     follow; 
-    } *uap = (struct a *) args;
-    
+       char *path;
+       int cmd;
+       caddr_t cmarg;
+       int follow;
+    } *uap = (struct a *)args;
+
     AFS_STATCNT(afs_pioctl);
-    return (afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow, p->p_cred->pc_ucred));
-}   
+    return (afs_syscall_pioctl
+           (uap->path, uap->cmd, uap->cmarg, uap->follow,
+            p->p_cred->pc_ucred));
+}
 
-#else   /* AFS_OSF_ENV */
-#endif
 #endif
 
 /* macro to avoid adding any more #ifdef's to pioctl code. */
@@ -740,262 +817,193 @@ afs_pioctl(p, args, retval)
 #define PIOCTL_FREE_CRED()
 #endif
 
+int
 #ifdef AFS_SUN5_ENV
 afs_syscall_pioctl(path, com, cmarg, follow, rvp, credp)
-    rval_t *rvp;
-    struct AFS_UCRED *credp;
+     rval_t *rvp;
+     struct AFS_UCRED *credp;
 #else
-#if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
+#if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
 afs_syscall_pioctl(path, com, cmarg, follow, credp)
-    struct AFS_UCRED *credp;
+     struct AFS_UCRED *credp;
 #else
 afs_syscall_pioctl(path, com, cmarg, follow)
 #endif
 #endif
-    char *path;
-    unsigned int       com;
-    caddr_t cmarg;
-    int        follow;
+     char *path;
+     unsigned int com;
+     caddr_t cmarg;
+     int follow;
 {
     struct afs_ioctl data;
-    struct AFS_UCRED *tmpcred, *foreigncreds = 0;
+    struct AFS_UCRED *tmpcred, *foreigncreds = NULL;
     register afs_int32 code = 0;
     struct vnode *vp;
 #ifdef AFS_DEC_ENV
     struct vnode *gp;
 #endif
 #ifdef AFS_AIX41_ENV
-    struct ucred *credp = crref(); /* don't free until done! */
+    struct ucred *credp = crref();     /* don't free until done! */
 #endif
 #ifdef AFS_LINUX22_ENV
-    cred_t *credp = crref(); /* don't free until done! */
+    cred_t *credp = crref();   /* don't free until done! */
     struct dentry *dp;
-
 #endif
+
     AFS_STATCNT(afs_syscall_pioctl);
-    if (follow) follow = 1;    /* compat. with old venus */
+    if (follow)
+       follow = 1;             /* compat. with old venus */
     code = copyin_afs_ioctl(cmarg, &data);
     if (code) {
        PIOCTL_FREE_CRED();
-#if defined(KERNEL_HAVE_SETUERROR)
+#if defined(KERNEL_HAVE_UERROR)
        setuerror(code);
 #endif
        return (code);
-  }
+    }
     if ((com & 0xff) == PSetClientContext) {
-#if defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
-       return EINVAL; /* Not handling these yet. */
-#else
-#if    defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV)
+#ifdef AFS_NEED_CLIENTCONTEXT
+#if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV)
        code = HandleClientContext(&data, &com, &foreigncreds, credp);
 #else
-#if    defined(AFS_HPUX101_ENV)
-       code=HandleClientContext(&data, &com, &foreigncreds, p_cred(u.u_procp));
-#else
-#ifdef AFS_SGI_ENV
-       code = HandleClientContext(&data, &com, &foreigncreds, OSI_GET_CURRENT_CRED());
-#else
-       code = HandleClientContext(&data, &com, &foreigncreds, u.u_cred);
-#endif /* AFS_SGI_ENV */
+       code = HandleClientContext(&data, &com, &foreigncreds, osi_curcred());
 #endif
-#endif
-#endif
-      if (code) {
-         if (foreigncreds) {
-             crfree(foreigncreds);
-         }
-         PIOCTL_FREE_CRED();
-#if defined(KERNEL_HAVE_SETUERROR)
-         return (setuerror(code), code);
+       if (code) {
+           if (foreigncreds) {
+               crfree(foreigncreds);
+           }
+           PIOCTL_FREE_CRED();
+#if defined(KERNEL_HAVE_UERROR)
+           return (setuerror(code), code);
 #else
-         return (code);
+           return (code);
 #endif
-      }
-    } 
-#if !defined(AFS_LINUX22_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV)
+       }
+#else /* AFS_NEED_CLIENTCONTEXT */
+       return EINVAL;
+#endif /* AFS_NEED_CLIENTCONTEXT */
+    }
+#ifdef AFS_NEED_CLIENTCONTEXT
     if (foreigncreds) {
-      /*
-       * We could have done without temporary setting the u.u_cred below
-       * (foreigncreds could be passed as param the pioctl modules)
-       * but calls such as afs_osi_suser() doesn't allow that since it
-       * references u.u_cred directly.  We could, of course, do something
-       * like afs_osi_suser(cred) which, I think, is better since it
-       * generalizes and supports multi cred environments...
-       */
+       /*
+        * We could have done without temporary setting the u.u_cred below
+        * (foreigncreds could be passed as param the pioctl modules)
+        * but calls such as afs_osi_suser() doesn't allow that since it
+        * references u.u_cred directly.  We could, of course, do something
+        * like afs_osi_suser(cred) which, I think, is better since it
+        * generalizes and supports multi cred environments...
+        */
 #ifdef AFS_SUN5_ENV
        tmpcred = credp;
        credp = foreigncreds;
-#else
-#ifdef AFS_AIX41_ENV
+#elif defined(AFS_AIX41_ENV)
        tmpcred = crref();      /* XXX */
        crset(foreigncreds);
-#else
-#if    defined(AFS_HPUX101_ENV)
+#elif defined(AFS_HPUX101_ENV)
        tmpcred = p_cred(u.u_procp);
        set_p_cred(u.u_procp, foreigncreds);
+#elif defined(AFS_SGI_ENV)
+       tmpcred = OSI_GET_CURRENT_CRED();
+       OSI_SET_CURRENT_CRED(foreigncreds);
 #else
-#ifdef AFS_SGI_ENV
-        tmpcred = OSI_GET_CURRENT_CRED();
-        OSI_SET_CURRENT_CRED(foreigncreds);
-#else
-        tmpcred = u.u_cred;
-        u.u_cred = foreigncreds;
-#endif /* AFS_SGI64_ENV */
-#endif /* AFS_HPUX101_ENV */
-#endif
+       tmpcred = u.u_cred;
+       u.u_cred = foreigncreds;
 #endif
     }
-#endif
+#endif /* AFS_NEED_CLIENTCONTEXT */
     if ((com & 0xff) == 15) {
-      /* special case prefetch so entire pathname eval occurs in helper process.
-        otherwise, the pioctl call is essentially useless */
-#if    defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
-       code =  Prefetch(path, &data, follow,
-                        foreigncreds ? foreigncreds : credp);
-#else
-#if    defined(AFS_HPUX101_ENV)
-       code =  Prefetch(path, &data, follow, p_cred(u.u_procp));
-#else
-#ifdef AFS_SGI_ENV 
-       code =  Prefetch(path, &data, follow, OSI_GET_CURRENT_CRED());
+       /* special case prefetch so entire pathname eval occurs in helper process.
+        * otherwise, the pioctl call is essentially useless */
+#if    defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
+       code =
+           Prefetch(path, &data, follow,
+                    foreigncreds ? foreigncreds : credp);
 #else
-       code =  Prefetch(path, &data, follow, u.u_cred);
-#endif /* AFS_SGI64_ENV */
-#endif /* AFS_HPUX101_ENV */
+       code = Prefetch(path, &data, follow, osi_curcred());
 #endif
-#if !defined(AFS_LINUX22_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV)
-       if (foreigncreds) {
-#ifdef AFS_AIX41_ENV
-           crset(tmpcred);     /* restore original credentials */
-#else
-#if    defined(AFS_HPUX101_ENV)
-       set_p_cred(u.u_procp, tmpcred); /* restore original credentials */
-#else
-#ifndef        AFS_SUN5_ENV
-#ifdef AFS_SGI_ENV
-           OSI_SET_CURRENT_CRED(tmpcred);          /* restore original credentials */
-#else
-           u.u_cred = tmpcred;     /* restore original credentials */
-#endif
-#endif
-#endif /* AFS_HPUX101_ENV */
-           crfree(foreigncreds);
-#endif
-       }
-#endif /* AFS_LINUX22_ENV */
-       PIOCTL_FREE_CRED();
-#if defined(KERNEL_HAVE_SETUERROR)
-       return (setuerror(code), code);
-#else
-       return (code);
+       vp = NULL;
+#if defined(KERNEL_HAVE_UERROR)
+       setuerror(code);
 #endif
+       goto rescred;
     }
     if (path) {
        AFS_GUNLOCK();
 #ifdef AFS_AIX41_ENV
-       code = lookupname(path, USR, follow, NULL, &vp,
-                       foreigncreds ? foreigncreds : credp);
+       code =
+           lookupname(path, USR, follow, NULL, &vp,
+                      foreigncreds ? foreigncreds : credp);
 #else
 #ifdef AFS_LINUX22_ENV
-       code = gop_lookupname(path, AFS_UIOUSER, follow,  NULL, &dp);
+       code = gop_lookupname(path, AFS_UIOUSER, follow, NULL, &dp);
        if (!code)
            vp = (struct vnode *)dp->d_inode;
 #else
-       code = gop_lookupname(path, AFS_UIOUSER, follow,  NULL, &vp);
+       code = gop_lookupname(path, AFS_UIOUSER, follow, NULL, &vp);
 #endif /* AFS_LINUX22_ENV */
 #endif /* AFS_AIX41_ENV */
        AFS_GLOCK();
        if (code) {
-#if !defined(AFS_LINUX22_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV)
-           if (foreigncreds) {
-#ifdef AFS_AIX41_ENV
-               crset(tmpcred); /* restore original credentials */
-#else
-#if    defined(AFS_HPUX101_ENV)
-       set_p_cred(u.u_procp, tmpcred); /* restore original credentials */
-#else
-#if    !defined(AFS_SUN5_ENV)
-#ifdef AFS_SGI_ENV
-               OSI_SET_CURRENT_CRED(tmpcred);      /* restore original credentials */
-#else
-               u.u_cred = tmpcred;         /* restore original credentials */
-#endif /* AFS_SGI64_ENV */
-#endif
-#endif /* AFS_HPUX101_ENV */
-               crfree(foreigncreds);
-#endif
-           }
-#endif /* AFS_LINUX22_ENV */
-           PIOCTL_FREE_CRED();
-#if defined(KERNEL_HAVE_SETUERROR)
-           return(setuerror(code), code);
-#else
-           return (code);
+           vp = NULL;
+#if defined(KERNEL_HAVE_UERROR)
+           setuerror(code);
 #endif
+           goto rescred;
        }
-    }
-    else vp = NULL;
-    
+    } else
+       vp = NULL;
+
     /* now make the call if we were passed no file, or were passed an AFS file */
     if (!vp || IsAfsVnode(vp)) {
-#ifdef AFS_DEC_ENV
-      /* Ultrix 4.0: can't get vcache entry unless we've got an AFS gnode.
-       * So, we must test in this part of the code.  Also, must arrange to
-       * GRELE the original gnode pointer when we're done, since in Ultrix 4.0,
-       * we hold gnodes, whose references hold our vcache entries.
-       */
-      if (vp) {
-       gp = vp;        /* remember for "put" */
-       vp = (struct vnode *) afs_gntovn(vp);   /* get vcache from gp */
-      }
-      else gp = NULL;
-#endif 
-#ifdef AFS_SUN5_ENV
-      code = afs_HandlePioctl(vp, com, &data, follow, &credp);
-#else
-#ifdef AFS_AIX41_ENV
-      {
-         struct ucred *cred1, *cred2;
-         if (foreigncreds) {
-             cred1 = cred2 = foreigncreds;
-         } else {
-             cred1 = cred2 = credp;
-         }
-         code = afs_HandlePioctl(vp, com, &data, follow, &cred1);
-         if (cred1 != cred2) { 
-             /* something changed the creds */
-             crset(cred1);
-         }
-      }
-#else
-#if    defined(AFS_HPUX101_ENV)
-      {
-         struct ucred *cred = p_cred(u.u_procp);
-         code = afs_HandlePioctl(vp, com, &data, follow, &cred);
-      }
-#else
-#ifdef AFS_SGI_ENV
-      {
-      struct cred *credp;
-      credp = OSI_GET_CURRENT_CRED();
-      code = afs_HandlePioctl(vp, com, &data, follow, &credp);
-      }
-#else
-#if defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
-      code = afs_HandlePioctl(vp, com, &data, follow, &credp);
+#if defined(AFS_DEC_ENV)
+       /* Ultrix 4.0: can't get vcache entry unless we've got an AFS gnode.
+        * So, we must test in this part of the code.  Also, must arrange to
+        * GRELE the original gnode pointer when we're done, since in Ultrix 4.0,
+        * we hold gnodes, whose references hold our vcache entries.
+        */
+       if (vp) {
+           gp = vp;            /* remember for "put" */
+           vp = (struct vnode *)afs_gntovn(vp);        /* get vcache from gp */
+       } else
+           gp = NULL;
+#elif defined(AFS_SUN5_ENV)
+       code = afs_HandlePioctl(vp, com, &data, follow, &credp);
+#elif defined(AFS_AIX41_ENV)
+       {
+           struct ucred *cred1, *cred2;
+
+           if (foreigncreds) {
+               cred1 = cred2 = foreigncreds;
+           } else {
+               cred1 = cred2 = credp;
+           }
+           code = afs_HandlePioctl(vp, com, &data, follow, &cred1);
+           if (cred1 != cred2) {
+               /* something changed the creds */
+               crset(cred1);
+           }
+       }
+#elif defined(AFS_HPUX101_ENV)
+       {
+           struct ucred *cred = p_cred(u.u_procp);
+           code = afs_HandlePioctl(vp, com, &data, follow, &cred);
+       }
+#elif defined(AFS_SGI_ENV)
+       {
+           struct cred *credp;
+           credp = OSI_GET_CURRENT_CRED();
+           code = afs_HandlePioctl(vp, com, &data, follow, &credp);
+       }
+#elif defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
+       code = afs_HandlePioctl(vp, com, &data, follow, &credp);
 #else
-      code = afs_HandlePioctl(vp, com, &data, follow, &u.u_cred);
+       code = afs_HandlePioctl(vp, com, &data, follow, &u.u_cred);
 #endif
-#endif /* AFS_SGI_ENV */
-#endif /* AFS_HPUX101_ENV */
-#endif /* AFS_AIX41_ENV */
-#endif /* AFS_SUN5_ENV */
     } else {
-#if defined(KERNEL_HAVE_SETUERROR)
+#if defined(KERNEL_HAVE_UERROR)
        setuerror(EINVAL);
 #else
-       code = EINVAL;  /* not in /afs */
+       code = EINVAL;          /* not in /afs */
 #endif
 #ifdef AFS_DEC_ENV
        if (vp) {
@@ -1005,60 +1013,62 @@ afs_syscall_pioctl(path, com, cmarg, follow)
 #endif
     }
 
-#if !defined(AFS_LINUX22_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV)
+  rescred:
+#if defined(AFS_NEED_CLIENTCONTEXT)
     if (foreigncreds) {
 #ifdef AFS_AIX41_ENV
-       crset(tmpcred);
+       crset(tmpcred);         /* restore original credentials */
 #else
 #if    defined(AFS_HPUX101_ENV)
-       set_p_cred(u.u_procp, tmpcred); /* restore original credentials */
-#else
-#ifndef        AFS_SUN5_ENV
-#ifdef AFS_SGI_ENV
-       OSI_SET_CURRENT_CRED(tmpcred);      /* restore original credentials */
-#else
-       u.u_cred = tmpcred;         /* restore original credentials */
-#endif /* ASF_SGI64_ENV */
-#endif
+       set_p_cred(u.u_procp, tmpcred); /* restore original credentials */
+#elif  defined(AFS_SGI_ENV)
+       OSI_SET_CURRENT_CRED(tmpcred);  /* restore original credentials */
+#elif  !defined(AFS_SUN5_ENV)
+       osi_curcred() = tmpcred;        /* restore original credentials */
 #endif /* AFS_HPUX101_ENV */
        crfree(foreigncreds);
-#endif
+#endif /* AIX41 */
     }
-#endif /* AFS_LINUX22_ENV */
+#endif /* AFS_NEED_CLIENTCONTEXT */
     if (vp) {
 #ifdef AFS_LINUX22_ENV
        dput(dp);
 #else
-       AFS_RELE(vp);   /* put vnode back */
+       AFS_RELE(vp);           /* put vnode back */
 #endif
     }
     PIOCTL_FREE_CRED();
-#if defined(KERNEL_HAVE_SETUERROR)
-    if (!getuerror())  
-       setuerror(code);
+#if defined(KERNEL_HAVE_UERROR)
+    if (!getuerror())
+       setuerror(code);
     return (getuerror());
 #else
     return (code);
 #endif
 }
-  
-  
-int afs_HandlePioctl(struct vcache *avc, afs_int32 acom, 
-       register struct afs_ioctl *ablob, int afollow, struct AFS_UCRED **acred)
+
+
+int
+afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
+                register struct afs_ioctl *ablob, int afollow,
+                struct AFS_UCRED **acred)
 {
+    struct vcache *avc;
     struct vrequest treq;
     register afs_int32 code;
     register afs_int32 function, device;
     afs_int32 inSize, outSize;
     char *inData, *outData;
-    int (*(*pioctlSw))();
+    int (*(*pioctlSw)) ();
     int pioctlSwSize;
     struct afs_fakestat_state fakestate;
 
+    avc = avp ? VTOAFS(avp) : NULL;
     afs_Trace3(afs_iclSetp, CM_TRACE_PIOCTL, ICL_TYPE_INT32, acom & 0xff,
               ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, afollow);
     AFS_STATCNT(HandlePioctl);
-    if ((code = afs_InitReq(&treq, *acred))) return code;
+    if ((code = afs_InitReq(&treq, *acred)))
+       return code;
     afs_InitFakeStat(&fakestate);
     if (avc) {
        code = afs_EvalFakeStat(&avc, &fakestate, &treq);
@@ -1069,31 +1079,35 @@ int afs_HandlePioctl(struct vcache *avc, afs_int32 acom,
     }
     device = (acom & 0xff00) >> 8;
     switch (device) {
-       case 'V':       /* Original pioctl's */
-               pioctlSw = VpioctlSw;
-               pioctlSwSize = sizeof(VpioctlSw);
-               break;
-       case 'C':       /* Coordinated/common pioctl's */
-               pioctlSw = CpioctlSw;
-               pioctlSwSize = sizeof(CpioctlSw);
-               break;
-       default:
-               afs_PutFakeStat(&fakestate);
-               return EINVAL;
+    case 'V':                  /* Original pioctls */
+       pioctlSw = VpioctlSw;
+       pioctlSwSize = sizeof(VpioctlSw);
+       break;
+    case 'C':                  /* Coordinated/common pioctls */
+       pioctlSw = CpioctlSw;
+       pioctlSwSize = sizeof(CpioctlSw);
+       break;
+    default:
+       afs_PutFakeStat(&fakestate);
+       return EINVAL;
     }
     function = acom & 0xff;
     if (function >= (pioctlSwSize / sizeof(char *))) {
        afs_PutFakeStat(&fakestate);
-       return EINVAL;  /* out of range */
+       return EINVAL;          /* out of range */
     }
     inSize = ablob->in_size;
-    if (inSize >= PIGGYSIZE) return E2BIG;
+
+    /* Do all range checking before continuing */
+    if (inSize >= PIGGYSIZE || inSize < 0 || ablob->out_size < 0)
+       return E2BIG;
+
     inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
     if (inSize > 0) {
-      AFS_COPYIN(ablob->in, inData, inSize, code);
-      inData[inSize]='\0';
-    }
-    else code = 0;
+       AFS_COPYIN(ablob->in, inData, inSize, code);
+       inData[inSize] = '\0';
+    } else
+       code = 0;
     if (code) {
        osi_FreeLargeSpace(inData);
        afs_PutFakeStat(&fakestate);
@@ -1101,32 +1115,35 @@ int afs_HandlePioctl(struct vcache *avc, afs_int32 acom,
     }
     outData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
     outSize = 0;
-    code = (*pioctlSw[function])(avc, function, &treq, inData, outData, inSize, &outSize, acred);
+    code =
+       (*pioctlSw[function]) (avc, function, &treq, inData, outData, inSize,
+                              &outSize, acred);
     osi_FreeLargeSpace(inData);
     if (code == 0 && ablob->out_size > 0) {
-      if (outSize > ablob->out_size) outSize = ablob->out_size;
-      if (outSize >= PIGGYSIZE) code = E2BIG;
-      else if  (outSize) {
-       outData[outSize]='\0';
-       AFS_COPYOUT(outData, ablob->out, outSize, code);
-      }
+       if (outSize > ablob->out_size)
+           outSize = ablob->out_size;
+       if (outSize >= PIGGYSIZE)
+           code = E2BIG;
+       else if (outSize) {
+           outData[outSize] = '\0';
+           AFS_COPYOUT(outData, ablob->out, outSize, code);
+       }
     }
     osi_FreeLargeSpace(outData);
     afs_PutFakeStat(&fakestate);
     return afs_CheckCode(code, &treq, 41);
-  }
-  
+}
+
 DECL_PIOCTL(PGetFID)
 {
-    register afs_int32 code;
-    
     AFS_STATCNT(PGetFID);
-    if (!avc) return EINVAL;
+    if (!avc)
+       return EINVAL;
     memcpy(aout, (char *)&avc->fid, sizeof(struct VenusFid));
     *aoutSize = sizeof(struct VenusFid);
     return 0;
-  }
-  
+}
+
 DECL_PIOCTL(PSetAcl)
 {
     register afs_int32 code;
@@ -1135,28 +1152,29 @@ DECL_PIOCTL(PSetAcl)
     struct AFSVolSync tsync;
     struct AFSFetchStatus OutStatus;
     XSTATS_DECLS;
-    
+
     AFS_STATCNT(PSetAcl);
     if (!avc)
-      return EINVAL;
-    if ((acl.AFSOpaque_len = strlen(ain)+1) > 1000)
-      return EINVAL;
+       return EINVAL;
+    if ((acl.AFSOpaque_len = strlen(ain) + 1) > 1000)
+       return EINVAL;
 
     acl.AFSOpaque_val = ain;
     do {
-      tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK);
-      if (tconn) {
-       XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREACL);
-       RX_AFS_GUNLOCK();
-       code = RXAFS_StoreACL(tconn->id, (struct AFSFid *) &avc->fid.Fid,
-                             &acl, &OutStatus, &tsync);
-       RX_AFS_GLOCK();
-       XSTATS_END_TIME;
-      }
-      else code = -1;
-    } while
-       (afs_Analyze(tconn, code, &avc->fid, areq,
-                    AFS_STATS_FS_RPCIDX_STOREACL, SHARED_LOCK, NULL));
+       tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK);
+       if (tconn) {
+           XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREACL);
+           RX_AFS_GUNLOCK();
+           code =
+               RXAFS_StoreACL(tconn->id, (struct AFSFid *)&avc->fid.Fid,
+                              &acl, &OutStatus, &tsync);
+           RX_AFS_GLOCK();
+           XSTATS_END_TIME;
+       } else
+           code = -1;
+    } while (afs_Analyze
+            (tconn, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_STOREACL,
+             SHARED_LOCK, NULL));
 
     /* now we've forgotten all of the access info */
     ObtainWriteLock(&afs_xcbhash, 455);
@@ -1167,48 +1185,50 @@ DECL_PIOCTL(PSetAcl)
     if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
        osi_dnlc_purgedp(avc);
     return code;
-  }
+}
 
 int afs_defaultAsynchrony = 0;
 
 DECL_PIOCTL(PStoreBehind)
 {
-  afs_int32 code = 0;
-  struct sbstruct *sbr;
+    afs_int32 code = 0;
+    struct sbstruct *sbr;
 
-  sbr = (struct sbstruct *)ain;
-  if (sbr->sb_default != -1) {
-    if (afs_osi_suser(*acred))
-      afs_defaultAsynchrony = sbr->sb_default;
-    else code = EPERM;
-  }
+    sbr = (struct sbstruct *)ain;
+    if (sbr->sb_default != -1) {
+       if (afs_osi_suser(*acred))
+           afs_defaultAsynchrony = sbr->sb_default;
+       else
+           code = EPERM;
+    }
 
-  if (avc && (sbr->sb_thisfile != -1)) {
-    if (afs_AccessOK(avc, PRSFS_WRITE | PRSFS_ADMINISTER, 
-                     areq, DONT_CHECK_MODE_BITS))
-      avc->asynchrony = sbr->sb_thisfile;
-    else code = EACCES;
-  }
+    if (avc && (sbr->sb_thisfile != -1)) {
+       if (afs_AccessOK
+           (avc, PRSFS_WRITE | PRSFS_ADMINISTER, areq, DONT_CHECK_MODE_BITS))
+           avc->asynchrony = sbr->sb_thisfile;
+       else
+           code = EACCES;
+    }
 
-  *aoutSize = sizeof(struct sbstruct);
-  sbr = (struct sbstruct *)aout;
-  sbr->sb_default = afs_defaultAsynchrony;
-  if (avc) {
-    sbr->sb_thisfile = avc->asynchrony;
-  }
+    *aoutSize = sizeof(struct sbstruct);
+    sbr = (struct sbstruct *)aout;
+    sbr->sb_default = afs_defaultAsynchrony;
+    if (avc) {
+       sbr->sb_thisfile = avc->asynchrony;
+    }
 
-  return code;
+    return code;
 }
 
 DECL_PIOCTL(PGCPAGs)
 {
-  if (!afs_osi_suser(*acred)) {
-    return EACCES;
-  }
-  afs_gcpags = AFS_GCPAGS_USERDISABLED;
-  return 0;
+    if (!afs_osi_suser(*acred)) {
+       return EACCES;
+    }
+    afs_gcpags = AFS_GCPAGS_USERDISABLED;
+    return 0;
 }
-  
+
 DECL_PIOCTL(PGetAcl)
 {
     struct AFSOpaque acl;
@@ -1220,7 +1240,8 @@ DECL_PIOCTL(PGetAcl)
     XSTATS_DECLS;
 
     AFS_STATCNT(PGetAcl);
-    if (!avc) return EINVAL;
+    if (!avc)
+       return EINVAL;
     Fid.Volume = avc->fid.Fid.Volume;
     Fid.Vnode = avc->fid.Fid.Vnode;
     Fid.Unique = avc->fid.Fid.Unique;
@@ -1231,116 +1252,116 @@ DECL_PIOCTL(PGetAcl)
         * we currently use the top 2-bytes (vals 0-4) to tell which
         * type of acl to bring back. Horrible hack but this will
         * cause the least number of changes to code size and interfaces.
-         */
+        */
        if (Fid.Vnode & 0xc0000000)
            return ERANGE;
        Fid.Vnode |= (ainSize << 30);
     }
     acl.AFSOpaque_val = aout;
     do {
-      tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK);
-      if (tconn) {
-       *aout = 0;
-       XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHACL);
-       RX_AFS_GUNLOCK();
-       code = RXAFS_FetchACL(tconn->id, &Fid,
-                             &acl, &OutStatus, &tsync);
-       RX_AFS_GLOCK();
-       XSTATS_END_TIME;
-      }
-      else code = -1;
-    } while
-       (afs_Analyze(tconn, code, &avc->fid, areq,
-                    AFS_STATS_FS_RPCIDX_FETCHACL,
-                    SHARED_LOCK, NULL));
+       tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK);
+       if (tconn) {
+           *aout = 0;
+           XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHACL);
+           RX_AFS_GUNLOCK();
+           code = RXAFS_FetchACL(tconn->id, &Fid, &acl, &OutStatus, &tsync);
+           RX_AFS_GLOCK();
+           XSTATS_END_TIME;
+       } else
+           code = -1;
+    } while (afs_Analyze
+            (tconn, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_FETCHACL,
+             SHARED_LOCK, NULL));
 
     if (code == 0) {
-      *aoutSize = (acl.AFSOpaque_len == 0 ? 1 : acl.AFSOpaque_len);
+       *aoutSize = (acl.AFSOpaque_len == 0 ? 1 : acl.AFSOpaque_len);
     }
     return code;
 }
-  
+
 DECL_PIOCTL(PNoop)
 {
     AFS_STATCNT(PNoop);
     return 0;
 }
-  
+
 DECL_PIOCTL(PBogus)
 {
     AFS_STATCNT(PBogus);
     return EINVAL;
 }
-  
+
 DECL_PIOCTL(PGetFileCell)
 {
     register struct cell *tcell;
-    
+
     AFS_STATCNT(PGetFileCell);
-    if (!avc) return EINVAL;
+    if (!avc)
+       return EINVAL;
     tcell = afs_GetCell(avc->fid.Cell, READ_LOCK);
-    if (!tcell) return ESRCH;
+    if (!tcell)
+       return ESRCH;
     strcpy(aout, tcell->cellName);
     afs_PutCell(tcell, READ_LOCK);
     *aoutSize = strlen(aout) + 1;
     return 0;
-  }
-  
+}
+
 DECL_PIOCTL(PGetWSCell)
 {
     struct cell *tcell = NULL;
-    
+
     AFS_STATCNT(PGetWSCell);
-    if ( !afs_resourceinit_flag )      /* afs deamons havn't started yet */
-       return EIO;          /* Inappropriate ioctl for device */
+    if (!afs_resourceinit_flag)        /* afs daemons haven't started yet */
+       return EIO;             /* Inappropriate ioctl for device */
 
     tcell = afs_GetPrimaryCell(READ_LOCK);
-    if (!tcell)                /* no primary cell? */
-      return ESRCH;
+    if (!tcell)                        /* no primary cell? */
+       return ESRCH;
     strcpy(aout, tcell->cellName);
     *aoutSize = strlen(aout) + 1;
     afs_PutCell(tcell, READ_LOCK);
     return 0;
-  }
-  
+}
+
 DECL_PIOCTL(PGetUserCell)
 {
     register afs_int32 i;
     register struct unixuser *tu;
     register struct cell *tcell;
-    
+
     AFS_STATCNT(PGetUserCell);
-    if ( !afs_resourceinit_flag )      /* afs deamons havn't started yet */
-       return EIO;          /* Inappropriate ioctl for device */
+    if (!afs_resourceinit_flag)        /* afs daemons haven't started yet */
+       return EIO;             /* Inappropriate ioctl for device */
 
     /* return the cell name of the primary cell for this user */
     i = UHash(areq->uid);
-    ObtainWriteLock(&afs_xuser,224);
-    for(tu = afs_users[i]; tu; tu = tu->next) {
-      if (tu->uid == areq->uid && (tu->states & UPrimary)) {
-       tu->refCount++;
-       ReleaseWriteLock(&afs_xuser);
-       break;
-      }
+    ObtainWriteLock(&afs_xuser, 224);
+    for (tu = afs_users[i]; tu; tu = tu->next) {
+       if (tu->uid == areq->uid && (tu->states & UPrimary)) {
+           tu->refCount++;
+           ReleaseWriteLock(&afs_xuser);
+           break;
+       }
     }
     if (tu) {
-      tcell = afs_GetCell(tu->cell, READ_LOCK);
-      afs_PutUser(tu, WRITE_LOCK);
-      if (!tcell) return ESRCH;
-      else {
-       strcpy(aout, tcell->cellName);
-       afs_PutCell(tcell, READ_LOCK);
-       *aoutSize =     strlen(aout)+1;     /* 1 for the null */
-      }
-    }
-    else {
-      ReleaseWriteLock(&afs_xuser);
-      *aout = 0;
-      *aoutSize = 1;
+       tcell = afs_GetCell(tu->cell, READ_LOCK);
+       afs_PutUser(tu, WRITE_LOCK);
+       if (!tcell)
+           return ESRCH;
+       else {
+           strcpy(aout, tcell->cellName);
+           afs_PutCell(tcell, READ_LOCK);
+           *aoutSize = strlen(aout) + 1;       /* 1 for the null */
+       }
+    } else {
+       ReleaseWriteLock(&afs_xuser);
+       *aout = 0;
+       *aoutSize = 1;
     }
     return 0;
-  }
-  
+}
+
 DECL_PIOCTL(PSetTokens)
 {
     afs_int32 i;
@@ -1351,58 +1372,63 @@ DECL_PIOCTL(PSetTokens)
     int stLen;
     struct vrequest treq;
     afs_int32 flag, set_parent_pag = 0;
-    
+
     AFS_STATCNT(PSetTokens);
     if (!afs_resourceinit_flag) {
-      return EIO;
+       return EIO;
     }
     memcpy((char *)&i, ain, sizeof(afs_int32));
     ain += sizeof(afs_int32);
-    stp        = ain;  /* remember where the ticket is */
-    if (i < 0 || i > 2000) return EINVAL;      /* malloc may fail */
+    stp = ain;                 /* remember where the ticket is */
+    if (i < 0 || i > 2000)
+       return EINVAL;          /* malloc may fail */
+    if (i > MAXKTCTICKETLEN)
+       return EINVAL;
     stLen = i;
-    ain        += i;   /* skip over ticket */
+    ain += i;                  /* skip over ticket */
     memcpy((char *)&i, ain, sizeof(afs_int32));
     ain += sizeof(afs_int32);
     if (i != sizeof(struct ClearToken)) {
-      return EINVAL;
+       return EINVAL;
     }
     memcpy((char *)&clear, ain, sizeof(struct ClearToken));
-    if (clear.AuthHandle == -1)        clear.AuthHandle = 999; /* more rxvab compat stuff */
+    if (clear.AuthHandle == -1)
+       clear.AuthHandle = 999; /* more rxvab compat stuff */
     ain += sizeof(struct ClearToken);
-    if (ainSize != 2*sizeof(afs_int32) + stLen + sizeof(struct ClearToken)) {
-      /* still stuff left?  we've got primary flag and cell name.  Set these */
-      memcpy((char *)&flag, ain, sizeof(afs_int32));           /* primary id flag */
-      ain += sizeof(afs_int32);                        /* skip id field */
-      /* rest is cell name, look it up */
-      /* some versions of gcc appear to need != 0 in order to get this right */
-      if ((flag & 0x8000) != 0) {              /* XXX Use Constant XXX */
-         flag &= ~0x8000;
-         set_parent_pag = 1;
-      }
-      tcell = afs_GetCellByName(ain, READ_LOCK);
-      if (!tcell) goto nocell;
-    }
-    else {
-      /* default to primary cell, primary id */
-      flag = 1;                /* primary id */
-      tcell = afs_GetPrimaryCell(READ_LOCK);
-      if (!tcell) goto nocell;
+    if (ainSize != 2 * sizeof(afs_int32) + stLen + sizeof(struct ClearToken)) {
+       /* still stuff left?  we've got primary flag and cell name.  Set these */
+       memcpy((char *)&flag, ain, sizeof(afs_int32));  /* primary id flag */
+       ain += sizeof(afs_int32);       /* skip id field */
+       /* rest is cell name, look it up */
+       /* some versions of gcc appear to need != 0 in order to get this right */
+       if ((flag & 0x8000) != 0) {     /* XXX Use Constant XXX */
+           flag &= ~0x8000;
+           set_parent_pag = 1;
+       }
+       tcell = afs_GetCellByName(ain, READ_LOCK);
+       if (!tcell)
+           goto nocell;
+    } else {
+       /* default to primary cell, primary id */
+       flag = 1;               /* primary id */
+       tcell = afs_GetPrimaryCell(READ_LOCK);
+       if (!tcell)
+           goto nocell;
     }
     i = tcell->cellNum;
     afs_PutCell(tcell, READ_LOCK);
     if (set_parent_pag) {
-       int pag;
-#if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
+       afs_int32 pag;
+#if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
 #if defined(AFS_DARWIN_ENV)
-        struct proc *p=current_proc(); /* XXX */
+       struct proc *p = current_proc();        /* XXX */
 #else
-        struct proc *p=curproc; /* XXX */
+       struct proc *p = curproc;       /* XXX */
 #endif
-        uprintf("Process %d (%s) tried to change pags in PSetTokens\n",
-                p->p_pid, p->p_comm);
-        if (!setpag(p, acred, -1, &pag, 1)) {
-#else   
+       uprintf("Process %d (%s) tried to change pags in PSetTokens\n",
+               p->p_pid, p->p_comm);
+       if (!setpag(p, acred, -1, &pag, 1)) {
+#else
 #ifdef AFS_OSF_ENV
        if (!setpag(u.u_procp, acred, -1, &pag, 1)) {   /* XXX u.u_procp is a no-op XXX */
 #else
@@ -1414,12 +1440,12 @@ DECL_PIOCTL(PSetTokens)
        }
     }
     /* now we just set the tokens */
-    tu = afs_GetUser(areq->uid,        i, WRITE_LOCK); /* i has the cell # */
+    tu = afs_GetUser(areq->uid, i, WRITE_LOCK);        /* i has the cell # */
     tu->vid = clear.ViceId;
     if (tu->stp != NULL) {
-      afs_osi_Free(tu->stp, tu->stLen);
+       afs_osi_Free(tu->stp, tu->stLen);
     }
-    tu->stp = (char *) afs_osi_Alloc(stLen);
+    tu->stp = (char *)afs_osi_Alloc(stLen);
     tu->stLen = stLen;
     memcpy(tu->stp, stp, stLen);
     tu->ct = clear;
@@ -1430,7 +1456,7 @@ DECL_PIOCTL(PSetTokens)
     tu->states |= UHasTokens;
     tu->states &= ~UTokensBad;
     afs_SetPrimary(tu, flag);
-    tu->tokenTime =osi_Time();
+    tu->tokenTime = osi_Time();
     afs_ResetUserConns(tu);
     afs_PutUser(tu, WRITE_LOCK);
 
@@ -1438,70 +1464,77 @@ DECL_PIOCTL(PSetTokens)
 
   nocell:
     {
-    int t1;
-    t1 = afs_initState;
-    if (t1 < 101)
-      return EIO;
-    else
-      return ESRCH;
-  }
-}  
+       int t1;
+       t1 = afs_initState;
+       if (t1 < 101)
+           return EIO;
+       else
+           return ESRCH;
+    }
+}
 
 DECL_PIOCTL(PGetVolumeStatus)
 {
     char volName[32];
-    char offLineMsg[256];
-    char motd[256];
+    char *offLineMsg = afs_osi_Alloc(256);
+    char *motd = afs_osi_Alloc(256);
     register struct conn *tc;
-    register afs_int32 code;
+    register afs_int32 code = 0;
     struct VolumeStatus volstat;
     register char *cp;
     char *Name, *OfflineMsg, *MOTD;
     XSTATS_DECLS;
 
     AFS_STATCNT(PGetVolumeStatus);
-    if (!avc) return EINVAL;
+    if (!avc) {
+       code = EINVAL;
+       goto out;
+    }
     Name = volName;
     OfflineMsg = offLineMsg;
     MOTD = motd;
     do {
-      tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
-      if (tc) {
-       XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS);
-       RX_AFS_GUNLOCK();
-       code = RXAFS_GetVolumeStatus(tc->id, avc->fid.Fid.Volume, &volstat,
-                                    &Name, &OfflineMsg, &MOTD);
-       RX_AFS_GLOCK();
-       XSTATS_END_TIME;
-      }
-      else code = -1;
-    } while
-      (afs_Analyze(tc, code, &avc->fid, areq,
-                  AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS,
-                  SHARED_LOCK, NULL));
-
-    if (code) return code;
+       tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
+       if (tc) {
+           XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS);
+           RX_AFS_GUNLOCK();
+           code =
+               RXAFS_GetVolumeStatus(tc->id, avc->fid.Fid.Volume, &volstat,
+                                     &Name, &OfflineMsg, &MOTD);
+           RX_AFS_GLOCK();
+           XSTATS_END_TIME;
+       } else
+           code = -1;
+    } while (afs_Analyze
+            (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS,
+             SHARED_LOCK, NULL));
+
+    if (code)
+       goto out;
     /* Copy all this junk into msg->im_data, keeping track of the lengths. */
     cp = aout;
     memcpy(cp, (char *)&volstat, sizeof(VolumeStatus));
     cp += sizeof(VolumeStatus);
     strcpy(cp, volName);
-    cp += strlen(volName)+1;
+    cp += strlen(volName) + 1;
     strcpy(cp, offLineMsg);
-    cp += strlen(offLineMsg)+1;
+    cp += strlen(offLineMsg) + 1;
     strcpy(cp, motd);
-    cp += strlen(motd)+1;
+    cp += strlen(motd) + 1;
     *aoutSize = (cp - aout);
-    return 0;
+  out:
+    afs_osi_Free(offLineMsg, 256);
+    afs_osi_Free(motd, 256);
+    return code;
 }
 
 DECL_PIOCTL(PSetVolumeStatus)
 {
     char volName[32];
-    char offLineMsg[256];
-    char motd[256];
+    char *offLineMsg = afs_osi_Alloc(256);
+    char *motd = afs_osi_Alloc(256);
     register struct conn *tc;
-    register afs_int32 code;
+    register afs_int32 code = 0;
     struct AFSFetchVolumeStatus volstat;
     struct AFSStoreVolumeStatus storeStat;
     register struct volume *tvp;
@@ -1509,9 +1542,10 @@ DECL_PIOCTL(PSetVolumeStatus)
     XSTATS_DECLS;
 
     AFS_STATCNT(PSetVolumeStatus);
-    if (!avc) return EINVAL;
+    if (!avc)
+       return EINVAL;
 
-    tvp        = afs_GetVolume(&avc->fid, areq, READ_LOCK);       
+    tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK);
     if (tvp) {
        if (tvp->states & (VRO | VBackup)) {
            afs_PutVolume(tvp, READ_LOCK);
@@ -1527,11 +1561,11 @@ DECL_PIOCTL(PSetVolumeStatus)
     if (strlen(cp) >= sizeof(volName))
        return E2BIG;
     strcpy(volName, cp);
-    cp += strlen(volName)+1;
+    cp += strlen(volName) + 1;
     if (strlen(cp) >= sizeof(offLineMsg))
        return E2BIG;
     strcpy(offLineMsg, cp);
-    cp +=  strlen(offLineMsg)+1;
+    cp += strlen(offLineMsg) + 1;
     if (strlen(cp) >= sizeof(motd))
        return E2BIG;
     strcpy(motd, cp);
@@ -1547,53 +1581,58 @@ DECL_PIOCTL(PSetVolumeStatus)
     do {
        tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
        if (tc) {
-          XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS);
+           XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS);
            RX_AFS_GUNLOCK();
-           code = RXAFS_SetVolumeStatus(tc->id, avc->fid.Fid.Volume,
-                                       &storeStat, volName, offLineMsg, motd);
+           code =
+               RXAFS_SetVolumeStatus(tc->id, avc->fid.Fid.Volume, &storeStat,
+                                     volName, offLineMsg, motd);
            RX_AFS_GLOCK();
-          XSTATS_END_TIME;
-       }
-       else code = -1;
-    } while
-      (afs_Analyze(tc, code, &avc->fid, areq,
-                  AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS,
-                  SHARED_LOCK, NULL));
-
-    if (code) return code;
+           XSTATS_END_TIME;
+       } else
+           code = -1;
+    } while (afs_Analyze
+            (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS,
+             SHARED_LOCK, NULL));
+
+    if (code)
+       goto out;
     /* we are sending parms back to make compat. with prev system.  should
-      change interface later to not ask for current status, just set new status */
+     * change interface later to not ask for current status, just set new status */
     cp = aout;
     memcpy(cp, (char *)&volstat, sizeof(VolumeStatus));
     cp += sizeof(VolumeStatus);
     strcpy(cp, volName);
-    cp += strlen(volName)+1;
+    cp += strlen(volName) + 1;
     strcpy(cp, offLineMsg);
-    cp += strlen(offLineMsg)+1;
+    cp += strlen(offLineMsg) + 1;
     strcpy(cp, motd);
-    cp += strlen(motd)+1;
+    cp += strlen(motd) + 1;
     *aoutSize = cp - aout;
-    return 0;
+  out:
+    afs_osi_Free(offLineMsg, 256);
+    afs_osi_Free(motd, 256);
+    return code;
 }
 
 DECL_PIOCTL(PFlush)
 {
     AFS_STATCNT(PFlush);
-    if (!avc) return EINVAL;
+    if (!avc)
+       return EINVAL;
 #if    defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
     afs_BozonLock(&avc->pvnLock, avc); /* Since afs_TryToSmush will do a pvn_vptrunc */
 #endif
-    ObtainWriteLock(&avc->lock,225);
+    ObtainWriteLock(&avc->lock, 225);
     ObtainWriteLock(&afs_xcbhash, 456);
     afs_DequeueCallback(avc);
-    avc->states        &= ~(CStatd | CDirty);  /* next reference will re-stat cache entry */
+    avc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
     ReleaseWriteLock(&afs_xcbhash);
     /* now find the disk cache entries */
     afs_TryToSmush(avc, *acred, 1);
     osi_dnlc_purgedp(avc);
     afs_symhint_inval(avc);
     if (avc->linkData && !(avc->states & CCore)) {
-       afs_osi_Free(avc->linkData, strlen(avc->linkData)+1);
+       afs_osi_Free(avc->linkData, strlen(avc->linkData) + 1);
        avc->linkData = NULL;
     }
     ReleaseWriteLock(&avc->lock);
@@ -1614,21 +1653,24 @@ DECL_PIOCTL(PNewStatMount)
     afs_size_t offset, len;
 
     AFS_STATCNT(PNewStatMount);
-    if (!avc) return EINVAL;
+    if (!avc)
+       return EINVAL;
     code = afs_VerifyVCache(avc, areq);
-    if (code) return code;
+    if (code)
+       return code;
     if (vType(avc) != VDIR) {
        return ENOTDIR;
     }
     tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
-    if (!tdc) return ENOENT;
+    if (!tdc)
+       return ENOENT;
     Check_AtSys(avc, ain, &sysState, areq);
     ObtainReadLock(&tdc->lock);
     do {
-      code = afs_dir_Lookup(&tdc->f.inode, sysState.name, &tfid.Fid);
+       code = afs_dir_Lookup(&tdc->f.inode, sysState.name, &tfid.Fid);
     } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
     ReleaseReadLock(&tdc->lock);
-    afs_PutDCache(tdc);            /* we're done with the data */
+    afs_PutDCache(tdc);                /* we're done with the data */
     bufp = sysState.name;
     if (code) {
        goto out;
@@ -1649,24 +1691,25 @@ DECL_PIOCTL(PNewStatMount)
        code = EINVAL;
        goto out;
     }
-    ObtainWriteLock(&tvc->lock,226);
+    ObtainWriteLock(&tvc->lock, 226);
     code = afs_HandleLink(tvc, areq);
     if (code == 0) {
        if (tvc->linkData) {
            if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
-               code =  EINVAL;
+               code = EINVAL;
            else {
                /* we have the data */
                strcpy(aout, tvc->linkData);
-               *aoutSize = strlen(tvc->linkData)+1;
+               *aoutSize = strlen(tvc->linkData) + 1;
            }
-       } else 
+       } else
            code = EIO;
     }
     ReleaseWriteLock(&tvc->lock);
     afs_PutVCache(tvc);
-out:
-    if (sysState.allocked) osi_FreeLargeSpace(bufp);
+  out:
+    if (sysState.allocked)
+       osi_FreeLargeSpace(bufp);
     return code;
 }
 
@@ -1680,36 +1723,37 @@ DECL_PIOCTL(PGetTokens)
     int newStyle;
 
     AFS_STATCNT(PGetTokens);
-    if ( !afs_resourceinit_flag )      /* afs deamons havn't started yet */
-       return EIO;          /* Inappropriate ioctl for device */
+    if (!afs_resourceinit_flag)        /* afs daemons haven't started yet */
+       return EIO;             /* Inappropriate ioctl for device */
 
     /* weird interface.  If input parameter is present, it is an integer and
-       we're supposed to return the parm'th tokens for this unix uid.
-       If not present, we just return tokens for cell 1.
-       If counter out of bounds, return EDOM.
-       If no tokens for the particular cell, return ENOTCONN.
-       Also, if this mysterious parm is present, we return, along with the
-       tokens, the primary cell indicator (an afs_int32 0) and the cell name
-       at the end, in that order.
-    */
+     * we're supposed to return the parm'th tokens for this unix uid.
+     * If not present, we just return tokens for cell 1.
+     * If counter out of bounds, return EDOM.
+     * If no tokens for the particular cell, return ENOTCONN.
+     * Also, if this mysterious parm is present, we return, along with the
+     * tokens, the primary cell indicator (an afs_int32 0) and the cell name
+     * at the end, in that order.
+     */
     if ((newStyle = (ainSize > 0))) {
        memcpy((char *)&iterator, ain, sizeof(afs_int32));
     }
     i = UHash(areq->uid);
     ObtainReadLock(&afs_xuser);
-    for(tu = afs_users[i]; tu; tu=tu->next) {
+    for (tu = afs_users[i]; tu; tu = tu->next) {
        if (newStyle) {
            if (tu->uid == areq->uid && (tu->states & UHasTokens)) {
-               if (iterator-- == 0) break;     /* are we done yet? */
+               if (iterator-- == 0)
+                   break;      /* are we done yet? */
            }
-       }
-       else {
-           if (tu->uid == areq->uid && afs_IsPrimaryCellNum(tu->cell)) break;
+       } else {
+           if (tu->uid == areq->uid && afs_IsPrimaryCellNum(tu->cell))
+               break;
        }
     }
     if (tu) {
        /*
-        * No need to hold a read lock on each user entry 
+        * No need to hold a read lock on each user entry
         */
        tu->refCount++;
     }
@@ -1718,7 +1762,8 @@ DECL_PIOCTL(PGetTokens)
     if (!tu) {
        return EDOM;
     }
-    if (((tu->states & UHasTokens) == 0) || (tu->ct.EndTimestamp < osi_Time())) {
+    if (((tu->states & UHasTokens) == 0)
+       || (tu->ct.EndTimestamp < osi_Time())) {
        tu->states |= (UTokensBad | UNeedsReset);
        afs_PutUser(tu, READ_LOCK);
        return ENOTCONN;
@@ -1726,7 +1771,8 @@ DECL_PIOCTL(PGetTokens)
     /* use iterator for temp */
     cp = aout;
     iterator = tu->stLen;      /* for compat, we try to return 56 byte tix if they fit */
-    if (iterator < 56) iterator        = 56;   /* # of bytes we're returning */
+    if (iterator < 56)
+       iterator = 56;          /* # of bytes we're returning */
     memcpy(cp, (char *)&iterator, sizeof(afs_int32));
     cp += sizeof(afs_int32);
     memcpy(cp, tu->stp, tu->stLen);    /* copy out st */
@@ -1744,10 +1790,10 @@ DECL_PIOCTL(PGetTokens)
        tcell = afs_GetCell(tu->cell, READ_LOCK);
        if (tcell) {
            strcpy(cp, tcell->cellName);
-           cp += strlen(tcell->cellName)+1;
+           cp += strlen(tcell->cellName) + 1;
            afs_PutCell(tcell, READ_LOCK);
-       }
-       else *cp++ = 0;
+       } else
+           *cp++ = 0;
     }
     *aoutSize = cp - aout;
     afs_PutUser(tu, READ_LOCK);
@@ -1760,12 +1806,12 @@ DECL_PIOCTL(PUnlog)
     register struct unixuser *tu;
 
     AFS_STATCNT(PUnlog);
-    if ( !afs_resourceinit_flag )      /* afs deamons havn't started yet */
-       return EIO;          /* Inappropriate ioctl for device */
+    if (!afs_resourceinit_flag)        /* afs daemons haven't started yet */
+       return EIO;             /* Inappropriate ioctl for device */
 
     i = UHash(areq->uid);
-    ObtainWriteLock(&afs_xuser,227);
-    for(tu=afs_users[i]; tu; tu=tu->next) {
+    ObtainWriteLock(&afs_xuser, 227);
+    for (tu = afs_users[i]; tu; tu = tu->next) {
        if (tu->uid == areq->uid) {
            tu->vid = UNDEFVID;
            tu->states &= ~UHasTokens;
@@ -1783,14 +1829,14 @@ DECL_PIOCTL(PUnlog)
             */
            afs_ResetUserConns(tu);
            tu->refCount--;
-           ObtainWriteLock(&afs_xuser,228);
+           ObtainWriteLock(&afs_xuser, 228);
 #ifdef UKERNEL
-            /* set the expire times to 0, causes
-             * afs_GCUserData to remove this entry
-             */
-            tu->ct.EndTimestamp = 0;
-            tu->tokenTime = 0;
-#endif  /* UKERNEL */
+           /* set the expire times to 0, causes
+            * afs_GCUserData to remove this entry
+            */
+           tu->ct.EndTimestamp = 0;
+           tu->tokenTime = 0;
+#endif /* UKERNEL */
        }
     }
     ReleaseWriteLock(&afs_xuser);
@@ -1801,19 +1847,19 @@ DECL_PIOCTL(PMariner)
 {
     afs_int32 newHostAddr;
     afs_int32 oldHostAddr;
-    
+
     AFS_STATCNT(PMariner);
     if (afs_mariner)
-       memcpy((char *)&oldHostAddr, (char *)&afs_marinerHost, sizeof(afs_int32));
+       memcpy((char *)&oldHostAddr, (char *)&afs_marinerHost,
+              sizeof(afs_int32));
     else
-       oldHostAddr = 0xffffffff;   /* disabled */
-    
+       oldHostAddr = 0xffffffff;       /* disabled */
+
     memcpy((char *)&newHostAddr, ain, sizeof(afs_int32));
     if (newHostAddr == 0xffffffff) {
        /* disable mariner operations */
        afs_mariner = 0;
-    }
-    else if (newHostAddr) {
+    } else if (newHostAddr) {
        afs_mariner = 1;
        afs_marinerHost = newHostAddr;
     }
@@ -1827,71 +1873,75 @@ DECL_PIOCTL(PCheckServers)
     register char *cp = 0;
     register int i;
     register struct server *ts;
-    afs_int32 temp, *lp = (afs_int32 *)ain, havecell=0;
+    afs_int32 temp, *lp = (afs_int32 *) ain, havecell = 0;
     struct cell *cellp;
     struct chservinfo *pcheck;
 
     AFS_STATCNT(PCheckServers);
 
-    if ( !afs_resourceinit_flag )      /* afs deamons havn't started yet */
-       return EIO;          /* Inappropriate ioctl for device */
+    if (!afs_resourceinit_flag)        /* afs daemons haven't started yet */
+       return EIO;             /* Inappropriate ioctl for device */
 
     if (*lp == 0x12345678) {   /* For afs3.3 version */
-       pcheck=(struct chservinfo *)ain;
+       pcheck = (struct chservinfo *)ain;
        if (pcheck->tinterval >= 0) {
-           cp = aout;      
+           cp = aout;
            memcpy(cp, (char *)&PROBE_INTERVAL, sizeof(afs_int32));
            *aoutSize = sizeof(afs_int32);
            if (pcheck->tinterval > 0) {
                if (!afs_osi_suser(*acred))
                    return EACCES;
-               PROBE_INTERVAL=pcheck->tinterval;
+               PROBE_INTERVAL = pcheck->tinterval;
            }
            return 0;
        }
        if (pcheck->tsize)
            havecell = 1;
-       temp=pcheck->tflags;
+       temp = pcheck->tflags;
        cp = pcheck->tbuffer;
-    } else {   /* For pre afs3.3 versions */
+    } else {                   /* For pre afs3.3 versions */
        memcpy((char *)&temp, ain, sizeof(afs_int32));
-       cp = ain+sizeof(afs_int32);
-       if (ainSize > sizeof(afs_int32)) 
+       cp = ain + sizeof(afs_int32);
+       if (ainSize > sizeof(afs_int32))
            havecell = 1;
     }
 
-    /* 
+    /*
      * 1: fast check, don't contact servers.
      * 2: local cell only.
      */
     if (havecell) {
        /* have cell name, too */
        cellp = afs_GetCellByName(cp, READ_LOCK);
-       if (!cellp) return ENOENT;
-    }
-    else cellp = NULL;
+       if (!cellp)
+           return ENOENT;
+    } else
+       cellp = NULL;
     if (!cellp && (temp & 2)) {
        /* use local cell */
        cellp = afs_GetPrimaryCell(READ_LOCK);
     }
-    if (!(temp & 1)) { /* if not fast, call server checker routine */
+    if (!(temp & 1)) {         /* if not fast, call server checker routine */
        afs_CheckServers(1, cellp);     /* check down servers */
        afs_CheckServers(0, cellp);     /* check up servers */
     }
     /* now return the current down server list */
     cp = aout;
     ObtainReadLock(&afs_xserver);
-    for(i=0;i<NSERVERS;i++) {
-       for(ts = afs_servers[i]; ts; ts=ts->next) {
-           if (cellp && ts->cell != cellp) continue;   /* cell spec'd and wrong */
-           if ((ts->flags & SRVR_ISDOWN) && ts->addr->sa_portal != ts->cell->vlport) {
+    for (i = 0; i < NSERVERS; i++) {
+       for (ts = afs_servers[i]; ts; ts = ts->next) {
+           if (cellp && ts->cell != cellp)
+               continue;       /* cell spec'd and wrong */
+           if ((ts->flags & SRVR_ISDOWN)
+               && ts->addr->sa_portal != ts->cell->vlport) {
                memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32));
                cp += sizeof(afs_int32);
            }
        }
     }
     ReleaseReadLock(&afs_xserver);
-    if (cellp) afs_PutCell(cellp, READ_LOCK);
+    if (cellp)
+       afs_PutCell(cellp, READ_LOCK);
     *aoutSize = cp - aout;
     return 0;
 }
@@ -1899,46 +1949,46 @@ DECL_PIOCTL(PCheckServers)
 DECL_PIOCTL(PCheckVolNames)
 {
     AFS_STATCNT(PCheckVolNames);
-    if ( !afs_resourceinit_flag )      /* afs deamons havn't started yet */
-       return EIO;          /* Inappropriate ioctl for device */
+    if (!afs_resourceinit_flag)        /* afs daemons haven't started yet */
+       return EIO;             /* Inappropriate ioctl for device */
 
     afs_CheckRootVolume();
-    afs_CheckVolumeNames(AFS_VOLCHECK_FORCE |
-                        AFS_VOLCHECK_EXPIRED |
-                        AFS_VOLCHECK_BUSY |
-                        AFS_VOLCHECK_MTPTS);
+    afs_CheckVolumeNames(AFS_VOLCHECK_FORCE | AFS_VOLCHECK_EXPIRED |
+                        AFS_VOLCHECK_BUSY | AFS_VOLCHECK_MTPTS);
     return 0;
 }
 
 DECL_PIOCTL(PCheckAuth)
 {
-       int i;
-       struct srvAddr *sa;
-       struct conn *tc;
-       struct unixuser *tu;
-       afs_int32 retValue;
+    int i;
+    struct srvAddr *sa;
+    struct conn *tc;
+    struct unixuser *tu;
+    afs_int32 retValue;
 
     AFS_STATCNT(PCheckAuth);
-    if ( !afs_resourceinit_flag )      /* afs deamons havn't started yet */
-       return EIO;          /* Inappropriate ioctl for device */
+    if (!afs_resourceinit_flag)        /* afs daemons haven't started yet */
+       return EIO;             /* Inappropriate ioctl for device */
 
     retValue = 0;
-    tu = afs_GetUser(areq->uid,        1, READ_LOCK);  /* check local cell authentication */
-    if (!tu) retValue = EACCES;
+    tu = afs_GetUser(areq->uid, 1, READ_LOCK); /* check local cell authentication */
+    if (!tu)
+       retValue = EACCES;
     else {
        /* we have a user */
-       ObtainReadLock(&afs_xsrvAddr);  
+       ObtainReadLock(&afs_xsrvAddr);
        ObtainReadLock(&afs_xconn);
 
        /* any tokens set? */
-       if ((tu->states & UHasTokens) == 0) retValue = EACCES;
+       if ((tu->states & UHasTokens) == 0)
+           retValue = EACCES;
        /* all connections in cell 1 working? */
-       for(i=0;i<NSERVERS;i++) {
-           for(sa = afs_srvAddrs[i]; sa; sa=sa->next_bkt) {
-              for (tc = sa->conns; tc; tc=tc->next) {
-                 if (tc->user == tu && (tu->states & UTokensBad))
-                      retValue = EACCES;
-              }
+       for (i = 0; i < NSERVERS; i++) {
+           for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
+               for (tc = sa->conns; tc; tc = tc->next) {
+                   if (tc->user == tu && (tu->states & UTokensBad))
+                       retValue = EACCES;
+               }
            }
        }
        ReleaseReadLock(&afs_xsrvAddr);
@@ -1950,30 +2000,33 @@ DECL_PIOCTL(PCheckAuth)
     return 0;
 }
 
-static int Prefetch(char *apath, struct afs_ioctl *adata, int afollow, struct AFS_UCRED *acred)
+static int
+Prefetch(char *apath, struct afs_ioctl *adata, int afollow,
+        struct AFS_UCRED *acred)
 {
     register char *tp;
     register afs_int32 code;
-#if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
+#if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
     size_t bufferSize;
 #else
     u_int bufferSize;
 #endif
 
     AFS_STATCNT(Prefetch);
-    if (!apath) return EINVAL;
+    if (!apath)
+       return EINVAL;
     tp = osi_AllocLargeSpace(1024);
     AFS_COPYINSTR(apath, tp, 1024, &bufferSize, code);
     if (code) {
        osi_FreeLargeSpace(tp);
        return code;
     }
-    if (afs_BBusy()) { /* do this as late as possible */
+    if (afs_BBusy()) {         /* do this as late as possible */
        osi_FreeLargeSpace(tp);
        return EWOULDBLOCK;     /* pretty close */
     }
-    afs_BQueue(BOP_PATH, (struct vcache*)0, 0, 0, acred,
-              (afs_size_t) 0, (afs_size_t) 0, tp);
+    afs_BQueue(BOP_PATH, (struct vcache *)0, 0, 0, acred, (afs_size_t) 0,
+              (afs_size_t) 0, tp);
     return 0;
 }
 
@@ -1983,19 +2036,21 @@ DECL_PIOCTL(PFindVolume)
     register struct server *ts;
     register afs_int32 i;
     register char *cp;
-    
+
     AFS_STATCNT(PFindVolume);
-    if (!avc) return EINVAL;
+    if (!avc)
+       return EINVAL;
     tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK);
     if (tvp) {
        cp = aout;
-       for(i=0;i<MAXHOSTS;i++) {
+       for (i = 0; i < MAXHOSTS; i++) {
            ts = tvp->serverHost[i];
-           if (!ts) break;
+           if (!ts)
+               break;
            memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32));
            cp += sizeof(afs_int32);
        }
-       if (i<MAXHOSTS) {
+       if (i < MAXHOSTS) {
            /* still room for terminating NULL, add it on */
            ainSize = 0;        /* reuse vbl */
            memcpy(cp, (char *)&ainSize, sizeof(afs_int32));
@@ -2012,29 +2067,35 @@ DECL_PIOCTL(PViceAccess)
 {
     register afs_int32 code;
     afs_int32 temp;
-    
+
     AFS_STATCNT(PViceAccess);
-    if (!avc) return EINVAL;
+    if (!avc)
+       return EINVAL;
     code = afs_VerifyVCache(avc, areq);
-    if (code) return code;
+    if (code)
+       return code;
     memcpy((char *)&temp, ain, sizeof(afs_int32));
-    code = afs_AccessOK(avc,temp, areq, CHECK_MODE_BITS);
-    if (code) return 0;
-    else return EACCES;
+    code = afs_AccessOK(avc, temp, areq, CHECK_MODE_BITS);
+    if (code)
+       return 0;
+    else
+       return EACCES;
 }
 
 DECL_PIOCTL(PSetCacheSize)
-{ 
+{
     afs_int32 newValue;
     int waitcnt = 0;
-    
+
     AFS_STATCNT(PSetCacheSize);
     if (!afs_osi_suser(*acred))
        return EACCES;
     /* too many things are setup initially in mem cache version */
-    if (cacheDiskType == AFS_FCACHE_TYPE_MEM) return EROFS;
+    if (cacheDiskType == AFS_FCACHE_TYPE_MEM)
+       return EROFS;
     memcpy((char *)&newValue, ain, sizeof(afs_int32));
-    if (newValue == 0) afs_cacheBlocks = afs_stats_cmperf.cacheBlocksOrig;
+    if (newValue == 0)
+       afs_cacheBlocks = afs_stats_cmperf.cacheBlocksOrig;
     else {
        if (newValue < afs_min_cache)
            afs_cacheBlocks = afs_min_cache;
@@ -2068,36 +2129,37 @@ DECL_PIOCTL(PGetCacheSize)
 DECL_PIOCTL(PRemoveCallBack)
 {
     register struct conn *tc;
-    register afs_int32 code;
+    register afs_int32 code = 0;
     struct AFSCallBack CallBacks_Array[1];
     struct AFSCBFids theFids;
     struct AFSCBs theCBs;
     XSTATS_DECLS;
 
     AFS_STATCNT(PRemoveCallBack);
-    if (!avc) return EINVAL;
-    if (avc->states & CRO) return 0;   /* read-only-ness can't change */
-    ObtainWriteLock(&avc->lock,229);
+    if (!avc)
+       return EINVAL;
+    if (avc->states & CRO)
+       return 0;               /* read-only-ness can't change */
+    ObtainWriteLock(&avc->lock, 229);
     theFids.AFSCBFids_len = 1;
     theCBs.AFSCBs_len = 1;
-    theFids.AFSCBFids_val = (struct AFSFid *) &avc->fid.Fid;
+    theFids.AFSCBFids_val = (struct AFSFid *)&avc->fid.Fid;
     theCBs.AFSCBs_val = CallBacks_Array;
     CallBacks_Array[0].CallBackType = CB_DROPPED;
     if (avc->callback) {
        do {
            tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
            if (tc) {
-             XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
-             RX_AFS_GUNLOCK();
-             code = RXAFS_GiveUpCallBacks(tc->id, &theFids, &theCBs);
-             RX_AFS_GLOCK();
-             XSTATS_END_TIME;
+               XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
+               RX_AFS_GUNLOCK();
+               code = RXAFS_GiveUpCallBacks(tc->id, &theFids, &theCBs);
+               RX_AFS_GLOCK();
+               XSTATS_END_TIME;
            }
            /* don't set code on failure since we wouldn't use it */
-       } while
-         (afs_Analyze(tc, code, &avc->fid, areq,
-                      AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS,
-                      SHARED_LOCK, NULL));
+       } while (afs_Analyze
+                (tc, code, &avc->fid, areq,
+                 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, SHARED_LOCK, NULL));
 
        ObtainWriteLock(&afs_xcbhash, 457);
        afs_DequeueCallback(avc);
@@ -2114,16 +2176,15 @@ DECL_PIOCTL(PRemoveCallBack)
 DECL_PIOCTL(PNewCell)
 {
     /* create a new cell */
-    afs_int32 cellHosts[MAXCELLHOSTS], *lp, magic=0;
-    register struct cell *tcell;
-    char *newcell=0, *linkedcell=0, *tp= ain;
-    register afs_int32 code, linkedstate=0, ls;
+    afs_int32 cellHosts[MAXCELLHOSTS], *lp, magic = 0;
+    char *newcell = 0, *linkedcell = 0, *tp = ain;
+    register afs_int32 code, linkedstate = 0, ls;
     u_short fsport = 0, vlport = 0;
     afs_int32 scount;
-    
+
     AFS_STATCNT(PNewCell);
-    if ( !afs_resourceinit_flag )      /* afs deamons havn't started yet */
-       return EIO;          /* Inappropriate ioctl for device */
+    if (!afs_resourceinit_flag)        /* afs daemons haven't started yet */
+       return EIO;             /* Inappropriate ioctl for device */
 
     if (!afs_osi_suser(*acred))
        return EACCES;
@@ -2131,35 +2192,38 @@ DECL_PIOCTL(PNewCell)
     memcpy((char *)&magic, tp, sizeof(afs_int32));
     tp += sizeof(afs_int32);
     if (magic != 0x12345678)
-        return EINVAL;
+       return EINVAL;
 
     /* A 3.4 fs newcell command will pass an array of MAXCELLHOSTS
      * server addresses while the 3.5 fs newcell command passes
      * MAXHOSTS. To figure out which is which, check if the cellname
      * is good.
      */
-    newcell = tp + (MAXCELLHOSTS+3)*sizeof(afs_int32);
+    newcell = tp + (MAXCELLHOSTS + 3) * sizeof(afs_int32);
     scount = ((newcell[0] != '\0') ? MAXCELLHOSTS : MAXHOSTS);
 
     /* MAXCELLHOSTS (=8) is less than MAXHOSTS (=13) */
     memcpy((char *)cellHosts, tp, MAXCELLHOSTS * sizeof(afs_int32));
     tp += (scount * sizeof(afs_int32));
 
-    lp = (afs_int32 *)tp;
+    lp = (afs_int32 *) tp;
     fsport = *lp++;
     vlport = *lp++;
-    if (fsport < 1024) fsport = 0;     /* Privileged ports not allowed */
-    if (vlport < 1024) vlport = 0;     /* Privileged ports not allowed */
+    if (fsport < 1024)
+       fsport = 0;             /* Privileged ports not allowed */
+    if (vlport < 1024)
+       vlport = 0;             /* Privileged ports not allowed */
     tp += (3 * sizeof(afs_int32));
     newcell = tp;
     if ((ls = *lp) & 1) {
-       linkedcell = tp + strlen(newcell)+1;
-       linkedstate |= CLinkedCell;
+       linkedcell = tp + strlen(newcell) + 1;
+       linkedstate |= CLinkedCell;
     }
 
-    linkedstate |= CNoSUID; /* setuid is disabled by default for fs newcell */
-    code = afs_NewCell(newcell, cellHosts, linkedstate, linkedcell, fsport,
-                      vlport, (int)0);
+    linkedstate |= CNoSUID;    /* setuid is disabled by default for fs newcell */
+    code =
+       afs_NewCell(newcell, cellHosts, linkedstate, linkedcell, fsport,
+                   vlport, (int)0);
     return code;
 }
 
@@ -2169,9 +2233,9 @@ DECL_PIOCTL(PNewAlias)
     char *tp = ain;
     register afs_int32 code;
     char *realName, *aliasName;
-    
-    if ( !afs_resourceinit_flag )      /* afs deamons havn't started yet */
-       return EIO;          /* Inappropriate ioctl for device */
+
+    if (!afs_resourceinit_flag)        /* afs daemons haven't started yet */
+       return EIO;             /* Inappropriate ioctl for device */
 
     if (!afs_osi_suser(*acred))
        return EACCES;
@@ -2188,13 +2252,13 @@ DECL_PIOCTL(PNewAlias)
 DECL_PIOCTL(PListCells)
 {
     afs_int32 whichCell;
-    register struct cell *tcell=0;
+    register struct cell *tcell = 0;
     register afs_int32 i;
     register char *cp, *tp = ain;
 
     AFS_STATCNT(PListCells);
-    if ( !afs_resourceinit_flag )      /* afs deamons havn't started yet */
-       return EIO;          /* Inappropriate ioctl for device */
+    if (!afs_resourceinit_flag)        /* afs daemons haven't started yet */
+       return EIO;             /* Inappropriate ioctl for device */
 
     memcpy((char *)&whichCell, tp, sizeof(afs_int32));
     tp += sizeof(afs_int32);
@@ -2202,29 +2266,33 @@ DECL_PIOCTL(PListCells)
     if (tcell) {
        cp = aout;
        memset(cp, 0, MAXCELLHOSTS * sizeof(afs_int32));
-       for(i=0;i<MAXCELLHOSTS;i++) {
-           if (tcell->cellHosts[i] == 0) break;
-           memcpy(cp, (char *)&tcell->cellHosts[i]->addr->sa_ip, sizeof(afs_int32));
+       for (i = 0; i < MAXCELLHOSTS; i++) {
+           if (tcell->cellHosts[i] == 0)
+               break;
+           memcpy(cp, (char *)&tcell->cellHosts[i]->addr->sa_ip,
+                  sizeof(afs_int32));
            cp += sizeof(afs_int32);
        }
        cp = aout + MAXCELLHOSTS * sizeof(afs_int32);
        strcpy(cp, tcell->cellName);
-       cp += strlen(tcell->cellName)+1;
+       cp += strlen(tcell->cellName) + 1;
        *aoutSize = cp - aout;
        afs_PutCell(tcell, READ_LOCK);
     }
-    if (tcell) return 0;
-    else return EDOM;
+    if (tcell)
+       return 0;
+    else
+       return EDOM;
 }
 
 DECL_PIOCTL(PListAliases)
 {
     afs_int32 whichAlias;
-    register struct cell_alias *tcalias=0;
+    register struct cell_alias *tcalias = 0;
     register char *cp, *tp = ain;
 
-    if ( !afs_resourceinit_flag )      /* afs deamons havn't started yet */
-       return EIO;          /* Inappropriate ioctl for device */
+    if (!afs_resourceinit_flag)        /* afs daemons haven't started yet */
+       return EIO;             /* Inappropriate ioctl for device */
     if (ainSize < sizeof(afs_int32))
        return EINVAL;
 
@@ -2232,17 +2300,19 @@ DECL_PIOCTL(PListAliases)
     tp += sizeof(afs_int32);
 
     tcalias = afs_GetCellAlias(whichAlias);
-    if (tcalias) {     
+    if (tcalias) {
        cp = aout;
        strcpy(cp, tcalias->alias);
-       cp += strlen(tcalias->alias)+1;
+       cp += strlen(tcalias->alias) + 1;
        strcpy(cp, tcalias->cell);
-       cp += strlen(tcalias->cell)+1;
+       cp += strlen(tcalias->cell) + 1;
        *aoutSize = cp - aout;
        afs_PutCellAlias(tcalias);
     }
-    if (tcalias) return 0;
-    else return EDOM;
+    if (tcalias)
+       return 0;
+    else
+       return EDOM;
 }
 
 DECL_PIOCTL(PRemoveMount)
@@ -2263,17 +2333,21 @@ DECL_PIOCTL(PRemoveMount)
     /* "ain" is the name of the file in this dir to remove */
 
     AFS_STATCNT(PRemoveMount);
-    if (!avc) return EINVAL;
+    if (!avc)
+       return EINVAL;
     code = afs_VerifyVCache(avc, areq);
-    if (code) return code;
-    if (vType(avc) != VDIR) return ENOTDIR;
+    if (code)
+       return code;
+    if (vType(avc) != VDIR)
+       return ENOTDIR;
 
-    tdc        = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);   /* test for error below */
-    if (!tdc) return ENOENT;
+    tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);  /* test for error below */
+    if (!tdc)
+       return ENOENT;
     Check_AtSys(avc, ain, &sysState, areq);
     ObtainReadLock(&tdc->lock);
     do {
-      code = afs_dir_Lookup(&tdc->f.inode, sysState.name, &tfid.Fid);
+       code = afs_dir_Lookup(&tdc->f.inode, sysState.name, &tfid.Fid);
     } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
     ReleaseReadLock(&tdc->lock);
     bufp = sysState.name;
@@ -2283,7 +2357,7 @@ DECL_PIOCTL(PRemoveMount)
     }
     tfid.Cell = avc->fid.Cell;
     tfid.Fid.Volume = avc->fid.Fid.Volume;
-    if (!tfid.Fid.Unique &&  (avc->states & CForeign)) {
+    if (!tfid.Fid.Unique && (avc->states & CForeign)) {
        tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
     } else {
        tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
@@ -2299,13 +2373,13 @@ DECL_PIOCTL(PRemoveMount)
        code = EINVAL;
        goto out;
     }
-    ObtainWriteLock(&tvc->lock,230);
+    ObtainWriteLock(&tvc->lock, 230);
     code = afs_HandleLink(tvc, areq);
     if (!code) {
        if (tvc->linkData) {
            if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
-               code =  EINVAL;
-       } else 
+               code = EINVAL;
+       } else
            code = EIO;
     }
     ReleaseWriteLock(&tvc->lock);
@@ -2315,26 +2389,27 @@ DECL_PIOCTL(PRemoveMount)
        afs_PutDCache(tdc);
        goto out;
     }
-    ObtainWriteLock(&avc->lock,231);
+    ObtainWriteLock(&avc->lock, 231);
     osi_dnlc_remove(avc, bufp, tvc);
     do {
        tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
        if (tc) {
-          XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEFILE);
-         RX_AFS_GUNLOCK();
-         code = RXAFS_RemoveFile(tc->id, (struct AFSFid *) &avc->fid.Fid,
-                                 bufp, &OutDirStatus, &tsync);
-         RX_AFS_GLOCK();
-          XSTATS_END_TIME;
-       }
-       else code = -1;
-    } while
-       (afs_Analyze(tc, code, &avc->fid, areq,
-                    AFS_STATS_FS_RPCIDX_REMOVEFILE,
-                    SHARED_LOCK, NULL));
+           XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEFILE);
+           RX_AFS_GUNLOCK();
+           code =
+               RXAFS_RemoveFile(tc->id, (struct AFSFid *)&avc->fid.Fid, bufp,
+                                &OutDirStatus, &tsync);
+           RX_AFS_GLOCK();
+           XSTATS_END_TIME;
+       } else
+           code = -1;
+    } while (afs_Analyze
+            (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_REMOVEFILE,
+             SHARED_LOCK, NULL));
 
     if (code) {
-       if (tdc) afs_PutDCache(tdc);
+       if (tdc)
+           afs_PutDCache(tdc);
        ReleaseWriteLock(&avc->lock);
        goto out;
     }
@@ -2352,12 +2427,13 @@ DECL_PIOCTL(PRemoveMount)
        ReleaseWriteLock(&tdc->lock);
        afs_PutDCache(tdc);     /* drop ref count */
     }
-    avc->states &= ~CUnique;           /* For the dfs xlator */
+    avc->states &= ~CUnique;   /* For the dfs xlator */
     ReleaseWriteLock(&avc->lock);
     code = 0;
-out:
-    if (sysState.allocked) osi_FreeLargeSpace(bufp);
-    return code;    
+  out:
+    if (sysState.allocked)
+       osi_FreeLargeSpace(bufp);
+    return code;
 }
 
 DECL_PIOCTL(PVenusLogging)
@@ -2371,11 +2447,12 @@ DECL_PIOCTL(PGetCellStatus)
     afs_int32 temp;
 
     AFS_STATCNT(PGetCellStatus);
-    if ( !afs_resourceinit_flag )      /* afs deamons havn't started yet */
-       return EIO;          /* Inappropriate ioctl for device */
+    if (!afs_resourceinit_flag)        /* afs daemons haven't started yet */
+       return EIO;             /* Inappropriate ioctl for device */
 
     tcell = afs_GetCellByName(ain, READ_LOCK);
-    if (!tcell) return ENOENT;
+    if (!tcell)
+       return ENOENT;
     temp = tcell->states;
     afs_PutCell(tcell, READ_LOCK);
     memcpy(aout, (char *)&temp, sizeof(afs_int32));
@@ -2387,14 +2464,15 @@ DECL_PIOCTL(PSetCellStatus)
 {
     register struct cell *tcell;
     afs_int32 temp;
-    
+
     if (!afs_osi_suser(*acred))
        return EACCES;
-    if ( !afs_resourceinit_flag )      /* afs deamons havn't started yet */
-       return EIO;          /* Inappropriate ioctl for device */
+    if (!afs_resourceinit_flag)        /* afs daemons haven't started yet */
+       return EIO;             /* Inappropriate ioctl for device */
 
-    tcell = afs_GetCellByName(ain+2*sizeof(afs_int32), WRITE_LOCK);
-    if (!tcell) return ENOENT;
+    tcell = afs_GetCellByName(ain + 2 * sizeof(afs_int32), WRITE_LOCK);
+    if (!tcell)
+       return ENOENT;
     memcpy((char *)&temp, ain, sizeof(afs_int32));
     if (temp & CNoSUID)
        tcell->states |= CNoSUID;
@@ -2415,24 +2493,24 @@ DECL_PIOCTL(PFlushVolumeData)
     AFS_STATCNT(PFlushVolumeData);
     if (!avc)
        return EINVAL;
-    if ( !afs_resourceinit_flag )      /* afs deamons havn't started yet */
-       return EIO;          /* Inappropriate ioctl for device */
+    if (!afs_resourceinit_flag)        /* afs daemons haven't started yet */
+       return EIO;             /* Inappropriate ioctl for device */
 
-    volume = avc->fid.Fid.Volume;  /* who to zap */
+    volume = avc->fid.Fid.Volume;      /* who to zap */
     cell = avc->fid.Cell;
 
-    /* 
+    /*
      * Clear stat'd flag from all vnodes from this volume; this will invalidate all
      * the vcaches associated with the volume.
      */
     ObtainReadLock(&afs_xvcache);
-    for(i = 0; i < VCSIZE; i++) {
-       for(tvc = afs_vhashT[i]; tvc; tvc=tvc->hnext) {
+    for (i = 0; i < VCSIZE; i++) {
+       for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
            if (tvc->fid.Fid.Volume == volume && tvc->fid.Cell == cell) {
 #if    defined(AFS_SGI_ENV) || defined(AFS_ALPHA_ENV)  || defined(AFS_SUN5_ENV)  || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV)
                VN_HOLD(AFSTOV(tvc));
 #else
-#if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
+#if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
                osi_vnhold(tvc, 0);
 #else
                VREFCOUNT_INC(tvc);
@@ -2442,7 +2520,7 @@ DECL_PIOCTL(PFlushVolumeData)
 #if    defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
                afs_BozonLock(&tvc->pvnLock, tvc);      /* Since afs_TryToSmush will do a pvn_vptrunc */
 #endif
-               ObtainWriteLock(&tvc->lock,232);
+               ObtainWriteLock(&tvc->lock, 232);
 
                ObtainWriteLock(&afs_xcbhash, 458);
                afs_DequeueCallback(tvc);
@@ -2464,22 +2542,23 @@ DECL_PIOCTL(PFlushVolumeData)
     ReleaseReadLock(&afs_xvcache);
 
 
-    MObtainWriteLock(&afs_xdcache,328);  /* needed if you're going to flush any stuff */
-    for(i=0;i<afs_cacheFiles;i++) {
-       if (!(afs_indexFlags[i] & IFEverUsed)) continue;        /* never had any data */
+    MObtainWriteLock(&afs_xdcache, 328);       /* needed if you're going to flush any stuff */
+    for (i = 0; i < afs_cacheFiles; i++) {
+       if (!(afs_indexFlags[i] & IFEverUsed))
+           continue;           /* never had any data */
        tdc = afs_GetDSlot(i, NULL);
-       if (tdc->refCount <= 1) {    /* too high, in use by running sys call */
+       if (tdc->refCount <= 1) {       /* too high, in use by running sys call */
            ReleaseReadLock(&tdc->tlock);
            if (tdc->f.fid.Fid.Volume == volume && tdc->f.fid.Cell == cell) {
-               if (! (afs_indexFlags[i] & IFDataMod)) {
+               if (!(afs_indexFlags[i] & IFDataMod)) {
                    /* if the file is modified, but has a ref cnt of only 1, then
-                      someone probably has the file open and is writing into it.
-                      Better to skip flushing such a file, it will be brought back
-                      immediately on the next write anyway.
-
-                      If we *must* flush, then this code has to be rearranged to call
-                      afs_storeAllSegments() first */
-                       afs_FlushDCache(tdc);
+                    * someone probably has the file open and is writing into it.
+                    * Better to skip flushing such a file, it will be brought back
+                    * immediately on the next write anyway.
+                    * 
+                    * If we *must* flush, then this code has to be rearranged to call
+                    * afs_storeAllSegments() first */
+                   afs_FlushDCache(tdc);
                }
            }
        } else {
@@ -2490,8 +2569,8 @@ DECL_PIOCTL(PFlushVolumeData)
     MReleaseWriteLock(&afs_xdcache);
 
     ObtainReadLock(&afs_xvolume);
-    for (i=0;i<NVOLS;i++) {
-       for (tv = afs_volumes[i]; tv; tv=tv->next) {
+    for (i = 0; i < NVOLS; i++) {
+       for (tv = afs_volumes[i]; tv; tv = tv->next) {
            if (tv->volume == volume) {
                afs_ResetVolumeInfo(tv);
                break;
@@ -2500,9 +2579,9 @@ DECL_PIOCTL(PFlushVolumeData)
     }
     ReleaseReadLock(&afs_xvolume);
 
-    /* probably, a user is doing this, probably, because things are screwed up. 
+    /* probably, a user is doing this, probably, because things are screwed up.
      * maybe it's the dnlc's fault? */
-    osi_dnlc_purge();  
+    osi_dnlc_purge();
     return 0;
 }
 
@@ -2513,17 +2592,19 @@ DECL_PIOCTL(PGetVnodeXStatus)
     register afs_int32 code;
     struct vcxstat stat;
     afs_int32 mode, i;
-    
+
 /*  AFS_STATCNT(PGetVnodeXStatus); */
-    if (!avc) return EINVAL;
+    if (!avc)
+       return EINVAL;
     code = afs_VerifyVCache(avc, areq);
-    if (code) return code;
+    if (code)
+       return code;
     if (vType(avc) == VDIR)
        mode = PRSFS_LOOKUP;
     else
        mode = PRSFS_READ;
     if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
-       return EACCES;    
+       return EACCES;
     stat.fid = avc->fid;
     hset32(stat.DataVersion, hgetlo(avc->m.DataVersion));
     stat.lock = avc->lock;
@@ -2532,13 +2613,13 @@ DECL_PIOCTL(PGetVnodeXStatus)
     hset(stat.flushDV, avc->flushDV);
     hset(stat.mapDV, avc->mapDV);
     stat.truncPos = avc->truncPos;
-    { /* just grab the first two - won't break anything... */
-      struct axscache *ac;
+    {                          /* just grab the first two - won't break anything... */
+       struct axscache *ac;
 
-      for (i=0, ac=avc->Access; ac && i < CPSIZE; i++, ac=ac->next) {
-       stat.randomUid[i] = ac->uid;
-       stat.randomAccess[i] = ac->axess;
-      }
+       for (i = 0, ac = avc->Access; ac && i < CPSIZE; i++, ac = ac->next) {
+           stat.randomUid[i] = ac->uid;
+           stat.randomAccess[i] = ac->axess;
+       }
     }
     stat.callback = afs_data_pointer_to_int32(avc->callback);
     stat.cbExpires = avc->cbExpires;
@@ -2561,7 +2642,7 @@ DECL_PIOCTL(PGetVnodeXStatus)
 DECL_PIOCTL(PSetSysName)
 {
     char *cp, inname[MAXSYSNAME], outname[MAXSYSNAME];
-    int setsysname, foundname=0;
+    int setsysname, foundname = 0;
     register struct afs_exporter *exporter;
     register struct unixuser *au;
     register afs_int32 pag, error;
@@ -2570,8 +2651,8 @@ DECL_PIOCTL(PSetSysName)
 
     AFS_STATCNT(PSetSysName);
     if (!afs_globalVFS) {
-      /* Afsd is NOT running; disable it */
-#if defined(KERNEL_HAVE_SETUERROR)
+       /* Afsd is NOT running; disable it */
+#if defined(KERNEL_HAVE_UERROR)
        return (setuerror(EINVAL), EINVAL);
 #else
        return (EINVAL);
@@ -2582,92 +2663,96 @@ DECL_PIOCTL(PSetSysName)
     ain += sizeof(afs_int32);
     if (setsysname) {
 
-      /* Check my args */
-      if (setsysname < 0 || setsysname > MAXNUMSYSNAMES)
-       return EINVAL;
-      for(cp = ain,count = 0;count < setsysname;count++) {
-       /* won't go past end of ain since maxsysname*num < ain length */
-       t = strlen(cp);
-       if (t >= MAXSYSNAME || t <= 0)
-         return EINVAL;
-       /* check for names that can shoot us in the foot */
-       if (*cp == '.' && (cp[1] == 0 || (cp[1] == '.' && cp[2] == 0)))
-         return EINVAL;
-       cp += t+1;
-      }
-      /* args ok */
-
-      /* inname gets first entry in case we're being a translater */
-      t = strlen(ain);
-      memcpy(inname, ain, t+1);  /* include terminating null */
-      ain += t + 1;
-    }
-    if ((*acred)->cr_gid == RMTUSER_REQ) { /* Handles all exporters */
+       /* Check my args */
+       if (setsysname < 0 || setsysname > MAXNUMSYSNAMES)
+           return EINVAL;
+       for (cp = ain, count = 0; count < setsysname; count++) {
+           /* won't go past end of ain since maxsysname*num < ain length */
+           t = strlen(cp);
+           if (t >= MAXSYSNAME || t <= 0)
+               return EINVAL;
+           /* check for names that can shoot us in the foot */
+           if (*cp == '.' && (cp[1] == 0 || (cp[1] == '.' && cp[2] == 0)))
+               return EINVAL;
+           cp += t + 1;
+       }
+       /* args ok */
+
+       /* inname gets first entry in case we're being a translater */
+       t = strlen(ain);
+       memcpy(inname, ain, t + 1);     /* include terminating null */
+       ain += t + 1;
+    }
+    if ((*acred)->cr_gid == RMTUSER_REQ) {     /* Handles all exporters */
        pag = PagInCred(*acred);
        if (pag == NOPAG) {
-           return EINVAL;  /* Better than panicing */
+           return EINVAL;      /* Better than panicing */
        }
        if (!(au = afs_FindUser(pag, -1, READ_LOCK))) {
-           return EINVAL;  /* Better than panicing */
+           return EINVAL;      /* Better than panicing */
        }
        if (!(exporter = au->exporter)) {
            afs_PutUser(au, READ_LOCK);
-           return EINVAL;  /* Better than panicing */
+           return EINVAL;      /* Better than panicing */
        }
-       error = EXP_SYSNAME(exporter, (setsysname? inname : NULL), outname);
+       error = EXP_SYSNAME(exporter, (setsysname ? inname : NULL), outname);
        if (error) {
-           if (error == ENODEV) foundname = 0; /* sysname not set yet! */
+           if (error == ENODEV)
+               foundname = 0;  /* sysname not set yet! */
            else {
                afs_PutUser(au, READ_LOCK);
                return error;
            }
-       }
-       else foundname = 1;
+       } else
+           foundname = 1;
        afs_PutUser(au, READ_LOCK);
     } else {
 
-      /* Not xlating, so local case */
-       if (!afs_sysname) osi_Panic("PSetSysName: !afs_sysname\n");
+       /* Not xlating, so local case */
+       if (!afs_sysname)
+           osi_Panic("PSetSysName: !afs_sysname\n");
        if (!setsysname) {      /* user just wants the info */
            strcpy(outname, afs_sysname);
            foundname = afs_sysnamecount;
-       } else {     /* Local guy; only root can change sysname */
+       } else {                /* Local guy; only root can change sysname */
            if (!afs_osi_suser(*acred))
                return EACCES;
-          
+
            /* clear @sys entries from the dnlc, once afs_lookup can
-            do lookups of @sys entries and thinks it can trust them */
+            * do lookups of @sys entries and thinks it can trust them */
            /* privs ok, store the entry, ... */
            strcpy(afs_sysname, inname);
-           if (setsysname > 1) { /* ... or list */
-             cp = ain;
-             for(count=1; count < setsysname;++count) {
-               if (!afs_sysnamelist[count])
-                 osi_Panic("PSetSysName: no afs_sysnamelist entry to write\n");
-               t = strlen(cp);
-               memcpy(afs_sysnamelist[count], cp, t+1); /* include null */
-               cp += t+1;
-             }
+           if (setsysname > 1) {       /* ... or list */
+               cp = ain;
+               for (count = 1; count < setsysname; ++count) {
+                   if (!afs_sysnamelist[count])
+                       osi_Panic
+                           ("PSetSysName: no afs_sysnamelist entry to write\n");
+                   t = strlen(cp);
+                   memcpy(afs_sysnamelist[count], cp, t + 1);  /* include null */
+                   cp += t + 1;
+               }
            }
            afs_sysnamecount = setsysname;
        }
     }
     if (!setsysname) {
-       cp = aout;  /* not changing so report back the count and ... */
+       cp = aout;              /* not changing so report back the count and ... */
        memcpy(cp, (char *)&foundname, sizeof(afs_int32));
        cp += sizeof(afs_int32);
        if (foundname) {
-           strcpy(cp, outname);                /* ... the entry, ... */
-           cp += strlen(outname)+1;
-           for(count=1; count < foundname; ++count) { /* ... or list. */
-             /* Note: we don't support @sys lists for exporters */
-             if (!afs_sysnamelist[count])
-               osi_Panic("PSetSysName: no afs_sysnamelist entry to read\n");
-             t = strlen(afs_sysnamelist[count]);
-             if (t >= MAXSYSNAME)
-               osi_Panic("PSetSysName: sysname entry garbled\n");
-             strcpy(cp, afs_sysnamelist[count]);
-             cp += t + 1;
+           strcpy(cp, outname);        /* ... the entry, ... */
+           cp += strlen(outname) + 1;
+           for (count = 1; count < foundname; ++count) {       /* ... or list. */
+               /* Note: we don't support @sys lists for exporters */
+               if (!afs_sysnamelist[count])
+                   osi_Panic
+                       ("PSetSysName: no afs_sysnamelist entry to read\n");
+               t = strlen(afs_sysnamelist[count]);
+               if (t >= MAXSYSNAME)
+                   osi_Panic("PSetSysName: sysname entry garbled\n");
+               strcpy(cp, afs_sysnamelist[count]);
+               cp += t + 1;
            }
        }
        *aoutSize = cp - aout;
@@ -2684,251 +2769,257 @@ DECL_PIOCTL(PSetSysName)
  * l - array of cell ids which have volumes that need to be sorted
  * vlonly - sort vl servers or file servers?
  */
-static void *ReSortCells_cb(struct cell *cell, void *arg)
+static void *
+ReSortCells_cb(struct cell *cell, void *arg)
 {
     afs_int32 *p = (afs_int32 *) arg;
     afs_int32 *l = p + 1;
     int i, s = p[0];
-    for (i=0; i<s; i++) {
+
+    for (i = 0; i < s; i++) {
        if (l[i] == cell->cellNum) {
            ObtainWriteLock(&cell->lock, 690);
            afs_SortServers(cell->cellHosts, MAXCELLHOSTS);
            ReleaseWriteLock(&cell->lock);
        }
     }
+
+    return NULL;
 }
 
-static void ReSortCells(int s, afs_int32 *l, int vlonly)  
+static void
+ReSortCells(int s, afs_int32 * l, int vlonly)
 {
-  int i;
-  struct volume *j;
-  register int  k;
+    int i;
+    struct volume *j;
+    register int k;
 
-  if (vlonly) {
-      afs_int32 *p;
-      p = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * (s+1));
-      p[0] = s;
-      memcpy(p+1, l, s * sizeof(afs_int32));
-      afs_TraverseCells(&ReSortCells_cb, p);
-      afs_osi_Free(p, sizeof(afs_int32) * (s+1));
-      return;
-  }
+    if (vlonly) {
+       afs_int32 *p;
+       p = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * (s + 1));
+       p[0] = s;
+       memcpy(p + 1, l, s * sizeof(afs_int32));
+       afs_TraverseCells(&ReSortCells_cb, p);
+       afs_osi_Free(p, sizeof(afs_int32) * (s + 1));
+       return;
+    }
 
-  ObtainReadLock(&afs_xvolume);
-  for (i= 0; i< NVOLS; i++) {
-      for (j=afs_volumes[i];j;j=j->next) {
-         for (k=0;k<s;k++)
-             if (j->cell == l[k]) {
-                 ObtainWriteLock(&j->lock,233);
-                 afs_SortServers(j->serverHost, MAXHOSTS);
-                 ReleaseWriteLock(&j->lock);
-                 break; 
-             }
-      }
-  }
-  ReleaseReadLock(&afs_xvolume);
+    ObtainReadLock(&afs_xvolume);
+    for (i = 0; i < NVOLS; i++) {
+       for (j = afs_volumes[i]; j; j = j->next) {
+           for (k = 0; k < s; k++)
+               if (j->cell == l[k]) {
+                   ObtainWriteLock(&j->lock, 233);
+                   afs_SortServers(j->serverHost, MAXHOSTS);
+                   ReleaseWriteLock(&j->lock);
+                   break;
+               }
+       }
+    }
+    ReleaseReadLock(&afs_xvolume);
 }
 
 
 static int debugsetsp = 0;
-static int afs_setsprefs(sp, num, vlonly)
-   struct spref *sp;
-   unsigned int num;
-   unsigned int vlonly;
-{
-   struct srvAddr *sa;
-   int i,j,k,matches,touchedSize;
-   struct server *srvr = NULL;
-   afs_int32 touched[34];
-   int isfs;
-   
-   touchedSize=0;
-   for (k=0; k < num; sp++, k++) { 
-      if (debugsetsp) {
-        printf ("sp host=%x, rank=%d\n",sp->host.s_addr, sp->rank);
-      }
-      matches=0;
-      ObtainReadLock(&afs_xserver);
-      
-      i = SHash(sp->host.s_addr);
-      for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
-        if (sa->sa_ip == sp->host.s_addr) {
-           srvr = sa->server;
-           isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))  
-                  || (sa->sa_portal == AFS_FSPORT); 
-           if ((!vlonly && isfs) || (vlonly && !isfs)) {
-              matches++;
-              break;
+static int
+afs_setsprefs(sp, num, vlonly)
+     struct spref *sp;
+     unsigned int num;
+     unsigned int vlonly;
+{
+    struct srvAddr *sa;
+    int i, j, k, matches, touchedSize;
+    struct server *srvr = NULL;
+    afs_int32 touched[34];
+    int isfs;
+
+    touchedSize = 0;
+    for (k = 0; k < num; sp++, k++) {
+       if (debugsetsp) {
+           printf("sp host=%x, rank=%d\n", sp->host.s_addr, sp->rank);
+       }
+       matches = 0;
+       ObtainReadLock(&afs_xserver);
+
+       i = SHash(sp->host.s_addr);
+       for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
+           if (sa->sa_ip == sp->host.s_addr) {
+               srvr = sa->server;
+               isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
+                   || (sa->sa_portal == AFS_FSPORT);
+               if ((!vlonly && isfs) || (vlonly && !isfs)) {
+                   matches++;
+                   break;
+               }
+           }
+       }
+
+       if (sa && matches) {    /* found one! */
+           if (debugsetsp) {
+               printf("sa ip=%x, ip_rank=%d\n", sa->sa_ip, sa->sa_iprank);
+           }
+           sa->sa_iprank = sp->rank + afs_randomMod15();
+           afs_SortOneServer(sa->server);
+
+           if (srvr->cell) {
+               /* if we don't know yet what cell it's in, this is moot */
+               for (j = touchedSize - 1;
+                    j >= 0 && touched[j] != srvr->cell->cellNum; j--)
+                   /* is it in our list of touched cells ?  */ ;
+               if (j < 0) {    /* no, it's not */
+                   touched[touchedSize++] = srvr->cell->cellNum;
+                   if (touchedSize >= 32) {    /* watch for ovrflow */
+                       ReleaseReadLock(&afs_xserver);
+                       ReSortCells(touchedSize, touched, vlonly);
+                       touchedSize = 0;
+                       ObtainReadLock(&afs_xserver);
+                   }
+               }
            }
-        }
-      }
-      
-      if (sa && matches) {  /* found one! */
-        if (debugsetsp) {
-           printf ("sa ip=%x, ip_rank=%d\n",sa->sa_ip, sa->sa_iprank);
-        }
-        sa->sa_iprank = sp->rank + afs_randomMod15();
-        afs_SortOneServer(sa->server);
-        
-        if (srvr->cell) {
-          /* if we don't know yet what cell it's in, this is moot */
-          for (j=touchedSize-1; j>=0 && touched[j] != srvr->cell->cellNum; j--)
-                /* is it in our list of touched cells ?  */ ;
-          if (j < 0) {                   /* no, it's not */
-            touched[touchedSize++] = srvr->cell->cellNum;
-            if (touchedSize >= 32) {                /* watch for ovrflow */
-              ReleaseReadLock(&afs_xserver);
-              ReSortCells(touchedSize, touched, vlonly);
-              touchedSize=0;
-              ObtainReadLock(&afs_xserver);
-            }
-          }
-        }
-      }
-      
-      ReleaseReadLock(&afs_xserver);
-      /* if we didn't find one, start to create one. */
-      /* Note that it doesn't have a cell yet...     */
-      if (!matches) {
-        afs_uint32 temp = sp->host.s_addr;
-        srvr = afs_GetServer(&temp, 1, 0, (vlonly ? AFS_VLPORT : AFS_FSPORT), 
-                             WRITE_LOCK, (afsUUID *)0,0);
-        srvr->addr->sa_iprank = sp->rank + afs_randomMod15();
-        afs_PutServer(srvr, WRITE_LOCK);
-      }
-   } /* for all cited preferences */
-   
-   ReSortCells(touchedSize, touched, vlonly);
-   return 0;
+       }
+
+       ReleaseReadLock(&afs_xserver);
+       /* if we didn't find one, start to create one. */
+       /* Note that it doesn't have a cell yet...     */
+       if (!matches) {
+           afs_uint32 temp = sp->host.s_addr;
+           srvr =
+               afs_GetServer(&temp, 1, 0, (vlonly ? AFS_VLPORT : AFS_FSPORT),
+                             WRITE_LOCK, (afsUUID *) 0, 0);
+           srvr->addr->sa_iprank = sp->rank + afs_randomMod15();
+           afs_PutServer(srvr, WRITE_LOCK);
+       }
+    }                          /* for all cited preferences */
+
+    ReSortCells(touchedSize, touched, vlonly);
+    return 0;
 }
 
  /* Note that this may only be performed by the local root user.
- */
+  */
 DECL_PIOCTL(PSetSPrefs)
 {
-  struct setspref *ssp;
-  AFS_STATCNT(PSetSPrefs);
+    struct setspref *ssp;
+    AFS_STATCNT(PSetSPrefs);
 
-  if ( !afs_resourceinit_flag )        /* afs deamons havn't started yet */
-       return EIO;          /* Inappropriate ioctl for device */
+    if (!afs_resourceinit_flag)        /* afs daemons haven't started yet */
+       return EIO;             /* Inappropriate ioctl for device */
 
-  if (!afs_osi_suser(*acred))
-      return EACCES;
+    if (!afs_osi_suser(*acred))
+       return EACCES;
 
-  if (ainSize < sizeof(struct setspref)) 
-    return EINVAL;
+    if (ainSize < sizeof(struct setspref))
+       return EINVAL;
 
-  ssp = (struct setspref *)ain;
-  if (ainSize < sizeof(struct spref)*ssp->num_servers) 
-    return EINVAL;
+    ssp = (struct setspref *)ain;
+    if (ainSize < sizeof(struct spref) * ssp->num_servers)
+       return EINVAL;
 
-  afs_setsprefs(&(ssp->servers[0]), ssp->num_servers, 
-               (ssp->flags & DBservers));
-  return 0;
+    afs_setsprefs(&(ssp->servers[0]), ssp->num_servers,
+                 (ssp->flags & DBservers));
+    return 0;
 }
 
 DECL_PIOCTL(PSetSPrefs33)
 {
-  struct spref *sp;
-  AFS_STATCNT(PSetSPrefs);
-  if ( !afs_resourceinit_flag )        /* afs deamons havn't started yet */
-       return EIO;          /* Inappropriate ioctl for device */
+    struct spref *sp;
+    AFS_STATCNT(PSetSPrefs);
+    if (!afs_resourceinit_flag)        /* afs daemons haven't started yet */
+       return EIO;             /* Inappropriate ioctl for device */
 
 
-  if (!afs_osi_suser(*acred))
-    return EACCES;
+    if (!afs_osi_suser(*acred))
+       return EACCES;
 
-  sp = (struct spref *)ain;
-  afs_setsprefs(sp, ainSize/(sizeof(struct spref)), 0 /*!vlonly*/);
-  return 0;
+    sp = (struct spref *)ain;
+    afs_setsprefs(sp, ainSize / (sizeof(struct spref)), 0 /*!vlonly */ );
+    return 0;
 }
 
 /* some notes on the following code...
  * in the hash table of server structs, all servers with the same IP address
- * will be on the same overflow chain.  
- * This could be sped slightly in some circumstances by having it cache the 
+ * will be on the same overflow chain.
+ * This could be sped slightly in some circumstances by having it cache the
  * immediately previous slot in the hash table and some supporting information
  * Only reports file servers now.
  */
 DECL_PIOCTL(PGetSPrefs)
 {
-   struct sprefrequest *spin; /* input */
-   struct sprefinfo *spout;   /* output */
-   struct spref *srvout;      /* one output component */
-   int i,j;                   /* counters for hash table traversal */
-   struct server *srvr;       /* one of CM's server structs */
-   struct srvAddr *sa;
-   afs_uint32 prevh;
-   int vlonly;                /* just return vlservers ? */
-   int isfs;
-   
-   AFS_STATCNT(PGetSPrefs);
-   if ( !afs_resourceinit_flag )       /* afs deamons havn't started yet */
-       return EIO;          /* Inappropriate ioctl for device */
-
-   
-   if (ainSize < sizeof (struct sprefrequest_33)) {
-      return ENOENT;
-   }
-   else {
-      spin = ((struct sprefrequest *) ain);
-   }
-   
-   if (ainSize > sizeof  (struct sprefrequest_33)) {
-      vlonly = (spin->flags & DBservers);
-   }
-   else vlonly = 0;
-   
-   /* struct sprefinfo includes 1 server struct...  that size gets added
-    * in during the loop that follows.
-    */
-   *aoutSize = sizeof(struct sprefinfo) - sizeof (struct spref);
-   spout = (struct sprefinfo *) aout;
-   spout->next_offset = spin->offset;
-   spout->num_servers = 0;
-   srvout = spout->servers;
-   
-   ObtainReadLock(&afs_xserver);
-   for (i=0, j=0; j < NSERVERS; j++) {       /* sift through hash table */
-      for (sa = afs_srvAddrs[j]; sa; sa = sa->next_bkt, i++) {
-        if (spin->offset > (unsigned short)i) {
-           continue;                /* catch up to where we left off */
-        }
+    struct sprefrequest *spin; /* input */
+    struct sprefinfo *spout;   /* output */
+    struct spref *srvout;      /* one output component */
+    int i, j;                  /* counters for hash table traversal */
+    struct server *srvr;       /* one of CM's server structs */
+    struct srvAddr *sa;
+    int vlonly;                        /* just return vlservers ? */
+    int isfs;
+
+    AFS_STATCNT(PGetSPrefs);
+    if (!afs_resourceinit_flag)        /* afs daemons haven't started yet */
+       return EIO;             /* Inappropriate ioctl for device */
+
+
+    if (ainSize < sizeof(struct sprefrequest_33)) {
+       return ENOENT;
+    } else {
+       spin = ((struct sprefrequest *)ain);
+    }
+
+    if (ainSize > sizeof(struct sprefrequest_33)) {
+       vlonly = (spin->flags & DBservers);
+    } else
+       vlonly = 0;
+
+    /* struct sprefinfo includes 1 server struct...  that size gets added
+     * in during the loop that follows.
+     */
+    *aoutSize = sizeof(struct sprefinfo) - sizeof(struct spref);
+    spout = (struct sprefinfo *)aout;
+    spout->next_offset = spin->offset;
+    spout->num_servers = 0;
+    srvout = spout->servers;
+
+    ObtainReadLock(&afs_xserver);
+    for (i = 0, j = 0; j < NSERVERS; j++) {    /* sift through hash table */
+       for (sa = afs_srvAddrs[j]; sa; sa = sa->next_bkt, i++) {
+           if (spin->offset > (unsigned short)i) {
+               continue;       /* catch up to where we left off */
+           }
            spout->next_offset++;
-        
+
            srvr = sa->server;
-           isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))  
-                || (sa->sa_portal == AFS_FSPORT); 
-        
+           isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
+               || (sa->sa_portal == AFS_FSPORT);
+
            if ((vlonly && isfs) || (!vlonly && !isfs)) {
-              /* only report ranks for vl servers */
-              continue;
+               /* only report ranks for vl servers */
+               continue;
            }
-        
-        srvout->host.s_addr = sa->sa_ip;
-        srvout->rank = sa->sa_iprank;
-        *aoutSize += sizeof(struct spref);
-        spout->num_servers++;
-        srvout++;
-
-        if (*aoutSize > (PIGGYSIZE - sizeof(struct spref))) {
-           ReleaseReadLock(&afs_xserver);                /* no more room! */
-           return 0;
-        }
-      }
-   }
-   ReleaseReadLock(&afs_xserver);
-   
-   spout->next_offset = 0;  /* start over from the beginning next time */
-   return 0;
+
+           srvout->host.s_addr = sa->sa_ip;
+           srvout->rank = sa->sa_iprank;
+           *aoutSize += sizeof(struct spref);
+           spout->num_servers++;
+           srvout++;
+
+           if (*aoutSize > (PIGGYSIZE - sizeof(struct spref))) {
+               ReleaseReadLock(&afs_xserver);  /* no more room! */
+               return 0;
+           }
+       }
+    }
+    ReleaseReadLock(&afs_xserver);
+
+    spout->next_offset = 0;    /* start over from the beginning next time */
+    return 0;
 }
 
 /* Enable/Disable the specified exporter. Must be root to disable an exporter */
-int  afs_NFSRootOnly = 1;
+int afs_NFSRootOnly = 1;
 DECL_PIOCTL(PExportAfs)
 {
-    afs_int32 export, newint=0, type, changestate, handleValue, convmode, pwsync, smounts;
+    afs_int32 export, newint =
+       0, type, changestate, handleValue, convmode, pwsync, smounts;
     register struct afs_exporter *exporter;
 
     AFS_STATCNT(PExportAfs);
@@ -2936,7 +3027,7 @@ DECL_PIOCTL(PExportAfs)
     type = handleValue >> 24;
     if (type == 0x71) {
        newint = 1;
-       type = 1;       /* nfs */
+       type = 1;               /* nfs */
     }
     exporter = exporter_find(type);
     if (newint) {
@@ -2962,7 +3053,7 @@ DECL_PIOCTL(PExportAfs)
        *aoutSize = sizeof(afs_int32);
     } else {
        if (!afs_osi_suser(*acred))
-           return EACCES;    /* Only superuser can do this */
+           return EACCES;      /* Only superuser can do this */
        if (newint) {
            if (export & 2) {
                if (export & 1)
@@ -3022,50 +3113,49 @@ DECL_PIOCTL(PExportAfs)
 
 DECL_PIOCTL(PGag)
 {
-struct gaginfo *gagflags;
+    struct gaginfo *gagflags;
 
-  if (!afs_osi_suser(*acred))
-    return EACCES;
+    if (!afs_osi_suser(*acred))
+       return EACCES;
 
-  gagflags = (struct gaginfo *) ain;
-  afs_showflags = gagflags->showflags;
+    gagflags = (struct gaginfo *)ain;
+    afs_showflags = gagflags->showflags;
 
-  return 0;
+    return 0;
 }
 
 
 DECL_PIOCTL(PTwiddleRx)
 {
-  struct rxparams *rxp;
-
-  if (!afs_osi_suser(*acred))
-    return EACCES;
-
-  rxp = (struct rxparams *) ain;
-
-  if (rxp->rx_initReceiveWindow)
-    rx_initReceiveWindow = rxp->rx_initReceiveWindow;
-  if (rxp->rx_maxReceiveWindow)
-    rx_maxReceiveWindow = rxp->rx_maxReceiveWindow;
-  if (rxp->rx_initSendWindow)
-    rx_initSendWindow = rxp->rx_initSendWindow;
-  if (rxp->rx_maxSendWindow)
-    rx_maxSendWindow = rxp->rx_maxSendWindow;
-  if (rxp->rxi_nSendFrags)
-    rxi_nSendFrags = rxp->rxi_nSendFrags;
-  if (rxp->rxi_nRecvFrags)
-    rxi_nRecvFrags = rxp->rxi_nRecvFrags;
-  if (rxp->rxi_OrphanFragSize)
-    rxi_OrphanFragSize = rxp->rxi_OrphanFragSize;
-  if (rxp->rx_maxReceiveSize)
-  {
-    rx_maxReceiveSize = rxp->rx_maxReceiveSize;
-    rx_maxReceiveSizeUser = rxp->rx_maxReceiveSize;
-  }
-  if (rxp->rx_MyMaxSendSize)
-    rx_MyMaxSendSize = rxp->rx_MyMaxSendSize;
-  return 0;
+    struct rxparams *rxp;
+
+    if (!afs_osi_suser(*acred))
+       return EACCES;
+
+    rxp = (struct rxparams *)ain;
+
+    if (rxp->rx_initReceiveWindow)
+       rx_initReceiveWindow = rxp->rx_initReceiveWindow;
+    if (rxp->rx_maxReceiveWindow)
+       rx_maxReceiveWindow = rxp->rx_maxReceiveWindow;
+    if (rxp->rx_initSendWindow)
+       rx_initSendWindow = rxp->rx_initSendWindow;
+    if (rxp->rx_maxSendWindow)
+       rx_maxSendWindow = rxp->rx_maxSendWindow;
+    if (rxp->rxi_nSendFrags)
+       rxi_nSendFrags = rxp->rxi_nSendFrags;
+    if (rxp->rxi_nRecvFrags)
+       rxi_nRecvFrags = rxp->rxi_nRecvFrags;
+    if (rxp->rxi_OrphanFragSize)
+       rxi_OrphanFragSize = rxp->rxi_OrphanFragSize;
+    if (rxp->rx_maxReceiveSize) {
+       rx_maxReceiveSize = rxp->rx_maxReceiveSize;
+       rx_maxReceiveSizeUser = rxp->rx_maxReceiveSize;
+    }
+    if (rxp->rx_MyMaxSendSize)
+       rx_MyMaxSendSize = rxp->rx_MyMaxSendSize;
+
+    return 0;
 }
 
 DECL_PIOCTL(PGetInitParams)
@@ -3073,18 +3163,19 @@ DECL_PIOCTL(PGetInitParams)
     if (sizeof(struct cm_initparams) > PIGGYSIZE)
        return E2BIG;
 
-    memcpy(aout, (char*)&cm_initParams, sizeof(struct cm_initparams));
+    memcpy(aout, (char *)&cm_initParams, sizeof(struct cm_initparams));
     *aoutSize = sizeof(struct cm_initparams);
     return 0;
 }
 
 #ifdef AFS_SGI65_ENV
 /* They took crget() from us, so fake it. */
-static cred_t *crget(void)
+static cred_t *
+crget(void)
 {
     cred_t *cr;
     cr = crdup(get_current_cred());
-    memset((char*)cr, 0, sizeof(cred_t));
+    memset((char *)cr, 0, sizeof(cred_t));
 #if CELL || CELL_PREPARE
     cr->cr_id = -1;
 #endif
@@ -3095,7 +3186,7 @@ static cred_t *crget(void)
 DECL_PIOCTL(PGetRxkcrypt)
 {
     memcpy(aout, (char *)&cryptall, sizeof(afs_int32));
-    *aoutSize=sizeof(afs_int32);
+    *aoutSize = sizeof(afs_int32);
     return 0;
 }
 
@@ -3104,17 +3195,18 @@ DECL_PIOCTL(PSetRxkcrypt)
     afs_int32 tmpval;
 
     if (!afs_osi_suser(*acred))
-      return EPERM;
+       return EPERM;
     if (ainSize != sizeof(afs_int32) || ain == NULL)
-      return EINVAL;
+       return EINVAL;
     memcpy((char *)&tmpval, ain, sizeof(afs_int32));
     /* if new mappings added later this will need to be changed */
     if (tmpval != 0 && tmpval != 1)
-      return EINVAL;
+       return EINVAL;
     cryptall = tmpval;
     return 0;
 }
 
+#ifdef AFS_NEED_CLIENTCONTEXT
 /*
  * Create new credentials to correspond to a remote user with given
  * <hostaddr, uid, g0, g1>.  This allows a server running as root to
@@ -3123,11 +3215,10 @@ DECL_PIOCTL(PSetRxkcrypt)
  */
 #define        PSETPAG         110
 #define        PIOCTL_HEADER   6
-static int HandleClientContext(struct afs_ioctl *ablob, int *com, struct AFS_UCRED **acred, struct AFS_UCRED *credp)
+static int
+HandleClientContext(struct afs_ioctl *ablob, int *com,
+                   struct AFS_UCRED **acred, struct AFS_UCRED *credp)
 {
-#if    defined(AFS_DEC_ENV) || (defined(AFS_NONFSTRANS) && !defined(AFS_AIX_IAUTH_ENV))
-    return EINVAL;                     /* NFS trans not supported for Ultrix */
-#else
     char *ain, *inData;
     afs_uint32 hostaddr;
     afs_int32 uid, g0, g1, i, code, pag, exporter_type;
@@ -3139,29 +3230,29 @@ static int HandleClientContext(struct afs_ioctl *ablob, int *com, struct AFS_UCR
     osi_Assert(ISAFS_GLOCK());
 #endif
     AFS_STATCNT(HandleClientContext);
-    if (ablob->in_size < PIOCTL_HEADER*sizeof(afs_int32)) { 
+    if (ablob->in_size < PIOCTL_HEADER * sizeof(afs_int32)) {
        /* Must at least include the PIOCTL_HEADER header words required by the protocol */
-       return EINVAL; /* Too small to be good  */
+       return EINVAL;          /* Too small to be good  */
     }
     ain = inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
-    AFS_COPYIN(ablob->in, ain, PIOCTL_HEADER*sizeof(afs_int32), code);
+    AFS_COPYIN(ablob->in, ain, PIOCTL_HEADER * sizeof(afs_int32), code);
     if (code) {
        osi_FreeLargeSpace(inData);
        return code;
     }
 
     /* Extract information for remote user */
-    hostaddr = *((afs_uint32 *)ain);
+    hostaddr = *((afs_uint32 *) ain);
     ain += sizeof(hostaddr);
-    uid = *((afs_uint32 *)ain);
+    uid = *((afs_uint32 *) ain);
     ain += sizeof(uid);
-    g0 = *((afs_uint32 *)ain);
+    g0 = *((afs_uint32 *) ain);
     ain += sizeof(g0);
-    g1 = *((afs_uint32 *)ain);
+    g1 = *((afs_uint32 *) ain);
     ain += sizeof(g1);
-    *com = *((afs_uint32 *)ain);
+    *com = *((afs_uint32 *) ain);
     ain += sizeof(afs_int32);
-    exporter_type = *((afs_uint32 *)ain);      /* In case we support more than NFS */
+    exporter_type = *((afs_uint32 *) ain);     /* In case we support more than NFS */
 
     /*
      * Of course, one must be root for most of these functions, but
@@ -3170,46 +3261,49 @@ static int HandleClientContext(struct afs_ioctl *ablob, int *com, struct AFS_UCR
      */
     i = (*com) & 0xff;
     if (!afs_osi_suser(credp)) {
-#ifdef AFS_SGI_ENV 
-#ifndef AFS_SGI64_ENV
+#if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
        /* Since SGI's suser() returns explicit failure after the call.. */
-       u.u_error = 0;          
-#endif 
+       u.u_error = 0;
 #endif
        /* check for acceptable opcodes for normal folks, which are, so far,
         * set tokens and unlog.
         */
-       if (i != 9 && i != 3 && i != 38 && i != 8)      {
+       if (i != 9 && i != 3 && i != 38 && i != 8) {
            osi_FreeLargeSpace(inData);
            return EACCES;
        }
     }
 
-    ablob->in_size -= PIOCTL_HEADER*sizeof(afs_int32);
-    ablob->in += PIOCTL_HEADER*sizeof(afs_int32);
+    ablob->in_size -= PIOCTL_HEADER * sizeof(afs_int32);
+    ablob->in += PIOCTL_HEADER * sizeof(afs_int32);
     osi_FreeLargeSpace(inData);
     if (uid == 0) {
-        /*
-         * We map uid 0 to nobody to match the mapping that the nfs
-         * server does and to ensure that the suser() calls in the afs
-         * code fails for remote client roots.
-         */
+       /*
+        * We map uid 0 to nobody to match the mapping that the nfs
+        * server does and to ensure that the suser() calls in the afs
+        * code fails for remote client roots.
+        */
        uid = afs_nobody;       /* NFS_NOBODY == -2 */
     }
     newcred = crget();
 #ifdef AFS_AIX41_ENV
-    setuerror(0);      
+    setuerror(0);
 #endif
     newcred->cr_gid = RMTUSER_REQ;
+#ifdef AFS_AIX51_ENV
+    newcred->cr_groupset.gs_union.un_groups[0] = g0;
+    newcred->cr_groupset.gs_union.un_groups[1] = g1;
+#else
     newcred->cr_groups[0] = g0;
     newcred->cr_groups[1] = g1;
+#endif
 #ifdef AFS_AIX_ENV
     newcred->cr_ngrps = 2;
 #else
 #if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV)
     newcred->cr_ngroups = 2;
 #else
-    for (i=2; i<NGROUPS; i++)
+    for (i = 2; i < NGROUPS; i++)
        newcred->cr_groups[i] = NOGROUP;
 #endif
 #endif
@@ -3218,8 +3312,8 @@ static int HandleClientContext(struct afs_ioctl *ablob, int *com, struct AFS_UCR
 #endif
     if (!(exporter = exporter_find(exporter_type))) {
        /* Exporter wasn't initialized or an invalid exporter type */
-        crfree(newcred);
-        return EINVAL;
+       crfree(newcred);
+       return EINVAL;
     }
     if (exporter->exp_states & EXP_PWSYNC) {
        if (uid != credp->cr_uid) {
@@ -3227,105 +3321,107 @@ static int HandleClientContext(struct afs_ioctl *ablob, int *com, struct AFS_UCR
            return ENOEXEC;     /* XXX Find a better errno XXX */
        }
     }
-    newcred->cr_uid = uid; /* Only temporary  */
+    newcred->cr_uid = uid;     /* Only temporary  */
     code = EXP_REQHANDLER(exporter, &newcred, hostaddr, &pag, &outexporter);
     /* The client's pag is the only unique identifier for it */
     newcred->cr_uid = pag;
     *acred = newcred;
     if (!code && *com == PSETPAG) {
-      /* Special case for 'setpag' */
-      afs_uint32 pagvalue = genpag();
-
-      au = afs_GetUser(pagvalue, -1, WRITE_LOCK); /* a new unixuser struct */
-      /*
-       * Note that we leave the 'outexporter' struct held so it won't
-       * dissappear on us
-       */
-      au->exporter = outexporter;
-      if (ablob->out_size >= 4) {
-       AFS_COPYOUT((char *)&pagvalue, ablob->out, sizeof(afs_int32), code);
-      }
-      afs_PutUser(au, WRITE_LOCK);
-      if (code) return code;
-      return PSETPAG;          /*  Special return for setpag  */
+       /* Special case for 'setpag' */
+       afs_uint32 pagvalue = genpag();
+
+       au = afs_GetUser(pagvalue, -1, WRITE_LOCK);     /* a new unixuser struct */
+       /*
+        * Note that we leave the 'outexporter' struct held so it won't
+        * dissappear on us
+        */
+       au->exporter = outexporter;
+       if (ablob->out_size >= 4) {
+           AFS_COPYOUT((char *)&pagvalue, ablob->out, sizeof(afs_int32),
+                       code);
+       }
+       afs_PutUser(au, WRITE_LOCK);
+       if (code)
+           return code;
+       return PSETPAG;         /*  Special return for setpag  */
     } else if (!code) {
        EXP_RELE(outexporter);
     }
     return code;
-#endif /*defined(AFS_DEC_ENV) || defined(AFS_NONFSTRANS)*/
 }
+#endif /* AFS_NEED_CLIENTCONTEXT */
 
 /* get all interface addresses of this client */
 
 DECL_PIOCTL(PGetCPrefs)
 {
-       struct sprefrequest *spin; /* input */
-       struct sprefinfo *spout;   /* output */
-       struct spref *srvout;      /* one output component */
-       int maxNumber;
-       int i,j;
+    struct sprefrequest *spin; /* input */
+    struct sprefinfo *spout;   /* output */
+    struct spref *srvout;      /* one output component */
+    int maxNumber;
+    int i, j;
 
-       AFS_STATCNT(PGetCPrefs);
-        if ( !afs_resourceinit_flag )  /* afs deamons havn't started yet */
-           return EIO;          /* Inappropriate ioctl for device */
+    AFS_STATCNT(PGetCPrefs);
+    if (!afs_resourceinit_flag)        /* afs daemons haven't started yet */
+       return EIO;             /* Inappropriate ioctl for device */
 
-       if ( ainSize < sizeof (struct sprefrequest ))
-               return EINVAL;
-       
-       spin = (struct sprefrequest *) ain;
-       spout = (struct sprefinfo *) aout;
-
-       maxNumber = spin->num_servers; /* max addrs this time */
-       srvout = spout->servers;
-
-       ObtainReadLock(&afs_xinterface);
-
-       /* copy out the client interface information from the
-       ** kernel data structure "interface" to the output buffer
-       */
-       for ( i=spin->offset, j=0; (i < afs_cb_interface.numberOfInterfaces)
-                                  && ( j< maxNumber) ; i++, j++, srvout++)
-               srvout->host.s_addr = afs_cb_interface.addr_in[i];
-       
-       spout->num_servers = j;
-       *aoutSize = sizeof(struct sprefinfo) +(j-1)* sizeof (struct spref);
-
-       if ( i >= afs_cb_interface.numberOfInterfaces )
-               spout->next_offset = 0; /* start from beginning again */
-       else
-               spout->next_offset = spin->offset + j;
-       
-       ReleaseReadLock(&afs_xinterface);
-       return 0;
+    if (ainSize < sizeof(struct sprefrequest))
+       return EINVAL;
+
+    spin = (struct sprefrequest *)ain;
+    spout = (struct sprefinfo *)aout;
+
+    maxNumber = spin->num_servers;     /* max addrs this time */
+    srvout = spout->servers;
+
+    ObtainReadLock(&afs_xinterface);
+
+    /* copy out the client interface information from the
+     ** kernel data structure "interface" to the output buffer
+     */
+    for (i = spin->offset, j = 0; (i < afs_cb_interface.numberOfInterfaces)
+        && (j < maxNumber); i++, j++, srvout++)
+       srvout->host.s_addr = afs_cb_interface.addr_in[i];
+
+    spout->num_servers = j;
+    *aoutSize = sizeof(struct sprefinfo) + (j - 1) * sizeof(struct spref);
+
+    if (i >= afs_cb_interface.numberOfInterfaces)
+       spout->next_offset = 0; /* start from beginning again */
+    else
+       spout->next_offset = spin->offset + j;
+
+    ReleaseReadLock(&afs_xinterface);
+    return 0;
 }
 
 DECL_PIOCTL(PSetCPrefs)
 {
-       struct setspref *sin;
-       int i;
+    struct setspref *sin;
+    int i;
 
-       AFS_STATCNT(PSetCPrefs);
-        if ( !afs_resourceinit_flag )  /* afs deamons havn't started yet */
-           return EIO;          /* Inappropriate ioctl for device */
+    AFS_STATCNT(PSetCPrefs);
+    if (!afs_resourceinit_flag)        /* afs daemons haven't started yet */
+       return EIO;             /* Inappropriate ioctl for device */
 
-       sin = (struct setspref *)ain;
+    sin = (struct setspref *)ain;
 
-       if ( ainSize < sizeof(struct setspref) )
-               return EINVAL;
-#if 0  /* num_servers is unsigned */
-       if ( sin->num_servers < 0 )
-               return EINVAL;
+    if (ainSize < sizeof(struct setspref))
+       return EINVAL;
+#if 0                          /* num_servers is unsigned */
+    if (sin->num_servers < 0)
+       return EINVAL;
 #endif
-       if ( sin->num_servers > AFS_MAX_INTERFACE_ADDR)
-               return ENOMEM;
+    if (sin->num_servers > AFS_MAX_INTERFACE_ADDR)
+       return ENOMEM;
 
-       ObtainWriteLock(&afs_xinterface, 412);
-       afs_cb_interface.numberOfInterfaces = sin->num_servers;
-       for ( i=0; (unsigned short)i < sin->num_servers; i++)
-               afs_cb_interface.addr_in[i] = sin->servers[i].host.s_addr;
+    ObtainWriteLock(&afs_xinterface, 412);
+    afs_cb_interface.numberOfInterfaces = sin->num_servers;
+    for (i = 0; (unsigned short)i < sin->num_servers; i++)
+       afs_cb_interface.addr_in[i] = sin->servers[i].host.s_addr;
 
-       ReleaseWriteLock(&afs_xinterface);
-       return 0;
+    ReleaseWriteLock(&afs_xinterface);
+    return 0;
 }
 
 DECL_PIOCTL(PFlushMount)
@@ -3339,21 +3435,24 @@ DECL_PIOCTL(PFlushMount)
     afs_size_t offset, len;
 
     AFS_STATCNT(PFlushMount);
-    if (!avc) return EINVAL;
+    if (!avc)
+       return EINVAL;
     code = afs_VerifyVCache(avc, areq);
-    if (code) return code;
+    if (code)
+       return code;
     if (vType(avc) != VDIR) {
        return ENOTDIR;
     }
     tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
-    if (!tdc) return ENOENT;
+    if (!tdc)
+       return ENOENT;
     Check_AtSys(avc, ain, &sysState, areq);
     ObtainReadLock(&tdc->lock);
     do {
-      code = afs_dir_Lookup(&tdc->f.inode, sysState.name, &tfid.Fid);
+       code = afs_dir_Lookup(&tdc->f.inode, sysState.name, &tfid.Fid);
     } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
     ReleaseReadLock(&tdc->lock);
-    afs_PutDCache(tdc);            /* we're done with the data */
+    afs_PutDCache(tdc);                /* we're done with the data */
     bufp = sysState.name;
     if (code) {
        goto out;
@@ -3377,17 +3476,17 @@ DECL_PIOCTL(PFlushMount)
 #if    defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
     afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
 #endif
-    ObtainWriteLock(&tvc->lock,649);
+    ObtainWriteLock(&tvc->lock, 649);
     ObtainWriteLock(&afs_xcbhash, 650);
     afs_DequeueCallback(tvc);
-    tvc->states        &= ~(CStatd | CDirty);  /* next reference will re-stat cache entry */
+    tvc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
     ReleaseWriteLock(&afs_xcbhash);
     /* now find the disk cache entries */
     afs_TryToSmush(tvc, *acred, 1);
     osi_dnlc_purgedp(tvc);
     afs_symhint_inval(tvc);
     if (tvc->linkData && !(tvc->states & CCore)) {
-       afs_osi_Free(tvc->linkData, strlen(tvc->linkData)+1);
+       afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
        tvc->linkData = NULL;
     }
     ReleaseWriteLock(&tvc->lock);
@@ -3395,8 +3494,9 @@ DECL_PIOCTL(PFlushMount)
     afs_BozonUnlock(&tvc->pvnLock, tvc);
 #endif
     afs_PutVCache(tvc);
-out:
-    if (sysState.allocked) osi_FreeLargeSpace(bufp);
+  out:
+    if (sysState.allocked)
+       osi_FreeLargeSpace(bufp);
     return code;
 }
 
@@ -3427,7 +3527,7 @@ DECL_PIOCTL(PRxStatProc)
     if (flags & AFSCALL_RXSTATS_CLEAR) {
        rx_clearProcessRPCStats(AFS_RX_STATS_CLEAR_ALL);
     }
-out:
+  out:
     *aoutSize = 0;
     return code;
 }
@@ -3460,7 +3560,7 @@ DECL_PIOCTL(PRxStatPeer)
     if (flags & AFSCALL_RXSTATS_CLEAR) {
        rx_clearPeerRPCStats(AFS_RX_STATS_CLEAR_ALL);
     }
-out:
+  out:
     *aoutSize = 0;
     return code;
 }
@@ -3477,16 +3577,15 @@ DECL_PIOCTL(PPrefetchFromTape)
     struct VenusFid tfid;
     struct AFSFid *Fid;
     struct vcache *tvc;
-    XSTATS_DECLS;
 
     AFS_STATCNT(PSetAcl);
     if (!avc)
-      return EINVAL;
+       return EINVAL;
 
     if (ain && (ainSize == 3 * sizeof(afs_int32)))
-        Fid = (struct AFSFid *) ain;
+       Fid = (struct AFSFid *)ain;
     else
-        Fid = &avc->fid.Fid;
+       Fid = &avc->fid.Fid;
     tfid.Cell = avc->fid.Cell;
     tfid.Fid.Volume = Fid->Volume;
     tfid.Fid.Vnode = Fid->Vnode;
@@ -3494,43 +3593,40 @@ DECL_PIOCTL(PPrefetchFromTape)
 
     tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
     if (!tvc) {
-        afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD,
-                ICL_TYPE_POINTER, tvc,
-                ICL_TYPE_FID, &tfid,
-                ICL_TYPE_FID, &avc->fid);
-        return ENOENT;
+       afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
+                  ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &avc->fid);
+       return ENOENT;
     }
-    afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD,
-                ICL_TYPE_POINTER, tvc,
-                ICL_TYPE_FID, &tfid,
-                ICL_TYPE_FID, &tvc->fid);
+    afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
+              ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &tvc->fid);
 
     do {
-        tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
-        if (tc) {
-
-            RX_AFS_GUNLOCK();
-            tcall = rx_NewCall(tc->id);
-            code = StartRXAFS_FetchData(tcall,
-                                (struct AFSFid *) &tvc->fid.Fid, 0, 0);
-            if (!code) {
-                bytes = rx_Read(tcall, (char *) aout, sizeof(afs_int32));
-                code = EndRXAFS_FetchData(tcall, &OutStatus, &CallBack, &tsync);
-            }
-            code1 = rx_EndCall(tcall, code);
-            RX_AFS_GLOCK();
-        } else
-            code = -1;
-    } while
-        (afs_Analyze(tc, code, &tvc->fid, areq, 
-               AFS_STATS_FS_RPCIDX_RESIDENCYRPCS, SHARED_LOCK, 
-               NULL));
+       tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
+       if (tc) {
+
+           RX_AFS_GUNLOCK();
+           tcall = rx_NewCall(tc->id);
+           code =
+               StartRXAFS_FetchData(tcall, (struct AFSFid *)&tvc->fid.Fid, 0,
+                                    0);
+           if (!code) {
+               bytes = rx_Read(tcall, (char *)aout, sizeof(afs_int32));
+               code =
+                   EndRXAFS_FetchData(tcall, &OutStatus, &CallBack, &tsync);
+           }
+           code1 = rx_EndCall(tcall, code);
+           RX_AFS_GLOCK();
+       } else
+           code = -1;
+    } while (afs_Analyze
+            (tc, code, &tvc->fid, areq, AFS_STATS_FS_RPCIDX_RESIDENCYRPCS,
+             SHARED_LOCK, NULL));
     /* This call is done only to have the callback things handled correctly */
     afs_FetchStatus(tvc, &tfid, areq, &OutStatus);
     afs_PutVCache(tvc);
 
     if (!code) {
-        *aoutSize = sizeof(afs_int32);
+       *aoutSize = sizeof(afs_int32);
     }
     return code;
 }
@@ -3545,14 +3641,16 @@ DECL_PIOCTL(PResidencyCmd)
     struct VenusFid tfid;
     struct AFSFid *Fid;
 
-    Inputs = (struct ResidencyCmdInputs *) ain;
-    Outputs = (struct ResidencyCmdOutputs *) aout;
-    if (!avc) return EINVAL;
-    if (!ain || ainSize != sizeof(struct ResidencyCmdInputs)) return EINVAL;
+    Inputs = (struct ResidencyCmdInputs *)ain;
+    Outputs = (struct ResidencyCmdOutputs *)aout;
+    if (!avc)
+       return EINVAL;
+    if (!ain || ainSize != sizeof(struct ResidencyCmdInputs))
+       return EINVAL;
 
     Fid = &Inputs->fid;
     if (!Fid->Volume)
-        Fid = &avc->fid.Fid;
+       Fid = &avc->fid.Fid;
 
     tfid.Cell = avc->fid.Cell;
     tfid.Fid.Volume = Fid->Volume;
@@ -3560,46 +3658,43 @@ DECL_PIOCTL(PResidencyCmd)
     tfid.Fid.Unique = Fid->Unique;
 
     tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
-    afs_Trace3(afs_iclSetp, CM_TRACE_RESIDCMD,
-                ICL_TYPE_POINTER, tvc,
-                ICL_TYPE_INT32, Inputs->command,
-                ICL_TYPE_FID, &tfid);
+    afs_Trace3(afs_iclSetp, CM_TRACE_RESIDCMD, ICL_TYPE_POINTER, tvc,
+              ICL_TYPE_INT32, Inputs->command, ICL_TYPE_FID, &tfid);
     if (!tvc)
-        return ENOENT;
+       return ENOENT;
 
     if (Inputs->command) {
-        do {
-            tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
-            if (tc) {
-                RX_AFS_GUNLOCK();
-                code = RXAFS_ResidencyCmd(tc->id, Fid,
-                                 Inputs,
-                                 (struct ResidencyCmdOutputs *) aout);
-                RX_AFS_GLOCK();
-            } else
-                code = -1;
-        } while
-          (afs_Analyze(tc, code, &tvc->fid, areq, 
-               AFS_STATS_FS_RPCIDX_RESIDENCYRPCS, SHARED_LOCK,
-                NULL));
-       /* This call is done to have the callback things handled correctly */
-       afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
-    } else { /* just a status request, return also link data */
-        code = 0;
-        Outputs->code = afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
-        Outputs->chars[0] = 0;
-        if (vType(tvc) == VLNK) {
-            ObtainWriteLock(&tvc->lock,555);
-            if (afs_HandleLink(tvc, areq) == 0)
-                strncpy((char *) &Outputs->chars, tvc->linkData, MAXCMDCHARS);
-            ReleaseWriteLock(&tvc->lock);
-        }
+       do {
+           tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
+           if (tc) {
+               RX_AFS_GUNLOCK();
+               code =
+                   RXAFS_ResidencyCmd(tc->id, Fid, Inputs,
+                                      (struct ResidencyCmdOutputs *)aout);
+               RX_AFS_GLOCK();
+           } else
+               code = -1;
+       } while (afs_Analyze
+                (tc, code, &tvc->fid, areq,
+                 AFS_STATS_FS_RPCIDX_RESIDENCYRPCS, SHARED_LOCK, NULL));
+       /* This call is done to have the callback things handled correctly */
+       afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
+    } else {                   /* just a status request, return also link data */
+       code = 0;
+       Outputs->code = afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
+       Outputs->chars[0] = 0;
+       if (vType(tvc) == VLNK) {
+           ObtainWriteLock(&tvc->lock, 555);
+           if (afs_HandleLink(tvc, areq) == 0)
+               strncpy((char *)&Outputs->chars, tvc->linkData, MAXCMDCHARS);
+           ReleaseWriteLock(&tvc->lock);
+       }
     }
 
     afs_PutVCache(tvc);
 
     if (!code) {
-        *aoutSize = sizeof(struct ResidencyCmdOutputs);
+       *aoutSize = sizeof(struct ResidencyCmdOutputs);
     }
     return code;
-}                                  
+}