VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxCalls.c@ 880

Last change on this file since 880 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 18.2 KB
Line 
1/** @file
2 *
3 * VBoxGuestLib - A support library for VirtualBox guest additions:
4 * Central calls
5 */
6
7/*
8 * Copyright (C) 2006 InnoTek Systemberatung GmbH
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License as published by the Free Software Foundation,
14 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
15 * distribution. VirtualBox OSE is distributed in the hope that it will
16 * be useful, but WITHOUT ANY WARRANTY of any kind.
17 *
18 * If you received this file as part of a commercial VirtualBox
19 * distribution, then only the terms of your commercial VirtualBox
20 * license agreement apply instead of the previous paragraph.
21 */
22
23/* Entire file is ifdef'ed with !VBGL_VBOXGUEST */
24#ifndef VBGL_VBOXGUEST
25
26#ifdef __linux__ /** @todo r=bird: Why isn't this __LINUX__ like everywhere else? */
27# include "VBoxCalls.h"
28# define DbgPrint AssertMsg2
29#else
30# include "VBoxCalls.h"
31#endif
32#include <iprt/time.h>
33#include <iprt/path.h>
34
35#define SHFL_CPARMS_SET_UTF8 0
36
37#define VBOX_INIT_CALL(a, b, c) \
38 (a)->result = VINF_SUCCESS; \
39 (a)->u32ClientID = (c)->ulClientID; \
40 (a)->u32Function = SHFL_FN_##b; \
41 (a)->cParms = SHFL_CPARMS_##b
42
43#ifdef __linux__
44# include <linux/string.h>
45# define RtlZeroMemory(a, b) memset (a, 0, b)
46#endif
47
48DECLVBGL(int) vboxInit (void)
49{
50 int rc = VINF_SUCCESS;
51
52 rc = VbglInit ();
53 return rc;
54}
55
56DECLVBGL(void) vboxUninit (void)
57{
58 VbglTerminate ();
59}
60
61DECLVBGL(int) vboxConnect (PVBSFCLIENT pClient)
62{
63 int rc = VINF_SUCCESS;
64
65 VBoxGuestHGCMConnectInfo data;
66
67 RtlZeroMemory (&data, sizeof (VBoxGuestHGCMConnectInfo));
68
69 pClient->handle = NULL;
70
71 data.result = VINF_SUCCESS;
72 data.Loc.type = VMMDevHGCMLoc_LocalHost_Existing;
73 strcpy (data.Loc.u.host.achName, "VBoxSharedFolders");
74
75 rc = VbglHGCMConnect (&pClient->handle, &data);
76
77/* Log(("VBOXSF: VBoxSF::vboxConnect: VbglHGCMConnect rc = %#x, result = %#x\n",
78 rc, data.result));
79*/
80 if (VBOX_SUCCESS (rc))
81 {
82 rc = data.result;
83 }
84
85 if (VBOX_SUCCESS (rc))
86 {
87 pClient->ulClientID = data.u32ClientID;
88 }
89 return rc;
90}
91
92DECLVBGL(void) vboxDisconnect (PVBSFCLIENT pClient)
93{
94 int rc;
95
96 VBoxGuestHGCMDisconnectInfo data;
97
98 if (pClient->handle == NULL)
99 return; /* not connected */
100
101 RtlZeroMemory (&data, sizeof (VBoxGuestHGCMDisconnectInfo));
102
103 data.result = VINF_SUCCESS;
104 data.u32ClientID = pClient->ulClientID;
105
106 rc = VbglHGCMDisconnect (pClient->handle, &data);
107/* Log(("VBOXSF: VBoxSF::vboxDisconnect: "
108 "VbglHGCMDisconnect rc = %#x, result = %#x\n", rc, data.result));
109*/
110 return;
111}
112
113DECLVBGL(int) vboxCallQueryMappings (PVBSFCLIENT pClient, SHFLMAPPING paMappings[],
114 uint32_t *pcMappings)
115{
116 int rc = VINF_SUCCESS;
117
118 VBoxSFQueryMappings data;
119
120 VBOX_INIT_CALL(&data.callInfo, QUERY_MAPPINGS, pClient);
121
122 data.flags.type = VMMDevHGCMParmType_32bit;
123 data.flags.u.value32 = SHFL_MF_UCS2;
124
125 data.numberOfMappings.type = VMMDevHGCMParmType_32bit;
126 data.numberOfMappings.u.value32 = *pcMappings;
127
128 data.mappings.type = VMMDevHGCMParmType_LinAddr;
129 data.mappings.u.Pointer.size = sizeof (SHFLMAPPING) * *pcMappings;
130 data.mappings.u.Pointer.u.linearAddr = (VBOXGCPTR)&paMappings[0];
131
132/* Log(("VBOXSF: in ifs difference %d\n",
133 (char *)&data.flags.type - (char *)&data.callInfo.cParms));
134*/
135 rc = VbglHGCMCall (pClient->handle, &data.callInfo, sizeof (data));
136/*
137 Log(("VBOXSF: VBoxSF::vboxCallQueryMappings: "
138 "VbglHGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.result));
139*/
140 if (VBOX_SUCCESS (rc))
141 {
142 rc = data.callInfo.result;
143 }
144
145 if (VBOX_SUCCESS (rc))
146 {
147 *pcMappings = data.numberOfMappings.u.value32;
148 }
149
150 return rc;
151}
152
153DECLVBGL(int) vboxCallQueryMapName (PVBSFCLIENT pClient, SHFLROOT root,
154 int type, SHFLSTRING *pString, uint32_t size)
155{
156 int rc = VINF_SUCCESS;
157
158 VBoxSFQueryMapName data;
159
160 VBOX_INIT_CALL(&data.callInfo, QUERY_MAP_NAME, pClient);
161
162 data.root.type = VMMDevHGCMParmType_32bit;
163 data.root.u.value32 = root;
164
165 data.type.type = VMMDevHGCMParmType_32bit;
166 data.type.u.value32 = type;
167
168 data.name.type = VMMDevHGCMParmType_LinAddr;
169 data.name.u.Pointer.size = size;
170 data.name.u.Pointer.u.linearAddr = (VBOXGCPTR)pString;
171
172 rc = VbglHGCMCall (pClient->handle, &data.callInfo, sizeof (data));
173
174/* Log(("VBOXSF: VBoxSF::vboxCallQueryMapName: "
175 "VbglHGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.result));
176*/
177 if (VBOX_SUCCESS (rc))
178 {
179 rc = data.callInfo.result;
180 }
181
182 return rc;
183}
184
185DECLVBGL(int) vboxCallMapFolder(PVBSFCLIENT pClient, PSHFLSTRING szFolderName,
186 PVBSFMAP pMap)
187{
188 int rc = VINF_SUCCESS;
189
190 VBoxSFMapFolder data;
191
192 VBOX_INIT_CALL(&data.callInfo, MAP_FOLDER, pClient);
193
194 data.path.type = VMMDevHGCMParmType_LinAddr;
195 data.path.u.Pointer.size = ShflStringSizeOfBuffer (szFolderName);
196 data.path.u.Pointer.u.linearAddr = (VBOXGCPTR)szFolderName;
197
198 data.root.type = VMMDevHGCMParmType_32bit;
199 data.root.u.value32 = 0;
200
201 data.delimiter.type = VMMDevHGCMParmType_32bit;
202 data.delimiter.u.value32 = RTPATH_DELIMITER;
203
204 rc = VbglHGCMCall (pClient->handle, &data.callInfo, sizeof (data));
205
206/* Log(("VBOXSF: VBoxSF::vboxCallMapFolder: "
207 "VbglHGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.result));
208*/
209 if (VBOX_SUCCESS (rc))
210 {
211 pMap->root = data.root.u.value32;
212 rc = data.callInfo.result;
213 }
214 return rc;
215}
216
217DECLVBGL(int) vboxCallUnmapFolder(PVBSFCLIENT pClient, PVBSFMAP pMap)
218{
219 int rc = VINF_SUCCESS;
220
221 VBoxSFUnmapFolder data;
222
223 VBOX_INIT_CALL(&data.callInfo, UNMAP_FOLDER, pClient);
224
225 data.root.type = VMMDevHGCMParmType_32bit;
226 data.root.u.value32 = pMap->root;
227
228 rc = VbglHGCMCall (pClient->handle, &data.callInfo, sizeof (data));
229
230/* Log(("VBOXSF: VBoxSF::vboxCallUnmapFolder: "
231 "VbglHGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.result));
232*/
233 if (VBOX_SUCCESS (rc))
234 {
235 rc = data.callInfo.result;
236 }
237 return rc;
238}
239
240DECLVBGL(int) vboxCallCreate (PVBSFCLIENT pClient, PVBSFMAP pMap,
241 PSHFLSTRING pParsedPath, PSHFLCREATEPARMS pCreateParms)
242{
243 /** @todo copy buffers to physical or mapped memory. */
244 int rc = VINF_SUCCESS;
245
246 VBoxSFCreate data;
247
248 VBOX_INIT_CALL(&data.callInfo, CREATE, pClient);
249
250 data.root.type = VMMDevHGCMParmType_32bit;
251 data.root.u.value32 = pMap->root;
252
253 data.path.type = VMMDevHGCMParmType_LinAddr;
254 data.path.u.Pointer.size = ShflStringSizeOfBuffer (pParsedPath);
255 data.path.u.Pointer.u.linearAddr = (VBOXGCPTR)pParsedPath;
256
257 data.parms.type = VMMDevHGCMParmType_LinAddr;
258 data.parms.u.Pointer.size = sizeof (SHFLCREATEPARMS);
259 data.parms.u.Pointer.u.linearAddr = (VBOXGCPTR)pCreateParms;
260
261 rc = VbglHGCMCall (pClient->handle, &data.callInfo, sizeof (data));
262
263/* Log(("VBOXSF: VBoxSF::vboxCallCreate: "
264 "VbglHGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.result));
265*/
266 if (VBOX_SUCCESS (rc))
267 {
268 rc = data.callInfo.result;
269 }
270 return rc;
271}
272
273DECLVBGL(int) vboxCallClose (PVBSFCLIENT pClient, PVBSFMAP pMap, SHFLHANDLE Handle)
274{
275 int rc = VINF_SUCCESS;
276
277 VBoxSFClose data;
278
279 VBOX_INIT_CALL(&data.callInfo, CLOSE, pClient);
280
281 data.root.type = VMMDevHGCMParmType_32bit;
282 data.root.u.value32 = pMap->root;
283
284 data.handle.type = VMMDevHGCMParmType_64bit;
285 data.handle.u.value64 = Handle;
286
287 rc = VbglHGCMCall (pClient->handle, &data.callInfo, sizeof (data));
288
289/* Log(("VBOXSF: VBoxSF::vboxCallClose: "
290 "VbglHGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.result));
291*/
292 if (VBOX_SUCCESS (rc))
293 {
294 rc = data.callInfo.result;
295 }
296
297 return rc;
298}
299
300DECLVBGL(int) vboxCallRemove (PVBSFCLIENT pClient, PVBSFMAP pMap,
301 PSHFLSTRING pParsedPath, uint32_t flags)
302{
303 int rc = VINF_SUCCESS;
304
305 VBoxSFRemove data;
306
307 VBOX_INIT_CALL(&data.callInfo, REMOVE, pClient);
308
309 data.root.type = VMMDevHGCMParmType_32bit;
310 data.root.u.value32 = pMap->root;
311
312 data.path.type = VMMDevHGCMParmType_LinAddr_In;
313 data.path.u.Pointer.size = ShflStringSizeOfBuffer (pParsedPath);
314 data.path.u.Pointer.u.linearAddr = (VBOXGCPTR)pParsedPath;
315
316 data.flags.type = VMMDevHGCMParmType_32bit;
317 data.flags.u.value32 = flags;
318
319 rc = VbglHGCMCall (pClient->handle, &data.callInfo, sizeof (data));
320
321/* Log(("VBOXSF: VBoxSF::vboxCallRemove: "
322 "VbglHGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.result));
323*/
324 if (VBOX_SUCCESS (rc))
325 {
326 rc = data.callInfo.result;
327 }
328
329 return rc;
330}
331
332DECLVBGL(int) vboxCallRename (PVBSFCLIENT pClient, PVBSFMAP pMap,
333 PSHFLSTRING pSrcPath, PSHFLSTRING pDestPath, uint32_t flags)
334{
335 int rc = VINF_SUCCESS;
336
337 VBoxSFRename data;
338
339 VBOX_INIT_CALL(&data.callInfo, RENAME, pClient);
340
341 data.root.type = VMMDevHGCMParmType_32bit;
342 data.root.u.value32 = pMap->root;
343
344 data.src.type = VMMDevHGCMParmType_LinAddr_In;
345 data.src.u.Pointer.size = ShflStringSizeOfBuffer (pSrcPath);
346 data.src.u.Pointer.u.linearAddr = (VBOXGCPTR)pSrcPath;
347
348 data.dest.type = VMMDevHGCMParmType_LinAddr_In;
349 data.dest.u.Pointer.size = ShflStringSizeOfBuffer (pDestPath);
350 data.dest.u.Pointer.u.linearAddr = (VBOXGCPTR)pDestPath;
351
352 data.flags.type = VMMDevHGCMParmType_32bit;
353 data.flags.u.value32 = flags;
354
355 rc = VbglHGCMCall (pClient->handle, &data.callInfo, sizeof (data));
356
357/* Log(("VBOXSF: VBoxSF::vboxCallRename: "
358 "VbglHGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.result));
359*/
360 if (VBOX_SUCCESS (rc))
361 {
362 rc = data.callInfo.result;
363 }
364 return rc;
365}
366
367DECLVBGL(int) vboxCallRead(PVBSFCLIENT pClient, PVBSFMAP pMap, SHFLHANDLE hFile,
368 uint64_t offset, uint32_t *pcbBuffer, uint8_t *pBuffer)
369{
370 int rc = VINF_SUCCESS;
371
372 VBoxSFRead data;
373
374 VBOX_INIT_CALL(&data.callInfo, READ, pClient);
375
376 data.root.type = VMMDevHGCMParmType_32bit;
377 data.root.u.value32 = pMap->root;
378
379 data.handle.type = VMMDevHGCMParmType_64bit;
380 data.handle.u.value64 = hFile;
381 data.offset.type = VMMDevHGCMParmType_64bit;
382 data.offset.u.value64 = offset;
383 data.cb.type = VMMDevHGCMParmType_32bit;
384 data.cb.u.value32 = *pcbBuffer;
385 data.buffer.type = VMMDevHGCMParmType_LinAddr_Out;
386 data.buffer.u.Pointer.size = *pcbBuffer;
387 data.buffer.u.Pointer.u.linearAddr = (VBOXGCPTR)pBuffer;
388
389 rc = VbglHGCMCall (pClient->handle, &data.callInfo, sizeof (data));
390
391/* Log(("VBOXSF: VBoxSF::vboxCallRead: "
392 "VbglHGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.result));
393*/
394 if (VBOX_SUCCESS (rc))
395 {
396 rc = data.callInfo.result;
397 *pcbBuffer = data.cb.u.value32;
398 }
399 return rc;
400}
401
402DECLVBGL(int) vboxCallWrite(PVBSFCLIENT pClient, PVBSFMAP pMap, SHFLHANDLE hFile,
403 uint64_t offset, uint32_t *pcbBuffer, uint8_t *pBuffer)
404{
405 int rc = VINF_SUCCESS;
406
407 VBoxSFWrite data;
408
409 VBOX_INIT_CALL(&data.callInfo, WRITE, pClient);
410
411 data.root.type = VMMDevHGCMParmType_32bit;
412 data.root.u.value32 = pMap->root;
413
414 data.handle.type = VMMDevHGCMParmType_64bit;
415 data.handle.u.value64 = hFile;
416 data.offset.type = VMMDevHGCMParmType_64bit;
417 data.offset.u.value64 = offset;
418 data.cb.type = VMMDevHGCMParmType_32bit;
419 data.cb.u.value32 = *pcbBuffer;
420 data.buffer.type = VMMDevHGCMParmType_LinAddr_In;
421 data.buffer.u.Pointer.size = *pcbBuffer;
422 data.buffer.u.Pointer.u.linearAddr = (VBOXGCPTR)pBuffer;
423
424 rc = VbglHGCMCall (pClient->handle, &data.callInfo, sizeof (data));
425
426/* Log(("VBOXSF: VBoxSF::vboxCallWrite: "
427 "VbglHGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.result));
428*/
429 if (VBOX_SUCCESS (rc))
430 {
431 rc = data.callInfo.result;
432 *pcbBuffer = data.cb.u.value32;
433 }
434 return rc;
435}
436
437DECLVBGL(int) vboxCallFlush(PVBSFCLIENT pClient, PVBSFMAP pMap, SHFLHANDLE hFile)
438{
439 int rc = VINF_SUCCESS;
440
441 VBoxSFFlush data;
442
443 VBOX_INIT_CALL(&data.callInfo, FLUSH, pClient);
444
445 data.root.type = VMMDevHGCMParmType_32bit;
446 data.root.u.value32 = pMap->root;
447
448 data.handle.type = VMMDevHGCMParmType_64bit;
449 data.handle.u.value64 = hFile;
450
451 rc = VbglHGCMCall (pClient->handle, &data.callInfo, sizeof (data));
452
453/* Log(("VBOXSF: VBoxSF::vboxCallFlush: "
454 "VbglHGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.result));
455*/
456 if (VBOX_SUCCESS (rc))
457 {
458 rc = data.callInfo.result;
459 }
460 return rc;
461}
462
463DECLVBGL(int) vboxCallDirInfo (
464 PVBSFCLIENT pClient,
465 PVBSFMAP pMap,
466 SHFLHANDLE hFile,
467 PSHFLSTRING ParsedPath,
468 uint32_t flags,
469 uint32_t index,
470 uint32_t *pcbBuffer,
471 PSHFLDIRINFO pBuffer,
472 uint32_t *pcFiles)
473{
474 int rc = VINF_SUCCESS;
475
476 VBoxSFList data;
477
478 VBOX_INIT_CALL(&data.callInfo, LIST, pClient);
479
480 data.root.type = VMMDevHGCMParmType_32bit;
481 data.root.u.value32 = pMap->root;
482
483 data.handle.type = VMMDevHGCMParmType_64bit;
484 data.handle.u.value64 = hFile;
485 data.flags.type = VMMDevHGCMParmType_32bit;
486 data.flags.u.value32 = flags;
487 data.cb.type = VMMDevHGCMParmType_32bit;
488 data.cb.u.value32 = *pcbBuffer;
489 data.path.type = VMMDevHGCMParmType_LinAddr_In;
490 data.path.u.Pointer.size =
491 (ParsedPath) ? ShflStringSizeOfBuffer(ParsedPath) : 0;
492 data.path.u.Pointer.u.linearAddr = (VBOXGCPTR) ParsedPath;
493
494 data.buffer.type = VMMDevHGCMParmType_LinAddr_Out;
495 data.buffer.u.Pointer.size = *pcbBuffer;
496 data.buffer.u.Pointer.u.linearAddr = (VBOXGCPTR)pBuffer;
497
498 data.resumePoint.type = VMMDevHGCMParmType_32bit;
499 data.resumePoint.u.value32 = index;
500 data.cFiles.type = VMMDevHGCMParmType_32bit;
501 data.cFiles.u.value32 = 0; /* out parameters only */
502
503 rc = VbglHGCMCall (pClient->handle, &data.callInfo, sizeof (data));
504
505/* Log(("VBOXSF: VBoxSF::vboxCallDirInfo: "
506 "VbglHGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.result));
507*/
508 if (VBOX_SUCCESS (rc))
509 {
510 rc = data.callInfo.result;
511 }
512 *pcbBuffer = data.cb.u.value32;
513 *pcFiles = data.cFiles.u.value32;
514 return rc;
515}
516
517DECLVBGL(int) vboxCallFSInfo(PVBSFCLIENT pClient, PVBSFMAP pMap, SHFLHANDLE hFile,
518 uint32_t flags, uint32_t *pcbBuffer, PSHFLDIRINFO pBuffer)
519{
520 int rc = VINF_SUCCESS;
521
522 VBoxSFInformation data;
523
524 VBOX_INIT_CALL(&data.callInfo, INFORMATION, pClient);
525
526 data.root.type = VMMDevHGCMParmType_32bit;
527 data.root.u.value32 = pMap->root;
528
529 data.handle.type = VMMDevHGCMParmType_64bit;
530 data.handle.u.value64 = hFile;
531 data.flags.type = VMMDevHGCMParmType_32bit;
532 data.flags.u.value32 = flags;
533 data.cb.type = VMMDevHGCMParmType_32bit;
534 data.cb.u.value32 = *pcbBuffer;
535 data.info.type = VMMDevHGCMParmType_LinAddr;
536 data.info.u.Pointer.size = *pcbBuffer;
537 data.info.u.Pointer.u.linearAddr = (VBOXGCPTR)pBuffer;
538
539 rc = VbglHGCMCall (pClient->handle, &data.callInfo, sizeof (data));
540
541/* Log(("VBOXSF: VBoxSF::vboxCallFileInfo: "
542 "VbglHGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.result));
543*/
544 if (VBOX_SUCCESS (rc))
545 {
546 rc = data.callInfo.result;
547 *pcbBuffer = data.cb.u.value32;
548 }
549 return rc;
550}
551
552DECLVBGL(int) vboxCallLock(PVBSFCLIENT pClient, PVBSFMAP pMap, SHFLHANDLE hFile,
553 uint64_t offset, uint64_t cbSize, uint32_t fLock)
554{
555 int rc = VINF_SUCCESS;
556
557 VBoxSFLock data;
558
559 VBOX_INIT_CALL(&data.callInfo, LOCK, pClient);
560
561 data.root.type = VMMDevHGCMParmType_32bit;
562 data.root.u.value32 = pMap->root;
563
564 data.handle.type = VMMDevHGCMParmType_64bit;
565 data.handle.u.value64 = hFile;
566 data.offset.type = VMMDevHGCMParmType_64bit;
567 data.offset.u.value64 = offset;
568 data.length.type = VMMDevHGCMParmType_64bit;
569 data.length.u.value64 = cbSize;
570
571 data.flags.type = VMMDevHGCMParmType_32bit;
572 data.flags.u.value32 = fLock;
573
574 rc = VbglHGCMCall (pClient->handle, &data.callInfo, sizeof (data));
575
576/* Log(("VBOXSF: VBoxSF::vboxCallLock: "
577 "VbglHGCMCall rc = %#x, result = %#x\n", rc, data.callInfo.result));
578*/
579 if (VBOX_SUCCESS (rc))
580 {
581 rc = data.callInfo.result;
582 }
583 return rc;
584}
585
586DECLVBGL(int) vboxCallSetUtf8 (PVBSFCLIENT pClient)
587{
588 int rc = VINF_SUCCESS;
589
590 VBoxGuestHGCMCallInfo callInfo;
591
592 VBOX_INIT_CALL (&callInfo, SET_UTF8, pClient);
593 rc = VbglHGCMCall (pClient->handle, &callInfo, sizeof (callInfo));
594 if (VBOX_SUCCESS (rc))
595 {
596 rc = callInfo.result;
597 }
598 return rc;
599}
600
601#endif /* !VBGL_VBOXGUEST */
Note: See TracBrowser for help on using the repository browser.

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