VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR0LibSharedFolders.c@ 58029

Last change on this file since 58029 was 57358, checked in by vboxsync, 9 years ago

*: scm cleanup run.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 28.9 KB
Line 
1/* $Id: VBoxGuestR0LibSharedFolders.c 57358 2015-08-14 15:16:38Z vboxsync $ */
2/** @file
3 * VBoxGuestR0LibSharedFolders - Ring 0 Shared Folders calls.
4 */
5
6/*
7 * Copyright (C) 2006-2015 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 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27/* Entire file is ifdef'ed with !VBGL_VBOXGUEST */
28#ifndef VBGL_VBOXGUEST
29
30
31/*********************************************************************************************************************************
32* Header Files *
33*********************************************************************************************************************************/
34#define LOG_GROUP LOG_GROUP_SHARED_FOLDERS
35#ifdef RT_OS_LINUX
36# include "VBoxGuestR0LibSharedFolders.h"
37#else
38# include "VBoxGuestR0LibSharedFolders.h"
39#endif
40#include <VBox/log.h>
41#include <iprt/time.h>
42#include <iprt/mem.h>
43#include <iprt/path.h>
44#include <iprt/string.h>
45
46
47/*********************************************************************************************************************************
48* Defined Constants And Macros *
49*********************************************************************************************************************************/
50#define SHFL_CPARMS_SET_UTF8 0
51#define SHFL_CPARMS_SET_SYMLINKS 0
52
53#define VBOX_INIT_CALL(a, b, c) \
54 LogFunc(("%s, u32ClientID=%d\n", "SHFL_FN_" # b, \
55 (c)->ulClientID)); \
56 (a)->result = VINF_SUCCESS; \
57 (a)->u32ClientID = (c)->ulClientID; \
58 (a)->u32Function = SHFL_FN_##b; \
59 (a)->cParms = SHFL_CPARMS_##b
60
61
62
63DECLVBGL(int) vboxInit (void)
64{
65 int rc = VINF_SUCCESS;
66
67 rc = VbglInit ();
68 return rc;
69}
70
71DECLVBGL(void) vboxUninit (void)
72{
73 VbglTerminate ();
74}
75
76DECLVBGL(int) vboxConnect (PVBSFCLIENT pClient)
77{
78 int rc;
79 VBoxGuestHGCMConnectInfo data;
80
81 pClient->handle = NULL;
82
83 RT_ZERO(data);
84 data.result = VINF_SUCCESS;
85 data.Loc.type = VMMDevHGCMLoc_LocalHost_Existing;
86 strcpy (data.Loc.u.host.achName, "VBoxSharedFolders");
87
88 rc = VbglHGCMConnect (&pClient->handle, &data);
89
90/* Log(("VBOXSF: VBoxSF::vboxConnect: VbglHGCMConnect rc = %#x, result = %#x\n",
91 rc, data.result));
92*/
93 if (RT_SUCCESS (rc))
94 {
95 rc = data.result;
96 }
97
98 if (RT_SUCCESS (rc))
99 {
100 pClient->ulClientID = data.u32ClientID;
101 LogFunc(("u32ClientID=%d\n", pClient->ulClientID));
102 }
103 return rc;
104}
105
106DECLVBGL(void) vboxDisconnect (PVBSFCLIENT pClient)
107{
108 int rc;
109 VBoxGuestHGCMDisconnectInfo data;
110
111 LogFunc(("u32ClientID=%d\n", pClient->ulClientID));
112 if (pClient->handle == NULL)
113 return; /* not connected */
114
115 RT_ZERO(data);
116 data.result = VINF_SUCCESS;
117 data.u32ClientID = pClient->ulClientID;
118
119 rc = VbglHGCMDisconnect (pClient->handle, &data);
120 NOREF(rc);
121/* Log(("VBOXSF: VBoxSF::vboxDisconnect: "
122 "VbglHGCMDisconnect rc = %#x, result = %#x\n", rc, data.result));
123*/
124 return;
125}
126
127DECLVBGL(int) vboxCallQueryMappings (PVBSFCLIENT pClient, SHFLMAPPING paMappings[],
128 uint32_t *pcMappings)
129{
130 int rc = VINF_SUCCESS;
131
132 VBoxSFQueryMappings data;
133
134 VBOX_INIT_CALL(&data.callInfo, QUERY_MAPPINGS, pClient);
135
136 data.flags.type = VMMDevHGCMParmType_32bit;
137 data.flags.u.value32 = SHFL_MF_UCS2;
138
139 data.numberOfMappings.type = VMMDevHGCMParmType_32bit;
140 data.numberOfMappings.u.value32 = *pcMappings;
141
142 data.mappings.type = VMMDevHGCMParmType_LinAddr;
143 data.mappings.u.Pointer.size = sizeof (SHFLMAPPING) * *pcMappings;
144 data.mappings.u.Pointer.u.linearAddr = (uintptr_t)&paMappings[0];
145
146/* Log(("VBOXSF: in ifs difference %d\n",
147 (char *)&data.flags.type - (char *)&data.callInfo.cParms));
148*/
149 rc = VbglHGCMCall (pClient->handle, &data.callInfo, sizeof (data));
150
151/*
152 Log(("VBOXSF: VBoxSF::vboxCallQueryMappings: "
153 "VbglHGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.result));
154*/
155 if (RT_SUCCESS (rc))
156 {
157 rc = data.callInfo.result;
158 }
159
160 if (RT_SUCCESS (rc))
161 {
162 *pcMappings = data.numberOfMappings.u.value32;
163 }
164
165 return rc;
166}
167
168DECLVBGL(int) vboxCallQueryMapName (PVBSFCLIENT pClient, SHFLROOT root, SHFLSTRING *pString, uint32_t size)
169{
170 int rc = VINF_SUCCESS;
171
172 VBoxSFQueryMapName data;
173
174 VBOX_INIT_CALL(&data.callInfo, QUERY_MAP_NAME, pClient);
175
176 data.root.type = VMMDevHGCMParmType_32bit;
177 data.root.u.value32 = root;
178
179 data.name.type = VMMDevHGCMParmType_LinAddr;
180 data.name.u.Pointer.size = size;
181 data.name.u.Pointer.u.linearAddr = (uintptr_t)pString;
182
183 rc = VbglHGCMCall (pClient->handle, &data.callInfo, sizeof (data));
184
185/* Log(("VBOXSF: VBoxSF::vboxCallQueryMapName: "
186 "VbglHGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.result));
187*/
188 if (RT_SUCCESS (rc))
189 {
190 rc = data.callInfo.result;
191 }
192
193 return rc;
194}
195
196DECLVBGL(int) vboxCallMapFolder(PVBSFCLIENT pClient, PSHFLSTRING szFolderName,
197 PVBSFMAP pMap)
198{
199 int rc = VINF_SUCCESS;
200
201 VBoxSFMapFolder data;
202
203 VBOX_INIT_CALL(&data.callInfo, MAP_FOLDER, pClient);
204
205 data.path.type = VMMDevHGCMParmType_LinAddr;
206 data.path.u.Pointer.size = ShflStringSizeOfBuffer (szFolderName);
207 data.path.u.Pointer.u.linearAddr = (uintptr_t)szFolderName;
208
209 data.root.type = VMMDevHGCMParmType_32bit;
210 data.root.u.value32 = 0;
211
212 data.delimiter.type = VMMDevHGCMParmType_32bit;
213 data.delimiter.u.value32 = RTPATH_DELIMITER;
214
215 data.fCaseSensitive.type = VMMDevHGCMParmType_32bit;
216#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
217 data.fCaseSensitive.u.value32 = 0;
218#else
219 data.fCaseSensitive.u.value32 = 1;
220#endif
221
222 rc = VbglHGCMCall (pClient->handle, &data.callInfo, sizeof (data));
223
224/* Log(("VBOXSF: VBoxSF::vboxCallMapFolder: "
225 "VbglHGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.result));
226*/
227 if (RT_SUCCESS (rc))
228 {
229 pMap->root = data.root.u.value32;
230 rc = data.callInfo.result;
231 }
232 else if (rc == VERR_NOT_IMPLEMENTED)
233 {
234 /* try the legacy interface too; temporary to assure backwards compatibility */
235 VBoxSFMapFolder_Old OldData;
236
237 VBOX_INIT_CALL(&OldData.callInfo, MAP_FOLDER_OLD, pClient);
238
239 OldData.path.type = VMMDevHGCMParmType_LinAddr;
240 OldData.path.u.Pointer.size = ShflStringSizeOfBuffer (szFolderName);
241 OldData.path.u.Pointer.u.linearAddr = (uintptr_t)szFolderName;
242
243 OldData.root.type = VMMDevHGCMParmType_32bit;
244 OldData.root.u.value32 = 0;
245
246 OldData.delimiter.type = VMMDevHGCMParmType_32bit;
247 OldData.delimiter.u.value32 = RTPATH_DELIMITER;
248
249 rc = VbglHGCMCall (pClient->handle, &OldData.callInfo, sizeof (OldData));
250
251 if (RT_SUCCESS (rc))
252 {
253 pMap->root = OldData.root.u.value32;
254 rc = OldData.callInfo.result;
255 }
256 }
257 return rc;
258}
259
260DECLVBGL(int) vboxCallUnmapFolder(PVBSFCLIENT pClient, PVBSFMAP pMap)
261{
262 int rc = VINF_SUCCESS;
263
264 VBoxSFUnmapFolder data;
265
266 VBOX_INIT_CALL(&data.callInfo, UNMAP_FOLDER, pClient);
267
268 data.root.type = VMMDevHGCMParmType_32bit;
269 data.root.u.value32 = pMap->root;
270
271 rc = VbglHGCMCall (pClient->handle, &data.callInfo, sizeof (data));
272
273/* Log(("VBOXSF: VBoxSF::vboxCallUnmapFolder: "
274 "VbglHGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.result));
275*/
276 if (RT_SUCCESS (rc))
277 {
278 rc = data.callInfo.result;
279 }
280 return rc;
281}
282
283DECLVBGL(int) vboxCallCreate (PVBSFCLIENT pClient, PVBSFMAP pMap,
284 PSHFLSTRING pParsedPath, PSHFLCREATEPARMS pCreateParms)
285{
286 /** @todo copy buffers to physical or mapped memory. */
287 int rc = VINF_SUCCESS;
288
289 VBoxSFCreate data;
290
291 VBOX_INIT_CALL(&data.callInfo, CREATE, pClient);
292
293 data.root.type = VMMDevHGCMParmType_32bit;
294 data.root.u.value32 = pMap->root;
295
296 data.path.type = VMMDevHGCMParmType_LinAddr;
297 data.path.u.Pointer.size = ShflStringSizeOfBuffer (pParsedPath);
298 data.path.u.Pointer.u.linearAddr = (uintptr_t)pParsedPath;
299
300 data.parms.type = VMMDevHGCMParmType_LinAddr;
301 data.parms.u.Pointer.size = sizeof (SHFLCREATEPARMS);
302 data.parms.u.Pointer.u.linearAddr = (uintptr_t)pCreateParms;
303
304 rc = VbglHGCMCall (pClient->handle, &data.callInfo, sizeof (data));
305
306/* Log(("VBOXSF: VBoxSF::vboxCallCreate: "
307 "VbglHGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.result));
308*/
309 if (RT_SUCCESS (rc))
310 {
311 rc = data.callInfo.result;
312 }
313 return rc;
314}
315
316DECLVBGL(int) vboxCallClose (PVBSFCLIENT pClient, PVBSFMAP pMap, SHFLHANDLE Handle)
317{
318 int rc = VINF_SUCCESS;
319
320 VBoxSFClose data;
321
322 VBOX_INIT_CALL(&data.callInfo, CLOSE, pClient);
323
324 data.root.type = VMMDevHGCMParmType_32bit;
325 data.root.u.value32 = pMap->root;
326
327 data.handle.type = VMMDevHGCMParmType_64bit;
328 data.handle.u.value64 = Handle;
329
330 rc = VbglHGCMCall (pClient->handle, &data.callInfo, sizeof (data));
331
332/* Log(("VBOXSF: VBoxSF::vboxCallClose: "
333 "VbglHGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.result));
334*/
335 if (RT_SUCCESS (rc))
336 {
337 rc = data.callInfo.result;
338 }
339
340 return rc;
341}
342
343DECLVBGL(int) vboxCallRemove (PVBSFCLIENT pClient, PVBSFMAP pMap,
344 PSHFLSTRING pParsedPath, uint32_t flags)
345{
346 int rc = VINF_SUCCESS;
347
348 VBoxSFRemove data;
349
350 VBOX_INIT_CALL(&data.callInfo, REMOVE, pClient);
351
352 data.root.type = VMMDevHGCMParmType_32bit;
353 data.root.u.value32 = pMap->root;
354
355 data.path.type = VMMDevHGCMParmType_LinAddr_In;
356 data.path.u.Pointer.size = ShflStringSizeOfBuffer (pParsedPath);
357 data.path.u.Pointer.u.linearAddr = (uintptr_t)pParsedPath;
358
359 data.flags.type = VMMDevHGCMParmType_32bit;
360 data.flags.u.value32 = flags;
361
362 rc = VbglHGCMCall (pClient->handle, &data.callInfo, sizeof (data));
363
364/* Log(("VBOXSF: VBoxSF::vboxCallRemove: "
365 "VbglHGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.result));
366*/
367 if (RT_SUCCESS (rc))
368 {
369 rc = data.callInfo.result;
370 }
371
372 return rc;
373}
374
375DECLVBGL(int) vboxCallRename (PVBSFCLIENT pClient, PVBSFMAP pMap,
376 PSHFLSTRING pSrcPath, PSHFLSTRING pDestPath, uint32_t flags)
377{
378 int rc = VINF_SUCCESS;
379
380 VBoxSFRename data;
381
382 VBOX_INIT_CALL(&data.callInfo, RENAME, pClient);
383
384 data.root.type = VMMDevHGCMParmType_32bit;
385 data.root.u.value32 = pMap->root;
386
387 data.src.type = VMMDevHGCMParmType_LinAddr_In;
388 data.src.u.Pointer.size = ShflStringSizeOfBuffer (pSrcPath);
389 data.src.u.Pointer.u.linearAddr = (uintptr_t)pSrcPath;
390
391 data.dest.type = VMMDevHGCMParmType_LinAddr_In;
392 data.dest.u.Pointer.size = ShflStringSizeOfBuffer (pDestPath);
393 data.dest.u.Pointer.u.linearAddr = (uintptr_t)pDestPath;
394
395 data.flags.type = VMMDevHGCMParmType_32bit;
396 data.flags.u.value32 = flags;
397
398 rc = VbglHGCMCall (pClient->handle, &data.callInfo, sizeof (data));
399
400/* Log(("VBOXSF: VBoxSF::vboxCallRename: "
401 "VbglHGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.result));
402*/
403 if (RT_SUCCESS (rc))
404 {
405 rc = data.callInfo.result;
406 }
407 return rc;
408}
409
410DECLVBGL(int) vboxCallRead(PVBSFCLIENT pClient, PVBSFMAP pMap, SHFLHANDLE hFile,
411 uint64_t offset, uint32_t *pcbBuffer, uint8_t *pBuffer, bool fLocked)
412{
413 int rc = VINF_SUCCESS;
414
415 VBoxSFRead data;
416
417 VBOX_INIT_CALL(&data.callInfo, READ, pClient);
418
419 data.root.type = VMMDevHGCMParmType_32bit;
420 data.root.u.value32 = pMap->root;
421
422 data.handle.type = VMMDevHGCMParmType_64bit;
423 data.handle.u.value64 = hFile;
424 data.offset.type = VMMDevHGCMParmType_64bit;
425 data.offset.u.value64 = offset;
426 data.cb.type = VMMDevHGCMParmType_32bit;
427 data.cb.u.value32 = *pcbBuffer;
428 data.buffer.type = (fLocked) ? VMMDevHGCMParmType_LinAddr_Locked_Out : VMMDevHGCMParmType_LinAddr_Out;
429 data.buffer.u.Pointer.size = *pcbBuffer;
430 data.buffer.u.Pointer.u.linearAddr = (uintptr_t)pBuffer;
431
432 rc = VbglHGCMCall (pClient->handle, &data.callInfo, sizeof (data));
433
434/* Log(("VBOXSF: VBoxSF::vboxCallRead: "
435 "VbglHGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.result));
436*/
437 if (RT_SUCCESS (rc))
438 {
439 rc = data.callInfo.result;
440 *pcbBuffer = data.cb.u.value32;
441 }
442 return rc;
443}
444
445DECLVBGL(int) VbglR0SharedFolderReadPageList(PVBSFCLIENT pClient, PVBSFMAP pMap, SHFLHANDLE hFile,
446 uint64_t offset, uint32_t *pcbBuffer,
447 uint16_t offFirstPage, uint16_t cPages, RTGCPHYS64 *paPages)
448{
449 uint32_t cbToRead = *pcbBuffer;
450 uint32_t cbData = (uint32_t)(sizeof(VBoxSFRead) + RT_UOFFSETOF(HGCMPageListInfo, aPages[cPages]));
451 VBoxSFRead *pData = (VBoxSFRead *)RTMemTmpAlloc(cbData);
452 HGCMPageListInfo *pPgLst = (HGCMPageListInfo *)(pData + 1);
453 uint16_t iPage;
454 int rc;
455
456 if (RT_UNLIKELY(!pData))
457 return VERR_NO_TMP_MEMORY;
458
459 VBOX_INIT_CALL(&pData->callInfo, READ, pClient);
460
461 pData->root.type = VMMDevHGCMParmType_32bit;
462 pData->root.u.value32 = pMap->root;
463
464 pData->handle.type = VMMDevHGCMParmType_64bit;
465 pData->handle.u.value64 = hFile;
466 pData->offset.type = VMMDevHGCMParmType_64bit;
467 pData->offset.u.value64 = offset;
468 pData->cb.type = VMMDevHGCMParmType_32bit;
469 pData->cb.u.value32 = cbToRead;
470 pData->buffer.type = VMMDevHGCMParmType_PageList;
471 pData->buffer.u.PageList.size = cbToRead;
472 pData->buffer.u.PageList.offset = sizeof(VBoxSFRead);
473
474 pPgLst->flags = VBOX_HGCM_F_PARM_DIRECTION_FROM_HOST;
475 pPgLst->offFirstPage = offFirstPage;
476 pPgLst->cPages = cPages;
477 for (iPage = 0; iPage < cPages; iPage++)
478 pPgLst->aPages[iPage] = paPages[iPage];
479
480 rc = VbglHGCMCall(pClient->handle, &pData->callInfo, cbData);
481 if (RT_SUCCESS (rc))
482 {
483 rc = pData->callInfo.result;
484 *pcbBuffer = pData->cb.u.value32;
485 }
486
487 RTMemTmpFree(pData);
488 return rc;
489}
490
491DECLVBGL(int) vboxCallWrite(PVBSFCLIENT pClient, PVBSFMAP pMap, SHFLHANDLE hFile,
492 uint64_t offset, uint32_t *pcbBuffer, uint8_t *pBuffer, bool fLocked)
493{
494 int rc = VINF_SUCCESS;
495
496 VBoxSFWrite data;
497
498 VBOX_INIT_CALL(&data.callInfo, WRITE, pClient);
499
500 data.root.type = VMMDevHGCMParmType_32bit;
501 data.root.u.value32 = pMap->root;
502
503 data.handle.type = VMMDevHGCMParmType_64bit;
504 data.handle.u.value64 = hFile;
505 data.offset.type = VMMDevHGCMParmType_64bit;
506 data.offset.u.value64 = offset;
507 data.cb.type = VMMDevHGCMParmType_32bit;
508 data.cb.u.value32 = *pcbBuffer;
509 data.buffer.type = (fLocked) ? VMMDevHGCMParmType_LinAddr_Locked_In : VMMDevHGCMParmType_LinAddr_In;
510 data.buffer.u.Pointer.size = *pcbBuffer;
511 data.buffer.u.Pointer.u.linearAddr = (uintptr_t)pBuffer;
512
513 rc = VbglHGCMCall (pClient->handle, &data.callInfo, sizeof (data));
514
515/* Log(("VBOXSF: VBoxSF::vboxCallWrite: "
516 "VbglHGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.result));
517*/
518 if (RT_SUCCESS (rc))
519 {
520 rc = data.callInfo.result;
521 *pcbBuffer = data.cb.u.value32;
522 }
523 return rc;
524}
525
526DECLVBGL(int) VbglR0SfWritePhysCont(PVBSFCLIENT pClient, PVBSFMAP pMap, SHFLHANDLE hFile, uint64_t offset, uint32_t *pcbBuffer, RTCCPHYS PhysBuffer)
527{
528 uint32_t cbToWrite = *pcbBuffer;
529 uint32_t cPages = RT_ALIGN_32((PhysBuffer & PAGE_OFFSET_MASK) + cbToWrite, PAGE_SIZE) >> PAGE_SHIFT;
530 uint32_t cbData = (uint32_t)(sizeof(VBoxSFWrite) + RT_UOFFSETOF(HGCMPageListInfo, aPages[cPages]));
531 VBoxSFWrite *pData = (VBoxSFWrite *)RTMemTmpAlloc(cbData);
532 HGCMPageListInfo *pPgLst = (HGCMPageListInfo *)(pData + 1);
533 uint32_t iPage;
534 int rc;
535
536 if (RT_UNLIKELY(!pData))
537 return VERR_NO_TMP_MEMORY;
538
539 VBOX_INIT_CALL(&pData->callInfo, WRITE, pClient);
540
541 pData->root.type = VMMDevHGCMParmType_32bit;
542 pData->root.u.value32 = pMap->root;
543
544 pData->handle.type = VMMDevHGCMParmType_64bit;
545 pData->handle.u.value64 = hFile;
546 pData->offset.type = VMMDevHGCMParmType_64bit;
547 pData->offset.u.value64 = offset;
548 pData->cb.type = VMMDevHGCMParmType_32bit;
549 pData->cb.u.value32 = cbToWrite;
550 pData->buffer.type = VMMDevHGCMParmType_PageList;
551 pData->buffer.u.PageList.size = cbToWrite;
552 pData->buffer.u.PageList.offset = sizeof(VBoxSFWrite);
553
554 pPgLst->flags = VBOX_HGCM_F_PARM_DIRECTION_TO_HOST;
555 pPgLst->offFirstPage = (uint16_t)(PhysBuffer & PAGE_OFFSET_MASK);
556 pPgLst->cPages = cPages;
557 PhysBuffer &= ~(RTCCPHYS)PAGE_OFFSET_MASK;
558 for (iPage = 0; iPage < cPages; iPage++, PhysBuffer += PAGE_SIZE)
559 pPgLst->aPages[iPage] = PhysBuffer;
560
561 rc = VbglHGCMCall (pClient->handle, &pData->callInfo, cbData);
562 if (RT_SUCCESS (rc))
563 {
564 rc = pData->callInfo.result;
565 *pcbBuffer = pData->cb.u.value32;
566 }
567
568 RTMemTmpFree(pData);
569 return rc;
570
571}
572
573DECLVBGL(int) VbglR0SharedFolderWritePageList(PVBSFCLIENT pClient, PVBSFMAP pMap, SHFLHANDLE hFile,
574 uint64_t offset, uint32_t *pcbBuffer,
575 uint16_t offFirstPage, uint16_t cPages, RTGCPHYS64 *paPages)
576{
577 uint32_t cbToWrite = *pcbBuffer;
578 uint32_t cbData = (uint32_t)(sizeof(VBoxSFWrite) + RT_UOFFSETOF(HGCMPageListInfo, aPages[cPages]));
579 VBoxSFWrite *pData = (VBoxSFWrite *)RTMemTmpAlloc(cbData);
580 HGCMPageListInfo *pPgLst = (HGCMPageListInfo *)(pData + 1);
581 uint16_t iPage;
582 int rc;
583
584 if (RT_UNLIKELY(!pData))
585 return VERR_NO_TMP_MEMORY;
586
587 VBOX_INIT_CALL(&pData->callInfo, WRITE, pClient);
588
589 pData->root.type = VMMDevHGCMParmType_32bit;
590 pData->root.u.value32 = pMap->root;
591
592 pData->handle.type = VMMDevHGCMParmType_64bit;
593 pData->handle.u.value64 = hFile;
594 pData->offset.type = VMMDevHGCMParmType_64bit;
595 pData->offset.u.value64 = offset;
596 pData->cb.type = VMMDevHGCMParmType_32bit;
597 pData->cb.u.value32 = cbToWrite;
598 pData->buffer.type = VMMDevHGCMParmType_PageList;
599 pData->buffer.u.PageList.size = cbToWrite;
600 pData->buffer.u.PageList.offset = sizeof(VBoxSFWrite);
601
602 pPgLst->flags = VBOX_HGCM_F_PARM_DIRECTION_TO_HOST;
603 pPgLst->offFirstPage = offFirstPage;
604 pPgLst->cPages = cPages;
605 for (iPage = 0; iPage < cPages; iPage++)
606 pPgLst->aPages[iPage] = paPages[iPage];
607
608 rc = VbglHGCMCall (pClient->handle, &pData->callInfo, cbData);
609 if (RT_SUCCESS (rc))
610 {
611 rc = pData->callInfo.result;
612 *pcbBuffer = pData->cb.u.value32;
613 }
614
615 RTMemTmpFree(pData);
616 return rc;
617}
618
619DECLVBGL(int) vboxCallFlush(PVBSFCLIENT pClient, PVBSFMAP pMap, SHFLHANDLE hFile)
620{
621 int rc = VINF_SUCCESS;
622
623 VBoxSFFlush data;
624
625 VBOX_INIT_CALL(&data.callInfo, FLUSH, pClient);
626
627 data.root.type = VMMDevHGCMParmType_32bit;
628 data.root.u.value32 = pMap->root;
629
630 data.handle.type = VMMDevHGCMParmType_64bit;
631 data.handle.u.value64 = hFile;
632
633 rc = VbglHGCMCall (pClient->handle, &data.callInfo, sizeof (data));
634
635/* Log(("VBOXSF: VBoxSF::vboxCallFlush: "
636 "VbglHGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.result));
637*/
638 if (RT_SUCCESS (rc))
639 {
640 rc = data.callInfo.result;
641 }
642 return rc;
643}
644
645DECLVBGL(int) vboxCallDirInfo (
646 PVBSFCLIENT pClient,
647 PVBSFMAP pMap,
648 SHFLHANDLE hFile,
649 PSHFLSTRING ParsedPath,
650 uint32_t flags,
651 uint32_t index,
652 uint32_t *pcbBuffer,
653 PSHFLDIRINFO pBuffer,
654 uint32_t *pcFiles)
655{
656 int rc = VINF_SUCCESS;
657
658 VBoxSFList data;
659
660 VBOX_INIT_CALL(&data.callInfo, LIST, pClient);
661
662 data.root.type = VMMDevHGCMParmType_32bit;
663 data.root.u.value32 = pMap->root;
664
665 data.handle.type = VMMDevHGCMParmType_64bit;
666 data.handle.u.value64 = hFile;
667 data.flags.type = VMMDevHGCMParmType_32bit;
668 data.flags.u.value32 = flags;
669 data.cb.type = VMMDevHGCMParmType_32bit;
670 data.cb.u.value32 = *pcbBuffer;
671 data.path.type = VMMDevHGCMParmType_LinAddr_In;
672 data.path.u.Pointer.size =
673 (ParsedPath) ? ShflStringSizeOfBuffer(ParsedPath) : 0;
674 data.path.u.Pointer.u.linearAddr = (uintptr_t) ParsedPath;
675
676 data.buffer.type = VMMDevHGCMParmType_LinAddr_Out;
677 data.buffer.u.Pointer.size = *pcbBuffer;
678 data.buffer.u.Pointer.u.linearAddr = (uintptr_t)pBuffer;
679
680 data.resumePoint.type = VMMDevHGCMParmType_32bit;
681 data.resumePoint.u.value32 = index;
682 data.cFiles.type = VMMDevHGCMParmType_32bit;
683 data.cFiles.u.value32 = 0; /* out parameters only */
684
685 rc = VbglHGCMCall (pClient->handle, &data.callInfo, sizeof (data));
686
687/* Log(("VBOXSF: VBoxSF::vboxCallDirInfo: "
688 "VbglHGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.result));
689*/
690 if (RT_SUCCESS (rc))
691 {
692 rc = data.callInfo.result;
693 }
694 *pcbBuffer = data.cb.u.value32;
695 *pcFiles = data.cFiles.u.value32;
696 return rc;
697}
698
699DECLVBGL(int) vboxCallFSInfo(PVBSFCLIENT pClient, PVBSFMAP pMap, SHFLHANDLE hFile,
700 uint32_t flags, uint32_t *pcbBuffer, PSHFLDIRINFO pBuffer)
701{
702 int rc = VINF_SUCCESS;
703
704 VBoxSFInformation data;
705
706 VBOX_INIT_CALL(&data.callInfo, INFORMATION, pClient);
707
708 data.root.type = VMMDevHGCMParmType_32bit;
709 data.root.u.value32 = pMap->root;
710
711 data.handle.type = VMMDevHGCMParmType_64bit;
712 data.handle.u.value64 = hFile;
713 data.flags.type = VMMDevHGCMParmType_32bit;
714 data.flags.u.value32 = flags;
715 data.cb.type = VMMDevHGCMParmType_32bit;
716 data.cb.u.value32 = *pcbBuffer;
717 data.info.type = VMMDevHGCMParmType_LinAddr;
718 data.info.u.Pointer.size = *pcbBuffer;
719 data.info.u.Pointer.u.linearAddr = (uintptr_t)pBuffer;
720
721 rc = VbglHGCMCall (pClient->handle, &data.callInfo, sizeof (data));
722
723/* Log(("VBOXSF: VBoxSF::vboxCallFileInfo: "
724 "VbglHGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.result));
725*/
726 if (RT_SUCCESS (rc))
727 {
728 rc = data.callInfo.result;
729 *pcbBuffer = data.cb.u.value32;
730 }
731 return rc;
732}
733
734DECLVBGL(int) vboxCallLock(PVBSFCLIENT pClient, PVBSFMAP pMap, SHFLHANDLE hFile,
735 uint64_t offset, uint64_t cbSize, uint32_t fLock)
736{
737 int rc = VINF_SUCCESS;
738
739 VBoxSFLock data;
740
741 VBOX_INIT_CALL(&data.callInfo, LOCK, pClient);
742
743 data.root.type = VMMDevHGCMParmType_32bit;
744 data.root.u.value32 = pMap->root;
745
746 data.handle.type = VMMDevHGCMParmType_64bit;
747 data.handle.u.value64 = hFile;
748 data.offset.type = VMMDevHGCMParmType_64bit;
749 data.offset.u.value64 = offset;
750 data.length.type = VMMDevHGCMParmType_64bit;
751 data.length.u.value64 = cbSize;
752
753 data.flags.type = VMMDevHGCMParmType_32bit;
754 data.flags.u.value32 = fLock;
755
756 rc = VbglHGCMCall (pClient->handle, &data.callInfo, sizeof (data));
757
758/* Log(("VBOXSF: VBoxSF::vboxCallLock: "
759 "VbglHGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.result));
760*/
761 if (RT_SUCCESS (rc))
762 {
763 rc = data.callInfo.result;
764 }
765 return rc;
766}
767
768DECLVBGL(int) vboxCallSetUtf8 (PVBSFCLIENT pClient)
769{
770 int rc = VINF_SUCCESS;
771
772 VBoxGuestHGCMCallInfo callInfo;
773
774 VBOX_INIT_CALL (&callInfo, SET_UTF8, pClient);
775 rc = VbglHGCMCall (pClient->handle, &callInfo, sizeof (callInfo));
776 if (RT_SUCCESS (rc))
777 {
778 rc = callInfo.result;
779 }
780 return rc;
781}
782
783DECLVBGL(int) vboxReadLink (PVBSFCLIENT pClient, PVBSFMAP pMap, PSHFLSTRING pParsedPath,
784 uint32_t cbBuffer, uint8_t *pBuffer)
785{
786 int rc = VINF_SUCCESS;
787
788 VBoxSFReadLink data;
789
790 VBOX_INIT_CALL(&data.callInfo, READLINK, pClient);
791
792 data.root.type = VMMDevHGCMParmType_32bit;
793 data.root.u.value32 = pMap->root;
794
795 data.path.type = VMMDevHGCMParmType_LinAddr_In;
796 data.path.u.Pointer.size = ShflStringSizeOfBuffer (pParsedPath);
797 data.path.u.Pointer.u.linearAddr = (uintptr_t)pParsedPath;
798
799 data.buffer.type = VMMDevHGCMParmType_LinAddr_Out;
800 data.buffer.u.Pointer.size = cbBuffer;
801 data.buffer.u.Pointer.u.linearAddr = (uintptr_t)pBuffer;
802
803 rc = VbglHGCMCall (pClient->handle, &data.callInfo, sizeof (data));
804
805/* Log(("VBOXSF: VBoxSF::vboxCallReadline: "
806 "VbglHGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.result));
807*/
808 if (RT_SUCCESS (rc))
809 {
810 rc = data.callInfo.result;
811 }
812 return rc;
813}
814
815DECLVBGL(int) vboxCallSymlink (PVBSFCLIENT pClient, PVBSFMAP pMap, PSHFLSTRING pNewPath, PSHFLSTRING pOldPath,
816 PSHFLFSOBJINFO pBuffer)
817{
818 int rc = VINF_SUCCESS;
819
820 VBoxSFSymlink data;
821
822 VBOX_INIT_CALL(&data.callInfo, SYMLINK, pClient);
823
824 data.root.type = VMMDevHGCMParmType_32bit;
825 data.root.u.value32 = pMap->root;
826
827 data.newPath.type = VMMDevHGCMParmType_LinAddr_In;
828 data.newPath.u.Pointer.size = ShflStringSizeOfBuffer (pNewPath);
829 data.newPath.u.Pointer.u.linearAddr = (uintptr_t)pNewPath;
830
831 data.oldPath.type = VMMDevHGCMParmType_LinAddr_In;
832 data.oldPath.u.Pointer.size = ShflStringSizeOfBuffer (pOldPath);
833 data.oldPath.u.Pointer.u.linearAddr = (uintptr_t)pOldPath;
834
835 data.info.type = VMMDevHGCMParmType_LinAddr_Out;
836 data.info.u.Pointer.size = sizeof(SHFLFSOBJINFO);
837 data.info.u.Pointer.u.linearAddr = (uintptr_t)pBuffer;
838
839 rc = VbglHGCMCall (pClient->handle, &data.callInfo, sizeof (data));
840
841/* Log(("VBOXSF: VBoxSF::vboxCallSymlink: "
842 "VbglHGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.result));
843*/
844 if (RT_SUCCESS (rc))
845 {
846 rc = data.callInfo.result;
847 }
848 return rc;
849}
850
851DECLVBGL(int) vboxCallSetSymlinks (PVBSFCLIENT pClient)
852{
853 int rc = VINF_SUCCESS;
854
855 VBoxGuestHGCMCallInfo callInfo;
856
857 VBOX_INIT_CALL (&callInfo, SET_SYMLINKS, pClient);
858 rc = VbglHGCMCall (pClient->handle, &callInfo, sizeof (callInfo));
859 if (RT_SUCCESS (rc))
860 {
861 rc = callInfo.result;
862 }
863 return rc;
864}
865
866
867#endif /* !VBGL_VBOXGUEST */
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