Changeset 46067 in vbox
- Timestamp:
- May 14, 2013 2:41:26 PM (12 years ago)
- Location:
- trunk/src/VBox/Main/src-server
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/ApplianceImplExport.cpp
r45622 r46067 324 324 LONG64 llSize = 0; 325 325 326 if ( deviceType == DeviceType_HardDisk 327 && pMedium 328 ) 326 if (deviceType == DeviceType_HardDisk 327 && pMedium) 329 328 { 330 329 Bstr bstrLocation; … … 358 357 if (FAILED(rc)) throw rc; 359 358 } 360 359 else if (deviceType == DeviceType_DVD 360 && pMedium) 361 { 362 Bstr bstrLocation; 363 rc = pMedium->COMGETTER(Location)(bstrLocation.asOutParam()); 364 if (FAILED(rc)) throw rc; 365 strLocation = bstrLocation; 366 367 // find the source's base medium for two things: 368 // 1) we'll use its name to determine the name of the target disk, which is readable, 369 // as opposed to the UUID filename of a differencing image, if pMedium is one 370 // 2) we need the size of the base image so we can give it to addEntry(), and later 371 // on export, the progress will be based on that (and not the diff image) 372 ComPtr<IMedium> pBaseMedium; 373 rc = pMedium->COMGETTER(Base)(pBaseMedium.asOutParam()); 374 // returns pMedium if there are no diff images 375 if (FAILED(rc)) throw rc; 376 377 Bstr bstrBaseName; 378 rc = pBaseMedium->COMGETTER(Name)(bstrBaseName.asOutParam()); 379 if (FAILED(rc)) throw rc; 380 381 Utf8Str strTargetName = Utf8Str(locInfo.strPath).stripPath().stripExt(); 382 strTargetVmdkName = Utf8StrFmt("%s-disk%d.iso", strTargetName.c_str(), ++pAppliance->m->cDisks); 383 384 // force reading state, or else size will be returned as 0 385 MediumState_T ms; 386 rc = pBaseMedium->RefreshState(&ms); 387 if (FAILED(rc)) throw rc; 388 389 rc = pBaseMedium->COMGETTER(Size)(&llSize); 390 if (FAILED(rc)) throw rc; 391 } 361 392 // and how this translates to the virtual system 362 393 int32_t lControllerVsys = 0; … … 435 466 case DeviceType_DVD: 436 467 pNewDesc->addEntry(VirtualSystemDescriptionType_CDROM, 437 str Empty, // disk ID438 str Empty, // OVF value439 str Empty, // vbox value440 1,// ulSize468 strTargetVmdkName, // disk ID 469 strTargetVmdkName, // OVF value 470 strLocation, // vbox value 471 (uint32_t)(llSize / _1M),// ulSize 441 472 strExtra); 442 473 break; … … 805 836 Bstr bstrSrcFilePath(strSrcFilePath); 806 837 838 //skip empty Medium. There are no information to add into section <References> or <DiskSection> 839 if (strSrcFilePath.isEmpty()) 840 continue; 841 807 842 // Do NOT check here whether the file exists. FindMedium will figure 808 843 // that out, and filesystem-based tests are simply wrong in the … … 811 846 // We need some info from the source disks 812 847 ComPtr<IMedium> pSourceDisk; 848 //DeviceType_T deviceType = DeviceType_HardDisk;// by default 813 849 814 850 Log(("Finding source disk \"%ls\"\n", bstrSrcFilePath.raw())); 815 HRESULT rc = mVirtualBox->OpenMedium(bstrSrcFilePath.raw(), DeviceType_HardDisk, AccessMode_ReadWrite, FALSE /* fForceNewUuid */, pSourceDisk.asOutParam()); 816 if (FAILED(rc)) throw rc; 851 852 HRESULT rc; 853 854 if (pDiskEntry->type == VirtualSystemDescriptionType_HardDiskImage) 855 { 856 rc = mVirtualBox->OpenMedium(bstrSrcFilePath.raw(), 857 DeviceType_HardDisk, 858 AccessMode_ReadWrite, 859 FALSE /* fForceNewUuid */, 860 pSourceDisk.asOutParam()); 861 if (FAILED(rc)) 862 throw rc; 863 } 864 else if (pDiskEntry->type == VirtualSystemDescriptionType_CDROM)//may be, this is CD/DVD 865 { 866 rc = mVirtualBox->OpenMedium(bstrSrcFilePath.raw(), 867 DeviceType_DVD, 868 AccessMode_ReadOnly, 869 FALSE, 870 pSourceDisk.asOutParam()); 871 if (FAILED(rc)) 872 throw rc; 873 } 817 874 818 875 Bstr uuidSource; … … 830 887 831 888 // We are always exporting to VMDK stream optimized for now 832 Bstr bstrSrcFormat = L"VMDK";889 //Bstr bstrSrcFormat = L"VMDK";//not used 833 890 834 891 diskList.push_back(strTargetFilePath); … … 862 919 pelmDisk->setAttribute("ovf:diskId", strDiskID); 863 920 pelmDisk->setAttribute("ovf:fileRef", strFileRef); 864 pelmDisk->setAttribute("ovf:format", 865 (enFormat == ovf::OVFVersion_0_9) 866 ? "http://www.vmware.com/specifications/vmdk.html#sparse" // must be sparse or ovftool chokes 867 : "http://www.vmware.com/interfaces/specifications/vmdk.html#streamOptimized" 868 // correct string as communicated to us by VMware (public bug #6612) 869 ); 921 922 if (pDiskEntry->type == VirtualSystemDescriptionType_HardDiskImage)//deviceType == DeviceType_HardDisk 923 { 924 pelmDisk->setAttribute("ovf:format", 925 (enFormat == ovf::OVFVersion_0_9) 926 ? "http://www.vmware.com/specifications/vmdk.html#sparse" // must be sparse or ovftool ch 927 : "http://www.vmware.com/interfaces/specifications/vmdk.html#streamOptimized" 928 // correct string as communicated to us by VMware (public bug #6612) 929 ); 930 } 931 else //pDiskEntry->type == VirtualSystemDescriptionType_CDROM, deviceType == DeviceType_DVD 932 { 933 pelmDisk->setAttribute("ovf:format", 934 "http://www.ecma-international.org/publications/standards/Ecma-119.htm" 935 ); 936 } 870 937 871 938 // add the UUID of the newly target image to the OVF disk element, but in the … … 1379 1446 1380 1447 case VirtualSystemDescriptionType_CDROM: 1448 /* <Item> 1449 <rasd:Caption>cdrom1</rasd:Caption> 1450 <rasd:InstanceId>8</rasd:InstanceId> 1451 <rasd:ResourceType>15</rasd:ResourceType> 1452 <rasd:HostResource>/disk/cdrom1</rasd:HostResource> 1453 <rasd:Parent>4</rasd:Parent> 1454 <rasd:AddressOnParent>0</rasd:AddressOnParent> 1455 </Item> */ 1381 1456 if (uLoop == 2) 1382 1457 { 1458 //uint32_t cDisks = stack.mapDisks.size(); 1459 Utf8Str strDiskID = Utf8StrFmt("iso%RI32", ++cDVDs); 1460 1383 1461 strDescription = "CD-ROM Drive"; 1384 strCaption = Utf8StrFmt("cdrom%RI32", ++cDVDs); // OVFTool starts with 11462 strCaption = Utf8StrFmt("cdrom%RI32", cDVDs); // OVFTool starts with 1 1385 1463 type = ovf::ResourceType_CDDrive; // 15 1386 1464 lAutomaticAllocation = 1; 1465 1466 //skip empty Medium. There are no information to add into section <References> or <DiskSection> 1467 if (desc.strVboxCurrent.isNotEmpty()) 1468 { 1469 // the following references the "<Disks>" XML block 1470 strHostResource = Utf8StrFmt("/disk/%s", strDiskID.c_str()); 1471 } 1387 1472 1388 1473 // controller=<index>;channel=<c> … … 1414 1499 tr("Missing or bad extra config string in DVD drive medium: \"%s\""), desc.strExtraConfigCurrent.c_str()); 1415 1500 1501 stack.mapDisks[strDiskID] = &desc; 1416 1502 // there is no DVD drive map to update because it is 1417 1503 // handled completely with this entry. … … 1580 1666 pConfig->buildMachineXML(*pelmVBoxMachine, 1581 1667 settings::MachineConfigFile::BuildMachineXML_WriteVboxVersionAttribute 1582 | settings::MachineConfigFile::BuildMachineXML_SkipRemovableMedia1668 /*| settings::MachineConfigFile::BuildMachineXML_SkipRemovableMedia*/ 1583 1669 | settings::MachineConfigFile::BuildMachineXML_SuppressSavedState, 1584 1670 // but not BuildMachineXML_IncludeSnapshots nor BuildMachineXML_MediaRegistry … … 1789 1875 1790 1876 // We need a proper format description 1877 ComObjPtr<MediumFormat> formatTemp; 1878 1791 1879 ComObjPtr<MediumFormat> format; 1792 1880 // Scope for the AutoReadLock … … 1795 1883 AutoReadLock propsLock(pSysProps COMMA_LOCKVAL_SRC_POS); 1796 1884 // We are always exporting to VMDK stream optimized for now 1885 formatTemp = pSysProps->mediumFormatFromExtension("iso"); 1886 1797 1887 format = pSysProps->mediumFormat("VMDK"); 1798 1888 if (format.isNull()) … … 1812 1902 const Utf8Str &strSrcFilePath = pDiskEntry->strVboxCurrent; 1813 1903 1904 //skip empty Medium. In common, It's may be empty CD/DVD 1905 if (strSrcFilePath.isEmpty()) 1906 continue; 1907 1814 1908 // Do NOT check here whether the file exists. findHardDisk will 1815 1909 // figure that out, and filesystem-based tests are simply wrong … … 1820 1914 1821 1915 Log(("Finding source disk \"%s\"\n", strSrcFilePath.c_str())); 1822 rc = mVirtualBox->findHardDiskByLocation(strSrcFilePath, true, &pSourceDisk); 1823 if (FAILED(rc)) throw rc; 1916 1917 if (pDiskEntry->type == VirtualSystemDescriptionType_HardDiskImage) 1918 { 1919 rc = mVirtualBox->findHardDiskByLocation(strSrcFilePath, true, &pSourceDisk); 1920 if (FAILED(rc)) throw rc; 1921 } 1922 else//may be CD or DVD 1923 { 1924 rc = mVirtualBox->findDVDOrFloppyImage(DeviceType_DVD, 1925 NULL, 1926 strSrcFilePath, 1927 true, 1928 &pSourceDisk); 1929 if (FAILED(rc)) throw rc; 1930 } 1824 1931 1825 1932 Bstr uuidSource; … … 1850 1957 1851 1958 // create a flat copy of the source disk image 1852 rc = pSourceDisk->exportFile(strTargetFilePath.c_str(), format, MediumVariant_VmdkStreamOptimized, pIfIo, pStorage, pProgress2); 1853 if (FAILED(rc)) throw rc; 1959 if (pDiskEntry->type == VirtualSystemDescriptionType_HardDiskImage) 1960 { 1961 rc = pSourceDisk->exportFile(strTargetFilePath.c_str(), 1962 format, 1963 MediumVariant_VmdkStreamOptimized, 1964 pIfIo, 1965 pStorage, 1966 pProgress2); 1967 if (FAILED(rc)) throw rc; 1968 } 1969 else 1970 { 1971 //copy/clone CD/DVD image 1972 rc = pSourceDisk->exportFile(strTargetFilePath.c_str(), 1973 formatTemp, 1974 MediumVariant_Standard, 1975 pIfIo, 1976 pStorage, 1977 pProgress2); 1978 if (FAILED(rc)) throw rc; 1979 } 1854 1980 1855 1981 ComPtr<IProgress> pProgress3(pProgress2); -
trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp
r45367 r46067 600 600 const ovf::VirtualDisk &hd = itVD->second; 601 601 /* Get the associated disk image */ 602 const ovf::DiskImage &di = m->pReader->m_mapDisks[hd.strDiskId]; 602 ovf::DiskImage di; 603 std::map<RTCString, ovf::DiskImage>::iterator foundDisk; 604 605 foundDisk = m->pReader->m_mapDisks.find(hd.strDiskId); 606 if (foundDisk == m->pReader->m_mapDisks.end()) 607 continue; 608 else 609 { 610 di = foundDisk->second; 611 } 603 612 604 613 // @todo: … … 606 615 // - figure out if there is a url specifier for vhd already 607 616 // - we need a url specifier for the vdi format 608 if ( di.strFormat.compare("http://www.vmware.com/specifications/vmdk.html#sparse", Utf8Str::CaseInsensitive) 609 || di.strFormat.compare("http://www.vmware.com/interfaces/specifications/vmdk.html#streamOptimized", Utf8Str::CaseInsensitive) 610 || di.strFormat.compare("http://www.vmware.com/specifications/vmdk.html#compressed", Utf8Str::CaseInsensitive) 611 || di.strFormat.compare("http://www.vmware.com/interfaces/specifications/vmdk.html#compressed", Utf8Str::CaseInsensitive) 612 ) 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 ) 613 626 { 614 627 /* If the href is empty use the VM name as filename */ 615 628 Utf8Str strFilename = di.strHref; 616 629 if (!strFilename.length()) 617 strFilename = Utf8StrFmt("%s.vmdk", nameVBox.c_str());618 619 Utf8Str strTargetPath = Utf8Str(strMachineFolder) 620 .append(RTPATH_DELIMITER)621 630 //strFilename = Utf8StrFmt("%s.vmdk", nameVBox.c_str()); 631 strFilename = Utf8StrFmt("%s.vmdk", hd.strDiskId.c_str()); 632 633 Utf8Str strTargetPath = Utf8Str(strMachineFolder); 634 strTargetPath.append(RTPATH_DELIMITER).append(di.strHref); 622 635 searchUniqueDiskImageFilePath(strTargetPath); 623 636 … … 641 654 di.ulSuggestedSizeMB, 642 655 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)) 659 { 660 /* If the href is empty use the VM name as filename */ 661 Utf8Str strFilename = di.strHref; 662 if (!strFilename.length()) 663 strFilename = Utf8StrFmt("%s.iso", hd.strDiskId.c_str()); 664 665 Utf8Str strTargetPath = Utf8Str(strMachineFolder) 666 .append(RTPATH_DELIMITER) 667 .append(di.strHref); 668 searchUniqueDiskImageFilePath(strTargetPath); 669 670 /* find the description for the hard disk controller 671 * that has the same ID as hd.idController */ 672 const VirtualSystemDescriptionEntry *pController; 673 if (!(pController = pNewDesc->findControllerFromID(hd.idController))) 674 throw setError(E_FAIL, 675 tr("Cannot find disk controller with OVF instance ID %RI32 to which disk \"%s\" sh ould be attached"), 676 hd.idController, 677 di.strHref.c_str()); 678 679 /* controller to attach to, and the bus within that controller */ 680 Utf8StrFmt strExtraConfig("controller=%RI16;channel=%RI16", 681 pController->ulIndex, 682 hd.ulAddressOnParent); 683 pNewDesc->addEntry(VirtualSystemDescriptionType_HardDiskImage, 684 hd.strDiskId, 685 di.strHref, 686 strTargetPath, 687 di.ulSuggestedSizeMB, 688 strExtraConfig); 689 }//url specifier for VHD 690 else if (!di.strFormat.compare("http://go.microsoft.com/fwlink/?LinkId=137171", Utf8Str::CaseInsensitive)) 691 { 643 692 } 644 693 else … … 1987 2036 SystemProperties *pSysProps = mVirtualBox->getSystemProperties(); 1988 2037 2038 const Utf8Str &strSourceOVF = di.strHref; 2039 /* Construct source file path */ 2040 Utf8StrFmt strSrcFilePath("%s%c%s", stack.strSourceDir.c_str(), RTPATH_DELIMITER, strSourceOVF.c_str()); 2041 1989 2042 /* First of all check if the path is an UUID. If so, the user like to 1990 2043 * import the disk into an existing path. This is useful for iSCSI for … … 2034 2087 /* Create an IMedium object. */ 2035 2088 pTargetHD.createObject(); 2036 rc = pTargetHD->init(mVirtualBox, 2037 strTrgFormat, 2038 strTargetPath, 2039 Guid::Empty /* media registry: none yet */); 2040 if (FAILED(rc)) throw rc; 2041 2042 /* Now create an empty hard disk. */ 2043 rc = mVirtualBox->CreateHardDisk(NULL, 2044 Bstr(strTargetPath).raw(), 2045 ComPtr<IMedium>(pTargetHD).asOutParam()); 2046 if (FAILED(rc)) throw rc; 2047 } 2048 2049 const Utf8Str &strSourceOVF = di.strHref; 2050 /* Construct source file path */ 2051 Utf8StrFmt strSrcFilePath("%s%c%s", stack.strSourceDir.c_str(), RTPATH_DELIMITER, strSourceOVF.c_str()); 2052 2053 /* If strHref is empty we have to create a new file. */ 2054 if (strSourceOVF.isEmpty()) 2055 { 2056 com::SafeArray<MediumVariant_T> mediumVariant; 2057 mediumVariant.push_back(MediumVariant_Standard); 2058 /* Create a dynamic growing disk image with the given capacity. */ 2059 rc = pTargetHD->CreateBaseStorage(di.iCapacity / _1M, ComSafeArrayAsInParam(mediumVariant), ComPtr<IProgress>(pProgress).asOutParam()); 2060 if (FAILED(rc)) throw rc; 2061 2062 /* Advance to the next operation. */ 2063 stack.pProgress->SetNextOperation(BstrFmt(tr("Creating disk image '%s'"), strTargetPath.c_str()).raw(), 2064 di.ulSuggestedSizeMB); // operation's weight, as set up with the IProgress originally 2065 } 2066 else 2067 { 2068 /* We need a proper source format description */ 2069 ComObjPtr<MediumFormat> srcFormat; 2070 /* Which format to use? */ 2071 Utf8Str strSrcFormat = "VDI"; 2072 if ( di.strFormat.compare("http://www.vmware.com/specifications/vmdk.html#sparse", Utf8Str::CaseInsensitive) 2073 || di.strFormat.compare("http://www.vmware.com/interfaces/specifications/vmdk.html#streamOptimized", Utf8Str::CaseInsensitive) 2074 || di.strFormat.compare("http://www.vmware.com/specifications/vmdk.html#compressed", Utf8Str::CaseInsensitive) 2075 || di.strFormat.compare("http://www.vmware.com/interfaces/specifications/vmdk.html#compressed", Utf8Str::CaseInsensitive) 2076 ) 2077 strSrcFormat = "VMDK"; 2078 srcFormat = pSysProps->mediumFormat(strSrcFormat); 2079 if (srcFormat.isNull()) 2080 throw setError(VBOX_E_NOT_SUPPORTED, 2081 tr("Could not find a valid medium format for the source disk '%s'"), 2082 RTPathFilename(strSrcFilePath.c_str())); 2083 2084 /* Clone the source disk image */ 2085 ComObjPtr<Medium> nullParent; 2086 rc = pTargetHD->importFile(strSrcFilePath.c_str(), 2087 srcFormat, 2088 MediumVariant_Standard, 2089 pCallbacks, pStorage, 2090 nullParent, 2091 pProgress); 2092 if (FAILED(rc)) throw rc; 2093 2094 /* Advance to the next operation. */ 2095 stack.pProgress->SetNextOperation(BstrFmt(tr("Importing virtual disk image '%s'"), RTPathFilename(strSrcFilePath.c_str())).raw(), 2096 di.ulSuggestedSizeMB); // operation's weight, as set up with the IProgress originally); 2097 } 2098 2099 /* Now wait for the background disk operation to complete; this throws 2100 * HRESULTs on error. */ 2101 ComPtr<IProgress> pp(pProgress); 2102 waitForAsyncProgress(stack.pProgress, pp); 2089 2090 /*CD/DVD case*/ 2091 if (strTrgFormat.compare("RAW", Utf8Str::CaseInsensitive) == 0) 2092 { 2093 /* copy ISO image to the destination folder*/ 2094 vrc = RTFileCopy(strSrcFilePath.c_str(), strTargetPath.c_str()); 2095 2096 if (RT_FAILURE(vrc)) 2097 throw setError(VBOX_E_FILE_ERROR, 2098 tr("Could not copy image %s to the destination folder '%s'"), 2099 strSrcFilePath.c_str(), 2100 strTargetPath.c_str()); 2101 2102 void *pvTmpBuf = 0; 2103 size_t cbSize = 0; 2104 2105 /* Read the ISO file into a memory buffer */ 2106 vrc = ShaReadBuf(strSrcFilePath.c_str(), &pvTmpBuf, &cbSize, pCallbacks, pStorage); 2107 if ( RT_FAILURE(vrc) || !pvTmpBuf) 2108 throw setError(VBOX_E_FILE_ERROR, 2109 tr("Could not read ISO file '%s' (%Rrc)"), 2110 RTPathFilename(strSrcFilePath.c_str()), vrc); 2111 2112 /* Advance to the next operation. */ 2113 stack.pProgress->SetNextOperation(BstrFmt(tr("Importing virtual disk image '%s'"), 2114 RTPathFilename(strSrcFilePath.c_str())).raw(), 2115 di.ulSuggestedSizeMB);//operation's weight, as set up with the IProgress origi 2116 } 2117 else/* HDD case*/ 2118 { 2119 rc = pTargetHD->init(mVirtualBox, 2120 strTrgFormat, 2121 strTargetPath, 2122 Guid::Empty /* media registry: none yet */); 2123 if (FAILED(rc)) throw rc; 2124 2125 /* Now create an empty hard disk. */ 2126 rc = mVirtualBox->CreateHardDisk(Bstr(strTrgFormat).raw(), 2127 Bstr(strTargetPath).raw(), 2128 ComPtr<IMedium>(pTargetHD).asOutParam()); 2129 if (FAILED(rc)) throw rc; 2130 2131 /* If strHref is empty we have to create a new file. */ 2132 if (strSourceOVF.isEmpty()) 2133 { 2134 com::SafeArray<MediumVariant_T> mediumVariant; 2135 mediumVariant.push_back(MediumVariant_Standard); 2136 /* Create a dynamic growing disk image with the given capacity. */ 2137 rc = pTargetHD->CreateBaseStorage(di.iCapacity / _1M, ComSafeArrayAsInParam(mediumVariant), ComPtr<IProgress>(pProgress).asOutParam()); 2138 if (FAILED(rc)) throw rc; 2139 2140 /* Advance to the next operation. */ 2141 stack.pProgress->SetNextOperation(BstrFmt(tr("Creating disk image '%s'"), strTargetPath.c_str()).raw(), 2142 di.ulSuggestedSizeMB); // operation's weight, as set up with the IProgress originally 2143 } 2144 else 2145 { 2146 /* We need a proper source format description */ 2147 ComObjPtr<MediumFormat> srcFormat; 2148 /* Which format to use? */ 2149 Utf8Str strSrcFormat = "VDI"; 2150 2151 if ( !di.strFormat.compare("http://www.vmware.com/specifications/vmdk.html#sparse", 2152 Utf8Str::CaseInsensitive) 2153 || !di.strFormat.compare("http://www.vmware.com/interfaces/specifications/vmdk.html#streamOptimized", 2154 Utf8Str::CaseInsensitive) 2155 || !di.strFormat.compare("http://www.vmware.com/specifications/vmdk.html#compressed", 2156 Utf8Str::CaseInsensitive) 2157 || !di.strFormat.compare("http://www.vmware.com/interfaces/specifications/vmdk.html#compressed", 2158 Utf8Str::CaseInsensitive) 2159 ) 2160 { 2161 strSrcFormat = "VMDK"; 2162 } 2163 else if (!di.strFormat.compare("http://go.microsoft.com/fwlink/?LinkId=137171", 2164 Utf8Str::CaseInsensitive)) 2165 { 2166 strSrcFormat = "VHD"; 2167 } 2168 2169 srcFormat = pSysProps->mediumFormat(strSrcFormat); 2170 if (srcFormat.isNull()) 2171 throw setError(VBOX_E_NOT_SUPPORTED, 2172 tr("Could not find a valid medium format for the source disk '%s'"), 2173 RTPathFilename(strSrcFilePath.c_str())); 2174 2175 /* Clone the source disk image */ 2176 ComObjPtr<Medium> nullParent; 2177 rc = pTargetHD->importFile(strSrcFilePath.c_str(), 2178 srcFormat, 2179 MediumVariant_Standard, 2180 pCallbacks, pStorage, 2181 nullParent, 2182 pProgress); 2183 if (FAILED(rc)) throw rc; 2184 2185 /* Advance to the next operation. */ 2186 stack.pProgress->SetNextOperation(BstrFmt(tr("Importing virtual disk image '%s'"), RTPathFilename(strSrcFilePath.c_str())).raw(), 2187 di.ulSuggestedSizeMB);// operation's weight, as set up with the IProgress originally); 2188 } 2189 2190 /* Now wait for the background disk operation to complete; this throws 2191 * HRESULTs on error. */ 2192 ComPtr<IProgress> pp(pProgress); 2193 waitForAsyncProgress(stack.pProgress, pp); 2194 } 2195 } 2103 2196 2104 2197 /* Add the newly create disk path + a corresponding digest the our list for … … 2504 2597 } 2505 2598 2506 // CD-ROMs next2507 for (std::list<VirtualSystemDescriptionEntry*>::const_iterator jt = vsdeCDROM.begin();2508 jt != vsdeCDROM.end();2509 ++jt)2510 {2511 // for now always attach to secondary master on IDE controller;2512 // there seems to be no useful information in OVF where else to2513 // attach it (@todo test with latest versions of OVF software)2514 2515 // find the IDE controller2516 const ovf::HardDiskController *pController = NULL;2517 for (ovf::ControllersMap::const_iterator kt = vsysThis.mapControllers.begin();2518 kt != vsysThis.mapControllers.end();2519 ++kt)2520 {2521 if (kt->second.system == ovf::HardDiskController::IDE)2522 {2523 pController = &kt->second;2524 break;2525 }2526 }2527 2528 if (!pController)2529 throw setError(VBOX_E_FILE_ERROR,2530 tr("OVF wants a CD-ROM drive but cannot find IDE controller, which is required in this version of VirtualBox"));2531 2532 // this is for rollback later2533 MyHardDiskAttachment mhda;2534 mhda.pMachine = pNewMachine;2535 2536 convertDiskAttachmentValues(*pController,2537 2, // interpreted as secondary master2538 mhda.controllerType, // Bstr2539 mhda.lControllerPort,2540 mhda.lDevice);2541 2542 Log(("Attaching CD-ROM to port %d on device %d\n", mhda.lControllerPort, mhda.lDevice));2543 2544 rc = sMachine->AttachDevice(mhda.controllerType.raw(),2545 mhda.lControllerPort,2546 mhda.lDevice,2547 DeviceType_DVD,2548 NULL);2549 if (FAILED(rc)) throw rc;2550 2551 stack.llHardDiskAttachments.push_back(mhda);2552 } // end for (itHD = avsdeHDs.begin();2553 2554 2599 rc = sMachine->SaveSettings(); 2555 2600 if (FAILED(rc)) throw rc; … … 2606 2651 2607 2652 ComObjPtr<Medium> pTargetHD; 2653 2608 2654 importOneDiskImage(ovfDiskImage, 2609 2655 vsdeHD->strVboxCurrent, … … 2633 2679 Log(("Attaching disk %s to port %d on device %d\n", vsdeHD->strVboxCurrent.c_str(), mhda.lControllerPort, mhda.lDevice)); 2634 2680 2635 rc = sMachine->AttachDevice(mhda.controllerType.raw(), // wstring name 2636 mhda.lControllerPort, // long controllerPort 2637 mhda.lDevice, // long device 2638 DeviceType_HardDisk, // DeviceType_T type 2639 pTargetHD); 2640 if (FAILED(rc)) throw rc; 2681 int ifISO = 0; 2682 ifISO = ovfDiskImage.strFormat.compare("http://www.ecma-international.org/publications/standards/Ecma-119.htm", 2683 Utf8Str::CaseInsensitive); 2684 if ( ifISO != 0) 2685 { 2686 rc = sMachine->AttachDevice(mhda.controllerType.raw(), // wstring name 2687 mhda.lControllerPort, // long controllerPort 2688 mhda.lDevice, // long device 2689 DeviceType_HardDisk, // DeviceType_T type 2690 pTargetHD); 2691 2692 if (FAILED(rc)) throw rc; 2693 } 2694 else 2695 { 2696 ComPtr<IMedium> dvdImage(pTargetHD); 2697 2698 rc = mVirtualBox->OpenMedium(Bstr(vsdeHD->strVboxCurrent).raw(), 2699 DeviceType_DVD, 2700 AccessMode_ReadWrite, 2701 false, 2702 dvdImage.asOutParam()); 2703 2704 if (FAILED(rc)) throw rc; 2705 2706 rc = sMachine->AttachDevice(mhda.controllerType.raw(), // wstring name 2707 mhda.lControllerPort, // long controllerPort 2708 mhda.lDevice, // long device 2709 DeviceType_DVD, // DeviceType_T type 2710 dvdImage); 2711 if (FAILED(rc)) throw rc; 2712 2713 } 2641 2714 2642 2715 stack.llHardDiskAttachments.push_back(mhda); … … 2953 3026 pStorage); 2954 3027 2955 // ... and replace the old UUID in the machine config with the one of2956 // the imported disk that was just created2957 3028 Bstr hdId; 2958 rc = pTargetHD->COMGETTER(Id)(hdId.asOutParam()); 2959 if (FAILED(rc)) throw rc; 3029 int ifISO = 0; 3030 ifISO = di.strFormat.compare("http://www.ecma-international.org/publications/standards/Ecma-119.htm", 3031 Utf8Str::CaseInsensitive); 3032 if ( ifISO == 0) 3033 { 3034 ComPtr<IMedium> dvdImage(pTargetHD); 3035 3036 rc = mVirtualBox->OpenMedium(Bstr(vsdeTargetHD->strVboxCurrent).raw(), 3037 DeviceType_DVD, 3038 AccessMode_ReadWrite, 3039 false, 3040 dvdImage.asOutParam()); 3041 3042 if (FAILED(rc)) throw rc; 3043 3044 // ... and replace the old UUID in the machine config with the one of 3045 // the imported disk that was just created 3046 rc = dvdImage->COMGETTER(Id)(hdId.asOutParam()); 3047 if (FAILED(rc)) throw rc; 3048 } 3049 else 3050 { 3051 // ... and replace the old UUID in the machine config with the one of 3052 // the imported disk that was just created 3053 rc = pTargetHD->COMGETTER(Id)(hdId.asOutParam()); 3054 if (FAILED(rc)) throw rc; 3055 } 2960 3056 2961 3057 d.uuid = hdId;
Note:
See TracChangeset
for help on using the changeset viewer.