1 | /* $Id: info.cpp 78487 2019-05-13 23:25:38Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox Windows Guest Shared Folders FSD - Information Querying & Setting 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 | #include <iprt/asm.h>
|
---|
25 |
|
---|
26 | extern "C" NTSTATUS NTAPI RxSetEndOfFileInfo(PRX_CONTEXT, PIRP, PFCB, PFOBX);
|
---|
27 |
|
---|
28 |
|
---|
29 | /*********************************************************************************************************************************
|
---|
30 | * Defined Constants And Macros *
|
---|
31 | *********************************************************************************************************************************/
|
---|
32 | /** Macro for copying a SHFLSTRING file name into a FILE_DIRECTORY_INFORMATION structure. */
|
---|
33 | #define INIT_FILE_NAME(obj, str) \
|
---|
34 | do { \
|
---|
35 | ULONG cbLength = (str).u16Length; \
|
---|
36 | (obj)->FileNameLength = cbLength; \
|
---|
37 | RtlCopyMemory((obj)->FileName, &(str).String.ucs2[0], cbLength + 2); \
|
---|
38 | } while (0)
|
---|
39 |
|
---|
40 |
|
---|
41 | NTSTATUS VBoxMRxQueryDirectory(IN OUT PRX_CONTEXT RxContext)
|
---|
42 | {
|
---|
43 | NTSTATUS Status = STATUS_SUCCESS;
|
---|
44 |
|
---|
45 | RxCaptureFobx;
|
---|
46 | RxCaptureFcb;
|
---|
47 |
|
---|
48 | PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension = VBoxMRxGetNetRootExtension(capFcb->pNetRoot);
|
---|
49 | PMRX_VBOX_FOBX pVBoxFobx = VBoxMRxGetFileObjectExtension(capFobx);
|
---|
50 |
|
---|
51 | PUNICODE_STRING DirectoryName = GET_ALREADY_PREFIXED_NAME_FROM_CONTEXT(RxContext);
|
---|
52 | PUNICODE_STRING Template = &capFobx->UnicodeQueryTemplate;
|
---|
53 | FILE_INFORMATION_CLASS FileInformationClass = RxContext->Info.FileInformationClass;
|
---|
54 | PCHAR pInfoBuffer = (PCHAR)RxContext->Info.Buffer;
|
---|
55 | LONG cbMaxSize = RxContext->Info.Length;
|
---|
56 | LONG *pLengthRemaining = (LONG *)&RxContext->Info.LengthRemaining;
|
---|
57 |
|
---|
58 | LONG cbToCopy;
|
---|
59 | int vrc;
|
---|
60 | uint8_t *pHGCMBuffer;
|
---|
61 | uint32_t index, fSFFlags, cFiles, u32BufSize;
|
---|
62 | LONG cbHGCMBuffer;
|
---|
63 | PSHFLDIRINFO pDirEntry;
|
---|
64 |
|
---|
65 | ULONG *pNextOffset = 0;
|
---|
66 | PSHFLSTRING ParsedPath = NULL;
|
---|
67 |
|
---|
68 | Log(("VBOXSF: MrxQueryDirectory: FileInformationClass %d, pVBoxFobx %p, hFile %RX64, pInfoBuffer %p\n",
|
---|
69 | FileInformationClass, pVBoxFobx, pVBoxFobx->hFile, pInfoBuffer));
|
---|
70 |
|
---|
71 | if (!pVBoxFobx)
|
---|
72 | {
|
---|
73 | Log(("VBOXSF: MrxQueryDirectory: pVBoxFobx is invalid!\n"));
|
---|
74 | return STATUS_INVALID_PARAMETER;
|
---|
75 | }
|
---|
76 |
|
---|
77 | if (!DirectoryName)
|
---|
78 | return STATUS_INVALID_PARAMETER;
|
---|
79 |
|
---|
80 | if (DirectoryName->Length == 0)
|
---|
81 | Log(("VBOXSF: MrxQueryDirectory: DirectoryName = \\ (null string)\n"));
|
---|
82 | else
|
---|
83 | Log(("VBOXSF: MrxQueryDirectory: DirectoryName = %.*ls\n",
|
---|
84 | DirectoryName->Length / sizeof(WCHAR), DirectoryName->Buffer));
|
---|
85 |
|
---|
86 | if (!Template)
|
---|
87 | return STATUS_INVALID_PARAMETER;
|
---|
88 |
|
---|
89 | if (Template->Length == 0)
|
---|
90 | Log(("VBOXSF: MrxQueryDirectory: Template = \\ (null string)\n"));
|
---|
91 | else
|
---|
92 | Log(("VBOXSF: MrxQueryDirectory: Template = %.*ls\n",
|
---|
93 | Template->Length / sizeof(WCHAR), Template->Buffer));
|
---|
94 |
|
---|
95 | cbHGCMBuffer = RT_MAX(cbMaxSize, PAGE_SIZE);
|
---|
96 |
|
---|
97 | Log(("VBOXSF: MrxQueryDirectory: Allocating cbHGCMBuffer = %d\n",
|
---|
98 | cbHGCMBuffer));
|
---|
99 |
|
---|
100 | pHGCMBuffer = (uint8_t *)vbsfNtAllocNonPagedMem(cbHGCMBuffer);
|
---|
101 | if (!pHGCMBuffer)
|
---|
102 | {
|
---|
103 | AssertFailed();
|
---|
104 | return STATUS_INSUFFICIENT_RESOURCES;
|
---|
105 | }
|
---|
106 |
|
---|
107 | /* Assume start from the beginning. */
|
---|
108 | index = 0;
|
---|
109 | if (RxContext->QueryDirectory.IndexSpecified == TRUE)
|
---|
110 | {
|
---|
111 | Log(("VBOXSF: MrxQueryDirectory: Index specified %d\n",
|
---|
112 | index));
|
---|
113 | index = RxContext->QueryDirectory.FileIndex;
|
---|
114 | }
|
---|
115 |
|
---|
116 | fSFFlags = SHFL_LIST_NONE;
|
---|
117 | if (RxContext->QueryDirectory.ReturnSingleEntry == TRUE)
|
---|
118 | {
|
---|
119 | Log(("VBOXSF: MrxQueryDirectory: Query single entry\n"));
|
---|
120 | fSFFlags |= SHFL_LIST_RETURN_ONE;
|
---|
121 | }
|
---|
122 | if ( RxContext->QueryDirectory.RestartScan == TRUE
|
---|
123 | && RxContext->QueryDirectory.InitialQuery == FALSE)
|
---|
124 | {
|
---|
125 | Log(("VBOXSF: MrxQueryDirectory: Restart scan\n"));
|
---|
126 | fSFFlags |= SHFL_LIST_RESTART;
|
---|
127 | }
|
---|
128 |
|
---|
129 | if (Template->Length)
|
---|
130 | {
|
---|
131 | ULONG ParsedPathSize, cch;
|
---|
132 |
|
---|
133 | /* Calculate size required for parsed path: dir + \ + template + 0. */
|
---|
134 | ParsedPathSize = SHFLSTRING_HEADER_SIZE + Template->Length + sizeof(WCHAR);
|
---|
135 | if (DirectoryName->Length)
|
---|
136 | ParsedPathSize += DirectoryName->Length + sizeof(WCHAR);
|
---|
137 | Log(("VBOXSF: MrxQueryDirectory: ParsedPathSize = %d\n", ParsedPathSize));
|
---|
138 |
|
---|
139 | ParsedPath = (PSHFLSTRING)vbsfNtAllocNonPagedMem(ParsedPathSize);
|
---|
140 | if (!ParsedPath)
|
---|
141 | {
|
---|
142 | Status = STATUS_INSUFFICIENT_RESOURCES;
|
---|
143 | goto end;
|
---|
144 | }
|
---|
145 |
|
---|
146 | if (!ShflStringInitBuffer(ParsedPath, ParsedPathSize))
|
---|
147 | {
|
---|
148 | Status = STATUS_INSUFFICIENT_RESOURCES;
|
---|
149 | goto end;
|
---|
150 | }
|
---|
151 |
|
---|
152 | cch = 0;
|
---|
153 | if (DirectoryName->Length)
|
---|
154 | {
|
---|
155 | /* Copy directory name into ParsedPath. */
|
---|
156 | RtlCopyMemory(ParsedPath->String.ucs2, DirectoryName->Buffer, DirectoryName->Length);
|
---|
157 | cch += DirectoryName->Length / sizeof(WCHAR);
|
---|
158 |
|
---|
159 | /* Add terminating backslash. */
|
---|
160 | ParsedPath->String.ucs2[cch] = L'\\';
|
---|
161 | cch++;
|
---|
162 | }
|
---|
163 |
|
---|
164 | RtlCopyMemory (&ParsedPath->String.ucs2[cch], Template->Buffer, Template->Length);
|
---|
165 | cch += Template->Length / sizeof(WCHAR);
|
---|
166 |
|
---|
167 | /* Add terminating nul. */
|
---|
168 | ParsedPath->String.ucs2[cch] = 0;
|
---|
169 |
|
---|
170 | /* cch is the number of chars without trailing nul. */
|
---|
171 | ParsedPath->u16Length = (uint16_t)(cch * sizeof(WCHAR));
|
---|
172 |
|
---|
173 | AssertMsg(ParsedPath->u16Length + sizeof(WCHAR) == ParsedPath->u16Size,
|
---|
174 | ("u16Length %d, u16Size %d\n", ParsedPath->u16Length, ParsedPath->u16Size));
|
---|
175 |
|
---|
176 | Log(("VBOXSF: MrxQueryDirectory: ParsedPath = %.*ls\n",
|
---|
177 | ParsedPath->u16Length / sizeof(WCHAR), ParsedPath->String.ucs2));
|
---|
178 | }
|
---|
179 |
|
---|
180 | cFiles = 0;
|
---|
181 |
|
---|
182 | /* VbglR0SfDirInfo requires a pointer to uint32_t. */
|
---|
183 | u32BufSize = cbHGCMBuffer;
|
---|
184 |
|
---|
185 | Log(("VBOXSF: MrxQueryDirectory: CallDirInfo: File = 0x%08x, Flags = 0x%08x, Index = %d, u32BufSize = %d\n",
|
---|
186 | pVBoxFobx->hFile, fSFFlags, index, u32BufSize));
|
---|
187 | vrc = VbglR0SfDirInfo(&g_SfClient, &pNetRootExtension->map, pVBoxFobx->hFile,
|
---|
188 | ParsedPath, fSFFlags, index, &u32BufSize, (PSHFLDIRINFO)pHGCMBuffer, &cFiles);
|
---|
189 | Log(("VBOXSF: MrxQueryDirectory: u32BufSize after CallDirInfo = %d, rc = %Rrc\n",
|
---|
190 | u32BufSize, vrc));
|
---|
191 |
|
---|
192 | switch (vrc)
|
---|
193 | {
|
---|
194 | case VINF_SUCCESS:
|
---|
195 | /* Nothing to do here. */
|
---|
196 | break;
|
---|
197 |
|
---|
198 | case VERR_NO_TRANSLATION:
|
---|
199 | Log(("VBOXSF: MrxQueryDirectory: Host could not translate entry!\n"));
|
---|
200 | break;
|
---|
201 |
|
---|
202 | case VERR_NO_MORE_FILES:
|
---|
203 | if (cFiles <= 0) /* VERR_NO_MORE_FILES appears at the first lookup when just returning the current dir ".".
|
---|
204 | * So we also have to check for the cFiles counter. */
|
---|
205 | {
|
---|
206 | /* Not an error, but we have to handle the return value. */
|
---|
207 | Log(("VBOXSF: MrxQueryDirectory: Host reported no more files!\n"));
|
---|
208 |
|
---|
209 | if (RxContext->QueryDirectory.InitialQuery)
|
---|
210 | {
|
---|
211 | /* First call. MSDN on FindFirstFile: "If the function fails because no matching files
|
---|
212 | * can be found, the GetLastError function returns ERROR_FILE_NOT_FOUND."
|
---|
213 | * So map this rc to file not found.
|
---|
214 | */
|
---|
215 | Status = STATUS_NO_SUCH_FILE;
|
---|
216 | }
|
---|
217 | else
|
---|
218 | {
|
---|
219 | /* Search continued. */
|
---|
220 | Status = STATUS_NO_MORE_FILES;
|
---|
221 | }
|
---|
222 | }
|
---|
223 | break;
|
---|
224 |
|
---|
225 | case VERR_FILE_NOT_FOUND:
|
---|
226 | Status = STATUS_NO_SUCH_FILE;
|
---|
227 | Log(("VBOXSF: MrxQueryDirectory: no such file!\n"));
|
---|
228 | break;
|
---|
229 |
|
---|
230 | default:
|
---|
231 | Status = vbsfNtVBoxStatusToNt(vrc);
|
---|
232 | Log(("VBOXSF: MrxQueryDirectory: Error %Rrc from CallDirInfo (cFiles=%d)!\n",
|
---|
233 | vrc, cFiles));
|
---|
234 | break;
|
---|
235 | }
|
---|
236 |
|
---|
237 | if (Status != STATUS_SUCCESS)
|
---|
238 | goto end;
|
---|
239 |
|
---|
240 | /* Verify that the returned buffer length is not greater than the original one. */
|
---|
241 | if (u32BufSize > (uint32_t)cbHGCMBuffer)
|
---|
242 | {
|
---|
243 | Log(("VBOXSF: MrxQueryDirectory: returned buffer size (%u) is invalid!!!\n",
|
---|
244 | u32BufSize));
|
---|
245 | Status = STATUS_INVALID_NETWORK_RESPONSE;
|
---|
246 | goto end;
|
---|
247 | }
|
---|
248 |
|
---|
249 | /* How many bytes remain in the buffer. */
|
---|
250 | cbHGCMBuffer = u32BufSize;
|
---|
251 |
|
---|
252 | pDirEntry = (PSHFLDIRINFO)pHGCMBuffer;
|
---|
253 | Status = STATUS_SUCCESS;
|
---|
254 |
|
---|
255 | Log(("VBOXSF: MrxQueryDirectory: cFiles=%d, Length=%d\n",
|
---|
256 | cFiles, cbHGCMBuffer));
|
---|
257 |
|
---|
258 | while ((*pLengthRemaining) && (cFiles > 0) && (pDirEntry != NULL))
|
---|
259 | {
|
---|
260 | int cbEntry = RT_UOFFSETOF(SHFLDIRINFO, name.String) + pDirEntry->name.u16Size;
|
---|
261 |
|
---|
262 | if (cbEntry > cbHGCMBuffer)
|
---|
263 | {
|
---|
264 | Log(("VBOXSF: MrxQueryDirectory: Entry size (%d) exceeds the buffer size (%d)!!!\n",
|
---|
265 | cbEntry, cbHGCMBuffer));
|
---|
266 | Status = STATUS_INVALID_NETWORK_RESPONSE;
|
---|
267 | goto end;
|
---|
268 | }
|
---|
269 |
|
---|
270 | switch (FileInformationClass)
|
---|
271 | {
|
---|
272 | case FileDirectoryInformation:
|
---|
273 | {
|
---|
274 | PFILE_DIRECTORY_INFORMATION pInfo = (PFILE_DIRECTORY_INFORMATION)pInfoBuffer;
|
---|
275 | Log(("VBOXSF: MrxQueryDirectory: FileDirectoryInformation\n"));
|
---|
276 |
|
---|
277 | cbToCopy = sizeof(FILE_DIRECTORY_INFORMATION);
|
---|
278 | /* Struct already contains one char for null terminator. */
|
---|
279 | cbToCopy += pDirEntry->name.u16Size;
|
---|
280 |
|
---|
281 | if (*pLengthRemaining >= cbToCopy)
|
---|
282 | {
|
---|
283 | RtlZeroMemory(pInfo, cbToCopy);
|
---|
284 |
|
---|
285 | pInfo->CreationTime.QuadPart = RTTimeSpecGetNtTime(&pDirEntry->Info.BirthTime); /* ridiculous name */
|
---|
286 | pInfo->LastAccessTime.QuadPart = RTTimeSpecGetNtTime(&pDirEntry->Info.AccessTime);
|
---|
287 | pInfo->LastWriteTime.QuadPart = RTTimeSpecGetNtTime(&pDirEntry->Info.ModificationTime);
|
---|
288 | pInfo->ChangeTime.QuadPart = RTTimeSpecGetNtTime(&pDirEntry->Info.ChangeTime);
|
---|
289 | pInfo->AllocationSize.QuadPart = pDirEntry->Info.cbAllocated;
|
---|
290 | pInfo->EndOfFile.QuadPart = pDirEntry->Info.cbObject;
|
---|
291 | pInfo->FileIndex = index;
|
---|
292 | pInfo->FileAttributes = VBoxToNTFileAttributes(pDirEntry->Info.Attr.fMode);
|
---|
293 |
|
---|
294 | INIT_FILE_NAME(pInfo, pDirEntry->name);
|
---|
295 |
|
---|
296 | /* Align to 8 byte boundary */
|
---|
297 | cbToCopy = RT_ALIGN(cbToCopy, sizeof(LONGLONG));
|
---|
298 | pInfo->NextEntryOffset = cbToCopy;
|
---|
299 | pNextOffset = &pInfo->NextEntryOffset;
|
---|
300 | }
|
---|
301 | else
|
---|
302 | {
|
---|
303 | pInfo->NextEntryOffset = 0; /* last item */
|
---|
304 | Status = STATUS_BUFFER_OVERFLOW;
|
---|
305 | }
|
---|
306 | break;
|
---|
307 | }
|
---|
308 |
|
---|
309 | case FileFullDirectoryInformation:
|
---|
310 | {
|
---|
311 | PFILE_FULL_DIR_INFORMATION pInfo = (PFILE_FULL_DIR_INFORMATION)pInfoBuffer;
|
---|
312 | Log(("VBOXSF: MrxQueryDirectory: FileFullDirectoryInformation\n"));
|
---|
313 |
|
---|
314 | cbToCopy = sizeof(FILE_FULL_DIR_INFORMATION);
|
---|
315 | /* Struct already contains one char for null terminator. */
|
---|
316 | cbToCopy += pDirEntry->name.u16Size;
|
---|
317 |
|
---|
318 | if (*pLengthRemaining >= cbToCopy)
|
---|
319 | {
|
---|
320 | RtlZeroMemory(pInfo, cbToCopy);
|
---|
321 |
|
---|
322 | pInfo->CreationTime.QuadPart = RTTimeSpecGetNtTime(&pDirEntry->Info.BirthTime); /* ridiculous name */
|
---|
323 | pInfo->LastAccessTime.QuadPart = RTTimeSpecGetNtTime(&pDirEntry->Info.AccessTime);
|
---|
324 | pInfo->LastWriteTime.QuadPart = RTTimeSpecGetNtTime(&pDirEntry->Info.ModificationTime);
|
---|
325 | pInfo->ChangeTime.QuadPart = RTTimeSpecGetNtTime(&pDirEntry->Info.ChangeTime);
|
---|
326 | pInfo->AllocationSize.QuadPart = pDirEntry->Info.cbAllocated;
|
---|
327 | pInfo->EndOfFile.QuadPart = pDirEntry->Info.cbObject;
|
---|
328 | pInfo->EaSize = 0;
|
---|
329 | pInfo->FileIndex = index;
|
---|
330 | pInfo->FileAttributes = VBoxToNTFileAttributes(pDirEntry->Info.Attr.fMode);
|
---|
331 |
|
---|
332 | INIT_FILE_NAME(pInfo, pDirEntry->name);
|
---|
333 |
|
---|
334 | /* Align to 8 byte boundary */
|
---|
335 | cbToCopy = RT_ALIGN(cbToCopy, sizeof(LONGLONG));
|
---|
336 | pInfo->NextEntryOffset = cbToCopy;
|
---|
337 | pNextOffset = &pInfo->NextEntryOffset;
|
---|
338 | }
|
---|
339 | else
|
---|
340 | {
|
---|
341 | pInfo->NextEntryOffset = 0; /* last item */
|
---|
342 | Status = STATUS_BUFFER_OVERFLOW;
|
---|
343 | }
|
---|
344 | break;
|
---|
345 | }
|
---|
346 |
|
---|
347 | case FileBothDirectoryInformation:
|
---|
348 | {
|
---|
349 | PFILE_BOTH_DIR_INFORMATION pInfo = (PFILE_BOTH_DIR_INFORMATION)pInfoBuffer;
|
---|
350 | Log(("VBOXSF: MrxQueryDirectory: FileBothDirectoryInformation\n"));
|
---|
351 |
|
---|
352 | cbToCopy = sizeof(FILE_BOTH_DIR_INFORMATION);
|
---|
353 | /* struct already contains one char for null terminator */
|
---|
354 | cbToCopy += pDirEntry->name.u16Size;
|
---|
355 |
|
---|
356 | if (*pLengthRemaining >= cbToCopy)
|
---|
357 | {
|
---|
358 | RtlZeroMemory(pInfo, cbToCopy);
|
---|
359 |
|
---|
360 | pInfo->CreationTime.QuadPart = RTTimeSpecGetNtTime(&pDirEntry->Info.BirthTime); /* ridiculous name */
|
---|
361 | pInfo->LastAccessTime.QuadPart = RTTimeSpecGetNtTime(&pDirEntry->Info.AccessTime);
|
---|
362 | pInfo->LastWriteTime.QuadPart = RTTimeSpecGetNtTime(&pDirEntry->Info.ModificationTime);
|
---|
363 | pInfo->ChangeTime.QuadPart = RTTimeSpecGetNtTime(&pDirEntry->Info.ChangeTime);
|
---|
364 | pInfo->AllocationSize.QuadPart = pDirEntry->Info.cbAllocated;
|
---|
365 | pInfo->EndOfFile.QuadPart = pDirEntry->Info.cbObject;
|
---|
366 | pInfo->EaSize = 0;
|
---|
367 | pInfo->ShortNameLength = 0; /** @todo ? */
|
---|
368 | pInfo->FileIndex = index;
|
---|
369 | pInfo->FileAttributes = VBoxToNTFileAttributes(pDirEntry->Info.Attr.fMode);
|
---|
370 |
|
---|
371 | INIT_FILE_NAME(pInfo, pDirEntry->name);
|
---|
372 |
|
---|
373 | Log(("VBOXSF: MrxQueryDirectory: FileBothDirectoryInformation cbAlloc = %x cbObject = %x\n",
|
---|
374 | pDirEntry->Info.cbAllocated, pDirEntry->Info.cbObject));
|
---|
375 | Log(("VBOXSF: MrxQueryDirectory: FileBothDirectoryInformation cbToCopy = %d, name size=%d name len=%d\n",
|
---|
376 | cbToCopy, pDirEntry->name.u16Size, pDirEntry->name.u16Length));
|
---|
377 | Log(("VBOXSF: MrxQueryDirectory: FileBothDirectoryInformation File name %.*ls (DirInfo)\n",
|
---|
378 | pInfo->FileNameLength / sizeof(WCHAR), pInfo->FileName));
|
---|
379 | Log(("VBOXSF: MrxQueryDirectory: FileBothDirectoryInformation File name %.*ls (DirEntry)\n",
|
---|
380 | pDirEntry->name.u16Size / sizeof(WCHAR), pDirEntry->name.String.ucs2));
|
---|
381 |
|
---|
382 | /* Align to 8 byte boundary. */
|
---|
383 | cbToCopy = RT_ALIGN(cbToCopy, sizeof(LONGLONG));
|
---|
384 | pInfo->NextEntryOffset = cbToCopy;
|
---|
385 | pNextOffset = &pInfo->NextEntryOffset;
|
---|
386 | }
|
---|
387 | else
|
---|
388 | {
|
---|
389 | pInfo->NextEntryOffset = 0; /* Last item. */
|
---|
390 | Status = STATUS_BUFFER_OVERFLOW;
|
---|
391 | }
|
---|
392 | break;
|
---|
393 | }
|
---|
394 |
|
---|
395 | case FileIdBothDirectoryInformation:
|
---|
396 | {
|
---|
397 | PFILE_ID_BOTH_DIR_INFORMATION pInfo = (PFILE_ID_BOTH_DIR_INFORMATION)pInfoBuffer;
|
---|
398 | Log(("VBOXSF: MrxQueryDirectory: FileIdBothDirectoryInformation\n"));
|
---|
399 |
|
---|
400 | cbToCopy = sizeof(FILE_ID_BOTH_DIR_INFORMATION);
|
---|
401 | /* struct already contains one char for null terminator */
|
---|
402 | cbToCopy += pDirEntry->name.u16Size;
|
---|
403 |
|
---|
404 | if (*pLengthRemaining >= cbToCopy)
|
---|
405 | {
|
---|
406 | RtlZeroMemory(pInfo, cbToCopy);
|
---|
407 |
|
---|
408 | pInfo->CreationTime.QuadPart = RTTimeSpecGetNtTime(&pDirEntry->Info.BirthTime); /* ridiculous name */
|
---|
409 | pInfo->LastAccessTime.QuadPart = RTTimeSpecGetNtTime(&pDirEntry->Info.AccessTime);
|
---|
410 | pInfo->LastWriteTime.QuadPart = RTTimeSpecGetNtTime(&pDirEntry->Info.ModificationTime);
|
---|
411 | pInfo->ChangeTime.QuadPart = RTTimeSpecGetNtTime(&pDirEntry->Info.ChangeTime);
|
---|
412 | pInfo->AllocationSize.QuadPart = pDirEntry->Info.cbAllocated;
|
---|
413 | pInfo->EndOfFile.QuadPart = pDirEntry->Info.cbObject;
|
---|
414 | pInfo->EaSize = 0;
|
---|
415 | pInfo->ShortNameLength = 0; /** @todo ? */
|
---|
416 | pInfo->EaSize = 0;
|
---|
417 | pInfo->FileId.QuadPart = 0;
|
---|
418 | pInfo->FileAttributes = VBoxToNTFileAttributes(pDirEntry->Info.Attr.fMode);
|
---|
419 |
|
---|
420 | INIT_FILE_NAME(pInfo, pDirEntry->name);
|
---|
421 |
|
---|
422 | Log(("VBOXSF: MrxQueryDirectory: FileIdBothDirectoryInformation cbAlloc = 0x%RX64 cbObject = 0x%RX64\n",
|
---|
423 | pDirEntry->Info.cbAllocated, pDirEntry->Info.cbObject));
|
---|
424 | Log(("VBOXSF: MrxQueryDirectory: FileIdBothDirectoryInformation cbToCopy = %d, name size=%d name len=%d\n",
|
---|
425 | cbToCopy, pDirEntry->name.u16Size, pDirEntry->name.u16Length));
|
---|
426 | Log(("VBOXSF: MrxQueryDirectory: FileIdBothDirectoryInformation File name %.*ls (DirInfo)\n",
|
---|
427 | pInfo->FileNameLength / sizeof(WCHAR), pInfo->FileName));
|
---|
428 | Log(("VBOXSF: MrxQueryDirectory: FileIdBothDirectoryInformation File name %.*ls (DirEntry)\n",
|
---|
429 | pDirEntry->name.u16Size / sizeof(WCHAR), pDirEntry->name.String.ucs2));
|
---|
430 |
|
---|
431 | /* Align to 8 byte boundary. */
|
---|
432 | cbToCopy = RT_ALIGN(cbToCopy, sizeof(LONGLONG));
|
---|
433 | pInfo->NextEntryOffset = cbToCopy;
|
---|
434 | pNextOffset = &pInfo->NextEntryOffset;
|
---|
435 | }
|
---|
436 | else
|
---|
437 | {
|
---|
438 | pInfo->NextEntryOffset = 0; /* Last item. */
|
---|
439 | Status = STATUS_BUFFER_OVERFLOW;
|
---|
440 | }
|
---|
441 | break;
|
---|
442 | }
|
---|
443 |
|
---|
444 | case FileNamesInformation:
|
---|
445 | {
|
---|
446 | PFILE_NAMES_INFORMATION pInfo = (PFILE_NAMES_INFORMATION)pInfoBuffer;
|
---|
447 | Log(("VBOXSF: MrxQueryDirectory: FileNamesInformation\n"));
|
---|
448 |
|
---|
449 | cbToCopy = sizeof(FILE_NAMES_INFORMATION);
|
---|
450 | /* Struct already contains one char for null terminator. */
|
---|
451 | cbToCopy += pDirEntry->name.u16Size;
|
---|
452 |
|
---|
453 | if (*pLengthRemaining >= cbToCopy)
|
---|
454 | {
|
---|
455 | RtlZeroMemory(pInfo, cbToCopy);
|
---|
456 |
|
---|
457 | pInfo->FileIndex = index;
|
---|
458 |
|
---|
459 | INIT_FILE_NAME(pInfo, pDirEntry->name);
|
---|
460 |
|
---|
461 | Log(("VBOXSF: MrxQueryDirectory: FileNamesInformation: File name [%.*ls]\n",
|
---|
462 | pInfo->FileNameLength / sizeof(WCHAR), pInfo->FileName));
|
---|
463 |
|
---|
464 | /* Align to 8 byte boundary. */
|
---|
465 | cbToCopy = RT_ALIGN(cbToCopy, sizeof(LONGLONG));
|
---|
466 | pInfo->NextEntryOffset = cbToCopy;
|
---|
467 | pNextOffset = &pInfo->NextEntryOffset;
|
---|
468 | }
|
---|
469 | else
|
---|
470 | {
|
---|
471 | pInfo->NextEntryOffset = 0; /* Last item. */
|
---|
472 | Status = STATUS_BUFFER_OVERFLOW;
|
---|
473 | }
|
---|
474 | break;
|
---|
475 | }
|
---|
476 |
|
---|
477 | default:
|
---|
478 | Log(("VBOXSF: MrxQueryDirectory: Not supported FileInformationClass %d!\n",
|
---|
479 | FileInformationClass));
|
---|
480 | Status = STATUS_INVALID_PARAMETER;
|
---|
481 | goto end;
|
---|
482 | }
|
---|
483 |
|
---|
484 | cbHGCMBuffer -= cbEntry;
|
---|
485 | pDirEntry = (PSHFLDIRINFO)((uintptr_t)pDirEntry + cbEntry);
|
---|
486 |
|
---|
487 | Log(("VBOXSF: MrxQueryDirectory: %d bytes left in HGCM buffer\n",
|
---|
488 | cbHGCMBuffer));
|
---|
489 |
|
---|
490 | if (*pLengthRemaining >= cbToCopy)
|
---|
491 | {
|
---|
492 | pInfoBuffer += cbToCopy;
|
---|
493 | *pLengthRemaining -= cbToCopy;
|
---|
494 | }
|
---|
495 | else
|
---|
496 | break;
|
---|
497 |
|
---|
498 | if (RxContext->QueryDirectory.ReturnSingleEntry)
|
---|
499 | break;
|
---|
500 |
|
---|
501 | /* More left? */
|
---|
502 | if (cbHGCMBuffer <= 0)
|
---|
503 | break;
|
---|
504 |
|
---|
505 | index++; /* File Index. */
|
---|
506 |
|
---|
507 | cFiles--;
|
---|
508 | }
|
---|
509 |
|
---|
510 | if (pNextOffset)
|
---|
511 | *pNextOffset = 0; /* Last pInfo->NextEntryOffset should be set to zero! */
|
---|
512 |
|
---|
513 | end:
|
---|
514 | if (pHGCMBuffer)
|
---|
515 | vbsfNtFreeNonPagedMem(pHGCMBuffer);
|
---|
516 |
|
---|
517 | if (ParsedPath)
|
---|
518 | vbsfNtFreeNonPagedMem(ParsedPath);
|
---|
519 |
|
---|
520 | Log(("VBOXSF: MrxQueryDirectory: Returned 0x%08X\n",
|
---|
521 | Status));
|
---|
522 | return Status;
|
---|
523 | }
|
---|
524 |
|
---|
525 | /**
|
---|
526 | * Updates VBSFNTFCBEXT::VolInfo.
|
---|
527 | */
|
---|
528 | static NTSTATUS vbsfNtUpdateFcbVolInfo(PVBSFNTFCBEXT pVBoxFcbX, PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension,
|
---|
529 | PMRX_VBOX_FOBX pVBoxFobx)
|
---|
530 | {
|
---|
531 | NTSTATUS rcNt;
|
---|
532 | VBOXSFVOLINFOREQ *pReq = (VBOXSFVOLINFOREQ *)VbglR0PhysHeapAlloc(sizeof(*pReq));
|
---|
533 | if (pReq)
|
---|
534 | {
|
---|
535 | int vrc = VbglR0SfHostReqQueryVolInfo(pNetRootExtension->map.root, pReq, pVBoxFobx->hFile);
|
---|
536 | if (RT_SUCCESS(vrc))
|
---|
537 | {
|
---|
538 | /* Make the units compatible with NT before assigning. */
|
---|
539 | if (pReq->VolInfo.ulBytesPerSector != 0)
|
---|
540 | {
|
---|
541 | if (pReq->VolInfo.ulBytesPerAllocationUnit > pReq->VolInfo.ulBytesPerSector)
|
---|
542 | {
|
---|
543 | uint32_t cSectorsPerUnit = pReq->VolInfo.ulBytesPerAllocationUnit / pReq->VolInfo.ulBytesPerSector;
|
---|
544 | pReq->VolInfo.ulBytesPerAllocationUnit = pReq->VolInfo.ulBytesPerSector * cSectorsPerUnit;
|
---|
545 | }
|
---|
546 | else if (pReq->VolInfo.ulBytesPerAllocationUnit < pReq->VolInfo.ulBytesPerSector)
|
---|
547 | pReq->VolInfo.ulBytesPerAllocationUnit = pReq->VolInfo.ulBytesPerSector;
|
---|
548 | }
|
---|
549 | else if (pReq->VolInfo.ulBytesPerAllocationUnit == 0)
|
---|
550 | pReq->VolInfo.ulBytesPerSector = pReq->VolInfo.ulBytesPerAllocationUnit = 512;
|
---|
551 | else
|
---|
552 | pReq->VolInfo.ulBytesPerSector = pReq->VolInfo.ulBytesPerAllocationUnit;
|
---|
553 |
|
---|
554 | /* Copy the info assigning: */
|
---|
555 | ASMCompilerBarrier();
|
---|
556 | pVBoxFcbX->VolInfo.ullTotalAllocationBytes = pReq->VolInfo.ullTotalAllocationBytes;
|
---|
557 | pVBoxFcbX->VolInfo.ullAvailableAllocationBytes = pReq->VolInfo.ullAvailableAllocationBytes;
|
---|
558 | pVBoxFcbX->VolInfo.ulBytesPerAllocationUnit = pReq->VolInfo.ulBytesPerAllocationUnit;
|
---|
559 | pVBoxFcbX->VolInfo.ulBytesPerSector = pReq->VolInfo.ulBytesPerSector;
|
---|
560 | pVBoxFcbX->VolInfo.ulSerial = pReq->VolInfo.ulSerial;
|
---|
561 | pVBoxFcbX->VolInfo.fsProperties.cbMaxComponent = pReq->VolInfo.fsProperties.cbMaxComponent;
|
---|
562 | pVBoxFcbX->VolInfo.fsProperties.fRemote = pReq->VolInfo.fsProperties.fRemote;
|
---|
563 | pVBoxFcbX->VolInfo.fsProperties.fCaseSensitive = pReq->VolInfo.fsProperties.fCaseSensitive;
|
---|
564 | pVBoxFcbX->VolInfo.fsProperties.fReadOnly = pReq->VolInfo.fsProperties.fReadOnly;
|
---|
565 | pVBoxFcbX->VolInfo.fsProperties.fSupportsUnicode = pReq->VolInfo.fsProperties.fSupportsUnicode;
|
---|
566 | pVBoxFcbX->VolInfo.fsProperties.fCompressed = pReq->VolInfo.fsProperties.fCompressed;
|
---|
567 | pVBoxFcbX->VolInfo.fsProperties.fFileCompression = pReq->VolInfo.fsProperties.fFileCompression;
|
---|
568 | ASMWriteFence();
|
---|
569 | pVBoxFcbX->nsVolInfoUpToDate = RTTimeSystemNanoTS();
|
---|
570 | ASMWriteFence();
|
---|
571 |
|
---|
572 | rcNt = STATUS_SUCCESS;
|
---|
573 | }
|
---|
574 | else
|
---|
575 | rcNt = vbsfNtVBoxStatusToNt(vrc);
|
---|
576 | VbglR0PhysHeapFree(pReq);
|
---|
577 | }
|
---|
578 | else
|
---|
579 | rcNt = STATUS_INSUFFICIENT_RESOURCES;
|
---|
580 | return rcNt;
|
---|
581 | }
|
---|
582 |
|
---|
583 |
|
---|
584 | /**
|
---|
585 | * Handles NtQueryVolumeInformationFile / FileFsVolumeInformation
|
---|
586 | */
|
---|
587 | static NTSTATUS vbsfNtQueryFsVolumeInfo(IN OUT PRX_CONTEXT pRxContext,
|
---|
588 | PFILE_FS_VOLUME_INFORMATION pInfo,
|
---|
589 | ULONG cbInfo,
|
---|
590 | PMRX_NET_ROOT pNetRoot,
|
---|
591 | PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension,
|
---|
592 | PMRX_VBOX_FOBX pVBoxFobx,
|
---|
593 | PVBSFNTFCBEXT pVBoxFcbX)
|
---|
594 | {
|
---|
595 | /*
|
---|
596 | * NtQueryVolumeInformationFile should've checked the minimum buffer size
|
---|
597 | * but just in case.
|
---|
598 | */
|
---|
599 | AssertReturnStmt(cbInfo >= RT_UOFFSETOF(FILE_FS_VOLUME_INFORMATION, VolumeLabel),
|
---|
600 | pRxContext->InformationToReturn = RT_UOFFSETOF(FILE_FS_VOLUME_INFORMATION, VolumeLabel),
|
---|
601 | STATUS_BUFFER_TOO_SMALL);
|
---|
602 |
|
---|
603 | /*
|
---|
604 | * Get up-to-date serial number.
|
---|
605 | *
|
---|
606 | * If we have a unixy host, we'll get additional unix attributes and the
|
---|
607 | * serial number is the same as INodeIdDevice.
|
---|
608 | *
|
---|
609 | * Note! Because it's possible that the host has mount points within the
|
---|
610 | * shared folder as well as symbolic links pointing out files or
|
---|
611 | * directories outside the tree, we cannot just cache the serial
|
---|
612 | * number in the net root extension data and skip querying it here.
|
---|
613 | *
|
---|
614 | * OTOH, only we don't report inode info from the host, so the only
|
---|
615 | * thing the serial number can be used for is to cache/whatever
|
---|
616 | * volume space information. So, we should probably provide a
|
---|
617 | * shortcut here via mount option, registry and guest properties.
|
---|
618 | */
|
---|
619 | /** @todo Make See OTOH above wrt. one serial per net root. */
|
---|
620 | uint64_t nsNow = RTTimeSystemNanoTS();
|
---|
621 | if ( pVBoxFobx->Info.Attr.enmAdditional == SHFLFSOBJATTRADD_UNIX
|
---|
622 | && pVBoxFobx->Info.Attr.u.Unix.INodeIdDevice != 0
|
---|
623 | && pVBoxFobx->nsUpToDate - nsNow < RT_NS_100US /** @todo implement proper TTL */)
|
---|
624 | pInfo->VolumeSerialNumber = pVBoxFobx->Info.Attr.u.Unix.INodeIdDevice;
|
---|
625 | else if (pVBoxFcbX->nsVolInfoUpToDate - nsNow < RT_NS_100MS /** @todo implement proper volume info TTL */ )
|
---|
626 | pInfo->VolumeSerialNumber = pVBoxFcbX->VolInfo.ulSerial;
|
---|
627 | else
|
---|
628 | {
|
---|
629 | /* Must fetch the info. */
|
---|
630 | NTSTATUS Status = vbsfNtUpdateFcbVolInfo(pVBoxFcbX, pNetRootExtension, pVBoxFobx);
|
---|
631 | if (NT_SUCCESS(Status))
|
---|
632 | pInfo->VolumeSerialNumber = pVBoxFcbX->VolInfo.ulSerial;
|
---|
633 | else
|
---|
634 | return Status;
|
---|
635 | }
|
---|
636 | Log(("VBOXSF: VBoxMRxQueryVolumeInfo: FileFsVolumeInformation: VolumeSerialNumber=%#010RX32\n", pInfo->VolumeSerialNumber));
|
---|
637 |
|
---|
638 | /*
|
---|
639 | * Fill in the static info.
|
---|
640 | */
|
---|
641 | pInfo->VolumeCreationTime.QuadPart = 0;
|
---|
642 | pInfo->SupportsObjects = FALSE;
|
---|
643 |
|
---|
644 | /*
|
---|
645 | * The volume label.
|
---|
646 | *
|
---|
647 | * We may get queries with insufficient buffer space for the whole (or any)
|
---|
648 | * volume label. In those cases we're to return STATUS_BUFFER_OVERFLOW,
|
---|
649 | * return the returned number of bytes in Ios.Information and set the
|
---|
650 | * VolumeLabelLength to the actual length (rather than the returned). At
|
---|
651 | * least this is was FAT and NTFS does (however, it is not what the NulMrx
|
---|
652 | * sample from the 6.1.6001.18002 does).
|
---|
653 | *
|
---|
654 | * Note! VolumeLabelLength is a byte count.
|
---|
655 | * Note! NTFS does not include a terminator, so neither do we.
|
---|
656 | */
|
---|
657 | uint32_t const cbShareName = pNetRoot->pNetRootName->Length
|
---|
658 | - pNetRoot->pSrvCall->pSrvCallName->Length
|
---|
659 | - sizeof(WCHAR) /* Remove the leading backslash. */;
|
---|
660 | uint32_t const cbVolLabel = VBOX_VOLNAME_PREFIX_SIZE + cbShareName;
|
---|
661 | pInfo->VolumeLabelLength = cbVolLabel;
|
---|
662 |
|
---|
663 | WCHAR const *pwcShareName = &pNetRoot->pNetRootName->Buffer[pNetRoot->pSrvCall->pSrvCallName->Length / sizeof(WCHAR) + 1];
|
---|
664 | uint32_t cbCopied = RT_UOFFSETOF(FILE_FS_VOLUME_INFORMATION, VolumeLabel);
|
---|
665 | NTSTATUS Status;
|
---|
666 | if (cbInfo >= cbCopied + cbVolLabel)
|
---|
667 | {
|
---|
668 | memcpy(pInfo->VolumeLabel, VBOX_VOLNAME_PREFIX, VBOX_VOLNAME_PREFIX_SIZE);
|
---|
669 | memcpy(&pInfo->VolumeLabel[VBOX_VOLNAME_PREFIX_SIZE / sizeof(WCHAR)], pwcShareName, cbShareName);
|
---|
670 | cbCopied += cbVolLabel;
|
---|
671 | Status = STATUS_SUCCESS;
|
---|
672 | Log(("VBOXSF: VBoxMRxQueryVolumeInfo: FileFsVolumeInformation: full result (%#x)\n", cbCopied));
|
---|
673 | }
|
---|
674 | else
|
---|
675 | {
|
---|
676 | if (cbInfo > cbCopied)
|
---|
677 | {
|
---|
678 | uint32_t cbLeft = cbInfo - cbCopied;
|
---|
679 | memcpy(pInfo->VolumeLabel, VBOX_VOLNAME_PREFIX, RT_MIN(cbLeft, VBOX_VOLNAME_PREFIX_SIZE));
|
---|
680 | if (cbLeft > VBOX_VOLNAME_PREFIX_SIZE)
|
---|
681 | memcpy(&pInfo->VolumeLabel[VBOX_VOLNAME_PREFIX_SIZE / sizeof(WCHAR)], pwcShareName, cbShareName);
|
---|
682 | Log(("VBOXSF: VBoxMRxQueryVolumeInfo: FileFsVolumeInformation: partial result (%#x, needed %#x)\n",
|
---|
683 | cbCopied, cbCopied + cbVolLabel));
|
---|
684 | cbCopied = cbInfo;
|
---|
685 | }
|
---|
686 | else
|
---|
687 | Log(("VBOXSF: VBoxMRxQueryVolumeInfo: FileFsVolumeInformation: partial result no label (%#x, needed %#x)\n",
|
---|
688 | cbCopied, cbCopied + cbVolLabel));
|
---|
689 | Status = STATUS_BUFFER_OVERFLOW;
|
---|
690 | }
|
---|
691 |
|
---|
692 | /*
|
---|
693 | * Update the return length in the context.
|
---|
694 | */
|
---|
695 | pRxContext->Info.LengthRemaining = cbInfo - cbCopied;
|
---|
696 | pRxContext->InformationToReturn = cbCopied; /* whatever */
|
---|
697 |
|
---|
698 | return Status;
|
---|
699 | }
|
---|
700 |
|
---|
701 | /**
|
---|
702 | * Handles NtQueryVolumeInformationFile / FileFsSizeInformation
|
---|
703 | *
|
---|
704 | * @note Almost identical to vbsfNtQueryFsFullSizeInfo.
|
---|
705 | */
|
---|
706 | static NTSTATUS vbsfNtQueryFsSizeInfo(IN OUT PRX_CONTEXT pRxContext,
|
---|
707 | PFILE_FS_SIZE_INFORMATION pInfo,
|
---|
708 | ULONG cbInfo,
|
---|
709 | PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension,
|
---|
710 | PMRX_VBOX_FOBX pVBoxFobx,
|
---|
711 | PVBSFNTFCBEXT pVBoxFcbX)
|
---|
712 | {
|
---|
713 | /*
|
---|
714 | * NtQueryVolumeInformationFile should've checked the minimum buffer size
|
---|
715 | * but just in case.
|
---|
716 | */
|
---|
717 | AssertReturnStmt(cbInfo >= sizeof(FILE_FS_SIZE_INFORMATION),
|
---|
718 | pRxContext->InformationToReturn = sizeof(FILE_FS_SIZE_INFORMATION),
|
---|
719 | STATUS_BUFFER_TOO_SMALL);
|
---|
720 |
|
---|
721 | /*
|
---|
722 | * Get up-to-date information.
|
---|
723 | * For the time being we always re-query this information from the host.
|
---|
724 | */
|
---|
725 | /** @todo don't requery this if it happens with XXXX ns of a _different_ info
|
---|
726 | * request to the same handle. */
|
---|
727 | {
|
---|
728 | /* Must fetch the info. */
|
---|
729 | NTSTATUS Status = vbsfNtUpdateFcbVolInfo(pVBoxFcbX, pNetRootExtension, pVBoxFobx);
|
---|
730 | if (NT_SUCCESS(Status))
|
---|
731 | { /* likely */ }
|
---|
732 | else
|
---|
733 | return Status;
|
---|
734 | }
|
---|
735 |
|
---|
736 | /* Make a copy of the info for paranoid reasons: */
|
---|
737 | SHFLVOLINFO VolInfoCopy;
|
---|
738 | memcpy(&VolInfoCopy, (void *)&pVBoxFcbX->VolInfo, sizeof(VolInfoCopy));
|
---|
739 | ASMCompilerBarrier();
|
---|
740 |
|
---|
741 | /*
|
---|
742 | * Produce the requested data.
|
---|
743 | */
|
---|
744 | pInfo->BytesPerSector = RT_MIN(VolInfoCopy.ulBytesPerSector, 1);
|
---|
745 | pInfo->SectorsPerAllocationUnit = VolInfoCopy.ulBytesPerAllocationUnit / pInfo->BytesPerSector;
|
---|
746 | AssertReturn(pInfo->SectorsPerAllocationUnit > 0, STATUS_INTERNAL_ERROR);
|
---|
747 | pInfo->TotalAllocationUnits.QuadPart = pVBoxFcbX->VolInfo.ullTotalAllocationBytes
|
---|
748 | / VolInfoCopy.ulBytesPerAllocationUnit;
|
---|
749 | pInfo->AvailableAllocationUnits.QuadPart = pVBoxFcbX->VolInfo.ullAvailableAllocationBytes
|
---|
750 | / VolInfoCopy.ulBytesPerAllocationUnit;
|
---|
751 |
|
---|
752 | Log(("VBOXSF: VBoxMRxQueryVolumeInfo: FileFsSizeInformation: BytesPerSector = %#010RX32\n",
|
---|
753 | pInfo->BytesPerSector));
|
---|
754 | Log(("VBOXSF: VBoxMRxQueryVolumeInfo: FileFsSizeInformation: SectorsPerAllocationUnit = %#010RX32\n",
|
---|
755 | pInfo->SectorsPerAllocationUnit));
|
---|
756 | Log(("VBOXSF: VBoxMRxQueryVolumeInfo: FileFsSizeInformation: TotalAllocationUnits = %#018RX32\n",
|
---|
757 | pInfo->TotalAllocationUnits.QuadPart));
|
---|
758 | Log(("VBOXSF: VBoxMRxQueryVolumeInfo: FileFsSizeInformation: AvailableAllocationUnits = %#018RX32\n",
|
---|
759 | pInfo->AvailableAllocationUnits.QuadPart));
|
---|
760 |
|
---|
761 | /*
|
---|
762 | * Update the return length in the context.
|
---|
763 | */
|
---|
764 | pRxContext->Info.LengthRemaining = cbInfo - sizeof(*pInfo);
|
---|
765 | pRxContext->InformationToReturn = sizeof(*pInfo); /* whatever */
|
---|
766 | return STATUS_SUCCESS;
|
---|
767 | }
|
---|
768 |
|
---|
769 | /**
|
---|
770 | * Handles NtQueryVolumeInformationFile / FileFsFullSizeInformation
|
---|
771 | *
|
---|
772 | * @note Almost identical to vbsfNtQueryFsSizeInfo.
|
---|
773 | */
|
---|
774 | static NTSTATUS vbsfNtQueryFsFullSizeInfo(IN OUT PRX_CONTEXT pRxContext,
|
---|
775 | PFILE_FS_FULL_SIZE_INFORMATION pInfo,
|
---|
776 | ULONG cbInfo,
|
---|
777 | PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension,
|
---|
778 | PMRX_VBOX_FOBX pVBoxFobx,
|
---|
779 | PVBSFNTFCBEXT pVBoxFcbX)
|
---|
780 | {
|
---|
781 | /*
|
---|
782 | * NtQueryVolumeInformationFile should've checked the minimum buffer size
|
---|
783 | * but just in case.
|
---|
784 | */
|
---|
785 | AssertReturnStmt(cbInfo >= sizeof(FILE_FS_SIZE_INFORMATION),
|
---|
786 | pRxContext->InformationToReturn = sizeof(FILE_FS_SIZE_INFORMATION),
|
---|
787 | STATUS_BUFFER_TOO_SMALL);
|
---|
788 |
|
---|
789 | /*
|
---|
790 | * Get up-to-date information.
|
---|
791 | * For the time being we always re-query this information from the host.
|
---|
792 | */
|
---|
793 | /** @todo don't requery this if it happens with XXXX ns of a _different_ info
|
---|
794 | * request to the same handle. */
|
---|
795 | {
|
---|
796 | /* Must fetch the info. */
|
---|
797 | NTSTATUS Status = vbsfNtUpdateFcbVolInfo(pVBoxFcbX, pNetRootExtension, pVBoxFobx);
|
---|
798 | if (NT_SUCCESS(Status))
|
---|
799 | { /* likely */ }
|
---|
800 | else
|
---|
801 | return Status;
|
---|
802 | }
|
---|
803 |
|
---|
804 | /* Make a copy of the info for paranoid reasons: */
|
---|
805 | SHFLVOLINFO VolInfoCopy;
|
---|
806 | memcpy(&VolInfoCopy, (void *)&pVBoxFcbX->VolInfo, sizeof(VolInfoCopy));
|
---|
807 | ASMCompilerBarrier();
|
---|
808 |
|
---|
809 | /*
|
---|
810 | * Produce the requested data.
|
---|
811 | */
|
---|
812 | pInfo->BytesPerSector = RT_MIN(VolInfoCopy.ulBytesPerSector, 1);
|
---|
813 | pInfo->SectorsPerAllocationUnit = VolInfoCopy.ulBytesPerAllocationUnit / pInfo->BytesPerSector;
|
---|
814 | AssertReturn(pInfo->SectorsPerAllocationUnit > 0, STATUS_INTERNAL_ERROR);
|
---|
815 | pInfo->TotalAllocationUnits.QuadPart = pVBoxFcbX->VolInfo.ullTotalAllocationBytes
|
---|
816 | / VolInfoCopy.ulBytesPerAllocationUnit;
|
---|
817 | pInfo->ActualAvailableAllocationUnits.QuadPart = pVBoxFcbX->VolInfo.ullAvailableAllocationBytes
|
---|
818 | / VolInfoCopy.ulBytesPerAllocationUnit;
|
---|
819 | pInfo->CallerAvailableAllocationUnits.QuadPart = pInfo->ActualAvailableAllocationUnits.QuadPart;
|
---|
820 |
|
---|
821 | Log(("VBOXSF: VBoxMRxQueryVolumeInfo: FileFsFullSizeInformation: BytesPerSector = %#010RX32\n",
|
---|
822 | pInfo->BytesPerSector));
|
---|
823 | Log(("VBOXSF: VBoxMRxQueryVolumeInfo: FileFsFullSizeInformation: SectorsPerAllocationUnit = %#010RX32\n",
|
---|
824 | pInfo->SectorsPerAllocationUnit));
|
---|
825 | Log(("VBOXSF: VBoxMRxQueryVolumeInfo: FileFsFullSizeInformation: TotalAllocationUnits = %#018RX32\n",
|
---|
826 | pInfo->TotalAllocationUnits.QuadPart));
|
---|
827 | Log(("VBOXSF: VBoxMRxQueryVolumeInfo: FileFsFullSizeInformation: ActualAvailableAllocationUnits = %#018RX32\n",
|
---|
828 | pInfo->ActualAvailableAllocationUnits.QuadPart));
|
---|
829 | Log(("VBOXSF: VBoxMRxQueryVolumeInfo: FileFsFullSizeInformation: CallerAvailableAllocationUnits = %#018RX32\n",
|
---|
830 | pInfo->CallerAvailableAllocationUnits.QuadPart));
|
---|
831 |
|
---|
832 | /*
|
---|
833 | * Update the return length in the context.
|
---|
834 | */
|
---|
835 | pRxContext->Info.LengthRemaining = cbInfo - sizeof(*pInfo);
|
---|
836 | pRxContext->InformationToReturn = sizeof(*pInfo); /* whatever */
|
---|
837 | return STATUS_SUCCESS;
|
---|
838 | }
|
---|
839 |
|
---|
840 |
|
---|
841 | /**
|
---|
842 | * Handles NtQueryVolumeInformationFile and similar.
|
---|
843 | */
|
---|
844 | NTSTATUS VBoxMRxQueryVolumeInfo(IN OUT PRX_CONTEXT RxContext)
|
---|
845 | {
|
---|
846 | NTSTATUS Status;
|
---|
847 |
|
---|
848 | RxCaptureFcb;
|
---|
849 | RxCaptureFobx;
|
---|
850 |
|
---|
851 | PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension = VBoxMRxGetNetRootExtension(capFcb->pNetRoot);
|
---|
852 | PMRX_VBOX_FOBX pVBoxFobx = VBoxMRxGetFileObjectExtension(capFobx);
|
---|
853 |
|
---|
854 | FS_INFORMATION_CLASS FsInformationClass = RxContext->Info.FsInformationClass;
|
---|
855 | PVOID pInfoBuffer = RxContext->Info.Buffer;
|
---|
856 | ULONG cbInfoBuffer = RxContext->Info.LengthRemaining;
|
---|
857 | ULONG cbToCopy = 0;
|
---|
858 | ULONG cbString = 0;
|
---|
859 |
|
---|
860 | Log(("VBOXSF: MrxQueryVolumeInfo: pInfoBuffer = %p, cbInfoBuffer = %d\n",
|
---|
861 | RxContext->Info.Buffer, RxContext->Info.LengthRemaining));
|
---|
862 | Log(("VBOXSF: MrxQueryVolumeInfo: vboxFobx = %p, Handle = 0x%RX64\n",
|
---|
863 | pVBoxFobx, pVBoxFobx? pVBoxFobx->hFile: 0));
|
---|
864 |
|
---|
865 | Status = STATUS_INVALID_PARAMETER;
|
---|
866 |
|
---|
867 | switch (FsInformationClass)
|
---|
868 | {
|
---|
869 | case FileFsVolumeInformation:
|
---|
870 | Log(("VBOXSF: VBoxMRxQueryVolumeInfo: FileFsVolumeInformation\n"));
|
---|
871 | AssertReturn(pVBoxFobx, STATUS_INVALID_PARAMETER);
|
---|
872 | Status = vbsfNtQueryFsVolumeInfo(RxContext, (PFILE_FS_VOLUME_INFORMATION)RxContext->Info.Buffer,
|
---|
873 | RxContext->Info.Length, capFcb->pNetRoot, pNetRootExtension, pVBoxFobx,
|
---|
874 | VBoxMRxGetFcbExtension(capFcb));
|
---|
875 | return Status;
|
---|
876 |
|
---|
877 | case FileFsLabelInformation:
|
---|
878 | AssertFailed(/* Only for setting, not for querying. */);
|
---|
879 | Status = STATUS_INVALID_INFO_CLASS;
|
---|
880 | break;
|
---|
881 |
|
---|
882 | case FileFsSizeInformation:
|
---|
883 | Log(("VBOXSF: VBoxMRxQueryVolumeInfo: FileFsSizeInformation\n"));
|
---|
884 | AssertReturn(pVBoxFobx, STATUS_INVALID_PARAMETER);
|
---|
885 | Status = vbsfNtQueryFsSizeInfo(RxContext, (PFILE_FS_SIZE_INFORMATION)RxContext->Info.Buffer,
|
---|
886 | RxContext->Info.Length, pNetRootExtension, pVBoxFobx,
|
---|
887 | VBoxMRxGetFcbExtension(capFcb));
|
---|
888 | return Status;
|
---|
889 |
|
---|
890 | case FileFsFullSizeInformation:
|
---|
891 | Log(("VBOXSF: VBoxMRxQueryVolumeInfo: FileFsFullSizeInformation\n"));
|
---|
892 | AssertReturn(pVBoxFobx, STATUS_INVALID_PARAMETER);
|
---|
893 | Status = vbsfNtQueryFsFullSizeInfo(RxContext, (PFILE_FS_FULL_SIZE_INFORMATION)RxContext->Info.Buffer,
|
---|
894 | RxContext->Info.Length, pNetRootExtension, pVBoxFobx,
|
---|
895 | VBoxMRxGetFcbExtension(capFcb));
|
---|
896 | return Status;
|
---|
897 |
|
---|
898 | case FileFsDeviceInformation:
|
---|
899 | {
|
---|
900 | PFILE_FS_DEVICE_INFORMATION pInfo = (PFILE_FS_DEVICE_INFORMATION)pInfoBuffer;
|
---|
901 | PMRX_NET_ROOT NetRoot = capFcb->pNetRoot;
|
---|
902 |
|
---|
903 | Log(("VBOXSF: MrxQueryVolumeInfo: FileFsDeviceInformation: Type = %d\n",
|
---|
904 | NetRoot->DeviceType));
|
---|
905 |
|
---|
906 | cbToCopy = sizeof(FILE_FS_DEVICE_INFORMATION);
|
---|
907 |
|
---|
908 | if (cbInfoBuffer < cbToCopy)
|
---|
909 | {
|
---|
910 | Status = STATUS_BUFFER_TOO_SMALL;
|
---|
911 | break;
|
---|
912 | }
|
---|
913 |
|
---|
914 | pInfo->DeviceType = NetRoot->DeviceType;
|
---|
915 | pInfo->Characteristics = FILE_REMOTE_DEVICE;
|
---|
916 |
|
---|
917 | Status = STATUS_SUCCESS;
|
---|
918 | break;
|
---|
919 | }
|
---|
920 |
|
---|
921 | case FileFsAttributeInformation:
|
---|
922 | {
|
---|
923 | PFILE_FS_ATTRIBUTE_INFORMATION pInfo = (PFILE_FS_ATTRIBUTE_INFORMATION)pInfoBuffer;
|
---|
924 |
|
---|
925 | Log(("VBOXSF: MrxQueryVolumeInfo: FileFsAttributeInformation\n"));
|
---|
926 |
|
---|
927 | cbToCopy = FIELD_OFFSET(FILE_FS_ATTRIBUTE_INFORMATION, FileSystemName);
|
---|
928 |
|
---|
929 | cbString = sizeof(MRX_VBOX_FILESYS_NAME_U);
|
---|
930 |
|
---|
931 | if (cbInfoBuffer < cbToCopy)
|
---|
932 | {
|
---|
933 | Status = STATUS_BUFFER_TOO_SMALL;
|
---|
934 | break;
|
---|
935 | }
|
---|
936 |
|
---|
937 | pInfo->FileSystemAttributes = 0; /** @todo set unicode, case sensitive etc? */
|
---|
938 | pInfo->MaximumComponentNameLength = 255; /** @todo should query from the host */
|
---|
939 |
|
---|
940 | if (cbInfoBuffer >= cbToCopy + cbString)
|
---|
941 | {
|
---|
942 | RtlCopyMemory(pInfo->FileSystemName,
|
---|
943 | MRX_VBOX_FILESYS_NAME_U,
|
---|
944 | sizeof(MRX_VBOX_FILESYS_NAME_U));
|
---|
945 | }
|
---|
946 | else
|
---|
947 | {
|
---|
948 | cbString = cbInfoBuffer - cbToCopy;
|
---|
949 |
|
---|
950 | RtlCopyMemory(pInfo->FileSystemName,
|
---|
951 | MRX_VBOX_FILESYS_NAME_U,
|
---|
952 | RT_MIN(cbString, sizeof(MRX_VBOX_FILESYS_NAME_U)));
|
---|
953 | }
|
---|
954 |
|
---|
955 | pInfo->FileSystemNameLength = cbString;
|
---|
956 |
|
---|
957 | cbToCopy += cbString;
|
---|
958 |
|
---|
959 | Log(("VBOXSF: MrxQueryVolumeInfo: FileFsAttributeInformation: FileSystemNameLength %d\n",
|
---|
960 | pInfo->FileSystemNameLength));
|
---|
961 |
|
---|
962 | Status = STATUS_SUCCESS;
|
---|
963 | break;
|
---|
964 | }
|
---|
965 |
|
---|
966 | case FileFsControlInformation:
|
---|
967 | Log(("VBOXSF: MrxQueryVolumeInfo: FileFsControlInformation: not supported\n"));
|
---|
968 | Status = STATUS_INVALID_PARAMETER;
|
---|
969 | break;
|
---|
970 |
|
---|
971 | case FileFsObjectIdInformation:
|
---|
972 | Log(("VBOXSF: MrxQueryVolumeInfo: FileFsObjectIdInformation: not supported\n"));
|
---|
973 | Status = STATUS_INVALID_PARAMETER;
|
---|
974 | break;
|
---|
975 |
|
---|
976 | case FileFsMaximumInformation:
|
---|
977 | Log(("VBOXSF: MrxQueryVolumeInfo: FileFsMaximumInformation: not supported\n"));
|
---|
978 | Status = STATUS_INVALID_PARAMETER;
|
---|
979 | break;
|
---|
980 |
|
---|
981 | default:
|
---|
982 | Log(("VBOXSF: MrxQueryVolumeInfo: Not supported FsInformationClass %d!\n",
|
---|
983 | FsInformationClass));
|
---|
984 | Status = STATUS_INVALID_PARAMETER;
|
---|
985 | break;
|
---|
986 | }
|
---|
987 |
|
---|
988 | if (Status == STATUS_SUCCESS)
|
---|
989 | RxContext->Info.LengthRemaining = cbInfoBuffer - cbToCopy;
|
---|
990 | else if (Status == STATUS_BUFFER_TOO_SMALL)
|
---|
991 | {
|
---|
992 | Log(("VBOXSF: MrxQueryVolumeInfo: Insufficient buffer size %d, required %d\n",
|
---|
993 | cbInfoBuffer, cbToCopy));
|
---|
994 | RxContext->InformationToReturn = cbToCopy;
|
---|
995 | }
|
---|
996 |
|
---|
997 | Log(("VBOXSF: MrxQueryVolumeInfo: cbToCopy = %d, LengthRemaining = %d, Status = 0x%08X\n",
|
---|
998 | cbToCopy, RxContext->Info.LengthRemaining, Status));
|
---|
999 |
|
---|
1000 | return Status;
|
---|
1001 | }
|
---|
1002 |
|
---|
1003 | /**
|
---|
1004 | * Updates the FCBs copy of the file size.
|
---|
1005 | *
|
---|
1006 | * The RDBSS is using the file size from the FCB in a few places without giving
|
---|
1007 | * us the chance to make sure that the value is up to date and properly
|
---|
1008 | * reflecting the size of the actual file on the host. Thus this mess to try
|
---|
1009 | * keep the the size up to date where ever possible as well as some hacks to
|
---|
1010 | * bypass RDBSS' use of the FCB file size. (And no, we cannot just make the
|
---|
1011 | * FCB_STATE_FILESIZECACHEING_ENABLED flag isn't set, because it was never
|
---|
1012 | * implemented.)
|
---|
1013 | *
|
---|
1014 | * @param pFileObj The file object.
|
---|
1015 | * @param pFcb The FCB.
|
---|
1016 | * @param pVBoxFobX Out file object extension data.
|
---|
1017 | * @param cbFileNew The new file size.
|
---|
1018 | * @param cbFileOld The old file size from the FCB/RDBSS.
|
---|
1019 | * @param cbAllocated The allocated size for the file, -1 if not
|
---|
1020 | * available.
|
---|
1021 | *
|
---|
1022 | * @note Will acquire the paging I/O resource lock in exclusive mode. Caller
|
---|
1023 | * must not be holding it in shared mode.
|
---|
1024 | */
|
---|
1025 | void vbsfNtUpdateFcbSize(PFILE_OBJECT pFileObj, PMRX_FCB pFcb, PMRX_VBOX_FOBX pVBoxFobX,
|
---|
1026 | LONGLONG cbFileNew, LONGLONG cbFileOld, LONGLONG cbAllocated)
|
---|
1027 | {
|
---|
1028 | Assert(cbFileNew != cbFileOld);
|
---|
1029 | Assert(cbFileNew >= 0);
|
---|
1030 | Assert( !ExIsResourceAcquiredSharedLite(pFcb->Header.PagingIoResource)
|
---|
1031 | || ExIsResourceAcquiredExclusiveLite(pFcb->Header.PagingIoResource));
|
---|
1032 |
|
---|
1033 | /*
|
---|
1034 | * Lock the paging I/O resources before trying to modify the header variables.
|
---|
1035 | *
|
---|
1036 | * Note! RxAcquirePagingIoResource and RxReleasePagingIoResource are unsafe
|
---|
1037 | * macros in need of {} wrappers when used with if statements.
|
---|
1038 | */
|
---|
1039 | NTSTATUS rcNtLock = RxAcquirePagingIoResource(NULL, pFcb);
|
---|
1040 |
|
---|
1041 | LONGLONG cbFileOldRecheck;
|
---|
1042 | RxGetFileSizeWithLock((PFCB)pFcb, &cbFileOldRecheck);
|
---|
1043 | if (cbFileOldRecheck == cbFileOld)
|
---|
1044 | {
|
---|
1045 | LONGLONG cbFileNewCopy = cbFileNew;
|
---|
1046 | RxSetFileSizeWithLock((PFCB)pFcb, &cbFileNewCopy);
|
---|
1047 |
|
---|
1048 | /* The valid data length is the same as the file size for us. */
|
---|
1049 | if (pFcb->Header.ValidDataLength.QuadPart != cbFileNew)
|
---|
1050 | pFcb->Header.ValidDataLength.QuadPart = cbFileNew;
|
---|
1051 |
|
---|
1052 | /* The allocation size must be larger or equal to the file size says https://www.osronline.com/article.cfm%5Eid=167.htm . */
|
---|
1053 | if (cbAllocated >= cbFileNew)
|
---|
1054 | {
|
---|
1055 | if (pFcb->Header.AllocationSize.QuadPart != cbAllocated)
|
---|
1056 | pFcb->Header.AllocationSize.QuadPart = cbAllocated;
|
---|
1057 | }
|
---|
1058 | else if (pFcb->Header.AllocationSize.QuadPart < cbFileNew)
|
---|
1059 | pFcb->Header.AllocationSize.QuadPart = cbFileNew;
|
---|
1060 |
|
---|
1061 | /* Update our copy. */
|
---|
1062 | pVBoxFobX->Info.cbObject = cbFileNew;
|
---|
1063 | if (cbAllocated >= 0)
|
---|
1064 | pVBoxFobX->Info.cbAllocated = cbAllocated;
|
---|
1065 |
|
---|
1066 | /*
|
---|
1067 | * Tell the cache manager if we can.
|
---|
1068 | *
|
---|
1069 | * According to the MSDN documentation, we must update the cache manager when
|
---|
1070 | * the file size changes, allocation size increases, valid data length descreases,
|
---|
1071 | * and when a non-cached I/O operation increases the valid data length.
|
---|
1072 | */
|
---|
1073 | SECTION_OBJECT_POINTERS *pSectPtrs = pFileObj->SectionObjectPointer;
|
---|
1074 | if (pSectPtrs)
|
---|
1075 | {
|
---|
1076 | LARGE_INTEGER NewSize;
|
---|
1077 | NewSize.QuadPart = cbFileNew;
|
---|
1078 | if ( cbFileNew >= cbFileOld
|
---|
1079 | || MmCanFileBeTruncated(pSectPtrs, &NewSize)) /** @todo do we need to check this? */
|
---|
1080 | {
|
---|
1081 | CC_FILE_SIZES FileSizes;
|
---|
1082 | FileSizes.AllocationSize = pFcb->Header.AllocationSize;
|
---|
1083 | FileSizes.FileSize.QuadPart = cbFileNew;
|
---|
1084 | FileSizes.ValidDataLength.QuadPart = cbFileNew;
|
---|
1085 |
|
---|
1086 | /* RDBSS leave the lock before calling CcSetFileSizes, so we do that too then.*/
|
---|
1087 | if (NT_SUCCESS(rcNtLock))
|
---|
1088 | {
|
---|
1089 | RxReleasePagingIoResource(NULL, pFcb);
|
---|
1090 | }
|
---|
1091 |
|
---|
1092 | __try
|
---|
1093 | {
|
---|
1094 | CcSetFileSizes(pFileObj, &FileSizes);
|
---|
1095 | }
|
---|
1096 | __except(EXCEPTION_EXECUTE_HANDLER)
|
---|
1097 | {
|
---|
1098 | #ifdef LOG_ENABLED
|
---|
1099 | NTSTATUS rcNt = GetExceptionCode();
|
---|
1100 | Log(("vbsfNtUpdateFcbSize: CcSetFileSizes -> %#x\n", rcNt));
|
---|
1101 | #endif
|
---|
1102 | }
|
---|
1103 | return;
|
---|
1104 | }
|
---|
1105 | /** @todo should we flag this so we can try again later? */
|
---|
1106 | }
|
---|
1107 | }
|
---|
1108 | else
|
---|
1109 | Log(("vbsfNtUpdateFcbSize: Seems we raced someone updating the file size: old size = %#RX64, new size = %#RX64, current size = %#RX64\n",
|
---|
1110 | cbFileOld, cbFileNew, cbFileOldRecheck));
|
---|
1111 |
|
---|
1112 | if (NT_SUCCESS(rcNtLock))
|
---|
1113 | {
|
---|
1114 | RxReleasePagingIoResource(NULL, pFcb);
|
---|
1115 | }
|
---|
1116 | }
|
---|
1117 |
|
---|
1118 |
|
---|
1119 | /**
|
---|
1120 | * Updates the object info to the VBox file object extension data.
|
---|
1121 | *
|
---|
1122 | * @param pVBoxFobX The VBox file object extension data.
|
---|
1123 | * @param pObjInfo The fresh data from the host. Okay to modify.
|
---|
1124 | * @param pVBoxFcbX The VBox FCB extension data.
|
---|
1125 | * @param fTimestampsToCopyAnyway VBOX_FOBX_F_INFO_XXX mask of timestamps to
|
---|
1126 | * copy regardless of their suppressed state.
|
---|
1127 | * This is used by the info setter function to
|
---|
1128 | * get current copies of newly modified and
|
---|
1129 | * suppressed fields.
|
---|
1130 | * @param pFileObj Pointer to the file object if we should
|
---|
1131 | * update the cache manager, otherwise NULL.
|
---|
1132 | * @param pFcb Pointer to the FCB if we should update its
|
---|
1133 | * copy of the file size, NULL if we should
|
---|
1134 | * leave it be. Must be NULL when pFileObj is.
|
---|
1135 | */
|
---|
1136 | static void vbsfNtCopyInfo(PMRX_VBOX_FOBX pVBoxFobX, PSHFLFSOBJINFO pObjInfo, PVBSFNTFCBEXT pVBoxFcbX,
|
---|
1137 | uint8_t fTimestampsToCopyAnyway, PFILE_OBJECT pFileObj, PMRX_FCB pFcb)
|
---|
1138 | {
|
---|
1139 | /*
|
---|
1140 | * Check if the size changed because RDBSS and the cache manager have
|
---|
1141 | * cached copies of the file and allocation sizes.
|
---|
1142 | */
|
---|
1143 | if (pFcb && pFileObj)
|
---|
1144 | {
|
---|
1145 | LONGLONG cbFileRdbss;
|
---|
1146 | RxGetFileSizeWithLock((PFCB)pFcb, &cbFileRdbss);
|
---|
1147 | if (pObjInfo->cbObject != cbFileRdbss)
|
---|
1148 | vbsfNtUpdateFcbSize(pFileObj, pFcb, pVBoxFobX, pObjInfo->cbObject, cbFileRdbss, pObjInfo->cbAllocated);
|
---|
1149 | }
|
---|
1150 |
|
---|
1151 | /*
|
---|
1152 | * Check if the modified timestamp changed and try guess if it was the host.
|
---|
1153 | */
|
---|
1154 | /** @todo use modification timestamp to detect host changes? We do on linux. */
|
---|
1155 |
|
---|
1156 | /*
|
---|
1157 | * Copy the object info over. To simplify preserving the value of timestamps
|
---|
1158 | * which implict updating is currently disabled, copy them over to the source
|
---|
1159 | * structure before preforming the copy.
|
---|
1160 | */
|
---|
1161 | Assert((pVBoxFobX->fTimestampsSetByUser & ~pVBoxFobX->fTimestampsUpdatingSuppressed) == 0);
|
---|
1162 | uint8_t fCopyTs = pVBoxFobX->fTimestampsUpdatingSuppressed & ~fTimestampsToCopyAnyway;
|
---|
1163 | if (fCopyTs)
|
---|
1164 | {
|
---|
1165 | if ( (fCopyTs & VBOX_FOBX_F_INFO_LASTACCESS_TIME)
|
---|
1166 | && pVBoxFcbX->pFobxLastAccessTime == pVBoxFobX)
|
---|
1167 | pObjInfo->AccessTime = pVBoxFobX->Info.AccessTime;
|
---|
1168 |
|
---|
1169 | if ( (fCopyTs & VBOX_FOBX_F_INFO_LASTWRITE_TIME)
|
---|
1170 | && pVBoxFcbX->pFobxLastWriteTime == pVBoxFobX)
|
---|
1171 | pObjInfo->ModificationTime = pVBoxFobX->Info.ModificationTime;
|
---|
1172 |
|
---|
1173 | if ( (fCopyTs & VBOX_FOBX_F_INFO_CHANGE_TIME)
|
---|
1174 | && pVBoxFcbX->pFobxChangeTime == pVBoxFobX)
|
---|
1175 | pObjInfo->ChangeTime = pVBoxFobX->Info.ChangeTime;
|
---|
1176 | }
|
---|
1177 | pVBoxFobX->Info = *pObjInfo;
|
---|
1178 | }
|
---|
1179 |
|
---|
1180 | /**
|
---|
1181 | * Queries the current file stats from the host and updates the RDBSS' copy of
|
---|
1182 | * the file size if necessary.
|
---|
1183 | *
|
---|
1184 | * @returns IPRT status code
|
---|
1185 | * @param pNetRootX Our net root extension data.
|
---|
1186 | * @param pFileObj The file object.
|
---|
1187 | * @param pVBoxFobX Our file object extension data.
|
---|
1188 | * @param pFcb The FCB.
|
---|
1189 | * @param pVBoxFcbX Our FCB extension data.
|
---|
1190 | */
|
---|
1191 | int vbsfNtQueryAndUpdateFcbSize(PMRX_VBOX_NETROOT_EXTENSION pNetRootX, PFILE_OBJECT pFileObj,
|
---|
1192 | PMRX_VBOX_FOBX pVBoxFobX, PMRX_FCB pFcb, PVBSFNTFCBEXT pVBoxFcbX)
|
---|
1193 | {
|
---|
1194 | VBOXSFOBJINFOREQ *pReq = (VBOXSFOBJINFOREQ *)VbglR0PhysHeapAlloc(sizeof(*pReq));
|
---|
1195 | AssertReturn(pReq, VERR_NO_MEMORY);
|
---|
1196 |
|
---|
1197 | int vrc = VbglR0SfHostReqQueryObjInfo(pNetRootX->map.root, pReq, pVBoxFobX->hFile);
|
---|
1198 | if (RT_SUCCESS(vrc))
|
---|
1199 | vbsfNtCopyInfo(pVBoxFobX, &pReq->ObjInfo, pVBoxFcbX, 0, pFileObj, pFcb);
|
---|
1200 | else
|
---|
1201 | AssertMsgFailed(("vrc=%Rrc\n", vrc));
|
---|
1202 |
|
---|
1203 | VbglR0PhysHeapFree(pReq);
|
---|
1204 | return vrc;
|
---|
1205 | }
|
---|
1206 |
|
---|
1207 | /**
|
---|
1208 | * Handle NtQueryInformationFile and similar requests.
|
---|
1209 | *
|
---|
1210 | * The RDBSS code has done various things before we get here wrt locking and
|
---|
1211 | * request pre-processing. Unless this is a paging file (FCB_STATE_PAGING_FILE)
|
---|
1212 | * or FileNameInformation is being queried, the FCB is locked. For all except
|
---|
1213 | * for FileCompressionInformation, a shared FCB access (FCB.Header.Resource) is
|
---|
1214 | * acquired, where as for FileCompressionInformation it is taken exclusively.
|
---|
1215 | */
|
---|
1216 | NTSTATUS VBoxMRxQueryFileInfo(IN PRX_CONTEXT RxContext)
|
---|
1217 | {
|
---|
1218 | RxCaptureFcb;
|
---|
1219 | RxCaptureFobx;
|
---|
1220 | NTSTATUS Status = STATUS_SUCCESS;
|
---|
1221 | PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension = VBoxMRxGetNetRootExtension(capFcb->pNetRoot);
|
---|
1222 | PMRX_VBOX_FOBX pVBoxFobx = VBoxMRxGetFileObjectExtension(capFobx);
|
---|
1223 | ULONG cbToCopy = 0;
|
---|
1224 |
|
---|
1225 | Log(("VBOXSF: VBoxMRxQueryFileInfo: Buffer = %p, Length = %x (%d) bytes, FileInformationClass = %d\n",
|
---|
1226 | RxContext->Info.Buffer, RxContext->Info.Length, RxContext->Info.Length, RxContext->Info.FileInformationClass));
|
---|
1227 |
|
---|
1228 | AssertReturn(pVBoxFobx, STATUS_INVALID_PARAMETER);
|
---|
1229 | AssertReturn(RxContext->Info.Buffer, STATUS_INVALID_PARAMETER);
|
---|
1230 |
|
---|
1231 | #define CHECK_SIZE_BREAK(a_RxContext, a_cbNeeded) \
|
---|
1232 | /* IO_STACK_LOCATION::Parameters::SetFile::Length is signed, the RxContext bugger is LONG. See end of function for why. */ \
|
---|
1233 | if ((ULONG)(a_RxContext)->Info.Length >= (a_cbNeeded)) \
|
---|
1234 | { /*likely */ } \
|
---|
1235 | else if (1) { Status = STATUS_BUFFER_TOO_SMALL; break; } else do { } while (0)
|
---|
1236 |
|
---|
1237 | switch (RxContext->Info.FileInformationClass)
|
---|
1238 | {
|
---|
1239 | /*
|
---|
1240 | * Queries we can satisfy without calling the host:
|
---|
1241 | */
|
---|
1242 |
|
---|
1243 | case FileNamesInformation:
|
---|
1244 | {
|
---|
1245 | PFILE_NAMES_INFORMATION pInfo = (PFILE_NAMES_INFORMATION)RxContext->Info.Buffer;
|
---|
1246 | PUNICODE_STRING FileName = GET_ALREADY_PREFIXED_NAME_FROM_CONTEXT(RxContext);
|
---|
1247 | Log(("VBOXSF: VBoxMRxQueryFileInfo: FileNamesInformation\n"));
|
---|
1248 |
|
---|
1249 | cbToCopy = RT_UOFFSETOF_DYN(FILE_NAMES_INFORMATION, FileName[FileName->Length / 2 + 1]);
|
---|
1250 | CHECK_SIZE_BREAK(RxContext, cbToCopy);
|
---|
1251 |
|
---|
1252 | pInfo->NextEntryOffset = 0;
|
---|
1253 | pInfo->FileIndex = 0;
|
---|
1254 | pInfo->FileNameLength = FileName->Length;
|
---|
1255 |
|
---|
1256 | RtlCopyMemory(pInfo->FileName, FileName->Buffer, FileName->Length);
|
---|
1257 | pInfo->FileName[FileName->Length] = 0;
|
---|
1258 | break;
|
---|
1259 | }
|
---|
1260 |
|
---|
1261 | case FileInternalInformation:
|
---|
1262 | {
|
---|
1263 | PFILE_INTERNAL_INFORMATION pInfo = (PFILE_INTERNAL_INFORMATION)RxContext->Info.Buffer;
|
---|
1264 | Log(("VBOXSF: VBoxMRxQueryFileInfo: FileInternalInformation\n"));
|
---|
1265 |
|
---|
1266 | cbToCopy = sizeof(FILE_INTERNAL_INFORMATION);
|
---|
1267 | CHECK_SIZE_BREAK(RxContext, cbToCopy);
|
---|
1268 |
|
---|
1269 | /* A 8-byte file reference number for the file. */
|
---|
1270 | pInfo->IndexNumber.QuadPart = (ULONG_PTR)capFcb;
|
---|
1271 | break;
|
---|
1272 | }
|
---|
1273 |
|
---|
1274 | case FileEaInformation:
|
---|
1275 | {
|
---|
1276 | PFILE_EA_INFORMATION pInfo = (PFILE_EA_INFORMATION)RxContext->Info.Buffer;
|
---|
1277 | Log(("VBOXSF: VBoxMRxQueryFileInfo: FileEaInformation\n"));
|
---|
1278 |
|
---|
1279 | cbToCopy = sizeof(FILE_EA_INFORMATION);
|
---|
1280 | CHECK_SIZE_BREAK(RxContext, cbToCopy);
|
---|
1281 |
|
---|
1282 | pInfo->EaSize = 0;
|
---|
1283 | break;
|
---|
1284 | }
|
---|
1285 |
|
---|
1286 | case FileStreamInformation:
|
---|
1287 | Log(("VBOXSF: VBoxMRxQueryFileInfo: FileStreamInformation: not supported\n"));
|
---|
1288 | Status = STATUS_INVALID_PARAMETER;
|
---|
1289 | break;
|
---|
1290 |
|
---|
1291 | case FileAlternateNameInformation:
|
---|
1292 | Log(("VBOXSF: VBoxMRxQueryFileInfo: FileStreamInformation: not implemented\n"));
|
---|
1293 | Status = STATUS_OBJECT_NAME_NOT_FOUND;
|
---|
1294 | break;
|
---|
1295 |
|
---|
1296 | case FileNumaNodeInformation:
|
---|
1297 | Log(("VBOXSF: VBoxMRxQueryFileInfo: FileNumaNodeInformation: not supported\n"));
|
---|
1298 | Status = STATUS_NO_SUCH_DEVICE; /* what's returned on a samba share */
|
---|
1299 | break;
|
---|
1300 |
|
---|
1301 | case FileStandardLinkInformation:
|
---|
1302 | Log(("VBOXSF: VBoxMRxQueryFileInfo: FileStandardLinkInformation: not supported\n"));
|
---|
1303 | Status = STATUS_NOT_SUPPORTED; /* what's returned on a samba share */
|
---|
1304 | break;
|
---|
1305 |
|
---|
1306 | /*
|
---|
1307 | * Queries where we need info from the host.
|
---|
1308 | *
|
---|
1309 | * For directories we don't necessarily go to the host but use info from when we
|
---|
1310 | * opened the them, why we do this is a little unclear as all the clues that r9630
|
---|
1311 | * give is "fixes".
|
---|
1312 | *
|
---|
1313 | * Note! We verify the buffer size after talking to the host, assuming that there
|
---|
1314 | * won't be a problem and saving an extra switch statement. IIRC the
|
---|
1315 | * NtQueryInformationFile code verfies the sizes too.
|
---|
1316 | */
|
---|
1317 | /** @todo r=bird: install a hack so we get FileAllInformation directly up here
|
---|
1318 | * rather than 5 individual queries. We may end up going 3 times to
|
---|
1319 | * the host (depending on the TTL hack) to fetch the same info over
|
---|
1320 | * and over again. */
|
---|
1321 | case FileEndOfFileInformation:
|
---|
1322 | case FileAllocationInformation:
|
---|
1323 | case FileBasicInformation:
|
---|
1324 | case FileStandardInformation:
|
---|
1325 | case FileNetworkOpenInformation:
|
---|
1326 | case FileAttributeTagInformation:
|
---|
1327 | case FileCompressionInformation:
|
---|
1328 | {
|
---|
1329 | /* Query the information if necessary. */
|
---|
1330 | if ( !(pVBoxFobx->Info.Attr.fMode & RTFS_DOS_DIRECTORY) /** @todo figure out why we don't return up-to-date info for directories! */
|
---|
1331 | && ( !pVBoxFobx->nsUpToDate
|
---|
1332 | || pVBoxFobx->nsUpToDate - RTTimeSystemNanoTS() < RT_NS_100US /** @todo implement proper TTL */ ) )
|
---|
1333 | {
|
---|
1334 | PVBSFNTFCBEXT pVBoxFcbx = VBoxMRxGetFcbExtension(capFcb);
|
---|
1335 | AssertReturn(pVBoxFcbx, STATUS_INTERNAL_ERROR);
|
---|
1336 |
|
---|
1337 | VBOXSFOBJINFOREQ *pReq = (VBOXSFOBJINFOREQ *)VbglR0PhysHeapAlloc(sizeof(*pReq));
|
---|
1338 | AssertBreakStmt(pReq, Status = STATUS_NO_MEMORY);
|
---|
1339 |
|
---|
1340 | int vrc = VbglR0SfHostReqQueryObjInfo(pNetRootExtension->map.root, pReq, pVBoxFobx->hFile);
|
---|
1341 | if (RT_SUCCESS(vrc))
|
---|
1342 | vbsfNtCopyInfo(pVBoxFobx, &pReq->ObjInfo, pVBoxFcbx, 0, /* ASSUMES that PageingIoResource is not */
|
---|
1343 | RxContext->pFobx->AssociatedFileObject, capFcb); /* held in shared mode here! */
|
---|
1344 | else
|
---|
1345 | {
|
---|
1346 | Status = vbsfNtVBoxStatusToNt(vrc);
|
---|
1347 | VbglR0PhysHeapFree(pReq);
|
---|
1348 | break;
|
---|
1349 | }
|
---|
1350 | VbglR0PhysHeapFree(pReq);
|
---|
1351 | }
|
---|
1352 |
|
---|
1353 | /* Copy it into the return buffer. */
|
---|
1354 | switch (RxContext->Info.FileInformationClass)
|
---|
1355 | {
|
---|
1356 | case FileBasicInformation:
|
---|
1357 | {
|
---|
1358 | PFILE_BASIC_INFORMATION pInfo = (PFILE_BASIC_INFORMATION)RxContext->Info.Buffer;
|
---|
1359 | Log(("VBOXSF: VBoxMRxQueryFileInfo: FileBasicInformation\n"));
|
---|
1360 |
|
---|
1361 | cbToCopy = sizeof(FILE_BASIC_INFORMATION);
|
---|
1362 | CHECK_SIZE_BREAK(RxContext, cbToCopy);
|
---|
1363 |
|
---|
1364 | pInfo->CreationTime.QuadPart = RTTimeSpecGetNtTime(&pVBoxFobx->Info.BirthTime);
|
---|
1365 | pInfo->LastAccessTime.QuadPart = RTTimeSpecGetNtTime(&pVBoxFobx->Info.AccessTime);
|
---|
1366 | pInfo->LastWriteTime.QuadPart = RTTimeSpecGetNtTime(&pVBoxFobx->Info.ModificationTime);
|
---|
1367 | pInfo->ChangeTime.QuadPart = RTTimeSpecGetNtTime(&pVBoxFobx->Info.ChangeTime);
|
---|
1368 | pInfo->FileAttributes = VBoxToNTFileAttributes(pVBoxFobx->Info.Attr.fMode);
|
---|
1369 | Log(("VBOXSF: VBoxMRxQueryFileInfo: FileBasicInformation: File attributes: 0x%x\n",
|
---|
1370 | pInfo->FileAttributes));
|
---|
1371 | break;
|
---|
1372 | }
|
---|
1373 |
|
---|
1374 | case FileStandardInformation:
|
---|
1375 | {
|
---|
1376 | PFILE_STANDARD_INFORMATION pInfo = (PFILE_STANDARD_INFORMATION)RxContext->Info.Buffer;
|
---|
1377 | Log(("VBOXSF: VBoxMRxQueryFileInfo: FileStandardInformation\n"));
|
---|
1378 |
|
---|
1379 | cbToCopy = sizeof(FILE_STANDARD_INFORMATION);
|
---|
1380 | CHECK_SIZE_BREAK(RxContext, cbToCopy);
|
---|
1381 |
|
---|
1382 | /* Note! We didn't used to set allocation size and end-of-file for directories.
|
---|
1383 | NTFS reports these, though, so why shouldn't we. */
|
---|
1384 | pInfo->AllocationSize.QuadPart = pVBoxFobx->Info.cbAllocated;
|
---|
1385 | pInfo->EndOfFile.QuadPart = pVBoxFobx->Info.cbObject;
|
---|
1386 | pInfo->NumberOfLinks = 1; /** @todo 0? */
|
---|
1387 | pInfo->DeletePending = FALSE;
|
---|
1388 | pInfo->Directory = pVBoxFobx->Info.Attr.fMode & RTFS_DOS_DIRECTORY ? TRUE : FALSE;
|
---|
1389 | break;
|
---|
1390 | }
|
---|
1391 |
|
---|
1392 | case FileNetworkOpenInformation:
|
---|
1393 | {
|
---|
1394 | PFILE_NETWORK_OPEN_INFORMATION pInfo = (PFILE_NETWORK_OPEN_INFORMATION)RxContext->Info.Buffer;
|
---|
1395 | Log(("VBOXSF: VBoxMRxQueryFileInfo: FileNetworkOpenInformation\n"));
|
---|
1396 |
|
---|
1397 | cbToCopy = sizeof(FILE_NETWORK_OPEN_INFORMATION);
|
---|
1398 | CHECK_SIZE_BREAK(RxContext, cbToCopy);
|
---|
1399 |
|
---|
1400 | pInfo->CreationTime.QuadPart = RTTimeSpecGetNtTime(&pVBoxFobx->Info.BirthTime);
|
---|
1401 | pInfo->LastAccessTime.QuadPart = RTTimeSpecGetNtTime(&pVBoxFobx->Info.AccessTime);
|
---|
1402 | pInfo->LastWriteTime.QuadPart = RTTimeSpecGetNtTime(&pVBoxFobx->Info.ModificationTime);
|
---|
1403 | pInfo->ChangeTime.QuadPart = RTTimeSpecGetNtTime(&pVBoxFobx->Info.ChangeTime);
|
---|
1404 | /* Note! We didn't used to set allocation size and end-of-file for directories.
|
---|
1405 | NTFS reports these, though, so why shouldn't we. */
|
---|
1406 | pInfo->AllocationSize.QuadPart = pVBoxFobx->Info.cbAllocated;
|
---|
1407 | pInfo->EndOfFile.QuadPart = pVBoxFobx->Info.cbObject;
|
---|
1408 | pInfo->FileAttributes = VBoxToNTFileAttributes(pVBoxFobx->Info.Attr.fMode);
|
---|
1409 | break;
|
---|
1410 | }
|
---|
1411 |
|
---|
1412 | case FileEndOfFileInformation:
|
---|
1413 | {
|
---|
1414 | PFILE_END_OF_FILE_INFORMATION pInfo = (PFILE_END_OF_FILE_INFORMATION)RxContext->Info.Buffer;
|
---|
1415 | Log(("VBOXSF: VBoxMRxQueryFileInfo: FileEndOfFileInformation\n"));
|
---|
1416 |
|
---|
1417 | cbToCopy = sizeof(FILE_END_OF_FILE_INFORMATION);
|
---|
1418 | CHECK_SIZE_BREAK(RxContext, cbToCopy);
|
---|
1419 |
|
---|
1420 | /* Note! We didn't used to set allocation size and end-of-file for directories.
|
---|
1421 | NTFS reports these, though, so why shouldn't we. */
|
---|
1422 | pInfo->EndOfFile.QuadPart = pVBoxFobx->Info.cbObject;
|
---|
1423 | break;
|
---|
1424 | }
|
---|
1425 |
|
---|
1426 | case FileAllocationInformation:
|
---|
1427 | {
|
---|
1428 | PFILE_ALLOCATION_INFORMATION pInfo = (PFILE_ALLOCATION_INFORMATION)RxContext->Info.Buffer;
|
---|
1429 | Log(("VBOXSF: VBoxMRxQueryFileInfo: FileAllocationInformation\n"));
|
---|
1430 |
|
---|
1431 | cbToCopy = sizeof(FILE_ALLOCATION_INFORMATION);
|
---|
1432 | CHECK_SIZE_BREAK(RxContext, cbToCopy);
|
---|
1433 |
|
---|
1434 | /* Note! We didn't used to set allocation size and end-of-file for directories.
|
---|
1435 | NTFS reports these, though, so why shouldn't we. */
|
---|
1436 | pInfo->AllocationSize.QuadPart = pVBoxFobx->Info.cbAllocated;
|
---|
1437 | break;
|
---|
1438 | }
|
---|
1439 |
|
---|
1440 | case FileAttributeTagInformation:
|
---|
1441 | {
|
---|
1442 | PFILE_ATTRIBUTE_TAG_INFORMATION pInfo = (PFILE_ATTRIBUTE_TAG_INFORMATION)RxContext->Info.Buffer;
|
---|
1443 | Log(("VBOXSF: VBoxMRxQueryFileInfo: FileAttributeTagInformation\n"));
|
---|
1444 |
|
---|
1445 | cbToCopy = sizeof(FILE_ATTRIBUTE_TAG_INFORMATION);
|
---|
1446 | CHECK_SIZE_BREAK(RxContext, cbToCopy);
|
---|
1447 |
|
---|
1448 | pInfo->FileAttributes = VBoxToNTFileAttributes(pVBoxFobx->Info.Attr.fMode);
|
---|
1449 | pInfo->ReparseTag = 0;
|
---|
1450 | break;
|
---|
1451 | }
|
---|
1452 |
|
---|
1453 | case FileCompressionInformation:
|
---|
1454 | {
|
---|
1455 | //PFILE_COMPRESSION_INFO pInfo = (PFILE_COMPRESSION_INFO)RxContext->Info.Buffer;
|
---|
1456 | struct MY_FILE_COMPRESSION_INFO
|
---|
1457 | {
|
---|
1458 | LARGE_INTEGER CompressedFileSize;
|
---|
1459 | WORD CompressionFormat;
|
---|
1460 | UCHAR CompressionUnitShift;
|
---|
1461 | UCHAR ChunkShift;
|
---|
1462 | UCHAR ClusterShift;
|
---|
1463 | UCHAR Reserved[3];
|
---|
1464 | } *pInfo = (struct MY_FILE_COMPRESSION_INFO *)RxContext->Info.Buffer;
|
---|
1465 | Log(("VBOXSF: VBoxMRxQueryFileInfo: FileCompressionInformation\n"));
|
---|
1466 |
|
---|
1467 | cbToCopy = sizeof(*pInfo);
|
---|
1468 | CHECK_SIZE_BREAK(RxContext, cbToCopy);
|
---|
1469 |
|
---|
1470 | pInfo->CompressedFileSize.QuadPart = pVBoxFobx->Info.cbObject;
|
---|
1471 | pInfo->CompressionFormat = 0;
|
---|
1472 | pInfo->CompressionUnitShift = 0;
|
---|
1473 | pInfo->ChunkShift = 0;
|
---|
1474 | pInfo->ClusterShift = 0;
|
---|
1475 | pInfo->Reserved[0] = 0;
|
---|
1476 | pInfo->Reserved[1] = 0;
|
---|
1477 | pInfo->Reserved[2] = 0;
|
---|
1478 | AssertCompile(sizeof(pInfo->Reserved) == 3);
|
---|
1479 | break;
|
---|
1480 | }
|
---|
1481 |
|
---|
1482 | default:
|
---|
1483 | AssertLogRelMsgFailed(("FileInformationClass=%d\n",
|
---|
1484 | RxContext->Info.FileInformationClass));
|
---|
1485 | Status = STATUS_INTERNAL_ERROR;
|
---|
1486 | break;
|
---|
1487 | }
|
---|
1488 | break;
|
---|
1489 | }
|
---|
1490 |
|
---|
1491 |
|
---|
1492 | /** @todo Implement:
|
---|
1493 | * FileHardLinkInformation: rcNt=0 (STATUS_SUCCESS) Ios.Status=0 (STATUS_SUCCESS) Ios.Information=0000000000000048
|
---|
1494 | * FileProcessIdsUsingFileInformation: rcNt=0 (STATUS_SUCCESS) Ios.Status=0 (STATUS_SUCCESS) Ios.Information=0000000000000010
|
---|
1495 | * FileNormalizedNameInformation: rcNt=0 (STATUS_SUCCESS) Ios.Status=0 (STATUS_SUCCESS) Ios.Information=00000000000000AA
|
---|
1496 | * => See during MoveFileEx call on W10.
|
---|
1497 | * FileNetworkPhysicalNameInformation: rcNt=0xc000000d (STATUS_INVALID_PARAMETER) Ios={not modified}
|
---|
1498 | * FileShortNameInformation?
|
---|
1499 | * FileNetworkPhysicalNameInformation
|
---|
1500 | */
|
---|
1501 |
|
---|
1502 | /*
|
---|
1503 | * Unsupported ones (STATUS_INVALID_PARAMETER is correct here if you
|
---|
1504 | * go by what fat + ntfs return, however samba mounts generally returns
|
---|
1505 | * STATUS_INVALID_INFO_CLASS except for pipe info - see queryfileinfo-1).
|
---|
1506 | */
|
---|
1507 | default:
|
---|
1508 | Log(("VBOXSF: VBoxMRxQueryFileInfo: Not supported FileInformationClass: %d!\n",
|
---|
1509 | RxContext->Info.FileInformationClass));
|
---|
1510 | Status = STATUS_INVALID_PARAMETER;
|
---|
1511 | break;
|
---|
1512 |
|
---|
1513 | }
|
---|
1514 | #undef CHECK_SIZE_BREAK
|
---|
1515 |
|
---|
1516 | /* Note! InformationToReturn doesn't seem to be used, instead Info.LengthRemaining should underflow
|
---|
1517 | so it can be used together with RxContext->CurrentIrpSp->Parameters.QueryFile.Length
|
---|
1518 | to calc the Ios.Information value. This explain the weird LONG type choice. */
|
---|
1519 | RxContext->InformationToReturn = cbToCopy;
|
---|
1520 | RxContext->Info.LengthRemaining -= cbToCopy;
|
---|
1521 | AssertStmt(RxContext->Info.LengthRemaining >= 0 || Status != STATUS_SUCCESS, Status = STATUS_BUFFER_TOO_SMALL);
|
---|
1522 |
|
---|
1523 | Log(("VBOXSF: VBoxMRxQueryFileInfo: Returns %#x, Remaining length = %d, cbToCopy = %u (%#x)\n",
|
---|
1524 | Status, RxContext->Info.Length, cbToCopy));
|
---|
1525 | return Status;
|
---|
1526 | }
|
---|
1527 |
|
---|
1528 | /**
|
---|
1529 | * Worker for VBoxMRxSetFileInfo.
|
---|
1530 | */
|
---|
1531 | static NTSTATUS vbsfNtSetBasicInfo(PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension, PFILE_OBJECT pFileObj, PMRX_VBOX_FOBX pVBoxFobx,
|
---|
1532 | PMRX_FCB pFcb, PVBSFNTFCBEXT pVBoxFcbx, PFILE_BASIC_INFORMATION pBasicInfo)
|
---|
1533 | {
|
---|
1534 | Log(("VBOXSF: MRxSetFileInfo: FileBasicInformation: CreationTime %RX64\n", pBasicInfo->CreationTime.QuadPart));
|
---|
1535 | Log(("VBOXSF: MRxSetFileInfo: FileBasicInformation: LastAccessTime %RX64\n", pBasicInfo->LastAccessTime.QuadPart));
|
---|
1536 | Log(("VBOXSF: MRxSetFileInfo: FileBasicInformation: LastWriteTime %RX64\n", pBasicInfo->LastWriteTime.QuadPart));
|
---|
1537 | Log(("VBOXSF: MRxSetFileInfo: FileBasicInformation: ChangeTime %RX64\n", pBasicInfo->ChangeTime.QuadPart));
|
---|
1538 | Log(("VBOXSF: MRxSetFileInfo: FileBasicInformation: FileAttributes %RX32\n", pBasicInfo->FileAttributes));
|
---|
1539 | AssertReturn(pVBoxFobx, STATUS_INTERNAL_ERROR);
|
---|
1540 | AssertReturn(pVBoxFcbx, STATUS_INTERNAL_ERROR);
|
---|
1541 | AssertReturn(pNetRootExtension, STATUS_INTERNAL_ERROR);
|
---|
1542 |
|
---|
1543 | /** @todo r=bird: The attempt at implementing the disable-timestamp-update
|
---|
1544 | * behaviour here needs a little adjusting. I'll get to that later.
|
---|
1545 | *
|
---|
1546 | * Reminders:
|
---|
1547 | *
|
---|
1548 | * X1. Drop VBOX_FOBX_F_INFO_CREATION_TIME.
|
---|
1549 | *
|
---|
1550 | * X2. Drop unused VBOX_FOBX_F_INFO_ATTRIBUTES.
|
---|
1551 | *
|
---|
1552 | * X3. Only act on VBOX_FOBX_F_INFO_CHANGE_TIME if modified attributes or grown
|
---|
1553 | * the file (?) so we don't cancel out updates by other parties (like the
|
---|
1554 | * host).
|
---|
1555 | *
|
---|
1556 | * X4. Only act on VBOX_FOBX_F_INFO_LASTWRITE_TIME if we've written to the
|
---|
1557 | * file.
|
---|
1558 | *
|
---|
1559 | * X5. Only act on VBOX_FOBX_F_INFO_LASTACCESS_TIME if we've read from the file
|
---|
1560 | * or done whatever else might modify the access time.
|
---|
1561 | *
|
---|
1562 | * 6. Don't bother calling the host if there are only zeros and -1 values.
|
---|
1563 | * => Not done / better use it to update FCB info?
|
---|
1564 | *
|
---|
1565 | * X7. Client application should probably be allowed to modify the timestamps
|
---|
1566 | * explicitly using this API after disabling updating, given the wording of
|
---|
1567 | * the footnote referenced above.
|
---|
1568 | * => Only verified via fastfat sample, need FsPerf test.
|
---|
1569 | *
|
---|
1570 | * 8. Extend the host interface to let the host handle this crap instead as it
|
---|
1571 | * can do a better job, like on windows it's done implicitly if we let -1
|
---|
1572 | * pass thru IPRT.
|
---|
1573 | * => We're actually better equipped to handle it than the host, given the
|
---|
1574 | * FCB/inode. New plan is to detect windows host and let it implement -1,
|
---|
1575 | * but use the old stuff as fallback for non-windows hosts.
|
---|
1576 | *
|
---|
1577 | * One worry here is that we hide timestamp updates made by the host or other
|
---|
1578 | * guest side processes. This could account for some of the issues we've been
|
---|
1579 | * having with the guest not noticing host side changes.
|
---|
1580 | */
|
---|
1581 |
|
---|
1582 |
|
---|
1583 | /*
|
---|
1584 | * The properties that need to be changed are set to something other
|
---|
1585 | * than zero and -1. (According to the fastfat sample code, -1 only
|
---|
1586 | * disable implicit timestamp updating, not explicit thru this code.)
|
---|
1587 | */
|
---|
1588 |
|
---|
1589 | /*
|
---|
1590 | * In the host request, zero values are ignored.
|
---|
1591 | *
|
---|
1592 | * As for the NT request, the same is true but with a slight twist for the
|
---|
1593 | * timestamp fields. If a timestamp value is non-zero, the client disables
|
---|
1594 | * implicit updating of that timestamp via this handle when reading, writing
|
---|
1595 | * and * changing attributes. The special -1 value is used to just disable
|
---|
1596 | * implicit updating without modifying the timestamp. While the value is
|
---|
1597 | * allowed for the CreationTime field, it will be treated as zero.
|
---|
1598 | *
|
---|
1599 | * More clues to the NT behaviour can be found here:
|
---|
1600 | * https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/16023025-8a78-492f-8b96-c873b042ac50
|
---|
1601 | * https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/d4bc551b-7aaf-4b4f-ba0e-3a75e7c528f0#Appendix_A_86
|
---|
1602 | *
|
---|
1603 | * P.S. One of the reasons behind suppressing of timestamp updating after setting
|
---|
1604 | * them is likely related to the need of opening objects to modify them. There are
|
---|
1605 | * no utimes() or chmod() function in NT, on the futimes() and fchmod() variants.
|
---|
1606 | */
|
---|
1607 | VBOXSFOBJINFOREQ *pReq = (VBOXSFOBJINFOREQ *)VbglR0PhysHeapAlloc(sizeof(*pReq));
|
---|
1608 | if (pReq)
|
---|
1609 | RT_ZERO(pReq->ObjInfo);
|
---|
1610 | else
|
---|
1611 | return STATUS_INSUFFICIENT_RESOURCES;
|
---|
1612 | uint32_t fModified = 0;
|
---|
1613 | uint32_t fSuppressed = 0;
|
---|
1614 |
|
---|
1615 | /** @todo FsPerf need to check what is supposed to happen if modified
|
---|
1616 | * against after -1 is specified. As state above, fastfat will not suppress
|
---|
1617 | * further setting of the timestamp like we used to do prior to revision
|
---|
1618 | * r130337 or thereabouts. */
|
---|
1619 |
|
---|
1620 | if (pBasicInfo->CreationTime.QuadPart && pBasicInfo->CreationTime.QuadPart != -1)
|
---|
1621 | RTTimeSpecSetNtTime(&pReq->ObjInfo.BirthTime, pBasicInfo->CreationTime.QuadPart);
|
---|
1622 |
|
---|
1623 | if (pBasicInfo->LastAccessTime.QuadPart)
|
---|
1624 | {
|
---|
1625 | if (pBasicInfo->LastAccessTime.QuadPart != -1)
|
---|
1626 | {
|
---|
1627 | RTTimeSpecSetNtTime(&pReq->ObjInfo.AccessTime, pBasicInfo->LastAccessTime.QuadPart);
|
---|
1628 | fModified |= VBOX_FOBX_F_INFO_LASTACCESS_TIME;
|
---|
1629 | }
|
---|
1630 | fSuppressed |= VBOX_FOBX_F_INFO_LASTACCESS_TIME;
|
---|
1631 | }
|
---|
1632 |
|
---|
1633 | if (pBasicInfo->LastWriteTime.QuadPart)
|
---|
1634 | {
|
---|
1635 | if (pBasicInfo->LastWriteTime.QuadPart != -1)
|
---|
1636 | {
|
---|
1637 | RTTimeSpecSetNtTime(&pReq->ObjInfo.ModificationTime, pBasicInfo->LastWriteTime.QuadPart);
|
---|
1638 | fModified |= VBOX_FOBX_F_INFO_LASTWRITE_TIME;
|
---|
1639 | }
|
---|
1640 | fSuppressed |= VBOX_FOBX_F_INFO_LASTWRITE_TIME;
|
---|
1641 | }
|
---|
1642 |
|
---|
1643 | if (pBasicInfo->ChangeTime.QuadPart)
|
---|
1644 | {
|
---|
1645 | if (pBasicInfo->ChangeTime.QuadPart != -1)
|
---|
1646 | {
|
---|
1647 | RTTimeSpecSetNtTime(&pReq->ObjInfo.ChangeTime, pBasicInfo->ChangeTime.QuadPart);
|
---|
1648 | fModified |= VBOX_FOBX_F_INFO_CHANGE_TIME;
|
---|
1649 | }
|
---|
1650 | fSuppressed |= VBOX_FOBX_F_INFO_CHANGE_TIME;
|
---|
1651 | }
|
---|
1652 |
|
---|
1653 | if (pBasicInfo->FileAttributes)
|
---|
1654 | {
|
---|
1655 | pReq->ObjInfo.Attr.fMode = NTToVBoxFileAttributes(pBasicInfo->FileAttributes);
|
---|
1656 | Assert(pReq->ObjInfo.Attr.fMode != 0);
|
---|
1657 | }
|
---|
1658 |
|
---|
1659 | /*
|
---|
1660 | * Call the host to do the actual updating.
|
---|
1661 | * Note! This may be a noop, but we want up-to-date info for any -1 timestamp.
|
---|
1662 | */
|
---|
1663 | int vrc = VbglR0SfHostReqSetObjInfo(pNetRootExtension->map.root, pReq, pVBoxFobx->hFile);
|
---|
1664 | NTSTATUS Status;
|
---|
1665 | if (RT_SUCCESS(vrc))
|
---|
1666 | {
|
---|
1667 | /*
|
---|
1668 | * Update our timestamp state tracking both in the file object and the file
|
---|
1669 | * control block extensions.
|
---|
1670 | */
|
---|
1671 | if (pBasicInfo->FileAttributes || fModified)
|
---|
1672 | {
|
---|
1673 | if ( pVBoxFcbx->pFobxChangeTime != pVBoxFobx
|
---|
1674 | && !(pVBoxFobx->fTimestampsUpdatingSuppressed & VBOX_FOBX_F_INFO_CHANGE_TIME))
|
---|
1675 | pVBoxFcbx->pFobxChangeTime = NULL;
|
---|
1676 | pVBoxFobx->fTimestampsImplicitlyUpdated |= VBOX_FOBX_F_INFO_CHANGE_TIME;
|
---|
1677 | }
|
---|
1678 | pVBoxFobx->fTimestampsImplicitlyUpdated &= ~fModified;
|
---|
1679 | pVBoxFobx->fTimestampsSetByUser |= fModified;
|
---|
1680 | pVBoxFobx->fTimestampsUpdatingSuppressed |= fSuppressed;
|
---|
1681 |
|
---|
1682 | if (fSuppressed)
|
---|
1683 | {
|
---|
1684 | if (fSuppressed & VBOX_FOBX_F_INFO_LASTACCESS_TIME)
|
---|
1685 | pVBoxFcbx->pFobxLastAccessTime = pVBoxFobx;
|
---|
1686 | if (fSuppressed & VBOX_FOBX_F_INFO_LASTWRITE_TIME)
|
---|
1687 | pVBoxFcbx->pFobxLastWriteTime = pVBoxFobx;
|
---|
1688 | if (fSuppressed & VBOX_FOBX_F_INFO_CHANGE_TIME)
|
---|
1689 | pVBoxFcbx->pFobxChangeTime = pVBoxFobx;
|
---|
1690 | }
|
---|
1691 |
|
---|
1692 | vbsfNtCopyInfo(pVBoxFobx, &pReq->ObjInfo, pVBoxFcbx, fSuppressed, pFileObj, pFcb);
|
---|
1693 |
|
---|
1694 | /*
|
---|
1695 | * Copy timestamps and attributes from the host into the return buffer to let
|
---|
1696 | * RDBSS update the FCB data when we return. Not sure if the FCB timestamps
|
---|
1697 | * are ever used for anything, but caller doesn't check for -1 so there will
|
---|
1698 | * be some funny/invalid timestamps in the FCB it ever does. (I seriously
|
---|
1699 | * doubt -1 is supposed to be there given that the FCB is shared and the -1
|
---|
1700 | * only applies to a given FILE_OBJECT/HANDLE.)
|
---|
1701 | */
|
---|
1702 | if (pBasicInfo->FileAttributes)
|
---|
1703 | pBasicInfo->FileAttributes = (pBasicInfo->FileAttributes & FILE_ATTRIBUTE_TEMPORARY)
|
---|
1704 | | VBoxToNTFileAttributes(pReq->ObjInfo.Attr.fMode);
|
---|
1705 | if (pBasicInfo->CreationTime.QuadPart)
|
---|
1706 | pBasicInfo->CreationTime.QuadPart = RTTimeSpecGetNtTime(&pReq->ObjInfo.BirthTime);
|
---|
1707 | if (pBasicInfo->LastAccessTime.QuadPart)
|
---|
1708 | pBasicInfo->LastAccessTime.QuadPart = RTTimeSpecGetNtTime(&pReq->ObjInfo.AccessTime);
|
---|
1709 | if (pBasicInfo->LastWriteTime.QuadPart)
|
---|
1710 | pBasicInfo->LastWriteTime.QuadPart = RTTimeSpecGetNtTime(&pReq->ObjInfo.ModificationTime);
|
---|
1711 | if (pBasicInfo->ChangeTime.QuadPart)
|
---|
1712 | pBasicInfo->ChangeTime.QuadPart = RTTimeSpecGetNtTime(&pReq->ObjInfo.ChangeTime);
|
---|
1713 |
|
---|
1714 | Status = STATUS_SUCCESS;
|
---|
1715 | }
|
---|
1716 | else
|
---|
1717 | Status = vbsfNtVBoxStatusToNt(vrc);
|
---|
1718 |
|
---|
1719 | VbglR0PhysHeapFree(pReq);
|
---|
1720 | return Status;
|
---|
1721 | }
|
---|
1722 |
|
---|
1723 | /**
|
---|
1724 | * Worker for VBoxMRxSetFileInfo.
|
---|
1725 | */
|
---|
1726 | static NTSTATUS vbsfNtSetEndOfFile(IN OUT struct _RX_CONTEXT * RxContext, IN uint64_t cbNewFileSize)
|
---|
1727 | {
|
---|
1728 | NTSTATUS Status = STATUS_SUCCESS;
|
---|
1729 |
|
---|
1730 | RxCaptureFcb;
|
---|
1731 | RxCaptureFobx;
|
---|
1732 |
|
---|
1733 | PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension = VBoxMRxGetNetRootExtension(capFcb->pNetRoot);
|
---|
1734 | PVBSFNTFCBEXT pVBoxFcbx = VBoxMRxGetFcbExtension(capFcb);
|
---|
1735 | PMRX_VBOX_FOBX pVBoxFobx = VBoxMRxGetFileObjectExtension(capFobx);
|
---|
1736 |
|
---|
1737 | PSHFLFSOBJINFO pObjInfo;
|
---|
1738 | uint32_t cbBuffer;
|
---|
1739 | int vrc;
|
---|
1740 |
|
---|
1741 | Log(("VBOXSF: vbsfNtSetEndOfFile: New size = %RX64\n",
|
---|
1742 | cbNewFileSize));
|
---|
1743 |
|
---|
1744 | Assert(pVBoxFobx && pNetRootExtension);
|
---|
1745 |
|
---|
1746 | cbBuffer = sizeof(SHFLFSOBJINFO);
|
---|
1747 | pObjInfo = (SHFLFSOBJINFO *)vbsfNtAllocNonPagedMem(cbBuffer);
|
---|
1748 | if (!pObjInfo)
|
---|
1749 | {
|
---|
1750 | AssertFailed();
|
---|
1751 | return STATUS_INSUFFICIENT_RESOURCES;
|
---|
1752 | }
|
---|
1753 |
|
---|
1754 | RtlZeroMemory(pObjInfo, cbBuffer);
|
---|
1755 | pObjInfo->cbObject = cbNewFileSize;
|
---|
1756 |
|
---|
1757 | vrc = VbglR0SfFsInfo(&g_SfClient, &pNetRootExtension->map, pVBoxFobx->hFile,
|
---|
1758 | SHFL_INFO_SET | SHFL_INFO_SIZE, &cbBuffer, (PSHFLDIRINFO)pObjInfo);
|
---|
1759 |
|
---|
1760 | Log(("VBOXSF: vbsfNtSetEndOfFile: VbglR0SfFsInfo returned %Rrc\n", vrc));
|
---|
1761 |
|
---|
1762 | Status = vbsfNtVBoxStatusToNt(vrc);
|
---|
1763 | if (Status == STATUS_SUCCESS)
|
---|
1764 | {
|
---|
1765 | pVBoxFobx->fTimestampsImplicitlyUpdated |= VBOX_FOBX_F_INFO_LASTWRITE_TIME;
|
---|
1766 | if (pVBoxFcbx->pFobxLastWriteTime != pVBoxFobx)
|
---|
1767 | pVBoxFcbx->pFobxLastWriteTime = NULL;
|
---|
1768 |
|
---|
1769 | Log(("VBOXSF: vbsfNtSetEndOfFile: VbglR0SfFsInfo new allocation size = %RX64\n",
|
---|
1770 | pObjInfo->cbAllocated));
|
---|
1771 |
|
---|
1772 | /** @todo update the file stats! */
|
---|
1773 | }
|
---|
1774 |
|
---|
1775 | if (pObjInfo)
|
---|
1776 | vbsfNtFreeNonPagedMem(pObjInfo);
|
---|
1777 |
|
---|
1778 | Log(("VBOXSF: vbsfNtSetEndOfFile: Returned 0x%08X\n", Status));
|
---|
1779 | return Status;
|
---|
1780 | }
|
---|
1781 |
|
---|
1782 | /**
|
---|
1783 | * Worker for VBoxMRxSetFileInfo handling FileRenameInformation.
|
---|
1784 | *
|
---|
1785 | * @note Renaming files from the guest is _very_ expensive:
|
---|
1786 | * - 52175 ns/call on the host
|
---|
1787 | * - 844237 ns/call from the guest
|
---|
1788 | *
|
---|
1789 | * The explanation for this is that RTPathRename translates to a
|
---|
1790 | * MoveFileEx call, which ends up doing a lot more than opening the
|
---|
1791 | * file and setting rename information on that handle (W10):
|
---|
1792 | * - Opens the file.
|
---|
1793 | * - Queries FileAllInformation.
|
---|
1794 | * - Tries to open the new filename (result: 0x00000000 but not
|
---|
1795 | * opened by our code - weird).
|
---|
1796 | * - Queries FileNormalizedNameInformation (result: 0xc000000d).
|
---|
1797 | * - Does IOCTL_REDIR_QUERY_PATH_EX on \vboxsvr\IPC$.
|
---|
1798 | * - Tries to open \vboxsvr\IPC$ (result: 0xc0000016)
|
---|
1799 | * - Opens the parent directory.
|
---|
1800 | * - Queries directory info with old name as filter.
|
---|
1801 | * - Closes parent directory handle.
|
---|
1802 | * - Finally does FileRenameInformation.
|
---|
1803 | * - Closes the handle to the renamed file.
|
---|
1804 | */
|
---|
1805 | static NTSTATUS vbsfNtRename(IN PRX_CONTEXT RxContext,
|
---|
1806 | IN PFILE_RENAME_INFORMATION pRenameInfo,
|
---|
1807 | IN ULONG cbInfo)
|
---|
1808 | {
|
---|
1809 | RxCaptureFcb;
|
---|
1810 | RxCaptureFobx;
|
---|
1811 | PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension = VBoxMRxGetNetRootExtension(capFcb->pNetRoot);
|
---|
1812 | PMRX_VBOX_FOBX pVBoxFobx = VBoxMRxGetFileObjectExtension(capFobx);
|
---|
1813 | PMRX_SRV_OPEN pSrvOpen = capFobx->pSrvOpen;
|
---|
1814 |
|
---|
1815 | /* Make sure we've got valid buffer and filename sizes: */
|
---|
1816 | AssertReturn(cbInfo >= RT_UOFFSETOF(FILE_RENAME_INFORMATION, FileName), STATUS_INFO_LENGTH_MISMATCH);
|
---|
1817 | size_t const cbFilename = pRenameInfo->FileNameLength;
|
---|
1818 | AssertReturn(cbFilename < _64K - 2, STATUS_INVALID_PARAMETER);
|
---|
1819 | AssertReturn(cbInfo - RT_UOFFSETOF(FILE_RENAME_INFORMATION, FileName) >= cbFilename, STATUS_INFO_LENGTH_MISMATCH);
|
---|
1820 |
|
---|
1821 | Log(("VBOXSF: vbsfNtRename: FileNameLength = %#x (%d), FileName = %.*ls\n",
|
---|
1822 | cbFilename, cbFilename, cbFilename / sizeof(WCHAR), &pRenameInfo->FileName[0]));
|
---|
1823 |
|
---|
1824 | /** @todo Add new function that also closes the handle, like for remove, saving a host call. */
|
---|
1825 |
|
---|
1826 | /* Must close the file before renaming it! */
|
---|
1827 | if (pVBoxFobx->hFile != SHFL_HANDLE_NIL)
|
---|
1828 | {
|
---|
1829 | Log(("VBOXSF: vbsfNtRename: Closing handle %#RX64...\n", pVBoxFobx->hFile));
|
---|
1830 | vbsfNtCloseFileHandle(pNetRootExtension, pVBoxFobx, VBoxMRxGetFcbExtension(capFcb));
|
---|
1831 | }
|
---|
1832 |
|
---|
1833 | /* Mark it as renamed, so we do nothing during close. */
|
---|
1834 | /** @todo r=bird: Isn't this a bit premature? */
|
---|
1835 | SetFlag(pSrvOpen->Flags, SRVOPEN_FLAG_FILE_RENAMED);
|
---|
1836 |
|
---|
1837 | /*
|
---|
1838 | * Allocate a request embedding the destination string.
|
---|
1839 | */
|
---|
1840 | NTSTATUS Status = STATUS_INSUFFICIENT_RESOURCES;
|
---|
1841 | size_t const cbReq = RT_UOFFSETOF(VBOXSFRENAMEWITHSRCBUFREQ, StrDstPath.String) + cbFilename + sizeof(RTUTF16);
|
---|
1842 | VBOXSFRENAMEWITHSRCBUFREQ *pReq = (VBOXSFRENAMEWITHSRCBUFREQ *)VbglR0PhysHeapAlloc((uint32_t)cbReq);
|
---|
1843 | if (pReq)
|
---|
1844 | {
|
---|
1845 | /* The destination path string. */
|
---|
1846 | pReq->StrDstPath.u16Size = (uint16_t)(cbFilename + sizeof(RTUTF16));
|
---|
1847 | pReq->StrDstPath.u16Length = (uint16_t)cbFilename;
|
---|
1848 | memcpy(&pReq->StrDstPath.String, pRenameInfo->FileName, cbFilename);
|
---|
1849 | pReq->StrDstPath.String.utf16[cbFilename / sizeof(RTUTF16)] = '\0';
|
---|
1850 |
|
---|
1851 | /* The source path string. */
|
---|
1852 | PUNICODE_STRING pNtSrcPath = GET_ALREADY_PREFIXED_NAME(pSrvOpen, capFcb);
|
---|
1853 | uint16_t const cbSrcPath = pNtSrcPath->Length;
|
---|
1854 | PSHFLSTRING pShflSrcPath = (PSHFLSTRING)VbglR0PhysHeapAlloc(SHFLSTRING_HEADER_SIZE + cbSrcPath + sizeof(RTUTF16));
|
---|
1855 | if (pShflSrcPath)
|
---|
1856 | {
|
---|
1857 | pShflSrcPath->u16Length = cbSrcPath;
|
---|
1858 | pShflSrcPath->u16Size = cbSrcPath + (uint16_t)sizeof(RTUTF16);
|
---|
1859 | memcpy(&pShflSrcPath->String, pNtSrcPath->Buffer, cbSrcPath);
|
---|
1860 | pShflSrcPath->String.utf16[cbSrcPath / sizeof(RTUTF16)] = '\0';
|
---|
1861 |
|
---|
1862 | /*
|
---|
1863 | * Call the host.
|
---|
1864 | */
|
---|
1865 | uint32_t fRename = pVBoxFobx->Info.Attr.fMode & RTFS_DOS_DIRECTORY ? SHFL_RENAME_DIR : SHFL_RENAME_FILE;
|
---|
1866 | if (pRenameInfo->ReplaceIfExists)
|
---|
1867 | fRename |= SHFL_RENAME_REPLACE_IF_EXISTS;
|
---|
1868 | Log(("VBOXSF: vbsfNtRename: Calling VbglR0SfHostReqRenameWithSrcBuf fFlags=%#x SrcPath=%.*ls, DstPath=%.*ls\n",
|
---|
1869 | fRename, pShflSrcPath->u16Length / sizeof(RTUTF16), pShflSrcPath->String.utf16,
|
---|
1870 | pReq->StrDstPath.u16Size / sizeof(RTUTF16), pReq->StrDstPath.String.utf16));
|
---|
1871 | int vrc = VbglR0SfHostReqRenameWithSrcBuf(pNetRootExtension->map.root, pReq, pShflSrcPath, fRename);
|
---|
1872 | if (RT_SUCCESS(vrc))
|
---|
1873 | Status = STATUS_SUCCESS;
|
---|
1874 | else
|
---|
1875 | {
|
---|
1876 | Status = vbsfNtVBoxStatusToNt(vrc);
|
---|
1877 | Log(("VBOXSF: vbsfNtRename: VbglR0SfRename failed with %Rrc (Status=%#x)\n", vrc, Status));
|
---|
1878 | }
|
---|
1879 |
|
---|
1880 | VbglR0PhysHeapFree(pShflSrcPath);
|
---|
1881 | }
|
---|
1882 | VbglR0PhysHeapFree(pReq);
|
---|
1883 | }
|
---|
1884 | Log(("VBOXSF: vbsfNtRename: Returned 0x%08X\n", Status));
|
---|
1885 | return Status;
|
---|
1886 | }
|
---|
1887 |
|
---|
1888 | /**
|
---|
1889 | * Handle NtSetInformationFile and similar requests.
|
---|
1890 | *
|
---|
1891 | * The RDBSS code has done various things before we get here wrt locking and
|
---|
1892 | * request pre-processing. It will normally acquire an exclusive FCB lock, but
|
---|
1893 | * not if this is related to a page file (FCB_STATE_PAGING_FILE set).
|
---|
1894 | */
|
---|
1895 | NTSTATUS VBoxMRxSetFileInfo(IN PRX_CONTEXT RxContext)
|
---|
1896 | {
|
---|
1897 | RxCaptureFcb;
|
---|
1898 | RxCaptureFobx;
|
---|
1899 | PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension = VBoxMRxGetNetRootExtension(capFcb->pNetRoot);
|
---|
1900 | PMRX_VBOX_FOBX pVBoxFobx = VBoxMRxGetFileObjectExtension(capFobx);
|
---|
1901 | NTSTATUS Status = STATUS_SUCCESS;
|
---|
1902 |
|
---|
1903 | Log(("VBOXSF: MrxSetFileInfo: Buffer = %p, Length = %#x (%d), FileInformationClass = %d\n",
|
---|
1904 | RxContext->Info.Buffer, RxContext->Info.Length, RxContext->Info.Length, RxContext->Info.FileInformationClass));
|
---|
1905 |
|
---|
1906 | /*
|
---|
1907 | * The essence of the size validation table for NtSetInformationFile from w10 build 17763:
|
---|
1908 | * UCHAR IoCheckQuerySetFileInformation[77]:
|
---|
1909 | * db 28h ; 4 FileBasicInformation, w7
|
---|
1910 | * db 18h ; 10 FileRenameInformation, w7
|
---|
1911 | * db 18h ; 11 FileLinkInformation, w7
|
---|
1912 | * db 1 ; 13 FileDispositionInformation, w7
|
---|
1913 | * db 8 ; 14 FilePositionInformation, w7
|
---|
1914 | * db 4 ; 16 FileModeInformation,
|
---|
1915 | * db 8 ; 19 FileAllocationInformation, w7
|
---|
1916 | * db 8 ; 20 FileEndOfFileInformation, w7
|
---|
1917 | * db 8 ; 23 FilePipeInformation, w7
|
---|
1918 | * db 10h ; 25 FilePipeRemoteInformation, w7
|
---|
1919 | * db 8 ; 27 FileMailslotSetInformation,
|
---|
1920 | * db 48h ; 29 FileObjectIdInformation,
|
---|
1921 | * db 10h ; 30 FileCompletionInformation, - "reserved for system use"
|
---|
1922 | * db 18h ; 31 FileMoveClusterInformation, w7 - "reserved for system use"
|
---|
1923 | * db 38h ; 32 FileQuotaInformation,
|
---|
1924 | * db 10h ; 36 FileTrackingInformation, - "reserved for system use"
|
---|
1925 | * db 8 ; 39 FileValidDataLengthInformation, w7
|
---|
1926 | * db 8 ; 40 FileShortNameInformation, w7
|
---|
1927 | * db 4 ; 41 FileIoCompletionNotificationInformation, - "reserved for system use"
|
---|
1928 | * db 10h ; 42 FileIoStatusBlockRangeInformation, - "reserved for system use"
|
---|
1929 | * db 4 ; 43 FileIoPriorityHintInformation,
|
---|
1930 | * db 14h ; 44 FileSfioReserveInformation, - "reserved for system use"
|
---|
1931 | * db 10h ; 61 FileReplaceCompletionInformation,
|
---|
1932 | * db 4 ; 64 FileDispositionInformationEx, - Adds posix semantics and stuff.
|
---|
1933 | * db 18h ; 65 FileRenameInformationEx, - Adds posix semantics and stuff.
|
---|
1934 | * db 8 ; 67 FileDesiredStorageClassInformation,
|
---|
1935 | * db 10h ; 69 FileMemoryPartitionInformation, - "reserved for system use", W10-1709
|
---|
1936 | * db 4 ; 71 FileCaseSensitiveInformation, - Per dir case sensitivity. (For linux?)
|
---|
1937 | * db 18h ; 72 FileLinkInformationEx, - Adds posix semantics and stuff.
|
---|
1938 | * db 4 ; 74 FileStorageReserveIdInformation,
|
---|
1939 | * db 4 ; 75 FileCaseSensitiveInformationForceAccessCheck, - for the i/o manager, w10-1809.
|
---|
1940 | *
|
---|
1941 | * Note! Using WDK 7600.16385.1/wnet, we're limited in what gets passed along, unknown
|
---|
1942 | * stuff will be rejected with STATUS_INVALID_PARAMETER and never get here. OTOH,
|
---|
1943 | * the 10.00.16299.0 WDK will forward anything it doesn't know from what I can tell.
|
---|
1944 | * Not sure exactly when this changed.
|
---|
1945 | */
|
---|
1946 | switch ((int)RxContext->Info.FileInformationClass)
|
---|
1947 | {
|
---|
1948 | /*
|
---|
1949 | * This is used to modify timestamps and attributes.
|
---|
1950 | *
|
---|
1951 | * Upon successful return, RDBSS will ensure that FILE_ATTRIBUTE_DIRECTORY is set
|
---|
1952 | * according to the FCB object type (see RxFinishFcbInitialization in path.cpp),
|
---|
1953 | * and that the FILE_ATTRIBUTE_TEMPORARY attribute is reflected in FcbState
|
---|
1954 | * (FCB_STATE_TEMPORARY) and the file object flags (FO_TEMPORARY_FILE). It will
|
---|
1955 | * also copy each non-zero timestamp into the FCB and set the corresponding
|
---|
1956 | * FOBX_FLAG_USER_SET_xxxx flag in the FOBX.
|
---|
1957 | *
|
---|
1958 | * RDBSS behaviour is idential between 16299.0/w10 and 7600.16385.1/wnet.
|
---|
1959 | */
|
---|
1960 | case FileBasicInformation:
|
---|
1961 | {
|
---|
1962 | Assert(RxContext->Info.Length >= sizeof(FILE_BASIC_INFORMATION));
|
---|
1963 | Status = vbsfNtSetBasicInfo(pNetRootExtension, RxContext->pFobx->AssociatedFileObject, pVBoxFobx, capFcb,
|
---|
1964 | VBoxMRxGetFcbExtension(capFcb), (PFILE_BASIC_INFORMATION)RxContext->Info.Buffer);
|
---|
1965 | break;
|
---|
1966 | }
|
---|
1967 |
|
---|
1968 | /*
|
---|
1969 | * This is used to rename a file.
|
---|
1970 | */
|
---|
1971 | case FileRenameInformation:
|
---|
1972 | {
|
---|
1973 | #ifdef LOG_ENABLED
|
---|
1974 | PFILE_RENAME_INFORMATION pInfo = (PFILE_RENAME_INFORMATION)RxContext->Info.Buffer;
|
---|
1975 | Log(("VBOXSF: MrxSetFileInfo: FileRenameInformation: ReplaceIfExists = %d, RootDirectory = 0x%x = [%.*ls]\n",
|
---|
1976 | pInfo->ReplaceIfExists, pInfo->RootDirectory, pInfo->FileNameLength / sizeof(WCHAR), pInfo->FileName));
|
---|
1977 | #endif
|
---|
1978 |
|
---|
1979 | Status = vbsfNtRename(RxContext, (PFILE_RENAME_INFORMATION)RxContext->Info.Buffer, RxContext->Info.Length);
|
---|
1980 | break;
|
---|
1981 | }
|
---|
1982 |
|
---|
1983 | /*
|
---|
1984 | * This is presumably used for hardlinking purposes. We don't support that.
|
---|
1985 | */
|
---|
1986 | case FileLinkInformation:
|
---|
1987 | {
|
---|
1988 | #ifdef LOG_ENABLED
|
---|
1989 | PFILE_LINK_INFORMATION pInfo = (PFILE_LINK_INFORMATION )RxContext->Info.Buffer;
|
---|
1990 | Log(("VBOXSF: MrxSetFileInfo: FileLinkInformation: ReplaceIfExists = %d, RootDirectory = 0x%x = [%.*ls]. Not implemented!\n",
|
---|
1991 | pInfo->ReplaceIfExists, pInfo->RootDirectory, pInfo->FileNameLength / sizeof(WCHAR), pInfo->FileName));
|
---|
1992 | #endif
|
---|
1993 |
|
---|
1994 | Status = STATUS_NOT_IMPLEMENTED;
|
---|
1995 | break;
|
---|
1996 | }
|
---|
1997 |
|
---|
1998 | /*
|
---|
1999 | * This is used to delete file.
|
---|
2000 | */
|
---|
2001 | case FileDispositionInformation:
|
---|
2002 | {
|
---|
2003 | PFILE_DISPOSITION_INFORMATION pInfo = (PFILE_DISPOSITION_INFORMATION)RxContext->Info.Buffer;
|
---|
2004 | Log(("VBOXSF: MrxSetFileInfo: FileDispositionInformation: Delete = %d\n",
|
---|
2005 | pInfo->DeleteFile));
|
---|
2006 |
|
---|
2007 | if (pInfo->DeleteFile && capFcb->OpenCount == 1)
|
---|
2008 | Status = vbsfNtRemove(RxContext);
|
---|
2009 | else
|
---|
2010 | Status = STATUS_SUCCESS;
|
---|
2011 | break;
|
---|
2012 | }
|
---|
2013 |
|
---|
2014 | /*
|
---|
2015 | * The file position is handled by the RDBSS library (RxSetPositionInfo)
|
---|
2016 | * and we should never see this request.
|
---|
2017 | */
|
---|
2018 | case FilePositionInformation:
|
---|
2019 | AssertMsgFailed(("VBOXSF: MrxSetFileInfo: FilePositionInformation: CurrentByteOffset = 0x%RX64. Unsupported!\n",
|
---|
2020 | ((PFILE_POSITION_INFORMATION)RxContext->Info.Buffer)->CurrentByteOffset.QuadPart));
|
---|
2021 | Status = STATUS_INTERNAL_ERROR;
|
---|
2022 | break;
|
---|
2023 |
|
---|
2024 | /*
|
---|
2025 | * Change the allocation size, leaving the EOF alone unless the file shrinks.
|
---|
2026 | *
|
---|
2027 | * There is no shared folder operation for this, so we only need to care
|
---|
2028 | * about adjusting EOF if the file shrinks.
|
---|
2029 | *
|
---|
2030 | * https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/d4bc551b-7aaf-4b4f-ba0e-3a75e7c528f0#Appendix_A_83
|
---|
2031 | */
|
---|
2032 | case FileAllocationInformation:
|
---|
2033 | {
|
---|
2034 | PFILE_ALLOCATION_INFORMATION pInfo = (PFILE_ALLOCATION_INFORMATION)RxContext->Info.Buffer;
|
---|
2035 | Log(("VBOXSF: MrxSetFileInfo: FileAllocationInformation: new AllocSize = 0x%RX64, FileSize = 0x%RX64\n",
|
---|
2036 | pInfo->AllocationSize.QuadPart, capFcb->Header.FileSize.QuadPart));
|
---|
2037 |
|
---|
2038 | if (pInfo->AllocationSize.QuadPart >= capFcb->Header.FileSize.QuadPart)
|
---|
2039 | Status = STATUS_SUCCESS;
|
---|
2040 | else
|
---|
2041 | {
|
---|
2042 | /** @todo get up to date EOF from host? We may risk accidentally growing the
|
---|
2043 | * file here if the host (or someone else) truncated it. */
|
---|
2044 | Status = vbsfNtSetEndOfFile(RxContext, pInfo->AllocationSize.QuadPart);
|
---|
2045 | }
|
---|
2046 | break;
|
---|
2047 | }
|
---|
2048 |
|
---|
2049 | /*
|
---|
2050 | * Prior to calling us, RxSetEndOfFileInfo will have updated the FCB fields space.FileSize,
|
---|
2051 | * Header.AllocationSize and (if old value was larger) Header.ValidDataLength. On success
|
---|
2052 | * it will inform the cache manager, while on failure the old values will be restored.
|
---|
2053 | *
|
---|
2054 | * Note! RxSetEndOfFileInfo assumes that the old Header.FileSize value is up to date and
|
---|
2055 | * will hide calls which does not change the size from us. This is of course not
|
---|
2056 | * the case for non-local file systems, as the server is the only which up-to-date
|
---|
2057 | * information.
|
---|
2058 | *
|
---|
2059 | * We work around this either by modifying FCB.Header.FileSize slightly when it equals
|
---|
2060 | * the new size. This is either done below in the FileEndOfFileInformation + 4096 case,
|
---|
2061 | * or when using older WDK libs in VBoxHookMjSetInformation. The FCB is locked
|
---|
2062 | * exclusivly while we operate with the incorrect Header.FileSize value, which should
|
---|
2063 | * prevent anyone else from making use of it till it has been updated again.
|
---|
2064 | *
|
---|
2065 | */
|
---|
2066 | case FileEndOfFileInformation:
|
---|
2067 | {
|
---|
2068 | PFILE_END_OF_FILE_INFORMATION pInfo = (PFILE_END_OF_FILE_INFORMATION)RxContext->Info.Buffer;
|
---|
2069 | Log(("VBOXSF: MrxSetFileInfo: FileEndOfFileInformation: new EndOfFile 0x%RX64, FileSize = 0x%RX64\n",
|
---|
2070 | pInfo->EndOfFile.QuadPart, capFcb->Header.FileSize.QuadPart));
|
---|
2071 |
|
---|
2072 | Status = vbsfNtSetEndOfFile(RxContext, pInfo->EndOfFile.QuadPart);
|
---|
2073 |
|
---|
2074 | Log(("VBOXSF: MrxSetFileInfo: FileEndOfFileInformation: Status 0x%08X\n",
|
---|
2075 | Status));
|
---|
2076 | break;
|
---|
2077 | }
|
---|
2078 |
|
---|
2079 | #if 0 /* This only works for more recent versions of the RDBSS library, not for the one we're using (WDK 7600.16385.1). */
|
---|
2080 | /*
|
---|
2081 | * HACK ALERT! This is FileEndOfFileInformation after it passed thru
|
---|
2082 | * VBoxHookMjSetInformation so we can twiddle the cached file size in
|
---|
2083 | * the FCB to ensure the set EOF request always reaches the host.
|
---|
2084 | *
|
---|
2085 | * Note! We have to call thru RxSetEndOfFileInfo to benefit from its
|
---|
2086 | * update logic and avoid needing to replicate that code.
|
---|
2087 | */
|
---|
2088 | case FileEndOfFileInformation + 4096:
|
---|
2089 | {
|
---|
2090 | PFILE_END_OF_FILE_INFORMATION pInfo = (PFILE_END_OF_FILE_INFORMATION)RxContext->Info.Buffer;
|
---|
2091 | Log(("VBOXSF: MrxSetFileInfo: FileEndOfFileInformation+4096: new EndOfFile 0x%RX64, FileSize = 0x%RX64\n",
|
---|
2092 | pInfo->EndOfFile.QuadPart, capFcb->Header.FileSize.QuadPart));
|
---|
2093 |
|
---|
2094 | /* Undo the change from VBoxHookMjSetInformation: */
|
---|
2095 | Assert(RxContext->CurrentIrpSp);
|
---|
2096 | RxContext->CurrentIrpSp->Parameters.SetFile.FileInformationClass = FileEndOfFileInformation;
|
---|
2097 | RxContext->Info.FileInformationClass = FileEndOfFileInformation;
|
---|
2098 |
|
---|
2099 | /* Tweak the size if necessary and forward the call. */
|
---|
2100 | int64_t const cbOldSize = capFcb->Header.FileSize.QuadPart;
|
---|
2101 | if ( pInfo->EndOfFile.QuadPart != cbOldSize
|
---|
2102 | || !(capFcb->FcbState & FCB_STATE_PAGING_FILE))
|
---|
2103 | {
|
---|
2104 | Status = RxSetEndOfFileInfo(RxContext, RxContext->CurrentIrp, (PFCB)capFcb, (PFOBX)capFobx);
|
---|
2105 | Log(("VBOXSF: MrxSetFileInfo: FileEndOfFileInformation+4096: Status 0x%08X\n",
|
---|
2106 | Status));
|
---|
2107 | }
|
---|
2108 | else
|
---|
2109 | {
|
---|
2110 | int64_t const cbHackedSize = cbOldSize ? cbOldSize - 1 : 1;
|
---|
2111 | capFcb->Header.FileSize.QuadPart = cbHackedSize;
|
---|
2112 | Status = RxSetEndOfFileInfo(RxContext, RxContext->CurrentIrp, (PFCB)capFcb, (PFOBX)capFobx);
|
---|
2113 | if ( !NT_SUCCESS(Status)
|
---|
2114 | && capFcb->Header.FileSize.QuadPart == cbHackedSize)
|
---|
2115 | capFcb->Header.FileSize.QuadPart = cbOldSize;
|
---|
2116 | else
|
---|
2117 | Assert( capFcb->Header.FileSize.QuadPart != cbHackedSize
|
---|
2118 | || pVBoxFobx->Info.cbObject == cbHackedSize);
|
---|
2119 | Log(("VBOXSF: MrxSetFileInfo: FileEndOfFileInformation+4096: Status 0x%08X (tweaked)\n",
|
---|
2120 | Status));
|
---|
2121 | }
|
---|
2122 | break;
|
---|
2123 | }
|
---|
2124 | #endif
|
---|
2125 |
|
---|
2126 | /// @todo FileModeInformation ?
|
---|
2127 | /// @todo return access denied or something for FileValidDataLengthInformation?
|
---|
2128 |
|
---|
2129 | default:
|
---|
2130 | Log(("VBOXSF: MrxSetFileInfo: Not supported FileInformationClass: %d!\n",
|
---|
2131 | RxContext->Info.FileInformationClass));
|
---|
2132 | Status = STATUS_INVALID_PARAMETER;
|
---|
2133 | break;
|
---|
2134 | }
|
---|
2135 |
|
---|
2136 | Log(("VBOXSF: MrxSetFileInfo: Returned 0x%08X\n", Status));
|
---|
2137 | return Status;
|
---|
2138 | }
|
---|
2139 |
|
---|
2140 | NTSTATUS VBoxMRxSetFileInfoAtCleanup(IN PRX_CONTEXT RxContext)
|
---|
2141 | {
|
---|
2142 | RT_NOREF(RxContext);
|
---|
2143 | Log(("VBOXSF: MRxSetFileInfoAtCleanup\n"));
|
---|
2144 | return STATUS_SUCCESS;
|
---|
2145 | }
|
---|
2146 |
|
---|