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