VirtualBox

Changeset 46518 in vbox


Ignore:
Timestamp:
Jun 13, 2013 10:07:09 AM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
86374
Message:

Export/import OVA/OVF package supports ISO images. The problem with the wrong search files in the archive has been resolved. (see #5429). 2 new elements SASD and EPASD were added in the OVF XML file structure (see #6022).

Location:
trunk/src/VBox
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/ApplianceImpl.h

    r45227 r46518  
    2727 * private classes. */
    2828#include <iprt/tar.h>
     29#include <iprt/circbuf.h>
     30#include <VBox/vd.h>
     31#include <iprt/sha.h>
    2932
    3033#include "ovfreader.h"
     34#include <set>
    3135
    3236/* VBox forward declarations */
     
    3842typedef struct VDINTERFACEIO *PVDINTERFACEIO;
    3943typedef struct SHASTORAGE    *PSHASTORAGE;
     44
     45typedef enum applianceIOName { applianceIOTar, applianceIOFile } APPLIANCEIONAME;
    4046
    4147namespace ovf
     
    139145    static DECLCALLBACK(int) taskThreadImportOrExport(RTTHREAD aThread, void *pvUser);
    140146
     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
    141157    /*******************************************************************************
    142158     * Read stuff
     
    178194                            PVDINTERFACEIO pCallbacks,
    179195                            PSHASTORAGE pStorage);
     196
    180197    void importMachineGeneric(const ovf::VirtualSystem &vsysThis,
    181198                              ComObjPtr<VirtualSystemDescription> &vsdescThis,
     
    219236                                     XMLStack &stack);
    220237
     238    HRESULT preCheckImageAvailability(PSHASTORAGE pSHAStorage,
     239                                      RTCString &availableImage);
     240
    221241    friend class Machine;
    222242};
  • trunk/src/VBox/Main/include/ApplianceImplPrivate.h

    r45622 r46518  
    2222
    2323#include "ovfreader.h"
     24#include <map>
    2425
    2526////////////////////////////////////////////////////////////////////////////////
     
    230231bool checkComplianceDigestAndOVFVersion(bool digestType, ovf::OVFVersion_T ovfVersion);
    231232
     233
    232234typedef struct SHASTORAGE
    233235{
  • trunk/src/VBox/Main/include/ovfreader.h

    r46169 r46518  
    2626namespace ovf
    2727{
     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
     41class OVFLogicError : public xml::LogicError
     42{
     43public:
     44    OVFLogicError(const char *aFormat, ...);
     45};
    2846
    2947////////////////////////////////////////////////////////////////////////////////
     
    173191const char* const OVF20_URI_string = "http://schemas.dmtf.org/ovf/envelope/2";
    174192
     193const char* const DTMF_SPECS_URI = "http://schemas.dmtf.org/wbem/cim-html/2/";
     194
    175195////////////////////////////////////////////////////////////////////////////////
    176196//
     
    206226    }
    207227};
     228
     229
     230struct FileReference
     231{
     232    RTCString strHref;       // value from /References/File/@href (filename)
     233    RTCString strDiskId;     // value from /References/File/@id ()
     234};
     235
     236typedef std::map<uint32_t, FileReference> FileReferenceMap;
    208237
    209238////////////////////////////////////////////////////////////////////////////////
     
    261290};
    262291
    263 struct VirtualHardwareItem
    264 {
     292
     293enum StorageAccessType_T
     294{   StorageAccessType_Unknown = 0,
     295    StorageAccessType_Readable = 1,
     296    StorageAccessType_Writeable = 2,
     297    StorageAccessType_ReadWrite = 3
     298};
     299
     300enum ComplianceType_T
     301{   ComplianceType_No = 0,
     302    ComplianceType_Soft = 1,
     303    ComplianceType_Medium = 2,
     304    ComplianceType_Strong = 3
     305};
     306
     307class VirtualHardwareItem
     308{
     309public:
    265310    RTCString strDescription;
    266311    RTCString strCaption;
     
    310355          ulBusNumber(0),
    311356          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
     378protected:
     379    virtual void _checkConsistencyAndCompliance() throw (OVFLogicError);
     380    virtual const RTCString& getItemName()
     381    {
     382        return _getItemName();
     383    }
     384
     385private:
     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
     395class 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
     412public:
     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
     429protected:
     430    virtual void _checkConsistencyAndCompliance() throw (OVFLogicError);
     431private:
     432    RTCString itemName;
     433
     434    virtual const RTCString& _getItemName()
     435    {
     436        return itemName;
     437    }
     438};
     439
     440
     441class 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
     467public:
     468    EthernetPortItem(): VirtualHardwareItem()
     469    {
     470        itemName = "EthernetPortItem";
     471    };
     472
     473    void fillItem(const xml::ElementNode *item);
     474
     475protected:
     476    virtual void _checkConsistencyAndCompliance() throw (OVFLogicError);
     477private:
     478    RTCString itemName;
     479
     480    virtual const RTCString& _getItemName()
     481    {
     482        return itemName;
     483    }
    313484};
    314485
     
    484655};
    485656
    486 ////////////////////////////////////////////////////////////////////////////////
    487 //
    488 // Errors
    489 //
    490 ////////////////////////////////////////////////////////////////////////////////
    491 
    492 /**
    493  * Thrown by OVFReader for any kind of error that is not an XML error but
    494  * still makes the OVF impossible to parse. Based on xml::LogicError so
    495  * that one catch() for all xml::LogicError can handle all possible errors.
    496  */
    497 
    498 class OVFLogicError : public xml::LogicError
    499 {
    500 public:
    501     OVFLogicError(const char *aFormat, ...);
    502 };
    503 
    504657} // end namespace ovf
    505658
  • trunk/src/VBox/Main/src-server/ApplianceImpl.cpp

    r46341 r46518  
    1919#include <iprt/path.h>
    2020#include <iprt/cpp/utils.h>
    21 
    2221#include <VBox/com/array.h>
     22#include <map>
    2323
    2424#include "ApplianceImpl.h"
     
    2929#include "ProgressImpl.h"
    3030#include "MachineImpl.h"
    31 
     31#include "MediumFormatImpl.h"
     32#include "SystemPropertiesImpl.h"
    3233#include "AutoCaller.h"
    3334#include "Logging.h"
     
    4243//
    4344////////////////////////////////////////////////////////////////////////////////
     45
     46static const char* const strISOURI = "http://www.ecma-international.org/publications/standards/Ecma-119.htm";
     47static const char* const strVMDKStreamURI = "http://www.vmware.com/interfaces/specifications/vmdk.html#streamOptimized";
     48static const char* const strVMDKSparseURI = "http://www.vmware.com/specifications/vmdk.html#sparse";
     49static const char* const strVMDKCompressedURI = "http://www.vmware.com/specifications/vmdk.html#compressed";
     50static const char* const strVMDKCompressedURI2 = "http://www.vmware.com/interfaces/specifications/vmdk.html#compressed";
     51static const char* const strVHDURI = "http://go.microsoft.com/fwlink/?LinkId=137171";
     52
     53static std::map<Utf8Str, Utf8Str> supportedStandardsURI;
     54
     55static const char* const applianceIOTarName = "Appliance::IOTar";
     56static const char* const applianceIOFileName = "Appliance::IOFile";
     57
     58static std::map<APPLIANCEIONAME, Utf8Str> applianceIONameMap;
    4459
    4560static const struct
     
    304319}
    305320
     321
    306322////////////////////////////////////////////////////////////////////////////////
    307323//
     
    355371HRESULT Appliance::init(VirtualBox *aVirtualBox)
    356372{
     373    HRESULT rc = S_OK;
    357374    /* Enclose the state transition NotReady->InInit->Ready */
    358375    AutoInitSpan autoInitSpan(this);
     
    365382    m = new Data;
    366383
     384    initApplianceIONameMap();
     385
     386    rc = initSetOfSupportedStandardsURI();
     387
    367388    /* Confirm a successful initialization */
    368389    autoInitSpan.setSucceeded();
    369390
    370     return S_OK;
     391    return rc;
    371392}
    372393
     
    604625////////////////////////////////////////////////////////////////////////////////
    605626
     627HRESULT 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
     683Utf8Str 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
     695std::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
     709HRESULT 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
     721Utf8Str 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
    606733/**
    607734 * Returns true if the appliance is in "idle" state. This should always be the
  • trunk/src/VBox/Main/src-server/ApplianceImplExport.cpp

    r46337 r46518  
    12301230            uint64_t uTemp;
    12311231
     1232            ovf::VirtualHardwareItem vhi;
     1233            ovf::StorageItem si;
     1234            ovf::EthernetPortItem epi;
     1235
    12321236            switch (desc.type)
    12331237            {
     
    15181522                            <rasd:ResourceType>10</rasd:ResourceType>
    15191523                        </Item> */
    1520                     if (uLoop == 1)
     1524                    if (uLoop == 2)
    15211525                    {
    15221526                        lAutomaticAllocation = 1;
     
    15871591            {
    15881592                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                }
    15911624
    15921625                // NOTE: DO NOT CHANGE THE ORDER of these items! The OVF standards prescribes that
     
    15951628
    15961629                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                }
    15981636
    15991637                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                }
    16011644
    16021645                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                }
    16041652
    16051653                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                }
    16071660
    16081661                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                }
    16111672
    16121673                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                }
    16141680
    16151681                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                }
    16171688
    16181689                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                }
    16201696
    16211697                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                }
    16241707
    16251708                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                }
    16351728
    16361729                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                }
    16381736
    16391737                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                }
    16441752
    16451753                // <rasd:VirtualQuantity>1</rasd:VirtualQuantity>
    16461754                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                }
    16481761            }
    16491762        }
     
    17571870        storage.fCreateDigest = m->fManifest;
    17581871        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(),
    17601877                                 VDINTERFACETYPE_IO, 0, sizeof(VDINTERFACEIO),
    17611878                                 &storage.pVDImageIfaces);
     
    18111928        storage.fCreateDigest = m->fManifest;
    18121929        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(),
    18141934                             VDINTERFACETYPE_IO, tar, sizeof(VDINTERFACEIO),
    18151935                             &storage.pVDImageIfaces);
     1936       
    18161937        if (RT_FAILURE(vrc))
    18171938        {
     
    18581979            // Now fully build a valid ovf document in memory
    18591980            buildXML(writeLock, doc, stack, pTask->locInfo.strPath, pTask->enFormat);
     1981            /* Extract the OVA file name */
     1982            Utf8Str strOvaFile = pTask->locInfo.strPath;
    18601983            /* Extract the path */
    1861             Utf8Str strOvfFile = Utf8Str(pTask->locInfo.strPath).stripExt().append(".ovf");
     1984            Utf8Str strOvfFile = strOvaFile.stripExt().append(".ovf");
    18621985            // Create a memory buffer containing the XML. */
    18631986            void *pvBuf = 0;
     
    19512074            try
    19522075            {
    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 
    19582076                // advance to the next operation
    19592077                pTask->pProgress->SetNextOperation(BstrFmt(tr("Exporting to disk image '%s'"), RTPathFilename(strTargetFilePath.c_str())).raw(),
     
    19632081                if (pDiskEntry->type == VirtualSystemDescriptionType_HardDiskImage)
    19642082                {
    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,
    19672090                                                 MediumVariant_VmdkStreamOptimized,
    19682091                                                 pIfIo,
     
    19702093                                                 pProgress2);
    19712094                    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);
    19722099                }
    19732100                else
    19742101                {
    19752102                    //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                    }
    19832149                }
    1984 
    1985                 ComPtr<IProgress> pProgress3(pProgress2);
    1986                 // now wait for the background disk operation to complete; this throws HRESULTs on error
    1987                 waitForAsyncProgress(pTask->pProgress, pProgress3);
    19882150            }
    19892151            catch (HRESULT rc3)
  • trunk/src/VBox/Main/src-server/ApplianceImplIO.cpp

    r45367 r46518  
    3636 *   Structures and Typedefs                                                  *
    3737 ******************************************************************************/
    38 
    3938typedef struct FILESTORAGEINTERNAL
    4039{
     
    282281    int rc = VINF_SUCCESS;
    283282
    284     if (   fOpen & RTFILE_O_READ
     283    if (fOpen & RTFILE_O_READ
    285284        && !(fOpen & RTFILE_O_WRITE))
    286285    {
     
    298297         */
    299298        bool fFound = false;
     299
    300300        for (;;)
    301301        {
     
    312312                    rc = RTTarSeekNextFile(tar);
    313313                    if (RT_FAILURE(rc))
     314                    {
    314315                        break;
     316                    }
    315317                }
    316318            }
  • trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp

    r46176 r46518  
    4747#include <VBox/version.h>
    4848#include <VBox/settings.h>
     49
     50#include <set>
    4951
    5052using namespace std;
     
    611613                    }
    612614
     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
    613651                    // @todo:
    614652                    //  - figure out all possible vmdk formats we also support
    615653                    //  - figure out if there is a url specifier for vhd already
    616654                    //  - 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)
    626657                    {
    627658                        /* If the href is empty use the VM name as filename */
    628659                        Utf8Str strFilename = di.strHref;
    629660                        if (!strFilename.length())
    630                             //strFilename = Utf8StrFmt("%s.vmdk", nameVBox.c_str());
    631661                            strFilename = Utf8StrFmt("%s.vmdk", hd.strDiskId.c_str());
    632662
     
    640670                        if (!(pController = pNewDesc->findControllerFromID(hd.idController)))
    641671                            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"),
    643674                                           hd.idController,
    644675                                           di.strHref.c_str());
     
    654685                                           di.ulSuggestedSizeMB,
    655686                                           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)
    659689                    {
    660690                        /* If the href is empty use the VM name as filename */
     
    673703                        if (!(pController = pNewDesc->findControllerFromID(hd.idController)))
    674704                            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"),
    676707                                           hd.idController,
    677708                                           di.strHref.c_str());
     
    690721                    else
    691722                        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());
    693726                }
    694727            }
     
    764797////////////////////////////////////////////////////////////////////////////////
    765798
     799HRESULT 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}
    766818
    767819/*******************************************************************************
     
    929981                    }
    930982
     983                    RTFileClose(pFile);
     984
    931985                    RTDIGESTTYPE digestType = RTDIGESTTYPE_UNKNOWN;
    932986                    vrc = RTManifestVerifyDigestType(pBuf, cbRead, digestType);
     
    9481002                    }
    9491003
    950                     vrc = VDInterfaceAdd(&pFileIo->Core, "Appliance::IOFile",
     1004                    Utf8Str name = applianceIOName(applianceIOFile);
     1005
     1006                    vrc = VDInterfaceAdd(&pFileIo->Core, name.c_str(),
    9511007                                             VDINTERFACETYPE_IO, 0, sizeof(VDINTERFACEIO),
    9521008                                             &storage.pVDImageIfaces);
     
    11011157                }
    11021158
    1103                 vrc = VDInterfaceAdd(&pTarIo->Core, "Appliance::IOTar",
     1159                Utf8Str name = applianceIOName(applianceIOTar);
     1160
     1161                vrc = VDInterfaceAdd(&pTarIo->Core, name.c_str(),
    11041162                                     VDINTERFACETYPE_IO, tar, sizeof(VDINTERFACEIO),
    11051163                                     &storage.pVDImageIfaces);
     
    14791537            storage.fCreateDigest = true;
    14801538
    1481             int vrc = VDInterfaceAdd(&pFileIo->Core, "Appliance::IOFile",
     1539            Utf8Str name = applianceIOName(applianceIOFile);
     1540
     1541            int vrc = VDInterfaceAdd(&pFileIo->Core, name.c_str(),
    14821542                                     VDINTERFACETYPE_IO, 0, sizeof(VDINTERFACEIO),
    14831543                                     &storage.pVDImageIfaces);
     
    15531613        SHASTORAGE storage;
    15541614        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(),
    15561619                             VDINTERFACETYPE_IO, tar, sizeof(VDINTERFACEIO),
    15571620                             &storage.pVDImageIfaces);
     
    20502113    {
    20512114        Utf8Str strTrgFormat = "VMDK";
     2115        ULONG lCabs = 0;
     2116
    20522117        if (RTPathHaveExt(strTargetPath.c_str()))
    20532118        {
     
    20602125                               strTargetPath.c_str());
    20612126            /* Check the capabilities. We need create capabilities. */
    2062             ULONG lCabs = 0;
     2127            lCabs = 0;
    20632128            com::SafeArray <MediumFormatCapabilities_T> mediumFormatCap;
    20642129            rc = trgFormat->COMGETTER(Capabilities)(ComSafeArrayAsOutParam(mediumFormatCap));
     
    20882153        if (strTrgFormat.compare("RAW", Utf8Str::CaseInsensitive) == 0)
    20892154        {
    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 
    20992155            void *pvTmpBuf = 0;
    21002156            size_t cbSize = 0;
     
    21022158            /* Read the ISO file into a memory buffer */
    21032159            vrc = ShaReadBuf(strSrcFilePath.c_str(), &pvTmpBuf, &cbSize, pCallbacks, pStorage);
     2160
    21042161            if ( RT_FAILURE(vrc) || !pvTmpBuf)
    21052162                throw setError(VBOX_E_FILE_ERROR,
     
    21072164                               RTPathFilename(strSrcFilePath.c_str()), vrc);
    21082165
     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            }
    21092202            /* Advance to the next operation. */
    21102203            stack.pProgress->SetNextOperation(BstrFmt(tr("Importing virtual disk image '%s'"),
     
    21462239                Utf8Str strSrcFormat = "VDI";
    21472240
    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())
    21572245                {
    21582246                    strSrcFormat = "VMDK";
    2159                 }
    2160                 else if (!di.strFormat.compare("http://go.microsoft.com/fwlink/?LinkId=137171",
    2161                                      Utf8Str::CaseInsensitive))
    2162                 {
    2163                     strSrcFormat = "VHD";
    21642247                }
    21652248
     
    26242707            stack.fSessionOpen = true;
    26252708
    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);
    26482895
    26492896                ComObjPtr<Medium> pTargetHD;
    26502897
    2651                 importOneDiskImage(ovfDiskImage,
    2652                                    vsdeHD->strVboxCurrent,
     2898                importOneDiskImage(diCurrent,
     2899                                   vsdeTargetHD->strVboxCurrent,
    26532900                                   pTargetHD,
    26542901                                   stack,
     
    26742921                                            mhda.lDevice);
    26752922
    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)
    26822929                {
    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);
    26892945                    if (FAILED(rc)) throw rc;
    26902946                }
    26912947                else
    26922948                {
    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);
    27002954
    27012955                    if (FAILED(rc)) throw rc;
    2702 
    2703                     rc = sMachine->AttachDevice(mhda.controllerType.raw(),    // wstring name
    2704                                                 mhda.lControllerPort,          // long controllerPort
    2705                                                 mhda.lDevice,           // long device
    2706                                                 DeviceType_DVD,    // DeviceType_T type
    2707                                                 dvdImage);
    2708                     if (FAILED(rc)) throw rc;
    2709 
    27102956                }
    27112957
     
    27142960                rc = sMachine->SaveSettings();
    27152961                if (FAILED(rc)) throw rc;
    2716             } // end for (itHD = avsdeHDs.begin();
     2962            } // end while(oit != stack.mapDisks.end())
    27172963
    27182964            // only now that we're done with all disks, close the session
     
    29293175        fRepairDuplicate = false;
    29303176
    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;
    29603194                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)
    29703214                {
    2971                     const ovf::DiskImage &di = itDiskImage->second;
    2972                     d.uuid = Guid(di.uuidVbox);
     3215                    vsdeTargetHD = vsdeHD;
     3216                    break;
    29733217                }
    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)
    29893246                {
    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                     */
    29953283                    list<VirtualSystemDescriptionEntry*>::const_iterator itHD;
    29963284                    for (itHD = avsdeHDs.begin();
     
    29993287                    {
    30003288                        VirtualSystemDescriptionEntry *vsdeHD = *itHD;
    3001                         if (vsdeHD->strRef == oit->first)
     3289                        if (vsdeHD->strRef == diCurrent.strDiskId)
    30023290                        {
    30033291                            vsdeTargetHD = vsdeHD;
     
    30083296                        throw setError(E_FAIL,
    30093297                                       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())
    30303376                    {
    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);
    30453379                    }
    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;
    30583381                }
    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();
    30603437
    30613438            // 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())
    30683446
    30693447    /*
     
    30803458    // instance that we created from the vbox:Machine
    30813459    rc = pNewMachine->init(mVirtualBox,
    3082                            stack.strNameVBox,       // name from OVF preparations; can be suffixed to avoid duplicates, or changed by user
    3083                            config);                 // the whole machine config
     3460                           stack.strNameVBox,// name from OVF preparations; can be suffixed to avoid duplicates, or changed by user
     3461                           config);          // the whole machine config
    30843462    if (FAILED(rc)) throw rc;
    30853463
     
    32253603}
    32263604
     3605
  • trunk/src/VBox/Main/xml/ovfreader.cpp

    r46169 r46518  
    9191    }
    9292
    93 //    if ((pTypeAttr = pRootElem->findAttribute("version")))
    94 //    {
    95 //        pcszTypeAttr = pTypeAttr->getValue();
    96 //        m_envelopeData.version = pcszTypeAttr;
    97 //    }
    98 //    else
    99 //    {
    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 
    10693    if ((pTypeAttr = pRootElem->findAttribute("xml:lang")))
    10794    {
     
    255242                   )
    256243                {
     244
    257245                    // copy remaining values from file node then
    258246                    const char *pcszBadInFile = NULL;
     
    432420            }
    433421
    434             xml::NodesLoop loopVirtualHardwareItems(*pelmThis, "Item");      // all "Item" child elements
    435             const xml::ElementNode *pelmItem;
    436             while ((pelmItem = loopVirtualHardwareItems.forAllNodes()))
    437422            {
    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()))
    445426                {
    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)
    460435                    {
    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
    485457                    {
    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\""),
    512463                                            m_strPath.c_str(),
    513                                             pcszItemChildName,
    514                                             i.ulLineNumber);
     464                                            e.what());
     465                    }
     466
     467                    vsys.mapHardwareItems[i.ulInstanceID] = i;
    515468                }
    516 
    517                 // store!
    518                 vsys.mapHardwareItems[i.ulInstanceID] = i;
    519469            }
    520470
    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
    522496
    523497            // now go thru all hardware items and handle them according to their type;
     
    857831}
    858832
     833void 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
     910void 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
     923void 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
     989void 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
     1035void 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
     1046void EthernetPortItem::_checkConsistencyAndCompliance() throw (OVFLogicError)
     1047{
     1048    VirtualHardwareItem::_checkConsistencyAndCompliance();
     1049}
     1050
    8591051////////////////////////////////////////////////////////////////////////////////
    8601052//
  • trunk/src/VBox/Runtime/common/zip/tar.cpp

    r46338 r46518  
    9090typedef RTTARRECORD *PRTTARRECORD;
    9191
    92 
    93 #if 0 /* not currently used */
    94 typedef struct RTTARFILELIST
    95 {
    96     char *pszFilename;
    97     RTTARFILELIST *pNext;
    98 } RTTARFILELIST;
    99 typedef RTTARFILELIST *PRTTARFILELIST;
    100 #endif
    101 
    10292/** Pointer to a tar file handle. */
    10393typedef struct RTTARFILEINTERNAL *PRTTARFILEINTERNAL;
     
    150140typedef RTTARFILEINTERNAL *PRTTARFILEINTERNAL;
    151141
     142#if 0 /* not currently used */
     143typedef struct RTTARFILELIST
     144{
     145    char *pszFilename;
     146    RTTARFILELIST *pNext;
     147} RTTARFILELIST;
     148typedef RTTARFILELIST *PRTTARFILELIST;
     149#endif
     150
     151
    152152
    153153/******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.

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