Changeset 46518 in vbox
- Timestamp:
- Jun 13, 2013 10:07:09 AM (12 years ago)
- svn:sync-xref-src-repo-rev:
- 86374
- Location:
- trunk/src/VBox
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/ApplianceImpl.h
r45227 r46518 27 27 * private classes. */ 28 28 #include <iprt/tar.h> 29 #include <iprt/circbuf.h> 30 #include <VBox/vd.h> 31 #include <iprt/sha.h> 29 32 30 33 #include "ovfreader.h" 34 #include <set> 31 35 32 36 /* VBox forward declarations */ … … 38 42 typedef struct VDINTERFACEIO *PVDINTERFACEIO; 39 43 typedef struct SHASTORAGE *PSHASTORAGE; 44 45 typedef enum applianceIOName { applianceIOTar, applianceIOFile } APPLIANCEIONAME; 40 46 41 47 namespace ovf … … 139 145 static DECLCALLBACK(int) taskThreadImportOrExport(RTTHREAD aThread, void *pvUser); 140 146 147 HRESULT initSetOfSupportedStandardsURI(); 148 149 Utf8Str typeOfVirtualDiskFormatFromURI(Utf8Str type) const; 150 151 std::set<Utf8Str> URIFromTypeOfVirtualDiskFormat(Utf8Str type); 152 153 HRESULT initApplianceIONameMap(); 154 155 Utf8Str applianceIOName(APPLIANCEIONAME type) const; 156 141 157 /******************************************************************************* 142 158 * Read stuff … … 178 194 PVDINTERFACEIO pCallbacks, 179 195 PSHASTORAGE pStorage); 196 180 197 void importMachineGeneric(const ovf::VirtualSystem &vsysThis, 181 198 ComObjPtr<VirtualSystemDescription> &vsdescThis, … … 219 236 XMLStack &stack); 220 237 238 HRESULT preCheckImageAvailability(PSHASTORAGE pSHAStorage, 239 RTCString &availableImage); 240 221 241 friend class Machine; 222 242 }; -
trunk/src/VBox/Main/include/ApplianceImplPrivate.h
r45622 r46518 22 22 23 23 #include "ovfreader.h" 24 #include <map> 24 25 25 26 //////////////////////////////////////////////////////////////////////////////// … … 230 231 bool checkComplianceDigestAndOVFVersion(bool digestType, ovf::OVFVersion_T ovfVersion); 231 232 233 232 234 typedef struct SHASTORAGE 233 235 { -
trunk/src/VBox/Main/include/ovfreader.h
r46169 r46518 26 26 namespace ovf 27 27 { 28 29 //////////////////////////////////////////////////////////////////////////////// 30 // 31 // Errors 32 // 33 //////////////////////////////////////////////////////////////////////////////// 34 35 /** 36 * Thrown by OVFReader for any kind of error that is not an XML error but 37 * still makes the OVF impossible to parse. Based on xml::LogicError so 38 * that one catch() for all xml::LogicError can handle all possible errors. 39 */ 40 41 class OVFLogicError : public xml::LogicError 42 { 43 public: 44 OVFLogicError(const char *aFormat, ...); 45 }; 28 46 29 47 //////////////////////////////////////////////////////////////////////////////// … … 173 191 const char* const OVF20_URI_string = "http://schemas.dmtf.org/ovf/envelope/2"; 174 192 193 const char* const DTMF_SPECS_URI = "http://schemas.dmtf.org/wbem/cim-html/2/"; 194 175 195 //////////////////////////////////////////////////////////////////////////////// 176 196 // … … 206 226 } 207 227 }; 228 229 230 struct FileReference 231 { 232 RTCString strHref; // value from /References/File/@href (filename) 233 RTCString strDiskId; // value from /References/File/@id () 234 }; 235 236 typedef std::map<uint32_t, FileReference> FileReferenceMap; 208 237 209 238 //////////////////////////////////////////////////////////////////////////////// … … 261 290 }; 262 291 263 struct VirtualHardwareItem 264 { 292 293 enum StorageAccessType_T 294 { StorageAccessType_Unknown = 0, 295 StorageAccessType_Readable = 1, 296 StorageAccessType_Writeable = 2, 297 StorageAccessType_ReadWrite = 3 298 }; 299 300 enum ComplianceType_T 301 { ComplianceType_No = 0, 302 ComplianceType_Soft = 1, 303 ComplianceType_Medium = 2, 304 ComplianceType_Strong = 3 305 }; 306 307 class VirtualHardwareItem 308 { 309 public: 265 310 RTCString strDescription; 266 311 RTCString strCaption; … … 310 355 ulBusNumber(0), 311 356 ulLineNumber(0) 312 {}; 357 { 358 itemName = "Item"; 359 }; 360 361 void fillItem(const xml::ElementNode *item); 362 363 void setDefaultFlag() 364 { 365 fDefault = true; 366 } 367 368 bool isThereDefaultValues() const 369 { 370 return fDefault; 371 } 372 373 void checkConsistencyAndCompliance() throw (OVFLogicError) 374 { 375 _checkConsistencyAndCompliance(); 376 } 377 378 protected: 379 virtual void _checkConsistencyAndCompliance() throw (OVFLogicError); 380 virtual const RTCString& getItemName() 381 { 382 return _getItemName(); 383 } 384 385 private: 386 RTCString itemName; 387 bool fDefault;//true means that some fields were absent in the XML and some default values were assigned to. 388 389 virtual const RTCString& _getItemName() 390 { 391 return itemName; 392 } 393 }; 394 395 class StorageItem: public VirtualHardwareItem 396 { 397 //see DMTF Schema Documentation http://schemas.dmtf.org/wbem/cim-html/2/ 398 StorageAccessType_T accessType; 399 RTCString strHostExtentName; 400 int16_t hostExtentNameFormat; 401 int16_t hostExtentNameNamespace; 402 int64_t hostExtentStartingAddress; 403 int64_t hostResourceBlockSize; 404 int64_t limit; 405 RTCString strOtherHostExtentNameFormat; 406 RTCString strOtherHostExtentNameNamespace; 407 int64_t reservation; 408 int64_t virtualQuantity; 409 RTCString strVirtualQuantityUnits; 410 int64_t virtualResourceBlockSize; 411 412 public: 413 StorageItem(): VirtualHardwareItem(), 414 accessType(StorageAccessType_Unknown), 415 hostExtentNameFormat(-1), 416 hostExtentNameNamespace(-1), 417 hostExtentStartingAddress(-1), 418 hostResourceBlockSize(-1), 419 limit(-1), 420 reservation(-1), 421 virtualQuantity(-1), 422 virtualResourceBlockSize(-1) 423 { 424 itemName = "StorageItem"; 425 }; 426 427 void fillItem(const xml::ElementNode *item); 428 429 protected: 430 virtual void _checkConsistencyAndCompliance() throw (OVFLogicError); 431 private: 432 RTCString itemName; 433 434 virtual const RTCString& _getItemName() 435 { 436 return itemName; 437 } 438 }; 439 440 441 class EthernetPortItem: public VirtualHardwareItem 442 { 443 //see DMTF Schema Documentation http://schemas.dmtf.org/wbem/cim-html/2/ 444 uint16_t DefaultPortVID; 445 uint16_t DefaultPriority; 446 uint16_t DesiredVLANEndpointMode; 447 uint32_t GroupID; 448 uint32_t ManagerID; 449 RTCString strNetworkPortProfileID; 450 uint16_t NetworkPortProfileIDType; 451 RTCString strOtherEndpointMode; 452 RTCString strOtherNetworkPortProfileIDTypeInfo; 453 RTCString strPortCorrelationID; 454 uint16_t PortVID; 455 bool Promiscuous; 456 uint64_t ReceiveBandwidthLimit; 457 uint16_t ReceiveBandwidthReservation; 458 bool SourceMACFilteringEnabled; 459 uint32_t VSITypeID; 460 uint8_t VSITypeIDVersion; 461 uint16_t AllowedPriorities[256]; 462 RTCString strAllowedToReceiveMACAddresses; 463 uint16_t AllowedToReceiveVLANs[256]; 464 RTCString strAllowedToTransmitMACAddresses; 465 uint16_t AllowedToTransmitVLANs[256]; 466 467 public: 468 EthernetPortItem(): VirtualHardwareItem() 469 { 470 itemName = "EthernetPortItem"; 471 }; 472 473 void fillItem(const xml::ElementNode *item); 474 475 protected: 476 virtual void _checkConsistencyAndCompliance() throw (OVFLogicError); 477 private: 478 RTCString itemName; 479 480 virtual const RTCString& _getItemName() 481 { 482 return itemName; 483 } 313 484 }; 314 485 … … 484 655 }; 485 656 486 ////////////////////////////////////////////////////////////////////////////////487 //488 // Errors489 //490 ////////////////////////////////////////////////////////////////////////////////491 492 /**493 * Thrown by OVFReader for any kind of error that is not an XML error but494 * still makes the OVF impossible to parse. Based on xml::LogicError so495 * that one catch() for all xml::LogicError can handle all possible errors.496 */497 498 class OVFLogicError : public xml::LogicError499 {500 public:501 OVFLogicError(const char *aFormat, ...);502 };503 504 657 } // end namespace ovf 505 658 -
trunk/src/VBox/Main/src-server/ApplianceImpl.cpp
r46341 r46518 19 19 #include <iprt/path.h> 20 20 #include <iprt/cpp/utils.h> 21 22 21 #include <VBox/com/array.h> 22 #include <map> 23 23 24 24 #include "ApplianceImpl.h" … … 29 29 #include "ProgressImpl.h" 30 30 #include "MachineImpl.h" 31 31 #include "MediumFormatImpl.h" 32 #include "SystemPropertiesImpl.h" 32 33 #include "AutoCaller.h" 33 34 #include "Logging.h" … … 42 43 // 43 44 //////////////////////////////////////////////////////////////////////////////// 45 46 static const char* const strISOURI = "http://www.ecma-international.org/publications/standards/Ecma-119.htm"; 47 static const char* const strVMDKStreamURI = "http://www.vmware.com/interfaces/specifications/vmdk.html#streamOptimized"; 48 static const char* const strVMDKSparseURI = "http://www.vmware.com/specifications/vmdk.html#sparse"; 49 static const char* const strVMDKCompressedURI = "http://www.vmware.com/specifications/vmdk.html#compressed"; 50 static const char* const strVMDKCompressedURI2 = "http://www.vmware.com/interfaces/specifications/vmdk.html#compressed"; 51 static const char* const strVHDURI = "http://go.microsoft.com/fwlink/?LinkId=137171"; 52 53 static std::map<Utf8Str, Utf8Str> supportedStandardsURI; 54 55 static const char* const applianceIOTarName = "Appliance::IOTar"; 56 static const char* const applianceIOFileName = "Appliance::IOFile"; 57 58 static std::map<APPLIANCEIONAME, Utf8Str> applianceIONameMap; 44 59 45 60 static const struct … … 304 319 } 305 320 321 306 322 //////////////////////////////////////////////////////////////////////////////// 307 323 // … … 355 371 HRESULT Appliance::init(VirtualBox *aVirtualBox) 356 372 { 373 HRESULT rc = S_OK; 357 374 /* Enclose the state transition NotReady->InInit->Ready */ 358 375 AutoInitSpan autoInitSpan(this); … … 365 382 m = new Data; 366 383 384 initApplianceIONameMap(); 385 386 rc = initSetOfSupportedStandardsURI(); 387 367 388 /* Confirm a successful initialization */ 368 389 autoInitSpan.setSucceeded(); 369 390 370 return S_OK;391 return rc; 371 392 } 372 393 … … 604 625 //////////////////////////////////////////////////////////////////////////////// 605 626 627 HRESULT Appliance::initSetOfSupportedStandardsURI() 628 { 629 HRESULT rc = S_OK; 630 if (!supportedStandardsURI.empty()) 631 return rc; 632 633 /* Get the system properties. */ 634 SystemProperties *pSysProps = mVirtualBox->getSystemProperties(); 635 { 636 ComObjPtr<MediumFormat> trgFormat = pSysProps->mediumFormatFromExtension("iso"); 637 if (trgFormat.isNull()) 638 return setError(E_FAIL, tr("Can't find appropriate medium format for ISO type of a virtual disk.")); 639 640 Bstr bstrFormatName; 641 rc = trgFormat->COMGETTER(Name)(bstrFormatName.asOutParam()); 642 if (FAILED(rc)) return rc; 643 644 Utf8Str strTrgFormat = Utf8Str(bstrFormatName); 645 646 supportedStandardsURI.insert(std::make_pair(Utf8Str(strISOURI), strTrgFormat)); 647 } 648 649 { 650 ComObjPtr<MediumFormat> trgFormat = pSysProps->mediumFormatFromExtension("vmdk"); 651 if (trgFormat.isNull()) 652 return setError(E_FAIL, tr("Can't find appropriate medium format for VMDK type of a virtual disk.")); 653 654 Bstr bstrFormatName; 655 rc = trgFormat->COMGETTER(Name)(bstrFormatName.asOutParam()); 656 if (FAILED(rc)) return rc; 657 658 Utf8Str strTrgFormat = Utf8Str(bstrFormatName); 659 660 supportedStandardsURI.insert(std::make_pair(Utf8Str(strVMDKStreamURI), strTrgFormat)); 661 supportedStandardsURI.insert(std::make_pair(Utf8Str(strVMDKSparseURI), strTrgFormat)); 662 supportedStandardsURI.insert(std::make_pair(Utf8Str(strVMDKCompressedURI), strTrgFormat)); 663 supportedStandardsURI.insert(std::make_pair(Utf8Str(strVMDKCompressedURI2), strTrgFormat)); 664 } 665 666 { 667 ComObjPtr<MediumFormat> trgFormat = pSysProps->mediumFormatFromExtension("vhd"); 668 if (trgFormat.isNull()) 669 return setError(E_FAIL, tr("Can't find appropriate medium format for VHD type of a virtual disk.")); 670 671 Bstr bstrFormatName; 672 rc = trgFormat->COMGETTER(Name)(bstrFormatName.asOutParam()); 673 if (FAILED(rc)) return rc; 674 675 Utf8Str strTrgFormat = Utf8Str(bstrFormatName); 676 677 supportedStandardsURI.insert(std::make_pair(Utf8Str(strVHDURI), strTrgFormat)); 678 } 679 680 return rc; 681 } 682 683 Utf8Str Appliance::typeOfVirtualDiskFormatFromURI(Utf8Str uri) const 684 { 685 Utf8Str type; 686 std::map<Utf8Str, Utf8Str>::const_iterator cit = supportedStandardsURI.find(uri); 687 if (cit != supportedStandardsURI.end()) 688 { 689 type = cit->second; 690 } 691 692 return type; 693 } 694 695 std::set<Utf8Str> Appliance::URIFromTypeOfVirtualDiskFormat(Utf8Str type) 696 { 697 std::set<Utf8Str> uri; 698 std::map<Utf8Str, Utf8Str>::const_iterator cit = supportedStandardsURI.begin(); 699 while(cit != supportedStandardsURI.end()) 700 { 701 if (cit->second.compare(type,Utf8Str::CaseInsensitive) == 0) 702 uri.insert(cit->first); 703 ++cit; 704 } 705 706 return uri; 707 } 708 709 HRESULT Appliance::initApplianceIONameMap() 710 { 711 HRESULT rc = S_OK; 712 if (!applianceIONameMap.empty()) 713 return rc; 714 715 applianceIONameMap.insert(std::make_pair(applianceIOTar, applianceIOTarName)); 716 applianceIONameMap.insert(std::make_pair(applianceIOFile, applianceIOFileName)); 717 718 return rc; 719 } 720 721 Utf8Str Appliance::applianceIOName(APPLIANCEIONAME type) const 722 { 723 Utf8Str name; 724 std::map<APPLIANCEIONAME, Utf8Str>::const_iterator cit = applianceIONameMap.find(type); 725 if (cit != applianceIONameMap.end()) 726 { 727 name = cit->second; 728 } 729 730 return name; 731 } 732 606 733 /** 607 734 * Returns true if the appliance is in "idle" state. This should always be the -
trunk/src/VBox/Main/src-server/ApplianceImplExport.cpp
r46337 r46518 1230 1230 uint64_t uTemp; 1231 1231 1232 ovf::VirtualHardwareItem vhi; 1233 ovf::StorageItem si; 1234 ovf::EthernetPortItem epi; 1235 1232 1236 switch (desc.type) 1233 1237 { … … 1518 1522 <rasd:ResourceType>10</rasd:ResourceType> 1519 1523 </Item> */ 1520 if (uLoop == 1)1524 if (uLoop == 2) 1521 1525 { 1522 1526 lAutomaticAllocation = 1; … … 1587 1591 { 1588 1592 xml::ElementNode *pItem; 1589 1590 pItem = pelmVirtualHardwareSection->createChild("Item"); 1593 xml::ElementNode *pItemHelper; 1594 RTCString itemElement; 1595 RTCString itemElementHelper; 1596 1597 if (enFormat == ovf::OVFVersion_2_0) 1598 { 1599 if(uLoop == 2) 1600 { 1601 if (desc.type == VirtualSystemDescriptionType_NetworkAdapter) 1602 { 1603 itemElement = "epasd:"; 1604 pItem = pelmVirtualHardwareSection->createChild("EthernetPortItem"); 1605 } 1606 else if (desc.type == VirtualSystemDescriptionType_CDROM || 1607 desc.type == VirtualSystemDescriptionType_HardDiskImage) 1608 { 1609 itemElement = "sasd:"; 1610 pItem = pelmVirtualHardwareSection->createChild("StorageItem"); 1611 } 1612 } 1613 else 1614 { 1615 itemElement = "rasd:"; 1616 pItem = pelmVirtualHardwareSection->createChild("Item"); 1617 } 1618 } 1619 else 1620 { 1621 itemElement = "rasd:"; 1622 pItem = pelmVirtualHardwareSection->createChild("Item"); 1623 } 1591 1624 1592 1625 // NOTE: DO NOT CHANGE THE ORDER of these items! The OVF standards prescribes that … … 1595 1628 1596 1629 if (lAddress != -1) 1597 pItem->createChild("rasd:Address")->addContent(Utf8StrFmt("%d", lAddress)); 1630 { 1631 //pItem->createChild("rasd:Address")->addContent(Utf8StrFmt("%d", lAddress)); 1632 itemElementHelper = itemElement; 1633 pItemHelper = pItem->createChild(itemElementHelper.append("Address").c_str()); 1634 pItemHelper->addContent(Utf8StrFmt("%d", lAddress)); 1635 } 1598 1636 1599 1637 if (lAddressOnParent != -1) 1600 pItem->createChild("rasd:AddressOnParent")->addContent(Utf8StrFmt("%d", lAddressOnParent)); 1638 { 1639 //pItem->createChild("rasd:AddressOnParent")->addContent(Utf8StrFmt("%d", lAddressOnParent)); 1640 itemElementHelper = itemElement; 1641 pItemHelper = pItem->createChild(itemElementHelper.append("AddressOnParent").c_str()); 1642 pItemHelper->addContent(Utf8StrFmt("%d", lAddressOnParent)); 1643 } 1601 1644 1602 1645 if (!strAllocationUnits.isEmpty()) 1603 pItem->createChild("rasd:AllocationUnits")->addContent(strAllocationUnits); 1646 { 1647 //pItem->createChild("rasd:AllocationUnits")->addContent(strAllocationUnits); 1648 itemElementHelper = itemElement; 1649 pItemHelper = pItem->createChild(itemElementHelper.append("AllocationUnits").c_str()); 1650 pItemHelper->addContent(strAllocationUnits); 1651 } 1604 1652 1605 1653 if (lAutomaticAllocation != -1) 1606 pItem->createChild("rasd:AutomaticAllocation")->addContent( (lAutomaticAllocation) ? "true" : "false" ); 1654 { 1655 //pItem->createChild("rasd:AutomaticAllocation")->addContent( (lAutomaticAllocation) ? "true" : "false" ); 1656 itemElementHelper = itemElement; 1657 pItemHelper = pItem->createChild(itemElementHelper.append("AutomaticAllocation").c_str()); 1658 pItemHelper->addContent((lAutomaticAllocation) ? "true" : "false" ); 1659 } 1607 1660 1608 1661 if (lBusNumber != -1) 1609 if (enFormat == ovf::OVFVersion_0_9) // BusNumber is invalid OVF 1.0 so only write it in 0.9 mode for OVFTool y 1610 pItem->createChild("rasd:BusNumber")->addContent(Utf8StrFmt("%d", lBusNumber)); 1662 { 1663 if (enFormat == ovf::OVFVersion_0_9) 1664 { 1665 // BusNumber is invalid OVF 1.0 so only write it in 0.9 mode for OVFTool 1666 //pItem->createChild("rasd:BusNumber")->addContent(Utf8StrFmt("%d", lBusNumber)); 1667 itemElementHelper = itemElement; 1668 pItemHelper = pItem->createChild(itemElementHelper.append("BusNumber").c_str()); 1669 pItemHelper->addContent(Utf8StrFmt("%d", lBusNumber)); 1670 } 1671 } 1611 1672 1612 1673 if (!strCaption.isEmpty()) 1613 pItem->createChild("rasd:Caption")->addContent(strCaption); 1674 { 1675 //pItem->createChild("rasd:Caption")->addContent(strCaption); 1676 itemElementHelper = itemElement; 1677 pItemHelper = pItem->createChild(itemElementHelper.append("Caption").c_str()); 1678 pItemHelper->addContent(strCaption); 1679 } 1614 1680 1615 1681 if (!strConnection.isEmpty()) 1616 pItem->createChild("rasd:Connection")->addContent(strConnection); 1682 { 1683 //pItem->createChild("rasd:Connection")->addContent(strConnection); 1684 itemElementHelper = itemElement; 1685 pItemHelper = pItem->createChild(itemElementHelper.append("Connection").c_str()); 1686 pItemHelper->addContent(strConnection); 1687 } 1617 1688 1618 1689 if (!strDescription.isEmpty()) 1619 pItem->createChild("rasd:Description")->addContent(strDescription); 1690 { 1691 //pItem->createChild("rasd:Description")->addContent(strDescription); 1692 itemElementHelper = itemElement; 1693 pItemHelper = pItem->createChild(itemElementHelper.append("Description").c_str()); 1694 pItemHelper->addContent(strDescription); 1695 } 1620 1696 1621 1697 if (!strCaption.isEmpty()) 1622 if (enFormat == ovf::OVFVersion_1_0) 1623 pItem->createChild("rasd:ElementName")->addContent(strCaption); 1698 { 1699 if (enFormat == ovf::OVFVersion_1_0) 1700 { 1701 //pItem->createChild("rasd:ElementName")->addContent(strCaption); 1702 itemElementHelper = itemElement; 1703 pItemHelper = pItem->createChild(itemElementHelper.append("ElementName").c_str()); 1704 pItemHelper->addContent(strCaption); 1705 } 1706 } 1624 1707 1625 1708 if (!strHostResource.isEmpty()) 1626 pItem->createChild("rasd:HostResource")->addContent(strHostResource); 1627 1628 // <rasd:InstanceID>1</rasd:InstanceID> 1629 xml::ElementNode *pelmInstanceID; 1630 if (enFormat == ovf::OVFVersion_0_9) 1631 pelmInstanceID = pItem->createChild("rasd:InstanceId"); 1632 else 1633 pelmInstanceID = pItem->createChild("rasd:InstanceID"); // capitalization changed... 1634 pelmInstanceID->addContent(Utf8StrFmt("%d", ulInstanceID++)); 1709 { 1710 //pItem->createChild("rasd:HostResource")->addContent(strHostResource); 1711 itemElementHelper = itemElement; 1712 pItemHelper = pItem->createChild(itemElementHelper.append("HostResource").c_str()); 1713 pItemHelper->addContent(strHostResource); 1714 } 1715 1716 { 1717 // <rasd:InstanceID>1</rasd:InstanceID> 1718 itemElementHelper = itemElement; 1719 if (enFormat == ovf::OVFVersion_0_9) 1720 //pelmInstanceID = pItem->createChild("rasd:InstanceId"); 1721 pItemHelper = pItem->createChild(itemElementHelper.append("InstanceId").c_str()); 1722 else 1723 //pelmInstanceID = pItem->createChild("rasd:InstanceID"); // capitalization changed... 1724 pItemHelper = pItem->createChild(itemElementHelper.append("InstanceID").c_str()); 1725 1726 pItemHelper->addContent(Utf8StrFmt("%d", ulInstanceID++)); 1727 } 1635 1728 1636 1729 if (ulParent) 1637 pItem->createChild("rasd:Parent")->addContent(Utf8StrFmt("%d", ulParent)); 1730 { 1731 //pItem->createChild("rasd:Parent")->addContent(Utf8StrFmt("%d", ulParent)); 1732 itemElementHelper = itemElement; 1733 pItemHelper = pItem->createChild(itemElementHelper.append("Parent").c_str()); 1734 pItemHelper->addContent(Utf8StrFmt("%d", ulParent)); 1735 } 1638 1736 1639 1737 if (!strResourceSubType.isEmpty()) 1640 pItem->createChild("rasd:ResourceSubType")->addContent(strResourceSubType); 1641 1642 // <rasd:ResourceType>3</rasd:ResourceType> 1643 pItem->createChild("rasd:ResourceType")->addContent(Utf8StrFmt("%d", type)); 1738 { 1739 //pItem->createChild("rasd:ResourceSubType")->addContent(strResourceSubType); 1740 itemElementHelper = itemElement; 1741 pItemHelper = pItem->createChild(itemElementHelper.append("ResourceSubType").c_str()); 1742 pItemHelper->addContent(strResourceSubType); 1743 } 1744 1745 { 1746 // <rasd:ResourceType>3</rasd:ResourceType> 1747 //pItem->createChild("rasd:ResourceType")->addContent(Utf8StrFmt("%d", type)); 1748 itemElementHelper = itemElement; 1749 pItemHelper = pItem->createChild(itemElementHelper.append("ResourceType").c_str()); 1750 pItemHelper->addContent(Utf8StrFmt("%d", type)); 1751 } 1644 1752 1645 1753 // <rasd:VirtualQuantity>1</rasd:VirtualQuantity> 1646 1754 if (lVirtualQuantity != -1) 1647 pItem->createChild("rasd:VirtualQuantity")->addContent(Utf8StrFmt("%d", lVirtualQuantity)); 1755 { 1756 //pItem->createChild("rasd:VirtualQuantity")->addContent(Utf8StrFmt("%d", lVirtualQuantity)); 1757 itemElementHelper = itemElement; 1758 pItemHelper = pItem->createChild(itemElementHelper.append("VirtualQuantity").c_str()); 1759 pItemHelper->addContent(Utf8StrFmt("%d", lVirtualQuantity)); 1760 } 1648 1761 } 1649 1762 } … … 1757 1870 storage.fCreateDigest = m->fManifest; 1758 1871 storage.fSha256 = m->fSha256; 1759 int vrc = VDInterfaceAdd(&pFileIo->Core, "Appliance::IOFile", 1872 1873 1874 Utf8Str name = applianceIOName(applianceIOFile); 1875 1876 int vrc = VDInterfaceAdd(&pFileIo->Core, name.c_str(), 1760 1877 VDINTERFACETYPE_IO, 0, sizeof(VDINTERFACEIO), 1761 1878 &storage.pVDImageIfaces); … … 1811 1928 storage.fCreateDigest = m->fManifest; 1812 1929 storage.fSha256 = m->fSha256; 1813 vrc = VDInterfaceAdd(&pTarIo->Core, "Appliance::IOTar", 1930 1931 Utf8Str name = applianceIOName(applianceIOTar); 1932 1933 vrc = VDInterfaceAdd(&pTarIo->Core, name.c_str(), 1814 1934 VDINTERFACETYPE_IO, tar, sizeof(VDINTERFACEIO), 1815 1935 &storage.pVDImageIfaces); 1936 1816 1937 if (RT_FAILURE(vrc)) 1817 1938 { … … 1858 1979 // Now fully build a valid ovf document in memory 1859 1980 buildXML(writeLock, doc, stack, pTask->locInfo.strPath, pTask->enFormat); 1981 /* Extract the OVA file name */ 1982 Utf8Str strOvaFile = pTask->locInfo.strPath; 1860 1983 /* Extract the path */ 1861 Utf8Str strOvfFile = Utf8Str(pTask->locInfo.strPath).stripExt().append(".ovf");1984 Utf8Str strOvfFile = strOvaFile.stripExt().append(".ovf"); 1862 1985 // Create a memory buffer containing the XML. */ 1863 1986 void *pvBuf = 0; … … 1951 2074 try 1952 2075 { 1953 ComObjPtr<Progress> pProgress2;1954 pProgress2.createObject();1955 rc = pProgress2->init(mVirtualBox, static_cast<IAppliance*>(this), BstrFmt(tr("Creating medium '%s'"), strTargetFilePath.c_str()).raw(), TRUE);1956 if (FAILED(rc)) throw rc;1957 1958 2076 // advance to the next operation 1959 2077 pTask->pProgress->SetNextOperation(BstrFmt(tr("Exporting to disk image '%s'"), RTPathFilename(strTargetFilePath.c_str())).raw(), … … 1963 2081 if (pDiskEntry->type == VirtualSystemDescriptionType_HardDiskImage) 1964 2082 { 1965 rc = pSourceDisk->exportFile(strTargetFilePath.c_str(), 1966 format, 2083 ComObjPtr<Progress> pProgress2; 2084 pProgress2.createObject(); 2085 rc = pProgress2->init(mVirtualBox, static_cast<IAppliance*>(this), BstrFmt(tr("Creating medium '%s'"), strTargetFilePath.c_str()).raw(), TRUE); 2086 if (FAILED(rc)) throw rc; 2087 2088 rc = pSourceDisk->exportFile(strTargetFilePath.c_str(), 2089 format, 1967 2090 MediumVariant_VmdkStreamOptimized, 1968 2091 pIfIo, … … 1970 2093 pProgress2); 1971 2094 if (FAILED(rc)) throw rc; 2095 2096 ComPtr<IProgress> pProgress3(pProgress2); 2097 // now wait for the background disk operation to complete; this throws HRESULTs on error 2098 waitForAsyncProgress(pTask->pProgress, pProgress3); 1972 2099 } 1973 2100 else 1974 2101 { 1975 2102 //copy/clone CD/DVD image 1976 rc = pSourceDisk->exportFile(strTargetFilePath.c_str(), 1977 formatTemp, 1978 MediumVariant_Standard, 1979 pIfIo, 1980 pStorage, 1981 pProgress2); 1982 if (FAILED(rc)) throw rc; 2103 /* Read the ISO file into a memory buffer */ 2104 { 2105 void *pvTmpBuf = 0; 2106 size_t cbSize = 0; 2107 2108 if (RTFileExists(strSrcFilePath.c_str())) 2109 { 2110 // open ISO file and read one into memory buffer 2111 RTFILE pFile = NULL; 2112 vrc = RTFileOpen(&pFile, strSrcFilePath.c_str(), RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_NONE); 2113 if (RT_SUCCESS(vrc) && pFile != NULL) 2114 { 2115 uint64_t cbFile = 0; 2116 2117 vrc = RTFileGetSize(pFile, &cbFile); 2118 2119 if (RT_SUCCESS(vrc)) 2120 pvTmpBuf = RTMemAllocZ(cbFile); 2121 else 2122 throw setError(VBOX_E_FILE_ERROR, 2123 tr("Could not get size of the ISO file '%s' "), 2124 RTPathFilename(strSrcFilePath.c_str())); 2125 2126 vrc = RTFileRead(pFile, pvTmpBuf, cbFile, &cbSize); 2127 2128 if (RT_FAILURE(vrc)) 2129 { 2130 if (pvTmpBuf) 2131 RTMemFree(pvTmpBuf); 2132 throw setError(VBOX_E_FILE_ERROR, 2133 tr("Could not read the ISO file '%s' (%Rrc)"), 2134 RTPathFilename(strSrcFilePath.c_str()), vrc); 2135 } 2136 } 2137 2138 RTFileClose(pFile); 2139 } 2140 2141 /* Write the ISO file to disk. */ 2142 vrc = ShaWriteBuf(strTargetFilePath.c_str(), pvTmpBuf, cbSize, pIfIo, pStorage); 2143 RTMemFree(pvTmpBuf); 2144 if (RT_FAILURE(vrc)) 2145 throw setError(VBOX_E_FILE_ERROR, 2146 tr("Could not create ISO file '%s' (%Rrc)"), 2147 strTargetFilePath.c_str(), vrc); 2148 } 1983 2149 } 1984 1985 ComPtr<IProgress> pProgress3(pProgress2);1986 // now wait for the background disk operation to complete; this throws HRESULTs on error1987 waitForAsyncProgress(pTask->pProgress, pProgress3);1988 2150 } 1989 2151 catch (HRESULT rc3) -
trunk/src/VBox/Main/src-server/ApplianceImplIO.cpp
r45367 r46518 36 36 * Structures and Typedefs * 37 37 ******************************************************************************/ 38 39 38 typedef struct FILESTORAGEINTERNAL 40 39 { … … 282 281 int rc = VINF_SUCCESS; 283 282 284 if ( 283 if (fOpen & RTFILE_O_READ 285 284 && !(fOpen & RTFILE_O_WRITE)) 286 285 { … … 298 297 */ 299 298 bool fFound = false; 299 300 300 for (;;) 301 301 { … … 312 312 rc = RTTarSeekNextFile(tar); 313 313 if (RT_FAILURE(rc)) 314 { 314 315 break; 316 } 315 317 } 316 318 } -
trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp
r46176 r46518 47 47 #include <VBox/version.h> 48 48 #include <VBox/settings.h> 49 50 #include <set> 49 51 50 52 using namespace std; … … 611 613 } 612 614 615 /* 616 * Figure out from URI which format the image of disk has. 617 * URI must have inside section <Disk> . 618 * But there aren't strong requirements about correspondence one URI for one disk virtual format. 619 * So possibly, we aren't able to recognize some URIs. 620 */ 621 Utf8Str vdf = typeOfVirtualDiskFormatFromURI(di.strFormat); 622 623 /* 624 * fallback, if we can't determine virtual disk format using URI from the attribute ovf:format 625 * in the corresponding section <Disk> in the OVF file. 626 */ 627 if (vdf.isEmpty()) 628 { 629 /* Figure out from extension which format the image of disk has. */ 630 { 631 char *pszExt = RTPathExt(di.strHref.c_str()); 632 /* Get the system properties. */ 633 SystemProperties *pSysProps = mVirtualBox->getSystemProperties(); 634 ComObjPtr<MediumFormat> trgFormat = pSysProps->mediumFormatFromExtension(&pszExt[1]); 635 if (trgFormat.isNull()) 636 { 637 throw setError(E_FAIL, 638 tr("Internal inconsistency looking up medium format for the disk image '%s'"), 639 di.strHref.c_str()); 640 } 641 642 Bstr bstrFormatName; 643 rc = trgFormat->COMGETTER(Name)(bstrFormatName.asOutParam()); 644 if (FAILED(rc)) 645 throw rc; 646 647 vdf = Utf8Str(bstrFormatName); 648 } 649 } 650 613 651 // @todo: 614 652 // - figure out all possible vmdk formats we also support 615 653 // - figure out if there is a url specifier for vhd already 616 654 // - we need a url specifier for the vdi format 617 if (!di.strFormat.compare("http://www.vmware.com/specifications/vmdk.html#sparse", 618 Utf8Str::CaseInsensitive) 619 || !di.strFormat.compare("http://www.vmware.com/interfaces/specifications/vmdk.html#streamOptimized", 620 Utf8Str::CaseInsensitive) 621 || !di.strFormat.compare("http://www.vmware.com/specifications/vmdk.html#compressed", 622 Utf8Str::CaseInsensitive) 623 || !di.strFormat.compare("http://www.vmware.com/interfaces/specifications/vmdk.html#compressed", 624 Utf8Str::CaseInsensitive) 625 ) 655 656 if (vdf.compare("VMDK", Utf8Str::CaseInsensitive) == 0) 626 657 { 627 658 /* If the href is empty use the VM name as filename */ 628 659 Utf8Str strFilename = di.strHref; 629 660 if (!strFilename.length()) 630 //strFilename = Utf8StrFmt("%s.vmdk", nameVBox.c_str());631 661 strFilename = Utf8StrFmt("%s.vmdk", hd.strDiskId.c_str()); 632 662 … … 640 670 if (!(pController = pNewDesc->findControllerFromID(hd.idController))) 641 671 throw setError(E_FAIL, 642 tr("Cannot find hard disk controller with OVF instance ID %RI32 to which disk \"%s\" should be attached"), 672 tr("Cannot find hard disk controller with OVF instance ID %RI32 " 673 "to which disk \"%s\" should be attached"), 643 674 hd.idController, 644 675 di.strHref.c_str()); … … 654 685 di.ulSuggestedSizeMB, 655 686 strExtraConfig); 656 }//url specifier for ISO 657 else if (!di.strFormat.compare("http://www.ecma-international.org/publications/standards/Ecma-119.htm", 658 Utf8Str::CaseInsensitive)) 687 } 688 else if (vdf.compare("RAW", Utf8Str::CaseInsensitive) == 0) 659 689 { 660 690 /* If the href is empty use the VM name as filename */ … … 673 703 if (!(pController = pNewDesc->findControllerFromID(hd.idController))) 674 704 throw setError(E_FAIL, 675 tr("Cannot find disk controller with OVF instance ID %RI32 to which disk \"%s\" sh ould be attached"), 705 tr("Cannot find disk controller with OVF instance ID %RI32 " 706 "to which disk \"%s\" should be attached"), 676 707 hd.idController, 677 708 di.strHref.c_str()); … … 690 721 else 691 722 throw setError(VBOX_E_FILE_ERROR, 692 tr("Unsupported format for virtual disk image in OVF: \"%s\"", di.strFormat.c_str())); 723 tr("Unsupported format for virtual disk image %s in OVF: \"%s\""), 724 di.strHref.c_str(), 725 di.strFormat.c_str()); 693 726 } 694 727 } … … 764 797 //////////////////////////////////////////////////////////////////////////////// 765 798 799 HRESULT Appliance::preCheckImageAvailability(PSHASTORAGE pSHAStorage, 800 RTCString &availableImage) 801 { 802 HRESULT rc = S_OK; 803 RTTAR tar = (RTTAR)pSHAStorage->pVDImageIfaces->pvUser; 804 char *pszFilename = 0; 805 806 int vrc = RTTarCurrentFile(tar, &pszFilename); 807 808 if (RT_FAILURE(vrc)) 809 { 810 throw setError(VBOX_E_FILE_ERROR, 811 tr("Could not open the current file in the archive (%Rrc)"), vrc); 812 } 813 814 availableImage = pszFilename; 815 816 return rc; 817 } 766 818 767 819 /******************************************************************************* … … 929 981 } 930 982 983 RTFileClose(pFile); 984 931 985 RTDIGESTTYPE digestType = RTDIGESTTYPE_UNKNOWN; 932 986 vrc = RTManifestVerifyDigestType(pBuf, cbRead, digestType); … … 948 1002 } 949 1003 950 vrc = VDInterfaceAdd(&pFileIo->Core, "Appliance::IOFile", 1004 Utf8Str name = applianceIOName(applianceIOFile); 1005 1006 vrc = VDInterfaceAdd(&pFileIo->Core, name.c_str(), 951 1007 VDINTERFACETYPE_IO, 0, sizeof(VDINTERFACEIO), 952 1008 &storage.pVDImageIfaces); … … 1101 1157 } 1102 1158 1103 vrc = VDInterfaceAdd(&pTarIo->Core, "Appliance::IOTar", 1159 Utf8Str name = applianceIOName(applianceIOTar); 1160 1161 vrc = VDInterfaceAdd(&pTarIo->Core, name.c_str(), 1104 1162 VDINTERFACETYPE_IO, tar, sizeof(VDINTERFACEIO), 1105 1163 &storage.pVDImageIfaces); … … 1479 1537 storage.fCreateDigest = true; 1480 1538 1481 int vrc = VDInterfaceAdd(&pFileIo->Core, "Appliance::IOFile", 1539 Utf8Str name = applianceIOName(applianceIOFile); 1540 1541 int vrc = VDInterfaceAdd(&pFileIo->Core, name.c_str(), 1482 1542 VDINTERFACETYPE_IO, 0, sizeof(VDINTERFACEIO), 1483 1543 &storage.pVDImageIfaces); … … 1553 1613 SHASTORAGE storage; 1554 1614 RT_ZERO(storage); 1555 vrc = VDInterfaceAdd(&pTarIo->Core, "Appliance::IOTar", 1615 1616 Utf8Str name = applianceIOName(applianceIOTar); 1617 1618 vrc = VDInterfaceAdd(&pTarIo->Core, name.c_str(), 1556 1619 VDINTERFACETYPE_IO, tar, sizeof(VDINTERFACEIO), 1557 1620 &storage.pVDImageIfaces); … … 2050 2113 { 2051 2114 Utf8Str strTrgFormat = "VMDK"; 2115 ULONG lCabs = 0; 2116 2052 2117 if (RTPathHaveExt(strTargetPath.c_str())) 2053 2118 { … … 2060 2125 strTargetPath.c_str()); 2061 2126 /* Check the capabilities. We need create capabilities. */ 2062 ULONGlCabs = 0;2127 lCabs = 0; 2063 2128 com::SafeArray <MediumFormatCapabilities_T> mediumFormatCap; 2064 2129 rc = trgFormat->COMGETTER(Capabilities)(ComSafeArrayAsOutParam(mediumFormatCap)); … … 2088 2153 if (strTrgFormat.compare("RAW", Utf8Str::CaseInsensitive) == 0) 2089 2154 { 2090 /* copy ISO image to the destination folder*/2091 vrc = RTFileCopy(strSrcFilePath.c_str(), strTargetPath.c_str());2092 2093 if (RT_FAILURE(vrc))2094 throw setError(VBOX_E_FILE_ERROR,2095 tr("Could not copy image %s to the destination folder '%s'"),2096 strSrcFilePath.c_str(),2097 strTargetPath.c_str());2098 2099 2155 void *pvTmpBuf = 0; 2100 2156 size_t cbSize = 0; … … 2102 2158 /* Read the ISO file into a memory buffer */ 2103 2159 vrc = ShaReadBuf(strSrcFilePath.c_str(), &pvTmpBuf, &cbSize, pCallbacks, pStorage); 2160 2104 2161 if ( RT_FAILURE(vrc) || !pvTmpBuf) 2105 2162 throw setError(VBOX_E_FILE_ERROR, … … 2107 2164 RTPathFilename(strSrcFilePath.c_str()), vrc); 2108 2165 2166 if (RTFileExists(strTargetPath.c_str()) == false) 2167 { 2168 2169 /* ensure the directory exists */ 2170 if (lCabs & MediumFormatCapabilities_File) 2171 { 2172 rc = VirtualBox::ensureFilePathExists(strTargetPath, true); 2173 if (FAILED(rc)) 2174 throw rc; 2175 } 2176 2177 // create a new file and copy raw data into one from buffer pvTmpBuf 2178 RTFILE pFile = NULL; 2179 vrc = RTFileOpen(&pFile, strTargetPath.c_str(), RTFILE_O_OPEN_CREATE | RTFILE_O_WRITE | RTFILE_O_DENY_NONE); 2180 if (RT_SUCCESS(vrc) && pFile != NULL) 2181 { 2182 size_t cbWritten = 0; 2183 2184 vrc = RTFileWrite(pFile, pvTmpBuf, cbSize, &cbWritten); 2185 2186 if (RT_FAILURE(vrc)) 2187 { 2188 Utf8Str path(strTargetPath); 2189 path = path.stripFilename(); 2190 if (pvTmpBuf) 2191 RTMemFree(pvTmpBuf); 2192 throw setError(VBOX_E_FILE_ERROR, 2193 tr("Could not write the ISO file '%s' into the folder %s (%Rrc)"), 2194 strSrcFilePath.stripPath().c_str(), 2195 path.c_str(), 2196 vrc); 2197 } 2198 } 2199 2200 RTFileClose(pFile); 2201 } 2109 2202 /* Advance to the next operation. */ 2110 2203 stack.pProgress->SetNextOperation(BstrFmt(tr("Importing virtual disk image '%s'"), … … 2146 2239 Utf8Str strSrcFormat = "VDI"; 2147 2240 2148 if ( !di.strFormat.compare("http://www.vmware.com/specifications/vmdk.html#sparse", 2149 Utf8Str::CaseInsensitive) 2150 || !di.strFormat.compare("http://www.vmware.com/interfaces/specifications/vmdk.html#streamOptimized", 2151 Utf8Str::CaseInsensitive) 2152 || !di.strFormat.compare("http://www.vmware.com/specifications/vmdk.html#compressed", 2153 Utf8Str::CaseInsensitive) 2154 || !di.strFormat.compare("http://www.vmware.com/interfaces/specifications/vmdk.html#compressed", 2155 Utf8Str::CaseInsensitive) 2156 ) 2241 std::set<Utf8Str> listURIs = Appliance::URIFromTypeOfVirtualDiskFormat("VMDK"); 2242 std::set<Utf8Str>::const_iterator itr = listURIs.find(di.strFormat); 2243 2244 if (itr != listURIs.end()) 2157 2245 { 2158 2246 strSrcFormat = "VMDK"; 2159 }2160 else if (!di.strFormat.compare("http://go.microsoft.com/fwlink/?LinkId=137171",2161 Utf8Str::CaseInsensitive))2162 {2163 strSrcFormat = "VHD";2164 2247 } 2165 2248 … … 2624 2707 stack.fSessionOpen = true; 2625 2708 2626 /* Iterate over all given disk images */ 2627 list<VirtualSystemDescriptionEntry*>::const_iterator itHD; 2628 for (itHD = avsdeHDs.begin(); 2629 itHD != avsdeHDs.end(); 2630 ++itHD) 2631 { 2632 VirtualSystemDescriptionEntry *vsdeHD = *itHD; 2633 2634 // vsdeHD->strRef contains the disk identifier (e.g. "vmdisk1"), which should exist 2635 // in the virtual system's disks map under that ID and also in the global images map 2636 ovf::VirtualDisksMap::const_iterator itVirtualDisk = vsysThis.mapVirtualDisks.find(vsdeHD->strRef); 2637 // and find the disk from the OVF's disk list 2638 ovf::DiskImagesMap::const_iterator itDiskImage = stack.mapDisks.find(vsdeHD->strRef); 2639 if ( (itVirtualDisk == vsysThis.mapVirtualDisks.end()) 2640 || (itDiskImage == stack.mapDisks.end()) 2641 ) 2642 throw setError(E_FAIL, 2643 tr("Internal inconsistency looking up disk image '%s'"), 2644 vsdeHD->strRef.c_str()); 2645 2646 const ovf::DiskImage &ovfDiskImage = itDiskImage->second; 2647 const ovf::VirtualDisk &ovfVdisk = itVirtualDisk->second; 2709 ovf::DiskImagesMap::const_iterator oit = stack.mapDisks.begin(); 2710 std::set<RTCString> disksResolvedNames; 2711 2712 while(oit != stack.mapDisks.end()) 2713 { 2714 if (RTPathHaveExt(oit->second.strHref.c_str())) 2715 { 2716 /* Figure out which format the user have. */ 2717 char *pszExt = RTPathExt(oit->second.strHref.c_str()); 2718 /* Get the system properties. */ 2719 SystemProperties *pSysProps = mVirtualBox->getSystemProperties(); 2720 ComObjPtr<MediumFormat> trgFormat = pSysProps->mediumFormatFromExtension(&pszExt[1]); 2721 if (trgFormat.isNull()) 2722 { 2723 ++oit; 2724 continue; 2725 } 2726 } 2727 2728 ovf::DiskImage diCurrent = oit->second; 2729 ovf::VirtualDisksMap::const_iterator itVDisk = vsysThis.mapVirtualDisks.begin(); 2730 bool fFoundInCurrentPosition = false; 2731 2732 VirtualSystemDescriptionEntry *vsdeTargetHD = 0; 2733 2734 /* 2735 * 2736 * Iterate over all given disk images of the virtual system 2737 * disks description. We need to find the target disk path, 2738 * which could be changed by the user. 2739 * 2740 */ 2741 { 2742 list<VirtualSystemDescriptionEntry*>::const_iterator itHD; 2743 for (itHD = avsdeHDs.begin(); 2744 itHD != avsdeHDs.end(); 2745 ++itHD) 2746 { 2747 VirtualSystemDescriptionEntry *vsdeHD = *itHD; 2748 if (vsdeHD->strRef == diCurrent.strDiskId) 2749 { 2750 vsdeTargetHD = vsdeHD; 2751 break; 2752 } 2753 } 2754 if (!vsdeTargetHD) 2755 throw setError(E_FAIL, 2756 tr("Internal inconsistency looking up disk image '%s'"), 2757 diCurrent.strHref.c_str()); 2758 2759 //diCurrent.strDiskId contains the disk identifier (e.g. "vmdisk1"), which should exist 2760 //in the virtual system's disks map under that ID and also in the global images map 2761 itVDisk = vsysThis.mapVirtualDisks.find(diCurrent.strDiskId); 2762 if (itVDisk == vsysThis.mapVirtualDisks.end()) 2763 throw setError(E_FAIL, 2764 tr("Internal inconsistency looking up disk image '%s'"), 2765 diCurrent.strHref.c_str()); 2766 } 2767 2768 /* 2769 * 2770 * preliminary check availability of the image 2771 * This step is useful if image is placed in the OVA (TAR) package 2772 * 2773 */ 2774 2775 Utf8Str name = applianceIOName(applianceIOTar); 2776 2777 if (strncmp(pStorage->pVDImageIfaces->pszInterfaceName, name.c_str(), name.length()) == 0) 2778 { 2779 RTCString availableImage(diCurrent.strHref); 2780 2781 rc = preCheckImageAvailability(pStorage, 2782 availableImage 2783 ); 2784 2785 if (SUCCEEDED(rc)) 2786 { 2787 /* current opened file isn't the same as passed one */ 2788 if(availableImage.compare(diCurrent.strHref, Utf8Str::CaseInsensitive) != 0) 2789 { 2790 2791 if (RTPathHaveExt(availableImage.c_str())) 2792 { 2793 /* Figure out which format the user have. */ 2794 char *pszExt = RTPathExt(availableImage.c_str()); 2795 /* Get the system properties. */ 2796 SystemProperties *pSysProps = mVirtualBox->getSystemProperties(); 2797 ComObjPtr<MediumFormat> trgFormat = pSysProps->mediumFormatFromExtension(&pszExt[1]); 2798 if (trgFormat.isNull()) 2799 { 2800 ++oit; 2801 continue; 2802 } 2803 } 2804 2805 /* 2806 * 2807 * availableImage contains the disk file reference (e.g. "disk1.vmdk"), which should exist 2808 * in the global images map. 2809 * And find the disk from the OVF's disk list 2810 * 2811 */ 2812 { 2813 ovf::DiskImagesMap::const_iterator itDiskImage = stack.mapDisks.begin(); 2814 while (++itDiskImage != stack.mapDisks.end()) 2815 { 2816 if (itDiskImage->second.strHref.compare(availableImage, Utf8Str::CaseInsensitive) == 0) 2817 break; 2818 } 2819 if (itDiskImage == stack.mapDisks.end()) 2820 { 2821 throw setError(E_FAIL, 2822 tr("Internal inconsistency looking up disk image '%s'"), 2823 availableImage.c_str()); 2824 } 2825 2826 /* replace with a new found disk image */ 2827 diCurrent = *(&itDiskImage->second); 2828 } 2829 2830 /* 2831 * 2832 * Again iterate over all given disk images of the virtual system 2833 * disks description using the found disk image 2834 * 2835 */ 2836 { 2837 list<VirtualSystemDescriptionEntry*>::const_iterator itHD; 2838 for (itHD = avsdeHDs.begin(); 2839 itHD != avsdeHDs.end(); 2840 ++itHD) 2841 { 2842 VirtualSystemDescriptionEntry *vsdeHD = *itHD; 2843 if (vsdeHD->strRef == diCurrent.strDiskId) 2844 { 2845 vsdeTargetHD = vsdeHD; 2846 break; 2847 } 2848 } 2849 if (!vsdeTargetHD) 2850 throw setError(E_FAIL, 2851 tr("Internal inconsistency looking up disk image '%s'"), 2852 diCurrent.strHref.c_str()); 2853 2854 itVDisk = vsysThis.mapVirtualDisks.find(diCurrent.strDiskId); 2855 if (itVDisk == vsysThis.mapVirtualDisks.end()) 2856 throw setError(E_FAIL, 2857 tr("Internal inconsistency looking up disk image '%s'"), 2858 diCurrent.strHref.c_str()); 2859 } 2860 } 2861 else 2862 { 2863 fFoundInCurrentPosition = true; 2864 ++oit; 2865 } 2866 } 2867 else 2868 { 2869 ++oit; 2870 continue; 2871 } 2872 } 2873 else 2874 { 2875 /* just continue with normal files*/ 2876 fFoundInCurrentPosition = true; 2877 ++oit; 2878 } 2879 2880 /* It means that we possibly have imported the storage earlier on the previous loop steps*/ 2881 if (!fFoundInCurrentPosition) 2882 { 2883 std::set<RTCString>::const_iterator h = disksResolvedNames.find(diCurrent.strHref); 2884 if (h != disksResolvedNames.end()) 2885 { 2886 /* Yes, disk name was found, we can skip it*/ 2887 continue; 2888 } 2889 } 2890 2891 const ovf::VirtualDisk &ovfVdisk = itVDisk->second; 2892 2893 /* very important to store disk name for the next checks */ 2894 disksResolvedNames.insert(diCurrent.strHref); 2648 2895 2649 2896 ComObjPtr<Medium> pTargetHD; 2650 2897 2651 importOneDiskImage( ovfDiskImage,2652 vsde HD->strVboxCurrent,2898 importOneDiskImage(diCurrent, 2899 vsdeTargetHD->strVboxCurrent, 2653 2900 pTargetHD, 2654 2901 stack, … … 2674 2921 mhda.lDevice); 2675 2922 2676 Log(("Attaching disk %s to port %d on device %d\n", vsdeHD->strVboxCurrent.c_str(), mhda.lControllerPort, mhda.lDevice));2677 2678 int ifISO = 0; 2679 ifISO = ovfDiskImage.strFormat.compare("http://www.ecma-international.org/publications/standards/Ecma-119.htm",2680 Utf8Str::CaseInsensitive); 2681 if ( ifISO != 0)2923 Log(("Attaching disk %s to port %d on device %d\n", 2924 vsdeTargetHD->strVboxCurrent.c_str(), mhda.lControllerPort, mhda.lDevice)); 2925 2926 Utf8Str vdf = typeOfVirtualDiskFormatFromURI(diCurrent.strFormat); 2927 2928 if (vdf.compare("RAW", Utf8Str::CaseInsensitive) == 0) 2682 2929 { 2683 rc = sMachine->AttachDevice(mhda.controllerType.raw(), // wstring name 2684 mhda.lControllerPort, // long controllerPort 2685 mhda.lDevice, // long device 2686 DeviceType_HardDisk, // DeviceType_T type 2687 pTargetHD); 2688 2930 ComPtr<IMedium> dvdImage(pTargetHD); 2931 2932 rc = mVirtualBox->OpenMedium(Bstr(vsdeTargetHD->strVboxCurrent).raw(), 2933 DeviceType_DVD, 2934 AccessMode_ReadWrite, 2935 false, 2936 dvdImage.asOutParam()); 2937 2938 if (FAILED(rc)) throw rc; 2939 2940 rc = sMachine->AttachDevice(mhda.controllerType.raw(),// wstring name 2941 mhda.lControllerPort, // long controllerPort 2942 mhda.lDevice, // long device 2943 DeviceType_DVD, // DeviceType_T type 2944 dvdImage); 2689 2945 if (FAILED(rc)) throw rc; 2690 2946 } 2691 2947 else 2692 2948 { 2693 ComPtr<IMedium> dvdImage(pTargetHD); 2694 2695 rc = mVirtualBox->OpenMedium(Bstr(vsdeHD->strVboxCurrent).raw(), 2696 DeviceType_DVD, 2697 AccessMode_ReadWrite, 2698 false, 2699 dvdImage.asOutParam()); 2949 rc = sMachine->AttachDevice(mhda.controllerType.raw(),// wstring name 2950 mhda.lControllerPort, // long controllerPort 2951 mhda.lDevice, // long device 2952 DeviceType_HardDisk, // DeviceType_T type 2953 pTargetHD); 2700 2954 2701 2955 if (FAILED(rc)) throw rc; 2702 2703 rc = sMachine->AttachDevice(mhda.controllerType.raw(), // wstring name2704 mhda.lControllerPort, // long controllerPort2705 mhda.lDevice, // long device2706 DeviceType_DVD, // DeviceType_T type2707 dvdImage);2708 if (FAILED(rc)) throw rc;2709 2710 2956 } 2711 2957 … … 2714 2960 rc = sMachine->SaveSettings(); 2715 2961 if (FAILED(rc)) throw rc; 2716 } // end for (itHD = avsdeHDs.begin();2962 } // end while(oit != stack.mapDisks.end()) 2717 2963 2718 2964 // only now that we're done with all disks, close the session … … 2929 3175 fRepairDuplicate = false; 2930 3176 2931 // for each storage controller... 2932 for (settings::StorageControllersList::iterator sit = config.storageMachine.llStorageControllers.begin(); 2933 sit != config.storageMachine.llStorageControllers.end(); 2934 ++sit) 2935 { 2936 settings::StorageController &sc = *sit; 2937 2938 // find the OVF virtual system description entry for this storage controller 2939 switch (sc.storageBus) 2940 { 2941 case StorageBus_SATA: 2942 break; 2943 case StorageBus_SCSI: 2944 break; 2945 case StorageBus_IDE: 2946 break; 2947 case StorageBus_SAS: 2948 break; 2949 } 2950 2951 // for each medium attachment to this controller... 2952 for (settings::AttachedDevicesList::iterator dit = sc.llAttachedDevices.begin(); 2953 dit != sc.llAttachedDevices.end(); 2954 ++dit) 2955 { 2956 settings::AttachedDevice &d = *dit; 2957 2958 if (d.uuid.isZero()) 2959 // empty DVD and floppy media 3177 // there must be an image in the OVF disk structs with the same UUID 3178 3179 ovf::DiskImagesMap::const_iterator oit = stack.mapDisks.begin(); 3180 std::set<RTCString> disksResolvedNames; 3181 3182 while(oit != stack.mapDisks.end()) 3183 { 3184 if (RTPathHaveExt(oit->first.c_str())) 3185 { 3186 /* Figure out which format the user have. */ 3187 char *pszExt = RTPathExt(oit->second.strHref.c_str()); 3188 /* Get the system properties. */ 3189 SystemProperties *pSysProps = mVirtualBox->getSystemProperties(); 3190 ComObjPtr<MediumFormat> trgFormat = pSysProps->mediumFormatFromExtension(&pszExt[1]); 3191 if (trgFormat.isNull()) 3192 { 3193 ++oit; 2960 3194 continue; 2961 2962 // When repairing a broken VirtualBox xml config section (written 2963 // by VirtualBox versions earlier than 3.2.10) assume the disks 2964 // show up in the same order as in the OVF description. 2965 if (fRepairDuplicate) 2966 { 2967 VirtualSystemDescriptionEntry *vsdeHD = *avsdeHDsIt; 2968 ovf::DiskImagesMap::const_iterator itDiskImage = stack.mapDisks.find(vsdeHD->strRef); 2969 if (itDiskImage != stack.mapDisks.end()) 3195 } 3196 } 3197 3198 ovf::DiskImage diCurrent = oit->second; 3199 bool fFoundInCurrentPosition = false; 3200 3201 VirtualSystemDescriptionEntry *vsdeTargetHD = 0; 3202 3203 { 3204 /* Iterate over all given disk images of the virtual system 3205 * disks description. We need to find the target disk path, 3206 * which could be changed by the user. */ 3207 list<VirtualSystemDescriptionEntry*>::const_iterator itHD; 3208 for (itHD = avsdeHDs.begin(); 3209 itHD != avsdeHDs.end(); 3210 ++itHD) 3211 { 3212 VirtualSystemDescriptionEntry *vsdeHD = *itHD; 3213 if (vsdeHD->strRef == oit->first) 2970 3214 { 2971 const ovf::DiskImage &di = itDiskImage->second;2972 d.uuid = Guid(di.uuidVbox);3215 vsdeTargetHD = vsdeHD; 3216 break; 2973 3217 } 2974 ++avsdeHDsIt; 2975 } 2976 2977 // convert the Guid to string 2978 Utf8Str strUuid = d.uuid.toString(); 2979 2980 // there must be an image in the OVF disk structs with the same UUID 2981 bool fFound = false; 2982 for (ovf::DiskImagesMap::const_iterator oit = stack.mapDisks.begin(); 2983 oit != stack.mapDisks.end(); 2984 ++oit) 2985 { 2986 const ovf::DiskImage &di = oit->second; 2987 2988 if (di.uuidVbox == strUuid) 3218 } 3219 if (!vsdeTargetHD) 3220 throw setError(E_FAIL, 3221 tr("Internal inconsistency looking up disk image '%s'"), 3222 oit->first.c_str()); 3223 } 3224 3225 /* 3226 * 3227 * preliminary check availability of the image 3228 * This step is useful if image is placed in the OVA (TAR) package 3229 * 3230 */ 3231 3232 Utf8Str name = applianceIOName(applianceIOTar); 3233 3234 if (strncmp(pStorage->pVDImageIfaces->pszInterfaceName, name.c_str(), name.length()) == 0) 3235 { 3236 RTCString availableImage(diCurrent.strHref); 3237 3238 rc = preCheckImageAvailability(pStorage, 3239 availableImage 3240 ); 3241 3242 if (SUCCEEDED(rc)) 3243 { 3244 /* current opened file isn't the same as passed one */ 3245 if(availableImage.compare(diCurrent.strHref, Utf8Str::CaseInsensitive) != 0) 2989 3246 { 2990 VirtualSystemDescriptionEntry *vsdeTargetHD = 0; 2991 2992 /* Iterate over all given disk images of the virtual system 2993 * disks description. We need to find the target disk path, 2994 * which could be changed by the user. */ 3247 if (RTPathHaveExt(availableImage.c_str())) 3248 { 3249 /* Figure out which format the user have. */ 3250 char *pszExt = RTPathExt(availableImage.c_str()); 3251 /* Get the system properties. */ 3252 SystemProperties *pSysProps = mVirtualBox->getSystemProperties(); 3253 ComObjPtr<MediumFormat> trgFormat = pSysProps->mediumFormatFromExtension(&pszExt[1]); 3254 if (trgFormat.isNull()) 3255 { 3256 ++oit; 3257 continue; 3258 } 3259 } 3260 3261 // availableImage contains the disk identifier (e.g. "vmdisk1"), which should exist 3262 // in the virtual system's disks map under that ID and also in the global images map 3263 // and find the disk from the OVF's disk list 3264 ovf::DiskImagesMap::const_iterator itDiskImage = stack.mapDisks.begin(); 3265 while (++itDiskImage != stack.mapDisks.end()) 3266 { 3267 if(itDiskImage->second.strHref.compare(availableImage, Utf8Str::CaseInsensitive) == 0 ) 3268 break; 3269 } 3270 if (itDiskImage == stack.mapDisks.end()) 3271 { 3272 throw setError(E_FAIL, 3273 tr("Internal inconsistency looking up disk image '%s'"), 3274 availableImage.c_str()); 3275 } 3276 3277 /* replace with a new found disk image */ 3278 diCurrent = *(&itDiskImage->second); 3279 3280 /* Again iterate over all given disk images of the virtual system 3281 * disks description using the found disk image 3282 */ 2995 3283 list<VirtualSystemDescriptionEntry*>::const_iterator itHD; 2996 3284 for (itHD = avsdeHDs.begin(); … … 2999 3287 { 3000 3288 VirtualSystemDescriptionEntry *vsdeHD = *itHD; 3001 if (vsdeHD->strRef == oit->first)3289 if (vsdeHD->strRef == diCurrent.strDiskId) 3002 3290 { 3003 3291 vsdeTargetHD = vsdeHD; … … 3008 3296 throw setError(E_FAIL, 3009 3297 tr("Internal inconsistency looking up disk image '%s'"), 3010 oit->first.c_str()); 3011 3012 /* 3013 * 3014 * step 3: import disk 3015 * 3016 */ 3017 ComObjPtr<Medium> pTargetHD; 3018 importOneDiskImage(di, 3019 vsdeTargetHD->strVboxCurrent, 3020 pTargetHD, 3021 stack, 3022 pCallbacks, 3023 pStorage); 3024 3025 Bstr hdId; 3026 int ifISO = 0; 3027 ifISO = di.strFormat.compare("http://www.ecma-international.org/publications/standards/Ecma-119.htm", 3028 Utf8Str::CaseInsensitive); 3029 if ( ifISO == 0) 3298 diCurrent.strHref.c_str()); 3299 } 3300 else 3301 { 3302 fFoundInCurrentPosition = true; 3303 ++oit; 3304 } 3305 } 3306 else 3307 { 3308 ++oit; 3309 continue; 3310 } 3311 } 3312 else 3313 { 3314 /* just continue with normal files*/ 3315 fFoundInCurrentPosition = true; 3316 ++oit; 3317 } 3318 3319 /* It means that we possibly have imported the storage earlier on the previous loop steps*/ 3320 if (!fFoundInCurrentPosition) 3321 { 3322 std::set<RTCString>::const_iterator h = disksResolvedNames.find(diCurrent.strHref); 3323 if (h != disksResolvedNames.end()) 3324 { 3325 /* Yes, disk name was found, we can skip it*/ 3326 continue; 3327 } 3328 } 3329 3330 /* Important! to store disk name for the next checks */ 3331 disksResolvedNames.insert(diCurrent.strHref); 3332 3333 // there must be an image in the OVF disk structs with the same UUID 3334 bool fFound = false; 3335 Utf8Str strUuid; 3336 3337 // for each storage controller... 3338 for (settings::StorageControllersList::iterator sit = config.storageMachine.llStorageControllers.begin(); 3339 sit != config.storageMachine.llStorageControllers.end(); 3340 ++sit) 3341 { 3342 settings::StorageController &sc = *sit; 3343 3344 // find the OVF virtual system description entry for this storage controller 3345 switch (sc.storageBus) 3346 { 3347 case StorageBus_SATA: 3348 break; 3349 case StorageBus_SCSI: 3350 break; 3351 case StorageBus_IDE: 3352 break; 3353 case StorageBus_SAS: 3354 break; 3355 } 3356 3357 // for each medium attachment to this controller... 3358 for (settings::AttachedDevicesList::iterator dit = sc.llAttachedDevices.begin(); 3359 dit != sc.llAttachedDevices.end(); 3360 ++dit) 3361 { 3362 settings::AttachedDevice &d = *dit; 3363 3364 if (d.uuid.isZero()) 3365 // empty DVD and floppy media 3366 continue; 3367 3368 // When repairing a broken VirtualBox xml config section (written 3369 // by VirtualBox versions earlier than 3.2.10) assume the disks 3370 // show up in the same order as in the OVF description. 3371 if (fRepairDuplicate) 3372 { 3373 VirtualSystemDescriptionEntry *vsdeHD = *avsdeHDsIt; 3374 ovf::DiskImagesMap::const_iterator itDiskImage = stack.mapDisks.find(vsdeHD->strRef); 3375 if (itDiskImage != stack.mapDisks.end()) 3030 3376 { 3031 ComPtr<IMedium> dvdImage(pTargetHD); 3032 3033 rc = mVirtualBox->OpenMedium(Bstr(vsdeTargetHD->strVboxCurrent).raw(), 3034 DeviceType_DVD, 3035 AccessMode_ReadWrite, 3036 false, 3037 dvdImage.asOutParam()); 3038 3039 if (FAILED(rc)) throw rc; 3040 3041 // ... and replace the old UUID in the machine config with the one of 3042 // the imported disk that was just created 3043 rc = dvdImage->COMGETTER(Id)(hdId.asOutParam()); 3044 if (FAILED(rc)) throw rc; 3377 const ovf::DiskImage &di = itDiskImage->second; 3378 d.uuid = Guid(di.uuidVbox); 3045 3379 } 3046 else 3047 { 3048 // ... and replace the old UUID in the machine config with the one of 3049 // the imported disk that was just created 3050 rc = pTargetHD->COMGETTER(Id)(hdId.asOutParam()); 3051 if (FAILED(rc)) throw rc; 3052 } 3053 3054 d.uuid = hdId; 3055 3056 fFound = true; 3057 break; 3380 ++avsdeHDsIt; 3058 3381 } 3059 } 3382 3383 // convert the Guid to string 3384 strUuid = d.uuid.toString(); 3385 3386 if (diCurrent.uuidVbox != strUuid) 3387 { 3388 continue; 3389 } 3390 /* 3391 * 3392 * step 3: import disk 3393 * 3394 */ 3395 ComObjPtr<Medium> pTargetHD; 3396 importOneDiskImage(diCurrent, 3397 vsdeTargetHD->strVboxCurrent, 3398 pTargetHD, 3399 stack, 3400 pCallbacks, 3401 pStorage); 3402 3403 Bstr hdId; 3404 3405 Utf8Str vdf = typeOfVirtualDiskFormatFromURI(diCurrent.strFormat); 3406 3407 if (vdf.compare("RAW", Utf8Str::CaseInsensitive) == 0) 3408 { 3409 ComPtr<IMedium> dvdImage(pTargetHD); 3410 3411 rc = mVirtualBox->OpenMedium(Bstr(vsdeTargetHD->strVboxCurrent).raw(), 3412 DeviceType_DVD, 3413 AccessMode_ReadWrite, 3414 false, 3415 dvdImage.asOutParam()); 3416 3417 if (FAILED(rc)) throw rc; 3418 3419 // ... and replace the old UUID in the machine config with the one of 3420 // the imported disk that was just created 3421 rc = dvdImage->COMGETTER(Id)(hdId.asOutParam()); 3422 if (FAILED(rc)) throw rc; 3423 } 3424 else 3425 { 3426 // ... and replace the old UUID in the machine config with the one of 3427 // the imported disk that was just created 3428 rc = pTargetHD->COMGETTER(Id)(hdId.asOutParam()); 3429 if (FAILED(rc)) throw rc; 3430 } 3431 3432 d.uuid = hdId; 3433 fFound = true; 3434 break; 3435 } // for (settings::AttachedDevicesList::const_iterator dit = sc.llAttachedDevices.begin(); 3436 } // for (settings::StorageControllersList::const_iterator sit = config.storageMachine.llStorageControllers.begin(); 3060 3437 3061 3438 // no disk with such a UUID found: 3062 if (!fFound) 3063 throw setError(E_FAIL, 3064 tr("<vbox:Machine> element in OVF contains a medium attachment for the disk image %s but the OVF describes no such image"), 3065 strUuid.c_str()); 3066 } // for (settings::AttachedDevicesList::const_iterator dit = sc.llAttachedDevices.begin(); 3067 } // for (settings::StorageControllersList::const_iterator sit = config.storageMachine.llStorageControllers.begin(); 3439 if (!fFound) 3440 throw setError(E_FAIL, 3441 tr("<vbox:Machine> element in OVF contains a medium attachment for the disk image %s " 3442 "but the OVF describes no such image"), 3443 strUuid.c_str()); 3444 3445 }// while(oit != stack.mapDisks.end()) 3068 3446 3069 3447 /* … … 3080 3458 // instance that we created from the vbox:Machine 3081 3459 rc = pNewMachine->init(mVirtualBox, 3082 stack.strNameVBox, 3083 config); 3460 stack.strNameVBox,// name from OVF preparations; can be suffixed to avoid duplicates, or changed by user 3461 config); // the whole machine config 3084 3462 if (FAILED(rc)) throw rc; 3085 3463 … … 3225 3603 } 3226 3604 3605 -
trunk/src/VBox/Main/xml/ovfreader.cpp
r46169 r46518 91 91 } 92 92 93 // if ((pTypeAttr = pRootElem->findAttribute("version")))94 // {95 // pcszTypeAttr = pTypeAttr->getValue();96 // m_envelopeData.version = pcszTypeAttr;97 // }98 // else99 // {100 // throw OVFLogicError(N_("Error reading \"%s\": missing or invalid attribute '%s' in 'Envelope' element, line %d"),101 // m_strPath.c_str(),102 // "version",103 // pRootElem->getLineNumber());104 // }105 106 93 if ((pTypeAttr = pRootElem->findAttribute("xml:lang"))) 107 94 { … … 255 242 ) 256 243 { 244 257 245 // copy remaining values from file node then 258 246 const char *pcszBadInFile = NULL; … … 432 420 } 433 421 434 xml::NodesLoop loopVirtualHardwareItems(*pelmThis, "Item"); // all "Item" child elements435 const xml::ElementNode *pelmItem;436 while ((pelmItem = loopVirtualHardwareItems.forAllNodes()))437 422 { 438 VirtualHardwareItem i; 439 440 i.ulLineNumber = pelmItem->getLineNumber(); 441 442 xml::NodesLoop loopItemChildren(*pelmItem); // all child elements 443 const xml::ElementNode *pelmItemChild; 444 while ((pelmItemChild = loopItemChildren.forAllNodes())) 423 xml::NodesLoop loopVirtualHardwareItems(*pelmThis, "Item"); // all "Item" child elements 424 const xml::ElementNode *pelmItem; 425 while ((pelmItem = loopVirtualHardwareItems.forAllNodes())) 445 426 { 446 const char *pcszItemChildName = pelmItemChild->getName(); 447 if (!strcmp(pcszItemChildName, "Description")) 448 i.strDescription = pelmItemChild->getValue(); 449 else if (!strcmp(pcszItemChildName, "Caption")) 450 i.strCaption = pelmItemChild->getValue(); 451 else if (!strcmp(pcszItemChildName, "ElementName")) 452 i.strElementName = pelmItemChild->getValue(); 453 else if ( (!strcmp(pcszItemChildName, "InstanceID")) 454 || (!strcmp(pcszItemChildName, "InstanceId")) 455 ) 456 pelmItemChild->copyValue(i.ulInstanceID); 457 else if (!strcmp(pcszItemChildName, "HostResource")) 458 i.strHostResource = pelmItemChild->getValue(); 459 else if (!strcmp(pcszItemChildName, "ResourceType")) 427 VirtualHardwareItem i; 428 429 i.ulLineNumber = pelmItem->getLineNumber(); 430 i.fillItem(pelmItem); 431 try{ 432 i.checkConsistencyAndCompliance(); 433 } 434 catch (OVFLogicError &e) 460 435 { 461 uint32_t ulType; 462 pelmItemChild->copyValue(ulType); 463 i.resourceType = (ResourceType_T)ulType; 464 i.fResourceRequired = true; 465 const char *pcszAttValue; 466 if (pelmItem->getAttributeValue("required", pcszAttValue)) 467 { 468 if (!strcmp(pcszAttValue, "false")) 469 i.fResourceRequired = false; 470 } 471 } 472 else if (!strcmp(pcszItemChildName, "OtherResourceType")) 473 i.strOtherResourceType = pelmItemChild->getValue(); 474 else if (!strcmp(pcszItemChildName, "ResourceSubType")) 475 i.strResourceSubType = pelmItemChild->getValue(); 476 else if (!strcmp(pcszItemChildName, "AutomaticAllocation")) 477 i.fAutomaticAllocation = (!strcmp(pelmItemChild->getValue(), "true")) ? true : false; 478 else if (!strcmp(pcszItemChildName, "AutomaticDeallocation")) 479 i.fAutomaticDeallocation = (!strcmp(pelmItemChild->getValue(), "true")) ? true : false; 480 else if (!strcmp(pcszItemChildName, "Parent")) 481 pelmItemChild->copyValue(i.ulParent); 482 else if (!strcmp(pcszItemChildName, "Connection")) 483 i.strConnection = pelmItemChild->getValue(); 484 else if (!strcmp(pcszItemChildName, "Address")) 436 throw OVFLogicError(N_("Error reading \"%s\": \"%s\""), 437 m_strPath.c_str(), 438 e.what()); 439 } 440 441 // store! 442 vsys.mapHardwareItems[i.ulInstanceID] = i; 443 } 444 } 445 446 { 447 xml::NodesLoop loopVirtualHardwareItems(*pelmThis, "StorageItem");// all "StorageItem" child elements 448 const xml::ElementNode *pelmItem; 449 while ((pelmItem = loopVirtualHardwareItems.forAllNodes())) 450 { 451 StorageItem i; 452 453 i.ulLineNumber = pelmItem->getLineNumber(); 454 i.fillItem(pelmItem); 455 456 try 485 457 { 486 i.strAddress = pelmItemChild->getValue(); 487 pelmItemChild->copyValue(i.lAddress); 488 } 489 else if (!strcmp(pcszItemChildName, "AddressOnParent")) 490 i.strAddressOnParent = pelmItemChild->getValue(); 491 else if (!strcmp(pcszItemChildName, "AllocationUnits")) 492 i.strAllocationUnits = pelmItemChild->getValue(); 493 else if (!strcmp(pcszItemChildName, "VirtualQuantity")) 494 pelmItemChild->copyValue(i.ullVirtualQuantity); 495 else if (!strcmp(pcszItemChildName, "Reservation")) 496 pelmItemChild->copyValue(i.ullReservation); 497 else if (!strcmp(pcszItemChildName, "Limit")) 498 pelmItemChild->copyValue(i.ullLimit); 499 else if (!strcmp(pcszItemChildName, "Weight")) 500 pelmItemChild->copyValue(i.ullWeight); 501 else if (!strcmp(pcszItemChildName, "ConsumerVisibility")) 502 i.strConsumerVisibility = pelmItemChild->getValue(); 503 else if (!strcmp(pcszItemChildName, "MappingBehavior")) 504 i.strMappingBehavior = pelmItemChild->getValue(); 505 else if (!strcmp(pcszItemChildName, "PoolID")) 506 i.strPoolID = pelmItemChild->getValue(); 507 else if (!strcmp(pcszItemChildName, "BusNumber")) // seen in some old OVF, but it's not listed in the OVF specs 508 pelmItemChild->copyValue(i.ulBusNumber); 509 else if ( pelmItemChild->getPrefix() == NULL 510 || strcmp(pelmItemChild->getPrefix(), "vmw")) 511 throw OVFLogicError(N_("Error reading \"%s\": unknown element \"%s\" under Item element, line %d"), 458 i.checkConsistencyAndCompliance(); 459 } 460 catch (OVFLogicError &e) 461 { 462 throw OVFLogicError(N_("Error reading \"%s\": \"%s\""), 512 463 m_strPath.c_str(), 513 pcszItemChildName, 514 i.ulLineNumber); 464 e.what()); 465 } 466 467 vsys.mapHardwareItems[i.ulInstanceID] = i; 515 468 } 516 517 // store!518 vsys.mapHardwareItems[i.ulInstanceID] = i;519 469 } 520 470 521 HardDiskController *pPrimaryIDEController = NULL; // will be set once found 471 { 472 xml::NodesLoop loopVirtualHardwareItems(*pelmThis, "EthernetPortItem");// all "EthernetPortItem" child elements 473 const xml::ElementNode *pelmItem; 474 while ((pelmItem = loopVirtualHardwareItems.forAllNodes())) 475 { 476 EthernetPortItem i; 477 478 i.ulLineNumber = pelmItem->getLineNumber(); 479 i.fillItem(pelmItem); 480 481 try{ 482 i.checkConsistencyAndCompliance(); 483 } 484 catch (OVFLogicError &e) 485 { 486 throw OVFLogicError(N_("Error reading \"%s\": \"%s\""), 487 m_strPath.c_str(), 488 e.what()); 489 } 490 491 vsys.mapHardwareItems[i.ulInstanceID] = i; 492 } 493 } 494 495 HardDiskController *pPrimaryIDEController = NULL;// will be set once found 522 496 523 497 // now go thru all hardware items and handle them according to their type; … … 857 831 } 858 832 833 void VirtualHardwareItem::fillItem(const xml::ElementNode *item) 834 { 835 xml::NodesLoop loopItemChildren(*item);// all child elements 836 const xml::ElementNode *pelmItemChild; 837 while ((pelmItemChild = loopItemChildren.forAllNodes())) 838 { 839 const char *pcszItemChildName = pelmItemChild->getName(); 840 if (!strcmp(pcszItemChildName, "Description")) 841 strDescription = pelmItemChild->getValue(); 842 else if (!strcmp(pcszItemChildName, "Caption")) 843 strCaption = pelmItemChild->getValue(); 844 else if (!strcmp(pcszItemChildName, "ElementName")) 845 strElementName = pelmItemChild->getValue(); 846 else if ((!strcmp(pcszItemChildName, "InstanceID")) 847 ||(!strcmp(pcszItemChildName, "InstanceId")) 848 ) 849 pelmItemChild->copyValue(ulInstanceID); 850 else if (!strcmp(pcszItemChildName, "HostResource")) 851 strHostResource = pelmItemChild->getValue(); 852 else if (!strcmp(pcszItemChildName, "ResourceType")) 853 { 854 uint32_t ulType; 855 pelmItemChild->copyValue(ulType); 856 resourceType = (ResourceType_T)ulType; 857 fResourceRequired = true; 858 const char *pcszAttValue; 859 if (pelmItemChild->getAttributeValue("required", pcszAttValue)) 860 { 861 if (!strcmp(pcszAttValue, "false")) 862 fResourceRequired = false; 863 } 864 } 865 else if (!strcmp(pcszItemChildName, "OtherResourceType")) 866 strOtherResourceType = pelmItemChild->getValue(); 867 else if (!strcmp(pcszItemChildName, "ResourceSubType")) 868 strResourceSubType = pelmItemChild->getValue(); 869 else if (!strcmp(pcszItemChildName, "AutomaticAllocation")) 870 fAutomaticAllocation = (!strcmp(pelmItemChild->getValue(), "true")) ? true : false; 871 else if (!strcmp(pcszItemChildName, "AutomaticDeallocation")) 872 fAutomaticDeallocation = (!strcmp(pelmItemChild->getValue(), "true")) ? true : false; 873 else if (!strcmp(pcszItemChildName, "Parent")) 874 pelmItemChild->copyValue(ulParent); 875 else if (!strcmp(pcszItemChildName, "Connection")) 876 strConnection = pelmItemChild->getValue(); 877 else if (!strcmp(pcszItemChildName, "Address")) 878 { 879 strAddress = pelmItemChild->getValue(); 880 pelmItemChild->copyValue(lAddress); 881 } 882 else if (!strcmp(pcszItemChildName, "AddressOnParent")) 883 strAddressOnParent = pelmItemChild->getValue(); 884 else if (!strcmp(pcszItemChildName, "AllocationUnits")) 885 strAllocationUnits = pelmItemChild->getValue(); 886 else if (!strcmp(pcszItemChildName, "VirtualQuantity")) 887 pelmItemChild->copyValue(ullVirtualQuantity); 888 else if (!strcmp(pcszItemChildName, "Reservation")) 889 pelmItemChild->copyValue(ullReservation); 890 else if (!strcmp(pcszItemChildName, "Limit")) 891 pelmItemChild->copyValue(ullLimit); 892 else if (!strcmp(pcszItemChildName, "Weight")) 893 pelmItemChild->copyValue(ullWeight); 894 else if (!strcmp(pcszItemChildName, "ConsumerVisibility")) 895 strConsumerVisibility = pelmItemChild->getValue(); 896 else if (!strcmp(pcszItemChildName, "MappingBehavior")) 897 strMappingBehavior = pelmItemChild->getValue(); 898 else if (!strcmp(pcszItemChildName, "PoolID")) 899 strPoolID = pelmItemChild->getValue(); 900 else if (!strcmp(pcszItemChildName, "BusNumber")) 901 pelmItemChild->copyValue(ulBusNumber); 902 // else if (pelmItemChild->getPrefix() == NULL 903 // || strcmp(pelmItemChild->getPrefix(), "vmw")) 904 // throw OVFLogicError(N_("Unknown element \"%s\" under Item element, line %d"), 905 // pcszItemChildName, 906 // ulLineNumber); 907 } 908 } 909 910 void VirtualHardwareItem::_checkConsistencyAndCompliance() throw (OVFLogicError) 911 { 912 RTCString name = getItemName(); 913 if (ulInstanceID == 0) 914 throw OVFLogicError(N_("Element InstanceID is absent under %s element, line %d. " 915 "see DMTF Schema Documentation %s"), 916 name.c_str(), ulLineNumber, DTMF_SPECS_URI); 917 if (resourceType == 0) 918 throw OVFLogicError(N_("Empty element ResourceType under %s element, line %d. " 919 "see DMTF Schema Documentation %s"), 920 name.c_str(), ulLineNumber, DTMF_SPECS_URI); 921 } 922 923 void StorageItem::fillItem(const xml::ElementNode *item) 924 { 925 VirtualHardwareItem::fillItem(item); 926 927 xml::NodesLoop loopItemChildren(*item);// all child elements 928 const xml::ElementNode *pelmItemChild; 929 while ((pelmItemChild = loopItemChildren.forAllNodes())) 930 { 931 const char *pcszItemChildName = pelmItemChild->getName(); 932 if (!strcmp(pcszItemChildName, "HostExtentName")) 933 strHostExtentName = pelmItemChild->getValue(); 934 else if (!strcmp(pcszItemChildName, "OtherHostExtentNameFormat")) 935 strOtherHostExtentNameFormat = pelmItemChild->getValue(); 936 else if (!strcmp(pcszItemChildName, "OtherHostExtentNameNamespace")) 937 strOtherHostExtentNameNamespace = pelmItemChild->getValue(); 938 else if (!strcmp(pcszItemChildName, "VirtualQuantityUnits")) 939 strVirtualQuantityUnits = pelmItemChild->getValue(); 940 else if (!strcmp(pcszItemChildName, "Access")) 941 { 942 uint32_t temp; 943 pelmItemChild->copyValue(temp); 944 accessType = (StorageAccessType_T)temp; 945 } 946 else if (!strcmp(pcszItemChildName, "HostExtentNameFormat")) 947 { 948 } 949 else if (!strcmp(pcszItemChildName, "HostExtentNameNamespace")) 950 { 951 } 952 else if (!strcmp(pcszItemChildName, "HostExtentStartingAddress")) 953 { 954 } 955 else if (!strcmp(pcszItemChildName, "HostResourceBlockSize")) 956 { 957 int64_t temp; 958 pelmItemChild->copyValue(temp); 959 hostResourceBlockSize = temp; 960 } 961 else if (!strcmp(pcszItemChildName, "Limit")) 962 { 963 int64_t temp; 964 pelmItemChild->copyValue(temp); 965 limit = temp; 966 } 967 else if (!strcmp(pcszItemChildName, "Reservation")) 968 { 969 int64_t temp; 970 pelmItemChild->copyValue(temp); 971 reservation = temp; 972 } 973 else if (!strcmp(pcszItemChildName, "VirtualQuantity")) 974 { 975 int64_t temp; 976 pelmItemChild->copyValue(temp); 977 virtualQuantity = temp; 978 } 979 else if (!strcmp(pcszItemChildName, "VirtualResourceBlockSize")) 980 { 981 int64_t temp; 982 pelmItemChild->copyValue(temp); 983 virtualResourceBlockSize = temp; 984 } 985 } 986 } 987 988 989 void StorageItem::_checkConsistencyAndCompliance() throw (OVFLogicError) 990 { 991 VirtualHardwareItem::_checkConsistencyAndCompliance(); 992 993 RTCString name = getItemName(); 994 995 if (accessType == StorageAccessType_Unknown) 996 { 997 //throw OVFLogicError(N_("Access type is unknown under %s element, line %d"), 998 // name.c_str(), ulLineNumber); 999 } 1000 1001 if (hostResourceBlockSize <= 0 && reservation > 0) 1002 { 1003 throw OVFLogicError(N_("Element HostResourceBlockSize is absent under %s element, line %d. " 1004 "see DMTF Schema Documentation %s"), 1005 name.c_str(), ulLineNumber, DTMF_SPECS_URI); 1006 } 1007 1008 if (virtualResourceBlockSize <= 0 && virtualQuantity > 0) 1009 { 1010 throw OVFLogicError(N_("Element VirtualResourceBlockSize is absent under %s element, line %d. " 1011 "see DMTF Schema Documentation %s"), 1012 name.c_str(), ulLineNumber, DTMF_SPECS_URI); 1013 } 1014 1015 if (virtualQuantity > 0 && strVirtualQuantityUnits.isEmpty()) 1016 { 1017 throw OVFLogicError(N_("Element VirtualQuantityUnits is absent under %s element, line %d. " 1018 "see DMTF Schema Documentation %s"), 1019 name.c_str(), ulLineNumber, DTMF_SPECS_URI); 1020 } 1021 1022 if (virtualResourceBlockSize <= 1 && 1023 strVirtualQuantityUnits.compare(RTCString("count"), RTCString::CaseInsensitive) == 0 1024 ) 1025 { 1026 throw OVFLogicError(N_("Element VirtualQuantityUnits is set to \"count\" " 1027 "while VirtualResourceBlockSize is set to 1. " 1028 "under %s element, line %d. " 1029 "It's needed to change on \"byte\". " 1030 "see DMTF Schema Documentation %s"), 1031 name.c_str(), ulLineNumber, DTMF_SPECS_URI); 1032 } 1033 } 1034 1035 void EthernetPortItem::fillItem(const xml::ElementNode *item) 1036 { 1037 VirtualHardwareItem::fillItem(item); 1038 1039 xml::NodesLoop loopItemChildren(*item);// all child elements 1040 const xml::ElementNode *pelmItemChild; 1041 while ((pelmItemChild = loopItemChildren.forAllNodes())) 1042 { 1043 } 1044 } 1045 1046 void EthernetPortItem::_checkConsistencyAndCompliance() throw (OVFLogicError) 1047 { 1048 VirtualHardwareItem::_checkConsistencyAndCompliance(); 1049 } 1050 859 1051 //////////////////////////////////////////////////////////////////////////////// 860 1052 // -
trunk/src/VBox/Runtime/common/zip/tar.cpp
r46338 r46518 90 90 typedef RTTARRECORD *PRTTARRECORD; 91 91 92 93 #if 0 /* not currently used */94 typedef struct RTTARFILELIST95 {96 char *pszFilename;97 RTTARFILELIST *pNext;98 } RTTARFILELIST;99 typedef RTTARFILELIST *PRTTARFILELIST;100 #endif101 102 92 /** Pointer to a tar file handle. */ 103 93 typedef struct RTTARFILEINTERNAL *PRTTARFILEINTERNAL; … … 150 140 typedef RTTARFILEINTERNAL *PRTTARFILEINTERNAL; 151 141 142 #if 0 /* not currently used */ 143 typedef struct RTTARFILELIST 144 { 145 char *pszFilename; 146 RTTARFILELIST *pNext; 147 } RTTARFILELIST; 148 typedef RTTARFILELIST *PRTTARFILELIST; 149 #endif 150 151 152 152 153 153 /******************************************************************************
Note:
See TracChangeset
for help on using the changeset viewer.