From 206b85c2784ded0457ac82819154f32fd91bee30 Mon Sep 17 00:00:00 2001 From: Bill Zissimopoulos Date: Sun, 29 Jan 2017 13:48:29 -0800 Subject: [PATCH] tst: passthrough-fuse: testing --- tst/passthrough-fuse/passthrough-fuse.c | 2 +- tst/passthrough-fuse/winposix.c | 72 ++++++++++++++++++++----- tst/passthrough-fuse/winposix.h | 5 ++ 3 files changed, 64 insertions(+), 15 deletions(-) diff --git a/tst/passthrough-fuse/passthrough-fuse.c b/tst/passthrough-fuse/passthrough-fuse.c index d3a725dd..0d224a2f 100644 --- a/tst/passthrough-fuse/passthrough-fuse.c +++ b/tst/passthrough-fuse/passthrough-fuse.c @@ -33,7 +33,7 @@ #define FSNAME "passthrough" #define PROGNAME "passthrough-fuse" -#define concat_path(ptfs, fn, fp) (sizeof fp > (unsigned)snprintf(fp, sizeof fp, "%s/%s", ptfs->rootdir, fn)) +#define concat_path(ptfs, fn, fp) (sizeof fp > (unsigned)snprintf(fp, sizeof fp, "%s%s", ptfs->rootdir, fn)) #define ptfs_impl_fullpath(n) \ char full ## n[PATH_MAX]; \ if (!concat_path(((PTFS *)fuse_get_context()->private_data), n, full ## n))\ diff --git a/tst/passthrough-fuse/winposix.c b/tst/passthrough-fuse/winposix.c index a9f7709a..f668d19c 100644 --- a/tst/passthrough-fuse/winposix.c +++ b/tst/passthrough-fuse/winposix.c @@ -54,12 +54,6 @@ char *realpath(const char *path, char *resolved) { char *result; - HANDLE h = CreateFileA(path, - FILE_READ_ATTRIBUTES, 0, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0); - - if (INVALID_HANDLE_VALUE == h) - return error0(); - if (0 == resolved) { result = malloc(PATH_MAX); /* sets errno */ @@ -69,19 +63,32 @@ char *realpath(const char *path, char *resolved) else result = resolved; - if (PATH_MAX < GetFinalPathNameByHandleA(h, resolved, PATH_MAX, 0)) - { - int LastError = GetLastError(); + int err = 0; + DWORD len = GetFullPathNameA(path, PATH_MAX, result, 0); + if (0 == len) + err = GetLastError(); + else if (PATH_MAX < len) + err = ERROR_INVALID_PARAMETER; + if (0 == err) + { + HANDLE h = CreateFileA(result, + FILE_READ_ATTRIBUTES, 0, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0); + if (INVALID_HANDLE_VALUE != h) + CloseHandle(h); + else + err = GetLastError(); + } + + if (0 != err) + { if (result != resolved) free(result); - errno = maperror(LastError); + errno = maperror(err); result = 0; } - CloseHandle(h); - return result; } @@ -113,7 +120,7 @@ int statvfs(const char *path, struct fuse_statvfs *stbuf) stbuf->f_fsid = VolumeSerialNumber; stbuf->f_namemax = MaxComponentLength; - return -1; + return 0; } int open(const char *path, int oflag, ...) @@ -130,7 +137,7 @@ int open(const char *path, int oflag, ...) HANDLE h = CreateFileA(path, DesiredAccess, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0/* default security */, - CreationDisposition, FILE_ATTRIBUTE_NORMAL, 0); + CreationDisposition, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, 0); if (INVALID_HANDLE_VALUE == h) return error(); @@ -493,3 +500,40 @@ static int maperror(int winerrno) return EINVAL; } } + +NTSTATUS WinFspLoad(VOID) +{ +#if defined(_WIN64) +#define FSP_DLLNAME "winfsp-x64.dll" +#else +#define FSP_DLLNAME "winfsp-x86.dll" +#endif +#define FSP_DLLPATH "bin\\" FSP_DLLNAME + + WCHAR PathBuf[MAX_PATH - (sizeof L"" FSP_DLLPATH / sizeof(WCHAR) - 1)]; + DWORD Size; + LONG Result; + HMODULE Module; + + Module = LoadLibraryW(L"" FSP_DLLNAME); + if (0 == Module) + { + Size = sizeof PathBuf; + Result = RegGetValueW( + HKEY_LOCAL_MACHINE, L"Software\\WinFsp", L"InstallDir", + RRF_RT_REG_SZ | 0x00020000/*RRF_SUBKEY_WOW6432KEY*/, + 0, PathBuf, &Size); + if (ERROR_SUCCESS != Result) + return 0xC0000034L/*STATUS_OBJECT_NAME_NOT_FOUND*/; + + RtlCopyMemory(PathBuf + (Size / sizeof(WCHAR) - 1), L"" FSP_DLLPATH, sizeof L"" FSP_DLLPATH); + Module = LoadLibraryW(PathBuf); + if (0 == Module) + return 0xC0000135L/*STATUS_DLL_NOT_FOUND*/; + } + + return 0/*STATUS_SUCCESS*/; + +#undef FSP_DLLNAME +#undef FSP_DLLPATH +} diff --git a/tst/passthrough-fuse/winposix.h b/tst/passthrough-fuse/winposix.h index ff34ce65..52a5f226 100644 --- a/tst/passthrough-fuse/winposix.h +++ b/tst/passthrough-fuse/winposix.h @@ -62,4 +62,9 @@ void rewinddir(DIR *dirp); struct dirent *readdir(DIR *dirp); int closedir(DIR *dirp); +long WinFspLoad(void); +#undef fuse_main +#define fuse_main(argc, argv, ops, data)\ + (WinFspLoad(), fuse_main_real(argc, argv, ops, sizeof *(ops), data)) + #endif