VirtualBox

source: vbox/trunk/src/VBox/Main/include/ApplianceImplPrivate.h@ 48112

Last change on this file since 48112 was 47963, checked in by vboxsync, 11 years ago

pr6022. Additional checks during OVA/OVF import. Deleting temporary files. Using small memory buffer for copying ISO images with simultaneously calculating SHA digest.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.7 KB
Line 
1/** @file
2 *
3 * VirtualBox Appliance private data definitions
4 */
5
6/*
7 * Copyright (C) 2006-2012 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#ifndef ____H_APPLIANCEIMPLPRIVATE
19#define ____H_APPLIANCEIMPLPRIVATE
20
21class VirtualSystemDescription;
22
23#include "ovfreader.h"
24#include <map>
25
26////////////////////////////////////////////////////////////////////////////////
27//
28// Appliance data definition
29//
30////////////////////////////////////////////////////////////////////////////////
31
32typedef std::pair<Utf8Str, Utf8Str> STRPAIR;
33
34/* Describe a location for the import/export. The location could be a file on a
35 * local hard disk or a remote target based on the supported inet protocols. */
36struct LocationInfo
37{
38 LocationInfo()
39 : storageType(VFSType_File) {}
40 VFSType_T storageType; /* Which type of storage should be handled */
41 Utf8Str strPath; /* File path for the import/export */
42 Utf8Str strHostname; /* Hostname on remote storage locations (could be empty) */
43 Utf8Str strUsername; /* Username on remote storage locations (could be empty) */
44 Utf8Str strPassword; /* Password on remote storage locations (could be empty) */
45};
46
47// opaque private instance data of Appliance class
48struct Appliance::Data
49{
50 enum ApplianceState { ApplianceIdle, ApplianceImporting, ApplianceExporting };
51 enum digest_T {SHA1, SHA256};
52
53 Data()
54 : state(ApplianceIdle)
55 , fManifest(true)
56 , fSha256(false)
57 , pReader(NULL)
58 , ulWeightForXmlOperation(0)
59 , ulWeightForManifestOperation(0)
60 , ulTotalDisksMB(0)
61 , cDisks(0)
62 {
63 }
64
65 ~Data()
66 {
67 if (pReader)
68 {
69 delete pReader;
70 pReader = NULL;
71 }
72 }
73
74 ApplianceState state;
75
76 LocationInfo locInfo; // location info for the currently processed OVF
77 bool fManifest; // Create a manifest file on export
78 bool fSha256; // true = SHA256 (OVF 2.0), false = SHA1 (OVF 1.0)
79 Utf8Str strOVFSHADigest;//SHA digest of OVf file. It is stored here after reading OVF file (before import)
80
81 RTCList<ImportOptions_T> optList;
82
83 ovf::OVFReader *pReader;
84
85 std::list< ComObjPtr<VirtualSystemDescription> >
86 virtualSystemDescriptions;
87
88 std::list<Utf8Str> llWarnings;
89
90 ULONG ulWeightForXmlOperation;
91 ULONG ulWeightForManifestOperation;
92 ULONG ulTotalDisksMB;
93 ULONG cDisks;
94
95 std::list<Guid> llGuidsMachinesCreated;
96};
97
98struct Appliance::XMLStack
99{
100 std::map<Utf8Str, const VirtualSystemDescriptionEntry*> mapDisks;
101 std::map<Utf8Str, bool> mapNetworks;
102};
103
104struct Appliance::TaskOVF
105{
106 enum TaskType
107 {
108 Read,
109 Import,
110 Write
111 };
112
113 TaskOVF(Appliance *aThat,
114 TaskType aType,
115 LocationInfo aLocInfo,
116 ComObjPtr<Progress> &aProgress)
117 : pAppliance(aThat),
118 taskType(aType),
119 locInfo(aLocInfo),
120 pProgress(aProgress),
121 enFormat(ovf::OVFVersion_unknown),
122 rc(S_OK)
123 {}
124
125 static int updateProgress(unsigned uPercent, void *pvUser);
126
127 int startThread();
128
129 Appliance *pAppliance;
130 TaskType taskType;
131 const LocationInfo locInfo;
132 ComObjPtr<Progress> pProgress;
133
134 ovf::OVFVersion_T enFormat;
135
136 HRESULT rc;
137};
138
139struct MyHardDiskAttachment
140{
141 ComPtr<IMachine> pMachine;
142 Bstr controllerType;
143 int32_t lControllerPort; // 0-29 for SATA
144 int32_t lDevice; // IDE: 0 or 1, otherwise 0 always
145};
146
147/**
148 * Used by Appliance::importMachineGeneric() to store
149 * input parameters and rollback information.
150 */
151struct Appliance::ImportStack
152{
153 // input pointers
154 const LocationInfo &locInfo; // ptr to location info from Appliance::importFS()
155 Utf8Str strSourceDir; // directory where source files reside
156 const ovf::DiskImagesMap &mapDisks; // ptr to disks map in OVF
157 ComObjPtr<Progress> &pProgress; // progress object passed into Appliance::importFS()
158
159 // input parameters from VirtualSystemDescriptions
160 Utf8Str strNameVBox; // VM name
161 Utf8Str strMachineFolder; // FQ host folder where the VirtualBox machine would be created
162 Utf8Str strOsTypeVBox; // VirtualBox guest OS type as string
163 Utf8Str strDescription;
164 uint32_t cCPUs; // CPU count
165 bool fForceHWVirt; // if true, we force enabling hardware virtualization
166 bool fForceIOAPIC; // if true, we force enabling the IOAPIC
167 uint32_t ulMemorySizeMB; // virtual machine RAM in megabytes
168#ifdef VBOX_WITH_USB
169 bool fUSBEnabled;
170#endif
171 Utf8Str strAudioAdapter; // if not empty, then the guest has audio enabled, and this is the decimal
172 // representation of the audio adapter (should always be "0" for AC97 presently)
173
174 // session (not initially created)
175 ComPtr<ISession> pSession; // session opened in Appliance::importFS() for machine manipulation
176 bool fSessionOpen; // true if the pSession is currently open and needs closing
177
178 // a list of images that we created/imported; this is initially empty
179 // and will be cleaned up on errors
180 std::list<MyHardDiskAttachment> llHardDiskAttachments; // disks that were attached
181 std::list<STRPAIR> llSrcDisksDigest; // Digests of the source disks
182
183 ImportStack(const LocationInfo &aLocInfo,
184 const ovf::DiskImagesMap &aMapDisks,
185 ComObjPtr<Progress> &aProgress)
186 : locInfo(aLocInfo),
187 mapDisks(aMapDisks),
188 pProgress(aProgress),
189 cCPUs(1),
190 fForceHWVirt(false),
191 fForceIOAPIC(false),
192 ulMemorySizeMB(0),
193 fSessionOpen(false)
194 {
195 // disk images have to be on the same place as the OVF file. So
196 // strip the filename out of the full file path
197 strSourceDir = aLocInfo.strPath;
198 strSourceDir.stripFilename();
199 }
200};
201
202////////////////////////////////////////////////////////////////////////////////
203//
204// VirtualSystemDescription data definition
205//
206////////////////////////////////////////////////////////////////////////////////
207
208struct VirtualSystemDescription::Data
209{
210 std::list<VirtualSystemDescriptionEntry>
211 llDescriptions; // item descriptions
212
213 ComPtr<Machine> pMachine; // VirtualBox machine this description was exported from (export only)
214
215 settings::MachineConfigFile
216 *pConfig; // machine config created from <vbox:Machine> element if found (import only)
217};
218
219////////////////////////////////////////////////////////////////////////////////
220//
221// Internal helpers
222//
223////////////////////////////////////////////////////////////////////////////////
224
225void convertCIMOSType2VBoxOSType(Utf8Str &strType, ovf::CIMOSType_T c, const Utf8Str &cStr);
226
227ovf::CIMOSType_T convertVBoxOSType2CIMOSType(const char *pcszVBox, BOOL fLongMode);
228
229Utf8Str convertNetworkAttachmentTypeToString(NetworkAttachmentType_T type);
230
231
232typedef struct SHASTORAGE
233{
234 PVDINTERFACE pVDImageIfaces;
235 bool fCreateDigest;
236 bool fSha256; /* false = SHA1 (OVF 1.x), true = SHA256 (OVF 2.0) */
237 Utf8Str strDigest;
238} SHASTORAGE, *PSHASTORAGE;
239
240PVDINTERFACEIO ShaCreateInterface();
241PVDINTERFACEIO FileCreateInterface();
242PVDINTERFACEIO TarCreateInterface();
243int ShaReadBuf(const char *pcszFilename, void **ppvBuf, size_t *pcbSize, PVDINTERFACEIO pIfIo, void *pvUser);
244int ShaWriteBuf(const char *pcszFilename, void *pvBuf, size_t cbSize, PVDINTERFACEIO pIfIo, void *pvUser);
245int decompressImageAndSave(const char *pcszFullFilenameIn, const char *pcszFullFilenameOut, PVDINTERFACEIO pIfIo, void *pvUser);
246int copyFileAndCalcShaDigest(const char *pcszSourceFilename, const char *pcszTargetFilename, PVDINTERFACEIO pIfIo, void *pvUser);
247#endif // !____H_APPLIANCEIMPLPRIVATE
248
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