afs: afs_osi_Read/Write returns negative on error
[openafs.git] / src / afs / HPUX / osi_file.c
index accd3de..2afe1da 100644 (file)
 #include <afsconfig.h>
 #include "afs/param.h"
 
-RCSID("$Header$");
 
 #include "afs/sysincludes.h"   /* Standard vendor system headers */
 #include "afsincludes.h"       /* Afs-based standard headers */
-#include "afs/afs_stats.h"  /* afs statistics */
+#include "afs/afs_stats.h"     /* afs statistics */
 #include "afs/osi_inode.h"     /* igetinode() */
 
 
-int afs_osicred_initialized=0;
-struct  AFS_UCRED afs_osi_cred;
+int afs_osicred_initialized = 0;
+afs_ucred_t afs_osi_cred;
 afs_lock_t afs_xosi;           /* lock is for tvattr */
 extern struct osi_dev cacheDev;
 extern struct vfs *afs_cacheVfsp;
 
 
-void *osi_UFSOpen(afs_int32 ainode)
+void *
+osi_UFSOpen(afs_dcache_id_t *ainode)
 {
     struct inode *ip;
-    register struct osi_file *afile = NULL;
+    struct osi_file *afile = NULL;
     extern int cacheDiskType;
     afs_int32 code = 0;
     int dummy;
     AFS_STATCNT(osi_UFSOpen);
-    if(cacheDiskType != AFS_FCACHE_TYPE_UFS) {
+    if (cacheDiskType != AFS_FCACHE_TYPE_UFS) {
        osi_Panic("UFSOpen called for non-UFS cache\n");
     }
     if (!afs_osicred_initialized) {
        /* valid for alpha_osf, SunOS, Ultrix */
-       memset((char *)&afs_osi_cred, 0, sizeof(struct AFS_UCRED));
+       memset(&afs_osi_cred, 0, sizeof(afs_ucred_t));
        crhold(&afs_osi_cred);  /* don't let it evaporate, since it is static */
        afs_osicred_initialized = 1;
     }
-    afile = (struct osi_file *) osi_AllocSmallSpace(sizeof(struct osi_file));
+    afile = (struct osi_file *)osi_AllocSmallSpace(sizeof(struct osi_file));
     setuerror(0);
     AFS_GUNLOCK();
-    ip = (struct inode *) igetinode(afs_cacheVfsp, (dev_t) cacheDev.dev, (ino_t)ainode,&dummy);
+    ip = (struct inode *)igetinode(afs_cacheVfsp, (dev_t) cacheDev.dev,
+                                  (ino_t) ainode->ufs, &dummy);
     AFS_GLOCK();
     if (getuerror()) {
        osi_FreeSmallSpace(afile);
@@ -55,46 +56,47 @@ void *osi_UFSOpen(afs_int32 ainode)
     afile->vnode = ITOV(ip);
     afile->size = VTOI(afile->vnode)->i_size;
     afile->offset = 0;
-    afile->proc = (int (*)()) 0;
-    afile->inum = ainode;        /* for hint validity checking */
+    afile->proc = (int (*)())0;
     return (void *)afile;
 }
 
-int afs_osi_Stat(register struct osi_file *afile, register struct osi_stat *astat)
+int
+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();
     code = VOP_GETATTR(afile->vnode, &tvattr, &afs_osi_cred, VSYNC);
     AFS_GLOCK();
     if (code == 0) {
        astat->size = tvattr.va_size;
-       astat->blksize = tvattr.va_blocksize;
        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)
+int
+osi_UFSClose(struct osi_file *afile)
 {
-      AFS_STATCNT(osi_Close);
-      if(afile->vnode) {
+    AFS_STATCNT(osi_Close);
+    if (afile->vnode) {
        AFS_RELE(afile->vnode);
-      }
-      
-      osi_FreeSmallSpace(afile);
-      return 0;
+    }
+
+    osi_FreeSmallSpace(afile);
+    return 0;
 }
 
-int osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize)
+int
+osi_UFSTruncate(struct osi_file *afile, afs_int32 asize)
 {
-    struct AFS_UCRED *oldCred;
+    afs_ucred_t *oldCred;
     struct vattr tvattr;
-    register afs_int32 code;
+    afs_int32 code;
     struct osi_stat tstat;
     AFS_STATCNT(osi_Truncate);
 
@@ -103,64 +105,69 @@ int osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize)
      * small enough.  Check now and save some time.
      */
     code = afs_osi_Stat(afile, &tstat);
-    if (code || tstat.size <= asize) return code;
-    MObtainWriteLock(&afs_xosi,321);    
+    if (code || tstat.size <= asize)
+       return code;
+    ObtainWriteLock(&afs_xosi, 321);
     VATTR_NULL(&tvattr);
     /* note that this credential swapping stuff is only necessary because
-       of ufs's references directly to u.u_cred instead of to
-       credentials parameter.  Probably should fix ufs some day. */
+     * of ufs's references directly to u.u_cred instead of to
+     * credentials parameter.  Probably should fix ufs some day. */
     oldCred = p_cred(u.u_procp);
     set_p_cred(u.u_procp, &afs_osi_cred);
     tvattr.va_size = asize;
     AFS_GUNLOCK();
     code = VOP_SETATTR(afile->vnode, &tvattr, &afs_osi_cred, 0);
     AFS_GLOCK();
-    set_p_cred(u.u_procp, oldCred);     /* restore */
-    MReleaseWriteLock(&afs_xosi);
+    set_p_cred(u.u_procp, oldCred);    /* restore */
+    ReleaseWriteLock(&afs_xosi);
     return code;
 }
 
-void osi_DisableAtimes(struct vnode *avp)
+void
+osi_DisableAtimes(struct vnode *avp)
 {
-   struct inode *ip = VTOI(avp);
-   ip->i_flag &= ~IACC;
+    struct inode *ip = VTOI(avp);
+    ip->i_flag &= ~IACC;
 }
 
 
 /* Generic read interface */
-int afs_osi_Read(register struct osi_file *afile, int offset, void *aptr, afs_int32 asize)
+int
+afs_osi_Read(struct osi_file *afile, int offset, void *aptr,
+            afs_int32 asize)
 {
-    struct AFS_UCRED *oldCred;
+    afs_ucred_t *oldCred;
     long resid;
-    register afs_int32 code;
-    register afs_int32 cnt1=0;
+    afs_int32 code;
+    afs_int32 cnt1 = 0;
     AFS_STATCNT(osi_Read);
 
     /**
       * If the osi_file passed in is NULL, panic only if AFS is not shutting
       * down. No point in crashing when we are already shutting down
       */
-    if ( !afile ) {
-       if ( !afs_shuttingdown )
+    if (!afile) {
+       if (!afs_shuttingdown)
            osi_Panic("osi_Read called with null param");
        else
-           return EIO;
+           return -EIO;
     }
 
-    if (offset != -1) afile->offset = offset;
-retry_IO:
+    if (offset != -1)
+       afile->offset = offset;
+  retry_IO:
     AFS_GUNLOCK();
-    code = gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, afile->offset,
-                 AFS_UIOSYS, IO_UNIT, &resid);
+    code =
+       gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, afile->offset,
+                AFS_UIOSYS, IO_UNIT, &resid);
     AFS_GLOCK();
     if (code == 0) {
        code = asize - resid;
        afile->offset += code;
        osi_DisableAtimes(afile->vnode);
-    }
-    else {
-       afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, (afs_int32) resid,
-                ICL_TYPE_INT32, code);
+    } else {
+       afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32,
+                  (afs_int32) resid, ICL_TYPE_INT32, code);
        /*
         * To handle periodic low-level EFAULT failures that we've seen with the
         * Weitek chip; in all observed failed cases a second read succeeded.
@@ -169,49 +176,52 @@ retry_IO:
            afs_stats_cmperf.osiread_efaults++;
            goto retry_IO;
        }
-        setuerror(code);
+       setuerror(code);
        code = -1;
     }
     return code;
 }
 
 /* Generic write interface */
-int afs_osi_Write(register struct osi_file *afile, afs_int32 offset, void *aptr, afs_int32 asize)
+int
+afs_osi_Write(struct osi_file *afile, afs_int32 offset, void *aptr,
+             afs_int32 asize)
 {
-    struct AFS_UCRED *oldCred;
+    afs_ucred_t *oldCred;
     long resid;
-    register afs_int32 code;
+    afs_int32 code;
     AFS_STATCNT(osi_Write);
-    if ( !afile )
-        osi_Panic("afs_osi_Write called with null param");
-    if (offset != -1) afile->offset = offset;
+    if (!afile)
+       osi_Panic("afs_osi_Write called with null param");
+    if (offset != -1)
+       afile->offset = offset;
     AFS_GUNLOCK();
-    code = gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize, afile->offset,
-                 AFS_UIOSYS, IO_UNIT, &resid);
+    code =
+       gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize,
+                afile->offset, AFS_UIOSYS, IO_UNIT, &resid);
     AFS_GLOCK();
     if (code == 0) {
        code = asize - resid;
        afile->offset += code;
-    }
-    else {
-       if (code == ENOSPC) afs_warnuser("\n\n\n*** Cache partition is FULL - Decrease cachesize!!! ***\n\n");
+    } else {
+       if (code == ENOSPC)
+           afs_warnuser
+               ("\n\n\n*** Cache partition is FULL - Decrease cachesize!!! ***\n\n");
        setuerror(code);
        code = -1;
     }
     if (afile->proc) {
-       (*afile->proc)(afile, code);
+       (*afile->proc) (afile, code);
     }
     return code;
 }
 
 
-void shutdown_osifile(void)
+void
+shutdown_osifile(void)
 {
-  extern int afs_cold_shutdown;
-
-  AFS_STATCNT(shutdown_osifile);
-  if (afs_cold_shutdown) {
-    afs_osicred_initialized = 0;
-  }
+    AFS_STATCNT(shutdown_osifile);
+    if (afs_cold_shutdown) {
+       afs_osicred_initialized = 0;
+    }
 }
-