VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR0LibSharedFolders.c@ 85271

Last change on this file since 85271 was 82968, checked in by vboxsync, 5 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 27.5 KB
Line 
1/* $Id: VBoxGuestR0LibSharedFolders.c 82968 2020-02-04 10:35:17Z vboxsync $ */
2/** @file
3 * VBoxGuestR0LibSharedFolders - Ring 0 Shared Folders calls.
4 */
5
6/*
7 * Copyright (C) 2006-2020 Oracle Corporation
8 *
9 * Permission is hereby granted, free of charge, to any person
10 * obtaining a copy of this software and associated documentation
11 * files (the "Software"), to deal in the Software without
12 * restriction, including without limitation the rights to use,
13 * copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following
16 * conditions:
17 *
18 * The above copyright notice and this permission notice shall be
19 * included in all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
23 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
26 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28 * OTHER DEALINGS IN THE SOFTWARE.
29 */
30
31
32/*********************************************************************************************************************************
33* Header Files *
34*********************************************************************************************************************************/
35#define LOG_GROUP LOG_GROUP_SHARED_FOLDERS
36#include "VBoxGuestR0LibInternal.h"
37#include <VBox/VBoxGuestLibSharedFolders.h>
38#include <VBox/log.h>
39#include <iprt/err.h>
40#include <iprt/time.h>
41#include <iprt/mem.h>
42#include <iprt/path.h>
43#include <iprt/string.h>
44
45#ifdef VBGL_VBOXGUEST
46# error "This file shouldn't be part of the VBoxGuestR0LibBase library that is linked into VBoxGuest. It's client code."
47#endif
48
49
50/*********************************************************************************************************************************
51* Defined Constants And Macros *
52*********************************************************************************************************************************/
53#define VBOX_INIT_CALL(a, b, c) \
54 LogFunc(("%s, idClient=%d\n", "SHFL_FN_" # b, (c)->idClient)); \
55 VBGL_HGCM_HDR_INIT(a, (c)->idClient, SHFL_FN_##b, SHFL_CPARMS_##b); \
56 (a)->fInterruptible = false /* Currently we do like nfs with -o hard (default). */
57
58#define VBOX_INIT_CALL_EX(a, b, c, a_cbReq) \
59 LogFunc(("%s, idClient=%d\n", "SHFL_FN_" # b, (c)->idClient)); \
60 VBGL_HGCM_HDR_INIT_EX(a, (c)->idClient, SHFL_FN_##b, SHFL_CPARMS_##b, a_cbReq); \
61 (a)->fInterruptible = false /* Currently we do like nfs with -o hard (default). */
62
63
64
65DECLVBGL(int) VbglR0SfInit(void)
66{
67 return VbglR0InitClient();
68}
69
70DECLVBGL(void) VbglR0SfTerm(void)
71{
72 VbglR0TerminateClient();
73}
74
75DECLVBGL(int) VbglR0SfConnect(PVBGLSFCLIENT pClient)
76{
77 int rc = VbglR0HGCMConnect(&pClient->handle, "VBoxSharedFolders", &pClient->idClient);
78 if (RT_SUCCESS(rc))
79 LogFunc(("idClient=%d\n", pClient->idClient));
80 else
81 LogFunc(("VbglR0HGCMConnect failed -> rc=%Rrc\n", rc));
82 return rc;
83}
84
85DECLVBGL(void) VbglR0SfDisconnect(PVBGLSFCLIENT pClient)
86{
87 int rc;
88 LogFunc(("u32ClientID=%d\n", pClient->idClient));
89 if (pClient->handle == NULL)
90 return; /* not connected */
91
92 rc = VbglR0HGCMDisconnect(pClient->handle, pClient->idClient);
93 NOREF(rc);
94/* Log(("VBOXSF: VbglR0SfDisconnect: VbglR0HGCMDisconnect -> %#x\n", rc)); */
95 pClient->idClient = 0;
96 pClient->handle = NULL;
97 return;
98}
99
100#if !defined(RT_OS_LINUX)
101
102# ifndef RT_OS_WINDOWS
103
104DECLVBGL(int) VbglR0SfSetUtf8(PVBGLSFCLIENT pClient)
105{
106 int rc;
107 VBGLIOCHGCMCALL callInfo;
108
109 VBOX_INIT_CALL(&callInfo, SET_UTF8, pClient);
110 rc = VbglR0HGCMCall(pClient->handle, &callInfo, sizeof(callInfo));
111/* Log(("VBOXSF: VbglR0SfSetUtf8: VbglR0HGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.Hdr.rc)); */
112 return rc;
113}
114
115# endif /* !RT_OS_WINDOWS */
116
117/** @name Deprecated VBGL shared folder helpers.
118 *
119 * @deprecated These are all use the slow VbglR0HGCMCall interface, that
120 * basically treat ring-0 and user land callers much the same.
121 * Since 6.0 there is VbglR0HGCMFastCall() that does not bother with
122 * repacking the request and locking/duplicating parameter buffers,
123 * but just passes it along to the host and handles the waiting.
124 * Also new in 6.0 is embedded buffers which saves a bit time on
125 * guest and host by embedding parameter buffers into the request.
126 *
127 * @{
128 */
129
130DECLVBGL(int) VbglR0SfQueryMappings(PVBGLSFCLIENT pClient, SHFLMAPPING paMappings[], uint32_t *pcMappings)
131{
132 int rc;
133 VBoxSFQueryMappings data;
134
135 VBOX_INIT_CALL(&data.callInfo, QUERY_MAPPINGS, pClient);
136
137 data.flags.type = VMMDevHGCMParmType_32bit;
138 data.flags.u.value32 = SHFL_MF_UCS2;
139
140 data.numberOfMappings.type = VMMDevHGCMParmType_32bit;
141 data.numberOfMappings.u.value32 = *pcMappings;
142
143 data.mappings.type = VMMDevHGCMParmType_LinAddr;
144 data.mappings.u.Pointer.size = sizeof(SHFLMAPPING) * *pcMappings;
145 data.mappings.u.Pointer.u.linearAddr = (uintptr_t)&paMappings[0];
146
147/* Log(("VBOXSF: in ifs difference %d\n", (char *)&data.flags.type - (char *)&data.callInfo.cParms)); */
148 rc = VbglR0HGCMCall(pClient->handle, &data.callInfo, sizeof(data));
149/* Log(("VBOXSF: VbglR0SfQueryMappings: VbglR0HGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.result)); */
150 if (RT_SUCCESS(rc))
151 *pcMappings = data.numberOfMappings.u.value32;
152
153 return rc;
154}
155
156DECLVBGL(int) VbglR0SfQueryMapName(PVBGLSFCLIENT pClient, SHFLROOT root, SHFLSTRING *pString, uint32_t size)
157{
158 int rc;
159 VBoxSFQueryMapName data;
160
161 VBOX_INIT_CALL(&data.callInfo, QUERY_MAP_NAME, pClient);
162
163 data.root.type = VMMDevHGCMParmType_32bit;
164 data.root.u.value32 = root;
165
166 data.name.type = VMMDevHGCMParmType_LinAddr;
167 data.name.u.Pointer.size = size;
168 data.name.u.Pointer.u.linearAddr = (uintptr_t)pString;
169
170 rc = VbglR0HGCMCall(pClient->handle, &data.callInfo, sizeof(data));
171/* Log(("VBOXSF: VbglR0SfQueryMapName: VbglR0HGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.Hdr.rc)); */
172 return rc;
173}
174
175DECLVBGL(int) VbglR0SfMapFolder(PVBGLSFCLIENT pClient, PSHFLSTRING szFolderName, PVBGLSFMAP pMap)
176{
177 int rc;
178 VBoxSFMapFolder data;
179
180 VBOX_INIT_CALL(&data.callInfo, MAP_FOLDER, pClient);
181
182 data.path.type = VMMDevHGCMParmType_LinAddr;
183 data.path.u.Pointer.size = ShflStringSizeOfBuffer(szFolderName);
184 data.path.u.Pointer.u.linearAddr = (uintptr_t)szFolderName;
185
186 data.root.type = VMMDevHGCMParmType_32bit;
187 data.root.u.value32 = 0;
188
189 data.delimiter.type = VMMDevHGCMParmType_32bit;
190 data.delimiter.u.value32 = RTPATH_DELIMITER;
191
192 data.fCaseSensitive.type = VMMDevHGCMParmType_32bit;
193#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
194 data.fCaseSensitive.u.value32 = 0;
195#else
196 data.fCaseSensitive.u.value32 = 1;
197#endif
198
199 rc = VbglR0HGCMCallRaw(pClient->handle, &data.callInfo, sizeof(data));
200/* Log(("VBOXSF: VbglR0SfMapFolder: VbglR0HGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.Hdr.rc)); */
201 if (RT_SUCCESS(rc))
202 {
203 pMap->root = data.root.u.value32;
204 rc = data.callInfo.Hdr.rc;
205 }
206 return rc;
207}
208
209DECLVBGL(int) VbglR0SfUnmapFolder(PVBGLSFCLIENT pClient, PVBGLSFMAP pMap)
210{
211 int rc;
212 VBoxSFUnmapFolder data;
213
214 VBOX_INIT_CALL(&data.callInfo, UNMAP_FOLDER, pClient);
215
216 data.root.type = VMMDevHGCMParmType_32bit;
217 data.root.u.value32 = pMap->root;
218
219 rc = VbglR0HGCMCall(pClient->handle, &data.callInfo, sizeof(data));
220/* Log(("VBOXSF: VbglR0SfUnmapFolder: VbglR0HGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.Hdr.rc)); */
221 return rc;
222}
223
224# if !defined(RT_OS_WINDOWS)
225
226DECLVBGL(int) VbglR0SfCreate(PVBGLSFCLIENT pClient, PVBGLSFMAP pMap, PSHFLSTRING pParsedPath, PSHFLCREATEPARMS pCreateParms)
227{
228 /** @todo copy buffers to physical or mapped memory. */
229 int rc;
230 VBoxSFCreate data;
231
232 VBOX_INIT_CALL(&data.callInfo, CREATE, pClient);
233
234 data.root.type = VMMDevHGCMParmType_32bit;
235 data.root.u.value32 = pMap->root;
236
237 data.path.type = VMMDevHGCMParmType_LinAddr;
238 data.path.u.Pointer.size = ShflStringSizeOfBuffer (pParsedPath);
239 data.path.u.Pointer.u.linearAddr = (uintptr_t)pParsedPath;
240
241 data.parms.type = VMMDevHGCMParmType_LinAddr;
242 data.parms.u.Pointer.size = sizeof(SHFLCREATEPARMS);
243 data.parms.u.Pointer.u.linearAddr = (uintptr_t)pCreateParms;
244
245 rc = VbglR0HGCMCall(pClient->handle, &data.callInfo, sizeof(data));
246/* Log(("VBOXSF: VbglR0SfCreate: VbglR0HGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.Hdr.rc)); */
247 return rc;
248}
249
250DECLVBGL(int) VbglR0SfClose(PVBGLSFCLIENT pClient, PVBGLSFMAP pMap, SHFLHANDLE Handle)
251{
252 int rc;
253 VBoxSFClose data;
254
255 VBOX_INIT_CALL(&data.callInfo, CLOSE, pClient);
256
257 data.root.type = VMMDevHGCMParmType_32bit;
258 data.root.u.value32 = pMap->root;
259
260 data.handle.type = VMMDevHGCMParmType_64bit;
261 data.handle.u.value64 = Handle;
262
263 rc = VbglR0HGCMCall(pClient->handle, &data.callInfo, sizeof(data));
264/* Log(("VBOXSF: VbglR0SfClose: VbglR0HGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.Hdr.rc)); */
265 return rc;
266}
267
268
269DECLVBGL(int) VbglR0SfRemove(PVBGLSFCLIENT pClient, PVBGLSFMAP pMap, PSHFLSTRING pParsedPath, uint32_t flags)
270{
271 int rc = VINF_SUCCESS;
272
273 VBoxSFRemove data;
274
275 VBOX_INIT_CALL(&data.callInfo, REMOVE, pClient);
276
277 data.root.type = VMMDevHGCMParmType_32bit;
278 data.root.u.value32 = pMap->root;
279
280 data.path.type = VMMDevHGCMParmType_LinAddr_In;
281 data.path.u.Pointer.size = ShflStringSizeOfBuffer(pParsedPath);
282 data.path.u.Pointer.u.linearAddr = (uintptr_t)pParsedPath;
283
284 data.flags.type = VMMDevHGCMParmType_32bit;
285 data.flags.u.value32 = flags;
286
287 rc = VbglR0HGCMCall(pClient->handle, &data.callInfo, sizeof(data));
288/* Log(("VBOXSF: VbglR0SfRemove: VbglR0HGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.Hdr.rc)); */
289 return rc;
290}
291
292DECLVBGL(int) VbglR0SfRename(PVBGLSFCLIENT pClient, PVBGLSFMAP pMap, PSHFLSTRING pSrcPath, PSHFLSTRING pDestPath, uint32_t flags)
293{
294 int rc;
295 VBoxSFRename data;
296
297 VBOX_INIT_CALL(&data.callInfo, RENAME, pClient);
298
299 data.root.type = VMMDevHGCMParmType_32bit;
300 data.root.u.value32 = pMap->root;
301
302 data.src.type = VMMDevHGCMParmType_LinAddr_In;
303 data.src.u.Pointer.size = ShflStringSizeOfBuffer(pSrcPath);
304 data.src.u.Pointer.u.linearAddr = (uintptr_t)pSrcPath;
305
306 data.dest.type = VMMDevHGCMParmType_LinAddr_In;
307 data.dest.u.Pointer.size = ShflStringSizeOfBuffer(pDestPath);
308 data.dest.u.Pointer.u.linearAddr = (uintptr_t)pDestPath;
309
310 data.flags.type = VMMDevHGCMParmType_32bit;
311 data.flags.u.value32 = flags;
312
313 rc = VbglR0HGCMCall(pClient->handle, &data.callInfo, sizeof(data));
314/* Log(("VBOXSF: VbglR0SfRename: VbglR0HGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.Hdr.rc)); */
315 return rc;
316}
317
318DECLVBGL(int) VbglR0SfRead(PVBGLSFCLIENT pClient, PVBGLSFMAP pMap, SHFLHANDLE hFile,
319 uint64_t offset, uint32_t *pcbBuffer, uint8_t *pBuffer, bool fLocked)
320{
321 int rc;
322 VBoxSFRead data;
323
324 VBOX_INIT_CALL(&data.callInfo, READ, pClient);
325
326 data.root.type = VMMDevHGCMParmType_32bit;
327 data.root.u.value32 = pMap->root;
328
329 data.handle.type = VMMDevHGCMParmType_64bit;
330 data.handle.u.value64 = hFile;
331 data.offset.type = VMMDevHGCMParmType_64bit;
332 data.offset.u.value64 = offset;
333 data.cb.type = VMMDevHGCMParmType_32bit;
334 data.cb.u.value32 = *pcbBuffer;
335 data.buffer.type = (fLocked) ? VMMDevHGCMParmType_LinAddr_Locked_Out : VMMDevHGCMParmType_LinAddr_Out;
336 data.buffer.u.Pointer.size = *pcbBuffer;
337 data.buffer.u.Pointer.u.linearAddr = (uintptr_t)pBuffer;
338
339 rc = VbglR0HGCMCallRaw(pClient->handle, &data.callInfo, sizeof(data));
340/* Log(("VBOXSF: VbglR0SfRead: VbglR0HGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.Hdr.rc)); */
341 if (RT_SUCCESS(rc))
342 {
343 rc = data.callInfo.Hdr.rc;
344 *pcbBuffer = data.cb.u.value32;
345 }
346 return rc;
347}
348
349DECLVBGL(int) VbglR0SfReadPageList(PVBGLSFCLIENT pClient, PVBGLSFMAP pMap, SHFLHANDLE hFile, uint64_t offset, uint32_t *pcbBuffer,
350 uint16_t offFirstPage, uint16_t cPages, RTGCPHYS64 *paPages)
351{
352 uint32_t cbToRead = *pcbBuffer;
353 uint32_t cbData = (uint32_t)(sizeof(VBoxSFRead) + RT_UOFFSETOF_DYN(HGCMPageListInfo, aPages[cPages]));
354 VBoxSFRead *pData = (VBoxSFRead *)RTMemTmpAlloc(cbData);
355 HGCMPageListInfo *pPgLst = (HGCMPageListInfo *)(pData + 1);
356 uint16_t iPage;
357 int rc;
358
359 if (RT_UNLIKELY(!pData))
360 return VERR_NO_TMP_MEMORY;
361
362 VBOX_INIT_CALL_EX(&pData->callInfo, READ, pClient, cbData);
363
364 pData->root.type = VMMDevHGCMParmType_32bit;
365 pData->root.u.value32 = pMap->root;
366
367 pData->handle.type = VMMDevHGCMParmType_64bit;
368 pData->handle.u.value64 = hFile;
369 pData->offset.type = VMMDevHGCMParmType_64bit;
370 pData->offset.u.value64 = offset;
371 pData->cb.type = VMMDevHGCMParmType_32bit;
372 pData->cb.u.value32 = cbToRead;
373 pData->buffer.type = VMMDevHGCMParmType_PageList;
374 pData->buffer.u.PageList.size = cbToRead;
375 pData->buffer.u.PageList.offset = sizeof(VBoxSFRead);
376
377 pPgLst->flags = VBOX_HGCM_F_PARM_DIRECTION_FROM_HOST;
378 pPgLst->offFirstPage = offFirstPage;
379 pPgLst->cPages = cPages;
380 for (iPage = 0; iPage < cPages; iPage++)
381 pPgLst->aPages[iPage] = paPages[iPage];
382
383 rc = VbglR0HGCMCallRaw(pClient->handle, &pData->callInfo, cbData);
384/* Log(("VBOXSF: VbglR0SfReadPageList: VbglR0HGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.Hdr.rc)); */
385 if (RT_SUCCESS(rc))
386 {
387 rc = pData->callInfo.Hdr.rc;
388 *pcbBuffer = pData->cb.u.value32;
389 }
390
391 RTMemTmpFree(pData);
392 return rc;
393}
394
395DECLVBGL(int) VbglR0SfWrite(PVBGLSFCLIENT pClient, PVBGLSFMAP pMap, SHFLHANDLE hFile,
396 uint64_t offset, uint32_t *pcbBuffer, uint8_t *pBuffer, bool fLocked)
397{
398 int rc;
399 VBoxSFWrite data;
400
401 VBOX_INIT_CALL(&data.callInfo, WRITE, pClient);
402
403 data.root.type = VMMDevHGCMParmType_32bit;
404 data.root.u.value32 = pMap->root;
405
406 data.handle.type = VMMDevHGCMParmType_64bit;
407 data.handle.u.value64 = hFile;
408 data.offset.type = VMMDevHGCMParmType_64bit;
409 data.offset.u.value64 = offset;
410 data.cb.type = VMMDevHGCMParmType_32bit;
411 data.cb.u.value32 = *pcbBuffer;
412 data.buffer.type = fLocked ? VMMDevHGCMParmType_LinAddr_Locked_In : VMMDevHGCMParmType_LinAddr_In;
413 data.buffer.u.Pointer.size = *pcbBuffer;
414 data.buffer.u.Pointer.u.linearAddr = (uintptr_t)pBuffer;
415
416 rc = VbglR0HGCMCallRaw(pClient->handle, &data.callInfo, sizeof(data));
417/* Log(("VBOXSF: VbglR0SfWrite: VbglR0HGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.Hdr.rc)); */
418 if (RT_SUCCESS(rc))
419 {
420 rc = data.callInfo.Hdr.rc;
421 *pcbBuffer = data.cb.u.value32;
422 }
423 return rc;
424}
425
426DECLVBGL(int) VbglR0SfWritePhysCont(PVBGLSFCLIENT pClient, PVBGLSFMAP pMap, SHFLHANDLE hFile, uint64_t offset,
427 uint32_t *pcbBuffer, RTCCPHYS PhysBuffer)
428{
429 uint32_t cbToWrite = *pcbBuffer;
430 uint32_t cPages = RT_ALIGN_32((PhysBuffer & PAGE_OFFSET_MASK) + cbToWrite, PAGE_SIZE) >> PAGE_SHIFT;
431 uint32_t cbData = (uint32_t)(sizeof(VBoxSFWrite) + RT_UOFFSETOF_DYN(HGCMPageListInfo, aPages[cPages]));
432 VBoxSFWrite *pData = (VBoxSFWrite *)RTMemTmpAlloc(cbData);
433 HGCMPageListInfo *pPgLst = (HGCMPageListInfo *)(pData + 1);
434 uint32_t iPage;
435 int rc;
436
437 if (RT_UNLIKELY(!pData))
438 return VERR_NO_TMP_MEMORY;
439
440 VBOX_INIT_CALL_EX(&pData->callInfo, WRITE, pClient, cbData);
441
442 pData->root.type = VMMDevHGCMParmType_32bit;
443 pData->root.u.value32 = pMap->root;
444
445 pData->handle.type = VMMDevHGCMParmType_64bit;
446 pData->handle.u.value64 = hFile;
447 pData->offset.type = VMMDevHGCMParmType_64bit;
448 pData->offset.u.value64 = offset;
449 pData->cb.type = VMMDevHGCMParmType_32bit;
450 pData->cb.u.value32 = cbToWrite;
451 pData->buffer.type = VMMDevHGCMParmType_PageList;
452 pData->buffer.u.PageList.size = cbToWrite;
453 pData->buffer.u.PageList.offset = sizeof(VBoxSFWrite);
454
455 pPgLst->flags = VBOX_HGCM_F_PARM_DIRECTION_TO_HOST;
456 pPgLst->offFirstPage = (uint16_t)(PhysBuffer & PAGE_OFFSET_MASK);
457 pPgLst->cPages = cPages;
458 PhysBuffer &= ~(RTCCPHYS)PAGE_OFFSET_MASK;
459 for (iPage = 0; iPage < cPages; iPage++, PhysBuffer += PAGE_SIZE)
460 pPgLst->aPages[iPage] = PhysBuffer;
461
462 rc = VbglR0HGCMCallRaw(pClient->handle, &pData->callInfo, cbData);
463/* Log(("VBOXSF: VbglR0SfWritePhysCont: VbglR0HGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.Hdr.rc)); */
464 if (RT_SUCCESS(rc))
465 {
466 rc = pData->callInfo.Hdr.rc;
467 *pcbBuffer = pData->cb.u.value32;
468 }
469
470 RTMemTmpFree(pData);
471 return rc;
472
473}
474
475DECLVBGL(int) VbglR0SfWritePageList(PVBGLSFCLIENT pClient, PVBGLSFMAP pMap, SHFLHANDLE hFile, uint64_t offset, uint32_t *pcbBuffer,
476 uint16_t offFirstPage, uint16_t cPages, RTGCPHYS64 *paPages)
477{
478 uint32_t cbToWrite = *pcbBuffer;
479 uint32_t cbData = (uint32_t)(sizeof(VBoxSFWrite) + RT_UOFFSETOF_DYN(HGCMPageListInfo, aPages[cPages]));
480 VBoxSFWrite *pData = (VBoxSFWrite *)RTMemTmpAlloc(cbData);
481 HGCMPageListInfo *pPgLst = (HGCMPageListInfo *)(pData + 1);
482 uint16_t iPage;
483 int rc;
484
485 if (RT_UNLIKELY(!pData))
486 return VERR_NO_TMP_MEMORY;
487
488 VBOX_INIT_CALL_EX(&pData->callInfo, WRITE, pClient, cbData);
489
490 pData->root.type = VMMDevHGCMParmType_32bit;
491 pData->root.u.value32 = pMap->root;
492
493 pData->handle.type = VMMDevHGCMParmType_64bit;
494 pData->handle.u.value64 = hFile;
495 pData->offset.type = VMMDevHGCMParmType_64bit;
496 pData->offset.u.value64 = offset;
497 pData->cb.type = VMMDevHGCMParmType_32bit;
498 pData->cb.u.value32 = cbToWrite;
499 pData->buffer.type = VMMDevHGCMParmType_PageList;
500 pData->buffer.u.PageList.size = cbToWrite;
501 pData->buffer.u.PageList.offset = sizeof(VBoxSFWrite);
502
503 pPgLst->flags = VBOX_HGCM_F_PARM_DIRECTION_TO_HOST;
504 pPgLst->offFirstPage = offFirstPage;
505 pPgLst->cPages = cPages;
506 for (iPage = 0; iPage < cPages; iPage++)
507 pPgLst->aPages[iPage] = paPages[iPage];
508
509 rc = VbglR0HGCMCallRaw(pClient->handle, &pData->callInfo, cbData);
510/* Log(("VBOXSF: VbglR0SfWritePageList: VbglR0HGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.Hdr.rc)); */
511 if (RT_SUCCESS(rc))
512 {
513 rc = pData->callInfo.Hdr.rc;
514 *pcbBuffer = pData->cb.u.value32;
515 }
516
517 RTMemTmpFree(pData);
518 return rc;
519}
520
521# endif /* !RT_OS_WINDOWS */
522
523DECLVBGL(int) VbglR0SfFlush(PVBGLSFCLIENT pClient, PVBGLSFMAP pMap, SHFLHANDLE hFile)
524{
525 int rc;
526 VBoxSFFlush data;
527
528 VBOX_INIT_CALL(&data.callInfo, FLUSH, pClient);
529
530 data.root.type = VMMDevHGCMParmType_32bit;
531 data.root.u.value32 = pMap->root;
532
533 data.handle.type = VMMDevHGCMParmType_64bit;
534 data.handle.u.value64 = hFile;
535
536 rc = VbglR0HGCMCall(pClient->handle, &data.callInfo, sizeof(data));
537/* Log(("VBOXSF: VbglR0SfFlush: VbglR0HGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.Hdr.rc)); */
538 return rc;
539}
540
541DECLVBGL(int) VbglR0SfDirInfo(
542 PVBGLSFCLIENT pClient,
543 PVBGLSFMAP pMap,
544 SHFLHANDLE hFile,
545 PSHFLSTRING ParsedPath,
546 uint32_t flags,
547 uint32_t index,
548 uint32_t *pcbBuffer,
549 PSHFLDIRINFO pBuffer,
550 uint32_t *pcFiles)
551{
552 int rc;
553 VBoxSFList data;
554
555 VBOX_INIT_CALL(&data.callInfo, LIST, pClient);
556
557 data.root.type = VMMDevHGCMParmType_32bit;
558 data.root.u.value32 = pMap->root;
559
560 data.handle.type = VMMDevHGCMParmType_64bit;
561 data.handle.u.value64 = hFile;
562 data.flags.type = VMMDevHGCMParmType_32bit;
563 data.flags.u.value32 = flags;
564 data.cb.type = VMMDevHGCMParmType_32bit;
565 data.cb.u.value32 = *pcbBuffer;
566 data.path.type = VMMDevHGCMParmType_LinAddr_In;
567 data.path.u.Pointer.size = ParsedPath ? ShflStringSizeOfBuffer(ParsedPath) : 0;
568 data.path.u.Pointer.u.linearAddr = (uintptr_t) ParsedPath;
569
570 data.buffer.type = VMMDevHGCMParmType_LinAddr_Out;
571 data.buffer.u.Pointer.size = *pcbBuffer;
572 data.buffer.u.Pointer.u.linearAddr = (uintptr_t)pBuffer;
573
574 data.resumePoint.type = VMMDevHGCMParmType_32bit;
575 data.resumePoint.u.value32 = index;
576 data.cFiles.type = VMMDevHGCMParmType_32bit;
577 data.cFiles.u.value32 = 0; /* out parameters only */
578
579 rc = VbglR0HGCMCall(pClient->handle, &data.callInfo, sizeof(data));
580/* Log(("VBOXSF: VbglR0SfDirInfo: rc = %#x, result = %#x\n", rc, data.callInfo.Hdr.rc)); */
581 *pcbBuffer = data.cb.u.value32;
582 *pcFiles = data.cFiles.u.value32;
583 return rc;
584}
585
586# ifndef RT_OS_WINDOWS
587
588DECLVBGL(int) VbglR0SfFsInfo(PVBGLSFCLIENT pClient, PVBGLSFMAP pMap, SHFLHANDLE hFile,
589 uint32_t flags, uint32_t *pcbBuffer, PSHFLDIRINFO pBuffer)
590{
591 int rc;
592 VBoxSFInformation data;
593
594 VBOX_INIT_CALL(&data.callInfo, INFORMATION, pClient);
595
596 data.root.type = VMMDevHGCMParmType_32bit;
597 data.root.u.value32 = pMap->root;
598
599 data.handle.type = VMMDevHGCMParmType_64bit;
600 data.handle.u.value64 = hFile;
601 data.flags.type = VMMDevHGCMParmType_32bit;
602 data.flags.u.value32 = flags;
603 data.cb.type = VMMDevHGCMParmType_32bit;
604 data.cb.u.value32 = *pcbBuffer;
605 data.info.type = VMMDevHGCMParmType_LinAddr;
606 data.info.u.Pointer.size = *pcbBuffer;
607 data.info.u.Pointer.u.linearAddr = (uintptr_t)pBuffer;
608
609 rc = VbglR0HGCMCallRaw(pClient->handle, &data.callInfo, sizeof(data));
610/* Log(("VBOXSF: VbglR0SfFsInfo: VbglR0HGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.Hdr.rc)); */
611 if (RT_SUCCESS(rc))
612 {
613 rc = data.callInfo.Hdr.rc;
614 *pcbBuffer = data.cb.u.value32;
615 }
616 return rc;
617}
618
619# endif /* !RT_OS_WINDOWS */
620
621DECLVBGL(int) VbglR0SfLock(PVBGLSFCLIENT pClient, PVBGLSFMAP pMap, SHFLHANDLE hFile,
622 uint64_t offset, uint64_t cbSize, uint32_t fLock)
623{
624 int rc;
625 VBoxSFLock data;
626
627 VBOX_INIT_CALL(&data.callInfo, LOCK, pClient);
628
629 data.root.type = VMMDevHGCMParmType_32bit;
630 data.root.u.value32 = pMap->root;
631
632 data.handle.type = VMMDevHGCMParmType_64bit;
633 data.handle.u.value64 = hFile;
634 data.offset.type = VMMDevHGCMParmType_64bit;
635 data.offset.u.value64 = offset;
636 data.length.type = VMMDevHGCMParmType_64bit;
637 data.length.u.value64 = cbSize;
638
639 data.flags.type = VMMDevHGCMParmType_32bit;
640 data.flags.u.value32 = fLock;
641
642 rc = VbglR0HGCMCall(pClient->handle, &data.callInfo, sizeof(data));
643/* Log(("VBOXSF: VbglR0SfLock: VbglR0HGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.Hdr.rc)); */
644 return rc;
645}
646
647# ifndef RT_OS_WINDOWS
648
649DECLVBGL(int) VbglR0SfReadLink(PVBGLSFCLIENT pClient, PVBGLSFMAP pMap, PSHFLSTRING pParsedPath, uint32_t cbBuffer, uint8_t *pBuffer)
650{
651 int rc;
652 VBoxSFReadLink data;
653
654 VBOX_INIT_CALL(&data.callInfo, READLINK, pClient);
655
656 data.root.type = VMMDevHGCMParmType_32bit;
657 data.root.u.value32 = pMap->root;
658
659 data.path.type = VMMDevHGCMParmType_LinAddr_In;
660 data.path.u.Pointer.size = ShflStringSizeOfBuffer (pParsedPath);
661 data.path.u.Pointer.u.linearAddr = (uintptr_t)pParsedPath;
662
663 data.buffer.type = VMMDevHGCMParmType_LinAddr_Out;
664 data.buffer.u.Pointer.size = cbBuffer;
665 data.buffer.u.Pointer.u.linearAddr = (uintptr_t)pBuffer;
666
667 rc = VbglR0HGCMCall(pClient->handle, &data.callInfo, sizeof(data));
668/* Log(("VBOXSF: VbglR0SfReadLink: VbglR0HGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.Hdr.rc)); */
669 return rc;
670}
671
672DECLVBGL(int) VbglR0SfSymlink(PVBGLSFCLIENT pClient, PVBGLSFMAP pMap, PSHFLSTRING pNewPath, PSHFLSTRING pOldPath,
673 PSHFLFSOBJINFO pBuffer)
674{
675 int rc;
676 VBoxSFSymlink data;
677
678 VBOX_INIT_CALL(&data.callInfo, SYMLINK, pClient);
679
680 data.root.type = VMMDevHGCMParmType_32bit;
681 data.root.u.value32 = pMap->root;
682
683 data.newPath.type = VMMDevHGCMParmType_LinAddr_In;
684 data.newPath.u.Pointer.size = ShflStringSizeOfBuffer (pNewPath);
685 data.newPath.u.Pointer.u.linearAddr = (uintptr_t)pNewPath;
686
687 data.oldPath.type = VMMDevHGCMParmType_LinAddr_In;
688 data.oldPath.u.Pointer.size = ShflStringSizeOfBuffer (pOldPath);
689 data.oldPath.u.Pointer.u.linearAddr = (uintptr_t)pOldPath;
690
691 data.info.type = VMMDevHGCMParmType_LinAddr_Out;
692 data.info.u.Pointer.size = sizeof(SHFLFSOBJINFO);
693 data.info.u.Pointer.u.linearAddr = (uintptr_t)pBuffer;
694
695 rc = VbglR0HGCMCall(pClient->handle, &data.callInfo, sizeof(data));
696/* Log(("VBOXSF: VbglR0SfSymlink: VbglR0HGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.Hdr.rc)); */
697 return rc;
698}
699
700DECLVBGL(int) VbglR0SfSetSymlinks(PVBGLSFCLIENT pClient)
701{
702 int rc;
703 VBGLIOCHGCMCALL callInfo;
704
705 VBOX_INIT_CALL(&callInfo, SET_SYMLINKS, pClient);
706 rc = VbglR0HGCMCall(pClient->handle, &callInfo, sizeof(callInfo));
707/* Log(("VBOXSF: VbglR0SfSetSymlinks: VbglR0HGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.Hdr.rc)); */
708 return rc;
709}
710
711# endif /* !RT_OS_WINDOWS */
712
713#endif /* !RT_OS_LINUX */
714
715/** @} */
716
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette