VirtualBox

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

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

winnt/vboxsf: Started cleaning up VBoxMRxSetFileInfo. bugref:9172

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.5 KB
Line 
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
52RT_C_DECLS_BEGIN
53
54/*
55 * Global data.
56 */
57extern 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 */
67typedef 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 */
90typedef 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 */
108typedef 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 */
148NTSTATUS VBoxMRxStart(IN OUT struct _RX_CONTEXT * RxContext,
149 IN OUT PRDBSS_DEVICE_OBJECT RxDeviceObject);
150NTSTATUS VBoxMRxStop(IN OUT struct _RX_CONTEXT * RxContext,
151 IN OUT PRDBSS_DEVICE_OBJECT RxDeviceObject);
152
153NTSTATUS VBoxMRxCreate(IN OUT PRX_CONTEXT RxContext);
154NTSTATUS VBoxMRxCollapseOpen(IN OUT PRX_CONTEXT RxContext);
155NTSTATUS VBoxMRxShouldTryToCollapseThisOpen(IN OUT PRX_CONTEXT RxContext);
156NTSTATUS VBoxMRxFlush(IN OUT PRX_CONTEXT RxContext);
157NTSTATUS VBoxMRxTruncate(IN OUT PRX_CONTEXT RxContext);
158NTSTATUS VBoxMRxCleanupFobx(IN OUT PRX_CONTEXT RxContext);
159NTSTATUS VBoxMRxCloseSrvOpen(IN OUT PRX_CONTEXT RxContext);
160NTSTATUS VBoxMRxDeallocateForFcb(IN OUT PMRX_FCB pFcb);
161NTSTATUS VBoxMRxDeallocateForFobx(IN OUT PMRX_FOBX pFobx);
162NTSTATUS VBoxMRxForceClosed(IN OUT PMRX_SRV_OPEN SrvOpen);
163
164NTSTATUS VBoxMRxQueryDirectory(IN OUT PRX_CONTEXT RxContext);
165NTSTATUS VBoxMRxQueryFileInfo(IN OUT PRX_CONTEXT RxContext);
166NTSTATUS VBoxMRxSetFileInfo(IN OUT PRX_CONTEXT RxContext);
167NTSTATUS VBoxMRxSetFileInfoAtCleanup(IN OUT PRX_CONTEXT RxContext);
168NTSTATUS VBoxMRxQueryEaInfo(IN OUT PRX_CONTEXT RxContext);
169NTSTATUS VBoxMRxSetEaInfo(IN OUT struct _RX_CONTEXT * RxContext);
170NTSTATUS VBoxMRxQuerySdInfo(IN OUT PRX_CONTEXT RxContext);
171NTSTATUS VBoxMRxSetSdInfo(IN OUT struct _RX_CONTEXT * RxContext);
172NTSTATUS VBoxMRxQueryVolumeInfo(IN OUT PRX_CONTEXT RxContext);
173
174NTSTATUS VBoxMRxComputeNewBufferingState(IN OUT PMRX_SRV_OPEN pSrvOpen,
175 IN PVOID pMRxContext,
176 OUT ULONG *pNewBufferingState);
177
178NTSTATUS VBoxMRxRead(IN OUT PRX_CONTEXT RxContext);
179NTSTATUS VBoxMRxWrite(IN OUT PRX_CONTEXT RxContext);
180NTSTATUS VBoxMRxLocks(IN OUT PRX_CONTEXT RxContext);
181NTSTATUS VBoxMRxFsCtl(IN OUT PRX_CONTEXT RxContext);
182NTSTATUS VBoxMRxIoCtl(IN OUT PRX_CONTEXT RxContext);
183NTSTATUS VBoxMRxNotifyChangeDirectory(IN OUT PRX_CONTEXT RxContext);
184
185ULONG NTAPI VBoxMRxExtendStub(IN OUT struct _RX_CONTEXT * RxContext,
186 IN OUT PLARGE_INTEGER pNewFileSize,
187 OUT PLARGE_INTEGER pNewAllocationSize);
188NTSTATUS VBoxMRxCompleteBufferingStateChangeRequest(IN OUT PRX_CONTEXT RxContext,
189 IN OUT PMRX_SRV_OPEN SrvOpen,
190 IN PVOID pContext);
191
192NTSTATUS VBoxMRxCreateVNetRoot(IN OUT PMRX_CREATENETROOT_CONTEXT pContext);
193NTSTATUS VBoxMRxFinalizeVNetRoot(IN OUT PMRX_V_NET_ROOT pVirtualNetRoot,
194 IN PBOOLEAN ForceDisconnect);
195NTSTATUS VBoxMRxFinalizeNetRoot(IN OUT PMRX_NET_ROOT pNetRoot,
196 IN PBOOLEAN ForceDisconnect);
197NTSTATUS VBoxMRxUpdateNetRootState(IN PMRX_NET_ROOT pNetRoot);
198VOID VBoxMRxExtractNetRootName(IN PUNICODE_STRING FilePathName,
199 IN PMRX_SRV_CALL SrvCall,
200 OUT PUNICODE_STRING NetRootName,
201 OUT PUNICODE_STRING RestOfName OPTIONAL);
202
203NTSTATUS VBoxMRxCreateSrvCall(PMRX_SRV_CALL pSrvCall,
204 PMRX_SRVCALL_CALLBACK_CONTEXT pCallbackContext);
205NTSTATUS VBoxMRxSrvCallWinnerNotify(IN OUT PMRX_SRV_CALL pSrvCall,
206 IN BOOLEAN ThisMinirdrIsTheWinner,
207 IN OUT PVOID pSrvCallContext);
208NTSTATUS VBoxMRxFinalizeSrvCall(PMRX_SRV_CALL pSrvCall,
209 BOOLEAN Force);
210
211NTSTATUS VBoxMRxDevFcbXXXControlFile(IN OUT PRX_CONTEXT RxContext);
212/** @} */
213
214/** @name Support functions and helpers
215 * @{
216 */
217NTSTATUS vbsfNtDeleteConnection(IN PRX_CONTEXT RxContext,
218 OUT PBOOLEAN PostToFsp);
219NTSTATUS vbsfNtCreateConnection(IN PRX_CONTEXT RxContext,
220 OUT PBOOLEAN PostToFsp);
221
222NTSTATUS vbsfNtSetEndOfFile(IN OUT struct _RX_CONTEXT * RxContext,
223 IN uint64_t cbNewFileSize);
224NTSTATUS vbsfNtRename(IN PRX_CONTEXT RxContext,
225 IN FILE_INFORMATION_CLASS FileInformationClass,
226 IN PVOID pBuffer,
227 IN ULONG BufferLength);
228NTSTATUS vbsfNtRemove(IN PRX_CONTEXT RxContext);
229
230void vbsfNtCopyInfoToLegacy(PMRX_VBOX_FOBX pVBoxFobx, PCSHFLFSOBJINFO pInfo);
231
232NTSTATUS vbsfNtVBoxStatusToNt(int vrc);
233PVOID vbsfNtAllocNonPagedMem(ULONG ulSize);
234void vbsfNtFreeNonPagedMem(PVOID lpMem);
235NTSTATUS vbsfNtShflStringFromUnicodeAlloc(PSHFLSTRING *ppShflString, const WCHAR *pwc, uint16_t cb);
236#if defined(DEBUG) || defined(LOG_ENABLED)
237const 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 */
247DECLINLINE(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 */
275DECLINLINE(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
284RT_C_DECLS_END
285
286#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