ApplianceImplIO.cpp revision 34290b0bc0f5900c975171dd402f3d270795da68
2N/A * available from http://www.virtualbox.org. This file is free software;
2N/A#include "ProgressImpl.h"
2N/A#include "ApplianceImpl.h"
2N/A#include "ApplianceImplPrivate.h"
2N/A#include "VirtualBoxImpl.h"
2N/Atypedef struct FILESTORAGEINTERNAL
2N/Atypedef struct TARSTORAGEINTERNAL
2N/Atypedef struct SHASTORAGEINTERNAL
# define DEBUG_PRINT_FLOW() do {} while (0)
return VERR_NOT_IMPLEMENTED;
static DECLCALLBACK(int) notImpl_Move(void *pvUser, const char *pcszSrc, const char *pcszDst, unsigned fMove)
return VERR_NOT_IMPLEMENTED;
static DECLCALLBACK(int) notImpl_GetFreeSpace(void *pvUser, const char *pcszFilename, int64_t *pcbFreeSpace)
return VERR_NOT_IMPLEMENTED;
static DECLCALLBACK(int) notImpl_GetModificationTime(void *pvUser, const char *pcszFilename, PRTTIMESPEC pModificationTime)
return VERR_NOT_IMPLEMENTED;
return VERR_NOT_IMPLEMENTED;
static DECLCALLBACK(int) notImpl_WriteSync(void *pvUser, void *pvStorage, uint64_t off, const void *pvBuf, size_t cbWrite, size_t *pcbWritten)
return VERR_NOT_IMPLEMENTED;
return VERR_NOT_IMPLEMENTED;
if (!pInt)
return VERR_NO_MEMORY;
return rc;
return rc;
static int fileMoveCallback(void * /* pvUser */, const char *pcszSrc, const char *pcszDst, unsigned fMove)
static int fileGetFreeSpaceCallback(void * /* pvUser */, const char *pcszFilename, int64_t *pcbFreeSpace)
return VERR_NOT_IMPLEMENTED;
static int fileGetModificationTimeCallback(void * /* pvUser */, const char *pcszFilename, PRTTIMESPEC pModificationTime)
return VERR_NOT_IMPLEMENTED;
int rc;
if (pInt)
return rc;
return rc;
if (!pCallbacks)
return NULL;
return pCallbacks;
typedef struct IOSRDONLYINTERNAL
typedef struct FSSRDONLYINTERFACEIO
bool fEndOfFss;
char *pszCurName;
static DECLCALLBACK(int) fssRdOnly_Open(void *pvUser, const char *pszLocation, uint32_t fOpen, PFNVDCOMPLETED pfnCompleted, void **ppInt)
case RTVFSOBJTYPE_IO_STREAM:
case RTVFSOBJTYPE_FILE:
if (!pFile)
return VERR_NO_MEMORY;
return VINF_SUCCESS;
case RTVFSOBJTYPE_DIR:
return VERR_IS_A_DIRECTORY;
return VERR_UNEXPECTED_FS_OBJ_TYPE;
return VERR_FILE_NOT_FOUND;
int rc = RTVfsFsStrmNext(pThis->hVfsFss, &pThis->pszCurName, &pThis->enmCurType, &pThis->hVfsCurObj);
return rc;
static DECLCALLBACK(int) fssRdOnly_ReadSync(void *pvUser, void *pvStorage, uint64_t off, void *pvBuf, size_t cbToRead, size_t *pcbRead)
int rc = RTVfsFileOpenNormal(pszFilename, RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN, &hVfsFile);
if (pThis)
return VINF_SUCCESS;
return rc;
return VERR_EOF;
int rc = RTVfsFsStrmNext(pFssIo->hVfsFss, &pFssIo->pszCurName, &pFssIo->enmCurType, &pFssIo->hVfsCurObj);
return rc;
return VINF_SUCCESS;
return VERR_EOF;
int rc = RTVfsFsStrmNext(pFssIo->hVfsFss, &pFssIo->pszCurName, &pFssIo->enmCurType, &pFssIo->hVfsCurObj);
return rc;
return VINF_SUCCESS;
int rc = RTVfsFsStrmNext(pFssIo->hVfsFss, &pFssIo->pszCurName, &pFssIo->enmCurType, &pFssIo->hVfsCurObj);
bool fLoop = true;
while (fLoop)
switch (u32Status)
case STATUS_WAIT:
fLoop = false;
case STATUS_WRITE:
|| fLoop == false)
char *pcBuf;
rc = vdIfIoFileWriteSync(pIfIo, pInt->pvStorage, pInt->cbCurFile, &pcBuf[cbAllWritten], cbToWrite, &cbWritten);
fLoop = false;
case STATUS_READ:
|| fLoop == false)
char *pcBuf;
rc = vdIfIoFileReadSync(pIfIo, pInt->pvStorage, pInt->cbCurFile, &pcBuf[cbAllRead], cbToRead, &cbRead);
fLoop = false;
if (cbRead == 0)
fLoop = false;
case STATUS_END:
fLoop = false;
return rc;
return rc;
return rc;
return rc;
AssertReturn((fOpen & RTFILE_O_READWRITE) != RTFILE_O_READWRITE, VERR_INVALID_PARAMETER); /* No read/write allowed */
if (!pInt)
return VERR_NO_MEMORY;
rc = RTThreadCreate(&pInt->pWorkerThread, shaCalcWorkerThread, pInt, 0, RTTHREADTYPE_MAIN_HEAVY_WORKER, RTTHREADFLAGS_WAITABLE, "SHA-Worker");
return rc;
char *pszDigest;
return rc;
static int shaGetModificationTimeCallback(void *pvUser, const char *pcszFilename, PRTTIMESPEC pModificationTime)
return rc;
return VINF_SUCCESS;
AssertMsgReturn(pInt->cbCurAll <= uOffset, ("Backward seeking is not allowed (uOffset: %7lu cbCurAll: %7lu)!", uOffset, pInt->cbCurAll), VERR_INVALID_PARAMETER);
return rc;
if ( cbAvail == 0
return VERR_EOF;
if (cbAvail == 0)
char *pcBuf;
if (pcbWritten)
return rc;
return rc;
if ( cbAvail == 0
if (cbAvail == 0)
char *pcBuf;
if (pcbRead)
return rc;
return rc;
if (!pCallbacks)
return NULL;
return pCallbacks;
if (!pCallbacks)
return NULL;
return pCallbacks;
int readFileIntoBuffer(const char *pcszFilename, void **ppvBuf, size_t *pcbSize, PVDINTERFACEIO pIfIo, void *pvUser)
void *pvStorage;
&pvStorage);
return rc;
void *pvTmpBuf = 0;
void *pvBuf = 0;
if (!pvTmpBuf)
|| cbRead == 0)
if (!pvBuf)
if (pvTmpBuf)
if (pvBuf)
return rc;
int writeBufferToFile(const char *pcszFilename, void *pvBuf, size_t cbSize, PVDINTERFACEIO pIfIo, void *pvUser)
void *pvStorage;
&pvStorage);
return rc;
rc = pIfIo->pfnWriteSync(pvUser, pvStorage, cbAllWritten, &((char*)pvBuf)[cbAllWritten], cbToWrite, &cbWritten);
return rc;
int decompressImageAndSave(const char *pcszFullFilenameIn, const char *pcszFullFilenameOut, PVDINTERFACEIO pIfIo, void *pvUser)
void *pvStorage;
&pvStorage);
return rc;
&hVfsIosDst);
uint32_t digestType = (pShaStorage->fSha256 == true) ? RTMANIFEST_ATTR_SHA256: RTMANIFEST_ATTR_SHA1;
return rc;
int copyFileAndCalcShaDigest(const char *pcszSourceFilename, const char *pcszTargetFilename, PVDINTERFACEIO pIfIo, void *pvUser)
void *pvStorage;
&pvStorage);
return rc;
&hVfsIosDst);
uint32_t digestType = (pShaStorage->fSha256 == true) ? RTMANIFEST_ATTR_SHA256: RTMANIFEST_ATTR_SHA1;
return rc;