From 3b0dbf3c86b98a66e1723b65da0a2761eeede651 Mon Sep 17 00:00:00 2001 From: Rod Widdowson Date: Thu, 28 Oct 2010 00:20:30 +0200 Subject: [PATCH] windows: native versions of ih_pread and ih_pwrite Separate the windows code out in ihandle.c to reduce dependency on ntops. As an aid to future threading issues, pass the offset in an OVERLAP rather than doing a separate SetFilePointerEx. Reviewed-on: http://gerrit.openafs.org/3176 Reviewed-by: Derrick Brashear Reviewed-by: Andrew Deason Tested-by: Derrick Brashear (cherry picked from commit 50b6a116a1c412d0e6d7442d13d6e92c9dbb35ee) Change-Id: Iaa340515bf36d249d4f2160b55c3fbb267bb90ee Reviewed-on: http://gerrit.openafs.org/3825 Tested-by: BuildBot Reviewed-by: Derrick Brashear --- src/config/afsconfig-windows.h | 4 +++ src/vol/ntops.c | 52 ++++++++++++++++++++++++++++++++++ src/vol/ntops.h | 2 ++ 3 files changed, 58 insertions(+) diff --git a/src/config/afsconfig-windows.h b/src/config/afsconfig-windows.h index 32369e690..6e7662c49 100644 --- a/src/config/afsconfig-windows.h +++ b/src/config/afsconfig-windows.h @@ -33,6 +33,7 @@ /* Define as the return type of signal handlers (int or void). */ #undef RETSIGTYPE + /* The size of `long', as computed by sizeof. */ #define SIZEOF_LONG 4 @@ -162,6 +163,9 @@ /* define if struct ufsvfs has vfs_dqrwlock */ #undef HAVE_VFS_DQRWLOCK +/* define if you have pread() and pwrite() */ +#define HAVE_PIO 1 + #undef PACKAGE #undef VERSION diff --git a/src/vol/ntops.c b/src/vol/ntops.c index a9e69c984..c14156c93 100644 --- a/src/vol/ntops.c +++ b/src/vol/ntops.c @@ -156,6 +156,31 @@ nt_write(FD_t fd, char *buf, size_t size) return (int)nbytes; } +int +nt_pwrite(FD_t fd, const void * buf, size_t count, afs_foff_t offset) +{ + /* + * same comment as read + */ + + DWORD nbytes; + BOOL code; + OVERLAPPED overlap = {0}; + LARGE_INTEGER liOffset; + + liOffset.QuadPart = offset; + overlap.Offset = liOffset.LowPart; + overlap.OffsetHigh = liOffset.HighPart; + + code = WriteFile((HANDLE) fd, (void *)buf, (DWORD) count, &nbytes, &overlap); + + if (!code) { + errno = nterr_nt2unix(GetLastError(), EBADF); + return -1; + } + return (ssize_t)nbytes; +} + int nt_read(FD_t fd, char *buf, size_t size) { @@ -171,6 +196,33 @@ nt_read(FD_t fd, char *buf, size_t size) return (int)nbytes; } +int +nt_pread(FD_t fd, void * buf, size_t count, afs_foff_t offset) +{ + /* + * This really ought to call NtReadFile + */ + DWORD nbytes; + BOOL code; + OVERLAPPED overlap = {0}; + LARGE_INTEGER liOffset; + /* + * Cast through a LARGE_INTEGER - make no assumption about + * byte ordering and leave that to the compiler.. + */ + liOffset.QuadPart = offset; + overlap.Offset = liOffset.LowPart; + overlap.OffsetHigh = liOffset.HighPart; + + code = ReadFile((HANDLE) fd, (void *)buf, (DWORD) count, &nbytes, &overlap); + + if (!code) { + errno = nterr_nt2unix(GetLastError(), EBADF); + return -1; + } + return (ssize_t)nbytes; +} + int nt_iread(IHandle_t * h, int offset, char *buf, int size) { diff --git a/src/vol/ntops.h b/src/vol/ntops.h index 8ffa46939..a01c4d9a3 100644 --- a/src/vol/ntops.h +++ b/src/vol/ntops.h @@ -25,6 +25,8 @@ extern FD_t nt_open(char *name, int flags, int mode); extern int nt_close(FD_t fd); extern int nt_write(FD_t fd, char *buf, size_t size); extern int nt_read(FD_t fd, char *buf, size_t size); +extern int nt_pread(FD_t fd, void * buf, size_t count, afs_foff_t offset); +extern int nt_pwrite(FD_t fd, const void * buf, size_t count, afs_foff_t offset); extern int nt_size(FD_t fd); extern int nt_getFileCreationTime(FD_t fd, FILETIME * ftime); extern int nt_setFileCreationTime(FD_t fd, FILETIME * ftime); -- 2.39.5