]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
ihandle: Add FDH_ISUNLINKED
authorAndrew Deason <adeason@sinenomine.net>
Fri, 21 Dec 2012 18:30:24 +0000 (12:30 -0600)
committerStephan Wiesand <stephan.wiesand@desy.de>
Thu, 4 Apr 2013 13:50:43 +0000 (06:50 -0700)
Add the FDH_ISUNLINKED functionality to ihandle. This lets the caller
know if the file for the underlying file descriptor has been deleted
out from under us. This is useful for sanity checks in some callers.

Reviewed-on: http://gerrit.openafs.org/8838
Reviewed-by: Chas Williams - CONTRACTOR <chas@cmf.nrl.navy.mil>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@your-file-system.com>
(cherry picked from commit 9cf9a0e978ece2b0afb8ba5947455f307a424cab)

Change-Id: If5cde825a2e7413c47409c69f15507d6df1934c3
Reviewed-on: http://gerrit.openafs.org/9507
Reviewed-by: Derrick Brashear <shadow@your-file-system.com>
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Stephan Wiesand <stephan.wiesand@desy.de>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
src/vol/ihandle.c
src/vol/ihandle.h

index e9cb7a8fade8633dd6abed0e208a32f8a89dcdd3..4ae1441a701c29250d5677d030ae63b2216d1459 100644 (file)
@@ -1089,3 +1089,18 @@ ih_pwrite(int fd, const void * buf, size_t count, afs_foff_t offset)
        return OS_WRITE(fd, buf, count);
 }
 #endif /* !HAVE_PIO */
+
+#ifndef AFS_NT40_ENV
+int
+ih_isunlinked(int fd)
+{
+    struct afs_stat status;
+    if (afs_fstat(fd, &status) < 0) {
+       return -1;
+    }
+    if (status.st_nlink < 1) {
+       return 1;
+    }
+    return 0;
+}
+#endif /* !AFS_NT40_ENV */
index ba4a8311778d1b6cd062bf99635bd0bfc09aaf59..cb6adcf37c8e788f14488e2dca3ee1af511844fb 100644 (file)
@@ -61,6 +61,7 @@
  * status information:
  * FDH_SIZE - returns the size of the file.
  * FDH_NLINK - returns the link count of the file.
+ * FDH_ISUNLINKED - returns if the file has been unlinked out from under us
  *
  * Miscellaneous:
  * FDH_FDOPEN - create a descriptor for buffered I/O
@@ -386,6 +387,8 @@ extern ssize_t ih_pwrite(int fd, const void * buf, size_t count, afs_foff_t offs
 # define OS_UNLOCKFILE(FD, O) (!UnlockFile(FD, (DWORD)((O) & 0xFFFFFFFF), (DWORD)((O) >> 32), 2, 0))
 # define OS_ERROR(X) nterr_nt2unix(GetLastError(), X)
 # define OS_UNLINK(X) nt_unlink(X)
+/* we can't have a file unlinked out from under us on NT */
+# define OS_ISUNLINKED(X) (0)
 # define OS_DIRSEP "\\"
 # define OS_DIRSEPC '\\'
 #else
@@ -393,6 +396,8 @@ extern ssize_t ih_pwrite(int fd, const void * buf, size_t count, afs_foff_t offs
 # define OS_UNLOCKFILE(FD, O) flock(FD, LOCK_UN)
 # define OS_ERROR(X) X
 # define OS_UNLINK(X) unlink(X)
+# define OS_ISUNLINKED(X) ih_isunlinked(X)
+extern int ih_isunlinked(FD_t fd);
 # define OS_DIRSEP "/"
 # define OS_DIRSEPC '/'
 #endif
@@ -550,5 +555,6 @@ extern afs_sfsize_t ih_size(FD_t);
 #define FDH_SIZE(H) OS_SIZE((H)->fd_fd)
 #define FDH_LOCKFILE(H, O) OS_LOCKFILE((H)->fd_fd, O)
 #define FDH_UNLOCKFILE(H, O) OS_UNLOCKFILE((H)->fd_fd, O)
+#define FDH_ISUNLINKED(H) OS_ISUNLINKED((H)->fd_fd)
 
 #endif /* _IHANDLE_H_ */