vol: Tidy header includes
[openafs.git] / src / vol / ihandle.c
index 2985bff..9bfdd9e 100644 (file)
 #include <afsconfig.h>
 #include <afs/param.h>
 
+#include <roken.h>
+
+#include <limits.h>
 
-#include <stdio.h>
-#include <sys/types.h>
-#include <errno.h>
-#include <string.h>
-#ifdef AFS_NT40_ENV
-#include <fcntl.h>
-#else
-#include <sys/file.h>
-#include <unistd.h>
-#include <sys/stat.h>
 #if defined(AFS_SUN5_ENV) || defined(AFS_NBSD_ENV)
 #include <sys/fcntl.h>
 #include <sys/resource.h>
 #endif
-#endif
 
 #include <rx/xdr.h>
 #include <afs/afsint.h>
-#include <errno.h>
 #include <afs/afssyscalls.h>
+
 #include "nfs.h"
 #include "ihandle.h"
 #include "viceinode.h"
 #include "afs/afs_assert.h"
-#include <limits.h>
-
-#ifndef AFS_NT40_ENV
-#ifdef O_LARGEFILE
-#define afs_stat       stat64
-#define afs_fstat      fstat64
-#else /* !O_LARGEFILE */
-#define        afs_stat        stat
-#define        afs_fstat       fstat
-#endif /* !O_LARGEFILE */
-#endif /* AFS_NT40_ENV */
 
 #ifdef AFS_PTHREAD_ENV
 pthread_once_t ih_glock_once = PTHREAD_ONCE_INIT;
@@ -302,6 +283,8 @@ fdHandleAllocateChunk(void)
        fdP[i].fd_refcnt = 0;
        fdP[i].fd_ih = NULL;
        fdP[i].fd_fd = INVALID_FD;
+        fdP[i].fd_ihnext = NULL;
+        fdP[i].fd_ihprev = NULL;
        DLL_INSERT_TAIL(&fdP[i], fdAvailHead, fdAvailTail, fd_next, fd_prev);
     }
 }
@@ -353,8 +336,8 @@ ih_open(IHandle_t * ihP)
 #endif /* HAVE_PIO */
            fdP->fd_refcnt++;
            if (fdP->fd_status == FD_HANDLE_OPEN) {
-           fdP->fd_status = FD_HANDLE_INUSE;
-           DLL_DELETE(fdP, fdLruHead, fdLruTail, fd_next, fd_prev);
+               fdP->fd_status = FD_HANDLE_INUSE;
+               DLL_DELETE(fdP, fdLruHead, fdLruTail, fd_next, fd_prev);
            }
            ihP->ih_refcnt++;
            IH_UNLOCK;
@@ -459,9 +442,9 @@ fd_close(FdHandle_t * fdP)
 
     fdP->fd_refcnt--;
     if (fdP->fd_refcnt == 0) {
-    /* Put this descriptor back into the cache */
-    fdP->fd_status = FD_HANDLE_OPEN;
-    DLL_INSERT_TAIL(fdP, fdLruHead, fdLruTail, fd_next, fd_prev);
+       /* Put this descriptor back into the cache */
+       fdP->fd_status = FD_HANDLE_OPEN;
+       DLL_INSERT_TAIL(fdP, fdLruHead, fdLruTail, fd_next, fd_prev);
     }
 
     /* If this is not the only reference to the Inode then we can decrement
@@ -501,13 +484,13 @@ fd_reallyclose(FdHandle_t * fdP)
     fdP->fd_refcnt--;
 
     if (fdP->fd_refcnt == 0) {
-    DLL_DELETE(fdP, ihP->ih_fdhead, ihP->ih_fdtail, fd_ihnext, fd_ihprev);
-    DLL_INSERT_TAIL(fdP, fdAvailHead, fdAvailTail, fd_next, fd_prev);
+       DLL_DELETE(fdP, ihP->ih_fdhead, ihP->ih_fdtail, fd_ihnext, fd_ihprev);
+       DLL_INSERT_TAIL(fdP, fdAvailHead, fdAvailTail, fd_next, fd_prev);
 
-    fdP->fd_status = FD_HANDLE_AVAIL;
-    fdP->fd_refcnt = 0;
-    fdP->fd_ih = NULL;
-    fdP->fd_fd = INVALID_FD;
+       fdP->fd_status = FD_HANDLE_AVAIL;
+       fdP->fd_refcnt = 0;
+       fdP->fd_ih = NULL;
+       fdP->fd_fd = INVALID_FD;
     }
 
     /* All the file descriptor handles have been closed; reset
@@ -519,10 +502,10 @@ fd_reallyclose(FdHandle_t * fdP)
     }
 
     if (fdP->fd_refcnt == 0) {
-    IH_UNLOCK;
-    OS_CLOSE(closeFd);
-    IH_LOCK;
-    fdInUseCount -= 1;
+       IH_UNLOCK;
+       OS_CLOSE(closeFd);
+       IH_LOCK;
+       fdInUseCount -= 1;
     }
 
     /* If this is not the only reference to the Inode then we can decrement
@@ -868,6 +851,7 @@ ih_reallyclose(IHandle_t * ihP)
     ihP->ih_refcnt++;   /* must not disappear over unlock */
     if (ihP->ih_synced) {
        FdHandle_t *fdP;
+        ihP->ih_synced = 0;
        IH_UNLOCK;
 
        fdP = IH_OPEN(ihP);
@@ -880,7 +864,6 @@ ih_reallyclose(IHandle_t * ihP)
     }
 
     osi_Assert(ihP->ih_refcnt > 0);
-    ihP->ih_synced = 0;
 
     ih_fdclose(ihP);
 
@@ -1043,7 +1026,7 @@ ih_size(FD_t fd)
        return -1;
     return size.QuadPart;
 #else
-    struct afs_stat status;
+    struct afs_stat_st status;
     if (afs_fstat(fd, &status) < 0)
        return -1;
     return status.st_size;