Changeset 47340 in vbox
- Timestamp:
- Jul 23, 2013 12:27:35 PM (12 years ago)
- svn:sync-xref-src-repo-rev:
- 87485
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/mangling.h
r47199 r47340 1861 1861 # define RTZipTarCmd RT_MANGLER(RTZipTarCmd) 1862 1862 # define RTZipTarFsStreamFromIoStream RT_MANGLER(RTZipTarFsStreamFromIoStream) 1863 1863 # define RTZipGzipDecompressBuffer RT_MANGLER(RTZipGzipDecompressBuffer) 1864 1864 /* 1865 1865 * Stable variables (alphabetical order): -
trunk/include/iprt/zip.h
r44528 r47340 29 29 #include <iprt/cdefs.h> 30 30 #include <iprt/types.h> 31 31 # include <zlib.h> 32 32 33 33 RT_C_DECLS_BEGIN … … 256 256 RTDECL(RTEXITCODE) RTZipTarCmd(unsigned cArgs, char **papszArgs); 257 257 258 RTDECL(int) RTZipGzipDecompressBuffer(z_stream streamIn, 259 uint32_t *cbDecompressed, 260 bool *finished); 258 261 /** @} */ 259 262 -
trunk/src/VBox/Main/include/ApplianceImpl.h
r46518 r47340 178 178 HRESULT importS3(TaskOVF *pTask); 179 179 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); 182 193 HRESULT verifyManifestFile(const Utf8Str &strFile, ImportStack &stack, void *pvBuf, size_t cbSize); 183 194 … … 189 200 190 201 void importOneDiskImage(const ovf::DiskImage &di, 191 const Utf8Str &strTargetPath,202 Utf8Str *strTargetPath, 192 203 ComObjPtr<Medium> &pTargetHD, 193 204 ImportStack &stack, -
trunk/src/VBox/Main/include/ApplianceImplPrivate.h
r46581 r47340 243 243 int ShaReadBuf(const char *pcszFilename, void **ppvBuf, size_t *pcbSize, PVDINTERFACEIO pIfIo, void *pvUser); 244 244 int ShaWriteBuf(const char *pcszFilename, void *pvBuf, size_t cbSize, PVDINTERFACEIO pIfIo, void *pvUser); 245 245 int decompressImageAndSave(const char *pcszFullFilenameIn, const char *pcszFullFilenameOut, PVDINTERFACEIO pIfIo, void *pvUser); 246 246 #endif // !____H_APPLIANCEIMPLPRIVATE 247 247 -
trunk/src/VBox/Main/src-server/ApplianceImplIO.cpp
r46971 r47340 24 24 #include "ApplianceImpl.h" 25 25 #include "ApplianceImplPrivate.h" 26 26 #include "VirtualBoxImpl.h" 27 28 #include <iprt/zip.h> 27 29 #include <iprt/tar.h> 28 30 #include <iprt/sha.h> … … 32 34 #include <iprt/circbuf.h> 33 35 #include <VBox/vd.h> 36 #include <zlib.h> 34 37 35 38 /****************************************************************************** … … 92 95 } SHASTORAGEINTERNAL, *PSHASTORAGEINTERNAL; 93 96 97 typedef 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 94 129 /****************************************************************************** 95 130 * Defined Constants And Macros * … … 110 145 #endif 111 146 147 /** Buffer for the decompressed data. */ 148 //static uint8_t *compressedBuffer; 149 /** The current size of the compressed data*/ 150 static size_t cbComprData; 151 /** The current offset into the compressed data */ 152 static size_t offComprData; 153 112 154 /****************************************************************************** 113 155 * Internal Functions * 114 156 ******************************************************************************/ 157 //static DECLCALLBACK(int) CopyCompressedDataToBuffer(void *pvUser, void *pvBuf, size_t cbBuf, size_t *pcbRead); 115 158 116 159 /****************************************************************************** … … 1174 1217 1175 1218 /****************************************************************************** 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 /****************************************************************************** 1176 1637 * Public Functions * 1177 1638 ******************************************************************************/ 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 //} 1178 1659 1179 1660 PVDINTERFACEIO ShaCreateInterface() … … 1339 1820 } 1340 1821 1822 int 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 119 119 { 120 120 // @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)) 122 123 // - Appropriate handle errors like not supported file formats 123 124 AutoCaller autoCaller(this); … … 280 281 if (cpuCountVBox > SchemaDefs::MaxCPUCount) 281 282 { 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."), 283 285 vsysThis.strName.c_str(), cpuCountVBox, SchemaDefs::MaxCPUCount); 284 286 cpuCountVBox = SchemaDefs::MaxCPUCount; … … 306 308 ) 307 309 { 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."), 309 312 vsysThis.strName.c_str(), ullMemSizeVBox, MM_RAM_MIN_IN_MB, MM_RAM_MAX_IN_MB); 310 313 ullMemSizeVBox = RT_MIN(RT_MAX(ullMemSizeVBox, MM_RAM_MIN_IN_MB), MM_RAM_MAX_IN_MB); … … 330 333 if ( vsysThis.pelmVboxMachine 331 334 && 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 } 333 339 else if (vsysThis.strSoundCardType.isNotEmpty()) 334 340 { … … 362 368 /* Check for the constrains */ 363 369 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."), 365 372 vsysThis.strName.c_str(), llNetworkAdapters.size(), maxNetworkAdapters); 366 373 /* Iterate through all network adapters. */ … … 390 397 /* Check for the constrains */ 391 398 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."), 393 401 vsysThis.strName.c_str(), cEthernetAdapters, maxNetworkAdapters); 394 402 … … 534 542 /* Warn only once */ 535 543 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."), 537 546 vsysThis.strName.c_str()); 538 547 … … 555 564 /* Warn only once */ 556 565 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"), 558 568 vsysThis.strName.c_str()); 559 569 … … 582 592 } 583 593 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."), 585 597 vsysThis.strName.c_str(), 586 598 hdc.strControllerType.c_str(), … … 1276 1288 1277 1289 /* 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); 1279 1295 if (RT_FAILURE(vrc)) 1280 1296 throw setError(VBOX_E_IPRT_ERROR, … … 1291 1307 else if (vrc == VERR_S3_ACCESS_DENIED) 1292 1308 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. " 1294 1311 "Also check that your host clock is properly synced"), 1295 1312 pszFilename); … … 1496 1513 PVDINTERFACEIO pFileIo = NULL; 1497 1514 void *pvMfBuf = NULL; 1515 void *pvCertBuf = NULL; 1498 1516 writeLock.release(); 1499 1517 try … … 1505 1523 1506 1524 Utf8Str strMfFile = Utf8Str(pTask->locInfo.strPath).stripExt().append(".mf"); 1525 1507 1526 SHASTORAGE storage; 1508 1527 RT_ZERO(storage); … … 1534 1553 /* Add the ovf file to the digest list. */ 1535 1554 stack.llSrcDisksDigest.push_front(STRPAIR(pTask->locInfo.strPath, m->strOVFSHADigest)); 1536 rc = read ManifestFile(strMfFile, &pvMfBuf, &cbMfSize, pShaIo, &storage);1555 rc = readFileToBuf(strMfFile, &pvMfBuf, &cbMfSize, true, pShaIo, &storage); 1537 1556 if (FAILED(rc)) throw rc; 1538 1557 rc = verifyManifestFile(strMfFile, stack, pvMfBuf, cbMfSize); 1539 1558 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 } 1540 1573 } 1541 1574 else … … 1554 1587 if (pvMfBuf) 1555 1588 RTMemFree(pvMfBuf); 1589 if (pvCertBuf) 1590 RTMemFree(pvCertBuf); 1556 1591 if (pShaIo) 1557 1592 RTMemFree(pShaIo); … … 1570 1605 1571 1606 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); 1573 1610 if (RT_FAILURE(vrc)) 1574 1611 return setError(VBOX_E_FILE_ERROR, … … 1582 1619 char *pszFilename = 0; 1583 1620 void *pvMfBuf = 0; 1621 void *pvCertBuf = 0; 1622 1584 1623 writeLock.release(); 1585 1624 try … … 1629 1668 else 1630 1669 { 1670 RTTarCurrentFile(tar, &pszFilename); 1631 1671 if (vrc == VINF_TAR_DIR_PATH) 1632 1672 { 1633 RTTarCurrentFile(tar, &pszFilename);1634 1673 throw setError(VBOX_E_FILE_ERROR, 1635 1674 tr("Empty directory folder (%s) isn't allowed in the OVA package (%Rrc)"), … … 1662 1701 * If it fails here, we will try it again after all disks where read. 1663 1702 */ 1664 rc = readTar ManifestFile(tar, strMfFile, &pvMfBuf, &cbMfSize, pCallbacks, pStorage);1703 rc = readTarFileToBuf(tar, strMfFile, &pvMfBuf, &cbMfSize, true, pCallbacks, pStorage); 1665 1704 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 1666 1732 /* Now import the appliance. */ 1667 1733 importMachines(stack, pCallbacks, pStorage); … … 1669 1735 if (!pvMfBuf) 1670 1736 { 1671 rc = readTar ManifestFile(tar, strMfFile, &pvMfBuf, &cbMfSize, pCallbacks, pStorage);1737 rc = readTarFileToBuf(tar, strMfFile, &pvMfBuf, &cbMfSize, true, pCallbacks, pStorage); 1672 1738 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 } 1681 1770 } 1682 1771 } … … 1698 1787 if (pTarIo) 1699 1788 RTMemFree(pTarIo); 1789 if (pvCertBuf) 1790 RTMemFree(pvCertBuf); 1700 1791 1701 1792 LogFlowFunc(("rc=%Rhrc\n", rc)); … … 1770 1861 1771 1862 /* 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); 1773 1868 if (RT_FAILURE(vrc)) 1774 1869 throw setError(VBOX_E_IPRT_ERROR, … … 1795 1890 throw setError(E_ACCESSDENIED, 1796 1891 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"), 1798 1894 pszFilename); 1799 1895 else if (vrc == VERR_S3_NOT_FOUND) … … 1831 1927 throw setError(E_ACCESSDENIED, 1832 1928 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"), 1834 1931 pszFilename); 1835 1932 else … … 1898 1995 #endif /* VBOX_WITH_S3 */ 1899 1996 1900 HRESULT Appliance::readManifestFile(const Utf8Str &strFile, void **ppvBuf, size_t *pcbSize, PVDINTERFACEIO pCallbacks, PSHASTORAGE pStorage) 1997 HRESULT Appliance::readFileToBuf(const Utf8Str &strFile, 1998 void **ppvBuf, 1999 size_t *pcbSize, 2000 bool fCreateDigest, 2001 PVDINTERFACEIO pCallbacks, 2002 PSHASTORAGE pStorage) 1901 2003 { 1902 2004 HRESULT rc = S_OK; 1903 2005 1904 bool fOldDigest = pStorage->fCreateDigest; 1905 pStorage->fCreateDigest = f alse; /* No digest for the manifest file */2006 bool fOldDigest = pStorage->fCreateDigest;/* Save the old digest property */ 2007 pStorage->fCreateDigest = fCreateDigest; 1906 2008 int vrc = ShaReadBuf(strFile.c_str(), ppvBuf, pcbSize, pCallbacks, pStorage); 1907 2009 if ( RT_FAILURE(vrc) 1908 2010 && vrc != VERR_FILE_NOT_FOUND) 1909 2011 rc = setError(VBOX_E_FILE_ERROR, 1910 tr("Could not read manifestfile '%s' (%Rrc)"),2012 tr("Could not read file '%s' (%Rrc)"), 1911 2013 RTPathFilename(strFile.c_str()), vrc); 1912 2014 pStorage->fCreateDigest = fOldDigest; /* Restore the old digest creation behavior again. */ … … 1915 2017 } 1916 2018 1917 HRESULT Appliance::readTarManifestFile(RTTAR tar, const Utf8Str &strFile, void **ppvBuf, size_t *pcbSize, PVDINTERFACEIO pCallbacks, PSHASTORAGE pStorage) 2019 HRESULT Appliance::readTarFileToBuf(RTTAR tar, 2020 const Utf8Str &strFile, 2021 void **ppvBuf, 2022 size_t *pcbSize, 2023 bool fCreateDigest, 2024 PVDINTERFACEIO pCallbacks, 2025 PSHASTORAGE pStorage) 1918 2026 { 1919 2027 HRESULT rc = S_OK; … … 1933 2041 { 1934 2042 if (!strcmp(pszCurFile, RTPathFilename(strFile.c_str()))) 1935 rc = read ManifestFile(strFile, ppvBuf, pcbSize, pCallbacks, pStorage);2043 rc = readFileToBuf(strFile, ppvBuf, pcbSize, fCreateDigest, pCallbacks, pStorage); 1936 2044 RTStrFree(pszCurFile); 1937 2045 } … … 1993 2101 int32_t &lDevice) 1994 2102 { 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)); 1996 2107 1997 2108 switch (hdc.system) … … 2089 2200 * 2090 2201 * @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)2092 2202 * @param strTargetPath Where to create the target image. 2093 2203 * @param pTargetHD out: The newly created target disk. This also gets pushed on stack.llHardDisksCreated for cleanup. … … 2095 2205 */ 2096 2206 void Appliance::importOneDiskImage(const ovf::DiskImage &di, 2097 const Utf8Str &strTargetPath,2207 Utf8Str *strTargetPath, 2098 2208 ComObjPtr<Medium> &pTargetHD, 2099 2209 ImportStack &stack, … … 2101 2211 PSHASTORAGE pStorage) 2102 2212 { 2213 SHASTORAGE finalStorage; 2214 PSHASTORAGE pRealUsedStorage = pStorage;/* may be changed later to finalStorage */ 2215 PVDINTERFACEIO pFileIo = NULL;/* used in GZIP case*/ 2103 2216 ComObjPtr<Progress> pProgress; 2104 2217 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); 2106 2223 if (FAILED(rc)) throw rc; 2107 2224 … … 2109 2226 SystemProperties *pSysProps = mVirtualBox->getSystemProperties(); 2110 2227 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 */ 2111 2232 const Utf8Str &strSourceOVF = di.strHref; 2112 2233 2113 2234 Utf8Str strSrcFilePath(stack.strSourceDir); 2235 Utf8Str strTargetDir(*strTargetPath); 2236 2114 2237 /* Construct source file path */ 2115 2238 Utf8Str name = applianceIOName(applianceIOTar); … … 2127 2250 * example. */ 2128 2251 RTUUID uuid; 2129 int vrc = RTUuidFromStr(&uuid, strTargetPath .c_str());2252 int vrc = RTUuidFromStr(&uuid, strTargetPath->c_str()); 2130 2253 if (vrc == VINF_SUCCESS) 2131 2254 { … … 2135 2258 else 2136 2259 { 2137 Utf8Str strTrgFormat = "VMDK"; 2138 ULONG lCabs = 0; 2139 2140 if (RTPathHaveExt(strTargetPath.c_str())) 2260 /* check read file to GZIP compression */ 2261 try 2141 2262 { 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 2194 2334 { 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]; 2198 2337 } 2199 2338 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 2204 2359 { 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) 2210 2369 { 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); 2220 2404 } 2221 2405 } 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 } 2229 2496 } 2230 else/* HDD case*/2497 catch (...) 2231 2498 { 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; 2297 2503 } 2298 2504 } 2505 2506 if (pFileIo) 2507 RTMemFree(pFileIo); 2299 2508 2300 2509 /* Add the newly create disk path + a corresponding digest the our list for 2301 2510 * later manifest verification. */ 2302 stack.llSrcDisksDigest.push_back(STRPAIR(strS rcFilePath, pStorage ? pStorage->strDigest : ""));2511 stack.llSrcDisksDigest.push_back(STRPAIR(strSourceOVF, pStorage ? pStorage->strDigest : "")); 2303 2512 } 2304 2513 … … 2432 2641 else if (vsdeNW.size() > maxNetworkAdapters) 2433 2642 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"), 2435 2645 vsdeNW.size(), maxNetworkAdapters); 2436 2646 else … … 2540 2750 // IDE Hard disk controller 2541 2751 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 */ 2544 2757 size_t cIDEControllers = vsdeHDCIDE.size(); 2545 2758 if (cIDEControllers > 2) … … 2578 2791 if (hdcVBox == "AHCI") 2579 2792 { 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()); 2581 2796 if (FAILED(rc)) throw rc; 2582 2797 } … … 2629 2844 { 2630 2845 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()); 2632 2849 if (FAILED(rc)) throw rc; 2633 2850 rc = pController->COMSETTER(ControllerType)(StorageControllerType_LsiLogicSas); … … 2674 2891 { 2675 2892 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()); 2677 2896 if (FAILED(rc)) throw rc; 2678 2897 … … 2735 2954 while(oit != stack.mapDisks.end()) 2736 2955 { 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 2751 2956 ovf::DiskImage diCurrent = oit->second; 2752 2957 ovf::VirtualDisksMap::const_iterator itVDisk = vsysThis.mapVirtualDisks.begin(); … … 2789 2994 2790 2995 /* 2791 *2792 2996 * preliminary check availability of the image 2793 2997 * This step is useful if image is placed in the OVA (TAR) package 2794 *2795 2998 */ 2796 2999 … … 2820 3023 { 2821 3024 /* 2822 *2823 3025 * availableImage contains the disk file reference (e.g. "disk1.vmdk"), which should exist 2824 3026 * in the global images map. … … 2847 3049 2848 3050 /* 2849 *2850 3051 * Again iterate over all given disk images of the virtual system 2851 3052 * disks description using the found disk image 2852 *2853 3053 */ 2854 3054 { … … 2901 3101 ComObjPtr<Medium> pTargetHD; 2902 3102 3103 Utf8Str savedVboxCurrent = vsdeTargetHD->strVboxCurrent; 3104 2903 3105 importOneDiskImage(diCurrent, 2904 vsdeTargetHD->strVboxCurrent,3106 &vsdeTargetHD->strVboxCurrent, 2905 3107 pTargetHD, 2906 3108 stack, … … 2965 3167 rc = sMachine->SaveSettings(); 2966 3168 if (FAILED(rc)) throw rc; 3169 3170 /* restore */ 3171 vsdeTargetHD->strVboxCurrent = savedVboxCurrent; 3172 2967 3173 } // end while(oit != stack.mapDisks.end()) 2968 3174 … … 3024 3230 3025 3231 /* 3026 *3027 3232 * step 1): modify machine config according to OVF config, in case the user 3028 3233 * has modified them using setFinalValues() 3029 *3030 3234 */ 3031 3235 … … 3168 3372 3169 3373 /* 3170 *3171 3374 * step 2: scan the machine config for media attachments 3172 *3173 3375 */ 3174 3376 … … 3187 3389 while(oit != stack.mapDisks.end()) 3188 3390 { 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 3203 3391 ovf::DiskImage diCurrent = oit->second; 3204 3392 … … 3228 3416 3229 3417 /* 3230 *3231 3418 * preliminary check availability of the image 3232 3419 * This step is useful if image is placed in the OVA (TAR) package 3233 *3234 3420 */ 3235 3421 … … 3279 3465 diCurrent = *(&itDiskImage->second); 3280 3466 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 3282 3469 * disks description using the found disk image 3283 3470 */ … … 3376 3563 continue; 3377 3564 } 3565 3378 3566 /* 3379 *3380 3567 * step 3: import disk 3381 *3382 3568 */ 3569 Utf8Str savedVboxCurrent = vsdeTargetHD->strVboxCurrent; 3383 3570 ComObjPtr<Medium> pTargetHD; 3384 3571 importOneDiskImage(diCurrent, 3385 vsdeTargetHD->strVboxCurrent,3572 &vsdeTargetHD->strVboxCurrent, 3386 3573 pTargetHD, 3387 3574 stack, … … 3418 3605 } 3419 3606 3607 /* restore */ 3608 vsdeTargetHD->strVboxCurrent = savedVboxCurrent; 3609 3420 3610 d.uuid = hdId; 3421 3611 fFound = true; … … 3434 3624 3435 3625 /* 3436 *3437 3626 * step 4): create the machine and have it import the config 3438 *3439 3627 */ 3440 3628 … … 3446 3634 // instance that we created from the vbox:Machine 3447 3635 rc = pNewMachine->init(mVirtualBox, 3448 stack.strNameVBox,// name from OVF preparations; can be suffixed to avoid duplicates , or changed by user3636 stack.strNameVBox,// name from OVF preparations; can be suffixed to avoid duplicates 3449 3637 config); // the whole machine config 3450 3638 if (FAILED(rc)) throw rc; -
trunk/src/VBox/Runtime/common/zip/zip.cpp
r44528 r47340 575 575 { 576 576 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); 578 579 579 580 /* … … 1927 1928 RT_EXPORT_SYMBOL(RTZipBlockDecompress); 1928 1929 1930 RTDECL(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 1968 RT_EXPORT_SYMBOL(RTZipGzipDecompressBuffer);
Note:
See TracChangeset
for help on using the changeset viewer.