1 | /** @file
|
---|
2 | * Settings File Manipulation API.
|
---|
3 | *
|
---|
4 | * Two classes, MainConfigFile and MachineConfigFile, represent the VirtualBox.xml and
|
---|
5 | * machine XML files. They share a common ancestor class, ConfigFileBase, which shares
|
---|
6 | * functionality such as talking to the XML back-end classes and settings version management.
|
---|
7 | *
|
---|
8 | * Rules for introducing new settings: If an element or attribute is introduced that was not
|
---|
9 | * present before VirtualBox 3.1, then settings version checks need to be introduced. The
|
---|
10 | * settings version for VirtualBox 3.1 is 1.9; see the SettingsVersion enumeration in
|
---|
11 | * src/VBox/Main/idl/VirtualBox.xidl for details about which version was used when.
|
---|
12 | *
|
---|
13 | * The settings versions checks are necessary because VirtualBox 3.1 no longer automatically
|
---|
14 | * converts XML settings files but only if necessary, that is, if settings are present that
|
---|
15 | * the old format does not support. If we write an element or attribute to a settings file
|
---|
16 | * of an older version, then an old VirtualBox (before 3.1) will attempt to validate it
|
---|
17 | * with XML schema, and that will certainly fail.
|
---|
18 | *
|
---|
19 | * So, to introduce a new setting:
|
---|
20 | *
|
---|
21 | * 1) Make sure the constructor of corresponding settings structure has a proper default.
|
---|
22 | *
|
---|
23 | * 2) In the settings reader method, try to read the setting; if it's there, great, if not,
|
---|
24 | * the default value will have been set by the constructor.
|
---|
25 | *
|
---|
26 | * 3) In the settings writer method, write the setting _only_ if the current settings
|
---|
27 | * version (stored in m->sv) is high enough. That is, for VirtualBox 3.1, write it
|
---|
28 | * only if (m->sv >= SettingsVersion_v1_9).
|
---|
29 | *
|
---|
30 | * 4) In MachineConfigFile::bumpSettingsVersionIfNeeded(), check if the new setting has
|
---|
31 | * a non-default value (i.e. that differs from the constructor). If so, bump the
|
---|
32 | * settings version to the current version so the settings writer (3) can write out
|
---|
33 | * the non-default value properly.
|
---|
34 | *
|
---|
35 | * So far a corresponding method for MainConfigFile has not been necessary since there
|
---|
36 | * have been no incompatible changes yet.
|
---|
37 | */
|
---|
38 |
|
---|
39 | /*
|
---|
40 | * Copyright (C) 2007-2009 Sun Microsystems, Inc.
|
---|
41 | *
|
---|
42 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
43 | * available from http://www.virtualbox.org. This file is free software;
|
---|
44 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
45 | * General Public License (GPL) as published by the Free Software
|
---|
46 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
47 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
48 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
49 | *
|
---|
50 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
51 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
52 | * additional information or have any questions.
|
---|
53 | */
|
---|
54 |
|
---|
55 | #include "VBox/com/string.h"
|
---|
56 | #include "VBox/settings.h"
|
---|
57 | #include <iprt/xml_cpp.h>
|
---|
58 | #include <iprt/stream.h>
|
---|
59 | #include <iprt/ctype.h>
|
---|
60 | #include <iprt/file.h>
|
---|
61 |
|
---|
62 | // generated header
|
---|
63 | #include "SchemaDefs.h"
|
---|
64 |
|
---|
65 | #include "Logging.h"
|
---|
66 |
|
---|
67 | using namespace com;
|
---|
68 | using namespace settings;
|
---|
69 |
|
---|
70 | ////////////////////////////////////////////////////////////////////////////////
|
---|
71 | //
|
---|
72 | // Defines
|
---|
73 | //
|
---|
74 | ////////////////////////////////////////////////////////////////////////////////
|
---|
75 |
|
---|
76 | /** VirtualBox XML settings namespace */
|
---|
77 | #define VBOX_XML_NAMESPACE "http://www.innotek.de/VirtualBox-settings"
|
---|
78 |
|
---|
79 | /** VirtualBox XML settings version number substring ("x.y") */
|
---|
80 | #define VBOX_XML_VERSION "1.9"
|
---|
81 |
|
---|
82 | /** VirtualBox XML settings version platform substring */
|
---|
83 | #if defined (RT_OS_DARWIN)
|
---|
84 | # define VBOX_XML_PLATFORM "macosx"
|
---|
85 | #elif defined (RT_OS_FREEBSD)
|
---|
86 | # define VBOX_XML_PLATFORM "freebsd"
|
---|
87 | #elif defined (RT_OS_LINUX)
|
---|
88 | # define VBOX_XML_PLATFORM "linux"
|
---|
89 | #elif defined (RT_OS_NETBSD)
|
---|
90 | # define VBOX_XML_PLATFORM "netbsd"
|
---|
91 | #elif defined (RT_OS_OPENBSD)
|
---|
92 | # define VBOX_XML_PLATFORM "openbsd"
|
---|
93 | #elif defined (RT_OS_OS2)
|
---|
94 | # define VBOX_XML_PLATFORM "os2"
|
---|
95 | #elif defined (RT_OS_SOLARIS)
|
---|
96 | # define VBOX_XML_PLATFORM "solaris"
|
---|
97 | #elif defined (RT_OS_WINDOWS)
|
---|
98 | # define VBOX_XML_PLATFORM "windows"
|
---|
99 | #else
|
---|
100 | # error Unsupported platform!
|
---|
101 | #endif
|
---|
102 |
|
---|
103 | /** VirtualBox XML settings full version string ("x.y-platform") */
|
---|
104 | #define VBOX_XML_VERSION_FULL VBOX_XML_VERSION "-" VBOX_XML_PLATFORM
|
---|
105 |
|
---|
106 | ////////////////////////////////////////////////////////////////////////////////
|
---|
107 | //
|
---|
108 | // Internal data
|
---|
109 | //
|
---|
110 | ////////////////////////////////////////////////////////////////////////////////
|
---|
111 |
|
---|
112 | /**
|
---|
113 | * Opaque data structore for ConfigFileBase (only declared
|
---|
114 | * in header, defined only here).
|
---|
115 | */
|
---|
116 |
|
---|
117 | struct ConfigFileBase::Data
|
---|
118 | {
|
---|
119 | Data()
|
---|
120 | : pParser(NULL),
|
---|
121 | pDoc(NULL),
|
---|
122 | pelmRoot(NULL),
|
---|
123 | sv(SettingsVersion_Null),
|
---|
124 | svRead(SettingsVersion_Null)
|
---|
125 | {}
|
---|
126 |
|
---|
127 | ~Data()
|
---|
128 | {
|
---|
129 | cleanup();
|
---|
130 | }
|
---|
131 |
|
---|
132 | iprt::MiniString strFilename;
|
---|
133 | bool fFileExists;
|
---|
134 |
|
---|
135 | xml::XmlFileParser *pParser;
|
---|
136 | xml::Document *pDoc;
|
---|
137 | xml::ElementNode *pelmRoot;
|
---|
138 |
|
---|
139 | com::Utf8Str strSettingsVersionFull; // e.g. "1.7-linux"
|
---|
140 | SettingsVersion_T sv; // e.g. SettingsVersion_v1_7
|
---|
141 |
|
---|
142 | SettingsVersion_T svRead; // settings version that the original file had when it was read,
|
---|
143 | // or SettingsVersion_Null if none
|
---|
144 |
|
---|
145 | void cleanup()
|
---|
146 | {
|
---|
147 | if (pDoc)
|
---|
148 | {
|
---|
149 | delete pDoc;
|
---|
150 | pDoc = NULL;
|
---|
151 | pelmRoot = NULL;
|
---|
152 | }
|
---|
153 |
|
---|
154 | if (pParser)
|
---|
155 | {
|
---|
156 | delete pParser;
|
---|
157 | pParser = NULL;
|
---|
158 | }
|
---|
159 | }
|
---|
160 | };
|
---|
161 |
|
---|
162 | /**
|
---|
163 | * Private exception class (not in the header file) that makes
|
---|
164 | * throwing xml::LogicError instances easier. That class is public
|
---|
165 | * and should be caught by client code.
|
---|
166 | */
|
---|
167 | class settings::ConfigFileError : public xml::LogicError
|
---|
168 | {
|
---|
169 | public:
|
---|
170 | ConfigFileError(const ConfigFileBase *file,
|
---|
171 | const xml::Node *pNode,
|
---|
172 | const char *pcszFormat, ...)
|
---|
173 | : xml::LogicError()
|
---|
174 | {
|
---|
175 | va_list args;
|
---|
176 | va_start(args, pcszFormat);
|
---|
177 | Utf8StrFmtVA what(pcszFormat, args);
|
---|
178 | va_end(args);
|
---|
179 |
|
---|
180 | Utf8Str strLine;
|
---|
181 | if (pNode)
|
---|
182 | strLine = Utf8StrFmt(" (line %RU32)", pNode->getLineNumber());
|
---|
183 |
|
---|
184 | const char *pcsz = strLine.c_str();
|
---|
185 | Utf8StrFmt str(N_("Error in %s%s -- %s"),
|
---|
186 | file->m->strFilename.c_str(),
|
---|
187 | (pcsz) ? pcsz : "",
|
---|
188 | what.c_str());
|
---|
189 |
|
---|
190 | setWhat(str.c_str());
|
---|
191 | }
|
---|
192 | };
|
---|
193 |
|
---|
194 | ////////////////////////////////////////////////////////////////////////////////
|
---|
195 | //
|
---|
196 | // ConfigFileBase
|
---|
197 | //
|
---|
198 | ////////////////////////////////////////////////////////////////////////////////
|
---|
199 |
|
---|
200 | /**
|
---|
201 | * Constructor. Allocates the XML internals.
|
---|
202 | * @param strFilename
|
---|
203 | */
|
---|
204 | ConfigFileBase::ConfigFileBase(const com::Utf8Str *pstrFilename)
|
---|
205 | : m(new Data)
|
---|
206 | {
|
---|
207 | Utf8Str strMajor;
|
---|
208 | Utf8Str strMinor;
|
---|
209 |
|
---|
210 | m->fFileExists = false;
|
---|
211 |
|
---|
212 | if (pstrFilename)
|
---|
213 | {
|
---|
214 | m->strFilename = *pstrFilename;
|
---|
215 |
|
---|
216 | m->pParser = new xml::XmlFileParser;
|
---|
217 | m->pDoc = new xml::Document;
|
---|
218 | m->pParser->read(*pstrFilename,
|
---|
219 | *m->pDoc);
|
---|
220 |
|
---|
221 | m->fFileExists = true;
|
---|
222 |
|
---|
223 | m->pelmRoot = m->pDoc->getRootElement();
|
---|
224 | if (!m->pelmRoot || !m->pelmRoot->nameEquals("VirtualBox"))
|
---|
225 | throw ConfigFileError(this, NULL, N_("Root element in VirtualBox settings files must be \"VirtualBox\"."));
|
---|
226 |
|
---|
227 | if (!(m->pelmRoot->getAttributeValue("version", m->strSettingsVersionFull)))
|
---|
228 | throw ConfigFileError(this, m->pelmRoot, N_("Required VirtualBox/@version attribute is missing"));
|
---|
229 |
|
---|
230 | LogRel(("Loading settings file \"%s\" with version \"%s\"\n", m->strFilename.c_str(), m->strSettingsVersionFull.c_str()));
|
---|
231 |
|
---|
232 | // parse settings version; allow future versions but fail if file is older than 1.6
|
---|
233 | m->sv = SettingsVersion_Null;
|
---|
234 | if (m->strSettingsVersionFull.length() > 3)
|
---|
235 | {
|
---|
236 | const char *pcsz = m->strSettingsVersionFull.c_str();
|
---|
237 | char c;
|
---|
238 |
|
---|
239 | while ( (c = *pcsz)
|
---|
240 | && RT_C_IS_DIGIT(c)
|
---|
241 | )
|
---|
242 | {
|
---|
243 | strMajor.append(c);
|
---|
244 | ++pcsz;
|
---|
245 | }
|
---|
246 |
|
---|
247 | if (*pcsz++ == '.')
|
---|
248 | {
|
---|
249 | while ( (c = *pcsz)
|
---|
250 | && RT_C_IS_DIGIT(c)
|
---|
251 | )
|
---|
252 | {
|
---|
253 | strMinor.append(c);
|
---|
254 | ++pcsz;
|
---|
255 | }
|
---|
256 | }
|
---|
257 |
|
---|
258 | uint32_t ulMajor = RTStrToUInt32(strMajor.c_str());
|
---|
259 | uint32_t ulMinor = RTStrToUInt32(strMinor.c_str());
|
---|
260 |
|
---|
261 | if (ulMajor == 1)
|
---|
262 | {
|
---|
263 | if (ulMinor == 3)
|
---|
264 | m->sv = SettingsVersion_v1_3;
|
---|
265 | else if (ulMinor == 4)
|
---|
266 | m->sv = SettingsVersion_v1_4;
|
---|
267 | else if (ulMinor == 5)
|
---|
268 | m->sv = SettingsVersion_v1_5;
|
---|
269 | else if (ulMinor == 6)
|
---|
270 | m->sv = SettingsVersion_v1_6;
|
---|
271 | else if (ulMinor == 7)
|
---|
272 | m->sv = SettingsVersion_v1_7;
|
---|
273 | else if (ulMinor == 8)
|
---|
274 | m->sv = SettingsVersion_v1_8;
|
---|
275 | else if (ulMinor == 9)
|
---|
276 | m->sv = SettingsVersion_v1_9;
|
---|
277 | else if (ulMinor > 9)
|
---|
278 | m->sv = SettingsVersion_Future;
|
---|
279 | }
|
---|
280 | else if (ulMajor > 1)
|
---|
281 | m->sv = SettingsVersion_Future;
|
---|
282 |
|
---|
283 | LogRel(("Parsed settings version %d.%d to enum value %d\n", ulMajor, ulMinor, m->sv));
|
---|
284 | }
|
---|
285 |
|
---|
286 | if (m->sv == SettingsVersion_Null)
|
---|
287 | throw ConfigFileError(this, m->pelmRoot, N_("Cannot handle settings version '%s'"), m->strSettingsVersionFull.c_str());
|
---|
288 |
|
---|
289 | // remember the settings version we read in case it gets upgraded later,
|
---|
290 | // so we know when to make backups
|
---|
291 | m->svRead = m->sv;
|
---|
292 | }
|
---|
293 | else
|
---|
294 | {
|
---|
295 | m->strSettingsVersionFull = VBOX_XML_VERSION_FULL;
|
---|
296 | m->sv = SettingsVersion_v1_9;
|
---|
297 | }
|
---|
298 | }
|
---|
299 |
|
---|
300 | /**
|
---|
301 | * Clean up.
|
---|
302 | */
|
---|
303 | ConfigFileBase::~ConfigFileBase()
|
---|
304 | {
|
---|
305 | if (m)
|
---|
306 | {
|
---|
307 | delete m;
|
---|
308 | m = NULL;
|
---|
309 | }
|
---|
310 | }
|
---|
311 |
|
---|
312 | /**
|
---|
313 | * Helper function that parses a UUID in string form into
|
---|
314 | * a com::Guid item. Since that uses an IPRT function which
|
---|
315 | * does not accept "{}" characters around the UUID string,
|
---|
316 | * we handle that here. Throws on errors.
|
---|
317 | * @param guid
|
---|
318 | * @param strUUID
|
---|
319 | */
|
---|
320 | void ConfigFileBase::parseUUID(Guid &guid,
|
---|
321 | const Utf8Str &strUUID) const
|
---|
322 | {
|
---|
323 | // {5f102a55-a51b-48e3-b45a-b28d33469488}
|
---|
324 | // 01234567890123456789012345678901234567
|
---|
325 | // 1 2 3
|
---|
326 | if ( (strUUID[0] == '{')
|
---|
327 | && (strUUID[37] == '}')
|
---|
328 | )
|
---|
329 | guid = strUUID.substr(1, 36).c_str();
|
---|
330 | else
|
---|
331 | guid = strUUID.c_str();
|
---|
332 |
|
---|
333 | if (guid.isEmpty())
|
---|
334 | throw ConfigFileError(this, NULL, N_("UUID \"%s\" has invalid format"), strUUID.c_str());
|
---|
335 | }
|
---|
336 |
|
---|
337 | /**
|
---|
338 | * Parses the given string in str and attempts to treat it as an ISO
|
---|
339 | * date/time stamp to put into timestamp. Throws on errors.
|
---|
340 | * @param timestamp
|
---|
341 | * @param str
|
---|
342 | */
|
---|
343 | void ConfigFileBase::parseTimestamp(RTTIMESPEC ×tamp,
|
---|
344 | const com::Utf8Str &str) const
|
---|
345 | {
|
---|
346 | const char *pcsz = str.c_str();
|
---|
347 | // yyyy-mm-ddThh:mm:ss
|
---|
348 | // "2009-07-10T11:54:03Z"
|
---|
349 | // 01234567890123456789
|
---|
350 | // 1
|
---|
351 | if (str.length() > 19)
|
---|
352 | {
|
---|
353 | // timezone must either be unspecified or 'Z' for UTC
|
---|
354 | if ( (pcsz[19])
|
---|
355 | && (pcsz[19] != 'Z')
|
---|
356 | )
|
---|
357 | throw ConfigFileError(this, NULL, N_("Cannot handle ISO timestamp '%s': is not UTC date"), str.c_str());
|
---|
358 |
|
---|
359 | int32_t yyyy;
|
---|
360 | uint32_t mm, dd, hh, min, secs;
|
---|
361 | if ( (pcsz[4] == '-')
|
---|
362 | && (pcsz[7] == '-')
|
---|
363 | && (pcsz[10] == 'T')
|
---|
364 | && (pcsz[13] == ':')
|
---|
365 | && (pcsz[16] == ':')
|
---|
366 | )
|
---|
367 | {
|
---|
368 | int rc;
|
---|
369 | if ( (RT_SUCCESS(rc = RTStrToInt32Ex(pcsz, NULL, 0, &yyyy)))
|
---|
370 | // could theoretically be negative but let's assume that nobody
|
---|
371 | // created virtual machines before the Christian era
|
---|
372 | && (RT_SUCCESS(rc = RTStrToUInt32Ex(pcsz + 5, NULL, 0, &mm)))
|
---|
373 | && (RT_SUCCESS(rc = RTStrToUInt32Ex(pcsz + 8, NULL, 0, &dd)))
|
---|
374 | && (RT_SUCCESS(rc = RTStrToUInt32Ex(pcsz + 11, NULL, 0, &hh)))
|
---|
375 | && (RT_SUCCESS(rc = RTStrToUInt32Ex(pcsz + 14, NULL, 0, &min)))
|
---|
376 | && (RT_SUCCESS(rc = RTStrToUInt32Ex(pcsz + 17, NULL, 0, &secs)))
|
---|
377 | )
|
---|
378 | {
|
---|
379 | RTTIME time = { yyyy,
|
---|
380 | (uint8_t)mm,
|
---|
381 | 0,
|
---|
382 | 0,
|
---|
383 | (uint8_t)dd,
|
---|
384 | (uint8_t)hh,
|
---|
385 | (uint8_t)min,
|
---|
386 | (uint8_t)secs,
|
---|
387 | 0,
|
---|
388 | RTTIME_FLAGS_TYPE_UTC };
|
---|
389 | if (RTTimeNormalize(&time))
|
---|
390 | if (RTTimeImplode(×tamp, &time))
|
---|
391 | return;
|
---|
392 | }
|
---|
393 |
|
---|
394 | throw ConfigFileError(this, NULL, N_("Cannot parse ISO timestamp '%s': runtime error, %Rra"), str.c_str(), rc);
|
---|
395 | }
|
---|
396 |
|
---|
397 | throw ConfigFileError(this, NULL, N_("Cannot parse ISO timestamp '%s': invalid format"), str.c_str());
|
---|
398 | }
|
---|
399 | }
|
---|
400 |
|
---|
401 | /**
|
---|
402 | * Helper to create a string for a RTTIMESPEC for writing out ISO timestamps.
|
---|
403 | * @param stamp
|
---|
404 | * @return
|
---|
405 | */
|
---|
406 | com::Utf8Str ConfigFileBase::makeString(const RTTIMESPEC &stamp)
|
---|
407 | {
|
---|
408 | RTTIME time;
|
---|
409 | if (!RTTimeExplode(&time, &stamp))
|
---|
410 | throw ConfigFileError(this, NULL, N_("Timespec %lld ms is invalid"), RTTimeSpecGetMilli(&stamp));
|
---|
411 |
|
---|
412 | return Utf8StrFmt("%04ld-%02hd-%02hdT%02hd:%02hd:%02hdZ",
|
---|
413 | time.i32Year,
|
---|
414 | (uint16_t)time.u8Month,
|
---|
415 | (uint16_t)time.u8MonthDay,
|
---|
416 | (uint16_t)time.u8Hour,
|
---|
417 | (uint16_t)time.u8Minute,
|
---|
418 | (uint16_t)time.u8Second);
|
---|
419 | }
|
---|
420 |
|
---|
421 | /**
|
---|
422 | * Helper to create a string for a GUID.
|
---|
423 | * @param guid
|
---|
424 | * @return
|
---|
425 | */
|
---|
426 | com::Utf8Str ConfigFileBase::makeString(const Guid &guid)
|
---|
427 | {
|
---|
428 | Utf8Str str("{");
|
---|
429 | str.append(guid.toString());
|
---|
430 | str.append("}");
|
---|
431 | return str;
|
---|
432 | }
|
---|
433 |
|
---|
434 | /**
|
---|
435 | * Helper method to read in an ExtraData subtree and stores its contents
|
---|
436 | * in the given map of extradata items. Used for both main and machine
|
---|
437 | * extradata (MainConfigFile and MachineConfigFile).
|
---|
438 | * @param elmExtraData
|
---|
439 | * @param map
|
---|
440 | */
|
---|
441 | void ConfigFileBase::readExtraData(const xml::ElementNode &elmExtraData,
|
---|
442 | ExtraDataItemsMap &map)
|
---|
443 | {
|
---|
444 | xml::NodesLoop nlLevel4(elmExtraData);
|
---|
445 | const xml::ElementNode *pelmExtraDataItem;
|
---|
446 | while ((pelmExtraDataItem = nlLevel4.forAllNodes()))
|
---|
447 | {
|
---|
448 | if (pelmExtraDataItem->nameEquals("ExtraDataItem"))
|
---|
449 | {
|
---|
450 | // <ExtraDataItem name="GUI/LastWindowPostion" value="97,88,981,858"/>
|
---|
451 | Utf8Str strName, strValue;
|
---|
452 | if ( ((pelmExtraDataItem->getAttributeValue("name", strName)))
|
---|
453 | && ((pelmExtraDataItem->getAttributeValue("value", strValue)))
|
---|
454 | )
|
---|
455 | map[strName] = strValue;
|
---|
456 | else
|
---|
457 | throw ConfigFileError(this, pelmExtraDataItem, N_("Required ExtraDataItem/@name or @value attribute is missing"));
|
---|
458 | }
|
---|
459 | }
|
---|
460 | }
|
---|
461 |
|
---|
462 | /**
|
---|
463 | * Reads <USBDeviceFilter> entries from under the given elmDeviceFilters node and
|
---|
464 | * stores them in the given linklist. This is in ConfigFileBase because it's used
|
---|
465 | * from both MainConfigFile (for host filters) and MachineConfigFile (for machine
|
---|
466 | * filters).
|
---|
467 | * @param elmDeviceFilters
|
---|
468 | * @param ll
|
---|
469 | */
|
---|
470 | void ConfigFileBase::readUSBDeviceFilters(const xml::ElementNode &elmDeviceFilters,
|
---|
471 | USBDeviceFiltersList &ll)
|
---|
472 | {
|
---|
473 | xml::NodesLoop nl1(elmDeviceFilters, "DeviceFilter");
|
---|
474 | const xml::ElementNode *pelmLevel4Child;
|
---|
475 | while ((pelmLevel4Child = nl1.forAllNodes()))
|
---|
476 | {
|
---|
477 | USBDeviceFilter flt;
|
---|
478 | flt.action = USBDeviceFilterAction_Ignore;
|
---|
479 | Utf8Str strAction;
|
---|
480 | if ( (pelmLevel4Child->getAttributeValue("name", flt.strName))
|
---|
481 | && (pelmLevel4Child->getAttributeValue("active", flt.fActive))
|
---|
482 | )
|
---|
483 | {
|
---|
484 | if (!pelmLevel4Child->getAttributeValue("vendorId", flt.strVendorId))
|
---|
485 | pelmLevel4Child->getAttributeValue("vendorid", flt.strVendorId); // used before 1.3
|
---|
486 | if (!pelmLevel4Child->getAttributeValue("productId", flt.strProductId))
|
---|
487 | pelmLevel4Child->getAttributeValue("productid", flt.strProductId); // used before 1.3
|
---|
488 | pelmLevel4Child->getAttributeValue("revision", flt.strRevision);
|
---|
489 | pelmLevel4Child->getAttributeValue("manufacturer", flt.strManufacturer);
|
---|
490 | pelmLevel4Child->getAttributeValue("product", flt.strProduct);
|
---|
491 | if (!pelmLevel4Child->getAttributeValue("serialNumber", flt.strSerialNumber))
|
---|
492 | pelmLevel4Child->getAttributeValue("serialnumber", flt.strSerialNumber); // used before 1.3
|
---|
493 | pelmLevel4Child->getAttributeValue("port", flt.strPort);
|
---|
494 |
|
---|
495 | // the next 2 are irrelevant for host USB objects
|
---|
496 | pelmLevel4Child->getAttributeValue("remote", flt.strRemote);
|
---|
497 | pelmLevel4Child->getAttributeValue("maskedInterfaces", flt.ulMaskedInterfaces);
|
---|
498 |
|
---|
499 | // action is only used with host USB objects
|
---|
500 | if (pelmLevel4Child->getAttributeValue("action", strAction))
|
---|
501 | {
|
---|
502 | if (strAction == "Ignore")
|
---|
503 | flt.action = USBDeviceFilterAction_Ignore;
|
---|
504 | else if (strAction == "Hold")
|
---|
505 | flt.action = USBDeviceFilterAction_Hold;
|
---|
506 | else
|
---|
507 | throw ConfigFileError(this, pelmLevel4Child, N_("Invalid value '%s' in DeviceFilter/@action attribute"), strAction.c_str());
|
---|
508 | }
|
---|
509 |
|
---|
510 | ll.push_back(flt);
|
---|
511 | }
|
---|
512 | }
|
---|
513 | }
|
---|
514 |
|
---|
515 | /**
|
---|
516 | * Creates a new stub xml::Document in the m->pDoc member with the
|
---|
517 | * root "VirtualBox" element set up. This is used by both
|
---|
518 | * MainConfigFile and MachineConfigFile at the beginning of writing
|
---|
519 | * out their XML.
|
---|
520 | *
|
---|
521 | * Before calling this, it is the responsibility of the caller to
|
---|
522 | * set the "sv" member to the required settings version that is to
|
---|
523 | * be written. For newly created files, the settings version will be
|
---|
524 | * the latest (1.9); for files read in from disk earlier, it will be
|
---|
525 | * the settings version indicated in the file. However, this method
|
---|
526 | * will silently make sure that the settings version is always
|
---|
527 | * at least 1.7 and change it if necessary, since there is no write
|
---|
528 | * support for earlier settings versions.
|
---|
529 | */
|
---|
530 | void ConfigFileBase::createStubDocument()
|
---|
531 | {
|
---|
532 | Assert(m->pDoc == NULL);
|
---|
533 | m->pDoc = new xml::Document;
|
---|
534 |
|
---|
535 | m->pelmRoot = m->pDoc->createRootElement("VirtualBox");
|
---|
536 | m->pelmRoot->setAttribute("xmlns", VBOX_XML_NAMESPACE);
|
---|
537 |
|
---|
538 | const char *pcszVersion = NULL;
|
---|
539 | switch (m->sv)
|
---|
540 | {
|
---|
541 | case SettingsVersion_v1_8:
|
---|
542 | pcszVersion = "1.8";
|
---|
543 | break;
|
---|
544 |
|
---|
545 | case SettingsVersion_v1_9:
|
---|
546 | case SettingsVersion_Future: // can be set if this code runs on XML files that were created by a future version of VBox;
|
---|
547 | // in that case, downgrade to current version when writing since we can't write future versions...
|
---|
548 | pcszVersion = "1.9";
|
---|
549 | m->sv = SettingsVersion_v1_9;
|
---|
550 | break;
|
---|
551 |
|
---|
552 | default:
|
---|
553 | // silently upgrade if this is less than 1.7 because that's the oldest we can write
|
---|
554 | pcszVersion = "1.7";
|
---|
555 | m->sv = SettingsVersion_v1_7;
|
---|
556 | break;
|
---|
557 | }
|
---|
558 |
|
---|
559 | m->pelmRoot->setAttribute("version", Utf8StrFmt("%s-%s",
|
---|
560 | pcszVersion,
|
---|
561 | VBOX_XML_PLATFORM)); // e.g. "linux"
|
---|
562 |
|
---|
563 | // since this gets called before the XML document is actually written out
|
---|
564 | // do this, this is where we must check whether we're upgrading the settings
|
---|
565 | // version and need to make a backup, so the user can go back to an earlier
|
---|
566 | // VirtualBox version and recover his old settings files.
|
---|
567 | if ( (m->svRead != SettingsVersion_Null) // old file exists?
|
---|
568 | && (m->svRead < m->sv) // we're upgrading?
|
---|
569 | )
|
---|
570 | {
|
---|
571 | // compose new filename: strip off trailing ".xml"
|
---|
572 | Utf8Str strFilenameNew = m->strFilename.substr(0, m->strFilename.length() - 4);
|
---|
573 | // and append something likd "-1.3-linux.xml"
|
---|
574 | strFilenameNew.append("-");
|
---|
575 | strFilenameNew.append(m->strSettingsVersionFull); // e.g. "1.3-linux"
|
---|
576 | strFilenameNew.append(".xml");
|
---|
577 |
|
---|
578 | RTFileMove(m->strFilename.c_str(),
|
---|
579 | strFilenameNew.c_str(),
|
---|
580 | 0); // no RTFILEMOVE_FLAGS_REPLACE
|
---|
581 |
|
---|
582 | // do this only once
|
---|
583 | m->svRead = SettingsVersion_Null;
|
---|
584 | }
|
---|
585 | }
|
---|
586 |
|
---|
587 | /**
|
---|
588 | * Creates an <ExtraData> node under the given parent element with
|
---|
589 | * <ExtraDataItem> childern according to the contents of the given
|
---|
590 | * map.
|
---|
591 | * This is in ConfigFileBase because it's used in both MainConfigFile
|
---|
592 | * MachineConfigFile, which both can have extradata.
|
---|
593 | *
|
---|
594 | * @param elmParent
|
---|
595 | * @param me
|
---|
596 | */
|
---|
597 | void ConfigFileBase::writeExtraData(xml::ElementNode &elmParent,
|
---|
598 | const ExtraDataItemsMap &me)
|
---|
599 | {
|
---|
600 | if (me.size())
|
---|
601 | {
|
---|
602 | xml::ElementNode *pelmExtraData = elmParent.createChild("ExtraData");
|
---|
603 | for (ExtraDataItemsMap::const_iterator it = me.begin();
|
---|
604 | it != me.end();
|
---|
605 | ++it)
|
---|
606 | {
|
---|
607 | const Utf8Str &strName = it->first;
|
---|
608 | const Utf8Str &strValue = it->second;
|
---|
609 | xml::ElementNode *pelmThis = pelmExtraData->createChild("ExtraDataItem");
|
---|
610 | pelmThis->setAttribute("name", strName);
|
---|
611 | pelmThis->setAttribute("value", strValue);
|
---|
612 | }
|
---|
613 | }
|
---|
614 | }
|
---|
615 |
|
---|
616 | /**
|
---|
617 | * Creates <DeviceFilter> nodes under the given parent element according to
|
---|
618 | * the contents of the given USBDeviceFiltersList. This is in ConfigFileBase
|
---|
619 | * because it's used in both MainConfigFile (for host filters) and
|
---|
620 | * MachineConfigFile (for machine filters).
|
---|
621 | *
|
---|
622 | * If fHostMode is true, this means that we're supposed to write filters
|
---|
623 | * for the IHost interface (respect "action", omit "strRemote" and
|
---|
624 | * "ulMaskedInterfaces" in struct USBDeviceFilter).
|
---|
625 | *
|
---|
626 | * @param elmParent
|
---|
627 | * @param ll
|
---|
628 | * @param fHostMode
|
---|
629 | */
|
---|
630 | void ConfigFileBase::writeUSBDeviceFilters(xml::ElementNode &elmParent,
|
---|
631 | const USBDeviceFiltersList &ll,
|
---|
632 | bool fHostMode)
|
---|
633 | {
|
---|
634 | for (USBDeviceFiltersList::const_iterator it = ll.begin();
|
---|
635 | it != ll.end();
|
---|
636 | ++it)
|
---|
637 | {
|
---|
638 | const USBDeviceFilter &flt = *it;
|
---|
639 | xml::ElementNode *pelmFilter = elmParent.createChild("DeviceFilter");
|
---|
640 | pelmFilter->setAttribute("name", flt.strName);
|
---|
641 | pelmFilter->setAttribute("active", flt.fActive);
|
---|
642 | if (flt.strVendorId.length())
|
---|
643 | pelmFilter->setAttribute("vendorId", flt.strVendorId);
|
---|
644 | if (flt.strProductId.length())
|
---|
645 | pelmFilter->setAttribute("productId", flt.strProductId);
|
---|
646 | if (flt.strRevision.length())
|
---|
647 | pelmFilter->setAttribute("revision", flt.strRevision);
|
---|
648 | if (flt.strManufacturer.length())
|
---|
649 | pelmFilter->setAttribute("manufacturer", flt.strManufacturer);
|
---|
650 | if (flt.strProduct.length())
|
---|
651 | pelmFilter->setAttribute("product", flt.strProduct);
|
---|
652 | if (flt.strSerialNumber.length())
|
---|
653 | pelmFilter->setAttribute("serialNumber", flt.strSerialNumber);
|
---|
654 | if (flt.strPort.length())
|
---|
655 | pelmFilter->setAttribute("port", flt.strPort);
|
---|
656 |
|
---|
657 | if (fHostMode)
|
---|
658 | {
|
---|
659 | const char *pcsz =
|
---|
660 | (flt.action == USBDeviceFilterAction_Ignore) ? "Ignore"
|
---|
661 | : /*(flt.action == USBDeviceFilterAction_Hold) ?*/ "Hold";
|
---|
662 | pelmFilter->setAttribute("action", pcsz);
|
---|
663 | }
|
---|
664 | else
|
---|
665 | {
|
---|
666 | if (flt.strRemote.length())
|
---|
667 | pelmFilter->setAttribute("remote", flt.strRemote);
|
---|
668 | if (flt.ulMaskedInterfaces)
|
---|
669 | pelmFilter->setAttribute("maskedInterfaces", flt.ulMaskedInterfaces);
|
---|
670 | }
|
---|
671 | }
|
---|
672 | }
|
---|
673 |
|
---|
674 | /**
|
---|
675 | * Cleans up memory allocated by the internal XML parser. To be called by
|
---|
676 | * descendant classes when they're done analyzing the DOM tree to discard it.
|
---|
677 | */
|
---|
678 | void ConfigFileBase::clearDocument()
|
---|
679 | {
|
---|
680 | m->cleanup();
|
---|
681 | }
|
---|
682 |
|
---|
683 | /**
|
---|
684 | * Returns true only if the underlying config file exists on disk;
|
---|
685 | * either because the file has been loaded from disk, or it's been written
|
---|
686 | * to disk, or both.
|
---|
687 | * @return
|
---|
688 | */
|
---|
689 | bool ConfigFileBase::fileExists()
|
---|
690 | {
|
---|
691 | return m->fFileExists;
|
---|
692 | }
|
---|
693 |
|
---|
694 |
|
---|
695 | ////////////////////////////////////////////////////////////////////////////////
|
---|
696 | //
|
---|
697 | // MainConfigFile
|
---|
698 | //
|
---|
699 | ////////////////////////////////////////////////////////////////////////////////
|
---|
700 |
|
---|
701 | /**
|
---|
702 | * Reads one <MachineEntry> from the main VirtualBox.xml file.
|
---|
703 | * @param elmMachineRegistry
|
---|
704 | */
|
---|
705 | void MainConfigFile::readMachineRegistry(const xml::ElementNode &elmMachineRegistry)
|
---|
706 | {
|
---|
707 | // <MachineEntry uuid="{ xxx }" src=" xxx "/>
|
---|
708 | xml::NodesLoop nl1(elmMachineRegistry);
|
---|
709 | const xml::ElementNode *pelmChild1;
|
---|
710 | while ((pelmChild1 = nl1.forAllNodes()))
|
---|
711 | {
|
---|
712 | if (pelmChild1->nameEquals("MachineEntry"))
|
---|
713 | {
|
---|
714 | MachineRegistryEntry mre;
|
---|
715 | Utf8Str strUUID;
|
---|
716 | if ( ((pelmChild1->getAttributeValue("uuid", strUUID)))
|
---|
717 | && ((pelmChild1->getAttributeValue("src", mre.strSettingsFile)))
|
---|
718 | )
|
---|
719 | {
|
---|
720 | parseUUID(mre.uuid, strUUID);
|
---|
721 | llMachines.push_back(mre);
|
---|
722 | }
|
---|
723 | else
|
---|
724 | throw ConfigFileError(this, pelmChild1, N_("Required MachineEntry/@uuid or @src attribute is missing"));
|
---|
725 | }
|
---|
726 | }
|
---|
727 | }
|
---|
728 |
|
---|
729 | /**
|
---|
730 | * Reads a media registry entry from the main VirtualBox.xml file.
|
---|
731 | *
|
---|
732 | * Whereas the current media registry code is fairly straightforward, it was quite a mess
|
---|
733 | * with settings format before 1.4 (VirtualBox 2.0 used settings format 1.3). The elements
|
---|
734 | * in the media registry were much more inconsistent, and different elements were used
|
---|
735 | * depending on the type of device and image.
|
---|
736 | *
|
---|
737 | * @param t
|
---|
738 | * @param elmMedium
|
---|
739 | * @param llMedia
|
---|
740 | */
|
---|
741 | void MainConfigFile::readMedium(MediaType t,
|
---|
742 | const xml::ElementNode &elmMedium, // HardDisk node if root; if recursing,
|
---|
743 | // child HardDisk node or DiffHardDisk node for pre-1.4
|
---|
744 | MediaList &llMedia) // list to append medium to (root disk or child list)
|
---|
745 | {
|
---|
746 | // <HardDisk uuid="{5471ecdb-1ddb-4012-a801-6d98e226868b}" location="/mnt/innotek-unix/vdis/Windows XP.vdi" format="VDI" type="Normal">
|
---|
747 | settings::Medium med;
|
---|
748 | Utf8Str strUUID;
|
---|
749 | if (!(elmMedium.getAttributeValue("uuid", strUUID)))
|
---|
750 | throw ConfigFileError(this, &elmMedium, N_("Required %s/@uuid attribute is missing"), elmMedium.getName());
|
---|
751 |
|
---|
752 | parseUUID(med.uuid, strUUID);
|
---|
753 |
|
---|
754 | bool fNeedsLocation = true;
|
---|
755 |
|
---|
756 | if (t == HardDisk)
|
---|
757 | {
|
---|
758 | if (m->sv < SettingsVersion_v1_4)
|
---|
759 | {
|
---|
760 | // here the system is:
|
---|
761 | // <HardDisk uuid="{....}" type="normal">
|
---|
762 | // <VirtualDiskImage filePath="/path/to/xxx.vdi"/>
|
---|
763 | // </HardDisk>
|
---|
764 |
|
---|
765 | fNeedsLocation = false;
|
---|
766 | bool fNeedsFilePath = true;
|
---|
767 | const xml::ElementNode *pelmImage;
|
---|
768 | if ((pelmImage = elmMedium.findChildElement("VirtualDiskImage")))
|
---|
769 | med.strFormat = "VDI";
|
---|
770 | else if ((pelmImage = elmMedium.findChildElement("VMDKImage")))
|
---|
771 | med.strFormat = "VMDK";
|
---|
772 | else if ((pelmImage = elmMedium.findChildElement("VHDImage")))
|
---|
773 | med.strFormat = "VHD";
|
---|
774 | else if ((pelmImage = elmMedium.findChildElement("ISCSIHardDisk")))
|
---|
775 | {
|
---|
776 | med.strFormat = "iSCSI";
|
---|
777 |
|
---|
778 | fNeedsFilePath = false;
|
---|
779 | // location is special here: current settings specify an "iscsi://user@server:port/target/lun"
|
---|
780 | // string for the location and also have several disk properties for these, whereas this used
|
---|
781 | // to be hidden in several sub-elements before 1.4, so compose a location string and set up
|
---|
782 | // the properties:
|
---|
783 | med.strLocation = "iscsi://";
|
---|
784 | Utf8Str strUser, strServer, strPort, strTarget, strLun;
|
---|
785 | if (pelmImage->getAttributeValue("userName", strUser))
|
---|
786 | {
|
---|
787 | med.strLocation.append(strUser);
|
---|
788 | med.strLocation.append("@");
|
---|
789 | }
|
---|
790 | Utf8Str strServerAndPort;
|
---|
791 | if (pelmImage->getAttributeValue("server", strServer))
|
---|
792 | {
|
---|
793 | strServerAndPort = strServer;
|
---|
794 | }
|
---|
795 | if (pelmImage->getAttributeValue("port", strPort))
|
---|
796 | {
|
---|
797 | if (strServerAndPort.length())
|
---|
798 | strServerAndPort.append(":");
|
---|
799 | strServerAndPort.append(strPort);
|
---|
800 | }
|
---|
801 | med.strLocation.append(strServerAndPort);
|
---|
802 | if (pelmImage->getAttributeValue("target", strTarget))
|
---|
803 | {
|
---|
804 | med.strLocation.append("/");
|
---|
805 | med.strLocation.append(strTarget);
|
---|
806 | }
|
---|
807 | if (pelmImage->getAttributeValue("lun", strLun))
|
---|
808 | {
|
---|
809 | med.strLocation.append("/");
|
---|
810 | med.strLocation.append(strLun);
|
---|
811 | }
|
---|
812 |
|
---|
813 | if (strServer.length() && strPort.length())
|
---|
814 | med.properties["TargetAddress"] = strServerAndPort;
|
---|
815 | if (strTarget.length())
|
---|
816 | med.properties["TargetName"] = strTarget;
|
---|
817 | if (strUser.length())
|
---|
818 | med.properties["InitiatorUsername"] = strUser;
|
---|
819 | Utf8Str strPassword;
|
---|
820 | if (pelmImage->getAttributeValue("password", strPassword))
|
---|
821 | med.properties["InitiatorSecret"] = strPassword;
|
---|
822 | if (strLun.length())
|
---|
823 | med.properties["LUN"] = strLun;
|
---|
824 | }
|
---|
825 | else if ((pelmImage = elmMedium.findChildElement("CustomHardDisk")))
|
---|
826 | {
|
---|
827 | fNeedsFilePath = false;
|
---|
828 | fNeedsLocation = true;
|
---|
829 | // also requires @format attribute, which will be queried below
|
---|
830 | }
|
---|
831 | else
|
---|
832 | throw ConfigFileError(this, &elmMedium, N_("Required %s/VirtualDiskImage element is missing"), elmMedium.getName());
|
---|
833 |
|
---|
834 | if (fNeedsFilePath)
|
---|
835 | if (!(pelmImage->getAttributeValue("filePath", med.strLocation)))
|
---|
836 | throw ConfigFileError(this, &elmMedium, N_("Required %s/@filePath attribute is missing"), elmMedium.getName());
|
---|
837 | }
|
---|
838 |
|
---|
839 | if (med.strFormat.isEmpty()) // not set with 1.4 format above, or 1.4 Custom format?
|
---|
840 | if (!(elmMedium.getAttributeValue("format", med.strFormat)))
|
---|
841 | throw ConfigFileError(this, &elmMedium, N_("Required %s/@format attribute is missing"), elmMedium.getName());
|
---|
842 |
|
---|
843 | if (!(elmMedium.getAttributeValue("autoReset", med.fAutoReset)))
|
---|
844 | med.fAutoReset = false;
|
---|
845 |
|
---|
846 | Utf8Str strType;
|
---|
847 | if ((elmMedium.getAttributeValue("type", strType)))
|
---|
848 | {
|
---|
849 | // pre-1.4 used lower case, so make this case-insensitive
|
---|
850 | strType.toUpper();
|
---|
851 | if (strType == "NORMAL")
|
---|
852 | med.hdType = MediumType_Normal;
|
---|
853 | else if (strType == "IMMUTABLE")
|
---|
854 | med.hdType = MediumType_Immutable;
|
---|
855 | else if (strType == "WRITETHROUGH")
|
---|
856 | med.hdType = MediumType_Writethrough;
|
---|
857 | else
|
---|
858 | throw ConfigFileError(this, &elmMedium, N_("HardDisk/@type attribute must be one of Normal, Immutable or Writethrough"));
|
---|
859 | }
|
---|
860 | }
|
---|
861 | else if (m->sv < SettingsVersion_v1_4)
|
---|
862 | {
|
---|
863 | // DVD and floppy images before 1.4 had "src" attribute instead of "location"
|
---|
864 | if (!(elmMedium.getAttributeValue("src", med.strLocation)))
|
---|
865 | throw ConfigFileError(this, &elmMedium, N_("Required %s/@src attribute is missing"), elmMedium.getName());
|
---|
866 |
|
---|
867 | fNeedsLocation = false;
|
---|
868 | }
|
---|
869 |
|
---|
870 | if (fNeedsLocation)
|
---|
871 | // current files and 1.4 CustomHardDisk elements must have a location attribute
|
---|
872 | if (!(elmMedium.getAttributeValue("location", med.strLocation)))
|
---|
873 | throw ConfigFileError(this, &elmMedium, N_("Required %s/@location attribute is missing"), elmMedium.getName());
|
---|
874 |
|
---|
875 | elmMedium.getAttributeValue("Description", med.strDescription); // optional
|
---|
876 |
|
---|
877 | // recurse to handle children
|
---|
878 | xml::NodesLoop nl2(elmMedium);
|
---|
879 | const xml::ElementNode *pelmHDChild;
|
---|
880 | while ((pelmHDChild = nl2.forAllNodes()))
|
---|
881 | {
|
---|
882 | if ( t == HardDisk
|
---|
883 | && ( pelmHDChild->nameEquals("HardDisk")
|
---|
884 | || ( (m->sv < SettingsVersion_v1_4)
|
---|
885 | && (pelmHDChild->nameEquals("DiffHardDisk"))
|
---|
886 | )
|
---|
887 | )
|
---|
888 | )
|
---|
889 | // recurse with this element and push the child onto our current children list
|
---|
890 | readMedium(t,
|
---|
891 | *pelmHDChild,
|
---|
892 | med.llChildren);
|
---|
893 | else if (pelmHDChild->nameEquals("Property"))
|
---|
894 | {
|
---|
895 | Utf8Str strPropName, strPropValue;
|
---|
896 | if ( (pelmHDChild->getAttributeValue("name", strPropName))
|
---|
897 | && (pelmHDChild->getAttributeValue("value", strPropValue))
|
---|
898 | )
|
---|
899 | med.properties[strPropName] = strPropValue;
|
---|
900 | else
|
---|
901 | throw ConfigFileError(this, pelmHDChild, N_("Required HardDisk/Property/@name or @value attribute is missing"));
|
---|
902 | }
|
---|
903 | }
|
---|
904 |
|
---|
905 | llMedia.push_back(med);
|
---|
906 | }
|
---|
907 |
|
---|
908 | /**
|
---|
909 | * Reads in the entire <MediaRegistry> chunk. For pre-1.4 files, this gets called
|
---|
910 | * with the <DiskRegistry> chunk instead.
|
---|
911 | * @param elmMediaRegistry
|
---|
912 | */
|
---|
913 | void MainConfigFile::readMediaRegistry(const xml::ElementNode &elmMediaRegistry)
|
---|
914 | {
|
---|
915 | xml::NodesLoop nl1(elmMediaRegistry);
|
---|
916 | const xml::ElementNode *pelmChild1;
|
---|
917 | while ((pelmChild1 = nl1.forAllNodes()))
|
---|
918 | {
|
---|
919 | MediaType t = Error;
|
---|
920 | if (pelmChild1->nameEquals("HardDisks"))
|
---|
921 | t = HardDisk;
|
---|
922 | else if (pelmChild1->nameEquals("DVDImages"))
|
---|
923 | t = DVDImage;
|
---|
924 | else if (pelmChild1->nameEquals("FloppyImages"))
|
---|
925 | t = FloppyImage;
|
---|
926 | else
|
---|
927 | continue;
|
---|
928 |
|
---|
929 | xml::NodesLoop nl2(*pelmChild1);
|
---|
930 | const xml::ElementNode *pelmMedium;
|
---|
931 | while ((pelmMedium = nl2.forAllNodes()))
|
---|
932 | {
|
---|
933 | if ( t == HardDisk
|
---|
934 | && (pelmMedium->nameEquals("HardDisk"))
|
---|
935 | )
|
---|
936 | readMedium(t,
|
---|
937 | *pelmMedium,
|
---|
938 | llHardDisks); // list to append hard disk data to: the root list
|
---|
939 | else if ( t == DVDImage
|
---|
940 | && (pelmMedium->nameEquals("Image"))
|
---|
941 | )
|
---|
942 | readMedium(t,
|
---|
943 | *pelmMedium,
|
---|
944 | llDvdImages); // list to append dvd images to: the root list
|
---|
945 | else if ( t == FloppyImage
|
---|
946 | && (pelmMedium->nameEquals("Image"))
|
---|
947 | )
|
---|
948 | readMedium(t,
|
---|
949 | *pelmMedium,
|
---|
950 | llFloppyImages); // list to append floppy images to: the root list
|
---|
951 | }
|
---|
952 | }
|
---|
953 | }
|
---|
954 |
|
---|
955 | /**
|
---|
956 | * Reads in the <DHCPServers> chunk.
|
---|
957 | * @param elmDHCPServers
|
---|
958 | */
|
---|
959 | void MainConfigFile::readDHCPServers(const xml::ElementNode &elmDHCPServers)
|
---|
960 | {
|
---|
961 | xml::NodesLoop nl1(elmDHCPServers);
|
---|
962 | const xml::ElementNode *pelmServer;
|
---|
963 | while ((pelmServer = nl1.forAllNodes()))
|
---|
964 | {
|
---|
965 | if (pelmServer->nameEquals("DHCPServer"))
|
---|
966 | {
|
---|
967 | DHCPServer srv;
|
---|
968 | if ( (pelmServer->getAttributeValue("networkName", srv.strNetworkName))
|
---|
969 | && (pelmServer->getAttributeValue("IPAddress", srv.strIPAddress))
|
---|
970 | && (pelmServer->getAttributeValue("networkMask", srv.strIPNetworkMask))
|
---|
971 | && (pelmServer->getAttributeValue("lowerIP", srv.strIPLower))
|
---|
972 | && (pelmServer->getAttributeValue("upperIP", srv.strIPUpper))
|
---|
973 | && (pelmServer->getAttributeValue("enabled", srv.fEnabled))
|
---|
974 | )
|
---|
975 | llDhcpServers.push_back(srv);
|
---|
976 | else
|
---|
977 | throw ConfigFileError(this, pelmServer, N_("Required DHCPServer/@networkName, @IPAddress, @networkMask, @lowerIP, @upperIP or @enabled attribute is missing"));
|
---|
978 | }
|
---|
979 | }
|
---|
980 | }
|
---|
981 |
|
---|
982 | /**
|
---|
983 | * Constructor.
|
---|
984 | *
|
---|
985 | * If pstrFilename is != NULL, this reads the given settings file into the member
|
---|
986 | * variables and various substructures and lists. Otherwise, the member variables
|
---|
987 | * are initialized with default values.
|
---|
988 | *
|
---|
989 | * Throws variants of xml::Error for I/O, XML and logical content errors, which
|
---|
990 | * the caller should catch; if this constructor does not throw, then the member
|
---|
991 | * variables contain meaningful values (either from the file or defaults).
|
---|
992 | *
|
---|
993 | * @param strFilename
|
---|
994 | */
|
---|
995 | MainConfigFile::MainConfigFile(const Utf8Str *pstrFilename)
|
---|
996 | : ConfigFileBase(pstrFilename)
|
---|
997 | {
|
---|
998 | if (pstrFilename)
|
---|
999 | {
|
---|
1000 | // the ConfigFileBase constructor has loaded the XML file, so now
|
---|
1001 | // we need only analyze what is in there
|
---|
1002 | xml::NodesLoop nlRootChildren(*m->pelmRoot);
|
---|
1003 | const xml::ElementNode *pelmRootChild;
|
---|
1004 | while ((pelmRootChild = nlRootChildren.forAllNodes()))
|
---|
1005 | {
|
---|
1006 | if (pelmRootChild->nameEquals("Global"))
|
---|
1007 | {
|
---|
1008 | xml::NodesLoop nlGlobalChildren(*pelmRootChild);
|
---|
1009 | const xml::ElementNode *pelmGlobalChild;
|
---|
1010 | while ((pelmGlobalChild = nlGlobalChildren.forAllNodes()))
|
---|
1011 | {
|
---|
1012 | if (pelmGlobalChild->nameEquals("SystemProperties"))
|
---|
1013 | {
|
---|
1014 | pelmGlobalChild->getAttributeValue("defaultMachineFolder", systemProperties.strDefaultMachineFolder);
|
---|
1015 | if (!pelmGlobalChild->getAttributeValue("defaultHardDiskFolder", systemProperties.strDefaultHardDiskFolder))
|
---|
1016 | // pre-1.4 used @defaultVDIFolder instead
|
---|
1017 | pelmGlobalChild->getAttributeValue("defaultVDIFolder", systemProperties.strDefaultHardDiskFolder);
|
---|
1018 | pelmGlobalChild->getAttributeValue("defaultHardDiskFormat", systemProperties.strDefaultHardDiskFormat);
|
---|
1019 | pelmGlobalChild->getAttributeValue("remoteDisplayAuthLibrary", systemProperties.strRemoteDisplayAuthLibrary);
|
---|
1020 | pelmGlobalChild->getAttributeValue("webServiceAuthLibrary", systemProperties.strWebServiceAuthLibrary);
|
---|
1021 | pelmGlobalChild->getAttributeValue("LogHistoryCount", systemProperties.ulLogHistoryCount);
|
---|
1022 | }
|
---|
1023 | else if (pelmGlobalChild->nameEquals("ExtraData"))
|
---|
1024 | readExtraData(*pelmGlobalChild, mapExtraDataItems);
|
---|
1025 | else if (pelmGlobalChild->nameEquals("MachineRegistry"))
|
---|
1026 | readMachineRegistry(*pelmGlobalChild);
|
---|
1027 | else if ( (pelmGlobalChild->nameEquals("MediaRegistry"))
|
---|
1028 | || ( (m->sv < SettingsVersion_v1_4)
|
---|
1029 | && (pelmGlobalChild->nameEquals("DiskRegistry"))
|
---|
1030 | )
|
---|
1031 | )
|
---|
1032 | readMediaRegistry(*pelmGlobalChild);
|
---|
1033 | else if (pelmGlobalChild->nameEquals("NetserviceRegistry"))
|
---|
1034 | {
|
---|
1035 | xml::NodesLoop nlLevel4(*pelmGlobalChild);
|
---|
1036 | const xml::ElementNode *pelmLevel4Child;
|
---|
1037 | while ((pelmLevel4Child = nlLevel4.forAllNodes()))
|
---|
1038 | {
|
---|
1039 | if (pelmLevel4Child->nameEquals("DHCPServers"))
|
---|
1040 | readDHCPServers(*pelmLevel4Child);
|
---|
1041 | }
|
---|
1042 | }
|
---|
1043 | else if (pelmGlobalChild->nameEquals("USBDeviceFilters"))
|
---|
1044 | readUSBDeviceFilters(*pelmGlobalChild, host.llUSBDeviceFilters);
|
---|
1045 | }
|
---|
1046 | } // end if (pelmRootChild->nameEquals("Global"))
|
---|
1047 | }
|
---|
1048 |
|
---|
1049 | clearDocument();
|
---|
1050 | }
|
---|
1051 |
|
---|
1052 | // DHCP servers were introduced with settings version 1.7; if we're loading
|
---|
1053 | // from an older version OR this is a fresh install, then add one DHCP server
|
---|
1054 | // with default settings
|
---|
1055 | if ( (!llDhcpServers.size())
|
---|
1056 | && ( (!pstrFilename) // empty VirtualBox.xml file
|
---|
1057 | || (m->sv < SettingsVersion_v1_7) // upgrading from before 1.7
|
---|
1058 | )
|
---|
1059 | )
|
---|
1060 | {
|
---|
1061 | DHCPServer srv;
|
---|
1062 | srv.strNetworkName =
|
---|
1063 | #ifdef RT_OS_WINDOWS
|
---|
1064 | "HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter";
|
---|
1065 | #else
|
---|
1066 | "HostInterfaceNetworking-vboxnet0";
|
---|
1067 | #endif
|
---|
1068 | srv.strIPAddress = "192.168.56.100";
|
---|
1069 | srv.strIPNetworkMask = "255.255.255.0";
|
---|
1070 | srv.strIPLower = "192.168.56.101";
|
---|
1071 | srv.strIPUpper = "192.168.56.254";
|
---|
1072 | srv.fEnabled = true;
|
---|
1073 | llDhcpServers.push_back(srv);
|
---|
1074 | }
|
---|
1075 | }
|
---|
1076 |
|
---|
1077 | /**
|
---|
1078 | * Creates a single <HardDisk> element for the given Medium structure
|
---|
1079 | * and recurses to write the child hard disks underneath. Called from
|
---|
1080 | * MainConfigFile::write().
|
---|
1081 | *
|
---|
1082 | * @param elmMedium
|
---|
1083 | * @param m
|
---|
1084 | * @param level
|
---|
1085 | */
|
---|
1086 | void MainConfigFile::writeHardDisk(xml::ElementNode &elmMedium,
|
---|
1087 | const Medium &m,
|
---|
1088 | uint32_t level) // 0 for "root" call, incremented with each recursion
|
---|
1089 | {
|
---|
1090 | xml::ElementNode *pelmHardDisk = elmMedium.createChild("HardDisk");
|
---|
1091 | pelmHardDisk->setAttribute("uuid", makeString(m.uuid));
|
---|
1092 | pelmHardDisk->setAttribute("location", m.strLocation);
|
---|
1093 | pelmHardDisk->setAttribute("format", m.strFormat);
|
---|
1094 | if (m.fAutoReset)
|
---|
1095 | pelmHardDisk->setAttribute("autoReset", m.fAutoReset);
|
---|
1096 | if (m.strDescription.length())
|
---|
1097 | pelmHardDisk->setAttribute("Description", m.strDescription);
|
---|
1098 |
|
---|
1099 | for (PropertiesMap::const_iterator it = m.properties.begin();
|
---|
1100 | it != m.properties.end();
|
---|
1101 | ++it)
|
---|
1102 | {
|
---|
1103 | xml::ElementNode *pelmProp = pelmHardDisk->createChild("Property");
|
---|
1104 | pelmProp->setAttribute("name", it->first);
|
---|
1105 | pelmProp->setAttribute("value", it->second);
|
---|
1106 | }
|
---|
1107 |
|
---|
1108 | // only for base hard disks, save the type
|
---|
1109 | if (level == 0)
|
---|
1110 | {
|
---|
1111 | const char *pcszType =
|
---|
1112 | m.hdType == MediumType_Normal ? "Normal" :
|
---|
1113 | m.hdType == MediumType_Immutable ? "Immutable" :
|
---|
1114 | /*m.hdType == MediumType_Writethrough ?*/ "Writethrough";
|
---|
1115 | pelmHardDisk->setAttribute("type", pcszType);
|
---|
1116 | }
|
---|
1117 |
|
---|
1118 | for (MediaList::const_iterator it = m.llChildren.begin();
|
---|
1119 | it != m.llChildren.end();
|
---|
1120 | ++it)
|
---|
1121 | {
|
---|
1122 | // recurse for children
|
---|
1123 | writeHardDisk(*pelmHardDisk, // parent
|
---|
1124 | *it, // settings::Medium
|
---|
1125 | ++level); // recursion level
|
---|
1126 | }
|
---|
1127 | }
|
---|
1128 |
|
---|
1129 | /**
|
---|
1130 | * Called from the IVirtualBox interface to write out VirtualBox.xml. This
|
---|
1131 | * builds an XML DOM tree and writes it out to disk.
|
---|
1132 | */
|
---|
1133 | void MainConfigFile::write(const com::Utf8Str strFilename)
|
---|
1134 | {
|
---|
1135 | m->strFilename = strFilename;
|
---|
1136 | createStubDocument();
|
---|
1137 |
|
---|
1138 | xml::ElementNode *pelmGlobal = m->pelmRoot->createChild("Global");
|
---|
1139 |
|
---|
1140 | writeExtraData(*pelmGlobal, mapExtraDataItems);
|
---|
1141 |
|
---|
1142 | xml::ElementNode *pelmMachineRegistry = pelmGlobal->createChild("MachineRegistry");
|
---|
1143 | for (MachinesRegistry::const_iterator it = llMachines.begin();
|
---|
1144 | it != llMachines.end();
|
---|
1145 | ++it)
|
---|
1146 | {
|
---|
1147 | // <MachineEntry uuid="{5f102a55-a51b-48e3-b45a-b28d33469488}" src="/mnt/innotek-unix/vbox-machines/Windows 5.1 XP 1 (Office 2003)/Windows 5.1 XP 1 (Office 2003).xml"/>
|
---|
1148 | const MachineRegistryEntry &mre = *it;
|
---|
1149 | xml::ElementNode *pelmMachineEntry = pelmMachineRegistry->createChild("MachineEntry");
|
---|
1150 | pelmMachineEntry->setAttribute("uuid", makeString(mre.uuid));
|
---|
1151 | pelmMachineEntry->setAttribute("src", mre.strSettingsFile);
|
---|
1152 | }
|
---|
1153 |
|
---|
1154 | xml::ElementNode *pelmMediaRegistry = pelmGlobal->createChild("MediaRegistry");
|
---|
1155 |
|
---|
1156 | xml::ElementNode *pelmHardDisks = pelmMediaRegistry->createChild("HardDisks");
|
---|
1157 | for (MediaList::const_iterator it = llHardDisks.begin();
|
---|
1158 | it != llHardDisks.end();
|
---|
1159 | ++it)
|
---|
1160 | {
|
---|
1161 | writeHardDisk(*pelmHardDisks, *it, 0);
|
---|
1162 | }
|
---|
1163 |
|
---|
1164 | xml::ElementNode *pelmDVDImages = pelmMediaRegistry->createChild("DVDImages");
|
---|
1165 | for (MediaList::const_iterator it = llDvdImages.begin();
|
---|
1166 | it != llDvdImages.end();
|
---|
1167 | ++it)
|
---|
1168 | {
|
---|
1169 | const Medium &m = *it;
|
---|
1170 | xml::ElementNode *pelmMedium = pelmDVDImages->createChild("Image");
|
---|
1171 | pelmMedium->setAttribute("uuid", makeString(m.uuid));
|
---|
1172 | pelmMedium->setAttribute("location", m.strLocation);
|
---|
1173 | if (m.strDescription.length())
|
---|
1174 | pelmMedium->setAttribute("Description", m.strDescription);
|
---|
1175 | }
|
---|
1176 |
|
---|
1177 | xml::ElementNode *pelmFloppyImages = pelmMediaRegistry->createChild("FloppyImages");
|
---|
1178 | for (MediaList::const_iterator it = llFloppyImages.begin();
|
---|
1179 | it != llFloppyImages.end();
|
---|
1180 | ++it)
|
---|
1181 | {
|
---|
1182 | const Medium &m = *it;
|
---|
1183 | xml::ElementNode *pelmMedium = pelmFloppyImages->createChild("Image");
|
---|
1184 | pelmMedium->setAttribute("uuid", makeString(m.uuid));
|
---|
1185 | pelmMedium->setAttribute("location", m.strLocation);
|
---|
1186 | if (m.strDescription.length())
|
---|
1187 | pelmMedium->setAttribute("Description", m.strDescription);
|
---|
1188 | }
|
---|
1189 |
|
---|
1190 | xml::ElementNode *pelmNetserviceRegistry = pelmGlobal->createChild("NetserviceRegistry");
|
---|
1191 | xml::ElementNode *pelmDHCPServers = pelmNetserviceRegistry->createChild("DHCPServers");
|
---|
1192 | for (DHCPServersList::const_iterator it = llDhcpServers.begin();
|
---|
1193 | it != llDhcpServers.end();
|
---|
1194 | ++it)
|
---|
1195 | {
|
---|
1196 | const DHCPServer &d = *it;
|
---|
1197 | xml::ElementNode *pelmThis = pelmDHCPServers->createChild("DHCPServer");
|
---|
1198 | pelmThis->setAttribute("networkName", d.strNetworkName);
|
---|
1199 | pelmThis->setAttribute("IPAddress", d.strIPAddress);
|
---|
1200 | pelmThis->setAttribute("networkMask", d.strIPNetworkMask);
|
---|
1201 | pelmThis->setAttribute("lowerIP", d.strIPLower);
|
---|
1202 | pelmThis->setAttribute("upperIP", d.strIPUpper);
|
---|
1203 | pelmThis->setAttribute("enabled", (d.fEnabled) ? 1 : 0); // too bad we chose 1 vs. 0 here
|
---|
1204 | }
|
---|
1205 |
|
---|
1206 | xml::ElementNode *pelmSysProps = pelmGlobal->createChild("SystemProperties");
|
---|
1207 | if (systemProperties.strDefaultMachineFolder.length())
|
---|
1208 | pelmSysProps->setAttribute("defaultMachineFolder", systemProperties.strDefaultMachineFolder);
|
---|
1209 | if (systemProperties.strDefaultHardDiskFolder.length())
|
---|
1210 | pelmSysProps->setAttribute("defaultHardDiskFolder", systemProperties.strDefaultHardDiskFolder);
|
---|
1211 | if (systemProperties.strDefaultHardDiskFormat.length())
|
---|
1212 | pelmSysProps->setAttribute("defaultHardDiskFormat", systemProperties.strDefaultHardDiskFormat);
|
---|
1213 | if (systemProperties.strRemoteDisplayAuthLibrary.length())
|
---|
1214 | pelmSysProps->setAttribute("remoteDisplayAuthLibrary", systemProperties.strRemoteDisplayAuthLibrary);
|
---|
1215 | if (systemProperties.strWebServiceAuthLibrary.length())
|
---|
1216 | pelmSysProps->setAttribute("webServiceAuthLibrary", systemProperties.strWebServiceAuthLibrary);
|
---|
1217 | pelmSysProps->setAttribute("LogHistoryCount", systemProperties.ulLogHistoryCount);
|
---|
1218 |
|
---|
1219 | writeUSBDeviceFilters(*pelmGlobal->createChild("USBDeviceFilters"),
|
---|
1220 | host.llUSBDeviceFilters,
|
---|
1221 | true); // fHostMode
|
---|
1222 |
|
---|
1223 | // now go write the XML
|
---|
1224 | xml::XmlFileWriter writer(*m->pDoc);
|
---|
1225 | writer.write(m->strFilename.c_str());
|
---|
1226 |
|
---|
1227 | m->fFileExists = true;
|
---|
1228 |
|
---|
1229 | clearDocument();
|
---|
1230 | }
|
---|
1231 |
|
---|
1232 | // use a define for the platform-dependent default value of
|
---|
1233 | // hwvirt exclusivity, since we'll need to check that value
|
---|
1234 | // in bumpSettingsVersionIfNeeded()
|
---|
1235 | #if defined(RT_OS_DARWIN) || defined(RT_OS_WINDOWS)
|
---|
1236 | #define HWVIRTEXCLUSIVEDEFAULT false
|
---|
1237 | #else
|
---|
1238 | #define HWVIRTEXCLUSIVEDEFAULT true
|
---|
1239 | #endif
|
---|
1240 |
|
---|
1241 | /**
|
---|
1242 | * Hardware struct constructor.
|
---|
1243 | */
|
---|
1244 | Hardware::Hardware()
|
---|
1245 | : strVersion("2"),
|
---|
1246 | fHardwareVirt(true),
|
---|
1247 | fHardwareVirtExclusive(HWVIRTEXCLUSIVEDEFAULT),
|
---|
1248 | fNestedPaging(false),
|
---|
1249 | fVPID(false),
|
---|
1250 | fSyntheticCpu(false),
|
---|
1251 | fPAE(false),
|
---|
1252 | cCPUs(1),
|
---|
1253 | ulMemorySizeMB((uint32_t)-1),
|
---|
1254 | ulVRAMSizeMB(8),
|
---|
1255 | cMonitors(1),
|
---|
1256 | fAccelerate3D(false),
|
---|
1257 | fAccelerate2DVideo(false),
|
---|
1258 | firmwareType(FirmwareType_BIOS),
|
---|
1259 | clipboardMode(ClipboardMode_Bidirectional),
|
---|
1260 | ulMemoryBalloonSize(0),
|
---|
1261 | ulStatisticsUpdateInterval(0)
|
---|
1262 | {
|
---|
1263 | mapBootOrder[0] = DeviceType_Floppy;
|
---|
1264 | mapBootOrder[1] = DeviceType_DVD;
|
---|
1265 | mapBootOrder[2] = DeviceType_HardDisk;
|
---|
1266 | }
|
---|
1267 |
|
---|
1268 | /**
|
---|
1269 | * Called from MachineConfigFile::readHardware() to cpuid information.
|
---|
1270 | * @param elmCpuid
|
---|
1271 | * @param ll
|
---|
1272 | */
|
---|
1273 | void MachineConfigFile::readCpuIdTree(const xml::ElementNode &elmCpuid,
|
---|
1274 | CpuIdLeafsList &ll)
|
---|
1275 | {
|
---|
1276 | xml::NodesLoop nl1(elmCpuid, "CpuId");
|
---|
1277 | const xml::ElementNode *pelmCpuIdLeaf;
|
---|
1278 | while ((pelmCpuIdLeaf = nl1.forAllNodes()))
|
---|
1279 | {
|
---|
1280 | CpuIdLeaf leaf;
|
---|
1281 |
|
---|
1282 | if (!pelmCpuIdLeaf->getAttributeValue("id", leaf.ulId))
|
---|
1283 | throw ConfigFileError(this, pelmCpuIdLeaf, N_("Required CpuId/@id attribute is missing"));
|
---|
1284 |
|
---|
1285 | pelmCpuIdLeaf->getAttributeValue("eax", leaf.ulEax);
|
---|
1286 | pelmCpuIdLeaf->getAttributeValue("ebx", leaf.ulEbx);
|
---|
1287 | pelmCpuIdLeaf->getAttributeValue("ecx", leaf.ulEcx);
|
---|
1288 | pelmCpuIdLeaf->getAttributeValue("edx", leaf.ulEdx);
|
---|
1289 |
|
---|
1290 | ll.push_back(leaf);
|
---|
1291 | }
|
---|
1292 | }
|
---|
1293 |
|
---|
1294 | /**
|
---|
1295 | * Called from MachineConfigFile::readHardware() to network information.
|
---|
1296 | * @param elmNetwork
|
---|
1297 | * @param ll
|
---|
1298 | */
|
---|
1299 | void MachineConfigFile::readNetworkAdapters(const xml::ElementNode &elmNetwork,
|
---|
1300 | NetworkAdaptersList &ll)
|
---|
1301 | {
|
---|
1302 | xml::NodesLoop nl1(elmNetwork, "Adapter");
|
---|
1303 | const xml::ElementNode *pelmAdapter;
|
---|
1304 | while ((pelmAdapter = nl1.forAllNodes()))
|
---|
1305 | {
|
---|
1306 | NetworkAdapter nic;
|
---|
1307 |
|
---|
1308 | if (!pelmAdapter->getAttributeValue("slot", nic.ulSlot))
|
---|
1309 | throw ConfigFileError(this, pelmAdapter, N_("Required Adapter/@slot attribute is missing"));
|
---|
1310 |
|
---|
1311 | Utf8Str strTemp;
|
---|
1312 | if (pelmAdapter->getAttributeValue("type", strTemp))
|
---|
1313 | {
|
---|
1314 | if (strTemp == "Am79C970A")
|
---|
1315 | nic.type = NetworkAdapterType_Am79C970A;
|
---|
1316 | else if (strTemp == "Am79C973")
|
---|
1317 | nic.type = NetworkAdapterType_Am79C973;
|
---|
1318 | else if (strTemp == "82540EM")
|
---|
1319 | nic.type = NetworkAdapterType_I82540EM;
|
---|
1320 | else if (strTemp == "82543GC")
|
---|
1321 | nic.type = NetworkAdapterType_I82543GC;
|
---|
1322 | else if (strTemp == "82545EM")
|
---|
1323 | nic.type = NetworkAdapterType_I82545EM;
|
---|
1324 | else if (strTemp == "virtio")
|
---|
1325 | nic.type = NetworkAdapterType_Virtio;
|
---|
1326 | else
|
---|
1327 | throw ConfigFileError(this, pelmAdapter, N_("Invalid value '%s' in Adapter/@type attribute"), strTemp.c_str());
|
---|
1328 | }
|
---|
1329 |
|
---|
1330 | pelmAdapter->getAttributeValue("enabled", nic.fEnabled);
|
---|
1331 | pelmAdapter->getAttributeValue("MACAddress", nic.strMACAddress);
|
---|
1332 | pelmAdapter->getAttributeValue("cable", nic.fCableConnected);
|
---|
1333 | pelmAdapter->getAttributeValue("speed", nic.ulLineSpeed);
|
---|
1334 | pelmAdapter->getAttributeValue("trace", nic.fTraceEnabled);
|
---|
1335 | pelmAdapter->getAttributeValue("tracefile", nic.strTraceFile);
|
---|
1336 |
|
---|
1337 | const xml::ElementNode *pelmAdapterChild;
|
---|
1338 | if ((pelmAdapterChild = pelmAdapter->findChildElement("NAT")))
|
---|
1339 | {
|
---|
1340 | nic.mode = NetworkAttachmentType_NAT;
|
---|
1341 | pelmAdapterChild->getAttributeValue("name", nic.strName); // optional network name
|
---|
1342 | }
|
---|
1343 | else if ( ((pelmAdapterChild = pelmAdapter->findChildElement("HostInterface")))
|
---|
1344 | || ((pelmAdapterChild = pelmAdapter->findChildElement("BridgedInterface")))
|
---|
1345 | )
|
---|
1346 | {
|
---|
1347 | nic.mode = NetworkAttachmentType_Bridged;
|
---|
1348 | pelmAdapterChild->getAttributeValue("name", nic.strName); // optional host interface name
|
---|
1349 | }
|
---|
1350 | else if ((pelmAdapterChild = pelmAdapter->findChildElement("InternalNetwork")))
|
---|
1351 | {
|
---|
1352 | nic.mode = NetworkAttachmentType_Internal;
|
---|
1353 | if (!pelmAdapterChild->getAttributeValue("name", nic.strName)) // required network name
|
---|
1354 | throw ConfigFileError(this, pelmAdapterChild, N_("Required InternalNetwork/@name element is missing"));
|
---|
1355 | }
|
---|
1356 | else if ((pelmAdapterChild = pelmAdapter->findChildElement("HostOnlyInterface")))
|
---|
1357 | {
|
---|
1358 | nic.mode = NetworkAttachmentType_HostOnly;
|
---|
1359 | if (!pelmAdapterChild->getAttributeValue("name", nic.strName)) // required network name
|
---|
1360 | throw ConfigFileError(this, pelmAdapterChild, N_("Required HostOnlyInterface/@name element is missing"));
|
---|
1361 | }
|
---|
1362 | // else: default is NetworkAttachmentType_Null
|
---|
1363 |
|
---|
1364 | ll.push_back(nic);
|
---|
1365 | }
|
---|
1366 | }
|
---|
1367 |
|
---|
1368 | /**
|
---|
1369 | * Called from MachineConfigFile::readHardware() to read serial port information.
|
---|
1370 | * @param elmUART
|
---|
1371 | * @param ll
|
---|
1372 | */
|
---|
1373 | void MachineConfigFile::readSerialPorts(const xml::ElementNode &elmUART,
|
---|
1374 | SerialPortsList &ll)
|
---|
1375 | {
|
---|
1376 | xml::NodesLoop nl1(elmUART, "Port");
|
---|
1377 | const xml::ElementNode *pelmPort;
|
---|
1378 | while ((pelmPort = nl1.forAllNodes()))
|
---|
1379 | {
|
---|
1380 | SerialPort port;
|
---|
1381 | if (!pelmPort->getAttributeValue("slot", port.ulSlot))
|
---|
1382 | throw ConfigFileError(this, pelmPort, N_("Required UART/Port/@slot attribute is missing"));
|
---|
1383 |
|
---|
1384 | // slot must be unique
|
---|
1385 | for (SerialPortsList::const_iterator it = ll.begin();
|
---|
1386 | it != ll.end();
|
---|
1387 | ++it)
|
---|
1388 | if ((*it).ulSlot == port.ulSlot)
|
---|
1389 | throw ConfigFileError(this, pelmPort, N_("Invalid value %RU32 in UART/Port/@slot attribute: value is not unique"), port.ulSlot);
|
---|
1390 |
|
---|
1391 | if (!pelmPort->getAttributeValue("enabled", port.fEnabled))
|
---|
1392 | throw ConfigFileError(this, pelmPort, N_("Required UART/Port/@enabled attribute is missing"));
|
---|
1393 | if (!pelmPort->getAttributeValue("IOBase", port.ulIOBase))
|
---|
1394 | throw ConfigFileError(this, pelmPort, N_("Required UART/Port/@IOBase attribute is missing"));
|
---|
1395 | if (!pelmPort->getAttributeValue("IRQ", port.ulIRQ))
|
---|
1396 | throw ConfigFileError(this, pelmPort, N_("Required UART/Port/@IRQ attribute is missing"));
|
---|
1397 |
|
---|
1398 | Utf8Str strPortMode;
|
---|
1399 | if (!pelmPort->getAttributeValue("hostMode", strPortMode))
|
---|
1400 | throw ConfigFileError(this, pelmPort, N_("Required UART/Port/@hostMode attribute is missing"));
|
---|
1401 | if (strPortMode == "RawFile")
|
---|
1402 | port.portMode = PortMode_RawFile;
|
---|
1403 | else if (strPortMode == "HostPipe")
|
---|
1404 | port.portMode = PortMode_HostPipe;
|
---|
1405 | else if (strPortMode == "HostDevice")
|
---|
1406 | port.portMode = PortMode_HostDevice;
|
---|
1407 | else if (strPortMode == "Disconnected")
|
---|
1408 | port.portMode = PortMode_Disconnected;
|
---|
1409 | else
|
---|
1410 | throw ConfigFileError(this, pelmPort, N_("Invalid value '%s' in UART/Port/@hostMode attribute"), strPortMode.c_str());
|
---|
1411 |
|
---|
1412 | pelmPort->getAttributeValue("path", port.strPath);
|
---|
1413 | pelmPort->getAttributeValue("server", port.fServer);
|
---|
1414 |
|
---|
1415 | ll.push_back(port);
|
---|
1416 | }
|
---|
1417 | }
|
---|
1418 |
|
---|
1419 | /**
|
---|
1420 | * Called from MachineConfigFile::readHardware() to read parallel port information.
|
---|
1421 | * @param elmLPT
|
---|
1422 | * @param ll
|
---|
1423 | */
|
---|
1424 | void MachineConfigFile::readParallelPorts(const xml::ElementNode &elmLPT,
|
---|
1425 | ParallelPortsList &ll)
|
---|
1426 | {
|
---|
1427 | xml::NodesLoop nl1(elmLPT, "Port");
|
---|
1428 | const xml::ElementNode *pelmPort;
|
---|
1429 | while ((pelmPort = nl1.forAllNodes()))
|
---|
1430 | {
|
---|
1431 | ParallelPort port;
|
---|
1432 | if (!pelmPort->getAttributeValue("slot", port.ulSlot))
|
---|
1433 | throw ConfigFileError(this, pelmPort, N_("Required LPT/Port/@slot attribute is missing"));
|
---|
1434 |
|
---|
1435 | // slot must be unique
|
---|
1436 | for (ParallelPortsList::const_iterator it = ll.begin();
|
---|
1437 | it != ll.end();
|
---|
1438 | ++it)
|
---|
1439 | if ((*it).ulSlot == port.ulSlot)
|
---|
1440 | throw ConfigFileError(this, pelmPort, N_("Invalid value %RU32 in LPT/Port/@slot attribute: value is not unique"), port.ulSlot);
|
---|
1441 |
|
---|
1442 | if (!pelmPort->getAttributeValue("enabled", port.fEnabled))
|
---|
1443 | throw ConfigFileError(this, pelmPort, N_("Required LPT/Port/@enabled attribute is missing"));
|
---|
1444 | if (!pelmPort->getAttributeValue("IOBase", port.ulIOBase))
|
---|
1445 | throw ConfigFileError(this, pelmPort, N_("Required LPT/Port/@IOBase attribute is missing"));
|
---|
1446 | if (!pelmPort->getAttributeValue("IRQ", port.ulIRQ))
|
---|
1447 | throw ConfigFileError(this, pelmPort, N_("Required LPT/Port/@IRQ attribute is missing"));
|
---|
1448 |
|
---|
1449 | pelmPort->getAttributeValue("path", port.strPath);
|
---|
1450 |
|
---|
1451 | ll.push_back(port);
|
---|
1452 | }
|
---|
1453 | }
|
---|
1454 |
|
---|
1455 | /**
|
---|
1456 | * Called from MachineConfigFile::readHardware() to read guest property information.
|
---|
1457 | * @param elmGuestProperties
|
---|
1458 | * @param hw
|
---|
1459 | */
|
---|
1460 | void MachineConfigFile::readGuestProperties(const xml::ElementNode &elmGuestProperties,
|
---|
1461 | Hardware &hw)
|
---|
1462 | {
|
---|
1463 | xml::NodesLoop nl1(elmGuestProperties, "GuestProperty");
|
---|
1464 | const xml::ElementNode *pelmProp;
|
---|
1465 | while ((pelmProp = nl1.forAllNodes()))
|
---|
1466 | {
|
---|
1467 | GuestProperty prop;
|
---|
1468 | pelmProp->getAttributeValue("name", prop.strName);
|
---|
1469 | pelmProp->getAttributeValue("value", prop.strValue);
|
---|
1470 |
|
---|
1471 | pelmProp->getAttributeValue("timestamp", prop.timestamp);
|
---|
1472 | pelmProp->getAttributeValue("flags", prop.strFlags);
|
---|
1473 | hw.llGuestProperties.push_back(prop);
|
---|
1474 | }
|
---|
1475 |
|
---|
1476 | elmGuestProperties.getAttributeValue("notificationPatterns", hw.strNotificationPatterns);
|
---|
1477 | }
|
---|
1478 |
|
---|
1479 | /**
|
---|
1480 | * Helper function to read attributes that are common to <SATAController> (pre-1.7)
|
---|
1481 | * and <StorageController>.
|
---|
1482 | * @param elmStorageController
|
---|
1483 | * @param strg
|
---|
1484 | */
|
---|
1485 | void MachineConfigFile::readStorageControllerAttributes(const xml::ElementNode &elmStorageController,
|
---|
1486 | StorageController &sctl)
|
---|
1487 | {
|
---|
1488 | elmStorageController.getAttributeValue("PortCount", sctl.ulPortCount);
|
---|
1489 | elmStorageController.getAttributeValue("IDE0MasterEmulationPort", sctl.lIDE0MasterEmulationPort);
|
---|
1490 | elmStorageController.getAttributeValue("IDE0SlaveEmulationPort", sctl.lIDE0SlaveEmulationPort);
|
---|
1491 | elmStorageController.getAttributeValue("IDE1MasterEmulationPort", sctl.lIDE1MasterEmulationPort);
|
---|
1492 | elmStorageController.getAttributeValue("IDE1SlaveEmulationPort", sctl.lIDE1SlaveEmulationPort);
|
---|
1493 | }
|
---|
1494 |
|
---|
1495 | /**
|
---|
1496 | * Reads in a <Hardware> block and stores it in the given structure. Used
|
---|
1497 | * both directly from readMachine and from readSnapshot, since snapshots
|
---|
1498 | * have their own hardware sections.
|
---|
1499 | *
|
---|
1500 | * For legacy pre-1.7 settings we also need a storage structure because
|
---|
1501 | * the IDE and SATA controllers used to be defined under <Hardware>.
|
---|
1502 | *
|
---|
1503 | * @param elmHardware
|
---|
1504 | * @param hw
|
---|
1505 | */
|
---|
1506 | void MachineConfigFile::readHardware(const xml::ElementNode &elmHardware,
|
---|
1507 | Hardware &hw,
|
---|
1508 | Storage &strg)
|
---|
1509 | {
|
---|
1510 | elmHardware.getAttributeValue("version", hw.strVersion);
|
---|
1511 | // defaults to 2 and is only written if != 2
|
---|
1512 |
|
---|
1513 | Utf8Str strUUID;
|
---|
1514 | if (elmHardware.getAttributeValue("uuid", strUUID))
|
---|
1515 | parseUUID(hw.uuid, strUUID);
|
---|
1516 |
|
---|
1517 | xml::NodesLoop nl1(elmHardware);
|
---|
1518 | const xml::ElementNode *pelmHwChild;
|
---|
1519 | while ((pelmHwChild = nl1.forAllNodes()))
|
---|
1520 | {
|
---|
1521 | if (pelmHwChild->nameEquals("CPU"))
|
---|
1522 | {
|
---|
1523 | if (!pelmHwChild->getAttributeValue("count", hw.cCPUs))
|
---|
1524 | {
|
---|
1525 | // pre-1.5 variant; not sure if this actually exists in the wild anywhere
|
---|
1526 | const xml::ElementNode *pelmCPUChild;
|
---|
1527 | if ((pelmCPUChild = pelmHwChild->findChildElement("CPUCount")))
|
---|
1528 | pelmCPUChild->getAttributeValue("count", hw.cCPUs);
|
---|
1529 | }
|
---|
1530 |
|
---|
1531 | const xml::ElementNode *pelmCPUChild;
|
---|
1532 | if ((pelmCPUChild = pelmHwChild->findChildElement("HardwareVirtEx")))
|
---|
1533 | {
|
---|
1534 | pelmCPUChild->getAttributeValue("enabled", hw.fHardwareVirt);
|
---|
1535 | pelmCPUChild->getAttributeValue("exclusive", hw.fHardwareVirtExclusive); // settings version 1.9
|
---|
1536 | }
|
---|
1537 | if ((pelmCPUChild = pelmHwChild->findChildElement("HardwareVirtExNestedPaging")))
|
---|
1538 | pelmCPUChild->getAttributeValue("enabled", hw.fNestedPaging);
|
---|
1539 | if ((pelmCPUChild = pelmHwChild->findChildElement("HardwareVirtExVPID")))
|
---|
1540 | pelmCPUChild->getAttributeValue("enabled", hw.fVPID);
|
---|
1541 | if ((pelmCPUChild = pelmHwChild->findChildElement("PAE")))
|
---|
1542 | pelmCPUChild->getAttributeValue("enabled", hw.fPAE);
|
---|
1543 | if ((pelmCPUChild = pelmHwChild->findChildElement("SyntheticCpu")))
|
---|
1544 | pelmCPUChild->getAttributeValue("enabled", hw.fSyntheticCpu);
|
---|
1545 | if ((pelmCPUChild = pelmHwChild->findChildElement("CpuIdTree")))
|
---|
1546 | readCpuIdTree(*pelmHwChild, hw.llCpuIdLeafs);
|
---|
1547 | }
|
---|
1548 | else if (pelmHwChild->nameEquals("Memory"))
|
---|
1549 | pelmHwChild->getAttributeValue("RAMSize", hw.ulMemorySizeMB);
|
---|
1550 | else if (pelmHwChild->nameEquals("Firmware"))
|
---|
1551 | {
|
---|
1552 | Utf8Str strFirmwareType;
|
---|
1553 | if (pelmHwChild->getAttributeValue("type", strFirmwareType))
|
---|
1554 | {
|
---|
1555 | if ( (strFirmwareType == "BIOS")
|
---|
1556 | || (strFirmwareType == "1") // some trunk builds used the number here
|
---|
1557 | )
|
---|
1558 | hw.firmwareType = FirmwareType_BIOS;
|
---|
1559 | else if ( (strFirmwareType == "EFI")
|
---|
1560 | || (strFirmwareType == "2") // some trunk builds used the number here
|
---|
1561 | )
|
---|
1562 | hw.firmwareType = FirmwareType_EFI;
|
---|
1563 | else
|
---|
1564 | throw ConfigFileError(this,
|
---|
1565 | pelmHwChild,
|
---|
1566 | N_("Invalid value '%s' in Boot/Firmware/@type"),
|
---|
1567 | strFirmwareType.c_str());
|
---|
1568 | }
|
---|
1569 | }
|
---|
1570 | else if (pelmHwChild->nameEquals("Boot"))
|
---|
1571 | {
|
---|
1572 | hw.mapBootOrder.clear();
|
---|
1573 |
|
---|
1574 | xml::NodesLoop nl2(*pelmHwChild, "Order");
|
---|
1575 | const xml::ElementNode *pelmOrder;
|
---|
1576 | while ((pelmOrder = nl2.forAllNodes()))
|
---|
1577 | {
|
---|
1578 | uint32_t ulPos;
|
---|
1579 | Utf8Str strDevice;
|
---|
1580 | if (!pelmOrder->getAttributeValue("position", ulPos))
|
---|
1581 | throw ConfigFileError(this, pelmOrder, N_("Required Boot/Order/@position attribute is missing"));
|
---|
1582 |
|
---|
1583 | if ( ulPos < 1
|
---|
1584 | || ulPos > SchemaDefs::MaxBootPosition
|
---|
1585 | )
|
---|
1586 | throw ConfigFileError(this,
|
---|
1587 | pelmOrder,
|
---|
1588 | N_("Invalid value '%RU32' in Boot/Order/@position: must be greater than 0 and less than %RU32"),
|
---|
1589 | ulPos,
|
---|
1590 | SchemaDefs::MaxBootPosition + 1);
|
---|
1591 | // XML is 1-based but internal data is 0-based
|
---|
1592 | --ulPos;
|
---|
1593 |
|
---|
1594 | if (hw.mapBootOrder.find(ulPos) != hw.mapBootOrder.end())
|
---|
1595 | throw ConfigFileError(this, pelmOrder, N_("Invalid value '%RU32' in Boot/Order/@position: value is not unique"), ulPos);
|
---|
1596 |
|
---|
1597 | if (!pelmOrder->getAttributeValue("device", strDevice))
|
---|
1598 | throw ConfigFileError(this, pelmOrder, N_("Required Boot/Order/@device attribute is missing"));
|
---|
1599 |
|
---|
1600 | DeviceType_T type;
|
---|
1601 | if (strDevice == "None")
|
---|
1602 | type = DeviceType_Null;
|
---|
1603 | else if (strDevice == "Floppy")
|
---|
1604 | type = DeviceType_Floppy;
|
---|
1605 | else if (strDevice == "DVD")
|
---|
1606 | type = DeviceType_DVD;
|
---|
1607 | else if (strDevice == "HardDisk")
|
---|
1608 | type = DeviceType_HardDisk;
|
---|
1609 | else if (strDevice == "Network")
|
---|
1610 | type = DeviceType_Network;
|
---|
1611 | else
|
---|
1612 | throw ConfigFileError(this, pelmOrder, N_("Invalid value '%s' in Boot/Order/@device attribute"), strDevice.c_str());
|
---|
1613 | hw.mapBootOrder[ulPos] = type;
|
---|
1614 | }
|
---|
1615 | }
|
---|
1616 | else if (pelmHwChild->nameEquals("Display"))
|
---|
1617 | {
|
---|
1618 | pelmHwChild->getAttributeValue("VRAMSize", hw.ulVRAMSizeMB);
|
---|
1619 | if (!pelmHwChild->getAttributeValue("monitorCount", hw.cMonitors))
|
---|
1620 | pelmHwChild->getAttributeValue("MonitorCount", hw.cMonitors); // pre-v1.5 variant
|
---|
1621 | if (!pelmHwChild->getAttributeValue("accelerate3D", hw.fAccelerate3D))
|
---|
1622 | pelmHwChild->getAttributeValue("Accelerate3D", hw.fAccelerate3D); // pre-v1.5 variant
|
---|
1623 | pelmHwChild->getAttributeValue("accelerate2DVideo", hw.fAccelerate2DVideo);
|
---|
1624 | }
|
---|
1625 | else if (pelmHwChild->nameEquals("RemoteDisplay"))
|
---|
1626 | {
|
---|
1627 | pelmHwChild->getAttributeValue("enabled", hw.vrdpSettings.fEnabled);
|
---|
1628 | pelmHwChild->getAttributeValue("port", hw.vrdpSettings.strPort);
|
---|
1629 | pelmHwChild->getAttributeValue("netAddress", hw.vrdpSettings.strNetAddress);
|
---|
1630 |
|
---|
1631 | Utf8Str strAuthType;
|
---|
1632 | if (pelmHwChild->getAttributeValue("authType", strAuthType))
|
---|
1633 | {
|
---|
1634 | // settings before 1.3 used lower case so make sure this is case-insensitive
|
---|
1635 | strAuthType.toUpper();
|
---|
1636 | if (strAuthType == "NULL")
|
---|
1637 | hw.vrdpSettings.authType = VRDPAuthType_Null;
|
---|
1638 | else if (strAuthType == "GUEST")
|
---|
1639 | hw.vrdpSettings.authType = VRDPAuthType_Guest;
|
---|
1640 | else if (strAuthType == "EXTERNAL")
|
---|
1641 | hw.vrdpSettings.authType = VRDPAuthType_External;
|
---|
1642 | else
|
---|
1643 | throw ConfigFileError(this, pelmHwChild, N_("Invalid value '%s' in RemoteDisplay/@authType attribute"), strAuthType.c_str());
|
---|
1644 | }
|
---|
1645 |
|
---|
1646 | pelmHwChild->getAttributeValue("authTimeout", hw.vrdpSettings.ulAuthTimeout);
|
---|
1647 | pelmHwChild->getAttributeValue("allowMultiConnection", hw.vrdpSettings.fAllowMultiConnection);
|
---|
1648 | pelmHwChild->getAttributeValue("reuseSingleConnection", hw.vrdpSettings.fReuseSingleConnection);
|
---|
1649 | }
|
---|
1650 | else if (pelmHwChild->nameEquals("BIOS"))
|
---|
1651 | {
|
---|
1652 | const xml::ElementNode *pelmBIOSChild;
|
---|
1653 | if ((pelmBIOSChild = pelmHwChild->findChildElement("ACPI")))
|
---|
1654 | pelmBIOSChild->getAttributeValue("enabled", hw.biosSettings.fACPIEnabled);
|
---|
1655 | if ((pelmBIOSChild = pelmHwChild->findChildElement("IOAPIC")))
|
---|
1656 | pelmBIOSChild->getAttributeValue("enabled", hw.biosSettings.fIOAPICEnabled);
|
---|
1657 | if ((pelmBIOSChild = pelmHwChild->findChildElement("Logo")))
|
---|
1658 | {
|
---|
1659 | pelmBIOSChild->getAttributeValue("fadeIn", hw.biosSettings.fLogoFadeIn);
|
---|
1660 | pelmBIOSChild->getAttributeValue("fadeOut", hw.biosSettings.fLogoFadeOut);
|
---|
1661 | pelmBIOSChild->getAttributeValue("displayTime", hw.biosSettings.ulLogoDisplayTime);
|
---|
1662 | pelmBIOSChild->getAttributeValue("imagePath", hw.biosSettings.strLogoImagePath);
|
---|
1663 | }
|
---|
1664 | if ((pelmBIOSChild = pelmHwChild->findChildElement("BootMenu")))
|
---|
1665 | {
|
---|
1666 | Utf8Str strBootMenuMode;
|
---|
1667 | if (pelmBIOSChild->getAttributeValue("mode", strBootMenuMode))
|
---|
1668 | {
|
---|
1669 | // settings before 1.3 used lower case so make sure this is case-insensitive
|
---|
1670 | strBootMenuMode.toUpper();
|
---|
1671 | if (strBootMenuMode == "DISABLED")
|
---|
1672 | hw.biosSettings.biosBootMenuMode = BIOSBootMenuMode_Disabled;
|
---|
1673 | else if (strBootMenuMode == "MENUONLY")
|
---|
1674 | hw.biosSettings.biosBootMenuMode = BIOSBootMenuMode_MenuOnly;
|
---|
1675 | else if (strBootMenuMode == "MESSAGEANDMENU")
|
---|
1676 | hw.biosSettings.biosBootMenuMode = BIOSBootMenuMode_MessageAndMenu;
|
---|
1677 | else
|
---|
1678 | throw ConfigFileError(this, pelmBIOSChild, N_("Invalid value '%s' in BootMenu/@mode attribute"), strBootMenuMode.c_str());
|
---|
1679 | }
|
---|
1680 | }
|
---|
1681 | if ((pelmBIOSChild = pelmHwChild->findChildElement("PXEDebug")))
|
---|
1682 | pelmBIOSChild->getAttributeValue("enabled", hw.biosSettings.fPXEDebugEnabled);
|
---|
1683 | if ((pelmBIOSChild = pelmHwChild->findChildElement("TimeOffset")))
|
---|
1684 | pelmBIOSChild->getAttributeValue("value", hw.biosSettings.llTimeOffset);
|
---|
1685 |
|
---|
1686 | // legacy BIOS/IDEController (pre 1.7)
|
---|
1687 | if ( (m->sv < SettingsVersion_v1_7)
|
---|
1688 | && ((pelmBIOSChild = pelmHwChild->findChildElement("IDEController")))
|
---|
1689 | )
|
---|
1690 | {
|
---|
1691 | StorageController sctl;
|
---|
1692 | sctl.strName = "IDE Controller";
|
---|
1693 | sctl.storageBus = StorageBus_IDE;
|
---|
1694 |
|
---|
1695 | Utf8Str strType;
|
---|
1696 | if (pelmBIOSChild->getAttributeValue("type", strType))
|
---|
1697 | {
|
---|
1698 | if (strType == "PIIX3")
|
---|
1699 | sctl.controllerType = StorageControllerType_PIIX3;
|
---|
1700 | else if (strType == "PIIX4")
|
---|
1701 | sctl.controllerType = StorageControllerType_PIIX4;
|
---|
1702 | else if (strType == "ICH6")
|
---|
1703 | sctl.controllerType = StorageControllerType_ICH6;
|
---|
1704 | else
|
---|
1705 | throw ConfigFileError(this, pelmBIOSChild, N_("Invalid value '%s' for IDEController/@type attribute"), strType.c_str());
|
---|
1706 | }
|
---|
1707 | sctl.ulPortCount = 2;
|
---|
1708 | strg.llStorageControllers.push_back(sctl);
|
---|
1709 | }
|
---|
1710 | }
|
---|
1711 | else if (pelmHwChild->nameEquals("USBController"))
|
---|
1712 | {
|
---|
1713 | pelmHwChild->getAttributeValue("enabled", hw.usbController.fEnabled);
|
---|
1714 | pelmHwChild->getAttributeValue("enabledEhci", hw.usbController.fEnabledEHCI);
|
---|
1715 |
|
---|
1716 | readUSBDeviceFilters(*pelmHwChild,
|
---|
1717 | hw.usbController.llDeviceFilters);
|
---|
1718 | }
|
---|
1719 | else if ( (m->sv < SettingsVersion_v1_7)
|
---|
1720 | && (pelmHwChild->nameEquals("SATAController"))
|
---|
1721 | )
|
---|
1722 | {
|
---|
1723 | bool f;
|
---|
1724 | if ( (pelmHwChild->getAttributeValue("enabled", f))
|
---|
1725 | && (f)
|
---|
1726 | )
|
---|
1727 | {
|
---|
1728 | StorageController sctl;
|
---|
1729 | sctl.strName = "SATA Controller";
|
---|
1730 | sctl.storageBus = StorageBus_SATA;
|
---|
1731 | sctl.controllerType = StorageControllerType_IntelAhci;
|
---|
1732 |
|
---|
1733 | readStorageControllerAttributes(*pelmHwChild, sctl);
|
---|
1734 |
|
---|
1735 | strg.llStorageControllers.push_back(sctl);
|
---|
1736 | }
|
---|
1737 | }
|
---|
1738 | else if (pelmHwChild->nameEquals("Network"))
|
---|
1739 | readNetworkAdapters(*pelmHwChild, hw.llNetworkAdapters);
|
---|
1740 | else if ( (pelmHwChild->nameEquals("UART"))
|
---|
1741 | || (pelmHwChild->nameEquals("Uart")) // used before 1.3
|
---|
1742 | )
|
---|
1743 | readSerialPorts(*pelmHwChild, hw.llSerialPorts);
|
---|
1744 | else if ( (pelmHwChild->nameEquals("LPT"))
|
---|
1745 | || (pelmHwChild->nameEquals("Lpt")) // used before 1.3
|
---|
1746 | )
|
---|
1747 | readParallelPorts(*pelmHwChild, hw.llParallelPorts);
|
---|
1748 | else if (pelmHwChild->nameEquals("AudioAdapter"))
|
---|
1749 | {
|
---|
1750 | pelmHwChild->getAttributeValue("enabled", hw.audioAdapter.fEnabled);
|
---|
1751 |
|
---|
1752 | Utf8Str strTemp;
|
---|
1753 | if (pelmHwChild->getAttributeValue("controller", strTemp))
|
---|
1754 | {
|
---|
1755 | if (strTemp == "SB16")
|
---|
1756 | hw.audioAdapter.controllerType = AudioControllerType_SB16;
|
---|
1757 | else if (strTemp == "AC97")
|
---|
1758 | hw.audioAdapter.controllerType = AudioControllerType_AC97;
|
---|
1759 | else
|
---|
1760 | throw ConfigFileError(this, pelmHwChild, N_("Invalid value '%s' in AudioAdapter/@controller attribute"), strTemp.c_str());
|
---|
1761 | }
|
---|
1762 | if (pelmHwChild->getAttributeValue("driver", strTemp))
|
---|
1763 | {
|
---|
1764 | // settings before 1.3 used lower case so make sure this is case-insensitive
|
---|
1765 | strTemp.toUpper();
|
---|
1766 | if (strTemp == "NULL")
|
---|
1767 | hw.audioAdapter.driverType = AudioDriverType_Null;
|
---|
1768 | else if (strTemp == "WINMM")
|
---|
1769 | hw.audioAdapter.driverType = AudioDriverType_WinMM;
|
---|
1770 | else if ( (strTemp == "DIRECTSOUND") || (strTemp == "DSOUND") )
|
---|
1771 | hw.audioAdapter.driverType = AudioDriverType_DirectSound;
|
---|
1772 | else if (strTemp == "SOLAUDIO")
|
---|
1773 | hw.audioAdapter.driverType = AudioDriverType_SolAudio;
|
---|
1774 | else if (strTemp == "ALSA")
|
---|
1775 | hw.audioAdapter.driverType = AudioDriverType_ALSA;
|
---|
1776 | else if (strTemp == "PULSE")
|
---|
1777 | hw.audioAdapter.driverType = AudioDriverType_Pulse;
|
---|
1778 | else if (strTemp == "OSS")
|
---|
1779 | hw.audioAdapter.driverType = AudioDriverType_OSS;
|
---|
1780 | else if (strTemp == "COREAUDIO")
|
---|
1781 | hw.audioAdapter.driverType = AudioDriverType_CoreAudio;
|
---|
1782 | else if (strTemp == "MMPM")
|
---|
1783 | hw.audioAdapter.driverType = AudioDriverType_MMPM;
|
---|
1784 | else
|
---|
1785 | throw ConfigFileError(this, pelmHwChild, N_("Invalid value '%s' in AudioAdapter/@driver attribute"), strTemp.c_str());
|
---|
1786 | }
|
---|
1787 | }
|
---|
1788 | else if (pelmHwChild->nameEquals("SharedFolders"))
|
---|
1789 | {
|
---|
1790 | xml::NodesLoop nl2(*pelmHwChild, "SharedFolder");
|
---|
1791 | const xml::ElementNode *pelmFolder;
|
---|
1792 | while ((pelmFolder = nl2.forAllNodes()))
|
---|
1793 | {
|
---|
1794 | SharedFolder sf;
|
---|
1795 | pelmFolder->getAttributeValue("name", sf.strName);
|
---|
1796 | pelmFolder->getAttributeValue("hostPath", sf.strHostPath);
|
---|
1797 | pelmFolder->getAttributeValue("writable", sf.fWritable);
|
---|
1798 | hw.llSharedFolders.push_back(sf);
|
---|
1799 | }
|
---|
1800 | }
|
---|
1801 | else if (pelmHwChild->nameEquals("Clipboard"))
|
---|
1802 | {
|
---|
1803 | Utf8Str strTemp;
|
---|
1804 | if (pelmHwChild->getAttributeValue("mode", strTemp))
|
---|
1805 | {
|
---|
1806 | if (strTemp == "Disabled")
|
---|
1807 | hw.clipboardMode = ClipboardMode_Disabled;
|
---|
1808 | else if (strTemp == "HostToGuest")
|
---|
1809 | hw.clipboardMode = ClipboardMode_HostToGuest;
|
---|
1810 | else if (strTemp == "GuestToHost")
|
---|
1811 | hw.clipboardMode = ClipboardMode_GuestToHost;
|
---|
1812 | else if (strTemp == "Bidirectional")
|
---|
1813 | hw.clipboardMode = ClipboardMode_Bidirectional;
|
---|
1814 | else
|
---|
1815 | throw ConfigFileError(this, pelmHwChild, N_("Invalid value '%s' in Clipbord/@mode attribute"), strTemp.c_str());
|
---|
1816 | }
|
---|
1817 | }
|
---|
1818 | else if (pelmHwChild->nameEquals("Guest"))
|
---|
1819 | {
|
---|
1820 | if (!pelmHwChild->getAttributeValue("memoryBalloonSize", hw.ulMemoryBalloonSize))
|
---|
1821 | pelmHwChild->getAttributeValue("MemoryBalloonSize", hw.ulMemoryBalloonSize); // used before 1.3
|
---|
1822 | if (!pelmHwChild->getAttributeValue("statisticsUpdateInterval", hw.ulStatisticsUpdateInterval))
|
---|
1823 | pelmHwChild->getAttributeValue("StatisticsUpdateInterval", hw.ulStatisticsUpdateInterval);
|
---|
1824 | }
|
---|
1825 | else if (pelmHwChild->nameEquals("GuestProperties"))
|
---|
1826 | readGuestProperties(*pelmHwChild, hw);
|
---|
1827 | }
|
---|
1828 |
|
---|
1829 | if (hw.ulMemorySizeMB == (uint32_t)-1)
|
---|
1830 | throw ConfigFileError(this, &elmHardware, N_("Required Memory/@RAMSize element/attribute is missing"));
|
---|
1831 | }
|
---|
1832 |
|
---|
1833 | /**
|
---|
1834 | * This gets called instead of readStorageControllers() for legacy pre-1.7 settings
|
---|
1835 | * files which have a <HardDiskAttachments> node and storage controller settings
|
---|
1836 | * hidden in the <Hardware> settings. We set the StorageControllers fields just the
|
---|
1837 | * same, just from different sources.
|
---|
1838 | * @param elmHardware <Hardware> XML node.
|
---|
1839 | * @param elmHardDiskAttachments <HardDiskAttachments> XML node.
|
---|
1840 | * @param strg
|
---|
1841 | */
|
---|
1842 | void MachineConfigFile::readHardDiskAttachments_pre1_7(const xml::ElementNode &elmHardDiskAttachments,
|
---|
1843 | Storage &strg)
|
---|
1844 | {
|
---|
1845 | StorageController *pIDEController = NULL;
|
---|
1846 | StorageController *pSATAController = NULL;
|
---|
1847 |
|
---|
1848 | for (StorageControllersList::iterator it = strg.llStorageControllers.begin();
|
---|
1849 | it != strg.llStorageControllers.end();
|
---|
1850 | ++it)
|
---|
1851 | {
|
---|
1852 | StorageController &s = *it;
|
---|
1853 | if (s.storageBus == StorageBus_IDE)
|
---|
1854 | pIDEController = &s;
|
---|
1855 | else if (s.storageBus == StorageBus_SATA)
|
---|
1856 | pSATAController = &s;
|
---|
1857 | }
|
---|
1858 |
|
---|
1859 | xml::NodesLoop nl1(elmHardDiskAttachments, "HardDiskAttachment");
|
---|
1860 | const xml::ElementNode *pelmAttachment;
|
---|
1861 | while ((pelmAttachment = nl1.forAllNodes()))
|
---|
1862 | {
|
---|
1863 | AttachedDevice att;
|
---|
1864 | Utf8Str strUUID, strBus;
|
---|
1865 |
|
---|
1866 | if (!pelmAttachment->getAttributeValue("hardDisk", strUUID))
|
---|
1867 | throw ConfigFileError(this, pelmAttachment, N_("Required HardDiskAttachment/@hardDisk attribute is missing"));
|
---|
1868 | parseUUID(att.uuid, strUUID);
|
---|
1869 |
|
---|
1870 | if (!pelmAttachment->getAttributeValue("bus", strBus))
|
---|
1871 | throw ConfigFileError(this, pelmAttachment, N_("Required HardDiskAttachment/@bus attribute is missing"));
|
---|
1872 | // pre-1.7 'channel' is now port
|
---|
1873 | if (!pelmAttachment->getAttributeValue("channel", att.lPort))
|
---|
1874 | throw ConfigFileError(this, pelmAttachment, N_("Required HardDiskAttachment/@channel attribute is missing"));
|
---|
1875 | // pre-1.7 'device' is still device
|
---|
1876 | if (!pelmAttachment->getAttributeValue("device", att.lDevice))
|
---|
1877 | throw ConfigFileError(this, pelmAttachment, N_("Required HardDiskAttachment/@device attribute is missing"));
|
---|
1878 |
|
---|
1879 | att.deviceType = DeviceType_HardDisk;
|
---|
1880 |
|
---|
1881 | if (strBus == "IDE")
|
---|
1882 | {
|
---|
1883 | if (!pIDEController)
|
---|
1884 | throw ConfigFileError(this, pelmAttachment, N_("HardDiskAttachment/@bus is 'IDE' but cannot find IDE controller"));
|
---|
1885 | pIDEController->llAttachedDevices.push_back(att);
|
---|
1886 | }
|
---|
1887 | else if (strBus == "SATA")
|
---|
1888 | {
|
---|
1889 | if (!pSATAController)
|
---|
1890 | throw ConfigFileError(this, pelmAttachment, N_("HardDiskAttachment/@bus is 'SATA' but cannot find SATA controller"));
|
---|
1891 | pSATAController->llAttachedDevices.push_back(att);
|
---|
1892 | }
|
---|
1893 | else
|
---|
1894 | throw ConfigFileError(this, pelmAttachment, N_("HardDiskAttachment/@bus attribute has illegal value '%s'"), strBus.c_str());
|
---|
1895 | }
|
---|
1896 | }
|
---|
1897 |
|
---|
1898 | /**
|
---|
1899 | * Reads in a <StorageControllers> block and stores it in the given Storage structure.
|
---|
1900 | * Used both directly from readMachine and from readSnapshot, since snapshots
|
---|
1901 | * have their own storage controllers sections.
|
---|
1902 | *
|
---|
1903 | * This is only called for settings version 1.7 and above; see readHardDiskAttachments_pre1_7()
|
---|
1904 | * for earlier versions.
|
---|
1905 | *
|
---|
1906 | * @param elmStorageControllers
|
---|
1907 | */
|
---|
1908 | void MachineConfigFile::readStorageControllers(const xml::ElementNode &elmStorageControllers,
|
---|
1909 | Storage &strg)
|
---|
1910 | {
|
---|
1911 | xml::NodesLoop nlStorageControllers(elmStorageControllers, "StorageController");
|
---|
1912 | const xml::ElementNode *pelmController;
|
---|
1913 | while ((pelmController = nlStorageControllers.forAllNodes()))
|
---|
1914 | {
|
---|
1915 | StorageController sctl;
|
---|
1916 |
|
---|
1917 | if (!pelmController->getAttributeValue("name", sctl.strName))
|
---|
1918 | throw ConfigFileError(this, pelmController, N_("Required StorageController/@name attribute is missing"));
|
---|
1919 | // canonicalize storage controller names for configs in the switchover
|
---|
1920 | // period.
|
---|
1921 | if (m->sv <= SettingsVersion_v1_9)
|
---|
1922 | {
|
---|
1923 | if (sctl.strName == "IDE")
|
---|
1924 | sctl.strName = "IDE Controller";
|
---|
1925 | else if (sctl.strName == "SATA")
|
---|
1926 | sctl.strName = "SATA Controller";
|
---|
1927 | }
|
---|
1928 |
|
---|
1929 | pelmController->getAttributeValue("Instance", sctl.ulInstance);
|
---|
1930 | // default from constructor is 0
|
---|
1931 |
|
---|
1932 | Utf8Str strType;
|
---|
1933 | if (!pelmController->getAttributeValue("type", strType))
|
---|
1934 | throw ConfigFileError(this, pelmController, N_("Required StorageController/@type attribute is missing"));
|
---|
1935 |
|
---|
1936 | if (strType == "AHCI")
|
---|
1937 | {
|
---|
1938 | sctl.storageBus = StorageBus_SATA;
|
---|
1939 | sctl.controllerType = StorageControllerType_IntelAhci;
|
---|
1940 | }
|
---|
1941 | else if (strType == "LsiLogic")
|
---|
1942 | {
|
---|
1943 | sctl.storageBus = StorageBus_SCSI;
|
---|
1944 | sctl.controllerType = StorageControllerType_LsiLogic;
|
---|
1945 | }
|
---|
1946 | else if (strType == "BusLogic")
|
---|
1947 | {
|
---|
1948 | sctl.storageBus = StorageBus_SCSI;
|
---|
1949 | sctl.controllerType = StorageControllerType_BusLogic;
|
---|
1950 | }
|
---|
1951 | else if (strType == "PIIX3")
|
---|
1952 | {
|
---|
1953 | sctl.storageBus = StorageBus_IDE;
|
---|
1954 | sctl.controllerType = StorageControllerType_PIIX3;
|
---|
1955 | }
|
---|
1956 | else if (strType == "PIIX4")
|
---|
1957 | {
|
---|
1958 | sctl.storageBus = StorageBus_IDE;
|
---|
1959 | sctl.controllerType = StorageControllerType_PIIX4;
|
---|
1960 | }
|
---|
1961 | else if (strType == "ICH6")
|
---|
1962 | {
|
---|
1963 | sctl.storageBus = StorageBus_IDE;
|
---|
1964 | sctl.controllerType = StorageControllerType_ICH6;
|
---|
1965 | }
|
---|
1966 | else if ( (m->sv >= SettingsVersion_v1_9)
|
---|
1967 | && (strType == "I82078")
|
---|
1968 | )
|
---|
1969 | {
|
---|
1970 | sctl.storageBus = StorageBus_Floppy;
|
---|
1971 | sctl.controllerType = StorageControllerType_I82078;
|
---|
1972 | }
|
---|
1973 | else
|
---|
1974 | throw ConfigFileError(this, pelmController, N_("Invalid value '%s' for StorageController/@type attribute"), strType.c_str());
|
---|
1975 |
|
---|
1976 | readStorageControllerAttributes(*pelmController, sctl);
|
---|
1977 |
|
---|
1978 | xml::NodesLoop nlAttached(*pelmController, "AttachedDevice");
|
---|
1979 | const xml::ElementNode *pelmAttached;
|
---|
1980 | while ((pelmAttached = nlAttached.forAllNodes()))
|
---|
1981 | {
|
---|
1982 | AttachedDevice att;
|
---|
1983 | Utf8Str strTemp;
|
---|
1984 | pelmAttached->getAttributeValue("type", strTemp);
|
---|
1985 |
|
---|
1986 | if (strTemp == "HardDisk")
|
---|
1987 | att.deviceType = DeviceType_HardDisk;
|
---|
1988 | else if (m->sv >= SettingsVersion_v1_9)
|
---|
1989 | {
|
---|
1990 | // starting with 1.9 we list DVD and floppy drive info + attachments under <StorageControllers>
|
---|
1991 | if (strTemp == "DVD")
|
---|
1992 | {
|
---|
1993 | att.deviceType = DeviceType_DVD;
|
---|
1994 | pelmAttached->getAttributeValue("passthrough", att.fPassThrough);
|
---|
1995 | }
|
---|
1996 | else if (strTemp == "Floppy")
|
---|
1997 | att.deviceType = DeviceType_Floppy;
|
---|
1998 | }
|
---|
1999 |
|
---|
2000 | if (att.deviceType != DeviceType_Null)
|
---|
2001 | {
|
---|
2002 | const xml::ElementNode *pelmImage;
|
---|
2003 | // all types can have images attached, but for HardDisk it's required
|
---|
2004 | if (!(pelmImage = pelmAttached->findChildElement("Image")))
|
---|
2005 | {
|
---|
2006 | if (att.deviceType == DeviceType_HardDisk)
|
---|
2007 | throw ConfigFileError(this, pelmImage, N_("Required AttachedDevice/Image element is missing"));
|
---|
2008 | else
|
---|
2009 | {
|
---|
2010 | // DVDs and floppies can also have <HostDrive> instead of <Image>
|
---|
2011 | const xml::ElementNode *pelmHostDrive;
|
---|
2012 | if ((pelmHostDrive = pelmAttached->findChildElement("HostDrive")))
|
---|
2013 | if (!pelmHostDrive->getAttributeValue("src", att.strHostDriveSrc))
|
---|
2014 | throw ConfigFileError(this, pelmHostDrive, N_("Required AttachedDevice/HostDrive/@src attribute is missing"));
|
---|
2015 | }
|
---|
2016 | }
|
---|
2017 | else
|
---|
2018 | {
|
---|
2019 | if (!pelmImage->getAttributeValue("uuid", strTemp))
|
---|
2020 | throw ConfigFileError(this, pelmImage, N_("Required AttachedDevice/Image/@uuid attribute is missing"));
|
---|
2021 | parseUUID(att.uuid, strTemp);
|
---|
2022 | }
|
---|
2023 |
|
---|
2024 | if (!pelmAttached->getAttributeValue("port", att.lPort))
|
---|
2025 | throw ConfigFileError(this, pelmImage, N_("Required AttachedDevice/@port attribute is missing"));
|
---|
2026 | if (!pelmAttached->getAttributeValue("device", att.lDevice))
|
---|
2027 | throw ConfigFileError(this, pelmImage, N_("Required AttachedDevice/@device attribute is missing"));
|
---|
2028 |
|
---|
2029 | sctl.llAttachedDevices.push_back(att);
|
---|
2030 | }
|
---|
2031 | }
|
---|
2032 |
|
---|
2033 | strg.llStorageControllers.push_back(sctl);
|
---|
2034 | }
|
---|
2035 | }
|
---|
2036 |
|
---|
2037 | /**
|
---|
2038 | * This gets called for legacy pre-1.9 settings files after having parsed the
|
---|
2039 | * <Hardware> and <StorageControllers> sections to parse <Hardware> once more
|
---|
2040 | * for the <DVDDrive> and <FloppyDrive> sections.
|
---|
2041 | *
|
---|
2042 | * Before settings version 1.9, DVD and floppy drives were specified separately
|
---|
2043 | * under <Hardware>; we then need this extra loop to make sure the storage
|
---|
2044 | * controller structs are already set up so we can add stuff to them.
|
---|
2045 | *
|
---|
2046 | * @param elmHardware
|
---|
2047 | * @param strg
|
---|
2048 | */
|
---|
2049 | void MachineConfigFile::readDVDAndFloppies_pre1_9(const xml::ElementNode &elmHardware,
|
---|
2050 | Storage &strg)
|
---|
2051 | {
|
---|
2052 | xml::NodesLoop nl1(elmHardware);
|
---|
2053 | const xml::ElementNode *pelmHwChild;
|
---|
2054 | while ((pelmHwChild = nl1.forAllNodes()))
|
---|
2055 | {
|
---|
2056 | if (pelmHwChild->nameEquals("DVDDrive"))
|
---|
2057 | {
|
---|
2058 | // create a DVD "attached device" and attach it to the existing IDE controller
|
---|
2059 | AttachedDevice att;
|
---|
2060 | att.deviceType = DeviceType_DVD;
|
---|
2061 | // legacy DVD drive is always secondary master (port 1, device 0)
|
---|
2062 | att.lPort = 1;
|
---|
2063 | att.lDevice = 0;
|
---|
2064 | pelmHwChild->getAttributeValue("passthrough", att.fPassThrough);
|
---|
2065 |
|
---|
2066 | const xml::ElementNode *pDriveChild;
|
---|
2067 | Utf8Str strTmp;
|
---|
2068 | if ( ((pDriveChild = pelmHwChild->findChildElement("Image")))
|
---|
2069 | && (pDriveChild->getAttributeValue("uuid", strTmp))
|
---|
2070 | )
|
---|
2071 | parseUUID(att.uuid, strTmp);
|
---|
2072 | else if ((pDriveChild = pelmHwChild->findChildElement("HostDrive")))
|
---|
2073 | pDriveChild->getAttributeValue("src", att.strHostDriveSrc);
|
---|
2074 |
|
---|
2075 | // find the IDE controller and attach the DVD drive
|
---|
2076 | bool fFound = false;
|
---|
2077 | for (StorageControllersList::iterator it = strg.llStorageControllers.begin();
|
---|
2078 | it != strg.llStorageControllers.end();
|
---|
2079 | ++it)
|
---|
2080 | {
|
---|
2081 | StorageController &sctl = *it;
|
---|
2082 | if (sctl.storageBus == StorageBus_IDE)
|
---|
2083 | {
|
---|
2084 | sctl.llAttachedDevices.push_back(att);
|
---|
2085 | fFound = true;
|
---|
2086 | break;
|
---|
2087 | }
|
---|
2088 | }
|
---|
2089 |
|
---|
2090 | if (!fFound)
|
---|
2091 | throw ConfigFileError(this, pelmHwChild, N_("Internal error: found DVD drive but IDE controller does not exist"));
|
---|
2092 | // shouldn't happen because pre-1.9 settings files always had at least one IDE controller in the settings
|
---|
2093 | // which should have gotten parsed in <StorageControllers> before this got called
|
---|
2094 | }
|
---|
2095 | else if (pelmHwChild->nameEquals("FloppyDrive"))
|
---|
2096 | {
|
---|
2097 | bool fEnabled;
|
---|
2098 | if ( (pelmHwChild->getAttributeValue("enabled", fEnabled))
|
---|
2099 | && (fEnabled)
|
---|
2100 | )
|
---|
2101 | {
|
---|
2102 | // create a new floppy controller and attach a floppy "attached device"
|
---|
2103 | StorageController sctl;
|
---|
2104 | sctl.strName = "Floppy Controller";
|
---|
2105 | sctl.storageBus = StorageBus_Floppy;
|
---|
2106 | sctl.controllerType = StorageControllerType_I82078;
|
---|
2107 | sctl.ulPortCount = 1;
|
---|
2108 |
|
---|
2109 | AttachedDevice att;
|
---|
2110 | att.deviceType = DeviceType_Floppy;
|
---|
2111 | att.lPort = 0;
|
---|
2112 | att.lDevice = 0;
|
---|
2113 |
|
---|
2114 | const xml::ElementNode *pDriveChild;
|
---|
2115 | Utf8Str strTmp;
|
---|
2116 | if ( ((pDriveChild = pelmHwChild->findChildElement("Image")))
|
---|
2117 | && (pDriveChild->getAttributeValue("uuid", strTmp))
|
---|
2118 | )
|
---|
2119 | parseUUID(att.uuid, strTmp);
|
---|
2120 | else if ((pDriveChild = pelmHwChild->findChildElement("HostDrive")))
|
---|
2121 | pDriveChild->getAttributeValue("src", att.strHostDriveSrc);
|
---|
2122 |
|
---|
2123 | // store attachment with controller
|
---|
2124 | sctl.llAttachedDevices.push_back(att);
|
---|
2125 | // store controller with storage
|
---|
2126 | strg.llStorageControllers.push_back(sctl);
|
---|
2127 | }
|
---|
2128 | }
|
---|
2129 | }
|
---|
2130 | }
|
---|
2131 |
|
---|
2132 | /**
|
---|
2133 | * Called initially for the <Snapshot> element under <Machine>, if present,
|
---|
2134 | * to store the snapshot's data into the given Snapshot structure (which is
|
---|
2135 | * then the one in the Machine struct). This might then recurse if
|
---|
2136 | * a <Snapshots> (plural) element is found in the snapshot, which should
|
---|
2137 | * contain a list of child snapshots; such lists are maintained in the
|
---|
2138 | * Snapshot structure.
|
---|
2139 | *
|
---|
2140 | * @param elmSnapshot
|
---|
2141 | * @param snap
|
---|
2142 | */
|
---|
2143 | void MachineConfigFile::readSnapshot(const xml::ElementNode &elmSnapshot,
|
---|
2144 | Snapshot &snap)
|
---|
2145 | {
|
---|
2146 | Utf8Str strTemp;
|
---|
2147 |
|
---|
2148 | if (!elmSnapshot.getAttributeValue("uuid", strTemp))
|
---|
2149 | throw ConfigFileError(this, &elmSnapshot, N_("Required Snapshot/@uuid attribute is missing"));
|
---|
2150 | parseUUID(snap.uuid, strTemp);
|
---|
2151 |
|
---|
2152 | if (!elmSnapshot.getAttributeValue("name", snap.strName))
|
---|
2153 | throw ConfigFileError(this, &elmSnapshot, N_("Required Snapshot/@name attribute is missing"));
|
---|
2154 |
|
---|
2155 | // earlier 3.1 trunk builds had a bug and added Description as an attribute, read it silently and write it back as an element
|
---|
2156 | elmSnapshot.getAttributeValue("Description", snap.strDescription);
|
---|
2157 |
|
---|
2158 | if (!elmSnapshot.getAttributeValue("timeStamp", strTemp))
|
---|
2159 | throw ConfigFileError(this, &elmSnapshot, N_("Required Snapshot/@timeStamp attribute is missing"));
|
---|
2160 | parseTimestamp(snap.timestamp, strTemp);
|
---|
2161 |
|
---|
2162 | elmSnapshot.getAttributeValue("stateFile", snap.strStateFile); // online snapshots only
|
---|
2163 |
|
---|
2164 | // parse Hardware before the other elements because other things depend on it
|
---|
2165 | const xml::ElementNode *pelmHardware;
|
---|
2166 | if (!(pelmHardware = elmSnapshot.findChildElement("Hardware")))
|
---|
2167 | throw ConfigFileError(this, &elmSnapshot, N_("Required Snapshot/@Hardware element is missing"));
|
---|
2168 | readHardware(*pelmHardware, snap.hardware, snap.storage);
|
---|
2169 |
|
---|
2170 | xml::NodesLoop nlSnapshotChildren(elmSnapshot);
|
---|
2171 | const xml::ElementNode *pelmSnapshotChild;
|
---|
2172 | while ((pelmSnapshotChild = nlSnapshotChildren.forAllNodes()))
|
---|
2173 | {
|
---|
2174 | if (pelmSnapshotChild->nameEquals("Description"))
|
---|
2175 | snap.strDescription = pelmSnapshotChild->getValue();
|
---|
2176 | else if ( (m->sv < SettingsVersion_v1_7)
|
---|
2177 | && (pelmSnapshotChild->nameEquals("HardDiskAttachments"))
|
---|
2178 | )
|
---|
2179 | readHardDiskAttachments_pre1_7(*pelmSnapshotChild, snap.storage);
|
---|
2180 | else if ( (m->sv >= SettingsVersion_v1_7)
|
---|
2181 | && (pelmSnapshotChild->nameEquals("StorageControllers"))
|
---|
2182 | )
|
---|
2183 | readStorageControllers(*pelmSnapshotChild, snap.storage);
|
---|
2184 | else if (pelmSnapshotChild->nameEquals("Snapshots"))
|
---|
2185 | {
|
---|
2186 | xml::NodesLoop nlChildSnapshots(*pelmSnapshotChild);
|
---|
2187 | const xml::ElementNode *pelmChildSnapshot;
|
---|
2188 | while ((pelmChildSnapshot = nlChildSnapshots.forAllNodes()))
|
---|
2189 | {
|
---|
2190 | if (pelmChildSnapshot->nameEquals("Snapshot"))
|
---|
2191 | {
|
---|
2192 | Snapshot child;
|
---|
2193 | readSnapshot(*pelmChildSnapshot, child);
|
---|
2194 | snap.llChildSnapshots.push_back(child);
|
---|
2195 | }
|
---|
2196 | }
|
---|
2197 | }
|
---|
2198 | }
|
---|
2199 |
|
---|
2200 | if (m->sv < SettingsVersion_v1_9)
|
---|
2201 | // go through Hardware once more to repair the settings controller structures
|
---|
2202 | // with data from old DVDDrive and FloppyDrive elements
|
---|
2203 | readDVDAndFloppies_pre1_9(*pelmHardware, snap.storage);
|
---|
2204 | }
|
---|
2205 |
|
---|
2206 | void MachineConfigFile::convertOldOSType_pre1_5(Utf8Str &str)
|
---|
2207 | {
|
---|
2208 | if (str == "unknown") str = "Other";
|
---|
2209 | else if (str == "dos") str = "DOS";
|
---|
2210 | else if (str == "win31") str = "Windows31";
|
---|
2211 | else if (str == "win95") str = "Windows95";
|
---|
2212 | else if (str == "win98") str = "Windows98";
|
---|
2213 | else if (str == "winme") str = "WindowsMe";
|
---|
2214 | else if (str == "winnt4") str = "WindowsNT4";
|
---|
2215 | else if (str == "win2k") str = "Windows2000";
|
---|
2216 | else if (str == "winxp") str = "WindowsXP";
|
---|
2217 | else if (str == "win2k3") str = "Windows2003";
|
---|
2218 | else if (str == "winvista") str = "WindowsVista";
|
---|
2219 | else if (str == "win2k8") str = "Windows2008";
|
---|
2220 | else if (str == "os2warp3") str = "OS2Warp3";
|
---|
2221 | else if (str == "os2warp4") str = "OS2Warp4";
|
---|
2222 | else if (str == "os2warp45") str = "OS2Warp45";
|
---|
2223 | else if (str == "ecs") str = "OS2eCS";
|
---|
2224 | else if (str == "linux22") str = "Linux22";
|
---|
2225 | else if (str == "linux24") str = "Linux24";
|
---|
2226 | else if (str == "linux26") str = "Linux26";
|
---|
2227 | else if (str == "archlinux") str = "ArchLinux";
|
---|
2228 | else if (str == "debian") str = "Debian";
|
---|
2229 | else if (str == "opensuse") str = "OpenSUSE";
|
---|
2230 | else if (str == "fedoracore") str = "Fedora";
|
---|
2231 | else if (str == "gentoo") str = "Gentoo";
|
---|
2232 | else if (str == "mandriva") str = "Mandriva";
|
---|
2233 | else if (str == "redhat") str = "RedHat";
|
---|
2234 | else if (str == "ubuntu") str = "Ubuntu";
|
---|
2235 | else if (str == "xandros") str = "Xandros";
|
---|
2236 | else if (str == "freebsd") str = "FreeBSD";
|
---|
2237 | else if (str == "openbsd") str = "OpenBSD";
|
---|
2238 | else if (str == "netbsd") str = "NetBSD";
|
---|
2239 | else if (str == "netware") str = "Netware";
|
---|
2240 | else if (str == "solaris") str = "Solaris";
|
---|
2241 | else if (str == "opensolaris") str = "OpenSolaris";
|
---|
2242 | else if (str == "l4") str = "L4";
|
---|
2243 | }
|
---|
2244 |
|
---|
2245 | /**
|
---|
2246 | * Called from the constructor to actually read in the <Machine> element
|
---|
2247 | * of a machine config file.
|
---|
2248 | * @param elmMachine
|
---|
2249 | */
|
---|
2250 | void MachineConfigFile::readMachine(const xml::ElementNode &elmMachine)
|
---|
2251 | {
|
---|
2252 | Utf8Str strUUID;
|
---|
2253 | if ( (elmMachine.getAttributeValue("uuid", strUUID))
|
---|
2254 | && (elmMachine.getAttributeValue("name", strName))
|
---|
2255 | )
|
---|
2256 | {
|
---|
2257 | parseUUID(uuid, strUUID);
|
---|
2258 |
|
---|
2259 | if (!elmMachine.getAttributeValue("nameSync", fNameSync))
|
---|
2260 | fNameSync = true;
|
---|
2261 |
|
---|
2262 | Utf8Str str;
|
---|
2263 | elmMachine.getAttributeValue("Description", strDescription);
|
---|
2264 |
|
---|
2265 | elmMachine.getAttributeValue("OSType", strOsType);
|
---|
2266 | if (m->sv < SettingsVersion_v1_5)
|
---|
2267 | convertOldOSType_pre1_5(strOsType);
|
---|
2268 |
|
---|
2269 | elmMachine.getAttributeValue("stateFile", strStateFile);
|
---|
2270 | if (elmMachine.getAttributeValue("currentSnapshot", str))
|
---|
2271 | parseUUID(uuidCurrentSnapshot, str);
|
---|
2272 | elmMachine.getAttributeValue("snapshotFolder", strSnapshotFolder);
|
---|
2273 | if (!elmMachine.getAttributeValue("currentStateModified", fCurrentStateModified))
|
---|
2274 | fCurrentStateModified = true;
|
---|
2275 | if (elmMachine.getAttributeValue("lastStateChange", str))
|
---|
2276 | parseTimestamp(timeLastStateChange, str);
|
---|
2277 | // constructor has called RTTimeNow(&timeLastStateChange) before
|
---|
2278 |
|
---|
2279 | #if 1 /** @todo Teleportation: Obsolete. Remove in a couple of days. */
|
---|
2280 | if (!elmMachine.getAttributeValue("teleporterEnabled", fTeleporterEnabled)
|
---|
2281 | && !elmMachine.getAttributeValue("liveMigrationTarget", fTeleporterEnabled))
|
---|
2282 | fTeleporterEnabled = false;
|
---|
2283 | if (!elmMachine.getAttributeValue("teleporterPort", uTeleporterPort)
|
---|
2284 | && !elmMachine.getAttributeValue("liveMigrationPort", uTeleporterPort))
|
---|
2285 | uTeleporterPort = 0;
|
---|
2286 | if (!elmMachine.getAttributeValue("teleporterAddress", strTeleporterAddress))
|
---|
2287 | strTeleporterAddress = "";
|
---|
2288 | if (!elmMachine.getAttributeValue("teleporterPassword", strTeleporterPassword)
|
---|
2289 | && !elmMachine.getAttributeValue("liveMigrationPassword", strTeleporterPassword))
|
---|
2290 | strTeleporterPassword = "";
|
---|
2291 | #endif
|
---|
2292 |
|
---|
2293 | // parse Hardware before the other elements because other things depend on it
|
---|
2294 | const xml::ElementNode *pelmHardware;
|
---|
2295 | if (!(pelmHardware = elmMachine.findChildElement("Hardware")))
|
---|
2296 | throw ConfigFileError(this, &elmMachine, N_("Required Machine/Hardware element is missing"));
|
---|
2297 | readHardware(*pelmHardware, hardwareMachine, storageMachine);
|
---|
2298 |
|
---|
2299 | xml::NodesLoop nlRootChildren(elmMachine);
|
---|
2300 | const xml::ElementNode *pelmMachineChild;
|
---|
2301 | while ((pelmMachineChild = nlRootChildren.forAllNodes()))
|
---|
2302 | {
|
---|
2303 | if (pelmMachineChild->nameEquals("ExtraData"))
|
---|
2304 | readExtraData(*pelmMachineChild,
|
---|
2305 | mapExtraDataItems);
|
---|
2306 | else if ( (m->sv < SettingsVersion_v1_7)
|
---|
2307 | && (pelmMachineChild->nameEquals("HardDiskAttachments"))
|
---|
2308 | )
|
---|
2309 | readHardDiskAttachments_pre1_7(*pelmMachineChild, storageMachine);
|
---|
2310 | else if ( (m->sv >= SettingsVersion_v1_7)
|
---|
2311 | && (pelmMachineChild->nameEquals("StorageControllers"))
|
---|
2312 | )
|
---|
2313 | readStorageControllers(*pelmMachineChild, storageMachine);
|
---|
2314 | else if (pelmMachineChild->nameEquals("Snapshot"))
|
---|
2315 | {
|
---|
2316 | Snapshot snap;
|
---|
2317 | // this will recurse into child snapshots, if necessary
|
---|
2318 | readSnapshot(*pelmMachineChild, snap);
|
---|
2319 | llFirstSnapshot.push_back(snap);
|
---|
2320 | }
|
---|
2321 | else if (pelmMachineChild->nameEquals("Description"))
|
---|
2322 | strDescription = pelmMachineChild->getValue();
|
---|
2323 | else if (pelmMachineChild->nameEquals("Teleporter"))
|
---|
2324 | {
|
---|
2325 | if (!pelmMachineChild->getAttributeValue("enabled", fTeleporterEnabled))
|
---|
2326 | fTeleporterEnabled = false;
|
---|
2327 | if (!pelmMachineChild->getAttributeValue("port", uTeleporterPort))
|
---|
2328 | uTeleporterPort = 0;
|
---|
2329 | if (!pelmMachineChild->getAttributeValue("address", strTeleporterAddress))
|
---|
2330 | strTeleporterAddress = "";
|
---|
2331 | if (!pelmMachineChild->getAttributeValue("password", strTeleporterPassword))
|
---|
2332 | strTeleporterPassword = "";
|
---|
2333 | }
|
---|
2334 | }
|
---|
2335 |
|
---|
2336 | if (m->sv < SettingsVersion_v1_9)
|
---|
2337 | // go through Hardware once more to repair the settings controller structures
|
---|
2338 | // with data from old DVDDrive and FloppyDrive elements
|
---|
2339 | readDVDAndFloppies_pre1_9(*pelmHardware, storageMachine);
|
---|
2340 | }
|
---|
2341 | else
|
---|
2342 | throw ConfigFileError(this, &elmMachine, N_("Required Machine/@uuid or @name attributes is missing"));
|
---|
2343 | }
|
---|
2344 |
|
---|
2345 | ////////////////////////////////////////////////////////////////////////////////
|
---|
2346 | //
|
---|
2347 | // MachineConfigFile
|
---|
2348 | //
|
---|
2349 | ////////////////////////////////////////////////////////////////////////////////
|
---|
2350 |
|
---|
2351 | /**
|
---|
2352 | * Constructor.
|
---|
2353 | *
|
---|
2354 | * If pstrFilename is != NULL, this reads the given settings file into the member
|
---|
2355 | * variables and various substructures and lists. Otherwise, the member variables
|
---|
2356 | * are initialized with default values.
|
---|
2357 | *
|
---|
2358 | * Throws variants of xml::Error for I/O, XML and logical content errors, which
|
---|
2359 | * the caller should catch; if this constructor does not throw, then the member
|
---|
2360 | * variables contain meaningful values (either from the file or defaults).
|
---|
2361 | *
|
---|
2362 | * @param strFilename
|
---|
2363 | */
|
---|
2364 | MachineConfigFile::MachineConfigFile(const Utf8Str *pstrFilename)
|
---|
2365 | : ConfigFileBase(pstrFilename),
|
---|
2366 | fNameSync(true),
|
---|
2367 | fTeleporterEnabled(false),
|
---|
2368 | uTeleporterPort(0),
|
---|
2369 | fCurrentStateModified(true),
|
---|
2370 | fAborted(false)
|
---|
2371 | {
|
---|
2372 | RTTimeNow(&timeLastStateChange);
|
---|
2373 |
|
---|
2374 | if (pstrFilename)
|
---|
2375 | {
|
---|
2376 | // the ConfigFileBase constructor has loaded the XML file, so now
|
---|
2377 | // we need only analyze what is in there
|
---|
2378 |
|
---|
2379 | xml::NodesLoop nlRootChildren(*m->pelmRoot);
|
---|
2380 | const xml::ElementNode *pelmRootChild;
|
---|
2381 | while ((pelmRootChild = nlRootChildren.forAllNodes()))
|
---|
2382 | {
|
---|
2383 | if (pelmRootChild->nameEquals("Machine"))
|
---|
2384 | readMachine(*pelmRootChild);
|
---|
2385 | }
|
---|
2386 |
|
---|
2387 | // clean up memory allocated by XML engine
|
---|
2388 | clearDocument();
|
---|
2389 | }
|
---|
2390 | }
|
---|
2391 |
|
---|
2392 | /**
|
---|
2393 | * Creates a <Hardware> node under elmParent and then writes out the XML
|
---|
2394 | * keys under that. Called for both the <Machine> node and for snapshots.
|
---|
2395 | * @param elmParent
|
---|
2396 | * @param st
|
---|
2397 | */
|
---|
2398 | void MachineConfigFile::writeHardware(xml::ElementNode &elmParent,
|
---|
2399 | const Hardware &hw,
|
---|
2400 | const Storage &strg)
|
---|
2401 | {
|
---|
2402 | xml::ElementNode *pelmHardware = elmParent.createChild("Hardware");
|
---|
2403 |
|
---|
2404 | if (hw.strVersion != "2")
|
---|
2405 | pelmHardware->setAttribute("version", hw.strVersion);
|
---|
2406 | if ( (m->sv >= SettingsVersion_v1_9)
|
---|
2407 | && (!hw.uuid.isEmpty())
|
---|
2408 | )
|
---|
2409 | pelmHardware->setAttribute("uuid", makeString(hw.uuid));
|
---|
2410 |
|
---|
2411 | xml::ElementNode *pelmCPU = pelmHardware->createChild("CPU");
|
---|
2412 |
|
---|
2413 | xml::ElementNode *pelmHwVirtEx = pelmCPU->createChild("HardwareVirtEx");
|
---|
2414 | pelmHwVirtEx->setAttribute("enabled", hw.fHardwareVirt);
|
---|
2415 | if (m->sv >= SettingsVersion_v1_9)
|
---|
2416 | pelmHwVirtEx->setAttribute("exclusive", hw.fHardwareVirtExclusive);
|
---|
2417 |
|
---|
2418 | if (hw.fNestedPaging)
|
---|
2419 | pelmCPU->createChild("HardwareVirtExNestedPaging")->setAttribute("enabled", hw.fNestedPaging);
|
---|
2420 | if (hw.fVPID)
|
---|
2421 | pelmCPU->createChild("HardwareVirtExVPID")->setAttribute("enabled", hw.fVPID);
|
---|
2422 | if (hw.fPAE)
|
---|
2423 | pelmCPU->createChild("PAE")->setAttribute("enabled", hw.fPAE);
|
---|
2424 | if (hw.fSyntheticCpu)
|
---|
2425 | pelmCPU->createChild("SyntheticCpu")->setAttribute("enabled", hw.fSyntheticCpu);
|
---|
2426 | pelmCPU->setAttribute("count", hw.cCPUs);
|
---|
2427 |
|
---|
2428 | xml::ElementNode *pelmCpuIdTree = pelmHardware->createChild("CpuId");
|
---|
2429 | for (CpuIdLeafsList::const_iterator it = hw.llCpuIdLeafs.begin();
|
---|
2430 | it != hw.llCpuIdLeafs.end();
|
---|
2431 | ++it)
|
---|
2432 | {
|
---|
2433 | const CpuIdLeaf &leaf = *it;
|
---|
2434 |
|
---|
2435 | xml::ElementNode *pelmCpuIdLeaf = pelmCpuIdTree->createChild("CpuIdLeaf");
|
---|
2436 | pelmCpuIdLeaf->setAttribute("id", leaf.ulId);
|
---|
2437 | pelmCpuIdLeaf->setAttribute("eax", leaf.ulEax);
|
---|
2438 | pelmCpuIdLeaf->setAttribute("ebx", leaf.ulEbx);
|
---|
2439 | pelmCpuIdLeaf->setAttribute("ecx", leaf.ulEcx);
|
---|
2440 | pelmCpuIdLeaf->setAttribute("edx", leaf.ulEdx);
|
---|
2441 | }
|
---|
2442 |
|
---|
2443 | xml::ElementNode *pelmMemory = pelmHardware->createChild("Memory");
|
---|
2444 | pelmMemory->setAttribute("RAMSize", hw.ulMemorySizeMB);
|
---|
2445 |
|
---|
2446 | if ( (m->sv >= SettingsVersion_v1_9)
|
---|
2447 | && (hw.firmwareType == FirmwareType_EFI)
|
---|
2448 | )
|
---|
2449 | {
|
---|
2450 | xml::ElementNode *pelmFirmware = pelmHardware->createChild("Firmware");
|
---|
2451 | pelmFirmware->setAttribute("type", "EFI");
|
---|
2452 | }
|
---|
2453 |
|
---|
2454 | xml::ElementNode *pelmBoot = pelmHardware->createChild("Boot");
|
---|
2455 | for (BootOrderMap::const_iterator it = hw.mapBootOrder.begin();
|
---|
2456 | it != hw.mapBootOrder.end();
|
---|
2457 | ++it)
|
---|
2458 | {
|
---|
2459 | uint32_t i = it->first;
|
---|
2460 | DeviceType_T type = it->second;
|
---|
2461 | const char *pcszDevice;
|
---|
2462 |
|
---|
2463 | switch (type)
|
---|
2464 | {
|
---|
2465 | case DeviceType_Floppy: pcszDevice = "Floppy"; break;
|
---|
2466 | case DeviceType_DVD: pcszDevice = "DVD"; break;
|
---|
2467 | case DeviceType_HardDisk: pcszDevice = "HardDisk"; break;
|
---|
2468 | case DeviceType_Network: pcszDevice = "Network"; break;
|
---|
2469 | default: /*case DeviceType_Null:*/ pcszDevice = "None"; break;
|
---|
2470 | }
|
---|
2471 |
|
---|
2472 | xml::ElementNode *pelmOrder = pelmBoot->createChild("Order");
|
---|
2473 | pelmOrder->setAttribute("position",
|
---|
2474 | i + 1); // XML is 1-based but internal data is 0-based
|
---|
2475 | pelmOrder->setAttribute("device", pcszDevice);
|
---|
2476 | }
|
---|
2477 |
|
---|
2478 | xml::ElementNode *pelmDisplay = pelmHardware->createChild("Display");
|
---|
2479 | pelmDisplay->setAttribute("VRAMSize", hw.ulVRAMSizeMB);
|
---|
2480 | pelmDisplay->setAttribute("monitorCount", hw.cMonitors);
|
---|
2481 | pelmDisplay->setAttribute("accelerate3D", hw.fAccelerate3D);
|
---|
2482 |
|
---|
2483 | if (m->sv >= SettingsVersion_v1_8)
|
---|
2484 | pelmDisplay->setAttribute("accelerate2DVideo", hw.fAccelerate2DVideo);
|
---|
2485 |
|
---|
2486 | xml::ElementNode *pelmVRDP = pelmHardware->createChild("RemoteDisplay");
|
---|
2487 | pelmVRDP->setAttribute("enabled", hw.vrdpSettings.fEnabled);
|
---|
2488 | pelmVRDP->setAttribute("port", hw.vrdpSettings.strPort);
|
---|
2489 | if (hw.vrdpSettings.strNetAddress.length())
|
---|
2490 | pelmVRDP->setAttribute("netAddress", hw.vrdpSettings.strNetAddress);
|
---|
2491 | const char *pcszAuthType;
|
---|
2492 | switch (hw.vrdpSettings.authType)
|
---|
2493 | {
|
---|
2494 | case VRDPAuthType_Guest: pcszAuthType = "Guest"; break;
|
---|
2495 | case VRDPAuthType_External: pcszAuthType = "External"; break;
|
---|
2496 | default: /*case VRDPAuthType_Null:*/ pcszAuthType = "Null"; break;
|
---|
2497 | }
|
---|
2498 | pelmVRDP->setAttribute("authType", pcszAuthType);
|
---|
2499 |
|
---|
2500 | if (hw.vrdpSettings.ulAuthTimeout != 0)
|
---|
2501 | pelmVRDP->setAttribute("authTimeout", hw.vrdpSettings.ulAuthTimeout);
|
---|
2502 | if (hw.vrdpSettings.fAllowMultiConnection)
|
---|
2503 | pelmVRDP->setAttribute("allowMultiConnection", hw.vrdpSettings.fAllowMultiConnection);
|
---|
2504 | if (hw.vrdpSettings.fReuseSingleConnection)
|
---|
2505 | pelmVRDP->setAttribute("reuseSingleConnection", hw.vrdpSettings.fReuseSingleConnection);
|
---|
2506 |
|
---|
2507 | xml::ElementNode *pelmBIOS = pelmHardware->createChild("BIOS");
|
---|
2508 | pelmBIOS->createChild("ACPI")->setAttribute("enabled", hw.biosSettings.fACPIEnabled);
|
---|
2509 | pelmBIOS->createChild("IOAPIC")->setAttribute("enabled", hw.biosSettings.fIOAPICEnabled);
|
---|
2510 |
|
---|
2511 | xml::ElementNode *pelmLogo = pelmBIOS->createChild("Logo");
|
---|
2512 | pelmLogo->setAttribute("fadeIn", hw.biosSettings.fLogoFadeIn);
|
---|
2513 | pelmLogo->setAttribute("fadeOut", hw.biosSettings.fLogoFadeOut);
|
---|
2514 | pelmLogo->setAttribute("displayTime", hw.biosSettings.ulLogoDisplayTime);
|
---|
2515 | if (hw.biosSettings.strLogoImagePath.length())
|
---|
2516 | pelmLogo->setAttribute("imagePath", hw.biosSettings.strLogoImagePath);
|
---|
2517 |
|
---|
2518 | const char *pcszBootMenu;
|
---|
2519 | switch (hw.biosSettings.biosBootMenuMode)
|
---|
2520 | {
|
---|
2521 | case BIOSBootMenuMode_Disabled: pcszBootMenu = "Disabled"; break;
|
---|
2522 | case BIOSBootMenuMode_MenuOnly: pcszBootMenu = "MenuOnly"; break;
|
---|
2523 | default: /*BIOSBootMenuMode_MessageAndMenu*/ pcszBootMenu = "MessageAndMenu"; break;
|
---|
2524 | }
|
---|
2525 | pelmBIOS->createChild("BootMenu")->setAttribute("mode", pcszBootMenu);
|
---|
2526 | pelmBIOS->createChild("TimeOffset")->setAttribute("value", hw.biosSettings.llTimeOffset);
|
---|
2527 | pelmBIOS->createChild("PXEDebug")->setAttribute("enabled", hw.biosSettings.fPXEDebugEnabled);
|
---|
2528 |
|
---|
2529 | if (m->sv < SettingsVersion_v1_9)
|
---|
2530 | {
|
---|
2531 | // settings formats before 1.9 had separate DVDDrive and FloppyDrive items under Hardware;
|
---|
2532 | // run thru the storage controllers to see if we have a DVD or floppy drives
|
---|
2533 | size_t cDVDs = 0;
|
---|
2534 | size_t cFloppies = 0;
|
---|
2535 |
|
---|
2536 | xml::ElementNode *pelmDVD = pelmHardware->createChild("DVDDrive");
|
---|
2537 | xml::ElementNode *pelmFloppy = pelmHardware->createChild("FloppyDrive");
|
---|
2538 |
|
---|
2539 | for (StorageControllersList::const_iterator it = strg.llStorageControllers.begin();
|
---|
2540 | it != strg.llStorageControllers.end();
|
---|
2541 | ++it)
|
---|
2542 | {
|
---|
2543 | const StorageController &sctl = *it;
|
---|
2544 | // in old settings format, the DVD drive could only have been under the IDE controller
|
---|
2545 | if (sctl.storageBus == StorageBus_IDE)
|
---|
2546 | {
|
---|
2547 | for (AttachedDevicesList::const_iterator it2 = sctl.llAttachedDevices.begin();
|
---|
2548 | it2 != sctl.llAttachedDevices.end();
|
---|
2549 | ++it2)
|
---|
2550 | {
|
---|
2551 | const AttachedDevice &att = *it2;
|
---|
2552 | if (att.deviceType == DeviceType_DVD)
|
---|
2553 | {
|
---|
2554 | if (cDVDs > 0)
|
---|
2555 | throw ConfigFileError(this, NULL, N_("Internal error: cannot save more than one DVD drive with old settings format"));
|
---|
2556 |
|
---|
2557 | ++cDVDs;
|
---|
2558 |
|
---|
2559 | pelmDVD->setAttribute("passthrough", att.fPassThrough);
|
---|
2560 | if (!att.uuid.isEmpty())
|
---|
2561 | pelmDVD->createChild("Image")->setAttribute("uuid", makeString(att.uuid));
|
---|
2562 | else if (att.strHostDriveSrc.length())
|
---|
2563 | pelmDVD->createChild("HostDrive")->setAttribute("src", att.strHostDriveSrc);
|
---|
2564 | }
|
---|
2565 | }
|
---|
2566 | }
|
---|
2567 | else if (sctl.storageBus == StorageBus_Floppy)
|
---|
2568 | {
|
---|
2569 | size_t cFloppiesHere = sctl.llAttachedDevices.size();
|
---|
2570 | if (cFloppiesHere > 1)
|
---|
2571 | throw ConfigFileError(this, NULL, N_("Internal error: floppy controller cannot have more than one device attachment"));
|
---|
2572 | if (cFloppiesHere)
|
---|
2573 | {
|
---|
2574 | const AttachedDevice &att = sctl.llAttachedDevices.front();
|
---|
2575 | pelmFloppy->setAttribute("enabled", true);
|
---|
2576 | if (!att.uuid.isEmpty())
|
---|
2577 | pelmFloppy->createChild("Image")->setAttribute("uuid", makeString(att.uuid));
|
---|
2578 | else if (att.strHostDriveSrc.length())
|
---|
2579 | pelmFloppy->createChild("HostDrive")->setAttribute("src", att.strHostDriveSrc);
|
---|
2580 | }
|
---|
2581 |
|
---|
2582 | cFloppies += cFloppiesHere;
|
---|
2583 | }
|
---|
2584 | }
|
---|
2585 |
|
---|
2586 | if (cFloppies == 0)
|
---|
2587 | pelmFloppy->setAttribute("enabled", false);
|
---|
2588 | else if (cFloppies > 1)
|
---|
2589 | throw ConfigFileError(this, NULL, N_("Internal error: cannot save more than one floppy drive with old settings format"));
|
---|
2590 | }
|
---|
2591 |
|
---|
2592 | xml::ElementNode *pelmUSB = pelmHardware->createChild("USBController");
|
---|
2593 | pelmUSB->setAttribute("enabled", hw.usbController.fEnabled);
|
---|
2594 | pelmUSB->setAttribute("enabledEhci", hw.usbController.fEnabledEHCI);
|
---|
2595 |
|
---|
2596 | writeUSBDeviceFilters(*pelmUSB,
|
---|
2597 | hw.usbController.llDeviceFilters,
|
---|
2598 | false); // fHostMode
|
---|
2599 |
|
---|
2600 | xml::ElementNode *pelmNetwork = pelmHardware->createChild("Network");
|
---|
2601 | for (NetworkAdaptersList::const_iterator it = hw.llNetworkAdapters.begin();
|
---|
2602 | it != hw.llNetworkAdapters.end();
|
---|
2603 | ++it)
|
---|
2604 | {
|
---|
2605 | const NetworkAdapter &nic = *it;
|
---|
2606 |
|
---|
2607 | xml::ElementNode *pelmAdapter = pelmNetwork->createChild("Adapter");
|
---|
2608 | pelmAdapter->setAttribute("slot", nic.ulSlot);
|
---|
2609 | pelmAdapter->setAttribute("enabled", nic.fEnabled);
|
---|
2610 | pelmAdapter->setAttribute("MACAddress", nic.strMACAddress);
|
---|
2611 | pelmAdapter->setAttribute("cable", nic.fCableConnected);
|
---|
2612 | pelmAdapter->setAttribute("speed", nic.ulLineSpeed);
|
---|
2613 | if (nic.fTraceEnabled)
|
---|
2614 | {
|
---|
2615 | pelmAdapter->setAttribute("trace", nic.fTraceEnabled);
|
---|
2616 | pelmAdapter->setAttribute("tracefile", nic.strTraceFile);
|
---|
2617 | }
|
---|
2618 |
|
---|
2619 | const char *pcszType;
|
---|
2620 | switch (nic.type)
|
---|
2621 | {
|
---|
2622 | case NetworkAdapterType_Am79C973: pcszType = "Am79C973"; break;
|
---|
2623 | case NetworkAdapterType_I82540EM: pcszType = "82540EM"; break;
|
---|
2624 | case NetworkAdapterType_I82543GC: pcszType = "82543GC"; break;
|
---|
2625 | case NetworkAdapterType_I82545EM: pcszType = "82545EM"; break;
|
---|
2626 | case NetworkAdapterType_Virtio: pcszType = "virtio"; break;
|
---|
2627 | default: /*case NetworkAdapterType_Am79C970A:*/ pcszType = "Am79C970A"; break;
|
---|
2628 | }
|
---|
2629 | pelmAdapter->setAttribute("type", pcszType);
|
---|
2630 |
|
---|
2631 | xml::ElementNode *pelmNAT;
|
---|
2632 | switch (nic.mode)
|
---|
2633 | {
|
---|
2634 | case NetworkAttachmentType_NAT:
|
---|
2635 | pelmNAT = pelmAdapter->createChild("NAT");
|
---|
2636 | if (nic.strName.length())
|
---|
2637 | pelmNAT->setAttribute("network", nic.strName);
|
---|
2638 | break;
|
---|
2639 |
|
---|
2640 | case NetworkAttachmentType_Bridged:
|
---|
2641 | pelmAdapter->createChild("BridgedInterface")->setAttribute("name", nic.strName);
|
---|
2642 | break;
|
---|
2643 |
|
---|
2644 | case NetworkAttachmentType_Internal:
|
---|
2645 | pelmAdapter->createChild("InternalNetwork")->setAttribute("name", nic.strName);
|
---|
2646 | break;
|
---|
2647 |
|
---|
2648 | case NetworkAttachmentType_HostOnly:
|
---|
2649 | pelmAdapter->createChild("HostOnlyInterface")->setAttribute("name", nic.strName);
|
---|
2650 | break;
|
---|
2651 |
|
---|
2652 | default: /*case NetworkAttachmentType_Null:*/
|
---|
2653 | break;
|
---|
2654 | }
|
---|
2655 | }
|
---|
2656 |
|
---|
2657 | xml::ElementNode *pelmPorts = pelmHardware->createChild("UART");
|
---|
2658 | for (SerialPortsList::const_iterator it = hw.llSerialPorts.begin();
|
---|
2659 | it != hw.llSerialPorts.end();
|
---|
2660 | ++it)
|
---|
2661 | {
|
---|
2662 | const SerialPort &port = *it;
|
---|
2663 | xml::ElementNode *pelmPort = pelmPorts->createChild("Port");
|
---|
2664 | pelmPort->setAttribute("slot", port.ulSlot);
|
---|
2665 | pelmPort->setAttribute("enabled", port.fEnabled);
|
---|
2666 | pelmPort->setAttributeHex("IOBase", port.ulIOBase);
|
---|
2667 | pelmPort->setAttribute("IRQ", port.ulIRQ);
|
---|
2668 |
|
---|
2669 | const char *pcszHostMode;
|
---|
2670 | switch (port.portMode)
|
---|
2671 | {
|
---|
2672 | case PortMode_HostPipe: pcszHostMode = "HostPipe"; break;
|
---|
2673 | case PortMode_HostDevice: pcszHostMode = "HostDevice"; break;
|
---|
2674 | case PortMode_RawFile: pcszHostMode = "RawFile"; break;
|
---|
2675 | default: /*case PortMode_Disconnected:*/ pcszHostMode = "Disconnected"; break;
|
---|
2676 | }
|
---|
2677 | switch (port.portMode)
|
---|
2678 | {
|
---|
2679 | case PortMode_HostPipe:
|
---|
2680 | pelmPort->setAttribute("server", port.fServer);
|
---|
2681 | /* no break */
|
---|
2682 | case PortMode_HostDevice:
|
---|
2683 | case PortMode_RawFile:
|
---|
2684 | pelmPort->setAttribute("path", port.strPath);
|
---|
2685 | break;
|
---|
2686 |
|
---|
2687 | default:
|
---|
2688 | break;
|
---|
2689 | }
|
---|
2690 | pelmPort->setAttribute("hostMode", pcszHostMode);
|
---|
2691 | }
|
---|
2692 |
|
---|
2693 | pelmPorts = pelmHardware->createChild("LPT");
|
---|
2694 | for (ParallelPortsList::const_iterator it = hw.llParallelPorts.begin();
|
---|
2695 | it != hw.llParallelPorts.end();
|
---|
2696 | ++it)
|
---|
2697 | {
|
---|
2698 | const ParallelPort &port = *it;
|
---|
2699 | xml::ElementNode *pelmPort = pelmPorts->createChild("Port");
|
---|
2700 | pelmPort->setAttribute("slot", port.ulSlot);
|
---|
2701 | pelmPort->setAttribute("enabled", port.fEnabled);
|
---|
2702 | pelmPort->setAttributeHex("IOBase", port.ulIOBase);
|
---|
2703 | pelmPort->setAttribute("IRQ", port.ulIRQ);
|
---|
2704 | if (port.strPath.length())
|
---|
2705 | pelmPort->setAttribute("path", port.strPath);
|
---|
2706 | }
|
---|
2707 |
|
---|
2708 | xml::ElementNode *pelmAudio = pelmHardware->createChild("AudioAdapter");
|
---|
2709 | pelmAudio->setAttribute("controller", (hw.audioAdapter.controllerType == AudioControllerType_SB16) ? "SB16" : "AC97");
|
---|
2710 |
|
---|
2711 | const char *pcszDriver;
|
---|
2712 | switch (hw.audioAdapter.driverType)
|
---|
2713 | {
|
---|
2714 | case AudioDriverType_WinMM: pcszDriver = "WinMM"; break;
|
---|
2715 | case AudioDriverType_DirectSound: pcszDriver = "DirectSound"; break;
|
---|
2716 | case AudioDriverType_SolAudio: pcszDriver = "SolAudio"; break;
|
---|
2717 | case AudioDriverType_ALSA: pcszDriver = "ALSA"; break;
|
---|
2718 | case AudioDriverType_Pulse: pcszDriver = "Pulse"; break;
|
---|
2719 | case AudioDriverType_OSS: pcszDriver = "OSS"; break;
|
---|
2720 | case AudioDriverType_CoreAudio: pcszDriver = "CoreAudio"; break;
|
---|
2721 | case AudioDriverType_MMPM: pcszDriver = "MMPM"; break;
|
---|
2722 | default: /*case AudioDriverType_Null:*/ pcszDriver = "Null"; break;
|
---|
2723 | }
|
---|
2724 | pelmAudio->setAttribute("driver", pcszDriver);
|
---|
2725 |
|
---|
2726 | pelmAudio->setAttribute("enabled", hw.audioAdapter.fEnabled);
|
---|
2727 |
|
---|
2728 | xml::ElementNode *pelmSharedFolders = pelmHardware->createChild("SharedFolders");
|
---|
2729 | for (SharedFoldersList::const_iterator it = hw.llSharedFolders.begin();
|
---|
2730 | it != hw.llSharedFolders.end();
|
---|
2731 | ++it)
|
---|
2732 | {
|
---|
2733 | const SharedFolder &sf = *it;
|
---|
2734 | xml::ElementNode *pelmThis = pelmSharedFolders->createChild("SharedFolder");
|
---|
2735 | pelmThis->setAttribute("name", sf.strName);
|
---|
2736 | pelmThis->setAttribute("hostPath", sf.strHostPath);
|
---|
2737 | pelmThis->setAttribute("writable", sf.fWritable);
|
---|
2738 | }
|
---|
2739 |
|
---|
2740 | xml::ElementNode *pelmClip = pelmHardware->createChild("Clipboard");
|
---|
2741 | const char *pcszClip;
|
---|
2742 | switch (hw.clipboardMode)
|
---|
2743 | {
|
---|
2744 | case ClipboardMode_Disabled: pcszClip = "Disabled"; break;
|
---|
2745 | case ClipboardMode_HostToGuest: pcszClip = "HostToGuest"; break;
|
---|
2746 | case ClipboardMode_GuestToHost: pcszClip = "GuestToHost"; break;
|
---|
2747 | default: /*case ClipboardMode_Bidirectional:*/ pcszClip = "Bidirectional"; break;
|
---|
2748 | }
|
---|
2749 | pelmClip->setAttribute("mode", pcszClip);
|
---|
2750 |
|
---|
2751 | xml::ElementNode *pelmGuest = pelmHardware->createChild("Guest");
|
---|
2752 | pelmGuest->setAttribute("memoryBalloonSize", hw.ulMemoryBalloonSize);
|
---|
2753 | pelmGuest->setAttribute("statisticsUpdateInterval", hw.ulStatisticsUpdateInterval);
|
---|
2754 |
|
---|
2755 | xml::ElementNode *pelmGuestProps = pelmHardware->createChild("GuestProperties");
|
---|
2756 | for (GuestPropertiesList::const_iterator it = hw.llGuestProperties.begin();
|
---|
2757 | it != hw.llGuestProperties.end();
|
---|
2758 | ++it)
|
---|
2759 | {
|
---|
2760 | const GuestProperty &prop = *it;
|
---|
2761 | xml::ElementNode *pelmProp = pelmGuestProps->createChild("GuestProperty");
|
---|
2762 | pelmProp->setAttribute("name", prop.strName);
|
---|
2763 | pelmProp->setAttribute("value", prop.strValue);
|
---|
2764 | pelmProp->setAttribute("timestamp", prop.timestamp);
|
---|
2765 | pelmProp->setAttribute("flags", prop.strFlags);
|
---|
2766 | }
|
---|
2767 |
|
---|
2768 | if (hw.strNotificationPatterns.length())
|
---|
2769 | pelmGuestProps->setAttribute("notificationPatterns", hw.strNotificationPatterns);
|
---|
2770 | }
|
---|
2771 |
|
---|
2772 | /**
|
---|
2773 | * Creates a <StorageControllers> node under elmParent and then writes out the XML
|
---|
2774 | * keys under that. Called for both the <Machine> node and for snapshots.
|
---|
2775 | * @param elmParent
|
---|
2776 | * @param st
|
---|
2777 | */
|
---|
2778 | void MachineConfigFile::writeStorageControllers(xml::ElementNode &elmParent,
|
---|
2779 | const Storage &st)
|
---|
2780 | {
|
---|
2781 | xml::ElementNode *pelmStorageControllers = elmParent.createChild("StorageControllers");
|
---|
2782 |
|
---|
2783 | for (StorageControllersList::const_iterator it = st.llStorageControllers.begin();
|
---|
2784 | it != st.llStorageControllers.end();
|
---|
2785 | ++it)
|
---|
2786 | {
|
---|
2787 | const StorageController &sc = *it;
|
---|
2788 |
|
---|
2789 | if ( (m->sv < SettingsVersion_v1_9)
|
---|
2790 | && (sc.controllerType == StorageControllerType_I82078)
|
---|
2791 | )
|
---|
2792 | // floppy controller already got written into <Hardware>/<FloppyController> in writeHardware()
|
---|
2793 | // for pre-1.9 settings
|
---|
2794 | continue;
|
---|
2795 |
|
---|
2796 | xml::ElementNode *pelmController = pelmStorageControllers->createChild("StorageController");
|
---|
2797 | com::Utf8Str name = sc.strName.raw();
|
---|
2798 | //
|
---|
2799 | if (m->sv < SettingsVersion_v1_8)
|
---|
2800 | {
|
---|
2801 | // pre-1.8 settings use shorter controller names, they are
|
---|
2802 | // expanded when reading the settings
|
---|
2803 | if (name == "IDE Controller")
|
---|
2804 | name = "IDE";
|
---|
2805 | else if (name == "SATA Controller")
|
---|
2806 | name = "SATA";
|
---|
2807 | }
|
---|
2808 | pelmController->setAttribute("name", sc.strName);
|
---|
2809 |
|
---|
2810 | const char *pcszType;
|
---|
2811 | switch (sc.controllerType)
|
---|
2812 | {
|
---|
2813 | case StorageControllerType_IntelAhci: pcszType = "AHCI"; break;
|
---|
2814 | case StorageControllerType_LsiLogic: pcszType = "LsiLogic"; break;
|
---|
2815 | case StorageControllerType_BusLogic: pcszType = "BusLogic"; break;
|
---|
2816 | case StorageControllerType_PIIX4: pcszType = "PIIX4"; break;
|
---|
2817 | case StorageControllerType_ICH6: pcszType = "ICH6"; break;
|
---|
2818 | case StorageControllerType_I82078: pcszType = "I82078"; break;
|
---|
2819 | default: /*case StorageControllerType_PIIX3:*/ pcszType = "PIIX3"; break;
|
---|
2820 | }
|
---|
2821 | pelmController->setAttribute("type", pcszType);
|
---|
2822 |
|
---|
2823 | pelmController->setAttribute("PortCount", sc.ulPortCount);
|
---|
2824 |
|
---|
2825 | if (m->sv >= SettingsVersion_v1_9)
|
---|
2826 | if (sc.ulInstance)
|
---|
2827 | pelmController->setAttribute("Instance", sc.ulInstance);
|
---|
2828 |
|
---|
2829 | if (sc.controllerType == StorageControllerType_IntelAhci)
|
---|
2830 | {
|
---|
2831 | pelmController->setAttribute("IDE0MasterEmulationPort", sc.lIDE0MasterEmulationPort);
|
---|
2832 | pelmController->setAttribute("IDE0SlaveEmulationPort", sc.lIDE0SlaveEmulationPort);
|
---|
2833 | pelmController->setAttribute("IDE1MasterEmulationPort", sc.lIDE1MasterEmulationPort);
|
---|
2834 | pelmController->setAttribute("IDE1SlaveEmulationPort", sc.lIDE1SlaveEmulationPort);
|
---|
2835 | }
|
---|
2836 |
|
---|
2837 | for (AttachedDevicesList::const_iterator it2 = sc.llAttachedDevices.begin();
|
---|
2838 | it2 != sc.llAttachedDevices.end();
|
---|
2839 | ++it2)
|
---|
2840 | {
|
---|
2841 | const AttachedDevice &att = *it2;
|
---|
2842 |
|
---|
2843 | // For settings version before 1.9, DVDs and floppies are in hardware, not storage controllers,
|
---|
2844 | // so we shouldn't write them here; we only get here for DVDs though because we ruled out
|
---|
2845 | // the floppy controller at the top of the loop
|
---|
2846 | if ( att.deviceType == DeviceType_DVD
|
---|
2847 | && m->sv < SettingsVersion_v1_9
|
---|
2848 | )
|
---|
2849 | continue;
|
---|
2850 |
|
---|
2851 | xml::ElementNode *pelmDevice = pelmController->createChild("AttachedDevice");
|
---|
2852 |
|
---|
2853 | pcszType = NULL;
|
---|
2854 |
|
---|
2855 | switch (att.deviceType)
|
---|
2856 | {
|
---|
2857 | case DeviceType_HardDisk:
|
---|
2858 | pcszType = "HardDisk";
|
---|
2859 | break;
|
---|
2860 |
|
---|
2861 | case DeviceType_DVD:
|
---|
2862 | pcszType = "DVD";
|
---|
2863 | if (att.fPassThrough)
|
---|
2864 | pelmDevice->setAttribute("passthrough", att.fPassThrough);
|
---|
2865 | break;
|
---|
2866 |
|
---|
2867 | case DeviceType_Floppy:
|
---|
2868 | pcszType = "Floppy";
|
---|
2869 | break;
|
---|
2870 | }
|
---|
2871 |
|
---|
2872 | pelmDevice->setAttribute("type", pcszType);
|
---|
2873 |
|
---|
2874 | pelmDevice->setAttribute("port", att.lPort);
|
---|
2875 | pelmDevice->setAttribute("device", att.lDevice);
|
---|
2876 |
|
---|
2877 | if (!att.uuid.isEmpty())
|
---|
2878 | pelmDevice->createChild("Image")->setAttribute("uuid", makeString(att.uuid));
|
---|
2879 | else if ( (m->sv >= SettingsVersion_v1_9)
|
---|
2880 | && (att.strHostDriveSrc.length())
|
---|
2881 | )
|
---|
2882 | pelmDevice->createChild("HostDrive")->setAttribute("src", att.strHostDriveSrc);
|
---|
2883 | }
|
---|
2884 | }
|
---|
2885 | }
|
---|
2886 |
|
---|
2887 | /**
|
---|
2888 | * Writes a single snapshot into the DOM tree. Initially this gets called from MachineConfigFile::write()
|
---|
2889 | * for the root snapshot of a machine, if present; elmParent then points to the <Snapshots> node under the
|
---|
2890 | * <Machine> node to which <Snapshot> must be added. This may then recurse for child snapshots.
|
---|
2891 | * @param elmParent
|
---|
2892 | * @param snap
|
---|
2893 | */
|
---|
2894 | void MachineConfigFile::writeSnapshot(xml::ElementNode &elmParent,
|
---|
2895 | const Snapshot &snap)
|
---|
2896 | {
|
---|
2897 | xml::ElementNode *pelmSnapshot = elmParent.createChild("Snapshot");
|
---|
2898 |
|
---|
2899 | pelmSnapshot->setAttribute("uuid", makeString(snap.uuid));
|
---|
2900 | pelmSnapshot->setAttribute("name", snap.strName);
|
---|
2901 | pelmSnapshot->setAttribute("timeStamp", makeString(snap.timestamp));
|
---|
2902 |
|
---|
2903 | if (snap.strStateFile.length())
|
---|
2904 | pelmSnapshot->setAttribute("stateFile", snap.strStateFile);
|
---|
2905 |
|
---|
2906 | if (snap.strDescription.length())
|
---|
2907 | pelmSnapshot->createChild("Description")->addContent(snap.strDescription);
|
---|
2908 |
|
---|
2909 | writeHardware(*pelmSnapshot, snap.hardware, snap.storage);
|
---|
2910 | writeStorageControllers(*pelmSnapshot, snap.storage);
|
---|
2911 |
|
---|
2912 | if (snap.llChildSnapshots.size())
|
---|
2913 | {
|
---|
2914 | xml::ElementNode *pelmChildren = pelmSnapshot->createChild("Snapshots");
|
---|
2915 | for (SnapshotsList::const_iterator it = snap.llChildSnapshots.begin();
|
---|
2916 | it != snap.llChildSnapshots.end();
|
---|
2917 | ++it)
|
---|
2918 | {
|
---|
2919 | const Snapshot &child = *it;
|
---|
2920 | writeSnapshot(*pelmChildren, child);
|
---|
2921 | }
|
---|
2922 | }
|
---|
2923 | }
|
---|
2924 |
|
---|
2925 | /**
|
---|
2926 | * Called from write() before calling ConfigFileBase::createStubDocument().
|
---|
2927 | * This adjusts the settings version in m->sv if incompatible settings require
|
---|
2928 | * a settings bump, whereas otherwise we try to preserve the settings version
|
---|
2929 | * to avoid breaking compatibility with older versions.
|
---|
2930 | */
|
---|
2931 | void MachineConfigFile::bumpSettingsVersionIfNeeded()
|
---|
2932 | {
|
---|
2933 | // "accelerate 2d video" requires settings version 1.8
|
---|
2934 | if ( (m->sv < SettingsVersion_v1_8)
|
---|
2935 | && (hardwareMachine.fAccelerate2DVideo)
|
---|
2936 | )
|
---|
2937 | m->sv = SettingsVersion_v1_8;
|
---|
2938 |
|
---|
2939 | // all the following require settings version 1.9
|
---|
2940 | if ( (m->sv < SettingsVersion_v1_9)
|
---|
2941 | && ( (hardwareMachine.firmwareType == FirmwareType_EFI)
|
---|
2942 | || (hardwareMachine.fHardwareVirtExclusive != HWVIRTEXCLUSIVEDEFAULT)
|
---|
2943 | || fTeleporterEnabled
|
---|
2944 | || uTeleporterPort
|
---|
2945 | || !strTeleporterAddress.isEmpty()
|
---|
2946 | || !strTeleporterPassword.isEmpty()
|
---|
2947 | || !hardwareMachine.uuid.isEmpty()
|
---|
2948 | )
|
---|
2949 | )
|
---|
2950 | m->sv = SettingsVersion_v1_9;
|
---|
2951 |
|
---|
2952 | // settings version 1.9 is also required if there is not exactly one DVD
|
---|
2953 | // or more than one floppy drive present or the DVD is not at the secondary
|
---|
2954 | // master; this check is a bit more complicated
|
---|
2955 | if (m->sv < SettingsVersion_v1_9)
|
---|
2956 | {
|
---|
2957 | size_t cDVDs = 0;
|
---|
2958 | size_t cFloppies = 0;
|
---|
2959 |
|
---|
2960 | // need to run thru all the storage controllers to figure this out
|
---|
2961 | for (StorageControllersList::const_iterator it = storageMachine.llStorageControllers.begin();
|
---|
2962 | it != storageMachine.llStorageControllers.end()
|
---|
2963 | && m->sv < SettingsVersion_v1_9;
|
---|
2964 | ++it)
|
---|
2965 | {
|
---|
2966 | const StorageController &sctl = *it;
|
---|
2967 | for (AttachedDevicesList::const_iterator it2 = sctl.llAttachedDevices.begin();
|
---|
2968 | it2 != sctl.llAttachedDevices.end();
|
---|
2969 | ++it2)
|
---|
2970 | {
|
---|
2971 | if (sctl.ulInstance != 0) // we can only write the StorageController/@Instance attribute with v1.9
|
---|
2972 | {
|
---|
2973 | m->sv = SettingsVersion_v1_9;
|
---|
2974 | break;
|
---|
2975 | }
|
---|
2976 |
|
---|
2977 | const AttachedDevice &att = *it2;
|
---|
2978 | if (att.deviceType == DeviceType_DVD)
|
---|
2979 | {
|
---|
2980 | if ( (sctl.storageBus != StorageBus_IDE) // DVD at bus other than DVD?
|
---|
2981 | || (att.lPort != 1) // DVDs not at secondary master?
|
---|
2982 | || (att.lDevice != 0)
|
---|
2983 | )
|
---|
2984 | {
|
---|
2985 | m->sv = SettingsVersion_v1_9;
|
---|
2986 | break;
|
---|
2987 | }
|
---|
2988 |
|
---|
2989 | ++cDVDs;
|
---|
2990 | }
|
---|
2991 | else if (att.deviceType == DeviceType_Floppy)
|
---|
2992 | ++cFloppies;
|
---|
2993 | }
|
---|
2994 | }
|
---|
2995 |
|
---|
2996 | // VirtualBox before 3.1 had zero or one floppy and exactly one DVD,
|
---|
2997 | // so any deviation from that will require settings version 1.9
|
---|
2998 | if ( (m->sv < SettingsVersion_v1_9)
|
---|
2999 | && ( (cDVDs != 1)
|
---|
3000 | || (cFloppies > 1)
|
---|
3001 | )
|
---|
3002 | )
|
---|
3003 | m->sv = SettingsVersion_v1_9;
|
---|
3004 | }
|
---|
3005 | }
|
---|
3006 |
|
---|
3007 | /**
|
---|
3008 | * Called from Main code to write a machine config file to disk. This builds a DOM tree from
|
---|
3009 | * the member variables and then writes the XML file; it throws xml::Error instances on errors,
|
---|
3010 | * in particular if the file cannot be written.
|
---|
3011 | */
|
---|
3012 | void MachineConfigFile::write(const com::Utf8Str &strFilename)
|
---|
3013 | {
|
---|
3014 | try
|
---|
3015 | {
|
---|
3016 | // createStubDocument() sets the settings version to at least 1.7; however,
|
---|
3017 | // we might need to enfore a later settings version if incompatible settings
|
---|
3018 | // are present:
|
---|
3019 | bumpSettingsVersionIfNeeded();
|
---|
3020 |
|
---|
3021 | m->strFilename = strFilename;
|
---|
3022 | createStubDocument();
|
---|
3023 |
|
---|
3024 | xml::ElementNode *pelmMachine = m->pelmRoot->createChild("Machine");
|
---|
3025 |
|
---|
3026 | pelmMachine->setAttribute("uuid", makeString(uuid));
|
---|
3027 | pelmMachine->setAttribute("name", strName);
|
---|
3028 | if (!fNameSync)
|
---|
3029 | pelmMachine->setAttribute("nameSync", fNameSync);
|
---|
3030 | if (strDescription.length())
|
---|
3031 | pelmMachine->createChild("Description")->addContent(strDescription);
|
---|
3032 | pelmMachine->setAttribute("OSType", strOsType);
|
---|
3033 | if (strStateFile.length())
|
---|
3034 | pelmMachine->setAttribute("stateFile", strStateFile);
|
---|
3035 | if (!uuidCurrentSnapshot.isEmpty())
|
---|
3036 | pelmMachine->setAttribute("currentSnapshot", makeString(uuidCurrentSnapshot));
|
---|
3037 | if (strSnapshotFolder.length())
|
---|
3038 | pelmMachine->setAttribute("snapshotFolder", strSnapshotFolder);
|
---|
3039 | if (!fCurrentStateModified)
|
---|
3040 | pelmMachine->setAttribute("currentStateModified", fCurrentStateModified);
|
---|
3041 | pelmMachine->setAttribute("lastStateChange", makeString(timeLastStateChange));
|
---|
3042 | if (fAborted)
|
---|
3043 | pelmMachine->setAttribute("aborted", fAborted);
|
---|
3044 | if ( m->sv >= SettingsVersion_v1_9
|
---|
3045 | && ( fTeleporterEnabled
|
---|
3046 | || uTeleporterPort
|
---|
3047 | || !strTeleporterAddress.isEmpty()
|
---|
3048 | || !strTeleporterPassword.isEmpty()
|
---|
3049 | )
|
---|
3050 | )
|
---|
3051 | {
|
---|
3052 | xml::ElementNode *pelmTeleporter = pelmMachine->createChild("Teleporter");
|
---|
3053 | pelmTeleporter->setAttribute("enabled", fTeleporterEnabled);
|
---|
3054 | pelmTeleporter->setAttribute("port", uTeleporterPort);
|
---|
3055 | pelmTeleporter->setAttribute("address", strTeleporterAddress);
|
---|
3056 | pelmTeleporter->setAttribute("password", strTeleporterPassword);
|
---|
3057 | }
|
---|
3058 |
|
---|
3059 | writeExtraData(*pelmMachine, mapExtraDataItems);
|
---|
3060 |
|
---|
3061 | if (llFirstSnapshot.size())
|
---|
3062 | writeSnapshot(*pelmMachine, llFirstSnapshot.front());
|
---|
3063 |
|
---|
3064 | writeHardware(*pelmMachine, hardwareMachine, storageMachine);
|
---|
3065 | writeStorageControllers(*pelmMachine, storageMachine);
|
---|
3066 |
|
---|
3067 | // now go write the XML
|
---|
3068 | xml::XmlFileWriter writer(*m->pDoc);
|
---|
3069 | writer.write(m->strFilename.c_str());
|
---|
3070 |
|
---|
3071 | m->fFileExists = true;
|
---|
3072 | clearDocument();
|
---|
3073 | }
|
---|
3074 | catch (...)
|
---|
3075 | {
|
---|
3076 | clearDocument();
|
---|
3077 | throw;
|
---|
3078 | }
|
---|
3079 | }
|
---|