VirtualBox

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

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

winnt/vboxsf: Reworked the set-timestamp handling. Need testcase and some host service tinkering. Also optimized handle closing. bugref:9172

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 31.7 KB
Line 
1/* $Id: path.cpp 78355 2019-04-30 03:48:46Z 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 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 vbsfNtBasicInfoFromVBoxObjInfo(&pVBoxFobx->FileBasicInfo, &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
614Exit:
615 return Status;
616}
617
618NTSTATUS 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
625NTSTATUS VBoxMRxDeallocateForFcb(IN OUT PMRX_FCB pFcb)
626{
627 RT_NOREF(pFcb);
628 Log(("VBOXSF: MRxDeallocateForFcb\n"));
629 return STATUS_SUCCESS;
630}
631
632NTSTATUS VBoxMRxDeallocateForFobx(IN OUT PMRX_FOBX pFobx)
633{
634 RT_NOREF(pFobx);
635 Log(("VBOXSF: MRxDeallocateForFobx\n"));
636 return STATUS_SUCCESS;
637}
638
639NTSTATUS VBoxMRxTruncate(IN PRX_CONTEXT RxContext)
640{
641 RT_NOREF(RxContext);
642 Log(("VBOXSF: MRxTruncate\n"));
643 return STATUS_NOT_IMPLEMENTED;
644}
645
646NTSTATUS 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
658NTSTATUS VBoxMRxForceClosed(IN PMRX_SRV_OPEN pSrvOpen)
659{
660 RT_NOREF(pSrvOpen);
661 Log(("VBOXSF: MRxForceClosed\n"));
662 return STATUS_NOT_IMPLEMENTED;
663}
664
665/**
666 * Closes an opened file handle of a MRX_VBOX_FOBX.
667 *
668 * Updates file attributes if necessary.
669 *
670 * Used by VBoxMRxCloseSrvOpen, vbsfNtRemove and vbsfNtRename.
671 */
672NTSTATUS vbsfNtCloseFileHandle(PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension,
673 PMRX_VBOX_FOBX pVBoxFobx,
674 PVBSFNTFCBEXT pVBoxFcbx)
675{
676 if (pVBoxFobx->hFile == SHFL_HANDLE_NIL)
677 {
678 Log(("VBOXSF: vbsfCloseFileHandle: SHFL_HANDLE_NIL\n"));
679 return STATUS_SUCCESS;
680 }
681
682 Log(("VBOXSF: vbsfCloseFileHandle: 0x%RX64, fTimestampsUpdatingSuppressed = %#x, fTimestampsImplicitlyUpdated = %#x\n",
683 pVBoxFobx->hFile, pVBoxFobx->fTimestampsUpdatingSuppressed, pVBoxFobx->fTimestampsImplicitlyUpdated));
684
685 /*
686 * We allocate a single request buffer for the timestamp updating and the closing
687 * to save time (at the risk of running out of heap, but whatever).
688 */
689 union MyCloseAndInfoReq
690 {
691 VBOXSFCLOSEREQ Close;
692 VBOXSFOBJINFOREQ Info;
693 } *pReq = (union MyCloseAndInfoReq *)VbglR0PhysHeapAlloc(sizeof(*pReq));
694 if (pReq)
695 RT_ZERO(*pReq);
696 else
697 return STATUS_INSUFF_SERVER_RESOURCES;
698
699 /*
700 * Restore timestamp that we may implicitly been updated via this handle
701 * after the user explicitly set them or turn off implict updating (the -1 value).
702 *
703 * Note! We ignore the status of this operation.
704 */
705 Assert(pVBoxFcbx);
706 uint8_t fUpdateTs = pVBoxFobx->fTimestampsUpdatingSuppressed & pVBoxFobx->fTimestampsImplicitlyUpdated;
707 if (fUpdateTs)
708 {
709 /** @todo skip this if the host is windows and fTimestampsUpdatingSuppressed == fTimestampsSetByUser */
710 /** @todo pass -1 timestamps thru so we can always skip this on windows hosts! */
711 if ( (fUpdateTs & VBOX_FOBX_F_INFO_LASTACCESS_TIME)
712 && pVBoxFcbx->pFobxLastAccessTime == pVBoxFobx)
713 pReq->Info.ObjInfo.AccessTime = pVBoxFobx->Info.AccessTime;
714 else
715 fUpdateTs &= ~VBOX_FOBX_F_INFO_LASTACCESS_TIME;
716
717 if ( (fUpdateTs & VBOX_FOBX_F_INFO_LASTWRITE_TIME)
718 && pVBoxFcbx->pFobxLastWriteTime == pVBoxFobx)
719 pReq->Info.ObjInfo.ModificationTime = pVBoxFobx->Info.ModificationTime;
720 else
721 fUpdateTs &= ~VBOX_FOBX_F_INFO_LASTWRITE_TIME;
722
723 if ( (fUpdateTs & VBOX_FOBX_F_INFO_CHANGE_TIME)
724 && pVBoxFcbx->pFobxChangeTime == pVBoxFobx)
725 pReq->Info.ObjInfo.ChangeTime = pVBoxFobx->Info.ChangeTime;
726 else
727 fUpdateTs &= ~VBOX_FOBX_F_INFO_CHANGE_TIME;
728 if (fUpdateTs)
729 {
730 Log(("VBOXSF: vbsfCloseFileHandle: Updating timestamp: %#x\n", fUpdateTs));
731 int vrc = VbglR0SfHostReqSetObjInfo(pNetRootExtension->map.root, &pReq->Info, pVBoxFobx->hFile);
732 if (RT_FAILURE(vrc))
733 Log(("VBOXSF: vbsfCloseFileHandle: VbglR0SfHostReqSetObjInfo failed for fUpdateTs=%#x: %Rrc\n", fUpdateTs, vrc));
734 RT_NOREF(vrc);
735 }
736 else
737 Log(("VBOXSF: vbsfCloseFileHandle: no timestamp needing updating\n"));
738 }
739
740 /* This isn't strictly necessary, but best to keep things clean. */
741 pVBoxFobx->fTimestampsSetByUser = 0;
742 pVBoxFobx->fTimestampsUpdatingSuppressed = 0;
743 pVBoxFobx->fTimestampsImplicitlyUpdated = 0;
744 if (pVBoxFcbx->pFobxLastAccessTime == pVBoxFobx)
745 pVBoxFcbx->pFobxLastAccessTime = NULL;
746 if (pVBoxFcbx->pFobxLastWriteTime == pVBoxFobx)
747 pVBoxFcbx->pFobxLastWriteTime = NULL;
748 if (pVBoxFcbx->pFobxChangeTime == pVBoxFobx)
749 pVBoxFcbx->pFobxChangeTime = NULL;
750
751 /*
752 * Now close the handle.
753 */
754 int vrc = VbglR0SfHostReqClose(pNetRootExtension->map.root, &pReq->Close, pVBoxFobx->hFile);
755
756 pVBoxFobx->hFile = SHFL_HANDLE_NIL;
757
758 VbglR0PhysHeapFree(pReq);
759
760 NTSTATUS const Status = RT_SUCCESS(vrc) ? STATUS_SUCCESS : vbsfNtVBoxStatusToNt(vrc);
761 Log(("VBOXSF: vbsfCloseFileHandle: Returned 0x%08X (vrc=%Rrc)\n", Status, vrc));
762 return Status;
763}
764
765NTSTATUS VBoxMRxCloseSrvOpen(IN PRX_CONTEXT RxContext)
766{
767 NTSTATUS Status = STATUS_SUCCESS;
768
769 RxCaptureFcb;
770 RxCaptureFobx;
771
772 PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension = VBoxMRxGetNetRootExtension(capFcb->pNetRoot);
773 PMRX_VBOX_FOBX pVBoxFobx = VBoxMRxGetFileObjectExtension(capFobx);
774 PMRX_SRV_OPEN pSrvOpen = capFobx->pSrvOpen;
775
776 PUNICODE_STRING RemainingName = NULL;
777
778 Log(("VBOXSF: MRxCloseSrvOpen: capFcb = %p, capFobx = %p, pVBoxFobx = %p, pSrvOpen = %p\n",
779 capFcb, capFobx, pVBoxFobx, pSrvOpen));
780
781 RemainingName = pSrvOpen->pAlreadyPrefixedName;
782
783 Log(("VBOXSF: MRxCloseSrvOpen: Remaining name = %.*ls, Len = %d\n",
784 RemainingName->Length / sizeof(WCHAR), RemainingName->Buffer, RemainingName->Length));
785
786 if (!pVBoxFobx)
787 return STATUS_INVALID_PARAMETER;
788
789 if (FlagOn(pSrvOpen->Flags, (SRVOPEN_FLAG_FILE_RENAMED | SRVOPEN_FLAG_FILE_DELETED)))
790 {
791 /* If we renamed or delete the file/dir, then it's already closed */
792 Assert(pVBoxFobx->hFile == SHFL_HANDLE_NIL);
793 Log(("VBOXSF: MRxCloseSrvOpen: File was renamed, handle 0x%RX64 ignore close.\n",
794 pVBoxFobx->hFile));
795 return STATUS_SUCCESS;
796 }
797
798 /* Close file */
799 if (pVBoxFobx->hFile != SHFL_HANDLE_NIL)
800 vbsfNtCloseFileHandle(pNetRootExtension, pVBoxFobx, VBoxMRxGetFcbExtension(capFcb));
801
802 if (capFcb->FcbState & FCB_STATE_DELETE_ON_CLOSE)
803 {
804 Log(("VBOXSF: MRxCloseSrvOpen: Delete on close. Open count = %d\n",
805 capFcb->OpenCount));
806
807 /* Remove file or directory if delete action is pending. */
808 if (capFcb->OpenCount == 0)
809 Status = vbsfNtRemove(RxContext);
810 }
811
812 return Status;
813}
814
815/**
816 * Worker for vbsfNtSetBasicInfo and VBoxMRxCloseSrvOpen.
817 */
818NTSTATUS vbsfNtRemove(IN PRX_CONTEXT RxContext)
819{
820 NTSTATUS Status = STATUS_SUCCESS;
821
822 RxCaptureFcb;
823 RxCaptureFobx;
824
825 PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension = VBoxMRxGetNetRootExtension(capFcb->pNetRoot);
826 PMRX_VBOX_FOBX pVBoxFobx = VBoxMRxGetFileObjectExtension(capFobx);
827
828 PUNICODE_STRING RemainingName = GET_ALREADY_PREFIXED_NAME_FROM_CONTEXT(RxContext);
829
830 int vrc;
831 PSHFLSTRING ParsedPath = NULL;
832
833 Log(("VBOXSF: vbsfNtRemove: Delete %.*ls. open count = %d\n",
834 RemainingName->Length / sizeof(WCHAR), RemainingName->Buffer, capFcb->OpenCount));
835
836 /* Close file first if not already done. */
837 if (pVBoxFobx->hFile != SHFL_HANDLE_NIL)
838 vbsfNtCloseFileHandle(pNetRootExtension, pVBoxFobx, VBoxMRxGetFcbExtension(capFcb));
839
840 Log(("VBOXSF: vbsfNtRemove: RemainingName->Length %d\n", RemainingName->Length));
841 Status = vbsfNtShflStringFromUnicodeAlloc(&ParsedPath, RemainingName->Buffer, RemainingName->Length);
842 if (Status != STATUS_SUCCESS)
843 return Status;
844
845 /* Call host. */
846 vrc = VbglR0SfRemove(&g_SfClient, &pNetRootExtension->map,
847 ParsedPath,
848 pVBoxFobx->Info.Attr.fMode & RTFS_DOS_DIRECTORY ? SHFL_REMOVE_DIR : SHFL_REMOVE_FILE);
849
850 if (ParsedPath)
851 vbsfNtFreeNonPagedMem(ParsedPath);
852
853 if (vrc == VINF_SUCCESS)
854 SetFlag(capFobx->pSrvOpen->Flags, SRVOPEN_FLAG_FILE_DELETED);
855
856 Status = vbsfNtVBoxStatusToNt(vrc);
857 if (vrc != VINF_SUCCESS)
858 Log(("VBOXSF: vbsfNtRemove: VbglR0SfRemove failed with %Rrc\n", vrc));
859
860 Log(("VBOXSF: vbsfNtRemove: Returned 0x%08X\n", Status));
861 return Status;
862}
863
864NTSTATUS VBoxMRxShouldTryToCollapseThisOpen(IN PRX_CONTEXT RxContext)
865{
866 RT_NOREF(RxContext);
867 Log(("VBOXSF: MRxShouldTryToCollapseThisOpen\n"));
868 return STATUS_MORE_PROCESSING_REQUIRED;
869}
870
871NTSTATUS VBoxMRxCollapseOpen(IN OUT PRX_CONTEXT RxContext)
872{
873 RT_NOREF(RxContext);
874 Log(("VBOXSF: MRxCollapseOpen\n"));
875 return STATUS_MORE_PROCESSING_REQUIRED;
876}
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