service.cpp revision 3a5b35d5463a8c9193cacb5d3983f0c9238712d8
/** @file
* Shared Folders: Host service entry points.
*/
/*
* Copyright (C) 2006-2007 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
#include "shfl.h"
#include "mappings.h"
#include "shflhandle.h"
#include "vbsf.h"
#define SHFL_SSM_VERSION 2
/* Shared Folders Host Service.
*
* Shared Folders map a host file system to guest logical filesystem.
* A mapping represents 'host name'<->'guest name' translation and a root
* identifier to be used to access this mapping.
*
* Therefore, host name and guest name are strings interpreted
* only by host service and guest client respectively. Host name is
* passed to guest only for informational purpose. Guest may for example
* display the string or construct volume label out of the string.
*
* Root identifiers are unique for whole guest life,
* 32 bit value incremented for each new mapping is used.
*
* Mapping strings are taken from VM XML configuration on VM startup.
* The service DLL takes mappings during initialization. There is
* also API for changing mappings at runtime.
*
* Current mappings and root identifiers are saved when VM is saved.
*
* Guest may use any of these mappings. Full path information
* about an object on a mapping consists of the root indentifier and
* a full path of object.
*
* Guest IFS connects to the service and calls SHFL_FN_QUERY_MAP
* function which returns current mappings. For guest convenience,
* removed mappings also returned with REMOVED flag and new mappings
* are marked with NEW flag.
*
* To access host file system guest just forwards file system calls
* to the service, and specifies full paths or handles for objects.
*
*
*/
static DECLCALLBACK(int) svcUnload (void *)
{
int rc = VINF_SUCCESS;
Log(("svcUnload\n"));
return rc;
}
{
int rc = VINF_SUCCESS;
return rc;
}
{
int rc = VINF_SUCCESS;
return rc;
}
/** @note We only save as much state as required to access the shared folder again after restore.
* All I/O requests pending at the time of saving will never be completed or result in errors.
* (file handles no longer valid etc)
* This works as designed at the moment. A full state save would be difficult and not always possible
* as the contents of a shared folder might change in between save and restore.
*/
static DECLCALLBACK(int) svcSaveState(void *, uint32_t u32ClientID, void *pvClient, PSSMHANDLE pSSM)
{
/* Save client structure length & contents */
/* Save all the active mappings. */
for (int i=0;i<SHFL_MAX_MAPPINGS;i++)
{
if (FolderMapping[i].fValid)
{
}
}
return VINF_SUCCESS;
}
static DECLCALLBACK(int) svcLoadState(void *, uint32_t u32ClientID, void *pvClient, PSSMHANDLE pSSM)
{
if (version != SHFL_SSM_VERSION)
if (nrMappings != SHFL_MAX_MAPPINGS)
/* Restore the client data (flags + path delimiter at the moment) */
/* We don't actually (fully) restore the state; we simply check if the current state is as we it expect it to be. */
for (int i=0;i<SHFL_MAX_MAPPINGS;i++)
{
bool fValid;
/* restore the folder mapping counter. */
return VERR_SSM_UNEXPECTED_DATA;
if (FolderMapping[i].fValid)
{
/* Check the host path name. */
return VERR_SSM_UNEXPECTED_DATA;
return VERR_NO_MEMORY;
{
return VERR_SSM_UNEXPECTED_DATA;
}
/* Check the map name. */
return VERR_SSM_UNEXPECTED_DATA;
return VERR_NO_MEMORY;
{
return VERR_SSM_UNEXPECTED_DATA;
}
bool fCaseSensitive;
return VERR_SSM_UNEXPECTED_DATA;
}
}
return VINF_SUCCESS;
}
static DECLCALLBACK(void) svcCall (void *, VBOXHGCMCALLHANDLE callHandle, uint32_t u32ClientID, void *pvClient, uint32_t u32Function, uint32_t cParms, VBOXHGCMSVCPARM paParms[])
{
int rc = VINF_SUCCESS;
Log(("svcCall: u32ClientID = %d, fn = %d, cParms = %d, pparms = %d\n", u32ClientID, u32Function, cParms, paParms));
bool fAsynchronousProcessing = false;
#ifdef DEBUG
uint32_t i;
for (i = 0; i < cParms; i++)
{
/** @todo parameters other than 32 bit */
}
#endif
switch (u32Function)
{
case SHFL_FN_QUERY_MAPPINGS:
{
Log(("svcCall: SHFL_FN_QUERY_MAPPINGS\n"));
/* Verify parameter count and types. */
if (cParms != SHFL_CPARMS_QUERY_MAPPINGS)
{
}
)
{
}
else
{
/* Fetch parameters. */
/* Verify parameters values. */
if ( (fu32Flags & ~SHFL_MF_UTF8) != 0
)
{
}
else
{
/* Execute the function. */
if (fu32Flags & SHFL_MF_UTF8)
{
}
if (VBOX_SUCCESS(rc))
{
/* Update parameters.*/
}
}
}
} break;
case SHFL_FN_QUERY_MAP_NAME:
{
Log(("svcCall: SHFL_FN_QUERY_MAP_NAME\n"));
/* Verify parameter count and types. */
if (cParms != SHFL_CPARMS_QUERY_MAP_NAME)
{
}
)
{
}
else
{
/* Fetch parameters. */
/* Verify parameters values. */
if ( (cbString < sizeof (SHFLSTRING))
)
{
}
else
{
/* Execute the function. */
if (VBOX_SUCCESS(rc))
{
/* Update parameters.*/
; /* none */
}
}
}
} break;
case SHFL_FN_CREATE:
{
Log(("svcCall: SHFL_FN_CREATE\n"));
/* Verify parameter count and types. */
if (cParms != SHFL_CPARMS_CREATE)
{
}
)
{
Log(("Invalid parameters types\n"));
}
else
{
/* Fetch parameters. */
/* Verify parameters values. */
if ( (cbPath < sizeof (SHFLSTRING))
|| (cbParms != sizeof (SHFLCREATEPARMS))
)
{
AssertMsgFailed (("Invalid parameters cbPath or cbParms (%x, %x - expected >=%x, %x)\n",
}
else
{
/* Execute the function. */
if (VBOX_SUCCESS(rc))
{
/* Update parameters.*/
; /* none */
}
}
}
break;
}
case SHFL_FN_CLOSE:
{
Log(("svcCall: SHFL_FN_CLOSE\n"));
/* Verify parameter count and types. */
if (cParms != SHFL_CPARMS_CLOSE)
{
}
)
{
}
else
{
/* Fetch parameters. */
/* Verify parameters values. */
if (Handle == SHFL_HANDLE_ROOT)
{
}
else
if (Handle == SHFL_HANDLE_NIL)
{
AssertMsgFailed(("Invalid handle!!!!\n"));
}
else
{
/* Execute the function. */
if (VBOX_SUCCESS(rc))
{
/* Update parameters.*/
; /* none */
}
}
}
break;
}
/** Read object content. */
case SHFL_FN_READ:
Log(("svcCall: SHFL_FN_READ\n"));
/* Verify parameter count and types. */
if (cParms != SHFL_CPARMS_READ)
{
}
else
)
{
}
else
{
/* Fetch parameters. */
/* Verify parameters values. */
if (Handle == SHFL_HANDLE_ROOT)
{
}
else
if (Handle == SHFL_HANDLE_NIL)
{
AssertMsgFailed(("Invalid handle!!!!\n"));
}
else
{
/* Execute the function. */
if (pStatusLed)
{
}
if (pStatusLed)
if (VBOX_SUCCESS(rc))
{
/* Update parameters.*/
}
else
{
}
}
}
break;
/** Write new object content. */
case SHFL_FN_WRITE:
Log(("svcCall: SHFL_FN_WRITE\n"));
/* Verify parameter count and types. */
if (cParms != SHFL_CPARMS_WRITE)
{
}
else
)
{
}
else
{
/* Fetch parameters. */
/* Verify parameters values. */
if (Handle == SHFL_HANDLE_ROOT)
{
}
else
if (Handle == SHFL_HANDLE_NIL)
{
AssertMsgFailed(("Invalid handle!!!!\n"));
}
else
{
/* Execute the function. */
if (pStatusLed)
{
}
if (pStatusLed)
if (VBOX_SUCCESS(rc))
{
/* Update parameters.*/
}
else
{
}
}
}
break;
case SHFL_FN_LOCK:
Log(("svcCall: SHFL_FN_LOCK\n"));
/* Verify parameter count and types. */
if (cParms != SHFL_CPARMS_LOCK)
{
}
else
)
{
}
else
{
/* Fetch parameters. */
/* Verify parameters values. */
if (Handle == SHFL_HANDLE_ROOT)
{
}
else
if (Handle == SHFL_HANDLE_NIL)
{
AssertMsgFailed(("Invalid handle!!!!\n"));
}
else if (flags & SHFL_LOCK_WAIT)
{
/* @todo This should be properly implemented by the shared folders service.
* The service thread must never block. If an operation requires
* blocking, it must be processed by another thread and when it is
* completed, the another thread must call
*
* g_pHelpers->pfnCallComplete (callHandle, rc);
*/
/* Operation is async. */
fAsynchronousProcessing = true;
/* Here the operation must be posted to another thread. At the moment it is not implemented. */
}
else
{
/* Execute the function. */
else
if (VBOX_SUCCESS(rc))
{
/* Update parameters.*/
/* none */
}
}
}
break;
/** List object content. */
case SHFL_FN_LIST:
{
Log(("svcCall: SHFL_FN_LIST\n"));
/* Verify parameter count and types. */
if (cParms != SHFL_CPARMS_LIST)
{
}
else
)
{
}
else
{
/* Fetch parameters. */
/* Verify parameters values. */
if ( (length < sizeof (SHFLDIRINFO))
)
{
}
else
{
if (pStatusLed)
{
}
/* Execute the function. */
if (pStatusLed)
if (VBOX_SUCCESS(rc))
{
/* Update parameters.*/
}
else
{
}
}
}
break;
}
/* Legacy interface */
case SHFL_FN_MAP_FOLDER_OLD:
{
Log(("svcCall: SHFL_FN_MAP_FOLDER_OLD\n"));
/* Verify parameter count and types. */
if (cParms != SHFL_CPARMS_MAP_FOLDER_OLD)
{
}
)
{
}
else
{
/* Fetch parameters. */
/* Execute the function. */
if (VBOX_SUCCESS(rc))
{
/* Update parameters.*/
}
}
break;
}
case SHFL_FN_MAP_FOLDER:
{
Log(("svcCall: SHFL_FN_MAP_FOLDER\n"));
/* Verify parameter count and types. */
if (cParms != SHFL_CPARMS_MAP_FOLDER)
{
}
)
{
}
else
{
/* Fetch parameters. */
/* Execute the function. */
if (VBOX_SUCCESS(rc))
{
/* Update parameters.*/
}
}
break;
}
case SHFL_FN_UNMAP_FOLDER:
{
Log(("svcCall: SHFL_FN_UNMAP_FOLDER\n"));
/* Verify parameter count and types. */
if (cParms != SHFL_CPARMS_UNMAP_FOLDER)
{
}
)
{
}
else
{
/* Fetch parameters. */
/* Execute the function. */
if (VBOX_SUCCESS(rc))
{
/* Update parameters.*/
/* nothing */
}
}
break;
}
case SHFL_FN_INFORMATION:
{
Log(("svcCall: SHFL_FN_INFORMATION\n"));
/* Verify parameter count and types. */
if (cParms != SHFL_CPARMS_INFORMATION)
{
}
else
)
{
}
else
{
/* Fetch parameters. */
/* Execute the function. */
if (flags & SHFL_INFO_SET)
else /* SHFL_INFO_GET */
if (VBOX_SUCCESS(rc))
{
/* Update parameters.*/
}
else
{
}
}
break;
}
/** Remove or rename object */
case SHFL_FN_REMOVE:
{
Log(("svcCall: SHFL_FN_REMOVE\n"));
/* Verify parameter count and types. */
if (cParms != SHFL_CPARMS_REMOVE)
{
}
)
{
}
else
{
/* Fetch parameters. */
/* Verify parameters values. */
if ( (cbPath < sizeof (SHFLSTRING))
)
{
}
else
{
/* Execute the function. */
if (VBOX_SUCCESS(rc))
{
/* Update parameters.*/
; /* none */
}
}
}
break;
}
case SHFL_FN_RENAME:
{
Log(("svcCall: SHFL_FN_RENAME\n"));
/* Verify parameter count and types. */
if (cParms != SHFL_CPARMS_RENAME)
{
}
)
{
}
else
{
/* Fetch parameters. */
/* Verify parameters values. */
if ( (cbSrc < sizeof (SHFLSTRING))
|| (cbDest < sizeof (SHFLSTRING))
)
{
}
else
{
/* Execute the function. */
if (VBOX_SUCCESS(rc))
{
/* Update parameters.*/
; /* none */
}
}
}
break;
}
case SHFL_FN_FLUSH:
{
Log(("svcCall: SHFL_FN_FLUSH\n"));
/* Verify parameter count and types. */
if (cParms != SHFL_CPARMS_FLUSH)
{
}
else
)
{
}
else
{
/* Fetch parameters. */
/* Verify parameters values. */
if (Handle == SHFL_HANDLE_ROOT)
{
}
else
if (Handle == SHFL_HANDLE_NIL)
{
AssertMsgFailed(("Invalid handle!!!!\n"));
}
else
{
/* Execute the function. */
if (VBOX_SUCCESS(rc))
{
/* Nothing to do */
}
}
}
} break;
case SHFL_FN_SET_UTF8:
{
rc = VINF_SUCCESS;
break;
}
default:
{
break;
}
}
if ( !fAsynchronousProcessing
|| VBOX_FAILURE (rc))
{
/* Complete the operation if it was unsuccessful or
* it was processed synchronously.
*/
}
}
/*
* 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.
*/
static DECLCALLBACK(int) svcHostCall (void *, uint32_t u32Function, uint32_t cParms, VBOXHGCMSVCPARM paParms[])
{
int rc = VINF_SUCCESS;
#ifdef DEBUG
uint32_t i;
for (i = 0; i < cParms; i++)
{
/** @todo parameters other than 32 bit */
}
#endif
switch (u32Function)
{
case SHFL_FN_ADD_MAPPING:
{
Log(("svcCall: SHFL_FN_ADD_MAPPING\n"));
/* Verify parameter count and types. */
if (cParms != SHFL_CPARMS_ADD_MAPPING)
{
}
)
{
}
else
{
/* Fetch parameters. */
/* Verify parameters values. */
if ( (cbStringFolder < sizeof (SHFLSTRING))
|| (cbStringMap < sizeof (SHFLSTRING))
)
{
}
else
{
/* Execute the function. */
if (VBOX_SUCCESS(rc))
{
/* Update parameters.*/
; /* none */
}
}
}
break;
}
case SHFL_FN_REMOVE_MAPPING:
{
Log(("svcCall: SHFL_FN_REMOVE_MAPPING\n"));
/* Verify parameter count and types. */
if (cParms != SHFL_CPARMS_REMOVE_MAPPING)
{
}
)
{
}
else
{
/* Fetch parameters. */
/* Verify parameters values. */
if ( (cbString < sizeof (SHFLSTRING))
)
{
}
else
{
/* Execute the function. */
if (VBOX_SUCCESS(rc))
{
/* Update parameters.*/
; /* none */
}
}
}
break;
}
case SHFL_FN_SET_STATUS_LED:
{
Log(("svcCall: SHFL_FN_SET_STATUS_LED\n"));
/* Verify parameter count and types. */
if (cParms != SHFL_CPARMS_SET_STATUS_LED)
{
}
)
{
}
else
{
/* Fetch parameters. */
/* Verify parameters values. */
)
{
}
else
{
/* Execute the function. */
pStatusLed = pLed;
rc = VINF_SUCCESS;
}
}
break;
}
default:
break;
}
return rc;
}
{
int rc = VINF_SUCCESS;
{
}
else
{
Log(("VBoxHGCMSvcLoad: ptable->cbSize = %d, ptable->u32Version = 0x%08X\n", ptable->cbSize, ptable->u32Version));
{
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));
}
else
{
}
/* Init handle table */
rc = vbsfInitHandleTable();
}
return rc;
}