儲存庫 vbox 的更動 40329
- 時間撮記:
- 2012-3-2 下午04:13:50 (13 年 以前)
- 位置:
- trunk
- 檔案:
-
- 修改 11 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/include/iprt/manifest.h
r39877 r40329 58 58 /** @} */ 59 59 60 /** @name Digest types. */ 61 typedef enum RTDIGESTTYPE 62 { 63 /** CRC32 checksum */ 64 RTDIGESTTYPE_CRC32 = 1, 65 /** CRC64 checksum */ 66 RTDIGESTTYPE_CRC64, 67 /** MD5 checksum (unsafe!) */ 68 RTDIGESTTYPE_MD5, 69 /** SHA1 checksum (unsafe!) */ 70 RTDIGESTTYPE_SHA1, 71 /** SHA256 checksum */ 72 RTDIGESTTYPE_SHA256, 73 /** SHA512 checksum */ 74 RTDIGESTTYPE_SHA512 75 } RTDIGESTTYPE; 76 /** @} */ 77 60 78 61 79 /** … … 399 417 /** 400 418 * Input structure for RTManifestVerify() which contains the filename & the 401 * SHA1 digest.419 * SHA1/SHA256 digest. 402 420 */ 403 421 typedef struct RTMANIFESTTEST … … 405 423 /** The filename. */ 406 424 const char *pszTestFile; 407 /** The SHA1 digest of the file. */425 /** The SHA1/SHA256 digest of the file. */ 408 426 const char *pszTestDigest; 409 427 } RTMANIFESTTEST; … … 457 475 * 458 476 * @param pszManifestFile Filename of the manifest file to create. 477 * @param enmDigestType The digest type (RTDIGESTTYPE_*) 459 478 * @param papszFiles Array of files to create SHA1 sums for. 460 479 * @param cFiles Number of entries in papszFiles. … … 462 481 * @param pvUser user defined pointer for the callback 463 482 */ 464 RTR3DECL(int) RTManifestWriteFiles(const char *pszManifestFile, const char * const *papszFiles, size_t cFiles, 483 RTR3DECL(int) RTManifestWriteFiles(const char *pszManifestFile, RTDIGESTTYPE enmDigestType, 484 const char * const *papszFiles, size_t cFiles, 465 485 PFNRTPROGRESS pfnProgressCallback, void *pvUser); 466 486 … … 490 510 * @param ppvBuf Pointer to resulting memory buffer. 491 511 * @param pcbSize Pointer for the size of the memory buffer. 512 * @param enmDigestType Which type of digest ("SHA1", "SHA256", ...) 492 513 * @param paFiles Array of file names and digests. 493 514 * @param cFiles Number of entries in paFiles. 494 515 */ 495 RTR3DECL(int) RTManifestWriteFilesBuf(void **ppvBuf, size_t *pcbSize, PRTMANIFESTTEST paFiles, size_t cFiles);516 RTR3DECL(int) RTManifestWriteFilesBuf(void **ppvBuf, size_t *pcbSize, RTDIGESTTYPE enmDigestType, PRTMANIFESTTEST paFiles, size_t cFiles); 496 517 497 518 /** @} */ -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageAppliance.cpp
r38525 r40329 794 794 { "--output", 'o', RTGETOPT_REQ_STRING }, 795 795 { "--legacy09", 'l', RTGETOPT_REQ_NOTHING }, 796 { "--ovf09", 'l', RTGETOPT_REQ_NOTHING }, 797 { "--ovf10", '1', RTGETOPT_REQ_NOTHING }, 798 { "--ovf20", '2', RTGETOPT_REQ_NOTHING }, 796 799 { "--manifest", 'm', RTGETOPT_REQ_NOTHING }, 797 800 { "--vsys", 's', RTGETOPT_REQ_UINT32 }, … … 837 840 else 838 841 strOutputFile = ValueUnion.psz; 839 break;840 841 case 'l': // --legacy09 842 break; 843 844 case 'l': // --legacy09/--ovf09 842 845 strOvfFormat = "ovf-0.9"; 843 break; 846 break; 847 848 case '1': // --ovf10 849 strOvfFormat = "ovf-1.0"; 850 break; 851 852 case '2': // --ovf20 853 strOvfFormat = "ovf-2.0"; 854 break; 844 855 845 856 case 'm': // --manifest 846 857 fManifest = true; 847 break;858 break; 848 859 849 860 case 's': // --vsys 850 861 ulCurVsys = ValueUnion.u32; 851 break;862 break; 852 863 853 864 case 'p': // --product … … 855 866 return errorSyntax(USAGE_EXPORTAPPLIANCE, "Option \"%s\" requires preceding --vsys argument.", GetState.pDef->pszLong); 856 867 mapArgsMapsPerVsys[ulCurVsys]["product"] = ValueUnion.psz; 857 break;868 break; 858 869 859 870 case 'P': // --producturl … … 861 872 return errorSyntax(USAGE_EXPORTAPPLIANCE, "Option \"%s\" requires preceding --vsys argument.", GetState.pDef->pszLong); 862 873 mapArgsMapsPerVsys[ulCurVsys]["producturl"] = ValueUnion.psz; 863 break;874 break; 864 875 865 876 case 'd': // --vendor … … 867 878 return errorSyntax(USAGE_EXPORTAPPLIANCE, "Option \"%s\" requires preceding --vsys argument.", GetState.pDef->pszLong); 868 879 mapArgsMapsPerVsys[ulCurVsys]["vendor"] = ValueUnion.psz; 869 break;880 break; 870 881 871 882 case 'D': // --vendorurl … … 873 884 return errorSyntax(USAGE_EXPORTAPPLIANCE, "Option \"%s\" requires preceding --vsys argument.", GetState.pDef->pszLong); 874 885 mapArgsMapsPerVsys[ulCurVsys]["vendorurl"] = ValueUnion.psz; 875 break;886 break; 876 887 877 888 case 'v': // --version … … 879 890 return errorSyntax(USAGE_EXPORTAPPLIANCE, "Option \"%s\" requires preceding --vsys argument.", GetState.pDef->pszLong); 880 891 mapArgsMapsPerVsys[ulCurVsys]["version"] = ValueUnion.psz; 881 break;892 break; 882 893 883 894 case 'e': // --eula … … 885 896 return errorSyntax(USAGE_EXPORTAPPLIANCE, "Option \"%s\" requires preceding --vsys argument.", GetState.pDef->pszLong); 886 897 mapArgsMapsPerVsys[ulCurVsys]["eula"] = ValueUnion.psz; 887 break;898 break; 888 899 889 900 case 'E': // --eulafile … … 891 902 return errorSyntax(USAGE_EXPORTAPPLIANCE, "Option \"%s\" requires preceding --vsys argument.", GetState.pDef->pszLong); 892 903 mapArgsMapsPerVsys[ulCurVsys]["eulafile"] = ValueUnion.psz; 893 break;904 break; 894 905 895 906 case VINF_GETOPT_NOT_OPTION: … … 902 913 if (machine) 903 914 llMachines.push_back(machine); 915 break; 904 916 } 905 break;906 917 907 918 default: -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp
r40324 r40329 360 360 RTStrmPrintf(pStrm, 361 361 "VBoxManage export <machines> --output|-o <ovf/ova>\n" 362 " [--legacy09 ]\n"362 " [--legacy09|--ovf09|--ovf10|--ovf20]\n" 363 363 " [--manifest]\n" 364 364 " [--vsys <number of virtual system>]\n" -
trunk/src/VBox/Main/idl/VirtualBox.xidl
r40212 r40329 2617 2617 <param name="format" type="wstring" dir="in"> 2618 2618 <desc> 2619 Output format, as a string. Currently supported formats are "ovf-0.9" and "ovf-1.0";2620 future versions of VirtualBox may support additional formats.2619 Output format, as a string. Currently supported formats are "ovf-0.9", "ovf-1.0" 2620 and "ovf-2.0"; future versions of VirtualBox may support additional formats. 2621 2621 </desc> 2622 2622 </param> -
trunk/src/VBox/Main/include/ApplianceImpl.h
r38455 r40329 35 35 typedef struct VDINTERFACE *PVDINTERFACE; 36 36 typedef struct VDINTERFACEIO *PVDINTERFACEIO; 37 typedef struct SHA 1STORAGE *PSHA1STORAGE;37 typedef struct SHASTORAGE *PSHASTORAGE; 38 38 39 39 namespace ovf … … 77 77 unspecified, 78 78 OVF_0_9, 79 OVF_1_0 79 OVF_1_0, 80 OVF_2_0 80 81 }; 81 82 … … 150 151 HRESULT readFSOVF(TaskOVF *pTask); 151 152 HRESULT readFSOVA(TaskOVF *pTask); 152 HRESULT readFSImpl(TaskOVF *pTask, const RTCString &strFilename, PVDINTERFACEIO pCallbacks, PSHA 1STORAGE pStorage);153 HRESULT readFSImpl(TaskOVF *pTask, const RTCString &strFilename, PVDINTERFACEIO pCallbacks, PSHASTORAGE pStorage); 153 154 HRESULT readS3(TaskOVF *pTask); 154 155 … … 164 165 HRESULT importS3(TaskOVF *pTask); 165 166 166 HRESULT readManifestFile(const Utf8Str &strFile, void **ppvBuf, size_t *pcbSize, PVDINTERFACEIO pCallbacks, PSHA 1STORAGE pStorage);167 HRESULT readTarManifestFile(RTTAR tar, const Utf8Str &strFile, void **ppvBuf, size_t *pcbSize, PVDINTERFACEIO pCallbacks, PSHA 1STORAGE pStorage);167 HRESULT readManifestFile(const Utf8Str &strFile, void **ppvBuf, size_t *pcbSize, PVDINTERFACEIO pCallbacks, PSHASTORAGE pStorage); 168 HRESULT readTarManifestFile(RTTAR tar, const Utf8Str &strFile, void **ppvBuf, size_t *pcbSize, PVDINTERFACEIO pCallbacks, PSHASTORAGE pStorage); 168 169 HRESULT verifyManifestFile(const Utf8Str &strFile, ImportStack &stack, void *pvBuf, size_t cbSize); 169 170 … … 179 180 ImportStack &stack, 180 181 PVDINTERFACEIO pCallbacks, 181 PSHA 1STORAGE pStorage);182 PSHASTORAGE pStorage); 182 183 void importMachineGeneric(const ovf::VirtualSystem &vsysThis, 183 184 ComObjPtr<VirtualSystemDescription> &vsdescThis, … … 185 186 ImportStack &stack, 186 187 PVDINTERFACEIO pCallbacks, 187 PSHA 1STORAGE pStorage);188 PSHASTORAGE pStorage); 188 189 void importVBoxMachine(ComObjPtr<VirtualSystemDescription> &vsdescThis, 189 190 ComPtr<IMachine> &pNewMachine, 190 191 ImportStack &stack, 191 192 PVDINTERFACEIO pCallbacks, 192 PSHA 1STORAGE pStorage);193 PSHASTORAGE pStorage); 193 194 void importMachines(ImportStack &stack, 194 195 PVDINTERFACEIO pCallbacks, 195 PSHA 1STORAGE pStorage);196 PSHASTORAGE pStorage); 196 197 197 198 /******************************************************************************* … … 204 205 HRESULT writeFSOVF(TaskOVF *pTask, AutoWriteLockBase& writeLock); 205 206 HRESULT writeFSOVA(TaskOVF *pTask, AutoWriteLockBase& writeLock); 206 HRESULT writeFSImpl(TaskOVF *pTask, AutoWriteLockBase& writeLock, PVDINTERFACEIO pCallbacks, PSHA 1STORAGE pStorage);207 HRESULT writeFSImpl(TaskOVF *pTask, AutoWriteLockBase& writeLock, PVDINTERFACEIO pCallbacks, PSHASTORAGE pStorage); 207 208 HRESULT writeS3(TaskOVF *pTask); 208 209 -
trunk/src/VBox/Main/include/ApplianceImplPrivate.h
r38469 r40329 52 52 : state(ApplianceIdle) 53 53 , fManifest(true) 54 , fSha256(false) 54 55 , pReader(NULL) 55 56 , ulWeightForXmlOperation(0) … … 73 74 LocationInfo locInfo; // location info for the currently processed OVF 74 75 bool fManifest; // Create a manifest file on export 76 bool fSha256; // true = SHA256 (OVF 2.0), false = SHA1 (OVF 1.0) 75 77 RTCList<ImportOptions_T> optList; 76 78 … … 86 88 ULONG ulTotalDisksMB; 87 89 ULONG cDisks; 88 Utf8Str strOVFSHA 1Digest;90 Utf8Str strOVFSHADigest; 89 91 90 92 std::list<Guid> llGuidsMachinesCreated; … … 224 226 Utf8Str convertNetworkAttachmentTypeToString(NetworkAttachmentType_T type); 225 227 226 typedef struct SHA 1STORAGE228 typedef struct SHASTORAGE 227 229 { 228 230 PVDINTERFACE pVDImageIfaces; 229 231 bool fCreateDigest; 232 bool fSha256; /* false = SHA1 (OVF 1.x), true = SHA256 (OVF 2.0) */ 230 233 Utf8Str strDigest; 231 } SHA 1STORAGE, *PSHA1STORAGE;232 233 PVDINTERFACEIO Sha 1CreateInterface();234 } SHASTORAGE, *PSHASTORAGE; 235 236 PVDINTERFACEIO ShaCreateInterface(); 234 237 PVDINTERFACEIO FileCreateInterface(); 235 238 PVDINTERFACEIO TarCreateInterface(); 236 int Sha 1ReadBuf(const char *pcszFilename, void **ppvBuf, size_t *pcbSize, PVDINTERFACEIO pIfIo, void *pvUser);237 int Sha 1WriteBuf(const char *pcszFilename, void *pvBuf, size_t cbSize, PVDINTERFACEIO pIfIo, void *pvUser);239 int ShaReadBuf(const char *pcszFilename, void **ppvBuf, size_t *pcbSize, PVDINTERFACEIO pIfIo, void *pvUser); 240 int ShaWriteBuf(const char *pcszFilename, void *pvBuf, size_t cbSize, PVDINTERFACEIO pIfIo, void *pvUser); 238 241 239 242 #endif // ____H_APPLIANCEIMPLPRIVATE -
trunk/src/VBox/Main/src-server/ApplianceImplExport.cpp
r39248 r40329 558 558 else if (strFormat == "ovf-1.0") 559 559 ovfF = OVF_1_0; 560 else if (strFormat == "ovf-2.0") 561 ovfF = OVF_2_0; 560 562 else 561 563 return setError(VBOX_E_FILE_ERROR, 562 564 tr("Invalid format \"%s\" specified"), strFormat.c_str()); 565 566 /* as of OVF 2.0 we have to use SHA256 */ 567 m->fSha256 = ovfF >= OVF_2_0; 563 568 564 569 ComObjPtr<Progress> progress; … … 658 663 xml::ElementNode *pelmRoot = doc.createRootElement("Envelope"); 659 664 660 pelmRoot->setAttribute("ovf:version", (enFormat == OVF_1_0) ? "1.0" : "0.9"); 665 pelmRoot->setAttribute("ovf:version", enFormat == OVF_2_0 ? "2.0" 666 : enFormat == OVF_1_0 ? "1.0" 667 : "0.9"); 661 668 pelmRoot->setAttribute("xml:lang", "en-US"); 662 669 … … 1621 1628 HRESULT rc = S_OK; 1622 1629 1623 PVDINTERFACEIO pSha 1Io = 0;1630 PVDINTERFACEIO pShaIo = 0; 1624 1631 PVDINTERFACEIO pFileIo = 0; 1625 1632 do 1626 1633 { 1627 pSha 1Io = Sha1CreateInterface();1628 if (!pSha 1Io)1634 pShaIo = ShaCreateInterface(); 1635 if (!pShaIo) 1629 1636 { 1630 1637 rc = E_OUTOFMEMORY; … … 1638 1645 } 1639 1646 1640 SHA 1STORAGE storage;1647 SHASTORAGE storage; 1641 1648 RT_ZERO(storage); 1642 1649 storage.fCreateDigest = m->fManifest; 1650 storage.fSha256 = m->fSha256; 1643 1651 int vrc = VDInterfaceAdd(&pFileIo->Core, "Appliance::IOFile", 1644 1652 VDINTERFACETYPE_IO, 0, sizeof(VDINTERFACEIO), … … 1649 1657 break; 1650 1658 } 1651 rc = writeFSImpl(pTask, writeLock, pSha 1Io, &storage);1659 rc = writeFSImpl(pTask, writeLock, pShaIo, &storage); 1652 1660 }while(0); 1653 1661 1654 1662 /* Cleanup */ 1655 if (pSha 1Io)1656 RTMemFree(pSha 1Io);1663 if (pShaIo) 1664 RTMemFree(pShaIo); 1657 1665 if (pFileIo) 1658 1666 RTMemFree(pFileIo); … … 1675 1683 HRESULT rc = S_OK; 1676 1684 1677 PVDINTERFACEIO pSha 1Io = 0;1685 PVDINTERFACEIO pShaIo = 0; 1678 1686 PVDINTERFACEIO pTarIo = 0; 1679 1687 do 1680 1688 { 1681 pSha 1Io = Sha1CreateInterface();1682 if (!pSha 1Io)1689 pShaIo = ShaCreateInterface(); 1690 if (!pShaIo) 1683 1691 { 1684 1692 rc = E_OUTOFMEMORY; … … 1691 1699 break; 1692 1700 } 1693 SHA 1STORAGE storage;1701 SHASTORAGE storage; 1694 1702 RT_ZERO(storage); 1695 1703 storage.fCreateDigest = m->fManifest; 1704 storage.fSha256 = m->fSha256; 1696 1705 vrc = VDInterfaceAdd(&pTarIo->Core, "Appliance::IOTar", 1697 1706 VDINTERFACETYPE_IO, tar, sizeof(VDINTERFACEIO), … … 1702 1711 break; 1703 1712 } 1704 rc = writeFSImpl(pTask, writeLock, pSha 1Io, &storage);1713 rc = writeFSImpl(pTask, writeLock, pShaIo, &storage); 1705 1714 }while(0); 1706 1715 … … 1708 1717 1709 1718 /* Cleanup */ 1710 if (pSha 1Io)1711 RTMemFree(pSha 1Io);1719 if (pShaIo) 1720 RTMemFree(pShaIo); 1712 1721 if (pTarIo) 1713 1722 RTMemFree(pTarIo); … … 1721 1730 } 1722 1731 1723 HRESULT Appliance::writeFSImpl(TaskOVF *pTask, AutoWriteLockBase& writeLock, PVDINTERFACEIO pIfIo, PSHA 1STORAGE pStorage)1732 HRESULT Appliance::writeFSImpl(TaskOVF *pTask, AutoWriteLockBase& writeLock, PVDINTERFACEIO pIfIo, PSHASTORAGE pStorage) 1724 1733 { 1725 1734 LogFlowFuncEnter(); … … 1753 1762 strOvfFile.c_str()); 1754 1763 /* Write the ovf file to disk. */ 1755 vrc = Sha 1WriteBuf(strOvfFile.c_str(), pvBuf, cbSize, pIfIo, pStorage);1764 vrc = ShaWriteBuf(strOvfFile.c_str(), pvBuf, cbSize, pIfIo, pStorage); 1756 1765 if (RT_FAILURE(vrc)) 1757 1766 throw setError(VBOX_E_FILE_ERROR, … … 1861 1870 void *pvBuf; 1862 1871 size_t cbSize; 1863 vrc = RTManifestWriteFilesBuf(&pvBuf, &cbSize, paManifestFiles, fileList.size()); 1872 vrc = RTManifestWriteFilesBuf(&pvBuf, &cbSize, m->fSha256 ? RTDIGESTTYPE_SHA256 : RTDIGESTTYPE_SHA1, 1873 paManifestFiles, fileList.size()); 1864 1874 RTMemFree(paManifestFiles); 1865 1875 if (RT_FAILURE(vrc)) … … 1870 1880 pStorage->fCreateDigest = false; 1871 1881 /* Write the manifest file to disk. */ 1872 vrc = Sha 1WriteBuf(strMfFilePath.c_str(), pvBuf, cbSize, pIfIo, pStorage);1882 vrc = ShaWriteBuf(strMfFilePath.c_str(), pvBuf, cbSize, pIfIo, pStorage); 1873 1883 RTMemFree(pvBuf); 1874 1884 if (RT_FAILURE(vrc)) -
trunk/src/VBox/Main/src-server/ApplianceImplIO.cpp
r39352 r40329 53 53 } TARSTORAGEINTERNAL, *PTARSTORAGEINTERNAL; 54 54 55 typedef struct SHA 1STORAGEINTERNAL55 typedef struct SHASTORAGEINTERNAL 56 56 { 57 57 /** Completion callback. */ … … 62 62 uint32_t fOpenMode; 63 63 /** Our own storage handle. */ 64 PSHA 1STORAGE pSha1Storage;64 PSHASTORAGE pShaStorage; 65 65 /** Circular buffer used for transferring data from/to the worker thread. */ 66 66 PRTCIRCBUF pCircBuf; … … 77 77 /** Event for signaling a finished task of the worker thread. */ 78 78 RTSEMEVENT workFinishedEvent; 79 /** SHA1 calculation context. */ 80 RTSHA1CONTEXT ctx; 79 /** SHA1/SHA256 calculation context. */ 80 union 81 { 82 RTSHA1CONTEXT Sha1; 83 RTSHA256CONTEXT Sha256; 84 } ctx; 81 85 /** Write mode only: Memory buffer for writing zeros. */ 82 86 void *pvZeroBuf; … … 87 91 // uint64_t calls; 88 92 // uint64_t waits; 89 } SHA 1STORAGEINTERNAL, *PSHA1STORAGEINTERNAL;93 } SHASTORAGEINTERNAL, *PSHASTORAGEINTERNAL; 90 94 91 95 /****************************************************************************** … … 458 462 459 463 /****************************************************************************** 460 * Internal: RTSha 1interface464 * Internal: RTSha interface 461 465 ******************************************************************************/ 462 466 463 DECLCALLBACK(int) sha 1CalcWorkerThread(RTTHREAD /* aThread */, void *pvUser)464 { 465 /* Validate input. */ 466 AssertPtrReturn(pvUser, VERR_INVALID_POINTER); 467 468 PSHA 1STORAGEINTERNAL pInt = (PSHA1STORAGEINTERNAL)pvUser;469 470 PVDINTERFACEIO pIfIo = VDIfIoGet(pInt->pSha 1Storage->pVDImageIfaces);467 DECLCALLBACK(int) shaCalcWorkerThread(RTTHREAD /* aThread */, void *pvUser) 468 { 469 /* Validate input. */ 470 AssertPtrReturn(pvUser, VERR_INVALID_POINTER); 471 472 PSHASTORAGEINTERNAL pInt = (PSHASTORAGEINTERNAL)pvUser; 473 474 PVDINTERFACEIO pIfIo = VDIfIoGet(pInt->pShaStorage->pVDImageIfaces); 471 475 AssertPtrReturn(pIfIo, VERR_INVALID_PARAMETER); 472 476 … … 526 530 pInt->cbCurFile += cbWritten; 527 531 } 528 /* Update the SHA1 context with the next data block. */532 /* Update the SHA1/SHA256 context with the next data block. */ 529 533 if ( RT_SUCCESS(rc) 530 && pInt->pSha1Storage->fCreateDigest) 531 RTSha1Update(&pInt->ctx, pcBuf, cbAllWritten); 534 && pInt->pShaStorage->fCreateDigest) 535 { 536 if (pInt->pShaStorage->fSha256) 537 RTSha256Update(&pInt->ctx.Sha256, pcBuf, cbAllWritten); 538 else 539 RTSha1Update(&pInt->ctx.Sha1, pcBuf, cbAllWritten); 540 } 532 541 /* Mark the block as empty. */ 533 542 RTCircBufReleaseReadBlock(pInt->pCircBuf, cbAllWritten); … … 585 594 pInt->cbCurFile += cbRead; 586 595 } 587 /* Update the SHA1 context with the next data block. */596 /* Update the SHA1/SHA256 context with the next data block. */ 588 597 if ( RT_SUCCESS(rc) 589 && pInt->pSha1Storage->fCreateDigest) 590 RTSha1Update(&pInt->ctx, pcBuf, cbAllRead); 598 && pInt->pShaStorage->fCreateDigest) 599 { 600 if (pInt->pShaStorage->fSha256) 601 RTSha256Update(&pInt->ctx.Sha256, pcBuf, cbAllRead); 602 else 603 RTSha1Update(&pInt->ctx.Sha1, pcBuf, cbAllRead); 604 } 591 605 /* Mark the block as full. */ 592 606 RTCircBufReleaseWriteBlock(pInt->pCircBuf, cbAllRead); … … 614 628 } 615 629 616 DECLINLINE(int) sha 1SignalManifestThread(PSHA1STORAGEINTERNAL pInt, uint32_t uStatus)630 DECLINLINE(int) shaSignalManifestThread(PSHASTORAGEINTERNAL pInt, uint32_t uStatus) 617 631 { 618 632 ASMAtomicWriteU32(&pInt->u32Status, uStatus); … … 620 634 } 621 635 622 DECLINLINE(int) sha 1WaitForManifestThreadFinished(PSHA1STORAGEINTERNAL pInt)636 DECLINLINE(int) shaWaitForManifestThreadFinished(PSHASTORAGEINTERNAL pInt) 623 637 { 624 638 // RTPrintf("start\n"); … … 640 654 } 641 655 642 DECLINLINE(int) sha 1FlushCurBuf(PSHA1STORAGEINTERNAL pInt)656 DECLINLINE(int) shaFlushCurBuf(PSHASTORAGEINTERNAL pInt) 643 657 { 644 658 int rc = VINF_SUCCESS; … … 646 660 { 647 661 /* Let the write worker thread start immediately. */ 648 rc = sha 1SignalManifestThread(pInt, STATUS_WRITE);662 rc = shaSignalManifestThread(pInt, STATUS_WRITE); 649 663 if (RT_FAILURE(rc)) 650 664 return rc; 651 665 652 666 /* Wait until the write worker thread has finished. */ 653 rc = sha 1WaitForManifestThreadFinished(pInt);667 rc = shaWaitForManifestThreadFinished(pInt); 654 668 } 655 669 … … 657 671 } 658 672 659 static int sha 1OpenCallback(void *pvUser, const char *pszLocation, uint32_t fOpen,673 static int shaOpenCallback(void *pvUser, const char *pszLocation, uint32_t fOpen, 660 674 PFNVDCOMPLETED pfnCompleted, void **ppInt) 661 675 { … … 667 681 AssertReturn((fOpen & RTFILE_O_READWRITE) != RTFILE_O_READWRITE, VERR_INVALID_PARAMETER); /* No read/write allowed */ 668 682 669 PSHA 1STORAGE pSha1Storage = (PSHA1STORAGE)pvUser;670 PVDINTERFACEIO pIfIo = VDIfIoGet(pSha 1Storage->pVDImageIfaces);683 PSHASTORAGE pShaStorage = (PSHASTORAGE)pvUser; 684 PVDINTERFACEIO pIfIo = VDIfIoGet(pShaStorage->pVDImageIfaces); 671 685 AssertPtrReturn(pIfIo, VERR_INVALID_PARAMETER); 672 686 673 687 DEBUG_PRINT_FLOW(); 674 688 675 PSHA 1STORAGEINTERNAL pInt = (PSHA1STORAGEINTERNAL)RTMemAllocZ(sizeof(SHA1STORAGEINTERNAL));689 PSHASTORAGEINTERNAL pInt = (PSHASTORAGEINTERNAL)RTMemAllocZ(sizeof(SHASTORAGEINTERNAL)); 676 690 if (!pInt) 677 691 return VERR_NO_MEMORY; … … 681 695 { 682 696 pInt->pfnCompleted = pfnCompleted; 683 pInt->pSha 1Storage = pSha1Storage;697 pInt->pShaStorage = pShaStorage; 684 698 pInt->fEOF = false; 685 699 pInt->fOpenMode = fOpen; … … 716 730 break; 717 731 /* Create the worker thread. */ 718 rc = RTThreadCreate(&pInt->pWorkerThread, sha 1CalcWorkerThread, pInt, 0, RTTHREADTYPE_MAIN_HEAVY_WORKER, RTTHREADFLAGS_WAITABLE, "SHA1-Worker");732 rc = RTThreadCreate(&pInt->pWorkerThread, shaCalcWorkerThread, pInt, 0, RTTHREADTYPE_MAIN_HEAVY_WORKER, RTTHREADFLAGS_WAITABLE, "SHA-Worker"); 719 733 if (RT_FAILURE(rc)) 720 734 break; 721 735 722 if (pSha1Storage->fCreateDigest) 723 /* Create a SHA1 context the worker thread will work with. */ 724 RTSha1Init(&pInt->ctx); 736 if (pShaStorage->fCreateDigest) 737 { 738 /* Create a SHA1/SHA256 context the worker thread will work with. */ 739 if (pShaStorage->fSha256) 740 RTSha256Init(&pInt->ctx.Sha256); 741 else 742 RTSha1Init(&pInt->ctx.Sha1); 743 } 725 744 726 745 /* Open the file. */ … … 733 752 { 734 753 /* Immediately let the worker thread start the reading. */ 735 rc = sha 1SignalManifestThread(pInt, STATUS_READ);754 rc = shaSignalManifestThread(pInt, STATUS_READ); 736 755 } 737 756 } … … 742 761 if (pInt->pWorkerThread) 743 762 { 744 sha 1SignalManifestThread(pInt, STATUS_END);763 shaSignalManifestThread(pInt, STATUS_END); 745 764 RTThreadWait(pInt->pWorkerThread, RT_INDEFINITE_WAIT, 0); 746 765 } … … 761 780 } 762 781 763 static int sha 1CloseCallback(void *pvUser, void *pvStorage)764 { 765 /* Validate input. */ 766 AssertPtrReturn(pvUser, VERR_INVALID_POINTER); 767 AssertPtrReturn(pvStorage, VERR_INVALID_POINTER); 768 769 PSHA 1STORAGE pSha1Storage = (PSHA1STORAGE)pvUser;770 PVDINTERFACEIO pIfIo = VDIfIoGet(pSha 1Storage->pVDImageIfaces);782 static int shaCloseCallback(void *pvUser, void *pvStorage) 783 { 784 /* Validate input. */ 785 AssertPtrReturn(pvUser, VERR_INVALID_POINTER); 786 AssertPtrReturn(pvStorage, VERR_INVALID_POINTER); 787 788 PSHASTORAGE pShaStorage = (PSHASTORAGE)pvUser; 789 PVDINTERFACEIO pIfIo = VDIfIoGet(pShaStorage->pVDImageIfaces); 771 790 AssertPtrReturn(pIfIo, VERR_INVALID_PARAMETER); 772 791 773 PSHA 1STORAGEINTERNAL pInt = (PSHA1STORAGEINTERNAL)pvStorage;792 PSHASTORAGEINTERNAL pInt = (PSHASTORAGEINTERNAL)pvStorage; 774 793 775 794 DEBUG_PRINT_FLOW(); … … 778 797 779 798 /* Make sure all pending writes are flushed */ 780 rc = sha 1FlushCurBuf(pInt);799 rc = shaFlushCurBuf(pInt); 781 800 782 801 if (pInt->pWorkerThread) 783 802 { 784 803 /* Signal the worker thread to end himself */ 785 rc = sha 1SignalManifestThread(pInt, STATUS_END);804 rc = shaSignalManifestThread(pInt, STATUS_END); 786 805 /* Worker thread stopped? */ 787 806 rc = RTThreadWait(pInt->pWorkerThread, RT_INDEFINITE_WAIT, 0); … … 789 808 790 809 if ( RT_SUCCESS(rc) 791 && pSha 1Storage->fCreateDigest)792 { 793 /* Finally calculate & format the SHA1 sum */794 unsigned char auchDig[RTSHA 1_HASH_SIZE];810 && pShaStorage->fCreateDigest) 811 { 812 /* Finally calculate & format the SHA1/SHA256 sum */ 813 unsigned char auchDig[RTSHA256_HASH_SIZE]; 795 814 char *pszDigest; 796 RTSha1Final(&pInt->ctx, auchDig); 797 rc = RTStrAllocEx(&pszDigest, RTSHA1_DIGEST_LEN + 1); 815 size_t cbDigest; 816 if (pShaStorage->fSha256) 817 { 818 RTSha256Final(&pInt->ctx.Sha256, auchDig); 819 cbDigest = RTSHA256_DIGEST_LEN; 820 } 821 else 822 { 823 RTSha1Final(&pInt->ctx.Sha1, auchDig); 824 cbDigest = RTSHA1_DIGEST_LEN; 825 } 826 rc = RTStrAllocEx(&pszDigest, cbDigest + 1); 798 827 if (RT_SUCCESS(rc)) 799 828 { 800 rc = RTSha1ToString(auchDig, pszDigest, RTSHA1_DIGEST_LEN + 1); 829 if (pShaStorage->fSha256) 830 rc = RTSha256ToString(auchDig, pszDigest, cbDigest + 1); 831 else 832 rc = RTSha1ToString(auchDig, pszDigest, cbDigest + 1); 801 833 if (RT_SUCCESS(rc)) 802 pSha 1Storage->strDigest = pszDigest;834 pShaStorage->strDigest = pszDigest; 803 835 RTStrFree(pszDigest); 804 836 } … … 824 856 } 825 857 826 static int sha 1DeleteCallback(void *pvUser, const char *pcszFilename)827 { 828 /* Validate input. */ 829 AssertPtrReturn(pvUser, VERR_INVALID_POINTER); 830 831 PSHA 1STORAGE pSha1Storage = (PSHA1STORAGE)pvUser;832 PVDINTERFACEIO pIfIo = VDIfIoGet(pSha 1Storage->pVDImageIfaces);858 static int shaDeleteCallback(void *pvUser, const char *pcszFilename) 859 { 860 /* Validate input. */ 861 AssertPtrReturn(pvUser, VERR_INVALID_POINTER); 862 863 PSHASTORAGE pShaStorage = (PSHASTORAGE)pvUser; 864 PVDINTERFACEIO pIfIo = VDIfIoGet(pShaStorage->pVDImageIfaces); 833 865 AssertPtrReturn(pIfIo, VERR_INVALID_PARAMETER); 834 866 … … 838 870 } 839 871 840 static int sha 1MoveCallback(void *pvUser, const char *pcszSrc, const char *pcszDst, unsigned fMove)841 { 842 /* Validate input. */ 843 AssertPtrReturn(pvUser, VERR_INVALID_POINTER); 844 845 PSHA 1STORAGE pSha1Storage = (PSHA1STORAGE)pvUser;846 PVDINTERFACEIO pIfIo = VDIfIoGet(pSha 1Storage->pVDImageIfaces);872 static int shaMoveCallback(void *pvUser, const char *pcszSrc, const char *pcszDst, unsigned fMove) 873 { 874 /* Validate input. */ 875 AssertPtrReturn(pvUser, VERR_INVALID_POINTER); 876 877 PSHASTORAGE pShaStorage = (PSHASTORAGE)pvUser; 878 PVDINTERFACEIO pIfIo = VDIfIoGet(pShaStorage->pVDImageIfaces); 847 879 AssertPtrReturn(pIfIo, VERR_INVALID_PARAMETER); 848 880 … … 853 885 } 854 886 855 static int sha 1GetFreeSpaceCallback(void *pvUser, const char *pcszFilename, int64_t *pcbFreeSpace)856 { 857 /* Validate input. */ 858 AssertPtrReturn(pvUser, VERR_INVALID_POINTER); 859 860 PSHA 1STORAGE pSha1Storage = (PSHA1STORAGE)pvUser;861 PVDINTERFACEIO pIfIo = VDIfIoGet(pSha 1Storage->pVDImageIfaces);887 static int shaGetFreeSpaceCallback(void *pvUser, const char *pcszFilename, int64_t *pcbFreeSpace) 888 { 889 /* Validate input. */ 890 AssertPtrReturn(pvUser, VERR_INVALID_POINTER); 891 892 PSHASTORAGE pShaStorage = (PSHASTORAGE)pvUser; 893 PVDINTERFACEIO pIfIo = VDIfIoGet(pShaStorage->pVDImageIfaces); 862 894 AssertPtrReturn(pIfIo, VERR_INVALID_PARAMETER); 863 895 … … 867 899 } 868 900 869 static int sha 1GetModificationTimeCallback(void *pvUser, const char *pcszFilename, PRTTIMESPEC pModificationTime)870 { 871 /* Validate input. */ 872 AssertPtrReturn(pvUser, VERR_INVALID_POINTER); 873 874 PSHA 1STORAGE pSha1Storage = (PSHA1STORAGE)pvUser;875 PVDINTERFACEIO pIfIo = VDIfIoGet(pSha 1Storage->pVDImageIfaces);901 static int shaGetModificationTimeCallback(void *pvUser, const char *pcszFilename, PRTTIMESPEC pModificationTime) 902 { 903 /* Validate input. */ 904 AssertPtrReturn(pvUser, VERR_INVALID_POINTER); 905 906 PSHASTORAGE pShaStorage = (PSHASTORAGE)pvUser; 907 PVDINTERFACEIO pIfIo = VDIfIoGet(pShaStorage->pVDImageIfaces); 876 908 AssertPtrReturn(pIfIo, VERR_INVALID_PARAMETER); 877 909 … … 882 914 883 915 884 static int sha 1GetSizeCallback(void *pvUser, void *pvStorage, uint64_t *pcbSize)885 { 886 /* Validate input. */ 887 AssertPtrReturn(pvUser, VERR_INVALID_POINTER); 888 AssertPtrReturn(pvStorage, VERR_INVALID_POINTER); 889 890 PSHA 1STORAGE pSha1Storage = (PSHA1STORAGE)pvUser;891 PVDINTERFACEIO pIfIo = VDIfIoGet(pSha 1Storage->pVDImageIfaces);916 static int shaGetSizeCallback(void *pvUser, void *pvStorage, uint64_t *pcbSize) 917 { 918 /* Validate input. */ 919 AssertPtrReturn(pvUser, VERR_INVALID_POINTER); 920 AssertPtrReturn(pvStorage, VERR_INVALID_POINTER); 921 922 PSHASTORAGE pShaStorage = (PSHASTORAGE)pvUser; 923 PVDINTERFACEIO pIfIo = VDIfIoGet(pShaStorage->pVDImageIfaces); 892 924 AssertPtrReturn(pIfIo, VERR_INVALID_PARAMETER); 893 925 894 PSHA 1STORAGEINTERNAL pInt = (PSHA1STORAGEINTERNAL)pvStorage;926 PSHASTORAGEINTERNAL pInt = (PSHASTORAGEINTERNAL)pvStorage; 895 927 896 928 DEBUG_PRINT_FLOW(); … … 906 938 } 907 939 908 static int sha 1SetSizeCallback(void *pvUser, void *pvStorage, uint64_t cbSize)909 { 910 /* Validate input. */ 911 AssertPtrReturn(pvUser, VERR_INVALID_POINTER); 912 AssertPtrReturn(pvStorage, VERR_INVALID_POINTER); 913 914 PSHA 1STORAGE pSha1Storage = (PSHA1STORAGE)pvUser;915 PVDINTERFACEIO pIfIo = VDIfIoGet(pSha 1Storage->pVDImageIfaces);940 static int shaSetSizeCallback(void *pvUser, void *pvStorage, uint64_t cbSize) 941 { 942 /* Validate input. */ 943 AssertPtrReturn(pvUser, VERR_INVALID_POINTER); 944 AssertPtrReturn(pvStorage, VERR_INVALID_POINTER); 945 946 PSHASTORAGE pShaStorage = (PSHASTORAGE)pvUser; 947 PVDINTERFACEIO pIfIo = VDIfIoGet(pShaStorage->pVDImageIfaces); 916 948 AssertPtrReturn(pIfIo, VERR_INVALID_PARAMETER); 917 949 918 PSHA 1STORAGEINTERNAL pInt = (PSHA1STORAGEINTERNAL)pvStorage;950 PSHASTORAGEINTERNAL pInt = (PSHASTORAGEINTERNAL)pvStorage; 919 951 920 952 DEBUG_PRINT_FLOW(); … … 923 955 } 924 956 925 static int sha 1WriteSyncCallback(void *pvUser, void *pvStorage, uint64_t uOffset,957 static int shaWriteSyncCallback(void *pvUser, void *pvStorage, uint64_t uOffset, 926 958 const void *pvBuf, size_t cbWrite, size_t *pcbWritten) 927 959 { … … 930 962 AssertPtrReturn(pvStorage, VERR_INVALID_POINTER); 931 963 932 PSHA 1STORAGE pSha1Storage = (PSHA1STORAGE)pvUser;933 PVDINTERFACEIO pIfIo = VDIfIoGet(pSha 1Storage->pVDImageIfaces);964 PSHASTORAGE pShaStorage = (PSHASTORAGE)pvUser; 965 PVDINTERFACEIO pIfIo = VDIfIoGet(pShaStorage->pVDImageIfaces); 934 966 AssertPtrReturn(pIfIo, VERR_INVALID_PARAMETER); 935 967 936 PSHA 1STORAGEINTERNAL pInt = (PSHA1STORAGEINTERNAL)pvStorage;968 PSHASTORAGEINTERNAL pInt = (PSHASTORAGEINTERNAL)pvStorage; 937 969 938 970 DEBUG_PRINT_FLOW(); … … 956 988 size_t cbToWrite = RT_MIN(pInt->cbZeroBuf, cbSize - cbAllWritten); 957 989 size_t cbWritten = 0; 958 rc = sha 1WriteSyncCallback(pvUser, pvStorage, pInt->cbCurAll,959 990 rc = shaWriteSyncCallback(pvUser, pvStorage, pInt->cbCurAll, 991 pInt->pvZeroBuf, cbToWrite, &cbWritten); 960 992 if (RT_FAILURE(rc)) 961 993 break; … … 981 1013 if ((cbWrite - cbAllWritten) > cbAvail) 982 1014 { 983 rc = sha 1SignalManifestThread(pInt, STATUS_WRITE);1015 rc = shaSignalManifestThread(pInt, STATUS_WRITE); 984 1016 if(RT_FAILURE(rc)) 985 1017 break; … … 987 1019 if (cbAvail == 0) 988 1020 { 989 rc = sha 1WaitForManifestThreadFinished(pInt);1021 rc = shaWaitForManifestThreadFinished(pInt); 990 1022 if (RT_FAILURE(rc)) 991 1023 break; … … 1013 1045 if ( RT_SUCCESS(rc) 1014 1046 && RTCircBufUsed(pInt->pCircBuf) >= (RTCircBufSize(pInt->pCircBuf) / 2)) 1015 rc = sha 1SignalManifestThread(pInt, STATUS_WRITE);1047 rc = shaSignalManifestThread(pInt, STATUS_WRITE); 1016 1048 1017 1049 return rc; 1018 1050 } 1019 1051 1020 static int sha 1ReadSyncCallback(void *pvUser, void *pvStorage, uint64_t uOffset,1021 1022 { 1023 /* Validate input. */ 1024 AssertPtrReturn(pvUser, VERR_INVALID_POINTER); 1025 AssertPtrReturn(pvStorage, VERR_INVALID_POINTER); 1026 1027 PSHA 1STORAGE pSha1Storage = (PSHA1STORAGE)pvUser;1028 PVDINTERFACEIO pIfIo = VDIfIoGet(pSha 1Storage->pVDImageIfaces);1052 static int shaReadSyncCallback(void *pvUser, void *pvStorage, uint64_t uOffset, 1053 void *pvBuf, size_t cbRead, size_t *pcbRead) 1054 { 1055 /* Validate input. */ 1056 AssertPtrReturn(pvUser, VERR_INVALID_POINTER); 1057 AssertPtrReturn(pvStorage, VERR_INVALID_POINTER); 1058 1059 PSHASTORAGE pShaStorage = (PSHASTORAGE)pvUser; 1060 PVDINTERFACEIO pIfIo = VDIfIoGet(pShaStorage->pVDImageIfaces); 1029 1061 AssertPtrReturn(pIfIo, VERR_INVALID_PARAMETER); 1030 1062 1031 1063 // DEBUG_PRINT_FLOW(); 1032 1064 1033 PSHA 1STORAGEINTERNAL pInt = (PSHA1STORAGEINTERNAL)pvStorage;1065 PSHASTORAGEINTERNAL pInt = (PSHASTORAGEINTERNAL)pvStorage; 1034 1066 1035 1067 int rc = VINF_SUCCESS; … … 1039 1071 1040 1072 /* Check if we jump forward in the file. If so we have to read the 1041 * remaining stuff in the gap anyway (SHA1 ; streaming). */1073 * remaining stuff in the gap anyway (SHA1/SHA256; streaming). */ 1042 1074 if (pInt->cbCurAll < uOffset) 1043 1075 { 1044 rc = sha 1ReadSyncCallback(pvUser, pvStorage, pInt->cbCurAll, 0,1045 1076 rc = shaReadSyncCallback(pvUser, pvStorage, pInt->cbCurAll, 0, 1077 (size_t)(uOffset - pInt->cbCurAll), 0); 1046 1078 if (RT_FAILURE(rc)) 1047 1079 return rc; … … 1066 1098 if ((cbRead - cbAllRead) > cbAvail) 1067 1099 { 1068 rc = sha 1SignalManifestThread(pInt, STATUS_READ);1100 rc = shaSignalManifestThread(pInt, STATUS_READ); 1069 1101 if(RT_FAILURE(rc)) 1070 1102 break; … … 1072 1104 if (cbAvail == 0) 1073 1105 { 1074 rc = sha 1WaitForManifestThreadFinished(pInt);1106 rc = shaWaitForManifestThreadFinished(pInt); 1075 1107 if (RT_FAILURE(rc)) 1076 1108 break; … … 1103 1135 if ( RT_SUCCESS(rc) 1104 1136 && RTCircBufFree(pInt->pCircBuf) >= (RTCircBufSize(pInt->pCircBuf) / 2)) 1105 rc = sha 1SignalManifestThread(pInt, STATUS_READ);1137 rc = shaSignalManifestThread(pInt, STATUS_READ); 1106 1138 1107 1139 return rc; 1108 1140 } 1109 1141 1110 static int sha 1FlushSyncCallback(void *pvUser, void *pvStorage)1111 { 1112 /* Validate input. */ 1113 AssertPtrReturn(pvUser, VERR_INVALID_POINTER); 1114 AssertPtrReturn(pvStorage, VERR_INVALID_POINTER); 1115 1116 PSHA 1STORAGE pSha1Storage = (PSHA1STORAGE)pvUser;1117 PVDINTERFACEIO pIfIo = VDIfIoGet(pSha 1Storage->pVDImageIfaces);1142 static int shaFlushSyncCallback(void *pvUser, void *pvStorage) 1143 { 1144 /* Validate input. */ 1145 AssertPtrReturn(pvUser, VERR_INVALID_POINTER); 1146 AssertPtrReturn(pvStorage, VERR_INVALID_POINTER); 1147 1148 PSHASTORAGE pShaStorage = (PSHASTORAGE)pvUser; 1149 PVDINTERFACEIO pIfIo = VDIfIoGet(pShaStorage->pVDImageIfaces); 1118 1150 AssertPtrReturn(pIfIo, VERR_INVALID_PARAMETER); 1119 1151 1120 1152 DEBUG_PRINT_FLOW(); 1121 1153 1122 PSHA 1STORAGEINTERNAL pInt = (PSHA1STORAGEINTERNAL)pvStorage;1154 PSHASTORAGEINTERNAL pInt = (PSHASTORAGEINTERNAL)pvStorage; 1123 1155 1124 1156 /* Check if there is still something in the buffer. If yes, flush it. */ 1125 int rc = sha 1FlushCurBuf(pInt);1157 int rc = shaFlushCurBuf(pInt); 1126 1158 if (RT_FAILURE(rc)) 1127 1159 return rc; … … 1134 1166 ******************************************************************************/ 1135 1167 1136 PVDINTERFACEIO Sha 1CreateInterface()1168 PVDINTERFACEIO ShaCreateInterface() 1137 1169 { 1138 1170 PVDINTERFACEIO pCallbacks = (PVDINTERFACEIO)RTMemAllocZ(sizeof(VDINTERFACEIO)); … … 1140 1172 return NULL; 1141 1173 1142 pCallbacks->pfnOpen = sha 1OpenCallback;1143 pCallbacks->pfnClose = sha 1CloseCallback;1144 pCallbacks->pfnDelete = sha 1DeleteCallback;1145 pCallbacks->pfnMove = sha 1MoveCallback;1146 pCallbacks->pfnGetFreeSpace = sha 1GetFreeSpaceCallback;1147 pCallbacks->pfnGetModificationTime = sha 1GetModificationTimeCallback;1148 pCallbacks->pfnGetSize = sha 1GetSizeCallback;1149 pCallbacks->pfnSetSize = sha 1SetSizeCallback;1150 pCallbacks->pfnReadSync = sha 1ReadSyncCallback;1151 pCallbacks->pfnWriteSync = sha 1WriteSyncCallback;1152 pCallbacks->pfnFlushSync = sha 1FlushSyncCallback;1174 pCallbacks->pfnOpen = shaOpenCallback; 1175 pCallbacks->pfnClose = shaCloseCallback; 1176 pCallbacks->pfnDelete = shaDeleteCallback; 1177 pCallbacks->pfnMove = shaMoveCallback; 1178 pCallbacks->pfnGetFreeSpace = shaGetFreeSpaceCallback; 1179 pCallbacks->pfnGetModificationTime = shaGetModificationTimeCallback; 1180 pCallbacks->pfnGetSize = shaGetSizeCallback; 1181 pCallbacks->pfnSetSize = shaSetSizeCallback; 1182 pCallbacks->pfnReadSync = shaReadSyncCallback; 1183 pCallbacks->pfnWriteSync = shaWriteSyncCallback; 1184 pCallbacks->pfnFlushSync = shaFlushSyncCallback; 1153 1185 1154 1186 return pCallbacks; … … 1197 1229 } 1198 1230 1199 int Sha 1ReadBuf(const char *pcszFilename, void **ppvBuf, size_t *pcbSize, PVDINTERFACEIO pIfIo, void *pvUser)1231 int ShaReadBuf(const char *pcszFilename, void **ppvBuf, size_t *pcbSize, PVDINTERFACEIO pIfIo, void *pvUser) 1200 1232 { 1201 1233 /* Validate input. */ … … 1263 1295 } 1264 1296 1265 int Sha 1WriteBuf(const char *pcszFilename, void *pvBuf, size_t cbSize, PVDINTERFACEIO pIfIo, void *pvUser)1297 int ShaWriteBuf(const char *pcszFilename, void *pvBuf, size_t cbSize, PVDINTERFACEIO pIfIo, void *pvUser) 1266 1298 { 1267 1299 /* Validate input. */ -
trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp
r39248 r40329 818 818 HRESULT rc = S_OK; 819 819 820 PVDINTERFACEIO pSha 1Io = 0;820 PVDINTERFACEIO pShaIo = 0; 821 821 PVDINTERFACEIO pFileIo = 0; 822 822 do 823 823 { 824 pSha 1Io = Sha1CreateInterface();825 if (!pSha 1Io)824 pShaIo = ShaCreateInterface(); 825 if (!pShaIo) 826 826 { 827 827 rc = E_OUTOFMEMORY; … … 834 834 break; 835 835 } 836 SHA 1STORAGE storage;836 SHASTORAGE storage; 837 837 RT_ZERO(storage); 838 838 int vrc = VDInterfaceAdd(&pFileIo->Core, "Appliance::IOFile", … … 845 845 } 846 846 847 rc = readFSImpl(pTask, pTask->locInfo.strPath, pSha 1Io, &storage);847 rc = readFSImpl(pTask, pTask->locInfo.strPath, pShaIo, &storage); 848 848 }while(0); 849 849 850 850 /* Cleanup */ 851 if (pSha 1Io)852 RTMemFree(pSha 1Io);851 if (pShaIo) 852 RTMemFree(pShaIo); 853 853 if (pFileIo) 854 854 RTMemFree(pFileIo); … … 873 873 HRESULT rc = S_OK; 874 874 875 PVDINTERFACEIO pSha 1Io = 0;875 PVDINTERFACEIO pShaIo = 0; 876 876 PVDINTERFACEIO pTarIo = 0; 877 877 char *pszFilename = 0; … … 884 884 break; 885 885 } 886 pSha 1Io = Sha1CreateInterface();887 if (!pSha 1Io)886 pShaIo = ShaCreateInterface(); 887 if (!pShaIo) 888 888 { 889 889 rc = E_OUTOFMEMORY; … … 896 896 break; 897 897 } 898 SHA 1STORAGE storage;898 SHASTORAGE storage; 899 899 RT_ZERO(storage); 900 900 vrc = VDInterfaceAdd(&pTarIo->Core, "Appliance::IOTar", … … 906 906 break; 907 907 } 908 rc = readFSImpl(pTask, pszFilename, pSha 1Io, &storage);908 rc = readFSImpl(pTask, pszFilename, pShaIo, &storage); 909 909 }while(0); 910 910 … … 914 914 if (pszFilename) 915 915 RTMemFree(pszFilename); 916 if (pSha 1Io)917 RTMemFree(pSha 1Io);916 if (pShaIo) 917 RTMemFree(pShaIo); 918 918 if (pTarIo) 919 919 RTMemFree(pTarIo); … … 925 925 } 926 926 927 HRESULT Appliance::readFSImpl(TaskOVF *pTask, const RTCString &strFilename, PVDINTERFACEIO pIfIo, PSHA 1STORAGE pStorage)927 HRESULT Appliance::readFSImpl(TaskOVF *pTask, const RTCString &strFilename, PVDINTERFACEIO pIfIo, PSHASTORAGE pStorage) 928 928 { 929 929 LogFlowFuncEnter(); … … 938 938 /* Read the OVF into a memory buffer */ 939 939 size_t cbSize = 0; 940 int vrc = Sha 1ReadBuf(strFilename.c_str(), &pvTmpBuf, &cbSize, pIfIo, pStorage);940 int vrc = ShaReadBuf(strFilename.c_str(), &pvTmpBuf, &cbSize, pIfIo, pStorage); 941 941 if ( RT_FAILURE(vrc) 942 942 || !pvTmpBuf) … … 944 944 tr("Could not read OVF file '%s' (%Rrc)"), 945 945 RTPathFilename(strFilename.c_str()), vrc); 946 /* Copy the SHA1 sum of the OVF file for later validation */947 m->strOVFSHA 1Digest = pStorage->strDigest;946 /* Copy the SHA1/SHA256 sum of the OVF file for later validation */ 947 m->strOVFSHADigest = pStorage->strDigest; 948 948 /* Read & parse the XML structure of the OVF file */ 949 949 m->pReader = new ovf::OVFReader(pvTmpBuf, cbSize, pTask->locInfo.strPath); … … 1233 1233 HRESULT rc = S_OK; 1234 1234 1235 PVDINTERFACEIO pSha 1Io = 0;1235 PVDINTERFACEIO pShaIo = 0; 1236 1236 PVDINTERFACEIO pFileIo = 0; 1237 1237 void *pvMfBuf = 0; … … 1240 1240 { 1241 1241 /* Create the necessary file access interfaces. */ 1242 pSha 1Io = Sha1CreateInterface();1243 if (!pSha 1Io)1242 pShaIo = ShaCreateInterface(); 1243 if (!pShaIo) 1244 1244 throw setError(E_OUTOFMEMORY); 1245 1245 pFileIo = FileCreateInterface(); … … 1247 1247 throw setError(E_OUTOFMEMORY); 1248 1248 1249 SHA 1STORAGE storage;1249 SHASTORAGE storage; 1250 1250 RT_ZERO(storage); 1251 1251 storage.fCreateDigest = true; … … 1263 1263 storage.fCreateDigest = RTFileExists(strMfFile.c_str()); 1264 1264 /* Now import the appliance. */ 1265 importMachines(stack, pSha 1Io, &storage);1265 importMachines(stack, pShaIo, &storage); 1266 1266 /* Read & verify the manifest file, if there is one. */ 1267 1267 if (storage.fCreateDigest) 1268 1268 { 1269 1269 /* Add the ovf file to the digest list. */ 1270 stack.llSrcDisksDigest.push_front(STRPAIR(pTask->locInfo.strPath, m->strOVFSHA 1Digest));1271 rc = readManifestFile(strMfFile, &pvMfBuf, &cbMfSize, pSha 1Io, &storage);1270 stack.llSrcDisksDigest.push_front(STRPAIR(pTask->locInfo.strPath, m->strOVFSHADigest)); 1271 rc = readManifestFile(strMfFile, &pvMfBuf, &cbMfSize, pShaIo, &storage); 1272 1272 if (FAILED(rc)) throw rc; 1273 1273 rc = verifyManifestFile(strMfFile, stack, pvMfBuf, cbMfSize); … … 1284 1284 if (pvMfBuf) 1285 1285 RTMemFree(pvMfBuf); 1286 if (pSha 1Io)1287 RTMemFree(pSha 1Io);1286 if (pShaIo) 1287 RTMemFree(pShaIo); 1288 1288 if (pFileIo) 1289 1289 RTMemFree(pFileIo); … … 1308 1308 HRESULT rc = S_OK; 1309 1309 1310 PVDINTERFACEIO pSha 1Io = 0;1310 PVDINTERFACEIO pShaIo = 0; 1311 1311 PVDINTERFACEIO pTarIo = 0; 1312 1312 char *pszFilename = 0; … … 1316 1316 { 1317 1317 /* Create the necessary file access interfaces. */ 1318 pSha 1Io = Sha1CreateInterface();1319 if (!pSha 1Io)1318 pShaIo = ShaCreateInterface(); 1319 if (!pShaIo) 1320 1320 throw setError(E_OUTOFMEMORY); 1321 1321 pTarIo = TarCreateInterface(); … … 1323 1323 throw setError(E_OUTOFMEMORY); 1324 1324 1325 SHA 1STORAGE storage;1325 SHASTORAGE storage; 1326 1326 RT_ZERO(storage); 1327 1327 vrc = VDInterfaceAdd(&pTarIo->Core, "Appliance::IOTar", … … 1345 1345 tr("Seeking within the archive failed (%Rrc)"), vrc); 1346 1346 1347 PVDINTERFACEIO pCallbacks = pSha 1Io;1348 PSHA 1STORAGE pStorage = &storage;1347 PVDINTERFACEIO pCallbacks = pShaIo; 1348 PSHASTORAGE pStorage = &storage; 1349 1349 1350 1350 /* We always need to create the digest, cause we didn't know if there … … 1382 1382 { 1383 1383 /* Add the ovf file to the digest list. */ 1384 stack.llSrcDisksDigest.push_front(STRPAIR(Utf8Str(pszFilename).stripExt().append(".ovf"), m->strOVFSHA 1Digest));1384 stack.llSrcDisksDigest.push_front(STRPAIR(Utf8Str(pszFilename).stripExt().append(".ovf"), m->strOVFSHADigest)); 1385 1385 rc = verifyManifestFile(strMfFile, stack, pvMfBuf, cbMfSize); 1386 1386 if (FAILED(rc)) throw rc; … … 1400 1400 if (pvMfBuf) 1401 1401 RTMemFree(pvMfBuf); 1402 if (pSha 1Io)1403 RTMemFree(pSha 1Io);1402 if (pShaIo) 1403 RTMemFree(pShaIo); 1404 1404 if (pTarIo) 1405 1405 RTMemFree(pTarIo); … … 1604 1604 #endif /* VBOX_WITH_S3 */ 1605 1605 1606 HRESULT Appliance::readManifestFile(const Utf8Str &strFile, void **ppvBuf, size_t *pcbSize, PVDINTERFACEIO pCallbacks, PSHA 1STORAGE pStorage)1606 HRESULT Appliance::readManifestFile(const Utf8Str &strFile, void **ppvBuf, size_t *pcbSize, PVDINTERFACEIO pCallbacks, PSHASTORAGE pStorage) 1607 1607 { 1608 1608 HRESULT rc = S_OK; … … 1610 1610 bool fOldDigest = pStorage->fCreateDigest; 1611 1611 pStorage->fCreateDigest = false; /* No digest for the manifest file */ 1612 int vrc = Sha 1ReadBuf(strFile.c_str(), ppvBuf, pcbSize, pCallbacks, pStorage);1612 int vrc = ShaReadBuf(strFile.c_str(), ppvBuf, pcbSize, pCallbacks, pStorage); 1613 1613 if ( RT_FAILURE(vrc) 1614 1614 && vrc != VERR_FILE_NOT_FOUND) … … 1621 1621 } 1622 1622 1623 HRESULT Appliance::readTarManifestFile(RTTAR tar, const Utf8Str &strFile, void **ppvBuf, size_t *pcbSize, PVDINTERFACEIO pCallbacks, PSHA 1STORAGE pStorage)1623 HRESULT Appliance::readTarManifestFile(RTTAR tar, const Utf8Str &strFile, void **ppvBuf, size_t *pcbSize, PVDINTERFACEIO pCallbacks, PSHASTORAGE pStorage) 1624 1624 { 1625 1625 HRESULT rc = S_OK; … … 1795 1795 ImportStack &stack, 1796 1796 PVDINTERFACEIO pCallbacks, 1797 PSHA 1STORAGE pStorage)1797 PSHASTORAGE pStorage) 1798 1798 { 1799 1799 ComObjPtr<Progress> pProgress; … … 1934 1934 ImportStack &stack, 1935 1935 PVDINTERFACEIO pCallbacks, 1936 PSHA 1STORAGE pStorage)1936 PSHASTORAGE pStorage) 1937 1937 { 1938 1938 HRESULT rc; … … 2502 2502 ImportStack &stack, 2503 2503 PVDINTERFACEIO pCallbacks, 2504 PSHA 1STORAGE pStorage)2504 PSHASTORAGE pStorage) 2505 2505 { 2506 2506 Assert(vsdescThis->m->pConfig); … … 2814 2814 void Appliance::importMachines(ImportStack &stack, 2815 2815 PVDINTERFACEIO pCallbacks, 2816 PSHA 1STORAGE pStorage)2816 PSHASTORAGE pStorage) 2817 2817 { 2818 2818 HRESULT rc = S_OK; -
trunk/src/VBox/Runtime/common/checksum/manifest.cpp
r33289 r40329 196 196 } 197 197 198 RTR3DECL(int) RTManifestWriteFiles(const char *pszManifestFile, const char * const *papszFiles, size_t cFiles, 198 RTR3DECL(int) RTManifestWriteFiles(const char *pszManifestFile, RTDIGESTTYPE enmDigestType, 199 const char * const *papszFiles, size_t cFiles, 199 200 PFNRTPROGRESS pfnProgressCallback, void *pvUser) 200 201 { … … 239 240 { 240 241 size_t cbSize = 0; 241 rc = RTManifestWriteFilesBuf(&pvBuf, &cbSize, paFiles, cFiles);242 rc = RTManifestWriteFilesBuf(&pvBuf, &cbSize, enmDigestType, paFiles, cFiles); 242 243 if (RT_FAILURE(rc)) 243 244 break; … … 442 443 } 443 444 444 RTR3DECL(int) RTManifestWriteFilesBuf(void **ppvBuf, size_t *pcbSize, PRTMANIFESTTEST paFiles, size_t cFiles)445 RTR3DECL(int) RTManifestWriteFilesBuf(void **ppvBuf, size_t *pcbSize, RTDIGESTTYPE enmDigestType, PRTMANIFESTTEST paFiles, size_t cFiles) 445 446 { 446 447 /* Validate input */ … … 468 469 char * pszTmp = RTStrAlloc(cbMaxSize + 1); 469 470 size_t cbPos = 0; 471 const char *pcszDigestType; 472 switch (enmDigestType) 473 { 474 case RTDIGESTTYPE_CRC32: pcszDigestType = "CRC32:"; break; 475 case RTDIGESTTYPE_CRC64: pcszDigestType = "CRC64:"; break; 476 case RTDIGESTTYPE_MD5: pcszDigestType = "MD5:"; break; 477 case RTDIGESTTYPE_SHA1: pcszDigestType = "SHA1:"; break; 478 case RTDIGESTTYPE_SHA256: pcszDigestType = "SHA256"; break; 479 default: return VERR_INVALID_PARAMETER; 480 } 470 481 for (size_t i = 0; i < cFiles; ++i) 471 482 { 472 size_t cch = RTStrPrintf(pszTmp, cbMaxSize + 1, " SHA1 (%s)= %s\n", RTPathFilename(paFiles[i].pszTestFile), paFiles[i].pszTestDigest);483 size_t cch = RTStrPrintf(pszTmp, cbMaxSize + 1, "%s (%s)= %s\n", pcszDigestType, RTPathFilename(paFiles[i].pszTestFile), paFiles[i].pszTestDigest); 473 484 memcpy(&((char*)pvBuf)[cbPos], pszTmp, cch); 474 485 cbPos += cch; -
trunk/src/VBox/Runtime/testcase/tstRTManifest.cpp
r34464 r40329 63 63 64 64 void *pvBuf = NULL; 65 RTTESTI_CHECK_RC_RETV(RTManifestWriteFilesBuf(&pvBuf, &cbSize, s_aFiles, 2), VINF_SUCCESS);65 RTTESTI_CHECK_RC_RETV(RTManifestWriteFilesBuf(&pvBuf, &cbSize, RTDIGESTTYPE_SHA1, s_aFiles, 2), VINF_SUCCESS); 66 66 67 67 /* Check returned memory size */
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器