dir/vol: Die() really does
[openafs.git] / src / volser / physio.c
index ea9a97f..0045100 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2000, International Business Machines Corporation and others.
  * All Rights Reserved.
- * 
+ *
  * This software has been released under the terms of the IBM Public
  * License.  For details, see the LICENSE file in the top-level source
  * directory or online at http://www.openafs.org/dl/license10.html
 #include <afsconfig.h>
 #include <afs/param.h>
 
-RCSID("$Header$");
-
-#include <sys/types.h>
-#ifdef AFS_NT40_ENV
-#include <fcntl.h>
-#else
-#include <sys/file.h>
-#include <netinet/in.h>
-#include <unistd.h>
-#endif
-#ifdef AFS_SUN5_ENV
-#include <sys/fcntl.h>
-#endif
-#include <errno.h>
+#include <roken.h>
+
 #include <rx/xdr.h>
 #include <rx/rx.h>
-#include <stdio.h>
 #include <afs/afsint.h>
 #include <afs/nfs.h>
-#include <afs/assert.h>
+#include <afs/afs_assert.h>
 #include <afs/dir.h>
 #include <afs/ihandle.h>
+
 #include "vol.h"
+#include "physio.h"
 
 /* returns 0 on success, errno on failure */
-int ReallyRead (file, block, data)
-DirHandle     *        file;
-int            block;
-char         * data;
+int
+ReallyRead(DirHandle * file, int block, char *data)
 {
     FdHandle_t *fdP;
     int code;
+    ssize_t nBytes;
     errno = 0;
     fdP = IH_OPEN(file->dirh_handle);
     if (fdP == NULL) {
        code = errno;
        return code;
     }
-    if (FDH_SEEK(fdP, block*AFS_PAGESIZE, SEEK_SET) < 0) {
-       code = errno;
-       FDH_REALLYCLOSE(fdP);
-       return code;
-    }
-    code = FDH_READ(fdP, data, AFS_PAGESIZE);
-    if (code != AFS_PAGESIZE) {
-       if (code < 0)
+    nBytes = FDH_PREAD(fdP, data, AFS_PAGESIZE, ((afs_foff_t)block) * AFS_PAGESIZE);
+    if (nBytes != AFS_PAGESIZE) {
+       if (nBytes < 0)
            code = errno;
-       else 
+       else
            code = EIO;
        FDH_REALLYCLOSE(fdP);
        return code;
@@ -67,14 +50,13 @@ char              * data;
 }
 
 /* returns 0 on success, errno on failure */
-int ReallyWrite (file, block, data)
-DirHandle     *        file;
-int            block;
-char         * data;
+int
+ReallyWrite(DirHandle * file, int block, char *data)
 {
     FdHandle_t *fdP;
     extern int VolumeChanged;
     int code;
+    ssize_t nBytes;
 
     errno = 0;
 
@@ -83,16 +65,11 @@ char              * data;
        code = errno;
        return code;
     }
-    if (FDH_SEEK(fdP, block*AFS_PAGESIZE, SEEK_SET) < 0) {
-       code = errno;
-       FDH_REALLYCLOSE(fdP);
-       return code;
-    }
-    code = FDH_WRITE(fdP, data, AFS_PAGESIZE);
-    if (code != AFS_PAGESIZE) {
-       if (code < 0)
+    nBytes = FDH_PWRITE(fdP, data, AFS_PAGESIZE, ((afs_foff_t)block) * AFS_PAGESIZE);
+    if (nBytes != AFS_PAGESIZE) {
+       if (nBytes < 0)
            code = errno;
-       else 
+       else
            code = EIO;
        FDH_REALLYCLOSE(fdP);
        return code;
@@ -106,14 +83,12 @@ char             * data;
  * Create a handle to a directory entry and reference it (IH_INIT).
  * The handle needs to be dereferenced with the FidZap() routine.
  */
-SetSalvageDirHandle(dir, volume, device, inode)
-DirHandle *dir;
-afs_int32 volume;
-Inode inode;
-afs_int32 device;
+void
+SetSalvageDirHandle(DirHandle * dir, afs_uint32 volume, afs_int32 device,
+                    Inode inode)
 {
-    private SalvageCacheCheck = 1;
-    bzero(dir, sizeof(DirHandle));
+    private int SalvageCacheCheck = 1;
+    memset(dir, 0, sizeof(DirHandle));
 
     dir->dirh_volume = volume;
     dir->dirh_device = device;
@@ -121,58 +96,54 @@ afs_int32 device;
     IH_INIT(dir->dirh_handle, device, volume, inode);
 
     /* Always re-read for a new dirhandle */
-    dir->dirh_cacheCheck = SalvageCacheCheck++;        
+    dir->dirh_cacheCheck = SalvageCacheCheck++;
 }
 
-FidZap (file)
-DirHandle     *        file;
-
+void
+FidZap(DirHandle * file)
 {
     IH_RELEASE(file->dirh_handle);
-    bzero(file, sizeof(DirHandle));
+    memset(file, 0, sizeof(DirHandle));
 }
 
-FidZero (file)
-DirHandle     *        file;
-
+void
+FidZero(DirHandle * file)
 {
-    bzero(file, sizeof(DirHandle));
+    memset(file, 0, sizeof(DirHandle));
 }
 
-FidEq (afile, bfile)
-DirHandle      * afile;
-DirHandle      * bfile;
-
+int
+FidEq(DirHandle * afile, DirHandle * bfile)
 {
-    if (afile->dirh_volume != bfile->dirh_volume) return 0;
-    if (afile->dirh_device != bfile->dirh_device) return 0;
-    if (afile->dirh_cacheCheck != bfile->dirh_cacheCheck) return 0;
-    if (afile->dirh_inode != bfile->dirh_inode) return 0;
+    if (afile->dirh_volume != bfile->dirh_volume)
+       return 0;
+    if (afile->dirh_device != bfile->dirh_device)
+       return 0;
+    if (afile->dirh_cacheCheck != bfile->dirh_cacheCheck)
+       return 0;
+    if (afile->dirh_inode != bfile->dirh_inode)
+       return 0;
     return 1;
 }
 
-FidVolEq (afile, vid)
-DirHandle      * afile;
-afs_int32            vid;
-
+int
+FidVolEq(DirHandle * afile, afs_int32 vid)
 {
-    if (afile->dirh_volume != vid) return 0;
+    if (afile->dirh_volume != vid)
+       return 0;
     return 1;
 }
 
-FidCpy (tofile, fromfile)
-DirHandle      * tofile;
-DirHandle      * fromfile;
-
+void
+FidCpy(DirHandle * tofile, DirHandle * fromfile)
 {
     *tofile = *fromfile;
     IH_COPY(tofile->dirh_handle, fromfile->dirh_handle);
 }
 
-Die (msg)
-char  * msg;
-
+void
+Die(const char *msg)
 {
-    printf("%s\n",msg);
-    assert(1==2);
+    printf("%s\n", msg);
+    osi_Panic("%s\n", msg);
 }