dokani.h
1 /*
2  Dokan : user-mode file system library for Windows
3 
4  Copyright (C) 2020 - 2023 Google, Inc.
5  Copyright (C) 2015 - 2019 Adrien J. <liryna.stark@gmail.com> and Maxime C. <maxime@islog.com>
6  Copyright (C) 2007 - 2011 Hiroki Asakawa <info@dokan-dev.net>
7 
8  http://dokan-dev.github.io
9 
10 This program is free software; you can redistribute it and/or modify it under
11 the terms of the GNU Lesser General Public License as published by the Free
12 Software Foundation; either version 3 of the License, or (at your option) any
13 later version.
14 
15 This program is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 
19 You should have received a copy of the GNU Lesser General Public License along
20 with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 #ifndef DOKANI_H_
24 #define DOKANI_H_
25 
26 #define WIN32_NO_STATUS
27 #include <windows.h>
28 #undef WIN32_NO_STATUS
29 #include <stdio.h>
30 
31 #include "dokan.h"
32 #include "dokanc.h"
33 #include "list.h"
34 #include "dokan_vector.h"
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 typedef struct _DOKAN_INSTANCE_THREADINFO {
41  PTP_POOL ThreadPool;
42  PTP_CLEANUP_GROUP CleanupGroup;
43  TP_CALLBACK_ENVIRON CallbackEnvironment;
45 
55 typedef struct _DOKAN_INSTANCE {
57  CRITICAL_SECTION CriticalSection;
62  WCHAR DeviceName[64];
64  WCHAR MountPoint[MAX_PATH];
66  WCHAR UNCName[64];
68  ULONG DeviceNumber;
70  ULONG MountId;
72  PDOKAN_OPTIONS DokanOptions;
74  PDOKAN_OPERATIONS DokanOperations;
76  LIST_ENTRY ListEntry;
78  HANDLE GlobalDevice;
80  HANDLE Device;
86  HANDLE NotifyHandle;
96 } DOKAN_INSTANCE, *PDOKAN_INSTANCE;
97 
104 typedef struct _DOKAN_OPEN_INFO {
105  CRITICAL_SECTION CriticalSection;
107  PDOKAN_INSTANCE DokanInstance;
108  PDOKAN_VECTOR DirList;
109  PWCHAR DirListSearchPattern;
113  LONG64 UserContext;
115  ULONG EventId;
119  ULONG OpenCount;
122  LONG64 CloseUserContext;
124  PEVENT_CONTEXT EventContext;
125 } DOKAN_OPEN_INFO, *PDOKAN_OPEN_INFO;
126 
138 typedef struct _DOKAN_IO_BATCH {
140  PDOKAN_INSTANCE DokanInstance;
161  EVENT_CONTEXT EventContext[1];
162 } DOKAN_IO_BATCH, *PDOKAN_IO_BATCH;
163 
171 typedef struct _DOKAN_IO_EVENT {
173  PDOKAN_INSTANCE DokanInstance;
175  PDOKAN_OPEN_INFO DokanOpenInfo;
180  PEVENT_INFORMATION EventResult;
191  PEVENT_CONTEXT EventContext;
196  PDOKAN_IO_BATCH IoBatch;
197 } DOKAN_IO_EVENT, *PDOKAN_IO_EVENT;
198 
199 #define IOEVENT_RESULT_BUFFER_SIZE(ioEvent) \
200  ((ioEvent)->EventResultSize >= offsetof(EVENT_INFORMATION, Buffer) \
201  ? (ioEvent)->EventResultSize - offsetof(EVENT_INFORMATION, Buffer) \
202  : 0)
203 
204 
205 int DokanStart(_In_ PDOKAN_INSTANCE DokanInstance);
206 
207 BOOL SendToDevice(LPCWSTR DeviceName, DWORD IoControlCode, PVOID InputBuffer,
208  ULONG InputLength, PVOID OutputBuffer, ULONG OutputLength,
209  PULONG ReturnedLength);
210 
211 VOID
212 GetRawDeviceName(LPCWSTR DeviceName, LPWSTR DestinationBuffer,
213  rsize_t DestinationBufferSizeInElements);
214 
215 VOID ALIGN_ALLOCATION_SIZE(PLARGE_INTEGER size, PDOKAN_OPTIONS DokanOptions);
216 
217 BOOL DokanMount(PDOKAN_INSTANCE DokanInstance,
218  PDOKAN_OPTIONS DokanOptions);
219 
220 BOOL IsMountPointDriveLetter(LPCWSTR mountPoint);
221 
222 VOID EventCompletion(PDOKAN_IO_EVENT EventInfo);
223 
224 VOID CreateDispatchCommon(PDOKAN_IO_EVENT IoEvent, ULONG SizeOfEventInfo,
225  BOOL UseExtraMemoryPool, BOOL ClearNonPoolBuffer);
226 
227 VOID DispatchDirectoryInformation(PDOKAN_IO_EVENT IoEvent);
228 
229 VOID DispatchQueryInformation(PDOKAN_IO_EVENT IoEvent);
230 
231 VOID DispatchQueryVolumeInformation(PDOKAN_IO_EVENT IoEvent);
232 
233 VOID DispatchSetInformation(PDOKAN_IO_EVENT IoEvent);
234 
235 VOID DispatchRead(PDOKAN_IO_EVENT IoEvent);
236 
237 VOID DispatchWrite(PDOKAN_IO_EVENT IoEvent);
238 
239 VOID DispatchCreate(PDOKAN_IO_EVENT IoEvent);
240 
241 VOID DispatchClose(PDOKAN_IO_EVENT IoEvent);
242 
243 VOID DispatchCleanup(PDOKAN_IO_EVENT IoEvent);
244 
245 VOID DispatchFlush(PDOKAN_IO_EVENT IoEvent);
246 
247 VOID DispatchLock(PDOKAN_IO_EVENT IoEvent);
248 
249 VOID DispatchQuerySecurity(PDOKAN_IO_EVENT IoEvent);
250 
251 VOID DispatchSetSecurity(PDOKAN_IO_EVENT IoEvent);
252 
253 BOOL SendReleaseIRP(LPCWSTR DeviceName);
254 
255 BOOL SendGlobalReleaseIRP(LPCWSTR MountPoint);
256 
257 VOID CheckFileName(LPWSTR FileName);
258 
259 VOID ReleaseDokanOpenInfo(PDOKAN_IO_EVENT IoEvent);
260 
261 VOID DokanNotifyUnmounted(PDOKAN_INSTANCE DokanInstance);
262 
263 #ifdef __cplusplus
264 }
265 #endif
266 
267 #endif // DOKANI_H_
PDOKAN_OPEN_INFO DokanOpenInfo
Definition: dokani.h:175
LONG64 UserContext
Definition: dokani.h:113
PDOKAN_INSTANCE DokanInstance
Definition: dokani.h:173
HANDLE KeepaliveHandle
Definition: dokani.h:88
ULONG OpenCount
Definition: dokani.h:119
Dokan mount instance informations.
Definition: dokani.h:55
ULONG DeviceNumber
Definition: dokani.h:68
PEVENT_CONTEXT EventContext
Definition: dokani.h:191
BOOL PoolAllocated
Definition: dokani.h:149
LPWSTR CloseFileName
Definition: dokani.h:121
BOOL FileSystemStopped
Definition: dokani.h:90
BOOL IsDirectory
Definition: dokani.h:117
PDOKAN_INSTANCE DokanInstance
Definition: dokani.h:140
Dokan IO batch buffer.
Definition: dokani.h:138
BOOLEAN UnimplementedFindFilesWithPattern
Definition: dokani.h:111
PDOKAN_OPTIONS DokanOptions
Definition: dokani.h:72
PEVENT_CONTEXT EventContext
Definition: dokani.h:124
Definition: dokani.h:40
BOOL PoolAllocated
Definition: dokani.h:187
Dokan IO Event.
Definition: dokani.h:171
LONG EventContextBatchCount
Definition: dokani.h:155
Dokan open file informations.
Definition: dokani.h:104
BOOL MainPullThread
Definition: dokani.h:144
LIST_ENTRY ListEntry
Definition: dokani.h:76
LONG UnmountedCalled
Definition: dokani.h:95
PDOKAN_IO_BATCH IoBatch
Definition: dokani.h:196
HANDLE DeviceClosedWaitHandle
Definition: dokani.h:82
ULONG MountId
Definition: dokani.h:70
PDOKAN_INSTANCE DokanInstance
Definition: dokani.h:107
Dokan file information on the current operation.
Definition: dokan.h:181
HANDLE Device
Definition: dokani.h:80
ULONG EventId
Definition: dokani.h:115
CRITICAL_SECTION CriticalSection
Definition: dokani.h:57
ULONG EventResultSize
Definition: dokani.h:182
PDOKAN_OPERATIONS DokanOperations
Definition: dokani.h:74
HANDLE NotifyHandle
Definition: dokani.h:86
HANDLE GlobalDevice
Definition: dokani.h:78
DOKAN_FILE_INFO DokanFileInfo
Definition: dokani.h:189
DOKAN_INSTANCE_THREADINFO ThreadInfo
Definition: dokani.h:84
DWORD NumberOfBytesTransferred
Definition: dokani.h:142
PEVENT_INFORMATION EventResult
Definition: dokani.h:180