forked from winfsp/winfsp
-
Notifications
You must be signed in to change notification settings - Fork 5
/
library.c
113 lines (91 loc) · 3.02 KB
/
library.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/**
* @file dll/library.c
*
* @copyright 2015-2020 Bill Zissimopoulos
*/
/*
* This file is part of WinFsp.
*
* You can redistribute it and/or modify it under the terms of the GNU
* General Public License version 3 as published by the Free Software
* Foundation.
*
* Licensees holding a valid commercial license may use this software
* in accordance with the commercial license agreement provided in
* conjunction with the software. The terms and conditions of any such
* commercial license agreement shall govern, supersede, and render
* ineffective any application of the GPLv3 license to this software,
* notwithstanding of any reference thereto in the software or
* associated repository.
*/
#include <dll/library.h>
HINSTANCE DllInstance;
BOOL WINAPI DllMain(HINSTANCE Instance, DWORD Reason, PVOID Reserved)
{
BOOLEAN Dynamic;
switch (Reason)
{
case DLL_PROCESS_ATTACH:
DllInstance = Instance;
break;
case DLL_PROCESS_DETACH:
/*
* These functions are called during DLL_PROCESS_DETACH. We must therefore keep
* finalization tasks to a minimum.
*
* See the following documents:
* https://msdn.microsoft.com/en-us/library/windows/desktop/dn633971(v=vs.85).aspx
* https://blogs.msdn.microsoft.com/oldnewthing/20070503-00/?p=27003/
* https://blogs.msdn.microsoft.com/oldnewthing/20100122-00/?p=15193/
*/
Dynamic = 0 == Reserved;
fsp_fuse_finalize(Dynamic);
FspServiceFinalize(Dynamic);
FspFileSystemFinalize(Dynamic);
FspEventLogFinalize(Dynamic);
FspPosixFinalize(Dynamic);
FspWksidFinalize(Dynamic);
break;
case DLL_THREAD_DETACH:
fsp_fuse_finalize_thread();
break;
}
return TRUE;
}
/* see comments in shared/minimal.h */
BOOL WINAPI _DllMainCRTStartup(HINSTANCE Instance, DWORD Reason, PVOID Reserved)
{
return DllMain(Instance, Reason, Reserved);
}
HRESULT WINAPI DllRegisterServer(VOID)
{
NTSTATUS Result;
Result = FspFsctlRegister();
FspDebugLog("FspFsctlRegister = %lx\n", Result);
if (!NT_SUCCESS(Result))
goto exit;
/* ignore errors below; these are non-critical */
Result = FspNpRegister();
FspDebugLog("FspNpRegister = %lx\n", Result);
Result = FspEventLogRegister();
FspDebugLog("FspEventLogRegister = %lx\n", Result);
Result = STATUS_SUCCESS;
exit:
return NT_SUCCESS(Result) ? S_OK : 0x80040201/*SELFREG_E_CLASS*/;
}
HRESULT WINAPI DllUnregisterServer(VOID)
{
NTSTATUS Result;
Result = FspFsctlUnregister();
FspDebugLog("FspFsctlUnregister = %lx\n", Result);
if (!NT_SUCCESS(Result))
goto exit;
/* ignore errors below; these are non-critical */
Result = FspNpUnregister();
FspDebugLog("FspNpUnregister = %lx\n", Result);
Result = FspEventLogUnregister();
FspDebugLog("FspEventLogUnregister = %lx\n", Result);
Result = STATUS_SUCCESS;
exit:
return NT_SUCCESS(Result) ? S_OK : 0x80040201/*SELFREG_E_CLASS*/;
}