mappings.cpp revision 14ef787eecdc243a9ad70e3397ac2315d0bd2e46
/** @file
* Shared Folders: Mappings support.
*/
/*
* Copyright (C) 2006-2012 Oracle Corporation
*
* 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.
*/
#ifdef UNITTEST
# include "testcase/tstSharedFolderService.h"
#endif
#include "mappings.h"
#ifdef UNITTEST
# include "teststubs.h"
#endif
/* Shared folders order in the saved state and in the FolderMapping can differ.
* So a translation array of root handle is needed.
*/
void vbsfMappingInit(void)
{
unsigned root;
{
}
}
{
/* Mapping loaded from the saved state with the index. Which means
* the guest uses the iMapping as root handle for this folder.
* Check whether there is the same mapping in FolderMapping and
* update the aIndexFromRoot.
*
* Also update the mapping properties, which were lost: cMappings.
*/
if (root >= SHFL_MAX_MAPPINGS)
{
return VERR_INVALID_PARAMETER;
}
SHFLROOT i;
for (i = 0; i < RT_ELEMENTS(FolderMapping); i++)
{
/* Equal? */
&& memcmp(pLoadedMapping->pMapName, pMapping->pMapName, ShflStringSizeOfBuffer(pMapping->pMapName)) == 0)
{
/* Actual index is i. */
aIndexFromRoot[root] = i;
/* Update the mapping properties. */
return VINF_SUCCESS;
}
}
return VERR_INVALID_PARAMETER;
}
{
{
if ( iMapping != SHFL_ROOT_NIL
{
return &FolderMapping[iMapping];
}
}
return NULL;
}
{
unsigned root;
{
{
return root;
}
}
return SHFL_ROOT_NIL;
}
{
unsigned i;
for (i=0; i<SHFL_MAX_MAPPINGS; i++)
{
if (FolderMapping[i].fValid == true)
{
{
if (root != SHFL_ROOT_NIL)
{
if (pRoot)
{
}
return &FolderMapping[i];
}
else
{
AssertFailed();
}
}
}
}
return NULL;
}
{
unsigned root;
{
{
return;
}
}
AssertFailed();
}
{
unsigned root;
{
{
return;
}
}
AssertFailed();
}
#ifdef UNITTEST
/** Unit test the SHFL_FN_ADD_MAPPING API. Located here as a form of API
* documentation. */
{
/* If the number or types of parameters are wrong the API should fail. */
/* Add tests as required... */
}
#endif
/*
* We are always executed from one specific HGCM thread. So thread safe.
*/
{
unsigned i;
/* check for duplicates */
for (i=0; i<SHFL_MAX_MAPPINGS; i++)
{
if (FolderMapping[i].fValid == true)
{
{
return VERR_ALREADY_EXISTS;
}
}
}
for (i=0; i<SHFL_MAX_MAPPINGS; i++)
{
if (FolderMapping[i].fValid == false)
{
if (!FolderMapping[i].pMapName)
{
AssertFailed();
return VERR_NO_MEMORY;
}
FolderMapping[i].fValid = true;
FolderMapping[i].cMappings = 0;
/* Check if the host file system is case sensitive */
char *pszAsciiRoot;
if (RT_SUCCESS(rc))
{
}
break;
}
}
if (i == SHFL_MAX_MAPPINGS)
{
AssertMsgFailed(("vbsfMappingsAdd: no more room to add mapping %ls to %ls!!\n", pFolderName->String.ucs2, pMapName->String.ucs2));
return VERR_TOO_MUCH_DATA;
}
Log(("vbsfMappingsAdd: added mapping %ls to %ls\n", pFolderName->String.ucs2, pMapName->String.ucs2));
return VINF_SUCCESS;
}
#ifdef UNITTEST
/** Unit test the SHFL_FN_REMOVE_MAPPING API. Located here as a form of API
* documentation. */
{
/* If the number or types of parameters are wrong the API should fail. */
/* Add tests as required... */
}
#endif
{
unsigned i;
for (i=0; i<SHFL_MAX_MAPPINGS; i++)
{
if (FolderMapping[i].fValid == true)
{
{
if (FolderMapping[i].cMappings != 0)
{
return VERR_PERMISSION_DENIED;
}
FolderMapping[i].fValid = false;
break;
}
}
}
if (i == SHFL_MAX_MAPPINGS)
{
return VERR_FILE_NOT_FOUND;
}
return VINF_SUCCESS;
}
{
if (pFolderMapping->fMissing)
return NULL;
return pFolderMapping->pszFolderName;
}
{
AssertReturn(pFolderMapping, false);
return pFolderMapping->fGuestCaseSensitive;
}
{
AssertReturn(pFolderMapping, false);
return pFolderMapping->fHostCaseSensitive;
}
#ifdef UNITTEST
/** Unit test the SHFL_FN_QUERY_MAPPINGS API. Located here as a form of API
{
/* The API should return all mappings if we provide enough buffers. */
/* If we provide too few buffers that should be signalled correctly. */
/* The SHFL_MF_AUTOMOUNT flag means return only auto-mounted mappings. */
/* The mappings return array must have numberOfMappings entries. */
}
#endif
/**
* Note: If pMappings / *pcMappings is smaller than the actual amount of mappings
* that *could* have been returned *pcMappings contains the required buffer size
* so that the caller can retry the operation if wanted.
*/
{
int rc = VINF_SUCCESS;
LogFlow(("vbsfMappingsQuery: pClient = %p, pMappings = %p, pcMappings = %p, *pcMappings = %d\n",
for (uint32_t i = 0; i < SHFL_MAX_MAPPINGS; i++)
{
if ( pFolderMapping != NULL
&& pFolderMapping->fValid == true)
{
if (idx < *pcMappings)
{
/* Skip mappings which are not marked for auto-mounting if
* the SHFL_MF_AUTOMOUNT flag ist set. */
&& !pFolderMapping->fAutoMount)
continue;
idx++;
}
cMappings++;
}
}
/* Return actual number of mappings, regardless whether the handed in
* mapping buffer was big enough. */
*pcMappings = cMappings;
return rc;
}
#ifdef UNITTEST
/** Unit test the SHFL_FN_QUERY_MAP_NAME API. Located here as a form of API
* documentation. */
{
/* If we query an valid mapping it should be returned. */
/* If we query an invalid mapping that should be signalled. */
/* If we pass in a bad string buffer that should be detected. */
}
#endif
{
int rc = VINF_SUCCESS;
LogFlow(("vbsfMappingsQuery: pClient = %p, root = %d, *pString = %p\n",
if (pFolderMapping == NULL)
{
return VERR_INVALID_PARAMETER;
}
{
/* Not implemented. */
AssertFailed();
return VERR_INVALID_PARAMETER;
}
if (pFolderMapping->fValid == true)
{
{
Log(("vbsfMappingsQuery: passed string too short (%d < %d bytes)!\n",
}
else
{
}
}
else
return rc;
}
{
int rc = VINF_SUCCESS;
if ( pFolderMapping->fValid
&& !pFolderMapping->fMissing)
else
return rc;
}
{
int rc = VINF_SUCCESS;
if (pFolderMapping->fValid == true)
else
return rc;
}
{
int rc = VINF_SUCCESS;
if (pFolderMapping->fValid == true)
else
return rc;
}
#ifdef UNITTEST
/** Unit test the SHFL_FN_MAP_FOLDER API. Located here as a form of API
* documentation. */
{
/* If we try to map a valid name we should get the root. */
/* If we try to map a valid name we should get VERR_FILE_NOT_FOUND. */
/* If we map a folder twice we can unmap it twice.
* Currently unmapping too often is only asserted but not signalled. */
/* The delimiter should be converted in e.g. file delete operations. */
/* Test case sensitive mapping by opening a file with the wrong case. */
/* Test case insensitive mapping by opening a file with the wrong case. */
/* If the number or types of parameters are wrong the API should fail. */
}
#endif
{
{
}
else
{
}
("Invalid path delimiter: %#x\n", wcDelimiter),
if (pClient->PathDelimiter == 0)
{
}
else
{
}
{
int rc;
if (RT_FAILURE (rc))
return rc;
}
else
{
}
if (!pFolderMapping)
{
return VERR_FILE_NOT_FOUND;
}
return VINF_SUCCESS;
}
#ifdef UNITTEST
/** Unit test the SHFL_FN_UNMAP_FOLDER API. Located here as a form of API
* documentation. */
{
/* Unmapping a mapped folder should succeed.
* If the folder is not mapped this is only asserted, not signalled. */
/* Unmapping a non-existant root should fail. */
/* If the number or types of parameters are wrong the API should fail. */
}
#endif
{
int rc = VINF_SUCCESS;
if (pFolderMapping == NULL)
{
AssertFailed();
return VERR_FILE_NOT_FOUND;
}
if (pFolderMapping->cMappings > 0)
Log(("vbsfUnmapFolder\n"));
return rc;
}