vbsf.cpp revision 3918ed075bc7939d7397b643c46b460a4f3b67fc
/** @file
*
* Shared Folders:
* VBox Shared Folders.
*/
/*
* 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 "mappings.h"
#include "vbsf.h"
#include "shflhandle.h"
#ifdef RT_OS_DARWIN
#endif
{
/* Do not strip root. */
char *s = pszFullPath + cbFullPathRoot;
char *delimSecondLast = NULL;
for (;;)
{
cp = RTStrGetCp(s);
{
break;
}
if (cp == RTPATH_DELIMITER)
{
{
}
delimLast = s;
}
s = RTStrNextCp (s);
}
if (cp == 0)
{
if (delimLast + 1 == s)
{
if (delimSecondLast)
{
*delimSecondLast = 0;
}
else if (delimLast)
{
*delimLast = 0;
}
}
else
{
if (delimLast)
{
*delimLast = 0;
}
}
}
}
{
int rc = VERR_FILE_NOT_FOUND;
char szWildCard[4];
cbDirEntry = 4096;
if (pDirEntry == 0)
{
AssertFailed();
return VERR_NO_MEMORY;
}
/** @todo this is quite inefficient, especially for directories with many files */
*(pszStartComponent-1) = 0;
szWildCard[0] = RTPATH_DELIMITER;
szWildCard[2] = 0;
if (RT_FAILURE(rc))
goto end;
for(;;)
{
if (rc == VERR_NO_MORE_FILES)
break;
{
AssertFailed();
if (rc != VERR_NO_TRANSLATION)
break;
else
continue;
}
{
rc = VINF_SUCCESS;
break;
}
}
end:
if (RT_FAILURE(rc))
if (pDirEntry)
if (hSearch)
return rc;
}
{
int rc = VINF_SUCCESS;
char *pszFullPath = NULL;
/* Query UCS2 root prefix for the path, cbRoot is the length in bytes including trailing (RTUTF16)0. */
{
Log(("vbsfBuildFullPath: invalid root!\n"));
return VERR_INVALID_PARAMETER;
}
{
int rc;
char *utf8Root;
if (RT_SUCCESS (rc))
{
char *utf8FullPath;
if (!utf8FullPath)
{
rc = VERR_NO_MEMORY;
*ppszFullPath = NULL;
}
else
{
if (pcbFullPathRoot)
}
}
else
{
}
}
else
{
#ifdef RT_OS_DARWIN
/** @todo This belongs in rtPathToNative or in the windows shared folder file system driver...
* The question is simply whether the NFD normalization is actually applied on a (virtaul) file
* system level in darwin, or just by the user mode application libs. */
// Is 8 times length enough for decomposed in worst case...?
if (!pPath)
{
rc = VERR_NO_MEMORY;
return rc;
}
::CFStringAppendCharacters(inStr, (UniChar*)pPathParameter->String.ucs2, pPathParameter->u16Length / sizeof(pPathParameter->String.ucs2[0]));
rangeCharacters.location = 0;
#endif
/* Client sends us UCS2, so convert it to UTF8. */
Log(("Root %ls path %.*ls\n", pwszRoot, pPath->u16Length/sizeof(pPath->String.ucs2[0]), pPath->String.ucs2));
/* Allocate buffer that will be able to contain
* the root prefix and the pPath converted to UTF8.
* Expect a 2 bytes UCS2 to be converted to 8 bytes UTF8
* in worst case.
*/
if (!pszFullPath)
{
rc = VERR_NO_MEMORY;
}
else
{
if (RT_FAILURE(rc))
{
AssertFailed();
#ifdef RT_OS_DARWIN
#endif
return rc;
}
char *dst = pszFullPath;
{
cbRoot++;
}
if (pcbFullPathRoot)
{
/* Convert and copy components. */
/* Correct path delimiters */
{
while (*src)
{
*src = RTPATH_DELIMITER;
src++;
}
}
if (*src == RTPATH_DELIMITER)
src++; /* we already appended a delimiter to the first part */
if (RT_FAILURE(rc))
{
AssertFailed();
#ifdef RT_OS_DARWIN
#endif
return rc;
}
cb -= l;
dst += l;
}
/* Nul terminate the string */
*dst = 0;
}
#ifdef RT_OS_DARWIN
#endif
}
if (RT_SUCCESS (rc))
{
/* When the host file system is case sensitive and the guest expects a case insensitive fs, then problems can occur */
{
char *pszWildCardComponent = NULL;
if (fWildCard)
{
/* strip off the last path component, that contains the wildcard(s) */
while(src > pszFullPath)
{
if (*src == RTPATH_DELIMITER)
break;
src--;
}
if (*src == RTPATH_DELIMITER)
{
bool fHaveWildcards = false;
while(*temp)
{
{
fHaveWildcards = true;
break;
}
temp++;
}
if (fHaveWildcards)
{
*pszWildCardComponent = 0;
}
}
}
/** @todo don't check when creating files or directories; waste of time */
{
/* Find partial path that's valid */
while(src > pszFullPath)
{
if (*src == RTPATH_DELIMITER)
{
*src = 0;
*src = RTPATH_DELIMITER;
if (rc == VINF_SUCCESS)
{
#ifdef DEBUG
*src = 0;
*src = RTPATH_DELIMITER;
#endif
break;
}
}
src--;
}
if ( *src == RTPATH_DELIMITER
&& RT_SUCCESS(rc))
{
src++;
for(;;)
{
bool fEndOfString = true;
while(*end)
{
if (*end == RTPATH_DELIMITER)
break;
end++;
}
if (*end == RTPATH_DELIMITER)
{
fEndOfString = false;
*end = 0;
}
else
else
{
/* path component is invalid; try to correct the casing */
if (RT_FAILURE(rc))
{
if (!fEndOfString)
break;
}
}
if (fEndOfString)
break;
*end = RTPATH_DELIMITER;
}
if (RT_FAILURE(rc))
}
else
}
if (pszWildCardComponent)
/* might be a new file so don't fail here! */
rc = VINF_SUCCESS;
}
}
return rc;
}
static void vbsfFreeFullPath (char *pszFullPath)
{
}
/**
*
* @returns iprt status code
* @param fShflFlags shared folder create flags
* @retval pfOpen iprt create flags
*/
{
unsigned fOpen = 0;
int rc = VINF_SUCCESS;
{
default:
case SHFL_CF_ACCESS_NONE:
{
/** @todo treat this as read access, but theoretically this could be a no access request. */
fOpen |= RTFILE_O_READ;
Log(("FLAG: SHFL_CF_ACCESS_NONE\n"));
break;
}
case SHFL_CF_ACCESS_READ:
{
fOpen |= RTFILE_O_READ;
Log(("FLAG: SHFL_CF_ACCESS_READ\n"));
break;
}
case SHFL_CF_ACCESS_WRITE:
{
fOpen |= RTFILE_O_WRITE;
Log(("FLAG: SHFL_CF_ACCESS_WRITE\n"));
break;
}
case SHFL_CF_ACCESS_READWRITE:
{
Log(("FLAG: SHFL_CF_ACCESS_READWRITE\n"));
break;
}
}
/* Sharing mask */
{
default:
case SHFL_CF_ACCESS_DENYNONE:
Log(("FLAG: SHFL_CF_ACCESS_DENYNONE\n"));
break;
case SHFL_CF_ACCESS_DENYREAD:
Log(("FLAG: SHFL_CF_ACCESS_DENYREAD\n"));
break;
case SHFL_CF_ACCESS_DENYWRITE:
Log(("FLAG: SHFL_CF_ACCESS_DENYWRITE\n"));
break;
case SHFL_CF_ACCESS_DENYALL:
Log(("FLAG: SHFL_CF_ACCESS_DENYALL\n"));
break;
}
{
{
Log(("FLAGS: SHFL_CF_ACT_OPEN_IF_EXISTS and SHFL_CF_ACT_CREATE_IF_NEW\n"));
}
{
fOpen |= RTFILE_O_OPEN;
Log(("FLAGS: SHFL_CF_ACT_OPEN_IF_EXISTS and SHFL_CF_ACT_FAIL_IF_NEW\n"));
}
else
{
}
break;
{
fOpen |= RTFILE_O_CREATE;
Log(("FLAGS: SHFL_CF_ACT_FAIL_IF_EXISTS and SHFL_CF_ACT_CREATE_IF_NEW\n"));
}
else
{
}
break;
{
Log(("FLAGS: SHFL_CF_ACT_REPLACE_IF_EXISTS and SHFL_CF_ACT_CREATE_IF_NEW\n"));
}
{
Log(("FLAGS: SHFL_CF_ACT_REPLACE_IF_EXISTS and SHFL_CF_ACT_FAIL_IF_NEW\n"));
}
else
{
}
break;
{
Log(("FLAGS: SHFL_CF_ACT_OVERWRITE_IF_EXISTS and SHFL_CF_ACT_CREATE_IF_NEW\n"));
}
{
Log(("FLAGS: SHFL_CF_ACT_OVERWRITE_IF_EXISTS and SHFL_CF_ACT_FAIL_IF_NEW\n"));
}
else
{
}
break;
default:
Log(("FLAG: SHFL_CF_ACT_MASK_IF_EXISTS - invalid parameter\n"));
}
if (RT_SUCCESS(rc))
{
}
return rc;
}
/**
* Open a file or create and open a new one.
*
* @returns IPRT status code
* @param pszPath Path to the file or folder on the host.
* @param pParms->Info When a new file is created this specifies the initial parameters.
* When a file is created or overwritten, it also specifies the
* initial size.
* @retval pParms->Handle On success the (shared folder) handle of the file opened or
* created
* @retval pParms->Info On success the parameters of the file opened or created
*/
{
SHFLFILEHANDLE *pHandle = 0;
/* Open or create a file. */
unsigned fOpen = 0;
bool fNoError = false;
if (RT_SUCCESS(rc))
{
}
if (SHFL_HANDLE_NIL != handle)
{
}
if (0 != pHandle)
{
}
if (RT_FAILURE (rc))
{
switch (rc)
{
case VERR_FILE_NOT_FOUND:
/* This actually isn't an error, so correct the rc before return later,
because the driver (VBoxSF.sys) expects rc = VINF_SUCCESS and checks the result code. */
fNoError = true;
break;
case VERR_PATH_NOT_FOUND:
/* This actually isn't an error, so correct the rc before return later,
because the driver (VBoxSF.sys) expects rc = VINF_SUCCESS and checks the result code. */
fNoError = true;
break;
case VERR_ALREADY_EXISTS:
/** @todo Possible race left here. */
{
}
/* This actually isn't an error, so correct the rc before return later,
because the driver (VBoxSF.sys) expects rc = VINF_SUCCESS and checks the result code. */
fNoError = true;
break;
default:
}
}
if (RT_SUCCESS(rc))
{
/** @note The shared folder status code is very approximate, as the runtime
* does not really provide this information. */
created when we eliminated the race. */
{
/* For now, we do not treat a failure here as fatal. */
/* @todo Also set the size for SHFL_CF_ACT_CREATE_IF_NEW if
SHFL_CF_ACT_FAIL_IF_EXISTS is set. */
}
if ( ( SHFL_CF_ACT_FAIL_IF_EXISTS
{
}
#if 0
/* @todo */
/* Set new attributes. */
{
);
}
#endif
/* Get file information */
if (RT_SUCCESS(rc))
{
}
}
if (RT_FAILURE(rc))
{
if ( (0 != pHandle)
{
}
if (SHFL_HANDLE_NIL != handle)
{
}
}
else
{
}
/* Report the driver that all is okay, we're done here */
if (fNoError)
rc = VINF_SUCCESS;
return rc;
}
/**
* Open a folder or create and open a new one.
*
* @returns IPRT status code
* @param pszPath Path to the file or folder on the host.
* @retval pParms->Handle On success the (shared folder) handle of the folder opened or
* created
* @retval pParms->Info On success the parameters of the folder opened or created
*
* @note folders are created with fMode = 0777
*/
{
int rc = VERR_NO_MEMORY;
if (0 != pHandle)
{
rc = VINF_SUCCESS;
/** @todo Can anyone think of a sensible, race-less way to do this? Although
I suspect that the race is inherent, due to the API available... */
/* Try to create the folder first if "create if new" is specified. If this
fails, and "open if exists" is specified, then we ignore the failure and try
to open the folder anyway. */
{
/** @todo render supplied attributes.
* bird: The guest should specify this. For windows guests RTFS_DOS_DIRECTORY should suffice. */
if (RT_FAILURE (rc))
{
switch (rc)
{
case VERR_ALREADY_EXISTS:
break;
case VERR_PATH_NOT_FOUND:
break;
default:
}
}
}
if ( RT_SUCCESS(rc)
{
/* Open the directory now */
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
}
}
else
{
switch (rc)
{
case VERR_FILE_NOT_FOUND: /* Does this make sense? */
break;
case VERR_PATH_NOT_FOUND:
break;
case VERR_ACCESS_DENIED:
break;
default:
}
}
}
}
if (RT_FAILURE(rc))
{
if ( (0 != pHandle)
{
}
if (SHFL_HANDLE_NIL != handle)
{
}
}
else
{
}
return rc;
}
{
int rc = VINF_SUCCESS;
LogFlow(("vbsfCloseDir: Handle = %08X Search Handle = %08X\n",
{
}
return rc;
}
{
int rc = VINF_SUCCESS;
LogFlow(("vbsfCloseFile: Handle = %08X\n",
return rc;
}
/**
* Look up file or folder information by host path.
*
* @returns iprt status code (currently VINF_SUCCESS)
* @param pszFullPath The path of the file to be looked up
* @retval pParms->Result Status of the operation (success or error)
* @retval pParms->Info On success, information returned about the file
*/
{
int rc;
LogFlow(("SHFL_CF_LOOKUP\n"));
/* Client just wants to know if the object exists. */
switch (rc)
{
case VINF_SUCCESS:
{
break;
}
case VERR_FILE_NOT_FOUND:
{
rc = VINF_SUCCESS;
break;
}
case VERR_PATH_NOT_FOUND:
{
rc = VINF_SUCCESS;
break;
}
}
return rc;
}
/**
* Create or open a file or folder. Perform character set and case
* conversion on the file name if necessary.
*
* @returns IPRT status code, but see note below
* @param pClient Data structure describing the client accessing the shared
* folder
* @param root The index of the shared folder in the table of mappings.
* The host path of the shared folder is found using this.
* @param pPath The path of the file or folder relative to the host path
* indexed by root.
* @param cbPath Presumably the length of the path in pPath. Actually
* ignored, as pPath contains a length parameter.
* @param pParms->Info If a new file is created or an old one overwritten, set
* these attributes
* @retval pParms->Handle Shared folder handle to the newly opened file
* @retval pParms->Info Attributes of the file or folder opened
*
* @note This function returns success if a "non-exceptional" error occurred,
* such as "no such file". In this case, the caller should check the
* pParms->Result return value and whether pParms->Handle is valid.
*/
int vbsfCreate (SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLSTRING *pPath, uint32_t cbPath, SHFLCREATEPARMS *pParms)
{
int rc = VINF_SUCCESS;
LogFlow(("vbsfCreate: pClient = %p, pPath = %p, cbPath = %d, pParms = %p CreateFlags=%x\n",
/* Check the client access rights to the root. */
/** @todo */
/* Build a host full path for the given path, handle file name case issues (if the guest
* expects case-insensitive paths but the host is case-sensitive) and convert ucs2 to utf8 if
* necessary.
*/
char *pszFullPath = NULL;
uint32_t cbFullPathRoot = 0;
if (RT_SUCCESS (rc))
{
/* Reset return values in case client forgot to do so. */
{
}
else
{
/* Query path information. */
if (RT_SUCCESS(rc))
{
/* Mark it as a directory in case the caller didn't. */
/**
* @todo I left this in in order not to change the behaviour of the
* function too much. Is it really needed, and should it really be
* here?
*/
{
}
/**
* @todo This should be in the Windows Guest Additions, as no-one else
* needs it.
*/
{
}
}
rc = VINF_SUCCESS;
/* write access requested? */
{
/* is the guest allowed to write to this share? */
bool fWritable;
}
if (RT_SUCCESS(rc))
{
{
}
else
{
}
}
}
/* free the path string */
}
Log(("vbsfCreate: handle = %RX64 rc = %Rrc result=%x\n", (uint64_t)pParms->Handle, rc, pParms->Result));
return rc;
}
{
int rc = VINF_SUCCESS;
LogFlow(("vbsfClose: pClient = %p, Handle = %RX64\n",
SHFLFILEHANDLE *pHandle = (SHFLFILEHANDLE *)vbsfQueryHandle(Handle, SHFL_HF_TYPE_DIR|SHFL_HF_TYPE_FILE);
if (!pHandle)
return VERR_INVALID_HANDLE;
{
case SHFL_HF_TYPE_DIR:
{
break;
}
case SHFL_HF_TYPE_FILE:
{
break;
}
default:
AssertFailed();
break;
}
return rc;
}
int vbsfRead (SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle, uint64_t offset, uint32_t *pcbBuffer, uint8_t *pBuffer)
{
int rc;
{
AssertFailed();
return VERR_INVALID_PARAMETER;
}
if (*pcbBuffer == 0)
return VINF_SUCCESS; /* @todo correct? */
if (rc != VINF_SUCCESS)
{
return rc;
}
return rc;
}
int vbsfWrite (SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle, uint64_t offset, uint32_t *pcbBuffer, uint8_t *pBuffer)
{
int rc;
{
AssertFailed();
return VERR_INVALID_PARAMETER;
}
/* Is the guest allowed to write to this share?
* XXX Actually this check was still done in vbsfCreate() -- RTFILE_O_WRITE cannot be set if vbsfMappingsQueryWritable() failed. */
bool fWritable;
return VERR_WRITE_PROTECT;
if (*pcbBuffer == 0)
return VINF_SUCCESS; /** @todo correct? */
if (rc != VINF_SUCCESS)
{
return rc;
}
return rc;
}
{
int rc = VINF_SUCCESS;
if (pHandle == 0)
{
AssertFailed();
return VERR_INVALID_HANDLE;
}
return rc;
}
int vbsfDirList(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle, SHFLSTRING *pPath, uint32_t flags, uint32_t *pcbBuffer, uint8_t *pBuffer,
{
int rc = VINF_SUCCESS;
bool fUtf8;
{
AssertFailed();
return VERR_INVALID_PARAMETER;
}
cbDirEntry = 4096;
if (pDirEntry == 0)
{
AssertFailed();
return VERR_NO_MEMORY;
}
cbBufferOrg = *pcbBuffer;
*pcbBuffer = 0;
*pcFiles = 0;
if (pPath)
{
{
/* Build a host full path for the given path
* and convert ucs2 to utf8 if necessary.
*/
char *pszFullPath = NULL;
if (RT_SUCCESS (rc))
{
/* free the path string */
if (RT_FAILURE (rc))
goto end;
}
else
goto end;
}
}
while(cbBufferOrg)
{
/* Do we still have a valid last entry for the active search? If so, then return it here */
{
}
else
{
if (rc == VERR_NO_MORE_FILES)
{
*pIndex = 0; /* listing completed */
break;
}
{
AssertFailed();
if (rc != VERR_NO_TRANSLATION)
break;
else
continue;
}
}
if (fUtf8)
else
/* Overestimating, but that's ok */
if (cbBufferOrg < cbNeeded)
{
/* No room, so save this directory entry, or else it's lost forever */
if (*pcFiles == 0)
{
AssertFailed();
return VINF_BUFFER_OVERFLOW; /* Return directly and don't free pDirEntry */
}
return VINF_SUCCESS; /* Return directly and don't free pDirEntry */
}
pSFDEntry->cucShortName = 0;
if (fUtf8)
{
}
else
{
#ifdef RT_OS_DARWIN
/** @todo This belongs in rtPathToNative or in the windows shared folder file system driver...
* The question is simply whether the NFD normalization is actually applied on a (virtaul) file
* system level in darwin, or just by the user mode application libs. */
{
// Convert to
// Normalization Form C (composed Unicode). We need this because
// Mac OS X file system uses NFD (Normalization Form D :decomposed Unicode)
// while most other OS', server-side programs usually expect NFC.
rangeCharacters.location = 0;
}
#endif
// adjust cbNeeded (it was overestimated before)
}
*pcFiles += 1;
/* Free the saved last entry, that we've just returned */
{
}
if (flags & SHFL_LIST_RETURN_ONE)
break; /* we're done */
}
end:
if (pDirEntry)
return rc;
}
int vbsfQueryFileInfo(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle, uint32_t flags, uint32_t *pcbBuffer, uint8_t *pBuffer)
{
SHFLFILEHANDLE *pHandle = (SHFLFILEHANDLE *)vbsfQueryHandle(Handle, SHFL_HF_TYPE_DIR|SHFL_HF_TYPE_FILE);
int rc = VINF_SUCCESS;
{
AssertFailed();
return VERR_INVALID_PARAMETER;
}
/* @todo other options */
*pcbBuffer = 0;
{
}
else
{
}
if (rc == VINF_SUCCESS)
{
*pcbBuffer = sizeof(RTFSOBJINFO);
}
else
AssertFailed();
return rc;
}
static int vbsfSetFileInfo(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle, uint32_t flags, uint32_t *pcbBuffer, uint8_t *pBuffer)
{
SHFLFILEHANDLE *pHandle = (SHFLFILEHANDLE *)vbsfQueryHandle(Handle, SHFL_HF_TYPE_DIR|SHFL_HF_TYPE_FILE);
int rc = VINF_SUCCESS;
{
AssertFailed();
return VERR_INVALID_PARAMETER;
}
*pcbBuffer = 0;
/* Change only the time values that are not zero */
{
);
}
else
{
);
}
if (rc != VINF_SUCCESS)
{
/* temporary hack */
rc = VINF_SUCCESS;
}
{
/* Change file attributes if necessary */
{
if (rc != VINF_SUCCESS)
{
/* silent failure, because this tends to fail with e.g. windows guest & linux host */
rc = VINF_SUCCESS;
}
}
}
if (rc == VINF_SUCCESS)
{
rc = vbsfQueryFileInfo(pClient, root, Handle, SHFL_INFO_GET|SHFL_INFO_FILE, &bufsize, (uint8_t *)pSFDEntry);
if (rc == VINF_SUCCESS)
{
*pcbBuffer = sizeof(RTFSOBJINFO);
}
else
AssertFailed();
}
return rc;
}
static int vbsfSetEndOfFile(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle, uint32_t flags, uint32_t *pcbBuffer, uint8_t *pBuffer)
{
int rc = VINF_SUCCESS;
{
AssertFailed();
return VERR_INVALID_PARAMETER;
}
*pcbBuffer = 0;
if (flags & SHFL_INFO_SIZE)
{
if (rc != VINF_SUCCESS)
AssertFailed();
}
else
AssertFailed();
if (rc == VINF_SUCCESS)
{
/* Query the new object info and return it */
if (rc == VINF_SUCCESS)
{
*pcbBuffer = sizeof(RTFSOBJINFO);
}
else
AssertFailed();
}
return rc;
}
int vbsfQueryVolumeInfo(SHFLCLIENTDATA *pClient, SHFLROOT root, uint32_t flags, uint32_t *pcbBuffer, uint8_t *pBuffer)
{
int rc = VINF_SUCCESS;
char *pszFullPath = NULL;
{
AssertFailed();
return VERR_INVALID_PARAMETER;
}
/* @todo other options */
*pcbBuffer = 0;
if (RT_SUCCESS (rc))
{
rc = RTFsQuerySizes(pszFullPath, &pSFDEntry->ullTotalAllocationBytes, &pSFDEntry->ullAvailableAllocationBytes, &pSFDEntry->ulBytesPerAllocationUnit, &pSFDEntry->ulBytesPerSector);
if (rc != VINF_SUCCESS)
goto exit;
if (rc != VINF_SUCCESS)
goto exit;
if (rc != VINF_SUCCESS)
goto exit;
*pcbBuffer = sizeof(SHFLVOLINFO);
}
else AssertFailed();
exit:
/* free the path string */
return rc;
}
int vbsfQueryFSInfo(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle, uint32_t flags, uint32_t *pcbBuffer, uint8_t *pBuffer)
{
{
AssertFailed();
return VERR_INVALID_PARAMETER;
}
if (flags & SHFL_INFO_FILE)
if (flags & SHFL_INFO_VOLUME)
AssertFailed();
return VERR_INVALID_PARAMETER;
}
int vbsfSetFSInfo(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle, uint32_t flags, uint32_t *pcbBuffer, uint8_t *pBuffer)
{
SHFLFILEHANDLE *pHandle = (SHFLFILEHANDLE *)vbsfQueryHandle(Handle, SHFL_HF_TYPE_DIR|SHFL_HF_TYPE_FILE|SHFL_HF_TYPE_VOLUME);
{
AssertFailed();
return VERR_INVALID_PARAMETER;
}
/* is the guest allowed to write to this share? */
bool fWritable;
return VERR_WRITE_PROTECT;
if (flags & SHFL_INFO_FILE)
if (flags & SHFL_INFO_SIZE)
// if (flags & SHFL_INFO_VOLUME)
// return vbsfVolumeInfo(pClient, root, Handle, flags, pcbBuffer, pBuffer);
AssertFailed();
return VERR_INVALID_PARAMETER;
}
int vbsfLock(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle, uint64_t offset, uint64_t length, uint32_t flags)
{
int rc;
if (pHandle == 0)
{
AssertFailed();
return VERR_INVALID_HANDLE;
}
|| (flags & SHFL_LOCK_ENTIRE)
)
{
AssertFailed();
return VERR_INVALID_PARAMETER;
}
/* Lock type */
switch(flags & SHFL_LOCK_MODE_MASK)
{
case SHFL_LOCK_SHARED:
break;
case SHFL_LOCK_EXCLUSIVE:
break;
default:
AssertFailed();
return VERR_INVALID_PARAMETER;
}
/* Lock wait type */
if (flags & SHFL_LOCK_WAIT)
else
#ifdef RT_OS_WINDOWS
if (rc != VINF_SUCCESS)
Log(("RTFileLock %RTfile %RX64 %RX64 failed with %Rrc\n", pHandle->file.Handle, offset, length, rc));
#else
rc = VINF_SUCCESS;
#endif
return rc;
}
int vbsfUnlock(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle, uint64_t offset, uint64_t length, uint32_t flags)
{
int rc;
if (pHandle == 0)
{
return VERR_INVALID_HANDLE;
}
|| (flags & SHFL_LOCK_ENTIRE)
)
{
return VERR_INVALID_PARAMETER;
}
#ifdef RT_OS_WINDOWS
if (rc != VINF_SUCCESS)
Log(("RTFileUnlock %RTfile %RX64 %RTX64 failed with %Rrc\n", pHandle->file.Handle, offset, length, rc));
#else
rc = VINF_SUCCESS;
#endif
return rc;
}
int vbsfRemove(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLSTRING *pPath, uint32_t cbPath, uint32_t flags)
{
int rc = VINF_SUCCESS;
/* Validate input */
|| cbPath == 0
|| pPath == 0)
{
AssertFailed();
return VERR_INVALID_PARAMETER;
}
/* Build a host full path for the given path
* and convert ucs2 to utf8 if necessary.
*/
char *pszFullPath = NULL;
if (RT_SUCCESS (rc))
{
/* is the guest allowed to write to this share? */
bool fWritable;
if (RT_SUCCESS (rc))
{
if (flags & SHFL_REMOVE_FILE)
else
}
#ifndef DEBUG_dmik
// VERR_ACCESS_DENIED for example?
// Assert(rc == VINF_SUCCESS || rc == VERR_DIR_NOT_EMPTY);
#endif
/* free the path string */
}
return rc;
}
int vbsfRename(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLSTRING *pSrc, SHFLSTRING *pDest, uint32_t flags)
{
int rc = VINF_SUCCESS;
/* Validate input */
|| pSrc == 0
|| pDest == 0)
{
AssertFailed();
return VERR_INVALID_PARAMETER;
}
/* Build a host full path for the given path
* and convert ucs2 to utf8 if necessary.
*/
char *pszFullPathSrc = NULL;
char *pszFullPathDest = NULL;
if (rc != VINF_SUCCESS)
return rc;
if (RT_SUCCESS (rc))
{
/* is the guest allowed to write to this share? */
bool fWritable;
if (RT_SUCCESS (rc))
{
if (flags & SHFL_RENAME_FILE)
{
rc = RTFileMove(pszFullPathSrc, pszFullPathDest, (flags & SHFL_RENAME_REPLACE_IF_EXISTS) ? RTFILEMOVE_FLAGS_REPLACE : 0);
}
else
{
/* NT ignores the REPLACE flag and simply return and already exists error. */
rc = RTDirRename(pszFullPathSrc, pszFullPathDest, (flags & SHFL_RENAME_REPLACE_IF_EXISTS) ? RTPATHRENAME_FLAGS_REPLACE : 0);
}
}
#ifndef DEBUG_dmik
#endif
/* free the path string */
}
/* free the path string */
return rc;
}
/*
* Clean up our mess by freeing all handles that are still valid.
*
*/
{
for (int i=0;i<SHFLHANDLE_MAX;i++)
{
if (pHandle)
{
Log(("Open handle %08x\n", i));
}
}
return VINF_SUCCESS;
}