X-Git-Url: https://git.kernel.dk/?a=blobdiff_plain;f=os%2Fos-windows.h;h=e790a51322b3ce10b422c7c3894526cdba481036;hb=7d130d8d2a5638ca91dc81ec085acef4d3c3ad08;hp=f5da6a5d583d53c737b3529a596f50e177f5f7d7;hpb=03e20d687566753b90383571e5e152c5142bdffd;p=fio.git diff --git a/os/os-windows.h b/os/os-windows.h index f5da6a5d..e790a513 100644 --- a/os/os-windows.h +++ b/os/os-windows.h @@ -1,10 +1,13 @@ #ifndef FIO_OS_WINDOWS_H #define FIO_OS_WINDOWS_H - #include #include +#include +#include "../smalloc.h" +#include "../file.h" +#include "../log.h" #define FIO_HAVE_ODIRECT #define FIO_USE_GENERIC_RAND @@ -15,28 +18,13 @@ #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 OS_CLOCK CLOCK_REALTIME +#define FIO_PREFERRED_ENGINE "windowsaio" -#define FIO_NOTUNIX - -#include -#include - -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 +32,45 @@ 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, 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) +static inline int blockdev_invalidate_cache(struct fio_file *f) { - int rc = 0; - HANDLE hFile = (HANDLE)_get_osfhandle(fd); - - if (hFile != INVALID_HANDLE_VALUE) - FlushFileBuffers(hFile); - else - rc = EIO; - - return rc; + /* There's no way to invalidate the cache in Windows + * so just pretend to succeed */ + return 0; } static inline unsigned long long os_phys_mem(void) @@ -100,5 +91,4 @@ static inline void os_get_tmpdir(char *path, int len) #define FIO_MADV_FREE MADV_FREE #endif - #endif /* FIO_OS_WINDOWS_H */