VirtualBox

source: vbox/trunk/src/VBox/Main/src-server/ApplianceImplExport.cpp@ 67197

Last change on this file since 67197 was 67197, checked in by vboxsync, 8 years ago

Main: ApplianceImplExport.cpp: Hacking OPC exporting.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 118.9 KB
Line 
1/* $Id: ApplianceImplExport.cpp 67197 2017-06-01 09:07:53Z vboxsync $ */
2/** @file
3 * IAppliance and IVirtualSystem COM class implementations.
4 */
5
6/*
7 * Copyright (C) 2008-2017 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#include <iprt/path.h>
19#include <iprt/dir.h>
20#include <iprt/param.h>
21#include <iprt/s3.h>
22#include <iprt/manifest.h>
23#include <iprt/stream.h>
24#ifndef VBOX_WITH_NEW_TAR_CREATOR
25# include <iprt/tar.h>
26#else
27# include <iprt/zip.h>
28#endif
29
30#include <VBox/version.h>
31
32#include "ApplianceImpl.h"
33#include "VirtualBoxImpl.h"
34#include "ProgressImpl.h"
35#include "MachineImpl.h"
36#include "MediumImpl.h"
37#include "MediumFormatImpl.h"
38#include "Global.h"
39#include "SystemPropertiesImpl.h"
40
41#include "AutoCaller.h"
42#include "Logging.h"
43
44#include "ApplianceImplPrivate.h"
45
46using namespace std;
47
48////////////////////////////////////////////////////////////////////////////////
49//
50// IMachine public methods
51//
52////////////////////////////////////////////////////////////////////////////////
53
54// This code is here so we won't have to include the appliance headers in the
55// IMachine implementation, and we also need to access private appliance data.
56
57/**
58* Public method implementation.
59* @param aAppliance Appliance object.
60* @param aLocation Where to store the appliance.
61* @param aDescription Appliance description.
62* @return
63*/
64HRESULT Machine::exportTo(const ComPtr<IAppliance> &aAppliance, const com::Utf8Str &aLocation,
65 ComPtr<IVirtualSystemDescription> &aDescription)
66{
67 HRESULT rc = S_OK;
68
69 if (!aAppliance)
70 return E_POINTER;
71
72 ComObjPtr<VirtualSystemDescription> pNewDesc;
73
74 try
75 {
76 IAppliance *iAppliance = aAppliance;
77 Appliance *pAppliance = static_cast<Appliance*>(iAppliance);
78
79 LocationInfo locInfo;
80 i_parseURI(aLocation, locInfo);
81 // create a new virtual system to store in the appliance
82 rc = pNewDesc.createObject();
83 if (FAILED(rc)) throw rc;
84 rc = pNewDesc->init();
85 if (FAILED(rc)) throw rc;
86
87 // store the machine object so we can dump the XML in Appliance::Write()
88 pNewDesc->m->pMachine = this;
89
90 // first, call the COM methods, as they request locks
91 BOOL fUSBEnabled = FALSE;
92 com::SafeIfaceArray<IUSBController> usbControllers;
93 rc = COMGETTER(USBControllers)(ComSafeArrayAsOutParam(usbControllers));
94 if (SUCCEEDED(rc))
95 {
96 for (unsigned i = 0; i < usbControllers.size(); ++i)
97 {
98 USBControllerType_T enmType;
99
100 rc = usbControllers[i]->COMGETTER(Type)(&enmType);
101 if (FAILED(rc)) throw rc;
102
103 if (enmType == USBControllerType_OHCI)
104 fUSBEnabled = TRUE;
105 }
106 }
107
108 // request the machine lock while accessing internal members
109 AutoReadLock alock1(this COMMA_LOCKVAL_SRC_POS);
110
111 ComPtr<IAudioAdapter> pAudioAdapter = mAudioAdapter;
112 BOOL fAudioEnabled;
113 rc = pAudioAdapter->COMGETTER(Enabled)(&fAudioEnabled);
114 if (FAILED(rc)) throw rc;
115 AudioControllerType_T audioController;
116 rc = pAudioAdapter->COMGETTER(AudioController)(&audioController);
117 if (FAILED(rc)) throw rc;
118
119 // get name
120 Utf8Str strVMName = mUserData->s.strName;
121 // get description
122 Utf8Str strDescription = mUserData->s.strDescription;
123 // get guest OS
124 Utf8Str strOsTypeVBox = mUserData->s.strOsType;
125 // CPU count
126 uint32_t cCPUs = mHWData->mCPUCount;
127 // memory size in MB
128 uint32_t ulMemSizeMB = mHWData->mMemorySize;
129 // VRAM size?
130 // BIOS settings?
131 // 3D acceleration enabled?
132 // hardware virtualization enabled?
133 // nested paging enabled?
134 // HWVirtExVPIDEnabled?
135 // PAEEnabled?
136 // Long mode enabled?
137 BOOL fLongMode;
138 rc = GetCPUProperty(CPUPropertyType_LongMode, &fLongMode);
139 if (FAILED(rc)) throw rc;
140
141 // snapshotFolder?
142 // VRDPServer?
143
144 /* Guest OS type */
145 ovf::CIMOSType_T cim = convertVBoxOSType2CIMOSType(strOsTypeVBox.c_str(), fLongMode);
146 pNewDesc->i_addEntry(VirtualSystemDescriptionType_OS,
147 "",
148 Utf8StrFmt("%RI32", cim),
149 strOsTypeVBox);
150
151 /* VM name */
152 pNewDesc->i_addEntry(VirtualSystemDescriptionType_Name,
153 "",
154 strVMName,
155 strVMName);
156
157 // description
158 pNewDesc->i_addEntry(VirtualSystemDescriptionType_Description,
159 "",
160 strDescription,
161 strDescription);
162
163 /* CPU count*/
164 Utf8Str strCpuCount = Utf8StrFmt("%RI32", cCPUs);
165 pNewDesc->i_addEntry(VirtualSystemDescriptionType_CPU,
166 "",
167 strCpuCount,
168 strCpuCount);
169
170 /* Memory */
171 Utf8Str strMemory = Utf8StrFmt("%RI64", (uint64_t)ulMemSizeMB * _1M);
172 pNewDesc->i_addEntry(VirtualSystemDescriptionType_Memory,
173 "",
174 strMemory,
175 strMemory);
176
177 // the one VirtualBox IDE controller has two channels with two ports each, which is
178 // considered two IDE controllers with two ports each by OVF, so export it as two
179 int32_t lIDEControllerPrimaryIndex = 0;
180 int32_t lIDEControllerSecondaryIndex = 0;
181 int32_t lSATAControllerIndex = 0;
182 int32_t lSCSIControllerIndex = 0;
183
184 /* Fetch all available storage controllers */
185 com::SafeIfaceArray<IStorageController> nwControllers;
186 rc = COMGETTER(StorageControllers)(ComSafeArrayAsOutParam(nwControllers));
187 if (FAILED(rc)) throw rc;
188
189 ComPtr<IStorageController> pIDEController;
190 ComPtr<IStorageController> pSATAController;
191 ComPtr<IStorageController> pSCSIController;
192 ComPtr<IStorageController> pSASController;
193 for (size_t j = 0; j < nwControllers.size(); ++j)
194 {
195 StorageBus_T eType;
196 rc = nwControllers[j]->COMGETTER(Bus)(&eType);
197 if (FAILED(rc)) throw rc;
198 if ( eType == StorageBus_IDE
199 && pIDEController.isNull())
200 pIDEController = nwControllers[j];
201 else if ( eType == StorageBus_SATA
202 && pSATAController.isNull())
203 pSATAController = nwControllers[j];
204 else if ( eType == StorageBus_SCSI
205 && pSATAController.isNull())
206 pSCSIController = nwControllers[j];
207 else if ( eType == StorageBus_SAS
208 && pSASController.isNull())
209 pSASController = nwControllers[j];
210 }
211
212// <const name="HardDiskControllerIDE" value="6" />
213 if (!pIDEController.isNull())
214 {
215 StorageControllerType_T ctlr;
216 rc = pIDEController->COMGETTER(ControllerType)(&ctlr);
217 if (FAILED(rc)) throw rc;
218
219 Utf8Str strVBox;
220 switch (ctlr)
221 {
222 case StorageControllerType_PIIX3: strVBox = "PIIX3"; break;
223 case StorageControllerType_PIIX4: strVBox = "PIIX4"; break;
224 case StorageControllerType_ICH6: strVBox = "ICH6"; break;
225 default: break; /* Shut up MSC. */
226 }
227
228 if (strVBox.length())
229 {
230 lIDEControllerPrimaryIndex = (int32_t)pNewDesc->m->maDescriptions.size();
231 pNewDesc->i_addEntry(VirtualSystemDescriptionType_HardDiskControllerIDE,
232 Utf8StrFmt("%d", lIDEControllerPrimaryIndex), // strRef
233 strVBox, // aOvfValue
234 strVBox); // aVBoxValue
235 lIDEControllerSecondaryIndex = lIDEControllerPrimaryIndex + 1;
236 pNewDesc->i_addEntry(VirtualSystemDescriptionType_HardDiskControllerIDE,
237 Utf8StrFmt("%d", lIDEControllerSecondaryIndex),
238 strVBox,
239 strVBox);
240 }
241 }
242
243// <const name="HardDiskControllerSATA" value="7" />
244 if (!pSATAController.isNull())
245 {
246 Utf8Str strVBox = "AHCI";
247 lSATAControllerIndex = (int32_t)pNewDesc->m->maDescriptions.size();
248 pNewDesc->i_addEntry(VirtualSystemDescriptionType_HardDiskControllerSATA,
249 Utf8StrFmt("%d", lSATAControllerIndex),
250 strVBox,
251 strVBox);
252 }
253
254// <const name="HardDiskControllerSCSI" value="8" />
255 if (!pSCSIController.isNull())
256 {
257 StorageControllerType_T ctlr;
258 rc = pSCSIController->COMGETTER(ControllerType)(&ctlr);
259 if (SUCCEEDED(rc))
260 {
261 Utf8Str strVBox = "LsiLogic"; // the default in VBox
262 switch (ctlr)
263 {
264 case StorageControllerType_LsiLogic: strVBox = "LsiLogic"; break;
265 case StorageControllerType_BusLogic: strVBox = "BusLogic"; break;
266 default: break; /* Shut up MSC. */
267 }
268 lSCSIControllerIndex = (int32_t)pNewDesc->m->maDescriptions.size();
269 pNewDesc->i_addEntry(VirtualSystemDescriptionType_HardDiskControllerSCSI,
270 Utf8StrFmt("%d", lSCSIControllerIndex),
271 strVBox,
272 strVBox);
273 }
274 else
275 throw rc;
276 }
277
278 if (!pSASController.isNull())
279 {
280 // VirtualBox considers the SAS controller a class of its own but in OVF
281 // it should be a SCSI controller
282 Utf8Str strVBox = "LsiLogicSas";
283 lSCSIControllerIndex = (int32_t)pNewDesc->m->maDescriptions.size();
284 pNewDesc->i_addEntry(VirtualSystemDescriptionType_HardDiskControllerSAS,
285 Utf8StrFmt("%d", lSCSIControllerIndex),
286 strVBox,
287 strVBox);
288 }
289
290// <const name="HardDiskImage" value="9" />
291// <const name="Floppy" value="18" />
292// <const name="CDROM" value="19" />
293
294 for (MediumAttachmentList::const_iterator
295 it = mMediumAttachments->begin();
296 it != mMediumAttachments->end();
297 ++it)
298 {
299 ComObjPtr<MediumAttachment> pHDA = *it;
300
301 // the attachment's data
302 ComPtr<IMedium> pMedium;
303 ComPtr<IStorageController> ctl;
304 Bstr controllerName;
305
306 rc = pHDA->COMGETTER(Controller)(controllerName.asOutParam());
307 if (FAILED(rc)) throw rc;
308
309 rc = GetStorageControllerByName(controllerName.raw(), ctl.asOutParam());
310 if (FAILED(rc)) throw rc;
311
312 StorageBus_T storageBus;
313 DeviceType_T deviceType;
314 LONG lChannel;
315 LONG lDevice;
316
317 rc = ctl->COMGETTER(Bus)(&storageBus);
318 if (FAILED(rc)) throw rc;
319
320 rc = pHDA->COMGETTER(Type)(&deviceType);
321 if (FAILED(rc)) throw rc;
322
323 rc = pHDA->COMGETTER(Medium)(pMedium.asOutParam());
324 if (FAILED(rc)) throw rc;
325
326 rc = pHDA->COMGETTER(Port)(&lChannel);
327 if (FAILED(rc)) throw rc;
328
329 rc = pHDA->COMGETTER(Device)(&lDevice);
330 if (FAILED(rc)) throw rc;
331
332 Utf8Str strTargetImageName;
333 Utf8Str strLocation;
334 LONG64 llSize = 0;
335
336 if ( deviceType == DeviceType_HardDisk
337 && pMedium)
338 {
339 Bstr bstrLocation;
340
341 rc = pMedium->COMGETTER(Location)(bstrLocation.asOutParam());
342 if (FAILED(rc)) throw rc;
343 strLocation = bstrLocation;
344
345 // find the source's base medium for two things:
346 // 1) we'll use its name to determine the name of the target disk, which is readable,
347 // as opposed to the UUID filename of a differencing image, if pMedium is one
348 // 2) we need the size of the base image so we can give it to addEntry(), and later
349 // on export, the progress will be based on that (and not the diff image)
350 ComPtr<IMedium> pBaseMedium;
351 rc = pMedium->COMGETTER(Base)(pBaseMedium.asOutParam());
352 // returns pMedium if there are no diff images
353 if (FAILED(rc)) throw rc;
354
355 Utf8Str strName = Utf8Str(locInfo.strPath).stripPath().stripSuffix();
356 strTargetImageName = Utf8StrFmt("%s-disk%.3d.vmdk", strName.c_str(), ++pAppliance->m->cDisks);
357 if (strTargetImageName.length() > RTTAR_NAME_MAX)
358 throw setError(VBOX_E_NOT_SUPPORTED,
359 tr("Cannot attach disk '%s' -- file name too long"), strTargetImageName.c_str());
360
361 // force reading state, or else size will be returned as 0
362 MediumState_T ms;
363 rc = pBaseMedium->RefreshState(&ms);
364 if (FAILED(rc)) throw rc;
365
366 rc = pBaseMedium->COMGETTER(Size)(&llSize);
367 if (FAILED(rc)) throw rc;
368
369 /* If the medium is encrypted add the key identifier to the list. */
370 IMedium *iBaseMedium = pBaseMedium;
371 Medium *pBase = static_cast<Medium*>(iBaseMedium);
372 const com::Utf8Str strKeyId = pBase->i_getKeyId();
373 if (!strKeyId.isEmpty())
374 {
375 IMedium *iMedium = pMedium;
376 Medium *pMed = static_cast<Medium*>(iMedium);
377 com::Guid mediumUuid = pMed->i_getId();
378 bool fKnown = false;
379
380 /* Check whether the ID is already in our sequence, add it otherwise. */
381 for (unsigned i = 0; i < pAppliance->m->m_vecPasswordIdentifiers.size(); i++)
382 {
383 if (strKeyId.equals(pAppliance->m->m_vecPasswordIdentifiers[i]))
384 {
385 fKnown = true;
386 break;
387 }
388 }
389
390 if (!fKnown)
391 {
392 GUIDVEC vecMediumIds;
393
394 vecMediumIds.push_back(mediumUuid);
395 pAppliance->m->m_vecPasswordIdentifiers.push_back(strKeyId);
396 pAppliance->m->m_mapPwIdToMediumIds.insert(std::pair<com::Utf8Str, GUIDVEC>(strKeyId, vecMediumIds));
397 }
398 else
399 {
400 std::map<com::Utf8Str, GUIDVEC>::iterator itMap = pAppliance->m->m_mapPwIdToMediumIds.find(strKeyId);
401 if (itMap == pAppliance->m->m_mapPwIdToMediumIds.end())
402 throw setError(E_FAIL, tr("Internal error adding a medium UUID to the map"));
403 itMap->second.push_back(mediumUuid);
404 }
405 }
406 }
407 else if ( deviceType == DeviceType_DVD
408 && pMedium)
409 {
410 /*
411 * check the minimal rules to grant access to export an image
412 * 1. no host drive CD/DVD image
413 * 2. the image must be accessible and readable
414 * 3. only ISO image is exported
415 */
416
417 //1. no host drive CD/DVD image
418 BOOL fHostDrive = false;
419 rc = pMedium->COMGETTER(HostDrive)(&fHostDrive);
420 if (FAILED(rc)) throw rc;
421
422 if(fHostDrive)
423 continue;
424
425 //2. the image must be accessible and readable
426 MediumState_T ms;
427 rc = pMedium->RefreshState(&ms);
428 if (FAILED(rc)) throw rc;
429
430 if (ms != MediumState_Created)
431 continue;
432
433 //3. only ISO image is exported
434 Bstr bstrLocation;
435 rc = pMedium->COMGETTER(Location)(bstrLocation.asOutParam());
436 if (FAILED(rc)) throw rc;
437
438 strLocation = bstrLocation;
439
440 Utf8Str ext = strLocation;
441 ext.assignEx(RTPathSuffix(ext.c_str()));//returns extension with dot (".iso")
442
443 int eq = ext.compare(".iso", Utf8Str::CaseInsensitive);
444 if (eq != 0)
445 continue;
446
447 Utf8Str strName = Utf8Str(locInfo.strPath).stripPath().stripSuffix();
448 strTargetImageName = Utf8StrFmt("%s-disk%.3d.iso", strName.c_str(), ++pAppliance->m->cDisks);
449 if (strTargetImageName.length() > RTTAR_NAME_MAX)
450 throw setError(VBOX_E_NOT_SUPPORTED,
451 tr("Cannot attach image '%s' -- file name too long"), strTargetImageName.c_str());
452
453 rc = pMedium->COMGETTER(Size)(&llSize);
454 if (FAILED(rc)) throw rc;
455 }
456 // and how this translates to the virtual system
457 int32_t lControllerVsys = 0;
458 LONG lChannelVsys;
459
460 switch (storageBus)
461 {
462 case StorageBus_IDE:
463 // this is the exact reverse to what we're doing in Appliance::taskThreadImportMachines,
464 // and it must be updated when that is changed!
465 // Before 3.2 we exported one IDE controller with channel 0-3, but we now maintain
466 // compatibility with what VMware does and export two IDE controllers with two channels each
467
468 if (lChannel == 0 && lDevice == 0) // primary master
469 {
470 lControllerVsys = lIDEControllerPrimaryIndex;
471 lChannelVsys = 0;
472 }
473 else if (lChannel == 0 && lDevice == 1) // primary slave
474 {
475 lControllerVsys = lIDEControllerPrimaryIndex;
476 lChannelVsys = 1;
477 }
478 else if (lChannel == 1 && lDevice == 0) // secondary master; by default this is the CD-ROM but
479 // as of VirtualBox 3.1 that can change
480 {
481 lControllerVsys = lIDEControllerSecondaryIndex;
482 lChannelVsys = 0;
483 }
484 else if (lChannel == 1 && lDevice == 1) // secondary slave
485 {
486 lControllerVsys = lIDEControllerSecondaryIndex;
487 lChannelVsys = 1;
488 }
489 else
490 throw setError(VBOX_E_NOT_SUPPORTED,
491 tr("Cannot handle medium attachment: channel is %d, device is %d"), lChannel, lDevice);
492 break;
493
494 case StorageBus_SATA:
495 lChannelVsys = lChannel; // should be between 0 and 29
496 lControllerVsys = lSATAControllerIndex;
497 break;
498
499 case StorageBus_SCSI:
500 case StorageBus_SAS:
501 lChannelVsys = lChannel; // should be between 0 and 15
502 lControllerVsys = lSCSIControllerIndex;
503 break;
504
505 case StorageBus_Floppy:
506 lChannelVsys = 0;
507 lControllerVsys = 0;
508 break;
509
510 default:
511 throw setError(VBOX_E_NOT_SUPPORTED,
512 tr("Cannot handle medium attachment: storageBus is %d, channel is %d, device is %d"),
513 storageBus, lChannel, lDevice);
514 break;
515 }
516
517 Utf8StrFmt strExtra("controller=%RI32;channel=%RI32", lControllerVsys, lChannelVsys);
518 Utf8Str strEmpty;
519
520 switch (deviceType)
521 {
522 case DeviceType_HardDisk:
523 Log(("Adding VirtualSystemDescriptionType_HardDiskImage, disk size: %RI64\n", llSize));
524 pNewDesc->i_addEntry(VirtualSystemDescriptionType_HardDiskImage,
525 strTargetImageName, // disk ID: let's use the name
526 strTargetImageName, // OVF value:
527 strLocation, // vbox value: media path
528 (uint32_t)(llSize / _1M),
529 strExtra);
530 break;
531
532 case DeviceType_DVD:
533 Log(("Adding VirtualSystemDescriptionType_CDROM, disk size: %RI64\n", llSize));
534 pNewDesc->i_addEntry(VirtualSystemDescriptionType_CDROM,
535 strTargetImageName, // disk ID
536 strTargetImageName, // OVF value
537 strLocation, // vbox value
538 (uint32_t)(llSize / _1M),// ulSize
539 strExtra);
540 break;
541
542 case DeviceType_Floppy:
543 pNewDesc->i_addEntry(VirtualSystemDescriptionType_Floppy,
544 strEmpty, // disk ID
545 strEmpty, // OVF value
546 strEmpty, // vbox value
547 1, // ulSize
548 strExtra);
549 break;
550
551 default: break; /* Shut up MSC. */
552 }
553 }
554
555// <const name="NetworkAdapter" />
556 uint32_t maxNetworkAdapters = Global::getMaxNetworkAdapters(i_getChipsetType());
557 size_t a;
558 for (a = 0; a < maxNetworkAdapters; ++a)
559 {
560 ComPtr<INetworkAdapter> pNetworkAdapter;
561 BOOL fEnabled;
562 NetworkAdapterType_T adapterType;
563 NetworkAttachmentType_T attachmentType;
564
565 rc = GetNetworkAdapter((ULONG)a, pNetworkAdapter.asOutParam());
566 if (FAILED(rc)) throw rc;
567 /* Enable the network card & set the adapter type */
568 rc = pNetworkAdapter->COMGETTER(Enabled)(&fEnabled);
569 if (FAILED(rc)) throw rc;
570
571 if (fEnabled)
572 {
573 rc = pNetworkAdapter->COMGETTER(AdapterType)(&adapterType);
574 if (FAILED(rc)) throw rc;
575
576 rc = pNetworkAdapter->COMGETTER(AttachmentType)(&attachmentType);
577 if (FAILED(rc)) throw rc;
578
579 Utf8Str strAttachmentType = convertNetworkAttachmentTypeToString(attachmentType);
580 pNewDesc->i_addEntry(VirtualSystemDescriptionType_NetworkAdapter,
581 "", // ref
582 strAttachmentType, // orig
583 Utf8StrFmt("%RI32", (uint32_t)adapterType), // conf
584 0,
585 Utf8StrFmt("type=%s", strAttachmentType.c_str())); // extra conf
586 }
587 }
588
589// <const name="USBController" />
590#ifdef VBOX_WITH_USB
591 if (fUSBEnabled)
592 pNewDesc->i_addEntry(VirtualSystemDescriptionType_USBController, "", "", "");
593#endif /* VBOX_WITH_USB */
594
595// <const name="SoundCard" />
596 if (fAudioEnabled)
597 pNewDesc->i_addEntry(VirtualSystemDescriptionType_SoundCard,
598 "",
599 "ensoniq1371", // this is what OVFTool writes and VMware supports
600 Utf8StrFmt("%RI32", audioController));
601
602 /* We return the new description to the caller */
603 ComPtr<IVirtualSystemDescription> copy(pNewDesc);
604 copy.queryInterfaceTo(aDescription.asOutParam());
605
606 AutoWriteLock alock(pAppliance COMMA_LOCKVAL_SRC_POS);
607 // finally, add the virtual system to the appliance
608 pAppliance->m->virtualSystemDescriptions.push_back(pNewDesc);
609 }
610 catch(HRESULT arc)
611 {
612 rc = arc;
613 }
614
615 return rc;
616}
617
618////////////////////////////////////////////////////////////////////////////////
619//
620// IAppliance public methods
621//
622////////////////////////////////////////////////////////////////////////////////
623
624/**
625 * Public method implementation.
626 * @param aFormat Appliance format.
627 * @param aOptions Export options.
628 * @param aPath Path to write the appliance to.
629 * @param aProgress Progress object.
630 * @return
631 */
632HRESULT Appliance::write(const com::Utf8Str &aFormat,
633 const std::vector<ExportOptions_T> &aOptions,
634 const com::Utf8Str &aPath,
635 ComPtr<IProgress> &aProgress)
636{
637 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
638
639 m->optListExport.clear();
640 if (aOptions.size())
641 {
642 for (size_t i = 0; i < aOptions.size(); ++i)
643 {
644 m->optListExport.insert(i, aOptions[i]);
645 }
646 }
647
648// AssertReturn(!(m->optListExport.contains(ExportOptions_CreateManifest)
649// && m->optListExport.contains(ExportOptions_ExportDVDImages)), E_INVALIDARG);
650
651 m->fExportISOImages = m->optListExport.contains(ExportOptions_ExportDVDImages);
652
653 if (!m->fExportISOImages)/* remove all ISO images from VirtualSystemDescription */
654 {
655 for (list<ComObjPtr<VirtualSystemDescription> >::const_iterator
656 it = m->virtualSystemDescriptions.begin();
657 it != m->virtualSystemDescriptions.end();
658 ++it)
659 {
660 ComObjPtr<VirtualSystemDescription> vsdescThis = *it;
661 std::list<VirtualSystemDescriptionEntry*> skipped = vsdescThis->i_findByType(VirtualSystemDescriptionType_CDROM);
662 std::list<VirtualSystemDescriptionEntry*>::const_iterator itSkipped = skipped.begin();
663 while (itSkipped != skipped.end())
664 {
665 (*itSkipped)->skipIt = true;
666 ++itSkipped;
667 }
668 }
669 }
670
671 // do not allow entering this method if the appliance is busy reading or writing
672 if (!i_isApplianceIdle())
673 return E_ACCESSDENIED;
674
675 // figure the export format. We exploit the unknown version value for oracle public cloud.
676 ovf::OVFVersion_T ovfF;
677 if (aFormat == "ovf-0.9")
678 ovfF = ovf::OVFVersion_0_9;
679 else if (aFormat == "ovf-1.0")
680 ovfF = ovf::OVFVersion_1_0;
681 else if (aFormat == "ovf-2.0")
682 ovfF = ovf::OVFVersion_2_0;
683 else if (aFormat == "opc")
684 ovfF = ovf::OVFVersion_unknown;
685 else
686 return setError(VBOX_E_FILE_ERROR,
687 tr("Invalid format \"%s\" specified"), aFormat.c_str());
688
689 // Check the extension.
690 if (ovfF == ovf::OVFVersion_unknown)
691 {
692 if (!aPath.endsWith(".tar.gz", Utf8Str::CaseInsensitive))
693 return setError(VBOX_E_FILE_ERROR,
694 tr("OPC appliance file must have .tar.gz extension"));
695 }
696 else if ( !aPath.endsWith(".ovf", Utf8Str::CaseInsensitive)
697 && !aPath.endsWith(".ova", Utf8Str::CaseInsensitive))
698 return setError(VBOX_E_FILE_ERROR, tr("Appliance file must have .ovf or .ova extension"));
699
700
701 /* As of OVF 2.0 we have to use SHA-256 in the manifest. */
702 m->fManifest = m->optListExport.contains(ExportOptions_CreateManifest);
703 if (m->fManifest)
704 m->fDigestTypes = ovfF >= ovf::OVFVersion_2_0 ? RTMANIFEST_ATTR_SHA256 : RTMANIFEST_ATTR_SHA1;
705#ifndef VBOX_WITH_NEW_TAR_CREATOR
706 m->fSha256 = ovfF >= ovf::OVFVersion_2_0;
707#endif
708 Assert(m->hOurManifest == NIL_RTMANIFEST);
709
710 /* Check whether all passwords are supplied or error out. */
711 if (m->m_cPwProvided < m->m_vecPasswordIdentifiers.size())
712 return setError(VBOX_E_INVALID_OBJECT_STATE,
713 tr("Appliance export failed because not all passwords were provided for all encrypted media"));
714
715 ComObjPtr<Progress> progress;
716 HRESULT rc = S_OK;
717 try
718 {
719 /* Parse all necessary info out of the URI */
720 i_parseURI(aPath, m->locInfo);
721 rc = i_writeImpl(ovfF, m->locInfo, progress);
722 }
723 catch (HRESULT aRC)
724 {
725 rc = aRC;
726 }
727
728 if (SUCCEEDED(rc))
729 /* Return progress to the caller */
730 progress.queryInterfaceTo(aProgress.asOutParam());
731
732 return rc;
733}
734
735////////////////////////////////////////////////////////////////////////////////
736//
737// Appliance private methods
738//
739////////////////////////////////////////////////////////////////////////////////
740
741/*******************************************************************************
742 * Export stuff
743 ******************************************************************************/
744
745/**
746 * Implementation for writing out the OVF to disk. This starts a new thread which will call
747 * Appliance::taskThreadWriteOVF().
748 *
749 * This is in a separate private method because it is used from two locations:
750 *
751 * 1) from the public Appliance::Write().
752 *
753 * 2) in a second worker thread; in that case, Appliance::Write() called Appliance::i_writeImpl(), which
754 * called Appliance::i_writeFSOVA(), which called Appliance::i_writeImpl(), which then called this again.
755 *
756 * @param aFormat
757 * @param aLocInfo
758 * @param aProgress
759 * @return
760 */
761HRESULT Appliance::i_writeImpl(ovf::OVFVersion_T aFormat, const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress)
762{
763 HRESULT rc;
764 try
765 {
766 rc = i_setUpProgress(aProgress,
767 BstrFmt(tr("Export appliance '%s'"), aLocInfo.strPath.c_str()),
768 (aLocInfo.storageType == VFSType_File) ? WriteFile : WriteS3);
769
770 /* Initialize our worker task */
771 TaskOVF* task = NULL;
772 try
773 {
774 task = new TaskOVF(this, TaskOVF::Write, aLocInfo, aProgress);
775 }
776 catch(...)
777 {
778 delete task;
779 throw rc = setError(VBOX_E_OBJECT_NOT_FOUND,
780 tr("Could not create TaskOVF object for for writing out the OVF to disk"));
781 }
782
783 /* The OVF version to write */
784 task->enFormat = aFormat;
785
786 rc = task->createThread();
787 if (FAILED(rc)) throw rc;
788
789 }
790 catch (HRESULT aRC)
791 {
792 rc = aRC;
793 }
794
795 return rc;
796}
797
798/**
799 * Called from Appliance::i_writeFS() for creating a XML document for this
800 * Appliance.
801 *
802 * @param writeLock The current write lock.
803 * @param doc The xml document to fill.
804 * @param stack Structure for temporary private
805 * data shared with caller.
806 * @param strPath Path to the target OVF.
807 * instance for which to write XML.
808 * @param enFormat OVF format (0.9 or 1.0).
809 */
810void Appliance::i_buildXML(AutoWriteLockBase& writeLock,
811 xml::Document &doc,
812 XMLStack &stack,
813 const Utf8Str &strPath,
814 ovf::OVFVersion_T enFormat)
815{
816 xml::ElementNode *pelmRoot = doc.createRootElement("Envelope");
817
818 pelmRoot->setAttribute("ovf:version", enFormat == ovf::OVFVersion_2_0 ? "2.0"
819 : enFormat == ovf::OVFVersion_1_0 ? "1.0"
820 : "0.9");
821 pelmRoot->setAttribute("xml:lang", "en-US");
822
823 Utf8Str strNamespace;
824
825 if (enFormat == ovf::OVFVersion_0_9)
826 {
827 strNamespace = ovf::OVF09_URI_string;
828 }
829 else if (enFormat == ovf::OVFVersion_1_0)
830 {
831 strNamespace = ovf::OVF10_URI_string;
832 }
833 else
834 {
835 strNamespace = ovf::OVF20_URI_string;
836 }
837
838 pelmRoot->setAttribute("xmlns", strNamespace);
839 pelmRoot->setAttribute("xmlns:ovf", strNamespace);
840
841 // pelmRoot->setAttribute("xmlns:ovfstr", "http://schema.dmtf.org/ovf/strings/1");
842 pelmRoot->setAttribute("xmlns:rasd", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData");
843 pelmRoot->setAttribute("xmlns:vssd", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData");
844 pelmRoot->setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
845 pelmRoot->setAttribute("xmlns:vbox", "http://www.virtualbox.org/ovf/machine");
846 // pelmRoot->setAttribute("xsi:schemaLocation", "http://schemas.dmtf.org/ovf/envelope/1 ../ovf-envelope.xsd");
847
848 if (enFormat == ovf::OVFVersion_2_0)
849 {
850 pelmRoot->setAttribute("xmlns:epasd",
851 "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_EthernetPortAllocationSettingData.xsd");
852 pelmRoot->setAttribute("xmlns:sasd",
853 "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_StorageAllocationSettingData.xsd");
854 }
855
856 // <Envelope>/<References>
857 xml::ElementNode *pelmReferences = pelmRoot->createChild("References"); // 0.9 and 1.0
858
859 /* <Envelope>/<DiskSection>:
860 <DiskSection>
861 <Info>List of the virtual disks used in the package</Info>
862 <Disk ovf:capacity="4294967296" ovf:diskId="lamp" ovf:format="..." ovf:populatedSize="1924967692"/>
863 </DiskSection> */
864 xml::ElementNode *pelmDiskSection;
865 if (enFormat == ovf::OVFVersion_0_9)
866 {
867 // <Section xsi:type="ovf:DiskSection_Type">
868 pelmDiskSection = pelmRoot->createChild("Section");
869 pelmDiskSection->setAttribute("xsi:type", "ovf:DiskSection_Type");
870 }
871 else
872 pelmDiskSection = pelmRoot->createChild("DiskSection");
873
874 xml::ElementNode *pelmDiskSectionInfo = pelmDiskSection->createChild("Info");
875 pelmDiskSectionInfo->addContent("List of the virtual disks used in the package");
876
877 /* <Envelope>/<NetworkSection>:
878 <NetworkSection>
879 <Info>Logical networks used in the package</Info>
880 <Network ovf:name="VM Network">
881 <Description>The network that the LAMP Service will be available on</Description>
882 </Network>
883 </NetworkSection> */
884 xml::ElementNode *pelmNetworkSection;
885 if (enFormat == ovf::OVFVersion_0_9)
886 {
887 // <Section xsi:type="ovf:NetworkSection_Type">
888 pelmNetworkSection = pelmRoot->createChild("Section");
889 pelmNetworkSection->setAttribute("xsi:type", "ovf:NetworkSection_Type");
890 }
891 else
892 pelmNetworkSection = pelmRoot->createChild("NetworkSection");
893
894 xml::ElementNode *pelmNetworkSectionInfo = pelmNetworkSection->createChild("Info");
895 pelmNetworkSectionInfo->addContent("Logical networks used in the package");
896
897 // and here come the virtual systems:
898
899 // write a collection if we have more than one virtual system _and_ we're
900 // writing OVF 1.0; otherwise fail since ovftool can't import more than
901 // one machine, it seems
902 xml::ElementNode *pelmToAddVirtualSystemsTo;
903 if (m->virtualSystemDescriptions.size() > 1)
904 {
905 if (enFormat == ovf::OVFVersion_0_9)
906 throw setError(VBOX_E_FILE_ERROR,
907 tr("Cannot export more than one virtual system with OVF 0.9, use OVF 1.0"));
908
909 pelmToAddVirtualSystemsTo = pelmRoot->createChild("VirtualSystemCollection");
910 pelmToAddVirtualSystemsTo->setAttribute("ovf:name", "ExportedVirtualBoxMachines"); // whatever
911 }
912 else
913 pelmToAddVirtualSystemsTo = pelmRoot; // add virtual system directly under root element
914
915 // this list receives pointers to the XML elements in the machine XML which
916 // might have UUIDs that need fixing after we know the UUIDs of the exported images
917 std::list<xml::ElementNode*> llElementsWithUuidAttributes;
918 uint32_t ulFile = 1;
919 /* Iterate through all virtual systems of that appliance */
920 for (list<ComObjPtr<VirtualSystemDescription> >::const_iterator
921 itV = m->virtualSystemDescriptions.begin();
922 itV != m->virtualSystemDescriptions.end();
923 ++itV)
924 {
925 ComObjPtr<VirtualSystemDescription> vsdescThis = *itV;
926 i_buildXMLForOneVirtualSystem(writeLock,
927 *pelmToAddVirtualSystemsTo,
928 &llElementsWithUuidAttributes,
929 vsdescThis,
930 enFormat,
931 stack); // disks and networks stack
932
933 list<Utf8Str> diskList;
934
935 for (list<Utf8Str>::const_iterator
936 itDisk = stack.mapDiskSequenceForOneVM.begin();
937 itDisk != stack.mapDiskSequenceForOneVM.end();
938 ++itDisk)
939 {
940 const Utf8Str &strDiskID = *itDisk;
941 const VirtualSystemDescriptionEntry *pDiskEntry = stack.mapDisks[strDiskID];
942
943 // source path: where the VBox image is
944 const Utf8Str &strSrcFilePath = pDiskEntry->strVBoxCurrent;
945 Bstr bstrSrcFilePath(strSrcFilePath);
946
947 //skip empty Medium. There are no information to add into section <References> or <DiskSection>
948 if (strSrcFilePath.isEmpty() ||
949 pDiskEntry->skipIt == true)
950 continue;
951
952 // Do NOT check here whether the file exists. FindMedium will figure
953 // that out, and filesystem-based tests are simply wrong in the
954 // general case (think of iSCSI).
955
956 // We need some info from the source disks
957 ComPtr<IMedium> pSourceDisk;
958 //DeviceType_T deviceType = DeviceType_HardDisk;// by default
959
960 Log(("Finding source disk \"%ls\"\n", bstrSrcFilePath.raw()));
961
962 HRESULT rc;
963
964 if (pDiskEntry->type == VirtualSystemDescriptionType_HardDiskImage)
965 {
966 rc = mVirtualBox->OpenMedium(bstrSrcFilePath.raw(),
967 DeviceType_HardDisk,
968 AccessMode_ReadWrite,
969 FALSE /* fForceNewUuid */,
970 pSourceDisk.asOutParam());
971 if (FAILED(rc))
972 throw rc;
973 }
974 else if (pDiskEntry->type == VirtualSystemDescriptionType_CDROM)//may be, this is CD/DVD
975 {
976 rc = mVirtualBox->OpenMedium(bstrSrcFilePath.raw(),
977 DeviceType_DVD,
978 AccessMode_ReadOnly,
979 FALSE,
980 pSourceDisk.asOutParam());
981 if (FAILED(rc))
982 throw rc;
983 }
984
985 Bstr uuidSource;
986 rc = pSourceDisk->COMGETTER(Id)(uuidSource.asOutParam());
987 if (FAILED(rc)) throw rc;
988 Guid guidSource(uuidSource);
989
990 // output filename
991 const Utf8Str &strTargetFileNameOnly = pDiskEntry->strOvf;
992 // target path needs to be composed from where the output OVF is
993 Utf8Str strTargetFilePath(strPath);
994 strTargetFilePath.stripFilename();
995 strTargetFilePath.append("/");
996 strTargetFilePath.append(strTargetFileNameOnly);
997
998 // We are always exporting to VMDK stream optimized for now
999 //Bstr bstrSrcFormat = L"VMDK";//not used
1000
1001 diskList.push_back(strTargetFilePath);
1002
1003 LONG64 cbCapacity = 0; // size reported to guest
1004 rc = pSourceDisk->COMGETTER(LogicalSize)(&cbCapacity);
1005 if (FAILED(rc)) throw rc;
1006 /// @todo r=poetzsch: wrong it is reported in bytes ...
1007 // capacity is reported in megabytes, so...
1008 //cbCapacity *= _1M;
1009
1010 Guid guidTarget; /* Creates a new uniq number for the target disk. */
1011 guidTarget.create();
1012
1013 // now handle the XML for the disk:
1014 Utf8StrFmt strFileRef("file%RI32", ulFile++);
1015 // <File ovf:href="WindowsXpProfessional-disk1.vmdk" ovf:id="file1" ovf:size="1710381056"/>
1016 xml::ElementNode *pelmFile = pelmReferences->createChild("File");
1017 pelmFile->setAttribute("ovf:id", strFileRef);
1018 pelmFile->setAttribute("ovf:href", strTargetFileNameOnly);
1019 /// @todo the actual size is not available at this point of time,
1020 // cause the disk will be compressed. The 1.0 standard says this is
1021 // optional! 1.1 isn't fully clear if the "gzip" format is used.
1022 // Need to be checked. */
1023 // pelmFile->setAttribute("ovf:size", Utf8StrFmt("%RI64", cbFile).c_str());
1024
1025 // add disk to XML Disks section
1026 // <Disk ovf:capacity="8589934592" ovf:diskId="vmdisk1" ovf:fileRef="file1" ovf:format="..."/>
1027 xml::ElementNode *pelmDisk = pelmDiskSection->createChild("Disk");
1028 pelmDisk->setAttribute("ovf:capacity", Utf8StrFmt("%RI64", cbCapacity).c_str());
1029 pelmDisk->setAttribute("ovf:diskId", strDiskID);
1030 pelmDisk->setAttribute("ovf:fileRef", strFileRef);
1031
1032 if (pDiskEntry->type == VirtualSystemDescriptionType_HardDiskImage)//deviceType == DeviceType_HardDisk
1033 {
1034 pelmDisk->setAttribute("ovf:format",
1035 (enFormat == ovf::OVFVersion_0_9)
1036 ? "http://www.vmware.com/specifications/vmdk.html#sparse" // must be sparse or ovftoo
1037 : "http://www.vmware.com/interfaces/specifications/vmdk.html#streamOptimized"
1038 // correct string as communicated to us by VMware (public bug #6612)
1039 );
1040 }
1041 else //pDiskEntry->type == VirtualSystemDescriptionType_CDROM, deviceType == DeviceType_DVD
1042 {
1043 pelmDisk->setAttribute("ovf:format",
1044 "http://www.ecma-international.org/publications/standards/Ecma-119.htm"
1045 );
1046 }
1047
1048 // add the UUID of the newly target image to the OVF disk element, but in the
1049 // vbox: namespace since it's not part of the standard
1050 pelmDisk->setAttribute("vbox:uuid", Utf8StrFmt("%RTuuid", guidTarget.raw()).c_str());
1051
1052 // now, we might have other XML elements from vbox:Machine pointing to this image,
1053 // but those would refer to the UUID of the _source_ image (which we created the
1054 // export image from); those UUIDs need to be fixed to the export image
1055 Utf8Str strGuidSourceCurly = guidSource.toStringCurly();
1056 for (std::list<xml::ElementNode*>::const_iterator
1057 it = llElementsWithUuidAttributes.begin();
1058 it != llElementsWithUuidAttributes.end();
1059 ++it)
1060 {
1061 xml::ElementNode *pelmImage = *it;
1062 Utf8Str strUUID;
1063 pelmImage->getAttributeValue("uuid", strUUID);
1064 if (strUUID == strGuidSourceCurly)
1065 // overwrite existing uuid attribute
1066 pelmImage->setAttribute("uuid", guidTarget.toStringCurly());
1067 }
1068 }
1069 llElementsWithUuidAttributes.clear();
1070 stack.mapDiskSequenceForOneVM.clear();
1071 }
1072
1073 // now, fill in the network section we set up empty above according
1074 // to the networks we found with the hardware items
1075 for (map<Utf8Str, bool>::const_iterator
1076 it = stack.mapNetworks.begin();
1077 it != stack.mapNetworks.end();
1078 ++it)
1079 {
1080 const Utf8Str &strNetwork = it->first;
1081 xml::ElementNode *pelmNetwork = pelmNetworkSection->createChild("Network");
1082 pelmNetwork->setAttribute("ovf:name", strNetwork.c_str());
1083 pelmNetwork->createChild("Description")->addContent("Logical network used by this appliance.");
1084 }
1085
1086}
1087
1088/**
1089 * Called from Appliance::i_buildXML() for each virtual system (machine) that
1090 * needs XML written out.
1091 *
1092 * @param writeLock The current write lock.
1093 * @param elmToAddVirtualSystemsTo XML element to append elements to.
1094 * @param pllElementsWithUuidAttributes out: list of XML elements produced here
1095 * with UUID attributes for quick
1096 * fixing by caller later
1097 * @param vsdescThis The IVirtualSystemDescription
1098 * instance for which to write XML.
1099 * @param enFormat OVF format (0.9 or 1.0).
1100 * @param stack Structure for temporary private
1101 * data shared with caller.
1102 */
1103void Appliance::i_buildXMLForOneVirtualSystem(AutoWriteLockBase& writeLock,
1104 xml::ElementNode &elmToAddVirtualSystemsTo,
1105 std::list<xml::ElementNode*> *pllElementsWithUuidAttributes,
1106 ComObjPtr<VirtualSystemDescription> &vsdescThis,
1107 ovf::OVFVersion_T enFormat,
1108 XMLStack &stack)
1109{
1110 LogFlowFunc(("ENTER appliance %p\n", this));
1111
1112 xml::ElementNode *pelmVirtualSystem;
1113 if (enFormat == ovf::OVFVersion_0_9)
1114 {
1115 // <Section xsi:type="ovf:NetworkSection_Type">
1116 pelmVirtualSystem = elmToAddVirtualSystemsTo.createChild("Content");
1117 pelmVirtualSystem->setAttribute("xsi:type", "ovf:VirtualSystem_Type");
1118 }
1119 else
1120 pelmVirtualSystem = elmToAddVirtualSystemsTo.createChild("VirtualSystem");
1121
1122 /*xml::ElementNode *pelmVirtualSystemInfo =*/ pelmVirtualSystem->createChild("Info")->addContent("A virtual machine");
1123
1124 std::list<VirtualSystemDescriptionEntry*> llName = vsdescThis->i_findByType(VirtualSystemDescriptionType_Name);
1125 if (llName.empty())
1126 throw setError(VBOX_E_NOT_SUPPORTED, tr("Missing VM name"));
1127 Utf8Str &strVMName = llName.back()->strVBoxCurrent;
1128 pelmVirtualSystem->setAttribute("ovf:id", strVMName);
1129
1130 // product info
1131 std::list<VirtualSystemDescriptionEntry*> llProduct = vsdescThis->i_findByType(VirtualSystemDescriptionType_Product);
1132 std::list<VirtualSystemDescriptionEntry*> llProductUrl = vsdescThis->i_findByType(VirtualSystemDescriptionType_ProductUrl);
1133 std::list<VirtualSystemDescriptionEntry*> llVendor = vsdescThis->i_findByType(VirtualSystemDescriptionType_Vendor);
1134 std::list<VirtualSystemDescriptionEntry*> llVendorUrl = vsdescThis->i_findByType(VirtualSystemDescriptionType_VendorUrl);
1135 std::list<VirtualSystemDescriptionEntry*> llVersion = vsdescThis->i_findByType(VirtualSystemDescriptionType_Version);
1136 bool fProduct = llProduct.size() && !llProduct.back()->strVBoxCurrent.isEmpty();
1137 bool fProductUrl = llProductUrl.size() && !llProductUrl.back()->strVBoxCurrent.isEmpty();
1138 bool fVendor = llVendor.size() && !llVendor.back()->strVBoxCurrent.isEmpty();
1139 bool fVendorUrl = llVendorUrl.size() && !llVendorUrl.back()->strVBoxCurrent.isEmpty();
1140 bool fVersion = llVersion.size() && !llVersion.back()->strVBoxCurrent.isEmpty();
1141 if (fProduct || fProductUrl || fVendor || fVendorUrl || fVersion)
1142 {
1143 /* <Section ovf:required="false" xsi:type="ovf:ProductSection_Type">
1144 <Info>Meta-information about the installed software</Info>
1145 <Product>VAtest</Product>
1146 <Vendor>SUN Microsystems</Vendor>
1147 <Version>10.0</Version>
1148 <ProductUrl>http://blogs.sun.com/VirtualGuru</ProductUrl>
1149 <VendorUrl>http://www.sun.com</VendorUrl>
1150 </Section> */
1151 xml::ElementNode *pelmAnnotationSection;
1152 if (enFormat == ovf::OVFVersion_0_9)
1153 {
1154 // <Section ovf:required="false" xsi:type="ovf:ProductSection_Type">
1155 pelmAnnotationSection = pelmVirtualSystem->createChild("Section");
1156 pelmAnnotationSection->setAttribute("xsi:type", "ovf:ProductSection_Type");
1157 }
1158 else
1159 pelmAnnotationSection = pelmVirtualSystem->createChild("ProductSection");
1160
1161 pelmAnnotationSection->createChild("Info")->addContent("Meta-information about the installed software");
1162 if (fProduct)
1163 pelmAnnotationSection->createChild("Product")->addContent(llProduct.back()->strVBoxCurrent);
1164 if (fVendor)
1165 pelmAnnotationSection->createChild("Vendor")->addContent(llVendor.back()->strVBoxCurrent);
1166 if (fVersion)
1167 pelmAnnotationSection->createChild("Version")->addContent(llVersion.back()->strVBoxCurrent);
1168 if (fProductUrl)
1169 pelmAnnotationSection->createChild("ProductUrl")->addContent(llProductUrl.back()->strVBoxCurrent);
1170 if (fVendorUrl)
1171 pelmAnnotationSection->createChild("VendorUrl")->addContent(llVendorUrl.back()->strVBoxCurrent);
1172 }
1173
1174 // description
1175 std::list<VirtualSystemDescriptionEntry*> llDescription = vsdescThis->i_findByType(VirtualSystemDescriptionType_Description);
1176 if (llDescription.size() &&
1177 !llDescription.back()->strVBoxCurrent.isEmpty())
1178 {
1179 /* <Section ovf:required="false" xsi:type="ovf:AnnotationSection_Type">
1180 <Info>A human-readable annotation</Info>
1181 <Annotation>Plan 9</Annotation>
1182 </Section> */
1183 xml::ElementNode *pelmAnnotationSection;
1184 if (enFormat == ovf::OVFVersion_0_9)
1185 {
1186 // <Section ovf:required="false" xsi:type="ovf:AnnotationSection_Type">
1187 pelmAnnotationSection = pelmVirtualSystem->createChild("Section");
1188 pelmAnnotationSection->setAttribute("xsi:type", "ovf:AnnotationSection_Type");
1189 }
1190 else
1191 pelmAnnotationSection = pelmVirtualSystem->createChild("AnnotationSection");
1192
1193 pelmAnnotationSection->createChild("Info")->addContent("A human-readable annotation");
1194 pelmAnnotationSection->createChild("Annotation")->addContent(llDescription.back()->strVBoxCurrent);
1195 }
1196
1197 // license
1198 std::list<VirtualSystemDescriptionEntry*> llLicense = vsdescThis->i_findByType(VirtualSystemDescriptionType_License);
1199 if (llLicense.size() &&
1200 !llLicense.back()->strVBoxCurrent.isEmpty())
1201 {
1202 /* <EulaSection>
1203 <Info ovf:msgid="6">License agreement for the Virtual System.</Info>
1204 <License ovf:msgid="1">License terms can go in here.</License>
1205 </EulaSection> */
1206 xml::ElementNode *pelmEulaSection;
1207 if (enFormat == ovf::OVFVersion_0_9)
1208 {
1209 pelmEulaSection = pelmVirtualSystem->createChild("Section");
1210 pelmEulaSection->setAttribute("xsi:type", "ovf:EulaSection_Type");
1211 }
1212 else
1213 pelmEulaSection = pelmVirtualSystem->createChild("EulaSection");
1214
1215 pelmEulaSection->createChild("Info")->addContent("License agreement for the virtual system");
1216 pelmEulaSection->createChild("License")->addContent(llLicense.back()->strVBoxCurrent);
1217 }
1218
1219 // operating system
1220 std::list<VirtualSystemDescriptionEntry*> llOS = vsdescThis->i_findByType(VirtualSystemDescriptionType_OS);
1221 if (llOS.empty())
1222 throw setError(VBOX_E_NOT_SUPPORTED, tr("Missing OS type"));
1223 /* <OperatingSystemSection ovf:id="82">
1224 <Info>Guest Operating System</Info>
1225 <Description>Linux 2.6.x</Description>
1226 </OperatingSystemSection> */
1227 VirtualSystemDescriptionEntry *pvsdeOS = llOS.back();
1228 xml::ElementNode *pelmOperatingSystemSection;
1229 if (enFormat == ovf::OVFVersion_0_9)
1230 {
1231 pelmOperatingSystemSection = pelmVirtualSystem->createChild("Section");
1232 pelmOperatingSystemSection->setAttribute("xsi:type", "ovf:OperatingSystemSection_Type");
1233 }
1234 else
1235 pelmOperatingSystemSection = pelmVirtualSystem->createChild("OperatingSystemSection");
1236
1237 pelmOperatingSystemSection->setAttribute("ovf:id", pvsdeOS->strOvf);
1238 pelmOperatingSystemSection->createChild("Info")->addContent("The kind of installed guest operating system");
1239 Utf8Str strOSDesc;
1240 convertCIMOSType2VBoxOSType(strOSDesc, (ovf::CIMOSType_T)pvsdeOS->strOvf.toInt32(), "");
1241 pelmOperatingSystemSection->createChild("Description")->addContent(strOSDesc);
1242 // add the VirtualBox ostype in a custom tag in a different namespace
1243 xml::ElementNode *pelmVBoxOSType = pelmOperatingSystemSection->createChild("vbox:OSType");
1244 pelmVBoxOSType->setAttribute("ovf:required", "false");
1245 pelmVBoxOSType->addContent(pvsdeOS->strVBoxCurrent);
1246
1247 // <VirtualHardwareSection ovf:id="hw1" ovf:transport="iso">
1248 xml::ElementNode *pelmVirtualHardwareSection;
1249 if (enFormat == ovf::OVFVersion_0_9)
1250 {
1251 // <Section xsi:type="ovf:VirtualHardwareSection_Type">
1252 pelmVirtualHardwareSection = pelmVirtualSystem->createChild("Section");
1253 pelmVirtualHardwareSection->setAttribute("xsi:type", "ovf:VirtualHardwareSection_Type");
1254 }
1255 else
1256 pelmVirtualHardwareSection = pelmVirtualSystem->createChild("VirtualHardwareSection");
1257
1258 pelmVirtualHardwareSection->createChild("Info")->addContent("Virtual hardware requirements for a virtual machine");
1259
1260 /* <System>
1261 <vssd:Description>Description of the virtual hardware section.</vssd:Description>
1262 <vssd:ElementName>vmware</vssd:ElementName>
1263 <vssd:InstanceID>1</vssd:InstanceID>
1264 <vssd:VirtualSystemIdentifier>MyLampService</vssd:VirtualSystemIdentifier>
1265 <vssd:VirtualSystemType>vmx-4</vssd:VirtualSystemType>
1266 </System> */
1267 xml::ElementNode *pelmSystem = pelmVirtualHardwareSection->createChild("System");
1268
1269 pelmSystem->createChild("vssd:ElementName")->addContent("Virtual Hardware Family"); // required OVF 1.0
1270
1271 // <vssd:InstanceId>0</vssd:InstanceId>
1272 if (enFormat == ovf::OVFVersion_0_9)
1273 pelmSystem->createChild("vssd:InstanceId")->addContent("0");
1274 else // capitalization changed...
1275 pelmSystem->createChild("vssd:InstanceID")->addContent("0");
1276
1277 // <vssd:VirtualSystemIdentifier>VAtest</vssd:VirtualSystemIdentifier>
1278 pelmSystem->createChild("vssd:VirtualSystemIdentifier")->addContent(strVMName);
1279 // <vssd:VirtualSystemType>vmx-4</vssd:VirtualSystemType>
1280 const char *pcszHardware = "virtualbox-2.2";
1281 if (enFormat == ovf::OVFVersion_0_9)
1282 // pretend to be vmware compatible then
1283 pcszHardware = "vmx-6";
1284 pelmSystem->createChild("vssd:VirtualSystemType")->addContent(pcszHardware);
1285
1286 // loop thru all description entries twice; once to write out all
1287 // devices _except_ disk images, and a second time to assign the
1288 // disk images; this is because disk images need to reference
1289 // IDE controllers, and we can't know their instance IDs without
1290 // assigning them first
1291
1292 uint32_t idIDEPrimaryController = 0;
1293 int32_t lIDEPrimaryControllerIndex = 0;
1294 uint32_t idIDESecondaryController = 0;
1295 int32_t lIDESecondaryControllerIndex = 0;
1296 uint32_t idSATAController = 0;
1297 int32_t lSATAControllerIndex = 0;
1298 uint32_t idSCSIController = 0;
1299 int32_t lSCSIControllerIndex = 0;
1300
1301 uint32_t ulInstanceID = 1;
1302
1303 uint32_t cDVDs = 0;
1304
1305 for (size_t uLoop = 1; uLoop <= 2; ++uLoop)
1306 {
1307 int32_t lIndexThis = 0;
1308 for (vector<VirtualSystemDescriptionEntry>::const_iterator
1309 it = vsdescThis->m->maDescriptions.begin();
1310 it != vsdescThis->m->maDescriptions.end();
1311 ++it, ++lIndexThis)
1312 {
1313 const VirtualSystemDescriptionEntry &desc = *it;
1314
1315 LogFlowFunc(("Loop %u: handling description entry ulIndex=%u, type=%s, strRef=%s, strOvf=%s, strVBox=%s, strExtraConfig=%s\n",
1316 uLoop,
1317 desc.ulIndex,
1318 ( desc.type == VirtualSystemDescriptionType_HardDiskControllerIDE ? "HardDiskControllerIDE"
1319 : desc.type == VirtualSystemDescriptionType_HardDiskControllerSATA ? "HardDiskControllerSATA"
1320 : desc.type == VirtualSystemDescriptionType_HardDiskControllerSCSI ? "HardDiskControllerSCSI"
1321 : desc.type == VirtualSystemDescriptionType_HardDiskControllerSAS ? "HardDiskControllerSAS"
1322 : desc.type == VirtualSystemDescriptionType_HardDiskImage ? "HardDiskImage"
1323 : Utf8StrFmt("%d", desc.type).c_str()),
1324 desc.strRef.c_str(),
1325 desc.strOvf.c_str(),
1326 desc.strVBoxCurrent.c_str(),
1327 desc.strExtraConfigCurrent.c_str()));
1328
1329 ovf::ResourceType_T type = (ovf::ResourceType_T)0; // if this becomes != 0 then we do stuff
1330 Utf8Str strResourceSubType;
1331
1332 Utf8Str strDescription; // results in <rasd:Description>...</rasd:Description> block
1333 Utf8Str strCaption; // results in <rasd:Caption>...</rasd:Caption> block
1334
1335 uint32_t ulParent = 0;
1336
1337 int32_t lVirtualQuantity = -1;
1338 Utf8Str strAllocationUnits;
1339
1340 int32_t lAddress = -1;
1341 int32_t lBusNumber = -1;
1342 int32_t lAddressOnParent = -1;
1343
1344 int32_t lAutomaticAllocation = -1; // 0 means "false", 1 means "true"
1345 Utf8Str strConnection; // results in <rasd:Connection>...</rasd:Connection> block
1346 Utf8Str strHostResource;
1347
1348 uint64_t uTemp;
1349
1350 ovf::VirtualHardwareItem vhi;
1351 ovf::StorageItem si;
1352 ovf::EthernetPortItem epi;
1353
1354 switch (desc.type)
1355 {
1356 case VirtualSystemDescriptionType_CPU:
1357 /* <Item>
1358 <rasd:Caption>1 virtual CPU</rasd:Caption>
1359 <rasd:Description>Number of virtual CPUs</rasd:Description>
1360 <rasd:ElementName>virtual CPU</rasd:ElementName>
1361 <rasd:InstanceID>1</rasd:InstanceID>
1362 <rasd:ResourceType>3</rasd:ResourceType>
1363 <rasd:VirtualQuantity>1</rasd:VirtualQuantity>
1364 </Item> */
1365 if (uLoop == 1)
1366 {
1367 strDescription = "Number of virtual CPUs";
1368 type = ovf::ResourceType_Processor; // 3
1369 desc.strVBoxCurrent.toInt(uTemp);
1370 lVirtualQuantity = (int32_t)uTemp;
1371 strCaption = Utf8StrFmt("%d virtual CPU", lVirtualQuantity); // without this ovftool
1372 // won't eat the item
1373 }
1374 break;
1375
1376 case VirtualSystemDescriptionType_Memory:
1377 /* <Item>
1378 <rasd:AllocationUnits>MegaBytes</rasd:AllocationUnits>
1379 <rasd:Caption>256 MB of memory</rasd:Caption>
1380 <rasd:Description>Memory Size</rasd:Description>
1381 <rasd:ElementName>Memory</rasd:ElementName>
1382 <rasd:InstanceID>2</rasd:InstanceID>
1383 <rasd:ResourceType>4</rasd:ResourceType>
1384 <rasd:VirtualQuantity>256</rasd:VirtualQuantity>
1385 </Item> */
1386 if (uLoop == 1)
1387 {
1388 strDescription = "Memory Size";
1389 type = ovf::ResourceType_Memory; // 4
1390 desc.strVBoxCurrent.toInt(uTemp);
1391 lVirtualQuantity = (int32_t)(uTemp / _1M);
1392 strAllocationUnits = "MegaBytes";
1393 strCaption = Utf8StrFmt("%d MB of memory", lVirtualQuantity); // without this ovftool
1394 // won't eat the item
1395 }
1396 break;
1397
1398 case VirtualSystemDescriptionType_HardDiskControllerIDE:
1399 /* <Item>
1400 <rasd:Caption>ideController1</rasd:Caption>
1401 <rasd:Description>IDE Controller</rasd:Description>
1402 <rasd:InstanceId>5</rasd:InstanceId>
1403 <rasd:ResourceType>5</rasd:ResourceType>
1404 <rasd:Address>1</rasd:Address>
1405 <rasd:BusNumber>1</rasd:BusNumber>
1406 </Item> */
1407 if (uLoop == 1)
1408 {
1409 strDescription = "IDE Controller";
1410 type = ovf::ResourceType_IDEController; // 5
1411 strResourceSubType = desc.strVBoxCurrent;
1412
1413 if (!lIDEPrimaryControllerIndex)
1414 {
1415 // first IDE controller:
1416 strCaption = "ideController0";
1417 lAddress = 0;
1418 lBusNumber = 0;
1419 // remember this ID
1420 idIDEPrimaryController = ulInstanceID;
1421 lIDEPrimaryControllerIndex = lIndexThis;
1422 }
1423 else
1424 {
1425 // second IDE controller:
1426 strCaption = "ideController1";
1427 lAddress = 1;
1428 lBusNumber = 1;
1429 // remember this ID
1430 idIDESecondaryController = ulInstanceID;
1431 lIDESecondaryControllerIndex = lIndexThis;
1432 }
1433 }
1434 break;
1435
1436 case VirtualSystemDescriptionType_HardDiskControllerSATA:
1437 /* <Item>
1438 <rasd:Caption>sataController0</rasd:Caption>
1439 <rasd:Description>SATA Controller</rasd:Description>
1440 <rasd:InstanceId>4</rasd:InstanceId>
1441 <rasd:ResourceType>20</rasd:ResourceType>
1442 <rasd:ResourceSubType>ahci</rasd:ResourceSubType>
1443 <rasd:Address>0</rasd:Address>
1444 <rasd:BusNumber>0</rasd:BusNumber>
1445 </Item>
1446 */
1447 if (uLoop == 1)
1448 {
1449 strDescription = "SATA Controller";
1450 strCaption = "sataController0";
1451 type = ovf::ResourceType_OtherStorageDevice; // 20
1452 // it seems that OVFTool always writes these two, and since we can only
1453 // have one SATA controller, we'll use this as well
1454 lAddress = 0;
1455 lBusNumber = 0;
1456
1457 if ( desc.strVBoxCurrent.isEmpty() // AHCI is the default in VirtualBox
1458 || (!desc.strVBoxCurrent.compare("ahci", Utf8Str::CaseInsensitive))
1459 )
1460 strResourceSubType = "AHCI";
1461 else
1462 throw setError(VBOX_E_NOT_SUPPORTED,
1463 tr("Invalid config string \"%s\" in SATA controller"), desc.strVBoxCurrent.c_str());
1464
1465 // remember this ID
1466 idSATAController = ulInstanceID;
1467 lSATAControllerIndex = lIndexThis;
1468 }
1469 break;
1470
1471 case VirtualSystemDescriptionType_HardDiskControllerSCSI:
1472 case VirtualSystemDescriptionType_HardDiskControllerSAS:
1473 /* <Item>
1474 <rasd:Caption>scsiController0</rasd:Caption>
1475 <rasd:Description>SCSI Controller</rasd:Description>
1476 <rasd:InstanceId>4</rasd:InstanceId>
1477 <rasd:ResourceType>6</rasd:ResourceType>
1478 <rasd:ResourceSubType>buslogic</rasd:ResourceSubType>
1479 <rasd:Address>0</rasd:Address>
1480 <rasd:BusNumber>0</rasd:BusNumber>
1481 </Item>
1482 */
1483 if (uLoop == 1)
1484 {
1485 strDescription = "SCSI Controller";
1486 strCaption = "scsiController0";
1487 type = ovf::ResourceType_ParallelSCSIHBA; // 6
1488 // it seems that OVFTool always writes these two, and since we can only
1489 // have one SATA controller, we'll use this as well
1490 lAddress = 0;
1491 lBusNumber = 0;
1492
1493 if ( desc.strVBoxCurrent.isEmpty() // LsiLogic is the default in VirtualBox
1494 || (!desc.strVBoxCurrent.compare("lsilogic", Utf8Str::CaseInsensitive))
1495 )
1496 strResourceSubType = "lsilogic";
1497 else if (!desc.strVBoxCurrent.compare("buslogic", Utf8Str::CaseInsensitive))
1498 strResourceSubType = "buslogic";
1499 else if (!desc.strVBoxCurrent.compare("lsilogicsas", Utf8Str::CaseInsensitive))
1500 strResourceSubType = "lsilogicsas";
1501 else
1502 throw setError(VBOX_E_NOT_SUPPORTED,
1503 tr("Invalid config string \"%s\" in SCSI/SAS controller"),
1504 desc.strVBoxCurrent.c_str());
1505
1506 // remember this ID
1507 idSCSIController = ulInstanceID;
1508 lSCSIControllerIndex = lIndexThis;
1509 }
1510 break;
1511
1512 case VirtualSystemDescriptionType_HardDiskImage:
1513 /* <Item>
1514 <rasd:Caption>disk1</rasd:Caption>
1515 <rasd:InstanceId>8</rasd:InstanceId>
1516 <rasd:ResourceType>17</rasd:ResourceType>
1517 <rasd:HostResource>/disk/vmdisk1</rasd:HostResource>
1518 <rasd:Parent>4</rasd:Parent>
1519 <rasd:AddressOnParent>0</rasd:AddressOnParent>
1520 </Item> */
1521 if (uLoop == 2)
1522 {
1523 uint32_t cDisks = (uint32_t)stack.mapDisks.size();
1524 Utf8Str strDiskID = Utf8StrFmt("vmdisk%RI32", ++cDisks);
1525
1526 strDescription = "Disk Image";
1527 strCaption = Utf8StrFmt("disk%RI32", cDisks); // this is not used for anything else
1528 type = ovf::ResourceType_HardDisk; // 17
1529
1530 // the following references the "<Disks>" XML block
1531 strHostResource = Utf8StrFmt("/disk/%s", strDiskID.c_str());
1532
1533 // controller=<index>;channel=<c>
1534 size_t pos1 = desc.strExtraConfigCurrent.find("controller=");
1535 size_t pos2 = desc.strExtraConfigCurrent.find("channel=");
1536 int32_t lControllerIndex = -1;
1537 if (pos1 != Utf8Str::npos)
1538 {
1539 RTStrToInt32Ex(desc.strExtraConfigCurrent.c_str() + pos1 + 11, NULL, 0, &lControllerIndex);
1540 if (lControllerIndex == lIDEPrimaryControllerIndex)
1541 ulParent = idIDEPrimaryController;
1542 else if (lControllerIndex == lIDESecondaryControllerIndex)
1543 ulParent = idIDESecondaryController;
1544 else if (lControllerIndex == lSCSIControllerIndex)
1545 ulParent = idSCSIController;
1546 else if (lControllerIndex == lSATAControllerIndex)
1547 ulParent = idSATAController;
1548 }
1549 if (pos2 != Utf8Str::npos)
1550 RTStrToInt32Ex(desc.strExtraConfigCurrent.c_str() + pos2 + 8, NULL, 0, &lAddressOnParent);
1551
1552 LogFlowFunc(("HardDiskImage details: pos1=%d, pos2=%d, lControllerIndex=%d, lIDEPrimaryControllerIndex=%d, lIDESecondaryControllerIndex=%d, ulParent=%d, lAddressOnParent=%d\n",
1553 pos1, pos2, lControllerIndex, lIDEPrimaryControllerIndex, lIDESecondaryControllerIndex,
1554 ulParent, lAddressOnParent));
1555
1556 if ( !ulParent
1557 || lAddressOnParent == -1
1558 )
1559 throw setError(VBOX_E_NOT_SUPPORTED,
1560 tr("Missing or bad extra config string in hard disk image: \"%s\""),
1561 desc.strExtraConfigCurrent.c_str());
1562
1563 stack.mapDisks[strDiskID] = &desc;
1564
1565 //use the list stack.mapDiskSequence where the disks go as the "VirtualSystem" should be placed
1566 //in the OVF description file.
1567 stack.mapDiskSequence.push_back(strDiskID);
1568 stack.mapDiskSequenceForOneVM.push_back(strDiskID);
1569 }
1570 break;
1571
1572 case VirtualSystemDescriptionType_Floppy:
1573 if (uLoop == 1)
1574 {
1575 strDescription = "Floppy Drive";
1576 strCaption = "floppy0"; // this is what OVFTool writes
1577 type = ovf::ResourceType_FloppyDrive; // 14
1578 lAutomaticAllocation = 0;
1579 lAddressOnParent = 0; // this is what OVFTool writes
1580 }
1581 break;
1582
1583 case VirtualSystemDescriptionType_CDROM:
1584 /* <Item>
1585 <rasd:Caption>cdrom1</rasd:Caption>
1586 <rasd:InstanceId>8</rasd:InstanceId>
1587 <rasd:ResourceType>15</rasd:ResourceType>
1588 <rasd:HostResource>/disk/cdrom1</rasd:HostResource>
1589 <rasd:Parent>4</rasd:Parent>
1590 <rasd:AddressOnParent>0</rasd:AddressOnParent>
1591 </Item> */
1592 if (uLoop == 2)
1593 {
1594 uint32_t cDisks = (uint32_t)stack.mapDisks.size();
1595 Utf8Str strDiskID = Utf8StrFmt("iso%RI32", ++cDisks);
1596 ++cDVDs;
1597 strDescription = "CD-ROM Drive";
1598 strCaption = Utf8StrFmt("cdrom%RI32", cDVDs); // OVFTool starts with 1
1599 type = ovf::ResourceType_CDDrive; // 15
1600 lAutomaticAllocation = 1;
1601
1602 //skip empty Medium. There are no information to add into section <References> or <DiskSection>
1603 if (desc.strVBoxCurrent.isNotEmpty() &&
1604 desc.skipIt == false)
1605 {
1606 // the following references the "<Disks>" XML block
1607 strHostResource = Utf8StrFmt("/disk/%s", strDiskID.c_str());
1608 }
1609
1610 // controller=<index>;channel=<c>
1611 size_t pos1 = desc.strExtraConfigCurrent.find("controller=");
1612 size_t pos2 = desc.strExtraConfigCurrent.find("channel=");
1613 int32_t lControllerIndex = -1;
1614 if (pos1 != Utf8Str::npos)
1615 {
1616 RTStrToInt32Ex(desc.strExtraConfigCurrent.c_str() + pos1 + 11, NULL, 0, &lControllerIndex);
1617 if (lControllerIndex == lIDEPrimaryControllerIndex)
1618 ulParent = idIDEPrimaryController;
1619 else if (lControllerIndex == lIDESecondaryControllerIndex)
1620 ulParent = idIDESecondaryController;
1621 else if (lControllerIndex == lSCSIControllerIndex)
1622 ulParent = idSCSIController;
1623 else if (lControllerIndex == lSATAControllerIndex)
1624 ulParent = idSATAController;
1625 }
1626 if (pos2 != Utf8Str::npos)
1627 RTStrToInt32Ex(desc.strExtraConfigCurrent.c_str() + pos2 + 8, NULL, 0, &lAddressOnParent);
1628
1629 LogFlowFunc(("DVD drive details: pos1=%d, pos2=%d, lControllerIndex=%d, lIDEPrimaryControllerIndex=%d, lIDESecondaryControllerIndex=%d, ulParent=%d, lAddressOnParent=%d\n",
1630 pos1, pos2, lControllerIndex, lIDEPrimaryControllerIndex,
1631 lIDESecondaryControllerIndex, ulParent, lAddressOnParent));
1632
1633 if ( !ulParent
1634 || lAddressOnParent == -1
1635 )
1636 throw setError(VBOX_E_NOT_SUPPORTED,
1637 tr("Missing or bad extra config string in DVD drive medium: \"%s\""),
1638 desc.strExtraConfigCurrent.c_str());
1639
1640 stack.mapDisks[strDiskID] = &desc;
1641
1642 //use the list stack.mapDiskSequence where the disks go as the "VirtualSystem" should be placed
1643 //in the OVF description file.
1644 stack.mapDiskSequence.push_back(strDiskID);
1645 stack.mapDiskSequenceForOneVM.push_back(strDiskID);
1646 // there is no DVD drive map to update because it is
1647 // handled completely with this entry.
1648 }
1649 break;
1650
1651 case VirtualSystemDescriptionType_NetworkAdapter:
1652 /* <Item>
1653 <rasd:AutomaticAllocation>true</rasd:AutomaticAllocation>
1654 <rasd:Caption>Ethernet adapter on 'VM Network'</rasd:Caption>
1655 <rasd:Connection>VM Network</rasd:Connection>
1656 <rasd:ElementName>VM network</rasd:ElementName>
1657 <rasd:InstanceID>3</rasd:InstanceID>
1658 <rasd:ResourceType>10</rasd:ResourceType>
1659 </Item> */
1660 if (uLoop == 2)
1661 {
1662 lAutomaticAllocation = 1;
1663 strCaption = Utf8StrFmt("Ethernet adapter on '%s'", desc.strOvf.c_str());
1664 type = ovf::ResourceType_EthernetAdapter; // 10
1665 /* Set the hardware type to something useful.
1666 * To be compatible with vmware & others we set
1667 * PCNet32 for our PCNet types & E1000 for the
1668 * E1000 cards. */
1669 switch (desc.strVBoxCurrent.toInt32())
1670 {
1671 case NetworkAdapterType_Am79C970A:
1672 case NetworkAdapterType_Am79C973: strResourceSubType = "PCNet32"; break;
1673#ifdef VBOX_WITH_E1000
1674 case NetworkAdapterType_I82540EM:
1675 case NetworkAdapterType_I82545EM:
1676 case NetworkAdapterType_I82543GC: strResourceSubType = "E1000"; break;
1677#endif /* VBOX_WITH_E1000 */
1678 }
1679 strConnection = desc.strOvf;
1680
1681 stack.mapNetworks[desc.strOvf] = true;
1682 }
1683 break;
1684
1685 case VirtualSystemDescriptionType_USBController:
1686 /* <Item ovf:required="false">
1687 <rasd:Caption>usb</rasd:Caption>
1688 <rasd:Description>USB Controller</rasd:Description>
1689 <rasd:InstanceId>3</rasd:InstanceId>
1690 <rasd:ResourceType>23</rasd:ResourceType>
1691 <rasd:Address>0</rasd:Address>
1692 <rasd:BusNumber>0</rasd:BusNumber>
1693 </Item> */
1694 if (uLoop == 1)
1695 {
1696 strDescription = "USB Controller";
1697 strCaption = "usb";
1698 type = ovf::ResourceType_USBController; // 23
1699 lAddress = 0; // this is what OVFTool writes
1700 lBusNumber = 0; // this is what OVFTool writes
1701 }
1702 break;
1703
1704 case VirtualSystemDescriptionType_SoundCard:
1705 /* <Item ovf:required="false">
1706 <rasd:Caption>sound</rasd:Caption>
1707 <rasd:Description>Sound Card</rasd:Description>
1708 <rasd:InstanceId>10</rasd:InstanceId>
1709 <rasd:ResourceType>35</rasd:ResourceType>
1710 <rasd:ResourceSubType>ensoniq1371</rasd:ResourceSubType>
1711 <rasd:AutomaticAllocation>false</rasd:AutomaticAllocation>
1712 <rasd:AddressOnParent>3</rasd:AddressOnParent>
1713 </Item> */
1714 if (uLoop == 1)
1715 {
1716 strDescription = "Sound Card";
1717 strCaption = "sound";
1718 type = ovf::ResourceType_SoundCard; // 35
1719 strResourceSubType = desc.strOvf; // e.g. ensoniq1371
1720 lAutomaticAllocation = 0;
1721 lAddressOnParent = 3; // what gives? this is what OVFTool writes
1722 }
1723 break;
1724
1725 default: break; /* Shut up MSC. */
1726 }
1727
1728 if (type)
1729 {
1730 xml::ElementNode *pItem;
1731 xml::ElementNode *pItemHelper;
1732 RTCString itemElement;
1733 RTCString itemElementHelper;
1734
1735 if (enFormat == ovf::OVFVersion_2_0)
1736 {
1737 if(uLoop == 2)
1738 {
1739 if (desc.type == VirtualSystemDescriptionType_NetworkAdapter)
1740 {
1741 itemElement = "epasd:";
1742 pItem = pelmVirtualHardwareSection->createChild("EthernetPortItem");
1743 }
1744 else if (desc.type == VirtualSystemDescriptionType_CDROM ||
1745 desc.type == VirtualSystemDescriptionType_HardDiskImage)
1746 {
1747 itemElement = "sasd:";
1748 pItem = pelmVirtualHardwareSection->createChild("StorageItem");
1749 }
1750 else
1751 pItem = NULL;
1752 }
1753 else
1754 {
1755 itemElement = "rasd:";
1756 pItem = pelmVirtualHardwareSection->createChild("Item");
1757 }
1758 }
1759 else
1760 {
1761 itemElement = "rasd:";
1762 pItem = pelmVirtualHardwareSection->createChild("Item");
1763 }
1764
1765 // NOTE: DO NOT CHANGE THE ORDER of these items! The OVF standards prescribes that
1766 // the elements from the rasd: namespace must be sorted by letter, and VMware
1767 // actually requires this as well (see public bug #6612)
1768
1769 if (lAddress != -1)
1770 {
1771 //pItem->createChild("rasd:Address")->addContent(Utf8StrFmt("%d", lAddress));
1772 itemElementHelper = itemElement;
1773 pItemHelper = pItem->createChild(itemElementHelper.append("Address").c_str());
1774 pItemHelper->addContent(Utf8StrFmt("%d", lAddress));
1775 }
1776
1777 if (lAddressOnParent != -1)
1778 {
1779 //pItem->createChild("rasd:AddressOnParent")->addContent(Utf8StrFmt("%d", lAddressOnParent));
1780 itemElementHelper = itemElement;
1781 pItemHelper = pItem->createChild(itemElementHelper.append("AddressOnParent").c_str());
1782 pItemHelper->addContent(Utf8StrFmt("%d", lAddressOnParent));
1783 }
1784
1785 if (!strAllocationUnits.isEmpty())
1786 {
1787 //pItem->createChild("rasd:AllocationUnits")->addContent(strAllocationUnits);
1788 itemElementHelper = itemElement;
1789 pItemHelper = pItem->createChild(itemElementHelper.append("AllocationUnits").c_str());
1790 pItemHelper->addContent(strAllocationUnits);
1791 }
1792
1793 if (lAutomaticAllocation != -1)
1794 {
1795 //pItem->createChild("rasd:AutomaticAllocation")->addContent( (lAutomaticAllocation) ? "true" : "false" );
1796 itemElementHelper = itemElement;
1797 pItemHelper = pItem->createChild(itemElementHelper.append("AutomaticAllocation").c_str());
1798 pItemHelper->addContent((lAutomaticAllocation) ? "true" : "false" );
1799 }
1800
1801 if (lBusNumber != -1)
1802 {
1803 if (enFormat == ovf::OVFVersion_0_9)
1804 {
1805 // BusNumber is invalid OVF 1.0 so only write it in 0.9 mode for OVFTool
1806 //pItem->createChild("rasd:BusNumber")->addContent(Utf8StrFmt("%d", lBusNumber));
1807 itemElementHelper = itemElement;
1808 pItemHelper = pItem->createChild(itemElementHelper.append("BusNumber").c_str());
1809 pItemHelper->addContent(Utf8StrFmt("%d", lBusNumber));
1810 }
1811 }
1812
1813 if (!strCaption.isEmpty())
1814 {
1815 //pItem->createChild("rasd:Caption")->addContent(strCaption);
1816 itemElementHelper = itemElement;
1817 pItemHelper = pItem->createChild(itemElementHelper.append("Caption").c_str());
1818 pItemHelper->addContent(strCaption);
1819 }
1820
1821 if (!strConnection.isEmpty())
1822 {
1823 //pItem->createChild("rasd:Connection")->addContent(strConnection);
1824 itemElementHelper = itemElement;
1825 pItemHelper = pItem->createChild(itemElementHelper.append("Connection").c_str());
1826 pItemHelper->addContent(strConnection);
1827 }
1828
1829 if (!strDescription.isEmpty())
1830 {
1831 //pItem->createChild("rasd:Description")->addContent(strDescription);
1832 itemElementHelper = itemElement;
1833 pItemHelper = pItem->createChild(itemElementHelper.append("Description").c_str());
1834 pItemHelper->addContent(strDescription);
1835 }
1836
1837 if (!strCaption.isEmpty())
1838 {
1839 if (enFormat == ovf::OVFVersion_1_0)
1840 {
1841 //pItem->createChild("rasd:ElementName")->addContent(strCaption);
1842 itemElementHelper = itemElement;
1843 pItemHelper = pItem->createChild(itemElementHelper.append("ElementName").c_str());
1844 pItemHelper->addContent(strCaption);
1845 }
1846 }
1847
1848 if (!strHostResource.isEmpty())
1849 {
1850 //pItem->createChild("rasd:HostResource")->addContent(strHostResource);
1851 itemElementHelper = itemElement;
1852 pItemHelper = pItem->createChild(itemElementHelper.append("HostResource").c_str());
1853 pItemHelper->addContent(strHostResource);
1854 }
1855
1856 {
1857 // <rasd:InstanceID>1</rasd:InstanceID>
1858 itemElementHelper = itemElement;
1859 if (enFormat == ovf::OVFVersion_0_9)
1860 //pelmInstanceID = pItem->createChild("rasd:InstanceId");
1861 pItemHelper = pItem->createChild(itemElementHelper.append("InstanceId").c_str());
1862 else
1863 //pelmInstanceID = pItem->createChild("rasd:InstanceID"); // capitalization changed...
1864 pItemHelper = pItem->createChild(itemElementHelper.append("InstanceID").c_str());
1865
1866 pItemHelper->addContent(Utf8StrFmt("%d", ulInstanceID++));
1867 }
1868
1869 if (ulParent)
1870 {
1871 //pItem->createChild("rasd:Parent")->addContent(Utf8StrFmt("%d", ulParent));
1872 itemElementHelper = itemElement;
1873 pItemHelper = pItem->createChild(itemElementHelper.append("Parent").c_str());
1874 pItemHelper->addContent(Utf8StrFmt("%d", ulParent));
1875 }
1876
1877 if (!strResourceSubType.isEmpty())
1878 {
1879 //pItem->createChild("rasd:ResourceSubType")->addContent(strResourceSubType);
1880 itemElementHelper = itemElement;
1881 pItemHelper = pItem->createChild(itemElementHelper.append("ResourceSubType").c_str());
1882 pItemHelper->addContent(strResourceSubType);
1883 }
1884
1885 {
1886 // <rasd:ResourceType>3</rasd:ResourceType>
1887 //pItem->createChild("rasd:ResourceType")->addContent(Utf8StrFmt("%d", type));
1888 itemElementHelper = itemElement;
1889 pItemHelper = pItem->createChild(itemElementHelper.append("ResourceType").c_str());
1890 pItemHelper->addContent(Utf8StrFmt("%d", type));
1891 }
1892
1893 // <rasd:VirtualQuantity>1</rasd:VirtualQuantity>
1894 if (lVirtualQuantity != -1)
1895 {
1896 //pItem->createChild("rasd:VirtualQuantity")->addContent(Utf8StrFmt("%d", lVirtualQuantity));
1897 itemElementHelper = itemElement;
1898 pItemHelper = pItem->createChild(itemElementHelper.append("VirtualQuantity").c_str());
1899 pItemHelper->addContent(Utf8StrFmt("%d", lVirtualQuantity));
1900 }
1901 }
1902 }
1903 } // for (size_t uLoop = 1; uLoop <= 2; ++uLoop)
1904
1905 // now that we're done with the official OVF <Item> tags under <VirtualSystem>, write out VirtualBox XML
1906 // under the vbox: namespace
1907 xml::ElementNode *pelmVBoxMachine = pelmVirtualSystem->createChild("vbox:Machine");
1908 // ovf:required="false" tells other OVF parsers that they can ignore this thing
1909 pelmVBoxMachine->setAttribute("ovf:required", "false");
1910 // ovf:Info element is required or VMware will bail out on the vbox:Machine element
1911 pelmVBoxMachine->createChild("ovf:Info")->addContent("Complete VirtualBox machine configuration in VirtualBox format");
1912
1913 // create an empty machine config
1914 // use the same settings version as the current VM settings file
1915 settings::MachineConfigFile *pConfig = new settings::MachineConfigFile(&vsdescThis->m->pMachine->i_getSettingsFileFull());
1916
1917 writeLock.release();
1918 try
1919 {
1920 AutoWriteLock machineLock(vsdescThis->m->pMachine COMMA_LOCKVAL_SRC_POS);
1921 // fill the machine config
1922 vsdescThis->m->pMachine->i_copyMachineDataToSettings(*pConfig);
1923
1924 // Apply export tweaks to machine settings
1925 bool fStripAllMACs = m->optListExport.contains(ExportOptions_StripAllMACs);
1926 bool fStripAllNonNATMACs = m->optListExport.contains(ExportOptions_StripAllNonNATMACs);
1927 if (fStripAllMACs || fStripAllNonNATMACs)
1928 {
1929 for (settings::NetworkAdaptersList::iterator
1930 it = pConfig->hardwareMachine.llNetworkAdapters.begin();
1931 it != pConfig->hardwareMachine.llNetworkAdapters.end();
1932 ++it)
1933 {
1934 settings::NetworkAdapter &nic = *it;
1935 if (fStripAllMACs || (fStripAllNonNATMACs && nic.mode != NetworkAttachmentType_NAT))
1936 nic.strMACAddress.setNull();
1937 }
1938 }
1939
1940 // write the machine config to the vbox:Machine element
1941 pConfig->buildMachineXML(*pelmVBoxMachine,
1942 settings::MachineConfigFile::BuildMachineXML_WriteVBoxVersionAttribute
1943 /*| settings::MachineConfigFile::BuildMachineXML_SkipRemovableMedia*/
1944 | settings::MachineConfigFile::BuildMachineXML_SuppressSavedState,
1945 // but not BuildMachineXML_IncludeSnapshots nor BuildMachineXML_MediaRegistry
1946 pllElementsWithUuidAttributes);
1947 delete pConfig;
1948 }
1949 catch (...)
1950 {
1951 writeLock.acquire();
1952 delete pConfig;
1953 throw;
1954 }
1955 writeLock.acquire();
1956}
1957
1958/**
1959 * Actual worker code for writing out OVF/OVA to disk. This is called from Appliance::taskThreadWriteOVF()
1960 * and therefore runs on the OVF/OVA write worker thread.
1961 *
1962 * This runs in one context:
1963 *
1964 * 1) in a first worker thread; in that case, Appliance::Write() called Appliance::i_writeImpl();
1965 *
1966 * @param pTask
1967 * @return
1968 */
1969HRESULT Appliance::i_writeFS(TaskOVF *pTask)
1970{
1971 LogFlowFuncEnter();
1972 LogFlowFunc(("ENTER appliance %p\n", this));
1973
1974 AutoCaller autoCaller(this);
1975 if (FAILED(autoCaller.rc())) return autoCaller.rc();
1976
1977 HRESULT rc = S_OK;
1978
1979 // Lock the media tree early to make sure nobody else tries to make changes
1980 // to the tree. Also lock the IAppliance object for writing.
1981 AutoMultiWriteLock2 multiLock(&mVirtualBox->i_getMediaTreeLockHandle(), this->lockHandle() COMMA_LOCKVAL_SRC_POS);
1982 // Additional protect the IAppliance object, cause we leave the lock
1983 // when starting the disk export and we don't won't block other
1984 // callers on this lengthy operations.
1985 m->state = Data::ApplianceExporting;
1986
1987 if (pTask->enFormat == ovf::OVFVersion_unknown)
1988#ifdef VBOX_WITH_NEW_TAR_CREATOR
1989 rc = i_writeFSOPC(pTask, multiLock);
1990#else
1991 rc = E_NOTIMPL;
1992#endif
1993 else if (pTask->locInfo.strPath.endsWith(".ovf", Utf8Str::CaseInsensitive))
1994 rc = i_writeFSOVF(pTask, multiLock);
1995 else
1996 rc = i_writeFSOVA(pTask, multiLock);
1997
1998 // reset the state so others can call methods again
1999 m->state = Data::ApplianceIdle;
2000
2001 LogFlowFunc(("rc=%Rhrc\n", rc));
2002 LogFlowFuncLeave();
2003 return rc;
2004}
2005
2006HRESULT Appliance::i_writeFSOVF(TaskOVF *pTask, AutoWriteLockBase& writeLock)
2007{
2008 LogFlowFuncEnter();
2009
2010#ifdef VBOX_WITH_NEW_TAR_CREATOR
2011 /*
2012 * Create write-to-dir file system stream for the target directory.
2013 * This unifies the disk access with the TAR based OVA variant.
2014 */
2015 HRESULT hrc;
2016 int vrc;
2017 RTVFSFSSTREAM hVfsFss2Dir = NIL_RTVFSFSSTREAM;
2018 try
2019 {
2020 Utf8Str strTargetDir(pTask->locInfo.strPath);
2021 strTargetDir.stripFilename();
2022 vrc = RTVfsFsStrmToNormalDir(strTargetDir.c_str(), 0 /*fFlags*/, &hVfsFss2Dir);
2023 if (RT_SUCCESS(vrc))
2024 hrc = S_OK;
2025 else
2026 hrc = setErrorVrc(vrc, tr("Failed to open directory '%s' (%Rrc)"), strTargetDir.c_str(), vrc);
2027 }
2028 catch (std::bad_alloc)
2029 {
2030 hrc = E_OUTOFMEMORY;
2031 }
2032 if (SUCCEEDED(hrc))
2033 {
2034 /*
2035 * Join i_writeFSOVA. On failure, delete (undo) anything we might
2036 * have written to the disk before failing.
2037 */
2038 hrc = i_writeFSImpl(pTask, writeLock, hVfsFss2Dir);
2039 if (FAILED(hrc))
2040 RTVfsFsStrmToDirUndo(hVfsFss2Dir);
2041 RTVfsFsStrmRelease(hVfsFss2Dir);
2042 }
2043
2044 LogFlowFuncLeave();
2045 return hrc;
2046
2047#else /* VBOX_WITH_NEW_TAR_CREATOR */
2048 HRESULT rc = S_OK;
2049
2050 PVDINTERFACEIO pShaIo = 0;
2051 PVDINTERFACEIO pFileIo = 0;
2052 do
2053 {
2054 pShaIo = ShaCreateInterface();
2055 if (!pShaIo)
2056 {
2057 rc = E_OUTOFMEMORY;
2058 break;
2059 }
2060 pFileIo = FileCreateInterface();
2061 if (!pFileIo)
2062 {
2063 rc = E_OUTOFMEMORY;
2064 break;
2065 }
2066
2067 SHASTORAGE storage;
2068 RT_ZERO(storage);
2069 storage.fCreateDigest = m->fManifest;
2070 storage.fSha256 = m->fSha256;
2071
2072
2073 Utf8Str name = i_applianceIOName(applianceIOFile);
2074
2075 int vrc = VDInterfaceAdd(&pFileIo->Core, name.c_str(),
2076 VDINTERFACETYPE_IO, 0, sizeof(VDINTERFACEIO),
2077 &storage.pVDImageIfaces);
2078 if (RT_FAILURE(vrc))
2079 {
2080 rc = E_FAIL;
2081 break;
2082 }
2083 rc = i_writeFSImpl(pTask, writeLock, pShaIo, &storage);
2084 } while (0);
2085
2086 /* Cleanup */
2087 if (pShaIo)
2088 RTMemFree(pShaIo);
2089 if (pFileIo)
2090 RTMemFree(pFileIo);
2091
2092 LogFlowFuncLeave();
2093 return rc;
2094#endif
2095}
2096
2097HRESULT Appliance::i_writeFSOVA(TaskOVF *pTask, AutoWriteLockBase &writeLock)
2098{
2099 LogFlowFuncEnter();
2100
2101#ifdef VBOX_WITH_NEW_TAR_CREATOR
2102 /*
2103 * Open the output file and attach a TAR creator to it.
2104 */
2105 HRESULT hrc;
2106 RTVFSIOSTREAM hVfsIosTar;
2107 int vrc = RTVfsIoStrmOpenNormal(pTask->locInfo.strPath.c_str(),
2108 RTFILE_O_CREATE | RTFILE_O_WRITE | RTFILE_O_DENY_WRITE,
2109 &hVfsIosTar);
2110 if (RT_SUCCESS(vrc))
2111 {
2112 /** @todo which format does the standard dictate here actually?
2113 * GNU or USTAR/POSIX? */
2114 RTVFSFSSTREAM hVfsFssTar;
2115 vrc = RTZipTarFsStreamToIoStream(hVfsIosTar, RTZIPTARFORMAT_GNU, 0 /*fFlags*/, &hVfsFssTar);
2116 RTVfsIoStrmRelease(hVfsIosTar);
2117 if (RT_SUCCESS(vrc))
2118 {
2119 hrc = i_writeFSImpl(pTask, writeLock, hVfsFssTar);
2120 RTVfsFsStrmRelease(hVfsFssTar);
2121 }
2122 else
2123 hrc = setErrorVrc(vrc, tr("Failed create TAR creator for '%s' (%Rrc)"), pTask->locInfo.strPath.c_str(), vrc);
2124
2125 /* Delete the OVA on failure. */
2126 if (FAILED(hrc))
2127 RTFileDelete(pTask->locInfo.strPath.c_str());
2128 }
2129 else
2130 hrc = setErrorVrc(vrc, tr("Failed to open '%s' for writing (%Rrc)"), pTask->locInfo.strPath.c_str(), vrc);
2131
2132 LogFlowFuncLeave();
2133 return hrc;
2134
2135#else /* VBOX_WITH_NEW_TAR_CREATOR */
2136
2137 RTTAR tar;
2138 int vrc = RTTarOpen(&tar, pTask->locInfo.strPath.c_str(), RTFILE_O_CREATE | RTFILE_O_WRITE | RTFILE_O_DENY_ALL);
2139 if (RT_FAILURE(vrc))
2140 return setError(VBOX_E_FILE_ERROR,
2141 tr("Could not create OVA file '%s' (%Rrc)"),
2142 pTask->locInfo.strPath.c_str(), vrc);
2143
2144 HRESULT rc = S_OK;
2145
2146 PVDINTERFACEIO pShaIo = 0;
2147 PVDINTERFACEIO pTarIo = 0;
2148 do
2149 {
2150 pShaIo = ShaCreateInterface();
2151 if (!pShaIo)
2152 {
2153 rc = E_OUTOFMEMORY;
2154 break;
2155 }
2156 pTarIo = tarWriterCreateInterface();
2157 if (!pTarIo)
2158 {
2159 rc = E_OUTOFMEMORY;
2160 break;
2161 }
2162 SHASTORAGE storage;
2163 RT_ZERO(storage);
2164 storage.fCreateDigest = m->fManifest;
2165 storage.fSha256 = m->fSha256;
2166
2167 Utf8Str name = i_applianceIOName(applianceIOTar);
2168
2169 vrc = VDInterfaceAdd(&pTarIo->Core, name.c_str(),
2170 VDINTERFACETYPE_IO, tar, sizeof(VDINTERFACEIO),
2171 &storage.pVDImageIfaces);
2172
2173 if (RT_FAILURE(vrc))
2174 {
2175 rc = E_FAIL;
2176 break;
2177 }
2178 rc = i_writeFSImpl(pTask, writeLock, pShaIo, &storage);
2179 } while (0);
2180
2181 RTTarClose(tar);
2182
2183 /* Cleanup */
2184 if (pShaIo)
2185 RTMemFree(pShaIo);
2186 if (pTarIo)
2187 RTMemFree(pTarIo);
2188
2189 /* Delete ova file on error */
2190 if (FAILED(rc))
2191 RTFileDelete(pTask->locInfo.strPath.c_str());
2192
2193 LogFlowFuncLeave();
2194 return rc;
2195#endif
2196}
2197
2198#ifdef VBOX_WITH_NEW_TAR_CREATOR
2199/**
2200 * Writes the Oracle Public Cloud appliance.
2201 *
2202 * It expect raw disk images inside a gzipped tarball. We enable sparse files
2203 * to save diskspace on the target host system.
2204 */
2205HRESULT Appliance::i_writeFSOPC(TaskOVF *pTask, AutoWriteLockBase &writeLock)
2206{
2207 LogFlowFuncEnter();
2208
2209 /*
2210 * Open the output file, pipe it thru gzip and attach a TAR creator.
2211 */
2212 HRESULT hrc;
2213 RTVFSIOSTREAM hVfsIosFile;
2214 int vrc = RTVfsIoStrmOpenNormal(pTask->locInfo.strPath.c_str(),
2215 RTFILE_O_CREATE | RTFILE_O_WRITE | RTFILE_O_DENY_WRITE,
2216 &hVfsIosFile);
2217 if (RT_SUCCESS(vrc))
2218 {
2219
2220 RTVFSIOSTREAM hVfsIosGzip;
2221 vrc = RTZipGzipCompressIoStream(hVfsIosFile, 0 /*fFlags*/, 6 /*uLevel*/, &hVfsIosGzip);
2222 RTVfsIoStrmRelease(hVfsIosFile);
2223 if (RT_SUCCESS(vrc))
2224 {
2225
2226 RTVFSFSSTREAM hVfsFssTar;
2227 vrc = RTZipTarFsStreamToIoStream(hVfsIosGzip, RTZIPTARFORMAT_GNU, RTZIPTAR_C_SPARSE, &hVfsFssTar);
2228 RTVfsIoStrmRelease(hVfsIosGzip);
2229 if (RT_SUCCESS(vrc))
2230 {
2231 /*
2232 * Before we do the actual writing, disable OVF and manifest creation.
2233 */
2234 bool fManifestSaved = m->fManifest;
2235 m->fManifest = false;
2236
2237 hrc = i_writeFSImpl(pTask, writeLock, hVfsFssTar, false /*fOvfFile*/, false /*fStreamOptimizedVmdk*/);
2238 RTVfsFsStrmRelease(hVfsFssTar);
2239
2240 m->fManifest = fManifestSaved;
2241 }
2242 else
2243 hrc = setErrorVrc(vrc, tr("Failed create TAR creator for '%s' (%Rrc)"), pTask->locInfo.strPath.c_str(), vrc);
2244 }
2245 else
2246 hrc = setErrorVrc(vrc, tr("Failed create gzipper for '%s' (%Rrc)"), pTask->locInfo.strPath.c_str(), vrc);
2247
2248 /* Delete the OVA on failure. */
2249 if (FAILED(hrc))
2250 RTFileDelete(pTask->locInfo.strPath.c_str());
2251 }
2252 else
2253 hrc = setErrorVrc(vrc, tr("Failed to open '%s' for writing (%Rrc)"), pTask->locInfo.strPath.c_str(), vrc);
2254
2255 LogFlowFuncLeave();
2256 return hrc;
2257
2258}
2259#endif
2260
2261#ifdef VBOX_WITH_NEW_TAR_CREATOR
2262HRESULT Appliance::i_writeFSImpl(TaskOVF *pTask, AutoWriteLockBase &writeLock, RTVFSFSSTREAM hVfsFssDst,
2263 bool fOvfFile /*= true*/, bool fStreamOptimizedVmdk /*= true*/)
2264#else
2265HRESULT Appliance::i_writeFSImpl(TaskOVF *pTask, AutoWriteLockBase& writeLock, PVDINTERFACEIO pIfIo, PSHASTORAGE pStorage)
2266#endif
2267{
2268 LogFlowFuncEnter();
2269
2270 HRESULT rc = S_OK;
2271#ifdef VBOX_WITH_NEW_TAR_CREATOR
2272 RTMANIFEST hManifest;
2273 int vrc = RTManifestCreate(0 /*fFlags*/, &hManifest);
2274
2275#else
2276 int vrc;
2277 list<STRPAIR> fileList;
2278#endif
2279 try
2280 {
2281 // the XML stack contains two maps for disks and networks, which allows us to
2282 // a) have a list of unique disk names (to make sure the same disk name is only added once)
2283 // and b) keep a list of all networks
2284 XMLStack stack;
2285 // Scope this to free the memory as soon as this is finished
2286 {
2287 /* Construct the OVF name. */
2288 Utf8Str strOvfFile(pTask->locInfo.strPath);
2289#ifdef VBOX_WITH_NEW_TAR_CREATOR
2290 strOvfFile.stripPath().stripSuffix().append(".ovf");
2291#else
2292 strOvfFile.stripSuffix().append(".ovf");
2293#endif
2294
2295 /* Render a valid ovf document into a memory buffer. The unknown
2296 version upgrade relates to the OPC hack up in Appliance::write(). */
2297 xml::Document doc;
2298 i_buildXML(writeLock, doc, stack, pTask->locInfo.strPath,
2299 pTask->enFormat != ovf::OVFVersion_unknown ? pTask->enFormat : ovf::OVFVersion_2_0);
2300
2301#ifdef VBOX_WITH_NEW_TAR_CREATOR
2302 if (fOvfFile)
2303#endif
2304 {
2305 void *pvBuf = NULL;
2306 size_t cbSize = 0;
2307 xml::XmlMemWriter writer;
2308 writer.write(doc, &pvBuf, &cbSize);
2309 if (RT_UNLIKELY(!pvBuf))
2310 throw setError(VBOX_E_FILE_ERROR, tr("Could not create OVF file '%s'"), strOvfFile.c_str());
2311
2312 /* Write the ovf file to "disk". */
2313#ifdef VBOX_WITH_NEW_TAR_CREATOR
2314 rc = i_writeBufferToFile(hVfsFssDst, strOvfFile.c_str(), pvBuf, cbSize);
2315 if (FAILED(rc))
2316 throw rc;
2317#else
2318 vrc = writeBufferToFile(strOvfFile.c_str(), pvBuf, cbSize, pIfIo, pStorage);
2319 if (RT_FAILURE(vrc))
2320 throw setErrorVrc(vrc, tr("Could not create OVF file '%s' (%Rrc)"), strOvfFile.c_str(), vrc);
2321#endif
2322
2323#ifndef VBOX_WITH_NEW_TAR_CREATOR
2324 fileList.push_back(STRPAIR(strOvfFile, pStorage->strDigest));
2325#endif
2326 }
2327 }
2328
2329 // We need a proper format description
2330 ComObjPtr<MediumFormat> formatTemp;
2331
2332 ComObjPtr<MediumFormat> format;
2333 // Scope for the AutoReadLock
2334 {
2335 SystemProperties *pSysProps = mVirtualBox->i_getSystemProperties();
2336 AutoReadLock propsLock(pSysProps COMMA_LOCKVAL_SRC_POS);
2337 // We are always exporting to VMDK stream optimized for now
2338 formatTemp = pSysProps->i_mediumFormatFromExtension("iso");
2339
2340 format = pSysProps->i_mediumFormat("VMDK");
2341 if (format.isNull())
2342 throw setError(VBOX_E_NOT_SUPPORTED,
2343 tr("Invalid medium storage format"));
2344 }
2345
2346 // Finally, write out the disks!
2347 //use the list stack.mapDiskSequence where the disks were put as the "VirtualSystem"s had been placed
2348 //in the OVF description file. I.e. we have one "VirtualSystem" in the OVF file, we extract all disks
2349 //attached to it. And these disks are stored in the stack.mapDiskSequence. Next we shift to the next
2350 //"VirtualSystem" and repeat the operation.
2351 //And here we go through the list and extract all disks in the same sequence
2352 for (list<Utf8Str>::const_iterator
2353 it = stack.mapDiskSequence.begin();
2354 it != stack.mapDiskSequence.end();
2355 ++it)
2356 {
2357 const Utf8Str &strDiskID = *it;
2358 const VirtualSystemDescriptionEntry *pDiskEntry = stack.mapDisks[strDiskID];
2359
2360 // source path: where the VBox image is
2361 const Utf8Str &strSrcFilePath = pDiskEntry->strVBoxCurrent;
2362
2363 //skip empty Medium. In common, It's may be empty CD/DVD
2364 if (strSrcFilePath.isEmpty() ||
2365 pDiskEntry->skipIt == true)
2366 continue;
2367
2368 // Do NOT check here whether the file exists. findHardDisk will
2369 // figure that out, and filesystem-based tests are simply wrong
2370 // in the general case (think of iSCSI).
2371
2372 // clone the disk:
2373 ComObjPtr<Medium> pSourceDisk;
2374
2375 Log(("Finding source disk \"%s\"\n", strSrcFilePath.c_str()));
2376
2377 if (pDiskEntry->type == VirtualSystemDescriptionType_HardDiskImage)
2378 {
2379 rc = mVirtualBox->i_findHardDiskByLocation(strSrcFilePath, true, &pSourceDisk);
2380 if (FAILED(rc)) throw rc;
2381 }
2382 else//may be CD or DVD
2383 {
2384 rc = mVirtualBox->i_findDVDOrFloppyImage(DeviceType_DVD,
2385 NULL,
2386 strSrcFilePath,
2387 true,
2388 &pSourceDisk);
2389 if (FAILED(rc)) throw rc;
2390 }
2391
2392 Bstr uuidSource;
2393 rc = pSourceDisk->COMGETTER(Id)(uuidSource.asOutParam());
2394 if (FAILED(rc)) throw rc;
2395 Guid guidSource(uuidSource);
2396
2397 // output filename
2398 const Utf8Str &strTargetFileNameOnly = pDiskEntry->strOvf;
2399 // target path needs to be composed from where the output OVF is
2400#ifdef VBOX_WITH_NEW_TAR_CREATOR
2401 const Utf8Str &strTargetFilePath = strTargetFileNameOnly;
2402#else
2403 Utf8Str strTargetFilePath(pTask->locInfo.strPath);
2404 strTargetFilePath.stripFilename()
2405 .append("/")
2406 .append(strTargetFileNameOnly);
2407#endif
2408
2409 // The exporting requests a lock on the media tree. So leave our lock temporary.
2410 writeLock.release();
2411 try
2412 {
2413 // advance to the next operation
2414 pTask->pProgress->SetNextOperation(BstrFmt(tr("Exporting to disk image '%s'"),
2415 RTPathFilename(strTargetFilePath.c_str())).raw(),
2416 pDiskEntry->ulSizeMB); // operation's weight, as set up
2417 // with the IProgress originally
2418
2419 // create a flat copy of the source disk image
2420 if (pDiskEntry->type == VirtualSystemDescriptionType_HardDiskImage)
2421 {
2422 /*
2423 * Export a disk image.
2424 */
2425 ComObjPtr<Progress> pProgress2;
2426 pProgress2.createObject();
2427 rc = pProgress2->init(mVirtualBox, static_cast<IAppliance*>(this),
2428 BstrFmt(tr("Creating medium '%s'"),
2429 strTargetFilePath.c_str()).raw(), TRUE);
2430 if (FAILED(rc)) throw rc;
2431
2432#ifdef VBOX_WITH_NEW_TAR_CREATOR
2433 /* For compressed VMDK fun, we let i_exportFile produce the image bytes. */
2434 if (fStreamOptimizedVmdk)
2435 {
2436 RTVFSIOSTREAM hVfsIosDst;
2437 vrc = RTVfsFsStrmPushFile(hVfsFssDst, strTargetFilePath.c_str(), UINT64_MAX,
2438 NULL /*paObjInfo*/, 0 /*cObjInfo*/, RTVFSFSSTRM_PUSH_F_STREAM, &hVfsIosDst);
2439 if (RT_FAILURE(vrc))
2440 throw setErrorVrc(vrc, tr("RTVfsFsStrmPushFile failed for '%s' (%Rrc)"), strTargetFilePath.c_str(), vrc);
2441 hVfsIosDst = i_manifestSetupDigestCalculationForGivenIoStream(hVfsIosDst, strTargetFilePath.c_str(),
2442 false /*fRead*/);
2443 if (hVfsIosDst == NIL_RTVFSIOSTREAM)
2444 throw setError(E_FAIL, "i_manifestSetupDigestCalculationForGivenIoStream(%s)", strTargetFilePath.c_str());
2445
2446 rc = pSourceDisk->i_exportFile(strTargetFilePath.c_str(),
2447 format,
2448 MediumVariant_VmdkStreamOptimized,
2449 m->m_pSecretKeyStore,
2450 hVfsIosDst,
2451 pProgress2);
2452 RTVfsIoStrmRelease(hVfsIosDst);
2453 if (FAILED(rc)) throw rc;
2454 }
2455 /* When creating sparse raw images, the tar creator stream pulls the data
2456 out of the disk image. It will scan for empty space first, then copy
2457 the non-empty segments into the tar stream. */
2458 else
2459 {
2460 throw E_NOTIMPL;
2461 }
2462#else
2463 rc = pSourceDisk->i_exportFile(strTargetFilePath.c_str(),
2464 format,
2465 MediumVariant_VmdkStreamOptimized,
2466 m->m_pSecretKeyStore,
2467 pIfIo,
2468 pStorage,
2469 pProgress2);
2470 if (FAILED(rc)) throw rc;
2471#endif
2472
2473 ComPtr<IProgress> pProgress3(pProgress2);
2474 // now wait for the background disk operation to complete; this throws HRESULTs on error
2475 i_waitForAsyncProgress(pTask->pProgress, pProgress3);
2476 }
2477 else
2478 {
2479 /*
2480 * Copy CD/DVD/floppy image.
2481 */
2482 Assert(pDiskEntry->type == VirtualSystemDescriptionType_CDROM);
2483
2484#ifdef VBOX_WITH_NEW_TAR_CREATOR
2485 /* Open the source image and cast it to a VFS base object. */
2486 RTVFSFILE hVfsSrcFile;
2487 vrc = RTVfsFileOpenNormal(strSrcFilePath.c_str(),
2488 RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_NONE,
2489 &hVfsSrcFile);
2490 if (RT_FAILURE(vrc))
2491 throw setErrorBoth(VBOX_E_FILE_ERROR, vrc,
2492 tr("Could not create or open file '%s' (%Rrc)"), strSrcFilePath.c_str(), vrc);
2493
2494 RTVFSOBJ hVfsSrc = RTVfsObjFromFile(hVfsSrcFile);
2495 RTVfsFileRelease(hVfsSrcFile);
2496 AssertStmt(hVfsSrc != NIL_RTVFSOBJ, throw VERR_INTERNAL_ERROR);
2497
2498 /* Add it to the output stream. This will pull in all the data from the object. */
2499 vrc = RTVfsFsStrmAdd(hVfsFssDst, strTargetFilePath.c_str(), hVfsSrc, 0 /*fFlags*/);
2500 RTVfsObjRelease(hVfsSrc);
2501 if (RT_FAILURE(vrc))
2502 throw setErrorBoth(VBOX_E_FILE_ERROR, vrc, tr("Error during copy CD/DVD image '%s' (%Rrc)"),
2503 strSrcFilePath.c_str(), vrc);
2504#else
2505 /* Read the ISO file and add one to OVA/OVF package */
2506 void *pvStorage;
2507 RTFILE pFile = NULL;
2508 void *pvUser = pStorage;
2509
2510 vrc = pIfIo->pfnOpen(pvUser, strTargetFilePath.c_str(),
2511 RTFILE_O_OPEN_CREATE | RTFILE_O_WRITE | RTFILE_O_DENY_NONE,
2512 0,
2513 &pvStorage);
2514 if (RT_FAILURE(vrc))
2515 throw setError(VBOX_E_FILE_ERROR,
2516 tr("Could not create or open file '%s' (%Rrc)"),
2517 strTargetFilePath.c_str(), vrc);
2518
2519 vrc = RTFileOpen(&pFile,
2520 strSrcFilePath.c_str(),
2521 RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_NONE);
2522
2523 if (RT_FAILURE(vrc) || pFile == NULL)
2524 {
2525 pIfIo->pfnClose(pvUser, pvStorage);
2526 throw setError(VBOX_E_FILE_ERROR,
2527 tr("Could not create or open file '%s' (%Rrc)"),
2528 strSrcFilePath.c_str(), vrc);
2529 }
2530
2531 uint64_t cbFile = 0;
2532 vrc = RTFileGetSize(pFile, &cbFile);
2533 if (RT_SUCCESS(vrc))
2534 {
2535 size_t const cbTmpSize = _1M;
2536 void *pvTmpBuf = RTMemAlloc(cbTmpSize);
2537 if (pvTmpBuf)
2538 {
2539 /* The copy loop. */
2540 uint64_t offDstFile = 0;
2541 for (;;)
2542 {
2543 size_t cbChunk = 0;
2544 vrc = RTFileRead(pFile, pvTmpBuf, cbTmpSize, &cbChunk);
2545 if (RT_FAILURE(vrc) || cbChunk == 0)
2546 break;
2547
2548 size_t cbWritten = 0;
2549 vrc = pIfIo->pfnWriteSync(pvUser,
2550 pvStorage,
2551 offDstFile,
2552 pvTmpBuf,
2553 cbChunk,
2554 &cbWritten);
2555 if (RT_FAILURE(vrc))
2556 break;
2557 Assert(cbWritten == cbChunk);
2558
2559 offDstFile += cbWritten;
2560 }
2561
2562 RTMemFree(pvTmpBuf);
2563 }
2564 else
2565 vrc = VERR_NO_MEMORY;
2566 }
2567
2568 pIfIo->pfnClose(pvUser, pvStorage);
2569 RTFileClose(pFile);
2570
2571 if (RT_FAILURE(vrc))
2572 {
2573 if (vrc == VERR_EOF)
2574 vrc = VINF_SUCCESS;
2575 else
2576 throw setError(VBOX_E_FILE_ERROR,
2577 tr("Error during copy CD/DVD image '%s' (%Rrc)"),
2578 strSrcFilePath.c_str(), vrc);
2579 }
2580#endif
2581 }
2582 }
2583 catch (HRESULT rc3)
2584 {
2585 writeLock.acquire();
2586 /// @todo file deletion on error? If not, we can remove that whole try/catch block.
2587 throw rc3;
2588 }
2589 // Finished, lock again (so nobody mess around with the medium tree
2590 // in the meantime)
2591 writeLock.acquire();
2592#ifndef VBOX_WITH_NEW_TAR_CREATOR
2593 fileList.push_back(STRPAIR(strTargetFilePath, pStorage->strDigest));
2594#endif
2595 }
2596
2597 if (m->fManifest)
2598 {
2599 // Create & write the manifest file
2600 Utf8Str strMfFilePath = Utf8Str(pTask->locInfo.strPath).stripSuffix().append(".mf");
2601 Utf8Str strMfFileName = Utf8Str(strMfFilePath).stripPath();
2602 pTask->pProgress->SetNextOperation(BstrFmt(tr("Creating manifest file '%s'"), strMfFileName.c_str()).raw(),
2603 m->ulWeightForManifestOperation); // operation's weight, as set up
2604 // with the IProgress originally);
2605#ifdef VBOX_WITH_NEW_TAR_CREATOR
2606 /* Create a memory I/O stream and write the manifest to it. */
2607 RTVFSIOSTREAM hVfsIosManifest;
2608 vrc = RTVfsMemIoStrmCreate(NIL_RTVFSIOSTREAM, _1K, &hVfsIosManifest);
2609 if (RT_FAILURE(vrc))
2610 throw setErrorVrc(vrc, tr("RTVfsMemIoStrmCreate failed (%Rrc)"), vrc);
2611 if (m->hOurManifest != NIL_RTMANIFEST) /* In case it's empty. */
2612 vrc = RTManifestWriteStandard(m->hOurManifest, hVfsIosManifest);
2613 if (RT_SUCCESS(vrc))
2614 {
2615 /* Rewind the stream and add it to the output. */
2616 size_t cbIgnored;
2617 vrc = RTVfsIoStrmReadAt(hVfsIosManifest, 0 /*offset*/, &cbIgnored, 0, true /*fBlocking*/, &cbIgnored);
2618 if (RT_SUCCESS(vrc))
2619 {
2620 RTVFSOBJ hVfsObjManifest = RTVfsObjFromIoStream(hVfsIosManifest);
2621 vrc = RTVfsFsStrmAdd(hVfsFssDst, strMfFileName.c_str(), hVfsObjManifest, 0 /*fFlags*/);
2622 if (RT_SUCCESS(vrc))
2623 rc = S_OK;
2624 else
2625 rc = setErrorVrc(vrc, tr("RTVfsFsStrmAdd failed for the manifest (%Rrc)"), vrc);
2626 }
2627 else
2628 rc = setErrorVrc(vrc, tr("RTManifestWriteStandard failed (%Rrc)"), vrc);
2629 }
2630 else
2631 rc = setErrorVrc(vrc, tr("RTManifestWriteStandard failed (%Rrc)"), vrc);
2632 RTVfsIoStrmRelease(hVfsIosManifest);
2633 if (FAILED(rc))
2634 throw rc;
2635#else
2636 PRTMANIFESTTEST paManifestFiles = (PRTMANIFESTTEST)RTMemAlloc(sizeof(RTMANIFESTTEST) * fileList.size());
2637 size_t i = 0;
2638 for (list<STRPAIR>::const_iterator
2639 it = fileList.begin();
2640 it != fileList.end();
2641 ++it, ++i)
2642 {
2643 paManifestFiles[i].pszTestFile = (*it).first.c_str();
2644 paManifestFiles[i].pszTestDigest = (*it).second.c_str();
2645 }
2646 void *pvBuf;
2647 size_t cbSize;
2648 vrc = RTManifestWriteFilesBuf(&pvBuf, &cbSize, m->fSha256 ? RTDIGESTTYPE_SHA256 : RTDIGESTTYPE_SHA1,
2649 paManifestFiles, fileList.size());
2650 RTMemFree(paManifestFiles);
2651 if (RT_FAILURE(vrc))
2652 throw setError(VBOX_E_FILE_ERROR,
2653 tr("Could not create manifest file '%s' (%Rrc)"),
2654 strMfFileName.c_str(), vrc);
2655 /* Disable digest creation for the manifest file. */
2656 pStorage->fCreateDigest = false;
2657 /* Write the manifest file to disk. */
2658 vrc = writeBufferToFile(strMfFilePath.c_str(), pvBuf, cbSize, pIfIo, pStorage);
2659 RTMemFree(pvBuf);
2660 if (RT_FAILURE(vrc))
2661 throw setError(VBOX_E_FILE_ERROR,
2662 tr("Could not create manifest file '%s' (%Rrc)"),
2663 strMfFilePath.c_str(), vrc);
2664#endif
2665 }
2666 }
2667 catch (RTCError &x) // includes all XML exceptions
2668 {
2669 rc = setError(VBOX_E_FILE_ERROR,
2670 x.what());
2671 }
2672 catch (HRESULT aRC)
2673 {
2674 rc = aRC;
2675 }
2676
2677#ifndef VBOX_WITH_NEW_TAR_CREATOR /* done in caller now */
2678 /* Cleanup on error */
2679 if (FAILED(rc))
2680 {
2681 for (list<STRPAIR>::const_iterator
2682 it = fileList.begin();
2683 it != fileList.end();
2684 ++it)
2685 pIfIo->pfnDelete(pStorage, (*it).first.c_str());
2686 }
2687#endif
2688
2689 LogFlowFunc(("rc=%Rhrc\n", rc));
2690 LogFlowFuncLeave();
2691
2692 return rc;
2693}
2694
2695
2696#ifdef VBOX_WITH_NEW_TAR_CREATOR
2697/**
2698 * Writes a memory buffer to a file in the output file system stream.
2699 *
2700 * @returns COM status code.
2701 * @param hVfsFssDst The file system stream to add the file to.
2702 * @param pszFilename The file name (w/ path if desired).
2703 * @param pvContent Pointer to buffer containing the file content.
2704 * @param cbContent Size of the content.
2705 */
2706HRESULT Appliance::i_writeBufferToFile(RTVFSFSSTREAM hVfsFssDst, const char *pszFilename, const void *pvContent, size_t cbContent)
2707{
2708 /*
2709 * Create a VFS file around the memory, converting it to a base VFS object handle.
2710 */
2711 HRESULT hrc;
2712 RTVFSIOSTREAM hVfsIosSrc;
2713 int vrc = RTVfsIoStrmFromBuffer(RTFILE_O_READ, pvContent, cbContent, &hVfsIosSrc);
2714 if (RT_SUCCESS(vrc))
2715 {
2716 hVfsIosSrc = i_manifestSetupDigestCalculationForGivenIoStream(hVfsIosSrc, pszFilename);
2717 AssertReturn(hVfsIosSrc != NIL_RTVFSIOSTREAM,
2718 setErrorVrc(vrc, "i_manifestSetupDigestCalculationForGivenIoStream"));
2719
2720 RTVFSOBJ hVfsObj = RTVfsObjFromIoStream(hVfsIosSrc);
2721 RTVfsIoStrmRelease(hVfsIosSrc);
2722 AssertReturn(hVfsObj != NIL_RTVFSOBJ, E_FAIL);
2723
2724 /*
2725 * Add it to the stream.
2726 */
2727 vrc = RTVfsFsStrmAdd(hVfsFssDst, pszFilename, hVfsObj, 0);
2728 RTVfsObjRelease(hVfsObj);
2729 if (RT_SUCCESS(vrc))
2730 hrc = S_OK;
2731 else
2732 hrc = setErrorVrc(vrc, tr("RTVfsFsStrmAdd failed for '%s' (%Rrc)"), pszFilename, vrc);
2733 }
2734 else
2735 hrc = setErrorVrc(vrc, "RTVfsIoStrmFromBuffer");
2736 return hrc;
2737}
2738#endif
2739
Note: See TracBrowser for help on using the repository browser.

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