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\n",
|
---|
497 | RemainingName, RemainingName->Length));
|
---|
498 |
|
---|
499 | if (RemainingName->Length)
|
---|
500 | {
|
---|
501 | Log(("VBOXSF: MRxCreate: Attempt to open %.*ls\n",
|
---|
502 | RemainingName->Length/sizeof(WCHAR), RemainingName->Buffer));
|
---|
503 | }
|
---|
504 | else
|
---|
505 | {
|
---|
506 | if (FlagOn(RxContext->Create.Flags, RX_CONTEXT_CREATE_FLAG_STRIPPED_TRAILING_BACKSLASH))
|
---|
507 | {
|
---|
508 | Log(("VBOXSF: MRxCreate: Empty name -> Only backslash used\n"));
|
---|
509 | RemainingName = &UnicodeBackslash;
|
---|
510 | }
|
---|
511 | }
|
---|
512 |
|
---|
513 | if ( pNetRoot->Type != NET_ROOT_WILD
|
---|
514 | && pNetRoot->Type != NET_ROOT_DISK)
|
---|
515 | {
|
---|
516 | Log(("VBOXSF: MRxCreate: netroot type %d not supported\n",
|
---|
517 | pNetRoot->Type));
|
---|
518 | Status = STATUS_NOT_IMPLEMENTED;
|
---|
519 | goto Exit;
|
---|
520 | }
|
---|
521 |
|
---|
522 | FileBasicInfo.FileAttributes = FILE_ATTRIBUTE_NORMAL;
|
---|
523 |
|
---|
524 | Status = vbsfProcessCreate(RxContext,
|
---|
525 | RemainingName,
|
---|
526 | &FileBasicInfo,
|
---|
527 | &FileStandardInfo,
|
---|
528 | RxContext->Create.EaBuffer,
|
---|
529 | RxContext->Create.EaLength,
|
---|
530 | &CreateAction,
|
---|
531 | &Handle);
|
---|
532 |
|
---|
533 | if (Status != STATUS_SUCCESS)
|
---|
534 | {
|
---|
535 | Log(("VBOXSF: MRxCreate: vbsfProcessCreate failed 0x%08X\n",
|
---|
536 | Status));
|
---|
537 | goto Exit;
|
---|
538 | }
|
---|
539 |
|
---|
540 | Log(("VBOXSF: MRxCreate: EOF is 0x%RX64 AllocSize is 0x%RX64\n",
|
---|
541 | FileStandardInfo.EndOfFile.QuadPart, FileStandardInfo.AllocationSize.QuadPart));
|
---|
542 |
|
---|
543 | RxContext->pFobx = RxCreateNetFobx(RxContext, SrvOpen);
|
---|
544 | if (RxContext->pFobx == NULL)
|
---|
545 | {
|
---|
546 | Log(("VBOXSF: MRxCreate: RxCreateNetFobx failed\n"));
|
---|
547 | Status = STATUS_INSUFFICIENT_RESOURCES;
|
---|
548 | goto Exit;
|
---|
549 | }
|
---|
550 |
|
---|
551 | Log(("VBOXSF: MRxCreate: CreateAction = 0x%08X\n",
|
---|
552 | CreateAction));
|
---|
553 |
|
---|
554 | RxContext->Create.ReturnedCreateInformation = CreateAction;
|
---|
555 |
|
---|
556 | if (capFcb->OpenCount == 0)
|
---|
557 | {
|
---|
558 | FCB_INIT_PACKET InitPacket;
|
---|
559 | RxFormInitPacket(InitPacket,
|
---|
560 | &FileBasicInfo.FileAttributes,
|
---|
561 | &FileStandardInfo.NumberOfLinks,
|
---|
562 | &FileBasicInfo.CreationTime,
|
---|
563 | &FileBasicInfo.LastAccessTime,
|
---|
564 | &FileBasicInfo.LastWriteTime,
|
---|
565 | &FileBasicInfo.ChangeTime,
|
---|
566 | &FileStandardInfo.AllocationSize,
|
---|
567 | &FileStandardInfo.EndOfFile,
|
---|
568 | &FileStandardInfo.EndOfFile);
|
---|
569 | RxFinishFcbInitialization(capFcb, RDBSS_STORAGE_NTC(FileTypeFile), &InitPacket);
|
---|
570 | }
|
---|
571 |
|
---|
572 | SrvOpen->BufferingFlags = 0;
|
---|
573 |
|
---|
574 | RxContext->pFobx->OffsetOfNextEaToReturn = 1;
|
---|
575 |
|
---|
576 | pVBoxFobx = VBoxMRxGetFileObjectExtension(RxContext->pFobx);
|
---|
577 |
|
---|
578 | Log(("VBOXSF: MRxCreate: VBoxFobx = %p\n",
|
---|
579 | pVBoxFobx));
|
---|
580 |
|
---|
581 | if (!pVBoxFobx)
|
---|
582 | {
|
---|
583 | Log(("VBOXSF: MRxCreate: no VBoxFobx!\n"));
|
---|
584 | AssertFailed();
|
---|
585 | Status = STATUS_INSUFFICIENT_RESOURCES;
|
---|
586 | goto Exit;
|
---|
587 | }
|
---|
588 |
|
---|
589 | pVBoxFobx->hFile = Handle;
|
---|
590 | pVBoxFobx->pSrvCall = RxContext->Create.pSrvCall;
|
---|
591 | pVBoxFobx->FileStandardInfo = FileStandardInfo;
|
---|
592 | pVBoxFobx->FileBasicInfo = FileBasicInfo;
|
---|
593 | pVBoxFobx->fKeepCreationTime = FALSE;
|
---|
594 | pVBoxFobx->fKeepLastAccessTime = FALSE;
|
---|
595 | pVBoxFobx->fKeepLastWriteTime = FALSE;
|
---|
596 | pVBoxFobx->fKeepChangeTime = FALSE;
|
---|
597 |
|
---|
598 | if (!RxIsFcbAcquiredExclusive(capFcb))
|
---|
599 | {
|
---|
600 | RxAcquireExclusiveFcbResourceInMRx(capFcb);
|
---|
601 | }
|
---|
602 |
|
---|
603 | Log(("VBOXSF: MRxCreate: NetRoot is %p, Fcb is %p, SrvOpen is %p, Fobx is %p\n",
|
---|
604 | pNetRoot, capFcb, SrvOpen, RxContext->pFobx));
|
---|
605 | Log(("VBOXSF: MRxCreate: return 0x%08X\n",
|
---|
606 | Status));
|
---|
607 |
|
---|
608 | Exit:
|
---|
609 | return Status;
|
---|
610 | }
|
---|
611 |
|
---|
612 | NTSTATUS VBoxMRxComputeNewBufferingState(IN OUT PMRX_SRV_OPEN pMRxSrvOpen,
|
---|
613 | IN PVOID pMRxContext,
|
---|
614 | OUT PULONG pNewBufferingState)
|
---|
615 | {
|
---|
616 | Log(("VBOXSF: MRxComputeNewBufferingState\n"));
|
---|
617 | return STATUS_NOT_SUPPORTED;
|
---|
618 | }
|
---|
619 |
|
---|
620 | NTSTATUS VBoxMRxDeallocateForFcb(IN OUT PMRX_FCB pFcb)
|
---|
621 | {
|
---|
622 | Log(("VBOXSF: MRxDeallocateForFcb\n"));
|
---|
623 | return STATUS_SUCCESS;
|
---|
624 | }
|
---|
625 |
|
---|
626 | NTSTATUS VBoxMRxDeallocateForFobx(IN OUT PMRX_FOBX pFobx)
|
---|
627 | {
|
---|
628 | Log(("VBOXSF: MRxDeallocateForFobx\n"));
|
---|
629 | return STATUS_SUCCESS;
|
---|
630 | }
|
---|
631 |
|
---|
632 | NTSTATUS VBoxMRxTruncate(IN PRX_CONTEXT RxContext)
|
---|
633 | {
|
---|
634 | Log(("VBOXSF: MRxTruncate\n"));
|
---|
635 | return STATUS_NOT_IMPLEMENTED;
|
---|
636 | }
|
---|
637 |
|
---|
638 | NTSTATUS VBoxMRxCleanupFobx(IN PRX_CONTEXT RxContext)
|
---|
639 | {
|
---|
640 | PMRX_VBOX_FOBX pVBoxFobx = VBoxMRxGetFileObjectExtension(RxContext->pFobx);
|
---|
641 |
|
---|
642 | Log(("VBOXSF: MRxCleanupFobx: pVBoxFobx = %p, Handle = 0x%RX64\n",
|
---|
643 | pVBoxFobx, pVBoxFobx? pVBoxFobx->hFile: 0));
|
---|
644 |
|
---|
645 | if (NULL == pVBoxFobx)
|
---|
646 | {
|
---|
647 | return STATUS_INVALID_PARAMETER;
|
---|
648 | }
|
---|
649 |
|
---|
650 | return STATUS_SUCCESS;
|
---|
651 | }
|
---|
652 |
|
---|
653 | NTSTATUS VBoxMRxForceClosed(IN PMRX_SRV_OPEN pSrvOpen)
|
---|
654 | {
|
---|
655 | Log(("VBOXSF: MRxForceClosed\n"));
|
---|
656 | return STATUS_NOT_IMPLEMENTED;
|
---|
657 | }
|
---|
658 |
|
---|
659 | NTSTATUS VBoxMRxCloseSrvOpen(IN PRX_CONTEXT RxContext)
|
---|
660 | {
|
---|
661 | NTSTATUS Status = STATUS_SUCCESS;
|
---|
662 |
|
---|
663 | RxCaptureFcb;
|
---|
664 | RxCaptureFobx;
|
---|
665 |
|
---|
666 | PMRX_VBOX_DEVICE_EXTENSION pDeviceExtension = VBoxMRxGetDeviceExtension(RxContext);
|
---|
667 | PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension = VBoxMRxGetNetRootExtension(capFcb->pNetRoot);
|
---|
668 | PMRX_VBOX_FOBX pVBoxFobx = VBoxMRxGetFileObjectExtension(capFobx);
|
---|
669 | PMRX_SRV_OPEN pSrvOpen = capFobx->pSrvOpen;
|
---|
670 |
|
---|
671 | int vboxRC = 0;
|
---|
672 | PUNICODE_STRING RemainingName = NULL;
|
---|
673 |
|
---|
674 | Log(("VBOXSF: MRxCloseSrvOpen: capFcb = %p, capFobx = %p, pVBoxFobx = %p, pSrvOpen = %p\n",
|
---|
675 | capFcb, capFobx, pVBoxFobx, pSrvOpen));
|
---|
676 |
|
---|
677 | RemainingName = pSrvOpen->pAlreadyPrefixedName;
|
---|
678 |
|
---|
679 | Log(("VBOXSF: MRxCloseSrvOpen: Remaining name = %.*ls, Len = %d\n",
|
---|
680 | RemainingName->Length / sizeof(WCHAR), RemainingName->Buffer, RemainingName->Length));
|
---|
681 |
|
---|
682 | if (NULL == pVBoxFobx)
|
---|
683 | {
|
---|
684 | return STATUS_INVALID_PARAMETER;
|
---|
685 | }
|
---|
686 |
|
---|
687 | if (FlagOn(pSrvOpen->Flags, (SRVOPEN_FLAG_FILE_RENAMED | SRVOPEN_FLAG_FILE_DELETED)))
|
---|
688 | {
|
---|
689 | /* If we renamed or delete the file/dir, then it's already closed */
|
---|
690 | Assert(pVBoxFobx->hFile == SHFL_HANDLE_NIL);
|
---|
691 | Log(("VBOXSF: MRxCloseSrvOpen: File was renamed, handle 0x%RX64 ignore close.\n",
|
---|
692 | pVBoxFobx->hFile));
|
---|
693 | return STATUS_SUCCESS;
|
---|
694 | }
|
---|
695 |
|
---|
696 | /* Close file */
|
---|
697 | if (pVBoxFobx->hFile != SHFL_HANDLE_NIL)
|
---|
698 | {
|
---|
699 | vboxRC = vboxCallClose(&pDeviceExtension->hgcmClient, &pNetRootExtension->map, pVBoxFobx->hFile);
|
---|
700 | pVBoxFobx->hFile = SHFL_HANDLE_NIL;
|
---|
701 | }
|
---|
702 |
|
---|
703 | if (capFcb->FcbState & FCB_STATE_DELETE_ON_CLOSE)
|
---|
704 | {
|
---|
705 | Log(("VBOXSF: MRxCloseSrvOpen: Delete on close. Open count = %d\n",
|
---|
706 | capFcb->OpenCount));
|
---|
707 |
|
---|
708 | /* Remove file or directory if delete action is pending. */
|
---|
709 | if (capFcb->OpenCount == 0)
|
---|
710 | {
|
---|
711 | Status = vbsfRemove(RxContext);
|
---|
712 | }
|
---|
713 | }
|
---|
714 |
|
---|
715 | return Status;
|
---|
716 | }
|
---|
717 |
|
---|
718 | NTSTATUS vbsfRemove(IN PRX_CONTEXT RxContext)
|
---|
719 | {
|
---|
720 | NTSTATUS Status = STATUS_SUCCESS;
|
---|
721 |
|
---|
722 | RxCaptureFcb;
|
---|
723 | RxCaptureFobx;
|
---|
724 |
|
---|
725 | PMRX_VBOX_DEVICE_EXTENSION pDeviceExtension = VBoxMRxGetDeviceExtension(RxContext);
|
---|
726 | PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension = VBoxMRxGetNetRootExtension(capFcb->pNetRoot);
|
---|
727 | PMRX_VBOX_FOBX pVBoxFobx = VBoxMRxGetFileObjectExtension(capFobx);
|
---|
728 |
|
---|
729 | PUNICODE_STRING RemainingName = GET_ALREADY_PREFIXED_NAME_FROM_CONTEXT(RxContext);
|
---|
730 |
|
---|
731 | int vboxRC;
|
---|
732 | PSHFLSTRING ParsedPath = NULL;
|
---|
733 | ULONG ParsedPathSize;
|
---|
734 |
|
---|
735 | Log(("VBOXSF: vbsfRemove: Delete %.*ls. open count = %d\n",
|
---|
736 | RemainingName->Length / sizeof(WCHAR), RemainingName->Buffer, capFcb->OpenCount));
|
---|
737 |
|
---|
738 | /* Close file first if not already done. */
|
---|
739 | if (pVBoxFobx->hFile != SHFL_HANDLE_NIL)
|
---|
740 | {
|
---|
741 | vboxRC = vboxCallClose(&pDeviceExtension->hgcmClient, &pNetRootExtension->map, pVBoxFobx->hFile);
|
---|
742 | pVBoxFobx->hFile = SHFL_HANDLE_NIL;
|
---|
743 | }
|
---|
744 |
|
---|
745 | /* Calculate length required for parsed path.
|
---|
746 | */
|
---|
747 | ParsedPathSize = sizeof(*ParsedPath) + (RemainingName->Length + sizeof(WCHAR));
|
---|
748 |
|
---|
749 | Log(("VBOXSF: vbsfRemove: ParsedPathSize %d\n",
|
---|
750 | ParsedPathSize));
|
---|
751 |
|
---|
752 | ParsedPath = (PSHFLSTRING)vbsfAllocNonPagedMem(ParsedPathSize);
|
---|
753 | if (!ParsedPath)
|
---|
754 | {
|
---|
755 | return STATUS_INSUFFICIENT_RESOURCES;
|
---|
756 | }
|
---|
757 |
|
---|
758 | ShflStringInitBuffer(ParsedPath, ParsedPathSize - sizeof(SHFLSTRING));
|
---|
759 |
|
---|
760 | Log(("VBOXSF: vbsfRemove: Setup ParsedPath\n"));
|
---|
761 | ParsedPath->u16Size = RemainingName->Length + sizeof(WCHAR);
|
---|
762 | ParsedPath->u16Length = ParsedPath->u16Size - sizeof(WCHAR); /* without terminating null */
|
---|
763 | RtlCopyMemory(ParsedPath->String.ucs2, RemainingName->Buffer, ParsedPath->u16Length);
|
---|
764 |
|
---|
765 | /* Call host. */
|
---|
766 | vboxRC = vboxCallRemove(&pDeviceExtension->hgcmClient, &pNetRootExtension->map,
|
---|
767 | ParsedPath,
|
---|
768 | (pVBoxFobx->FileStandardInfo.Directory) ? SHFL_REMOVE_DIR : SHFL_REMOVE_FILE);
|
---|
769 |
|
---|
770 | if (ParsedPath)
|
---|
771 | {
|
---|
772 | vbsfFreeNonPagedMem(ParsedPath);
|
---|
773 | }
|
---|
774 |
|
---|
775 | if (vboxRC == VINF_SUCCESS)
|
---|
776 | {
|
---|
777 | SetFlag(capFobx->pSrvOpen->Flags, SRVOPEN_FLAG_FILE_DELETED);
|
---|
778 | }
|
---|
779 |
|
---|
780 | Status = VBoxErrorToNTStatus(vboxRC);
|
---|
781 | if (vboxRC != VINF_SUCCESS)
|
---|
782 | {
|
---|
783 | Log(("VBOXSF: vbsfRemove: vboxCallRemove failed with %Rrc\n",
|
---|
784 | vboxRC));
|
---|
785 | }
|
---|
786 |
|
---|
787 | Log(("VBOXSF: vbsfRemove: Returned 0x%08X\n",
|
---|
788 | Status));
|
---|
789 | return Status;
|
---|
790 | }
|
---|
791 |
|
---|
792 | NTSTATUS vbsfRename(IN PRX_CONTEXT RxContext,
|
---|
793 | IN FILE_INFORMATION_CLASS FileInformationClass,
|
---|
794 | IN PVOID pBuffer,
|
---|
795 | IN ULONG BufferLength)
|
---|
796 | {
|
---|
797 | NTSTATUS Status = STATUS_SUCCESS;
|
---|
798 |
|
---|
799 | RxCaptureFcb;
|
---|
800 | RxCaptureFobx;
|
---|
801 |
|
---|
802 | PMRX_VBOX_DEVICE_EXTENSION pDeviceExtension = VBoxMRxGetDeviceExtension(RxContext);
|
---|
803 | PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension = VBoxMRxGetNetRootExtension(capFcb->pNetRoot);
|
---|
804 | PMRX_VBOX_FOBX pVBoxFobx = VBoxMRxGetFileObjectExtension(capFobx);
|
---|
805 | PMRX_SRV_OPEN pSrvOpen = capFobx->pSrvOpen;
|
---|
806 |
|
---|
807 | PFILE_RENAME_INFORMATION RenameInformation = (PFILE_RENAME_INFORMATION)RxContext->Info.Buffer;
|
---|
808 | PUNICODE_STRING RemainingName = GET_ALREADY_PREFIXED_NAME(pSrvOpen, capFcb);
|
---|
809 |
|
---|
810 | int vboxRC;
|
---|
811 | PSHFLSTRING SrcPath = 0, DestPath = 0;
|
---|
812 | ULONG ParsedPathSize, flags;
|
---|
813 |
|
---|
814 | Assert(FileInformationClass == FileRenameInformation);
|
---|
815 |
|
---|
816 | Log(("VBOXSF: vbsfRename: FileName = %.*ls\n",
|
---|
817 | RenameInformation->FileNameLength / sizeof(WCHAR), &RenameInformation->FileName[0]));
|
---|
818 |
|
---|
819 | /* Must close the file before renaming it! */
|
---|
820 | if (pVBoxFobx->hFile != SHFL_HANDLE_NIL)
|
---|
821 | {
|
---|
822 | vboxRC = vboxCallClose(&pDeviceExtension->hgcmClient, &pNetRootExtension->map, pVBoxFobx->hFile);
|
---|
823 | pVBoxFobx->hFile = SHFL_HANDLE_NIL;
|
---|
824 | }
|
---|
825 |
|
---|
826 | /* Mark it as renamed, so we do nothing during close */
|
---|
827 | SetFlag(pSrvOpen->Flags, SRVOPEN_FLAG_FILE_RENAMED);
|
---|
828 |
|
---|
829 | /* Calculate length required for destination path. */
|
---|
830 | ParsedPathSize = sizeof(*DestPath) + (RenameInformation->FileNameLength + sizeof(WCHAR));
|
---|
831 |
|
---|
832 | Log(("VBOXSF: vbsfRename: ParsedPathSize = %d\n",
|
---|
833 | ParsedPathSize));
|
---|
834 |
|
---|
835 | DestPath = (PSHFLSTRING)vbsfAllocNonPagedMem(ParsedPathSize);
|
---|
836 |
|
---|
837 | if (NULL == DestPath)
|
---|
838 | {
|
---|
839 | return STATUS_INSUFFICIENT_RESOURCES;
|
---|
840 | }
|
---|
841 |
|
---|
842 | RtlZeroMemory(DestPath, ParsedPathSize);
|
---|
843 | ShflStringInitBuffer(DestPath, ParsedPathSize - sizeof(SHFLSTRING));
|
---|
844 |
|
---|
845 | Log(("VBOXSF: vbsfRename: Setting up destination path\n"));
|
---|
846 |
|
---|
847 | DestPath->u16Size = (USHORT)(RenameInformation->FileNameLength + sizeof(WCHAR));
|
---|
848 | DestPath->u16Length = DestPath->u16Size - sizeof(WCHAR); /* without terminating null */
|
---|
849 | RtlCopyMemory(DestPath->String.ucs2, RenameInformation->FileName, DestPath->u16Length);
|
---|
850 |
|
---|
851 | Log(("VBOXSF: vbsfRename: Destination path = %.*ls\n",
|
---|
852 | DestPath->u16Length / sizeof(WCHAR), &DestPath->String.ucs2[0]));
|
---|
853 |
|
---|
854 | /* Calculate length required for source path */
|
---|
855 | ParsedPathSize = sizeof(*DestPath) + (RemainingName->Length + sizeof(WCHAR));
|
---|
856 |
|
---|
857 | Log(("VBOXSF: vbsfRename: ParsedPathSize = %d\n", ParsedPathSize));
|
---|
858 |
|
---|
859 | SrcPath = (PSHFLSTRING)vbsfAllocNonPagedMem(ParsedPathSize);
|
---|
860 |
|
---|
861 | if (NULL == SrcPath)
|
---|
862 | {
|
---|
863 | vbsfFreeNonPagedMem(DestPath);
|
---|
864 | return STATUS_INSUFFICIENT_RESOURCES;
|
---|
865 | }
|
---|
866 |
|
---|
867 | RtlZeroMemory(SrcPath, ParsedPathSize);
|
---|
868 | ShflStringInitBuffer(SrcPath, ParsedPathSize - sizeof(SHFLSTRING));
|
---|
869 |
|
---|
870 | Log(("VBOXSF: vbsfRename: Setting up source path\n"));
|
---|
871 |
|
---|
872 | SrcPath->u16Size = RemainingName->Length + sizeof(WCHAR);
|
---|
873 | SrcPath->u16Length = SrcPath->u16Size - sizeof(WCHAR); /* without terminating null */
|
---|
874 | RtlCopyMemory(SrcPath->String.ucs2, RemainingName->Buffer, SrcPath->u16Length);
|
---|
875 |
|
---|
876 | Log(("VBOXSF: vbsfRename: Source path = %.*ls\n",
|
---|
877 | SrcPath->u16Length / sizeof(WCHAR), &SrcPath->String.ucs2[0]));
|
---|
878 |
|
---|
879 | /* Call host. */
|
---|
880 | flags = pVBoxFobx->FileStandardInfo.Directory? SHFL_RENAME_DIR : SHFL_RENAME_FILE;
|
---|
881 | if (RenameInformation->ReplaceIfExists)
|
---|
882 | {
|
---|
883 | flags |= SHFL_RENAME_REPLACE_IF_EXISTS;
|
---|
884 | }
|
---|
885 |
|
---|
886 | Log(("VBOXSF: vbsfRename: Calling vboxCallRename\n"));
|
---|
887 | vboxRC = vboxCallRename(&pDeviceExtension->hgcmClient, &pNetRootExtension->map, SrcPath, DestPath, flags);
|
---|
888 |
|
---|
889 | vbsfFreeNonPagedMem(SrcPath);
|
---|
890 | vbsfFreeNonPagedMem(DestPath);
|
---|
891 |
|
---|
892 | Status = VBoxErrorToNTStatus(vboxRC);
|
---|
893 | if (vboxRC != VINF_SUCCESS)
|
---|
894 | {
|
---|
895 | Log(("VBOXSF: vbsfRename: vboxCallRename failed with %Rrc\n",
|
---|
896 | vboxRC));
|
---|
897 | }
|
---|
898 |
|
---|
899 | Log(("VBOXSF: vbsfRename: Returned 0x%08X\n",
|
---|
900 | Status));
|
---|
901 | return Status;
|
---|
902 | }
|
---|
903 |
|
---|
904 | NTSTATUS VBoxMRxShouldTryToCollapseThisOpen(IN PRX_CONTEXT RxContext)
|
---|
905 | {
|
---|
906 | Log(("VBOXSF: MRxShouldTryToCollapseThisOpen\n"));
|
---|
907 | return STATUS_MORE_PROCESSING_REQUIRED;
|
---|
908 | }
|
---|
909 |
|
---|
910 | NTSTATUS VBoxMRxCollapseOpen(IN OUT PRX_CONTEXT RxContext)
|
---|
911 | {
|
---|
912 | Log(("VBOXSF: MRxCollapseOpen\n"));
|
---|
913 | return STATUS_MORE_PROCESSING_REQUIRED;
|
---|
914 | }
|
---|