VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/SharedFolders/driver/path.cpp@ 78366

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

winnt/vboxsf: Removed FileBasicInfo from MRX_VBOX_FOBX as it was only used for logging attributes during file creation/opening. bugref:9172

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 31.9 KB
Line 
1/* $Id: path.cpp 78366 2019-05-02 21:56:23Z 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*********************************************************************************************************************************/
29static UNICODE_STRING g_UnicodeBackslash = { 2, 4, L"\\" };
30
31
32static 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
443failure:
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
460NTSTATUS 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 * See if the size has changed and update the FCB if it has.
575 */
576 else
577 {
578 /** @todo Need to check RDBSS stack for locking semantics before updating
579 * anything. */
580 }
581
582 SrvOpen->BufferingFlags = 0;
583
584 RxContext->pFobx->OffsetOfNextEaToReturn = 1;
585
586 pVBoxFobx = VBoxMRxGetFileObjectExtension(RxContext->pFobx);
587
588 Log(("VBOXSF: MRxCreate: VBoxFobx = %p\n",
589 pVBoxFobx));
590
591 if (!pVBoxFobx)
592 {
593 Log(("VBOXSF: MRxCreate: no VBoxFobx!\n"));
594 AssertFailed();
595 Status = STATUS_INSUFFICIENT_RESOURCES;
596 goto Exit;
597 }
598
599 pVBoxFobx->hFile = Handle;
600 pVBoxFobx->pSrvCall = RxContext->Create.pSrvCall;
601 pVBoxFobx->Info = Info;
602 Log(("VBOXSF: MRxCreate: Info: BirthTime %RI64\n", RTTimeSpecGetNano(&pVBoxFobx->Info.BirthTime)));
603 Log(("VBOXSF: MRxCreate: Info: ChangeTime %RI64\n", RTTimeSpecGetNano(&pVBoxFobx->Info.ChangeTime)));
604 Log(("VBOXSF: MRxCreate: Info: ModificationTime %RI64\n", RTTimeSpecGetNano(&pVBoxFobx->Info.ModificationTime)));
605 Log(("VBOXSF: MRxCreate: Info: AccessTime %RI64\n", RTTimeSpecGetNano(&pVBoxFobx->Info.AccessTime)));
606 Log(("VBOXSF: MRxCreate: Info: fMode %#RX32\n", pVBoxFobx->Info.Attr.fMode));
607 if (!(Info.Attr.fMode & RTFS_DOS_DIRECTORY))
608 {
609 Log(("VBOXSF: MRxCreate: Info: cbObject %#RX64\n", pVBoxFobx->Info.cbObject));
610 Log(("VBOXSF: MRxCreate: Info: cbAllocated %#RX64\n", pVBoxFobx->Info.cbAllocated));
611 }
612
613 if (!RxIsFcbAcquiredExclusive(capFcb))
614 {
615 RxAcquireExclusiveFcbResourceInMRx(capFcb);
616 }
617
618 Log(("VBOXSF: MRxCreate: NetRoot is %p, Fcb is %p, SrvOpen is %p, Fobx is %p\n",
619 pNetRoot, capFcb, SrvOpen, RxContext->pFobx));
620 Log(("VBOXSF: MRxCreate: return 0x%08X\n",
621 Status));
622
623Exit:
624 return Status;
625}
626
627NTSTATUS VBoxMRxComputeNewBufferingState(IN OUT PMRX_SRV_OPEN pMRxSrvOpen, IN PVOID pMRxContext, OUT PULONG pNewBufferingState)
628{
629 RT_NOREF(pMRxSrvOpen, pMRxContext, pNewBufferingState);
630 Log(("VBOXSF: MRxComputeNewBufferingState\n"));
631 return STATUS_NOT_SUPPORTED;
632}
633
634NTSTATUS VBoxMRxDeallocateForFcb(IN OUT PMRX_FCB pFcb)
635{
636 RT_NOREF(pFcb);
637 Log(("VBOXSF: MRxDeallocateForFcb\n"));
638 return STATUS_SUCCESS;
639}
640
641NTSTATUS VBoxMRxDeallocateForFobx(IN OUT PMRX_FOBX pFobx)
642{
643 RT_NOREF(pFobx);
644 Log(("VBOXSF: MRxDeallocateForFobx\n"));
645 return STATUS_SUCCESS;
646}
647
648NTSTATUS VBoxMRxTruncate(IN PRX_CONTEXT RxContext)
649{
650 RT_NOREF(RxContext);
651 Log(("VBOXSF: MRxTruncate\n"));
652 return STATUS_NOT_IMPLEMENTED;
653}
654
655NTSTATUS VBoxMRxCleanupFobx(IN PRX_CONTEXT RxContext)
656{
657 PMRX_VBOX_FOBX pVBoxFobx = VBoxMRxGetFileObjectExtension(RxContext->pFobx);
658
659 Log(("VBOXSF: MRxCleanupFobx: pVBoxFobx = %p, Handle = 0x%RX64\n", pVBoxFobx, pVBoxFobx? pVBoxFobx->hFile: 0));
660
661 if (!pVBoxFobx)
662 return STATUS_INVALID_PARAMETER;
663
664 return STATUS_SUCCESS;
665}
666
667NTSTATUS VBoxMRxForceClosed(IN PMRX_SRV_OPEN pSrvOpen)
668{
669 RT_NOREF(pSrvOpen);
670 Log(("VBOXSF: MRxForceClosed\n"));
671 return STATUS_NOT_IMPLEMENTED;
672}
673
674/**
675 * Closes an opened file handle of a MRX_VBOX_FOBX.
676 *
677 * Updates file attributes if necessary.
678 *
679 * Used by VBoxMRxCloseSrvOpen, vbsfNtRemove and vbsfNtRename.
680 */
681NTSTATUS vbsfNtCloseFileHandle(PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension,
682 PMRX_VBOX_FOBX pVBoxFobx,
683 PVBSFNTFCBEXT pVBoxFcbx)
684{
685 if (pVBoxFobx->hFile == SHFL_HANDLE_NIL)
686 {
687 Log(("VBOXSF: vbsfCloseFileHandle: SHFL_HANDLE_NIL\n"));
688 return STATUS_SUCCESS;
689 }
690
691 Log(("VBOXSF: vbsfCloseFileHandle: 0x%RX64, fTimestampsUpdatingSuppressed = %#x, fTimestampsImplicitlyUpdated = %#x\n",
692 pVBoxFobx->hFile, pVBoxFobx->fTimestampsUpdatingSuppressed, pVBoxFobx->fTimestampsImplicitlyUpdated));
693
694 /*
695 * We allocate a single request buffer for the timestamp updating and the closing
696 * to save time (at the risk of running out of heap, but whatever).
697 */
698 union MyCloseAndInfoReq
699 {
700 VBOXSFCLOSEREQ Close;
701 VBOXSFOBJINFOREQ Info;
702 } *pReq = (union MyCloseAndInfoReq *)VbglR0PhysHeapAlloc(sizeof(*pReq));
703 if (pReq)
704 RT_ZERO(*pReq);
705 else
706 return STATUS_INSUFF_SERVER_RESOURCES;
707
708 /*
709 * Restore timestamp that we may implicitly been updated via this handle
710 * after the user explicitly set them or turn off implict updating (the -1 value).
711 *
712 * Note! We ignore the status of this operation.
713 */
714 Assert(pVBoxFcbx);
715 uint8_t fUpdateTs = pVBoxFobx->fTimestampsUpdatingSuppressed & pVBoxFobx->fTimestampsImplicitlyUpdated;
716 if (fUpdateTs)
717 {
718 /** @todo skip this if the host is windows and fTimestampsUpdatingSuppressed == fTimestampsSetByUser */
719 /** @todo pass -1 timestamps thru so we can always skip this on windows hosts! */
720 if ( (fUpdateTs & VBOX_FOBX_F_INFO_LASTACCESS_TIME)
721 && pVBoxFcbx->pFobxLastAccessTime == pVBoxFobx)
722 pReq->Info.ObjInfo.AccessTime = pVBoxFobx->Info.AccessTime;
723 else
724 fUpdateTs &= ~VBOX_FOBX_F_INFO_LASTACCESS_TIME;
725
726 if ( (fUpdateTs & VBOX_FOBX_F_INFO_LASTWRITE_TIME)
727 && pVBoxFcbx->pFobxLastWriteTime == pVBoxFobx)
728 pReq->Info.ObjInfo.ModificationTime = pVBoxFobx->Info.ModificationTime;
729 else
730 fUpdateTs &= ~VBOX_FOBX_F_INFO_LASTWRITE_TIME;
731
732 if ( (fUpdateTs & VBOX_FOBX_F_INFO_CHANGE_TIME)
733 && pVBoxFcbx->pFobxChangeTime == pVBoxFobx)
734 pReq->Info.ObjInfo.ChangeTime = pVBoxFobx->Info.ChangeTime;
735 else
736 fUpdateTs &= ~VBOX_FOBX_F_INFO_CHANGE_TIME;
737 if (fUpdateTs)
738 {
739 Log(("VBOXSF: vbsfCloseFileHandle: Updating timestamp: %#x\n", fUpdateTs));
740 int vrc = VbglR0SfHostReqSetObjInfo(pNetRootExtension->map.root, &pReq->Info, pVBoxFobx->hFile);
741 if (RT_FAILURE(vrc))
742 Log(("VBOXSF: vbsfCloseFileHandle: VbglR0SfHostReqSetObjInfo failed for fUpdateTs=%#x: %Rrc\n", fUpdateTs, vrc));
743 RT_NOREF(vrc);
744 }
745 else
746 Log(("VBOXSF: vbsfCloseFileHandle: no timestamp needing updating\n"));
747 }
748
749 /* This isn't strictly necessary, but best to keep things clean. */
750 pVBoxFobx->fTimestampsSetByUser = 0;
751 pVBoxFobx->fTimestampsUpdatingSuppressed = 0;
752 pVBoxFobx->fTimestampsImplicitlyUpdated = 0;
753 if (pVBoxFcbx->pFobxLastAccessTime == pVBoxFobx)
754 pVBoxFcbx->pFobxLastAccessTime = NULL;
755 if (pVBoxFcbx->pFobxLastWriteTime == pVBoxFobx)
756 pVBoxFcbx->pFobxLastWriteTime = NULL;
757 if (pVBoxFcbx->pFobxChangeTime == pVBoxFobx)
758 pVBoxFcbx->pFobxChangeTime = NULL;
759
760 /*
761 * Now close the handle.
762 */
763 int vrc = VbglR0SfHostReqClose(pNetRootExtension->map.root, &pReq->Close, pVBoxFobx->hFile);
764
765 pVBoxFobx->hFile = SHFL_HANDLE_NIL;
766
767 VbglR0PhysHeapFree(pReq);
768
769 NTSTATUS const Status = RT_SUCCESS(vrc) ? STATUS_SUCCESS : vbsfNtVBoxStatusToNt(vrc);
770 Log(("VBOXSF: vbsfCloseFileHandle: Returned 0x%08X (vrc=%Rrc)\n", Status, vrc));
771 return Status;
772}
773
774NTSTATUS VBoxMRxCloseSrvOpen(IN PRX_CONTEXT RxContext)
775{
776 NTSTATUS Status = STATUS_SUCCESS;
777
778 RxCaptureFcb;
779 RxCaptureFobx;
780
781 PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension = VBoxMRxGetNetRootExtension(capFcb->pNetRoot);
782 PMRX_VBOX_FOBX pVBoxFobx = VBoxMRxGetFileObjectExtension(capFobx);
783 PMRX_SRV_OPEN pSrvOpen = capFobx->pSrvOpen;
784
785 PUNICODE_STRING RemainingName = NULL;
786
787 Log(("VBOXSF: MRxCloseSrvOpen: capFcb = %p, capFobx = %p, pVBoxFobx = %p, pSrvOpen = %p\n",
788 capFcb, capFobx, pVBoxFobx, pSrvOpen));
789
790 RemainingName = pSrvOpen->pAlreadyPrefixedName;
791
792 Log(("VBOXSF: MRxCloseSrvOpen: Remaining name = %.*ls, Len = %d\n",
793 RemainingName->Length / sizeof(WCHAR), RemainingName->Buffer, RemainingName->Length));
794
795 if (!pVBoxFobx)
796 return STATUS_INVALID_PARAMETER;
797
798 if (FlagOn(pSrvOpen->Flags, (SRVOPEN_FLAG_FILE_RENAMED | SRVOPEN_FLAG_FILE_DELETED)))
799 {
800 /* If we renamed or delete the file/dir, then it's already closed */
801 Assert(pVBoxFobx->hFile == SHFL_HANDLE_NIL);
802 Log(("VBOXSF: MRxCloseSrvOpen: File was renamed, handle 0x%RX64 ignore close.\n",
803 pVBoxFobx->hFile));
804 return STATUS_SUCCESS;
805 }
806
807 /* Close file */
808 if (pVBoxFobx->hFile != SHFL_HANDLE_NIL)
809 vbsfNtCloseFileHandle(pNetRootExtension, pVBoxFobx, VBoxMRxGetFcbExtension(capFcb));
810
811 if (capFcb->FcbState & FCB_STATE_DELETE_ON_CLOSE)
812 {
813 Log(("VBOXSF: MRxCloseSrvOpen: Delete on close. Open count = %d\n",
814 capFcb->OpenCount));
815
816 /* Remove file or directory if delete action is pending. */
817 if (capFcb->OpenCount == 0)
818 Status = vbsfNtRemove(RxContext);
819 }
820
821 return Status;
822}
823
824/**
825 * Worker for vbsfNtSetBasicInfo and VBoxMRxCloseSrvOpen.
826 */
827NTSTATUS vbsfNtRemove(IN PRX_CONTEXT RxContext)
828{
829 NTSTATUS Status = STATUS_SUCCESS;
830
831 RxCaptureFcb;
832 RxCaptureFobx;
833
834 PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension = VBoxMRxGetNetRootExtension(capFcb->pNetRoot);
835 PMRX_VBOX_FOBX pVBoxFobx = VBoxMRxGetFileObjectExtension(capFobx);
836
837 PUNICODE_STRING RemainingName = GET_ALREADY_PREFIXED_NAME_FROM_CONTEXT(RxContext);
838
839 int vrc;
840 PSHFLSTRING ParsedPath = NULL;
841
842 Log(("VBOXSF: vbsfNtRemove: Delete %.*ls. open count = %d\n",
843 RemainingName->Length / sizeof(WCHAR), RemainingName->Buffer, capFcb->OpenCount));
844
845 /* Close file first if not already done. */
846 if (pVBoxFobx->hFile != SHFL_HANDLE_NIL)
847 vbsfNtCloseFileHandle(pNetRootExtension, pVBoxFobx, VBoxMRxGetFcbExtension(capFcb));
848
849 Log(("VBOXSF: vbsfNtRemove: RemainingName->Length %d\n", RemainingName->Length));
850 Status = vbsfNtShflStringFromUnicodeAlloc(&ParsedPath, RemainingName->Buffer, RemainingName->Length);
851 if (Status != STATUS_SUCCESS)
852 return Status;
853
854 /* Call host. */
855 vrc = VbglR0SfRemove(&g_SfClient, &pNetRootExtension->map,
856 ParsedPath,
857 pVBoxFobx->Info.Attr.fMode & RTFS_DOS_DIRECTORY ? SHFL_REMOVE_DIR : SHFL_REMOVE_FILE);
858
859 if (ParsedPath)
860 vbsfNtFreeNonPagedMem(ParsedPath);
861
862 if (vrc == VINF_SUCCESS)
863 SetFlag(capFobx->pSrvOpen->Flags, SRVOPEN_FLAG_FILE_DELETED);
864
865 Status = vbsfNtVBoxStatusToNt(vrc);
866 if (vrc != VINF_SUCCESS)
867 Log(("VBOXSF: vbsfNtRemove: VbglR0SfRemove failed with %Rrc\n", vrc));
868
869 Log(("VBOXSF: vbsfNtRemove: Returned 0x%08X\n", Status));
870 return Status;
871}
872
873NTSTATUS VBoxMRxShouldTryToCollapseThisOpen(IN PRX_CONTEXT RxContext)
874{
875 RT_NOREF(RxContext);
876 Log(("VBOXSF: MRxShouldTryToCollapseThisOpen\n"));
877 return STATUS_MORE_PROCESSING_REQUIRED;
878}
879
880NTSTATUS VBoxMRxCollapseOpen(IN OUT PRX_CONTEXT RxContext)
881{
882 RT_NOREF(RxContext);
883 Log(("VBOXSF: MRxCollapseOpen\n"));
884 return STATUS_MORE_PROCESSING_REQUIRED;
885}
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