ApplianceImplIO.cpp revision ceec11f70ccba5b30ce0a34c66116a09155aeb6e
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync * IO helper for IAppliance COM class implementations.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync * Copyright (C) 2010-2012 Oracle Corporation
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync * available from http://www.virtualbox.org. This file is free software;
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync * you can redistribute it and/or modify it under the terms of the GNU
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync * General Public License (GPL) as published by the Free Software
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync/******************************************************************************
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync * Header Files *
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync ******************************************************************************/
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync/******************************************************************************
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync * Structures and Typedefs *
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync ******************************************************************************/
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync /** File handle. */
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync /** Completion callback. */
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync /** Tar handle. */
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync /** Completion callback. */
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync /** Completion callback. */
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync /** Storage handle for the next callback in chain. */
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync /** Current file open mode. */
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync /** Our own storage handle. */
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync /** Circular buffer used for transferring data from/to the worker thread. */
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync /** Current absolute position (regardless of the real read/written data). */
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync /** Current real position in the file. */
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync /** Handle of the worker thread. */
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync /** Status of the worker thread. */
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync /** Event for signaling a new status. */
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync /** Event for signaling a finished task of the worker thread. */
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync /** SHA1/SHA256 calculation context. */
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync /** Write mode only: Memory buffer for writing zeros. */
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync /** Write mode only: Size of the zero memory buffer. */
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync /** Read mode only: Indicate if we reached end of file. */
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync volatile bool fEOF;
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync// uint64_t calls;
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync// uint64_t waits;
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync /** Completion callback. */
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync /** Storage handle for the next callback in chain. */
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync /** Current file open mode. */
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync /** Circular buffer used for transferring data from/to the worker thread. */
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync /** Current absolute position (regardless of the real read/written data). */
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync /** Current real position in the file. */
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync /** Handle of the worker thread. */
void *pvZeroBuf;
volatile bool fEOF;
# define DEBUG_PRINT_FLOW() do {} while (0)
//static DECLCALLBACK(int) CopyCompressedDataToBuffer(void *pvUser, void *pvBuf, size_t cbBuf, size_t *pcbRead);
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;
if (!pInt)
return VERR_NO_MEMORY;
bool fFound = false;
char *pszFilename = 0;
if (fFound)
if (fFound)
return rc;
return rc;
return VERR_NOT_IMPLEMENTED;
static int tarMoveCallback(void *pvUser, const char *pcszSrc, const char *pcszDst, unsigned /* fMove */)
return VERR_NOT_IMPLEMENTED;
return VERR_NOT_IMPLEMENTED;
static int tarGetModificationTimeCallback(void *pvUser, const char *pcszFilename, PRTTIMESPEC pModificationTime)
return VERR_NOT_IMPLEMENTED;
return VERR_NOT_IMPLEMENTED;
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;
// rc = vdIfIoFileReadSync(pIfIo, pInt->pvStorage, pInt->cbCurFile, &pcBuf[cbAllRead], cbToRead, &cbRead);
// AssertReturn((fOpen & RTFILE_O_READWRITE) != RTFILE_O_READWRITE, VERR_INVALID_PARAMETER); /* No read/write allowed */
// rc = RTThreadCreate(&pInt->pWorkerThread, gziCalcWorkerThread, pInt, 0, RTTHREADTYPE_MAIN_HEAVY_WORKER,
//static int gzipMoveCallback(void *pvUser, const char *pcszSrc, const char *pcszDst, unsigned fMove)
//static int gzipGetFreeSpaceCallback(void *pvUser, const char *pcszFilename, int64_t *pcbFreeSpace)
//static int gzipGetModificationTimeCallback(void *pvUser, const char *pcszFilename, PRTTIMESPEC pModificationTime)
if (!pCallbacks)
return NULL;
return pCallbacks;
if (!pCallbacks)
return NULL;
return pCallbacks;
if (!pCallbacks)
return NULL;
return pCallbacks;
int ShaReadBuf(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 ShaWriteBuf(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;
rc = RTFileOpen(&pFile, pcszFullFilenameOut, RTFILE_O_OPEN_CREATE | RTFILE_O_WRITE | RTFILE_O_DENY_NONE);
rc = RTFileOpen(&pFile, pcszFullFilenameOut, RTFILE_O_CREATE_REPLACE | RTFILE_O_WRITE | RTFILE_O_DENY_NONE);
if (!compressedBuffer)
if (!decompressedBuffer)
if (rc < 0)
bool fFinished = true;
if (fFinished == true)
|| cbRead == 0)
&fFinished);
if (decompressedBuffer)
if (compressedBuffer)
return rc;