Use AFS_CACHE_VNODE_PATH for UKERNEL
[openafs.git] / src / afs / UKERNEL / afs_usrops.c
index 8650349..e946b90 100644 (file)
@@ -1,3 +1,4 @@
+
 /*
  * Copyright 2000, International Business Machines Corporation and others.
  * All Rights Reserved.
 #include <afsconfig.h>
 #include "afs/param.h"
 
-RCSID("$Header$");
-
-
 #ifdef UKERNEL
 
 #include "afs/sysincludes.h"   /* Standard vendor system headers */
 #include <net/if.h>
+
 #include "afsincludes.h"       /* Afs-based standard headers */
 #include "afs_usrops.h"
 #include "afs/afs_stats.h"
 #include "afs/auth.h"
 #include "afs/cellconfig.h"
 #include "afs/vice.h"
+#include "afs/kauth.h"
 #include "afs/kautils.h"
 #include "afs/afsutil.h"
 #include "rx/rx_globals.h"
@@ -35,10 +35,15 @@ RCSID("$Header$");
 #undef VIRTUE
 #undef VICE
 
+#ifndef AFS_CACHE_VNODE_PATH
+#error You must compile UKERNEL code with -DAFS_CACHE_VNODE_PATH
+#endif
+
 #define CACHEINFOFILE  "cacheinfo"
 #define        AFSLOGFILE      "AFSLog"
 #define        DCACHEFILE      "CacheItems"
 #define        VOLINFOFILE     "VolumeItems"
+#define        CELLINFOFILE    "CellItems"
 #define MAXIPADDRS 64
 
 #ifndef MIN
@@ -54,7 +59,7 @@ char afs_LclCellName[64];
 
 struct usr_vnode *afs_FileTable[MAX_OSI_FILES];
 int afs_FileFlags[MAX_OSI_FILES];
-int afs_FileOffsets[MAX_OSI_FILES];
+off_t afs_FileOffsets[MAX_OSI_FILES];
 
 #define MAX_CACHE_LOOPS 4
 
@@ -62,50 +67,49 @@ struct usr_vfs afs_RootVfs;
 struct usr_vnode *afs_RootVnode = NULL;
 struct usr_vnode *afs_CurrentDir = NULL;
 
-afs_int32 cacheBlocks;                 /* Num blocks in cache */
-afs_int32 cacheFiles = 1000;           /* Num files in workstation cache */
-afs_int32 cacheStatEntries = 300;              /* Num of stat cache entries */
-char cacheBaseDir[1024];               /* AFS cache directory */
-char confDir[1024];                    /* AFS configuration directory */
-char afs_mountDir[1024];               /* AFS mount point */
-int afs_mountDirLen;                   /* strlen of AFS mount point */
-char fullpn_DCacheFile[1024];          /* Full pathname of DCACHEFILE */
-char fullpn_VolInfoFile[1024];         /* Full pathname of VOLINFOFILE */
-char fullpn_AFSLogFile[1024];          /* Full pathname of AFSLOGFILE */
-char fullpn_CacheInfo[1024];           /* Full pathname of CACHEINFO */
-char fullpn_VFile[1024];               /* Full pathname of data cache files */
-char *vFileNumber;                     /* Ptr to number in file pathname */
+afs_int32 cacheBlocks;         /* Num blocks in cache */
+afs_int32 cacheFiles = 1000;   /* Num files in workstation cache */
+afs_int32 cacheStatEntries = 300;      /* Num of stat cache entries */
+char cacheBaseDir[1024];       /* AFS cache directory */
+char confDir[1024];            /* AFS configuration directory */
+char afs_mountDir[1024];       /* AFS mount point */
+int afs_mountDirLen;           /* strlen of AFS mount point */
+char fullpn_DCacheFile[1024];  /* Full pathname of DCACHEFILE */
+char fullpn_VolInfoFile[1024]; /* Full pathname of VOLINFOFILE */
+char fullpn_CellInfoFile[1024];        /* Full pathname of CELLINFOFILE */
+char fullpn_AFSLogFile[1024];  /* Full pathname of AFSLOGFILE */
+char fullpn_CacheInfo[1024];   /* Full pathname of CACHEINFO */
+char fullpn_VFile[1024];       /* Full pathname of data cache files */
+char *vFileNumber;             /* Ptr to number in file pathname */
 char rootVolume[64] = "root.afs";      /* AFS root volume name */
-afs_int32 isHomeCell;                  /* Is current cell info for home cell */
-afs_int32 lookingForHomeCell;          /* Are we still looking for home cell */
-int createAndTrunc = O_CREAT | O_TRUNC; /* Create & truncate on open */
-int ownerRWmode = 0600;                        /* Read/write OK by owner */
-static int nDaemons = 2;               /* Number of background daemons */
-static int chunkSize = 0;              /* 2^chunkSize bytes per chunk */
-static int dCacheSize = 300;           /* # of dcache entries */
-static int vCacheSize = 50;            /* # of volume cache entries */
-static int cacheFlags = 0;             /* Flags to cache manager */
-static int preallocs = 400;            /* Def # of allocated memory blocks */
-int afsd_verbose = 0;                  /* Are we being chatty? */
-int afsd_debug = 0;                    /* Are we printing debugging info? */
-int afsd_CloseSynch = 0;               /* Are closes synchronous or not? */
+afs_int32 isHomeCell;          /* Is current cell info for home cell */
+int createAndTrunc = O_CREAT | O_TRUNC;        /* Create & truncate on open */
+int ownerRWmode = 0600;                /* Read/write OK by owner */
+static int nDaemons = 2;       /* Number of background daemons */
+static int chunkSize = 0;      /* 2^chunkSize bytes per chunk */
+static int dCacheSize = 300;   /* # of dcache entries */
+static int vCacheSize = 50;    /* # of volume cache entries */
+static int cacheFlags = 0;     /* Flags to cache manager */
+static int preallocs = 400;    /* Def # of allocated memory blocks */
+int afsd_verbose = 0;          /* Are we being chatty? */
+int afsd_debug = 0;            /* Are we printing debugging info? */
+int afsd_CloseSynch = 0;       /* Are closes synchronous or not? */
 
 #define AFSD_INO_T afs_uint32
-char **pathname_for_V;                 /* Array of cache file pathnames */
-int missing_DCacheFile = 1;            /* Is the DCACHEFILE missing? */
-int missing_VolInfoFile = 1;           /* Is the VOLINFOFILE missing? */
-struct afs_cacheParams cparams;                /* params passed to cache manager */
-struct afsconf_dir *afs_cdir;          /* config dir */
-
-static int HandleMTab();
+char **pathname_for_V;         /* Array of cache file pathnames */
+int missing_DCacheFile = 1;    /* Is the DCACHEFILE missing? */
+int missing_VolInfoFile = 1;   /* Is the VOLINFOFILE missing? */
+int missing_CellInfoFile = 1;
+struct afs_cacheParams cparams;        /* params passed to cache manager */
+struct afsconf_dir *afs_cdir;  /* config dir */
 
 int afs_bufferpages = 100;
 int usr_udpcksum = 0;
 
 usr_key_t afs_global_u_key;
 
-struct usr_proc *afs_global_procp;
-struct usr_ucred *afs_global_ucredp;
+struct usr_proc *afs_global_procp = NULL;
+struct usr_ucred *afs_global_ucredp = NULL;
 struct usr_sysent usr_sysent[200];
 
 #ifdef AFS_USR_OSF_ENV
@@ -114,12 +118,12 @@ char V = 'V';
 long V = 'V';
 #endif /* AFS_USR_OSF_ENV */
 
-struct usr_ucred afs_osi_cred;
+struct usr_ucred afs_osi_cred, *afs_osi_credp;
 usr_mutex_t afs_global_lock;
 usr_thread_t afs_global_owner;
 usr_mutex_t rx_global_lock;
 usr_thread_t rx_global_owner;
-usr_mutex_t osi_inode_lock;
+usr_mutex_t osi_dummy_lock;
 usr_mutex_t osi_waitq_lock;
 usr_mutex_t osi_authenticate_lock;
 afs_lock_t afs_ftf;
@@ -128,7 +132,7 @@ afs_lock_t osi_fsplock;
 void *vnodefops;
 
 #ifndef NETSCAPE_NSAPI
+
 /*
  * Mutex and condition variable used to implement sleep
  */
@@ -138,6 +142,7 @@ pthread_cond_t usr_sleep_cond;
 #endif /* !NETSCAPE_NSAPI */
 
 int call_syscall(long, long, long, long, long, long);
+int fork_syscall(long, long, long, long, long, long);
 
 
 /*
@@ -145,14 +150,14 @@ int call_syscall(long, long, long, long, long, long);
  * osi_Sleep/osi_Wakeup and osi_Wait/osi_Wakeup
  */
 typedef struct osi_wait {
-    caddr_t            addr;
-    usr_cond_t         cond;
-    int                        flag;
-    struct osi_wait    *next;
-    struct osi_wait    *prev;
-    time_t             expiration;
-    struct osi_wait    *timedNext;
-    struct osi_wait    *timedPrev;
+    caddr_t addr;
+    usr_cond_t cond;
+    int flag;
+    struct osi_wait *next;
+    struct osi_wait *prev;
+    time_t expiration;
+    struct osi_wait *timedNext;
+    struct osi_wait *timedPrev;
 } osi_wait_t;
 
 /*
@@ -169,40 +174,48 @@ osi_wait_t *osi_timedwait_head;
 osi_wait_t *osi_timedwait_tail;
 
 struct {
-    osi_wait_t         *head;
-    osi_wait_t         *tail;
+    osi_wait_t *head;
+    osi_wait_t *tail;
 } osi_waithash_table[OSI_WAITHASH_SIZE];
 
 /*
  * Never call afs_brelse
  */
-int ufs_brelse(struct usr_vnode *vp, struct usr_buf *bp)
+int
+ufs_brelse(struct usr_vnode *vp, struct usr_buf *bp)
 {
     usr_assert(0);
+    return 0;
 }
 
 /*
  * I am not sure what to do with these, they assert for now
  */
-int iodone(struct usr_buf *bp)
+int
+iodone(struct usr_buf *bp)
 {
     usr_assert(0);
+    return 0;
 }
 
-struct usr_file *getf(int fd)
+struct usr_file *
+getf(int fd)
 {
     usr_assert(0);
+    return 0;
 }
 
 /*
  * Every user is a super user
  */
-int afs_osi_suser(void *credp)
+int
+afs_osi_suser(void *credp)
 {
     return 1;
 }
 
-int afs_suser(void *credp)
+int
+afs_suser(void *credp)
 {
     return 1;
 }
@@ -211,7 +224,8 @@ int afs_suser(void *credp)
  * These are no-ops in user space
  */
 
-void afs_osi_SetTime(osi_timeval_t *atv)
+void
+afs_osi_SetTime(osi_timeval_t * atv)
 {
     return;
 }
@@ -220,71 +234,92 @@ void afs_osi_SetTime(osi_timeval_t *atv)
  * xflock should never fall through, the only files we know
  * about are AFS files
  */
-int usr_flock(void)
+int
+usr_flock(void)
 {
     usr_assert(0);
+    return 0;
 }
 
 /*
  * ioctl should never fall through, the only files we know
  * about are AFS files
  */
-int usr_ioctl(void)
+int
+usr_ioctl(void)
 {
     usr_assert(0);
+    return 0;
 }
 
 /*
  * We do not support the inode related system calls
  */
-int afs_syscall_icreate(void)
+int
+afs_syscall_icreate(long a, long b, long c, long d, long e, long f)
 {
     usr_assert(0);
+    return 0;
 }
 
-int afs_syscall_iincdec(void)
+int
+afs_syscall_iincdec(int dev, int inode, int inode_p1, int amount)
 {
     usr_assert(0);
+    return 0;
 }
 
-int afs_syscall_iopen(void)
+int
+afs_syscall_iopen(int dev, int inode, int usrmod)
 {
     usr_assert(0);
+    return 0;
 }
 
-int afs_syscall_ireadwrite(void)
+int
+afs_syscall_ireadwrite(void)
 {
     usr_assert(0);
+    return 0;
 }
 
 /*
  * these routines are referenced in the vfsops structure, but
  * should never get called
  */
-int vno_close(void)
+int
+vno_close(void)
 {
     usr_assert(0);
+    return 0;
 }
 
-int vno_ioctl(void)
+int
+vno_ioctl(void)
 {
     usr_assert(0);
+    return 0;
 }
 
-int vno_rw(void)
+int
+vno_rw(void)
 {
     usr_assert(0);
+    return 0;
 }
 
-int vno_select(void)
+int
+vno_select(void)
 {
     usr_assert(0);
+    return 0;
 }
 
 /*
  * uiomove copies data between kernel buffers and uio buffers
  */
-int usr_uiomove(char *kbuf, int n, int rw, struct usr_uio *uio)
+int
+usr_uiomove(char *kbuf, int n, int rw, struct usr_uio *uio)
 {
     int nio;
     int len;
@@ -301,7 +336,7 @@ int usr_uiomove(char *kbuf, int n, int rw, struct usr_uio *uio)
      * copy the data
      */
     ptr = kbuf;
-    while(nio > 0 && n > 0) {
+    while (nio > 0 && n > 0) {
        len = MIN(n, iovp->iov_len);
        if (rw == UIO_READ) {
            memcpy(iovp->iov_base, ptr, len);
@@ -326,7 +361,8 @@ int usr_uiomove(char *kbuf, int n, int rw, struct usr_uio *uio)
 /*
  * routines to manage user credentials
  */
-struct usr_ucred *usr_crcopy(struct usr_ucred *credp)
+struct usr_ucred *
+usr_crcopy(struct usr_ucred *credp)
 {
     struct usr_ucred *newcredp;
 
@@ -336,7 +372,8 @@ struct usr_ucred *usr_crcopy(struct usr_ucred *credp)
     return newcredp;
 }
 
-struct usr_ucred *usr_crget(void)
+struct usr_ucred *
+usr_crget(void)
 {
     struct usr_ucred *newcredp;
 
@@ -345,24 +382,29 @@ struct usr_ucred *usr_crget(void)
     return newcredp;
 }
 
-int usr_crfree(struct usr_ucred *credp)
+int
+usr_crfree(struct usr_ucred *credp)
 {
     credp->cr_ref--;
     if (credp->cr_ref == 0) {
        afs_osi_Free((char *)credp, sizeof(struct usr_ucred));
     }
+    return 0;
 }
 
-int usr_crhold(struct usr_ucred *credp)
+int
+usr_crhold(struct usr_ucred *credp)
 {
     credp->cr_ref++;
+    return 0;
 }
 
-void usr_vattr_null(struct usr_vattr *vap)
+void
+usr_vattr_null(struct usr_vattr *vap)
 {
     int n;
     char *cp;
+
     n = sizeof(struct usr_vattr);
     cp = (char *)vap;
     while (n--) {
@@ -375,7 +417,8 @@ void usr_vattr_null(struct usr_vattr *vap)
  * kernel environment for each thread. The user structure
  * is stored in the thread specific data.
  */
-void uafs_InitThread(void)
+void
+uafs_InitThread(void)
 {
     int st;
     struct usr_user *uptr;
@@ -385,13 +428,14 @@ void uafs_InitThread(void)
      * allocate the data block, so pthread_finish can free the buffer
      * when this thread terminates.
      */
-    uptr = (struct usr_user *)malloc(sizeof(struct usr_user) +
-                                    sizeof(struct usr_ucred));
+    uptr =
+       (struct usr_user *)malloc(sizeof(struct usr_user) +
+                                 sizeof(struct usr_ucred));
     usr_assert(uptr != NULL);
     uptr->u_error = 0;
     uptr->u_prio = 0;
     uptr->u_procp = afs_global_procp;
-    uptr->u_cred = (struct usr_ucred *)(uptr+1);
+    uptr->u_cred = (struct usr_ucred *)(uptr + 1);
     *uptr->u_cred = *afs_global_ucredp;
     st = usr_setspecific(afs_global_u_key, (void *)uptr);
     usr_assert(st == 0);
@@ -402,13 +446,14 @@ void uafs_InitThread(void)
  * this routine is used to implement the global 'u' structure. Initializes
  * the thread if needed.
  */
-struct usr_user *get_user_struct(void)
+struct usr_user *
+get_user_struct(void)
 {
     struct usr_user *uptr;
     int st;
     st = usr_getspecific(afs_global_u_key, (void **)&uptr);
     usr_assert(st == 0);
-    if(uptr == NULL) {
+    if (uptr == NULL) {
        uafs_InitThread();
        st = usr_getspecific(afs_global_u_key, (void **)&uptr);
        usr_assert(st == 0);
@@ -426,23 +471,20 @@ struct usr_user *get_user_struct(void)
 /*
  * Sleep on an event
  */
-void afs_osi_Sleep(void *x)
+void
+afs_osi_Sleep(void *x)
 {
     int index;
     osi_wait_t *waitp;
-    int rxGlockOwner = ISAFS_RXGLOCK();
     int glockOwner = ISAFS_GLOCK();
 
     usr_mutex_lock(&osi_waitq_lock);
     if (glockOwner) {
        AFS_GUNLOCK();
     }
-    if (rxGlockOwner) {
-       AFS_RXGUNLOCK();
-    }
     index = WAITHASH(x);
     if (osi_waithash_avail == NULL) {
-       waitp = (osi_wait_t *)afs_osi_Alloc(sizeof(osi_wait_t));
+       waitp = (osi_wait_t *) afs_osi_Alloc(sizeof(osi_wait_t));
        usr_cond_init(&waitp->cond);
     } else {
        waitp = osi_waithash_avail;
@@ -466,18 +508,17 @@ void afs_osi_Sleep(void *x)
     if (glockOwner) {
        AFS_GLOCK();
     }
-    if (rxGlockOwner) {
-       AFS_RXGLOCK();
-    }
 }
 
-int afs_osi_SleepSig(void *x)
+int
+afs_osi_SleepSig(void *x)
 {
     afs_osi_Sleep(x);
     return 0;
 }
 
-int afs_osi_Wakeup(void *x)
+int
+afs_osi_Wakeup(void *x)
 {
     int index;
     osi_wait_t *waitp;
@@ -493,15 +534,22 @@ int afs_osi_Wakeup(void *x)
        waitp = waitp->next;
     }
     usr_mutex_unlock(&osi_waitq_lock);
+    return 0;
+}
+
+int
+afs_osi_TimedSleep(void *event, afs_int32 ams, int aintok)
+{
+    return afs_osi_Wait(ams, event, aintok);
 }
 
-int afs_osi_Wait(afs_int32 msec, struct afs_osi_WaitHandle *handle, int intok)
+int
+afs_osi_Wait(afs_int32 msec, struct afs_osi_WaitHandle *handle, int intok)
 {
     int index;
     osi_wait_t *waitp;
     struct timespec tv;
     int ret;
-    int rxGlockOwner = ISAFS_RXGLOCK();
     int glockOwner = ISAFS_GLOCK();
 
     tv.tv_sec = msec / 1000;
@@ -510,41 +558,32 @@ int afs_osi_Wait(afs_int32 msec, struct afs_osi_WaitHandle *handle, int intok)
        if (glockOwner) {
            AFS_GUNLOCK();
        }
-       if (rxGlockOwner) {
-           AFS_RXGUNLOCK();
-       }
        usr_thread_sleep(&tv);
        ret = 0;
        if (glockOwner) {
            AFS_GLOCK();
-       }    
-       if (rxGlockOwner) {
-           AFS_RXGLOCK();
        }
     } else {
        usr_mutex_lock(&osi_waitq_lock);
        if (glockOwner) {
            AFS_GUNLOCK();
        }
-       if (rxGlockOwner) {
-           AFS_RXGUNLOCK();
-       }
-       index = WAITHASH((caddr_t)handle);
+       index = WAITHASH((caddr_t) handle);
        if (osi_waithash_avail == NULL) {
-           waitp = (osi_wait_t *)afs_osi_Alloc(sizeof(osi_wait_t));
+           waitp = (osi_wait_t *) afs_osi_Alloc(sizeof(osi_wait_t));
            usr_cond_init(&waitp->cond);
        } else {
            waitp = osi_waithash_avail;
            osi_waithash_avail = osi_waithash_avail->next;
        }
-       waitp->addr = (caddr_t)handle;
+       waitp->addr = (caddr_t) handle;
        waitp->flag = 0;
        DLL_INSERT_TAIL(waitp, osi_waithash_table[index].head,
                        osi_waithash_table[index].tail, next, prev);
        tv.tv_sec += time(NULL);
-       waitp->expiration = tv.tv_sec + ((tv.tv_nsec == 0)?0:1);
+       waitp->expiration = tv.tv_sec + ((tv.tv_nsec == 0) ? 0 : 1);
        DLL_INSERT_TAIL(waitp, osi_timedwait_head, osi_timedwait_tail,
-                       timedNext, timedPrev);
+                       timedNext, timedPrev);
        usr_cond_wait(&waitp->cond, &osi_waitq_lock);
        if (waitp->flag) {
            ret = 2;
@@ -553,22 +592,20 @@ int afs_osi_Wait(afs_int32 msec, struct afs_osi_WaitHandle *handle, int intok)
        }
        DLL_DELETE(waitp, osi_waithash_table[index].head,
                   osi_waithash_table[index].tail, next, prev);
-       DLL_DELETE(waitp, osi_timedwait_head, osi_timedwait_tail,
-                  timedNext, timedPrev);
+       DLL_DELETE(waitp, osi_timedwait_head, osi_timedwait_tail, timedNext,
+                  timedPrev);
        waitp->next = osi_waithash_avail;
        osi_waithash_avail = waitp;
        usr_mutex_unlock(&osi_waitq_lock);
        if (glockOwner) {
            AFS_GLOCK();
        }
-       if (rxGlockOwner) {
-           AFS_RXGLOCK();
-       }
     }
     return ret;
 }
 
-void afs_osi_CancelWait(struct afs_osi_WaitHandle *handle)
+void
+afs_osi_CancelWait(struct afs_osi_WaitHandle *handle)
 {
     afs_osi_Wakeup(handle);
 }
@@ -577,7 +614,8 @@ void afs_osi_CancelWait(struct afs_osi_WaitHandle *handle)
  * Netscape NSAPI doesn't have a cond_timed_wait, so we need
  * to explicitly signal cond_timed_waits when their timers expire
  */
-int afs_osi_CheckTimedWaits(void)
+int
+afs_osi_CheckTimedWaits(void)
 {
     time_t curTime;
     osi_wait_t *waitp;
@@ -594,36 +632,33 @@ int afs_osi_CheckTimedWaits(void)
        waitp = waitp->timedNext;
     }
     usr_mutex_unlock(&osi_waitq_lock);
+    return 0;
 }
 
 /*
- * I-node numbers are indeces into a table containing a filename
- * i-node structure and a vnode structure. When we create an i-node,
- * we copy the name into the array and initialize enough of the fields
- * in the inode and vnode structures to get the client to work.
+ * 'dummy' vnode, for non-AFS files. We don't actually need most vnode
+ * information for non-AFS files, so point all of them towards this vnode
+ * to save memory.
  */
-typedef struct {
-    struct usr_inode i_node;
-    char *name;
-} osi_file_table_t;
-osi_file_table_t *osi_file_table;
-int n_osi_files = 0;
-int max_osi_files = 0;
+static struct usr_vnode dummy_vnode = {
+    0,    /* v_flag */
+    1024, /* v_count */
+    NULL, /* v_op */
+    NULL, /* v_vfsp */
+    0,    /* v_type */
+    0,    /* v_rdev */
+    NULL  /* v_data */
+};
 
 /*
  * Allocate a slot in the file table if there is not one there already,
  * copy in the file name and kludge up the vnode and inode structures
  */
-int lookupname(char *fnamep, int segflg, int followlink, 
-       struct usr_vnode **dirvpp, struct usr_vnode **compvpp)
+int
+lookupname(char *fnamep, int segflg, int followlink,
+          struct usr_vnode **compvpp)
 {
-    int i;
     int code;
-    struct usr_inode *ip;
-    struct usr_vnode *vp;
-
-    /*usr_assert(followlink == 0);*/
-    usr_assert(dirvpp == NULL);
 
     /*
      * Assume relative pathnames refer to files in AFS
@@ -635,41 +670,25 @@ int lookupname(char *fnamep, int segflg, int followlink,
        return code;
     }
 
-    usr_mutex_lock(&osi_inode_lock);
+    /* For non-afs files, nobody really looks at the meaningful values in the
+     * returned vnode, so we can return a 'fake' one. The vnode can be held,
+     * released, etc. and some callers check for a NULL vnode anyway, so we
+     * to return something. */
 
-    for (i = 0 ; i < n_osi_files ; i++) {
-       if (strcmp(fnamep, osi_file_table[i].name) == 0) {
-           *compvpp = &osi_file_table[i].i_node.i_vnode;
-           (*compvpp)->v_count++;
-           usr_mutex_unlock(&osi_inode_lock);
-           return 0;
-       }
-    }
+    usr_mutex_lock(&osi_dummy_lock);
+    VN_HOLD(&dummy_vnode);
+    usr_mutex_unlock(&osi_dummy_lock);
 
-    if (n_osi_files == max_osi_files) {
-       usr_mutex_unlock(&osi_inode_lock);
-       return ENOSPC;
-    }
+    *compvpp = &dummy_vnode;
 
-    osi_file_table[n_osi_files].name = afs_osi_Alloc(strlen(fnamep)+1);
-    usr_assert(osi_file_table[n_osi_files].name != NULL);
-    strcpy(osi_file_table[n_osi_files].name, fnamep);
-    ip = &osi_file_table[i].i_node;
-    vp = &ip->i_vnode;
-    vp->v_data = (caddr_t)ip;
-    ip->i_dev = -1;
-    n_osi_files++;
-    ip->i_number = n_osi_files;
-    vp->v_count = 2;
-    usr_mutex_unlock(&osi_inode_lock);
-    *compvpp = vp;
     return 0;
 }
 
 /*
  * open a file given its i-node number
  */
-void *osi_UFSOpen(afs_int32 ino)
+void *
+osi_UFSOpen(afs_dcache_id_t *ino)
 {
     int rc;
     struct osi_file *fp;
@@ -677,38 +696,36 @@ void *osi_UFSOpen(afs_int32 ino)
 
     AFS_ASSERT_GLOCK();
 
-    if (ino > n_osi_files) {
-       u.u_error = ENOENT;
-       return NULL;
-    }
-
     AFS_GUNLOCK();
     fp = (struct osi_file *)afs_osi_Alloc(sizeof(struct osi_file));
     usr_assert(fp != NULL);
-    fp->fd = open(osi_file_table[ino-1].name, O_RDWR|O_CREAT, 0);
+
+    usr_assert(ino->ufs);
+
+    fp->fd = open(ino->ufs, O_RDWR | O_CREAT, 0);
     if (fp->fd < 0) {
-       u.u_error = errno;
+       get_user_struct()->u_error = errno;
        afs_osi_Free((char *)fp, sizeof(struct osi_file));
        AFS_GLOCK();
        return NULL;
     }
     rc = fstat(fp->fd, &st);
     if (rc < 0) {
-       u.u_error = errno;
+       get_user_struct()->u_error = errno;
        afs_osi_Free((void *)fp, sizeof(struct osi_file));
        AFS_GLOCK();
        return NULL;
     }
     fp->size = st.st_size;
     fp->offset = 0;
-    fp->inum = ino;
     fp->vnode = (struct usr_vnode *)fp;
 
     AFS_GLOCK();
     return fp;
 }
 
-int osi_UFSClose(struct osi_file *fp)
+int
+osi_UFSClose(struct osi_file *fp)
 {
     int rc;
 
@@ -717,7 +734,7 @@ int osi_UFSClose(struct osi_file *fp)
     AFS_GUNLOCK();
     rc = close(fp->fd);
     if (rc < 0) {
-       u.u_error = errno;
+       get_user_struct()->u_error = errno;
        afs_osi_Free((void *)fp, sizeof(struct osi_file));
        AFS_GLOCK();
        return -1;
@@ -727,7 +744,8 @@ int osi_UFSClose(struct osi_file *fp)
     return 0;
 }
 
-int osi_UFSTruncate(struct osi_file *fp, afs_int32 len)
+int
+osi_UFSTruncate(struct osi_file *fp, afs_int32 len)
 {
     int rc;
 
@@ -736,7 +754,7 @@ int osi_UFSTruncate(struct osi_file *fp, afs_int32 len)
     AFS_GUNLOCK();
     rc = ftruncate(fp->fd, len);
     if (rc < 0) {
-       u.u_error = errno;
+       get_user_struct()->u_error = errno;
        AFS_GLOCK();
        return -1;
     }
@@ -745,10 +763,10 @@ int osi_UFSTruncate(struct osi_file *fp, afs_int32 len)
     return 0;
 }
 
-int afs_osi_Read(struct osi_file *fp, int offset, void *buf, afs_int32 len)
+int
+afs_osi_Read(struct osi_file *fp, int offset, void *buf, afs_int32 len)
 {
     int rc, ret;
-    int code;
     struct stat st;
 
     AFS_ASSERT_GLOCK();
@@ -760,21 +778,21 @@ int afs_osi_Read(struct osi_file *fp, int offset, void *buf, afs_int32 len)
        rc = lseek(fp->fd, fp->offset, SEEK_SET);
     }
     if (rc < 0) {
-       u.u_error = errno;
+       get_user_struct()->u_error = errno;
        AFS_GLOCK();
        return -1;
     }
     fp->offset = rc;
     ret = read(fp->fd, buf, len);
     if (ret < 0) {
-       u.u_error = errno;
+       get_user_struct()->u_error = errno;
        AFS_GLOCK();
        return -1;
     }
     fp->offset += ret;
     rc = fstat(fp->fd, &st);
     if (rc < 0) {
-       u.u_error = errno;
+       get_user_struct()->u_error = errno;
        AFS_GLOCK();
        return -1;
     }
@@ -783,10 +801,10 @@ int afs_osi_Read(struct osi_file *fp, int offset, void *buf, afs_int32 len)
     return ret;
 }
 
-int afs_osi_Write(struct osi_file *fp, afs_int32 offset, void *buf, afs_int32 len)
+int
+afs_osi_Write(struct osi_file *fp, afs_int32 offset, void *buf, afs_int32 len)
 {
     int rc, ret;
-    int code;
     struct stat st;
 
     AFS_ASSERT_GLOCK();
@@ -798,21 +816,21 @@ int afs_osi_Write(struct osi_file *fp, afs_int32 offset, void *buf, afs_int32 le
        rc = lseek(fp->fd, fp->offset, SEEK_SET);
     }
     if (rc < 0) {
-       u.u_error = errno;
+       get_user_struct()->u_error = errno;
        AFS_GLOCK();
        return -1;
     }
     fp->offset = rc;
     ret = write(fp->fd, buf, len);
     if (ret < 0) {
-       u.u_error = errno;
+       get_user_struct()->u_error = errno;
        AFS_GLOCK();
        return -1;
     }
     fp->offset += ret;
     rc = fstat(fp->fd, &st);
     if (rc < 0) {
-       u.u_error = errno;
+       get_user_struct()->u_error = errno;
        AFS_GLOCK();
        return -1;
     }
@@ -821,7 +839,8 @@ int afs_osi_Write(struct osi_file *fp, afs_int32 offset, void *buf, afs_int32 le
     return ret;
 }
 
-int afs_osi_Stat(struct osi_file *fp, struct osi_stat *stp)
+int
+afs_osi_Stat(struct osi_file *fp, struct osi_stat *stp)
 {
     int rc;
     struct stat st;
@@ -829,12 +848,11 @@ int afs_osi_Stat(struct osi_file *fp, struct osi_stat *stp)
     AFS_GUNLOCK();
     rc = fstat(fp->fd, &st);
     if (rc < 0) {
-       u.u_error = errno;
+       get_user_struct()->u_error = errno;
        AFS_GLOCK();
-       return -1;
+       return -1;
     }
     stp->size = st.st_size;
-    stp->blksize = st.st_blksize;
     stp->mtime = st.st_mtime;
     stp->atime = st.st_atime;
     AFS_GLOCK();
@@ -844,12 +862,9 @@ int afs_osi_Stat(struct osi_file *fp, struct osi_stat *stp)
 /*
  * VOP_RDWR routine
  */
-int afs_osi_VOP_RDWR(
-    struct usr_vnode *vnodeP,
-    struct usr_uio *uioP,
-    int rw,
-    int flags,
-    struct usr_ucred* credP)
+int
+afs_osi_VOP_RDWR(struct usr_vnode *vnodeP, struct usr_uio *uioP, int rw,
+                int flags, struct usr_ucred *credP)
 {
     int rc;
     struct osi_file *fp = (struct osi_file *)vnodeP;
@@ -862,17 +877,15 @@ int afs_osi_VOP_RDWR(
 
     if (rw == UIO_WRITE) {
        usr_assert(uioP->uio_fmode == FWRITE);
-       rc = afs_osi_Write(fp, uioP->uio_offset,
-                          uioP->uio_iov[0].iov_base,
+       rc = afs_osi_Write(fp, uioP->uio_offset, uioP->uio_iov[0].iov_base,
                           uioP->uio_iov[0].iov_len);
     } else {
        usr_assert(uioP->uio_fmode == FREAD);
-       rc = afs_osi_Read(fp, uioP->uio_offset,
-                         uioP->uio_iov[0].iov_base,
+       rc = afs_osi_Read(fp, uioP->uio_offset, uioP->uio_iov[0].iov_base,
                          uioP->uio_iov[0].iov_len);
     }
     if (rc < 0) {
-       return u.u_error;
+       return get_user_struct()->u_error;
     }
 
     uioP->uio_resid -= rc;
@@ -882,155 +895,166 @@ int afs_osi_VOP_RDWR(
     return 0;
 }
 
-/*
- * Use malloc/free routines with check patterns before and after each block
- */
-
-static char *afs_check_string1 = "UAFS";
-static char *afs_check_string2 = "AFS_OSI_";
-
-void *afs_osi_Alloc(size_t size)
+void *
+afs_osi_Alloc(size_t size)
 {
     return malloc(size);
 }
 
-void afs_osi_Free(void *ptr, size_t size)
+void
+afs_osi_Free(void *ptr, size_t size)
 {
     free(ptr);
 }
 
-void afs_osi_FreeStr(char *ptr)
+void
+afs_osi_FreeStr(char *ptr)
 {
     free(ptr);
 }
 
-void *osi_AllocLargeSpace(size_t size)
+void *
+osi_AllocLargeSpace(size_t size)
 {
     AFS_STATCNT(osi_AllocLargeSpace);
     return afs_osi_Alloc(size);
 }
 
-void osi_FreeLargeSpace(void *ptr)
+void
+osi_FreeLargeSpace(void *ptr)
 {
     AFS_STATCNT(osi_FreeLargeSpace);
     afs_osi_Free(ptr, 0);
 }
 
-void *osi_AllocSmallSpace(size_t size)
+void *
+osi_AllocSmallSpace(size_t size)
 {
     AFS_STATCNT(osi_AllocSmallSpace);
     return afs_osi_Alloc(size);
 }
 
-void osi_FreeSmallSpace(void *ptr)
+void
+osi_FreeSmallSpace(void *ptr)
 {
     AFS_STATCNT(osi_FreeSmallSpace);
     afs_osi_Free(ptr, 0);
 }
 
-void shutdown_osi(void)
+void
+shutdown_osi(void)
 {
     AFS_STATCNT(shutdown_osi);
     return;
 }
 
-void shutdown_osinet(void)
+void
+shutdown_osinet(void)
 {
     AFS_STATCNT(shutdown_osinet);
     return;
 }
 
-void shutdown_osifile(void)
+void
+shutdown_osifile(void)
 {
     AFS_STATCNT(shutdown_osifile);
     return;
 }
 
-int afs_nfsclient_init(void)
+void
+afs_nfsclient_init(void)
 {
-    return 0;
 }
 
-void shutdown_nfsclnt(void)
+void
+shutdown_nfsclnt(void)
+{
+    return;
+}
+
+void
+afs_osi_Invisible(void)
 {
     return;
 }
 
-void afs_osi_Invisible(void)
+void
+afs_osi_Visible(void)
 {
     return;
 }
 
-int osi_GetTime(struct timeval *tv)
+int
+osi_GetTime(struct timeval *tv)
 {
     gettimeofday(tv, NULL);
     return 0;
 }
 
-int osi_SetTime(struct timeval *tv)
+int
+osi_SetTime(struct timeval *tv)
 {
     return 0;
 }
 
-int osi_Active(struct vcache *avc)
+int
+osi_Active(struct vcache *avc)
 {
     AFS_STATCNT(osi_Active);
-    if (avc->opens > 0) return(1);
+    if (avc->opens > 0)
+       return (1);
     return 0;
 }
 
-int afs_osi_MapStrategy(int (*aproc)(), struct usr_buf *bp)
+int
+afs_osi_MapStrategy(int (*aproc) (struct usr_buf *), struct usr_buf *bp)
 {
     afs_int32 returnCode;
-    returnCode = (*aproc)(bp);
+    returnCode = (*aproc) (bp);
     return returnCode;
 }
 
-void osi_FlushPages(register struct vcache *avc, struct AFS_UCRED *credp)
+void
+osi_FlushPages(register struct vcache *avc, afs_ucred_t *credp)
 {
-    ObtainSharedLock(&avc->lock,555);
-    if ((hcmp((avc->m.DataVersion), (avc->mapDV)) <= 0) || 
-       ((avc->execsOrWriters > 0) && afs_DirtyPages(avc))) {
+    ObtainSharedLock(&avc->lock, 555);
+    if ((hcmp((avc->f.m.DataVersion), (avc->mapDV)) <= 0)
+       || ((avc->execsOrWriters > 0) && afs_DirtyPages(avc))) {
        ReleaseSharedLock(&avc->lock);
        return;
     }
-    UpgradeSToWLock(&avc->lock,565);
-    hset(avc->mapDV, avc->m.DataVersion);
+    UpgradeSToWLock(&avc->lock, 565);
+    hset(avc->mapDV, avc->f.m.DataVersion);
     ReleaseWriteLock(&avc->lock);
     return;
 }
 
-void osi_FlushText_really(register struct vcache *vp)
+void
+osi_FlushText_really(register struct vcache *vp)
 {
-    if (hcmp(vp->m.DataVersion, vp->flushDV) > 0) {
-       hset(vp->flushDV, vp->m.DataVersion);
+    if (hcmp(vp->f.m.DataVersion, vp->flushDV) > 0) {
+       hset(vp->flushDV, vp->f.m.DataVersion);
     }
     return;
 }
 
-int osi_SyncVM(struct vcache *avc)
+int
+osi_SyncVM(struct vcache *avc)
 {
     return 0;
 }
 
-void osi_ReleaseVM(struct vcache *avc, int len, struct usr_ucred *credp)
+void
+osi_ReleaseVM(struct vcache *avc, int len, struct usr_ucred *credp)
 {
     return;
 }
 
-void osi_Init(void)
+void
+osi_Init(void)
 {
     int i;
-    int rc;
-    usr_thread_t tid;
-
-    /*
-     * Allocate the table used to implement psuedo-inodes.
-     */
-    max_osi_files = cacheFiles + 100;
-    osi_file_table = (osi_file_table_t *)
-                    afs_osi_Alloc(max_osi_files * sizeof(osi_file_table_t));
-    usr_assert(osi_file_table != NULL);
 
 #ifndef NETSCAPE_NSAPI
     /*
@@ -1044,7 +1068,7 @@ void osi_Init(void)
     /*
      * Initialize the hash table used for sleep/wakeup
      */
-    for (i = 0 ; i < OSI_WAITHASH_SIZE ; i++) {
+    for (i = 0; i < OSI_WAITHASH_SIZE; i++) {
        DLL_INIT_LIST(osi_waithash_table[i].head, osi_waithash_table[i].tail);
     }
     DLL_INIT_LIST(osi_timedwait_head, osi_timedwait_tail);
@@ -1053,7 +1077,7 @@ void osi_Init(void)
     /*
      * Initialize the AFS file table
      */
-    for (i = 0 ; i < MAX_OSI_FILES ; i++) {
+    for (i = 0; i < MAX_OSI_FILES; i++) {
        afs_FileTable[i] = NULL;
     }
 
@@ -1062,7 +1086,7 @@ void osi_Init(void)
      */
     usr_mutex_init(&afs_global_lock);
     usr_mutex_init(&rx_global_lock);
-    usr_mutex_init(&osi_inode_lock);
+    usr_mutex_init(&osi_dummy_lock);
     usr_mutex_init(&osi_waitq_lock);
     usr_mutex_init(&osi_authenticate_lock);
 
@@ -1070,6 +1094,7 @@ void osi_Init(void)
      * Initialize the AFS OSI credentials
      */
     afs_osi_cred = *afs_global_ucredp;
+    afs_osi_credp = &afs_osi_cred;
 }
 
 /* ParseArgs is now obsolete, being handled by cmd */
@@ -1097,11 +1122,12 @@ void osi_Init(void)
   *    None.
   *------------------------------------------------------------------------*/
 
-int GetVFileNumber(char *fname)
+int
+GetVFileNumber(char *fname)
 {
-    int        computedVNumber;    /*The computed file number we return*/
-    int        filenameLen;        /*Number of chars in filename*/
-    int        currDigit;          /*Current digit being processed*/
+    int computedVNumber;       /*The computed file number we return */
+    int filenameLen;           /*Number of chars in filename */
+    int currDigit;             /*Current digit being processed */
 
     /*
      * The filename must have at least two characters, the first of which must be a ``V''
@@ -1109,11 +1135,11 @@ int GetVFileNumber(char *fname)
      */
     filenameLen = strlen(fname);
     if (filenameLen < 2)
-       return(-1);
+       return (-1);
     if (fname[0] != 'V')
-       return(-1);
+       return (-1);
     if ((filenameLen > 2) && (fname[1] == '0'))
-       return(-1);
+       return (-1);
 
     /*
      * Scan through the characters in the given filename, failing immediately if a non-digit
@@ -1121,7 +1147,7 @@ int GetVFileNumber(char *fname)
      */
     for (currDigit = 1; currDigit < filenameLen; currDigit++)
        if (isdigit(fname[currDigit]) == 0)
-           return(-1);
+           return (-1);
 
     /*
      * All relevant characters are digits.  Pull out the decimal number they represent.
@@ -1129,9 +1155,9 @@ int GetVFileNumber(char *fname)
      */
     computedVNumber = atoi(++fname);
     if (computedVNumber < cacheFiles)
-       return(computedVNumber);
+       return (computedVNumber);
     else
-       return(-1);
+       return (-1);
 }
 
 /*---------------------------------------------------------------------
@@ -1155,29 +1181,30 @@ int GetVFileNumber(char *fname)
   *    As described.
   *------------------------------------------------------------------------*/
 
-int CreateCacheFile(char *fname)
+int
+CreateCacheFile(char *fname)
 {
-    static char        rn[] = "CreateCacheFile";   /*Routine name*/
-    int        cfd;                                /*File descriptor to AFS cache file*/
-    int        closeResult;                        /*Result of close()*/
+    static char rn[] = "CreateCacheFile";      /*Routine name */
+    int cfd;                   /*File descriptor to AFS cache file */
+    int closeResult;           /*Result of close() */
 
     if (afsd_verbose)
-       printf("%s: Creating cache file '%s'\n",
-              rn, fname);
+       printf("%s: Creating cache file '%s'\n", rn, fname);
     cfd = open(fname, createAndTrunc, ownerRWmode);
-    if (cfd <= 0) {
-       printf("%s: Can't create '%s', error return is %d (%d)\n",
-              rn, fname, cfd, errno);
-       return(-1);
+    if (cfd <= 0) {
+       printf("%s: Can't create '%s', error return is %d (%d)\n", rn, fname,
+              cfd, errno);
+       return (-1);
     }
     closeResult = close(cfd);
-    if (closeResult) {
-       printf("%s: Can't close newly-created AFS cache file '%s' (code %d)\n",
-              rn, fname, errno);
-       return(-1);
+    if (closeResult) {
+       printf
+           ("%s: Can't close newly-created AFS cache file '%s' (code %d)\n",
+            rn, fname, errno);
+       return (-1);
     }
 
-    return(0);
+    return (0);
 }
 
 /*---------------------------------------------------------------------
@@ -1208,15 +1235,16 @@ int CreateCacheFile(char *fname)
   *     delete files as explained above.
   *------------------------------------------------------------------------*/
 
-int SweepAFSCache(int *vFilesFound)
+int
+SweepAFSCache(int *vFilesFound)
 {
-    static char        rn[] = "SweepAFSCache"; /*Routine name*/
-    char fullpn_FileToDelete[1024];    /*File to be deleted from cache*/
-    char *fileToDelete;                        /*Ptr to last component of above*/
-    DIR        *cdirp;                         /*Ptr to cache directory structure*/
+    static char rn[] = "SweepAFSCache";        /*Routine name */
+    char fullpn_FileToDelete[1024];    /*File to be deleted from cache */
+    char *fileToDelete;                /*Ptr to last component of above */
+    DIR *cdirp;                        /*Ptr to cache directory structure */
 #undef dirent
-    struct dirent *currp;              /*Current directory entry*/
-    int        vFileNum;                       /*Data cache file's associated number*/
+    struct dirent *currp;      /*Current directory entry */
+    int vFileNum;              /*Data cache file's associated number */
 
     if (cacheFlags & AFSCALL_INIT_MEMCACHE) {
        if (afsd_debug)
@@ -1226,19 +1254,18 @@ int SweepAFSCache(int *vFilesFound)
     }
 
     if (afsd_debug)
-       printf("%s: Opening cache directory '%s'\n",
-              rn, cacheBaseDir);
+       printf("%s: Opening cache directory '%s'\n", rn, cacheBaseDir);
 
-    if (chmod(cacheBaseDir, 0700)) {           /* force it to be 700 */
-       printf("%s: Can't 'chmod 0700' the cache dir, '%s'.\n",
-              rn, cacheBaseDir);
+    if (chmod(cacheBaseDir, 0700)) {   /* force it to be 700 */
+       printf("%s: Can't 'chmod 0700' the cache dir, '%s'.\n", rn,
+              cacheBaseDir);
        return (-1);
     }
     cdirp = opendir(cacheBaseDir);
-    if (cdirp == (DIR *)0) {
-       printf("%s: Can't open AFS cache directory, '%s'.\n",
-              rn, cacheBaseDir);
-       return(-1);
+    if (cdirp == (DIR *) 0) {
+       printf("%s: Can't open AFS cache directory, '%s'.\n", rn,
+              cacheBaseDir);
+       return (-1);
     }
 
     /*
@@ -1249,13 +1276,19 @@ int SweepAFSCache(int *vFilesFound)
     sprintf(fullpn_FileToDelete, "%s/", cacheBaseDir);
     fileToDelete = fullpn_FileToDelete + strlen(fullpn_FileToDelete);
 
-    for (currp = readdir(cdirp); currp; currp = readdir(cdirp))
-       {
+    for (currp = readdir(cdirp); currp; currp = readdir(cdirp)) {
        if (afsd_debug) {
-           printf("%s: Current directory entry:\n",
-                  rn);
-           printf("\tinode=%d, reclen=%d, name='%s'\n",
+           printf("%s: Current directory entry:\n", rn);
+#if defined(AFS_SGI62_ENV) || defined(AFS_USR_DARWIN100_ENV)
+            printf("\tinode=%" AFS_INT64_FMT ", reclen=%d, name='%s'\n",
                   currp->d_ino, currp->d_reclen, currp->d_name);
+#elif defined(AFS_USR_DFBSD_ENV)
+           printf("\tinode=%d, name='%s'\n", currp->d_ino,
+                  currp->d_name);
+#else
+           printf("\tinode=%d, reclen=%d, name='%s'\n", currp->d_ino,
+                  currp->d_reclen, currp->d_name);
+#endif
        }
 
        /*
@@ -1267,43 +1300,41 @@ int SweepAFSCache(int *vFilesFound)
             * Found a valid data cache filename.  Remember this file's name
             * and bump the number of files found.
             */
-           pathname_for_V[vFileNum] = afs_osi_Alloc(strlen(currp->d_name) +
-                                                    strlen(cacheBaseDir) + 2);
+           pathname_for_V[vFileNum] =
+               afs_osi_Alloc(strlen(currp->d_name) + strlen(cacheBaseDir) +
+                             2);
            usr_assert(pathname_for_V[vFileNum] != NULL);
-           sprintf(pathname_for_V[vFileNum], "%s/%s",
-                   cacheBaseDir, currp->d_name);
+           sprintf(pathname_for_V[vFileNum], "%s/%s", cacheBaseDir,
+                   currp->d_name);
            (*vFilesFound)++;
-       }
-       else if (strcmp(currp->d_name, DCACHEFILE) == 0) {
+       } else if (strcmp(currp->d_name, DCACHEFILE) == 0) {
            /*
             * Found the file holding the dcache entries.
             */
            missing_DCacheFile = 0;
-       }
-       else if (strcmp(currp->d_name, VOLINFOFILE) == 0) {
+       } else if (strcmp(currp->d_name, VOLINFOFILE) == 0) {
            /*
             * Found the file holding the volume info.
             */
            missing_VolInfoFile = 0;
-       }
-       else  if ((strcmp(currp->d_name,          ".") == 0) ||
-                 (strcmp(currp->d_name,         "..") == 0) ||
-                 (strcmp(currp->d_name, "lost+found") == 0)) {
+       } else if (strcmp(currp->d_name, CELLINFOFILE) == 0) {
+           missing_CellInfoFile = 0;
+       } else if ((strcmp(currp->d_name, ".") == 0)
+                  || (strcmp(currp->d_name, "..") == 0)
+                  || (strcmp(currp->d_name, "lost+found") == 0)) {
            /*
             * Don't do anything - this file is legit, and is to be left alone.
             */
-       }
-       else {
+       } else {
            /*
             * This file doesn't belong in the cache.  Nuke it.
             */
            sprintf(fileToDelete, "%s", currp->d_name);
            if (afsd_verbose)
-               printf("%s: Deleting '%s'\n",
-                      rn, fullpn_FileToDelete);
+               printf("%s: Deleting '%s'\n", rn, fullpn_FileToDelete);
            if (unlink(fullpn_FileToDelete)) {
-               printf("%s: Can't unlink '%s', errno is %d\n",
-                      rn, fullpn_FileToDelete, errno);
+               printf("%s: Can't unlink '%s', errno is %d\n", rn,
+                      fullpn_FileToDelete, errno);
            }
        }
     }
@@ -1313,19 +1344,21 @@ int SweepAFSCache(int *vFilesFound)
      */
     if (missing_DCacheFile) {
        if (afsd_verbose)
-           printf("%s: Creating '%s'\n",
-                  rn, fullpn_DCacheFile);
+           printf("%s: Creating '%s'\n", rn, fullpn_DCacheFile);
        if (CreateCacheFile(fullpn_DCacheFile))
-           printf("%s: Can't create '%s'\n",
-                  rn, fullpn_DCacheFile);
+           printf("%s: Can't create '%s'\n", rn, fullpn_DCacheFile);
     }
     if (missing_VolInfoFile) {
        if (afsd_verbose)
-           printf("%s: Creating '%s'\n",
-                  rn, fullpn_VolInfoFile);
+           printf("%s: Creating '%s'\n", rn, fullpn_VolInfoFile);
        if (CreateCacheFile(fullpn_VolInfoFile))
-           printf("%s: Can't create '%s'\n",
-                  rn, fullpn_VolInfoFile);
+           printf("%s: Can't create '%s'\n", rn, fullpn_VolInfoFile);
+    }
+    if (missing_CellInfoFile) {
+       if (afsd_verbose)
+           printf("%s: Creating '%s'\n", rn, fullpn_CellInfoFile);
+       if (CreateCacheFile(fullpn_CellInfoFile))
+           printf("%s: Can't create '%s'\n", rn, fullpn_CellInfoFile);
     }
 
     if (*vFilesFound < cacheFiles) {
@@ -1334,14 +1367,12 @@ int SweepAFSCache(int *vFilesFound)
         * list and create all missing files.
         */
        for (vFileNum = 0; vFileNum < cacheFiles; vFileNum++)
-           if (pathname_for_V[vFileNum] == (AFSD_INO_T)0) {
+           if (pathname_for_V[vFileNum] == (AFSD_INO_T) 0) {
                sprintf(vFileNumber, "%d", vFileNum);
                if (afsd_verbose)
-                   printf("%s: Creating '%s'\n",
-                          rn, fullpn_VFile);
+                   printf("%s: Creating '%s'\n", rn, fullpn_VFile);
                if (CreateCacheFile(fullpn_VFile))
-                   printf("%s: Can't create '%s'\n",
-                          rn, fullpn_VFile);
+                   printf("%s: Can't create '%s'\n", rn, fullpn_VFile);
            }
     }
 
@@ -1349,49 +1380,54 @@ int SweepAFSCache(int *vFilesFound)
      * Close the directory, return success.
      */
     if (afsd_debug)
-       printf("%s: Closing cache directory.\n",
-              rn);
+       printf("%s: Closing cache directory.\n", rn);
     closedir(cdirp);
-    return(0);
+    return (0);
 }
 
-static ConfigCell(register struct afsconf_cell *aci, char *arock, struct afsconf_dir *adir)
+static int
+ConfigCell(register struct afsconf_cell *aci, void *arock,
+          struct afsconf_dir *adir)
 {
     register int isHomeCell;
     register int i;
-    afs_int32 cellFlags;
+    afs_int32 cellFlags = 0;
     afs_int32 hosts[MAXHOSTSPERCELL];
 
     /* figure out if this is the home cell */
     isHomeCell = (strcmp(aci->name, afs_LclCellName) == 0);
-    if (isHomeCell) {
-       lookingForHomeCell = 0;
-       cellFlags = 1;      /* home cell, suid is ok */
-    }
-    else {
-       cellFlags = 2;      /* not home, suid is forbidden */
-    }
+    if (!isHomeCell)
+       cellFlags = 2;          /* not home, suid is forbidden */
 
     /* build address list */
-    for(i=0;i<MAXHOSTSPERCELL;i++)
+    for (i = 0; i < MAXHOSTSPERCELL; i++)
        memcpy(&hosts[i], &aci->hostAddr[i].sin_addr, sizeof(afs_int32));
 
-    if (aci->linkedCell) cellFlags |= 4; /* Flag that linkedCell arg exists,
-                                           for upwards compatibility */
+    if (aci->linkedCell)
+       cellFlags |= 4;         /* Flag that linkedCell arg exists,
+                                * for upwards compatibility */
 
     /* configure one cell */
-    call_syscall(AFSCALL_CALL, AFSOP_ADDCELL2,
-            (long)hosts,               /* server addresses */
-            (long)aci->name,           /* cell name */
-            (long)cellFlags,           /* is this the home cell? */
-            (long)aci->linkedCell);    /* Linked cell, if any */
+    call_syscall(AFSCALL_CALL, AFSOP_ADDCELL2, (long)hosts,    /* server addresses */
+                (long)aci->name,       /* cell name */
+                (long)cellFlags,       /* is this the home cell? */
+                (long)aci->linkedCell);        /* Linked cell, if any */
     return 0;
 }
 
+static int
+ConfigCellAlias(struct afsconf_cellalias *aca, void *arock, struct afsconf_dir *adir)
+{
+       call_syscall(AFSOP_ADDCELLALIAS, (long)aca->aliasName, 
+                    (long)aca->realName, 0, 0, 0);
+       return 0;
+}
+
 /*
  * Set the UDP port number RX uses for UDP datagrams
  */
-void uafs_SetRxPort(int port)
+void
+uafs_SetRxPort(int port)
 {
     usr_assert(usr_rx_port == 0);
     usr_rx_port = port;
@@ -1401,35 +1437,21 @@ void uafs_SetRxPort(int port)
 /*
  * Initialize the user space client.
  */
-void uafs_Init(
-    char *rn,
-    char *mountDirParam,
-    char *confDirParam,
-    char *cacheBaseDirParam,
-    int cacheBlocksParam,
-    int cacheFilesParam,
-    int cacheStatEntriesParam,
-    int dCacheSizeParam,
-    int vCacheSizeParam,
-    int chunkSizeParam,
-    int closeSynchParam,
-    int debugParam,
-    int nDaemonsParam,
-    int cacheFlagsParam,
-    char *logFile)
+void
+uafs_Init(char *rn, char *mountDirParam, char *confDirParam,
+         char *cacheBaseDirParam, int cacheBlocksParam, int cacheFilesParam,
+         int cacheStatEntriesParam, int dCacheSizeParam, int vCacheSizeParam,
+         int chunkSizeParam, int closeSynchParam, int debugParam,
+         int nDaemonsParam, int cacheFlagsParam, char *logFile)
 {
     int st;
-    struct usr_proc *procp;
-    struct usr_ucred *ucredp;
     int i;
     int rc;
-    int        currVFile;                  /* Current AFS cache file number */
-    int        lookupResult;               /* Result of GetLocalCellName() */
-    int        cacheIteration;             /* cache verification loop counter */
-    int        vFilesFound;                /* Num data cache files found in sweep */
+    int currVFile;             /* Current AFS cache file number */
+    int lookupResult;          /* Result of GetLocalCellName() */
+    int cacheIteration;                /* cache verification loop counter */
+    int vFilesFound;           /* Num data cache files found in sweep */
     FILE *logfd;
-    afs_int32 vfs1_type = -1;
-    struct afs_ioctl iob;
     char tbuffer[1024];
     char *p;
     char lastchar;
@@ -1446,19 +1468,19 @@ void uafs_Init(
      * Initialize the global ucred structure
      */
     afs_global_ucredp = (struct usr_ucred *)
-                       afs_osi_Alloc(sizeof(struct usr_ucred));
+       afs_osi_Alloc(sizeof(struct usr_ucred));
     usr_assert(afs_global_ucredp != NULL);
     afs_global_ucredp->cr_ref = 1;
-    afs_global_ucredp->cr_uid = geteuid();
-    afs_global_ucredp->cr_gid = getegid();
-    afs_global_ucredp->cr_ruid = getuid();
-    afs_global_ucredp->cr_rgid = getgid();
-    afs_global_ucredp->cr_suid = afs_global_ucredp->cr_ruid;
-    afs_global_ucredp->cr_sgid = afs_global_ucredp->cr_rgid;
+    afs_set_cr_uid(afs_global_ucredp, geteuid());
+    afs_set_cr_gid(afs_global_ucredp, getegid());
+    afs_set_cr_ruid(afs_global_ucredp, getuid());
+    afs_set_cr_rgid(afs_global_ucredp, getgid());
+    afs_global_ucredp->cr_suid = afs_cr_ruid(afs_global_ucredp);
+    afs_global_ucredp->cr_sgid = afs_cr_rgid(afs_global_ucredp);
     st = getgroups(NGROUPS, &afs_global_ucredp->cr_groups[0]);
     usr_assert(st >= 0);
     afs_global_ucredp->cr_ngroups = (unsigned long)st;
-    for (i = st ; i < NGROUPS ; i++) {
+    for (i = st; i < NGROUPS; i++) {
        afs_global_ucredp->cr_groups[i] = NOGROUP;
     }
 
@@ -1466,10 +1488,10 @@ void uafs_Init(
      * Initialize the global process structure
      */
     afs_global_procp = (struct usr_proc *)
-                      afs_osi_Alloc(sizeof(struct usr_proc));
+       afs_osi_Alloc(sizeof(struct usr_proc));
     usr_assert(afs_global_procp != NULL);
-    afs_global_procp->p_pid = getpid();
-    afs_global_procp->p_ppid = (pid_t)1;
+    afs_global_procp->p_pid = osi_getpid();
+    afs_global_procp->p_ppid = (pid_t) 1;
     afs_global_procp->p_ucred = afs_global_ucredp;
 
     /*
@@ -1484,7 +1506,7 @@ void uafs_Init(
     }
     afs_mountDir[0] = '/';
     afs_mountDirLen = 1;
-    for (lastchar = '/', p = &tbuffer[0] ; *p != '\0' ; p++) {
+    for (lastchar = '/', p = &tbuffer[0]; *p != '\0'; p++) {
        if (lastchar != '/' || *p != '/') {
            afs_mountDir[afs_mountDirLen++] = lastchar = *p;
        }
@@ -1502,13 +1524,13 @@ void uafs_Init(
     if (cacheFilesParam != 0) {
        cacheFiles = cacheFilesParam;
     } else {
-       cacheFiles = cacheBlocks/10;
+       cacheFiles = cacheBlocks / 10;
     }
     if (cacheStatEntriesParam != 0) {
        cacheStatEntries = cacheStatEntriesParam;
     }
     strcpy(cacheBaseDir, cacheBaseDirParam);
-    if (nDaemons != 0) {
+    if (nDaemonsParam != 0) {
        nDaemons = nDaemonsParam;
     } else {
        nDaemons = 3;
@@ -1519,7 +1541,7 @@ void uafs_Init(
     if (dCacheSizeParam != 0) {
        dCacheSize = dCacheSizeParam;
     } else {
-       dCacheSize = cacheFiles/2;
+       dCacheSize = cacheFiles / 2;
     }
     if (vCacheSizeParam != 0) {
        vCacheSize = vCacheSizeParam;
@@ -1530,12 +1552,12 @@ void uafs_Init(
        cacheFlags = cacheFlagsParam;
     }
     if (cacheFlags & AFSCALL_INIT_MEMCACHE) {
-        cacheFiles = dCacheSize; 
+       cacheFiles = dCacheSize;
     }
 
-    sprintf(fullpn_CacheInfo,  "%s/%s", confDir, CACHEINFOFILE);
+    sprintf(fullpn_CacheInfo, "%s/%s", confDir, CACHEINFOFILE);
     if (logFile == NULL) {
-       sprintf(fullpn_AFSLogFile,  "%s/%s", confDir, AFSLOGFILE);
+       sprintf(fullpn_AFSLogFile, "%s/%s", confDir, AFSLOGFILE);
     } else {
        strcpy(fullpn_AFSLogFile, logFile);
     }
@@ -1573,22 +1595,24 @@ void uafs_Init(
        exit(1);
     }
 
-    lookupResult = afsconf_GetLocalCell(afs_cdir, afs_LclCellName,
-                                       sizeof(afs_LclCellName));
+    lookupResult =
+       afsconf_GetLocalCell(afs_cdir, afs_LclCellName,
+                            sizeof(afs_LclCellName));
     if (lookupResult) {
-       printf("%s: Can't get my home cell name!  [Error is %d]\n",
-              rn, lookupResult);
-    }
-    else {
+       printf("%s: Can't get my home cell name!  [Error is %d]\n", rn,
+              lookupResult);
+    } else {
        if (afsd_verbose)
-           printf("%s: My home cell is '%s'\n",
-                  rn, afs_LclCellName);
+           printf("%s: My home cell is '%s'\n", rn, afs_LclCellName);
     }
 
-    if ((logfd = fopen(fullpn_AFSLogFile,"r+")) == 0) {
-       if (afsd_verbose)  printf("%s: Creating '%s'\n",  rn, fullpn_AFSLogFile);
+    if ((logfd = fopen(fullpn_AFSLogFile, "r+")) == 0) {
+       if (afsd_verbose)
+           printf("%s: Creating '%s'\n", rn, fullpn_AFSLogFile);
        if (CreateCacheFile(fullpn_AFSLogFile)) {
-           printf("%s: Can't create '%s' (You may want to use the -logfile option)\n",  rn, fullpn_AFSLogFile);
+           printf
+               ("%s: Can't create '%s' (You may want to use the -logfile option)\n",
+                rn, fullpn_AFSLogFile);
            exit(1);
        }
     } else
@@ -1605,92 +1629,65 @@ void uafs_Init(
     }
     memset(pathname_for_V, 0, (cacheFiles * sizeof(char *)));
     if (afsd_debug)
-       printf("%s: %d pathname_for_V entries at 0x%x, %d bytes\n",
-              rn, cacheFiles, pathname_for_V, (cacheFiles * sizeof(AFSD_INO_T)));
+       printf("%s: %d pathname_for_V entries at %" AFS_PTR_FMT
+              ", %lud bytes\n", rn, cacheFiles, pathname_for_V,
+              afs_printable_uint32_lu(cacheFiles * sizeof(AFSD_INO_T)));
 
     /*
      * Set up all the pathnames we'll need for later.
      */
-    sprintf(fullpn_DCacheFile,  "%s/%s", cacheBaseDir, DCACHEFILE);
+    sprintf(fullpn_DCacheFile, "%s/%s", cacheBaseDir, DCACHEFILE);
     sprintf(fullpn_VolInfoFile, "%s/%s", cacheBaseDir, VOLINFOFILE);
-    sprintf(fullpn_VFile,       "%s/V",  cacheBaseDir);
+    sprintf(fullpn_CellInfoFile, "%s/%s", cacheBaseDir, CELLINFOFILE);
+    sprintf(fullpn_VFile, "%s/V", cacheBaseDir);
     vFileNumber = fullpn_VFile + strlen(fullpn_VFile);
 
-    /*
-     * Start the RX listener.
-     */
-    if (afsd_debug)
-        printf("%s: Calling AFSOP_RXLISTENER_DAEMON\n", rn);
-    fork_syscall(AFSCALL_CALL, AFSOP_RXLISTENER_DAEMON, FALSE);
+    /* initialize AFS callback interface */
+    {
+       /* parse multihomed address files */
+       char reason[1024];
+       st = parseNetFiles((afs_uint32*)buffer,(afs_uint32*) maskbuffer, (afs_uint32*)mtubuffer, MAXIPADDRS, reason,
+                          AFSDIR_CLIENT_NETINFO_FILEPATH,
+                          AFSDIR_CLIENT_NETRESTRICT_FILEPATH);
+       if (st > 0)
+           call_syscall(AFSCALL_CALL, AFSOP_ADVISEADDR, st,
+                        (long)(&buffer[0]), (long)(&maskbuffer[0]),
+                        (long)(&mtubuffer[0]));
+       else {
+           printf("ADVISEADDR: Error in specifying interface addresses:%s\n",
+                  reason);
+           exit(1);
+       }
+    }
 
     /*
-     * Start the RX event handler.
+     * Start the RX listener.
      */
     if (afsd_debug)
-        printf("%s: Calling AFSOP_RXEVENT_DAEMON\n", rn);
-    fork_syscall(AFSCALL_CALL, AFSOP_RXEVENT_DAEMON, FALSE);
-
-    /*
-     * Set up all the kernel processes needed for AFS.
-     */
-
-    /* initialize AFS callback interface */
-    {
-      /* parse multihomed address files */
-      char reason[1024];
-      st=parseNetFiles(buffer,maskbuffer,mtubuffer,MAXIPADDRS,reason,
-                    AFSDIR_CLIENT_NETINFO_FILEPATH,
-                    AFSDIR_CLIENT_NETRESTRICT_FILEPATH);
-      if(st>0) 
-        call_syscall(AFSCALL_CALL, AFSOP_ADVISEADDR, st, (long) (&buffer[0]), 
-                    (long) (&maskbuffer[0]), (long) (&mtubuffer[0]));
-      else {
-        printf("ADVISEADDR: Error in specifying interface addresses:%s\n",reason);
-       exit(1);
-      }
-    }
+       printf("%s: Calling AFSOP_RXLISTENER_DAEMON\n", rn);
+    fork_syscall(AFSCALL_CALL, AFSOP_RXLISTENER_DAEMON, FALSE, FALSE, FALSE, 0);
 
     if (afsd_verbose)
        printf("%s: Forking rx callback listener.\n", rn);
     /* Child */
-    if (preallocs < cacheStatEntries+50)
-       preallocs = cacheStatEntries+50;
-    fork_syscall(AFSCALL_CALL, AFSOP_START_RXCALLBACK, preallocs);
-
-    if (afsd_verbose)
-       printf("%s: Forking AFS daemon.\n", rn);
-    fork_syscall(AFSCALL_CALL, AFSOP_START_AFS);
-
-    if (afsd_verbose)
-       printf("%s: Forking check server daemon.\n", rn);
-    fork_syscall(AFSCALL_CALL, AFSOP_START_CS);
-
-    if (afsd_verbose)
-       printf("%s: Forking %d background daemons.\n", rn, nDaemons);
-    for (i=0;i<nDaemons;i++) {
-       fork_syscall(AFSCALL_CALL, AFSOP_START_BKG);
-    }
+    if (preallocs < cacheStatEntries + 50)
+       preallocs = cacheStatEntries + 50;
+    fork_syscall(AFSCALL_CALL, AFSOP_START_RXCALLBACK, preallocs, 0, 0, 0);
 
     /*
-     * Tell the kernel about each cell in the configuration.
+     * Start the RX event handler.
      */
-    lookingForHomeCell = 1;
-
-    afsconf_CellApply(afs_cdir, ConfigCell, NULL);
+    if (afsd_debug)
+       printf("%s: Calling AFSOP_RXEVENT_DAEMON\n", rn);
+    fork_syscall(AFSCALL_CALL, AFSOP_RXEVENT_DAEMON, FALSE, 0, 0, 0);
 
     /*
-     * If we're still looking for the home cell after the whole cell
-     * configuration database has been parsed, there's something wrong.
+     * Set up all the kernel processes needed for AFS.
      */
-    if (lookingForHomeCell) {
-       printf("%s: Can't find home cell '%s' in cell database!\n",
-              rn, afs_LclCellName);
-    }
 
     if (afsd_verbose)
-       printf("%s: Calling AFSOP_ROOTVOLUME with '%s'\n",
-              rn, rootVolume);
-    call_syscall(AFSCALL_CALL, AFSOP_ROOTVOLUME, (long)rootVolume, 0, 0, 0);
+       printf("%s: Initializing AFS daemon.\n", rn);
+    call_syscall(AFSCALL_CALL, AFSOP_BASIC_INIT, 1, 0, 0, 0);
 
     /*
      * Tell the kernel some basic information about the workstation's cache.
@@ -1698,9 +1695,8 @@ void uafs_Init(
     if (afsd_verbose)
        printf("%s: Calling AFSOP_CACHEINIT: %d stat cache entries,"
               " %d optimum cache files, %d blocks in the cache,"
-              " flags = 0x%x, dcache entries %d\n",
-              rn, cacheStatEntries, cacheFiles, cacheBlocks, cacheFlags,
-              dCacheSize);
+              " flags = 0x%x, dcache entries %d\n", rn, cacheStatEntries,
+              cacheFiles, cacheBlocks, cacheFlags, dCacheSize);
     memset(&cparams, 0, sizeof(cparams));
     cparams.cacheScaches = cacheStatEntries;
     cparams.cacheFiles = cacheFiles;
@@ -1711,8 +1707,8 @@ void uafs_Init(
     cparams.setTimeFlag = FALSE;
     cparams.memCacheFlag = cacheFlags;
     call_syscall(AFSCALL_CALL, AFSOP_CACHEINIT, (long)&cparams, 0, 0, 0);
-    if (afsd_CloseSynch) 
-      call_syscall(AFSCALL_CALL, AFSOP_CLOSEWAIT, 0, 0, 0, 0);
+    if (afsd_CloseSynch)
+       call_syscall(AFSCALL_CALL, AFSOP_CLOSEWAIT, 0, 0, 0, 0);
 
     /*
      * Sweep the workstation AFS cache directory, remembering the inodes of
@@ -1721,11 +1717,10 @@ void uafs_Init(
      * times.
      */
     if (afsd_verbose)
-       printf("%s: Sweeping workstation's AFS cache directory.\n",
-              rn);
+       printf("%s: Sweeping workstation's AFS cache directory.\n", rn);
     cacheIteration = 0;
     /* Memory-cache based system doesn't need any of this */
-    if(!(cacheFlags & AFSCALL_INIT_MEMCACHE)) {
+    if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) {
        do {
            cacheIteration++;
            if (SweepAFSCache(&vFilesFound)) {
@@ -1734,11 +1729,12 @@ void uafs_Init(
                exit(1);
            }
            if (afsd_verbose)
-               printf("%s: %d out of %d data cache files found in sweep %d.\n",
-                      rn, vFilesFound, cacheFiles, cacheIteration);
-       } while ((vFilesFound < cacheFiles) &&
-                (cacheIteration < MAX_CACHE_LOOPS));
-    } else if(afsd_verbose)
+               printf
+                   ("%s: %d out of %d data cache files found in sweep %d.\n",
+                    rn, vFilesFound, cacheFiles, cacheIteration);
+       } while ((vFilesFound < cacheFiles)
+                && (cacheIteration < MAX_CACHE_LOOPS));
+    } else if (afsd_verbose)
        printf("%s: Using memory cache, not swept\n", rn);
 
     /*
@@ -1746,53 +1742,89 @@ void uafs_Init(
      * dcache entries.
      */
     if (afsd_debug)
-       printf("%s: Calling AFSOP_CACHEINFO: dcache file is '%s'\n",
-              rn, fullpn_DCacheFile);
+       printf("%s: Calling AFSOP_CACHEINFO: dcache file is '%s'\n", rn,
+              fullpn_DCacheFile);
     /* once again, meaningless for a memory-based cache. */
-    if(!(cacheFlags & AFSCALL_INIT_MEMCACHE))
+    if (!(cacheFlags & AFSCALL_INIT_MEMCACHE))
        call_syscall(AFSCALL_CALL, AFSOP_CACHEINFO, (long)fullpn_DCacheFile,
                     0, 0, 0);
 
+    call_syscall(AFSCALL_CALL, AFSOP_CELLINFO, (long)fullpn_CellInfoFile, 0,
+                0, 0);
 
     /*
      * Pass the kernel the name of the workstation cache file holding the
      * volume information.
      */
     if (afsd_debug)
-       printf("%s: Calling AFSOP_VOLUMEINFO: volume info file is '%s'\n",
-              rn, fullpn_VolInfoFile);
-    call_syscall(AFSCALL_CALL, AFSOP_VOLUMEINFO,(long)fullpn_VolInfoFile,
-                0, 0, 0);
+       printf("%s: Calling AFSOP_VOLUMEINFO: volume info file is '%s'\n", rn,
+              fullpn_VolInfoFile);
+    call_syscall(AFSCALL_CALL, AFSOP_VOLUMEINFO, (long)fullpn_VolInfoFile, 0,
+                0, 0);
 
     /*
      * Pass the kernel the name of the afs logging file holding the volume
      * information.
      */
     if (afsd_debug)
-       printf("%s: Calling AFSOP_AFSLOG: volume info file is '%s'\n",
-              rn, fullpn_AFSLogFile);
-    if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) /* ... nor this ... */
-       call_syscall(AFSCALL_CALL, AFSOP_AFSLOG,(long)fullpn_AFSLogFile,
-                    0, 0, 0);
+       printf("%s: Calling AFSOP_AFSLOG: volume info file is '%s'\n", rn,
+              fullpn_AFSLogFile);
+    if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) /* ... nor this ... */
+       call_syscall(AFSCALL_CALL, AFSOP_AFSLOG, (long)fullpn_AFSLogFile, 0,
+                    0, 0);
+
+    /*
+     * Tell the kernel about each cell in the configuration.
+     */
+    afsconf_CellApply(afs_cdir, ConfigCell, NULL);
+    afsconf_CellAliasApply(afs_cdir, ConfigCellAlias, NULL);
+
+    /*
+     * Set the primary cell name.
+     */
+    call_syscall(AFSCALL_CALL, AFSOP_SET_THISCELL, (long)afs_LclCellName, 0, 0, 0);
+
+    if (afsd_verbose)
+       printf("%s: Forking AFS daemon.\n", rn);
+    fork_syscall(AFSCALL_CALL, AFSOP_START_AFS, 0, 0, 0, 0);
+
+    if (afsd_verbose)
+       printf("%s: Forking check server daemon.\n", rn);
+    fork_syscall(AFSCALL_CALL, AFSOP_START_CS, 0, 0, 0, 0);
+
+    if (afsd_verbose)
+       printf("%s: Forking %d background daemons.\n", rn, nDaemons);
+    for (i = 0; i < nDaemons; i++) {
+       fork_syscall(AFSCALL_CALL, AFSOP_START_BKG, 0, 0, 0, 0);
+    }
+
+    if (afsd_verbose)
+       printf("%s: Calling AFSOP_ROOTVOLUME with '%s'\n", rn, rootVolume);
+    call_syscall(AFSCALL_CALL, AFSOP_ROOTVOLUME, (long)rootVolume, 0, 0, 0);
 
     /*
      * Give the kernel the names of the AFS files cached on the workstation's
      * disk.
      */
     if (afsd_debug)
-       printf("%s: Calling AFSOP_CACHEFILES for each of the %d files in '%s'\n",
-              rn, cacheFiles, cacheBaseDir);
-    if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) /* ... and again ... */
+       printf
+           ("%s: Calling AFSOP_CACHEFILES for each of the %d files in '%s'\n",
+            rn, cacheFiles, cacheBaseDir);
+    if (!(cacheFlags & AFSCALL_INIT_MEMCACHE)) /* ... and again ... */
        for (currVFile = 0; currVFile < cacheFiles; currVFile++) {
            call_syscall(AFSCALL_CALL, AFSOP_CACHEFILE,
                         (long)pathname_for_V[currVFile], 0, 0, 0);
-       } /*end for*/
+       }
+    /*end for */
+/*#ifndef NETSCAPE_NSAPI*/
+#if 0
+/* this breaks solaris if the kernel-mode client has never been installed,
+ * and it doesn't seem to work now anyway, so just disable it */
 
-#ifndef NETSCAPE_NSAPI
     /*
      * Copy our tokens from the kernel to the user space client
      */
-    for(i = 0 ; i < 200 ; i++) {
+    for (i = 0; i < 200; i++) {
        /*
         * Get the i'th token from the kernel
         */
@@ -1811,7 +1843,7 @@ void uafs_Init(
        rc = lpioctl(0, _VICEIOCTL(8), &iob, 0);
 #endif
        if (rc < 0) {
-           usr_assert(errno == EDOM);
+           usr_assert(errno == EDOM || errno == ENOSYS || errno == ERANGE);
            break;
        }
 
@@ -1828,8 +1860,8 @@ void uafs_Init(
      * system.  Give the kernel our go-ahead.
      */
     if (afsd_debug)
-        printf("%s: Calling AFSOP_GO\n", rn);
-     call_syscall(AFSCALL_CALL, AFSOP_GO, FALSE, 0, 0, 0);
+       printf("%s: Calling AFSOP_GO\n", rn);
+    call_syscall(AFSCALL_CALL, AFSOP_GO, FALSE, 0, 0, 0);
 
     /*
      * At this point, we have finished passing the kernel all the info 
@@ -1839,7 +1871,7 @@ void uafs_Init(
 
     if (afsd_verbose)
        printf("%s: Forking trunc-cache daemon.\n", rn);
-    fork_syscall(AFSCALL_CALL, AFSOP_START_TRUNCDAEMON);
+    fork_syscall(AFSCALL_CALL, AFSOP_START_TRUNCDAEMON, 0, 0, 0, 0);
 
     /*
      * Mount the AFS filesystem
@@ -1860,14 +1892,36 @@ void uafs_Init(
     return;
 }
 
-void uafs_Shutdown(void)
+int
+uafs_statvfs(struct statvfs *buf)
+{
+    int rc;
+
+    AFS_GLOCK();
+
+    rc = afs_statvfs(&afs_RootVfs, buf);
+
+    AFS_GUNLOCK();
+
+    if (rc) {
+       errno = rc;
+       return -1;
+    }
+
+    return 0;
+}
+
+void
+uafs_Shutdown(void)
 {
     int rc;
 
     printf("\n");
 
     AFS_GLOCK();
-    VN_RELE(afs_CurrentDir);
+    if (afs_CurrentDir) {
+       VN_RELE(afs_CurrentDir);
+    }
     rc = afs_unmount(&afs_RootVfs);
     usr_assert(rc == 0);
     AFS_GUNLOCK();
@@ -1878,16 +1932,17 @@ void uafs_Shutdown(void)
 /*
  * Donate the current thread to the RX server pool.
  */
-void uafs_RxServerProc(void)
+void
+uafs_RxServerProc(void)
 {
     osi_socket sock;
     int threadID;
     struct rx_call *newcall = NULL;
 
-    rxi_MorePackets(2); /* alloc more packets */
+    rxi_MorePackets(2);                /* alloc more packets */
     threadID = rxi_availProcs++;
 
-    while(1) {
+    while (1) {
        sock = OSI_NULLSOCKET;
        rxi_ServerProc(threadID, newcall, &sock);
        if (sock == OSI_NULLSOCKET) {
@@ -1911,10 +1966,12 @@ struct syscallThreadArgs {
 };
 
 #ifdef NETSCAPE_NSAPI
-void syscallThread(void *argp)
+void
+syscallThread(void *argp)
 #else /* NETSCAPE_NSAPI */
-void *syscallThread(void *argp)
-#endif /* NETSCAPE_NSAPI */
+void *
+syscallThread(void *argp)
+#endif                         /* NETSCAPE_NSAPI */
 {
     int i;
     struct usr_ucred *crp;
@@ -1923,32 +1980,33 @@ void *syscallThread(void *argp)
     /*
      * AFS daemons run authenticated
      */
-    u.u_viceid = getuid();
-    crp = u.u_cred;
-    crp->cr_uid = getuid();
-    crp->cr_ruid = getuid();
+    get_user_struct()->u_viceid = getuid();
+    crp = get_user_struct()->u_cred;
+    afs_set_cr_uid(crp, getuid());
+    afs_set_cr_ruid(crp, getuid());
     crp->cr_suid = getuid();
     crp->cr_groups[0] = getgid();
     crp->cr_ngroups = 1;
-    for (i = 1 ; i < NGROUPS ; i++) {
+    for (i = 1; i < NGROUPS; i++) {
        crp->cr_groups[i] = NOGROUP;
     }
 
-    call_syscall(sysArgsP->syscall, sysArgsP->afscall,
-                sysArgsP->param1, sysArgsP->param2,
-                sysArgsP->param3, sysArgsP->param4);
+    call_syscall(sysArgsP->syscall, sysArgsP->afscall, sysArgsP->param1,
+                sysArgsP->param2, sysArgsP->param3, sysArgsP->param4);
 
     afs_osi_Free(argp, -1);
+    return 0;
 }
 
-fork_syscall(syscall, afscall, param1, param2, param3, param4)
-long syscall, afscall, param1, param2, param3, param4;
+int
+fork_syscall(long syscall, long afscall, long param1, long param2,
+            long param3, long param4)
 {
     usr_thread_t tid;
     struct syscallThreadArgs *sysArgsP;
 
     sysArgsP = (struct syscallThreadArgs *)
-              afs_osi_Alloc(sizeof(struct syscallThreadArgs));
+       afs_osi_Alloc(sizeof(struct syscallThreadArgs));
     usr_assert(sysArgsP != NULL);
     sysArgsP->syscall = syscall;
     sysArgsP->afscall = afscall;
@@ -1959,10 +2017,12 @@ long syscall, afscall, param1, param2, param3, param4;
 
     usr_thread_create(&tid, syscallThread, sysArgsP);
     usr_thread_detach(tid);
+    return 0;
 }
 
-call_syscall(syscall, afscall, param1, param2, param3, param4)
-long syscall, afscall, param1, param2, param3, param4;
+int
+call_syscall(long syscall, long afscall, long param1, long param2,
+            long param3, long param4)
 {
     int code = 0;
     struct a {
@@ -1981,14 +2041,15 @@ long syscall, afscall, param1, param2, param3, param4;
     a.parm3 = param3;
     a.parm4 = param4;
 
-    u.u_error = 0;
-    u.u_ap = (char *)&a;
+    get_user_struct()->u_error = 0;
+    get_user_struct()->u_ap = (char *)&a;
 
     code = Afs_syscall();
     return code;
 }
 
-int uafs_SetTokens(char *tbuffer, int tlen)
+int
+uafs_SetTokens(char *tbuffer, int tlen)
 {
     int rc;
     struct afs_ioctl iob;
@@ -1998,6 +2059,7 @@ int uafs_SetTokens(char *tbuffer, int tlen)
     iob.in_size = tlen;
     iob.out = &outbuf[0];
     iob.out_size = sizeof(outbuf);
+
     rc = call_syscall(AFSCALL_PIOCTL, 0, _VICEIOCTL(3), (long)&iob, 0, 0);
     if (rc != 0) {
        errno = rc;
@@ -2006,7 +2068,8 @@ int uafs_SetTokens(char *tbuffer, int tlen)
     return 0;
 }
 
-int uafs_RPCStatsEnableProc(void)
+int
+uafs_RPCStatsEnableProc(void)
 {
     int rc;
     struct afs_ioctl iob;
@@ -2025,7 +2088,8 @@ int uafs_RPCStatsEnableProc(void)
     return rc;
 }
 
-int uafs_RPCStatsDisableProc(void)
+int
+uafs_RPCStatsDisableProc(void)
 {
     int rc;
     struct afs_ioctl iob;
@@ -2044,7 +2108,8 @@ int uafs_RPCStatsDisableProc(void)
     return rc;
 }
 
-int uafs_RPCStatsClearProc(void)
+int
+uafs_RPCStatsClearProc(void)
 {
     int rc;
     struct afs_ioctl iob;
@@ -2063,7 +2128,8 @@ int uafs_RPCStatsClearProc(void)
     return rc;
 }
 
-int uafs_RPCStatsEnablePeer(void)
+int
+uafs_RPCStatsEnablePeer(void)
 {
     int rc;
     struct afs_ioctl iob;
@@ -2082,7 +2148,8 @@ int uafs_RPCStatsEnablePeer(void)
     return rc;
 }
 
-int uafs_RPCStatsDisablePeer(void)
+int
+uafs_RPCStatsDisablePeer(void)
 {
     int rc;
     struct afs_ioctl iob;
@@ -2101,7 +2168,8 @@ int uafs_RPCStatsDisablePeer(void)
     return rc;
 }
 
-int uafs_RPCStatsClearPeer(void)
+int
+uafs_RPCStatsClearPeer(void)
 {
     int rc;
     struct afs_ioctl iob;
@@ -2127,21 +2195,19 @@ int uafs_RPCStatsClearPeer(void)
  *
  * Note: Caller must hold the AFS global lock.
  */
-int uafs_LookupName(
-    char *path,
-    struct usr_vnode *parentVp,
-    struct usr_vnode **vpp,
-    int follow,
-    int no_eval_mtpt)
+int
+uafs_LookupName(char *path, struct usr_vnode *parentVp,
+               struct usr_vnode **vpp, int follow, int no_eval_mtpt)
 {
-    int code;
+    int code = 0;
     int linkCount;
     struct usr_vnode *vp;
     struct usr_vnode *nextVp;
     struct usr_vnode *linkVp;
+    struct vcache *nextVc;
     char *tmpPath;
     char *pathP;
-    char *nextPathP;
+    char *nextPathP = NULL;
 
     AFS_ASSERT_GLOCK();
 
@@ -2161,7 +2227,7 @@ int uafs_LookupName(
     /*
      * Loop through the path looking for the new directory
      */
-    tmpPath = afs_osi_Alloc(strlen(path)+1);
+    tmpPath = afs_osi_Alloc(strlen(path) + 1);
     usr_assert(tmpPath != NULL);
     strcpy(tmpPath, path);
     VN_HOLD(vp);
@@ -2172,7 +2238,7 @@ int uafs_LookupName(
        /*
         * terminate the current component and skip over slashes
         */
-       nextPathP = strchr(pathP, '/');
+       nextPathP = afs_strchr(pathP, '/');
        if (nextPathP != NULL) {
            while (*nextPathP == '/') {
                *(nextPathP++) = '\0';
@@ -2184,7 +2250,7 @@ int uafs_LookupName(
         */
        if (vp->v_type != VDIR) {
            VN_RELE(vp);
-           afs_osi_Free(tmpPath, strlen(path)+1);
+           afs_osi_Free(tmpPath, strlen(path) + 1);
            return ENOTDIR;
        }
 
@@ -2197,10 +2263,10 @@ int uafs_LookupName(
            /*
             * We need execute permission to search a directory
             */
-           code = afs_access(vp, VEXEC, u.u_cred);
+           code = afs_access(VTOAFS(vp), VEXEC, get_user_struct()->u_cred);
            if (code != 0) {
                VN_RELE(vp);
-               afs_osi_Free(tmpPath, strlen(path)+1);
+               afs_osi_Free(tmpPath, strlen(path) + 1);
                return code;
            }
 
@@ -2208,18 +2274,23 @@ int uafs_LookupName(
             * lookup the next component in the path, we can release the
             * subdirectory since we hold the global lock
             */
+           nextVc = NULL;
            nextVp = NULL;
 #ifdef AFS_WEB_ENHANCEMENTS
-            if ((nextPathP != NULL && *nextPathP != '\0') || !no_eval_mtpt)
-              code = afs_lookup(vp, pathP, &nextVp, u.u_cred, 0);
-            else
-              code = afs_lookup(vp, pathP, &nextVp, u.u_cred, AFS_LOOKUP_NOEVAL);
+           if ((nextPathP != NULL && *nextPathP != '\0') || !no_eval_mtpt)
+               code = afs_lookup(VTOAFS(vp), pathP, &nextVc, get_user_struct()->u_cred, 0);
+           else
+               code =
+                   afs_lookup(VTOAFS(vp), pathP, &nextVc, get_user_struct()->u_cred,
+                              AFS_LOOKUP_NOEVAL);
 #else
-            code = afs_lookup(vp, pathP, &nextVp, u.u_cred, 0);
+           code = afs_lookup(VTOAFS(vp), pathP, &nextVc, get_user_struct()->u_cred, 0);
 #endif /* AFS_WEB_ENHANCEMENTS */
+           if (nextVc)
+               nextVp=AFSTOV(nextVc);
            if (code != 0) {
                VN_RELE(vp);
-               afs_osi_Free(tmpPath, strlen(path)+1);
+               afs_osi_Free(tmpPath, strlen(path) + 1);
                return code;
            }
        }
@@ -2230,18 +2301,18 @@ int uafs_LookupName(
         */
        if ((nextPathP != NULL && *nextPathP != '\0') || follow) {
            linkCount = 0;
-           while(nextVp->v_type == VLNK) {
+           while (nextVp->v_type == VLNK) {
                if (++linkCount > MAX_OSI_LINKS) {
                    VN_RELE(vp);
                    VN_RELE(nextVp);
-                   afs_osi_Free(tmpPath, strlen(path)+1);
+                   afs_osi_Free(tmpPath, strlen(path) + 1);
                    return code;
                }
                code = uafs_LookupLink(nextVp, vp, &linkVp);
                if (code) {
                    VN_RELE(vp);
                    VN_RELE(nextVp);
-                   afs_osi_Free(tmpPath, strlen(path)+1);
+                   afs_osi_Free(tmpPath, strlen(path) + 1);
                    return code;
                }
                VN_RELE(nextVp);
@@ -2259,11 +2330,11 @@ int uafs_LookupName(
      */
     if (nextPathP != NULL && vp->v_type != VDIR) {
        VN_RELE(vp);
-       afs_osi_Free(tmpPath, strlen(path)+1);
+       afs_osi_Free(tmpPath, strlen(path) + 1);
        return ENOTDIR;
     }
 
-    afs_osi_Free(tmpPath, strlen(path)+1);
+    afs_osi_Free(tmpPath, strlen(path) + 1);
     *vpp = vp;
     return 0;
 }
@@ -2275,10 +2346,9 @@ int uafs_LookupName(
  *
  * Note: Caller must hold the AFS global lock.
  */
-int uafs_LookupLink(
-    struct usr_vnode *vp,
-    struct usr_vnode *parentVp,
-    struct usr_vnode **vpp)
+int
+uafs_LookupLink(struct usr_vnode *vp, struct usr_vnode *parentVp,
+               struct usr_vnode **vpp)
 {
     int code;
     int len;
@@ -2289,27 +2359,27 @@ int uafs_LookupLink(
 
     AFS_ASSERT_GLOCK();
 
-    pathP = afs_osi_Alloc(MAX_OSI_PATH+1);
+    pathP = afs_osi_Alloc(MAX_OSI_PATH + 1);
     usr_assert(pathP != NULL);
 
     /*
      * set up the uio buffer
      */
     iov[0].iov_base = pathP;
-    iov[0].iov_len = MAX_OSI_PATH+1;
+    iov[0].iov_len = MAX_OSI_PATH + 1;
     uio.uio_iov = &iov[0];
     uio.uio_iovcnt = 1;
     uio.uio_offset = 0;
     uio.uio_segflg = 0;
     uio.uio_fmode = FREAD;
-    uio.uio_resid = MAX_OSI_PATH+1;
+    uio.uio_resid = MAX_OSI_PATH + 1;
 
     /*
      * Read the link data
      */
-    code = afs_readlink(vp, &uio, u.u_cred);
+    code = afs_readlink(VTOAFS(vp), &uio, get_user_struct()->u_cred);
     if (code) {
-       afs_osi_Free(pathP, MAX_OSI_PATH+1);
+       afs_osi_Free(pathP, MAX_OSI_PATH + 1);
        return code;
     }
     len = MAX_OSI_PATH + 1 - uio.uio_resid;
@@ -2320,11 +2390,11 @@ int uafs_LookupLink(
      */
     code = uafs_LookupName(pathP, parentVp, &linkVp, 1, 0);
     if (code) {
-       afs_osi_Free(pathP, MAX_OSI_PATH+1);
+       afs_osi_Free(pathP, MAX_OSI_PATH + 1);
        return code;
     }
 
-    afs_osi_Free(pathP, MAX_OSI_PATH+1);
+    afs_osi_Free(pathP, MAX_OSI_PATH + 1);
     *vpp = linkVp;
     return 0;
 }
@@ -2336,9 +2406,8 @@ int uafs_LookupLink(
  *
  * Note: Caller must hold the AFS global lock.
  */
-int uafs_LookupParent(
-    char *path,
-    struct usr_vnode **vpp)
+int
+uafs_LookupParent(char *path, struct usr_vnode **vpp)
 {
     int len;
     int code;
@@ -2361,13 +2430,13 @@ int uafs_LookupParent(
      * Find the length of the parent path
      */
     len = strlen(path);
-    while(len > 0 && path[len-1] == '/') {
+    while (len > 0 && path[len - 1] == '/') {
        len--;
     }
     if (len == 0) {
        return EINVAL;
     }
-    while(len > 0 && path[len-1] != '/') {
+    while (len > 0 && path[len - 1] != '/') {
        len--;
     }
     if (len == 0) {
@@ -2376,8 +2445,8 @@ int uafs_LookupParent(
 
     pathP = afs_osi_Alloc(len);
     usr_assert(pathP != NULL);
-    memcpy(pathP, path, len-1);
-    pathP[len-1] = '\0';
+    memcpy(pathP, path, len - 1);
+    pathP[len - 1] = '\0';
 
     /*
      * look up the parent
@@ -2400,15 +2469,16 @@ int uafs_LookupParent(
  * Return a pointer to the first character in the last component
  * of a pathname
  */
-char *uafs_LastPath(char *path)
+char *
+uafs_LastPath(char *path)
 {
     int len;
 
     len = strlen(path);
-    while (len > 0 && path[len-1] == '/') {
+    while (len > 0 && path[len - 1] == '/') {
        len--;
     }
-    while (len > 0 && path[len-1] != '/') {
+    while (len > 0 && path[len - 1] != '/') {
        len--;
     }
     if (len == 0) {
@@ -2420,7 +2490,8 @@ char *uafs_LastPath(char *path)
 /*
  * Set the working directory.
  */
-int uafs_chdir(char *path)
+int
+uafs_chdir(char *path)
 {
     int retval;
     AFS_GLOCK();
@@ -2429,7 +2500,8 @@ int uafs_chdir(char *path)
     return retval;
 }
 
-int uafs_chdir_r(char *path)
+int
+uafs_chdir_r(char *path)
 {
     int code;
     struct vnode *dirP;
@@ -2452,7 +2524,8 @@ int uafs_chdir_r(char *path)
 /*
  * Create a directory.
  */
-int uafs_mkdir(char *path, int mode)
+int
+uafs_mkdir(char *path, int mode)
 {
     int retval;
     AFS_GLOCK();
@@ -2461,12 +2534,13 @@ int uafs_mkdir(char *path, int mode)
     return retval;
 }
 
-int uafs_mkdir_r(char *path, int mode)
+int
+uafs_mkdir_r(char *path, int mode)
 {
     int code;
     char *nameP;
     struct vnode *parentP;
-    struct vnode *dirP;
+    struct vcache *dirP;
     struct usr_vattr attrs;
 
     if (uafs_IsRoot(path)) {
@@ -2504,25 +2578,26 @@ int uafs_mkdir_r(char *path, int mode)
     usr_vattr_null(&attrs);
     attrs.va_type = VREG;
     attrs.va_mode = mode;
-    attrs.va_uid = u.u_cred->cr_uid;
-    attrs.va_gid = u.u_cred->cr_gid;
+    attrs.va_uid = afs_cr_uid(get_user_struct()->u_cred);
+    attrs.va_gid = afs_cr_gid(get_user_struct()->u_cred);
     dirP = NULL;
-    code = afs_mkdir(parentP, nameP, &attrs, &dirP, u.u_cred);
+    code = afs_mkdir(VTOAFS(parentP), nameP, &attrs, &dirP, get_user_struct()->u_cred);
     VN_RELE(parentP);
     if (code != 0) {
        errno = code;
        return -1;
     }
-    VN_RELE(dirP);
+    VN_RELE(AFSTOV(dirP));
     return 0;
 }
 
 /*
  * Return 1 if path is the AFS root, otherwise return 0
  */
-int uafs_IsRoot(char *path)
+int
+uafs_IsRoot(char *path)
 {
-    while(*path == '/' && *(path+1) == '/') {
+    while (*path == '/' && *(path + 1) == '/') {
        path++;
     }
     if (strncmp(path, afs_mountDir, afs_mountDirLen) != 0) {
@@ -2542,7 +2617,8 @@ int uafs_IsRoot(char *path)
  * Open a file
  * Note: file name may not end in a slash.
  */
-int uafs_open(char *path, int flags, int mode)
+int
+uafs_open(char *path, int flags, int mode)
 {
     int retval;
     AFS_GLOCK();
@@ -2551,7 +2627,8 @@ int uafs_open(char *path, int flags, int mode)
     return retval;
 }
 
-int uafs_open_r(char *path, int flags, int mode)
+int
+uafs_open_r(char *path, int flags, int mode)
 {
     int fd;
     int code;
@@ -2562,6 +2639,8 @@ int uafs_open_r(char *path, int flags, int mode)
     struct usr_vattr attrs;
     char *nameP;
 
+    struct vcache* vc;
+
     if (uafs_IsRoot(path)) {
        fileP = afs_RootVnode;
        VN_HOLD(fileP);
@@ -2598,20 +2677,23 @@ int uafs_open_r(char *path, int flags, int mode)
            usr_vattr_null(&attrs);
            attrs.va_type = VREG;
            attrs.va_mode = mode;
-           attrs.va_uid = u.u_cred->cr_uid;
-           attrs.va_gid = u.u_cred->cr_gid;
+           attrs.va_uid = afs_cr_uid(get_user_struct()->u_cred);
+           attrs.va_gid = afs_cr_gid(get_user_struct()->u_cred);
            if (flags & O_TRUNC) {
                attrs.va_size = 0;
            }
            fileP = NULL;
-           code = afs_create(dirP, nameP, &attrs,
-                             (flags & O_EXCL)?usr_EXCL:usr_NONEXCL,
-                             mode, &fileP, u.u_cred);
+           vc=VTOAFS(fileP);
+           code =
+               afs_create(VTOAFS(dirP), nameP, &attrs,
+                          (flags & O_EXCL) ? usr_EXCL : usr_NONEXCL, mode,
+                          &vc, get_user_struct()->u_cred);
            VN_RELE(dirP);
            if (code != 0) {
-               errno = code;
-               return -1;
+               errno = code;
+               return -1;
            }
+           fileP = AFSTOV(vc);
        } else {
            fileP = NULL;
            code = uafs_LookupName(nameP, dirP, &fileP, 1, 0);
@@ -2625,14 +2707,15 @@ int uafs_open_r(char *path, int flags, int mode)
             * Check whether we have access to this file
             */
            fileMode = 0;
-           if (flags & (O_RDONLY|O_RDWR)) {
+           if (flags & (O_RDONLY | O_RDWR)) {
                fileMode |= VREAD;
            }
-           if (flags & (O_WRONLY|O_RDWR)) {
+           if (flags & (O_WRONLY | O_RDWR)) {
                fileMode |= VWRITE;
            }
-           if (!fileMode) fileMode = VREAD;  /* since O_RDONLY is 0 */
-           code = afs_access(fileP, fileMode, u.u_cred);
+           if (!fileMode)
+               fileMode = VREAD;       /* since O_RDONLY is 0 */
+           code = afs_access(VTOAFS(fileP), fileMode, get_user_struct()->u_cred);
            if (code != 0) {
                VN_RELE(fileP);
                errno = code;
@@ -2642,7 +2725,7 @@ int uafs_open_r(char *path, int flags, int mode)
            /*
             * Get the file attributes, all we need is the size
             */
-           code = afs_getattr(fileP, &attrs, u.u_cred);
+           code = afs_getattr(VTOAFS(fileP), &attrs, get_user_struct()->u_cred);
            if (code != 0) {
                VN_RELE(fileP);
                errno = code;
@@ -2667,20 +2750,25 @@ int uafs_open_r(char *path, int flags, int mode)
     if (flags & O_SYNC) {
        openFlags |= FSYNC;
     }
-    if (flags & (O_RDONLY|O_RDWR)) {
+    if (flags & (O_RDONLY | O_RDWR)) {
        openFlags |= FREAD;
     }
-    if (flags & (O_WRONLY|O_RDWR)) {
+    if (flags & (O_WRONLY | O_RDWR)) {
        openFlags |= FWRITE;
     }
+    if ((openFlags & (FREAD | FWRITE)) == 0) {
+       /* O_RDONLY is 0, so ... */
+       openFlags |= FREAD;
+    }
 
     /*
      * Truncate if necessary
      */
     if ((flags & O_TRUNC) && (attrs.va_size != 0)) {
        usr_vattr_null(&attrs);
+       attrs.va_mask = ATTR_SIZE;
        attrs.va_size = 0;
-       code = afs_setattr(fileP, &attrs, u.u_cred);
+       code = afs_setattr(VTOAFS(fileP), &attrs, get_user_struct()->u_cred);
        if (code != 0) {
            VN_RELE(fileP);
            errno = code;
@@ -2688,10 +2776,11 @@ int uafs_open_r(char *path, int flags, int mode)
        }
     }
 
+    vc=VTOAFS(fileP);  
     /*
      * do the open
      */
-    code = afs_open(&fileP, openFlags, u.u_cred);
+    code = afs_open(&vc, openFlags, get_user_struct()->u_cred);
     if (code != 0) {
        VN_RELE(fileP);
        errno = code;
@@ -2701,7 +2790,7 @@ int uafs_open_r(char *path, int flags, int mode)
     /*
      * Put the vnode pointer into the file table
      */
-    for (fd = 0 ; fd < MAX_OSI_FILES ; fd++) {
+    for (fd = 0; fd < MAX_OSI_FILES; fd++) {
        if (afs_FileTable[fd] == NULL) {
            afs_FileTable[fd] = fileP;
            afs_FileFlags[fd] = openFlags;
@@ -2725,33 +2814,47 @@ int uafs_open_r(char *path, int flags, int mode)
 /*
  * Create a file
  */
-int uafs_creat(char *path, int mode)
+int
+uafs_creat(char *path, int mode)
 {
     int rc;
-    rc = uafs_open(path, O_CREAT|O_WRONLY|O_TRUNC, mode);
+    rc = uafs_open(path, O_CREAT | O_WRONLY | O_TRUNC, mode);
     return rc;
 }
 
-int uafs_creat_r(char *path, int mode)
+int
+uafs_creat_r(char *path, int mode)
 {
     int rc;
-    rc = uafs_open_r(path, O_CREAT|O_WRONLY|O_TRUNC, mode);
+    rc = uafs_open_r(path, O_CREAT | O_WRONLY | O_TRUNC, mode);
     return rc;
 }
 
 /*
  * Write to a file
  */
-int uafs_write(int fd, char *buf, int len)
+int
+uafs_write(int fd, char *buf, int len)
 {
     int retval;
     AFS_GLOCK();
-    retval = uafs_write_r(fd, buf, len);
+    retval = uafs_pwrite_r(fd, buf, len, afs_FileOffsets[fd]);
     AFS_GUNLOCK();
     return retval;
 }
 
-int uafs_write_r(int fd, char *buf, int len)
+int
+uafs_pwrite(int fd, char *buf, int len, off_t offset)
+{
+    int retval;
+    AFS_GLOCK();
+    retval = uafs_pwrite_r(fd, buf, len, offset);
+    AFS_GUNLOCK();
+    return retval;
+}
+
+int
+uafs_pwrite_r(int fd, char *buf, int len, off_t offset)
 {
     int code;
     struct usr_uio uio;
@@ -2774,7 +2877,7 @@ int uafs_write_r(int fd, char *buf, int len)
     iov[0].iov_len = len;
     uio.uio_iov = &iov[0];
     uio.uio_iovcnt = 1;
-    uio.uio_offset = afs_FileOffsets[fd];
+    uio.uio_offset = offset;
     uio.uio_segflg = 0;
     uio.uio_fmode = FWRITE;
     uio.uio_resid = len;
@@ -2783,29 +2886,41 @@ int uafs_write_r(int fd, char *buf, int len)
      * do the write
      */
 
-    code = afs_write(fileP, &uio, afs_FileFlags[fd], u.u_cred, 0);
+    code = afs_write(VTOAFS(fileP), &uio, afs_FileFlags[fd], get_user_struct()->u_cred, 0);
     if (code) {
        errno = code;
        return -1;
     }
 
     afs_FileOffsets[fd] = uio.uio_offset;
-    return(len - uio.uio_resid);
+    return (len - uio.uio_resid);
 }
 
 /*
  * Read from a file
  */
-int uafs_read(int fd, char *buf, int len)
+int
+uafs_read(int fd, char *buf, int len)
+{
+    int retval;
+    AFS_GLOCK();
+    retval = uafs_pread_r(fd, buf, len, afs_FileOffsets[fd]);
+    AFS_GUNLOCK();
+    return retval;
+}
+
+int
+uafs_pread(int fd, char *buf, int len, off_t offset)
 {
     int retval;
     AFS_GLOCK();
-    retval = uafs_read_r(fd, buf, len);
+    retval = uafs_pread_r(fd, buf, len, offset);
     AFS_GUNLOCK();
     return retval;
 }
 
-int uafs_read_r(int fd, char *buf, int len)
+int
+uafs_pread_r(int fd, char *buf, int len, off_t offset)
 {
     int code;
     struct usr_uio uio;
@@ -2829,7 +2944,7 @@ int uafs_read_r(int fd, char *buf, int len)
     iov[0].iov_len = len;
     uio.uio_iov = &iov[0];
     uio.uio_iovcnt = 1;
-    uio.uio_offset = afs_FileOffsets[fd];
+    uio.uio_offset = offset;
     uio.uio_segflg = 0;
     uio.uio_fmode = FREAD;
     uio.uio_resid = len;
@@ -2837,14 +2952,14 @@ int uafs_read_r(int fd, char *buf, int len)
     /*
      * do the read
      */
-    code = afs_read(fileP, &uio, u.u_cred, 0, &bufP, 0);
+    code = afs_read(VTOAFS(fileP), &uio, get_user_struct()->u_cred, 0, &bufP, 0);
     if (code) {
        errno = code;
        return -1;
     }
 
     afs_FileOffsets[fd] = uio.uio_offset;
-    return(len - uio.uio_resid);
+    return (len - uio.uio_resid);
 }
 
 /*
@@ -2852,7 +2967,8 @@ int uafs_read_r(int fd, char *buf, int len)
  *
  * NOTE: Caller must hold the global AFS lock.
  */
-int uafs_GetAttr(struct usr_vnode *vp, struct stat *stats)
+int
+uafs_GetAttr(struct usr_vnode *vp, struct stat *stats)
 {
     int code;
     struct usr_vattr attrs;
@@ -2862,7 +2978,7 @@ int uafs_GetAttr(struct usr_vnode *vp, struct stat *stats)
     /*
      * Get the attributes
      */
-    code = afs_getattr(vp, &attrs, u.u_cred);
+    code = afs_getattr(VTOAFS(vp), &attrs, get_user_struct()->u_cred);
     if (code != 0) {
        return code;
     }
@@ -2891,9 +3007,8 @@ int uafs_GetAttr(struct usr_vnode *vp, struct stat *stats)
 /*
  * Get the attributes of a file, do follow links
  */
-int uafs_stat(
-    char *path,
-    struct stat *buf)
+int
+uafs_stat(char *path, struct stat *buf)
 {
     int retval;
     AFS_GLOCK();
@@ -2902,9 +3017,8 @@ int uafs_stat(
     return retval;
 }
 
-int uafs_stat_r(
-    char *path,
-    struct stat *buf)
+int
+uafs_stat_r(char *path, struct stat *buf)
 {
     int code;
     struct vnode *vp;
@@ -2926,9 +3040,8 @@ int uafs_stat_r(
 /*
  * Get the attributes of a file, don't follow links
  */
-int uafs_lstat(
-    char *path,
-    struct stat *buf)
+int
+uafs_lstat(char *path, struct stat *buf)
 {
     int retval;
     AFS_GLOCK();
@@ -2937,9 +3050,8 @@ int uafs_lstat(
     return retval;
 }
 
-int uafs_lstat_r(
-    char *path,
-    struct stat *buf)
+int
+uafs_lstat_r(char *path, struct stat *buf)
 {
     int code;
     struct vnode *vp;
@@ -2961,9 +3073,8 @@ int uafs_lstat_r(
 /*
  * Get the attributes of an open file
  */
-int uafs_fstat(
-    int fd,
-    struct stat *buf)
+int
+uafs_fstat(int fd, struct stat *buf)
 {
     int retval;
     AFS_GLOCK();
@@ -2972,9 +3083,8 @@ int uafs_fstat(
     return retval;
 }
 
-int uafs_fstat_r(
-    int fd,
-    struct stat *buf)
+int
+uafs_fstat_r(int fd, struct stat *buf)
 {
     int code;
     struct vnode *vp;
@@ -2985,7 +3095,6 @@ int uafs_fstat_r(
        return -1;
     }
     code = uafs_GetAttr(vp, buf);
-    VN_RELE(vp);
     if (code) {
        errno = code;
        return -1;
@@ -2996,9 +3105,8 @@ int uafs_fstat_r(
 /*
  * change the permissions on a file
  */
-int uafs_chmod(
-    char *path,
-    int mode)
+int
+uafs_chmod(char *path, int mode)
 {
     int retval;
     AFS_GLOCK();
@@ -3007,9 +3115,8 @@ int uafs_chmod(
     return retval;
 }
 
-int uafs_chmod_r(
-    char *path,
-    int mode)
+int
+uafs_chmod_r(char *path, int mode)
 {
     int code;
     struct vnode *vp;
@@ -3021,8 +3128,9 @@ int uafs_chmod_r(
        return -1;
     }
     usr_vattr_null(&attrs);
+    attrs.va_mask = ATTR_MODE;
     attrs.va_mode = mode;
-    code = afs_setattr(vp, &attrs, u.u_cred);
+    code = afs_setattr(VTOAFS(vp), &attrs, get_user_struct()->u_cred);
     VN_RELE(vp);
     if (code != 0) {
        errno = code;
@@ -3034,9 +3142,8 @@ int uafs_chmod_r(
 /*
  * change the permissions on an open file
  */
-int uafs_fchmod(
-    int fd,
-    int mode)
+int
+uafs_fchmod(int fd, int mode)
 {
     int retval;
     AFS_GLOCK();
@@ -3045,9 +3152,8 @@ int uafs_fchmod(
     return retval;
 }
 
-int uafs_fchmod_r(
-    int fd,
-    int mode)
+int
+uafs_fchmod_r(int fd, int mode)
 {
     int code;
     struct vnode *vp;
@@ -3059,8 +3165,9 @@ int uafs_fchmod_r(
        return -1;
     }
     usr_vattr_null(&attrs);
+    attrs.va_mask = ATTR_MODE;
     attrs.va_mode = mode;
-    code = afs_setattr(vp, &attrs, u.u_cred);
+    code = afs_setattr(VTOAFS(vp), &attrs, get_user_struct()->u_cred);
     if (code != 0) {
        errno = code;
        return -1;
@@ -3071,9 +3178,8 @@ int uafs_fchmod_r(
 /*
  * truncate a file
  */
-int uafs_truncate(
-    char *path,
-    int length)
+int
+uafs_truncate(char *path, int length)
 {
     int retval;
     AFS_GLOCK();
@@ -3082,9 +3188,8 @@ int uafs_truncate(
     return retval;
 }
 
-int uafs_truncate_r(
-    char *path,
-    int length)
+int
+uafs_truncate_r(char *path, int length)
 {
     int code;
     struct vnode *vp;
@@ -3096,8 +3201,9 @@ int uafs_truncate_r(
        return -1;
     }
     usr_vattr_null(&attrs);
+    attrs.va_mask = ATTR_SIZE;
     attrs.va_size = length;
-    code = afs_setattr(vp, &attrs, u.u_cred);
+    code = afs_setattr(VTOAFS(vp), &attrs, get_user_struct()->u_cred);
     VN_RELE(vp);
     if (code != 0) {
        errno = code;
@@ -3109,9 +3215,8 @@ int uafs_truncate_r(
 /*
  * truncate an open file
  */
-int uafs_ftruncate(
-    int fd,
-    int length)
+int
+uafs_ftruncate(int fd, int length)
 {
     int retval;
     AFS_GLOCK();
@@ -3120,9 +3225,8 @@ int uafs_ftruncate(
     return retval;
 }
 
-int uafs_ftruncate_r(
-    int fd,
-    int length)
+int
+uafs_ftruncate_r(int fd, int length)
 {
     int code;
     struct vnode *vp;
@@ -3134,8 +3238,9 @@ int uafs_ftruncate_r(
        return -1;
     }
     usr_vattr_null(&attrs);
+    attrs.va_mask = ATTR_SIZE;
     attrs.va_size = length;
-    code = afs_setattr(vp, &attrs, u.u_cred);
+    code = afs_setattr(VTOAFS(vp), &attrs, get_user_struct()->u_cred);
     if (code != 0) {
        errno = code;
        return -1;
@@ -3146,10 +3251,8 @@ int uafs_ftruncate_r(
 /*
  * set the read/write file pointer of an open file
  */
-int uafs_lseek(
-    int fd,
-    int offset,
-    int whence)
+int
+uafs_lseek(int fd, int offset, int whence)
 {
     int retval;
     AFS_GLOCK();
@@ -3158,10 +3261,8 @@ int uafs_lseek(
     return retval;
 }
 
-int uafs_lseek_r(
-    int fd,
-    int offset,
-    int whence)
+int
+uafs_lseek_r(int fd, int offset, int whence)
 {
     int code;
     int newpos;
@@ -3174,21 +3275,21 @@ int uafs_lseek_r(
        return -1;
     }
     switch (whence) {
-      case SEEK_CUR:
+    case SEEK_CUR:
        newpos = afs_FileOffsets[fd] + offset;
        break;
-      case SEEK_SET:
+    case SEEK_SET:
        newpos = offset;
        break;
-      case SEEK_END:
-       code = afs_getattr(vp, &attrs, u.u_cred);
+    case SEEK_END:
+       code = afs_getattr(VTOAFS(vp), &attrs, get_user_struct()->u_cred);
        if (code != 0) {
            errno = code;
            return -1;
        }
        newpos = attrs.va_size + offset;
        break;
-      default:
+    default:
        errno = EINVAL;
        return -1;
     }
@@ -3203,8 +3304,8 @@ int uafs_lseek_r(
 /*
  * sync a file
  */
-int uafs_fsync(
-    int fd)
+int
+uafs_fsync(int fd)
 {
     int retval;
     AFS_GLOCK();
@@ -3213,8 +3314,8 @@ int uafs_fsync(
     return retval;
 }
 
-int uafs_fsync_r(
-    int fd)
+int
+uafs_fsync_r(int fd)
 {
     int code;
     struct usr_vnode *fileP;
@@ -3226,20 +3327,20 @@ int uafs_fsync_r(
        return -1;
     }
 
-    code = afs_fsync(fileP, u.u_cred);
+    code = afs_fsync(VTOAFS(fileP), get_user_struct()->u_cred);
     if (code != 0) {
        errno = code;
        return -1;
     }
 
-    return 0; 
+    return 0;
 }
 
 /*
  * Close a file
  */
-int uafs_close(
-    int fd)
+int
+uafs_close(int fd)
 {
     int retval;
     AFS_GLOCK();
@@ -3248,8 +3349,8 @@ int uafs_close(
     return retval;
 }
 
-int uafs_close_r(
-    int fd)
+int
+uafs_close_r(int fd)
 {
     int code;
     struct usr_vnode *fileP;
@@ -3261,23 +3362,22 @@ int uafs_close_r(
     }
     afs_FileTable[fd] = NULL;
 
-    code = afs_close(fileP, afs_FileFlags[fd], u.u_cred);
+    code = afs_close(VTOAFS(fileP), afs_FileFlags[fd], get_user_struct()->u_cred);
     VN_RELE(fileP);
     if (code != 0) {
        errno = code;
        return -1;
     }
 
-    return 0; 
+    return 0;
 }
 
 /*
  * Create a hard link from the source to the target
  * Note: file names may not end in a slash.
  */
-int uafs_link(
-    char *existing,
-    char *new)
+int
+uafs_link(char *existing, char *new)
 {
     int retval;
     AFS_GLOCK();
@@ -3286,9 +3386,8 @@ int uafs_link(
     return retval;
 }
 
-int uafs_link_r(
-    char *existing,
-    char *new)
+int
+uafs_link_r(char *existing, char *new)
 {
     int code;
     struct usr_vnode *existP;
@@ -3338,7 +3437,7 @@ int uafs_link_r(
     /*
      * Create the link
      */
-    code = afs_link(existP, dirP, nameP, u.u_cred);
+    code = afs_link(VTOAFS(existP), VTOAFS(dirP), nameP, get_user_struct()->u_cred);
     VN_RELE(existP);
     VN_RELE(dirP);
     if (code != 0) {
@@ -3352,9 +3451,8 @@ int uafs_link_r(
  * Create a symbolic link from the source to the target
  * Note: file names may not end in a slash.
  */
-int uafs_symlink(
-    char *target,
-    char *source)
+int
+uafs_symlink(char *target, char *source)
 {
     int retval;
     AFS_GLOCK();
@@ -3363,9 +3461,8 @@ int uafs_symlink(
     return retval;
 }
 
-int uafs_symlink_r(
-    char *target,
-    char *source)
+int
+uafs_symlink_r(char *target, char *source)
 {
     int code;
     struct usr_vnode *dirP;
@@ -3407,9 +3504,9 @@ int uafs_symlink_r(
     usr_vattr_null(&attrs);
     attrs.va_type = VLNK;
     attrs.va_mode = 0777;
-    attrs.va_uid = u.u_cred->cr_uid;
-    attrs.va_gid = u.u_cred->cr_gid;
-    code = afs_symlink(dirP, nameP, &attrs, target, u.u_cred);
+    attrs.va_uid = afs_cr_uid(get_user_struct()->u_cred);
+    attrs.va_gid = afs_cr_gid(get_user_struct()->u_cred);
+    code = afs_symlink(VTOAFS(dirP), nameP, &attrs, target, get_user_struct()->u_cred);
     VN_RELE(dirP);
     if (code != 0) {
        errno = code;
@@ -3421,10 +3518,8 @@ int uafs_symlink_r(
 /*
  * Read a symbolic link into the buffer
  */
-int uafs_readlink(
-    char *path,
-    char *buf,
-    int len)
+int
+uafs_readlink(char *path, char *buf, int len)
 {
     int retval;
     AFS_GLOCK();
@@ -3433,10 +3528,8 @@ int uafs_readlink(
     return retval;
 }
 
-int uafs_readlink_r(
-    char *path,
-    char *buf,
-    int len)
+int
+uafs_readlink_r(char *path, char *buf, int len)
 {
     int code;
     struct usr_vnode *vp;
@@ -3470,10 +3563,10 @@ int uafs_readlink_r(
     /*
      * Read the the link
      */
-    code = afs_readlink(vp, &uio, u.u_cred);
+    code = afs_readlink(VTOAFS(vp), &uio, get_user_struct()->u_cred);
     VN_RELE(vp);
     if (code) {
-        errno = code;
+       errno = code;
        return -1;
     }
 
@@ -3487,8 +3580,8 @@ int uafs_readlink_r(
  * Remove a file (or directory)
  * Note: file name may not end in a slash.
  */
-int uafs_unlink(
-    char *path)
+int
+uafs_unlink(char *path)
 {
     int retval;
     AFS_GLOCK();
@@ -3497,12 +3590,10 @@ int uafs_unlink(
     return retval;
 }
 
-int uafs_unlink_r(
-    char *path)
+int
+uafs_unlink_r(char *path)
 {
     int code;
-    int openFlags;
-    struct usr_vnode *fileP;
     struct usr_vnode *dirP;
     char *nameP;
 
@@ -3538,7 +3629,7 @@ int uafs_unlink_r(
     /*
      * Remove the file
      */
-    code = afs_remove(dirP, nameP, u.u_cred);
+    code = afs_remove(VTOAFS(dirP), nameP, get_user_struct()->u_cred);
     VN_RELE(dirP);
     if (code != 0) {
        errno = code;
@@ -3551,9 +3642,8 @@ int uafs_unlink_r(
 /*
  * Rename a file (or directory)
  */
-int uafs_rename(
-    char *old,
-    char *new)
+int
+uafs_rename(char *old, char *new)
 {
     int retval;
     AFS_GLOCK();
@@ -3562,9 +3652,8 @@ int uafs_rename(
     return retval;
 }
 
-int uafs_rename_r(
-    char *old,
-    char *new)
+int
+uafs_rename_r(char *old, char *new)
 {
     int code;
     char *onameP;
@@ -3617,7 +3706,7 @@ int uafs_rename_r(
     /*
      * Rename the file
      */
-    code = afs_rename(odirP, onameP, ndirP, nnameP, u.u_cred);
+    code = afs_rename(VTOAFS(odirP), onameP, VTOAFS(ndirP), nnameP, get_user_struct()->u_cred);
     VN_RELE(odirP);
     VN_RELE(ndirP);
     if (code != 0) {
@@ -3632,8 +3721,8 @@ int uafs_rename_r(
  * Remove a or directory
  * Note: file name may not end in a slash.
  */
-int uafs_rmdir(
-    char *path)
+int
+uafs_rmdir(char *path)
 {
     int retval;
     AFS_GLOCK();
@@ -3642,12 +3731,10 @@ int uafs_rmdir(
     return retval;
 }
 
-int uafs_rmdir_r(
-    char *path)
+int
+uafs_rmdir_r(char *path)
 {
     int code;
-    int openFlags;
-    struct usr_vnode *fileP;
     struct usr_vnode *dirP;
     char *nameP;
 
@@ -3683,7 +3770,7 @@ int uafs_rmdir_r(
     /*
      * Remove the directory
      */
-    code = afs_rmdir(dirP, nameP, u.u_cred);
+    code = afs_rmdir(VTOAFS(dirP), nameP, get_user_struct()->u_cred);
     VN_RELE(dirP);
     if (code != 0) {
        errno = code;
@@ -3696,8 +3783,8 @@ int uafs_rmdir_r(
 /*
  * Flush a file from the AFS cache
  */
-int uafs_FlushFile(
-     char *path)
+int
+uafs_FlushFile(char *path)
 {
     int code;
     struct afs_ioctl iob;
@@ -3707,8 +3794,9 @@ int uafs_FlushFile(
     iob.out = NULL;
     iob.out_size = 0;
 
-    code = call_syscall(AFSCALL_PIOCTL, (long)path, _VICEIOCTL(6),
-                       (long)&iob, 0, 0);
+    code =
+       call_syscall(AFSCALL_PIOCTL, (long)path, _VICEIOCTL(6), (long)&iob, 0,
+                    0);
     if (code != 0) {
        errno = code;
        return -1;
@@ -3716,8 +3804,9 @@ int uafs_FlushFile(
 
     return 0;
 }
-int uafs_FlushFile_r(
-     char *path)
+
+int
+uafs_FlushFile_r(char *path)
 {
     int retval;
     AFS_GUNLOCK();
@@ -3729,8 +3818,8 @@ int uafs_FlushFile_r(
 /*
  * open a directory
  */
-usr_DIR *uafs_opendir(
-    char *path)
+usr_DIR *
+uafs_opendir(char *path)
 {
     usr_DIR *retval;
     AFS_GLOCK();
@@ -3739,8 +3828,8 @@ usr_DIR *uafs_opendir(
     return retval;
 }
 
-usr_DIR *uafs_opendir_r(
-    char *path)
+usr_DIR *
+uafs_opendir_r(char *path)
 {
     usr_DIR *dirp;
     struct usr_vnode *fileP;
@@ -3756,22 +3845,23 @@ usr_DIR *uafs_opendir_r(
 
     fileP = afs_FileTable[fd];
     if (fileP == NULL) {
-     return NULL;
+       return NULL;
     }
 
     if (fileP->v_type != VDIR) {
-      uafs_close_r(fd);
-      errno = ENOTDIR;
-      return NULL;
+       uafs_close_r(fd);
+       errno = ENOTDIR;
+       return NULL;
     }
 
     /*
      * Set up the directory structures
      */
-    dirp = (usr_DIR *)afs_osi_Alloc(sizeof(usr_DIR) + USR_DIRSIZE +
-                                   sizeof(struct usr_dirent));
+    dirp =
+       (usr_DIR *) afs_osi_Alloc(sizeof(usr_DIR) + USR_DIRSIZE +
+                                 sizeof(struct usr_dirent));
     usr_assert(dirp != NULL);
-    dirp->dd_buf = (char *)(dirp+1);
+    dirp->dd_buf = (char *)(dirp + 1);
     dirp->dd_fd = fd;
     dirp->dd_loc = 0;
     dirp->dd_size = 0;
@@ -3785,10 +3875,8 @@ usr_DIR *uafs_opendir_r(
  * This routine was developed to support AFS cache consistency testing.
  * You should use uafs_readdir instead.
  */
-int uafs_getdents(
-    int fd,
-    struct min_direct *buf,
-    int len)
+int
+uafs_getdents(int fd, struct min_direct *buf, int len)
 {
     int retval;
     AFS_GLOCK();
@@ -3797,10 +3885,8 @@ int uafs_getdents(
     return retval;
 }
 
-int uafs_getdents_r(
-    int fd,
-    struct min_direct *buf,
-    int len)
+int
+uafs_getdents_r(int fd, struct min_direct *buf, int len)
 {
     int code;
     struct usr_uio uio;
@@ -3832,21 +3918,21 @@ int uafs_getdents_r(
     /*
      * read the next chunk from the directory
      */
-    code = afs_readdir(vp, &uio, u.u_cred);
+    code = afs_readdir(VTOAFS(vp), &uio, get_user_struct()->u_cred);
     if (code != 0) {
        errno = code;
        return -1;
     }
 
     afs_FileOffsets[fd] = uio.uio_offset;
-    return(len - uio.uio_resid);
+    return (len - uio.uio_resid);
 }
 
 /*
  * read from a directory (names only)
  */
-struct usr_dirent *uafs_readdir(
-    usr_DIR *dirp)
+struct usr_dirent *
+uafs_readdir(usr_DIR * dirp)
 {
     struct usr_dirent *retval;
     AFS_GLOCK();
@@ -3855,10 +3941,9 @@ struct usr_dirent *uafs_readdir(
     return retval;
 }
 
-struct usr_dirent *uafs_readdir_r(
-    usr_DIR *dirp)
+struct usr_dirent *
+uafs_readdir_r(usr_DIR * dirp)
 {
-    int rc;
     int code;
     int len;
     struct usr_uio uio;
@@ -3867,6 +3952,11 @@ struct usr_dirent *uafs_readdir_r(
     struct usr_dirent *direntP;
     struct min_direct *directP;
 
+    if (!dirp) {
+       errno = EBADF;
+       return NULL;
+    }
+
     /*
      * Make sure this is an open file
      */
@@ -3880,7 +3970,7 @@ struct usr_dirent *uafs_readdir_r(
      * If there are no entries in the stream buffer
      * then read another chunk
      */
-    directP = (struct min_direct *)(dirp->dd_buf+dirp->dd_loc);
+    directP = (struct min_direct *)(dirp->dd_buf + dirp->dd_loc);
     if (dirp->dd_size == 0 || directP->d_fileno == 0) {
        /*
         * set up the uio buffer
@@ -3897,7 +3987,7 @@ struct usr_dirent *uafs_readdir_r(
        /*
         * read the next chunk from the directory
         */
-       code = afs_readdir(vp, &uio, u.u_cred);
+       code = afs_readdir(VTOAFS(vp), &uio, get_user_struct()->u_cred);
        if (code != 0) {
            errno = code;
            return NULL;
@@ -3906,7 +3996,7 @@ struct usr_dirent *uafs_readdir_r(
 
        dirp->dd_size = USR_DIRSIZE - iov[0].iov_len;
        dirp->dd_loc = 0;
-       directP = (struct min_direct *)(dirp->dd_buf+dirp->dd_loc);
+       directP = (struct min_direct *)(dirp->dd_buf + dirp->dd_loc);
     }
 
     /*
@@ -3916,18 +4006,18 @@ struct usr_dirent *uafs_readdir_r(
        errno = 0;
        return NULL;
     }
-    len = ((sizeof(struct min_direct)+directP->d_namlen+4) & (~3));
+    len = ((sizeof(struct min_direct) + directP->d_namlen + 4) & (~3));
     usr_assert(len <= dirp->dd_size);
 
     /*
      * Copy the next entry into the usr_dirent structure and advance
      */
-    direntP = (struct usr_dirent *)(dirp->dd_buf+USR_DIRSIZE);
+    direntP = (struct usr_dirent *)(dirp->dd_buf + USR_DIRSIZE);
     direntP->d_ino = directP->d_fileno;
     direntP->d_off = direntP->d_reclen;
-    direntP->d_reclen = sizeof(struct usr_dirent) - MAXNAMLEN +
-                              directP->d_namlen + 1;
-    memcpy(&direntP->d_name[0], (void *)(directP+1), directP->d_namlen);
+    direntP->d_reclen =
+       sizeof(struct usr_dirent) - MAXNAMLEN + directP->d_namlen + 1;
+    memcpy(&direntP->d_name[0], (void *)(directP + 1), directP->d_namlen);
     direntP->d_name[directP->d_namlen] = '\0';
     dirp->dd_loc += len;
     dirp->dd_size -= len;
@@ -3938,8 +4028,8 @@ struct usr_dirent *uafs_readdir_r(
 /*
  * Close a directory
  */
-int uafs_closedir(
-    usr_DIR *dirp)
+int
+uafs_closedir(usr_DIR * dirp)
 {
     int retval;
     AFS_GLOCK();
@@ -3948,12 +4038,17 @@ int uafs_closedir(
     return retval;
 }
 
-int uafs_closedir_r(
-    usr_DIR *dirp)
+int
+uafs_closedir_r(usr_DIR * dirp)
 {
     int fd;
     int rc;
 
+    if (!dirp) {
+       errno = EBADF;
+       return -1;
+    }
+
     fd = dirp->dd_fd;
     afs_osi_Free((char *)dirp,
                 sizeof(usr_DIR) + USR_DIRSIZE + sizeof(struct usr_dirent));
@@ -3964,29 +4059,23 @@ int uafs_closedir_r(
 /*
  * Do AFS authentication
  */
-int uafs_klog(
-    char *user,
-    char *cell,
-    char *passwd,
-    char **reason)
+int
+uafs_klog(char *user, char *cell, char *passwd, char **reason)
 {
     int code;
     afs_int32 password_expires = -1;
 
     usr_mutex_lock(&osi_authenticate_lock);
-    code = ka_UserAuthenticateGeneral(
-               KA_USERAUTH_VERSION+KA_USERAUTH_DOSETPAG2, user,
-               NULL, cell, passwd, 0, &password_expires,
-               0, reason);
+    code =
+       ka_UserAuthenticateGeneral(KA_USERAUTH_VERSION +
+                                  KA_USERAUTH_DOSETPAG2, user, NULL, cell,
+                                  passwd, 0, &password_expires, 0, reason);
     usr_mutex_unlock(&osi_authenticate_lock);
     return code;
 }
 
-int uafs_klog_r(
-    char *user,
-    char *cell,
-    char *passwd,
-    char **reason)
+int
+uafs_klog_r(char *user, char *cell, char *passwd, char **reason)
 {
     int retval;
     AFS_GUNLOCK();
@@ -3998,7 +4087,8 @@ int uafs_klog_r(
 /*
  * Destroy AFS credentials from the kernel cache
  */
-int uafs_unlog(void)
+int
+uafs_unlog(void)
 {
     int code;
 
@@ -4008,7 +4098,8 @@ int uafs_unlog(void)
     return code;
 }
 
-int uafs_unlog_r(void)
+int
+uafs_unlog_r(void)
 {
     int retval;
     AFS_GUNLOCK();
@@ -4022,7 +4113,8 @@ int uafs_unlog_r(void)
  * NULL if the path is a relative pathname or if the path
  * doesn't start with the AFS mount point string.
  */
-char *uafs_afsPathName(char *path)
+char *
+uafs_afsPathName(char *path)
 {
     char *p;
     char lastchar;
@@ -4031,7 +4123,7 @@ char *uafs_afsPathName(char *path)
     if (path[0] != '/')
        return NULL;
     lastchar = '/';
-    for (i = 1, p = path+1; *p != '\0' ; p++) {
+    for (i = 1, p = path + 1; *p != '\0'; p++) {
        /* Ignore duplicate slashes */
        if (*p == '/' && lastchar == '/')
            continue;
@@ -4060,20 +4152,17 @@ char *uafs_afsPathName(char *path)
  * uafs_klog_nopag
  * klog but don't allocate a new pag
  */
-int uafs_klog_nopag(
-    char *user,
-    char *cell,
-    char *passwd,
-    char **reason)
+int
+uafs_klog_nopag(char *user, char *cell, char *passwd, char **reason)
 {
     int code;
     afs_int32 password_expires = -1;
 
     usr_mutex_lock(&osi_authenticate_lock);
-    code = ka_UserAuthenticateGeneral(
-      KA_USERAUTH_VERSION  /*+KA_USERAUTH_DOSETPAG2*/, user,
-          NULL, cell, passwd, 0, &password_expires,
-          0, reason);
+    code = ka_UserAuthenticateGeneral(KA_USERAUTH_VERSION
+                                     /*+KA_USERAUTH_DOSETPAG2 */ , user,
+                                     NULL, cell, passwd, 0,
+                                     &password_expires, 0, reason);
     usr_mutex_unlock(&osi_authenticate_lock);
     return code;
 }
@@ -4082,88 +4171,91 @@ int uafs_klog_nopag(
  * uafs_getcellstatus
  * get the cell status
  */
-int uafs_getcellstatus(char *cell, afs_int32 *status)
+int
+uafs_getcellstatus(char *cell, afs_int32 * status)
 {
-  int rc;
-  struct afs_ioctl iob;
+    int rc;
+    struct afs_ioctl iob;
 
-  iob.in = cell;
-  iob.in_size = strlen(cell)+1;
-  iob.out = 0;
-  iob.out_size = 0;
+    iob.in = cell;
+    iob.in_size = strlen(cell) + 1;
+    iob.out = 0;
+    iob.out_size = 0;
 
-  rc = call_syscall(AFSCALL_PIOCTL, /*path*/0, _VICEIOCTL(35),
-                      (long)&iob, 0, 0);
+    rc = call_syscall(AFSCALL_PIOCTL, /*path */ 0, _VICEIOCTL(35),
+                     (long)&iob, 0, 0);
 
-  if (rc < 0) {
-    errno = rc;
-    return -1;
-  }
+    if (rc < 0) {
+       errno = rc;
+       return -1;
+    }
 
-  *status = (afs_int32) iob.out;
-  return 0;
+    *status = (intptr_t)iob.out;
+    return 0;
 }
 
 /*
  * uafs_getvolquota
  * Get quota of volume associated with path
  */
-int uafs_getvolquota(char *path, afs_int32 *BlocksInUse, afs_int32 *MaxQuota)
+int
+uafs_getvolquota(char *path, afs_int32 * BlocksInUse, afs_int32 * MaxQuota)
 {
-  int rc;
-  struct afs_ioctl iob;
-  VolumeStatus *status;
-  char buf[1024];
+    int rc;
+    struct afs_ioctl iob;
+    VolumeStatus *status;
+    char buf[1024];
 
-  iob.in = 0;
-  iob.in_size = 0;
-  iob.out = buf;
-  iob.out_size = 1024;
+    iob.in = 0;
+    iob.in_size = 0;
+    iob.out = buf;
+    iob.out_size = 1024;
 
-  rc = call_syscall(AFSCALL_PIOCTL, (long) path, _VICEIOCTL(4),
-                      (long)&iob, 0, 0);
+    rc = call_syscall(AFSCALL_PIOCTL, (long)path, _VICEIOCTL(4), (long)&iob,
+                     0, 0);
 
-  if (rc != 0) {
-    errno = rc;
-    return -1;
-  }
+    if (rc != 0) {
+       errno = rc;
+       return -1;
+    }
 
-  status = (VolumeStatus *) buf;
-  *BlocksInUse = status->BlocksInUse;
-  *MaxQuota = status->MaxQuota;
-  return 0;
+    status = (VolumeStatus *) buf;
+    *BlocksInUse = status->BlocksInUse;
+    *MaxQuota = status->MaxQuota;
+    return 0;
 }
 
 /*
  * uafs_setvolquota
  * Set quota of volume associated with path
  */
-int uafs_setvolquota(char *path, afs_int32 MaxQuota)
+int
+uafs_setvolquota(char *path, afs_int32 MaxQuota)
 {
-  int rc;
-  struct afs_ioctl iob;
-  VolumeStatus *status;
-  char buf[1024];
+    int rc;
+    struct afs_ioctl iob;
+    VolumeStatus *status;
+    char buf[1024];
 
-  iob.in = buf;
-  iob.in_size = 1024;
-  iob.out = 0;
-  iob.out_size = 0;
+    iob.in = buf;
+    iob.in_size = 1024;
+    iob.out = 0;
+    iob.out_size = 0;
 
-  memset(buf, 0, sizeof(VolumeStatus));
-  status = (VolumeStatus *) buf;
-  status->MaxQuota = MaxQuota;
-  status->MinQuota = -1;
+    memset(buf, 0, sizeof(VolumeStatus));
+    status = (VolumeStatus *) buf;
+    status->MaxQuota = MaxQuota;
+    status->MinQuota = -1;
 
-  rc = call_syscall(AFSCALL_PIOCTL, (long) path, _VICEIOCTL(5),
-                      (long)&iob, 0, 0);
+    rc = call_syscall(AFSCALL_PIOCTL, (long)path, _VICEIOCTL(5), (long)&iob,
+                     0, 0);
 
-  if (rc != 0) {
-    errno = rc;
-    return -1;
-  }
+    if (rc != 0) {
+       errno = rc;
+       return -1;
+    }
 
-  return 0;
+    return 0;
 }
 
 /*
@@ -4171,11 +4263,10 @@ int uafs_setvolquota(char *path, afs_int32 MaxQuota)
  * Determine whether a dir. is a mount point or not
  * return 1 if mount point, 0 if not
  */
-int uafs_statmountpoint(char *path)
+int
+uafs_statmountpoint(char *path)
 {
     int retval;
-    int code;
-    char buf[256];
 
     AFS_GLOCK();
     retval = uafs_statmountpoint_r(path);
@@ -4183,18 +4274,18 @@ int uafs_statmountpoint(char *path)
     return retval;
 }
 
-int uafs_statmountpoint_r(char *path)
+int
+uafs_statmountpoint_r(char *path)
 {
     int code;
     struct vnode *vp;
     struct vcache *avc;
-    struct vrequest treq;
     int r;
 
     code = uafs_LookupName(path, afs_CurrentDir, &vp, 0, 1);
     if (code != 0) {
-     errno = code;
-     return -1;
+       errno = code;
+       return -1;
     }
 
     avc = VTOAFS(vp);
@@ -4208,29 +4299,26 @@ int uafs_statmountpoint_r(char *path)
  * uafs_getRights
  * Get a list of rights for the current user on path.
  */
-int uafs_getRights(char *path)
+int
+uafs_getRights(char *path)
 {
-    int code, rc;
+    int code;
     struct vnode *vp;
     int afs_rights;
 
     AFS_GLOCK();
     code = uafs_LookupName(path, afs_CurrentDir, &vp, 1, 0);
     if (code != 0) {
-     errno = code;
-     AFS_GUNLOCK();
-     return -1;
+       errno = code;
+       AFS_GUNLOCK();
+       return -1;
     }
 
-    afs_rights = PRSFS_READ |
-      PRSFS_WRITE |
-      PRSFS_INSERT |
-      PRSFS_LOOKUP |
-      PRSFS_DELETE |
-      PRSFS_LOCK |
-      PRSFS_ADMINISTER;
+    afs_rights =
+       PRSFS_READ | PRSFS_WRITE | PRSFS_INSERT | PRSFS_LOOKUP | PRSFS_DELETE
+       | PRSFS_LOCK | PRSFS_ADMINISTER;
 
-    afs_rights = afs_getRights (vp, afs_rights, u.u_cred);
+    afs_rights = afs_getRights(VTOAFS(vp), afs_rights, get_user_struct()->u_cred);
 
     AFS_GUNLOCK();
     return afs_rights;