1 | /* $Id: vbsf.h 78338 2019-04-26 22:08:31Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox Windows Guest Shared Folders - File System Driver header file
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012-2019 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef GA_INCLUDED_SRC_WINNT_SharedFolders_driver_vbsf_h
|
---|
19 | #define GA_INCLUDED_SRC_WINNT_SharedFolders_driver_vbsf_h
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 |
|
---|
25 | /*
|
---|
26 | * This must be defined before including RX headers.
|
---|
27 | */
|
---|
28 | #define MINIRDR__NAME VBoxMRx
|
---|
29 | #define ___MINIRDR_IMPORTS_NAME (VBoxMRxDeviceObject->RdbssExports)
|
---|
30 |
|
---|
31 | /*
|
---|
32 | * System and RX headers.
|
---|
33 | */
|
---|
34 | #include <iprt/nt/nt.h> /* includes ntifs.h + wdm.h */
|
---|
35 | #include <iprt/win/windef.h>
|
---|
36 | #ifndef INVALID_HANDLE_VALUE
|
---|
37 | # define INVALID_HANDLE_VALUE RTNT_INVALID_HANDLE_VALUE /* (The rx.h definition causes warnings for amd64) */
|
---|
38 | #endif
|
---|
39 | #include <iprt/nt/rx.h>
|
---|
40 |
|
---|
41 | /*
|
---|
42 | * VBox shared folders.
|
---|
43 | */
|
---|
44 | #include "vbsfshared.h"
|
---|
45 | #include <VBox/log.h>
|
---|
46 | #include <VBox/VBoxGuestLibSharedFolders.h>
|
---|
47 | #ifdef __cplusplus /* not for Win2kWorkarounds.c */
|
---|
48 | # include <VBox/VBoxGuestLibSharedFoldersInline.h>
|
---|
49 | #endif
|
---|
50 |
|
---|
51 |
|
---|
52 | RT_C_DECLS_BEGIN
|
---|
53 |
|
---|
54 | /*
|
---|
55 | * Global data.
|
---|
56 | */
|
---|
57 | extern PRDBSS_DEVICE_OBJECT VBoxMRxDeviceObject;
|
---|
58 |
|
---|
59 | /**
|
---|
60 | * Maximum drive letters (A - Z).
|
---|
61 | */
|
---|
62 | #define _MRX_MAX_DRIVE_LETTERS 26
|
---|
63 |
|
---|
64 | /**
|
---|
65 | * The shared folders device extension.
|
---|
66 | */
|
---|
67 | typedef struct _MRX_VBOX_DEVICE_EXTENSION
|
---|
68 | {
|
---|
69 | /** The shared folders device object pointer. */
|
---|
70 | PRDBSS_DEVICE_OBJECT pDeviceObject;
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * Keep a list of local connections used.
|
---|
74 | * The size (_MRX_MAX_DRIVE_LETTERS = 26) of the array presents the available drive letters C: - Z: of Windows.
|
---|
75 | */
|
---|
76 | CHAR cLocalConnections[_MRX_MAX_DRIVE_LETTERS];
|
---|
77 | PUNICODE_STRING wszLocalConnectionName[_MRX_MAX_DRIVE_LETTERS];
|
---|
78 | FAST_MUTEX mtxLocalCon;
|
---|
79 |
|
---|
80 | /** Saved pointer to the original IRP_MJ_DEVICE_CONTROL handler. */
|
---|
81 | NTSTATUS (* pfnRDBSSDeviceControl) (PDEVICE_OBJECT pDevObj, PIRP pIrp);
|
---|
82 | /** Saved pointer to the original IRP_MJ_CREATE handler. */
|
---|
83 | NTSTATUS (NTAPI * pfnRDBSSCreate)(PDEVICE_OBJECT pDevObj, PIRP pIrp);
|
---|
84 |
|
---|
85 | } MRX_VBOX_DEVICE_EXTENSION, *PMRX_VBOX_DEVICE_EXTENSION;
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * The shared folders NET_ROOT extension.
|
---|
89 | */
|
---|
90 | typedef struct _MRX_VBOX_NETROOT_EXTENSION
|
---|
91 | {
|
---|
92 | /** The shared folder map handle of this netroot. */
|
---|
93 | VBGLSFMAP map;
|
---|
94 | /** Simple initialized (mapped folder) indicator that works better with the
|
---|
95 | * zero filled defaults than SHFL_ROOT_NIL. */
|
---|
96 | bool fInitialized;
|
---|
97 | } MRX_VBOX_NETROOT_EXTENSION, *PMRX_VBOX_NETROOT_EXTENSION;
|
---|
98 |
|
---|
99 | #define VBOX_FOBX_F_INFO_CREATION_TIME 0x01
|
---|
100 | #define VBOX_FOBX_F_INFO_LASTACCESS_TIME 0x02
|
---|
101 | #define VBOX_FOBX_F_INFO_LASTWRITE_TIME 0x04
|
---|
102 | #define VBOX_FOBX_F_INFO_CHANGE_TIME 0x08
|
---|
103 | #define VBOX_FOBX_F_INFO_ATTRIBUTES 0x10
|
---|
104 |
|
---|
105 | /**
|
---|
106 | * The shared folders file extension.
|
---|
107 | */
|
---|
108 | typedef struct MRX_VBOX_FOBX
|
---|
109 | {
|
---|
110 | /** The host file handle. */
|
---|
111 | SHFLHANDLE hFile;
|
---|
112 | PMRX_SRV_CALL pSrvCall;
|
---|
113 | /** The RTTimeSystemNanoTS value when Info was retrieved, 0 to force update. */
|
---|
114 | uint64_t nsUpToDate;
|
---|
115 | /** Cached object info. */
|
---|
116 | SHFLFSOBJINFO Info;
|
---|
117 | /** NT version of Info.
|
---|
118 | * @todo try eliminate */
|
---|
119 | FILE_BASIC_INFORMATION FileBasicInfo;
|
---|
120 |
|
---|
121 | BOOLEAN fKeepCreationTime;
|
---|
122 | BOOLEAN fKeepLastAccessTime;
|
---|
123 | BOOLEAN fKeepLastWriteTime;
|
---|
124 | BOOLEAN fKeepChangeTime;
|
---|
125 | BYTE SetFileInfoOnCloseFlags;
|
---|
126 | } MRX_VBOX_FOBX, *PMRX_VBOX_FOBX;
|
---|
127 |
|
---|
128 | #define VBoxMRxGetDeviceExtension(RxContext) \
|
---|
129 | (PMRX_VBOX_DEVICE_EXTENSION)((PBYTE)(RxContext->RxDeviceObject) + sizeof(RDBSS_DEVICE_OBJECT))
|
---|
130 |
|
---|
131 | #define VBoxMRxGetNetRootExtension(pNetRoot) \
|
---|
132 | (((pNetRoot) == NULL) ? NULL : (PMRX_VBOX_NETROOT_EXTENSION)((pNetRoot)->Context))
|
---|
133 |
|
---|
134 | #define VBoxMRxGetSrvOpenExtension(pSrvOpen) \
|
---|
135 | (((pSrvOpen) == NULL) ? NULL : (PMRX_VBOX_SRV_OPEN)((pSrvOpen)->Context))
|
---|
136 |
|
---|
137 | #define VBoxMRxGetFileObjectExtension(pFobx) \
|
---|
138 | (((pFobx) == NULL) ? NULL : (PMRX_VBOX_FOBX)((pFobx)->Context))
|
---|
139 |
|
---|
140 | /** HACK ALERT: Special Create.ShareAccess indicating trailing slash for
|
---|
141 | * non-directory IRP_MJ_CREATE request.
|
---|
142 | * Set by VBoxHookMjCreate, used by VBoxMRxCreate. */
|
---|
143 | #define VBOX_MJ_CREATE_SLASH_HACK UINT16_C(0x0400)
|
---|
144 |
|
---|
145 | /** @name Prototypes for the dispatch table routines.
|
---|
146 | * @{
|
---|
147 | */
|
---|
148 | NTSTATUS VBoxMRxStart(IN OUT struct _RX_CONTEXT * RxContext,
|
---|
149 | IN OUT PRDBSS_DEVICE_OBJECT RxDeviceObject);
|
---|
150 | NTSTATUS VBoxMRxStop(IN OUT struct _RX_CONTEXT * RxContext,
|
---|
151 | IN OUT PRDBSS_DEVICE_OBJECT RxDeviceObject);
|
---|
152 |
|
---|
153 | NTSTATUS VBoxMRxCreate(IN OUT PRX_CONTEXT RxContext);
|
---|
154 | NTSTATUS VBoxMRxCollapseOpen(IN OUT PRX_CONTEXT RxContext);
|
---|
155 | NTSTATUS VBoxMRxShouldTryToCollapseThisOpen(IN OUT PRX_CONTEXT RxContext);
|
---|
156 | NTSTATUS VBoxMRxFlush(IN OUT PRX_CONTEXT RxContext);
|
---|
157 | NTSTATUS VBoxMRxTruncate(IN OUT PRX_CONTEXT RxContext);
|
---|
158 | NTSTATUS VBoxMRxCleanupFobx(IN OUT PRX_CONTEXT RxContext);
|
---|
159 | NTSTATUS VBoxMRxCloseSrvOpen(IN OUT PRX_CONTEXT RxContext);
|
---|
160 | NTSTATUS VBoxMRxDeallocateForFcb(IN OUT PMRX_FCB pFcb);
|
---|
161 | NTSTATUS VBoxMRxDeallocateForFobx(IN OUT PMRX_FOBX pFobx);
|
---|
162 | NTSTATUS VBoxMRxForceClosed(IN OUT PMRX_SRV_OPEN SrvOpen);
|
---|
163 |
|
---|
164 | NTSTATUS VBoxMRxQueryDirectory(IN OUT PRX_CONTEXT RxContext);
|
---|
165 | NTSTATUS VBoxMRxQueryFileInfo(IN OUT PRX_CONTEXT RxContext);
|
---|
166 | NTSTATUS VBoxMRxSetFileInfo(IN OUT PRX_CONTEXT RxContext);
|
---|
167 | NTSTATUS VBoxMRxSetFileInfoAtCleanup(IN OUT PRX_CONTEXT RxContext);
|
---|
168 | NTSTATUS VBoxMRxQueryEaInfo(IN OUT PRX_CONTEXT RxContext);
|
---|
169 | NTSTATUS VBoxMRxSetEaInfo(IN OUT struct _RX_CONTEXT * RxContext);
|
---|
170 | NTSTATUS VBoxMRxQuerySdInfo(IN OUT PRX_CONTEXT RxContext);
|
---|
171 | NTSTATUS VBoxMRxSetSdInfo(IN OUT struct _RX_CONTEXT * RxContext);
|
---|
172 | NTSTATUS VBoxMRxQueryVolumeInfo(IN OUT PRX_CONTEXT RxContext);
|
---|
173 |
|
---|
174 | NTSTATUS VBoxMRxComputeNewBufferingState(IN OUT PMRX_SRV_OPEN pSrvOpen,
|
---|
175 | IN PVOID pMRxContext,
|
---|
176 | OUT ULONG *pNewBufferingState);
|
---|
177 |
|
---|
178 | NTSTATUS VBoxMRxRead(IN OUT PRX_CONTEXT RxContext);
|
---|
179 | NTSTATUS VBoxMRxWrite(IN OUT PRX_CONTEXT RxContext);
|
---|
180 | NTSTATUS VBoxMRxLocks(IN OUT PRX_CONTEXT RxContext);
|
---|
181 | NTSTATUS VBoxMRxFsCtl(IN OUT PRX_CONTEXT RxContext);
|
---|
182 | NTSTATUS VBoxMRxIoCtl(IN OUT PRX_CONTEXT RxContext);
|
---|
183 | NTSTATUS VBoxMRxNotifyChangeDirectory(IN OUT PRX_CONTEXT RxContext);
|
---|
184 |
|
---|
185 | ULONG NTAPI VBoxMRxExtendStub(IN OUT struct _RX_CONTEXT * RxContext,
|
---|
186 | IN OUT PLARGE_INTEGER pNewFileSize,
|
---|
187 | OUT PLARGE_INTEGER pNewAllocationSize);
|
---|
188 | NTSTATUS VBoxMRxCompleteBufferingStateChangeRequest(IN OUT PRX_CONTEXT RxContext,
|
---|
189 | IN OUT PMRX_SRV_OPEN SrvOpen,
|
---|
190 | IN PVOID pContext);
|
---|
191 |
|
---|
192 | NTSTATUS VBoxMRxCreateVNetRoot(IN OUT PMRX_CREATENETROOT_CONTEXT pContext);
|
---|
193 | NTSTATUS VBoxMRxFinalizeVNetRoot(IN OUT PMRX_V_NET_ROOT pVirtualNetRoot,
|
---|
194 | IN PBOOLEAN ForceDisconnect);
|
---|
195 | NTSTATUS VBoxMRxFinalizeNetRoot(IN OUT PMRX_NET_ROOT pNetRoot,
|
---|
196 | IN PBOOLEAN ForceDisconnect);
|
---|
197 | NTSTATUS VBoxMRxUpdateNetRootState(IN PMRX_NET_ROOT pNetRoot);
|
---|
198 | VOID VBoxMRxExtractNetRootName(IN PUNICODE_STRING FilePathName,
|
---|
199 | IN PMRX_SRV_CALL SrvCall,
|
---|
200 | OUT PUNICODE_STRING NetRootName,
|
---|
201 | OUT PUNICODE_STRING RestOfName OPTIONAL);
|
---|
202 |
|
---|
203 | NTSTATUS VBoxMRxCreateSrvCall(PMRX_SRV_CALL pSrvCall,
|
---|
204 | PMRX_SRVCALL_CALLBACK_CONTEXT pCallbackContext);
|
---|
205 | NTSTATUS VBoxMRxSrvCallWinnerNotify(IN OUT PMRX_SRV_CALL pSrvCall,
|
---|
206 | IN BOOLEAN ThisMinirdrIsTheWinner,
|
---|
207 | IN OUT PVOID pSrvCallContext);
|
---|
208 | NTSTATUS VBoxMRxFinalizeSrvCall(PMRX_SRV_CALL pSrvCall,
|
---|
209 | BOOLEAN Force);
|
---|
210 |
|
---|
211 | NTSTATUS VBoxMRxDevFcbXXXControlFile(IN OUT PRX_CONTEXT RxContext);
|
---|
212 | /** @} */
|
---|
213 |
|
---|
214 | /** @name Support functions and helpers
|
---|
215 | * @{
|
---|
216 | */
|
---|
217 | NTSTATUS vbsfNtDeleteConnection(IN PRX_CONTEXT RxContext,
|
---|
218 | OUT PBOOLEAN PostToFsp);
|
---|
219 | NTSTATUS vbsfNtCreateConnection(IN PRX_CONTEXT RxContext,
|
---|
220 | OUT PBOOLEAN PostToFsp);
|
---|
221 |
|
---|
222 | NTSTATUS vbsfNtSetEndOfFile(IN OUT struct _RX_CONTEXT * RxContext,
|
---|
223 | IN uint64_t cbNewFileSize);
|
---|
224 | NTSTATUS vbsfNtRename(IN PRX_CONTEXT RxContext,
|
---|
225 | IN FILE_INFORMATION_CLASS FileInformationClass,
|
---|
226 | IN PVOID pBuffer,
|
---|
227 | IN ULONG BufferLength);
|
---|
228 | NTSTATUS vbsfNtRemove(IN PRX_CONTEXT RxContext);
|
---|
229 |
|
---|
230 | void vbsfNtCopyInfoToLegacy(PMRX_VBOX_FOBX pVBoxFobx, PCSHFLFSOBJINFO pInfo);
|
---|
231 |
|
---|
232 | NTSTATUS vbsfNtVBoxStatusToNt(int vrc);
|
---|
233 | PVOID vbsfNtAllocNonPagedMem(ULONG ulSize);
|
---|
234 | void vbsfNtFreeNonPagedMem(PVOID lpMem);
|
---|
235 | NTSTATUS vbsfNtShflStringFromUnicodeAlloc(PSHFLSTRING *ppShflString, const WCHAR *pwc, uint16_t cb);
|
---|
236 | #if defined(DEBUG) || defined(LOG_ENABLED)
|
---|
237 | const char *vbsfNtMajorFunctionName(UCHAR MajorFunction, LONG MinorFunction);
|
---|
238 | #endif
|
---|
239 |
|
---|
240 | /**
|
---|
241 | * Converts VBox (IPRT) file mode to NT file attributes.
|
---|
242 | *
|
---|
243 | * @returns NT file attributes
|
---|
244 | * @param fIprtMode IPRT file mode.
|
---|
245 | *
|
---|
246 | */
|
---|
247 | DECLINLINE(uint32_t) VBoxToNTFileAttributes(uint32_t fIprtMode)
|
---|
248 | {
|
---|
249 | AssertCompile((RTFS_DOS_READONLY >> RTFS_DOS_SHIFT) == FILE_ATTRIBUTE_READONLY);
|
---|
250 | AssertCompile((RTFS_DOS_HIDDEN >> RTFS_DOS_SHIFT) == FILE_ATTRIBUTE_HIDDEN);
|
---|
251 | AssertCompile((RTFS_DOS_SYSTEM >> RTFS_DOS_SHIFT) == FILE_ATTRIBUTE_SYSTEM);
|
---|
252 | AssertCompile((RTFS_DOS_DIRECTORY >> RTFS_DOS_SHIFT) == FILE_ATTRIBUTE_DIRECTORY);
|
---|
253 | AssertCompile((RTFS_DOS_ARCHIVED >> RTFS_DOS_SHIFT) == FILE_ATTRIBUTE_ARCHIVE);
|
---|
254 | AssertCompile((RTFS_DOS_NT_DEVICE >> RTFS_DOS_SHIFT) == FILE_ATTRIBUTE_DEVICE);
|
---|
255 | AssertCompile((RTFS_DOS_NT_NORMAL >> RTFS_DOS_SHIFT) == FILE_ATTRIBUTE_NORMAL);
|
---|
256 | AssertCompile((RTFS_DOS_NT_TEMPORARY >> RTFS_DOS_SHIFT) == FILE_ATTRIBUTE_TEMPORARY);
|
---|
257 | AssertCompile((RTFS_DOS_NT_SPARSE_FILE >> RTFS_DOS_SHIFT) == FILE_ATTRIBUTE_SPARSE_FILE);
|
---|
258 | AssertCompile((RTFS_DOS_NT_REPARSE_POINT >> RTFS_DOS_SHIFT) == FILE_ATTRIBUTE_REPARSE_POINT);
|
---|
259 | AssertCompile((RTFS_DOS_NT_COMPRESSED >> RTFS_DOS_SHIFT) == FILE_ATTRIBUTE_COMPRESSED);
|
---|
260 | AssertCompile((RTFS_DOS_NT_OFFLINE >> RTFS_DOS_SHIFT) == FILE_ATTRIBUTE_OFFLINE);
|
---|
261 | AssertCompile((RTFS_DOS_NT_NOT_CONTENT_INDEXED >> RTFS_DOS_SHIFT) == FILE_ATTRIBUTE_NOT_CONTENT_INDEXED);
|
---|
262 | AssertCompile((RTFS_DOS_NT_ENCRYPTED >> RTFS_DOS_SHIFT) == FILE_ATTRIBUTE_ENCRYPTED);
|
---|
263 |
|
---|
264 | uint32_t fNtAttribs = (fIprtMode & (RTFS_DOS_MASK_NT & ~(RTFS_DOS_NT_OFFLINE | RTFS_DOS_NT_DEVICE | RTFS_DOS_NT_REPARSE_POINT)))
|
---|
265 | >> RTFS_DOS_SHIFT;
|
---|
266 | return fNtAttribs ? fNtAttribs : FILE_ATTRIBUTE_NORMAL;
|
---|
267 | }
|
---|
268 |
|
---|
269 | /**
|
---|
270 | * Converts NT file attributes to VBox (IPRT) ones.
|
---|
271 | *
|
---|
272 | * @returns IPRT file mode
|
---|
273 | * @param fNtAttribs NT file attributes
|
---|
274 | */
|
---|
275 | DECLINLINE(uint32_t) NTToVBoxFileAttributes(uint32_t fNtAttribs)
|
---|
276 | {
|
---|
277 | uint32_t fIprtMode = (fNtAttribs << RTFS_DOS_SHIFT) & RTFS_DOS_MASK_NT;
|
---|
278 | fIprtMode &= ~(RTFS_DOS_NT_OFFLINE | RTFS_DOS_NT_DEVICE | RTFS_DOS_NT_REPARSE_POINT);
|
---|
279 | return fIprtMode ? fIprtMode : RTFS_DOS_NT_NORMAL;
|
---|
280 | }
|
---|
281 |
|
---|
282 | /** @} */
|
---|
283 |
|
---|
284 | RT_C_DECLS_END
|
---|
285 |
|
---|
286 | #endif /* !GA_INCLUDED_SRC_WINNT_SharedFolders_driver_vbsf_h */
|
---|