Use AFS_CACHE_VNODE_PATH for UKERNEL
[openafs.git] / src / afs / UKERNEL / afs_usrops.c
index 9ee5021..e946b90 100644 (file)
 #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"
@@ -119,7 +123,7 @@ 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;
@@ -534,6 +538,12 @@ afs_osi_Wakeup(void *x)
 }
 
 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 index;
@@ -626,18 +636,19 @@ afs_osi_CheckTimedWaits(void)
 }
 
 /*
- * 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,
@@ -647,12 +658,7 @@ 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); */
 
     /*
      * Assume relative pathnames refer to files in AFS
@@ -664,34 +670,17 @@ 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;
 }
 
@@ -707,31 +696,28 @@ osi_UFSOpen(afs_dcache_id_t *ino)
 
     AFS_ASSERT_GLOCK();
 
-    if (ino->ufs > 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->ufs - 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->ufs;
     fp->vnode = (struct usr_vnode *)fp;
 
     AFS_GLOCK();
@@ -748,7 +734,7 @@ 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;
@@ -768,7 +754,7 @@ 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;
     }
@@ -792,21 +778,21 @@ 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;
     }
@@ -830,21 +816,21 @@ afs_osi_Write(struct osi_file *fp, afs_int32 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 = 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;
     }
@@ -862,7 +848,7 @@ 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;
     }
@@ -899,7 +885,7 @@ afs_osi_VOP_RDWR(struct usr_vnode *vnodeP, struct usr_uio *uioP, int rw,
                          uioP->uio_iov[0].iov_len);
     }
     if (rc < 0) {
-       return u.u_error;
+       return get_user_struct()->u_error;
     }
 
     uioP->uio_resid -= rc;
@@ -1030,7 +1016,7 @@ afs_osi_MapStrategy(int (*aproc) (struct usr_buf *), struct usr_buf *bp)
 }
 
 void
-osi_FlushPages(register struct vcache *avc, AFS_UCRED *credp)
+osi_FlushPages(register struct vcache *avc, afs_ucred_t *credp)
 {
     ObtainSharedLock(&avc->lock, 555);
     if ((hcmp((avc->f.m.DataVersion), (avc->mapDV)) <= 0)
@@ -1070,14 +1056,6 @@ osi_Init(void)
 {
     int i;
 
-    /*
-     * 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
     /*
      * Initialize the mutex and condition variable used to implement
@@ -1108,7 +1086,7 @@ 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);
 
@@ -1301,7 +1279,10 @@ SweepAFSCache(int *vFilesFound)
     for (currp = readdir(cdirp); currp; currp = readdir(cdirp)) {
        if (afsd_debug) {
            printf("%s: Current directory entry:\n", rn);
-#if defined(AFS_USR_DFBSD_ENV)
+#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
@@ -1490,12 +1471,12 @@ uafs_Init(char *rn, char *mountDirParam, char *confDirParam,
        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;
@@ -1509,7 +1490,7 @@ uafs_Init(char *rn, char *mountDirParam, char *confDirParam,
     afs_global_procp = (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_pid = osi_getpid();
     afs_global_procp->p_ppid = (pid_t) 1;
     afs_global_procp->p_ucred = afs_global_ucredp;
 
@@ -1911,6 +1892,25 @@ uafs_Init(char *rn, char *mountDirParam, char *confDirParam,
     return;
 }
 
+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)
 {
@@ -1919,7 +1919,9 @@ uafs_Shutdown(void)
     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();
@@ -1978,10 +1980,10 @@ 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;
@@ -2039,8 +2041,8 @@ call_syscall(long syscall, long afscall, long param1, long param2,
     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;
@@ -2261,7 +2263,7 @@ uafs_LookupName(char *path, struct usr_vnode *parentVp,
            /*
             * We need execute permission to search a directory
             */
-           code = afs_access(VTOAFS(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);
@@ -2276,13 +2278,13 @@ uafs_LookupName(char *path, struct usr_vnode *parentVp,
            nextVp = NULL;
 #ifdef AFS_WEB_ENHANCEMENTS
            if ((nextPathP != NULL && *nextPathP != '\0') || !no_eval_mtpt)
-               code = afs_lookup(VTOAFS(vp), pathP, &nextVc, u.u_cred, 0);
+               code = afs_lookup(VTOAFS(vp), pathP, &nextVc, get_user_struct()->u_cred, 0);
            else
                code =
-                   afs_lookup(VTOAFS(vp), pathP, &nextVc, u.u_cred,
+                   afs_lookup(VTOAFS(vp), pathP, &nextVc, get_user_struct()->u_cred,
                               AFS_LOOKUP_NOEVAL);
 #else
-           code = afs_lookup(VTOAFS(vp), pathP, &nextVc, 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);
@@ -2375,7 +2377,7 @@ uafs_LookupLink(struct usr_vnode *vp, struct usr_vnode *parentVp,
     /*
      * Read the link data
      */
-    code = afs_readlink(VTOAFS(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);
        return code;
@@ -2576,10 +2578,10 @@ 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(VTOAFS(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;
@@ -2675,8 +2677,8 @@ 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;
            }
@@ -2685,7 +2687,7 @@ uafs_open_r(char *path, int flags, int mode)
            code =
                afs_create(VTOAFS(dirP), nameP, &attrs,
                           (flags & O_EXCL) ? usr_EXCL : usr_NONEXCL, mode,
-                          &vc, u.u_cred);
+                          &vc, get_user_struct()->u_cred);
            VN_RELE(dirP);
            if (code != 0) {
                errno = code;
@@ -2713,7 +2715,7 @@ uafs_open_r(char *path, int flags, int mode)
            }
            if (!fileMode)
                fileMode = VREAD;       /* since O_RDONLY is 0 */
-           code = afs_access(VTOAFS(fileP), fileMode, u.u_cred);
+           code = afs_access(VTOAFS(fileP), fileMode, get_user_struct()->u_cred);
            if (code != 0) {
                VN_RELE(fileP);
                errno = code;
@@ -2723,7 +2725,7 @@ uafs_open_r(char *path, int flags, int mode)
            /*
             * Get the file attributes, all we need is the size
             */
-           code = afs_getattr(VTOAFS(fileP), &attrs, u.u_cred);
+           code = afs_getattr(VTOAFS(fileP), &attrs, get_user_struct()->u_cred);
            if (code != 0) {
                VN_RELE(fileP);
                errno = code;
@@ -2766,7 +2768,7 @@ uafs_open_r(char *path, int flags, int mode)
        usr_vattr_null(&attrs);
        attrs.va_mask = ATTR_SIZE;
        attrs.va_size = 0;
-       code = afs_setattr(VTOAFS(fileP), &attrs, u.u_cred);
+       code = afs_setattr(VTOAFS(fileP), &attrs, get_user_struct()->u_cred);
        if (code != 0) {
            VN_RELE(fileP);
            errno = code;
@@ -2778,7 +2780,7 @@ uafs_open_r(char *path, int flags, int mode)
     /*
      * do the open
      */
-    code = afs_open(&vc, openFlags, u.u_cred);
+    code = afs_open(&vc, openFlags, get_user_struct()->u_cred);
     if (code != 0) {
        VN_RELE(fileP);
        errno = code;
@@ -2884,7 +2886,7 @@ uafs_pwrite_r(int fd, char *buf, int len, off_t offset)
      * do the write
      */
 
-    code = afs_write(VTOAFS(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;
@@ -2950,7 +2952,7 @@ uafs_pread_r(int fd, char *buf, int len, off_t offset)
     /*
      * do the read
      */
-    code = afs_read(VTOAFS(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;
@@ -2976,7 +2978,7 @@ uafs_GetAttr(struct usr_vnode *vp, struct stat *stats)
     /*
      * Get the attributes
      */
-    code = afs_getattr(VTOAFS(vp), &attrs, u.u_cred);
+    code = afs_getattr(VTOAFS(vp), &attrs, get_user_struct()->u_cred);
     if (code != 0) {
        return code;
     }
@@ -3128,7 +3130,7 @@ uafs_chmod_r(char *path, int mode)
     usr_vattr_null(&attrs);
     attrs.va_mask = ATTR_MODE;
     attrs.va_mode = mode;
-    code = afs_setattr(VTOAFS(vp), &attrs, u.u_cred);
+    code = afs_setattr(VTOAFS(vp), &attrs, get_user_struct()->u_cred);
     VN_RELE(vp);
     if (code != 0) {
        errno = code;
@@ -3165,7 +3167,7 @@ uafs_fchmod_r(int fd, int mode)
     usr_vattr_null(&attrs);
     attrs.va_mask = ATTR_MODE;
     attrs.va_mode = mode;
-    code = afs_setattr(VTOAFS(vp), &attrs, u.u_cred);
+    code = afs_setattr(VTOAFS(vp), &attrs, get_user_struct()->u_cred);
     if (code != 0) {
        errno = code;
        return -1;
@@ -3201,7 +3203,7 @@ uafs_truncate_r(char *path, int length)
     usr_vattr_null(&attrs);
     attrs.va_mask = ATTR_SIZE;
     attrs.va_size = length;
-    code = afs_setattr(VTOAFS(vp), &attrs, u.u_cred);
+    code = afs_setattr(VTOAFS(vp), &attrs, get_user_struct()->u_cred);
     VN_RELE(vp);
     if (code != 0) {
        errno = code;
@@ -3238,7 +3240,7 @@ uafs_ftruncate_r(int fd, int length)
     usr_vattr_null(&attrs);
     attrs.va_mask = ATTR_SIZE;
     attrs.va_size = length;
-    code = afs_setattr(VTOAFS(vp), &attrs, u.u_cred);
+    code = afs_setattr(VTOAFS(vp), &attrs, get_user_struct()->u_cred);
     if (code != 0) {
        errno = code;
        return -1;
@@ -3280,7 +3282,7 @@ uafs_lseek_r(int fd, int offset, int whence)
        newpos = offset;
        break;
     case SEEK_END:
-       code = afs_getattr(VTOAFS(vp), &attrs, u.u_cred);
+       code = afs_getattr(VTOAFS(vp), &attrs, get_user_struct()->u_cred);
        if (code != 0) {
            errno = code;
            return -1;
@@ -3325,7 +3327,7 @@ uafs_fsync_r(int fd)
        return -1;
     }
 
-    code = afs_fsync(VTOAFS(fileP), u.u_cred);
+    code = afs_fsync(VTOAFS(fileP), get_user_struct()->u_cred);
     if (code != 0) {
        errno = code;
        return -1;
@@ -3360,7 +3362,7 @@ uafs_close_r(int fd)
     }
     afs_FileTable[fd] = NULL;
 
-    code = afs_close(VTOAFS(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;
@@ -3435,7 +3437,7 @@ uafs_link_r(char *existing, char *new)
     /*
      * Create the link
      */
-    code = afs_link(VTOAFS(existP), VTOAFS(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) {
@@ -3502,9 +3504,9 @@ uafs_symlink_r(char *target, char *source)
     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(VTOAFS(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;
@@ -3561,7 +3563,7 @@ uafs_readlink_r(char *path, char *buf, int len)
     /*
      * Read the the link
      */
-    code = afs_readlink(VTOAFS(vp), &uio, u.u_cred);
+    code = afs_readlink(VTOAFS(vp), &uio, get_user_struct()->u_cred);
     VN_RELE(vp);
     if (code) {
        errno = code;
@@ -3627,7 +3629,7 @@ uafs_unlink_r(char *path)
     /*
      * Remove the file
      */
-    code = afs_remove(VTOAFS(dirP), nameP, u.u_cred);
+    code = afs_remove(VTOAFS(dirP), nameP, get_user_struct()->u_cred);
     VN_RELE(dirP);
     if (code != 0) {
        errno = code;
@@ -3704,7 +3706,7 @@ uafs_rename_r(char *old, char *new)
     /*
      * Rename the file
      */
-    code = afs_rename(VTOAFS(odirP), onameP, VTOAFS(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) {
@@ -3768,7 +3770,7 @@ uafs_rmdir_r(char *path)
     /*
      * Remove the directory
      */
-    code = afs_rmdir(VTOAFS(dirP), nameP, u.u_cred);
+    code = afs_rmdir(VTOAFS(dirP), nameP, get_user_struct()->u_cred);
     VN_RELE(dirP);
     if (code != 0) {
        errno = code;
@@ -3916,7 +3918,7 @@ uafs_getdents_r(int fd, struct min_direct *buf, int len)
     /*
      * read the next chunk from the directory
      */
-    code = afs_readdir(VTOAFS(vp), &uio, u.u_cred);
+    code = afs_readdir(VTOAFS(vp), &uio, get_user_struct()->u_cred);
     if (code != 0) {
        errno = code;
        return -1;
@@ -3950,6 +3952,11 @@ uafs_readdir_r(usr_DIR * dirp)
     struct usr_dirent *direntP;
     struct min_direct *directP;
 
+    if (!dirp) {
+       errno = EBADF;
+       return NULL;
+    }
+
     /*
      * Make sure this is an open file
      */
@@ -3980,7 +3987,7 @@ uafs_readdir_r(usr_DIR * dirp)
        /*
         * read the next chunk from the directory
         */
-       code = afs_readdir(VTOAFS(vp), &uio, u.u_cred);
+       code = afs_readdir(VTOAFS(vp), &uio, get_user_struct()->u_cred);
        if (code != 0) {
            errno = code;
            return NULL;
@@ -4037,6 +4044,11 @@ 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));
@@ -4178,7 +4190,7 @@ uafs_getcellstatus(char *cell, afs_int32 * status)
        return -1;
     }
 
-    *status = (afs_int32) iob.out;
+    *status = (intptr_t)iob.out;
     return 0;
 }
 
@@ -4306,7 +4318,7 @@ uafs_getRights(char *path)
        PRSFS_READ | PRSFS_WRITE | PRSFS_INSERT | PRSFS_LOOKUP | PRSFS_DELETE
        | PRSFS_LOCK | PRSFS_ADMINISTER;
 
-    afs_rights = afs_getRights(VTOAFS(vp), afs_rights, u.u_cred);
+    afs_rights = afs_getRights(VTOAFS(vp), afs_rights, get_user_struct()->u_cred);
 
     AFS_GUNLOCK();
     return afs_rights;