VirtualBox

Changeset 47340 in vbox


Ignore:
Timestamp:
Jul 23, 2013 12:27:35 PM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
87485
Message:

pr6022. OVA appliance don't fail when a certificate file exists. GZIP support has been implemented (first version).

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/mangling.h

    r47199 r47340  
    18611861# define RTZipTarCmd                                    RT_MANGLER(RTZipTarCmd)
    18621862# define RTZipTarFsStreamFromIoStream                   RT_MANGLER(RTZipTarFsStreamFromIoStream)
    1863 
     1863# define RTZipGzipDecompressBuffer                      RT_MANGLER(RTZipGzipDecompressBuffer)
    18641864/*
    18651865 * Stable variables (alphabetical order):
  • trunk/include/iprt/zip.h

    r44528 r47340  
    2929#include <iprt/cdefs.h>
    3030#include <iprt/types.h>
    31 
     31# include <zlib.h>
    3232
    3333RT_C_DECLS_BEGIN
     
    256256RTDECL(RTEXITCODE) RTZipTarCmd(unsigned cArgs, char **papszArgs);
    257257
     258RTDECL(int) RTZipGzipDecompressBuffer(z_stream streamIn,
     259                                      uint32_t *cbDecompressed,
     260                                      bool *finished);
    258261/** @} */
    259262
  • trunk/src/VBox/Main/include/ApplianceImpl.h

    r46518 r47340  
    178178    HRESULT importS3(TaskOVF *pTask);
    179179
    180     HRESULT readManifestFile(const Utf8Str &strFile, void **ppvBuf, size_t *pcbSize, PVDINTERFACEIO pCallbacks, PSHASTORAGE pStorage);
    181     HRESULT readTarManifestFile(RTTAR tar, const Utf8Str &strFile, void **ppvBuf, size_t *pcbSize, PVDINTERFACEIO pCallbacks, PSHASTORAGE pStorage);
     180    HRESULT readFileToBuf(const Utf8Str &strFile,
     181                             void **ppvBuf,
     182                             size_t *pcbSize,
     183                             bool fCreateDigest,
     184                             PVDINTERFACEIO pCallbacks,
     185                             PSHASTORAGE pStorage);
     186    HRESULT readTarFileToBuf(RTTAR tar,
     187                             const Utf8Str &strFile,
     188                             void **ppvBuf,
     189                             size_t *pcbSize,
     190                             bool fCreateDigest,
     191                             PVDINTERFACEIO pCallbacks,
     192                             PSHASTORAGE pStorage);
    182193    HRESULT verifyManifestFile(const Utf8Str &strFile, ImportStack &stack, void *pvBuf, size_t cbSize);
    183194
     
    189200
    190201    void importOneDiskImage(const ovf::DiskImage &di,
    191                             const Utf8Str &strTargetPath,
     202                            Utf8Str *strTargetPath,
    192203                            ComObjPtr<Medium> &pTargetHD,
    193204                            ImportStack &stack,
  • trunk/src/VBox/Main/include/ApplianceImplPrivate.h

    r46581 r47340  
    243243int ShaReadBuf(const char *pcszFilename, void **ppvBuf, size_t *pcbSize, PVDINTERFACEIO pIfIo, void *pvUser);
    244244int ShaWriteBuf(const char *pcszFilename, void *pvBuf, size_t cbSize, PVDINTERFACEIO pIfIo, void *pvUser);
    245 
     245int decompressImageAndSave(const char *pcszFullFilenameIn, const char *pcszFullFilenameOut, PVDINTERFACEIO pIfIo, void *pvUser);
    246246#endif // !____H_APPLIANCEIMPLPRIVATE
    247247
  • trunk/src/VBox/Main/src-server/ApplianceImplIO.cpp

    r46971 r47340  
    2424#include "ApplianceImpl.h"
    2525#include "ApplianceImplPrivate.h"
    26 
     26#include "VirtualBoxImpl.h"
     27
     28#include <iprt/zip.h>
    2729#include <iprt/tar.h>
    2830#include <iprt/sha.h>
     
    3234#include <iprt/circbuf.h>
    3335#include <VBox/vd.h>
     36#include <zlib.h>
    3437
    3538/******************************************************************************
     
    9295} SHASTORAGEINTERNAL, *PSHASTORAGEINTERNAL;
    9396
     97typedef struct GZIPSTORAGEINTERNAL
     98{
     99    /** Completion callback. */
     100    PFNVDCOMPLETED pfnCompleted;
     101    /** Storage handle for the next callback in chain. */
     102    void *pvStorage;
     103    /** Current file open mode. */
     104    uint32_t fOpenMode;
     105    /** Circular buffer used for transferring data from/to the worker thread. */
     106    PRTCIRCBUF pCircBuf;
     107    /** Current absolute position (regardless of the real read/written data). */
     108    uint64_t cbCurAll;
     109    /** Current real position in the file. */
     110    uint64_t cbCurFile;
     111    /** Handle of the worker thread. */
     112    RTTHREAD pWorkerThread;
     113    /** Status of the worker thread. */
     114    volatile uint32_t u32Status;
     115    /** Event for signaling a new status. */
     116    RTSEMEVENT newStatusEvent;
     117    /** Event for signaling a finished task of the worker thread. */
     118    RTSEMEVENT workFinishedEvent;
     119    /** Write mode only: Memory buffer for writing zeros. */
     120    void *pvZeroBuf;
     121    /** Write mode only: Size of the zero memory buffer. */
     122    size_t cbZeroBuf;
     123    /** Read mode only: Indicate if we reached end of file. */
     124    volatile bool fEOF;
     125//    uint64_t calls;
     126//    uint64_t waits;
     127} GZIPSTORAGEINTERNAL, *PGZIPSTORAGEINTERNAL;
     128
    94129/******************************************************************************
    95130 *   Defined Constants And Macros                                             *
     
    110145#endif
    111146
     147/** Buffer for the decompressed data. */
     148//static uint8_t *compressedBuffer;
     149/** The current size of the compressed data*/
     150static size_t   cbComprData;
     151/** The current offset into the compressed data */
     152static size_t   offComprData;
     153
    112154/******************************************************************************
    113155 *   Internal Functions                                                       *
    114156 ******************************************************************************/
     157//static DECLCALLBACK(int) CopyCompressedDataToBuffer(void *pvUser, void *pvBuf, size_t cbBuf, size_t *pcbRead);
    115158
    116159/******************************************************************************
     
    11741217
    11751218/******************************************************************************
     1219 *   Internal: RTGZIP interface
     1220 ******************************************************************************/
     1221
     1222//DECLCALLBACK(int) gzipCalcWorkerThread(RTTHREAD /* aThread */, void *pvUser)
     1223//{
     1224//    /* Validate input. */
     1225//    AssertPtrReturn(pvUser, VERR_INVALID_POINTER);
     1226//
     1227//    PGZIPSTORAGEINTERNAL pInt = (PGZIPSTORAGEINTERNAL)pvUser;
     1228//
     1229//    PVDINTERFACEIO pIfIo = VDIfIoGet(pInt->pShaStorage->pVDImageIfaces);
     1230//    AssertPtrReturn(pIfIo, VERR_INVALID_PARAMETER);
     1231//
     1232//    int rc = VINF_SUCCESS;
     1233//    bool fLoop = true;
     1234//    while (fLoop)
     1235//    {
     1236//        /* What should we do next? */
     1237//        uint32_t u32Status = ASMAtomicReadU32(&pInt->u32Status);
     1238////        RTPrintf("status: %d\n", u32Status);
     1239//        switch (u32Status)
     1240//        {
     1241//            case STATUS_WAIT:
     1242//            {
     1243//                /* Wait for new work. */
     1244//                rc = RTSemEventWait(pInt->newStatusEvent, 100);
     1245//                if (   RT_FAILURE(rc)
     1246//                    && rc != VERR_TIMEOUT)
     1247//                    fLoop = false;
     1248//                break;
     1249//            }
     1250//            case STATUS_READ:
     1251//            {
     1252//                ASMAtomicCmpXchgU32(&pInt->u32Status, STATUS_READING, STATUS_READ);
     1253//                size_t cbAvail = RTCircBufFree(pInt->pCircBuf);
     1254//                size_t cbMemAllWrite = 0;
     1255//                /* First loop over all the available memory in the circular
     1256//                 * memory buffer (could be turn around at the end). */
     1257//                for (;;)
     1258//                {
     1259//                    if (   cbMemAllWrite == cbAvail
     1260//                        || fLoop == false)
     1261//                        break;
     1262//                    char *pcBuf;
     1263//                    size_t cbMemToWrite = cbAvail - cbMemAllWrite;
     1264//                    size_t cbMemWrite = 0;
     1265//                    /* Try to acquire all the free space of the circular buffer. */
     1266//                    RTCircBufAcquireWriteBlock(pInt->pCircBuf, cbMemToWrite, (void**)&pcBuf, &cbMemWrite);
     1267//                    /* Second, read as long as we filled all the memory. The
     1268//                     * read method could also split the reads up into to
     1269//                     * smaller parts. */
     1270//                    size_t cbAllRead = 0;
     1271//                    for (;;)
     1272//                    {
     1273//                        if (cbAllRead == cbMemWrite)
     1274//                            break;
     1275//                        size_t cbToRead = cbMemWrite - cbAllRead;
     1276//                        size_t cbRead = 0;
     1277//                        rc = vdIfIoFileReadSync(pIfIo, pInt->pvStorage, pInt->cbCurFile, &pcBuf[cbAllRead], cbToRead, &cbRead);
     1278//                        if (RT_FAILURE(rc))
     1279//                        {
     1280//                            fLoop = false;
     1281//                            break;
     1282//                        }
     1283//                        /* This indicates end of file. Stop reading. */
     1284//                        if (cbRead == 0)
     1285//                        {
     1286//                            fLoop = false;
     1287//                            ASMAtomicWriteBool(&pInt->fEOF, true);
     1288//                            break;
     1289//                        }
     1290//                        cbAllRead += cbRead;
     1291//                        pInt->cbCurFile += cbRead;
     1292//                    }
     1293//                    /* Update the GZIP context with the next data block. */
     1294//                    if (RT_SUCCESS(rc))
     1295//                    {
     1296//                            RTSha256Update(&pInt->ctx.Sha256, pcBuf, cbAllRead);
     1297//                    }
     1298//                    /* Mark the block as full. */
     1299//                    RTCircBufReleaseWriteBlock(pInt->pCircBuf, cbAllRead);
     1300//                    cbMemAllWrite += cbAllRead;
     1301//                }
     1302//                /* Reset the thread status and signal the main thread that we
     1303//                 * are finished. Use CmpXchg, so we not overwrite other states
     1304//                 * which could be signaled in the meantime. */
     1305//                if (ASMAtomicCmpXchgU32(&pInt->u32Status, STATUS_WAIT, STATUS_READING))
     1306//                    rc = RTSemEventSignal(pInt->workFinishedEvent);
     1307//                break;
     1308//            }
     1309//            case STATUS_END:
     1310//            {
     1311//                /* End signaled */
     1312//                fLoop = false;
     1313//                break;
     1314//            }
     1315//        }
     1316//    }
     1317//    /* Cleanup any status changes to indicate we are finished. */
     1318//    ASMAtomicWriteU32(&pInt->u32Status, STATUS_END);
     1319//    rc = RTSemEventSignal(pInt->workFinishedEvent);
     1320//    return rc;
     1321//}
     1322//
     1323//DECLINLINE(int) gzipSignalManifestThread(PGZIPSTORAGEINTERNAL pInt, uint32_t uStatus)
     1324//{
     1325//    ASMAtomicWriteU32(&pInt->u32Status, uStatus);
     1326//    return RTSemEventSignal(pInt->newStatusEvent);
     1327//}
     1328//
     1329//DECLINLINE(int) gzipWaitForManifestThreadFinished(PGZIPSTORAGEINTERNAL pInt)
     1330//{
     1331////    RTPrintf("start\n");
     1332//    int rc = VINF_SUCCESS;
     1333//    for (;;)
     1334//    {
     1335////        RTPrintf(" wait\n");
     1336//        uint32_t u32Status = ASMAtomicReadU32(&pInt->u32Status);
     1337//        if (!(   u32Status == STATUS_WRITE
     1338//              || u32Status == STATUS_WRITING
     1339//              || u32Status == STATUS_READ
     1340//              || u32Status == STATUS_READING))
     1341//            break;
     1342//        rc = RTSemEventWait(pInt->workFinishedEvent, 100);
     1343//    }
     1344//    if (rc == VERR_TIMEOUT)
     1345//        rc = VINF_SUCCESS;
     1346//    return rc;
     1347//}
     1348//
     1349//DECLINLINE(int) gzipFlushCurBuf(PGZIPSTORAGEINTERNAL pInt)
     1350//{
     1351//    int rc = VINF_SUCCESS;
     1352//    if (pInt->fOpenMode & RTFILE_O_WRITE)
     1353//    {
     1354//        /* Let the write worker thread start immediately. */
     1355//        rc = gzipSignalManifestThread(pInt, STATUS_WRITE);
     1356//        if (RT_FAILURE(rc))
     1357//            return rc;
     1358//
     1359//        /* Wait until the write worker thread has finished. */
     1360//        rc = gzipWaitForManifestThreadFinished(pInt);
     1361//    }
     1362//
     1363//    return rc;
     1364//}
     1365//
     1366//static int gzipOpenCallback(void *pvUser, const char *pszLocation, uint32_t fOpen,
     1367//                              PFNVDCOMPLETED pfnCompleted, void **ppInt)
     1368//{
     1369//    /* Validate input. */
     1370//    AssertPtrReturn(pvUser, VERR_INVALID_PARAMETER);
     1371//    AssertPtrReturn(pszLocation, VERR_INVALID_POINTER);
     1372//    AssertPtrNullReturn(pfnCompleted, VERR_INVALID_PARAMETER);
     1373//    AssertPtrReturn(ppInt, VERR_INVALID_POINTER);
     1374//    AssertReturn((fOpen & RTFILE_O_READWRITE) != RTFILE_O_READWRITE, VERR_INVALID_PARAMETER); /* No read/write allowed */
     1375//
     1376//    DEBUG_PRINT_FLOW();
     1377//
     1378//    PGZIPSTORAGEINTERNAL pInt = (PGZIPSTORAGEINTERNAL)RTMemAllocZ(sizeof(GZIPSTORAGEINTERNAL));
     1379//    if (!pInt)
     1380//        return VERR_NO_MEMORY;
     1381//
     1382//    int rc = VINF_SUCCESS;
     1383//    do
     1384//    {
     1385//        pInt->pfnCompleted = pfnCompleted;
     1386//        pInt->fEOF         = false;
     1387//        pInt->fOpenMode    = fOpen;
     1388//        pInt->u32Status    = STATUS_WAIT;
     1389//
     1390//        /* Circular buffer in the read case. */
     1391//        rc = RTCircBufCreate(&pInt->pCircBuf, _1M * 2);
     1392//        if (RT_FAILURE(rc))
     1393//            break;
     1394//
     1395//        /* Create an event semaphore to indicate a state change for the worker
     1396//         * thread. */
     1397//        rc = RTSemEventCreate(&pInt->newStatusEvent);
     1398//        if (RT_FAILURE(rc))
     1399//            break;
     1400//        /* Create an event semaphore to indicate a finished calculation of the
     1401//           worker thread. */
     1402//        rc = RTSemEventCreate(&pInt->workFinishedEvent);
     1403//        if (RT_FAILURE(rc))
     1404//            break;
     1405//        /* Create the worker thread. */
     1406//        rc = RTThreadCreate(&pInt->pWorkerThread, gziCalcWorkerThread, pInt, 0, RTTHREADTYPE_MAIN_HEAVY_WORKER,
     1407//                            RTTHREADFLAGS_WAITABLE, "GZIP-Worker");
     1408//        if (RT_FAILURE(rc))
     1409//            break;
     1410//
     1411//        /* Open the file. */
     1412//        rc = vdIfIoFileOpen(pIfIo, pszLocation, fOpen, pInt->pfnCompleted,
     1413//                            &pInt->pvStorage);
     1414//        if (RT_FAILURE(rc))
     1415//            break;
     1416//
     1417//        if (fOpen & RTFILE_O_READ)
     1418//        {
     1419//            /* Immediately let the worker thread start the reading. */
     1420//            rc = gzipSignalManifestThread(pInt, STATUS_READ);
     1421//        }
     1422//    }
     1423//    while (0);
     1424//
     1425//    if (RT_FAILURE(rc))
     1426//    {
     1427//        if (pInt->pWorkerThread)
     1428//        {
     1429//            gzipSignalManifestThread(pInt, STATUS_END);
     1430//            RTThreadWait(pInt->pWorkerThread, RT_INDEFINITE_WAIT, 0);
     1431//        }
     1432//        if (pInt->workFinishedEvent)
     1433//            RTSemEventDestroy(pInt->workFinishedEvent);
     1434//        if (pInt->newStatusEvent)
     1435//            RTSemEventDestroy(pInt->newStatusEvent);
     1436//        if (pInt->pCircBuf)
     1437//            RTCircBufDestroy(pInt->pCircBuf);
     1438//        if (pInt->pvZeroBuf)
     1439//            RTMemFree(pInt->pvZeroBuf);
     1440//        RTMemFree(pInt);
     1441//    }
     1442//    else
     1443//        *ppInt = pInt;
     1444//
     1445//    return rc;
     1446//}
     1447//
     1448//static int gzipCloseCallback(void *pvUser, void *pvStorage)
     1449//{
     1450//    /* Validate input. */
     1451//    AssertPtrReturn(pvUser, VERR_INVALID_POINTER);
     1452//    AssertPtrReturn(pvStorage, VERR_INVALID_POINTER);
     1453//
     1454//    PSHASTORAGE pShaStorage = (PSHASTORAGE)pvUser;
     1455//    PVDINTERFACEIO pIfIo = VDIfIoGet(pShaStorage->pVDImageIfaces);
     1456//    AssertPtrReturn(pIfIo, VERR_INVALID_PARAMETER);
     1457//
     1458//    PSHASTORAGEINTERNAL pInt = (PSHASTORAGEINTERNAL)pvStorage;
     1459//
     1460//    DEBUG_PRINT_FLOW();
     1461//
     1462//    int rc = VINF_SUCCESS;
     1463//
     1464//    /* Make sure all pending writes are flushed */
     1465//    rc = gzipFlushCurBuf(pInt);
     1466//
     1467//    if (pInt->pWorkerThread)
     1468//    {
     1469//        /* Signal the worker thread to end himself */
     1470//        rc = gzipSignalManifestThread(pInt, STATUS_END);
     1471//        /* Worker thread stopped? */
     1472//        rc = RTThreadWait(pInt->pWorkerThread, RT_INDEFINITE_WAIT, 0);
     1473//    }
     1474//
     1475//    /* Close the file */
     1476//    rc = vdIfIoFileClose(pIfIo, pInt->pvStorage);
     1477//
     1478//    /* Cleanup */
     1479//    if (pInt->workFinishedEvent)
     1480//        RTSemEventDestroy(pInt->workFinishedEvent);
     1481//    if (pInt->newStatusEvent)
     1482//        RTSemEventDestroy(pInt->newStatusEvent);
     1483//    if (pInt->pCircBuf)
     1484//        RTCircBufDestroy(pInt->pCircBuf);
     1485//    if (pInt->pvZeroBuf)
     1486//        RTMemFree(pInt->pvZeroBuf);
     1487//    RTMemFree(pInt);
     1488//
     1489//    return rc;
     1490//}
     1491//
     1492//static int gzipDeleteCallback(void *pvUser, const char *pcszFilename)
     1493//{
     1494//    /* Validate input. */
     1495//    AssertPtrReturn(pvUser, VERR_INVALID_POINTER);
     1496//
     1497//    DEBUG_PRINT_FLOW();
     1498//
     1499//    return VERR_NOT_IMPLEMENTED;
     1500//}
     1501//
     1502//static int gzipMoveCallback(void *pvUser, const char *pcszSrc, const char *pcszDst, unsigned fMove)
     1503//{
     1504//    /* Validate input. */
     1505//    AssertPtrReturn(pvUser, VERR_INVALID_POINTER);
     1506//
     1507//    DEBUG_PRINT_FLOW();
     1508//
     1509//    return VERR_NOT_IMPLEMENTED;
     1510//}
     1511//
     1512//static int gzipGetFreeSpaceCallback(void *pvUser, const char *pcszFilename, int64_t *pcbFreeSpace)
     1513//{
     1514//    /* Validate input. */
     1515//    AssertPtrReturn(pvUser, VERR_INVALID_POINTER);
     1516//
     1517//    DEBUG_PRINT_FLOW();
     1518//
     1519//    return VERR_NOT_IMPLEMENTED;
     1520//}
     1521//
     1522//static int gzipGetModificationTimeCallback(void *pvUser, const char *pcszFilename, PRTTIMESPEC pModificationTime)
     1523//{
     1524//    /* Validate input. */
     1525//    AssertPtrReturn(pvUser, VERR_INVALID_POINTER);
     1526//
     1527//    DEBUG_PRINT_FLOW();
     1528//
     1529//    return VERR_NOT_IMPLEMENTED;
     1530//}
     1531//
     1532//
     1533//static int gzipGetSizeCallback(void *pvUser, void *pvStorage, uint64_t *pcbSize)
     1534//{
     1535//    /* Validate input. */
     1536//    AssertPtrReturn(pvUser, VERR_INVALID_POINTER);
     1537//    AssertPtrReturn(pvStorage, VERR_INVALID_POINTER);
     1538//
     1539//    PSHASTORAGE pShaStorage = (PSHASTORAGE)pvUser;
     1540//    PVDINTERFACEIO pIfIo = VDIfIoGet(pShaStorage->pVDImageIfaces);
     1541//    AssertPtrReturn(pIfIo, VERR_INVALID_PARAMETER);
     1542//
     1543//    PGZIPSTORAGEINTERNAL pInt = (PGZIPSTORAGEINTERNAL)pvStorage;
     1544//
     1545//    DEBUG_PRINT_FLOW();
     1546//
     1547//    uint64_t cbSize;
     1548//    int rc = vdIfIoFileGetSize(pIfIo, pInt->pvStorage, &cbSize);
     1549//    if (RT_FAILURE(rc))
     1550//        return rc;
     1551//
     1552//    *pcbSize = RT_MAX(pInt->cbCurAll, cbSize);
     1553//
     1554//    return VINF_SUCCESS;
     1555//}
     1556//
     1557//static int gzipSetSizeCallback(void *pvUser, void *pvStorage, uint64_t cbSize)
     1558//{
     1559//    /* Validate input. */
     1560//    AssertPtrReturn(pvUser, VERR_INVALID_POINTER);
     1561//    AssertPtrReturn(pvStorage, VERR_INVALID_POINTER);
     1562//
     1563//    PSHASTORAGE pShaStorage = (PSHASTORAGE)pvUser;
     1564//    PVDINTERFACEIO pIfIo = VDIfIoGet(pShaStorage->pVDImageIfaces);
     1565//    AssertPtrReturn(pIfIo, VERR_INVALID_PARAMETER);
     1566//
     1567//    PGZIPSTORAGEINTERNAL pInt = (PGZIPSTORAGEINTERNAL)pvStorage;
     1568//
     1569//    DEBUG_PRINT_FLOW();
     1570//
     1571//    return vdIfIoFileSetSize(pIfIo, pInt->pvStorage, cbSize);
     1572//}
     1573//
     1574//static int gzipWriteSyncCallback(void *pvUser, void *pvStorage, uint64_t uOffset,
     1575//                                 const void *pvBuf, size_t cbWrite, size_t *pcbWritten)
     1576//{
     1577//    /* Validate input. */
     1578//    AssertPtrReturn(pvUser, VERR_INVALID_POINTER);
     1579//    AssertPtrReturn(pvStorage, VERR_INVALID_POINTER);
     1580//
     1581//    PSHASTORAGE pShaStorage = (PSHASTORAGE)pvUser;
     1582//    PVDINTERFACEIO pIfIo = VDIfIoGet(pShaStorage->pVDImageIfaces);
     1583//    AssertPtrReturn(pIfIo, VERR_INVALID_PARAMETER);
     1584//
     1585//    PGZIPSTORAGEINTERNAL pInt = (PGZIPSTORAGEINTERNAL)pvStorage;
     1586//
     1587//    DEBUG_PRINT_FLOW();
     1588//
     1589//    int rc = VINF_SUCCESS;
     1590//
     1591//    return VERR_NOT_IMPLEMENTED;
     1592//}
     1593//
     1594//static int gzipReadSyncCallback(void *pvUser, void *pvStorage, uint64_t uOffset,
     1595//                               void *pvBuf, size_t cbRead, size_t *pcbRead)
     1596//{
     1597//    /* Validate input. */
     1598//    AssertPtrReturn(pvUser, VERR_INVALID_POINTER);
     1599//    AssertPtrReturn(pvStorage, VERR_INVALID_POINTER);
     1600//
     1601//    PSHASTORAGE pShaStorage = (PSHASTORAGE)pvUser;
     1602//    PVDINTERFACEIO pIfIo = VDIfIoGet(pShaStorage->pVDImageIfaces);
     1603//    AssertPtrReturn(pIfIo, VERR_INVALID_PARAMETER);
     1604//
     1605//    DEBUG_PRINT_FLOW();
     1606//
     1607//    PGZIPSTORAGEINTERNAL pInt = (PGZIPSTORAGEINTERNAL)pvStorage;
     1608//
     1609//    int rc = VINF_SUCCESS;
     1610//
     1611//    return rc;
     1612//}
     1613//
     1614//static int gzipFlushSyncCallback(void *pvUser, void *pvStorage)
     1615//{
     1616//    /* Validate input. */
     1617//    AssertPtrReturn(pvUser, VERR_INVALID_POINTER);
     1618//    AssertPtrReturn(pvStorage, VERR_INVALID_POINTER);
     1619//
     1620//    PSHASTORAGE pShaStorage = (PSHASTORAGE)pvUser;
     1621//    PVDINTERFACEIO pIfIo = VDIfIoGet(pShaStorage->pVDImageIfaces);
     1622//    AssertPtrReturn(pIfIo, VERR_INVALID_PARAMETER);
     1623//
     1624//    DEBUG_PRINT_FLOW();
     1625//
     1626//    PGZIPSTORAGEINTERNAL pInt = (PGZIPSTORAGEINTERNAL)pvStorage;
     1627//
     1628//    /* Check if there is still something in the buffer. If yes, flush it. */
     1629//    int rc = gzipFlushCurBuf(pInt);
     1630//    if (RT_FAILURE(rc))
     1631//        return rc;
     1632//
     1633//    return vdIfIoFileFlushSync(pIfIo, pInt->pvStorage);
     1634//}
     1635
     1636/******************************************************************************
    11761637 *   Public Functions                                                         *
    11771638 ******************************************************************************/
     1639//PVDINTERFACEIO GzipCreateInterface()
     1640//{
     1641//    PVDINTERFACEIO pCallbacks = (PVDINTERFACEIO)RTMemAllocZ(sizeof(VDINTERFACEIO));
     1642//    if (!pCallbacks)
     1643//        return NULL;
     1644//
     1645//    pCallbacks->pfnOpen                = gzipOpenCallback;
     1646//    pCallbacks->pfnClose               = gzipCloseCallback;
     1647//    pCallbacks->pfnDelete              = gzipDeleteCallback;
     1648//    pCallbacks->pfnMove                = gzipMoveCallback;
     1649//    pCallbacks->pfnGetFreeSpace        = gzipGetFreeSpaceCallback;
     1650//    pCallbacks->pfnGetModificationTime = gzipGetModificationTimeCallback;
     1651//    pCallbacks->pfnGetSize             = gzipGetSizeCallback;
     1652//    pCallbacks->pfnSetSize             = gzipSetSizeCallback;
     1653//    pCallbacks->pfnReadSync            = gzipReadSyncCallback;
     1654//    pCallbacks->pfnWriteSync           = gzipWriteSyncCallback;
     1655//    pCallbacks->pfnFlushSync           = gzipFlushSyncCallback;
     1656//
     1657//    return pCallbacks;
     1658//}
    11781659
    11791660PVDINTERFACEIO ShaCreateInterface()
     
    13391820}
    13401821
     1822int decompressImageAndSave(const char *pcszFullFilenameIn, const char *pcszFullFilenameOut, PVDINTERFACEIO pIfIo, void *pvUser)
     1823{
     1824    /* Validate input. */
     1825    AssertPtrReturn(pIfIo, VERR_INVALID_POINTER);
     1826
     1827    void *pvStorage;
     1828    int rc = pIfIo->pfnOpen(pvUser, pcszFullFilenameIn,
     1829                            RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_NONE, 0,
     1830                            &pvStorage);
     1831    if (RT_FAILURE(rc))
     1832        return rc;
     1833
     1834    Bytef *decompressedBuffer = 0;
     1835    Bytef *compressedBuffer = 0;
     1836    uint64_t cbTmpSize = _1M;
     1837    size_t cbAllRead = 0;
     1838    size_t cbAllWritten = 0;
     1839    RTFILE pFile = NULL;
     1840    z_stream gzipStream;
     1841
     1842    Utf8Str pathOut(pcszFullFilenameOut);
     1843    pathOut = pathOut.stripFilename();
     1844
     1845    Utf8Str fileIn(pcszFullFilenameIn);
     1846    fileIn = fileIn.stripPath();
     1847
     1848    do
     1849    {
     1850        if (RTFileExists(pcszFullFilenameOut) == false)
     1851        {
     1852            /* ensure the directory exists */
     1853            rc = VirtualBox::ensureFilePathExists(Utf8Str(pcszFullFilenameOut), true);
     1854            if (FAILED(rc))
     1855            {
     1856                rc = VBOX_E_FILE_ERROR;
     1857                break;
     1858            }
     1859
     1860            rc = RTFileOpen(&pFile, pcszFullFilenameOut, RTFILE_O_OPEN_CREATE | RTFILE_O_WRITE | RTFILE_O_DENY_NONE);
     1861        }
     1862        else
     1863        {
     1864            rc = RTFileOpen(&pFile, pcszFullFilenameOut, RTFILE_O_CREATE_REPLACE | RTFILE_O_WRITE | RTFILE_O_DENY_NONE);
     1865        }
     1866
     1867        if (FAILED(rc) || pFile == NULL)
     1868        {
     1869            rc = VBOX_E_FILE_ERROR;
     1870            break;
     1871        }
     1872
     1873        compressedBuffer = (Bytef *)RTMemAlloc(cbTmpSize);
     1874
     1875        if (!compressedBuffer)
     1876        {
     1877            rc = VERR_NO_MEMORY;
     1878            break;
     1879        }
     1880
     1881
     1882        decompressedBuffer = (Bytef *)RTMemAlloc(cbTmpSize*10);
     1883
     1884        if (!decompressedBuffer)
     1885        {
     1886            rc = VERR_NO_MEMORY;
     1887            break;
     1888        }
     1889
     1890        gzipStream.zalloc = Z_NULL;
     1891        gzipStream.zfree = Z_NULL;
     1892        gzipStream.opaque = Z_NULL;
     1893        gzipStream.next_in = compressedBuffer;
     1894        gzipStream.avail_in = 0;
     1895        gzipStream.next_out = decompressedBuffer;
     1896        gzipStream.avail_out = cbTmpSize*10;
     1897
     1898        rc = inflateInit2(&gzipStream, MAX_WBITS + 16 /* autodetect gzip header */);
     1899
     1900        if (rc < 0)
     1901        {
     1902            break;
     1903        }
     1904
     1905        size_t cbRead = 0;
     1906        size_t cbDecompressed = 0;
     1907        bool fFinished = true;
     1908
     1909        for (;;)
     1910        {
     1911            if (fFinished == true)
     1912            {
     1913                rc = pIfIo->pfnReadSync(pvUser, pvStorage, cbAllRead, compressedBuffer, cbTmpSize, &cbRead);
     1914                if (   RT_FAILURE(rc)
     1915                    || cbRead == 0)
     1916                    break;
     1917
     1918                gzipStream.avail_in = cbRead;
     1919                gzipStream.avail_out = cbTmpSize*10;
     1920            }
     1921
     1922            /* decompress the buffer */
     1923            rc = RTZipGzipDecompressBuffer(gzipStream,
     1924                                           (uint32_t *)(&cbDecompressed),
     1925                                           &fFinished);
     1926
     1927            if (RT_FAILURE(rc))
     1928                break;
     1929
     1930            rc = RTFileWrite(pFile, decompressedBuffer, cbDecompressed, &cbDecompressed);
     1931
     1932            if (RT_FAILURE(rc))
     1933                break;
     1934
     1935            cbAllWritten += cbDecompressed;
     1936            cbAllRead += cbRead;
     1937        }
     1938    } while (0);
     1939
     1940    pIfIo->pfnClose(pvUser, pvStorage);
     1941
     1942    if (rc == VERR_EOF)
     1943        rc = VINF_SUCCESS;
     1944
     1945    rc = inflateEnd(&gzipStream);
     1946
     1947    rc = RTFileClose(pFile);
     1948
     1949    if (decompressedBuffer)
     1950        RTMemFree(decompressedBuffer);
     1951    if (compressedBuffer)
     1952        RTMemFree(compressedBuffer);
     1953
     1954    return rc;
     1955}
     1956
     1957
  • trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp

    r46980 r47340  
    119119{
    120120    // @todo:
    121     //  - don't use COM methods but the methods directly (faster, but needs appropriate locking of that objects itself (s. HardDisk))
     121    //  - don't use COM methods but the methods directly (faster, but needs appropriate
     122    // locking of that objects itself (s. HardDisk))
    122123    //  - Appropriate handle errors like not supported file formats
    123124    AutoCaller autoCaller(this);
     
    280281            if (cpuCountVBox > SchemaDefs::MaxCPUCount)
    281282            {
    282                 addWarning(tr("The virtual system \"%s\" claims support for %u CPU's, but VirtualBox has support for max %u CPU's only."),
     283                addWarning(tr("The virtual system \"%s\" claims support for %u CPU's, but VirtualBox has support for "
     284                              "max %u CPU's only."),
    283285                           vsysThis.strName.c_str(), cpuCountVBox, SchemaDefs::MaxCPUCount);
    284286                cpuCountVBox = SchemaDefs::MaxCPUCount;
     
    306308               )
    307309            {
    308                 addWarning(tr("The virtual system \"%s\" claims support for %llu MB RAM size, but VirtualBox has support for min %u & max %u MB RAM size only."),
     310                addWarning(tr("The virtual system \"%s\" claims support for %llu MB RAM size, but VirtualBox has "
     311                              "support for min %u & max %u MB RAM size only."),
    309312                              vsysThis.strName.c_str(), ullMemSizeVBox, MM_RAM_MIN_IN_MB, MM_RAM_MAX_IN_MB);
    310313                ullMemSizeVBox = RT_MIN(RT_MAX(ullMemSizeVBox, MM_RAM_MIN_IN_MB), MM_RAM_MAX_IN_MB);
     
    330333            if (   vsysThis.pelmVboxMachine
    331334                && pNewDesc->m->pConfig->hardwareMachine.audioAdapter.fEnabled)
    332                 strSoundCard = Utf8StrFmt("%RU32", (uint32_t)pNewDesc->m->pConfig->hardwareMachine.audioAdapter.controllerType);
     335            {
     336                strSoundCard = Utf8StrFmt("%RU32",
     337                                          (uint32_t)pNewDesc->m->pConfig->hardwareMachine.audioAdapter.controllerType);
     338            }
    333339            else if (vsysThis.strSoundCardType.isNotEmpty())
    334340            {
     
    362368                /* Check for the constrains */
    363369                if (llNetworkAdapters.size() > maxNetworkAdapters)
    364                     addWarning(tr("The virtual system \"%s\" claims support for %zu network adapters, but VirtualBox has support for max %u network adapter only."),
     370                    addWarning(tr("The virtual system \"%s\" claims support for %zu network adapters, but VirtualBox "
     371                                  "has support for max %u network adapter only."),
    365372                                  vsysThis.strName.c_str(), llNetworkAdapters.size(), maxNetworkAdapters);
    366373                /* Iterate through all network adapters. */
     
    390397                /* Check for the constrains */
    391398                if (cEthernetAdapters > maxNetworkAdapters)
    392                     addWarning(tr("The virtual system \"%s\" claims support for %zu network adapters, but VirtualBox has support for max %u network adapter only."),
     399                    addWarning(tr("The virtual system \"%s\" claims support for %zu network adapters, but VirtualBox "
     400                                  "has support for max %u network adapter only."),
    393401                                  vsysThis.strName.c_str(), cEthernetAdapters, maxNetworkAdapters);
    394402
     
    534542                            /* Warn only once */
    535543                            if (cIDEused == 2)
    536                                 addWarning(tr("The virtual \"%s\" system requests support for more than two IDE controller channels, but VirtualBox supports only two."),
     544                                addWarning(tr("The virtual \"%s\" system requests support for more than two "
     545                                              "IDE controller channels, but VirtualBox supports only two."),
    537546                                            vsysThis.strName.c_str());
    538547
     
    555564                            /* Warn only once */
    556565                            if (cSATAused == 1)
    557                                 addWarning(tr("The virtual system \"%s\" requests support for more than one SATA controller, but VirtualBox has support for only one"),
     566                                addWarning(tr("The virtual system \"%s\" requests support for more than one "
     567                                              "SATA controller, but VirtualBox has support for only one"),
    558568                                            vsysThis.strName.c_str());
    559569
     
    582592                        }
    583593                        else
    584                             addWarning(tr("The virtual system \"%s\" requests support for an additional SCSI controller of type \"%s\" with ID %s, but VirtualBox presently supports only one SCSI controller."),
     594                            addWarning(tr("The virtual system \"%s\" requests support for an additional "
     595                                          "SCSI controller of type \"%s\" with ID %s, but VirtualBox presently "
     596                                          "supports only one SCSI controller."),
    585597                                        vsysThis.strName.c_str(),
    586598                                        hdc.strControllerType.c_str(),
     
    12761288
    12771289        /* Next we have to download the OVF */
    1278         vrc = RTS3Create(&hS3, pTask->locInfo.strUsername.c_str(), pTask->locInfo.strPassword.c_str(), pTask->locInfo.strHostname.c_str(), "virtualbox-agent/"VBOX_VERSION_STRING);
     1290        vrc = RTS3Create(&hS3,
     1291                         pTask->locInfo.strUsername.c_str(),
     1292                         pTask->locInfo.strPassword.c_str(),
     1293                         pTask->locInfo.strHostname.c_str(),
     1294                         "virtualbox-agent/"VBOX_VERSION_STRING);
    12791295        if (RT_FAILURE(vrc))
    12801296            throw setError(VBOX_E_IPRT_ERROR,
     
    12911307            else if (vrc == VERR_S3_ACCESS_DENIED)
    12921308                throw setError(E_ACCESSDENIED,
    1293                                tr("Cannot download file '%s' from S3 storage server (Access denied). Make sure that your credentials are right."
     1309                               tr("Cannot download file '%s' from S3 storage server (Access denied). Make sure that "
     1310                                  "your credentials are right. "
    12941311                                  "Also check that your host clock is properly synced"),
    12951312                               pszFilename);
     
    14961513    PVDINTERFACEIO pFileIo = NULL;
    14971514    void *pvMfBuf = NULL;
     1515    void *pvCertBuf = NULL;
    14981516    writeLock.release();
    14991517    try
     
    15051523
    15061524        Utf8Str strMfFile = Utf8Str(pTask->locInfo.strPath).stripExt().append(".mf");
     1525
    15071526        SHASTORAGE storage;
    15081527        RT_ZERO(storage);
     
    15341553            /* Add the ovf file to the digest list. */
    15351554            stack.llSrcDisksDigest.push_front(STRPAIR(pTask->locInfo.strPath, m->strOVFSHADigest));
    1536             rc = readManifestFile(strMfFile, &pvMfBuf, &cbMfSize, pShaIo, &storage);
     1555            rc = readFileToBuf(strMfFile, &pvMfBuf, &cbMfSize, true, pShaIo, &storage);
    15371556            if (FAILED(rc)) throw rc;
    15381557            rc = verifyManifestFile(strMfFile, stack, pvMfBuf, cbMfSize);
    15391558            if (FAILED(rc)) throw rc;
     1559
     1560            size_t cbCertSize = 0;
     1561            Utf8Str manifestShaDigest;
     1562            Utf8Str strCertFile = Utf8Str(pTask->locInfo.strPath).stripExt().append(".cert");
     1563            if (RTFileExists(strCertFile.c_str()))
     1564            {
     1565                rc = readFileToBuf(strCertFile, &pvCertBuf, &cbCertSize, false, pShaIo, &storage);
     1566                if (FAILED(rc)) throw rc;
     1567
     1568                /* Save the SHA digest of the manifest file for the next validation */
     1569                manifestShaDigest = storage.strDigest;
     1570
     1571                /* verify Certificate */
     1572            }
    15401573        }
    15411574        else
     
    15541587    if (pvMfBuf)
    15551588        RTMemFree(pvMfBuf);
     1589    if (pvCertBuf)
     1590        RTMemFree(pvCertBuf);
    15561591    if (pShaIo)
    15571592        RTMemFree(pShaIo);
     
    15701605
    15711606    RTTAR tar;
    1572     int vrc = RTTarOpen(&tar, pTask->locInfo.strPath.c_str(), RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_NONE, true);
     1607    int vrc = RTTarOpen(&tar,
     1608                        pTask->locInfo.strPath.c_str(),
     1609                        RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_NONE, true);
    15731610    if (RT_FAILURE(vrc))
    15741611        return setError(VBOX_E_FILE_ERROR,
     
    15821619    char *pszFilename = 0;
    15831620    void *pvMfBuf = 0;
     1621    void *pvCertBuf = 0;
     1622
    15841623    writeLock.release();
    15851624    try
     
    16291668        else
    16301669        {
     1670            RTTarCurrentFile(tar, &pszFilename);
    16311671            if (vrc == VINF_TAR_DIR_PATH)
    16321672            {
    1633                 RTTarCurrentFile(tar, &pszFilename);
    16341673                throw setError(VBOX_E_FILE_ERROR,
    16351674                       tr("Empty directory folder (%s) isn't allowed in the OVA package (%Rrc)"),
     
    16621701         * If it fails here, we will try it again after all disks where read.
    16631702         */
    1664         rc = readTarManifestFile(tar, strMfFile, &pvMfBuf, &cbMfSize, pCallbacks, pStorage);
     1703        rc = readTarFileToBuf(tar, strMfFile, &pvMfBuf, &cbMfSize, true, pCallbacks, pStorage);
    16651704        if (FAILED(rc)) throw rc;
     1705
     1706        /*
     1707         * Try to read the certificate file. First try.
     1708         * Logic is the same as with manifest file
     1709         * Only if the manifest file had been read successfully before
     1710         */
     1711        vrc = RTTarCurrentFile(tar, &pszFilename);
     1712        if (RT_FAILURE(vrc))
     1713            throw setError(VBOX_E_IPRT_ERROR,
     1714                           tr("Getting the current file within the archive failed (%Rrc)"), vrc);
     1715
     1716        size_t cbCertSize = 0;
     1717        Utf8Str strCertFile = Utf8Str(pszFilename).stripExt().append(".cert");
     1718        if (pvMfBuf)
     1719        {
     1720            if (strCertFile.compare(pszFilename) == 0)
     1721            {
     1722                rc = readTarFileToBuf(tar, strCertFile, &pvCertBuf, &cbCertSize, false, pCallbacks, pStorage);
     1723                if (FAILED(rc)) throw rc;
     1724
     1725                if (pvCertBuf)
     1726                {
     1727                /* verify the certificate */
     1728                }
     1729            }
     1730        }
     1731
    16661732        /* Now import the appliance. */
    16671733        importMachines(stack, pCallbacks, pStorage);
     
    16691735        if (!pvMfBuf)
    16701736        {
    1671             rc = readTarManifestFile(tar, strMfFile, &pvMfBuf, &cbMfSize, pCallbacks, pStorage);
     1737            rc = readTarFileToBuf(tar, strMfFile, &pvMfBuf, &cbMfSize, true, pCallbacks, pStorage);
    16721738            if (FAILED(rc)) throw rc;
    1673         }
    1674         /* If we were able to read a manifest file we can check it now. */
    1675         if (pvMfBuf)
    1676         {
    1677             /* Add the ovf file to the digest list. */
    1678             stack.llSrcDisksDigest.push_front(STRPAIR(Utf8Str(pszFilename).stripExt().append(".ovf"), m->strOVFSHADigest));
    1679             rc = verifyManifestFile(strMfFile, stack, pvMfBuf, cbMfSize);
    1680             if (FAILED(rc)) throw rc;
     1739
     1740            /* If we were able to read a manifest file we can check it now. */
     1741            if (pvMfBuf)
     1742            {
     1743                /* Add the ovf file to the digest list. */
     1744                stack.llSrcDisksDigest.push_front(STRPAIR(Utf8Str(pszFilename).stripExt().append(".ovf"),
     1745                                                  m->strOVFSHADigest));
     1746                rc = verifyManifestFile(strMfFile, stack, pvMfBuf, cbMfSize);
     1747                if (FAILED(rc)) throw rc;
     1748
     1749                /*
     1750                 * Try to read the certificate file. Second try.
     1751                 * Only if the manifest file had been read successfully before
     1752                 */
     1753
     1754                vrc = RTTarCurrentFile(tar, &pszFilename);
     1755                if (RT_FAILURE(vrc))
     1756                    throw setError(VBOX_E_IPRT_ERROR,
     1757                                   tr("Getting the current file within the archive failed (%Rrc)"), vrc);
     1758
     1759                if (strCertFile.compare(pszFilename) == 0)
     1760                {
     1761                    rc = readTarFileToBuf(tar, strCertFile, &pvCertBuf, &cbCertSize, false, pCallbacks, pStorage);
     1762                    if (FAILED(rc)) throw rc;
     1763
     1764                    if (pvCertBuf)
     1765                    {
     1766                    /* verify the certificate */
     1767                    }
     1768                }
     1769            }
    16811770        }
    16821771    }
     
    16981787    if (pTarIo)
    16991788        RTMemFree(pTarIo);
     1789    if (pvCertBuf)
     1790        RTMemFree(pvCertBuf);
    17001791
    17011792    LogFlowFunc(("rc=%Rhrc\n", rc));
     
    17701861
    17711862        /* Next we have to download the disk images */
    1772         vrc = RTS3Create(&hS3, pTask->locInfo.strUsername.c_str(), pTask->locInfo.strPassword.c_str(), pTask->locInfo.strHostname.c_str(), "virtualbox-agent/"VBOX_VERSION_STRING);
     1863        vrc = RTS3Create(&hS3,
     1864                         pTask->locInfo.strUsername.c_str(),
     1865                         pTask->locInfo.strPassword.c_str(),
     1866                         pTask->locInfo.strHostname.c_str(),
     1867                         "virtualbox-agent/"VBOX_VERSION_STRING);
    17731868        if (RT_FAILURE(vrc))
    17741869            throw setError(VBOX_E_IPRT_ERROR,
     
    17951890                    throw setError(E_ACCESSDENIED,
    17961891                                   tr("Cannot download file '%s' from S3 storage server (Access denied). "
    1797                                       "Make sure that your credentials are right. Also check that your host clock is properly synced"),
     1892                                      "Make sure that your credentials are right. Also check that your host clock is "
     1893                                      "properly synced"),
    17981894                                   pszFilename);
    17991895                else if (vrc == VERR_S3_NOT_FOUND)
     
    18311927                throw setError(E_ACCESSDENIED,
    18321928                               tr("Cannot download file '%s' from S3 storage server (Access denied)."
    1833                                   "Make sure that your credentials are right. Also check that your host clock is properly synced"),
     1929                                  "Make sure that your credentials are right. "
     1930                                  "Also check that your host clock is properly synced"),
    18341931                               pszFilename);
    18351932            else
     
    18981995#endif /* VBOX_WITH_S3 */
    18991996
    1900 HRESULT Appliance::readManifestFile(const Utf8Str &strFile, void **ppvBuf, size_t *pcbSize, PVDINTERFACEIO pCallbacks, PSHASTORAGE pStorage)
     1997HRESULT Appliance::readFileToBuf(const Utf8Str &strFile,
     1998                                 void **ppvBuf,
     1999                                 size_t *pcbSize,
     2000                                 bool fCreateDigest,
     2001                                 PVDINTERFACEIO pCallbacks,
     2002                                 PSHASTORAGE pStorage)
    19012003{
    19022004    HRESULT rc = S_OK;
    19032005
    1904     bool fOldDigest = pStorage->fCreateDigest;
    1905     pStorage->fCreateDigest = false; /* No digest for the manifest file */
     2006    bool fOldDigest = pStorage->fCreateDigest;/* Save the old digest property */
     2007    pStorage->fCreateDigest = fCreateDigest;
    19062008    int vrc = ShaReadBuf(strFile.c_str(), ppvBuf, pcbSize, pCallbacks, pStorage);
    19072009    if (   RT_FAILURE(vrc)
    19082010        && vrc != VERR_FILE_NOT_FOUND)
    19092011        rc = setError(VBOX_E_FILE_ERROR,
    1910                       tr("Could not read manifest file '%s' (%Rrc)"),
     2012                      tr("Could not read file '%s' (%Rrc)"),
    19112013                      RTPathFilename(strFile.c_str()), vrc);
    19122014    pStorage->fCreateDigest = fOldDigest; /* Restore the old digest creation behavior again. */
     
    19152017}
    19162018
    1917 HRESULT Appliance::readTarManifestFile(RTTAR tar, const Utf8Str &strFile, void **ppvBuf, size_t *pcbSize, PVDINTERFACEIO pCallbacks, PSHASTORAGE pStorage)
     2019HRESULT Appliance::readTarFileToBuf(RTTAR tar,
     2020                                    const Utf8Str &strFile,
     2021                                    void **ppvBuf,
     2022                                    size_t *pcbSize,
     2023                                    bool fCreateDigest,
     2024                                    PVDINTERFACEIO pCallbacks,
     2025                                    PSHASTORAGE pStorage)
    19182026{
    19192027    HRESULT rc = S_OK;
     
    19332041        {
    19342042            if (!strcmp(pszCurFile, RTPathFilename(strFile.c_str())))
    1935                 rc = readManifestFile(strFile, ppvBuf, pcbSize, pCallbacks, pStorage);
     2043                rc = readFileToBuf(strFile, ppvBuf, pcbSize, fCreateDigest, pCallbacks, pStorage);
    19362044            RTStrFree(pszCurFile);
    19372045        }
     
    19932101                                            int32_t &lDevice)
    19942102{
    1995     Log(("Appliance::convertDiskAttachmentValues: hdc.system=%d, hdc.fPrimary=%d, ulAddressOnParent=%d\n", hdc.system, hdc.fPrimary, ulAddressOnParent));
     2103    Log(("Appliance::convertDiskAttachmentValues: hdc.system=%d, hdc.fPrimary=%d, ulAddressOnParent=%d\n",
     2104         hdc.system,
     2105         hdc.fPrimary,
     2106         ulAddressOnParent));
    19962107
    19972108    switch (hdc.system)
     
    20892200 *
    20902201 * @param di ovfreader.cpp structure describing the disk image from the OVF that is to be imported
    2091  * @param ulSizeMB Size of the disk image (for progress reporting)
    20922202 * @param strTargetPath Where to create the target image.
    20932203 * @param pTargetHD out: The newly created target disk. This also gets pushed on stack.llHardDisksCreated for cleanup.
     
    20952205 */
    20962206void Appliance::importOneDiskImage(const ovf::DiskImage &di,
    2097                                    const Utf8Str &strTargetPath,
     2207                                   Utf8Str *strTargetPath,
    20982208                                   ComObjPtr<Medium> &pTargetHD,
    20992209                                   ImportStack &stack,
     
    21012211                                   PSHASTORAGE pStorage)
    21022212{
     2213    SHASTORAGE finalStorage;
     2214    PSHASTORAGE pRealUsedStorage = pStorage;/* may be changed later to finalStorage */
     2215    PVDINTERFACEIO pFileIo = NULL;/* used in GZIP case*/
    21032216    ComObjPtr<Progress> pProgress;
    21042217    pProgress.createObject();
    2105     HRESULT rc = pProgress->init(mVirtualBox, static_cast<IAppliance*>(this), BstrFmt(tr("Creating medium '%s'"), strTargetPath.c_str()).raw(), TRUE);
     2218    HRESULT rc = pProgress->init(mVirtualBox,
     2219                                 static_cast<IAppliance*>(this),
     2220                                 BstrFmt(tr("Creating medium '%s'"),
     2221                                 strTargetPath->c_str()).raw(),
     2222                                 TRUE);
    21062223    if (FAILED(rc)) throw rc;
    21072224
     
    21092226    SystemProperties *pSysProps = mVirtualBox->getSystemProperties();
    21102227
     2228    /*
     2229     * we put strSourceOVF into the stack.llSrcDisksDigest in the end of this
     2230     * function like a key for a later validation of the SHA digests
     2231     */
    21112232    const Utf8Str &strSourceOVF = di.strHref;
    21122233
    21132234    Utf8Str strSrcFilePath(stack.strSourceDir);
     2235    Utf8Str strTargetDir(*strTargetPath);
     2236
    21142237    /* Construct source file path */
    21152238    Utf8Str name = applianceIOName(applianceIOTar);
     
    21272250     * example. */
    21282251    RTUUID uuid;
    2129     int vrc = RTUuidFromStr(&uuid, strTargetPath.c_str());
     2252    int vrc = RTUuidFromStr(&uuid, strTargetPath->c_str());
    21302253    if (vrc == VINF_SUCCESS)
    21312254    {
     
    21352258    else
    21362259    {
    2137         Utf8Str strTrgFormat = "VMDK";
    2138         ULONG lCabs = 0;
    2139 
    2140         if (RTPathHaveExt(strTargetPath.c_str()))
     2260        /* check read file to GZIP compression */
     2261        try
    21412262        {
    2142             char *pszExt = RTPathExt(strTargetPath.c_str());
    2143             /* Figure out which format the user like to have. Default is VMDK. */
    2144             ComObjPtr<MediumFormat> trgFormat = pSysProps->mediumFormatFromExtension(&pszExt[1]);
    2145             if (trgFormat.isNull())
    2146                 throw setError(VBOX_E_NOT_SUPPORTED,
    2147                                tr("Could not find a valid medium format for the target disk '%s'"),
    2148                                strTargetPath.c_str());
    2149             /* Check the capabilities. We need create capabilities. */
    2150             lCabs = 0;
    2151             com::SafeArray <MediumFormatCapabilities_T> mediumFormatCap;
    2152             rc = trgFormat->COMGETTER(Capabilities)(ComSafeArrayAsOutParam(mediumFormatCap));
    2153 
    2154             if (FAILED(rc)) throw rc;
    2155             else
    2156             {
    2157                 for (ULONG j = 0; j < mediumFormatCap.size(); j++)
    2158                     lCabs |= mediumFormatCap[j];
    2159             }
    2160 
    2161             if (!(   ((lCabs & MediumFormatCapabilities_CreateFixed) == MediumFormatCapabilities_CreateFixed)
    2162                   || ((lCabs & MediumFormatCapabilities_CreateDynamic) == MediumFormatCapabilities_CreateDynamic)))
    2163                 throw setError(VBOX_E_NOT_SUPPORTED,
    2164                                tr("Could not find a valid medium format for the target disk '%s'"),
    2165                                strTargetPath.c_str());
    2166             Bstr bstrFormatName;
    2167             rc = trgFormat->COMGETTER(Name)(bstrFormatName.asOutParam());
    2168             if (FAILED(rc)) throw rc;
    2169             strTrgFormat = Utf8Str(bstrFormatName);
    2170         }
    2171 
    2172         /* Create an IMedium object. */
    2173         pTargetHD.createObject();
    2174 
    2175         /*CD/DVD case*/
    2176         if (strTrgFormat.compare("RAW", Utf8Str::CaseInsensitive) == 0)
    2177         {
    2178             void *pvTmpBuf = 0;
    2179             size_t cbSize = 0;
    2180 
    2181             /* Read the ISO file into a memory buffer */
    2182             vrc = ShaReadBuf(strSrcFilePath.c_str(), &pvTmpBuf, &cbSize, pCallbacks, pStorage);
    2183 
    2184             if ( RT_FAILURE(vrc) || !pvTmpBuf)
    2185                 throw setError(VBOX_E_FILE_ERROR,
    2186                                tr("Could not read ISO file '%s' (%Rrc)"),
    2187                                RTPathFilename(strSrcFilePath.c_str()), vrc);
    2188 
    2189             if (RTFileExists(strTargetPath.c_str()) == false)
    2190             {
    2191 
    2192                 /* ensure the directory exists */
    2193                 if (lCabs & MediumFormatCapabilities_File)
     2263            if (di.strCompression.compare("gzip",Utf8Str::CaseInsensitive) == 0)
     2264            {
     2265                /*
     2266                 * 1. extract a file to the local/temporary folder
     2267                 * 2. apply GZIP decompression for the file
     2268                 * 3. replace the value of strSrcFilePath with a new path to the file
     2269                 * 4. replace SHA-TAR I/O interface with File I/O interface
     2270                 * 5. save calculated SHA digest of GZIPed file for later validation
     2271                 */
     2272
     2273                /* Decompress the GZIP file and save a new file in the target path */
     2274                strTargetDir = strTargetDir.stripFilename();
     2275                strTargetDir.append("/temp_");
     2276
     2277                Utf8Str strTempTargetFilename(*strTargetPath);
     2278                strTempTargetFilename = strTempTargetFilename.stripPath();
     2279                strTempTargetFilename = strTempTargetFilename.stripExt();
     2280                Utf8Str vdf = typeOfVirtualDiskFormatFromURI(di.strFormat);
     2281
     2282                strTargetDir.append(strTempTargetFilename);
     2283
     2284                vrc = decompressImageAndSave(strSrcFilePath.c_str(), strTargetDir.c_str(), pCallbacks, pStorage);
     2285
     2286                if (RT_FAILURE(vrc))
     2287                    throw setError(VBOX_E_FILE_ERROR,
     2288                                   tr("Could not read the file '%s' (%Rrc)"),
     2289                                   RTPathFilename(strSrcFilePath.c_str()), vrc);
     2290
     2291                /* Create the necessary file access interfaces. */
     2292                pFileIo = FileCreateInterface();
     2293                if (!pFileIo)
     2294                    throw setError(E_OUTOFMEMORY);
     2295
     2296                name = applianceIOName(applianceIOFile);
     2297
     2298                vrc = VDInterfaceAdd(&pFileIo->Core, name.c_str(),
     2299                                     VDINTERFACETYPE_IO, NULL, sizeof(VDINTERFACEIO),
     2300                                     &finalStorage.pVDImageIfaces);
     2301                if (RT_FAILURE(vrc))
     2302                    throw setError(VBOX_E_IPRT_ERROR,
     2303                                   tr("Creation of the VD interface failed (%Rrc)"), vrc);
     2304
     2305                strSrcFilePath = strTargetDir;
     2306                strTargetDir = strTargetDir.stripFilename();
     2307                strTargetDir.append(RTPATH_SLASH_STR);
     2308                strTargetDir.append(strTempTargetFilename.c_str());
     2309                *strTargetPath = strTargetDir.c_str();
     2310
     2311                pRealUsedStorage = &finalStorage;
     2312            }
     2313
     2314            Utf8Str strTrgFormat = "VMDK";
     2315            ULONG lCabs = 0;
     2316
     2317            if (RTPathHaveExt(strTargetPath->c_str()))
     2318            {
     2319                char *pszExt = RTPathExt(strTargetPath->c_str());
     2320                /* Figure out which format the user like to have. Default is VMDK. */
     2321                ComObjPtr<MediumFormat> trgFormat = pSysProps->mediumFormatFromExtension(&pszExt[1]);
     2322                if (trgFormat.isNull())
     2323                    throw setError(VBOX_E_NOT_SUPPORTED,
     2324                                   tr("Could not find a valid medium format for the target disk '%s'"),
     2325                                   strTargetPath->c_str());
     2326                /* Check the capabilities. We need create capabilities. */
     2327                lCabs = 0;
     2328                com::SafeArray <MediumFormatCapabilities_T> mediumFormatCap;
     2329                rc = trgFormat->COMGETTER(Capabilities)(ComSafeArrayAsOutParam(mediumFormatCap));
     2330
     2331                if (FAILED(rc))
     2332                    throw rc;
     2333                else
    21942334                {
    2195                     rc = VirtualBox::ensureFilePathExists(strTargetPath, true);
    2196                     if (FAILED(rc))
    2197                         throw rc;
     2335                    for (ULONG j = 0; j < mediumFormatCap.size(); j++)
     2336                        lCabs |= mediumFormatCap[j];
    21982337                }
    21992338
    2200                 // create a new file and copy raw data into one from buffer pvTmpBuf
    2201                 RTFILE pFile = NULL;
    2202                 vrc = RTFileOpen(&pFile, strTargetPath.c_str(), RTFILE_O_OPEN_CREATE | RTFILE_O_WRITE | RTFILE_O_DENY_NONE);
    2203                 if (RT_SUCCESS(vrc) && pFile != NULL)
     2339                if (!(   ((lCabs & MediumFormatCapabilities_CreateFixed) == MediumFormatCapabilities_CreateFixed)
     2340                      || ((lCabs & MediumFormatCapabilities_CreateDynamic) == MediumFormatCapabilities_CreateDynamic)))
     2341                    throw setError(VBOX_E_NOT_SUPPORTED,
     2342                                   tr("Could not find a valid medium format for the target disk '%s'"),
     2343                                   strTargetPath->c_str());
     2344                Bstr bstrFormatName;
     2345                rc = trgFormat->COMGETTER(Name)(bstrFormatName.asOutParam());
     2346                if (FAILED(rc)) throw rc;
     2347                strTrgFormat = Utf8Str(bstrFormatName);
     2348            }
     2349
     2350            /* Create an IMedium object. */
     2351            pTargetHD.createObject();
     2352
     2353            /*CD/DVD case*/
     2354            if (strTrgFormat.compare("RAW", Utf8Str::CaseInsensitive) == 0)
     2355            {
     2356                void *pvTmpBuf = 0;
     2357                size_t cbSize = 0;
     2358                try
    22042359                {
    2205                     size_t cbWritten = 0;
    2206 
    2207                     vrc = RTFileWrite(pFile, pvTmpBuf, cbSize, &cbWritten);
    2208 
    2209                     if (RT_FAILURE(vrc))
     2360                    /* Read the ISO file into a memory buffer */
     2361                    vrc = ShaReadBuf(strSrcFilePath.c_str(), &pvTmpBuf, &cbSize, pCallbacks, pRealUsedStorage);
     2362
     2363                    if ( RT_FAILURE(vrc) || !pvTmpBuf)
     2364                        throw setError(VBOX_E_FILE_ERROR,
     2365                                       tr("Could not read ISO file '%s' listed in the OVF file (%Rrc)"),
     2366                                       RTPathFilename(strSourceOVF.c_str()), vrc);
     2367
     2368                    if (RTFileExists(strTargetPath->c_str()) == false)
    22102369                    {
    2211                         Utf8Str path(strTargetPath);
    2212                         path = path.stripFilename();
    2213                         if (pvTmpBuf)
    2214                             RTMemFree(pvTmpBuf);
    2215                         throw setError(VBOX_E_FILE_ERROR,
    2216                                        tr("Could not write the ISO file '%s' into the folder %s (%Rrc)"),
    2217                                        strSrcFilePath.stripPath().c_str(),
    2218                                        path.c_str(),
    2219                                        vrc);
     2370
     2371                        /* ensure the directory exists */
     2372                        if (lCabs & MediumFormatCapabilities_File)
     2373                        {
     2374                            rc = VirtualBox::ensureFilePathExists(*strTargetPath, true);
     2375                            if (FAILED(rc))
     2376                                throw rc;
     2377                        }
     2378
     2379                        // create a new file and copy raw data into one from buffer pvTmpBuf
     2380                        RTFILE pFile = NULL;
     2381                        vrc = RTFileOpen(&pFile,
     2382                                         strTargetPath->c_str(),
     2383                                         RTFILE_O_OPEN_CREATE | RTFILE_O_WRITE | RTFILE_O_DENY_NONE);
     2384
     2385                        if (RT_SUCCESS(vrc) && pFile != NULL)
     2386                        {
     2387                            size_t cbWritten = 0;
     2388
     2389                            vrc = RTFileWrite(pFile, pvTmpBuf, cbSize, &cbWritten);
     2390
     2391                            if (RT_FAILURE(vrc))
     2392                            {
     2393                                Utf8Str path(*strTargetPath);
     2394                                path = path.stripFilename();
     2395
     2396                                throw setError(VBOX_E_FILE_ERROR,
     2397                                               tr("Could not write the ISO file '%s' into the folder %s (%Rrc)"),
     2398                                               strSrcFilePath.stripPath().c_str(),
     2399                                               path.c_str(),
     2400                                               vrc);
     2401                            }
     2402                        }
     2403                        RTFileClose(pFile);
    22202404                    }
    22212405                }
    2222 
    2223                 RTFileClose(pFile);
    2224             }
    2225             /* Advance to the next operation. */
    2226             stack.pProgress->SetNextOperation(BstrFmt(tr("Importing virtual disk image '%s'"),
    2227                                             RTPathFilename(strSrcFilePath.c_str())).raw(),
    2228                                             di.ulSuggestedSizeMB);//operation's weight, as set up with the IProgress origi
     2406                catch (HRESULT arc)
     2407                {
     2408                    if (pvTmpBuf)
     2409                        RTMemFree(pvTmpBuf);
     2410                    throw;
     2411                }
     2412
     2413                if (pvTmpBuf)
     2414                    RTMemFree(pvTmpBuf);
     2415
     2416                /* Advance to the next operation. */
     2417                /* operation's weight, as set up with the IProgress originally */
     2418                stack.pProgress->SetNextOperation(BstrFmt(tr("Importing virtual disk image '%s'"),
     2419                                                  RTPathFilename(strSourceOVF.c_str())).raw(),
     2420                                                  di.ulSuggestedSizeMB);
     2421            }
     2422            else/* HDD case*/
     2423            {
     2424                rc = pTargetHD->init(mVirtualBox,
     2425                                     strTrgFormat,
     2426                                     *strTargetPath,
     2427                                     Guid::Empty /* media registry: none yet */);
     2428                if (FAILED(rc)) throw rc;
     2429
     2430                /* Now create an empty hard disk. */
     2431                rc = mVirtualBox->CreateHardDisk(Bstr(strTrgFormat).raw(),
     2432                                                 Bstr(*strTargetPath).raw(),
     2433                                                 ComPtr<IMedium>(pTargetHD).asOutParam());
     2434                if (FAILED(rc)) throw rc;
     2435
     2436                /* If strHref is empty we have to create a new file. */
     2437                if (strSourceOVF.isEmpty())
     2438                {
     2439                    com::SafeArray<MediumVariant_T>  mediumVariant;
     2440                    mediumVariant.push_back(MediumVariant_Standard);
     2441                    /* Create a dynamic growing disk image with the given capacity. */
     2442                    rc = pTargetHD->CreateBaseStorage(di.iCapacity / _1M,
     2443                                                      ComSafeArrayAsInParam(mediumVariant),
     2444                                                      ComPtr<IProgress>(pProgress).asOutParam());
     2445                    if (FAILED(rc)) throw rc;
     2446
     2447                    /* Advance to the next operation. */
     2448                    /* operation's weight, as set up with the IProgress originally */
     2449                    stack.pProgress->SetNextOperation(BstrFmt(tr("Creating disk image '%s'"),
     2450                                                      strTargetPath->c_str()).raw(),
     2451                                                      di.ulSuggestedSizeMB);
     2452                }
     2453                else
     2454                {
     2455                    /* We need a proper source format description */
     2456                    ComObjPtr<MediumFormat> srcFormat;
     2457                    /* Which format to use? */
     2458                    Utf8Str strSrcFormat = "VDI";
     2459
     2460                    std::set<Utf8Str> listURIs = Appliance::URIFromTypeOfVirtualDiskFormat("VMDK");
     2461                    std::set<Utf8Str>::const_iterator itr = listURIs.find(di.strFormat);
     2462
     2463                    if (itr != listURIs.end())
     2464                    {
     2465                        strSrcFormat = "VMDK";
     2466                    }
     2467
     2468                    srcFormat = pSysProps->mediumFormat(strSrcFormat);
     2469                    if (srcFormat.isNull())
     2470                        throw setError(VBOX_E_NOT_SUPPORTED,
     2471                                       tr("Could not find a valid medium format for the source disk '%s'"),
     2472                                       RTPathFilename(strSourceOVF.c_str()));
     2473
     2474                    /* Clone the source disk image */
     2475                    ComObjPtr<Medium> nullParent;
     2476                    rc = pTargetHD->importFile(strSrcFilePath.c_str(),
     2477                                               srcFormat,
     2478                                               MediumVariant_Standard,
     2479                                               pCallbacks, pRealUsedStorage,
     2480                                               nullParent,
     2481                                               pProgress);
     2482                    if (FAILED(rc)) throw rc;
     2483
     2484                    /* Advance to the next operation. */
     2485                    /* operation's weight, as set up with the IProgress originally */
     2486                    stack.pProgress->SetNextOperation(BstrFmt(tr("Importing virtual disk image '%s'"),
     2487                                                      RTPathFilename(strSourceOVF.c_str())).raw(),
     2488                                                      di.ulSuggestedSizeMB);
     2489                }
     2490
     2491                /* Now wait for the background disk operation to complete; this throws
     2492                 * HRESULTs on error. */
     2493                ComPtr<IProgress> pp(pProgress);
     2494                waitForAsyncProgress(stack.pProgress, pp);
     2495            }
    22292496        }
    2230         else/* HDD case*/
     2497        catch (...)
    22312498        {
    2232             rc = pTargetHD->init(mVirtualBox,
    2233                                  strTrgFormat,
    2234                                  strTargetPath,
    2235                                  Guid::Empty /* media registry: none yet */);
    2236             if (FAILED(rc)) throw rc;
    2237 
    2238             /* Now create an empty hard disk. */
    2239             rc = mVirtualBox->CreateHardDisk(Bstr(strTrgFormat).raw(),
    2240                                              Bstr(strTargetPath).raw(),
    2241                                              ComPtr<IMedium>(pTargetHD).asOutParam());
    2242             if (FAILED(rc)) throw rc;
    2243 
    2244             /* If strHref is empty we have to create a new file. */
    2245             if (strSourceOVF.isEmpty())
    2246             {
    2247                 com::SafeArray<MediumVariant_T>  mediumVariant;
    2248                 mediumVariant.push_back(MediumVariant_Standard);
    2249                 /* Create a dynamic growing disk image with the given capacity. */
    2250                 rc = pTargetHD->CreateBaseStorage(di.iCapacity / _1M, ComSafeArrayAsInParam(mediumVariant), ComPtr<IProgress>(pProgress).asOutParam());
    2251                 if (FAILED(rc)) throw rc;
    2252 
    2253                 /* Advance to the next operation. */
    2254                 stack.pProgress->SetNextOperation(BstrFmt(tr("Creating disk image '%s'"), strTargetPath.c_str()).raw(),
    2255                                                   di.ulSuggestedSizeMB);     // operation's weight, as set up with the IProgress originally
    2256             }
    2257             else
    2258             {
    2259                 /* We need a proper source format description */
    2260                 ComObjPtr<MediumFormat> srcFormat;
    2261                 /* Which format to use? */
    2262                 Utf8Str strSrcFormat = "VDI";
    2263 
    2264                 std::set<Utf8Str> listURIs = Appliance::URIFromTypeOfVirtualDiskFormat("VMDK");
    2265                 std::set<Utf8Str>::const_iterator itr = listURIs.find(di.strFormat);
    2266 
    2267                 if (itr != listURIs.end())
    2268                 {
    2269                     strSrcFormat = "VMDK";
    2270                 }
    2271 
    2272                 srcFormat = pSysProps->mediumFormat(strSrcFormat);
    2273                 if (srcFormat.isNull())
    2274                     throw setError(VBOX_E_NOT_SUPPORTED,
    2275                                    tr("Could not find a valid medium format for the source disk '%s'"),
    2276                                    RTPathFilename(strSrcFilePath.c_str()));
    2277 
    2278                 /* Clone the source disk image */
    2279                 ComObjPtr<Medium> nullParent;
    2280                 rc = pTargetHD->importFile(strSrcFilePath.c_str(),
    2281                                            srcFormat,
    2282                                            MediumVariant_Standard,
    2283                                            pCallbacks, pStorage,
    2284                                            nullParent,
    2285                                            pProgress);
    2286                 if (FAILED(rc)) throw rc;
    2287 
    2288                 /* Advance to the next operation. */
    2289                 stack.pProgress->SetNextOperation(BstrFmt(tr("Importing virtual disk image '%s'"), RTPathFilename(strSrcFilePath.c_str())).raw(),
    2290                                                   di.ulSuggestedSizeMB);// operation's weight, as set up with the IProgress originally);
    2291             }
    2292 
    2293             /* Now wait for the background disk operation to complete; this throws
    2294              * HRESULTs on error. */
    2295             ComPtr<IProgress> pp(pProgress);
    2296             waitForAsyncProgress(stack.pProgress, pp);
     2499            if (pFileIo)
     2500                RTMemFree(pFileIo);
     2501
     2502            throw;
    22972503        }
    22982504    }
     2505
     2506    if (pFileIo)
     2507        RTMemFree(pFileIo);
    22992508
    23002509    /* Add the newly create disk path + a corresponding digest the our list for
    23012510     * later manifest verification. */
    2302     stack.llSrcDisksDigest.push_back(STRPAIR(strSrcFilePath, pStorage ? pStorage->strDigest : ""));
     2511    stack.llSrcDisksDigest.push_back(STRPAIR(strSourceOVF, pStorage ? pStorage->strDigest : ""));
    23032512}
    23042513
     
    24322641    else if (vsdeNW.size() > maxNetworkAdapters)
    24332642        throw setError(VBOX_E_FILE_ERROR,
    2434                        tr("Too many network adapters: OVF requests %d network adapters, but VirtualBox only supports %d"),
     2643                       tr("Too many network adapters: OVF requests %d network adapters, "
     2644                          "but VirtualBox only supports %d"),
    24352645                       vsdeNW.size(), maxNetworkAdapters);
    24362646    else
     
    25402750    // IDE Hard disk controller
    25412751    std::list<VirtualSystemDescriptionEntry*> vsdeHDCIDE = vsdescThis->findByType(VirtualSystemDescriptionType_HardDiskControllerIDE);
    2542     // In OVF (at least VMware's version of it), an IDE controller has two ports, so VirtualBox's single IDE controller
    2543     // with two channels and two ports each counts as two OVF IDE controllers -- so we accept one or two such IDE controllers
     2752    /*
     2753     * In OVF (at least VMware's version of it), an IDE controller has two ports,
     2754     * so VirtualBox's single IDE controller with two channels and two ports each counts as
     2755     * two OVF IDE controllers -- so we accept one or two such IDE controllers
     2756     */
    25442757    size_t cIDEControllers = vsdeHDCIDE.size();
    25452758    if (cIDEControllers > 2)
     
    25782791        if (hdcVBox == "AHCI")
    25792792        {
    2580             rc = pNewMachine->AddStorageController(Bstr("SATA Controller").raw(), StorageBus_SATA, pController.asOutParam());
     2793            rc = pNewMachine->AddStorageController(Bstr("SATA Controller").raw(),
     2794                                                   StorageBus_SATA,
     2795                                                   pController.asOutParam());
    25812796            if (FAILED(rc)) throw rc;
    25822797        }
     
    26292844    {
    26302845        ComPtr<IStorageController> pController;
    2631         rc = pNewMachine->AddStorageController(Bstr(L"SAS Controller").raw(), StorageBus_SAS, pController.asOutParam());
     2846        rc = pNewMachine->AddStorageController(Bstr(L"SAS Controller").raw(),
     2847                                               StorageBus_SAS,
     2848                                               pController.asOutParam());
    26322849        if (FAILED(rc)) throw rc;
    26332850        rc = pController->COMSETTER(ControllerType)(StorageControllerType_LsiLogicSas);
     
    26742891            {
    26752892                ComPtr<IStorageController> pController;
    2676                 rc = sMachine->AddStorageController(Bstr("Floppy Controller").raw(), StorageBus_Floppy, pController.asOutParam());
     2893                rc = sMachine->AddStorageController(Bstr("Floppy Controller").raw(),
     2894                                                    StorageBus_Floppy,
     2895                                                    pController.asOutParam());
    26772896                if (FAILED(rc)) throw rc;
    26782897
     
    27352954            while(oit != stack.mapDisks.end())
    27362955            {
    2737                 if (RTPathHaveExt(oit->second.strHref.c_str()))
    2738                 {
    2739                     /* Figure out which format the user have. */
    2740                     char *pszExt = RTPathExt(oit->second.strHref.c_str());
    2741                     /* Get the system properties. */
    2742                     SystemProperties *pSysProps = mVirtualBox->getSystemProperties();
    2743                     ComObjPtr<MediumFormat> trgFormat = pSysProps->mediumFormatFromExtension(&pszExt[1]);
    2744                     if (trgFormat.isNull())
    2745                     {
    2746                         ++oit;
    2747                         continue;
    2748                     }
    2749                 }
    2750 
    27512956                ovf::DiskImage diCurrent = oit->second;
    27522957                ovf::VirtualDisksMap::const_iterator itVDisk = vsysThis.mapVirtualDisks.begin();
     
    27892994
    27902995                /*
    2791                  *
    27922996                 * preliminary check availability of the image
    27932997                 * This step is useful if image is placed in the OVA (TAR) package
    2794                  *
    27952998                 */
    27962999
     
    28203023                        {
    28213024                            /*
    2822                              *
    28233025                             * availableImage contains the disk file reference (e.g. "disk1.vmdk"), which should exist
    28243026                             * in the global images map.
     
    28473049
    28483050                            /*
    2849                              * 
    28503051                             * Again iterate over all given disk images of the virtual system
    28513052                             * disks description using the found disk image
    2852                              * 
    28533053                             */
    28543054                            {
     
    29013101                ComObjPtr<Medium> pTargetHD;
    29023102
     3103                Utf8Str savedVboxCurrent = vsdeTargetHD->strVboxCurrent;
     3104
    29033105                importOneDiskImage(diCurrent,
    2904                                    vsdeTargetHD->strVboxCurrent,
     3106                                   &vsdeTargetHD->strVboxCurrent,
    29053107                                   pTargetHD,
    29063108                                   stack,
     
    29653167                rc = sMachine->SaveSettings();
    29663168                if (FAILED(rc)) throw rc;
     3169
     3170                /* restore */
     3171                vsdeTargetHD->strVboxCurrent = savedVboxCurrent;
     3172
    29673173            } // end while(oit != stack.mapDisks.end())
    29683174
     
    30243230
    30253231    /*
    3026      *
    30273232     * step 1): modify machine config according to OVF config, in case the user
    30283233     * has modified them using setFinalValues()
    3029      *
    30303234     */
    30313235
     
    31683372
    31693373    /*
    3170      *
    31713374     * step 2: scan the machine config for media attachments
    3172      *
    31733375     */
    31743376
     
    31873389    while(oit != stack.mapDisks.end())
    31883390    {
    3189         if (RTPathHaveExt(oit->second.strHref.c_str()))
    3190         {
    3191             /* Figure out which format the user have. */
    3192             char *pszExt = RTPathExt(oit->second.strHref.c_str());
    3193             /* Get the system properties. */
    3194             SystemProperties *pSysProps = mVirtualBox->getSystemProperties();
    3195             ComObjPtr<MediumFormat> trgFormat = pSysProps->mediumFormatFromExtension(&pszExt[1]);
    3196             if (trgFormat.isNull())
    3197             {
    3198                 ++oit;
    3199                 continue;
    3200             }
    3201         }
    3202 
    32033391        ovf::DiskImage diCurrent = oit->second;
    32043392
     
    32283416
    32293417        /*
    3230          *
    32313418         * preliminary check availability of the image
    32323419         * This step is useful if image is placed in the OVA (TAR) package
    3233          *
    32343420         */
    32353421
     
    32793465                    diCurrent = *(&itDiskImage->second);
    32803466
    3281                     /* Again iterate over all given disk images of the virtual system
     3467                    /*
     3468                     * Again iterate over all given disk images of the virtual system
    32823469                     * disks description using the found disk image
    32833470                     */
     
    33763563                    continue;
    33773564                }
     3565
    33783566                /*
    3379                  *
    33803567                 * step 3: import disk
    3381                  *
    33823568                 */
     3569                Utf8Str savedVboxCurrent = vsdeTargetHD->strVboxCurrent;
    33833570                ComObjPtr<Medium> pTargetHD;
    33843571                importOneDiskImage(diCurrent,
    3385                                    vsdeTargetHD->strVboxCurrent,
     3572                                   &vsdeTargetHD->strVboxCurrent,
    33863573                                   pTargetHD,
    33873574                                   stack,
     
    34183605                }
    34193606
     3607                /* restore */
     3608                vsdeTargetHD->strVboxCurrent = savedVboxCurrent;
     3609
    34203610                d.uuid = hdId;
    34213611                fFound = true;
     
    34343624
    34353625    /*
    3436      *
    34373626     * step 4): create the machine and have it import the config
    3438      *
    34393627     */
    34403628
     
    34463634    // instance that we created from the vbox:Machine
    34473635    rc = pNewMachine->init(mVirtualBox,
    3448                            stack.strNameVBox,// name from OVF preparations; can be suffixed to avoid duplicates, or changed by user
     3636                           stack.strNameVBox,// name from OVF preparations; can be suffixed to avoid duplicates
    34493637                           config);          // the whole machine config
    34503638    if (FAILED(rc)) throw rc;
  • trunk/src/VBox/Runtime/common/zip/zip.cpp

    r44528 r47340  
    575575{
    576576    pZip->u.Zlib.next_out = (Bytef *)pvBuf;
    577     pZip->u.Zlib.avail_out = (uInt)cbBuf;                   Assert(pZip->u.Zlib.avail_out == cbBuf);
     577    pZip->u.Zlib.avail_out = (uInt)cbBuf;
     578    Assert(pZip->u.Zlib.avail_out == cbBuf);
    578579
    579580    /*
     
    19271928RT_EXPORT_SYMBOL(RTZipBlockDecompress);
    19281929
     1930RTDECL(int) RTZipGzipDecompressBuffer(z_stream streamIn,
     1931                                      uint32_t *cbDecompressed,
     1932                                      bool *finished)
     1933{
     1934    int rc;
     1935    int sh = streamIn.avail_out;
     1936
     1937    *cbDecompressed = 0;
     1938
     1939    do
     1940    {
     1941        rc = inflate(&streamIn, Z_NO_FLUSH);
     1942
     1943        if (rc < 0)
     1944        {
     1945            rc = zipErrConvertFromZlib(rc, false /*decompress*/);
     1946            break;
     1947        }
     1948
     1949        *cbDecompressed += (sh - streamIn.avail_out);
     1950        sh = streamIn.avail_out;
     1951    }
     1952    while (streamIn.avail_out > 0 && streamIn.avail_in > 0 );
     1953
     1954    if (RT_SUCCESS(rc))
     1955    {
     1956        if (streamIn.avail_in == 0)
     1957            *finished = true;
     1958        else
     1959        {
     1960            if (streamIn.avail_out == 0)
     1961                *finished = false;
     1962        }
     1963    }
     1964
     1965    return rc;
     1966}
     1967
     1968RT_EXPORT_SYMBOL(RTZipGzipDecompressBuffer);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette