VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/SharedFolders/driver/vbsf.h@ 78551

Last change on this file since 78551 was 78487, checked in by vboxsync, 6 years ago

winnt/vboxsf: FileFsSizeInformation and FileFsFullSizeInformation. bugref:9172

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.2 KB
Line 
1/* $Id: vbsf.h 78487 2019-05-13 23:25:38Z 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
52RT_C_DECLS_BEGIN
53
54/*
55 * Global data.
56 */
57extern PRDBSS_DEVICE_OBJECT VBoxMRxDeviceObject;
58extern uint32_t g_uSfLastFunction;
59
60/**
61 * Maximum drive letters (A - Z).
62 */
63#define _MRX_MAX_DRIVE_LETTERS 26
64
65/**
66 * The shared folders device extension.
67 */
68typedef struct _MRX_VBOX_DEVICE_EXTENSION
69{
70 /** The shared folders device object pointer. */
71 PRDBSS_DEVICE_OBJECT pDeviceObject;
72
73 /**
74 * Keep a list of local connections used.
75 * The size (_MRX_MAX_DRIVE_LETTERS = 26) of the array presents the available drive letters C: - Z: of Windows.
76 */
77 CHAR cLocalConnections[_MRX_MAX_DRIVE_LETTERS];
78 PUNICODE_STRING wszLocalConnectionName[_MRX_MAX_DRIVE_LETTERS];
79 FAST_MUTEX mtxLocalCon;
80
81 /** Saved pointer to the original IRP_MJ_DEVICE_CONTROL handler. */
82 NTSTATUS (* pfnRDBSSDeviceControl) (PDEVICE_OBJECT pDevObj, PIRP pIrp);
83 /** Saved pointer to the original IRP_MJ_CREATE handler. */
84 NTSTATUS (NTAPI * pfnRDBSSCreate)(PDEVICE_OBJECT pDevObj, PIRP pIrp);
85 /** Saved pointer to the original IRP_MJ_SET_INFORMATION handler. */
86 NTSTATUS (NTAPI * pfnRDBSSSetInformation)(PDEVICE_OBJECT pDevObj, PIRP pIrp);
87
88} MRX_VBOX_DEVICE_EXTENSION, *PMRX_VBOX_DEVICE_EXTENSION;
89
90/**
91 * The shared folders NET_ROOT extension.
92 */
93typedef struct _MRX_VBOX_NETROOT_EXTENSION
94{
95 /** The shared folder map handle of this netroot. */
96 VBGLSFMAP map;
97 /** Simple initialized (mapped folder) indicator that works better with the
98 * zero filled defaults than SHFL_ROOT_NIL. */
99 bool fInitialized;
100} MRX_VBOX_NETROOT_EXTENSION, *PMRX_VBOX_NETROOT_EXTENSION;
101
102
103/** Pointer to the VBox file object extension data. */
104typedef struct MRX_VBOX_FOBX *PMRX_VBOX_FOBX;
105
106/**
107 * VBox extension data to the file control block (FCB).
108 *
109 * @note To unix people, think of the FCB as the inode structure. This is our
110 * private addition to the inode info.
111 */
112typedef struct VBSFNTFCBEXT
113{
114 /** @name Pointers to file object extensions currently sitting on the given timestamps.
115 *
116 * The file object extensions pointed to have disabled implicit updating the
117 * respective timestamp due to a FileBasicInformation set request. Should these
118 * timestamps be modified via any other file handle, these pointers will be
119 * updated or set to NULL to reflect this. So, when the cleaning up a file
120 * object it can be more accurately determined whether to restore timestamps on
121 * non-windows host systems or not.
122 *
123 * @{ */
124 PMRX_VBOX_FOBX pFobxLastAccessTime;
125 PMRX_VBOX_FOBX pFobxLastWriteTime;
126 PMRX_VBOX_FOBX pFobxChangeTime;
127 /** @} */
128
129 /** @name Cached volume info.
130 * @{ */
131 /** The RTTimeSystemNanoTS value when VolInfo was retrieved, 0 to force update. */
132 uint64_t volatile nsVolInfoUpToDate;
133 /** Volume information. */
134 SHFLVOLINFO volatile VolInfo;
135 /** @} */
136} VBSFNTFCBEXT;
137/** Pointer to the VBox FCB extension data. */
138typedef VBSFNTFCBEXT *PVBSFNTFCBEXT;
139
140
141/** @name VBOX_FOBX_F_INFO_XXX
142 * @{ */
143#define VBOX_FOBX_F_INFO_LASTACCESS_TIME UINT8_C(0x01)
144#define VBOX_FOBX_F_INFO_LASTWRITE_TIME UINT8_C(0x02)
145#define VBOX_FOBX_F_INFO_CHANGE_TIME UINT8_C(0x04)
146/** @} */
147
148/**
149 * The shared folders file extension.
150 */
151typedef struct MRX_VBOX_FOBX
152{
153 /** The host file handle. */
154 SHFLHANDLE hFile;
155 PMRX_SRV_CALL pSrvCall;
156 /** The RTTimeSystemNanoTS value when Info was retrieved, 0 to force update. */
157 uint64_t nsUpToDate;
158 /** Cached object info.
159 * @todo Consider moving it to VBSFNTFCBEXT. Better fit than on "handle". */
160 SHFLFSOBJINFO Info;
161
162 /** VBOX_FOBX_F_INFO_XXX of timestamps which may need setting on close. */
163 uint8_t fTimestampsSetByUser;
164 /** VBOX_FOBX_F_INFO_XXX of timestamps which implicit updating is suppressed. */
165 uint8_t fTimestampsUpdatingSuppressed;
166 /** VBOX_FOBX_F_INFO_XXX of timestamps which may have implicitly update. */
167 uint8_t fTimestampsImplicitlyUpdated;
168} MRX_VBOX_FOBX;
169
170#define VBoxMRxGetDeviceExtension(RxContext) \
171 ((PMRX_VBOX_DEVICE_EXTENSION)((PBYTE)(RxContext)->RxDeviceObject + sizeof(RDBSS_DEVICE_OBJECT)))
172
173#define VBoxMRxGetNetRootExtension(pNetRoot) ((pNetRoot) != NULL ? (PMRX_VBOX_NETROOT_EXTENSION)(pNetRoot)->Context : NULL)
174
175#define VBoxMRxGetFcbExtension(pFcb) ((pFcb) != NULL ? (PVBSFNTFCBEXT)(pFcb)->Context : NULL)
176
177#define VBoxMRxGetSrvOpenExtension(pSrvOpen) ((pSrvOpen) != NULL ? (PMRX_VBOX_SRV_OPEN)(pSrvOpen)->Context : NULL)
178
179#define VBoxMRxGetFileObjectExtension(pFobx) ((pFobx) != NULL ? (PMRX_VBOX_FOBX)(pFobx)->Context : NULL)
180
181/** HACK ALERT: Special Create.ShareAccess indicating trailing slash for
182 * non-directory IRP_MJ_CREATE request.
183 * Set by VBoxHookMjCreate, used by VBoxMRxCreate. */
184#define VBOX_MJ_CREATE_SLASH_HACK UINT16_C(0x0400)
185
186/** @name Prototypes for the dispatch table routines.
187 * @{
188 */
189NTSTATUS VBoxMRxStart(IN OUT struct _RX_CONTEXT * RxContext,
190 IN OUT PRDBSS_DEVICE_OBJECT RxDeviceObject);
191NTSTATUS VBoxMRxStop(IN OUT struct _RX_CONTEXT * RxContext,
192 IN OUT PRDBSS_DEVICE_OBJECT RxDeviceObject);
193
194NTSTATUS VBoxMRxCreate(IN OUT PRX_CONTEXT RxContext);
195NTSTATUS VBoxMRxCollapseOpen(IN OUT PRX_CONTEXT RxContext);
196NTSTATUS VBoxMRxShouldTryToCollapseThisOpen(IN OUT PRX_CONTEXT RxContext);
197NTSTATUS VBoxMRxFlush(IN OUT PRX_CONTEXT RxContext);
198NTSTATUS VBoxMRxTruncate(IN OUT PRX_CONTEXT RxContext);
199NTSTATUS VBoxMRxCleanupFobx(IN OUT PRX_CONTEXT RxContext);
200NTSTATUS VBoxMRxCloseSrvOpen(IN OUT PRX_CONTEXT RxContext);
201NTSTATUS VBoxMRxDeallocateForFcb(IN OUT PMRX_FCB pFcb);
202NTSTATUS VBoxMRxDeallocateForFobx(IN OUT PMRX_FOBX pFobx);
203NTSTATUS VBoxMRxForceClosed(IN OUT PMRX_SRV_OPEN SrvOpen);
204
205NTSTATUS VBoxMRxQueryDirectory(IN OUT PRX_CONTEXT RxContext);
206NTSTATUS VBoxMRxQueryFileInfo(IN OUT PRX_CONTEXT RxContext);
207NTSTATUS VBoxMRxSetFileInfo(IN OUT PRX_CONTEXT RxContext);
208NTSTATUS VBoxMRxSetFileInfoAtCleanup(IN OUT PRX_CONTEXT RxContext);
209NTSTATUS VBoxMRxQueryEaInfo(IN OUT PRX_CONTEXT RxContext);
210NTSTATUS VBoxMRxSetEaInfo(IN OUT struct _RX_CONTEXT * RxContext);
211NTSTATUS VBoxMRxQuerySdInfo(IN OUT PRX_CONTEXT RxContext);
212NTSTATUS VBoxMRxSetSdInfo(IN OUT struct _RX_CONTEXT * RxContext);
213NTSTATUS VBoxMRxQueryVolumeInfo(IN OUT PRX_CONTEXT RxContext);
214
215NTSTATUS VBoxMRxComputeNewBufferingState(IN OUT PMRX_SRV_OPEN pSrvOpen,
216 IN PVOID pMRxContext,
217 OUT ULONG *pNewBufferingState);
218
219NTSTATUS VBoxMRxRead(IN OUT PRX_CONTEXT RxContext);
220NTSTATUS VBoxMRxWrite(IN OUT PRX_CONTEXT RxContext);
221NTSTATUS VBoxMRxLocks(IN OUT PRX_CONTEXT RxContext);
222NTSTATUS VBoxMRxFsCtl(IN OUT PRX_CONTEXT RxContext);
223NTSTATUS VBoxMRxIoCtl(IN OUT PRX_CONTEXT RxContext);
224NTSTATUS VBoxMRxNotifyChangeDirectory(IN OUT PRX_CONTEXT RxContext);
225
226ULONG NTAPI VBoxMRxExtendStub(IN OUT struct _RX_CONTEXT * RxContext,
227 IN OUT PLARGE_INTEGER pNewFileSize,
228 OUT PLARGE_INTEGER pNewAllocationSize);
229NTSTATUS VBoxMRxCompleteBufferingStateChangeRequest(IN OUT PRX_CONTEXT RxContext,
230 IN OUT PMRX_SRV_OPEN SrvOpen,
231 IN PVOID pContext);
232
233NTSTATUS VBoxMRxCreateVNetRoot(IN OUT PMRX_CREATENETROOT_CONTEXT pContext);
234NTSTATUS VBoxMRxFinalizeVNetRoot(IN OUT PMRX_V_NET_ROOT pVirtualNetRoot,
235 IN PBOOLEAN ForceDisconnect);
236NTSTATUS VBoxMRxFinalizeNetRoot(IN OUT PMRX_NET_ROOT pNetRoot,
237 IN PBOOLEAN ForceDisconnect);
238NTSTATUS VBoxMRxUpdateNetRootState(IN PMRX_NET_ROOT pNetRoot);
239VOID VBoxMRxExtractNetRootName(IN PUNICODE_STRING FilePathName,
240 IN PMRX_SRV_CALL SrvCall,
241 OUT PUNICODE_STRING NetRootName,
242 OUT PUNICODE_STRING RestOfName OPTIONAL);
243
244NTSTATUS VBoxMRxCreateSrvCall(PMRX_SRV_CALL pSrvCall,
245 PMRX_SRVCALL_CALLBACK_CONTEXT pCallbackContext);
246NTSTATUS VBoxMRxSrvCallWinnerNotify(IN OUT PMRX_SRV_CALL pSrvCall,
247 IN BOOLEAN ThisMinirdrIsTheWinner,
248 IN OUT PVOID pSrvCallContext);
249NTSTATUS VBoxMRxFinalizeSrvCall(PMRX_SRV_CALL pSrvCall,
250 BOOLEAN Force);
251
252NTSTATUS VBoxMRxDevFcbXXXControlFile(IN OUT PRX_CONTEXT RxContext);
253/** @} */
254
255/** @name Support functions and helpers
256 * @{
257 */
258NTSTATUS vbsfNtDeleteConnection(IN PRX_CONTEXT RxContext,
259 OUT PBOOLEAN PostToFsp);
260NTSTATUS vbsfNtCreateConnection(IN PRX_CONTEXT RxContext,
261 OUT PBOOLEAN PostToFsp);
262NTSTATUS vbsfNtCloseFileHandle(PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension,
263 PMRX_VBOX_FOBX pVBoxFobx,
264 PVBSFNTFCBEXT pVBoxFcbx);
265NTSTATUS vbsfNtRemove(IN PRX_CONTEXT RxContext);
266NTSTATUS vbsfNtVBoxStatusToNt(int vrc);
267PVOID vbsfNtAllocNonPagedMem(ULONG ulSize);
268void vbsfNtFreeNonPagedMem(PVOID lpMem);
269NTSTATUS vbsfNtShflStringFromUnicodeAlloc(PSHFLSTRING *ppShflString, const WCHAR *pwc, uint16_t cb);
270#if defined(DEBUG) || defined(LOG_ENABLED)
271const char *vbsfNtMajorFunctionName(UCHAR MajorFunction, LONG MinorFunction);
272#endif
273
274void vbsfNtUpdateFcbSize(PFILE_OBJECT pFileObj, PMRX_FCB pFcb, PMRX_VBOX_FOBX pVBoxFobX,
275 LONGLONG cbFileNew, LONGLONG cbFileOld, LONGLONG cbAllocated);
276int vbsfNtQueryAndUpdateFcbSize(PMRX_VBOX_NETROOT_EXTENSION pNetRootX, PFILE_OBJECT pFileObj,
277 PMRX_VBOX_FOBX pVBoxFobX, PMRX_FCB pFcb, PVBSFNTFCBEXT pVBoxFcbX);
278
279/**
280 * Converts VBox (IPRT) file mode to NT file attributes.
281 *
282 * @returns NT file attributes
283 * @param fIprtMode IPRT file mode.
284 *
285 */
286DECLINLINE(uint32_t) VBoxToNTFileAttributes(uint32_t fIprtMode)
287{
288 AssertCompile((RTFS_DOS_READONLY >> RTFS_DOS_SHIFT) == FILE_ATTRIBUTE_READONLY);
289 AssertCompile((RTFS_DOS_HIDDEN >> RTFS_DOS_SHIFT) == FILE_ATTRIBUTE_HIDDEN);
290 AssertCompile((RTFS_DOS_SYSTEM >> RTFS_DOS_SHIFT) == FILE_ATTRIBUTE_SYSTEM);
291 AssertCompile((RTFS_DOS_DIRECTORY >> RTFS_DOS_SHIFT) == FILE_ATTRIBUTE_DIRECTORY);
292 AssertCompile((RTFS_DOS_ARCHIVED >> RTFS_DOS_SHIFT) == FILE_ATTRIBUTE_ARCHIVE);
293 AssertCompile((RTFS_DOS_NT_DEVICE >> RTFS_DOS_SHIFT) == FILE_ATTRIBUTE_DEVICE);
294 AssertCompile((RTFS_DOS_NT_NORMAL >> RTFS_DOS_SHIFT) == FILE_ATTRIBUTE_NORMAL);
295 AssertCompile((RTFS_DOS_NT_TEMPORARY >> RTFS_DOS_SHIFT) == FILE_ATTRIBUTE_TEMPORARY);
296 AssertCompile((RTFS_DOS_NT_SPARSE_FILE >> RTFS_DOS_SHIFT) == FILE_ATTRIBUTE_SPARSE_FILE);
297 AssertCompile((RTFS_DOS_NT_REPARSE_POINT >> RTFS_DOS_SHIFT) == FILE_ATTRIBUTE_REPARSE_POINT);
298 AssertCompile((RTFS_DOS_NT_COMPRESSED >> RTFS_DOS_SHIFT) == FILE_ATTRIBUTE_COMPRESSED);
299 AssertCompile((RTFS_DOS_NT_OFFLINE >> RTFS_DOS_SHIFT) == FILE_ATTRIBUTE_OFFLINE);
300 AssertCompile((RTFS_DOS_NT_NOT_CONTENT_INDEXED >> RTFS_DOS_SHIFT) == FILE_ATTRIBUTE_NOT_CONTENT_INDEXED);
301 AssertCompile((RTFS_DOS_NT_ENCRYPTED >> RTFS_DOS_SHIFT) == FILE_ATTRIBUTE_ENCRYPTED);
302
303 uint32_t fNtAttribs = (fIprtMode & (RTFS_DOS_MASK_NT & ~(RTFS_DOS_NT_OFFLINE | RTFS_DOS_NT_DEVICE | RTFS_DOS_NT_REPARSE_POINT)))
304 >> RTFS_DOS_SHIFT;
305 return fNtAttribs ? fNtAttribs : FILE_ATTRIBUTE_NORMAL;
306}
307
308/**
309 * Converts NT file attributes to VBox (IPRT) ones.
310 *
311 * @returns IPRT file mode
312 * @param fNtAttribs NT file attributes
313 */
314DECLINLINE(uint32_t) NTToVBoxFileAttributes(uint32_t fNtAttribs)
315{
316 uint32_t fIprtMode = (fNtAttribs << RTFS_DOS_SHIFT) & RTFS_DOS_MASK_NT;
317 fIprtMode &= ~(RTFS_DOS_NT_OFFLINE | RTFS_DOS_NT_DEVICE | RTFS_DOS_NT_REPARSE_POINT);
318 return fIprtMode ? fIprtMode : RTFS_DOS_NT_NORMAL;
319}
320
321/**
322 * Helper for converting VBox object info to NT basic file info.
323 */
324DECLINLINE(void) vbsfNtBasicInfoFromVBoxObjInfo(FILE_BASIC_INFORMATION *pNtBasicInfo, PCSHFLFSOBJINFO pVBoxInfo)
325{
326 pNtBasicInfo->CreationTime.QuadPart = RTTimeSpecGetNtTime(&pVBoxInfo->BirthTime);
327 pNtBasicInfo->LastAccessTime.QuadPart = RTTimeSpecGetNtTime(&pVBoxInfo->AccessTime);
328 pNtBasicInfo->LastWriteTime.QuadPart = RTTimeSpecGetNtTime(&pVBoxInfo->ModificationTime);
329 pNtBasicInfo->ChangeTime.QuadPart = RTTimeSpecGetNtTime(&pVBoxInfo->ChangeTime);
330 pNtBasicInfo->FileAttributes = VBoxToNTFileAttributes(pVBoxInfo->Attr.fMode);
331}
332
333
334/** @} */
335
336RT_C_DECLS_END
337
338#endif /* !GA_INCLUDED_SRC_WINNT_SharedFolders_driver_vbsf_h */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette