mirror of
https://github.com/winfsp/winfsp.git
synced 2025-04-22 08:23:05 -05:00
inc: winfsp.h: FspLoad
This commit is contained in:
parent
06f6c192ed
commit
acf6ce1008
@ -71,60 +71,12 @@ First add the WinFsp DLL as a delay loaded DLL. Open the project properties and
|
||||
|
||||
- Linker > Input > Delay Loaded Dll's: `winfsp-$(PlatformTarget).dll`
|
||||
|
||||
Then add the function `WinFspLoad` to passthrough.c. This function consults the registry to find the WinFsp installation directory, loads the WinFsp DLL and then makes all delay loaded imports available.
|
||||
|
||||
.`*WinFspLoad*`
|
||||
[source,c]
|
||||
----
|
||||
static 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];
|
||||
DWORD Size;
|
||||
HKEY RegKey;
|
||||
LONG Result;
|
||||
HMODULE Module;
|
||||
|
||||
Module = LoadLibraryW(L"" FSP_DLLNAME);
|
||||
if (0 == Module)
|
||||
{
|
||||
Result = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\WinFsp",
|
||||
0, KEY_READ | KEY_WOW64_32KEY, &RegKey);
|
||||
if (ERROR_SUCCESS == Result)
|
||||
{
|
||||
Size = sizeof PathBuf - sizeof L"" FSP_DLLPATH + sizeof(WCHAR);
|
||||
Result = RegGetValueW(RegKey, 0, L"InstallDir",
|
||||
RRF_RT_REG_SZ, 0, PathBuf, &Size);
|
||||
RegCloseKey(RegKey);
|
||||
}
|
||||
if (ERROR_SUCCESS != Result)
|
||||
return 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 STATUS_DLL_NOT_FOUND;
|
||||
}
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
|
||||
#undef FSP_DLLNAME
|
||||
#undef FSP_DLLPATH
|
||||
}
|
||||
----
|
||||
|
||||
Also add the following lines in the beginning of `wmain`:
|
||||
Then add the following lines in the beginning of `wmain`:
|
||||
|
||||
.`*wmain excerpt*`
|
||||
[source,c]
|
||||
----
|
||||
if (!NT_SUCCESS(WinFspLoad()))
|
||||
if (!NT_SUCCESS(FspLoad()))
|
||||
return ERROR_DELAY_LOAD_FAILED;
|
||||
----
|
||||
|
||||
|
@ -1626,6 +1626,52 @@ FSP_API NTSTATUS FspCallNamedPipeSecurely(PWSTR PipeName,
|
||||
PULONG PBytesTransferred, ULONG Timeout,
|
||||
PSID Sid);
|
||||
|
||||
/*
|
||||
* Delay load
|
||||
*/
|
||||
static inline
|
||||
NTSTATUS FspLoad(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];
|
||||
DWORD Size;
|
||||
HKEY RegKey;
|
||||
LONG Result;
|
||||
HMODULE Module;
|
||||
|
||||
Module = LoadLibraryW(L"" FSP_DLLNAME);
|
||||
if (0 == Module)
|
||||
{
|
||||
Result = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\WinFsp",
|
||||
0, KEY_READ | KEY_WOW64_32KEY, &RegKey);
|
||||
if (ERROR_SUCCESS == Result)
|
||||
{
|
||||
Size = sizeof PathBuf - sizeof L"" FSP_DLLPATH + sizeof(WCHAR);
|
||||
Result = RegGetValueW(RegKey, 0, L"InstallDir",
|
||||
RRF_RT_REG_SZ, 0, PathBuf, &Size);
|
||||
RegCloseKey(RegKey);
|
||||
}
|
||||
if (ERROR_SUCCESS != Result)
|
||||
return 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 STATUS_DLL_NOT_FOUND;
|
||||
}
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
|
||||
#undef FSP_DLLNAME
|
||||
#undef FSP_DLLPATH
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -101,7 +101,7 @@
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(MSBuildProgramFiles32)\WinFsp\inc\fuse</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(MSBuildProgramFiles32)\WinFsp\inc\fuse;$(MSBuildProgramFiles32)\WinFsp\inc</AdditionalIncludeDirectories>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
|
||||
</ClCompile>
|
||||
@ -120,7 +120,7 @@
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(MSBuildProgramFiles32)\WinFsp\inc\fuse</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(MSBuildProgramFiles32)\WinFsp\inc\fuse;$(MSBuildProgramFiles32)\WinFsp\inc</AdditionalIncludeDirectories>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
|
||||
</ClCompile>
|
||||
@ -141,7 +141,7 @@
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(MSBuildProgramFiles32)\WinFsp\inc\fuse</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(MSBuildProgramFiles32)\WinFsp\inc\fuse;$(MSBuildProgramFiles32)\WinFsp\inc</AdditionalIncludeDirectories>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
|
||||
</ClCompile>
|
||||
@ -164,7 +164,7 @@
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(MSBuildProgramFiles32)\WinFsp\inc\fuse</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(MSBuildProgramFiles32)\WinFsp\inc\fuse;$(MSBuildProgramFiles32)\WinFsp\inc</AdditionalIncludeDirectories>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
|
||||
</ClCompile>
|
||||
|
@ -24,7 +24,7 @@
|
||||
* file names and security.
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
#include <winfsp/winfsp.h>
|
||||
#include <fcntl.h>
|
||||
#include <fuse.h>
|
||||
#include "winposix.h"
|
||||
@ -523,44 +523,7 @@ static int maperror(int winerrno)
|
||||
}
|
||||
}
|
||||
|
||||
static NTSTATUS WinFspLoad(VOID)
|
||||
long 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];
|
||||
DWORD Size;
|
||||
HKEY RegKey;
|
||||
LONG Result;
|
||||
HMODULE Module;
|
||||
|
||||
Module = LoadLibraryW(L"" FSP_DLLNAME);
|
||||
if (0 == Module)
|
||||
{
|
||||
Result = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\WinFsp",
|
||||
0, KEY_READ | KEY_WOW64_32KEY, &RegKey);
|
||||
if (ERROR_SUCCESS == Result)
|
||||
{
|
||||
Size = sizeof PathBuf - sizeof L"" FSP_DLLPATH + sizeof(WCHAR);
|
||||
Result = RegGetValueW(RegKey, 0, L"InstallDir",
|
||||
RRF_RT_REG_SZ, 0, PathBuf, &Size);
|
||||
RegCloseKey(RegKey);
|
||||
}
|
||||
if (ERROR_SUCCESS != Result)
|
||||
return 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 STATUS_DLL_NOT_FOUND;
|
||||
}
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
|
||||
#undef FSP_DLLNAME
|
||||
#undef FSP_DLLPATH
|
||||
return FspLoad();
|
||||
}
|
||||
|
@ -916,51 +916,9 @@ static NTSTATUS SvcStop(FSP_SERVICE *Service)
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static 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];
|
||||
DWORD Size;
|
||||
HKEY RegKey;
|
||||
LONG Result;
|
||||
HMODULE Module;
|
||||
|
||||
Module = LoadLibraryW(L"" FSP_DLLNAME);
|
||||
if (0 == Module)
|
||||
{
|
||||
Result = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\WinFsp",
|
||||
0, KEY_READ | KEY_WOW64_32KEY, &RegKey);
|
||||
if (ERROR_SUCCESS == Result)
|
||||
{
|
||||
Size = sizeof PathBuf - sizeof L"" FSP_DLLPATH + sizeof(WCHAR);
|
||||
Result = RegGetValueW(RegKey, 0, L"InstallDir",
|
||||
RRF_RT_REG_SZ, 0, PathBuf, &Size);
|
||||
RegCloseKey(RegKey);
|
||||
}
|
||||
if (ERROR_SUCCESS != Result)
|
||||
return 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 STATUS_DLL_NOT_FOUND;
|
||||
}
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
|
||||
#undef FSP_DLLNAME
|
||||
#undef FSP_DLLPATH
|
||||
}
|
||||
|
||||
int wmain(int argc, wchar_t **argv)
|
||||
{
|
||||
if (!NT_SUCCESS(WinFspLoad()))
|
||||
if (!NT_SUCCESS(FspLoad()))
|
||||
return ERROR_DELAY_LOAD_FAILED;
|
||||
|
||||
return FspServiceRun(L"" PROGNAME, SvcStart, SvcStop, 0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user