1 | /** @file
|
---|
2 | *
|
---|
3 | * VirtualBox Windows Guest Shared Folders
|
---|
4 | *
|
---|
5 | * File System Driver path related routines
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2012 Oracle Corporation
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | * available from http://www.virtualbox.org. This file is free software;
|
---|
13 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | * General Public License (GPL) as published by the Free Software
|
---|
15 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | */
|
---|
19 |
|
---|
20 | #include "vbsf.h"
|
---|
21 |
|
---|
22 | static UNICODE_STRING UnicodeBackslash = { 2, 4, L"\\" };
|
---|
23 |
|
---|
24 | static NTSTATUS vbsfProcessCreate(PRX_CONTEXT RxContext,
|
---|
25 | PUNICODE_STRING RemainingName,
|
---|
26 | FILE_BASIC_INFORMATION *pFileBasicInfo,
|
---|
27 | FILE_STANDARD_INFORMATION *pFileStandardInfo,
|
---|
28 | PVOID EaBuffer,
|
---|
29 | ULONG EaLength,
|
---|
30 | ULONG *pulCreateAction,
|
---|
31 | SHFLHANDLE *pHandle)
|
---|
32 | {
|
---|
33 | NTSTATUS Status = STATUS_SUCCESS;
|
---|
34 |
|
---|
35 | RxCaptureFcb;
|
---|
36 |
|
---|
37 | PMRX_VBOX_DEVICE_EXTENSION pDeviceExtension = VBoxMRxGetDeviceExtension(RxContext);
|
---|
38 | PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension = VBoxMRxGetNetRootExtension(capFcb->pNetRoot);
|
---|
39 |
|
---|
40 | int vboxRC = VINF_SUCCESS;
|
---|
41 |
|
---|
42 | /* Various boolean flags. */
|
---|
43 | struct
|
---|
44 | {
|
---|
45 | ULONG CreateDirectory :1;
|
---|
46 | ULONG OpenDirectory :1;
|
---|
47 | ULONG DirectoryFile :1;
|
---|
48 | ULONG NonDirectoryFile :1;
|
---|
49 | ULONG DeleteOnClose :1;
|
---|
50 | ULONG TemporaryFile :1;
|
---|
51 | } bf;
|
---|
52 |
|
---|
53 | ACCESS_MASK DesiredAccess;
|
---|
54 | ULONG Options;
|
---|
55 | UCHAR FileAttributes;
|
---|
56 | ULONG ShareAccess;
|
---|
57 | ULONG CreateDisposition;
|
---|
58 | SHFLCREATEPARMS *pCreateParms = NULL;
|
---|
59 |
|
---|
60 | if (EaLength)
|
---|
61 | {
|
---|
62 | Log(("VBOXSF: vbsfProcessCreate: Unsupported: extended attributes!\n"));
|
---|
63 | Status = STATUS_NOT_SUPPORTED;
|
---|
64 | goto failure;
|
---|
65 | }
|
---|
66 |
|
---|
67 | if (BooleanFlagOn(capFcb->FcbState, FCB_STATE_PAGING_FILE))
|
---|
68 | {
|
---|
69 | Log(("VBOXSF: vbsfProcessCreate: Unsupported: paging file!\n"));
|
---|
70 | Status = STATUS_NOT_IMPLEMENTED;
|
---|
71 | goto failure;
|
---|
72 | }
|
---|
73 |
|
---|
74 | Log(("VBOXSF: vbsfProcessCreate: FileAttributes = 0x%08x\n",
|
---|
75 | RxContext->Create.NtCreateParameters.FileAttributes));
|
---|
76 | Log(("VBOXSF: vbsfProcessCreate: CreateOptions = 0x%08x\n",
|
---|
77 | RxContext->Create.NtCreateParameters.CreateOptions));
|
---|
78 |
|
---|
79 | RtlZeroMemory (&bf, sizeof (bf));
|
---|
80 |
|
---|
81 | DesiredAccess = RxContext->Create.NtCreateParameters.DesiredAccess;
|
---|
82 | Options = RxContext->Create.NtCreateParameters.CreateOptions & FILE_VALID_OPTION_FLAGS;
|
---|
83 | FileAttributes = (UCHAR)(RxContext->Create.NtCreateParameters.FileAttributes & ~FILE_ATTRIBUTE_NORMAL);
|
---|
84 | ShareAccess = RxContext->Create.NtCreateParameters.ShareAccess;
|
---|
85 |
|
---|
86 | /* We do not support opens by file ids. */
|
---|
87 | if (FlagOn(Options, FILE_OPEN_BY_FILE_ID))
|
---|
88 | {
|
---|
89 | Log(("VBOXSF: vbsfProcessCreate: Unsupported: file open by id!\n"));
|
---|
90 | Status = STATUS_NOT_IMPLEMENTED;
|
---|
91 | goto failure;
|
---|
92 | }
|
---|
93 |
|
---|
94 | /* Mask out unsupported attribute bits. */
|
---|
95 | FileAttributes &= (FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_ARCHIVE);
|
---|
96 |
|
---|
97 | bf.DirectoryFile = BooleanFlagOn(Options, FILE_DIRECTORY_FILE);
|
---|
98 | bf.NonDirectoryFile = BooleanFlagOn(Options, FILE_NON_DIRECTORY_FILE);
|
---|
99 | bf.DeleteOnClose = BooleanFlagOn(Options, FILE_DELETE_ON_CLOSE);
|
---|
100 | if (bf.DeleteOnClose)
|
---|
101 | Log(("VBOXSF: vbsfProcessCreate: Delete on close!\n"));
|
---|
102 |
|
---|
103 | CreateDisposition = RxContext->Create.NtCreateParameters.Disposition;
|
---|
104 |
|
---|
105 | bf.CreateDirectory = (BOOLEAN)(bf.DirectoryFile && ((CreateDisposition == FILE_CREATE) || (CreateDisposition == FILE_OPEN_IF)));
|
---|
106 | bf.OpenDirectory = (BOOLEAN)(bf.DirectoryFile && ((CreateDisposition == FILE_OPEN) || (CreateDisposition == FILE_OPEN_IF)));
|
---|
107 | bf.TemporaryFile = BooleanFlagOn(RxContext->Create.NtCreateParameters.FileAttributes, FILE_ATTRIBUTE_TEMPORARY);
|
---|
108 |
|
---|
109 | if (FlagOn(capFcb->FcbState, FCB_STATE_TEMPORARY))
|
---|
110 | bf.TemporaryFile = TRUE;
|
---|
111 |
|
---|
112 | Log(("VBOXSF: vbsfProcessCreate: bf.TemporaryFile %d, bf.CreateDirectory %d, bf.DirectoryFile = %d\n",
|
---|
113 | (ULONG)bf.TemporaryFile, (ULONG)bf.CreateDirectory, (ULONG)bf.DirectoryFile));
|
---|
114 |
|
---|
115 | /* Check consistency in specified flags. */
|
---|
116 | if (bf.TemporaryFile && bf.CreateDirectory) /* Directories with temporary flag set are not allowed! */
|
---|
117 | {
|
---|
118 | Log(("VBOXSF: vbsfProcessCreate: Not allowed: Temporary directories!\n"));
|
---|
119 | Status = STATUS_INVALID_PARAMETER;
|
---|
120 | goto failure;
|
---|
121 | }
|
---|
122 |
|
---|
123 | if (bf.DirectoryFile && bf.NonDirectoryFile)
|
---|
124 | {
|
---|
125 | Log(("VBOXSF: vbsfProcessCreate: Unsupported combination: dir && !dir\n"));
|
---|
126 | Status = STATUS_INVALID_PARAMETER;
|
---|
127 | goto failure;
|
---|
128 | }
|
---|
129 |
|
---|
130 | /* Initialize create parameters. */
|
---|
131 | pCreateParms = (SHFLCREATEPARMS *)vbsfAllocNonPagedMem(sizeof(SHFLCREATEPARMS));
|
---|
132 | if (!pCreateParms)
|
---|
133 | {
|
---|
134 | Status = STATUS_INSUFFICIENT_RESOURCES;
|
---|
135 | goto failure;
|
---|
136 | }
|
---|
137 |
|
---|
138 | RtlZeroMemory(pCreateParms, sizeof (SHFLCREATEPARMS));
|
---|
139 |
|
---|
140 | pCreateParms->Handle = SHFL_HANDLE_NIL;
|
---|
141 | pCreateParms->Result = SHFL_NO_RESULT;
|
---|
142 |
|
---|
143 | if (bf.DirectoryFile)
|
---|
144 | {
|
---|
145 | if (CreateDisposition != FILE_CREATE && CreateDisposition != FILE_OPEN && CreateDisposition != FILE_OPEN_IF)
|
---|
146 | {
|
---|
147 | Log(("VBOXSF: vbsfProcessCreate: Invalid disposition 0x%08X for directory!\n",
|
---|
148 | CreateDisposition));
|
---|
149 | Status = STATUS_INVALID_PARAMETER;
|
---|
150 | goto failure;
|
---|
151 | }
|
---|
152 |
|
---|
153 | pCreateParms->CreateFlags |= SHFL_CF_DIRECTORY;
|
---|
154 | }
|
---|
155 |
|
---|
156 | Log(("VBOXSF: vbsfProcessCreate: CreateDisposition = 0x%08X\n",
|
---|
157 | CreateDisposition));
|
---|
158 |
|
---|
159 | switch (CreateDisposition)
|
---|
160 | {
|
---|
161 | case FILE_SUPERSEDE:
|
---|
162 | pCreateParms->CreateFlags |= SHFL_CF_ACT_REPLACE_IF_EXISTS | SHFL_CF_ACT_CREATE_IF_NEW;
|
---|
163 | Log(("VBOXSF: vbsfProcessCreate: CreateFlags |= SHFL_CF_ACT_REPLACE_IF_EXISTS | SHFL_CF_ACT_CREATE_IF_NEW\n"));
|
---|
164 | break;
|
---|
165 |
|
---|
166 | case FILE_OPEN:
|
---|
167 | pCreateParms->CreateFlags |= SHFL_CF_ACT_OPEN_IF_EXISTS | SHFL_CF_ACT_FAIL_IF_NEW;
|
---|
168 | Log(("VBOXSF: vbsfProcessCreate: CreateFlags |= SHFL_CF_ACT_OPEN_IF_EXISTS | SHFL_CF_ACT_FAIL_IF_NEW\n"));
|
---|
169 | break;
|
---|
170 |
|
---|
171 | case FILE_CREATE:
|
---|
172 | pCreateParms->CreateFlags |= SHFL_CF_ACT_FAIL_IF_EXISTS | SHFL_CF_ACT_CREATE_IF_NEW;
|
---|
173 | Log(("VBOXSF: vbsfProcessCreate: CreateFlags |= SHFL_CF_ACT_FAIL_IF_EXISTS | SHFL_CF_ACT_CREATE_IF_NEW\n"));
|
---|
174 | break;
|
---|
175 |
|
---|
176 | case FILE_OPEN_IF:
|
---|
177 | pCreateParms->CreateFlags |= SHFL_CF_ACT_OPEN_IF_EXISTS | SHFL_CF_ACT_CREATE_IF_NEW;
|
---|
178 | Log(("VBOXSF: vbsfProcessCreate: CreateFlags |= SHFL_CF_ACT_OPEN_IF_EXISTS | SHFL_CF_ACT_CREATE_IF_NEW\n"));
|
---|
179 | break;
|
---|
180 |
|
---|
181 | case FILE_OVERWRITE:
|
---|
182 | pCreateParms->CreateFlags |= SHFL_CF_ACT_OVERWRITE_IF_EXISTS | SHFL_CF_ACT_FAIL_IF_NEW;
|
---|
183 | Log(("VBOXSF: vbsfProcessCreate: CreateFlags |= SHFL_CF_ACT_OVERWRITE_IF_EXISTS | SHFL_CF_ACT_FAIL_IF_NEW\n"));
|
---|
184 | break;
|
---|
185 |
|
---|
186 | case FILE_OVERWRITE_IF:
|
---|
187 | pCreateParms->CreateFlags |= SHFL_CF_ACT_OVERWRITE_IF_EXISTS | SHFL_CF_ACT_CREATE_IF_NEW;
|
---|
188 | Log(("VBOXSF: vbsfProcessCreate: CreateFlags |= SHFL_CF_ACT_OVERWRITE_IF_EXISTS | SHFL_CF_ACT_CREATE_IF_NEW\n"));
|
---|
189 | break;
|
---|
190 |
|
---|
191 | default:
|
---|
192 | Log(("VBOXSF: vbsfProcessCreate: Unexpected create disposition: 0x%08X\n",
|
---|
193 | CreateDisposition));
|
---|
194 | Status = STATUS_INVALID_PARAMETER;
|
---|
195 | goto failure;
|
---|
196 | }
|
---|
197 |
|
---|
198 | Log(("VBOXSF: vbsfProcessCreate: DesiredAccess = 0x%08X\n",
|
---|
199 | DesiredAccess));
|
---|
200 | Log(("VBOXSF: vbsfProcessCreate: ShareAccess = 0x%08X\n",
|
---|
201 | ShareAccess));
|
---|
202 |
|
---|
203 | if (DesiredAccess & FILE_READ_DATA)
|
---|
204 | {
|
---|
205 | Log(("VBOXSF: vbsfProcessCreate: FILE_READ_DATA\n"));
|
---|
206 | pCreateParms->CreateFlags |= SHFL_CF_ACCESS_READ;
|
---|
207 | }
|
---|
208 |
|
---|
209 | if (DesiredAccess & FILE_WRITE_DATA)
|
---|
210 | {
|
---|
211 | Log(("VBOXSF: vbsfProcessCreate: FILE_WRITE_DATA\n"));
|
---|
212 | /* FILE_WRITE_DATA means write access regardless of FILE_APPEND_DATA bit.
|
---|
213 | */
|
---|
214 | pCreateParms->CreateFlags |= SHFL_CF_ACCESS_WRITE;
|
---|
215 | }
|
---|
216 | else if (DesiredAccess & FILE_APPEND_DATA)
|
---|
217 | {
|
---|
218 | Log(("VBOXSF: vbsfProcessCreate: FILE_APPEND_DATA\n"));
|
---|
219 | /* FILE_APPEND_DATA without FILE_WRITE_DATA means append only mode.
|
---|
220 | *
|
---|
221 | * Both write and append access flags are required for shared folders,
|
---|
222 | * as on Windows FILE_APPEND_DATA implies write access.
|
---|
223 | */
|
---|
224 | pCreateParms->CreateFlags |= SHFL_CF_ACCESS_WRITE | SHFL_CF_ACCESS_APPEND;
|
---|
225 | }
|
---|
226 |
|
---|
227 | if (DesiredAccess & FILE_READ_ATTRIBUTES)
|
---|
228 | pCreateParms->CreateFlags |= SHFL_CF_ACCESS_ATTR_READ;
|
---|
229 | if (DesiredAccess & FILE_WRITE_ATTRIBUTES)
|
---|
230 | pCreateParms->CreateFlags |= SHFL_CF_ACCESS_ATTR_WRITE;
|
---|
231 |
|
---|
232 | if (ShareAccess & (FILE_SHARE_READ | FILE_SHARE_WRITE))
|
---|
233 | pCreateParms->CreateFlags |= SHFL_CF_ACCESS_DENYNONE;
|
---|
234 | else if (ShareAccess & FILE_SHARE_READ)
|
---|
235 | pCreateParms->CreateFlags |= SHFL_CF_ACCESS_DENYWRITE;
|
---|
236 | else if (ShareAccess & FILE_SHARE_WRITE)
|
---|
237 | pCreateParms->CreateFlags |= SHFL_CF_ACCESS_DENYREAD;
|
---|
238 | else pCreateParms->CreateFlags |= SHFL_CF_ACCESS_DENYALL;
|
---|
239 |
|
---|
240 | /* Set initial allocation size. */
|
---|
241 | pCreateParms->Info.cbObject = RxContext->Create.NtCreateParameters.AllocationSize.QuadPart;
|
---|
242 |
|
---|
243 | if (FileAttributes == 0)
|
---|
244 | FileAttributes = FILE_ATTRIBUTE_NORMAL;
|
---|
245 |
|
---|
246 | pCreateParms->Info.Attr.fMode = NTToVBoxFileAttributes(FileAttributes);
|
---|
247 |
|
---|
248 | {
|
---|
249 | PSHFLSTRING ParsedPath;
|
---|
250 | ULONG ParsedPathSize;
|
---|
251 |
|
---|
252 | /* Calculate length required for parsed path.
|
---|
253 | */
|
---|
254 | ParsedPathSize = sizeof(*ParsedPath) + (RemainingName->Length + sizeof(WCHAR));
|
---|
255 |
|
---|
256 | Log(("VBOXSF: vbsfProcessCreate: ParsedPathSize = %d\n",
|
---|
257 | ParsedPathSize));
|
---|
258 |
|
---|
259 | ParsedPath = (PSHFLSTRING)vbsfAllocNonPagedMem(ParsedPathSize);
|
---|
260 | if (ParsedPath == NULL)
|
---|
261 | {
|
---|
262 | Status = STATUS_INSUFFICIENT_RESOURCES;
|
---|
263 | goto failure;
|
---|
264 | }
|
---|
265 |
|
---|
266 | ShflStringInitBuffer(ParsedPath, ParsedPathSize - sizeof(SHFLSTRING));
|
---|
267 |
|
---|
268 | ParsedPath->u16Size = RemainingName->Length + sizeof(WCHAR);
|
---|
269 | ParsedPath->u16Length = ParsedPath->u16Size - sizeof(WCHAR); /* without terminating null */
|
---|
270 | RtlCopyMemory (ParsedPath->String.ucs2, RemainingName->Buffer, ParsedPath->u16Length);
|
---|
271 | Log(("VBOXSF: ParsedPath: %.*ls\n",
|
---|
272 | ParsedPath->u16Length / sizeof(WCHAR), ParsedPath->String.ucs2));
|
---|
273 |
|
---|
274 | /* Call host. */
|
---|
275 | Log(("VBOXSF: vbsfProcessCreate: vboxCallCreate called.\n"));
|
---|
276 | vboxRC = vboxCallCreate(&pDeviceExtension->hgcmClient, &pNetRootExtension->map, ParsedPath, pCreateParms);
|
---|
277 |
|
---|
278 | vbsfFreeNonPagedMem(ParsedPath);
|
---|
279 | }
|
---|
280 |
|
---|
281 | Log(("VBOXSF: vbsfProcessCreate: vboxCallCreate returns vboxRC = %Rrc, Result = 0x%x\n",
|
---|
282 | vboxRC, pCreateParms->Result));
|
---|
283 |
|
---|
284 | if (RT_FAILURE(vboxRC))
|
---|
285 | {
|
---|
286 | /* Map some VBoxRC to STATUS codes expected by the system. */
|
---|
287 | switch (vboxRC)
|
---|
288 | {
|
---|
289 | case VERR_ALREADY_EXISTS:
|
---|
290 | {
|
---|
291 | *pulCreateAction = FILE_EXISTS;
|
---|
292 | Status = STATUS_OBJECT_NAME_COLLISION;
|
---|
293 | goto failure;
|
---|
294 | } break;
|
---|
295 |
|
---|
296 | /* On POSIX systems, the "mkdir" command returns VERR_FILE_NOT_FOUND when
|
---|
297 | doing a recursive directory create. Handle this case. */
|
---|
298 | case VERR_FILE_NOT_FOUND:
|
---|
299 | {
|
---|
300 | pCreateParms->Result = SHFL_PATH_NOT_FOUND;
|
---|
301 | } break;
|
---|
302 |
|
---|
303 | default:
|
---|
304 | {
|
---|
305 | *pulCreateAction = FILE_DOES_NOT_EXIST;
|
---|
306 | Status = VBoxErrorToNTStatus(vboxRC);
|
---|
307 | goto failure;
|
---|
308 | } break;
|
---|
309 | }
|
---|
310 | }
|
---|
311 |
|
---|
312 | /*
|
---|
313 | * The request succeeded. Analyze host response,
|
---|
314 | */
|
---|
315 | switch (pCreateParms->Result)
|
---|
316 | {
|
---|
317 | case SHFL_PATH_NOT_FOUND:
|
---|
318 | {
|
---|
319 | /* Path to object does not exist. */
|
---|
320 | Log(("VBOXSF: vbsfProcessCreate: Path not found\n"));
|
---|
321 | *pulCreateAction = FILE_DOES_NOT_EXIST;
|
---|
322 | Status = STATUS_OBJECT_PATH_NOT_FOUND;
|
---|
323 | goto failure;
|
---|
324 | }
|
---|
325 |
|
---|
326 | case SHFL_FILE_NOT_FOUND:
|
---|
327 | {
|
---|
328 | Log(("VBOXSF: vbsfProcessCreate: File not found\n"));
|
---|
329 | *pulCreateAction = FILE_DOES_NOT_EXIST;
|
---|
330 | if (pCreateParms->Handle == SHFL_HANDLE_NIL)
|
---|
331 | {
|
---|
332 | Status = STATUS_OBJECT_NAME_NOT_FOUND;
|
---|
333 | goto failure;
|
---|
334 | }
|
---|
335 |
|
---|
336 | Log(("VBOXSF: vbsfProcessCreate: File not found but have a handle!\n"));
|
---|
337 | Status = STATUS_UNSUCCESSFUL;
|
---|
338 | goto failure;
|
---|
339 |
|
---|
340 | break;
|
---|
341 | }
|
---|
342 |
|
---|
343 | case SHFL_FILE_EXISTS:
|
---|
344 | {
|
---|
345 | Log(("VBOXSF: vbsfProcessCreate: File exists, Handle = 0x%RX64\n",
|
---|
346 | pCreateParms->Handle));
|
---|
347 | if (pCreateParms->Handle == SHFL_HANDLE_NIL)
|
---|
348 | {
|
---|
349 | *pulCreateAction = FILE_EXISTS;
|
---|
350 | if (CreateDisposition == FILE_CREATE)
|
---|
351 | {
|
---|
352 | /* File was not opened because we requested a create. */
|
---|
353 | Status = STATUS_OBJECT_NAME_COLLISION;
|
---|
354 | goto failure;
|
---|
355 | }
|
---|
356 |
|
---|
357 | /* Actually we should not go here, unless we have no rights to open the object. */
|
---|
358 | Log(("VBOXSF: vbsfProcessCreate: Existing file was not opened!\n"));
|
---|
359 | Status = STATUS_ACCESS_DENIED;
|
---|
360 | goto failure;
|
---|
361 | }
|
---|
362 |
|
---|
363 | *pulCreateAction = FILE_OPENED;
|
---|
364 |
|
---|
365 | /* Existing file was opened. Go check flags and create FCB. */
|
---|
366 | break;
|
---|
367 | }
|
---|
368 |
|
---|
369 | case SHFL_FILE_CREATED:
|
---|
370 | {
|
---|
371 | /* A new file was created. */
|
---|
372 |
|
---|
373 | Assert(pCreateParms->Handle != SHFL_HANDLE_NIL);
|
---|
374 |
|
---|
375 | *pulCreateAction = FILE_CREATED;
|
---|
376 |
|
---|
377 | /* Go check flags and create FCB. */
|
---|
378 | break;
|
---|
379 | }
|
---|
380 |
|
---|
381 | case SHFL_FILE_REPLACED:
|
---|
382 | {
|
---|
383 | /* Existing file was replaced or overwriting. */
|
---|
384 |
|
---|
385 | Assert(pCreateParms->Handle != SHFL_HANDLE_NIL);
|
---|
386 |
|
---|
387 | if (CreateDisposition == FILE_SUPERSEDE)
|
---|
388 | {
|
---|
389 | *pulCreateAction = FILE_SUPERSEDED;
|
---|
390 | }
|
---|
391 | else
|
---|
392 | {
|
---|
393 | *pulCreateAction = FILE_OVERWRITTEN;
|
---|
394 | }
|
---|
395 | /* Go check flags and create FCB. */
|
---|
396 | break;
|
---|
397 | }
|
---|
398 |
|
---|
399 | default:
|
---|
400 | {
|
---|
401 | Log(("VBOXSF: vbsfProcessCreate: Invalid CreateResult from host (0x%08X)\n",
|
---|
402 | pCreateParms->Result));
|
---|
403 | *pulCreateAction = FILE_DOES_NOT_EXIST;
|
---|
404 | Status = STATUS_OBJECT_PATH_NOT_FOUND;
|
---|
405 | goto failure;
|
---|
406 | }
|
---|
407 | }
|
---|
408 |
|
---|
409 | /* Check flags. */
|
---|
410 | if (bf.NonDirectoryFile && FlagOn(pCreateParms->Info.Attr.fMode, RTFS_DOS_DIRECTORY))
|
---|
411 | {
|
---|
412 | /* Caller wanted only a file, but the object is a directory. */
|
---|
413 | Log(("VBOXSF: vbsfProcessCreate: File is a directory!\n"));
|
---|
414 | Status = STATUS_FILE_IS_A_DIRECTORY;
|
---|
415 | goto failure;
|
---|
416 | }
|
---|
417 |
|
---|
418 | if (bf.DirectoryFile && !FlagOn(pCreateParms->Info.Attr.fMode, RTFS_DOS_DIRECTORY))
|
---|
419 | {
|
---|
420 | /* Caller wanted only a directory, but the object is not a directory. */
|
---|
421 | Log(("VBOXSF: vbsfProcessCreate: File is not a directory!\n"));
|
---|
422 | Status = STATUS_NOT_A_DIRECTORY;
|
---|
423 | goto failure;
|
---|
424 | }
|
---|
425 |
|
---|
426 | *pHandle = pCreateParms->Handle;
|
---|
427 |
|
---|
428 | /* Translate attributes */
|
---|
429 | pFileBasicInfo->FileAttributes = VBoxToNTFileAttributes(pCreateParms->Info.Attr.fMode);
|
---|
430 |
|
---|
431 | /* Translate file times */
|
---|
432 | pFileBasicInfo->CreationTime.QuadPart = RTTimeSpecGetNtTime(&pCreateParms->Info.BirthTime); /* ridiculous name */
|
---|
433 | pFileBasicInfo->LastAccessTime.QuadPart = RTTimeSpecGetNtTime(&pCreateParms->Info.AccessTime);
|
---|
434 | pFileBasicInfo->LastWriteTime.QuadPart = RTTimeSpecGetNtTime(&pCreateParms->Info.ModificationTime);
|
---|
435 | pFileBasicInfo->ChangeTime.QuadPart = RTTimeSpecGetNtTime(&pCreateParms->Info.ChangeTime);
|
---|
436 |
|
---|
437 | if (!FlagOn(pCreateParms->Info.Attr.fMode, RTFS_DOS_DIRECTORY))
|
---|
438 | {
|
---|
439 | pFileStandardInfo->AllocationSize.QuadPart = pCreateParms->Info.cbAllocated;
|
---|
440 | pFileStandardInfo->EndOfFile.QuadPart = pCreateParms->Info.cbObject;
|
---|
441 | pFileStandardInfo->Directory = FALSE;
|
---|
442 |
|
---|
443 | Log(("VBOXSF: vbsfProcessCreate: AllocationSize = 0x%RX64, EndOfFile = 0x%RX64\n",
|
---|
444 | pCreateParms->Info.cbAllocated, pCreateParms->Info.cbObject));
|
---|
445 | }
|
---|
446 | else
|
---|
447 | {
|
---|
448 | pFileStandardInfo->AllocationSize.QuadPart = 0;
|
---|
449 | pFileStandardInfo->EndOfFile.QuadPart = 0;
|
---|
450 | pFileStandardInfo->Directory = TRUE;
|
---|
451 | }
|
---|
452 | pFileStandardInfo->NumberOfLinks = 0;
|
---|
453 | pFileStandardInfo->DeletePending = FALSE;
|
---|
454 |
|
---|
455 | vbsfFreeNonPagedMem(pCreateParms);
|
---|
456 |
|
---|
457 | return Status;
|
---|
458 |
|
---|
459 | failure:
|
---|
460 |
|
---|
461 | Log(("VBOXSF: vbsfProcessCreate: Returned with status = 0x%08X\n",
|
---|
462 | Status));
|
---|
463 |
|
---|
464 | if (pCreateParms && pCreateParms->Handle != SHFL_HANDLE_NIL)
|
---|
465 | {
|
---|
466 | vboxCallClose(&pDeviceExtension->hgcmClient, &pNetRootExtension->map, pCreateParms->Handle);
|
---|
467 | *pHandle = SHFL_HANDLE_NIL;
|
---|
468 | }
|
---|
469 |
|
---|
470 | if (pCreateParms)
|
---|
471 | {
|
---|
472 | vbsfFreeNonPagedMem(pCreateParms);
|
---|
473 | }
|
---|
474 |
|
---|
475 | return Status;
|
---|
476 | }
|
---|
477 |
|
---|
478 | NTSTATUS VBoxMRxCreate(IN OUT PRX_CONTEXT RxContext)
|
---|
479 | {
|
---|
480 | NTSTATUS Status = STATUS_SUCCESS;
|
---|
481 |
|
---|
482 | RxCaptureFcb;
|
---|
483 | RxCaptureFobx;
|
---|
484 |
|
---|
485 | PMRX_NET_ROOT pNetRoot = capFcb->pNetRoot;
|
---|
486 | PMRX_SRV_OPEN SrvOpen = RxContext->pRelevantSrvOpen;
|
---|
487 | PUNICODE_STRING RemainingName = GET_ALREADY_PREFIXED_NAME_FROM_CONTEXT(RxContext);
|
---|
488 |
|
---|
489 | FILE_BASIC_INFORMATION FileBasicInfo;
|
---|
490 | FILE_STANDARD_INFORMATION FileStandardInfo;
|
---|
491 |
|
---|
492 | ULONG CreateAction = FILE_CREATED;
|
---|
493 | SHFLHANDLE Handle = SHFL_HANDLE_NIL;
|
---|
494 | PMRX_VBOX_FOBX pVBoxFobx;
|
---|
495 |
|
---|
496 | Log(("VBOXSF: MRxCreate: name ptr %p length=%d, SrvOpen->Flags 0x%08X\n",
|
---|
497 | RemainingName, RemainingName->Length, SrvOpen->Flags));
|
---|
498 |
|
---|
499 | /* Disable FastIO. It causes a verifier bugcheck. */
|
---|
500 | #ifdef SRVOPEN_FLAG_DONTUSE_READ_CACHING
|
---|
501 | SetFlag(SrvOpen->Flags, SRVOPEN_FLAG_DONTUSE_READ_CACHING | SRVOPEN_FLAG_DONTUSE_WRITE_CACHING);
|
---|
502 | #else
|
---|
503 | SetFlag(SrvOpen->Flags, SRVOPEN_FLAG_DONTUSE_READ_CACHEING | SRVOPEN_FLAG_DONTUSE_WRITE_CACHEING);
|
---|
504 | #endif
|
---|
505 |
|
---|
506 | if (RemainingName->Length)
|
---|
507 | {
|
---|
508 | Log(("VBOXSF: MRxCreate: Attempt to open %.*ls\n",
|
---|
509 | RemainingName->Length/sizeof(WCHAR), RemainingName->Buffer));
|
---|
510 | }
|
---|
511 | else
|
---|
512 | {
|
---|
513 | if (FlagOn(RxContext->Create.Flags, RX_CONTEXT_CREATE_FLAG_STRIPPED_TRAILING_BACKSLASH))
|
---|
514 | {
|
---|
515 | Log(("VBOXSF: MRxCreate: Empty name -> Only backslash used\n"));
|
---|
516 | RemainingName = &UnicodeBackslash;
|
---|
517 | }
|
---|
518 | }
|
---|
519 |
|
---|
520 | if ( pNetRoot->Type != NET_ROOT_WILD
|
---|
521 | && pNetRoot->Type != NET_ROOT_DISK)
|
---|
522 | {
|
---|
523 | Log(("VBOXSF: MRxCreate: netroot type %d not supported\n",
|
---|
524 | pNetRoot->Type));
|
---|
525 | Status = STATUS_NOT_IMPLEMENTED;
|
---|
526 | goto Exit;
|
---|
527 | }
|
---|
528 |
|
---|
529 | FileBasicInfo.FileAttributes = FILE_ATTRIBUTE_NORMAL;
|
---|
530 |
|
---|
531 | Status = vbsfProcessCreate(RxContext,
|
---|
532 | RemainingName,
|
---|
533 | &FileBasicInfo,
|
---|
534 | &FileStandardInfo,
|
---|
535 | RxContext->Create.EaBuffer,
|
---|
536 | RxContext->Create.EaLength,
|
---|
537 | &CreateAction,
|
---|
538 | &Handle);
|
---|
539 |
|
---|
540 | if (Status != STATUS_SUCCESS)
|
---|
541 | {
|
---|
542 | Log(("VBOXSF: MRxCreate: vbsfProcessCreate failed 0x%08X\n",
|
---|
543 | Status));
|
---|
544 | goto Exit;
|
---|
545 | }
|
---|
546 |
|
---|
547 | Log(("VBOXSF: MRxCreate: EOF is 0x%RX64 AllocSize is 0x%RX64\n",
|
---|
548 | FileStandardInfo.EndOfFile.QuadPart, FileStandardInfo.AllocationSize.QuadPart));
|
---|
549 |
|
---|
550 | RxContext->pFobx = RxCreateNetFobx(RxContext, SrvOpen);
|
---|
551 | if (RxContext->pFobx == NULL)
|
---|
552 | {
|
---|
553 | Log(("VBOXSF: MRxCreate: RxCreateNetFobx failed\n"));
|
---|
554 | Status = STATUS_INSUFFICIENT_RESOURCES;
|
---|
555 | goto Exit;
|
---|
556 | }
|
---|
557 |
|
---|
558 | Log(("VBOXSF: MRxCreate: CreateAction = 0x%08X\n",
|
---|
559 | CreateAction));
|
---|
560 |
|
---|
561 | RxContext->Create.ReturnedCreateInformation = CreateAction;
|
---|
562 |
|
---|
563 | if (capFcb->OpenCount == 0)
|
---|
564 | {
|
---|
565 | FCB_INIT_PACKET InitPacket;
|
---|
566 | RxFormInitPacket(InitPacket,
|
---|
567 | &FileBasicInfo.FileAttributes,
|
---|
568 | &FileStandardInfo.NumberOfLinks,
|
---|
569 | &FileBasicInfo.CreationTime,
|
---|
570 | &FileBasicInfo.LastAccessTime,
|
---|
571 | &FileBasicInfo.LastWriteTime,
|
---|
572 | &FileBasicInfo.ChangeTime,
|
---|
573 | &FileStandardInfo.AllocationSize,
|
---|
574 | &FileStandardInfo.EndOfFile,
|
---|
575 | &FileStandardInfo.EndOfFile);
|
---|
576 | RxFinishFcbInitialization(capFcb, RDBSS_STORAGE_NTC(FileTypeFile), &InitPacket);
|
---|
577 | }
|
---|
578 |
|
---|
579 | SrvOpen->BufferingFlags = 0;
|
---|
580 |
|
---|
581 | RxContext->pFobx->OffsetOfNextEaToReturn = 1;
|
---|
582 |
|
---|
583 | pVBoxFobx = VBoxMRxGetFileObjectExtension(RxContext->pFobx);
|
---|
584 |
|
---|
585 | Log(("VBOXSF: MRxCreate: VBoxFobx = %p\n",
|
---|
586 | pVBoxFobx));
|
---|
587 |
|
---|
588 | if (!pVBoxFobx)
|
---|
589 | {
|
---|
590 | Log(("VBOXSF: MRxCreate: no VBoxFobx!\n"));
|
---|
591 | AssertFailed();
|
---|
592 | Status = STATUS_INSUFFICIENT_RESOURCES;
|
---|
593 | goto Exit;
|
---|
594 | }
|
---|
595 |
|
---|
596 | Log(("VBOXSF: MRxCreate: FileBasicInformation: CreationTime %RX64\n", FileBasicInfo.CreationTime.QuadPart));
|
---|
597 | Log(("VBOXSF: MRxCreate: FileBasicInformation: LastAccessTime %RX64\n", FileBasicInfo.LastAccessTime.QuadPart));
|
---|
598 | Log(("VBOXSF: MRxCreate: FileBasicInformation: LastWriteTime %RX64\n", FileBasicInfo.LastWriteTime.QuadPart));
|
---|
599 | Log(("VBOXSF: MRxCreate: FileBasicInformation: ChangeTime %RX64\n", FileBasicInfo.ChangeTime.QuadPart));
|
---|
600 | Log(("VBOXSF: MRxCreate: FileBasicInformation: FileAttributes %RX32\n", FileBasicInfo.FileAttributes));
|
---|
601 |
|
---|
602 | pVBoxFobx->hFile = Handle;
|
---|
603 | pVBoxFobx->pSrvCall = RxContext->Create.pSrvCall;
|
---|
604 | pVBoxFobx->FileStandardInfo = FileStandardInfo;
|
---|
605 | pVBoxFobx->FileBasicInfo = FileBasicInfo;
|
---|
606 | pVBoxFobx->fKeepCreationTime = FALSE;
|
---|
607 | pVBoxFobx->fKeepLastAccessTime = FALSE;
|
---|
608 | pVBoxFobx->fKeepLastWriteTime = FALSE;
|
---|
609 | pVBoxFobx->fKeepChangeTime = FALSE;
|
---|
610 | pVBoxFobx->SetFileInfoOnCloseFlags = 0;
|
---|
611 |
|
---|
612 | if (!RxIsFcbAcquiredExclusive(capFcb))
|
---|
613 | {
|
---|
614 | RxAcquireExclusiveFcbResourceInMRx(capFcb);
|
---|
615 | }
|
---|
616 |
|
---|
617 | Log(("VBOXSF: MRxCreate: NetRoot is %p, Fcb is %p, SrvOpen is %p, Fobx is %p\n",
|
---|
618 | pNetRoot, capFcb, SrvOpen, RxContext->pFobx));
|
---|
619 | Log(("VBOXSF: MRxCreate: return 0x%08X\n",
|
---|
620 | Status));
|
---|
621 |
|
---|
622 | Exit:
|
---|
623 | return Status;
|
---|
624 | }
|
---|
625 |
|
---|
626 | NTSTATUS VBoxMRxComputeNewBufferingState(IN OUT PMRX_SRV_OPEN pMRxSrvOpen,
|
---|
627 | IN PVOID pMRxContext,
|
---|
628 | OUT PULONG pNewBufferingState)
|
---|
629 | {
|
---|
630 | Log(("VBOXSF: MRxComputeNewBufferingState\n"));
|
---|
631 | return STATUS_NOT_SUPPORTED;
|
---|
632 | }
|
---|
633 |
|
---|
634 | NTSTATUS VBoxMRxDeallocateForFcb(IN OUT PMRX_FCB pFcb)
|
---|
635 | {
|
---|
636 | Log(("VBOXSF: MRxDeallocateForFcb\n"));
|
---|
637 | return STATUS_SUCCESS;
|
---|
638 | }
|
---|
639 |
|
---|
640 | NTSTATUS VBoxMRxDeallocateForFobx(IN OUT PMRX_FOBX pFobx)
|
---|
641 | {
|
---|
642 | Log(("VBOXSF: MRxDeallocateForFobx\n"));
|
---|
643 | return STATUS_SUCCESS;
|
---|
644 | }
|
---|
645 |
|
---|
646 | NTSTATUS VBoxMRxTruncate(IN PRX_CONTEXT RxContext)
|
---|
647 | {
|
---|
648 | Log(("VBOXSF: MRxTruncate\n"));
|
---|
649 | return STATUS_NOT_IMPLEMENTED;
|
---|
650 | }
|
---|
651 |
|
---|
652 | NTSTATUS VBoxMRxCleanupFobx(IN PRX_CONTEXT RxContext)
|
---|
653 | {
|
---|
654 | PMRX_VBOX_FOBX pVBoxFobx = VBoxMRxGetFileObjectExtension(RxContext->pFobx);
|
---|
655 |
|
---|
656 | Log(("VBOXSF: MRxCleanupFobx: pVBoxFobx = %p, Handle = 0x%RX64\n",
|
---|
657 | pVBoxFobx, pVBoxFobx? pVBoxFobx->hFile: 0));
|
---|
658 |
|
---|
659 | if (NULL == pVBoxFobx)
|
---|
660 | {
|
---|
661 | return STATUS_INVALID_PARAMETER;
|
---|
662 | }
|
---|
663 |
|
---|
664 | return STATUS_SUCCESS;
|
---|
665 | }
|
---|
666 |
|
---|
667 | NTSTATUS VBoxMRxForceClosed(IN PMRX_SRV_OPEN pSrvOpen)
|
---|
668 | {
|
---|
669 | Log(("VBOXSF: MRxForceClosed\n"));
|
---|
670 | return STATUS_NOT_IMPLEMENTED;
|
---|
671 | }
|
---|
672 |
|
---|
673 | NTSTATUS vbsfSetFileInfo(PMRX_VBOX_DEVICE_EXTENSION pDeviceExtension,
|
---|
674 | PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension,
|
---|
675 | PMRX_VBOX_FOBX pVBoxFobx,
|
---|
676 | PFILE_BASIC_INFORMATION pInfo,
|
---|
677 | BYTE SetAttrFlags)
|
---|
678 | {
|
---|
679 | NTSTATUS Status = STATUS_SUCCESS;
|
---|
680 |
|
---|
681 | int vboxRC;
|
---|
682 | PSHFLFSOBJINFO pSHFLFileInfo;
|
---|
683 |
|
---|
684 | uint8_t *pHGCMBuffer = NULL;
|
---|
685 | uint32_t cbBuffer = 0;
|
---|
686 |
|
---|
687 | Log(("VBOXSF: vbsfSetFileInfo: SetAttrFlags 0x%02X\n", SetAttrFlags));
|
---|
688 | Log(("VBOXSF: vbsfSetFileInfo: FileBasicInformation: CreationTime %RX64\n", pInfo->CreationTime.QuadPart));
|
---|
689 | Log(("VBOXSF: vbsfSetFileInfo: FileBasicInformation: LastAccessTime %RX64\n", pInfo->LastAccessTime.QuadPart));
|
---|
690 | Log(("VBOXSF: vbsfSetFileInfo: FileBasicInformation: LastWriteTime %RX64\n", pInfo->LastWriteTime.QuadPart));
|
---|
691 | Log(("VBOXSF: vbsfSetFileInfo: FileBasicInformation: ChangeTime %RX64\n", pInfo->ChangeTime.QuadPart));
|
---|
692 | Log(("VBOXSF: vbsfSetFileInfo: FileBasicInformation: FileAttributes %RX32\n", pInfo->FileAttributes));
|
---|
693 |
|
---|
694 | if (SetAttrFlags == 0)
|
---|
695 | {
|
---|
696 | Log(("VBOXSF: vbsfSetFileInfo: nothing to set\n"));
|
---|
697 | return STATUS_SUCCESS;
|
---|
698 | }
|
---|
699 |
|
---|
700 | cbBuffer = sizeof(SHFLFSOBJINFO);
|
---|
701 | pHGCMBuffer = (uint8_t *)vbsfAllocNonPagedMem(cbBuffer);
|
---|
702 | if (pHGCMBuffer == NULL)
|
---|
703 | {
|
---|
704 | AssertFailed();
|
---|
705 | return STATUS_INSUFFICIENT_RESOURCES;
|
---|
706 | }
|
---|
707 | RtlZeroMemory(pHGCMBuffer, cbBuffer);
|
---|
708 | pSHFLFileInfo = (PSHFLFSOBJINFO)pHGCMBuffer;
|
---|
709 |
|
---|
710 | /* The properties, that need to be changed, are set to something other than zero */
|
---|
711 | if (pInfo->CreationTime.QuadPart && (SetAttrFlags & VBOX_FOBX_F_INFO_CREATION_TIME) != 0)
|
---|
712 | {
|
---|
713 | RTTimeSpecSetNtTime(&pSHFLFileInfo->BirthTime, pInfo->CreationTime.QuadPart);
|
---|
714 | }
|
---|
715 | if (pInfo->LastAccessTime.QuadPart && (SetAttrFlags & VBOX_FOBX_F_INFO_LASTACCESS_TIME) != 0)
|
---|
716 | {
|
---|
717 | RTTimeSpecSetNtTime(&pSHFLFileInfo->AccessTime, pInfo->LastAccessTime.QuadPart);
|
---|
718 | }
|
---|
719 | if (pInfo->LastWriteTime.QuadPart && (SetAttrFlags & VBOX_FOBX_F_INFO_LASTWRITE_TIME) != 0)
|
---|
720 | {
|
---|
721 | RTTimeSpecSetNtTime(&pSHFLFileInfo->ModificationTime, pInfo->LastWriteTime.QuadPart);
|
---|
722 | }
|
---|
723 | if (pInfo->ChangeTime.QuadPart && (SetAttrFlags & VBOX_FOBX_F_INFO_CHANGE_TIME) != 0)
|
---|
724 | {
|
---|
725 | RTTimeSpecSetNtTime(&pSHFLFileInfo->ChangeTime, pInfo->ChangeTime.QuadPart);
|
---|
726 | }
|
---|
727 | if (pInfo->FileAttributes && (SetAttrFlags & VBOX_FOBX_F_INFO_ATTRIBUTES) != 0)
|
---|
728 | {
|
---|
729 | pSHFLFileInfo->Attr.fMode = NTToVBoxFileAttributes(pInfo->FileAttributes);
|
---|
730 | }
|
---|
731 |
|
---|
732 | vboxRC = vboxCallFSInfo(&pDeviceExtension->hgcmClient, &pNetRootExtension->map, pVBoxFobx->hFile,
|
---|
733 | SHFL_INFO_SET | SHFL_INFO_FILE, &cbBuffer, (PSHFLDIRINFO)pSHFLFileInfo);
|
---|
734 |
|
---|
735 | if (vboxRC != VINF_SUCCESS)
|
---|
736 | {
|
---|
737 | Status = VBoxErrorToNTStatus(vboxRC);
|
---|
738 | }
|
---|
739 |
|
---|
740 | if (pHGCMBuffer)
|
---|
741 | {
|
---|
742 | vbsfFreeNonPagedMem(pHGCMBuffer);
|
---|
743 | }
|
---|
744 |
|
---|
745 | Log(("VBOXSF: vbsfSetFileInfo: Returned 0x%08X\n",
|
---|
746 | Status));
|
---|
747 | return Status;
|
---|
748 | }
|
---|
749 |
|
---|
750 | /*
|
---|
751 | * Closes an opened file handle of a MRX_VBOX_FOBX.
|
---|
752 | * Updates file attributes if necessary.
|
---|
753 | */
|
---|
754 | NTSTATUS vbsfCloseFileHandle(PMRX_VBOX_DEVICE_EXTENSION pDeviceExtension,
|
---|
755 | PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension,
|
---|
756 | PMRX_VBOX_FOBX pVBoxFobx)
|
---|
757 | {
|
---|
758 | NTSTATUS Status = STATUS_SUCCESS;
|
---|
759 |
|
---|
760 | int vboxRC;
|
---|
761 |
|
---|
762 | if (pVBoxFobx->hFile == SHFL_HANDLE_NIL)
|
---|
763 | {
|
---|
764 | Log(("VBOXSF: vbsfCloseFileHandle: SHFL_HANDLE_NIL\n"));
|
---|
765 | return STATUS_SUCCESS;
|
---|
766 | }
|
---|
767 |
|
---|
768 | Log(("VBOXSF: vbsfCloseFileHandle: 0x%RX64, on close info 0x%02X\n",
|
---|
769 | pVBoxFobx->hFile, pVBoxFobx->SetFileInfoOnCloseFlags));
|
---|
770 |
|
---|
771 | if (pVBoxFobx->SetFileInfoOnCloseFlags)
|
---|
772 | {
|
---|
773 | /* If the file timestamps were set by the user, then update them before closing the handle,
|
---|
774 | * to cancel any effect of the file read/write operations on the host.
|
---|
775 | */
|
---|
776 | Status = vbsfSetFileInfo(pDeviceExtension,
|
---|
777 | pNetRootExtension,
|
---|
778 | pVBoxFobx,
|
---|
779 | &pVBoxFobx->FileBasicInfo,
|
---|
780 | pVBoxFobx->SetFileInfoOnCloseFlags);
|
---|
781 | }
|
---|
782 |
|
---|
783 | vboxRC = vboxCallClose(&pDeviceExtension->hgcmClient,
|
---|
784 | &pNetRootExtension->map,
|
---|
785 | pVBoxFobx->hFile);
|
---|
786 |
|
---|
787 | pVBoxFobx->hFile = SHFL_HANDLE_NIL;
|
---|
788 |
|
---|
789 | if (vboxRC != VINF_SUCCESS)
|
---|
790 | {
|
---|
791 | Status = VBoxErrorToNTStatus(vboxRC);
|
---|
792 | }
|
---|
793 |
|
---|
794 | Log(("VBOXSF: vbsfCloseFileHandle: Returned 0x%08X\n",
|
---|
795 | Status));
|
---|
796 | return Status;
|
---|
797 | }
|
---|
798 |
|
---|
799 | NTSTATUS VBoxMRxCloseSrvOpen(IN PRX_CONTEXT RxContext)
|
---|
800 | {
|
---|
801 | NTSTATUS Status = STATUS_SUCCESS;
|
---|
802 |
|
---|
803 | RxCaptureFcb;
|
---|
804 | RxCaptureFobx;
|
---|
805 |
|
---|
806 | PMRX_VBOX_DEVICE_EXTENSION pDeviceExtension = VBoxMRxGetDeviceExtension(RxContext);
|
---|
807 | PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension = VBoxMRxGetNetRootExtension(capFcb->pNetRoot);
|
---|
808 | PMRX_VBOX_FOBX pVBoxFobx = VBoxMRxGetFileObjectExtension(capFobx);
|
---|
809 | PMRX_SRV_OPEN pSrvOpen = capFobx->pSrvOpen;
|
---|
810 |
|
---|
811 | int vboxRC = 0;
|
---|
812 | PUNICODE_STRING RemainingName = NULL;
|
---|
813 |
|
---|
814 | Log(("VBOXSF: MRxCloseSrvOpen: capFcb = %p, capFobx = %p, pVBoxFobx = %p, pSrvOpen = %p\n",
|
---|
815 | capFcb, capFobx, pVBoxFobx, pSrvOpen));
|
---|
816 |
|
---|
817 | RemainingName = pSrvOpen->pAlreadyPrefixedName;
|
---|
818 |
|
---|
819 | Log(("VBOXSF: MRxCloseSrvOpen: Remaining name = %.*ls, Len = %d\n",
|
---|
820 | RemainingName->Length / sizeof(WCHAR), RemainingName->Buffer, RemainingName->Length));
|
---|
821 |
|
---|
822 | if (NULL == pVBoxFobx)
|
---|
823 | {
|
---|
824 | return STATUS_INVALID_PARAMETER;
|
---|
825 | }
|
---|
826 |
|
---|
827 | if (FlagOn(pSrvOpen->Flags, (SRVOPEN_FLAG_FILE_RENAMED | SRVOPEN_FLAG_FILE_DELETED)))
|
---|
828 | {
|
---|
829 | /* If we renamed or delete the file/dir, then it's already closed */
|
---|
830 | Assert(pVBoxFobx->hFile == SHFL_HANDLE_NIL);
|
---|
831 | Log(("VBOXSF: MRxCloseSrvOpen: File was renamed, handle 0x%RX64 ignore close.\n",
|
---|
832 | pVBoxFobx->hFile));
|
---|
833 | return STATUS_SUCCESS;
|
---|
834 | }
|
---|
835 |
|
---|
836 | /* Close file */
|
---|
837 | if (pVBoxFobx->hFile != SHFL_HANDLE_NIL)
|
---|
838 | {
|
---|
839 | vbsfCloseFileHandle(pDeviceExtension, pNetRootExtension, pVBoxFobx);
|
---|
840 | }
|
---|
841 |
|
---|
842 | if (capFcb->FcbState & FCB_STATE_DELETE_ON_CLOSE)
|
---|
843 | {
|
---|
844 | Log(("VBOXSF: MRxCloseSrvOpen: Delete on close. Open count = %d\n",
|
---|
845 | capFcb->OpenCount));
|
---|
846 |
|
---|
847 | /* Remove file or directory if delete action is pending. */
|
---|
848 | if (capFcb->OpenCount == 0)
|
---|
849 | {
|
---|
850 | Status = vbsfRemove(RxContext);
|
---|
851 | }
|
---|
852 | }
|
---|
853 |
|
---|
854 | return Status;
|
---|
855 | }
|
---|
856 |
|
---|
857 | NTSTATUS vbsfRemove(IN PRX_CONTEXT RxContext)
|
---|
858 | {
|
---|
859 | NTSTATUS Status = STATUS_SUCCESS;
|
---|
860 |
|
---|
861 | RxCaptureFcb;
|
---|
862 | RxCaptureFobx;
|
---|
863 |
|
---|
864 | PMRX_VBOX_DEVICE_EXTENSION pDeviceExtension = VBoxMRxGetDeviceExtension(RxContext);
|
---|
865 | PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension = VBoxMRxGetNetRootExtension(capFcb->pNetRoot);
|
---|
866 | PMRX_VBOX_FOBX pVBoxFobx = VBoxMRxGetFileObjectExtension(capFobx);
|
---|
867 |
|
---|
868 | PUNICODE_STRING RemainingName = GET_ALREADY_PREFIXED_NAME_FROM_CONTEXT(RxContext);
|
---|
869 |
|
---|
870 | int vboxRC;
|
---|
871 | PSHFLSTRING ParsedPath = NULL;
|
---|
872 | ULONG ParsedPathSize;
|
---|
873 |
|
---|
874 | Log(("VBOXSF: vbsfRemove: Delete %.*ls. open count = %d\n",
|
---|
875 | RemainingName->Length / sizeof(WCHAR), RemainingName->Buffer, capFcb->OpenCount));
|
---|
876 |
|
---|
877 | /* Close file first if not already done. */
|
---|
878 | if (pVBoxFobx->hFile != SHFL_HANDLE_NIL)
|
---|
879 | {
|
---|
880 | vbsfCloseFileHandle(pDeviceExtension, pNetRootExtension, pVBoxFobx);
|
---|
881 | }
|
---|
882 |
|
---|
883 | /* Calculate length required for parsed path.
|
---|
884 | */
|
---|
885 | ParsedPathSize = sizeof(*ParsedPath) + (RemainingName->Length + sizeof(WCHAR));
|
---|
886 |
|
---|
887 | Log(("VBOXSF: vbsfRemove: ParsedPathSize %d\n",
|
---|
888 | ParsedPathSize));
|
---|
889 |
|
---|
890 | ParsedPath = (PSHFLSTRING)vbsfAllocNonPagedMem(ParsedPathSize);
|
---|
891 | if (!ParsedPath)
|
---|
892 | {
|
---|
893 | return STATUS_INSUFFICIENT_RESOURCES;
|
---|
894 | }
|
---|
895 |
|
---|
896 | ShflStringInitBuffer(ParsedPath, ParsedPathSize - sizeof(SHFLSTRING));
|
---|
897 |
|
---|
898 | Log(("VBOXSF: vbsfRemove: Setup ParsedPath\n"));
|
---|
899 | ParsedPath->u16Size = RemainingName->Length + sizeof(WCHAR);
|
---|
900 | ParsedPath->u16Length = ParsedPath->u16Size - sizeof(WCHAR); /* without terminating null */
|
---|
901 | RtlCopyMemory(ParsedPath->String.ucs2, RemainingName->Buffer, ParsedPath->u16Length);
|
---|
902 |
|
---|
903 | /* Call host. */
|
---|
904 | vboxRC = vboxCallRemove(&pDeviceExtension->hgcmClient, &pNetRootExtension->map,
|
---|
905 | ParsedPath,
|
---|
906 | (pVBoxFobx->FileStandardInfo.Directory) ? SHFL_REMOVE_DIR : SHFL_REMOVE_FILE);
|
---|
907 |
|
---|
908 | if (ParsedPath)
|
---|
909 | {
|
---|
910 | vbsfFreeNonPagedMem(ParsedPath);
|
---|
911 | }
|
---|
912 |
|
---|
913 | if (vboxRC == VINF_SUCCESS)
|
---|
914 | {
|
---|
915 | SetFlag(capFobx->pSrvOpen->Flags, SRVOPEN_FLAG_FILE_DELETED);
|
---|
916 | }
|
---|
917 |
|
---|
918 | Status = VBoxErrorToNTStatus(vboxRC);
|
---|
919 | if (vboxRC != VINF_SUCCESS)
|
---|
920 | {
|
---|
921 | Log(("VBOXSF: vbsfRemove: vboxCallRemove failed with %Rrc\n",
|
---|
922 | vboxRC));
|
---|
923 | }
|
---|
924 |
|
---|
925 | Log(("VBOXSF: vbsfRemove: Returned 0x%08X\n",
|
---|
926 | Status));
|
---|
927 | return Status;
|
---|
928 | }
|
---|
929 |
|
---|
930 | NTSTATUS vbsfRename(IN PRX_CONTEXT RxContext,
|
---|
931 | IN FILE_INFORMATION_CLASS FileInformationClass,
|
---|
932 | IN PVOID pBuffer,
|
---|
933 | IN ULONG BufferLength)
|
---|
934 | {
|
---|
935 | NTSTATUS Status = STATUS_SUCCESS;
|
---|
936 |
|
---|
937 | RxCaptureFcb;
|
---|
938 | RxCaptureFobx;
|
---|
939 |
|
---|
940 | PMRX_VBOX_DEVICE_EXTENSION pDeviceExtension = VBoxMRxGetDeviceExtension(RxContext);
|
---|
941 | PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension = VBoxMRxGetNetRootExtension(capFcb->pNetRoot);
|
---|
942 | PMRX_VBOX_FOBX pVBoxFobx = VBoxMRxGetFileObjectExtension(capFobx);
|
---|
943 | PMRX_SRV_OPEN pSrvOpen = capFobx->pSrvOpen;
|
---|
944 |
|
---|
945 | PFILE_RENAME_INFORMATION RenameInformation = (PFILE_RENAME_INFORMATION)RxContext->Info.Buffer;
|
---|
946 | PUNICODE_STRING RemainingName = GET_ALREADY_PREFIXED_NAME(pSrvOpen, capFcb);
|
---|
947 |
|
---|
948 | int vboxRC;
|
---|
949 | PSHFLSTRING SrcPath = 0, DestPath = 0;
|
---|
950 | ULONG ParsedPathSize, flags;
|
---|
951 |
|
---|
952 | Assert(FileInformationClass == FileRenameInformation);
|
---|
953 |
|
---|
954 | Log(("VBOXSF: vbsfRename: FileName = %.*ls\n",
|
---|
955 | RenameInformation->FileNameLength / sizeof(WCHAR), &RenameInformation->FileName[0]));
|
---|
956 |
|
---|
957 | /* Must close the file before renaming it! */
|
---|
958 | if (pVBoxFobx->hFile != SHFL_HANDLE_NIL)
|
---|
959 | {
|
---|
960 | vbsfCloseFileHandle(pDeviceExtension, pNetRootExtension, pVBoxFobx);
|
---|
961 | }
|
---|
962 |
|
---|
963 | /* Mark it as renamed, so we do nothing during close */
|
---|
964 | SetFlag(pSrvOpen->Flags, SRVOPEN_FLAG_FILE_RENAMED);
|
---|
965 |
|
---|
966 | /* Calculate length required for destination path. */
|
---|
967 | ParsedPathSize = sizeof(*DestPath) + (RenameInformation->FileNameLength + sizeof(WCHAR));
|
---|
968 |
|
---|
969 | Log(("VBOXSF: vbsfRename: ParsedPathSize = %d\n",
|
---|
970 | ParsedPathSize));
|
---|
971 |
|
---|
972 | DestPath = (PSHFLSTRING)vbsfAllocNonPagedMem(ParsedPathSize);
|
---|
973 |
|
---|
974 | if (NULL == DestPath)
|
---|
975 | {
|
---|
976 | return STATUS_INSUFFICIENT_RESOURCES;
|
---|
977 | }
|
---|
978 |
|
---|
979 | RtlZeroMemory(DestPath, ParsedPathSize);
|
---|
980 | ShflStringInitBuffer(DestPath, ParsedPathSize - sizeof(SHFLSTRING));
|
---|
981 |
|
---|
982 | Log(("VBOXSF: vbsfRename: Setting up destination path\n"));
|
---|
983 |
|
---|
984 | DestPath->u16Size = (USHORT)(RenameInformation->FileNameLength + sizeof(WCHAR));
|
---|
985 | DestPath->u16Length = DestPath->u16Size - sizeof(WCHAR); /* without terminating null */
|
---|
986 | RtlCopyMemory(DestPath->String.ucs2, RenameInformation->FileName, DestPath->u16Length);
|
---|
987 |
|
---|
988 | Log(("VBOXSF: vbsfRename: Destination path = %.*ls\n",
|
---|
989 | DestPath->u16Length / sizeof(WCHAR), &DestPath->String.ucs2[0]));
|
---|
990 |
|
---|
991 | /* Calculate length required for source path */
|
---|
992 | ParsedPathSize = sizeof(*DestPath) + (RemainingName->Length + sizeof(WCHAR));
|
---|
993 |
|
---|
994 | Log(("VBOXSF: vbsfRename: ParsedPathSize = %d\n", ParsedPathSize));
|
---|
995 |
|
---|
996 | SrcPath = (PSHFLSTRING)vbsfAllocNonPagedMem(ParsedPathSize);
|
---|
997 |
|
---|
998 | if (NULL == SrcPath)
|
---|
999 | {
|
---|
1000 | vbsfFreeNonPagedMem(DestPath);
|
---|
1001 | return STATUS_INSUFFICIENT_RESOURCES;
|
---|
1002 | }
|
---|
1003 |
|
---|
1004 | RtlZeroMemory(SrcPath, ParsedPathSize);
|
---|
1005 | ShflStringInitBuffer(SrcPath, ParsedPathSize - sizeof(SHFLSTRING));
|
---|
1006 |
|
---|
1007 | Log(("VBOXSF: vbsfRename: Setting up source path\n"));
|
---|
1008 |
|
---|
1009 | SrcPath->u16Size = RemainingName->Length + sizeof(WCHAR);
|
---|
1010 | SrcPath->u16Length = SrcPath->u16Size - sizeof(WCHAR); /* without terminating null */
|
---|
1011 | RtlCopyMemory(SrcPath->String.ucs2, RemainingName->Buffer, SrcPath->u16Length);
|
---|
1012 |
|
---|
1013 | Log(("VBOXSF: vbsfRename: Source path = %.*ls\n",
|
---|
1014 | SrcPath->u16Length / sizeof(WCHAR), &SrcPath->String.ucs2[0]));
|
---|
1015 |
|
---|
1016 | /* Call host. */
|
---|
1017 | flags = pVBoxFobx->FileStandardInfo.Directory? SHFL_RENAME_DIR : SHFL_RENAME_FILE;
|
---|
1018 | if (RenameInformation->ReplaceIfExists)
|
---|
1019 | {
|
---|
1020 | flags |= SHFL_RENAME_REPLACE_IF_EXISTS;
|
---|
1021 | }
|
---|
1022 |
|
---|
1023 | Log(("VBOXSF: vbsfRename: Calling vboxCallRename\n"));
|
---|
1024 | vboxRC = vboxCallRename(&pDeviceExtension->hgcmClient, &pNetRootExtension->map, SrcPath, DestPath, flags);
|
---|
1025 |
|
---|
1026 | vbsfFreeNonPagedMem(SrcPath);
|
---|
1027 | vbsfFreeNonPagedMem(DestPath);
|
---|
1028 |
|
---|
1029 | Status = VBoxErrorToNTStatus(vboxRC);
|
---|
1030 | if (vboxRC != VINF_SUCCESS)
|
---|
1031 | {
|
---|
1032 | Log(("VBOXSF: vbsfRename: vboxCallRename failed with %Rrc\n",
|
---|
1033 | vboxRC));
|
---|
1034 | }
|
---|
1035 |
|
---|
1036 | Log(("VBOXSF: vbsfRename: Returned 0x%08X\n",
|
---|
1037 | Status));
|
---|
1038 | return Status;
|
---|
1039 | }
|
---|
1040 |
|
---|
1041 | NTSTATUS VBoxMRxShouldTryToCollapseThisOpen(IN PRX_CONTEXT RxContext)
|
---|
1042 | {
|
---|
1043 | Log(("VBOXSF: MRxShouldTryToCollapseThisOpen\n"));
|
---|
1044 | return STATUS_MORE_PROCESSING_REQUIRED;
|
---|
1045 | }
|
---|
1046 |
|
---|
1047 | NTSTATUS VBoxMRxCollapseOpen(IN OUT PRX_CONTEXT RxContext)
|
---|
1048 | {
|
---|
1049 | Log(("VBOXSF: MRxCollapseOpen\n"));
|
---|
1050 | return STATUS_MORE_PROCESSING_REQUIRED;
|
---|
1051 | }
|
---|