From 313fb9f8cb8b0e91b26c10b5c3dd124cd34e619b Mon Sep 17 00:00:00 2001 From: Jorgen Lundman Date: Thu, 10 Oct 2019 17:48:27 +0900 Subject: [PATCH 1/3] Re-port userland Instead of littering source file with #ifdef _WIN32, we create a wrapper for the POSIX calls that uses "int fd;". As we need to use HANDLEs to open devices, we implement alternate versions of the POSIX functions that take HANDLEs instead. Currently the implementation uses simple cast between HANDLE and int, should we find that the missing bits (64bit -> 32bit) to be a problem the shim layer could further be enhanced to handle this case. The functions that have a whole WIN32 replacement are left to use WIN32 specific code, but as much as possible remains unchanged from upstream. --- ZFSin/zfs/cmd/zfs/zfs_main.c | 10 +- ZFSin/zfs/cmd/zpool/zpool_main.c | 10 - ZFSin/zfs/cmd/zpool/zpool_vdev.c | 2 +- ZFSin/zfs/cmd/zstreamdump/zstreamdump.c | 2 +- ZFSin/zfs/include/libzfs_impl.h | 2 +- ZFSin/zfs/include/sys/efi_partition.h | 14 +- ZFSin/zfs/include/sys/zfs_context_userland.h | 1 - ZFSin/zfs/lib/libefi/rdwr_efi.c | 85 +-- ZFSin/zfs/lib/libshare/libshare.c | 6 - ZFSin/zfs/lib/libspl/fdatasync.c | 10 - ZFSin/zfs/lib/libspl/include/sys/w32_types.h | 13 +- ZFSin/zfs/lib/libspl/include/unistd.h | 9 - ZFSin/zfs/lib/libspl/include/wosix.h | 111 +++ ZFSin/zfs/lib/libspl/posix.c | 704 ++++++++++++------- ZFSin/zfs/lib/libzfs/libzfs_crypto.c | 19 +- ZFSin/zfs/lib/libzfs/libzfs_diff.c | 10 - ZFSin/zfs/lib/libzfs/libzfs_import.c | 11 +- ZFSin/zfs/lib/libzfs/libzfs_pool.c | 39 +- ZFSin/zfs/lib/libzfs/libzfs_sendrecv.c | 94 +-- ZFSin/zfs/lib/libzfs/libzfs_util.c | 18 +- ZFSin/zfs/lib/libzfs_core/libzfs_core.c | 23 +- 21 files changed, 618 insertions(+), 575 deletions(-) create mode 100644 ZFSin/zfs/lib/libspl/include/wosix.h diff --git a/ZFSin/zfs/cmd/zfs/zfs_main.c b/ZFSin/zfs/cmd/zfs/zfs_main.c index cecd879a..8f42b2a7 100644 --- a/ZFSin/zfs/cmd/zfs/zfs_main.c +++ b/ZFSin/zfs/cmd/zfs/zfs_main.c @@ -2587,7 +2587,7 @@ userspace_cb(void *arg, const char *domain, uid_t rid, uint64_t space) if ((cb->cb_numname && cb->cb_sid2posix) || name == NULL) { if (nvlist_add_uint64(props, "name", rid) != 0) nomem(); - namelen = snprintf(NULL, 0, "%u", rid); + namelen = snprintf(NULL, 0, "%llu", rid); } else { if (nvlist_add_string(props, "name", name) != 0) nomem(); @@ -4014,7 +4014,7 @@ zfs_do_send(int argc, char **argv) } } - if (!flags.dryrun && win_isatty(STDOUT_FILENO)) { + if (!flags.dryrun && isatty(STDOUT_FILENO)) { (void) fprintf(stderr, gettext("Error: Stream can not be written to a terminal.\n" "You must redirect standard output.\n")); @@ -4267,7 +4267,7 @@ zfs_do_receive(int argc, char **argv) } - if (win_isatty(STDIN_FILENO)) { + if (isatty(STDIN_FILENO)) { (void) fprintf(stderr, gettext("Error: Backup stream can not be read " "from a terminal.\n" @@ -5334,7 +5334,7 @@ construct_fsacl_list(boolean_t un, struct allow_opts *opts, nvlist_t **nvlp) } } - (void) sprintf(id, "%u", rid); + (void) sprintf(id, "%llu", rid); who = id; store_allow_perm(who_type, opts->local, @@ -7116,7 +7116,7 @@ manual_mount(int argc, char **argv) /* check for legacy mountpoint and complain appropriately */ ret = 0; if (strcmp(mountpoint, ZFS_MOUNTPOINT_LEGACY) == 0) { - if (zmount(dataset, path, MS_OPTIONSTR | flags, MNTTYPE_ZFS, + if (zmount(zhp, path, MS_OPTIONSTR | flags, MNTTYPE_ZFS, NULL, 0, mntopts, sizeof (mntopts)) != 0) { #ifdef __APPLE__ if (errno == ENOTSUP && zfs_version > ZPL_VERSION) { diff --git a/ZFSin/zfs/cmd/zpool/zpool_main.c b/ZFSin/zfs/cmd/zpool/zpool_main.c index e83fb245..bb6119a1 100644 --- a/ZFSin/zfs/cmd/zpool/zpool_main.c +++ b/ZFSin/zfs/cmd/zpool/zpool_main.c @@ -8363,14 +8363,8 @@ zpool_do_events_next(ev_opts_t *opts) nvlist_t *nvl; int zevent_fd, ret, dropped; -#ifdef WIN32 - zevent_fd = CreateFile(ZFS_DEV, GENERIC_READ | GENERIC_WRITE, - 0, NULL, OPEN_EXISTING, 0, NULL); - VERIFY(zevent_fd != INVALID_HANDLE_VALUE); -#else zevent_fd = open(ZFS_DEV, O_RDWR); VERIFY(zevent_fd >= 0); -#endif if (!opts->scripted) (void) printf(gettext("%-30s %s\n"), "TIME", "CLASS"); @@ -8395,11 +8389,7 @@ zpool_do_events_next(ev_opts_t *opts) nvlist_free(nvl); } -#ifdef WIN32 - VERIFY(CloseHandle(zevent_fd)); -#else VERIFY(0 == close(zevent_fd)); -#endif return (ret); } diff --git a/ZFSin/zfs/cmd/zpool/zpool_vdev.c b/ZFSin/zfs/cmd/zpool/zpool_vdev.c index 452ba263..ecd612cf 100644 --- a/ZFSin/zfs/cmd/zpool/zpool_vdev.c +++ b/ZFSin/zfs/cmd/zpool/zpool_vdev.c @@ -799,7 +799,7 @@ make_leaf_vdev(nvlist_t *props, const char *arg, uint64_t is_log) return NULL; } - PARTITION_INFORMATION partInfo; + //PARTITION_INFORMATION partInfo; DWORD retcount = 0; //int err; char buf[1024]; diff --git a/ZFSin/zfs/cmd/zstreamdump/zstreamdump.c b/ZFSin/zfs/cmd/zstreamdump/zstreamdump.c index e34e527c..1416a23a 100644 --- a/ZFSin/zfs/cmd/zstreamdump/zstreamdump.c +++ b/ZFSin/zfs/cmd/zstreamdump/zstreamdump.c @@ -280,7 +280,7 @@ main(int argc, char *argv[]) } } - if (win_isatty((uintptr_t)STDIN_FILENO)) { + if (isatty(STDIN_FILENO)) { (void) fprintf(stderr, "Error: Backup stream can not be read " "from a terminal.\n" diff --git a/ZFSin/zfs/include/libzfs_impl.h b/ZFSin/zfs/include/libzfs_impl.h index 43e827cd..b4581a98 100644 --- a/ZFSin/zfs/include/libzfs_impl.h +++ b/ZFSin/zfs/include/libzfs_impl.h @@ -65,7 +65,7 @@ typedef struct libzfs_fru { struct libzfs_handle { int libzfs_error; - HANDLE libzfs_fd; + int libzfs_fd; FILE *libzfs_mnttab; FILE *libzfs_sharetab; zpool_handle_t *libzfs_pool_handles; diff --git a/ZFSin/zfs/include/sys/efi_partition.h b/ZFSin/zfs/include/sys/efi_partition.h index 1953e818..ec68ae95 100644 --- a/ZFSin/zfs/include/sys/efi_partition.h +++ b/ZFSin/zfs/include/sys/efi_partition.h @@ -233,15 +233,15 @@ struct partition64 { #endif #ifndef _KERNEL -extern int efi_alloc_and_init(HANDLE, uint32_t, struct dk_gpt **); -extern int efi_alloc_and_read(HANDLE, struct dk_gpt **); -extern int efi_write(HANDLE, struct dk_gpt *); -extern int efi_rescan(HANDLE); +extern int efi_alloc_and_init(int, uint32_t, struct dk_gpt **); +extern int efi_alloc_and_read(int, struct dk_gpt **); +extern int efi_write(int, struct dk_gpt *); +extern int efi_rescan(int); extern void efi_free(struct dk_gpt *); -extern int efi_type(HANDLE); +extern int efi_type(int); extern void efi_err_check(struct dk_gpt *); -extern int efi_auto_sense(HANDLE fd, struct dk_gpt **); -extern int efi_use_whole_disk(HANDLE fd); +extern int efi_auto_sense(int fd, struct dk_gpt **); +extern int efi_use_whole_disk(int fd); #endif #ifdef __cplusplus diff --git a/ZFSin/zfs/include/sys/zfs_context_userland.h b/ZFSin/zfs/include/sys/zfs_context_userland.h index 24f6f8e9..156ff7e5 100644 --- a/ZFSin/zfs/include/sys/zfs_context_userland.h +++ b/ZFSin/zfs/include/sys/zfs_context_userland.h @@ -458,7 +458,6 @@ typedef struct vnode vnode_t; #ifdef _WIN32 #define vnode_vid(vp) ((vp)->v_id) -#define pwrite64 pwrite int vnode_getwithvid(vnode_t *vp, uint32_t id); int vnode_getwithref(vnode_t *vp); int vnode_put(vnode_t *vp); diff --git a/ZFSin/zfs/lib/libefi/rdwr_efi.c b/ZFSin/zfs/lib/libefi/rdwr_efi.c index 06a1a4af..11b5b9e2 100644 --- a/ZFSin/zfs/lib/libefi/rdwr_efi.c +++ b/ZFSin/zfs/lib/libefi/rdwr_efi.c @@ -49,56 +49,6 @@ #include #include int osx_device_isvirtual(char *pathbuf); -#endif - -#ifdef _WIN32 -#include -#include - -static inline int lseek(HANDLE fd, uint64_t offset, int seek) -{ - LARGE_INTEGER LOFF, LNEW; - int type; - - LOFF.QuadPart = offset; - switch (seek) { - case SEEK_SET: - type = FILE_BEGIN; - break; - case SEEK_CUR: - type = FILE_CURRENT; - break; - case SEEK_END: - type = FILE_END; - break; - } - if (!SetFilePointerEx(fd, LOFF, &LNEW, type)) - return -1; - return LNEW.QuadPart; -} - -static inline int read(HANDLE fd, void *data, uint32_t len) -{ - DWORD red; - - if (!ReadFile(fd, data, len, &red, NULL)) - return -1; - - return red; -} - -static inline int write(HANDLE fd, void *data, uint32_t len) -{ - DWORD wrote; - - if (!WriteFile(fd, data, len, &wrote, NULL)) - return -1; - - return wrote; -} - - - #endif static struct uuid_to_ptag { @@ -189,13 +139,13 @@ efi_crc32(const unsigned char *buf, unsigned int size) } static int -read_disk_info(HANDLE fd, diskaddr_t *capacity, uint_t *lbsize) +read_disk_info(int fd, diskaddr_t *capacity, uint_t *lbsize) { DISK_GEOMETRY_EX geometry_ex; DWORD len; LARGE_INTEGER large; - if (DeviceIoControl(fd, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, + if (DeviceIoControl(ITOH(fd), IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, &geometry_ex, sizeof(geometry_ex), &len, NULL)) { *lbsize = (uint_t)geometry_ex.Geometry.BytesPerSector; @@ -208,7 +158,7 @@ read_disk_info(HANDLE fd, diskaddr_t *capacity, uint_t *lbsize) } static int -efi_get_info(HANDLE fd, struct dk_cinfo *dki_info) +efi_get_info(int fd, struct dk_cinfo *dki_info) { int rval = 0; #if defined(__linux__) @@ -378,7 +328,7 @@ efi_get_info(HANDLE fd, struct dk_cinfo *dki_info) PARTITION_INFORMATION partInfo; DWORD retcount = 0; int err; - err = DeviceIoControl(fd, + err = DeviceIoControl(ITOH(fd), IOCTL_DISK_GET_PARTITION_INFO, (LPVOID)NULL, (DWORD)0, @@ -423,7 +373,7 @@ efi_get_info(HANDLE fd, struct dk_cinfo *dki_info) sizeof (struct dk_part)) int -efi_alloc_and_init(HANDLE fd, uint32_t nparts, struct dk_gpt **vtoc) +efi_alloc_and_init(int fd, uint32_t nparts, struct dk_gpt **vtoc) { diskaddr_t capacity = 0; uint_t lbsize = 0; @@ -494,7 +444,7 @@ efi_alloc_and_init(HANDLE fd, uint32_t nparts, struct dk_gpt **vtoc) * Read EFI - return partition number upon success. */ int -efi_alloc_and_read(HANDLE fd, struct dk_gpt **vtoc) +efi_alloc_and_read(int fd, struct dk_gpt **vtoc) { int rval; uint32_t nparts; @@ -539,7 +489,7 @@ efi_alloc_and_read(HANDLE fd, struct dk_gpt **vtoc) } static int -efi_ioctl(HANDLE fd, int cmd, dk_efi_t *dk_ioc) +efi_ioctl(int fd, int cmd, dk_efi_t *dk_ioc) { void *data = dk_ioc->dki_data; int error; @@ -630,11 +580,8 @@ efi_ioctl(HANDLE fd, int cmd, dk_efi_t *dk_ioc) } /* Sync the new EFI table to disk */ -#ifdef _WIN32 - FlushFileBuffers(fd); // I think I added fsync to posix.c, but this is the only call? -#else error = fsync(fd); -#endif + if (error == -1) return (error); @@ -662,7 +609,7 @@ efi_ioctl(HANDLE fd, int cmd, dk_efi_t *dk_ioc) } int -efi_rescan(HANDLE fd) +efi_rescan(int fd) { #if defined(__linux__) int retry = 10; @@ -683,7 +630,7 @@ efi_rescan(HANDLE fd) } static int -check_label(HANDLE fd, dk_efi_t *dk_ioc) +check_label(int fd, dk_efi_t *dk_ioc) { efi_gpt_t *efi; uint_t crc; @@ -735,7 +682,7 @@ check_label(HANDLE fd, dk_efi_t *dk_ioc) } static int -efi_read(HANDLE fd, struct dk_gpt *vtoc) +efi_read(int fd, struct dk_gpt *vtoc) { int i, j; int label_len; @@ -1000,7 +947,7 @@ efi_read(HANDLE fd, struct dk_gpt *vtoc) /* writes a "protective" MBR */ static int -write_pmbr(HANDLE fd, struct dk_gpt *vtoc) +write_pmbr(int fd, struct dk_gpt *vtoc) { dk_efi_t dk_ioc; struct mboot mb; @@ -1191,7 +1138,7 @@ check_input(struct dk_gpt *vtoc) * add all the unallocated space to the current label */ int -efi_use_whole_disk(HANDLE fd) +efi_use_whole_disk(int fd) { struct dk_gpt *efi_label; int rval; @@ -1273,7 +1220,7 @@ efi_use_whole_disk(HANDLE fd) * write EFI label and backup label */ int -efi_write(HANDLE fd, struct dk_gpt *vtoc) +efi_write(int fd, struct dk_gpt *vtoc) { dk_efi_t dk_ioc; efi_gpt_t *efi; @@ -1487,7 +1434,7 @@ efi_free(struct dk_gpt *ptr) * Otherwise 0. */ int -efi_type(HANDLE fd) +efi_type(int fd) { #if 0 struct vtoc vtoc; @@ -1604,7 +1551,7 @@ efi_err_check(struct dk_gpt *vtoc) * label type */ int -efi_auto_sense(HANDLE fd, struct dk_gpt **vtoc) +efi_auto_sense(int fd, struct dk_gpt **vtoc) { int i; diff --git a/ZFSin/zfs/lib/libshare/libshare.c b/ZFSin/zfs/lib/libshare/libshare.c index 96e77a9c..d8ff1aab 100644 --- a/ZFSin/zfs/lib/libshare/libshare.c +++ b/ZFSin/zfs/lib/libshare/libshare.c @@ -196,15 +196,9 @@ update_sharetab(sa_handle_impl_t impl_handle) sa_fstype_t *fstype; const char *resource; -#ifdef _WIN32 - if (mkdir("/etc/dfs") < 0 && errno != EEXIST) { - return; - } -#else if (mkdir("/etc/dfs", 0755) < 0 && errno != EEXIST) { return; } -#endif temp_fd = mkstemp(tempfile); diff --git a/ZFSin/zfs/lib/libspl/fdatasync.c b/ZFSin/zfs/lib/libspl/fdatasync.c index 5b0b67bf..971836fa 100644 --- a/ZFSin/zfs/lib/libspl/fdatasync.c +++ b/ZFSin/zfs/lib/libspl/fdatasync.c @@ -19,13 +19,3 @@ * CDDL HEADER END */ -#include -#include - -int -fdatasync(int fd) -{ - //if (fcntl(fd, F_FULLFSYNC) == -1) - // return -1; - return 0; -} diff --git a/ZFSin/zfs/lib/libspl/include/sys/w32_types.h b/ZFSin/zfs/lib/libspl/include/sys/w32_types.h index 2a390672..8ae3c1ee 100644 --- a/ZFSin/zfs/lib/libspl/include/sys/w32_types.h +++ b/ZFSin/zfs/lib/libspl/include/sys/w32_types.h @@ -44,6 +44,9 @@ #include #include +/* Now replace POSIX calls with our versions. */ +#include + typedef enum boolean { B_FALSE=0, B_TRUE } boolean_t; typedef enum boolean bool_t; @@ -157,9 +160,9 @@ typedef union { #define FLT_MAX 3.4028234663852885981170E+38F #define FLT_MIN 1.1754943508222875079688E-38F -#define STDIN_FILENO GetStdHandle(STD_INPUT_HANDLE) -#define STDOUT_FILENO GetStdHandle(STD_OUTPUT_HANDLE) -#define STDERR_FILENO GetStdHandle(STD_ERROR_HANDLE) +#define STDIN_FILENO HTOI(GetStdHandle(STD_INPUT_HANDLE)) +#define STDOUT_FILENO HTOI(GetStdHandle(STD_OUTPUT_HANDLE)) +#define STDERR_FILENO HTOI(GetStdHandle(STD_ERROR_HANDLE)) #define O_EXLOCK 0 #define bzero(b,len) (memset((b), '\0', (len))) @@ -176,9 +179,9 @@ int posix_memalign(void **memptr, size_t alignment, size_t size); #define sleep(x) Sleep(x * 1000) -int fsync(int); - #define lstat _stat64 +#define unlink _unlink +#define strdup _strdup #define MFSTYPENAMELEN 16 #define MNAMELEN MAXPATHLEN diff --git a/ZFSin/zfs/lib/libspl/include/unistd.h b/ZFSin/zfs/lib/libspl/include/unistd.h index 219614ef..54f5572c 100644 --- a/ZFSin/zfs/lib/libspl/include/unistd.h +++ b/ZFSin/zfs/lib/libspl/include/unistd.h @@ -49,10 +49,7 @@ extern int optopt; extern int optreset; extern char *optarg; -int fdatasync(int fd); - #include -#define ftruncate _chsize_s #include #include @@ -64,24 +61,18 @@ size_t strlcat(register char* s, register const char* t, register size_t n); ssize_t getline(char** linep, size_t *linecapp, FILE* stream); -int pread(int fd, void* buf, size_t nbyte, off_t offset); int pread_win(HANDLE h, void* buf, size_t nbyte, off_t offset); -int pwrite(HANDLE h, const void* buf, size_t nbyte, off_t offset); -int fstat_blk(int fd, struct _stat64* st); int pipe(int fildes[2]); char* realpath(const char* file_name, char* resolved_name); -int win_isatty(uintptr_t h); int usleep(__int64 usec); int vasprintf(char** strp, const char* fmt, va_list ap); int asprintf(char** strp, const char* fmt, ...); int strncasecmp(char* s1, char* s2, size_t n); -int socketpair(int* sv); int readlink(const char* path, char* buf, size_t bufsize); const char* getexecname(void); uint64_t geteuid(void); struct zfs_cmd; -int ioctl(HANDLE hDevice, unsigned long request, struct zfs_cmd *zc); int mkstemp(char* tmpl); int64_t gethrtime(void); int gettimeofday(struct timeval* tp, struct timezone* tzp); diff --git a/ZFSin/zfs/lib/libspl/include/wosix.h b/ZFSin/zfs/lib/libspl/include/wosix.h new file mode 100644 index 00000000..3b79af95 --- /dev/null +++ b/ZFSin/zfs/lib/libspl/include/wosix.h @@ -0,0 +1,111 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + /* + * Copyright(c) 2019 Jorgen Lundman + */ + +#ifndef WOSIX_HEADER +#define WOSIX_HEADER + +/* Replace all the normal POSIX calls; open, read, write, close, lseek, fstat + * As we have to use HANDLEs to open devices, we add a shim-layer to handle + * int fd and the change in underlying API calls. + * First, include the header that defines them in Windows. + */ +#include +#include +#include +#include + +#define HTOI(H) ((int)(unsigned __int64)(H)) +#define ITOH(I) ((HANDLE)(unsigned __int64)(I)) + +extern int wosix_fsync(int fd); +extern int wosix_open(const char *path, int oflag, ...); +extern int wosix_close(int fd); +extern int wosix_ioctl(int fd, unsigned long request, void *zc); +extern int wosix_read(int fd, void *data, uint32_t len); +extern int wosix_write(int fd, const void *data, uint32_t len); +extern int wosix_isatty(int fd); +extern int wosix_mkdir(const char *path, mode_t mode); +extern int wosix_pwrite(int fd, const void *buf, size_t nbyte, off_t offset); +extern int wosix_pread(int fd, void *buf, size_t nbyte, off_t offset); +extern int wosix_fstat(int fd, struct _stat64 *st); +extern int wosix_fstat_blk(int fd, struct _stat64 *st); +extern uint64_t wosix_lseek(int fd, uint64_t offset, int seek); +extern int wosix_fdatasync(int fd); +extern int wosix_ftruncate(int fd, off_t length); +extern int wosix_socketpair(int domain, int type, int protocol, int socket_vector[2]); +extern int wosix_dup2(int fildes, int fildes2); + +#define wosix_fileno(X) (_get_osfhandle(_fileno((X)))) + +extern FILE *wosix_fdopen(int fildes, const char *mode); + + /* + * Thin wrapper for the POSIX IO calls, to translate to HANDLEs + * + * Currently it "hopes" that HANDLE value will fit in type "int". + * This could be improved in future. + */ +#undef open +#define open wosix_open +#undef close +#define close wosix_close +#undef ioctl +#define ioctl wosix_ioctl +#undef lseek +#define lseek wosix_lseek +#undef fsync +#define fsync wosix_fsync +#undef read +#define read wosix_read +#undef write +#define write wosix_write +#undef fileno +#define fileno wosix_fileno +#undef isatty +#define isatty wosix_isatty +#undef mkdir +#define mkdir wosix_mkdir +#undef pread +#define pread wosix_pread +#define pread64 wosix_pread +#undef pwrite +#define pwrite wosix_pwrite +#define pwrite64 wosix_pwrite +#undef fstat +#define fstat wosix_fstat +#undef fstat_blk +#define fstat_blk wosix_fstat_blk +#undef fdatasync +#define fdatasync wosix_fdatasync +#undef ftruncate +#define ftruncate wosix_ftruncate +#undef socketpair +#define socketpair wosix_socketpair +#undef fdopen +#define fdopen wosix_fdopen +#undef dup2 +#define dup2 wosix_dup2 + +#endif /* WOSIX_HEADER */ \ No newline at end of file diff --git a/ZFSin/zfs/lib/libspl/posix.c b/ZFSin/zfs/lib/libspl/posix.c index c0f59b8d..b98521e7 100644 --- a/ZFSin/zfs/lib/libspl/posix.c +++ b/ZFSin/zfs/lib/libspl/posix.c @@ -48,14 +48,7 @@ int posix_memalign(void **memptr, size_t alignment, size_t size) return 0; } -int fsync(int fd) { - HANDLE h = (HANDLE)_get_osfhandle(fd); - if (!FlushFileBuffers(h)) - return EIO; - return 0; -} - -const char* getexecname(void) +const char *getexecname(void) { __declspec(thread) static char execname[32767 + 1]; GetModuleFileNameA(NULL, execname, sizeof(execname)); @@ -125,93 +118,6 @@ char *realpath(const char *file_name, char *resolved_name) return resolved_name; } -int pread(int fd, void *buf, size_t nbyte, off_t offset) -{ - uint64_t off; - int red; - - off = _lseek(fd, 0, SEEK_CUR); - if (_lseek(fd, offset, SEEK_SET) != offset) - return -1; - - red = read(fd, buf, nbyte); - - _lseek(fd, off, SEEK_SET); - - return red; -} - -int pread_win(HANDLE h, void *buf, size_t nbyte, off_t offset) -{ - uint64_t off; - DWORD red; - LARGE_INTEGER large; - LARGE_INTEGER lnew; - - // This code does all seeks based on "current" so we can pre-seek to offset start - - // Find current position - large.QuadPart = 0; - SetFilePointerEx(h, large, &lnew, FILE_CURRENT); - - // Seek to place to read - large.QuadPart = offset; - SetFilePointerEx(h, large, NULL, FILE_CURRENT); - - // Read - if (!ReadFile(h, buf, nbyte, &red, NULL)) - red = -GetLastError(); - - // Restore position - SetFilePointerEx(h, lnew, NULL, FILE_BEGIN); - - return red; -} - -int pwrite(HANDLE h, const void *buf, size_t nbyte, off_t offset) -{ - uint64_t off; - DWORD wrote; - LARGE_INTEGER large; - LARGE_INTEGER lnew; - - // This code does all seeks based on "current" so we can pre-seek to offset start - - // Find current position - large.QuadPart = 0; - SetFilePointerEx(h, large, &lnew, FILE_CURRENT); - - // Seek to place to read - large.QuadPart = offset; - SetFilePointerEx(h, large, NULL, FILE_CURRENT); - - // Read - if (!WriteFile(h, buf, nbyte, &wrote, NULL)) - wrote = -GetLastError(); - - // Restore position - SetFilePointerEx(h, lnew, NULL, FILE_BEGIN); - - return wrote; -} - - -int fstat_blk(int fd, struct _stat64 *st) -{ - DISK_GEOMETRY_EX geometry_ex; - HANDLE handle; - DWORD len; - - handle = (HANDLE) _get_osfhandle(fd); - if (!DeviceIoControl(handle, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, - &geometry_ex, sizeof(geometry_ex), &len, NULL)) - return -1; - - st->st_size = (diskaddr_t)geometry_ex.DiskSize.QuadPart; - - return (0); -} - int statfs(const char *path, struct statfs *buf) { ULARGE_INTEGER lpFreeBytesAvailable; @@ -332,7 +238,6 @@ mkstemp(char *tmpl) return -1; } - int readlink(const char *path, char *buf, size_t bufsize) { return -1; @@ -461,7 +366,8 @@ basename(char *arg) return(basedir(arg, BASENAME)); } -char* getIoctlAsString(int cmdNo) { +char* getIoctlAsString(int cmdNo) +{ switch (cmdNo) { case 0x800: return "ZFS_IOC_FIRST"; case 0x801: return "ZFS_IOC_POOL_DESTROY"; @@ -557,66 +463,11 @@ char* getIoctlAsString(int cmdNo) { } } -int ioctl(HANDLE hDevice, unsigned long request, zfs_cmd_t *zc) -{ - int error; - //HANDLE hDevice; - ULONG bytesReturned; - - //hDevice = _get_osfhandle(fd); -#if 0 - fprintf(stderr, "calling ioctl on 0x%x (raw 0x%x) struct size %d in %p:%d out %p:%d\n", - (request&0x2ffc) >> 2, request, - sizeof(zfs_cmd_t), - zc->zc_nvlist_src, zc->zc_nvlist_src_size, - zc->zc_nvlist_dst, zc->zc_nvlist_dst_size - ); fflush(stderr); - strcpy(zc->zc_name, "thisisatest"); - zc->zc_dev = 0x12345678; - for (int x = 0; x < 16; x++) - fprintf(stderr, "%02x ", ((unsigned char *)zc)[x]); - fprintf(stderr, "\n"); - fflush(stderr); -#endif - error = DeviceIoControl(hDevice, - (DWORD)request, - zc, - (DWORD)sizeof(zfs_cmd_t), - zc, - (DWORD)sizeof(zfs_cmd_t), - &bytesReturned, - NULL - ); - - if (error == 0) - error = GetLastError(); - else - error = zc->zc_ioc_error; - -#ifdef DEBUG - fprintf(stderr, " (ioctl 0x%x (%s) status %d bytes %ld)\n", (request & 0x2ffc) >> 2, getIoctlAsString((request & 0x2ffc) >> 2), error, bytesReturned); fflush(stderr); -#endif -#if 0 - for (int x = 0; x < 16; x++) - fprintf(stderr, "%02x ", ((unsigned char *)zc)[x]); - fprintf(stderr, "\n"); - fflush(stderr); - fprintf(stderr, "returned ioctl on 0x%x (raw 0x%x) struct size %d in %p:%d out %p:%d\n", - (request & 0x2ffc) >> 2, request, - sizeof(zfs_cmd_t), - zc->zc_nvlist_src, zc->zc_nvlist_src_size, - zc->zc_nvlist_dst, zc->zc_nvlist_dst_size - ); fflush(stderr); -#endif - errno = error; - return error; -} - int vasprintf(char **strp, const char *fmt, va_list ap) { int r = -1, size; - + size = _vscprintf(fmt, ap); if ((size >= 0) && (size < INT_MAX)) { @@ -629,7 +480,7 @@ int vasprintf(char **strp, const char *fmt, va_list ap) } } } else { - *strp = 0; + *strp = 0; } return(r); @@ -755,7 +606,7 @@ openlog(const char *ident, int logopt, int facility) } void -syslog(int priority, const char *message, ... ) +syslog(int priority, const char *message, ...) { } @@ -784,82 +635,6 @@ unmount(const char *dir, int flags) return -1; } -int socketpair(int *sv) -{ - int temp, s1, s2, result; - struct sockaddr_in saddr; - int nameLen; - unsigned long option_arg = 1; - - nameLen = sizeof(saddr); - - /* ignore address family for now; just stay with AF_INET */ - temp = socket(AF_INET, SOCK_STREAM, 0); - if (temp == INVALID_SOCKET) return -1; - - setsockopt(temp, SOL_SOCKET, SO_REUSEADDR, (void *)&option_arg, - sizeof(option_arg)); - - /* We *SHOULD* choose the correct sockaddr structure based - on the address family requested... */ - memset(&saddr, 0, sizeof(saddr)); - - saddr.sin_family = AF_INET; - saddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); - saddr.sin_port = 0; // give me a port - - result = bind(temp, (struct sockaddr *)&saddr, nameLen); - if (result == SOCKET_ERROR) { - errno = WSAGetLastError(); - closesocket(temp); - return -2; - } - - // Don't care about error here, the connect will fail instead - listen(temp, 1); - - // Fetch out the port that was given to us. - nameLen = sizeof(struct sockaddr_in); - - result = getsockname(temp, (struct sockaddr *)&saddr, &nameLen); - - if (result == INVALID_SOCKET) { - closesocket(temp); - return -4; /* error case */ - } - - s1 = socket(AF_INET, SOCK_STREAM, 0); - if (s1 == INVALID_SOCKET) { - closesocket(temp); - return -5; - } - - nameLen = sizeof(struct sockaddr_in); - - result = connect(s1, (struct sockaddr *)&saddr, nameLen); - - if (result == INVALID_SOCKET) { - closesocket(temp); - closesocket(s1); - return -6; /* error case */ - } - - s2 = accept(temp, NULL, NULL); - - closesocket(temp); - - if (s2 == INVALID_SOCKET) { - closesocket(s1); - return -7; - } - - sv[0] = s1; sv[1] = s2; - - if ((sv[0] < 0) || (sv[1] < 0)) return -8; - - return 0; /* normal case */ -} - extern size_t strlcpy(register char* s, register const char* t, register size_t n) { @@ -919,44 +694,6 @@ char *strndup(char *src, size_t size) return r; } -int win_isatty(uintptr_t x) -{ - DWORD mode; - HANDLE h = (HANDLE)x; - int ret; -#if 0 - const unsigned long bufSize = sizeof(DWORD) + MAX_PATH * sizeof(WCHAR); - BYTE buf[sizeof(DWORD) + MAX_PATH * sizeof(WCHAR)]; - PFILE_NAME_INFO pfni = (PFILE_NAME_INFO)buf; - - if (!GetFileInformationByHandleEx(h, FileNameInfo, buf, bufSize)) { - return 0; - } - - PWSTR fn = pfni->FileName; - fn[pfni->FileNameLength] = L'\0'; - - ret = ((wcsstr(fn, L"\\cygwin-") || wcsstr(fn, L"\\msys-")) && - wcsstr(fn, L"-pty") && wcsstr(fn, L"-master")); - - //printf("ret %d Got name as '%S'\n", ret, fn); fflush(stdout); - return ret; -#else - - ret = ((GetFileType(h) & ~FILE_TYPE_REMOTE) == FILE_TYPE_CHAR); - -#endif - //fprintf(stderr, "%s: return %d\r\n", __func__, ret); - //fflush(stderr); - - // FIXME - always say it ISN'T a tty, this way zfs send will work - // everywhere - the only negative side-effect is garbage printed - // on console if users do something dumb. - return 0; - - return ret; -} - int setrlimit(int resource, const struct rlimit *rlp) { return 0; @@ -1014,4 +751,431 @@ ssize_t getline(char **linep, size_t* linecapp, SetConsoleMode(hStdin, mode); return i; -} \ No newline at end of file +} + + +/* Windows POSIX wrappers */ + + +int wosix_fsync(int fd) +{ + if (!FlushFileBuffers(ITOH(fd))) + return EIO; + return 0; +} + +int wosix_open(const char *path, int oflag, ...) +{ + HANDLE h; + DWORD mode = GENERIC_READ; // RDONLY=0, WRONLY=1, RDWR=2; + DWORD how = OPEN_EXISTING; + DWORD share = FILE_SHARE_READ; + // This is wrong, not all bitfields + if (oflag&O_WRONLY) mode = GENERIC_WRITE; + if (oflag&O_RDWR) mode = GENERIC_READ | GENERIC_WRITE; + + switch (oflag&(O_CREAT | O_TRUNC | O_EXCL)) { + case O_CREAT: + how = OPEN_ALWAYS; + break; + case O_TRUNC: + how = TRUNCATE_EXISTING; + break; + case (O_CREAT | O_EXCL): + case (O_CREAT | O_EXCL | O_TRUNC): // Only creating new implies starting from 0 + how = CREATE_NEW; + break; + case (O_CREAT | O_TRUNC): + how = CREATE_ALWAYS; + break; + default: + case O_EXCL: // Invalid, ignore bit - treat as normal open + how = OPEN_EXISTING; + break; + } + if (oflag&O_APPEND) mode |= FILE_APPEND_DATA; + +#ifdef O_EXLOCK + if (!oflag&O_EXLOCK) share |= FILE_SHARE_WRITE; +#endif + + h = CreateFile(path, mode, share, NULL, how, FILE_ATTRIBUTE_NORMAL, NULL); + if (h == INVALID_HANDLE_VALUE) { + errno = EINVAL; + switch (GetLastError()) { + case ERROR_FILE_NOT_FOUND: + case ERROR_PATH_NOT_FOUND: + errno = ENOENT; + break; + case ERROR_ACCESS_DENIED: + errno = EACCES; + break; + case ERROR_FILE_EXISTS: + errno = EEXIST; + break; + } + return -1; + } + return (HTOI(h)); +} + +int wosix_close(int fd) +{ + HANDLE h = ITOH(fd); + + // Use CloseHandle() for everything except sockets. + if ((GetFileType(h) == FILE_TYPE_REMOTE) && + !GetNamedPipeInfo(h, NULL, NULL, NULL, NULL)) + return closesocket((SOCKET)h); + + if (CloseHandle(h)) + return 0; + return -1; +} + +int wosix_ioctl(int fd, unsigned long request, zfs_cmd_t *zc) +{ + int error; + ULONG bytesReturned; + + error = DeviceIoControl(ITOH(fd), + (DWORD)request, + zc, + (DWORD)sizeof(zfs_cmd_t), + zc, + (DWORD)sizeof(zfs_cmd_t), + &bytesReturned, + NULL + ); + + if (error == 0) + error = GetLastError(); + else + error = zc->zc_ioc_error; + +#ifdef DEBUG + fprintf(stderr, " (ioctl 0x%x (%s) status %d bytes %ld)\n", (request & 0x2ffc) >> 2, getIoctlAsString((request & 0x2ffc) >> 2), error, bytesReturned); fflush(stderr); +#endif +#if 0 + for (int x = 0; x < 16; x++) + fprintf(stderr, "%02x ", ((unsigned char *)zc)[x]); + fprintf(stderr, "\n"); + fflush(stderr); + fprintf(stderr, "returned ioctl on 0x%x (raw 0x%x) struct size %d in %p:%d out %p:%d\n", + (request & 0x2ffc) >> 2, request, + sizeof(zfs_cmd_t), + zc->zc_nvlist_src, zc->zc_nvlist_src_size, + zc->zc_nvlist_dst, zc->zc_nvlist_dst_size + ); fflush(stderr); +#endif + errno = error; + return error; +} + +uint64_t wosix_lseek(int fd, uint64_t offset, int seek) +{ + LARGE_INTEGER LOFF, LNEW; + int type = FILE_BEGIN; + + LOFF.QuadPart = offset; + switch (seek) { + case SEEK_SET: + type = FILE_BEGIN; + break; + case SEEK_CUR: + type = FILE_CURRENT; + break; + case SEEK_END: + type = FILE_END; + break; + } + if (!SetFilePointerEx(ITOH(fd), LOFF, &LNEW, type)) + return -1; + return LNEW.QuadPart; +} + +int wosix_read(int fd, void *data, uint32_t len) +{ + DWORD red; + + if (!ReadFile(ITOH(fd), data, len, &red, NULL)) + return -1; + + return red; +} + +int wosix_write(int fd, const void *data, uint32_t len) +{ + DWORD wrote; + + if (!WriteFile(ITOH(fd), data, len, &wrote, NULL)) + return -1; + + return wrote; +} + +int wosix_isatty(int fd) +{ + DWORD mode; + HANDLE h = ITOH(fd); + int ret; +#if 0 + const unsigned long bufSize = sizeof(DWORD) + MAX_PATH * sizeof(WCHAR); + BYTE buf[sizeof(DWORD) + MAX_PATH * sizeof(WCHAR)]; + PFILE_NAME_INFO pfni = (PFILE_NAME_INFO)buf; + + if (!GetFileInformationByHandleEx(h, FileNameInfo, buf, bufSize)) { + return 0; + } + + PWSTR fn = pfni->FileName; + fn[pfni->FileNameLength] = L'\0'; + + ret = ((wcsstr(fn, L"\\cygwin-") || wcsstr(fn, L"\\msys-")) && + wcsstr(fn, L"-pty") && wcsstr(fn, L"-master")); + + //printf("ret %d Got name as '%S'\n", ret, fn); fflush(stdout); + return ret; +#else + + ret = ((GetFileType(h) & ~FILE_TYPE_REMOTE) == FILE_TYPE_CHAR); + +#endif + //fprintf(stderr, "%s: return %d\r\n", __func__, ret); + //fflush(stderr); + + // FIXME - always say it ISN'T a tty, this way zfs send will work + // everywhere - the only negative side-effect is garbage printed + // on console if users do something dumb. + return 0; + + return ret; +} + +// A bit different, just to wrap away the second argument +// Presumably _mkdir() sets errno, as EEXIST is tested. +int wosix_mkdir(const char *path, mode_t mode) +{ + return _mkdir(path); +} + +// Only fill in what we actually use in ZFS +// Mostly used to test for existance, st_mode, st_size +// also FIFO and BLK (fixme) +int wosix_fstat(int fd, struct _stat64 *st) +{ + HANDLE h = ITOH(fd); + BY_HANDLE_FILE_INFORMATION info; + + if (!GetFileInformationByHandle(h, &info)) + return -1; // errno? + + st->st_dev = 0; + st->st_ino = 0; + st->st_mode = (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? + _S_IFDIR : _S_IFREG; + st->st_nlink = (info.nNumberOfLinks > SHRT_MAX ? SHRT_MAX : info.nNumberOfLinks); + st->st_uid = 0; + st->st_gid = 0; + st->st_rdev = 0; + st->st_size = ((long long)info.nFileSizeHigh << 32ULL) | (long long)info.nFileSizeLow; + st->st_atime = 0; + st->st_mtime = 0; + st->st_ctime = 0; + + return 0; +} + +int wosix_fstat_blk(int fd, struct _stat64 *st) +{ + DISK_GEOMETRY_EX geometry_ex; + HANDLE handle = ITOH(fd); + DWORD len; + + if (!DeviceIoControl(handle, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, + &geometry_ex, sizeof(geometry_ex), &len, NULL)) + return -1; + + st->st_size = (diskaddr_t)geometry_ex.DiskSize.QuadPart; + + return (0); +} + +// os specific files can call this directly. +int pread_win(HANDLE h, void *buf, size_t nbyte, off_t offset) +{ + uint64_t off; + DWORD red; + LARGE_INTEGER large; + LARGE_INTEGER lnew; + + // This code does all seeks based on "current" so we can pre-seek to offset start + + // Find current position + large.QuadPart = 0; + SetFilePointerEx(h, large, &lnew, FILE_CURRENT); + + // Seek to place to read + large.QuadPart = offset; + SetFilePointerEx(h, large, NULL, FILE_CURRENT); + + // Read + if (!ReadFile(h, buf, nbyte, &red, NULL)) + red = -GetLastError(); + + // Restore position + SetFilePointerEx(h, lnew, NULL, FILE_BEGIN); + + return red; +} + +int wosix_pread(int fd, void *buf, size_t nbyte, off_t offset) +{ + return pread_win(ITOH(fd), buf, nbyte, offset); +} + +int wosix_pwrite(int fd, const void *buf, size_t nbyte, off_t offset) +{ + HANDLE h = ITOH(fd); + uint64_t off; + DWORD wrote; + LARGE_INTEGER large; + LARGE_INTEGER lnew; + + // This code does all seeks based on "current" so we can pre-seek to offset start + + // Find current position + large.QuadPart = 0; + SetFilePointerEx(h, large, &lnew, FILE_CURRENT); + + // Seek to place to read + large.QuadPart = offset; + SetFilePointerEx(h, large, NULL, FILE_CURRENT); + + // Write + if (!WriteFile(h, buf, nbyte, &wrote, NULL)) + wrote = -GetLastError(); + + // Restore position + SetFilePointerEx(h, lnew, NULL, FILE_BEGIN); + + return wrote; +} + +int wosix_fdatasync(int fd) +{ + //if (fcntl(fd, F_FULLFSYNC) == -1) + // return -1; + return 0; +} + +int wosix_ftruncate(int fd, off_t length) +{ + HANDLE h = ITOH(fd); + LARGE_INTEGER lnew; + + lnew.QuadPart = length; + if (SetFilePointerEx(h, lnew, NULL, FILE_BEGIN) && + SetEndOfFile(h)) + return 0; // Success + // errno? + return -1; +} + +// This one is a little bit special, ordinarily +// we would take the HANDLE and convert it to a +// FILE *, using _fdopen(_open_osfhandle()); +// But, this is only used from libzfs_sendrecv.c and +// comes from socketpair() - which uses sockets, ie +// already HANDLEs. So they are passed into ssread() +// which uses HANDLEs directly. close() is updated +// to handle closing of SOCKETS. +// Note we do not change fread()/fwrite() from FILE* +// as they are used throughout userland. The fix +// resides in ssread(). +FILE *wosix_fdopen(int fd, const char *mode) +{ + return ((FILE *)ITOH(fd)); +} + +int wosix_socketpair(int domain, int type, int protocol, int sv[2]) +{ + int temp, s1, s2, result; + struct sockaddr_in saddr; + int nameLen; + unsigned long option_arg = 1; + + nameLen = sizeof(saddr); + + /* ignore address family for now; just stay with AF_INET */ + temp = socket(AF_INET, SOCK_STREAM, 0); + if (temp == INVALID_SOCKET) return -1; + + setsockopt(temp, SOL_SOCKET, SO_REUSEADDR, (void *)&option_arg, + sizeof(option_arg)); + + /* We *SHOULD* choose the correct sockaddr structure based + on the address family requested... */ + memset(&saddr, 0, sizeof(saddr)); + + saddr.sin_family = AF_INET; + saddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + saddr.sin_port = 0; // give me a port + + result = bind(temp, (struct sockaddr *)&saddr, nameLen); + if (result == SOCKET_ERROR) { + errno = WSAGetLastError(); + closesocket(temp); + return -2; + } + + // Don't care about error here, the connect will fail instead + listen(temp, 1); + + // Fetch out the port that was given to us. + nameLen = sizeof(struct sockaddr_in); + + result = getsockname(temp, (struct sockaddr *)&saddr, &nameLen); + + if (result == INVALID_SOCKET) { + closesocket(temp); + return -4; /* error case */ + } + + s1 = socket(AF_INET, SOCK_STREAM, 0); + if (s1 == INVALID_SOCKET) { + closesocket(temp); + return -5; + } + + nameLen = sizeof(struct sockaddr_in); + + result = connect(s1, (struct sockaddr *)&saddr, nameLen); + + if (result == INVALID_SOCKET) { + closesocket(temp); + closesocket(s1); + return -6; /* error case */ + } + + s2 = accept(temp, NULL, NULL); + + closesocket(temp); + + if (s2 == INVALID_SOCKET) { + closesocket(s1); + return -7; + } + + sv[0] = s1; sv[1] = s2; + + if ((sv[0] < 0) || (sv[1] < 0)) return -8; + + return 0; /* normal case */ +} + +int wosix_dup2(int fildes, int fildes2) +{ + return -1; +} + diff --git a/ZFSin/zfs/lib/libzfs/libzfs_crypto.c b/ZFSin/zfs/lib/libzfs/libzfs_crypto.c index 67625f9c..234c1fb4 100644 --- a/ZFSin/zfs/lib/libzfs/libzfs_crypto.c +++ b/ZFSin/zfs/lib/libzfs/libzfs_crypto.c @@ -135,12 +135,7 @@ get_key_material_raw(FILE *fd, const char *fsname, zfs_keyformat_t keyformat, #endif *len_out = 0; - -#ifdef _WIN32 - if (win_isatty(_get_osfhandle(_fileno(fd)))) { -#else - if (isatty(fileno(fd)) { -#endif + if (isatty(fileno(fd))) { /* * handle SIGINT and ignore SIGSTP. This is necessary to * restore the state of the terminal. @@ -224,11 +219,7 @@ get_key_material_raw(FILE *fd, const char *fsname, zfs_keyformat_t keyformat, *len_out = bytes; out: -#ifdef _WIN32 - if (win_isatty(_get_osfhandle(_fileno(fd)))) { -#else if (isatty(fileno(fd))) { -#endif /* reset the teminal */ (void) tcsetattr(fileno(fd), TCSAFLUSH, &old_term); #ifndef _WIN32 @@ -276,11 +267,7 @@ get_key_material(libzfs_handle_t *hdl, boolean_t do_verify, boolean_t newkey, switch (keyloc) { case ZFS_KEYLOCATION_PROMPT: fd = stdin; -#ifdef _WIN32 - if (win_isatty(_get_osfhandle(_fileno(fd)))) { -#else if (isatty(fileno(fd))) { -#endif can_retry = B_TRUE; /* raw keys cannot be entered on the terminal */ @@ -386,11 +373,7 @@ get_key_material(libzfs_handle_t *hdl, boolean_t do_verify, boolean_t newkey, break; } -#ifdef _WIN32 - if (do_verify && win_isatty(_get_osfhandle(_fileno(fd)))) { -#else if (do_verify && isatty(fileno(fd))) { -#endif ret = get_key_material_raw(fd, fsname, keyformat, B_TRUE, newkey, &km2, &kmlen2); if (ret != 0) diff --git a/ZFSin/zfs/lib/libzfs/libzfs_diff.c b/ZFSin/zfs/lib/libzfs/libzfs_diff.c index 1968d611..92f2f711 100644 --- a/ZFSin/zfs/lib/libzfs/libzfs_diff.c +++ b/ZFSin/zfs/lib/libzfs/libzfs_diff.c @@ -558,11 +558,7 @@ teardown_differ_info(differ_info_t *di) free(di->tosnap); free(di->tmpsnap); free(di->tomnt); -#ifdef WIN32 - CloseHandle(di->cleanupfd); -#else (void) close(di->cleanupfd); -#endif } static int @@ -750,14 +746,8 @@ setup_differ_info(zfs_handle_t *zhp, const char *fromsnap, { di->zhp = zhp; -#ifdef WIN32 - di->cleanupfd = CreateFile(ZFS_DEV, GENERIC_READ | GENERIC_WRITE, - 0, NULL, OPEN_EXISTING, 0, NULL); - VERIFY(di->cleanupfd != INVALID_HANDLE_VALUE); -#else di->cleanupfd = open(ZFS_DEV, O_RDWR); VERIFY(di->cleanupfd >= 0); -#endif if (get_snapshot_names(di, fromsnap, tosnap) != 0) return (-1); diff --git a/ZFSin/zfs/lib/libzfs/libzfs_import.c b/ZFSin/zfs/lib/libzfs/libzfs_import.c index 9c16c182..ab124c44 100644 --- a/ZFSin/zfs/lib/libzfs/libzfs_import.c +++ b/ZFSin/zfs/lib/libzfs/libzfs_import.c @@ -1093,7 +1093,7 @@ typedef struct rdsk_node { char *rn_parent; #endif int rn_num_labels; - HANDLE rn_dfd; + int rn_dfd; libzfs_handle_t *rn_hdl; nvlist_t *rn_config; avl_tree_t *rn_avl; @@ -1292,6 +1292,7 @@ void signal_alarm(int foo) } #endif +#ifndef _WIN32 static void zpool_open_func(void *arg) { @@ -1452,7 +1453,9 @@ fprintf(stderr, "%s: enter\n", __func__); fflush(stderr); rn->rn_config = config; rn->rn_num_labels = num_labels; } +#endif +// Should probably rename this, and only define one. static void zpool_open_func_win(void *arg) { @@ -1560,7 +1563,7 @@ zpool_open_func_win(void *arg) * Try to read the disk label first so we don't have to * open a bunch of minor nodes that can't have a zpool. */ - check_slices(rn->rn_avl, fd, rn->rn_name); + check_slices(rn->rn_avl, HTOI(fd), rn->rn_name); } if ((zpool_read_label_win(fd, drive_len, &config, &num_labels)) != 0) { @@ -1585,7 +1588,7 @@ zpool_open_func_win(void *arg) * Given a file descriptor, clear (zero) the label information. */ int -zpool_clear_label(HANDLE fd) +zpool_clear_label(int fd) { struct _stat64 statbuf; int l; @@ -1833,7 +1836,7 @@ zpool_find_import_impl(libzfs_handle_t *hdl, importargs_t *iarg) slice->rn_name = zfs_strdup(hdl, name); slice->rn_parent = zfs_strdup(hdl, path); slice->rn_avl = &slice_cache; - slice->rn_dfd = dfd; + slice->rn_dfd = HTOI(dfd); slice->rn_hdl = hdl; slice->rn_nozpool = B_FALSE; avl_add(&slice_cache, slice); diff --git a/ZFSin/zfs/lib/libzfs/libzfs_pool.c b/ZFSin/zfs/lib/libzfs/libzfs_pool.c index aab4f625..858b5b0d 100644 --- a/ZFSin/zfs/lib/libzfs/libzfs_pool.c +++ b/ZFSin/zfs/lib/libzfs/libzfs_pool.c @@ -2840,7 +2840,7 @@ zpool_get_physpath(zpool_handle_t *zhp, char *physpath, size_t phypath_size) * can block ZFS from accessing the device. This function allows limited retries * in order to work around this behavior. */ -static HANDLE +static int zpool_open_delay(int timeout, const char *path, int oflag) { int i = 0; @@ -2886,7 +2886,7 @@ zpool_open_delay(int timeout, const char *path, int oflag) // fd = open(path, oflag); // } - return (fd); + return (HTOI(fd)); } /* @@ -2896,7 +2896,7 @@ zpool_open_delay(int timeout, const char *path, int oflag) static int zpool_relabel_disk(libzfs_handle_t *hdl, const char *path, const char *msg) { - HANDLE fd; + int fd; int error; if ((fd = zpool_open_delay(10, path, O_RDWR|O_DIRECT|O_SHLOCK)) < 0) { @@ -2914,11 +2914,8 @@ zpool_relabel_disk(libzfs_handle_t *hdl, const char *path, const char *msg) * The module will do it for us in vdev_disk_open(). */ error = efi_use_whole_disk(fd); -#ifdef _WIN32 - CloseHandle(fd); -#else (void) close(fd); -#endif + if (error && error != VT_ENOSPC) { zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "cannot " "relabel '%s': unable to read disk capacity"), path); @@ -4828,36 +4825,24 @@ zpool_label_disk_check(char *path) { struct dk_gpt *vtoc; int err; - HANDLE fd; + int fd; if ((fd = zpool_open_delay(10, path, O_RDWR|O_DIRECT)) < 0) return (errno); if ((err = efi_alloc_and_read(fd, &vtoc)) != 0) { -#ifdef _WIN32 - CloseHandle(fd); -#else (void) close(fd); -#endif return (err); } if (vtoc->efi_flags & EFI_GPT_PRIMARY_CORRUPT) { efi_free(vtoc); -#ifdef _WIN32 - CloseHandle(fd); -#else (void)close(fd); -#endif return (EIDRM); } efi_free(vtoc); -#ifdef _WIN32 - CloseHandle(fd); -#else (void)close(fd); -#endif return (0); } @@ -4871,7 +4856,7 @@ zpool_label_disk(libzfs_handle_t *hdl, zpool_handle_t *zhp, const char *name) char path[MAXPATHLEN]; struct dk_gpt *vtoc; int rval; - HANDLE fd; + int fd; size_t resv = EFI_MIN_RESV_SIZE; uint64_t slice_size; diskaddr_t start_block; @@ -4929,11 +4914,7 @@ zpool_label_disk(libzfs_handle_t *hdl, zpool_handle_t *zhp, const char *name) */ if (errno == ENOMEM) (void) no_memory(hdl); -#ifdef _WIN32 - CloseHandle(fd); -#else (void) close(fd); -#endif zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "cannot " "label '%s': unable to read disk capacity"), path); @@ -4972,11 +4953,7 @@ zpool_label_disk(libzfs_handle_t *hdl, zpool_handle_t *zhp, const char *name) * ecting the user to manually label the disk and give * a specific slice. */ -#ifdef _WIN32 - CloseHandle(fd); -#else (void) close(fd); -#endif efi_free(vtoc); zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "try using " @@ -4984,11 +4961,7 @@ zpool_label_disk(libzfs_handle_t *hdl, zpool_handle_t *zhp, const char *name) return (zfs_error(hdl, EZFS_LABELFAILED, errbuf)); } -#ifdef _WIN32 - CloseHandle(fd); -#else (void)close(fd); -#endif efi_free(vtoc); /* Wait for the first expected partition to appear. */ diff --git a/ZFSin/zfs/lib/libzfs/libzfs_sendrecv.c b/ZFSin/zfs/lib/libzfs/libzfs_sendrecv.c index 3a90ef49..4bbf7379 100644 --- a/ZFSin/zfs/lib/libzfs/libzfs_sendrecv.c +++ b/ZFSin/zfs/lib/libzfs/libzfs_sendrecv.c @@ -137,7 +137,7 @@ ssread(void *buf, size_t len, FILE *stream) { size_t outlen; #ifdef WIN32 - /* Windows we have a SOCKET type here*/ + /* Windows we have a SOCKET type here - can't change fread() call. */ DWORD rv; if (!ReadFile(stream, buf, len, &rv, NULL)) return 0; @@ -210,7 +210,7 @@ ddt_update(libzfs_handle_t *hdl, dedup_table_t *ddt, zio_cksum_t *cs, static int dump_record(dmu_replay_record_t *drr, void *payload, int payload_len, - zio_cksum_t *zc, HANDLE outfd) + zio_cksum_t *zc, int outfd) { ASSERT3U(offsetof(dmu_replay_record_t, drr_u.drr_checksum.drr_checksum), ==, sizeof (dmu_replay_record_t) - sizeof (zio_cksum_t)); @@ -224,31 +224,17 @@ dump_record(dmu_replay_record_t *drr, void *payload, int payload_len, (void) fletcher_4_incremental_native( &drr->drr_u.drr_checksum.drr_checksum, sizeof (zio_cksum_t), zc); -#ifdef WIN32 - DWORD byteswritten = 0; - if (!WriteFile(outfd, drr, sizeof(*drr), &byteswritten, NULL)) { - return (GetLastError()); - } -#else if (write(outfd, drr, sizeof (*drr)) == -1) return (errno); -#endif + if (payload_len != 0) { (void) fletcher_4_incremental_native(payload, payload_len, zc); -#ifdef WIN32 - byteswritten = 0; - if (!WriteFile(outfd, payload, payload_len, &byteswritten, NULL)) { - return (GetLastError()); - } -#else if (write(outfd, payload, payload_len) == -1) return (errno); -#endif } return (0); } - /* * This function is started in a separate thread when the dedup option * has been requested. The main send thread determines the list of @@ -310,12 +296,7 @@ cksummer(void *arg) ddt.ddt_full = B_FALSE; outfd = dda->outputfd; -#ifdef WIN32 - // "inputfd" is from socketpair(), so SOCKET type (HANDLE) and not "fd int". - ofp = dda->inputfd; -#else ofp = fdopen(dda->inputfd, "r"); -#endif while (ssread(drr, sizeof (*drr), ofp) != 0) { /* @@ -522,7 +503,11 @@ cksummer(void *arg) umem_cache_destroy(ddt.ddecache); free(ddt.dedup_hash_array); free(buf); -#ifndef WIN32 +#ifdef _WIN32 + // We don't want to wrap fclose() so this is a special + // place we manually close the handle from socketpair(). + CloseHandle(ofp); +#else (void) fclose(ofp); #endif @@ -1301,7 +1286,7 @@ send_progress_thread(void *arg) 0, NULL, OPEN_EXISTING, 0, NULL); libzfs_handle_t tmp; if (h != INVALID_HANDLE_VALUE) { - tmp.libzfs_fd = h; + tmp.libzfs_fd = HTOI(h); hdl = &tmp; } #endif @@ -2051,13 +2036,8 @@ zfs_send(zfs_handle_t *zhp, const char *fromsnap, const char *tosnap, dda.inputfd = pipefd[1]; dda.dedup_hdl = zhp->zfs_hdl; if ((err = pthread_create(&tid, NULL, cksummer, &dda)) != 0) { -#ifdef WIN32 - (void) closesocket(pipefd[0]); - (void) closesocket(pipefd[1]); -#else (void) close(pipefd[0]); (void) close(pipefd[1]); -#endif zfs_error_aux(zhp->zfs_hdl, strerror(errno)); return (zfs_error(zhp->zfs_hdl, EZFS_THREADCREATEFAILED, errbuf)); @@ -2136,19 +2116,11 @@ zfs_send(zfs_handle_t *zhp, const char *fromsnap, const char *tosnap, bzero(&drr, sizeof (drr)); drr.drr_type = DRR_END; drr.drr_u.drr_end.drr_checksum = zc; -#ifdef WIN32 - DWORD byteswritten = 0; - if (!WriteFile(outfd, &drr, sizeof(drr), &byteswritten, NULL)) { - err = GetLastError(); - goto stderr_out; - } -#else err = write(outfd, &drr, sizeof (drr)); if (err == -1) { err = errno; goto stderr_out; } -#endif err = 0; } @@ -2197,20 +2169,11 @@ zfs_send(zfs_handle_t *zhp, const char *fromsnap, const char *tosnap, ++holdseq; (void) snprintf(sdd.holdtag, sizeof (sdd.holdtag), ".send-%d-%llu", getpid(), (u_longlong_t)holdseq); -#ifdef WIN32 - sdd.cleanup_fd = CreateFile(ZFS_DEV, GENERIC_READ | GENERIC_WRITE, - 0, NULL, OPEN_EXISTING, 0, NULL); - if (sdd.cleanup_fd == INVALID_HANDLE_VALUE) { - err = errno; - goto stderr_out; - } -#else sdd.cleanup_fd = open(ZFS_DEV, O_RDWR); if (sdd.cleanup_fd < 0) { err = errno; goto stderr_out; } -#endif sdd.snapholds = fnvlist_alloc(); } else { sdd.cleanup_fd = -1; @@ -2275,20 +2238,12 @@ zfs_send(zfs_handle_t *zhp, const char *fromsnap, const char *tosnap, if (tid_set != 0) { if (err != 0) (void) pthread_cancel(tid); -#ifdef WIN32 - (void) closesocket(pipefd[0]); -#else (void) close(pipefd[0]); -#endif (void) pthread_join(tid, NULL); } if (sdd.cleanup_fd != -1) { -#ifdef WIN32 - VERIFY(0 != CloseHandle(sdd.cleanup_fd)); -#else VERIFY(0 == close(sdd.cleanup_fd)); -#endif sdd.cleanup_fd = -1; } @@ -2301,18 +2256,10 @@ zfs_send(zfs_handle_t *zhp, const char *fromsnap, const char *tosnap, */ dmu_replay_record_t drr = { 0 }; drr.drr_type = DRR_END; -#ifdef WIN32 - DWORD byteswritten = 0; - if (!WriteFile(outfd, &drr, sizeof(drr), &byteswritten, NULL)) { - return (zfs_standard_error(zhp->zfs_hdl, - GetLastError(), errbuf)); - } -#else if (write(outfd, &drr, sizeof (drr)) == -1) { return (zfs_standard_error(zhp->zfs_hdl, errno, errbuf)); } -#endif } return (err || sdd.err); @@ -2324,13 +2271,9 @@ zfs_send(zfs_handle_t *zhp, const char *fromsnap, const char *tosnap, nvlist_free(fss); fnvlist_free(sdd.snapholds); -#ifdef WIN32 - if (sdd.cleanup_fd != INVALID_HANDLE_VALUE) - VERIFY(CloseHandle(sdd.cleanup_fd)); -#else if (sdd.cleanup_fd != -1) VERIFY(0 == close(sdd.cleanup_fd)); -#endif + if (tid_set != 0) { (void) pthread_cancel(tid); (void) close(pipefd[0]); @@ -2437,11 +2380,7 @@ recv_read(libzfs_handle_t *hdl, int fd, void *buf, int ilen, int len = ilen; do { -#ifdef WIN32 - ReadFile(fd, cp, len, &rv, NULL); -#else rv = read(fd, cp, len); -#endif cp += rv; len -= rv; } while (rv > 0); @@ -4877,7 +4816,7 @@ zfs_receive(libzfs_handle_t *hdl, const char *tosnap, nvlist_t *props, { char *top_zfs = NULL; int err; - HANDLE cleanup_fd; + int cleanup_fd; uint64_t action_handle = 0; struct _stat64 sb; char *originsnap = NULL; @@ -4930,16 +4869,6 @@ zfs_receive(libzfs_handle_t *hdl, const char *tosnap, nvlist_t *props, if (err && err != ENOENT) return (err); } -#ifdef WIN32 - cleanup_fd = CreateFile(ZFS_DEV, GENERIC_READ | GENERIC_WRITE, - 0, NULL, OPEN_EXISTING, 0, NULL); - VERIFY(cleanup_fd != INVALID_HANDLE_VALUE); - - err = zfs_receive_impl(hdl, tosnap, originsnap, flags, infd, NULL, NULL, - stream_avl, &top_zfs, cleanup_fd, &action_handle, NULL, props); - - VERIFY(CloseHandle(cleanup_fd)); -#else cleanup_fd = open(ZFS_DEV, O_RDWR); VERIFY(cleanup_fd >= 0); @@ -4947,7 +4876,6 @@ zfs_receive(libzfs_handle_t *hdl, const char *tosnap, nvlist_t *props, stream_avl, &top_zfs, cleanup_fd, &action_handle, NULL, props); VERIFY(0 == close(cleanup_fd)); -#endif if (err == 0 && !flags->nomount && top_zfs) { zfs_handle_t *zhp = NULL; diff --git a/ZFSin/zfs/lib/libzfs/libzfs_util.c b/ZFSin/zfs/lib/libzfs/libzfs_util.c index 33c4456d..8d837023 100644 --- a/ZFSin/zfs/lib/libzfs/libzfs_util.c +++ b/ZFSin/zfs/lib/libzfs/libzfs_util.c @@ -1024,14 +1024,8 @@ libzfs_init(void) return (NULL); } -#ifdef WIN32 - hdl->libzfs_fd = CreateFile(ZFS_DEV, GENERIC_READ | GENERIC_WRITE, - 0, NULL, OPEN_EXISTING, 0, NULL); - if ((hdl->libzfs_fd) == INVALID_HANDLE_VALUE) { -#else - hdl->libzfs_fd = open(ZFS_DEV, O_RDWR)); + hdl->libzfs_fd = open(ZFS_DEV, O_RDWR); if (hdl->libzfs_fd < 0) { -#endif (void) fprintf(stderr, gettext("Unable to open %s: %s.\n"), ZFS_DEV, strerror(errno)); @@ -1067,11 +1061,8 @@ libzfs_init(void) #endif if (libzfs_core_init() != 0) { -#ifdef WIN32 - (void) CloseHandle(hdl->libzfs_fd); -#else (void) close(hdl->libzfs_fd); -#endif + #ifdef LINUX (void) fclose(hdl->libzfs_mnttab); #endif @@ -1102,11 +1093,8 @@ libzfs_init(void) void libzfs_fini(libzfs_handle_t *hdl) { -#ifdef WIN32 - (void) CloseHandle(hdl->libzfs_fd); -#else (void) close(hdl->libzfs_fd); -#endif + #ifdef LINUX if (hdl->libzfs_mnttab) #ifdef HAVE_SETMNTENT diff --git a/ZFSin/zfs/lib/libzfs_core/libzfs_core.c b/ZFSin/zfs/lib/libzfs_core/libzfs_core.c index 88e10157..4db7fa32 100644 --- a/ZFSin/zfs/lib/libzfs_core/libzfs_core.c +++ b/ZFSin/zfs/lib/libzfs_core/libzfs_core.c @@ -90,11 +90,8 @@ #include #include #include -#ifdef _WIN32 -static HANDLE g_fd = INVALID_HANDLE_VALUE; -#else + static int g_fd = -1; -#endif static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER; static int g_refcount; @@ -139,14 +136,7 @@ libzfs_core_init(void) { (void) pthread_mutex_lock(&g_lock); if (g_refcount == 0) { - //g_fd = open("/dev/zfs", O_RDWR); - g_fd = CreateFile("\\\\.\\ZFS", GENERIC_READ | GENERIC_WRITE, - 0, NULL, OPEN_EXISTING, 0, NULL); - - if (g_fd == INVALID_HANDLE_VALUE) { - (void) pthread_mutex_unlock(&g_lock); - return (errno); - } + g_fd = open(ZFS_DEV, O_RDWR); } g_refcount++; @@ -166,10 +156,9 @@ libzfs_core_fini(void) if (g_refcount > 0) g_refcount--; - if (g_refcount == 0 && g_fd != INVALID_HANDLE_VALUE) { - //(void) close(g_fd); - (void)CloseHandle(g_fd); - g_fd = INVALID_HANDLE_VALUE; + if (g_refcount == 0 && g_fd != -1) { + (void) close(g_fd); + g_fd = -1; } (void) pthread_mutex_unlock(&g_lock); } @@ -181,7 +170,7 @@ libzfs_core_fini(void) * can handle this, so this wrapper is not required. */ static int -zioctl(HANDLE fildes, zfs_ioc_t ioc, zfs_cmd_t *zc) +zioctl(int fildes, zfs_ioc_t ioc, zfs_cmd_t *zc) { return ioctl(g_fd, ioc, zc); } From 56eb0995b3c9511f440542375a8bab7a27368583 Mon Sep 17 00:00:00 2001 From: Jorgen Lundman Date: Fri, 11 Oct 2019 14:35:11 +0900 Subject: [PATCH 2/3] Compile as MT/MTd to avoid vcruntime140.dll --- ZFSin/zfs/cmd/kstat/kstat.vcxproj | 4 ++-- ZFSin/zfs/cmd/zdb/zdb/zdb.vcxproj | 5 ++--- ZFSin/zfs/cmd/zfs/zfs/zfs.vcxproj | 5 ++--- ZFSin/zfs/cmd/zpool/zpool/zpool.vcxproj | 6 ++---- ZFSin/zfs/cmd/zstreamdump/zstreamdump/zstreamdump.vcxproj | 5 ++--- ZFSin/zfs/lib/libavl/libavl/libavl.vcxproj | 5 ++--- ZFSin/zfs/lib/libefi/libefi/libefi.vcxproj | 5 ++--- ZFSin/zfs/lib/libicp/libicp/libicp.vcxproj | 5 ++--- ZFSin/zfs/lib/libkstat/libkstat.vcxproj | 4 ++-- ZFSin/zfs/lib/libnvpair/libnvpair/libnvpair.vcxproj | 5 ++--- ZFSin/zfs/lib/libshare/libshare/libshare.vcxproj | 5 ++--- ZFSin/zfs/lib/libspl/libspl/libspl.vcxproj | 5 ++--- ZFSin/zfs/lib/libunicode/libunicode/libunicode.vcxproj | 5 ++--- ZFSin/zfs/lib/libuuid/libuuid/libuuid.vcxproj | 5 ++--- ZFSin/zfs/lib/libuutil/libuutil/libuutil.vcxproj | 5 ++--- ZFSin/zfs/lib/libzfs/libzfs/libzfs.vcxproj | 5 ++--- ZFSin/zfs/lib/libzfs_core/libzfs_core/libzfs_core.vcxproj | 5 ++--- ZFSin/zfs/lib/libzpool/libzpool/libzpool.vcxproj | 5 ++--- zfsinstaller/zfsinstaller.vcxproj | 3 ++- 19 files changed, 38 insertions(+), 54 deletions(-) diff --git a/ZFSin/zfs/cmd/kstat/kstat.vcxproj b/ZFSin/zfs/cmd/kstat/kstat.vcxproj index 0840982c..28cb574e 100644 --- a/ZFSin/zfs/cmd/kstat/kstat.vcxproj +++ b/ZFSin/zfs/cmd/kstat/kstat.vcxproj @@ -103,7 +103,7 @@ true __x86_64;_CRT_SECURE_NO_WARNINGS $(SolutionDir)/ZFSin/zfs/lib/libspl/include;$(SolutionDir)/ZFSin/zfs/include;$(SolutionDir)/ZFSin/zfs/lib/libpthread;$(SolutionDir)/ZFSin/zfs/lib/zlib-1.2.3;%(AdditionalIncludeDirectories) - + MultiThreaded Console @@ -133,7 +133,7 @@ true __x86_64;_CRT_SECURE_NO_WARNINGS $(SolutionDir)/ZFSin/zfs/lib/libspl/include;$(SolutionDir)/ZFSin/zfs/include;$(SolutionDir)/ZFSin/zfs/lib/libpthread;$(SolutionDir)/ZFSin/zfs/lib/zlib-1.2.3;%(AdditionalIncludeDirectories) - + MultiThreadedDebug Console diff --git a/ZFSin/zfs/cmd/zdb/zdb/zdb.vcxproj b/ZFSin/zfs/cmd/zdb/zdb/zdb.vcxproj index ad01f052..46815e4c 100644 --- a/ZFSin/zfs/cmd/zdb/zdb/zdb.vcxproj +++ b/ZFSin/zfs/cmd/zdb/zdb/zdb.vcxproj @@ -111,7 +111,7 @@ false __x86_64;_CRT_SECURE_NO_WARNINGS $(SolutionDir)/ZFSin/zfs/lib/libspl/include;$(SolutionDir)/ZFSin/zfs/include;$(SolutionDir)/ZFSin/zfs/lib/libpthread;$(SolutionDir)/ZFSin/zfs/lib/zlib-1.2.3;%(AdditionalIncludeDirectories) - + MultiThreadedDebug 4146 @@ -164,8 +164,7 @@ false __x86_64;_CRT_SECURE_NO_WARNINGS $(SolutionDir)/ZFSin/zfs/lib/libspl/include;$(SolutionDir)/ZFSin/zfs/include;$(SolutionDir)/ZFSin/zfs/lib/libpthread;$(SolutionDir)/ZFSin/zfs/lib/zlib-1.2.3;%(AdditionalIncludeDirectories) - - + MultiThreaded 4146 diff --git a/ZFSin/zfs/cmd/zfs/zfs/zfs.vcxproj b/ZFSin/zfs/cmd/zfs/zfs/zfs.vcxproj index aa5b7242..3949eb60 100644 --- a/ZFSin/zfs/cmd/zfs/zfs/zfs.vcxproj +++ b/ZFSin/zfs/cmd/zfs/zfs/zfs.vcxproj @@ -133,7 +133,7 @@ __x86_64;_CRT_SECURE_NO_WARNINGS $(SolutionDir)/ZFSin/zfs/lib/libspl/include;$(SolutionDir)/ZFSin/zfs/include;$(SolutionDir)/ZFSin/zfs/lib/libpthread;$(SolutionDir)/ZFSin/zfs/lib/zlib-1.2.3;%(AdditionalIncludeDirectories) false - + MultiThreadedDebug Console @@ -171,8 +171,7 @@ __x86_64;_CRT_SECURE_NO_WARNINGS $(SolutionDir)/ZFSin/zfs/lib/libspl/include;$(SolutionDir)/ZFSin/zfs/include;$(SolutionDir)/ZFSin/zfs/lib/libpthread;$(SolutionDir)/ZFSin/zfs/lib/zlib-1.2.3;%(AdditionalIncludeDirectories) false - - + MultiThreaded Console diff --git a/ZFSin/zfs/cmd/zpool/zpool/zpool.vcxproj b/ZFSin/zfs/cmd/zpool/zpool/zpool.vcxproj index ba7ee2e3..57d81a5b 100644 --- a/ZFSin/zfs/cmd/zpool/zpool/zpool.vcxproj +++ b/ZFSin/zfs/cmd/zpool/zpool/zpool.vcxproj @@ -136,8 +136,7 @@ __x86_64;_CRT_SECURE_NO_WARNINGS false $(SolutionDir)/ZFSin/zfs/lib/libuuid;$(SolutionDir)/ZFSin/zfs/lib/libspl/include;$(SolutionDir)/ZFSin/zfs/include;$(SolutionDir)/ZFSin/zfs/lib/libpthread;$(SolutionDir)/ZFSin/zfs/lib/zlib-1.2.3;%(AdditionalIncludeDirectories) - - + MultiThreadedDebug 4018;4242;4244 @@ -179,8 +178,7 @@ __x86_64;_CRT_SECURE_NO_WARNINGS false $(SolutionDir)/ZFSin/zfs/lib/libuuid;$(SolutionDir)/ZFSin/zfs/lib/libspl/include;$(SolutionDir)/ZFSin/zfs/include;$(SolutionDir)/ZFSin/zfs/lib/libpthread;$(SolutionDir)/ZFSin/zfs/lib/zlib-1.2.3;%(AdditionalIncludeDirectories) - - + MultiThreaded 4018;4242;4244 diff --git a/ZFSin/zfs/cmd/zstreamdump/zstreamdump/zstreamdump.vcxproj b/ZFSin/zfs/cmd/zstreamdump/zstreamdump/zstreamdump.vcxproj index 5f606b6b..61c820a9 100644 --- a/ZFSin/zfs/cmd/zstreamdump/zstreamdump/zstreamdump.vcxproj +++ b/ZFSin/zfs/cmd/zstreamdump/zstreamdump/zstreamdump.vcxproj @@ -113,7 +113,7 @@ true __x86_64;_CRT_SECURE_NO_WARNINGS $(SolutionDir)/ZFSin/zfs/lib/libuuid;$(SolutionDir)/ZFSin/zfs/lib/libspl/include;$(SolutionDir)/ZFSin/zfs/include;$(SolutionDir)/ZFSin/zfs/lib/libpthread;$(SolutionDir)/ZFSin/zfs/lib/zlib-1.2.3;%(AdditionalIncludeDirectories) - + MultiThreadedDebug Console @@ -164,8 +164,7 @@ true __x86_64;_CRT_SECURE_NO_WARNINGS $(SolutionDir)/ZFSin/zfs/lib/libuuid;$(SolutionDir)/ZFSin/zfs/lib/libspl/include;$(SolutionDir)/ZFSin/zfs/include;$(SolutionDir)/ZFSin/zfs/lib/libpthread;$(SolutionDir)/ZFSin/zfs/lib/zlib-1.2.3;%(AdditionalIncludeDirectories) - - + MultiThreaded Console diff --git a/ZFSin/zfs/lib/libavl/libavl/libavl.vcxproj b/ZFSin/zfs/lib/libavl/libavl/libavl.vcxproj index a9e9971c..41a22025 100644 --- a/ZFSin/zfs/lib/libavl/libavl/libavl.vcxproj +++ b/ZFSin/zfs/lib/libavl/libavl/libavl.vcxproj @@ -109,7 +109,7 @@ __x86_64 $(SolutionDir)/ZFSin/zfs/lib/libspl/include;$(SolutionDir)/ZFSin/zfs/include;$(SolutionDir)/ZFSin/zfs/lib/libpthread;$(SolutionDir)/ZFSin/zfs/lib/zlib-1.2.3;%(AdditionalIncludeDirectories) - + MultiThreadedDebug 4018;4100;4152;4200;4201;4211;4204;4210;4389;4706;4146;4242 @@ -117,8 +117,7 @@ __x86_64 $(SolutionDir)/ZFSin/zfs/lib/libspl/include;$(SolutionDir)/ZFSin/zfs/include;$(SolutionDir)/ZFSin/zfs/lib/libpthread;$(SolutionDir)/ZFSin/zfs/lib/zlib-1.2.3;%(AdditionalIncludeDirectories) - - + MultiThreaded 4018;4100;4152;4200;4201;4211;4204;4210;4389;4706;4146;4242 diff --git a/ZFSin/zfs/lib/libefi/libefi/libefi.vcxproj b/ZFSin/zfs/lib/libefi/libefi/libefi.vcxproj index 2a21777e..1842cd37 100644 --- a/ZFSin/zfs/lib/libefi/libefi/libefi.vcxproj +++ b/ZFSin/zfs/lib/libefi/libefi/libefi.vcxproj @@ -114,7 +114,7 @@ $(SolutionDir)/ZFSin/zfs/lib/libspl/include;$(SolutionDir)/ZFSin/zfs/include;$(SolutionDir)/ZFSin/zfs/lib/libpthread;$(SolutionDir)/ZFSin/zfs/lib/zlib-1.2.3;%(AdditionalIncludeDirectories) __x86_64 - + MultiThreadedDebug 4018;4100;4152;4200;4201;4211;4204;4210;4389;4706;4146;4242 @@ -122,8 +122,7 @@ $(SolutionDir)/ZFSin/zfs/lib/libspl/include;$(SolutionDir)/ZFSin/zfs/include;$(SolutionDir)/ZFSin/zfs/lib/libpthread;$(SolutionDir)/ZFSin/zfs/lib/zlib-1.2.3;%(AdditionalIncludeDirectories) __x86_64 - - + MultiThreaded 4018;4100;4152;4200;4201;4211;4204;4210;4389;4706;4146;4242 diff --git a/ZFSin/zfs/lib/libicp/libicp/libicp.vcxproj b/ZFSin/zfs/lib/libicp/libicp/libicp.vcxproj index 1f778807..ab7c4368 100644 --- a/ZFSin/zfs/lib/libicp/libicp/libicp.vcxproj +++ b/ZFSin/zfs/lib/libicp/libicp/libicp.vcxproj @@ -142,7 +142,7 @@ $(SolutionDir)/ZFSin/zfs/lib/libspl/include;$(SolutionDir)/ZFSin/zfs/lib/libpthread;$(SolutionDir)/ZFSin/zfs/include;$(SolutionDir)/ZFSin/zfs/module/icp/include;%(AdditionalIncludeDirectories) __x86_64 - + MultiThreadedDebug 4018;4100;4152;4200;4201;4211;4204;4210;4389;4706;4146;4242 @@ -150,8 +150,7 @@ $(SolutionDir)/ZFSin/zfs/lib/libspl/include;$(SolutionDir)/ZFSin/zfs/lib/libpthread;$(SolutionDir)/ZFSin/zfs/include;$(SolutionDir)/ZFSin/zfs/module/icp/include;%(AdditionalIncludeDirectories) __x86_64 - - + MultiThreaded 4018;4100;4152;4200;4201;4211;4204;4210;4389;4706;4146;4242 diff --git a/ZFSin/zfs/lib/libkstat/libkstat.vcxproj b/ZFSin/zfs/lib/libkstat/libkstat.vcxproj index 37a20f48..bf371e83 100644 --- a/ZFSin/zfs/lib/libkstat/libkstat.vcxproj +++ b/ZFSin/zfs/lib/libkstat/libkstat.vcxproj @@ -109,7 +109,7 @@ true __x86_64 $(SolutionDir)/ZFSin/zfs/lib/libspl/include;$(SolutionDir)/ZFSin/zfs/include;$(SolutionDir)/ZFSin/zfs/lib/libpthread;$(SolutionDir)/ZFSin/zfs/lib/zlib-1.2.3;%(AdditionalIncludeDirectories) - + MultiThreaded 4018;4100;4152;4200;4201;4211;4204;4210;4389;4706;4146;4242 @@ -140,7 +140,7 @@ true __x86_64 $(SolutionDir)/ZFSin/zfs/lib/libspl/include;$(SolutionDir)/ZFSin/zfs/include;$(SolutionDir)/ZFSin/zfs/lib/libpthread;$(SolutionDir)/ZFSin/zfs/lib/zlib-1.2.3;%(AdditionalIncludeDirectories) - + MultiThreadedDebug 4018;4100;4152;4200;4201;4211;4204;4210;4389;4706;4146;4242 diff --git a/ZFSin/zfs/lib/libnvpair/libnvpair/libnvpair.vcxproj b/ZFSin/zfs/lib/libnvpair/libnvpair/libnvpair.vcxproj index 219f257e..85e5cf03 100644 --- a/ZFSin/zfs/lib/libnvpair/libnvpair/libnvpair.vcxproj +++ b/ZFSin/zfs/lib/libnvpair/libnvpair/libnvpair.vcxproj @@ -122,7 +122,7 @@ $(SolutionDir)/ZFSin/zfs/lib/libspl/include;$(SolutionDir)/ZFSin/zfs/include;$(SolutionDir)/ZFSin/zfs/lib/libpthread;$(SolutionDir)/ZFSin/zfs/lib/zlib-1.2.3;%(AdditionalIncludeDirectories) __x86_64 - + MultiThreadedDebug 4018;4100;4152;4200;4201;4211;4204;4210;4389;4706;4146;4242 @@ -130,8 +130,7 @@ $(SolutionDir)/ZFSin/zfs/lib/libspl/include;$(SolutionDir)/ZFSin/zfs/include;$(SolutionDir)/ZFSin/zfs/lib/libpthread;$(SolutionDir)/ZFSin/zfs/lib/zlib-1.2.3;%(AdditionalIncludeDirectories) __x86_64 - - + MultiThreaded 4018;4100;4152;4200;4201;4211;4204;4210;4389;4706;4146;4242 diff --git a/ZFSin/zfs/lib/libshare/libshare/libshare.vcxproj b/ZFSin/zfs/lib/libshare/libshare/libshare.vcxproj index 8da8bf98..59f94d38 100644 --- a/ZFSin/zfs/lib/libshare/libshare/libshare.vcxproj +++ b/ZFSin/zfs/lib/libshare/libshare/libshare.vcxproj @@ -111,7 +111,7 @@ $(SolutionDir)/ZFSin/zfs/lib/libspl/include;$(SolutionDir)/ZFSin/zfs/lib/libpthread;$(SolutionDir)/ZFSin/zfs/include;%(AdditionalIncludeDirectories) __x86_64 - + MultiThreadedDebug 4018;4100;4152;4200;4201;4211;4204;4210;4389;4706;4146;4242 @@ -119,8 +119,7 @@ $(SolutionDir)/ZFSin/zfs/lib/libspl/include;$(SolutionDir)/ZFSin/zfs/lib/libpthread;$(SolutionDir)/ZFSin/zfs/include;%(AdditionalIncludeDirectories) __x86_64 - - + MultiThreaded 4018;4100;4152;4200;4201;4211;4204;4210;4389;4706;4146;4242 diff --git a/ZFSin/zfs/lib/libspl/libspl/libspl.vcxproj b/ZFSin/zfs/lib/libspl/libspl/libspl.vcxproj index 051b05c3..99d97680 100644 --- a/ZFSin/zfs/lib/libspl/libspl/libspl.vcxproj +++ b/ZFSin/zfs/lib/libspl/libspl/libspl.vcxproj @@ -137,7 +137,7 @@ $(SolutionDir)/ZFSin/zfs/lib/libspl/include;$(SolutionDir)/ZFSin/zfs/lib/libpthread;$(SolutionDir)/ZFSin/zfs/include;%(AdditionalIncludeDirectories) __x86_64;%(PreprocessorDefinitions) - + MultiThreadedDebug 4018;4100;4152;4200;4201;4211;4204;4210;4389;4706;4146;4242 @@ -149,8 +149,7 @@ __x86_64;%(PreprocessorDefinitions) $(SolutionDir)/ZFSin/zfs/lib/libspl/include;$(SolutionDir)/ZFSin/zfs/lib/libpthread;$(SolutionDir)/ZFSin/zfs/include;%(AdditionalIncludeDirectories) - - + MultiThreaded 4018;4100;4152;4200;4201;4211;4204;4210;4389;4706;4146;4242 diff --git a/ZFSin/zfs/lib/libunicode/libunicode/libunicode.vcxproj b/ZFSin/zfs/lib/libunicode/libunicode/libunicode.vcxproj index 1bf16ece..81b18fbc 100644 --- a/ZFSin/zfs/lib/libunicode/libunicode/libunicode.vcxproj +++ b/ZFSin/zfs/lib/libunicode/libunicode/libunicode.vcxproj @@ -110,7 +110,7 @@ $(SolutionDir)/ZFSin/zfs/lib/libspl/include;$(SolutionDir)/ZFSin/zfs/lib/libpthread;$(SolutionDir)/ZFSin/zfs/include;%(AdditionalIncludeDirectories) __x86_64 - + MultiThreadedDebug 4018;4100;4152;4200;4201;4211;4204;4210;4389;4706;4146;4242 @@ -118,8 +118,7 @@ $(SolutionDir)/ZFSin/zfs/lib/libspl/include;$(SolutionDir)/ZFSin/zfs/lib/libpthread;$(SolutionDir)/ZFSin/zfs/include;%(AdditionalIncludeDirectories) __x86_64 - - + MultiThreaded 4018;4100;4152;4200;4201;4211;4204;4210;4389;4706;4146;4242 diff --git a/ZFSin/zfs/lib/libuuid/libuuid/libuuid.vcxproj b/ZFSin/zfs/lib/libuuid/libuuid/libuuid.vcxproj index 2bc4c349..c06d8c8f 100644 --- a/ZFSin/zfs/lib/libuuid/libuuid/libuuid.vcxproj +++ b/ZFSin/zfs/lib/libuuid/libuuid/libuuid.vcxproj @@ -123,7 +123,7 @@ __x86_64;_WIN64;_AMD64_;AMD64;HAVE_STDINT_H;%(PreprocessorDefinitions) $(SolutionDir)/ZFSin/zfs/lib/libspl/include;$(SolutionDir)/ZFSin/zfs/include;$(SolutionDir)/ZFSin/zfs/lib/libpthread;$(SolutionDir)/ZFSin/zfs/lib/zlib-1.2.3;%(AdditionalIncludeDirectories) - + MultiThreadedDebug 4018;4100;4152;4200;4201;4211;4204;4210;4389;4706;4146;4242 @@ -131,8 +131,7 @@ __x86_64;_WIN64;_AMD64_;AMD64;HAVE_STDINT_H;%(PreprocessorDefinitions) $(SolutionDir)/ZFSin/zfs/lib/libspl/include;$(SolutionDir)/ZFSin/zfs/include;$(SolutionDir)/ZFSin/zfs/lib/libpthread;$(SolutionDir)/ZFSin/zfs/lib/zlib-1.2.3;%(AdditionalIncludeDirectories) - - + MultiThreaded 4018;4100;4152;4200;4201;4211;4204;4210;4389;4706;4146;4242 diff --git a/ZFSin/zfs/lib/libuutil/libuutil/libuutil.vcxproj b/ZFSin/zfs/lib/libuutil/libuutil/libuutil.vcxproj index c5ea6e14..7fa0823b 100644 --- a/ZFSin/zfs/lib/libuutil/libuutil/libuutil.vcxproj +++ b/ZFSin/zfs/lib/libuutil/libuutil/libuutil.vcxproj @@ -129,7 +129,7 @@ $(SolutionDir)/ZFSin/zfs/lib/libspl/include;$(SolutionDir)/ZFSin/zfs/include;$(SolutionDir)/ZFSin/zfs/lib/libpthread;$(SolutionDir)/ZFSin/zfs/lib/zlib-1.2.3;%(AdditionalIncludeDirectories) __x86_64 - + MultiThreadedDebug 4018;4100;4152;4200;4201;4211;4204;4210;4389;4706;4146;4242 @@ -137,8 +137,7 @@ $(SolutionDir)/ZFSin/zfs/lib/libspl/include;$(SolutionDir)/ZFSin/zfs/include;$(SolutionDir)/ZFSin/zfs/lib/libpthread;$(SolutionDir)/ZFSin/zfs/lib/zlib-1.2.3;%(AdditionalIncludeDirectories) __x86_64 - - + MultiThreaded 4018;4100;4152;4200;4201;4211;4204;4210;4389;4706;4146;4242 diff --git a/ZFSin/zfs/lib/libzfs/libzfs/libzfs.vcxproj b/ZFSin/zfs/lib/libzfs/libzfs/libzfs.vcxproj index 2bd498fc..74ba928d 100644 --- a/ZFSin/zfs/lib/libzfs/libzfs/libzfs.vcxproj +++ b/ZFSin/zfs/lib/libzfs/libzfs/libzfs.vcxproj @@ -130,7 +130,7 @@ $(SolutionDir)/ZFSin/zfs/lib/libspl/include;$(SolutionDir)/ZFSin/zfs/include;$(SolutionDir)/ZFSin/zfs/lib/libpthread;$(SolutionDir)/ZFSin/zfs/lib/zlib-1.2.3;%(AdditionalIncludeDirectories) __x86_64 - + MultiThreadedDebug 4018;4100;4152;4200;4201;4211;4204;4210;4389;4706;4146;4242 @@ -138,8 +138,7 @@ $(SolutionDir)/ZFSin/zfs/lib/libspl/include;$(SolutionDir)/ZFSin/zfs/include;$(SolutionDir)/ZFSin/zfs/lib/libpthread;$(SolutionDir)/ZFSin/zfs/lib/zlib-1.2.3;%(AdditionalIncludeDirectories) __x86_64 - - + MultiThreaded 4018;4100;4152;4200;4201;4211;4204;4210;4389;4706;4146;4242 diff --git a/ZFSin/zfs/lib/libzfs_core/libzfs_core/libzfs_core.vcxproj b/ZFSin/zfs/lib/libzfs_core/libzfs_core/libzfs_core.vcxproj index 8ac2a9d4..811433a1 100644 --- a/ZFSin/zfs/lib/libzfs_core/libzfs_core/libzfs_core.vcxproj +++ b/ZFSin/zfs/lib/libzfs_core/libzfs_core/libzfs_core.vcxproj @@ -109,7 +109,7 @@ $(SolutionDir)/ZFSin/zfs/lib/libspl/include;$(SolutionDir)/ZFSin/zfs/include;$(SolutionDir)/ZFSin/zfs/lib/libpthread;$(SolutionDir)/ZFSin/zfs/lib/zlib-1.2.3;%(AdditionalIncludeDirectories) __x86_64 - + MultiThreadedDebug 4018;4100;4152;4200;4201;4211;4204;4210;4389;4706;4146;4242 @@ -117,8 +117,7 @@ $(SolutionDir)/ZFSin/zfs/lib/libspl/include;$(SolutionDir)/ZFSin/zfs/include;$(SolutionDir)/ZFSin/zfs/lib/libpthread;$(SolutionDir)/ZFSin/zfs/lib/zlib-1.2.3;%(AdditionalIncludeDirectories) __x86_64 - - + MultiThreaded 4018;4100;4152;4200;4201;4211;4204;4210;4389;4706;4146;4242 diff --git a/ZFSin/zfs/lib/libzpool/libzpool/libzpool.vcxproj b/ZFSin/zfs/lib/libzpool/libzpool/libzpool.vcxproj index f4f2959d..e9965520 100644 --- a/ZFSin/zfs/lib/libzpool/libzpool/libzpool.vcxproj +++ b/ZFSin/zfs/lib/libzpool/libzpool/libzpool.vcxproj @@ -268,7 +268,7 @@ $(SolutionDir)/ZFSin/zfs/lib/libspl/include;$(SolutionDir)/ZFSin/zfs/include;$(SolutionDir)/ZFSin/zfs/lib/libpthread;$(SolutionDir)/ZFSin/zfs/lib/zlib-1.2.3;%(AdditionalIncludeDirectories) __x86_64 - + MultiThreadedDebug 4018;4100;4152;4200;4201;4211;4204;4210;4389;4706;4146;4242 @@ -276,8 +276,7 @@ $(SolutionDir)/ZFSin/zfs/lib/libspl/include;$(SolutionDir)/ZFSin/zfs/include;$(SolutionDir)/ZFSin/zfs/lib/libpthread;$(SolutionDir)/ZFSin/zfs/lib/zlib-1.2.3;%(AdditionalIncludeDirectories) __x86_64 - - + MultiThreaded 4018;4100;4152;4200;4201;4211;4204;4210;4389;4706;4146;4242 diff --git a/zfsinstaller/zfsinstaller.vcxproj b/zfsinstaller/zfsinstaller.vcxproj index 28eabdf7..ee0845ca 100644 --- a/zfsinstaller/zfsinstaller.vcxproj +++ b/zfsinstaller/zfsinstaller.vcxproj @@ -91,7 +91,7 @@ _DEBUG;_CONSOLE;%(PreprocessorDefinitions) true pch.h - MultiThreaded + MultiThreadedDebug Console @@ -145,6 +145,7 @@ NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true pch.h + MultiThreaded Console From e65df1d0f4964e2607b64d301cf8e81e738e276d Mon Sep 17 00:00:00 2001 From: Jorgen Lundman Date: Fri, 11 Oct 2019 17:13:25 +0900 Subject: [PATCH 3/3] Implement FASTIO Implement minimal skeleton code for fastio ability, mostly to test if it changes anything with the long-time standing issues. It does not, appears to be optional as it says on the tin. --- ZFSin/zfs/cmd/zpool/zpool_main.c | 2 +- ZFSin/zfs/cmd/zpool/zpool_vdev.c | 10 +- ZFSin/zfs/include/sys/metaslab_impl.h | 1 + ZFSin/zfs/include/sys/zfs_context_userland.h | 2 +- ZFSin/zfs/include/sys/zfs_windows.h | 1 + ZFSin/zfs/lib/libzfs/libzfs_import.c | 2 +- ZFSin/zfs/lib/libzfs/libzfs_pool.c | 2 +- ZFSin/zfs/module/zfs/zfs_ioctl.c | 3 +- ZFSin/zfs/module/zfs/zfs_vnops_windows_lib.c | 547 ++++++++++++++++++- 9 files changed, 548 insertions(+), 22 deletions(-) diff --git a/ZFSin/zfs/cmd/zpool/zpool_main.c b/ZFSin/zfs/cmd/zpool/zpool_main.c index bb6119a1..274ae9c9 100644 --- a/ZFSin/zfs/cmd/zpool/zpool_main.c +++ b/ZFSin/zfs/cmd/zpool/zpool_main.c @@ -4327,7 +4327,7 @@ static int get_columns(void) { CONSOLE_SCREEN_BUFFER_INFO csbi; - int columns, rows; + int columns /*, rows*/; csbi.srWindow.Right = 1; csbi.srWindow.Left = 80; diff --git a/ZFSin/zfs/cmd/zpool/zpool_vdev.c b/ZFSin/zfs/cmd/zpool/zpool_vdev.c index ecd612cf..c879084d 100644 --- a/ZFSin/zfs/cmd/zpool/zpool_vdev.c +++ b/ZFSin/zfs/cmd/zpool/zpool_vdev.c @@ -606,7 +606,7 @@ is_whole_disk(const char *path) h = CreateFile(path, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); if ((h == INVALID_HANDLE_VALUE)) return (B_FALSE); - if (efi_alloc_and_init(h, EFI_NUMPAR, &label) != 0) { + if (efi_alloc_and_init(HTOI(h), EFI_NUMPAR, &label) != 0) { (void) CloseHandle(h); return (B_FALSE); } @@ -815,7 +815,7 @@ make_leaf_vdev(nvlist_t *props, const char *arg, uint64_t is_log) (LPOVERLAPPED)NULL); if (err) isdisk++; fprintf(stderr, "DeviceName said %s with '%s'\n", err ? "OK" : "NG", buf); - DISK_GEOMETRY_EX *p = buf; + DISK_GEOMETRY_EX *p = (DISK_GEOMETRY_EX *)buf; err = DeviceIoControl(h, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, (LPVOID)NULL, @@ -826,7 +826,7 @@ make_leaf_vdev(nvlist_t *props, const char *arg, uint64_t is_log) (LPOVERLAPPED)NULL); if (err) isdisk++; fprintf(stderr, "DriveGeometry said %s\n", err ? "OK" : "NG"); - DRIVE_LAYOUT_INFORMATION_EX *x = buf; + DRIVE_LAYOUT_INFORMATION_EX *x = (DRIVE_LAYOUT_INFORMATION_EX *)buf; err = DeviceIoControl(h, IOCTL_DISK_GET_DRIVE_LAYOUT_EX, (LPVOID)NULL, @@ -837,7 +837,7 @@ make_leaf_vdev(nvlist_t *props, const char *arg, uint64_t is_log) (LPOVERLAPPED)NULL); if (err) isdisk++; fprintf(stderr, "LayoutInfo said %s\n", err ? "OK" : "NG"); - VOLUME_DISK_EXTENTS *e = buf; + VOLUME_DISK_EXTENTS *e = (VOLUME_DISK_EXTENTS *)buf; err = DeviceIoControl(h, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, (LPVOID)NULL, @@ -1445,7 +1445,7 @@ make_disks(zpool_handle_t *zhp, nvlist_t *nv) h = CreateFile(path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); if (h != INVALID_HANDLE_VALUE) { struct dk_gpt *vtoc; - if ((efi_alloc_and_read(h, &vtoc)) == 0) { + if ((efi_alloc_and_read(HTOI(h), &vtoc)) == 0) { // Slice 1 should be ZFS snprintf(udevpath, MAXPATHLEN, "#%llu#%llu#%s", vtoc->efi_parts[0].p_start * (uint64_t)vtoc->efi_lbasize, diff --git a/ZFSin/zfs/include/sys/metaslab_impl.h b/ZFSin/zfs/include/sys/metaslab_impl.h index 7c86912a..9fc4a8f7 100644 --- a/ZFSin/zfs/include/sys/metaslab_impl.h +++ b/ZFSin/zfs/include/sys/metaslab_impl.h @@ -60,6 +60,7 @@ typedef struct metaslab_alloc_trace { * error conditions. These errors are stored to the offset member * of the metaslab_alloc_trace_t record and displayed by mdb. */ +#pragma warning (disable: 4146) typedef enum trace_alloc_type { TRACE_ALLOC_FAILURE = -1ULL, TRACE_TOO_SMALL = -2ULL, diff --git a/ZFSin/zfs/include/sys/zfs_context_userland.h b/ZFSin/zfs/include/sys/zfs_context_userland.h index 156ff7e5..61abcf62 100644 --- a/ZFSin/zfs/include/sys/zfs_context_userland.h +++ b/ZFSin/zfs/include/sys/zfs_context_userland.h @@ -223,7 +223,7 @@ extern void zk_thread_join(pthread_t tid); */ #define MTX_MAGIC 0x9522f51362a6e326ull #define MTX_INIT ((void *)NULL) -#define MTX_DEST ((void *)-1UL) +#define MTX_DEST ((void *)-1ULL) typedef struct kmutex { void *m_owner; diff --git a/ZFSin/zfs/include/sys/zfs_windows.h b/ZFSin/zfs/include/sys/zfs_windows.h index 37579cf3..e018b48e 100644 --- a/ZFSin/zfs/include/sys/zfs_windows.h +++ b/ZFSin/zfs/include/sys/zfs_windows.h @@ -153,5 +153,6 @@ extern NTSTATUS ioctl_mountdev_query_suggested_link_name(PDEVICE_OBJECT, PIRP, P extern NTSTATUS ioctl_mountdev_query_stable_guid(PDEVICE_OBJECT, PIRP, PIO_STACK_LOCATION); extern NTSTATUS ioctl_query_stable_guid(PDEVICE_OBJECT, PIRP, PIO_STACK_LOCATION); +extern void fastio_init(FAST_IO_DISPATCH **fast); #endif diff --git a/ZFSin/zfs/lib/libzfs/libzfs_import.c b/ZFSin/zfs/lib/libzfs/libzfs_import.c index ab124c44..1d8a4f85 100644 --- a/ZFSin/zfs/lib/libzfs/libzfs_import.c +++ b/ZFSin/zfs/lib/libzfs/libzfs_import.c @@ -2166,7 +2166,7 @@ zpool_find_import_win(libzfs_handle_t *hdl, importargs_t *iarg) fprintf(stderr, "asking libefi to read label\n"); fflush(stderr); int error; struct dk_gpt *vtoc; - error = efi_alloc_and_read(disk, &vtoc); + error = efi_alloc_and_read(HTOI(disk), &vtoc); if (error >= 0) { fprintf(stderr, "EFI read OK, max partitions %d\n", vtoc->efi_nparts); fflush(stderr); for (int i = 0; i < vtoc->efi_nparts; i++) { diff --git a/ZFSin/zfs/lib/libzfs/libzfs_pool.c b/ZFSin/zfs/lib/libzfs/libzfs_pool.c index 858b5b0d..fad816af 100644 --- a/ZFSin/zfs/lib/libzfs/libzfs_pool.c +++ b/ZFSin/zfs/lib/libzfs/libzfs_pool.c @@ -2849,7 +2849,7 @@ zpool_open_delay(int timeout, const char *path, int oflag) if (path[0] == '#') { uint64_t offset; uint64_t len; - char *end = NULL; + const char *end = NULL; end = path; while (end && *end == '#') end++; diff --git a/ZFSin/zfs/module/zfs/zfs_ioctl.c b/ZFSin/zfs/module/zfs/zfs_ioctl.c index ba632787..7360a9aa 100644 --- a/ZFSin/zfs/module/zfs/zfs_ioctl.c +++ b/ZFSin/zfs/module/zfs/zfs_ioctl.c @@ -7964,6 +7964,7 @@ zfs_attach(void) WIN_DriverObject->MajorFunction[IRP_MJ_QUERY_SECURITY] = (PDRIVER_DISPATCH)dispatcher; WIN_DriverObject->MajorFunction[IRP_MJ_SET_SECURITY] = (PDRIVER_DISPATCH)dispatcher; + fastio_init(&WIN_DriverObject->FastIoDispatch); // Register some locking callback thingy extern NTSTATUS ZFSCallbackAcquireForCreateSection( @@ -7981,7 +7982,6 @@ zfs_attach(void) FilterCallbacks.SizeOfFsFilterCallbacks = sizeof(FS_FILTER_CALLBACKS); FilterCallbacks.PreAcquireForSectionSynchronization = ZFSCallbackAcquireForCreateSection; FilterCallbacks.PreReleaseForSectionSynchronization = ZFSCallbackReleaseForCreateSection; - FilterCallbacks.PreAcquireForSectionSynchronization = ZFSCallbackAcquireForCreateSection; FilterCallbacks.PostAcquireForSectionSynchronization = ZFSCallbackAcquireForCreateSection; FilterCallbacks.PreReleaseForSectionSynchronization = ZFSCallbackReleaseForCreateSection; @@ -7995,7 +7995,6 @@ zfs_attach(void) FilterCallbacks.PreReleaseForModifiedPageWriter = ZFSCallbackReleaseForCreateSection; FilterCallbacks.PostReleaseForModifiedPageWriter = ZFSCallbackReleaseForCreateSection; - NTSTATUS Status; Status = FsRtlRegisterFileSystemFilterCallbacks(WIN_DriverObject, diff --git a/ZFSin/zfs/module/zfs/zfs_vnops_windows_lib.c b/ZFSin/zfs/module/zfs/zfs_vnops_windows_lib.c index bb489f49..278c6f87 100644 --- a/ZFSin/zfs/module/zfs/zfs_vnops_windows_lib.c +++ b/ZFSin/zfs/module/zfs/zfs_vnops_windows_lib.c @@ -2460,17 +2460,18 @@ NTSTATUS file_standard_information(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_ST standard->NumberOfLinks = 1; if (IrpSp->FileObject && IrpSp->FileObject->FsContext) { struct vnode *vp = IrpSp->FileObject->FsContext; - VN_HOLD(vp); - znode_t *zp = VTOZ(vp); - standard->Directory = vnode_isdir(vp) ? TRUE : FALSE; - // sa_object_size(zp->z_sa_hdl, &blksize, &nblks); - uint64_t blk = zfs_blksz(zp); - standard->AllocationSize.QuadPart = P2ROUNDUP(zp->z_size ? zp->z_size : 1, blk); // space taken on disk, multiples of block size - //standard->AllocationSize.QuadPart = zp->z_size; // space taken on disk, multiples of block size - standard->EndOfFile.QuadPart = vnode_isdir(vp) ? 0 : zp->z_size; // byte size of file - standard->NumberOfLinks = zp->z_links; - standard->DeletePending = vnode_deleteonclose(vp) ? TRUE : FALSE; - VN_RELE(vp); + if (VN_HOLD(vp) == 0) { + znode_t *zp = VTOZ(vp); + standard->Directory = vnode_isdir(vp) ? TRUE : FALSE; + // sa_object_size(zp->z_sa_hdl, &blksize, &nblks); + uint64_t blk = zfs_blksz(zp); + standard->AllocationSize.QuadPart = P2ROUNDUP(zp->z_size ? zp->z_size : 1, blk); // space taken on disk, multiples of block size + //standard->AllocationSize.QuadPart = zp->z_size; // space taken on disk, multiples of block size + standard->EndOfFile.QuadPart = vnode_isdir(vp) ? 0 : zp->z_size; // byte size of file + standard->NumberOfLinks = zp->z_links; + standard->DeletePending = vnode_deleteonclose(vp) ? TRUE : FALSE; + VN_RELE(vp); + } dprintf("Returning size %llu and allocsize %llu\n", standard->EndOfFile.QuadPart, standard->AllocationSize.QuadPart); Irp->IoStatus.Information = sizeof(FILE_STANDARD_INFORMATION); @@ -3551,6 +3552,530 @@ NTSTATUS ioctl_mountdev_query_stable_guid(PDEVICE_OBJECT DeviceObject, PIRP Irp, return STATUS_SUCCESS; } + +/* FastIO support */ + + +static BOOLEAN __stdcall fastio_check_if_possible(PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, ULONG Length, BOOLEAN Wait, + ULONG LockKey, BOOLEAN CheckForReadOperation, PIO_STATUS_BLOCK IoStatus, + PDEVICE_OBJECT DeviceObject) +{ + vnode_t *vp = FileObject->FsContext; + LARGE_INTEGER quadlen; + + quadlen.QuadPart = Length; + + if (CheckForReadOperation) { + if (FsRtlFastCheckLockForRead(&vp->lock, FileOffset, &quadlen, LockKey, FileObject, PsGetCurrentProcess())) + return TRUE; + } + else { + if (/*!vp->Vcb->readonly && !is_subvol_readonly(vp->subvol, NULL) && */ // FIXME, readonly + FsRtlFastCheckLockForWrite(&vp->lock, FileOffset, &quadlen, LockKey, FileObject, PsGetCurrentProcess())) + return TRUE; + } + + return FALSE; +} + +static BOOLEAN __stdcall fastio_write(PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, + ULONG Length, BOOLEAN Wait, ULONG LockKey, PVOID Buffer, PIO_STATUS_BLOCK IoStatus, + PDEVICE_OBJECT DeviceObject) +{ + vnode_t *vp = FileObject->FsContext; + BOOLEAN ret; + +#if 0 + if (!ExAcquireResourceSharedLite(&fcb->Vcb->tree_lock, Wait)) + return false; +#endif + + if (!ExAcquireResourceExclusiveLite(vp->FileHeader.Resource, Wait)) { +// ExReleaseResourceLite(&vp->Vcb->tree_lock); + return FALSE; + } + + ret = FsRtlCopyWrite(FileObject, FileOffset, Length, Wait, LockKey, Buffer, IoStatus, DeviceObject); + +// if (ret) +// vp->inode_item.st_size = fcb->Header.FileSize.QuadPart; + + ExReleaseResourceLite(vp->FileHeader.Resource); +// ExReleaseResourceLite(&fcb->Vcb->tree_lock); + + return ret; +} + +// It would perhaps be re-use the query_basic_info() call above, if some of the +// IrpSp is moved out of it. +static BOOLEAN __stdcall fastio_query_basic_info(PFILE_OBJECT FileObject, BOOLEAN wait, + PFILE_BASIC_INFORMATION fbi, PIO_STATUS_BLOCK IoStatus, PDEVICE_OBJECT DeviceObject) +{ + vnode_t *vp; + zfs_dirlist_t *ccb; + + FsRtlEnterFileSystem(); + + dprintf("%s: \n", __func__); + + if (!FileObject) { + FsRtlExitFileSystem(); + return FALSE; + } + + vp = FileObject->FsContext; + + if (!vp) { + FsRtlExitFileSystem(); + return FALSE; + } + +#if 0 + // Only dirs have ccb for us, perhaps this is a mistake? + ccb = FileObject->FsContext2; + + if (!ccb) { + FsRtlExitFileSystem(); + return false; + } + + if (!(ccb->access & (FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES))) { + FsRtlExitFileSystem(); + return false; + } + + // handle streams as well + if (vp->ads) { + if (!ccb->fileref || !ccb->fileref->parent || !ccb->fileref->parent->fcb) { + FsRtlExitFileSystem(); + return false; + } + + fcb = ccb->fileref->parent->fcb; + } +#endif + + if (!ExAcquireResourceSharedLite(vp->FileHeader.Resource, wait)) { + FsRtlExitFileSystem(); + return FALSE; + } + + if (VN_HOLD(vp) == 0) { + znode_t *zp = VTOZ(vp); + zfsvfs_t *zfsvfs = zp->z_zfsvfs; + sa_bulk_attr_t bulk[3]; + int count = 0; + uint64_t mtime[2]; + uint64_t ctime[2]; + uint64_t crtime[2]; + SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zfsvfs), NULL, &mtime, 16); + SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs), NULL, &ctime, 16); + SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CRTIME(zfsvfs), NULL, &crtime, 16); + sa_bulk_lookup(zp->z_sa_hdl, bulk, count); + + TIME_UNIX_TO_WINDOWS(mtime, fbi->LastWriteTime.QuadPart); + TIME_UNIX_TO_WINDOWS(ctime, fbi->ChangeTime.QuadPart); + TIME_UNIX_TO_WINDOWS(crtime, fbi->CreationTime.QuadPart); + TIME_UNIX_TO_WINDOWS(zp->z_atime, fbi->LastAccessTime.QuadPart); + + fbi->FileAttributes = zfs_getwinflags(zp); + VN_RELE(vp); + + IoStatus->Status = STATUS_SUCCESS; + IoStatus->Information = sizeof(FILE_BASIC_INFORMATION); + } else { + IoStatus->Status = STATUS_INVALID_PARAMETER; + IoStatus->Information = 0; + } + + ExReleaseResourceLite(vp->FileHeader.Resource); + FsRtlExitFileSystem(); + return TRUE; +} + +static BOOLEAN __stdcall fastio_query_standard_info(PFILE_OBJECT FileObject, + BOOLEAN wait, PFILE_STANDARD_INFORMATION fsi, PIO_STATUS_BLOCK IoStatus, + PDEVICE_OBJECT DeviceObject) +{ + vnode_t *vp; + zfs_dirlist_t *ccb; + BOOLEAN ads; + ULONG adssize; + + FsRtlEnterFileSystem(); + + dprintf("%s: \n", __func__); + + if (!FileObject) { + FsRtlExitFileSystem(); + return FALSE; + } + + vp = FileObject->FsContext; + ccb = FileObject->FsContext2; + + if (!vp) { + FsRtlExitFileSystem(); + return FALSE; + } + + if (!ExAcquireResourceSharedLite(vp->FileHeader.Resource, wait)) { + FsRtlExitFileSystem(); + return FALSE; + } + +#if 0 + // TODO handle streams + ads = fcb->ads; + + if (ads) { + struct _fcb* fcb2; + + if (!ccb || !ccb->fileref || !ccb->fileref->parent || !ccb->fileref->parent->fcb) { + ExReleaseResourceLite(fcb->Header.Resource); + FsRtlExitFileSystem(); + return false; + } + + adssize = fcb->adsdata.Length; + + fcb2 = ccb->fileref->parent->fcb; + + ExReleaseResourceLite(fcb->Header.Resource); + + fcb = fcb2; + + if (!ExAcquireResourceSharedLite(fcb->Header.Resource, wait)) { + FsRtlExitFileSystem(); + return false; + } + + fsi->AllocationSize.QuadPart = fsi->EndOfFile.QuadPart = adssize; + fsi->NumberOfLinks = fcb->inode_item.st_nlink; + fsi->Directory = false; + } + else { + fsi->AllocationSize.QuadPart = fcb_alloc_size(fcb); + fsi->EndOfFile.QuadPart = S_ISDIR(fcb->inode_item.st_mode) ? 0 : fcb->inode_item.st_size; + fsi->NumberOfLinks = fcb->inode_item.st_nlink; + fsi->Directory = S_ISDIR(fcb->inode_item.st_mode); + } +#endif + + if (VN_HOLD(vp) == 0) { + znode_t *zp = VTOZ(vp); + fsi->Directory = vnode_isdir(vp) ? TRUE : FALSE; + uint64_t blk = zfs_blksz(zp); + fsi->AllocationSize.QuadPart = P2ROUNDUP(zp->z_size ? zp->z_size : 1, blk); // space taken on disk, multiples of block size + fsi->EndOfFile.QuadPart = vnode_isdir(vp) ? 0 : zp->z_size; // byte size of file + fsi->NumberOfLinks = zp->z_links; + fsi->DeletePending = vnode_deleteonclose(vp) ? TRUE : FALSE; + VN_RELE(vp); + } + + IoStatus->Status = STATUS_SUCCESS; + IoStatus->Information = sizeof(FILE_STANDARD_INFORMATION); + + ExReleaseResourceLite(vp->FileHeader.Resource); + + FsRtlExitFileSystem(); + + return TRUE; +} + +#define fastio_possible(vp) (!FsRtlAreThereCurrentFileLocks(&vp->lock) /*&& !fcb->Vcb->readonly */ ? FastIoIsPossible : FastIoIsQuestionable) + +static BOOLEAN __stdcall fastio_lock(PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, + PLARGE_INTEGER Length, PEPROCESS ProcessId, ULONG Key, BOOLEAN FailImmediately, + BOOLEAN ExclusiveLock, PIO_STATUS_BLOCK IoStatus, PDEVICE_OBJECT DeviceObject) +{ + BOOLEAN ret; + vnode_t *vp = FileObject->FsContext; + + dprintf("%s: \n", __func__); + + if (!vnode_isreg(vp)) { + dprintf("%s: can only lock files\n", __func__); + IoStatus->Status = STATUS_INVALID_PARAMETER; + IoStatus->Information = 0; + return TRUE; + } + + FsRtlEnterFileSystem(); + ExAcquireResourceSharedLite(vp->FileHeader.Resource, TRUE); + + ret = FsRtlFastLock(&vp->lock, FileObject, FileOffset, Length, ProcessId, Key, FailImmediately, + ExclusiveLock, IoStatus, NULL, FALSE); + + if (ret) + vp->FileHeader.IsFastIoPossible = fastio_possible(vp); + + ExReleaseResourceLite(vp->FileHeader.Resource); + FsRtlExitFileSystem(); + + return ret; +} + +static BOOLEAN __stdcall fastio_unlock_single(PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, + PLARGE_INTEGER Length, PEPROCESS ProcessId, ULONG Key, PIO_STATUS_BLOCK IoStatus, PDEVICE_OBJECT DeviceObject) +{ + vnode_t *vp = FileObject->FsContext; + + dprintf("%s: \n", __func__); + + IoStatus->Information = 0; + + if (!vnode_isreg(vp)) { + dprintf("%s: can only lock files\n", __func__); + IoStatus->Status = STATUS_INVALID_PARAMETER; + return TRUE; + } + + FsRtlEnterFileSystem(); + + IoStatus->Status = FsRtlFastUnlockSingle(&vp->lock, FileObject, FileOffset, Length, ProcessId, Key, NULL, FALSE); + + vp->FileHeader.IsFastIoPossible = fastio_possible(vp); + + FsRtlExitFileSystem(); + + return TRUE; +} + +static BOOLEAN __stdcall fastio_unlock_all(PFILE_OBJECT FileObject, PEPROCESS ProcessId, + PIO_STATUS_BLOCK IoStatus, PDEVICE_OBJECT DeviceObject) +{ + vnode_t *vp = FileObject->FsContext; + + dprintf("%s: \n", __func__); + + IoStatus->Information = 0; + + if (!vnode_isreg(vp)) { + dprintf("%s: can only lock files\n", __func__); + IoStatus->Status = STATUS_INVALID_PARAMETER; + return TRUE; + } + + FsRtlEnterFileSystem(); + + ExAcquireResourceSharedLite(vp->FileHeader.Resource, TRUE); + + IoStatus->Status = FsRtlFastUnlockAll(&vp->lock, FileObject, ProcessId, NULL); + + vp->FileHeader.IsFastIoPossible = fastio_possible(vp); + + ExReleaseResourceLite(vp->FileHeader.Resource); + + FsRtlExitFileSystem(); + + return TRUE; +} + +static BOOLEAN __stdcall fastio_unlock_all_by_key(PFILE_OBJECT FileObject, PVOID ProcessId, + ULONG Key, PIO_STATUS_BLOCK IoStatus, PDEVICE_OBJECT DeviceObject) +{ + vnode_t *vp = FileObject->FsContext; + + dprintf("%s: \n", __func__); + + IoStatus->Information = 0; + + if (!vnode_isreg(vp)) { + dprintf("%s: can only lock files\n", __func__); + IoStatus->Status = STATUS_INVALID_PARAMETER; + return TRUE; + } + + FsRtlEnterFileSystem(); + + ExAcquireResourceSharedLite(vp->FileHeader.Resource, TRUE); + + IoStatus->Status = FsRtlFastUnlockAllByKey(&vp->lock, FileObject, ProcessId, Key, NULL); + + vp->FileHeader.IsFastIoPossible = fastio_possible(vp); + + ExReleaseResourceLite(vp->FileHeader.Resource); + + FsRtlExitFileSystem(); + + return TRUE; +} + +static BOOLEAN __stdcall fastio_query_network_open_info(PFILE_OBJECT FileObject, + BOOLEAN Wait, FILE_NETWORK_OPEN_INFORMATION *fnoi, PIO_STATUS_BLOCK IoStatus, + PDEVICE_OBJECT DeviceObject) +{ + vnode_t *vp; + zfs_dirlist_t *ccb; + + FsRtlEnterFileSystem(); + + dprintf("%s: \n", __func__); + + RtlZeroMemory(fnoi, sizeof(FILE_NETWORK_OPEN_INFORMATION)); + + vp = FileObject->FsContext; + + if (!vp /*|| fcb == fcb->Vcb->volume_fcb*/ ) { + FsRtlExitFileSystem(); + return FALSE; + } + + ccb = FileObject->FsContext2; + +#if 0 + if (!ccb) { + FsRtlExitFileSystem(); + return false; + } +#endif + + // fileref = ccb->fileref; + + // FIXME, handle streams +#if 0 + if (fcb->ads) { + if (!fileref || !fileref->parent) { + ERR("no fileref for stream\n"); + FsRtlExitFileSystem(); + return false; + } + + ii = &fileref->parent->fcb->inode_item; + } + else + ii = &fcb->inode_item; +#endif + + if (VN_HOLD(vp) == 0) { + znode_t *zp = VTOZ(vp); + zfsvfs_t *zfsvfs = zp->z_zfsvfs; + sa_bulk_attr_t bulk[3]; + int count = 0; + uint64_t mtime[2]; + uint64_t ctime[2]; + uint64_t crtime[2]; + SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zfsvfs), NULL, &mtime, 16); + SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs), NULL, &ctime, 16); + SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CRTIME(zfsvfs), NULL, &crtime, 16); + sa_bulk_lookup(zp->z_sa_hdl, bulk, count); + + TIME_UNIX_TO_WINDOWS(mtime, fnoi->LastWriteTime.QuadPart); + TIME_UNIX_TO_WINDOWS(ctime, fnoi->ChangeTime.QuadPart); + TIME_UNIX_TO_WINDOWS(crtime, fnoi->CreationTime.QuadPart); + TIME_UNIX_TO_WINDOWS(zp->z_atime, fnoi->LastAccessTime.QuadPart); + fnoi->AllocationSize.QuadPart = P2ROUNDUP(zp->z_size, zfs_blksz(zp)); + fnoi->EndOfFile.QuadPart = vnode_isdir(vp) ? 0 : zp->z_size; + fnoi->FileAttributes = zfs_getwinflags(zp); + VN_RELE(vp); + } + + FsRtlExitFileSystem(); + + return TRUE; +} + +static NTSTATUS __stdcall fastio_acquire_for_mod_write(PFILE_OBJECT FileObject, + PLARGE_INTEGER EndingOffset, struct _ERESOURCE **ResourceToRelease, PDEVICE_OBJECT DeviceObject) +{ + vnode_t *vp; + + dprintf("%s: \n", __func__); + + vp = FileObject->FsContext; + + if (!vp) + return STATUS_INVALID_PARAMETER; + + // Make sure we don't get interrupted by the flush thread, which can cause a deadlock +#if 0 + if (!ExAcquireResourceSharedLite(&vp->Vcb->tree_lock, false)) + return STATUS_CANT_WAIT; +#endif + + if (!ExAcquireResourceExclusiveLite(vp->FileHeader.Resource, FALSE)) { + //ExReleaseResourceLite(&fcb->Vcb->tree_lock); + dprintf("%s: returning STATUS_CANT_WAIT\n", __func__); + return STATUS_CANT_WAIT; + } + + // Ideally this would be PagingIoResource, but that doesn't play well with copy-on-write, + // as we can't guarantee that we won't need to do any reallocations. + + *ResourceToRelease = vp->FileHeader.Resource; + + dprintf("%s: returning STATUS_SUCCESS\n", __func__); + + return STATUS_SUCCESS; +} + +static NTSTATUS __stdcall fastio_release_for_mod_write(PFILE_OBJECT FileObject, + struct _ERESOURCE *ResourceToRelease, PDEVICE_OBJECT DeviceObject) +{ + vnode_t *vp; + + dprintf("%s:\n", __func__); + + vp = FileObject->FsContext; + + ExReleaseResourceLite(ResourceToRelease); + + //ExReleaseResourceLite(&fcb->Vcb->tree_lock); + return STATUS_SUCCESS; +} + +static NTSTATUS __stdcall fastio_acquire_for_ccflush(PFILE_OBJECT FileObject, + PDEVICE_OBJECT DeviceObject) +{ + + IoSetTopLevelIrp((PIRP)FSRTL_CACHE_TOP_LEVEL_IRP); + + return STATUS_SUCCESS; +} + +static NTSTATUS __stdcall fastio_release_for_ccflush(PFILE_OBJECT FileObject, + PDEVICE_OBJECT DeviceObject) +{ + + if (IoGetTopLevelIrp() == (PIRP)FSRTL_CACHE_TOP_LEVEL_IRP) + IoSetTopLevelIrp(NULL); + + return STATUS_SUCCESS; +} + +static FAST_IO_DISPATCH FastIoDispatch; + +void fastio_init(FAST_IO_DISPATCH **fast) +{ + RtlZeroMemory(&FastIoDispatch, sizeof(FastIoDispatch)); + FastIoDispatch.SizeOfFastIoDispatch = sizeof(FAST_IO_DISPATCH); + + FastIoDispatch.FastIoCheckIfPossible = fastio_check_if_possible; + FastIoDispatch.FastIoRead = FsRtlCopyRead; + FastIoDispatch.FastIoWrite = fastio_write; + FastIoDispatch.FastIoQueryBasicInfo = fastio_query_basic_info; + FastIoDispatch.FastIoQueryStandardInfo = fastio_query_standard_info; + FastIoDispatch.FastIoLock = fastio_lock; + FastIoDispatch.FastIoUnlockSingle = fastio_unlock_single; + FastIoDispatch.FastIoUnlockAll = fastio_unlock_all; + FastIoDispatch.FastIoUnlockAllByKey = fastio_unlock_all_by_key; + FastIoDispatch.FastIoQueryNetworkOpenInfo = fastio_query_network_open_info; + FastIoDispatch.AcquireForModWrite = fastio_acquire_for_mod_write; + FastIoDispatch.MdlRead = FsRtlMdlReadDev; + FastIoDispatch.MdlReadComplete = FsRtlMdlReadCompleteDev; + FastIoDispatch.PrepareMdlWrite = FsRtlPrepareMdlWriteDev; + FastIoDispatch.MdlWriteComplete = FsRtlMdlWriteCompleteDev; + FastIoDispatch.ReleaseForModWrite = fastio_release_for_mod_write; + FastIoDispatch.AcquireForCcFlush = fastio_acquire_for_ccflush; + FastIoDispatch.ReleaseForCcFlush = fastio_release_for_ccflush; + + *fast = &FastIoDispatch; + dprintf("Using FASTIO\n"); +} + + + // FFFF9284A054B080: * user_fs_request: unknown class 0x903bc: CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 238, // 0x2d118c - MASS_STORAGE 0x463