From 93bcfd20e37cef8cec350fe06d3a086724c9f257 Mon Sep 17 00:00:00 2001 From: Bruce Cran Date: Mon, 20 Feb 2012 20:18:19 +0100 Subject: [PATCH] Move Windows port to MinGW - Add calls to WSAStartup in the network code as required by Winsock. - Add Windows-specific init_random_state function which uses the Crypto API. - Move Windows port to MinGW and update build system to create a 64-bit binary by default. - Install text files as .rtf so they won't open in Notepad by default (Wordpad understands Unix line endings; Notepad doesn't). - Simplify WiX installer code. Signed-off-by: Jens Axboe --- HOWTO | 3 +- Makefile | 10 +- README | 19 +- client.c | 5 + diskutil.c | 2 +- engines/mmap.c | 4 +- engines/windowsaio.c | 20 +- file.h | 2 +- helpers.h | 1 + init.c | 42 +- ioengine.h | 2 +- os/os-aix.h | 1 + os/os-freebsd.h | 1 + os/os-hpux.h | 1 + os/os-linux.h | 1 + os/os-mac.h | 1 + os/os-netbsd.h | 1 + os/os-solaris.h | 1 + os/os-windows.h | 472 +- os/os.h | 29 +- os/windows/FIO.lnk | Bin 1422 -> 0 bytes os/windows/cygwin.wxs | 8469 ----------------------- os/windows/dobuild.cmd | 30 +- os/windows/examples.wxs | 62 +- os/windows/fio/FIO.bat | 9 - os/windows/harvest.cmd | 2 - os/windows/install.wxs | 78 +- os/windows/posix/include/arpa/inet.h | 13 + os/windows/posix/include/asm/types.h | 8 + os/windows/posix/include/dirent.h | 16 + os/windows/posix/include/dlfcn.h | 11 + os/windows/posix/include/libgen.h | 6 + os/windows/posix/include/netdb.h | 4 + os/windows/posix/include/netinet/in.h | 21 + os/windows/posix/include/poll.h | 4 + os/windows/posix/include/semaphore.h | 4 + os/windows/posix/include/sys/ipc.h | 4 + os/windows/posix/include/sys/mman.h | 36 + os/windows/posix/include/sys/poll.h | 15 + os/windows/posix/include/sys/resource.h | 18 + os/windows/posix/include/sys/shm.h | 41 + os/windows/posix/include/sys/socket.h | 4 + os/windows/posix/include/sys/uio.h | 16 + os/windows/posix/include/sys/un.h | 14 + os/windows/posix/include/sys/wait.h | 12 + os/windows/posix/include/syslog.h | 18 + server.c | 5 + 47 files changed, 700 insertions(+), 8838 deletions(-) delete mode 100644 os/windows/FIO.lnk delete mode 100755 os/windows/cygwin.wxs mode change 100755 => 100644 os/windows/dobuild.cmd delete mode 100644 os/windows/fio/FIO.bat delete mode 100755 os/windows/harvest.cmd create mode 100644 os/windows/posix/include/arpa/inet.h create mode 100644 os/windows/posix/include/asm/types.h create mode 100644 os/windows/posix/include/dirent.h create mode 100644 os/windows/posix/include/dlfcn.h create mode 100644 os/windows/posix/include/libgen.h create mode 100644 os/windows/posix/include/netdb.h create mode 100644 os/windows/posix/include/netinet/in.h create mode 100644 os/windows/posix/include/poll.h create mode 100644 os/windows/posix/include/semaphore.h create mode 100644 os/windows/posix/include/sys/ipc.h create mode 100644 os/windows/posix/include/sys/mman.h create mode 100644 os/windows/posix/include/sys/poll.h create mode 100644 os/windows/posix/include/sys/resource.h create mode 100644 os/windows/posix/include/sys/shm.h create mode 100644 os/windows/posix/include/sys/socket.h create mode 100644 os/windows/posix/include/sys/uio.h create mode 100644 os/windows/posix/include/sys/un.h create mode 100644 os/windows/posix/include/sys/wait.h create mode 100644 os/windows/posix/include/syslog.h diff --git a/HOWTO b/HOWTO index da037d2b..0a3351c3 100644 --- a/HOWTO +++ b/HOWTO @@ -627,6 +627,7 @@ iodepth_low=int The low water mark indicating when to start filling direct=bool If value is true, use non-buffered io. This is usually O_DIRECT. Note that ZFS on Solaris doesn't support direct io. + On Windows the synchronous ioengines don't support direct io. buffered=bool If value is true, use buffered io. This is the opposite of the 'direct' option. Defaults to true. @@ -644,7 +645,7 @@ fsync=int If writing to a file, issue a sync of the dirty data fdatasync=int Like fsync= but uses fdatasync() to only sync data and not metadata blocks. - In FreeBSD there is no fdatasync(), this falls back to + In FreeBSD and Windows there is no fdatasync(), this falls back to using fsync() sync_file_range=str:val Use sync_file_range() for every 'val' number of diff --git a/Makefile b/Makefile index 8cce80ff..673107f0 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ PROGS = fio SCRIPTS = fio_generate_plots UNAME := $(shell uname) -SOURCE = gettime.c fio.c ioengines.c init.c stat.c log.c time.c filesetup.c \ +SOURCE := gettime.c fio.c ioengines.c init.c stat.c log.c time.c filesetup.c \ eta.c verify.c memory.c io_u.c parse.c mutex.c options.c \ rbtree.c smalloc.c filehash.c profile.c debug.c lib/rand.c \ lib/num2str.c lib/ieee754.c $(wildcard crc/*.c) engines/cpu.c \ @@ -56,9 +56,11 @@ ifeq ($(UNAME), Darwin) LIBS += -lpthread -ldl endif ifneq (,$(findstring CYGWIN,$(UNAME))) - SOURCE += engines/windowsaio.c - LIBS += -lpthread -lrt -lpsapi - CFLAGS += -DPSAPI_VERSION=1 + SOURCE := $(filter-out engines/mmap.c,$(SOURCE)) + SOURCE += engines/windowsaio.c os/windows/posix.c + LIBS += -lpthread -lpsapi -lws2_32 + CFLAGS += -DPSAPI_VERSION=1 -Ios/windows/posix/include -Wno-format + CC = x86_64-w64-mingw32-gcc endif OBJS = $(SOURCE:.c=.o) diff --git a/README b/README index 03e6751c..c21fb6a9 100644 --- a/README +++ b/README @@ -109,21 +109,10 @@ based distros, it's typically called libaio-devel. Windows ------- -On Windows Cygwin (http://www.cygwin.com) is required with at least -devel/gcc4 and devel/make installed in order to build fio, and -admin/cygrunsrv to run it. You can also install devel/git to fetch/update -the source files. To create an MSI installer package put a copy of Cygwin -in os\windows\fio, install WiX 3.6 from http://wix.sourceforge.net/releases/ -and run dobuild.cmd from the os/windows directory. - -Before running fio you'll need to have a copy of cygserver running. Run -"/usr/bin/cygserver-config" from an elevated Cygwin shell (i.e. launch the -Cygwin shell under the Administrator account) to configure it. Once -configured, run "net start cygserver" to start it, or type -"/usr/sbin/cygserver &" in the Cygwin shell to start a local copy. - -If fio exits with the message "Bad system call" it normally means that -Cygserver isn't running. +On Windows MinGW (http://www.mingw.org/) is required in order to +build fio. To create an MSI installer package install WiX 3.6 from +http://wix.sourceforge.net/releases/ and run dobuild.cmd from the +os/windows directory. Command line diff --git a/client.c b/client.c index f1675492..ace70d35 100644 --- a/client.c +++ b/client.c @@ -404,6 +404,11 @@ int fio_clients_connect(void) struct flist_head *entry, *tmp; int ret; +#ifdef WIN32 + WSADATA wsd; + WSAStartup(MAKEWORD(2,2), &wsd); +#endif + dprint(FD_NET, "client: connect all\n"); client_signal_handler(); diff --git a/diskutil.c b/diskutil.c index 47d739bb..feb88526 100644 --- a/diskutil.c +++ b/diskutil.c @@ -31,7 +31,7 @@ static void disk_util_free(struct disk_util *du) flist_del(&slave->slavelist); slave->users--; } - + fio_mutex_remove(du->lock); sfree(du); } diff --git a/engines/mmap.c b/engines/mmap.c index 79238b1e..c1aff5ba 100644 --- a/engines/mmap.c +++ b/engines/mmap.c @@ -59,7 +59,7 @@ static int fio_mmap_file(struct thread_data *td, struct fio_file *f, err: if (td->error && f->mmap_ptr) munmap(f->mmap_ptr, length); - + return td->error; } @@ -200,7 +200,7 @@ static int fio_mmapio_init(struct thread_data *td) break; shift++; } while (1); - + mmap_map_mask = 1UL << shift; return 0; } diff --git a/engines/windowsaio.c b/engines/windowsaio.c index 45d23d20..766cc5d4 100644 --- a/engines/windowsaio.c +++ b/engines/windowsaio.c @@ -1,6 +1,6 @@ /* * Native Windows async IO engine - * Copyright (C) 2011 Bruce Cran + * Copyright (C) 2012 Bruce Cran */ #include @@ -113,9 +113,9 @@ static int fio_windowsaio_init(struct thread_data *td) } hKernel32Dll = GetModuleHandle("kernel32.dll"); - wd->pCancelIoEx = GetProcAddress(hKernel32Dll, "CancelIoEx"); - + wd->pCancelIoEx = (CANCELIOEX)GetProcAddress(hKernel32Dll, "CancelIoEx"); td->io_ops->data = wd; + return rc; } @@ -133,8 +133,9 @@ static void fio_windowsaio_cleanup(struct thread_data *td) CloseHandle(wd->iothread); CloseHandle(wd->iocomplete_event); - for (i = 0; i < td->o.iodepth; i++) + for (i = 0; i < td->o.iodepth; i++) { CloseHandle(wd->ovls[i].o.hEvent); + } free(wd->aio_events); free(wd->ovls); @@ -171,6 +172,10 @@ static int fio_windowsaio_open_file(struct thread_data *td, struct fio_file *f) if (td->o.sync_io) flags |= FILE_FLAG_WRITE_THROUGH; + /* + * Inform Windows whether we're going to be doing sequential or + * random io so it can tune the Cache Manager + */ if (td->o.td_ddir == TD_DDIR_READ || td->o.td_ddir == TD_DDIR_WRITE) flags |= FILE_FLAG_SEQUENTIAL_SCAN; @@ -182,7 +187,7 @@ static int fio_windowsaio_open_file(struct thread_data *td, struct fio_file *f) else access = (GENERIC_READ | GENERIC_WRITE); - if (td->o.create_on_open > 0) + if (td->o.create_on_open) openmode = OPEN_ALWAYS; else openmode = OPEN_EXISTING; @@ -193,7 +198,7 @@ static int fio_windowsaio_open_file(struct thread_data *td, struct fio_file *f) if (f->hFile == INVALID_HANDLE_VALUE) rc = 1; - /* Only set up the competion port and thread if we're not just + /* Only set up the completion port and thread if we're not just * querying the device size */ if (!rc && td->io_ops->data != NULL) { struct thread_ctx *ctx; @@ -308,7 +313,7 @@ static int fio_windowsaio_queue(struct thread_data *td, struct io_u *io_u) LPOVERLAPPED lpOvl = NULL; struct windowsaio_data *wd; DWORD iobytes; - BOOL success; + BOOL success = FALSE; int index; int rc = FIO_Q_COMPLETED; @@ -358,6 +363,7 @@ static int fio_windowsaio_queue(struct thread_data *td, struct io_u *io_u) break; default: assert(0); + break; } if (success || GetLastError() == ERROR_IO_PENDING) diff --git a/file.h b/file.h index 67ef24f1..1d6624e5 100644 --- a/file.h +++ b/file.h @@ -62,7 +62,7 @@ struct fio_file { void *file_data; int fd; -#ifdef __CYGWIN__ +#ifdef WIN32 HANDLE hFile; HANDLE ioCP; #endif diff --git a/helpers.h b/helpers.h index da20a6ba..ed2086d1 100644 --- a/helpers.h +++ b/helpers.h @@ -3,6 +3,7 @@ #include "compiler/compiler.h" +#include #include struct in_addr; diff --git a/init.c b/init.c index d7d80118..710e8673 100644 --- a/init.c +++ b/init.c @@ -555,6 +555,19 @@ static int fixup_options(struct thread_data *td) } #endif +#ifdef WIN32 + /* + * Windows doesn't support O_DIRECT or O_SYNC with the _open interface, + * so fail if we're passed those flags + */ + if ((td->io_ops->flags & FIO_SYNCIO) && (td->o.odirect || td->o.sync_io)) { + log_err("fio: Windows does not support direct or non-buffered io with" + " the synchronous ioengines. Use the 'windowsaio' ioengine" + " with 'direct=1' and 'iodepth=1' instead.\n"); + ret = 1; + } +#endif + return ret; } @@ -660,31 +673,6 @@ void td_fill_rand_seeds(struct thread_data *td) init_rand_seed(&td->buf_state, td->rand_seeds[7]); } -/* - * Initialize the various random states we need (random io, block size ranges, - * read/write mix, etc). - */ -static int init_random_state(struct thread_data *td) -{ - int fd; - - fd = open("/dev/urandom", O_RDONLY); - if (fd == -1) { - td_verror(td, errno, "open"); - return 1; - } - - if (read(fd, td->rand_seeds, sizeof(td->rand_seeds)) < - (int) sizeof(td->rand_seeds)) { - td_verror(td, EIO, "read"); - close(fd); - return 1; - } - - close(fd); - td_fill_rand_seeds(td); - return 0; -} /* * Initializes the ioengine configured for a job, if it has not been done so @@ -839,8 +827,10 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num) td->groupid = groupid; prev_group_jobs++; - if (init_random_state(td)) + if (init_random_state(td, td->rand_seeds, sizeof(td->rand_seeds))) { + td_verror(td, errno, "init_random_state"); goto err; + } if (setup_rate(td)) goto err; diff --git a/ioengine.h b/ioengine.h index be74b66f..51e55944 100644 --- a/ioengine.h +++ b/ioengine.h @@ -132,7 +132,7 @@ enum fio_ioengine_flags { FIO_RAWIO = 1 << 1, /* some sort of direct/raw io */ FIO_DISKLESSIO = 1 << 2, /* no disk involved */ FIO_NOEXTEND = 1 << 3, /* engine can't extend file */ - FIO_NODISKUTIL = 1 << 4, /* diskutil can't handle filename */ + FIO_NODISKUTIL = 1 << 4, /* diskutil can't handle filename */ FIO_UNIDIR = 1 << 5, /* engine is uni-directional */ FIO_NOIO = 1 << 6, /* thread does only pseudo IO */ FIO_SIGTERM = 1 << 7, /* needs SIGTERM to exit */ diff --git a/os/os-aix.h b/os/os-aix.h index 2f75bf8f..1870e6e4 100644 --- a/os/os-aix.h +++ b/os/os-aix.h @@ -13,6 +13,7 @@ #define FIO_HAVE_POSIXAIO #define FIO_HAVE_ODIRECT #define FIO_USE_GENERIC_RAND +#define FIO_USE_GENERIC_INIT_RANDOM_STATE #define FIO_HAVE_CLOCK_MONOTONIC /* diff --git a/os/os-freebsd.h b/os/os-freebsd.h index 9fbc6236..2a7b7b32 100644 --- a/os/os-freebsd.h +++ b/os/os-freebsd.h @@ -16,6 +16,7 @@ #define FIO_HAVE_ODIRECT #define FIO_HAVE_STRSEP #define FIO_USE_GENERIC_RAND +#define FIO_USE_GENERIC_INIT_RANDOM_STATE #define FIO_HAVE_CHARDEV_SIZE #define FIO_HAVE_GETTID #define FIO_HAVE_CLOCK_MONOTONIC diff --git a/os/os-hpux.h b/os/os-hpux.h index 59439381..821c9169 100644 --- a/os/os-hpux.h +++ b/os/os-hpux.h @@ -22,6 +22,7 @@ #define FIO_HAVE_POSIXAIO #define FIO_HAVE_ODIRECT #define FIO_USE_GENERIC_RAND +#define FIO_USE_GENERIC_INIT_RANDOM_STATE #define FIO_HAVE_CLOCK_MONOTONIC #define FIO_HAVE_PSHARED_MUTEX #define FIO_HAVE_FADVISE diff --git a/os/os-linux.h b/os/os-linux.h index c0953df4..3bf6bd97 100644 --- a/os/os-linux.h +++ b/os/os-linux.h @@ -44,6 +44,7 @@ #define FIO_HAVE_BINJECT #define FIO_HAVE_CLOCK_MONOTONIC #define FIO_HAVE_GETTID +#define FIO_USE_GENERIC_INIT_RANDOM_STATE /* * Can only enable this for newer glibcs, or the header and defines are diff --git a/os/os-mac.h b/os/os-mac.h index aec30f96..553f8200 100644 --- a/os/os-mac.h +++ b/os/os-mac.h @@ -27,6 +27,7 @@ #define FIO_HAVE_POSIXAIO #define FIO_HAVE_CLOCK_MONOTONIC #define FIO_USE_GENERIC_RAND +#define FIO_USE_GENERIC_INIT_RANDOM_STATE #define FIO_HAVE_GETTID #define FIO_HAVE_CHARDEV_SIZE diff --git a/os/os-netbsd.h b/os/os-netbsd.h index 78ac135f..aef578e8 100644 --- a/os/os-netbsd.h +++ b/os/os-netbsd.h @@ -23,6 +23,7 @@ #define FIO_HAVE_FDATASYNC #define FIO_USE_GENERIC_BDEV_SIZE #define FIO_USE_GENERIC_RAND +#define FIO_USE_GENERIC_INIT_RANDOM_STATE #define FIO_HAVE_GETTID #undef FIO_HAVE_CPU_AFFINITY /* XXX notyet */ diff --git a/os/os-solaris.h b/os/os-solaris.h index c6a46ee0..d97643d0 100644 --- a/os/os-solaris.h +++ b/os/os-solaris.h @@ -22,6 +22,7 @@ #define FIO_HAVE_FDATASYNC #define FIO_HAVE_CHARDEV_SIZE #define FIO_USE_GENERIC_BDEV_SIZE +#define FIO_USE_GENERIC_INIT_RANDOM_STATE #define FIO_HAVE_GETTID #define OS_MAP_ANON MAP_ANON diff --git a/os/os-windows.h b/os/os-windows.h index 8812cfa2..06fe4335 100644 --- a/os/os-windows.h +++ b/os/os-windows.h @@ -1,220 +1,252 @@ -#ifndef FIO_OS_WINDOWS_H -#define FIO_OS_WINDOWS_H - -#define FIO_OS os_windows - -#include -#include -#include -#include -#include - -#include "../smalloc.h" -#include "../file.h" -#include "../log.h" - -#define FIO_HAVE_ODIRECT -#define FIO_HAVE_CPU_AFFINITY -#define FIO_HAVE_CHARDEV_SIZE -#define FIO_HAVE_FALLOCATE -#define FIO_HAVE_FDATASYNC -#define FIO_HAVE_WINDOWSAIO -#define FIO_HAVE_GETTID - -#define FIO_OS_HAVE_SOCKLEN_T -typedef int fio_socklen_t; - -#define FIO_USE_GENERIC_RAND - -#define OS_MAP_ANON MAP_ANON - -#define OS_CLOCK CLOCK_REALTIME - -#define FIO_PREFERRED_ENGINE "windowsaio" - -#define FIO_LITTLE_ENDIAN -#define fio_swap16(x) _byteswap_ushort(x) -#define fio_swap32(x) _byteswap_ulong(x) -#define fio_swap64(x) _byteswap_uint64(x) - -typedef off_t off64_t; - -typedef struct { - LARGE_INTEGER Length; -} GET_LENGTH_INFORMATION; - -#define IOCTL_DISK_GET_LENGTH_INFO 0x7405C - -pid_t cygwin_winpid_to_pid(int winpid); - -static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes) -{ - int rc = 0; - 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; - } - - 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(struct fio_file *f, unsigned long long *bytes) -{ - return blockdev_size(f, bytes); -} - -static inline int blockdev_invalidate_cache(struct fio_file *f) -{ - /* 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) -{ - SYSTEM_INFO sysInfo; - unsigned long addr; - GetSystemInfo(&sysInfo); - addr = (unsigned long)sysInfo.lpMaximumApplicationAddress; - return addr; -} - -static inline void os_get_tmpdir(char *path, int len) -{ - GetTempPath(len, path); -} - -typedef DWORD_PTR os_cpu_mask_t; - -static inline int gettid(void) -{ - return GetCurrentThreadId(); -} - -static inline int pid_to_winpid(int pid) -{ - int winpid = 0; - DWORD outbytes = 0; - DWORD *ids = NULL; - size_t allocsize; - - allocsize = sizeof(DWORD) * 1024; - - do { - if (allocsize == outbytes) - allocsize *= 2; - - ids = realloc(ids, allocsize); - EnumProcesses(ids, allocsize, &outbytes); - } while (allocsize == outbytes); - - for (int i = 0; i < (outbytes/sizeof(DWORD)); i++) { - if (cygwin_winpid_to_pid(ids[i]) == pid) { - winpid = ids[i]; - break; - } - } - - free(ids); - return winpid; -} - -HANDLE WINAPI OpenThread( - DWORD dwDesiredAccess, - BOOL bInheritHandle, - DWORD dwThreadId); - -DWORD WINAPI GetProcessIdOfThread(HANDLE Thread); - -static inline int fio_setaffinity(int pid, os_cpu_mask_t cpumask) -{ - HANDLE h; - BOOL bSuccess; - int winpid; - - h = OpenThread(THREAD_QUERY_INFORMATION | THREAD_SET_INFORMATION, TRUE, pid); - if (h != NULL) { - bSuccess = SetThreadAffinityMask(h, cpumask); - } else { - // then we might have a process id instead of a thread id - winpid = pid_to_winpid(pid); - h = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_SET_INFORMATION, TRUE, winpid); - if (h == NULL) - return -1; - - bSuccess = SetProcessAffinityMask(h, cpumask); - } - - CloseHandle(h); - - return (bSuccess)? 0 : -1; -} - -static inline void fio_getaffinity(int pid, os_cpu_mask_t *mask) -{ - os_cpu_mask_t systemMask; - int winpid; - - HANDLE h = OpenThread(THREAD_QUERY_INFORMATION, TRUE, pid); - if (h != NULL) - winpid = GetProcessIdOfThread(h); - else - winpid = pid_to_winpid(pid); - - h = OpenProcess(PROCESS_QUERY_INFORMATION, TRUE, winpid); - - if (h != NULL) { - GetProcessAffinityMask(h, mask, &systemMask); - CloseHandle(h); - } else { - fprintf(stderr, "fio_getaffinity failed: failed to get handle for pid %d\n", pid); - } - -} - -static inline void fio_cpu_clear(os_cpu_mask_t *mask, int cpu) -{ - *mask ^= 1 << (cpu-1); -} - -static inline void fio_cpu_set(os_cpu_mask_t *mask, int cpu) -{ - *mask |= 1 << (cpu-1); -} - -static inline int fio_cpuset_init(os_cpu_mask_t *mask) -{ - *mask = 0; - return 0; -} - -static inline int fio_cpuset_exit(os_cpu_mask_t *mask) -{ - return 0; -} - -#define FIO_MAX_CPUS MAXIMUM_PROCESSORS - -#ifdef MADV_FREE -#define FIO_MADV_FREE MADV_FREE -#endif - -#endif /* FIO_OS_WINDOWS_H */ +#ifndef FIO_OS_WINDOWS_H +#define FIO_OS_WINDOWS_H + +#define FIO_OS os_windows + +#include +#include +#include +#include +#include +#include +#include + +#include "../smalloc.h" +#include "../file.h" +#include "../log.h" + +#define FIO_HAVE_ODIRECT +#define FIO_HAVE_CPU_AFFINITY +#define FIO_HAVE_CHARDEV_SIZE +#define FIO_HAVE_FDATASYNC +#define FIO_HAVE_WINDOWSAIO +#define FIO_HAVE_GETTID +#define FIO_HAVE_CLOCK_MONOTONIC +#define FIO_USE_GENERIC_RAND + +#define FIO_PREFERRED_ENGINE "windowsaio" +#define FIO_PREFERRED_CLOCK_SOURCE CS_CGETTIME +#define FIO_OS_PATH_SEPARATOR "\\" + +#define FIO_MAX_CPUS MAXIMUM_PROCESSORS + +#define FIO_OS_HAVE_SOCKLEN_T +typedef int fio_socklen_t; + +#define OS_MAP_ANON MAP_ANON + +#define FIO_LITTLE_ENDIAN +#define fio_swap16(x) _byteswap_ushort(x) +#define fio_swap32(x) _byteswap_ulong(x) +#define fio_swap64(x) _byteswap_uint64(x) + +typedef off_t off64_t; +typedef int clockid_t; + +typedef DWORD_PTR os_cpu_mask_t; + +#define CLOCK_REALTIME 1 +#define CLOCK_MONOTONIC 2 + +#define _SC_PAGESIZE 0x1 +#define _SC_NPROCESSORS_ONLN 0x2 +#define _SC_PHYS_PAGES 0x4 + +#define SA_RESTART 0 +#define SIGPIPE 0 + +/* + * Windows doesn't have O_DIRECT or O_SYNC, so define them + * here so we can reject them at runtime when using the _open + * interface (windowsaio uses CreateFile) + */ +#define O_DIRECT 0x1000000 +#define O_SYNC 0x2000000 + +/* Windows doesn't support madvise, so any values will work */ +#define POSIX_MADV_DONTNEED 0 +#define POSIX_MADV_SEQUENTIAL 0 +#define POSIX_MADV_RANDOM 0 + +#define F_SETFL 0x1 +#define F_GETFL 0x2 +#define O_NONBLOCK FIONBIO + +/* Winsock doesn't support MSG_WAIT */ +#define OS_MSG_DONTWAIT 0 + +#define POLLOUT 1 +#define POLLIN 2 +#define POLLERR 0 +#define POLLHUP 1 + +#define SIGCONT 0 + +typedef int sigset_t; +typedef int siginfo_t; + +struct sigaction +{ + void (*sa_handler)(int); + sigset_t sa_mask; + int sa_flags; + void* (*sa_sigaction)(int, siginfo_t *, void*); +}; + +char *strsep(char **stringp, const char *delim); +long sysconf(int name); + +int kill(pid_t pid, int sig); +pid_t setsid(void); +int setgid(gid_t gid); +int setuid(uid_t uid); +int nice(int incr); +int sigaction(int sig, const struct sigaction *act, + struct sigaction *oact); +int fsync(int fildes); +int fork(void); +int fcntl(int fildes, int cmd, ...); +int fdatasync(int fildes); +int lstat(const char * path, struct stat * buf); +uid_t geteuid(void); +int nanosleep(const struct timespec *rqtp, struct timespec *rmtp); +ssize_t pread(int fildes, void *buf, size_t nbyte, off_t offset); +ssize_t pwrite(int fildes, const void *buf, size_t nbyte, + off_t offset); +extern void td_fill_rand_seeds(struct thread_data *); + +static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes) +{ + int rc = 0; + 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; + } + + 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(struct fio_file *f, unsigned long long *bytes) +{ + return blockdev_size(f, bytes); +} + +static inline int blockdev_invalidate_cache(struct fio_file *f) +{ + /* 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) +{ + SYSTEM_INFO sysInfo; + uintptr_t addr; + + GetSystemInfo(&sysInfo); + addr = (uintptr_t)sysInfo.lpMaximumApplicationAddress; + return (unsigned long long)addr; +} + +static inline void os_get_tmpdir(char *path, int len) +{ + GetTempPath(len, path); +} + +static inline int gettid(void) +{ + return GetCurrentThreadId(); +} + +static inline int fio_setaffinity(int pid, os_cpu_mask_t cpumask) +{ + HANDLE h; + BOOL bSuccess = FALSE; + + h = OpenThread(THREAD_QUERY_INFORMATION | THREAD_SET_INFORMATION, TRUE, pid); + if (h != NULL) { + bSuccess = SetThreadAffinityMask(h, cpumask); + CloseHandle(h); + } + + return (bSuccess)? 0 : -1; +} + +static inline void fio_getaffinity(int pid, os_cpu_mask_t *mask) +{ + os_cpu_mask_t systemMask; + + HANDLE h = OpenProcess(PROCESS_QUERY_INFORMATION, TRUE, pid); + + if (h != NULL) { + GetProcessAffinityMask(h, mask, &systemMask); + CloseHandle(h); + } else { + log_err("fio_getaffinity failed: failed to get handle for pid %d\n", pid); + } +} + +static inline void fio_cpu_clear(os_cpu_mask_t *mask, int cpu) +{ + *mask ^= 1 << (cpu-1); +} + +static inline void fio_cpu_set(os_cpu_mask_t *mask, int cpu) +{ + *mask |= 1 << (cpu-1); +} + +static inline int fio_cpuset_init(os_cpu_mask_t *mask) +{ + *mask = 0; + return 0; +} + +static inline int fio_cpuset_exit(os_cpu_mask_t *mask) +{ + return 0; +} + +static inline int init_random_state(struct thread_data *td, unsigned long *rand_seeds, int size) +{ + HCRYPTPROV hCryptProv; + + if (!CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) + { + errno = GetLastError(); + log_err("CryptAcquireContext() failed: error %d\n", errno); + return 1; + } + + if (!CryptGenRandom(hCryptProv, size, (BYTE*)rand_seeds)) { + errno = GetLastError(); + log_err("CryptGenRandom() failed, error %d\n", errno); + CryptReleaseContext(hCryptProv, 0); + return 1; + } + + CryptReleaseContext(hCryptProv, 0); + td_fill_rand_seeds(td); + return 0; +} + + +#endif /* FIO_OS_WINDOWS_H */ diff --git a/os/os.h b/os/os.h index c10cb127..8d2a6ae8 100644 --- a/os/os.h +++ b/os/os.h @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -34,7 +35,7 @@ enum { #include "os-aix.h" #elif defined(__hpux) #include "os-hpux.h" -#elif defined(__CYGWIN__) +#elif defined(WIN32) #include "os-windows.h" #else #error "unsupported os" @@ -267,6 +268,32 @@ static inline long os_random_long(os_random_state_t *rs) } #endif +#ifdef FIO_USE_GENERIC_INIT_RANDOM_STATE +extern void td_fill_rand_seeds(struct thread_data *td); +/* + * Initialize the various random states we need (random io, block size ranges, + * read/write mix, etc). + */ +static inline int init_random_state(struct thread_data *td, unsigned long *rand_seeds, int size) +{ + int fd; + + fd = open("/dev/urandom", O_RDONLY); + if (fd == -1) { + return 1; + } + + if (read(fd, rand_seeds, size) < size) { + close(fd); + return 1; + } + + close(fd); + td_fill_rand_seeds(td); + return 0; +} +#endif + #ifndef FIO_HAVE_FS_STAT static inline unsigned long long get_fs_size(const char *path) { diff --git a/os/windows/FIO.lnk b/os/windows/FIO.lnk deleted file mode 100644 index 5a8bdefd92616fd790ff6c271e899683c903e3fa..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1422 zcmb7EZAepL6h2d$Q6ETWDi6|n7 zzPMQ0pQ0cv`eZ-)SCsUluU`@bQJEM7QIR=nNvGP+QdwuB9N)M+W`6Go8iro#X}u(! z&!i1*N6V~Hf;mJsAy}NbK_mI1sht1{kT901%aAh_03joRi^uV7<5miE$0tkb2>`iEEAKKSX5j53I zn?;G*(cVPM*?uXom>Cz7`0%najb&!E$z^^KD_unmzaGD%^Lc(@(BF z-TNd6{cKK!5E{@78&Db_C+3Ptg02#@1jAq#ClcghF=}><9P7%2RjH8ptPDCEbo{7m zJ2p;YLc0IjO^3agzmBC}8VKZ8LEph9T)E|dS~)Wn%-Ki_za|#ngq@GX~u$ zImP5x8Dm?a&t?mDz6$u)+0bT0n=1C9tyVA?Ql&Yrhy?qJDy5#D_CUE^+SNtZUj!_} zjcdGTMr-m)Bj*OCy*IMot{gY+drE1R=$+KL&L6`s#!Z<|Ur?EM$sMTh?@N!?b5)P) zh#K)R2;(!sv*gF8;D1+U`~|oYe@Nar8jl6@>WUKKN71Odfr6!2EQXyAX2g$XW|#x; Iu!;%RFPtX$X8-^I diff --git a/os/windows/cygwin.wxs b/os/windows/cygwin.wxs deleted file mode 100755 index c33c1335..00000000 --- a/os/windows/cygwin.wxs +++ /dev/null @@ -1,8469 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/os/windows/dobuild.cmd b/os/windows/dobuild.cmd old mode 100755 new mode 100644 index 95543d75..43e5db4d --- a/os/windows/dobuild.cmd +++ b/os/windows/dobuild.cmd @@ -1,4 +1,26 @@ -"%WIX%bin\candle" cygwin.wxs -"%WIX%bin\candle" install.wxs -"%WIX%bin\candle" examples.wxs -"%WIX%bin\light" install.wixobj cygwin.wixobj examples.wixobj -ext WixUIExtension -out fio.msi \ No newline at end of file +@echo off +setlocal enabledelayedexpansion +set /a counter=4 +for /f "tokens=3" %%i in (..\..\fio_version.h) do ( + if "!counter!"=="4" set FIO_MAJOR=%%i + if "!counter!"=="5" set FIO_MINOR=%%i + if "!counter!"=="6" set FIO_PATCH=%%i +set /a counter+=1 +) + +if "%1"=="x86" set FIO_ARCH=x86 +if "%1"=="x64" set FIO_ARCH=x64 + +if not defined FIO_ARCH ( + echo Error: must specify the architecture. + echo Usage: dobuild x86 + echo Usage: dobuild x64 + goto end +) + +"%WIX%bin\candle" -nologo -arch %FIO_ARCH% install.wxs +@if ERRORLEVEL 1 goto end +"%WIX%bin\candle" -nologo -arch %FIO_ARCH% examples.wxs +@if ERRORLEVEL 1 goto end +"%WIX%bin\light" -nologo install.wixobj examples.wixobj -ext WixUIExtension -out fio-%FIO_MAJOR%.%FIO_MINOR%.%FIO_PATCH%-%FIO_ARCH%.msi +:end \ No newline at end of file diff --git a/os/windows/examples.wxs b/os/windows/examples.wxs index 5ade1e16..f3d6bc3f 100755 --- a/os/windows/examples.wxs +++ b/os/windows/examples.wxs @@ -2,46 +2,54 @@ - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + + + + + + + - - - - - - - - - + + + + + + + + + + + \ No newline at end of file diff --git a/os/windows/fio/FIO.bat b/os/windows/fio/FIO.bat deleted file mode 100644 index 320043bb..00000000 --- a/os/windows/fio/FIO.bat +++ /dev/null @@ -1,9 +0,0 @@ -@echo off - -%SYSTEMDRIVE% -IF EXIST "%PROGRAMFILES(X86)%" set ROOTDIR=%PROGRAMFILES(X86)%\FIO -IF NOT EXIST "%PROGRAMFILES(X86)%" set ROOTDIR=%PROGRAMFILES%\FIO -chdir "%ROOTDIR%\bin" - -bash -c "echo \"Run FIO by typing 'fio'\" && echo \"This is a virtual filesystem: the root directory is $ROOTDIR\" && echo \"In this environment the path separator is '/' not '\\'\" && echo \"The C: drive is available under /cygdrive/c\" && echo \"Examples are in /examples ($ROOTDIR\\examples)\" && echo \"Type 'cd' to change directory and 'dir' (or 'ls') to see directory contents\" && echo \"QuickEdit mode is enabled: copy text by highlighting it and right-clicking\" && echo \"To exit, close the window\" && /usr/sbin/cygserver & 2> /dev/null" -bash --login -i diff --git a/os/windows/harvest.cmd b/os/windows/harvest.cmd deleted file mode 100755 index 575af255..00000000 --- a/os/windows/harvest.cmd +++ /dev/null @@ -1,2 +0,0 @@ -"%WIX%\bin\heat" dir fio -gg -sfrag -scom -out cygwin.wxs -scom -sreg -dr cygwin -ke -cg cygwin -"%WIX%\bin\heat" dir ..\..\examples -gg -sfrag -scom -out examples.wxs -scom -sreg -dr examples -ke -cg examples diff --git a/os/windows/install.wxs b/os/windows/install.wxs index b853e4b2..d3d683e7 100755 --- a/os/windows/install.wxs +++ b/os/windows/install.wxs @@ -1,79 +1,61 @@ - - - - + + + + + + + UpgradeCode="{2338A332-5511-43cf-b9BD-5C60496CCFCC}" Version="$(env.FIO_MAJOR).$(env.FIO_MINOR).$(env.FIO_PATCH)"> - + - + - - - - - - - - - - + + + - - - - - + + - - - + + - - - + + - - - + + + + + + - - - - - - - - - - - - - + + + - - + @@ -85,7 +67,7 @@ - + Installed OR ALLUSERS=1 diff --git a/os/windows/posix/include/arpa/inet.h b/os/windows/posix/include/arpa/inet.h new file mode 100644 index 00000000..df9e2780 --- /dev/null +++ b/os/windows/posix/include/arpa/inet.h @@ -0,0 +1,13 @@ +#ifndef ARPA_INET_H +#define ARPA_INET_H + +#include +#include + +typedef int socklen_t; + +const char *inet_ntop(int af, const void *restrict src, + char *restrict dst, socklen_t size); +int inet_pton(int af, const char *restrict src, void *restrict dst); + +#endif /* ARPA_INET_H */ diff --git a/os/windows/posix/include/asm/types.h b/os/windows/posix/include/asm/types.h new file mode 100644 index 00000000..89ab3d09 --- /dev/null +++ b/os/windows/posix/include/asm/types.h @@ -0,0 +1,8 @@ +#ifndef ASM_TYPES_H +#define ASM_TYPES_H + +typedef unsigned short __u16; +typedef unsigned int __u32; +typedef unsigned long long __u64; + +#endif /* ASM_TYPES_H */ diff --git a/os/windows/posix/include/dirent.h b/os/windows/posix/include/dirent.h new file mode 100644 index 00000000..39a880da --- /dev/null +++ b/os/windows/posix/include/dirent.h @@ -0,0 +1,16 @@ +#ifndef DIRENT_H +#define DIRENT_H + +struct dirent +{ + ino_t d_ino; // File serial number. + char d_name[]; // Name of entry. +}; + +typedef int DIR; + +DIR *opendir(const char *dirname); +struct dirent *readdir(DIR *dirp); +int closedir(DIR *dirp); + +#endif /* DIRENT_H */ diff --git a/os/windows/posix/include/dlfcn.h b/os/windows/posix/include/dlfcn.h new file mode 100644 index 00000000..2953aec6 --- /dev/null +++ b/os/windows/posix/include/dlfcn.h @@ -0,0 +1,11 @@ +#ifndef DLFCN_H +#define DLFCN_H + +#define RTLD_LAZY 1 + +void *dlopen(const char *file, int mode); +int dlclose(void *handle); +void *dlsym(void *restrict handle, const char *restrict name); +char *dlerror(void); + +#endif /* DLFCN_H */ diff --git a/os/windows/posix/include/libgen.h b/os/windows/posix/include/libgen.h new file mode 100644 index 00000000..9d97c253 --- /dev/null +++ b/os/windows/posix/include/libgen.h @@ -0,0 +1,6 @@ +#ifndef LIBGEN_H +#define LIBGEN_H + +char *basename(char *path); + +#endif /* LIBGEN_H */ diff --git a/os/windows/posix/include/netdb.h b/os/windows/posix/include/netdb.h new file mode 100644 index 00000000..237288b3 --- /dev/null +++ b/os/windows/posix/include/netdb.h @@ -0,0 +1,4 @@ +#ifndef NETDB_H +#define NETDB_H + +#endif /* NETDB_H */ diff --git a/os/windows/posix/include/netinet/in.h b/os/windows/posix/include/netinet/in.h new file mode 100644 index 00000000..80b69a72 --- /dev/null +++ b/os/windows/posix/include/netinet/in.h @@ -0,0 +1,21 @@ +#ifndef NETINET_IN_H +#define NETINET_IN_H + +#include +#include + +struct in6_addr +{ + uint8_t s6_addr[16]; +}; + +struct sockaddr_in6 +{ + sa_family_t sin6_family; // AF_INET6. + in_port_t sin6_port; // Port number. + uint32_t sin6_flowinfo; // IPv6 traffic class and flow information. + struct in6_addr sin6_addr; // IPv6 address. + uint32_t sin6_scope_id; // Set of interfaces for a scope. +}; + +#endif /* NETINET_IN_H */ diff --git a/os/windows/posix/include/poll.h b/os/windows/posix/include/poll.h new file mode 100644 index 00000000..f5c47e78 --- /dev/null +++ b/os/windows/posix/include/poll.h @@ -0,0 +1,4 @@ +#ifndef POLL_H +#define POLL_H + +#endif /* POLL_H */ diff --git a/os/windows/posix/include/semaphore.h b/os/windows/posix/include/semaphore.h new file mode 100644 index 00000000..d58f899d --- /dev/null +++ b/os/windows/posix/include/semaphore.h @@ -0,0 +1,4 @@ +#ifndef SEMAPHORE_H +#define SEMAPHORE_H + +#endif /* SEMAPHORE_H */ diff --git a/os/windows/posix/include/sys/ipc.h b/os/windows/posix/include/sys/ipc.h new file mode 100644 index 00000000..2601a539 --- /dev/null +++ b/os/windows/posix/include/sys/ipc.h @@ -0,0 +1,4 @@ +#ifndef SYS_IPC_H +#define SYS_IPC_H + +#endif /* SYS_IPC_H */ diff --git a/os/windows/posix/include/sys/mman.h b/os/windows/posix/include/sys/mman.h new file mode 100644 index 00000000..36480a43 --- /dev/null +++ b/os/windows/posix/include/sys/mman.h @@ -0,0 +1,36 @@ +#ifndef SYS_MMAN_H +#define SYS_MMAN_H + +#include + +#define PROT_NONE 1 +#define PROT_READ 2 +#define PROT_WRITE 4 + +#define MAP_ANON 0x1 +#define MAP_ANONYMOUS MAP_ANON +#define MAP_FIXED 0x2 +#define MAP_HASSEMAPHORE 0x4 +#define MAP_INHERIT 0x8 +#define MAP_NOCORE 0x10 +#define MAP_NOSYNC 0x20 +#define MAP_PREFAULT_READ 0x40 +#define MAP_PRIVATE 0x80 +#define MAP_SHARED 0x100 +#define MAP_STACK 0x200 + +#define MAP_FAILED NULL + +#define MS_ASYNC 0x1 +#define MS_SYNC 0x2 +#define MS_INVALIDATE 0x3 + +int posix_madvise(void *addr, size_t len, int advice); +void *mmap(void *addr, size_t len, int prot, int flags, + int fildes, off_t off); +int munmap(void *addr, size_t len); +int msync(void *addr, size_t len, int flags); +int munlock(const void * addr, size_t len); +int mlock(const void *addr, size_t len); + +#endif /* SYS_MMAN_H */ diff --git a/os/windows/posix/include/sys/poll.h b/os/windows/posix/include/sys/poll.h new file mode 100644 index 00000000..e1626b25 --- /dev/null +++ b/os/windows/posix/include/sys/poll.h @@ -0,0 +1,15 @@ +#ifndef SYS_POLL_H +#define SYS_POLL_H + +typedef int nfds_t; + +struct pollfd +{ + int fd; + short events; + short revents; +}; + +int poll(struct pollfd fds[], nfds_t nfds, int timeout); + +#endif /* SYS_POLL_H */ diff --git a/os/windows/posix/include/sys/resource.h b/os/windows/posix/include/sys/resource.h new file mode 100644 index 00000000..837d6577 --- /dev/null +++ b/os/windows/posix/include/sys/resource.h @@ -0,0 +1,18 @@ +#ifndef SYS_RESOURCE_H +#define SYS_RESOURCE_H + +#define RUSAGE_SELF 0 + +struct rusage +{ + struct timeval ru_utime; + struct timeval ru_stime; + int ru_nvcsw; + int ru_minflt; + int ru_majflt; + int ru_nivcsw; +}; + +int getrusage(int who, struct rusage *r_usage); + +#endif /* SYS_RESOURCE_H */ diff --git a/os/windows/posix/include/sys/shm.h b/os/windows/posix/include/sys/shm.h new file mode 100644 index 00000000..6f6b0328 --- /dev/null +++ b/os/windows/posix/include/sys/shm.h @@ -0,0 +1,41 @@ +#ifndef SYS_SHM_H +#define SYS_SHM_H + +#define IPC_RMID 0x1 +#define IPC_CREAT 0x2 +#define IPC_PRIVATE 0x4 + +typedef int uid_t; +typedef int gid_t; + +typedef int shmatt_t; +typedef int key_t; + +struct ipc_perm +{ + uid_t uid; //owner's user ID + gid_t gid; //owner's group ID + uid_t cuid; //creator's user ID + gid_t cgid; //creator's group ID + mode_t mode; //read/write permission +}; + + +struct shmid_ds +{ + struct ipc_perm shm_perm; //operation permission structure + size_t shm_segsz; //size of segment in bytes + pid_t shm_lpid; //process ID of last shared memory operation + pid_t shm_cpid; //process ID of creator + shmatt_t shm_nattch; //number of current attaches + time_t shm_atime; //time of last shmat() + time_t shm_dtime; //time of last shmdt() + time_t shm_ctime; //time of last change by shmctl() +}; + +int shmctl(int shmid, int cmd, struct shmid_ds *buf); +int shmget(key_t key, size_t size, int shmflg); +void *shmat(int shmid, const void *shmaddr, int shmflg); +int shmdt(const void *shmaddr); + +#endif /* SYS_SHM_H */ diff --git a/os/windows/posix/include/sys/socket.h b/os/windows/posix/include/sys/socket.h new file mode 100644 index 00000000..eef3b45b --- /dev/null +++ b/os/windows/posix/include/sys/socket.h @@ -0,0 +1,4 @@ +#ifndef SYS_SOCKET_H +#define SYS_SOCKET_H + +#endif /* SYS_SOCKET_H */ diff --git a/os/windows/posix/include/sys/uio.h b/os/windows/posix/include/sys/uio.h new file mode 100644 index 00000000..10229869 --- /dev/null +++ b/os/windows/posix/include/sys/uio.h @@ -0,0 +1,16 @@ +#ifndef SYS_UIO_H +#define SYS_UIO_H + +#include +#include + + struct iovec + { + void *iov_base; //Base address of a memory region for input or output. + size_t iov_len; //The size of the memory pointed to by iov_base. +}; + + ssize_t readv(int fildes, const struct iovec *iov, int iovcnt); + ssize_t writev(int fildes, const struct iovec *iov, int iovcnt); + +#endif /* SYS_UIO_H */ diff --git a/os/windows/posix/include/sys/un.h b/os/windows/posix/include/sys/un.h new file mode 100644 index 00000000..0053f328 --- /dev/null +++ b/os/windows/posix/include/sys/un.h @@ -0,0 +1,14 @@ +#ifndef SYS_UN_H +#define SYS_UN_H + +typedef int sa_family_t; +typedef int in_port_t; + + struct sockaddr_un + { + sa_family_t sun_family; // Address family. + char sun_path[]; // Socket pathname. +}; + + +#endif /* SYS_UN_H */ diff --git a/os/windows/posix/include/sys/wait.h b/os/windows/posix/include/sys/wait.h new file mode 100644 index 00000000..954bd2bf --- /dev/null +++ b/os/windows/posix/include/sys/wait.h @@ -0,0 +1,12 @@ +#ifndef SYS_WAIT_H +#define SYS_WAIT_H + +#define WIFSIGNALED(a) 0 +#define WIFEXITED(a) 0 +#define WTERMSIG(a) 0 +#define WEXITSTATUS(a) 0 +#define WNOHANG 0 + +pid_t waitpid(pid_t, int *stat_loc, int options); + +#endif /* SYS_WAIT_H */ diff --git a/os/windows/posix/include/syslog.h b/os/windows/posix/include/syslog.h new file mode 100644 index 00000000..a06bda48 --- /dev/null +++ b/os/windows/posix/include/syslog.h @@ -0,0 +1,18 @@ +#ifndef SYSLOG_H +#define SYSLOG_H + +int syslog(); + +#define LOG_INFO 0 +#define LOG_ERROR 1 +#define LOG_WARN 2 + +#define LOG_NDELAY 0 +#define LOG_NOWAIT 0 +#define LOG_PID 0 +#define LOG_USER 0 + +void closelog(void); +void openlog(const char *ident, int logopt, int facility); + +#endif /* SYSLOG_H */ diff --git a/server.c b/server.c index 9af278aa..84b106e8 100644 --- a/server.c +++ b/server.c @@ -1187,6 +1187,11 @@ int fio_start_server(char *pidfile) pid_t pid; int ret; +#if defined(WIN32) + WSADATA wsd; + WSAStartup(MAKEWORD(2,2), &wsd); +#endif + if (!pidfile) return fio_server(); -- 2.25.1