VirtualBox

source: vbox/trunk/src/VBox/HostServices/SharedFolders/service.cpp@ 7692

Last change on this file since 7692 was 7429, checked in by vboxsync, 17 years ago

RTUCS2 -> RTUTF16.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 41.5 KB
Line 
1/** @file
2 * Shared Folders: Host service entry points.
3 */
4
5/*
6 * Copyright (C) 2006-2007 innotek GmbH
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 */
16
17#include <VBox/shflsvc.h>
18
19
20#include "shfl.h"
21#include "mappings.h"
22#include "shflhandle.h"
23#include "vbsf.h"
24#include <iprt/alloc.h>
25#include <iprt/string.h>
26#include <iprt/assert.h>
27#include <VBox/ssm.h>
28#include <VBox/pdm.h>
29
30#define SHFL_SSM_VERSION 2
31
32
33/* Shared Folders Host Service.
34 *
35 * Shared Folders map a host file system to guest logical filesystem.
36 * A mapping represents 'host name'<->'guest name' translation and a root
37 * identifier to be used to access this mapping.
38 * Examples: "C:\WINNT"<->"F:", "C:\WINNT\System32"<->"/mnt/host/system32".
39 *
40 * Therefore, host name and guest name are strings interpreted
41 * only by host service and guest client respectively. Host name is
42 * passed to guest only for informational purpose. Guest may for example
43 * display the string or construct volume label out of the string.
44 *
45 * Root identifiers are unique for whole guest life,
46 * that is until next guest reset/fresh start.
47 * 32 bit value incremented for each new mapping is used.
48 *
49 * Mapping strings are taken from VM XML configuration on VM startup.
50 * The service DLL takes mappings during initialization. There is
51 * also API for changing mappings at runtime.
52 *
53 * Current mappings and root identifiers are saved when VM is saved.
54 *
55 * Guest may use any of these mappings. Full path information
56 * about an object on a mapping consists of the root indentifier and
57 * a full path of object.
58 *
59 * Guest IFS connects to the service and calls SHFL_FN_QUERY_MAP
60 * function which returns current mappings. For guest convenience,
61 * removed mappings also returned with REMOVED flag and new mappings
62 * are marked with NEW flag.
63 *
64 * To access host file system guest just forwards file system calls
65 * to the service, and specifies full paths or handles for objects.
66 *
67 *
68 */
69
70
71PVBOXHGCMSVCHELPERS g_pHelpers;
72static PPDMLED pStatusLed = NULL;
73
74static DECLCALLBACK(int) svcUnload (void)
75{
76 int rc = VINF_SUCCESS;
77
78 Log(("svcUnload\n"));
79
80 return rc;
81}
82
83static DECLCALLBACK(int) svcConnect (uint32_t u32ClientID, void *pvClient)
84{
85 int rc = VINF_SUCCESS;
86
87 NOREF(u32ClientID);
88 NOREF(pvClient);
89
90 Log(("svcConnect: u32ClientID = %d\n", u32ClientID));
91
92 return rc;
93}
94
95static DECLCALLBACK(int) svcDisconnect (uint32_t u32ClientID, void *pvClient)
96{
97 int rc = VINF_SUCCESS;
98 SHFLCLIENTDATA *pClient = (SHFLCLIENTDATA *)pvClient;
99
100 Log(("svcDisconnect: u32ClientID = %d\n", u32ClientID));
101
102 vbsfDisconnect(pClient);
103 return rc;
104}
105
106/** @note We only save as much state as required to access the shared folder again after restore.
107 * All I/O requests pending at the time of saving will never be completed or result in errors.
108 * (file handles no longer valid etc)
109 * This works as designed at the moment. A full state save would be difficult and not always possible
110 * as the contents of a shared folder might change in between save and restore.
111 */
112static DECLCALLBACK(int) svcSaveState(uint32_t u32ClientID, void *pvClient, PSSMHANDLE pSSM)
113{
114 SHFLCLIENTDATA *pClient = (SHFLCLIENTDATA *)pvClient;
115
116 Log(("svcSaveState: u32ClientID = %d\n", u32ClientID));
117
118 int rc = SSMR3PutU32(pSSM, SHFL_SSM_VERSION);
119 AssertRCReturn(rc, rc);
120
121 rc = SSMR3PutU32(pSSM, SHFL_MAX_MAPPINGS);
122 AssertRCReturn(rc, rc);
123
124 /* Save client structure length & contents */
125 rc = SSMR3PutU32(pSSM, sizeof(*pClient));
126 AssertRCReturn(rc, rc);
127
128 rc = SSMR3PutMem(pSSM, pClient, sizeof(*pClient));
129 AssertRCReturn(rc, rc);
130
131 /* Save all the active mappings. */
132 for (int i=0;i<SHFL_MAX_MAPPINGS;i++)
133 {
134 rc = SSMR3PutU32(pSSM, FolderMapping[i].cMappings);
135 AssertRCReturn(rc, rc);
136
137 rc = SSMR3PutBool(pSSM, FolderMapping[i].fValid);
138 AssertRCReturn(rc, rc);
139
140 if (FolderMapping[i].fValid)
141 {
142 uint32_t len;
143
144 len = ShflStringSizeOfBuffer(FolderMapping[i].pFolderName);
145 rc = SSMR3PutU32(pSSM, len);
146 AssertRCReturn(rc, rc);
147
148 rc = SSMR3PutMem(pSSM, FolderMapping[i].pFolderName, len);
149 AssertRCReturn(rc, rc);
150
151 len = ShflStringSizeOfBuffer(FolderMapping[i].pMapName);
152 rc = SSMR3PutU32(pSSM, len);
153 AssertRCReturn(rc, rc);
154
155 rc = SSMR3PutMem(pSSM, FolderMapping[i].pMapName, len);
156 AssertRCReturn(rc, rc);
157
158 rc = SSMR3PutBool(pSSM, FolderMapping[i].fHostCaseSensitive);
159 AssertRCReturn(rc, rc);
160
161 rc = SSMR3PutBool(pSSM, FolderMapping[i].fGuestCaseSensitive);
162 AssertRCReturn(rc, rc);
163 }
164 }
165
166 return VINF_SUCCESS;
167}
168
169static DECLCALLBACK(int) svcLoadState(uint32_t u32ClientID, void *pvClient, PSSMHANDLE pSSM)
170{
171 uint32_t nrMappings;
172 SHFLCLIENTDATA *pClient = (SHFLCLIENTDATA *)pvClient;
173 uint32_t len, version;
174
175 Log(("svcLoadState: u32ClientID = %d\n", u32ClientID));
176
177 int rc = SSMR3GetU32(pSSM, &version);
178 AssertRCReturn(rc, rc);
179
180 if (version != SHFL_SSM_VERSION)
181 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
182
183 rc = SSMR3GetU32(pSSM, &nrMappings);
184 AssertRCReturn(rc, rc);
185 if (nrMappings != SHFL_MAX_MAPPINGS)
186 return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
187
188 /* Restore the client data (flags + path delimiter at the moment) */
189 rc = SSMR3GetU32(pSSM, &len);
190 AssertRCReturn(rc, rc);
191
192 if (len != sizeof(*pClient))
193 return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
194
195 rc = SSMR3GetMem(pSSM, pClient, sizeof(*pClient));
196 AssertRCReturn(rc, rc);
197
198 /* We don't actually (fully) restore the state; we simply check if the current state is as we it expect it to be. */
199 for (int i=0;i<SHFL_MAX_MAPPINGS;i++)
200 {
201 bool fValid;
202
203 /* restore the folder mapping counter. */
204 rc = SSMR3GetU32(pSSM, &FolderMapping[i].cMappings);
205 AssertRCReturn(rc, rc);
206
207 rc = SSMR3GetBool(pSSM, &fValid);
208 AssertRCReturn(rc, rc);
209
210 if (fValid != FolderMapping[i].fValid)
211 return VERR_SSM_UNEXPECTED_DATA;
212
213 if (FolderMapping[i].fValid)
214 {
215 PSHFLSTRING pName;
216
217 /* Check the host path name. */
218 rc = SSMR3GetU32(pSSM, &len);
219 AssertRCReturn(rc, rc);
220
221 if (len != ShflStringSizeOfBuffer(FolderMapping[i].pFolderName))
222 return VERR_SSM_UNEXPECTED_DATA;
223
224 pName = (PSHFLSTRING)RTMemAlloc(len);
225 Assert(pName);
226 if (pName == NULL)
227 return VERR_NO_MEMORY;
228
229 rc = SSMR3GetMem(pSSM, pName, len);
230 AssertRCReturn(rc, rc);
231
232 if (memcmp(FolderMapping[i].pFolderName, pName, len))
233 {
234 RTMemFree(pName);
235 return VERR_SSM_UNEXPECTED_DATA;
236 }
237 RTMemFree(pName);
238
239 /* Check the map name. */
240 rc = SSMR3GetU32(pSSM, &len);
241 AssertRCReturn(rc, rc);
242
243 if (len != ShflStringSizeOfBuffer(FolderMapping[i].pMapName))
244 return VERR_SSM_UNEXPECTED_DATA;
245
246 pName = (PSHFLSTRING)RTMemAlloc(len);
247 Assert(pName);
248 if (pName == NULL)
249 return VERR_NO_MEMORY;
250
251 rc = SSMR3GetMem(pSSM, pName, len);
252 AssertRCReturn(rc, rc);
253
254 if (memcmp(FolderMapping[i].pMapName, pName, len))
255 {
256 RTMemFree(pName);
257 return VERR_SSM_UNEXPECTED_DATA;
258 }
259 RTMemFree(pName);
260
261 bool fCaseSensitive;
262
263 rc = SSMR3GetBool(pSSM, &fCaseSensitive);
264 AssertRCReturn(rc, rc);
265 if (FolderMapping[i].fHostCaseSensitive != fCaseSensitive)
266 return VERR_SSM_UNEXPECTED_DATA;
267
268 rc = SSMR3GetBool(pSSM, &FolderMapping[i].fGuestCaseSensitive);
269 AssertRCReturn(rc, rc);
270 }
271 }
272 return VINF_SUCCESS;
273}
274
275static DECLCALLBACK(void) svcCall (VBOXHGCMCALLHANDLE callHandle, uint32_t u32ClientID, void *pvClient, uint32_t u32Function, uint32_t cParms, VBOXHGCMSVCPARM paParms[])
276{
277 int rc = VINF_SUCCESS;
278
279 Log(("svcCall: u32ClientID = %d, fn = %d, cParms = %d, pparms = %d\n", u32ClientID, u32Function, cParms, paParms));
280
281 SHFLCLIENTDATA *pClient = (SHFLCLIENTDATA *)pvClient;
282
283 uint8_t AsynchronousProcessing = 0;
284
285#ifdef DEBUG
286 uint32_t i;
287
288 for (i = 0; i < cParms; i++)
289 {
290 /** @todo parameters other than 32 bit */
291 Log((" pparms[%d]: type %d value %d\n", i, paParms[i].type, paParms[i].u.uint32));
292 }
293#endif
294
295 switch (u32Function)
296 {
297 case SHFL_FN_QUERY_MAPPINGS:
298 {
299 Log(("svcCall: SHFL_FN_QUERY_MAPPINGS\n"));
300
301 /* Verify parameter count and types. */
302 if (cParms != SHFL_CPARMS_QUERY_MAPPINGS)
303 {
304 rc = VERR_INVALID_PARAMETER;
305 }
306 else if ( paParms[0].type != VBOX_HGCM_SVC_PARM_32BIT /* flags */
307 || paParms[1].type != VBOX_HGCM_SVC_PARM_32BIT /* numberOfMappings */
308 || paParms[2].type != VBOX_HGCM_SVC_PARM_PTR /* mappings */
309 )
310 {
311 rc = VERR_INVALID_PARAMETER;
312 }
313 else
314 {
315 /* Fetch parameters. */
316 uint32_t fu32Flags = paParms[0].u.uint32;
317 uint32_t cMappings = paParms[1].u.uint32;
318 SHFLMAPPING *pMappings = (SHFLMAPPING *)paParms[2].u.pointer.addr;
319 uint32_t cbMappings = paParms[2].u.pointer.size;
320
321 /* Verify parameters values. */
322 if ( (fu32Flags & ~SHFL_MF_UTF8) != 0
323 || (cbMappings < sizeof (SHFLMAPPING) * cMappings)
324 )
325 {
326 rc = VERR_INVALID_PARAMETER;
327 }
328 else
329 {
330 /* Execute the function. */
331 if (fu32Flags & SHFL_MF_UTF8)
332 {
333 pClient->fu32Flags |= SHFL_CF_UTF8;
334 }
335
336 rc = vbsfMappingsQuery (pClient, pMappings, &cMappings);
337
338 if (VBOX_SUCCESS(rc))
339 {
340 /* Update parameters.*/
341 paParms[1].u.uint32 = cMappings;
342 }
343 }
344 }
345
346
347 } break;
348
349 case SHFL_FN_QUERY_MAP_NAME:
350 {
351 Log(("svcCall: SHFL_FN_QUERY_MAP_NAME\n"));
352
353 /* Verify parameter count and types. */
354 if (cParms != SHFL_CPARMS_QUERY_MAP_NAME)
355 {
356 rc = VERR_INVALID_PARAMETER;
357 }
358 else if ( paParms[0].type != VBOX_HGCM_SVC_PARM_32BIT /* root */
359 || paParms[1].type != VBOX_HGCM_SVC_PARM_PTR /* name */
360 )
361 {
362 rc = VERR_INVALID_PARAMETER;
363 }
364 else
365 {
366 /* Fetch parameters. */
367 SHFLROOT root = (SHFLROOT)paParms[0].u.uint32;
368 SHFLSTRING *pString = (SHFLSTRING *)paParms[1].u.pointer.addr;
369 uint32_t cbString = paParms[1].u.pointer.size;
370
371 /* Verify parameters values. */
372 if ( (cbString < sizeof (SHFLSTRING))
373 || (cbString < pString->u16Size)
374 )
375 {
376 rc = VERR_INVALID_PARAMETER;
377 }
378 else
379 {
380 /* Execute the function. */
381 rc = vbsfMappingsQueryName (pClient, root, pString);
382
383 if (VBOX_SUCCESS(rc))
384 {
385 /* Update parameters.*/
386 ; /* none */
387 }
388 }
389 }
390
391 } break;
392
393 case SHFL_FN_CREATE:
394 {
395 Log(("svcCall: SHFL_FN_CREATE\n"));
396
397 /* Verify parameter count and types. */
398 if (cParms != SHFL_CPARMS_CREATE)
399 {
400 rc = VERR_INVALID_PARAMETER;
401 }
402 else if ( paParms[0].type != VBOX_HGCM_SVC_PARM_32BIT /* root */
403 || paParms[1].type != VBOX_HGCM_SVC_PARM_PTR /* path */
404 || paParms[2].type != VBOX_HGCM_SVC_PARM_PTR /* parms */
405 )
406 {
407 Log(("Invalid parameters types\n"));
408 rc = VERR_INVALID_PARAMETER;
409 }
410 else
411 {
412 /* Fetch parameters. */
413 SHFLROOT root = (SHFLROOT)paParms[0].u.uint32;
414 SHFLSTRING *pPath = (SHFLSTRING *)paParms[1].u.pointer.addr;
415 uint32_t cbPath = paParms[1].u.pointer.size;
416 SHFLCREATEPARMS *pParms = (SHFLCREATEPARMS *)paParms[2].u.pointer.addr;
417 uint32_t cbParms = paParms[2].u.pointer.size;
418
419 /* Verify parameters values. */
420 if ( (cbPath < sizeof (SHFLSTRING))
421 || (cbParms != sizeof (SHFLCREATEPARMS))
422 )
423 {
424 AssertMsgFailed (("Invalid parameters cbPath or cbParms (%x, %x - expected >=%x, %x)\n",
425 cbPath, cbParms, sizeof(SHFLSTRING), sizeof (SHFLCREATEPARMS)));
426 rc = VERR_INVALID_PARAMETER;
427 }
428 else
429 {
430 /* Execute the function. */
431
432 rc = vbsfCreate (pClient, root, pPath, cbPath, pParms);
433
434 if (VBOX_SUCCESS(rc))
435 {
436 /* Update parameters.*/
437 ; /* none */
438 }
439 }
440 }
441 break;
442 }
443
444 case SHFL_FN_CLOSE:
445 {
446 Log(("svcCall: SHFL_FN_CLOSE\n"));
447
448 /* Verify parameter count and types. */
449 if (cParms != SHFL_CPARMS_CLOSE)
450 {
451 rc = VERR_INVALID_PARAMETER;
452 }
453 else if ( paParms[0].type != VBOX_HGCM_SVC_PARM_32BIT /* root */
454 || paParms[1].type != VBOX_HGCM_SVC_PARM_64BIT /* handle */
455 )
456 {
457 rc = VERR_INVALID_PARAMETER;
458 }
459 else
460 {
461 /* Fetch parameters. */
462 SHFLROOT root = (SHFLROOT)paParms[0].u.uint32;
463 SHFLHANDLE Handle = paParms[1].u.uint64;
464
465 /* Verify parameters values. */
466 if (Handle == SHFL_HANDLE_ROOT)
467 {
468 rc = VERR_INVALID_PARAMETER;
469 }
470 else
471 if (Handle == SHFL_HANDLE_NIL)
472 {
473 AssertMsgFailed(("Invalid handle!!!!\n"));
474 rc = VERR_INVALID_HANDLE;
475 }
476 else
477 {
478 /* Execute the function. */
479
480 rc = vbsfClose (pClient, root, Handle);
481
482 if (VBOX_SUCCESS(rc))
483 {
484 /* Update parameters.*/
485 ; /* none */
486 }
487 }
488 }
489 break;
490
491 }
492
493 /** Read object content. */
494 case SHFL_FN_READ:
495 Log(("svcCall: SHFL_FN_READ\n"));
496
497 /* Verify parameter count and types. */
498 if (cParms != SHFL_CPARMS_READ)
499 {
500 rc = VERR_INVALID_PARAMETER;
501 }
502 else
503 if ( paParms[0].type != VBOX_HGCM_SVC_PARM_32BIT /* root */
504 || paParms[1].type != VBOX_HGCM_SVC_PARM_64BIT /* handle */
505 || paParms[2].type != VBOX_HGCM_SVC_PARM_64BIT /* offset */
506 || paParms[3].type != VBOX_HGCM_SVC_PARM_32BIT /* count */
507 || paParms[4].type != VBOX_HGCM_SVC_PARM_PTR /* buffer */
508 )
509 {
510 rc = VERR_INVALID_PARAMETER;
511 }
512 else
513 {
514 /* Fetch parameters. */
515 SHFLROOT root = (SHFLROOT)paParms[0].u.uint32;
516 SHFLHANDLE Handle = paParms[1].u.uint64;
517 uint64_t offset = paParms[2].u.uint64;
518 uint32_t count = paParms[3].u.uint32;
519 uint8_t *pBuffer = (uint8_t *)paParms[4].u.pointer.addr;
520
521 /* Verify parameters values. */
522 if (Handle == SHFL_HANDLE_ROOT)
523 {
524 rc = VERR_INVALID_PARAMETER;
525 }
526 else
527 if (Handle == SHFL_HANDLE_NIL)
528 {
529 AssertMsgFailed(("Invalid handle!!!!\n"));
530 rc = VERR_INVALID_HANDLE;
531 }
532 else
533 {
534 /* Execute the function. */
535 if (pStatusLed)
536 {
537 Assert(pStatusLed->u32Magic == PDMLED_MAGIC);
538 pStatusLed->Asserted.s.fReading = pStatusLed->Actual.s.fReading = 1;
539 }
540
541 rc = vbsfRead (pClient, root, Handle, offset, &count, pBuffer);
542 if (pStatusLed)
543 pStatusLed->Actual.s.fReading = 0;
544
545 if (VBOX_SUCCESS(rc))
546 {
547 /* Update parameters.*/
548 paParms[3].u.uint32 = count;
549 }
550 else
551 {
552 paParms[3].u.uint32 = 0; /* nothing read */
553 }
554 }
555 }
556 break;
557
558 /** Write new object content. */
559 case SHFL_FN_WRITE:
560 Log(("svcCall: SHFL_FN_WRITE\n"));
561
562 /* Verify parameter count and types. */
563 if (cParms != SHFL_CPARMS_WRITE)
564 {
565 rc = VERR_INVALID_PARAMETER;
566 }
567 else
568 if ( paParms[0].type != VBOX_HGCM_SVC_PARM_32BIT /* root */
569 || paParms[1].type != VBOX_HGCM_SVC_PARM_64BIT /* handle */
570 || paParms[2].type != VBOX_HGCM_SVC_PARM_64BIT /* offset */
571 || paParms[3].type != VBOX_HGCM_SVC_PARM_32BIT /* count */
572 || paParms[4].type != VBOX_HGCM_SVC_PARM_PTR /* buffer */
573 )
574 {
575 rc = VERR_INVALID_PARAMETER;
576 }
577 else
578 {
579 /* Fetch parameters. */
580 SHFLROOT root = (SHFLROOT)paParms[0].u.uint32;
581 SHFLHANDLE Handle = paParms[1].u.uint64;
582 uint64_t offset = paParms[2].u.uint64;
583 uint32_t count = paParms[3].u.uint32;
584 uint8_t *pBuffer = (uint8_t *)paParms[4].u.pointer.addr;
585
586 /* Verify parameters values. */
587 if (Handle == SHFL_HANDLE_ROOT)
588 {
589 rc = VERR_INVALID_PARAMETER;
590 }
591 else
592 if (Handle == SHFL_HANDLE_NIL)
593 {
594 AssertMsgFailed(("Invalid handle!!!!\n"));
595 rc = VERR_INVALID_HANDLE;
596 }
597 else
598 {
599 /* Execute the function. */
600 if (pStatusLed)
601 {
602 Assert(pStatusLed->u32Magic == PDMLED_MAGIC);
603 pStatusLed->Asserted.s.fWriting = pStatusLed->Actual.s.fWriting = 1;
604 }
605
606 rc = vbsfWrite (pClient, root, Handle, offset, &count, pBuffer);
607 if (pStatusLed)
608 pStatusLed->Actual.s.fWriting = 0;
609
610 if (VBOX_SUCCESS(rc))
611 {
612 /* Update parameters.*/
613 paParms[3].u.uint32 = count;
614 }
615 else
616 {
617 paParms[3].u.uint32 = 0; /* nothing read */
618 }
619 }
620 }
621 break;
622
623 /** Lock/unlock a range in the object. */
624 case SHFL_FN_LOCK:
625 Log(("svcCall: SHFL_FN_LOCK\n"));
626
627 /* Verify parameter count and types. */
628 if (cParms != SHFL_CPARMS_LOCK)
629 {
630 rc = VERR_INVALID_PARAMETER;
631 }
632 else
633 if ( paParms[0].type != VBOX_HGCM_SVC_PARM_32BIT /* root */
634 || paParms[1].type != VBOX_HGCM_SVC_PARM_64BIT /* handle */
635 || paParms[2].type != VBOX_HGCM_SVC_PARM_64BIT /* offset */
636 || paParms[3].type != VBOX_HGCM_SVC_PARM_64BIT /* length */
637 || paParms[4].type != VBOX_HGCM_SVC_PARM_32BIT /* flags */
638 )
639 {
640 rc = VERR_INVALID_PARAMETER;
641 }
642 else
643 {
644 /* Fetch parameters. */
645 SHFLROOT root = (SHFLROOT)paParms[0].u.uint32;
646 SHFLHANDLE Handle = paParms[1].u.uint64;
647 uint64_t offset = paParms[2].u.uint64;
648 uint64_t length = paParms[3].u.uint64;
649 uint32_t flags = paParms[4].u.uint32;
650
651 /* Verify parameters values. */
652 if (Handle == SHFL_HANDLE_ROOT)
653 {
654 rc = VERR_INVALID_PARAMETER;
655 }
656 else
657 if (Handle == SHFL_HANDLE_NIL)
658 {
659 AssertMsgFailed(("Invalid handle!!!!\n"));
660 rc = VERR_INVALID_HANDLE;
661 }
662 else
663 {
664 /* Execute the function. */
665 if ((flags & SHFL_LOCK_MODE_MASK) == SHFL_LOCK_CANCEL)
666 rc = vbsfUnlock(pClient, root, Handle, offset, length, flags);
667 else
668 rc = vbsfLock(pClient, root, Handle, offset, length, flags);
669
670 if (VBOX_SUCCESS(rc))
671 {
672 /* Update parameters.*/
673 /* none */
674 }
675 }
676 }
677 break;
678
679 /** List object content. */
680 case SHFL_FN_LIST:
681 {
682 Log(("svcCall: SHFL_FN_LIST\n"));
683
684 /* Verify parameter count and types. */
685 if (cParms != SHFL_CPARMS_LIST)
686 {
687 rc = VERR_INVALID_PARAMETER;
688 }
689 else
690 if ( paParms[0].type != VBOX_HGCM_SVC_PARM_32BIT /* root */
691 || paParms[1].type != VBOX_HGCM_SVC_PARM_64BIT /* handle */
692 || paParms[2].type != VBOX_HGCM_SVC_PARM_32BIT /* flags */
693 || paParms[3].type != VBOX_HGCM_SVC_PARM_32BIT /* cb */
694 || paParms[4].type != VBOX_HGCM_SVC_PARM_PTR /* pPath */
695 || paParms[5].type != VBOX_HGCM_SVC_PARM_PTR /* buffer */
696 || paParms[6].type != VBOX_HGCM_SVC_PARM_32BIT /* resumePoint */
697 || paParms[7].type != VBOX_HGCM_SVC_PARM_32BIT /* cFiles (out) */
698 )
699 {
700 rc = VERR_INVALID_PARAMETER;
701 }
702 else
703 {
704 /* Fetch parameters. */
705 SHFLROOT root = (SHFLROOT)paParms[0].u.uint32;
706 SHFLHANDLE Handle = paParms[1].u.uint64;
707 uint32_t flags = paParms[2].u.uint32;
708 uint32_t length = paParms[3].u.uint32;
709 SHFLSTRING *pPath = (paParms[4].u.pointer.size == 0) ? 0 : (SHFLSTRING *)paParms[4].u.pointer.addr;
710 uint8_t *pBuffer = (uint8_t *)paParms[5].u.pointer.addr;
711 uint32_t resumePoint = paParms[6].u.uint32;
712 uint32_t cFiles = 0;
713
714 /* Verify parameters values. */
715 if ( (length < sizeof (SHFLDIRINFO))
716 )
717 {
718 rc = VERR_INVALID_PARAMETER;
719 }
720 else
721 {
722 if (pStatusLed)
723 {
724 Assert(pStatusLed->u32Magic == PDMLED_MAGIC);
725 pStatusLed->Asserted.s.fReading = pStatusLed->Actual.s.fReading = 1;
726 }
727
728 /* Execute the function. */
729 rc = vbsfDirList (pClient, root, Handle, pPath, flags, &length, pBuffer, &resumePoint, &cFiles);
730
731 if (pStatusLed)
732 pStatusLed->Actual.s.fReading = 0;
733
734 if (VBOX_SUCCESS(rc))
735 {
736 /* Update parameters.*/
737 paParms[3].u.uint32 = length;
738 paParms[6].u.uint32 = resumePoint;
739 paParms[7].u.uint32 = cFiles;
740 }
741 else
742 {
743 paParms[3].u.uint32 = 0; /* nothing read */
744 paParms[6].u.uint32 = 0;
745 paParms[7].u.uint32 = cFiles;
746 }
747 }
748 }
749 break;
750 }
751
752 /* Legacy interface */
753 case SHFL_FN_MAP_FOLDER_OLD:
754 {
755 Log(("svcCall: SHFL_FN_MAP_FOLDER_OLD\n"));
756
757 /* Verify parameter count and types. */
758 if (cParms != SHFL_CPARMS_MAP_FOLDER_OLD)
759 {
760 rc = VERR_INVALID_PARAMETER;
761 }
762 else if ( paParms[0].type != VBOX_HGCM_SVC_PARM_PTR /* path */
763 || paParms[1].type != VBOX_HGCM_SVC_PARM_32BIT /* root */
764 || paParms[2].type != VBOX_HGCM_SVC_PARM_32BIT /* delimiter */
765 )
766 {
767 rc = VERR_INVALID_PARAMETER;
768 }
769 else
770 {
771 /* Fetch parameters. */
772 PSHFLSTRING pszMapName = (PSHFLSTRING)paParms[0].u.pointer.addr;
773 SHFLROOT root = (SHFLROOT)paParms[1].u.uint32;
774 RTUTF16 delimiter = (RTUTF16)paParms[2].u.uint32;
775
776 /* Execute the function. */
777 rc = vbsfMapFolder (pClient, pszMapName, delimiter, false, &root);
778
779 if (VBOX_SUCCESS(rc))
780 {
781 /* Update parameters.*/
782 paParms[1].u.uint32 = root;
783 }
784 }
785 break;
786 }
787
788 case SHFL_FN_MAP_FOLDER:
789 {
790 Log(("svcCall: SHFL_FN_MAP_FOLDER\n"));
791
792 /* Verify parameter count and types. */
793 if (cParms != SHFL_CPARMS_MAP_FOLDER)
794 {
795 rc = VERR_INVALID_PARAMETER;
796 }
797 else if ( paParms[0].type != VBOX_HGCM_SVC_PARM_PTR /* path */
798 || paParms[1].type != VBOX_HGCM_SVC_PARM_32BIT /* root */
799 || paParms[2].type != VBOX_HGCM_SVC_PARM_32BIT /* delimiter */
800 || paParms[3].type != VBOX_HGCM_SVC_PARM_32BIT /* fCaseSensitive */
801 )
802 {
803 rc = VERR_INVALID_PARAMETER;
804 }
805 else
806 {
807 /* Fetch parameters. */
808 PSHFLSTRING pszMapName = (PSHFLSTRING)paParms[0].u.pointer.addr;
809 SHFLROOT root = (SHFLROOT)paParms[1].u.uint32;
810 RTUTF16 delimiter = (RTUTF16)paParms[2].u.uint32;
811 bool fCaseSensitive = !!paParms[3].u.uint32;
812
813 /* Execute the function. */
814 rc = vbsfMapFolder (pClient, pszMapName, delimiter, fCaseSensitive, &root);
815
816 if (VBOX_SUCCESS(rc))
817 {
818 /* Update parameters.*/
819 paParms[1].u.uint32 = root;
820 }
821 }
822 break;
823 }
824
825 case SHFL_FN_UNMAP_FOLDER:
826 {
827 Log(("svcCall: SHFL_FN_UNMAP_FOLDER\n"));
828
829 /* Verify parameter count and types. */
830 if (cParms != SHFL_CPARMS_UNMAP_FOLDER)
831 {
832 rc = VERR_INVALID_PARAMETER;
833 }
834 else if ( paParms[0].type != VBOX_HGCM_SVC_PARM_32BIT /* root */
835 )
836 {
837 rc = VERR_INVALID_PARAMETER;
838 }
839 else
840 {
841 /* Fetch parameters. */
842 SHFLROOT root = (SHFLROOT)paParms[0].u.uint32;
843
844 /* Execute the function. */
845 rc = vbsfUnmapFolder (pClient, root);
846
847 if (VBOX_SUCCESS(rc))
848 {
849 /* Update parameters.*/
850 /* nothing */
851 }
852 }
853 break;
854 }
855
856 /** Query/set object information. */
857 case SHFL_FN_INFORMATION:
858 {
859 Log(("svcCall: SHFL_FN_INFORMATION\n"));
860
861 /* Verify parameter count and types. */
862 if (cParms != SHFL_CPARMS_INFORMATION)
863 {
864 rc = VERR_INVALID_PARAMETER;
865 }
866 else
867 if ( paParms[0].type != VBOX_HGCM_SVC_PARM_32BIT /* root */
868 || paParms[1].type != VBOX_HGCM_SVC_PARM_64BIT /* handle */
869 || paParms[2].type != VBOX_HGCM_SVC_PARM_32BIT /* flags */
870 || paParms[3].type != VBOX_HGCM_SVC_PARM_32BIT /* cb */
871 || paParms[4].type != VBOX_HGCM_SVC_PARM_PTR /* buffer */
872 )
873 {
874 rc = VERR_INVALID_PARAMETER;
875 }
876 else
877 {
878 /* Fetch parameters. */
879 SHFLROOT root = (SHFLROOT)paParms[0].u.uint32;
880 SHFLHANDLE Handle = paParms[1].u.uint64;
881 uint32_t flags = paParms[2].u.uint32;
882 uint32_t length = paParms[3].u.uint32;
883 uint8_t *pBuffer = (uint8_t *)paParms[4].u.pointer.addr;
884
885 /* Execute the function. */
886 if (flags & SHFL_INFO_SET)
887 rc = vbsfSetFSInfo (pClient, root, Handle, flags, &length, pBuffer);
888 else /* SHFL_INFO_GET */
889 rc = vbsfQueryFSInfo (pClient, root, Handle, flags, &length, pBuffer);
890
891 if (VBOX_SUCCESS(rc))
892 {
893 /* Update parameters.*/
894 paParms[3].u.uint32 = length;
895 }
896 else
897 {
898 paParms[3].u.uint32 = 0; /* nothing read */
899 }
900 }
901 break;
902 }
903
904 /** Remove or rename object */
905 case SHFL_FN_REMOVE:
906 {
907 Log(("svcCall: SHFL_FN_REMOVE\n"));
908
909 /* Verify parameter count and types. */
910 if (cParms != SHFL_CPARMS_REMOVE)
911 {
912 rc = VERR_INVALID_PARAMETER;
913 }
914 else if ( paParms[0].type != VBOX_HGCM_SVC_PARM_32BIT /* root */
915 || paParms[1].type != VBOX_HGCM_SVC_PARM_PTR /* path */
916 || paParms[2].type != VBOX_HGCM_SVC_PARM_32BIT /* flags */
917 )
918 {
919 rc = VERR_INVALID_PARAMETER;
920 }
921 else
922 {
923 /* Fetch parameters. */
924 SHFLROOT root = (SHFLROOT)paParms[0].u.uint32;
925 SHFLSTRING *pPath = (SHFLSTRING *)paParms[1].u.pointer.addr;
926 uint32_t cbPath = paParms[1].u.pointer.size;
927 uint32_t flags = paParms[2].u.uint32;
928
929 /* Verify parameters values. */
930 if ( (cbPath < sizeof (SHFLSTRING))
931 )
932 {
933 rc = VERR_INVALID_PARAMETER;
934 }
935 else
936 {
937 /* Execute the function. */
938
939 rc = vbsfRemove (pClient, root, pPath, cbPath, flags);
940 if (VBOX_SUCCESS(rc))
941 {
942 /* Update parameters.*/
943 ; /* none */
944 }
945 }
946 }
947 break;
948 }
949
950 case SHFL_FN_RENAME:
951 {
952 Log(("svcCall: SHFL_FN_RENAME\n"));
953
954 /* Verify parameter count and types. */
955 if (cParms != SHFL_CPARMS_RENAME)
956 {
957 rc = VERR_INVALID_PARAMETER;
958 }
959 else if ( paParms[0].type != VBOX_HGCM_SVC_PARM_32BIT /* root */
960 || paParms[1].type != VBOX_HGCM_SVC_PARM_PTR /* src */
961 || paParms[2].type != VBOX_HGCM_SVC_PARM_PTR /* dest */
962 || paParms[3].type != VBOX_HGCM_SVC_PARM_32BIT /* flags */
963 )
964 {
965 rc = VERR_INVALID_PARAMETER;
966 }
967 else
968 {
969 /* Fetch parameters. */
970 SHFLROOT root = (SHFLROOT)paParms[0].u.uint32;
971 SHFLSTRING *pSrc = (SHFLSTRING *)paParms[1].u.pointer.addr;
972 uint32_t cbSrc = paParms[1].u.pointer.size;
973 SHFLSTRING *pDest = (SHFLSTRING *)paParms[2].u.pointer.addr;
974 uint32_t cbDest = paParms[2].u.pointer.size;
975 uint32_t flags = paParms[3].u.uint32;
976
977 /* Verify parameters values. */
978 if ( (cbSrc < sizeof (SHFLSTRING))
979 || (cbDest < sizeof (SHFLSTRING))
980 )
981 {
982 rc = VERR_INVALID_PARAMETER;
983 }
984 else
985 {
986 /* Execute the function. */
987 rc = vbsfRename (pClient, root, pSrc, pDest, flags);
988 if (VBOX_SUCCESS(rc))
989 {
990 /* Update parameters.*/
991 ; /* none */
992 }
993 }
994 }
995 break;
996 }
997
998 case SHFL_FN_FLUSH:
999 {
1000 Log(("svcCall: SHFL_FN_FLUSH\n"));
1001
1002 /* Verify parameter count and types. */
1003 if (cParms != SHFL_CPARMS_FLUSH)
1004 {
1005 rc = VERR_INVALID_PARAMETER;
1006 }
1007 else
1008 if ( paParms[0].type != VBOX_HGCM_SVC_PARM_32BIT /* root */
1009 || paParms[1].type != VBOX_HGCM_SVC_PARM_64BIT /* handle */
1010 )
1011 {
1012 rc = VERR_INVALID_PARAMETER;
1013 }
1014 else
1015 {
1016 /* Fetch parameters. */
1017 SHFLROOT root = (SHFLROOT)paParms[0].u.uint32;
1018 SHFLHANDLE Handle = paParms[1].u.uint64;
1019
1020 /* Verify parameters values. */
1021 if (Handle == SHFL_HANDLE_ROOT)
1022 {
1023 rc = VERR_INVALID_PARAMETER;
1024 }
1025 else
1026 if (Handle == SHFL_HANDLE_NIL)
1027 {
1028 AssertMsgFailed(("Invalid handle!!!!\n"));
1029 rc = VERR_INVALID_HANDLE;
1030 }
1031 else
1032 {
1033 /* Execute the function. */
1034
1035 rc = vbsfFlush (pClient, root, Handle);
1036
1037 if (VBOX_SUCCESS(rc))
1038 {
1039 /* Nothing to do */
1040 }
1041 }
1042 }
1043 } break;
1044
1045 case SHFL_FN_SET_UTF8:
1046 {
1047 pClient->fu32Flags |= SHFL_CF_UTF8;
1048 rc = VINF_SUCCESS;
1049 break;
1050 }
1051
1052 default:
1053 {
1054 rc = VERR_NOT_IMPLEMENTED;
1055 break;
1056 }
1057 }
1058
1059 LogFlow(("svcCall: rc = %Vrc\n", rc));
1060
1061 if (!AsynchronousProcessing)
1062 {
1063 g_pHelpers->pfnCallComplete (callHandle, rc);
1064 }
1065}
1066
1067/*
1068 * We differentiate between a function handler for the guest and one for the host. The guest is not allowed to add or remove mappings for obvious security reasons.
1069 */
1070static DECLCALLBACK(int) svcHostCall (uint32_t u32Function, uint32_t cParms, VBOXHGCMSVCPARM paParms[])
1071{
1072 int rc = VINF_SUCCESS;
1073
1074 Log(("svcHostCall: fn = %d, cParms = %d, pparms = %d\n", u32Function, cParms, paParms));
1075
1076#ifdef DEBUG
1077 uint32_t i;
1078
1079 for (i = 0; i < cParms; i++)
1080 {
1081 /** @todo parameters other than 32 bit */
1082 Log((" pparms[%d]: type %d value %d\n", i, paParms[i].type, paParms[i].u.uint32));
1083 }
1084#endif
1085
1086 switch (u32Function)
1087 {
1088 case SHFL_FN_ADD_MAPPING:
1089 {
1090 Log(("svcCall: SHFL_FN_ADD_MAPPING\n"));
1091
1092 /* Verify parameter count and types. */
1093 if (cParms != SHFL_CPARMS_ADD_MAPPING)
1094 {
1095 rc = VERR_INVALID_PARAMETER;
1096 }
1097 else if ( paParms[0].type != VBOX_HGCM_SVC_PARM_PTR /* host folder name */
1098 || paParms[1].type != VBOX_HGCM_SVC_PARM_PTR /* guest map name */
1099 || paParms[2].type != VBOX_HGCM_SVC_PARM_32BIT /* fWritable */
1100 )
1101 {
1102 rc = VERR_INVALID_PARAMETER;
1103 }
1104 else
1105 {
1106 /* Fetch parameters. */
1107 SHFLSTRING *pFolderName = (SHFLSTRING *)paParms[0].u.pointer.addr;
1108 uint32_t cbStringFolder = paParms[0].u.pointer.size;
1109 SHFLSTRING *pMapName = (SHFLSTRING *)paParms[1].u.pointer.addr;
1110 uint32_t cbStringMap = paParms[1].u.pointer.size;
1111 uint32_t fWritable = paParms[2].u.uint32;
1112
1113 /* Verify parameters values. */
1114 if ( (cbStringFolder < sizeof (SHFLSTRING))
1115 || (cbStringFolder < pFolderName->u16Size)
1116 || (cbStringMap < sizeof (SHFLSTRING))
1117 || (cbStringMap < pMapName->u16Size)
1118 )
1119 {
1120 rc = VERR_INVALID_PARAMETER;
1121 }
1122 else
1123 {
1124 /* Execute the function. */
1125 rc = vbsfMappingsAdd (pFolderName, pMapName, fWritable);
1126
1127 if (VBOX_SUCCESS(rc))
1128 {
1129 /* Update parameters.*/
1130 ; /* none */
1131 }
1132 }
1133 }
1134 break;
1135 }
1136
1137 case SHFL_FN_REMOVE_MAPPING:
1138 {
1139 Log(("svcCall: SHFL_FN_REMOVE_MAPPING\n"));
1140
1141 /* Verify parameter count and types. */
1142 if (cParms != SHFL_CPARMS_REMOVE_MAPPING)
1143 {
1144 rc = VERR_INVALID_PARAMETER;
1145 }
1146 else if ( paParms[0].type != VBOX_HGCM_SVC_PARM_PTR /* folder name */
1147 )
1148 {
1149 rc = VERR_INVALID_PARAMETER;
1150 }
1151 else
1152 {
1153 /* Fetch parameters. */
1154 SHFLSTRING *pString = (SHFLSTRING *)paParms[0].u.pointer.addr;
1155 uint32_t cbString = paParms[0].u.pointer.size;
1156
1157 /* Verify parameters values. */
1158 if ( (cbString < sizeof (SHFLSTRING))
1159 || (cbString < pString->u16Size)
1160 )
1161 {
1162 rc = VERR_INVALID_PARAMETER;
1163 }
1164 else
1165 {
1166 /* Execute the function. */
1167 rc = vbsfMappingsRemove (pString);
1168
1169 if (VBOX_SUCCESS(rc))
1170 {
1171 /* Update parameters.*/
1172 ; /* none */
1173 }
1174 }
1175 }
1176 break;
1177 }
1178
1179 case SHFL_FN_SET_STATUS_LED:
1180 {
1181 Log(("svcCall: SHFL_FN_SET_STATUS_LED\n"));
1182
1183 /* Verify parameter count and types. */
1184 if (cParms != SHFL_CPARMS_SET_STATUS_LED)
1185 {
1186 rc = VERR_INVALID_PARAMETER;
1187 }
1188 else if ( paParms[0].type != VBOX_HGCM_SVC_PARM_PTR /* folder name */
1189 )
1190 {
1191 rc = VERR_INVALID_PARAMETER;
1192 }
1193 else
1194 {
1195 /* Fetch parameters. */
1196 PPDMLED pLed = (PPDMLED)paParms[0].u.pointer.addr;
1197 uint32_t cbLed = paParms[0].u.pointer.size;
1198
1199 /* Verify parameters values. */
1200 if ( (cbLed != sizeof (PDMLED))
1201 )
1202 {
1203 rc = VERR_INVALID_PARAMETER;
1204 }
1205 else
1206 {
1207 /* Execute the function. */
1208 pStatusLed = pLed;
1209 rc = VINF_SUCCESS;
1210 }
1211 }
1212 break;
1213 }
1214
1215 default:
1216 rc = VERR_NOT_IMPLEMENTED;
1217 break;
1218 }
1219
1220 LogFlow(("svcHostCall: rc = %Vrc\n", rc));
1221 return rc;
1222}
1223
1224extern "C" DECLCALLBACK(DECLEXPORT(int)) VBoxHGCMSvcLoad (VBOXHGCMSVCFNTABLE *ptable)
1225{
1226 int rc = VINF_SUCCESS;
1227
1228 Log(("VBoxHGCMSvcLoad: ptable = %p\n", ptable));
1229
1230 if (!ptable)
1231 {
1232 rc = VERR_INVALID_PARAMETER;
1233 }
1234 else
1235 {
1236 Log(("VBoxHGCMSvcLoad: ptable->cbSize = %d, ptable->u32Version = 0x%08X\n", ptable->cbSize, ptable->u32Version));
1237
1238 if ( ptable->cbSize != sizeof (VBOXHGCMSVCFNTABLE)
1239 || ptable->u32Version != VBOX_HGCM_SVC_VERSION)
1240 {
1241 rc = VERR_INVALID_PARAMETER;
1242 }
1243 else
1244 {
1245 g_pHelpers = ptable->pHelpers;
1246
1247 ptable->cbClient = sizeof (SHFLCLIENTDATA);
1248
1249 ptable->pfnUnload = svcUnload;
1250 ptable->pfnConnect = svcConnect;
1251 ptable->pfnDisconnect = svcDisconnect;
1252 ptable->pfnCall = svcCall;
1253 ptable->pfnHostCall = svcHostCall;
1254 ptable->pfnSaveState = svcSaveState;
1255 ptable->pfnLoadState = svcLoadState;
1256 }
1257
1258 /* Init handle table */
1259 rc = vbsfInitHandleTable();
1260 AssertRC(rc);
1261 }
1262
1263 return rc;
1264}
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