afs: Indicate error from afs_osi_Read/Write better
[openafs.git] / src / afs / FBSD / osi_file.c
index 0afddc1..7c695d6 100644 (file)
@@ -17,7 +17,9 @@
 
 
 int afs_osicred_initialized = 0;
-AFS_UCRED afs_osi_cred;
+#ifndef AFS_FBSD80_ENV /* cr_groups is now malloc()'d */
+afs_ucred_t afs_osi_cred;
+#endif
 afs_lock_t afs_xosi;           /* lock is for tvattr */
 extern struct osi_dev cacheDev;
 extern struct mount *afs_cacheVfsp;
@@ -36,11 +38,7 @@ osi_UFSOpen(afs_dcache_id_t *ainode)
        osi_Panic("UFSOpen called for non-UFS cache\n");
     afile = (struct osi_file *)osi_AllocSmallSpace(sizeof(struct osi_file));
     AFS_GUNLOCK();
-#if defined(AFS_FBSD50_ENV)
     code = VFS_VGET(afs_cacheVfsp, (ino_t) ainode->ufs, LK_EXCLUSIVE, &vp);
-#else
-    code = VFS_VGET(afs_cacheVfsp, (ino_t) ainode->ufs, &vp);
-#endif
     AFS_GLOCK();
     if (code == 0 && vp->v_type == VNON)
        code = ENOENT;
@@ -50,37 +48,32 @@ osi_UFSOpen(afs_dcache_id_t *ainode)
     }
 #if defined(AFS_FBSD80_ENV)
     VOP_UNLOCK(vp, 0);
-#elif defined(AFS_FBSD50_ENV)
-    VOP_UNLOCK(vp, 0, curthread);
 #else
-    VOP_UNLOCK(vp, 0, curproc);
+    VOP_UNLOCK(vp, 0, curthread);
 #endif
     afile->vnode = vp;
     afile->size = VTOI(vp)->i_size;
     afile->offset = 0;
     afile->proc = NULL;
-    afile->inum = ainode->ufs; /* for hint validity checking */
     return (void *)afile;
 }
 
 int
-afs_osi_Stat(register struct osi_file *afile, register struct osi_stat *astat)
+afs_osi_Stat(struct osi_file *afile, struct osi_stat *astat)
 {
-    register afs_int32 code;
+    afs_int32 code;
     struct vattr tvattr;
     AFS_STATCNT(osi_Stat);
-    MObtainWriteLock(&afs_xosi, 320);
+    ObtainWriteLock(&afs_xosi, 320);
     AFS_GUNLOCK();
 #if defined(AFS_FBSD80_ENV)
     vn_lock(afile->vnode, LK_EXCLUSIVE | LK_RETRY);
-    code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp, curthread);
+    code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp);
     VOP_UNLOCK(afile->vnode, 0);
-#elif defined(AFS_FBSD50_ENV)
+#else
     vn_lock(afile->vnode, LK_EXCLUSIVE | LK_RETRY, curthread);
     code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp, curthread);
     VOP_UNLOCK(afile->vnode, LK_EXCLUSIVE, curthread);
-#else
-    code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp, curproc);
 #endif
     AFS_GLOCK();
     if (code == 0) {
@@ -88,12 +81,12 @@ afs_osi_Stat(register struct osi_file *afile, register struct osi_stat *astat)
        astat->mtime = tvattr.va_mtime.tv_sec;
        astat->atime = tvattr.va_atime.tv_sec;
     }
-    MReleaseWriteLock(&afs_xosi);
+    ReleaseWriteLock(&afs_xosi);
     return code;
 }
 
 int
-osi_UFSClose(register struct osi_file *afile)
+osi_UFSClose(struct osi_file *afile)
 {
     AFS_STATCNT(osi_Close);
     if (afile->vnode) {
@@ -105,14 +98,14 @@ osi_UFSClose(register struct osi_file *afile)
 }
 
 int
-osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize)
+osi_UFSTruncate(struct osi_file *afile, afs_int32 asize)
 {
     struct vattr tvattr;
     struct vnode *vp;
-    register afs_int32 code, glocked;
+    afs_int32 code, glocked;
     AFS_STATCNT(osi_Truncate);
 
-    MObtainWriteLock(&afs_xosi, 321);
+    ObtainWriteLock(&afs_xosi, 321);
     vp = afile->vnode;
     /*
      * This routine only shrinks files, and most systems
@@ -124,36 +117,31 @@ osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize)
       AFS_GUNLOCK();
 #if defined(AFS_FBSD80_ENV)
     vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
-    code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp, curthread);
-#elif defined(AFS_FBSD50_ENV)
+    code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp);
+#else
     vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curthread);
     code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp, curthread);
-#else
-    vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curproc);
-    code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp, curproc);
 #endif
     if (code != 0 || tvattr.va_size <= asize)
        goto out;
 
     VATTR_NULL(&tvattr);
     tvattr.va_size = asize;
-#if defined(AFS_FBSD50_ENV)
-    code = VOP_SETATTR(vp, &tvattr, afs_osi_credp, curthread);
+#if defined(AFS_FBSD80_ENV)
+    code = VOP_SETATTR(vp, &tvattr, afs_osi_credp);
 #else
-    code = VOP_SETATTR(vp, &tvattr, afs_osi_credp, curproc);
+    code = VOP_SETATTR(vp, &tvattr, afs_osi_credp, curthread);
 #endif
 
 out:
 #if defined(AFS_FBSD80_ENV)
     VOP_UNLOCK(vp, 0);
-#elif defined(AFS_FBSD50_ENV)
-    VOP_UNLOCK(vp, LK_EXCLUSIVE, curthread);
 #else
-    VOP_UNLOCK(vp, LK_EXCLUSIVE, curproc);
+    VOP_UNLOCK(vp, LK_EXCLUSIVE, curthread);
 #endif
     if (glocked)
       AFS_GLOCK();
-    MReleaseWriteLock(&afs_xosi);
+    ReleaseWriteLock(&afs_xosi);
     return code;
 }
 
@@ -167,11 +155,11 @@ osi_DisableAtimes(struct vnode *avp)
 
 /* Generic read interface */
 int
-afs_osi_Read(register struct osi_file *afile, int offset, void *aptr,
+afs_osi_Read(struct osi_file *afile, int offset, void *aptr,
             afs_int32 asize)
 {
-    unsigned int resid;
-    register afs_int32 code;
+    int resid;
+    afs_int32 code;
     AFS_STATCNT(osi_Read);
 
     /**
@@ -182,7 +170,7 @@ afs_osi_Read(register struct osi_file *afile, int offset, void *aptr,
        if (!afs_shuttingdown)
            osi_Panic("osi_Read called with null param");
        else
-           return EIO;
+           return -EIO;
     }
 
     if (offset != -1)
@@ -199,18 +187,20 @@ afs_osi_Read(register struct osi_file *afile, int offset, void *aptr,
     } else {
        afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid,
                   ICL_TYPE_INT32, code);
-       code = -1;
+       if (code > 0) {
+           code *= -1;
+       }
     }
     return code;
 }
 
 /* Generic write interface */
 int
-afs_osi_Write(register struct osi_file *afile, afs_int32 offset, void *aptr,
+afs_osi_Write(struct osi_file *afile, afs_int32 offset, void *aptr,
              afs_int32 asize)
 {
     unsigned int resid;
-    register afs_int32 code;
+    afs_int32 code;
     AFS_STATCNT(osi_Write);
     if (!afile)
        osi_Panic("afs_osi_Write called with null param");
@@ -228,7 +218,9 @@ afs_osi_Write(register struct osi_file *afile, afs_int32 offset, void *aptr,
        code = asize - resid;
        afile->offset += code;
     } else {
-       code = -1;
+       if (code > 0) {
+           code *= -1;
+       }
     }
     if (afile->proc) {
        (*afile->proc) (afile, code);
@@ -241,7 +233,7 @@ afs_osi_Write(register struct osi_file *afile, afs_int32 offset, void *aptr,
     This routine written from the RT NFS port strategy routine.
     It has been generalized a bit, but should still be pretty clear. */
 int
-afs_osi_MapStrategy(int (*aproc) (), register struct buf *bp)
+afs_osi_MapStrategy(int (*aproc) (), struct buf *bp)
 {
     afs_int32 returnCode;