VirtualBox

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

Last change on this file since 47151 was 45016, checked in by vboxsync, 12 years ago

VBoxGuestR0LibSharedFolders.c: nits.

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