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.
Change-Id: I225387a574b1301516a9313838bbcb86e9e14b8d
Reviewed-on: http://gerrit.openafs.org/3176
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Tested-by: Derrick Brashear <shadow@dementia.org>
/* 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
/* 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
#define IH_CONDSYNC(H) ih_condsync(H)
#ifdef HAVE_PIO
+#ifdef AFS_NT40_ENV
+#define OS_PREAD(FD, B, S, O) nt_pread(FD, B, S, O)
+#define OS_PWRITE(FD, B, S, O) nt_pwrite(FD, B, S, O)
+#else
#ifdef O_LARGEFILE
#define OS_PREAD(FD, B, S, O) pread64(FD, B, S, O)
#define OS_PWRITE(FD, B, S, O) pwrite64(FD, B, S, O)
#define OS_PREAD(FD, B, S, O) pread(FD, B, S, O)
#define OS_PWRITE(FD, B, S, O) pwrite(FD, B, S, O)
#endif /* !O_LARGEFILE */
+#endif /* AFS_NT40_ENV */
#else /* !HAVE_PIO */
extern ssize_t ih_pread(int fd, void * buf, size_t count, afs_foff_t offset);
extern ssize_t ih_pwrite(int fd, const void * buf, size_t count, afs_foff_t offset);
}
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)
{
BOOL code;
}
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)
{
int nBytes;
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);