1 | /* $Id: path.cpp 78329 2019-04-26 15:35:04Z 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 | * Updates file attributes if necessary.
|
---|
729 | */
|
---|
730 | static NTSTATUS vbsfCloseFileHandle(PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension,
|
---|
731 | PMRX_VBOX_FOBX pVBoxFobx)
|
---|
732 | {
|
---|
733 | NTSTATUS Status = STATUS_SUCCESS;
|
---|
734 |
|
---|
735 | int vrc;
|
---|
736 |
|
---|
737 | if (pVBoxFobx->hFile == SHFL_HANDLE_NIL)
|
---|
738 | {
|
---|
739 | Log(("VBOXSF: vbsfCloseFileHandle: SHFL_HANDLE_NIL\n"));
|
---|
740 | return STATUS_SUCCESS;
|
---|
741 | }
|
---|
742 |
|
---|
743 | Log(("VBOXSF: vbsfCloseFileHandle: 0x%RX64, on close info 0x%02X\n",
|
---|
744 | pVBoxFobx->hFile, pVBoxFobx->SetFileInfoOnCloseFlags));
|
---|
745 |
|
---|
746 | if (pVBoxFobx->SetFileInfoOnCloseFlags)
|
---|
747 | {
|
---|
748 | /* If the file timestamps were set by the user, then update them before closing the handle,
|
---|
749 | * to cancel any effect of the file read/write operations on the host.
|
---|
750 | */
|
---|
751 | Status = vbsfSetFileInfoOnClose(pNetRootExtension,
|
---|
752 | pVBoxFobx,
|
---|
753 | &pVBoxFobx->FileBasicInfo,
|
---|
754 | pVBoxFobx->SetFileInfoOnCloseFlags);
|
---|
755 | }
|
---|
756 |
|
---|
757 | vrc = VbglR0SfClose(&g_SfClient,
|
---|
758 | &pNetRootExtension->map,
|
---|
759 | pVBoxFobx->hFile);
|
---|
760 |
|
---|
761 | pVBoxFobx->hFile = SHFL_HANDLE_NIL;
|
---|
762 |
|
---|
763 | if (vrc != VINF_SUCCESS)
|
---|
764 | Status = vbsfNtVBoxStatusToNt(vrc);
|
---|
765 |
|
---|
766 | Log(("VBOXSF: vbsfCloseFileHandle: Returned 0x%08X\n", Status));
|
---|
767 | return Status;
|
---|
768 | }
|
---|
769 |
|
---|
770 | NTSTATUS VBoxMRxCloseSrvOpen(IN PRX_CONTEXT RxContext)
|
---|
771 | {
|
---|
772 | NTSTATUS Status = STATUS_SUCCESS;
|
---|
773 |
|
---|
774 | RxCaptureFcb;
|
---|
775 | RxCaptureFobx;
|
---|
776 |
|
---|
777 | PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension = VBoxMRxGetNetRootExtension(capFcb->pNetRoot);
|
---|
778 | PMRX_VBOX_FOBX pVBoxFobx = VBoxMRxGetFileObjectExtension(capFobx);
|
---|
779 | PMRX_SRV_OPEN pSrvOpen = capFobx->pSrvOpen;
|
---|
780 |
|
---|
781 | PUNICODE_STRING RemainingName = NULL;
|
---|
782 |
|
---|
783 | Log(("VBOXSF: MRxCloseSrvOpen: capFcb = %p, capFobx = %p, pVBoxFobx = %p, pSrvOpen = %p\n",
|
---|
784 | capFcb, capFobx, pVBoxFobx, pSrvOpen));
|
---|
785 |
|
---|
786 | RemainingName = pSrvOpen->pAlreadyPrefixedName;
|
---|
787 |
|
---|
788 | Log(("VBOXSF: MRxCloseSrvOpen: Remaining name = %.*ls, Len = %d\n",
|
---|
789 | RemainingName->Length / sizeof(WCHAR), RemainingName->Buffer, RemainingName->Length));
|
---|
790 |
|
---|
791 | if (!pVBoxFobx)
|
---|
792 | return STATUS_INVALID_PARAMETER;
|
---|
793 |
|
---|
794 | if (FlagOn(pSrvOpen->Flags, (SRVOPEN_FLAG_FILE_RENAMED | SRVOPEN_FLAG_FILE_DELETED)))
|
---|
795 | {
|
---|
796 | /* If we renamed or delete the file/dir, then it's already closed */
|
---|
797 | Assert(pVBoxFobx->hFile == SHFL_HANDLE_NIL);
|
---|
798 | Log(("VBOXSF: MRxCloseSrvOpen: File was renamed, handle 0x%RX64 ignore close.\n",
|
---|
799 | pVBoxFobx->hFile));
|
---|
800 | return STATUS_SUCCESS;
|
---|
801 | }
|
---|
802 |
|
---|
803 | /* Close file */
|
---|
804 | if (pVBoxFobx->hFile != SHFL_HANDLE_NIL)
|
---|
805 | vbsfCloseFileHandle(pNetRootExtension, pVBoxFobx);
|
---|
806 |
|
---|
807 | if (capFcb->FcbState & FCB_STATE_DELETE_ON_CLOSE)
|
---|
808 | {
|
---|
809 | Log(("VBOXSF: MRxCloseSrvOpen: Delete on close. Open count = %d\n",
|
---|
810 | capFcb->OpenCount));
|
---|
811 |
|
---|
812 | /* Remove file or directory if delete action is pending. */
|
---|
813 | if (capFcb->OpenCount == 0)
|
---|
814 | Status = vbsfNtRemove(RxContext);
|
---|
815 | }
|
---|
816 |
|
---|
817 | return Status;
|
---|
818 | }
|
---|
819 |
|
---|
820 | NTSTATUS vbsfNtRemove(IN PRX_CONTEXT RxContext)
|
---|
821 | {
|
---|
822 | NTSTATUS Status = STATUS_SUCCESS;
|
---|
823 |
|
---|
824 | RxCaptureFcb;
|
---|
825 | RxCaptureFobx;
|
---|
826 |
|
---|
827 | PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension = VBoxMRxGetNetRootExtension(capFcb->pNetRoot);
|
---|
828 | PMRX_VBOX_FOBX pVBoxFobx = VBoxMRxGetFileObjectExtension(capFobx);
|
---|
829 |
|
---|
830 | PUNICODE_STRING RemainingName = GET_ALREADY_PREFIXED_NAME_FROM_CONTEXT(RxContext);
|
---|
831 |
|
---|
832 | int vrc;
|
---|
833 | PSHFLSTRING ParsedPath = NULL;
|
---|
834 |
|
---|
835 | Log(("VBOXSF: vbsfNtRemove: Delete %.*ls. open count = %d\n",
|
---|
836 | RemainingName->Length / sizeof(WCHAR), RemainingName->Buffer, capFcb->OpenCount));
|
---|
837 |
|
---|
838 | /* Close file first if not already done. */
|
---|
839 | if (pVBoxFobx->hFile != SHFL_HANDLE_NIL)
|
---|
840 | vbsfCloseFileHandle(pNetRootExtension, pVBoxFobx);
|
---|
841 |
|
---|
842 | Log(("VBOXSF: vbsfNtRemove: RemainingName->Length %d\n", RemainingName->Length));
|
---|
843 | Status = vbsfNtShflStringFromUnicodeAlloc(&ParsedPath, RemainingName->Buffer, RemainingName->Length);
|
---|
844 | if (Status != STATUS_SUCCESS)
|
---|
845 | return Status;
|
---|
846 |
|
---|
847 | /* Call host. */
|
---|
848 | vrc = VbglR0SfRemove(&g_SfClient, &pNetRootExtension->map,
|
---|
849 | ParsedPath,
|
---|
850 | pVBoxFobx->Info.Attr.fMode & RTFS_DOS_DIRECTORY ? SHFL_REMOVE_DIR : SHFL_REMOVE_FILE);
|
---|
851 |
|
---|
852 | if (ParsedPath)
|
---|
853 | vbsfNtFreeNonPagedMem(ParsedPath);
|
---|
854 |
|
---|
855 | if (vrc == VINF_SUCCESS)
|
---|
856 | SetFlag(capFobx->pSrvOpen->Flags, SRVOPEN_FLAG_FILE_DELETED);
|
---|
857 |
|
---|
858 | Status = vbsfNtVBoxStatusToNt(vrc);
|
---|
859 | if (vrc != VINF_SUCCESS)
|
---|
860 | Log(("VBOXSF: vbsfNtRemove: VbglR0SfRemove failed with %Rrc\n", vrc));
|
---|
861 |
|
---|
862 | Log(("VBOXSF: vbsfNtRemove: Returned 0x%08X\n", Status));
|
---|
863 | return Status;
|
---|
864 | }
|
---|
865 |
|
---|
866 | NTSTATUS vbsfNtRename(IN PRX_CONTEXT RxContext,
|
---|
867 | IN FILE_INFORMATION_CLASS FileInformationClass,
|
---|
868 | IN PVOID pBuffer,
|
---|
869 | IN ULONG BufferLength)
|
---|
870 | {
|
---|
871 | NTSTATUS Status = STATUS_SUCCESS;
|
---|
872 |
|
---|
873 | RxCaptureFcb;
|
---|
874 | RxCaptureFobx;
|
---|
875 |
|
---|
876 | PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension = VBoxMRxGetNetRootExtension(capFcb->pNetRoot);
|
---|
877 | PMRX_VBOX_FOBX pVBoxFobx = VBoxMRxGetFileObjectExtension(capFobx);
|
---|
878 | PMRX_SRV_OPEN pSrvOpen = capFobx->pSrvOpen;
|
---|
879 |
|
---|
880 | PFILE_RENAME_INFORMATION RenameInformation = (PFILE_RENAME_INFORMATION)RxContext->Info.Buffer;
|
---|
881 | PUNICODE_STRING RemainingName = GET_ALREADY_PREFIXED_NAME(pSrvOpen, capFcb);
|
---|
882 |
|
---|
883 | int vrc;
|
---|
884 | PSHFLSTRING SrcPath = 0, DestPath = 0;
|
---|
885 | ULONG flags;
|
---|
886 |
|
---|
887 | RT_NOREF(FileInformationClass, pBuffer, BufferLength);
|
---|
888 |
|
---|
889 | Assert(FileInformationClass == FileRenameInformation);
|
---|
890 |
|
---|
891 | Log(("VBOXSF: vbsfNtRename: FileName = %.*ls\n",
|
---|
892 | RenameInformation->FileNameLength / sizeof(WCHAR), &RenameInformation->FileName[0]));
|
---|
893 |
|
---|
894 | /* Must close the file before renaming it! */
|
---|
895 | if (pVBoxFobx->hFile != SHFL_HANDLE_NIL)
|
---|
896 | vbsfCloseFileHandle(pNetRootExtension, pVBoxFobx);
|
---|
897 |
|
---|
898 | /* Mark it as renamed, so we do nothing during close */
|
---|
899 | SetFlag(pSrvOpen->Flags, SRVOPEN_FLAG_FILE_RENAMED);
|
---|
900 |
|
---|
901 | Log(("VBOXSF: vbsfNtRename: RenameInformation->FileNameLength = %d\n", RenameInformation->FileNameLength));
|
---|
902 | Status = vbsfNtShflStringFromUnicodeAlloc(&DestPath, RenameInformation->FileName, (uint16_t)RenameInformation->FileNameLength);
|
---|
903 | if (Status != STATUS_SUCCESS)
|
---|
904 | return Status;
|
---|
905 |
|
---|
906 | Log(("VBOXSF: vbsfNtRename: Destination path = %.*ls\n",
|
---|
907 | DestPath->u16Length / sizeof(WCHAR), &DestPath->String.ucs2[0]));
|
---|
908 |
|
---|
909 | Log(("VBOXSF: vbsfNtRename: RemainingName->Length = %d\n", RemainingName->Length));
|
---|
910 | Status = vbsfNtShflStringFromUnicodeAlloc(&SrcPath, RemainingName->Buffer, RemainingName->Length);
|
---|
911 | if (Status != STATUS_SUCCESS)
|
---|
912 | {
|
---|
913 | vbsfNtFreeNonPagedMem(DestPath);
|
---|
914 | return Status;
|
---|
915 | }
|
---|
916 |
|
---|
917 | Log(("VBOXSF: vbsfNtRename: Source path = %.*ls\n",
|
---|
918 | SrcPath->u16Length / sizeof(WCHAR), &SrcPath->String.ucs2[0]));
|
---|
919 |
|
---|
920 | /* Call host. */
|
---|
921 | flags = pVBoxFobx->Info.Attr.fMode & RTFS_DOS_DIRECTORY ? SHFL_RENAME_DIR : SHFL_RENAME_FILE;
|
---|
922 | if (RenameInformation->ReplaceIfExists)
|
---|
923 | flags |= SHFL_RENAME_REPLACE_IF_EXISTS;
|
---|
924 |
|
---|
925 | Log(("VBOXSF: vbsfNtRename: Calling VbglR0SfRename\n"));
|
---|
926 | vrc = VbglR0SfRename(&g_SfClient, &pNetRootExtension->map, SrcPath, DestPath, flags);
|
---|
927 |
|
---|
928 | vbsfNtFreeNonPagedMem(SrcPath);
|
---|
929 | vbsfNtFreeNonPagedMem(DestPath);
|
---|
930 |
|
---|
931 | Status = vbsfNtVBoxStatusToNt(vrc);
|
---|
932 | if (vrc != VINF_SUCCESS)
|
---|
933 | Log(("VBOXSF: vbsfNtRename: VbglR0SfRename failed with %Rrc\n", vrc));
|
---|
934 |
|
---|
935 | Log(("VBOXSF: vbsfNtRename: Returned 0x%08X\n", Status));
|
---|
936 | return Status;
|
---|
937 | }
|
---|
938 |
|
---|
939 | NTSTATUS VBoxMRxShouldTryToCollapseThisOpen(IN PRX_CONTEXT RxContext)
|
---|
940 | {
|
---|
941 | RT_NOREF(RxContext);
|
---|
942 | Log(("VBOXSF: MRxShouldTryToCollapseThisOpen\n"));
|
---|
943 | return STATUS_MORE_PROCESSING_REQUIRED;
|
---|
944 | }
|
---|
945 |
|
---|
946 | NTSTATUS VBoxMRxCollapseOpen(IN OUT PRX_CONTEXT RxContext)
|
---|
947 | {
|
---|
948 | RT_NOREF(RxContext);
|
---|
949 | Log(("VBOXSF: MRxCollapseOpen\n"));
|
---|
950 | return STATUS_MORE_PROCESSING_REQUIRED;
|
---|
951 | }
|
---|