1 | /* $Id: path.cpp 78339 2019-04-28 11:38:32Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox Windows Guest Shared Folders - Path related routines.
|
---|
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 |
|
---|
19 | /*********************************************************************************************************************************
|
---|
20 | * Header Files *
|
---|
21 | *********************************************************************************************************************************/
|
---|
22 | #include "vbsf.h"
|
---|
23 | #include <iprt/err.h>
|
---|
24 |
|
---|
25 |
|
---|
26 | /*********************************************************************************************************************************
|
---|
27 | * Defined Constants And Macros *
|
---|
28 | *********************************************************************************************************************************/
|
---|
29 | static UNICODE_STRING g_UnicodeBackslash = { 2, 4, L"\\" };
|
---|
30 |
|
---|
31 |
|
---|
32 | static NTSTATUS vbsfProcessCreate(PRX_CONTEXT RxContext,
|
---|
33 | PUNICODE_STRING RemainingName,
|
---|
34 | SHFLFSOBJINFO *pInfo,
|
---|
35 | PVOID EaBuffer,
|
---|
36 | ULONG EaLength,
|
---|
37 | ULONG *pulCreateAction,
|
---|
38 | SHFLHANDLE *pHandle)
|
---|
39 | {
|
---|
40 | NTSTATUS Status = STATUS_SUCCESS;
|
---|
41 |
|
---|
42 | RxCaptureFcb;
|
---|
43 |
|
---|
44 | PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension = VBoxMRxGetNetRootExtension(capFcb->pNetRoot);
|
---|
45 |
|
---|
46 | int vrc = VINF_SUCCESS;
|
---|
47 |
|
---|
48 | /* Various boolean flags. */
|
---|
49 | struct
|
---|
50 | {
|
---|
51 | ULONG CreateDirectory :1;
|
---|
52 | ULONG OpenDirectory :1;
|
---|
53 | ULONG DirectoryFile :1;
|
---|
54 | ULONG NonDirectoryFile :1;
|
---|
55 | ULONG DeleteOnClose :1;
|
---|
56 | ULONG TemporaryFile :1;
|
---|
57 | ULONG SlashHack :1;
|
---|
58 | } bf;
|
---|
59 |
|
---|
60 | ACCESS_MASK DesiredAccess;
|
---|
61 | ULONG Options;
|
---|
62 | UCHAR FileAttributes;
|
---|
63 | ULONG ShareAccess;
|
---|
64 | ULONG CreateDisposition;
|
---|
65 | SHFLCREATEPARMS *pCreateParms = NULL;
|
---|
66 |
|
---|
67 | RT_NOREF(EaBuffer);
|
---|
68 |
|
---|
69 | if (EaLength)
|
---|
70 | {
|
---|
71 | Log(("VBOXSF: vbsfProcessCreate: Unsupported: extended attributes!\n"));
|
---|
72 | Status = STATUS_NOT_SUPPORTED; /// @todo STATUS_EAS_NOT_SUPPORTED ?
|
---|
73 | goto failure;
|
---|
74 | }
|
---|
75 |
|
---|
76 | if (BooleanFlagOn(capFcb->FcbState, FCB_STATE_PAGING_FILE))
|
---|
77 | {
|
---|
78 | Log(("VBOXSF: vbsfProcessCreate: Unsupported: paging file!\n"));
|
---|
79 | Status = STATUS_NOT_IMPLEMENTED;
|
---|
80 | goto failure;
|
---|
81 | }
|
---|
82 |
|
---|
83 | Log(("VBOXSF: vbsfProcessCreate: FileAttributes = 0x%08x\n",
|
---|
84 | RxContext->Create.NtCreateParameters.FileAttributes));
|
---|
85 | Log(("VBOXSF: vbsfProcessCreate: CreateOptions = 0x%08x\n",
|
---|
86 | RxContext->Create.NtCreateParameters.CreateOptions));
|
---|
87 |
|
---|
88 | RtlZeroMemory (&bf, sizeof (bf));
|
---|
89 |
|
---|
90 | DesiredAccess = RxContext->Create.NtCreateParameters.DesiredAccess;
|
---|
91 | Options = RxContext->Create.NtCreateParameters.CreateOptions & FILE_VALID_OPTION_FLAGS;
|
---|
92 | FileAttributes = (UCHAR)(RxContext->Create.NtCreateParameters.FileAttributes & ~FILE_ATTRIBUTE_NORMAL);
|
---|
93 | ShareAccess = RxContext->Create.NtCreateParameters.ShareAccess;
|
---|
94 |
|
---|
95 | /* We do not support opens by file ids. */
|
---|
96 | if (FlagOn(Options, FILE_OPEN_BY_FILE_ID))
|
---|
97 | {
|
---|
98 | Log(("VBOXSF: vbsfProcessCreate: Unsupported: file open by id!\n"));
|
---|
99 | Status = STATUS_NOT_IMPLEMENTED;
|
---|
100 | goto failure;
|
---|
101 | }
|
---|
102 |
|
---|
103 | /* Mask out unsupported attribute bits. */
|
---|
104 | FileAttributes &= (FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_ARCHIVE);
|
---|
105 |
|
---|
106 | bf.DirectoryFile = BooleanFlagOn(Options, FILE_DIRECTORY_FILE);
|
---|
107 | bf.NonDirectoryFile = BooleanFlagOn(Options, FILE_NON_DIRECTORY_FILE);
|
---|
108 | bf.DeleteOnClose = BooleanFlagOn(Options, FILE_DELETE_ON_CLOSE);
|
---|
109 | if (bf.DeleteOnClose)
|
---|
110 | Log(("VBOXSF: vbsfProcessCreate: Delete on close!\n"));
|
---|
111 |
|
---|
112 | CreateDisposition = RxContext->Create.NtCreateParameters.Disposition;
|
---|
113 |
|
---|
114 | bf.CreateDirectory = (bf.DirectoryFile && ((CreateDisposition == FILE_CREATE) || (CreateDisposition == FILE_OPEN_IF)));
|
---|
115 | bf.OpenDirectory = (bf.DirectoryFile && ((CreateDisposition == FILE_OPEN) || (CreateDisposition == FILE_OPEN_IF)));
|
---|
116 | bf.TemporaryFile = BooleanFlagOn(RxContext->Create.NtCreateParameters.FileAttributes, FILE_ATTRIBUTE_TEMPORARY);
|
---|
117 |
|
---|
118 | if (FlagOn(capFcb->FcbState, FCB_STATE_TEMPORARY))
|
---|
119 | bf.TemporaryFile = TRUE;
|
---|
120 |
|
---|
121 | bf.SlashHack = RxContext->CurrentIrpSp
|
---|
122 | && (RxContext->CurrentIrpSp->Parameters.Create.ShareAccess & VBOX_MJ_CREATE_SLASH_HACK);
|
---|
123 |
|
---|
124 | Log(("VBOXSF: vbsfProcessCreate: bf.TemporaryFile %d, bf.CreateDirectory %d, bf.DirectoryFile = %d, bf.SlashHack = %d\n",
|
---|
125 | bf.TemporaryFile, bf.CreateDirectory, bf.DirectoryFile, bf.SlashHack));
|
---|
126 |
|
---|
127 | /* Check consistency in specified flags. */
|
---|
128 | if (bf.TemporaryFile && bf.CreateDirectory) /* Directories with temporary flag set are not allowed! */
|
---|
129 | {
|
---|
130 | Log(("VBOXSF: vbsfProcessCreate: Not allowed: Temporary directories!\n"));
|
---|
131 | Status = STATUS_INVALID_PARAMETER;
|
---|
132 | goto failure;
|
---|
133 | }
|
---|
134 |
|
---|
135 | if (bf.DirectoryFile && bf.NonDirectoryFile)
|
---|
136 | {
|
---|
137 | /** @todo r=bird: Check if FILE_DIRECTORY_FILE+FILE_NON_DIRECTORY_FILE really is illegal in all combinations... */
|
---|
138 | Log(("VBOXSF: vbsfProcessCreate: Unsupported combination: dir && !dir\n"));
|
---|
139 | Status = STATUS_INVALID_PARAMETER;
|
---|
140 | goto failure;
|
---|
141 | }
|
---|
142 |
|
---|
143 | /* Initialize create parameters. */
|
---|
144 | pCreateParms = (SHFLCREATEPARMS *)vbsfNtAllocNonPagedMem(sizeof(SHFLCREATEPARMS));
|
---|
145 | if (!pCreateParms)
|
---|
146 | {
|
---|
147 | Status = STATUS_INSUFFICIENT_RESOURCES;
|
---|
148 | goto failure;
|
---|
149 | }
|
---|
150 |
|
---|
151 | RtlZeroMemory(pCreateParms, sizeof (SHFLCREATEPARMS));
|
---|
152 |
|
---|
153 | pCreateParms->Handle = SHFL_HANDLE_NIL;
|
---|
154 | pCreateParms->Result = SHFL_NO_RESULT;
|
---|
155 |
|
---|
156 | if (bf.DirectoryFile)
|
---|
157 | {
|
---|
158 | if (CreateDisposition != FILE_CREATE && CreateDisposition != FILE_OPEN && CreateDisposition != FILE_OPEN_IF)
|
---|
159 | {
|
---|
160 | Log(("VBOXSF: vbsfProcessCreate: Invalid disposition 0x%08X for directory!\n",
|
---|
161 | CreateDisposition));
|
---|
162 | Status = STATUS_INVALID_PARAMETER;
|
---|
163 | goto failure;
|
---|
164 | }
|
---|
165 |
|
---|
166 | pCreateParms->CreateFlags |= SHFL_CF_DIRECTORY;
|
---|
167 | }
|
---|
168 |
|
---|
169 | Log(("VBOXSF: vbsfProcessCreate: CreateDisposition = 0x%08X\n",
|
---|
170 | CreateDisposition));
|
---|
171 |
|
---|
172 | switch (CreateDisposition)
|
---|
173 | {
|
---|
174 | case FILE_SUPERSEDE:
|
---|
175 | pCreateParms->CreateFlags |= SHFL_CF_ACT_REPLACE_IF_EXISTS | SHFL_CF_ACT_CREATE_IF_NEW;
|
---|
176 | Log(("VBOXSF: vbsfProcessCreate: CreateFlags |= SHFL_CF_ACT_REPLACE_IF_EXISTS | SHFL_CF_ACT_CREATE_IF_NEW\n"));
|
---|
177 | break;
|
---|
178 |
|
---|
179 | case FILE_OPEN:
|
---|
180 | pCreateParms->CreateFlags |= SHFL_CF_ACT_OPEN_IF_EXISTS | SHFL_CF_ACT_FAIL_IF_NEW;
|
---|
181 | Log(("VBOXSF: vbsfProcessCreate: CreateFlags |= SHFL_CF_ACT_OPEN_IF_EXISTS | SHFL_CF_ACT_FAIL_IF_NEW\n"));
|
---|
182 | break;
|
---|
183 |
|
---|
184 | case FILE_CREATE:
|
---|
185 | pCreateParms->CreateFlags |= SHFL_CF_ACT_FAIL_IF_EXISTS | SHFL_CF_ACT_CREATE_IF_NEW;
|
---|
186 | Log(("VBOXSF: vbsfProcessCreate: CreateFlags |= SHFL_CF_ACT_FAIL_IF_EXISTS | SHFL_CF_ACT_CREATE_IF_NEW\n"));
|
---|
187 | break;
|
---|
188 |
|
---|
189 | case FILE_OPEN_IF:
|
---|
190 | pCreateParms->CreateFlags |= SHFL_CF_ACT_OPEN_IF_EXISTS | SHFL_CF_ACT_CREATE_IF_NEW;
|
---|
191 | Log(("VBOXSF: vbsfProcessCreate: CreateFlags |= SHFL_CF_ACT_OPEN_IF_EXISTS | SHFL_CF_ACT_CREATE_IF_NEW\n"));
|
---|
192 | break;
|
---|
193 |
|
---|
194 | case FILE_OVERWRITE:
|
---|
195 | pCreateParms->CreateFlags |= SHFL_CF_ACT_OVERWRITE_IF_EXISTS | SHFL_CF_ACT_FAIL_IF_NEW;
|
---|
196 | Log(("VBOXSF: vbsfProcessCreate: CreateFlags |= SHFL_CF_ACT_OVERWRITE_IF_EXISTS | SHFL_CF_ACT_FAIL_IF_NEW\n"));
|
---|
197 | break;
|
---|
198 |
|
---|
199 | case FILE_OVERWRITE_IF:
|
---|
200 | pCreateParms->CreateFlags |= SHFL_CF_ACT_OVERWRITE_IF_EXISTS | SHFL_CF_ACT_CREATE_IF_NEW;
|
---|
201 | Log(("VBOXSF: vbsfProcessCreate: CreateFlags |= SHFL_CF_ACT_OVERWRITE_IF_EXISTS | SHFL_CF_ACT_CREATE_IF_NEW\n"));
|
---|
202 | break;
|
---|
203 |
|
---|
204 | default:
|
---|
205 | Log(("VBOXSF: vbsfProcessCreate: Unexpected create disposition: 0x%08X\n",
|
---|
206 | CreateDisposition));
|
---|
207 | Status = STATUS_INVALID_PARAMETER;
|
---|
208 | goto failure;
|
---|
209 | }
|
---|
210 |
|
---|
211 | Log(("VBOXSF: vbsfProcessCreate: DesiredAccess = 0x%08X\n",
|
---|
212 | DesiredAccess));
|
---|
213 | Log(("VBOXSF: vbsfProcessCreate: ShareAccess = 0x%08X\n",
|
---|
214 | ShareAccess));
|
---|
215 |
|
---|
216 | if (DesiredAccess & FILE_READ_DATA)
|
---|
217 | {
|
---|
218 | Log(("VBOXSF: vbsfProcessCreate: FILE_READ_DATA\n"));
|
---|
219 | pCreateParms->CreateFlags |= SHFL_CF_ACCESS_READ;
|
---|
220 | }
|
---|
221 |
|
---|
222 | if (DesiredAccess & FILE_WRITE_DATA)
|
---|
223 | {
|
---|
224 | Log(("VBOXSF: vbsfProcessCreate: FILE_WRITE_DATA\n"));
|
---|
225 | /* FILE_WRITE_DATA means write access regardless of FILE_APPEND_DATA bit.
|
---|
226 | */
|
---|
227 | pCreateParms->CreateFlags |= SHFL_CF_ACCESS_WRITE;
|
---|
228 | }
|
---|
229 | else if (DesiredAccess & FILE_APPEND_DATA)
|
---|
230 | {
|
---|
231 | Log(("VBOXSF: vbsfProcessCreate: FILE_APPEND_DATA\n"));
|
---|
232 | /* FILE_APPEND_DATA without FILE_WRITE_DATA means append only mode.
|
---|
233 | *
|
---|
234 | * Both write and append access flags are required for shared folders,
|
---|
235 | * as on Windows FILE_APPEND_DATA implies write access.
|
---|
236 | */
|
---|
237 | pCreateParms->CreateFlags |= SHFL_CF_ACCESS_WRITE | SHFL_CF_ACCESS_APPEND;
|
---|
238 | }
|
---|
239 |
|
---|
240 | if (DesiredAccess & FILE_READ_ATTRIBUTES)
|
---|
241 | pCreateParms->CreateFlags |= SHFL_CF_ACCESS_ATTR_READ;
|
---|
242 | if (DesiredAccess & FILE_WRITE_ATTRIBUTES)
|
---|
243 | pCreateParms->CreateFlags |= SHFL_CF_ACCESS_ATTR_WRITE;
|
---|
244 |
|
---|
245 | if (ShareAccess & (FILE_SHARE_READ | FILE_SHARE_WRITE))
|
---|
246 | pCreateParms->CreateFlags |= SHFL_CF_ACCESS_DENYNONE;
|
---|
247 | else if (ShareAccess & FILE_SHARE_READ)
|
---|
248 | pCreateParms->CreateFlags |= SHFL_CF_ACCESS_DENYWRITE;
|
---|
249 | else if (ShareAccess & FILE_SHARE_WRITE)
|
---|
250 | pCreateParms->CreateFlags |= SHFL_CF_ACCESS_DENYREAD;
|
---|
251 | else pCreateParms->CreateFlags |= SHFL_CF_ACCESS_DENYALL;
|
---|
252 |
|
---|
253 | /* Set initial allocation size. */
|
---|
254 | pCreateParms->Info.cbObject = RxContext->Create.NtCreateParameters.AllocationSize.QuadPart;
|
---|
255 |
|
---|
256 | if (FileAttributes == 0)
|
---|
257 | FileAttributes = FILE_ATTRIBUTE_NORMAL;
|
---|
258 |
|
---|
259 | pCreateParms->Info.Attr.fMode = NTToVBoxFileAttributes(FileAttributes);
|
---|
260 |
|
---|
261 | {
|
---|
262 | PSHFLSTRING ParsedPath;
|
---|
263 | Log(("VBOXSF: vbsfProcessCreate: RemainingName->Length = %d\n", RemainingName->Length));
|
---|
264 |
|
---|
265 |
|
---|
266 | if (!bf.SlashHack)
|
---|
267 | {
|
---|
268 | Status = vbsfNtShflStringFromUnicodeAlloc(&ParsedPath, RemainingName->Buffer, RemainingName->Length);
|
---|
269 | if (Status != STATUS_SUCCESS)
|
---|
270 | goto failure;
|
---|
271 | }
|
---|
272 | else
|
---|
273 | {
|
---|
274 | /* Add back the slash we had to hide from RDBSS. */
|
---|
275 | Status = vbsfNtShflStringFromUnicodeAlloc(&ParsedPath, NULL, RemainingName->Length + sizeof(RTUTF16));
|
---|
276 | if (Status != STATUS_SUCCESS)
|
---|
277 | goto failure;
|
---|
278 | memcpy(ParsedPath->String.utf16, RemainingName->Buffer, RemainingName->Length);
|
---|
279 | ParsedPath->String.utf16[RemainingName->Length / sizeof(RTUTF16)] = '\\';
|
---|
280 | ParsedPath->String.utf16[RemainingName->Length / sizeof(RTUTF16) + 1] = '\0';
|
---|
281 | ParsedPath->u16Length = RemainingName->Length + sizeof(RTUTF16);
|
---|
282 | }
|
---|
283 |
|
---|
284 | Log(("VBOXSF: ParsedPath: %.*ls\n",
|
---|
285 | ParsedPath->u16Length / sizeof(WCHAR), ParsedPath->String.ucs2));
|
---|
286 |
|
---|
287 | /* Call host. */
|
---|
288 | Log(("VBOXSF: vbsfProcessCreate: VbglR0SfCreate called.\n"));
|
---|
289 | vrc = VbglR0SfCreate(&g_SfClient, &pNetRootExtension->map, ParsedPath, pCreateParms);
|
---|
290 |
|
---|
291 | vbsfNtFreeNonPagedMem(ParsedPath);
|
---|
292 | }
|
---|
293 |
|
---|
294 | Log(("VBOXSF: vbsfProcessCreate: VbglR0SfCreate returns vrc = %Rrc, Result = 0x%x\n",
|
---|
295 | vrc, pCreateParms->Result));
|
---|
296 |
|
---|
297 | if (RT_FAILURE(vrc))
|
---|
298 | {
|
---|
299 | /* Map some VBoxRC to STATUS codes expected by the system. */
|
---|
300 | switch (vrc)
|
---|
301 | {
|
---|
302 | case VERR_ALREADY_EXISTS:
|
---|
303 | {
|
---|
304 | *pulCreateAction = FILE_EXISTS;
|
---|
305 | Status = STATUS_OBJECT_NAME_COLLISION;
|
---|
306 | goto failure;
|
---|
307 | }
|
---|
308 |
|
---|
309 | /* On POSIX systems, the "mkdir" command returns VERR_FILE_NOT_FOUND when
|
---|
310 | doing a recursive directory create. Handle this case.
|
---|
311 |
|
---|
312 | bird: We end up here on windows systems too if opening a dir that doesn't
|
---|
313 | exists. Thus, I've changed the SHFL_PATH_NOT_FOUND to SHFL_FILE_NOT_FOUND
|
---|
314 | so that FsPerf is happy. */
|
---|
315 | case VERR_FILE_NOT_FOUND: /** @todo r=bird: this is a host bug, isn't it? */
|
---|
316 | {
|
---|
317 | pCreateParms->Result = SHFL_FILE_NOT_FOUND;
|
---|
318 | break;
|
---|
319 | }
|
---|
320 |
|
---|
321 | default:
|
---|
322 | {
|
---|
323 | *pulCreateAction = FILE_DOES_NOT_EXIST;
|
---|
324 | Status = vbsfNtVBoxStatusToNt(vrc);
|
---|
325 | goto failure;
|
---|
326 | }
|
---|
327 | }
|
---|
328 | }
|
---|
329 |
|
---|
330 | /*
|
---|
331 | * The request succeeded. Analyze host response,
|
---|
332 | */
|
---|
333 | switch (pCreateParms->Result)
|
---|
334 | {
|
---|
335 | case SHFL_PATH_NOT_FOUND:
|
---|
336 | {
|
---|
337 | /* Path to the object does not exist. */
|
---|
338 | Log(("VBOXSF: vbsfProcessCreate: Path not found\n"));
|
---|
339 | *pulCreateAction = FILE_DOES_NOT_EXIST;
|
---|
340 | Status = STATUS_OBJECT_PATH_NOT_FOUND;
|
---|
341 | goto failure;
|
---|
342 | }
|
---|
343 |
|
---|
344 | case SHFL_FILE_NOT_FOUND:
|
---|
345 | {
|
---|
346 | Log(("VBOXSF: vbsfProcessCreate: File not found\n"));
|
---|
347 | *pulCreateAction = FILE_DOES_NOT_EXIST;
|
---|
348 | if (pCreateParms->Handle == SHFL_HANDLE_NIL)
|
---|
349 | {
|
---|
350 | Status = STATUS_OBJECT_NAME_NOT_FOUND;
|
---|
351 | goto failure;
|
---|
352 | }
|
---|
353 |
|
---|
354 | Log(("VBOXSF: vbsfProcessCreate: File not found but have a handle!\n"));
|
---|
355 | Status = STATUS_UNSUCCESSFUL;
|
---|
356 | goto failure;
|
---|
357 | }
|
---|
358 |
|
---|
359 | case SHFL_FILE_EXISTS:
|
---|
360 | {
|
---|
361 | Log(("VBOXSF: vbsfProcessCreate: File exists, Handle = 0x%RX64\n",
|
---|
362 | pCreateParms->Handle));
|
---|
363 | if (pCreateParms->Handle == SHFL_HANDLE_NIL)
|
---|
364 | {
|
---|
365 | *pulCreateAction = FILE_EXISTS;
|
---|
366 | if (CreateDisposition == FILE_CREATE)
|
---|
367 | {
|
---|
368 | /* File was not opened because we requested a create. */
|
---|
369 | Status = STATUS_OBJECT_NAME_COLLISION;
|
---|
370 | goto failure;
|
---|
371 | }
|
---|
372 |
|
---|
373 | /* Actually we should not go here, unless we have no rights to open the object. */
|
---|
374 | Log(("VBOXSF: vbsfProcessCreate: Existing file was not opened!\n"));
|
---|
375 | Status = STATUS_ACCESS_DENIED;
|
---|
376 | goto failure;
|
---|
377 | }
|
---|
378 |
|
---|
379 | *pulCreateAction = FILE_OPENED;
|
---|
380 |
|
---|
381 | /* Existing file was opened. Go check flags and create FCB. */
|
---|
382 | break;
|
---|
383 | }
|
---|
384 |
|
---|
385 | case SHFL_FILE_CREATED:
|
---|
386 | {
|
---|
387 | /* A new file was created. */
|
---|
388 | Assert(pCreateParms->Handle != SHFL_HANDLE_NIL);
|
---|
389 |
|
---|
390 | *pulCreateAction = FILE_CREATED;
|
---|
391 |
|
---|
392 | /* Go check flags and create FCB. */
|
---|
393 | break;
|
---|
394 | }
|
---|
395 |
|
---|
396 | case SHFL_FILE_REPLACED:
|
---|
397 | {
|
---|
398 | /* Existing file was replaced or overwriting. */
|
---|
399 | Assert(pCreateParms->Handle != SHFL_HANDLE_NIL);
|
---|
400 |
|
---|
401 | if (CreateDisposition == FILE_SUPERSEDE)
|
---|
402 | *pulCreateAction = FILE_SUPERSEDED;
|
---|
403 | else
|
---|
404 | *pulCreateAction = FILE_OVERWRITTEN;
|
---|
405 | /* Go check flags and create FCB. */
|
---|
406 | break;
|
---|
407 | }
|
---|
408 |
|
---|
409 | default:
|
---|
410 | {
|
---|
411 | Log(("VBOXSF: vbsfProcessCreate: Invalid CreateResult from host (0x%08X)\n",
|
---|
412 | pCreateParms->Result));
|
---|
413 | *pulCreateAction = FILE_DOES_NOT_EXIST;
|
---|
414 | Status = STATUS_OBJECT_PATH_NOT_FOUND;
|
---|
415 | goto failure;
|
---|
416 | }
|
---|
417 | }
|
---|
418 |
|
---|
419 | /* Check flags. */
|
---|
420 | if (bf.NonDirectoryFile && FlagOn(pCreateParms->Info.Attr.fMode, RTFS_DOS_DIRECTORY))
|
---|
421 | {
|
---|
422 | /* Caller wanted only a file, but the object is a directory. */
|
---|
423 | Log(("VBOXSF: vbsfProcessCreate: File is a directory!\n"));
|
---|
424 | Status = STATUS_FILE_IS_A_DIRECTORY;
|
---|
425 | goto failure;
|
---|
426 | }
|
---|
427 |
|
---|
428 | if (bf.DirectoryFile && !FlagOn(pCreateParms->Info.Attr.fMode, RTFS_DOS_DIRECTORY))
|
---|
429 | {
|
---|
430 | /* Caller wanted only a directory, but the object is not a directory. */
|
---|
431 | Log(("VBOXSF: vbsfProcessCreate: File is not a directory!\n"));
|
---|
432 | Status = STATUS_NOT_A_DIRECTORY;
|
---|
433 | goto failure;
|
---|
434 | }
|
---|
435 |
|
---|
436 | *pHandle = pCreateParms->Handle;
|
---|
437 | *pInfo = pCreateParms->Info;
|
---|
438 |
|
---|
439 | vbsfNtFreeNonPagedMem(pCreateParms);
|
---|
440 |
|
---|
441 | return Status;
|
---|
442 |
|
---|
443 | failure:
|
---|
444 |
|
---|
445 | Log(("VBOXSF: vbsfProcessCreate: Returned with status = 0x%08X\n",
|
---|
446 | Status));
|
---|
447 |
|
---|
448 | if (pCreateParms && pCreateParms->Handle != SHFL_HANDLE_NIL)
|
---|
449 | {
|
---|
450 | VbglR0SfClose(&g_SfClient, &pNetRootExtension->map, pCreateParms->Handle);
|
---|
451 | *pHandle = SHFL_HANDLE_NIL;
|
---|
452 | }
|
---|
453 |
|
---|
454 | if (pCreateParms)
|
---|
455 | vbsfNtFreeNonPagedMem(pCreateParms);
|
---|
456 |
|
---|
457 | return Status;
|
---|
458 | }
|
---|
459 |
|
---|
460 | NTSTATUS VBoxMRxCreate(IN OUT PRX_CONTEXT RxContext)
|
---|
461 | {
|
---|
462 | NTSTATUS Status = STATUS_SUCCESS;
|
---|
463 |
|
---|
464 | RxCaptureFcb;
|
---|
465 | RxCaptureFobx;
|
---|
466 |
|
---|
467 | PMRX_NET_ROOT pNetRoot = capFcb->pNetRoot;
|
---|
468 | PMRX_SRV_OPEN SrvOpen = RxContext->pRelevantSrvOpen;
|
---|
469 | PUNICODE_STRING RemainingName = GET_ALREADY_PREFIXED_NAME_FROM_CONTEXT(RxContext);
|
---|
470 |
|
---|
471 | SHFLFSOBJINFO Info = {0};
|
---|
472 |
|
---|
473 | ULONG CreateAction = FILE_CREATED;
|
---|
474 | SHFLHANDLE Handle = SHFL_HANDLE_NIL;
|
---|
475 | PMRX_VBOX_FOBX pVBoxFobx;
|
---|
476 |
|
---|
477 | RT_NOREF(__C_Fobx); /* RxCaptureFobx */
|
---|
478 |
|
---|
479 | Log(("VBOXSF: MRxCreate: name ptr %p length=%d, SrvOpen->Flags 0x%08X\n",
|
---|
480 | RemainingName, RemainingName->Length, SrvOpen->Flags));
|
---|
481 |
|
---|
482 | /* Disable FastIO. It causes a verifier bugcheck. */
|
---|
483 | #ifdef SRVOPEN_FLAG_DONTUSE_READ_CACHING
|
---|
484 | SetFlag(SrvOpen->Flags, SRVOPEN_FLAG_DONTUSE_READ_CACHING | SRVOPEN_FLAG_DONTUSE_WRITE_CACHING);
|
---|
485 | #else
|
---|
486 | SetFlag(SrvOpen->Flags, SRVOPEN_FLAG_DONTUSE_READ_CACHEING | SRVOPEN_FLAG_DONTUSE_WRITE_CACHEING);
|
---|
487 | #endif
|
---|
488 |
|
---|
489 | if (RemainingName->Length)
|
---|
490 | {
|
---|
491 | Log(("VBOXSF: MRxCreate: Attempt to open %.*ls\n",
|
---|
492 | RemainingName->Length/sizeof(WCHAR), RemainingName->Buffer));
|
---|
493 | }
|
---|
494 | else
|
---|
495 | {
|
---|
496 | if (FlagOn(RxContext->Create.Flags, RX_CONTEXT_CREATE_FLAG_STRIPPED_TRAILING_BACKSLASH))
|
---|
497 | {
|
---|
498 | Log(("VBOXSF: MRxCreate: Empty name -> Only backslash used\n"));
|
---|
499 | RemainingName = &g_UnicodeBackslash;
|
---|
500 | }
|
---|
501 | }
|
---|
502 |
|
---|
503 | if ( pNetRoot->Type != NET_ROOT_WILD
|
---|
504 | && pNetRoot->Type != NET_ROOT_DISK)
|
---|
505 | {
|
---|
506 | Log(("VBOXSF: MRxCreate: netroot type %d not supported\n",
|
---|
507 | pNetRoot->Type));
|
---|
508 | Status = STATUS_NOT_IMPLEMENTED;
|
---|
509 | goto Exit;
|
---|
510 | }
|
---|
511 |
|
---|
512 | Status = vbsfProcessCreate(RxContext,
|
---|
513 | RemainingName,
|
---|
514 | &Info,
|
---|
515 | RxContext->Create.EaBuffer,
|
---|
516 | RxContext->Create.EaLength,
|
---|
517 | &CreateAction,
|
---|
518 | &Handle);
|
---|
519 |
|
---|
520 | if (Status != STATUS_SUCCESS)
|
---|
521 | {
|
---|
522 | Log(("VBOXSF: MRxCreate: vbsfProcessCreate failed 0x%08X\n",
|
---|
523 | Status));
|
---|
524 | goto Exit;
|
---|
525 | }
|
---|
526 |
|
---|
527 | Log(("VBOXSF: MRxCreate: EOF is 0x%RX64 AllocSize is 0x%RX64\n",
|
---|
528 | Info.cbObject, Info.cbAllocated));
|
---|
529 |
|
---|
530 | RxContext->pFobx = RxCreateNetFobx(RxContext, SrvOpen);
|
---|
531 | if (!RxContext->pFobx)
|
---|
532 | {
|
---|
533 | Log(("VBOXSF: MRxCreate: RxCreateNetFobx failed\n"));
|
---|
534 | Status = STATUS_INSUFFICIENT_RESOURCES;
|
---|
535 | goto Exit;
|
---|
536 | }
|
---|
537 |
|
---|
538 | Log(("VBOXSF: MRxCreate: CreateAction = 0x%08X\n",
|
---|
539 | CreateAction));
|
---|
540 |
|
---|
541 | RxContext->Create.ReturnedCreateInformation = CreateAction;
|
---|
542 |
|
---|
543 | /* Initialize the FCB if this is the first open.
|
---|
544 | Note! The RxFinishFcbInitialization call expects node types as the 2nd parameter, but is for
|
---|
545 | some reason given enum RX_FILE_TYPE as type. */
|
---|
546 | if (capFcb->OpenCount == 0)
|
---|
547 | {
|
---|
548 | FCB_INIT_PACKET InitPacket;
|
---|
549 | FILE_NETWORK_OPEN_INFORMATION Data;
|
---|
550 | ULONG NumberOfLinks = 0; /** @todo ?? */
|
---|
551 | Data.CreationTime.QuadPart = RTTimeSpecGetNtTime(&Info.BirthTime);
|
---|
552 | Data.LastAccessTime.QuadPart = RTTimeSpecGetNtTime(&Info.AccessTime);
|
---|
553 | Data.LastWriteTime.QuadPart = RTTimeSpecGetNtTime(&Info.ModificationTime);
|
---|
554 | Data.ChangeTime.QuadPart = RTTimeSpecGetNtTime(&Info.ChangeTime);
|
---|
555 | Data.AllocationSize.QuadPart = Info.cbAllocated;
|
---|
556 | Data.EndOfFile.QuadPart = Info.cbObject;
|
---|
557 | Data.FileAttributes = VBoxToNTFileAttributes(Info.Attr.fMode);
|
---|
558 | RxFormInitPacket(InitPacket,
|
---|
559 | &Data.FileAttributes,
|
---|
560 | &NumberOfLinks,
|
---|
561 | &Data.CreationTime,
|
---|
562 | &Data.LastAccessTime,
|
---|
563 | &Data.LastWriteTime,
|
---|
564 | &Data.ChangeTime,
|
---|
565 | &Data.AllocationSize,
|
---|
566 | &Data.EndOfFile,
|
---|
567 | &Data.EndOfFile);
|
---|
568 | if (Info.Attr.fMode & RTFS_DOS_DIRECTORY)
|
---|
569 | RxFinishFcbInitialization(capFcb, (RX_FILE_TYPE)RDBSS_NTC_STORAGE_TYPE_DIRECTORY, &InitPacket);
|
---|
570 | else
|
---|
571 | RxFinishFcbInitialization(capFcb, (RX_FILE_TYPE)RDBSS_NTC_STORAGE_TYPE_FILE, &InitPacket);
|
---|
572 | }
|
---|
573 |
|
---|
574 | SrvOpen->BufferingFlags = 0;
|
---|
575 |
|
---|
576 | RxContext->pFobx->OffsetOfNextEaToReturn = 1;
|
---|
577 |
|
---|
578 | pVBoxFobx = VBoxMRxGetFileObjectExtension(RxContext->pFobx);
|
---|
579 |
|
---|
580 | Log(("VBOXSF: MRxCreate: VBoxFobx = %p\n",
|
---|
581 | pVBoxFobx));
|
---|
582 |
|
---|
583 | if (!pVBoxFobx)
|
---|
584 | {
|
---|
585 | Log(("VBOXSF: MRxCreate: no VBoxFobx!\n"));
|
---|
586 | AssertFailed();
|
---|
587 | Status = STATUS_INSUFFICIENT_RESOURCES;
|
---|
588 | goto Exit;
|
---|
589 | }
|
---|
590 |
|
---|
591 | pVBoxFobx->hFile = Handle;
|
---|
592 | pVBoxFobx->pSrvCall = RxContext->Create.pSrvCall;
|
---|
593 | pVBoxFobx->Info = Info;
|
---|
594 | vbsfNtCopyInfoToLegacy(pVBoxFobx, &Info);
|
---|
595 | Log(("VBOXSF: MRxCreate: FileBasicInformation: CreationTime %RX64\n", pVBoxFobx->FileBasicInfo.CreationTime.QuadPart));
|
---|
596 | Log(("VBOXSF: MRxCreate: FileBasicInformation: LastAccessTime %RX64\n", pVBoxFobx->FileBasicInfo.LastAccessTime.QuadPart));
|
---|
597 | Log(("VBOXSF: MRxCreate: FileBasicInformation: LastWriteTime %RX64\n", pVBoxFobx->FileBasicInfo.LastWriteTime.QuadPart));
|
---|
598 | Log(("VBOXSF: MRxCreate: FileBasicInformation: ChangeTime %RX64\n", pVBoxFobx->FileBasicInfo.ChangeTime.QuadPart));
|
---|
599 | Log(("VBOXSF: MRxCreate: FileBasicInformation: FileAttributes %RX32\n", pVBoxFobx->FileBasicInfo.FileAttributes));
|
---|
600 | if (!(Info.Attr.fMode & RTFS_DOS_DIRECTORY))
|
---|
601 | Log(("VBOXSF: MRxCreate: AllocationSize = %#RX64, EndOfFile = %#RX64\n",
|
---|
602 | Info.cbAllocated, Info.cbObject));
|
---|
603 |
|
---|
604 | if (!RxIsFcbAcquiredExclusive(capFcb))
|
---|
605 | {
|
---|
606 | RxAcquireExclusiveFcbResourceInMRx(capFcb);
|
---|
607 | }
|
---|
608 |
|
---|
609 | Log(("VBOXSF: MRxCreate: NetRoot is %p, Fcb is %p, SrvOpen is %p, Fobx is %p\n",
|
---|
610 | pNetRoot, capFcb, SrvOpen, RxContext->pFobx));
|
---|
611 | Log(("VBOXSF: MRxCreate: return 0x%08X\n",
|
---|
612 | Status));
|
---|
613 |
|
---|
614 | Exit:
|
---|
615 | return Status;
|
---|
616 | }
|
---|
617 |
|
---|
618 | NTSTATUS VBoxMRxComputeNewBufferingState(IN OUT PMRX_SRV_OPEN pMRxSrvOpen, IN PVOID pMRxContext, OUT PULONG pNewBufferingState)
|
---|
619 | {
|
---|
620 | RT_NOREF(pMRxSrvOpen, pMRxContext, pNewBufferingState);
|
---|
621 | Log(("VBOXSF: MRxComputeNewBufferingState\n"));
|
---|
622 | return STATUS_NOT_SUPPORTED;
|
---|
623 | }
|
---|
624 |
|
---|
625 | NTSTATUS VBoxMRxDeallocateForFcb(IN OUT PMRX_FCB pFcb)
|
---|
626 | {
|
---|
627 | RT_NOREF(pFcb);
|
---|
628 | Log(("VBOXSF: MRxDeallocateForFcb\n"));
|
---|
629 | return STATUS_SUCCESS;
|
---|
630 | }
|
---|
631 |
|
---|
632 | NTSTATUS VBoxMRxDeallocateForFobx(IN OUT PMRX_FOBX pFobx)
|
---|
633 | {
|
---|
634 | RT_NOREF(pFobx);
|
---|
635 | Log(("VBOXSF: MRxDeallocateForFobx\n"));
|
---|
636 | return STATUS_SUCCESS;
|
---|
637 | }
|
---|
638 |
|
---|
639 | NTSTATUS VBoxMRxTruncate(IN PRX_CONTEXT RxContext)
|
---|
640 | {
|
---|
641 | RT_NOREF(RxContext);
|
---|
642 | Log(("VBOXSF: MRxTruncate\n"));
|
---|
643 | return STATUS_NOT_IMPLEMENTED;
|
---|
644 | }
|
---|
645 |
|
---|
646 | NTSTATUS VBoxMRxCleanupFobx(IN PRX_CONTEXT RxContext)
|
---|
647 | {
|
---|
648 | PMRX_VBOX_FOBX pVBoxFobx = VBoxMRxGetFileObjectExtension(RxContext->pFobx);
|
---|
649 |
|
---|
650 | Log(("VBOXSF: MRxCleanupFobx: pVBoxFobx = %p, Handle = 0x%RX64\n", pVBoxFobx, pVBoxFobx? pVBoxFobx->hFile: 0));
|
---|
651 |
|
---|
652 | if (!pVBoxFobx)
|
---|
653 | return STATUS_INVALID_PARAMETER;
|
---|
654 |
|
---|
655 | return STATUS_SUCCESS;
|
---|
656 | }
|
---|
657 |
|
---|
658 | NTSTATUS VBoxMRxForceClosed(IN PMRX_SRV_OPEN pSrvOpen)
|
---|
659 | {
|
---|
660 | RT_NOREF(pSrvOpen);
|
---|
661 | Log(("VBOXSF: MRxForceClosed\n"));
|
---|
662 | return STATUS_NOT_IMPLEMENTED;
|
---|
663 | }
|
---|
664 |
|
---|
665 | static NTSTATUS vbsfSetFileInfoOnClose(PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension,
|
---|
666 | PMRX_VBOX_FOBX pVBoxFobx,
|
---|
667 | PFILE_BASIC_INFORMATION pInfo,
|
---|
668 | BYTE SetAttrFlags)
|
---|
669 | {
|
---|
670 | NTSTATUS Status = STATUS_SUCCESS;
|
---|
671 |
|
---|
672 | int vrc;
|
---|
673 | PSHFLFSOBJINFO pSHFLFileInfo;
|
---|
674 |
|
---|
675 | uint8_t *pHGCMBuffer = NULL;
|
---|
676 | uint32_t cbBuffer = 0;
|
---|
677 |
|
---|
678 | Log(("VBOXSF: vbsfSetFileInfoOnClose: SetAttrFlags 0x%02X\n", SetAttrFlags));
|
---|
679 | Log(("VBOXSF: vbsfSetFileInfoOnClose: FileBasicInformation: CreationTime %RX64\n", pInfo->CreationTime.QuadPart));
|
---|
680 | Log(("VBOXSF: vbsfSetFileInfoOnClose: FileBasicInformation: LastAccessTime %RX64\n", pInfo->LastAccessTime.QuadPart));
|
---|
681 | Log(("VBOXSF: vbsfSetFileInfoOnClose: FileBasicInformation: LastWriteTime %RX64\n", pInfo->LastWriteTime.QuadPart));
|
---|
682 | Log(("VBOXSF: vbsfSetFileInfoOnClose: FileBasicInformation: ChangeTime %RX64\n", pInfo->ChangeTime.QuadPart));
|
---|
683 | Log(("VBOXSF: vbsfSetFileInfoOnClose: FileBasicInformation: FileAttributes %RX32\n", pInfo->FileAttributes));
|
---|
684 |
|
---|
685 | if (SetAttrFlags == 0)
|
---|
686 | {
|
---|
687 | Log(("VBOXSF: vbsfSetFileInfo: nothing to set\n"));
|
---|
688 | return STATUS_SUCCESS;
|
---|
689 | }
|
---|
690 |
|
---|
691 | cbBuffer = sizeof(SHFLFSOBJINFO);
|
---|
692 | pHGCMBuffer = (uint8_t *)vbsfNtAllocNonPagedMem(cbBuffer);
|
---|
693 | if (!pHGCMBuffer)
|
---|
694 | {
|
---|
695 | AssertFailed();
|
---|
696 | return STATUS_INSUFFICIENT_RESOURCES;
|
---|
697 | }
|
---|
698 | RtlZeroMemory(pHGCMBuffer, cbBuffer);
|
---|
699 | pSHFLFileInfo = (PSHFLFSOBJINFO)pHGCMBuffer;
|
---|
700 |
|
---|
701 | /* The properties, that need to be changed, are set to something other than zero */
|
---|
702 | if (pInfo->CreationTime.QuadPart && (SetAttrFlags & VBOX_FOBX_F_INFO_CREATION_TIME) != 0)
|
---|
703 | RTTimeSpecSetNtTime(&pSHFLFileInfo->BirthTime, pInfo->CreationTime.QuadPart);
|
---|
704 | if (pInfo->LastAccessTime.QuadPart && (SetAttrFlags & VBOX_FOBX_F_INFO_LASTACCESS_TIME) != 0)
|
---|
705 | RTTimeSpecSetNtTime(&pSHFLFileInfo->AccessTime, pInfo->LastAccessTime.QuadPart);
|
---|
706 | if (pInfo->LastWriteTime.QuadPart && (SetAttrFlags & VBOX_FOBX_F_INFO_LASTWRITE_TIME) != 0)
|
---|
707 | RTTimeSpecSetNtTime(&pSHFLFileInfo->ModificationTime, pInfo->LastWriteTime.QuadPart);
|
---|
708 | if (pInfo->ChangeTime.QuadPart && (SetAttrFlags & VBOX_FOBX_F_INFO_CHANGE_TIME) != 0)
|
---|
709 | RTTimeSpecSetNtTime(&pSHFLFileInfo->ChangeTime, pInfo->ChangeTime.QuadPart);
|
---|
710 | if (pInfo->FileAttributes && (SetAttrFlags & VBOX_FOBX_F_INFO_ATTRIBUTES) != 0) /// @todo r=bird: never ever set.
|
---|
711 | pSHFLFileInfo->Attr.fMode = NTToVBoxFileAttributes(pInfo->FileAttributes);
|
---|
712 |
|
---|
713 | vrc = VbglR0SfFsInfo(&g_SfClient, &pNetRootExtension->map, pVBoxFobx->hFile,
|
---|
714 | SHFL_INFO_SET | SHFL_INFO_FILE, &cbBuffer, (PSHFLDIRINFO)pSHFLFileInfo);
|
---|
715 |
|
---|
716 | if (vrc != VINF_SUCCESS)
|
---|
717 | Status = vbsfNtVBoxStatusToNt(vrc);
|
---|
718 |
|
---|
719 | if (pHGCMBuffer)
|
---|
720 | vbsfNtFreeNonPagedMem(pHGCMBuffer);
|
---|
721 |
|
---|
722 | Log(("VBOXSF: vbsfSetFileInfo: Returned 0x%08X\n", Status));
|
---|
723 | return Status;
|
---|
724 | }
|
---|
725 |
|
---|
726 | /**
|
---|
727 | * Closes an opened file handle of a MRX_VBOX_FOBX.
|
---|
728 | *
|
---|
729 | * Updates file attributes if necessary.
|
---|
730 | *
|
---|
731 | * Used by VBoxMRxCloseSrvOpen, vbsfNtRemove and vbsfNtRename.
|
---|
732 | */
|
---|
733 | NTSTATUS vbsfNtCloseFileHandle(PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension,
|
---|
734 | PMRX_VBOX_FOBX pVBoxFobx)
|
---|
735 | {
|
---|
736 | NTSTATUS Status = STATUS_SUCCESS;
|
---|
737 |
|
---|
738 | int vrc;
|
---|
739 |
|
---|
740 | if (pVBoxFobx->hFile == SHFL_HANDLE_NIL)
|
---|
741 | {
|
---|
742 | Log(("VBOXSF: vbsfCloseFileHandle: SHFL_HANDLE_NIL\n"));
|
---|
743 | return STATUS_SUCCESS;
|
---|
744 | }
|
---|
745 |
|
---|
746 | Log(("VBOXSF: vbsfCloseFileHandle: 0x%RX64, on close info 0x%02X\n",
|
---|
747 | pVBoxFobx->hFile, pVBoxFobx->SetFileInfoOnCloseFlags));
|
---|
748 |
|
---|
749 | if (pVBoxFobx->SetFileInfoOnCloseFlags)
|
---|
750 | {
|
---|
751 | /* If the file timestamps were set by the user, then update them before closing the handle,
|
---|
752 | * to cancel any effect of the file read/write operations on the host.
|
---|
753 | */
|
---|
754 | Status = vbsfSetFileInfoOnClose(pNetRootExtension,
|
---|
755 | pVBoxFobx,
|
---|
756 | &pVBoxFobx->FileBasicInfo,
|
---|
757 | pVBoxFobx->SetFileInfoOnCloseFlags);
|
---|
758 | }
|
---|
759 |
|
---|
760 | vrc = VbglR0SfClose(&g_SfClient,
|
---|
761 | &pNetRootExtension->map,
|
---|
762 | pVBoxFobx->hFile);
|
---|
763 |
|
---|
764 | pVBoxFobx->hFile = SHFL_HANDLE_NIL;
|
---|
765 |
|
---|
766 | if (vrc != VINF_SUCCESS)
|
---|
767 | Status = vbsfNtVBoxStatusToNt(vrc);
|
---|
768 |
|
---|
769 | Log(("VBOXSF: vbsfCloseFileHandle: Returned 0x%08X\n", Status));
|
---|
770 | return Status;
|
---|
771 | }
|
---|
772 |
|
---|
773 | NTSTATUS VBoxMRxCloseSrvOpen(IN PRX_CONTEXT RxContext)
|
---|
774 | {
|
---|
775 | NTSTATUS Status = STATUS_SUCCESS;
|
---|
776 |
|
---|
777 | RxCaptureFcb;
|
---|
778 | RxCaptureFobx;
|
---|
779 |
|
---|
780 | PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension = VBoxMRxGetNetRootExtension(capFcb->pNetRoot);
|
---|
781 | PMRX_VBOX_FOBX pVBoxFobx = VBoxMRxGetFileObjectExtension(capFobx);
|
---|
782 | PMRX_SRV_OPEN pSrvOpen = capFobx->pSrvOpen;
|
---|
783 |
|
---|
784 | PUNICODE_STRING RemainingName = NULL;
|
---|
785 |
|
---|
786 | Log(("VBOXSF: MRxCloseSrvOpen: capFcb = %p, capFobx = %p, pVBoxFobx = %p, pSrvOpen = %p\n",
|
---|
787 | capFcb, capFobx, pVBoxFobx, pSrvOpen));
|
---|
788 |
|
---|
789 | RemainingName = pSrvOpen->pAlreadyPrefixedName;
|
---|
790 |
|
---|
791 | Log(("VBOXSF: MRxCloseSrvOpen: Remaining name = %.*ls, Len = %d\n",
|
---|
792 | RemainingName->Length / sizeof(WCHAR), RemainingName->Buffer, RemainingName->Length));
|
---|
793 |
|
---|
794 | if (!pVBoxFobx)
|
---|
795 | return STATUS_INVALID_PARAMETER;
|
---|
796 |
|
---|
797 | if (FlagOn(pSrvOpen->Flags, (SRVOPEN_FLAG_FILE_RENAMED | SRVOPEN_FLAG_FILE_DELETED)))
|
---|
798 | {
|
---|
799 | /* If we renamed or delete the file/dir, then it's already closed */
|
---|
800 | Assert(pVBoxFobx->hFile == SHFL_HANDLE_NIL);
|
---|
801 | Log(("VBOXSF: MRxCloseSrvOpen: File was renamed, handle 0x%RX64 ignore close.\n",
|
---|
802 | pVBoxFobx->hFile));
|
---|
803 | return STATUS_SUCCESS;
|
---|
804 | }
|
---|
805 |
|
---|
806 | /* Close file */
|
---|
807 | if (pVBoxFobx->hFile != SHFL_HANDLE_NIL)
|
---|
808 | vbsfNtCloseFileHandle(pNetRootExtension, pVBoxFobx);
|
---|
809 |
|
---|
810 | if (capFcb->FcbState & FCB_STATE_DELETE_ON_CLOSE)
|
---|
811 | {
|
---|
812 | Log(("VBOXSF: MRxCloseSrvOpen: Delete on close. Open count = %d\n",
|
---|
813 | capFcb->OpenCount));
|
---|
814 |
|
---|
815 | /* Remove file or directory if delete action is pending. */
|
---|
816 | if (capFcb->OpenCount == 0)
|
---|
817 | Status = vbsfNtRemove(RxContext);
|
---|
818 | }
|
---|
819 |
|
---|
820 | return Status;
|
---|
821 | }
|
---|
822 |
|
---|
823 | /**
|
---|
824 | * Worker for vbsfNtSetBasicInfo and VBoxMRxCloseSrvOpen.
|
---|
825 | */
|
---|
826 | NTSTATUS vbsfNtRemove(IN PRX_CONTEXT RxContext)
|
---|
827 | {
|
---|
828 | NTSTATUS Status = STATUS_SUCCESS;
|
---|
829 |
|
---|
830 | RxCaptureFcb;
|
---|
831 | RxCaptureFobx;
|
---|
832 |
|
---|
833 | PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension = VBoxMRxGetNetRootExtension(capFcb->pNetRoot);
|
---|
834 | PMRX_VBOX_FOBX pVBoxFobx = VBoxMRxGetFileObjectExtension(capFobx);
|
---|
835 |
|
---|
836 | PUNICODE_STRING RemainingName = GET_ALREADY_PREFIXED_NAME_FROM_CONTEXT(RxContext);
|
---|
837 |
|
---|
838 | int vrc;
|
---|
839 | PSHFLSTRING ParsedPath = NULL;
|
---|
840 |
|
---|
841 | Log(("VBOXSF: vbsfNtRemove: Delete %.*ls. open count = %d\n",
|
---|
842 | RemainingName->Length / sizeof(WCHAR), RemainingName->Buffer, capFcb->OpenCount));
|
---|
843 |
|
---|
844 | /* Close file first if not already done. */
|
---|
845 | if (pVBoxFobx->hFile != SHFL_HANDLE_NIL)
|
---|
846 | vbsfNtCloseFileHandle(pNetRootExtension, pVBoxFobx);
|
---|
847 |
|
---|
848 | Log(("VBOXSF: vbsfNtRemove: RemainingName->Length %d\n", RemainingName->Length));
|
---|
849 | Status = vbsfNtShflStringFromUnicodeAlloc(&ParsedPath, RemainingName->Buffer, RemainingName->Length);
|
---|
850 | if (Status != STATUS_SUCCESS)
|
---|
851 | return Status;
|
---|
852 |
|
---|
853 | /* Call host. */
|
---|
854 | vrc = VbglR0SfRemove(&g_SfClient, &pNetRootExtension->map,
|
---|
855 | ParsedPath,
|
---|
856 | pVBoxFobx->Info.Attr.fMode & RTFS_DOS_DIRECTORY ? SHFL_REMOVE_DIR : SHFL_REMOVE_FILE);
|
---|
857 |
|
---|
858 | if (ParsedPath)
|
---|
859 | vbsfNtFreeNonPagedMem(ParsedPath);
|
---|
860 |
|
---|
861 | if (vrc == VINF_SUCCESS)
|
---|
862 | SetFlag(capFobx->pSrvOpen->Flags, SRVOPEN_FLAG_FILE_DELETED);
|
---|
863 |
|
---|
864 | Status = vbsfNtVBoxStatusToNt(vrc);
|
---|
865 | if (vrc != VINF_SUCCESS)
|
---|
866 | Log(("VBOXSF: vbsfNtRemove: VbglR0SfRemove failed with %Rrc\n", vrc));
|
---|
867 |
|
---|
868 | Log(("VBOXSF: vbsfNtRemove: Returned 0x%08X\n", Status));
|
---|
869 | return Status;
|
---|
870 | }
|
---|
871 |
|
---|
872 | NTSTATUS VBoxMRxShouldTryToCollapseThisOpen(IN PRX_CONTEXT RxContext)
|
---|
873 | {
|
---|
874 | RT_NOREF(RxContext);
|
---|
875 | Log(("VBOXSF: MRxShouldTryToCollapseThisOpen\n"));
|
---|
876 | return STATUS_MORE_PROCESSING_REQUIRED;
|
---|
877 | }
|
---|
878 |
|
---|
879 | NTSTATUS VBoxMRxCollapseOpen(IN OUT PRX_CONTEXT RxContext)
|
---|
880 | {
|
---|
881 | RT_NOREF(RxContext);
|
---|
882 | Log(("VBOXSF: MRxCollapseOpen\n"));
|
---|
883 | return STATUS_MORE_PROCESSING_REQUIRED;
|
---|
884 | }
|
---|