diff options
author | Bruce Cran <bruce@cran.org.uk> | 2011-01-04 10:59:30 +0100 |
---|---|---|
committer | Jens Axboe <jaxboe@fusionio.com> | 2011-01-04 10:59:30 +0100 |
commit | ecc314ba7c5f02b7e90ac1dfbce1a74cd4e6d6fe (patch) | |
tree | 6ffdc338398b8426022d7e32a185db4ffb41d58f /os/os-windows.h | |
parent | 03e20d687566753b90383571e5e152c5142bdffd (diff) | |
download | fio-ecc314ba7c5f02b7e90ac1dfbce1a74cd4e6d6fe.tar.gz fio-ecc314ba7c5f02b7e90ac1dfbce1a74cd4e6d6fe.tar.bz2 |
FIO Windows update
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
Diffstat (limited to 'os/os-windows.h')
-rw-r--r-- | os/os-windows.h | 81 |
1 files changed, 38 insertions, 43 deletions
diff --git a/os/os-windows.h b/os/os-windows.h index f5da6a5d..74c0f9e8 100644 --- a/os/os-windows.h +++ b/os/os-windows.h @@ -4,7 +4,11 @@ #include <sys/types.h>
#include <errno.h>
+#include <windows.h>
+#include "../smalloc.h"
+#include "../file.h"
+#include "../log.h"
#define FIO_HAVE_ODIRECT
#define FIO_USE_GENERIC_RAND
@@ -15,28 +19,11 @@ #define FIO_HAVE_FDATASYNC
#define FIO_HAVE_WINDOWSAIO
-/* TODO add support for FIO_HAVE_CPU_AFFINITY */
-
#define OS_MAP_ANON MAP_ANON
-typedef off_t off64_t;
-
-
-#define FIO_NOTUNIX
-
-#include <windows.h>
-#include <io.h>
+#define OS_CLOCK CLOCK_REALTIME
-typedef void* HANDLE;
-
-BOOL WINAPI GetFileSizeEx(
- HANDLE hFile,
- PLARGE_INTEGER lpFileSize
-);
-
-long _get_osfhandle(
- int fd
-);
+typedef off_t off64_t;
typedef struct {
LARGE_INTEGER Length;
@@ -44,42 +31,50 @@ typedef struct { #define IOCTL_DISK_GET_LENGTH_INFO 0x7405C
-
-static inline int blockdev_size(int fd, unsigned long long *bytes)
+static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
{
int rc = 0;
- HANDLE hFile = (HANDLE)_get_osfhandle(fd);
- if (hFile != INVALID_HANDLE_VALUE)
- {
- GET_LENGTH_INFORMATION info;
- DWORD outBytes;
- LARGE_INTEGER size;
- size.QuadPart = 0;
- if (DeviceIoControl(hFile, IOCTL_DISK_GET_LENGTH_INFO, NULL, 0, &info, sizeof(info), &outBytes, NULL))
- *bytes = info.Length.QuadPart;
- else
- rc = EIO;
+ HANDLE hFile;
+
+ if (f->hFile == NULL) {
+ hFile = CreateFile(f->file_name, (GENERIC_READ | GENERIC_WRITE),
+ (FILE_SHARE_READ | FILE_SHARE_WRITE), NULL, OPEN_EXISTING, 0, NULL);
+ } else {
+ hFile = f->hFile;
}
- return 0;
+ GET_LENGTH_INFORMATION info;
+ DWORD outBytes;
+ LARGE_INTEGER size;
+ size.QuadPart = 0;
+ if (DeviceIoControl(hFile, IOCTL_DISK_GET_LENGTH_INFO, NULL, 0, &info, sizeof(info), &outBytes, NULL))
+ *bytes = info.Length.QuadPart;
+ else
+ rc = EIO;
+ }
+
+ /* If we were passed a POSIX fd,
+ * close the HANDLE we created via CreateFile */
+ if (hFile != INVALID_HANDLE_VALUE && f->hFile == NULL)
+ CloseHandle(hFile);
+
+ return rc;
}
-static inline int chardev_size(int fd, unsigned long long *bytes)
+static inline int chardev_size(struct fio_file *f, unsigned long long *bytes)
{
- return blockdev_size(fd, bytes);
+ return blockdev_size(f, bytes);
}
-static inline int blockdev_invalidate_cache(int fd)
{
- int rc = 0;
- HANDLE hFile = (HANDLE)_get_osfhandle(fd);
- if (hFile != INVALID_HANDLE_VALUE)
- FlushFileBuffers(hFile);
- else
- rc = EIO;
+static inline int blockdev_invalidate_cache(struct fio_file *f)
+{
+ BOOL bSuccess = FlushFileBuffers(f->hFile);
+ if (!bSuccess)
+ log_info("blockdev_invalidate_cache - FlushFileBuffers failed\n");
- return rc;
+ return 0;
}
static inline unsigned long long os_phys_mem(void)
|