VirtualBox

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

Last change on this file since 8985 was 8155, checked in by vboxsync, 17 years ago

The Big Sun Rebranding Header Change

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