VirtualBox

source: vbox/trunk/include/VBox/settings.h@ 81087

最後變更 在這個檔案從81087是 81087,由 vboxsync 提交於 5 年 前

Main/Machine+BIOSSettings: bare bones NVRAM logic, many parts missing (no snapshot handling, no move VM handling, no remove VM handling).
Main/Settings: adaptions to store NVRAM config in the settings file
Frontends/VBoxManage: support enabling and showing state

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Date Revision Author Id
檔案大小: 44.1 KB
 
1/** @file
2 * Settings file data structures.
3 *
4 * These structures are created by the settings file loader and filled with values
5 * copied from the raw XML data. This was all new with VirtualBox 3.1 and allows us
6 * to finally make the XML reader version-independent and read VirtualBox XML files
7 * from earlier and even newer (future) versions without requiring complicated,
8 * tedious and error-prone XSLT conversions.
9 *
10 * It is this file that defines all structures that map VirtualBox global and
11 * machine settings to XML files. These structures are used by the rest of Main,
12 * even though this header file does not require anything else in Main.
13 *
14 * Note: Headers in Main code have been tweaked to only declare the structures
15 * defined here so that this header need only be included from code files that
16 * actually use these structures.
17 */
18
19/*
20 * Copyright (C) 2007-2019 Oracle Corporation
21 *
22 * This file is part of VirtualBox Open Source Edition (OSE), as
23 * available from http://www.alldomusa.eu.org. This file is free software;
24 * you can redistribute it and/or modify it under the terms of the GNU
25 * General Public License (GPL) as published by the Free Software
26 * Foundation, in version 2 as it comes in the "COPYING" file of the
27 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
28 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
29 *
30 * The contents of this file may alternatively be used under the terms
31 * of the Common Development and Distribution License Version 1.0
32 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
33 * VirtualBox OSE distribution, in which case the provisions of the
34 * CDDL are applicable instead of those of the GPL.
35 *
36 * You may elect to license modified versions of this file under the
37 * terms and conditions of either the GPL or the CDDL or both.
38 */
39
40#ifndef VBOX_INCLUDED_settings_h
41#define VBOX_INCLUDED_settings_h
42#ifndef RT_WITHOUT_PRAGMA_ONCE
43# pragma once
44#endif
45
46#include <iprt/time.h>
47
48#include "VBox/com/VirtualBox.h"
49
50#include <VBox/com/Guid.h>
51#include <VBox/com/string.h>
52
53#include <list>
54#include <map>
55#include <vector>
56
57/**
58 * Maximum depth of a medium tree, to prevent stack overflows.
59 * XPCOM has a relatively low stack size for its workers, and we have
60 * to avoid crashes due to exceeding the limit both on reading and
61 * writing config files.
62 */
63#define SETTINGS_MEDIUM_DEPTH_MAX 300
64
65/**
66 * Maximum depth of the snapshot tree, to prevent stack overflows.
67 * XPCOM has a relatively low stack size for its workers, and we have
68 * to avoid crashes due to exceeding the limit both on reading and
69 * writing config files. The bottleneck is reading config files with
70 * deep snapshot nesting, as libxml2 needs quite some stack space,
71 * so with the current stack size the margin isn't big.
72 */
73#define SETTINGS_SNAPSHOT_DEPTH_MAX 250
74
75namespace xml
76{
77 class ElementNode;
78}
79
80namespace settings
81{
82
83class ConfigFileError;
84
85////////////////////////////////////////////////////////////////////////////////
86//
87// Structures shared between Machine XML and VirtualBox.xml
88//
89////////////////////////////////////////////////////////////////////////////////
90
91typedef std::map<com::Utf8Str, com::Utf8Str> StringsMap;
92typedef std::list<com::Utf8Str> StringsList;
93
94/**
95 * USB device filter definition. This struct is used both in MainConfigFile
96 * (for global USB filters) and MachineConfigFile (for machine filters).
97 *
98 * NOTE: If you add any fields in here, you must update a) the constructor and b)
99 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
100 * your settings might never get saved.
101 */
102struct USBDeviceFilter
103{
104 USBDeviceFilter();
105
106 bool operator==(const USBDeviceFilter&u) const;
107
108 com::Utf8Str strName;
109 bool fActive;
110 com::Utf8Str strVendorId,
111 strProductId,
112 strRevision,
113 strManufacturer,
114 strProduct,
115 strSerialNumber,
116 strPort;
117 USBDeviceFilterAction_T action; // only used with host USB filters
118 com::Utf8Str strRemote; // irrelevant for host USB objects
119 uint32_t ulMaskedInterfaces; // irrelevant for host USB objects
120};
121
122typedef std::list<USBDeviceFilter> USBDeviceFiltersList;
123
124struct Medium;
125typedef std::list<Medium> MediaList;
126
127/**
128 * NOTE: If you add any fields in here, you must update a) the constructor and b)
129 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
130 * your settings might never get saved.
131 */
132struct Medium
133{
134 Medium();
135
136 bool operator==(const Medium &m) const;
137
138 com::Guid uuid;
139 com::Utf8Str strLocation;
140 com::Utf8Str strDescription;
141
142 // the following are for hard disks only:
143 com::Utf8Str strFormat;
144 bool fAutoReset; // optional, only for diffs, default is false
145 StringsMap properties;
146 MediumType_T hdType;
147
148 MediaList llChildren; // only used with hard disks
149
150 static const struct Medium Empty;
151};
152
153/**
154 * A media registry. Starting with VirtualBox 3.3, this can appear in both the
155 * VirtualBox.xml file as well as machine XML files with settings version 1.11
156 * or higher, so these lists are now in ConfigFileBase.
157 *
158 * NOTE: If you add any fields in here, you must update a) the constructor and b)
159 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
160 * your settings might never get saved.
161 */
162struct MediaRegistry
163{
164 bool operator==(const MediaRegistry &m) const;
165
166 MediaList llHardDisks,
167 llDvdImages,
168 llFloppyImages;
169};
170
171/**
172 * NOTE: If you add any fields in here, you must update a) the constructor and b)
173 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
174 * your settings might never get saved.
175 */
176struct NATRule
177{
178 NATRule();
179
180 bool operator==(const NATRule &r) const;
181
182 com::Utf8Str strName;
183 NATProtocol_T proto;
184 uint16_t u16HostPort;
185 com::Utf8Str strHostIP;
186 uint16_t u16GuestPort;
187 com::Utf8Str strGuestIP;
188};
189typedef std::map<com::Utf8Str, NATRule> NATRulesMap;
190
191struct NATHostLoopbackOffset
192{
193 NATHostLoopbackOffset();
194
195 bool operator==(const NATHostLoopbackOffset &o) const;
196
197 bool operator==(const com::Utf8Str& strAddr)
198 {
199 return strLoopbackHostAddress == strAddr;
200 }
201
202 bool operator==(uint32_t off)
203 {
204 return u32Offset == off;
205 }
206
207 /** Note: 128/8 is only acceptable */
208 com::Utf8Str strLoopbackHostAddress;
209 uint32_t u32Offset;
210};
211
212typedef std::list<NATHostLoopbackOffset> NATLoopbackOffsetList;
213
214typedef std::vector<uint8_t> IconBlob;
215
216/**
217 * Common base class for both MainConfigFile and MachineConfigFile
218 * which contains some common logic for both.
219 */
220class ConfigFileBase
221{
222public:
223 bool fileExists();
224
225 void copyBaseFrom(const ConfigFileBase &b);
226
227protected:
228 ConfigFileBase(const com::Utf8Str *pstrFilename);
229 /* Note: this copy constructor doesn't create a full copy of other, cause
230 * the file based stuff (xml doc) could not be copied. */
231 ConfigFileBase(const ConfigFileBase &other);
232
233 ~ConfigFileBase();
234
235 typedef enum {Error, HardDisk, DVDImage, FloppyImage} MediaType;
236
237 static const char *stringifyMediaType(MediaType t);
238 SettingsVersion_T parseVersion(const com::Utf8Str &strVersion,
239 const xml::ElementNode *pElm);
240 void parseUUID(com::Guid &guid,
241 const com::Utf8Str &strUUID,
242 const xml::ElementNode *pElm) const;
243 void parseTimestamp(RTTIMESPEC &timestamp,
244 const com::Utf8Str &str,
245 const xml::ElementNode *pElm) const;
246 void parseBase64(IconBlob &binary,
247 const com::Utf8Str &str,
248 const xml::ElementNode *pElm) const;
249 com::Utf8Str stringifyTimestamp(const RTTIMESPEC &tm) const;
250 void toBase64(com::Utf8Str &str,
251 const IconBlob &binary) const;
252
253 void readExtraData(const xml::ElementNode &elmExtraData,
254 StringsMap &map);
255 void readUSBDeviceFilters(const xml::ElementNode &elmDeviceFilters,
256 USBDeviceFiltersList &ll);
257 void readMediumOne(MediaType t, const xml::ElementNode &elmMedium, Medium &med);
258 void readMedium(MediaType t, uint32_t depth, const xml::ElementNode &elmMedium, Medium &med);
259 void readMediaRegistry(const xml::ElementNode &elmMediaRegistry, MediaRegistry &mr);
260 void readNATForwardRulesMap(const xml::ElementNode &elmParent, NATRulesMap &mapRules);
261 void readNATLoopbacks(const xml::ElementNode &elmParent, NATLoopbackOffsetList &llLoopBacks);
262
263 void setVersionAttribute(xml::ElementNode &elm);
264 void specialBackupIfFirstBump();
265 void createStubDocument();
266
267 void buildExtraData(xml::ElementNode &elmParent, const StringsMap &me);
268 void buildUSBDeviceFilters(xml::ElementNode &elmParent,
269 const USBDeviceFiltersList &ll,
270 bool fHostMode);
271 void buildMedium(MediaType t,
272 uint32_t depth,
273 xml::ElementNode &elmMedium,
274 const Medium &mdm);
275 void buildMediaRegistry(xml::ElementNode &elmParent,
276 const MediaRegistry &mr);
277 void buildNATForwardRulesMap(xml::ElementNode &elmParent, const NATRulesMap &mapRules);
278 void buildNATLoopbacks(xml::ElementNode &elmParent, const NATLoopbackOffsetList &natLoopbackList);
279 void clearDocument();
280
281 struct Data;
282 Data *m;
283
284 friend class ConfigFileError;
285};
286
287////////////////////////////////////////////////////////////////////////////////
288//
289// VirtualBox.xml structures
290//
291////////////////////////////////////////////////////////////////////////////////
292
293struct USBDeviceSource
294{
295 com::Utf8Str strName;
296 com::Utf8Str strBackend;
297 com::Utf8Str strAddress;
298 StringsMap properties;
299};
300
301typedef std::list<USBDeviceSource> USBDeviceSourcesList;
302
303struct Host
304{
305 USBDeviceFiltersList llUSBDeviceFilters;
306 USBDeviceSourcesList llUSBDeviceSources;
307};
308
309struct SystemProperties
310{
311 SystemProperties();
312
313 com::Utf8Str strDefaultMachineFolder;
314 com::Utf8Str strDefaultHardDiskFolder;
315 com::Utf8Str strDefaultHardDiskFormat;
316 com::Utf8Str strVRDEAuthLibrary;
317 com::Utf8Str strWebServiceAuthLibrary;
318 com::Utf8Str strDefaultVRDEExtPack;
319 com::Utf8Str strAutostartDatabasePath;
320 com::Utf8Str strDefaultAdditionsISO;
321 com::Utf8Str strDefaultFrontend;
322 com::Utf8Str strLoggingLevel;
323 com::Utf8Str strProxyUrl;
324 uint32_t uProxyMode; /**< ProxyMode_T */
325 uint32_t uLogHistoryCount;
326 bool fExclusiveHwVirt;
327};
328
329struct MachineRegistryEntry
330{
331 com::Guid uuid;
332 com::Utf8Str strSettingsFile;
333};
334
335typedef std::list<MachineRegistryEntry> MachinesRegistry;
336
337struct DhcpOptValue
338{
339 DhcpOptValue();
340 DhcpOptValue(const com::Utf8Str &aText, DHCPOptionEncoding_T aEncoding = DHCPOptionEncoding_Normal);
341
342 com::Utf8Str strValue;
343 DHCPOptionEncoding_T enmEncoding;
344};
345
346typedef std::map<DHCPOption_T, DhcpOptValue> DhcpOptionMap;
347typedef DhcpOptionMap::value_type DhcpOptValuePair;
348typedef DhcpOptionMap::iterator DhcpOptIterator;
349typedef DhcpOptionMap::const_iterator DhcpOptConstIterator;
350
351struct DHCPGroupCondition
352{
353 DHCPGroupCondition();
354
355 bool fInclusive;
356 DHCPGroupConditionType_T enmType;
357 com::Utf8Str strValue;
358};
359typedef std::vector<DHCPGroupCondition> DHCPGroupConditionVec;
360
361
362struct DHCPConfig
363{
364 DHCPConfig();
365
366 DhcpOptionMap mapOptions;
367 uint32_t secMinLeaseTime;
368 uint32_t secDefaultLeaseTime;
369 uint32_t secMaxLeaseTime;
370 com::Utf8Str strForcedOptions;
371 com::Utf8Str strSuppressedOptions;
372};
373
374struct DHCPGroupConfig : DHCPConfig
375{
376 DHCPGroupConfig();
377
378 com::Utf8Str strName;
379 DHCPGroupConditionVec vecConditions;
380};
381typedef std::vector<DHCPGroupConfig> DHCPGroupConfigVec;
382
383struct DHCPIndividualConfig : DHCPConfig
384{
385 DHCPIndividualConfig();
386
387 com::Utf8Str strMACAddress;
388 com::Utf8Str strVMName;
389 uint32_t uSlot;
390 com::Utf8Str strFixedAddress;
391};
392typedef std::map<com::Utf8Str, DHCPIndividualConfig> DHCPIndividualConfigMap;
393
394struct DHCPServer
395{
396 DHCPServer();
397
398 com::Utf8Str strNetworkName;
399 com::Utf8Str strIPAddress;
400 com::Utf8Str strIPLower;
401 com::Utf8Str strIPUpper;
402 bool fEnabled;
403 DHCPConfig globalConfig;
404 DHCPGroupConfigVec vecGroupConfigs;
405 DHCPIndividualConfigMap mapIndividualConfigs;
406};
407typedef std::list<DHCPServer> DHCPServersList;
408
409
410/**
411 * NAT Networking settings (NAT service).
412 */
413struct NATNetwork
414{
415 NATNetwork();
416
417 com::Utf8Str strNetworkName;
418 com::Utf8Str strIPv4NetworkCidr;
419 com::Utf8Str strIPv6Prefix;
420 bool fEnabled;
421 bool fIPv6Enabled;
422 bool fAdvertiseDefaultIPv6Route;
423 bool fNeedDhcpServer;
424 uint32_t u32HostLoopback6Offset;
425 NATLoopbackOffsetList llHostLoopbackOffsetList;
426 NATRulesMap mapPortForwardRules4;
427 NATRulesMap mapPortForwardRules6;
428};
429
430typedef std::list<NATNetwork> NATNetworksList;
431
432
433class MainConfigFile : public ConfigFileBase
434{
435public:
436 MainConfigFile(const com::Utf8Str *pstrFilename);
437
438 void readMachineRegistry(const xml::ElementNode &elmMachineRegistry);
439 void readNATNetworks(const xml::ElementNode &elmNATNetworks);
440
441 void write(const com::Utf8Str strFilename);
442
443 Host host;
444 SystemProperties systemProperties;
445 MediaRegistry mediaRegistry;
446 MachinesRegistry llMachines;
447 DHCPServersList llDhcpServers;
448 NATNetworksList llNATNetworks;
449 StringsMap mapExtraDataItems;
450
451private:
452 void bumpSettingsVersionIfNeeded();
453 void buildUSBDeviceSources(xml::ElementNode &elmParent, const USBDeviceSourcesList &ll);
454 void readUSBDeviceSources(const xml::ElementNode &elmDeviceSources, USBDeviceSourcesList &ll);
455 void buildDHCPServers(xml::ElementNode &elmDHCPServers, DHCPServersList const &ll);
456 void buildDHCPOptions(xml::ElementNode &elmOptions, DHCPConfig const &rConfig, bool fIgnoreSubnetMask);
457 void readDHCPServers(const xml::ElementNode &elmDHCPServers);
458 void readDHCPOptions(DHCPConfig &rConfig, const xml::ElementNode &elmOptions, bool fIgnoreSubnetMask);
459 bool convertGuiProxySettings(const com::Utf8Str &strUIProxySettings);
460};
461
462////////////////////////////////////////////////////////////////////////////////
463//
464// Machine XML structures
465//
466////////////////////////////////////////////////////////////////////////////////
467
468/**
469 * NOTE: If you add any fields in here, you must update a) the constructor and b)
470 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
471 * your settings might never get saved.
472 */
473struct VRDESettings
474{
475 VRDESettings();
476
477 bool areDefaultSettings(SettingsVersion_T sv) const;
478
479 bool operator==(const VRDESettings& v) const;
480
481 bool fEnabled;
482 AuthType_T authType;
483 uint32_t ulAuthTimeout;
484 com::Utf8Str strAuthLibrary;
485 bool fAllowMultiConnection,
486 fReuseSingleConnection;
487 com::Utf8Str strVrdeExtPack;
488 StringsMap mapProperties;
489};
490
491/**
492 * NOTE: If you add any fields in here, you must update a) the constructor and b)
493 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
494 * your settings might never get saved.
495 */
496struct BIOSSettings
497{
498 BIOSSettings();
499
500 bool areDefaultSettings() const;
501
502 bool operator==(const BIOSSettings &d) const;
503
504 bool fACPIEnabled,
505 fIOAPICEnabled,
506 fLogoFadeIn,
507 fLogoFadeOut,
508 fPXEDebugEnabled,
509 fNVRAMEnabled;
510 uint32_t ulLogoDisplayTime;
511 BIOSBootMenuMode_T biosBootMenuMode;
512 APICMode_T apicMode; // requires settings version 1.16 (VirtualBox 5.1)
513 int64_t llTimeOffset;
514 com::Utf8Str strLogoImagePath;
515 com::Utf8Str strNVRAMPath;
516};
517
518/** List for keeping a recording feature list. */
519typedef std::map<RecordingFeature_T, bool> RecordingFeatureMap;
520
521struct RecordingScreenSettings
522{
523 RecordingScreenSettings();
524
525 virtual ~RecordingScreenSettings();
526
527 void applyDefaults(void);
528
529 bool areDefaultSettings(void) const;
530
531 bool isFeatureEnabled(RecordingFeature_T enmFeature) const;
532
533 bool operator==(const RecordingScreenSettings &d) const;
534
535 /** Whether to record this screen or not. */
536 bool fEnabled; // requires settings version 1.14 (VirtualBox 4.3)
537 /** Destination to record to. */
538 RecordingDestination_T enmDest; /** @todo Implement with next settings version bump. */
539 /** Which features are enable or not. */
540 RecordingFeatureMap featureMap; /** @todo Implement with next settings version bump. */
541 /** Maximum time (in s) to record. If set to 0, no time limit is set. */
542 uint32_t ulMaxTimeS; // requires settings version 1.14 (VirtualBox 4.3)
543 /** Options string for hidden / advanced / experimental features. */
544 com::Utf8Str strOptions; // new since VirtualBox 5.2.
545
546 /**
547 * Structure holding settings for audio recording.
548 */
549 struct Audio
550 {
551 Audio()
552 : enmAudioCodec(RecordingAudioCodec_Opus)
553 , uHz(22050)
554 , cBits(16)
555 , cChannels(2) { }
556
557 /** The audio codec type to use. */
558 RecordingAudioCodec_T enmAudioCodec; /** @todo Implement with next settings version bump. */
559 /** Hz rate. */
560 uint16_t uHz; /** @todo Implement with next settings version bump. */
561 /** Bits per sample. */
562 uint8_t cBits; /** @todo Implement with next settings version bump. */
563 /** Number of audio channels. */
564 uint8_t cChannels; /** @todo Implement with next settings version bump. */
565 } Audio;
566
567 /**
568 * Structure holding settings for video recording.
569 */
570 struct Video
571 {
572 Video()
573 : enmCodec(RecordingVideoCodec_VP8)
574 , ulWidth(1024)
575 , ulHeight(768)
576 , ulRate(512)
577 , ulFPS(25) { }
578
579 /** The codec to use. */
580 RecordingVideoCodec_T enmCodec; /** @todo Implement with next settings version bump. */
581 /** Target frame width in pixels (X). */
582 uint32_t ulWidth; // requires settings version 1.14 (VirtualBox 4.3)
583 /** Target frame height in pixels (Y). */
584 uint32_t ulHeight; // requires settings version 1.14 (VirtualBox 4.3)
585 /** Encoding rate. */
586 uint32_t ulRate; // requires settings version 1.14 (VirtualBox 4.3)
587 /** Frames per second (FPS). */
588 uint32_t ulFPS; // requires settings version 1.14 (VirtualBox 4.3)
589 } Video;
590
591 /**
592 * Structure holding settings if the destination is a file.
593 */
594 struct File
595 {
596 File()
597 : ulMaxSizeMB(0) { }
598
599 /** Maximum size (in MB) the file is allowed to have.
600 * When reaching the limit, recording will stop. */
601 uint32_t ulMaxSizeMB; // requires settings version 1.14 (VirtualBox 4.3)
602 /** Absolute file name path to use for recording. */
603 com::Utf8Str strName; // requires settings version 1.14 (VirtualBox 4.3)
604 } File;
605};
606
607/** Map for keeping settings per virtual screen.
608 * The key specifies the screen ID. */
609typedef std::map<uint32_t, RecordingScreenSettings> RecordingScreenMap;
610
611/**
612 * NOTE: If you add any fields in here, you must update a) the constructor and b)
613 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
614 * your settings might never get saved.
615 */
616struct RecordingSettings
617{
618 RecordingSettings();
619
620 void applyDefaults(void);
621
622 bool areDefaultSettings(void) const;
623
624 bool operator==(const RecordingSettings &d) const;
625
626 /** Whether recording as a whole is enabled or disabled. */
627 bool fEnabled; // requires settings version 1.14 (VirtualBox 4.3)
628 /** Map of handled recording screen settings.
629 * The key specifies the screen ID. */
630 RecordingScreenMap mapScreens;
631};
632
633/**
634 * NOTE: If you add any fields in here, you must update a) the constructor and b)
635 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
636 * your settings might never get saved.
637 */
638struct USBController
639{
640 USBController();
641
642 bool operator==(const USBController &u) const;
643
644 com::Utf8Str strName;
645 USBControllerType_T enmType;
646};
647
648typedef std::list<USBController> USBControllerList;
649
650struct USB
651{
652 USB();
653
654 bool operator==(const USB &u) const;
655
656 /** List of USB controllers present. */
657 USBControllerList llUSBControllers;
658 /** List of USB device filters. */
659 USBDeviceFiltersList llDeviceFilters;
660};
661
662struct NAT
663{
664 NAT();
665
666 bool areDNSDefaultSettings() const;
667 bool areAliasDefaultSettings() const;
668 bool areTFTPDefaultSettings() const;
669 bool areDefaultSettings() const;
670
671 bool operator==(const NAT &n) const;
672
673 com::Utf8Str strNetwork;
674 com::Utf8Str strBindIP;
675 uint32_t u32Mtu;
676 uint32_t u32SockRcv;
677 uint32_t u32SockSnd;
678 uint32_t u32TcpRcv;
679 uint32_t u32TcpSnd;
680 com::Utf8Str strTFTPPrefix;
681 com::Utf8Str strTFTPBootFile;
682 com::Utf8Str strTFTPNextServer;
683 bool fDNSPassDomain;
684 bool fDNSProxy;
685 bool fDNSUseHostResolver;
686 bool fAliasLog;
687 bool fAliasProxyOnly;
688 bool fAliasUseSamePorts;
689 NATRulesMap mapRules;
690};
691
692/**
693 * NOTE: If you add any fields in here, you must update a) the constructor and b)
694 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
695 * your settings might never get saved.
696 */
697struct NetworkAdapter
698{
699 NetworkAdapter();
700
701 bool areGenericDriverDefaultSettings() const;
702 bool areDefaultSettings(SettingsVersion_T sv) const;
703 bool areDisabledDefaultSettings() const;
704
705 bool operator==(const NetworkAdapter &n) const;
706
707 uint32_t ulSlot;
708
709 NetworkAdapterType_T type;
710 bool fEnabled;
711 com::Utf8Str strMACAddress;
712 bool fCableConnected;
713 uint32_t ulLineSpeed;
714 NetworkAdapterPromiscModePolicy_T enmPromiscModePolicy;
715 bool fTraceEnabled;
716 com::Utf8Str strTraceFile;
717
718 NetworkAttachmentType_T mode;
719 NAT nat;
720 com::Utf8Str strBridgedName;
721 com::Utf8Str strHostOnlyName;
722 com::Utf8Str strInternalNetworkName;
723 com::Utf8Str strGenericDriver;
724 StringsMap genericProperties;
725 com::Utf8Str strNATNetworkName;
726 uint32_t ulBootPriority;
727 com::Utf8Str strBandwidthGroup; // requires settings version 1.13 (VirtualBox 4.2)
728};
729
730typedef std::list<NetworkAdapter> NetworkAdaptersList;
731
732/**
733 * NOTE: If you add any fields in here, you must update a) the constructor and b)
734 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
735 * your settings might never get saved.
736 */
737struct SerialPort
738{
739 SerialPort();
740
741 bool operator==(const SerialPort &n) const;
742
743 uint32_t ulSlot;
744
745 bool fEnabled;
746 uint32_t ulIOBase;
747 uint32_t ulIRQ;
748 PortMode_T portMode;
749 com::Utf8Str strPath;
750 bool fServer;
751 UartType_T uartType;
752};
753
754typedef std::list<SerialPort> SerialPortsList;
755
756/**
757 * NOTE: If you add any fields in here, you must update a) the constructor and b)
758 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
759 * your settings might never get saved.
760 */
761struct ParallelPort
762{
763 ParallelPort();
764
765 bool operator==(const ParallelPort &d) const;
766
767 uint32_t ulSlot;
768
769 bool fEnabled;
770 uint32_t ulIOBase;
771 uint32_t ulIRQ;
772 com::Utf8Str strPath;
773};
774
775typedef std::list<ParallelPort> ParallelPortsList;
776
777/**
778 * NOTE: If you add any fields in here, you must update a) the constructor and b)
779 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
780 * your settings might never get saved.
781 */
782struct AudioAdapter
783{
784 AudioAdapter();
785
786 bool areDefaultSettings(SettingsVersion_T sv) const;
787
788 bool operator==(const AudioAdapter &a) const;
789
790 bool fEnabled;
791 bool fEnabledIn;
792 bool fEnabledOut;
793 AudioControllerType_T controllerType;
794 AudioCodecType_T codecType;
795 AudioDriverType_T driverType;
796 settings::StringsMap properties;
797};
798
799/**
800 * NOTE: If you add any fields in here, you must update a) the constructor and b)
801 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
802 * your settings might never get saved.
803 */
804struct SharedFolder
805{
806 SharedFolder();
807
808 bool operator==(const SharedFolder &a) const;
809
810 com::Utf8Str strName,
811 strHostPath;
812 bool fWritable;
813 bool fAutoMount;
814 com::Utf8Str strAutoMountPoint;
815};
816
817typedef std::list<SharedFolder> SharedFoldersList;
818
819/**
820 * NOTE: If you add any fields in here, you must update a) the constructor and b)
821 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
822 * your settings might never get saved.
823 */
824struct GuestProperty
825{
826 GuestProperty();
827
828 bool operator==(const GuestProperty &g) const;
829
830 com::Utf8Str strName,
831 strValue;
832 uint64_t timestamp;
833 com::Utf8Str strFlags;
834};
835
836typedef std::list<GuestProperty> GuestPropertiesList;
837
838typedef std::map<uint32_t, DeviceType_T> BootOrderMap;
839
840/**
841 * NOTE: If you add any fields in here, you must update a) the constructor and b)
842 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
843 * your settings might never get saved.
844 */
845struct CpuIdLeaf
846{
847 CpuIdLeaf();
848
849 bool operator==(const CpuIdLeaf &c) const;
850
851 uint32_t idx;
852 uint32_t idxSub;
853 uint32_t uEax;
854 uint32_t uEbx;
855 uint32_t uEcx;
856 uint32_t uEdx;
857};
858
859typedef std::list<CpuIdLeaf> CpuIdLeafsList;
860
861/**
862 * NOTE: If you add any fields in here, you must update a) the constructor and b)
863 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
864 * your settings might never get saved.
865 */
866struct Cpu
867{
868 Cpu();
869
870 bool operator==(const Cpu &c) const;
871
872 uint32_t ulId;
873};
874
875typedef std::list<Cpu> CpuList;
876
877/**
878 * NOTE: If you add any fields in here, you must update a) the constructor and b)
879 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
880 * your settings might never get saved.
881 */
882struct BandwidthGroup
883{
884 BandwidthGroup();
885
886 bool operator==(const BandwidthGroup &i) const;
887
888 com::Utf8Str strName;
889 uint64_t cMaxBytesPerSec;
890 BandwidthGroupType_T enmType;
891};
892
893typedef std::list<BandwidthGroup> BandwidthGroupList;
894
895/**
896 * NOTE: If you add any fields in here, you must update a) the constructor and b)
897 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
898 * your settings might never get saved.
899 */
900struct IOSettings
901{
902 IOSettings();
903
904 bool areIOCacheDefaultSettings() const;
905 bool areDefaultSettings() const;
906
907 bool operator==(const IOSettings &i) const;
908
909 bool fIOCacheEnabled;
910 uint32_t ulIOCacheSize;
911 BandwidthGroupList llBandwidthGroups;
912};
913
914/**
915 * NOTE: If you add any fields in here, you must update a) the constructor and b)
916 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
917 * your settings might never get saved.
918 */
919struct HostPCIDeviceAttachment
920{
921 HostPCIDeviceAttachment();
922
923 bool operator==(const HostPCIDeviceAttachment &a) const;
924
925 com::Utf8Str strDeviceName;
926 uint32_t uHostAddress;
927 uint32_t uGuestAddress;
928};
929
930typedef std::list<HostPCIDeviceAttachment> HostPCIDeviceAttachmentList;
931
932/**
933 * A device attached to a storage controller. This can either be a
934 * hard disk or a DVD drive or a floppy drive and also specifies
935 * which medium is "in" the drive; as a result, this is a combination
936 * of the Main IMedium and IMediumAttachment interfaces.
937 *
938 * NOTE: If you add any fields in here, you must update a) the constructor and b)
939 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
940 * your settings might never get saved.
941 */
942struct AttachedDevice
943{
944 AttachedDevice();
945
946 bool operator==(const AttachedDevice &a) const;
947
948 DeviceType_T deviceType; // only HardDisk, DVD or Floppy are allowed
949
950 // DVDs can be in pass-through mode:
951 bool fPassThrough;
952
953 // Whether guest-triggered eject of DVDs will keep the medium in the
954 // VM config or not:
955 bool fTempEject;
956
957 // Whether the medium is non-rotational:
958 bool fNonRotational;
959
960 // Whether the medium supports discarding unused blocks:
961 bool fDiscard;
962
963 // Whether the medium is hot-pluggable:
964 bool fHotPluggable;
965
966 int32_t lPort;
967 int32_t lDevice;
968
969 // if an image file is attached to the device (ISO, RAW, or hard disk image such as VDI),
970 // this is its UUID; it depends on deviceType which media registry this then needs to
971 // be looked up in. If no image file (only permitted for DVDs and floppies), then the UUID is NULL
972 com::Guid uuid;
973
974 // for DVDs and floppies, the attachment can also be a host device:
975 com::Utf8Str strHostDriveSrc; // if != NULL, value of <HostDrive>/@src
976
977 // Bandwidth group the device is attached to.
978 com::Utf8Str strBwGroup;
979};
980
981typedef std::list<AttachedDevice> AttachedDevicesList;
982
983/**
984 * NOTE: If you add any fields in here, you must update a) the constructor and b)
985 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
986 * your settings might never get saved.
987 */
988struct StorageController
989{
990 StorageController();
991
992 bool operator==(const StorageController &s) const;
993
994 com::Utf8Str strName;
995 StorageBus_T storageBus; // _SATA, _SCSI, _IDE, _SAS
996 StorageControllerType_T controllerType;
997 uint32_t ulPortCount;
998 uint32_t ulInstance;
999 bool fUseHostIOCache;
1000 bool fBootable;
1001
1002 // only for when controllerType == StorageControllerType_IntelAhci:
1003 int32_t lIDE0MasterEmulationPort,
1004 lIDE0SlaveEmulationPort,
1005 lIDE1MasterEmulationPort,
1006 lIDE1SlaveEmulationPort;
1007
1008 AttachedDevicesList llAttachedDevices;
1009};
1010
1011typedef std::list<StorageController> StorageControllersList;
1012
1013/**
1014 * We wrap the storage controllers list into an extra struct so we can
1015 * use an undefined struct without needing std::list<> in all the headers.
1016 *
1017 * NOTE: If you add any fields in here, you must update a) the constructor and b)
1018 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
1019 * your settings might never get saved.
1020 */
1021struct Storage
1022{
1023 bool operator==(const Storage &s) const;
1024
1025 StorageControllersList llStorageControllers;
1026};
1027
1028/**
1029 * Representation of Machine hardware; this is used in the MachineConfigFile.hardwareMachine
1030 * field.
1031 *
1032 * NOTE: If you add any fields in here, you must update a) the constructor and b)
1033 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
1034 * your settings might never get saved.
1035 */
1036struct Hardware
1037{
1038 Hardware();
1039
1040 bool areParavirtDefaultSettings(SettingsVersion_T sv) const;
1041 bool areBootOrderDefaultSettings() const;
1042 bool areDisplayDefaultSettings() const;
1043 bool areAllNetworkAdaptersDefaultSettings(SettingsVersion_T sv) const;
1044
1045 bool operator==(const Hardware&) const;
1046
1047 com::Utf8Str strVersion; // hardware version, optional
1048 com::Guid uuid; // hardware uuid, optional (null).
1049
1050 bool fHardwareVirt,
1051 fNestedPaging,
1052 fLargePages,
1053 fVPID,
1054 fUnrestrictedExecution,
1055 fHardwareVirtForce,
1056 fUseNativeApi,
1057 fSyntheticCpu,
1058 fTripleFaultReset,
1059 fPAE,
1060 fAPIC, // requires settings version 1.16 (VirtualBox 5.1)
1061 fX2APIC; // requires settings version 1.16 (VirtualBox 5.1)
1062 bool fIBPBOnVMExit; //< added out of cycle, after 1.16 was out.
1063 bool fIBPBOnVMEntry; //< added out of cycle, after 1.16 was out.
1064 bool fSpecCtrl; //< added out of cycle, after 1.16 was out.
1065 bool fSpecCtrlByHost; //< added out of cycle, after 1.16 was out.
1066 bool fL1DFlushOnSched ; //< added out of cycle, after 1.16 was out.
1067 bool fL1DFlushOnVMEntry ; //< added out of cycle, after 1.16 was out.
1068 bool fMDSClearOnSched; //< added out of cycle, after 1.16 was out.
1069 bool fMDSClearOnVMEntry; //< added out of cycle, after 1.16 was out.
1070 bool fNestedHWVirt; //< requires settings version 1.17 (VirtualBox 6.0)
1071 typedef enum LongModeType { LongMode_Enabled, LongMode_Disabled, LongMode_Legacy } LongModeType;
1072 LongModeType enmLongMode;
1073 uint32_t cCPUs;
1074 bool fCpuHotPlug; // requires settings version 1.10 (VirtualBox 3.2)
1075 CpuList llCpus; // requires settings version 1.10 (VirtualBox 3.2)
1076 bool fHPETEnabled; // requires settings version 1.10 (VirtualBox 3.2)
1077 uint32_t ulCpuExecutionCap; // requires settings version 1.11 (VirtualBox 3.3)
1078 uint32_t uCpuIdPortabilityLevel; // requires settings version 1.15 (VirtualBox 5.0)
1079 com::Utf8Str strCpuProfile; // requires settings version 1.16 (VirtualBox 5.1)
1080
1081 CpuIdLeafsList llCpuIdLeafs;
1082
1083 uint32_t ulMemorySizeMB;
1084
1085 BootOrderMap mapBootOrder; // item 0 has highest priority
1086
1087 GraphicsControllerType_T graphicsControllerType;
1088 uint32_t ulVRAMSizeMB;
1089 uint32_t cMonitors;
1090 bool fAccelerate3D,
1091 fAccelerate2DVideo; // requires settings version 1.8 (VirtualBox 3.1)
1092
1093 FirmwareType_T firmwareType; // requires settings version 1.9 (VirtualBox 3.1)
1094
1095 PointingHIDType_T pointingHIDType; // requires settings version 1.10 (VirtualBox 3.2)
1096 KeyboardHIDType_T keyboardHIDType; // requires settings version 1.10 (VirtualBox 3.2)
1097
1098 ChipsetType_T chipsetType; // requires settings version 1.11 (VirtualBox 4.0)
1099 ParavirtProvider_T paravirtProvider; // requires settings version 1.15 (VirtualBox 4.4)
1100 com::Utf8Str strParavirtDebug; // requires settings version 1.16 (VirtualBox 5.1)
1101
1102 bool fEmulatedUSBCardReader; // 1.12 (VirtualBox 4.1)
1103
1104 VRDESettings vrdeSettings;
1105
1106 BIOSSettings biosSettings;
1107 RecordingSettings recordingSettings;
1108 USB usbSettings;
1109 NetworkAdaptersList llNetworkAdapters;
1110 SerialPortsList llSerialPorts;
1111 ParallelPortsList llParallelPorts;
1112 AudioAdapter audioAdapter;
1113 Storage storage;
1114
1115 // technically these two have no business in the hardware section, but for some
1116 // clever reason <Hardware> is where they are in the XML....
1117 SharedFoldersList llSharedFolders;
1118 ClipboardMode_T clipboardMode;
1119 DnDMode_T dndMode;
1120
1121 uint32_t ulMemoryBalloonSize;
1122 bool fPageFusionEnabled;
1123
1124 GuestPropertiesList llGuestProperties;
1125
1126 IOSettings ioSettings; // requires settings version 1.10 (VirtualBox 3.2)
1127 HostPCIDeviceAttachmentList pciAttachments; // requires settings version 1.12 (VirtualBox 4.1)
1128
1129 com::Utf8Str strDefaultFrontend; // requires settings version 1.14 (VirtualBox 4.3)
1130};
1131
1132/**
1133 * Settings that has to do with debugging.
1134 */
1135struct Debugging
1136{
1137 Debugging();
1138
1139 bool areDefaultSettings() const;
1140
1141 bool operator==(const Debugging &rOther) const;
1142
1143 bool fTracingEnabled;
1144 bool fAllowTracingToAccessVM;
1145 com::Utf8Str strTracingConfig;
1146};
1147
1148/**
1149 * Settings that has to do with autostart.
1150 */
1151struct Autostart
1152{
1153 Autostart();
1154
1155 bool areDefaultSettings() const;
1156
1157 bool operator==(const Autostart &rOther) const;
1158
1159 bool fAutostartEnabled;
1160 uint32_t uAutostartDelay;
1161 AutostopType_T enmAutostopType;
1162};
1163
1164struct Snapshot;
1165typedef std::list<Snapshot> SnapshotsList;
1166
1167/**
1168 * NOTE: If you add any fields in here, you must update a) the constructor and b)
1169 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
1170 * your settings might never get saved.
1171 */
1172struct Snapshot
1173{
1174 Snapshot();
1175
1176 bool operator==(const Snapshot &s) const;
1177
1178 com::Guid uuid;
1179 com::Utf8Str strName,
1180 strDescription; // optional
1181 RTTIMESPEC timestamp;
1182
1183 com::Utf8Str strStateFile; // for online snapshots only
1184
1185 Hardware hardware;
1186
1187 Debugging debugging;
1188 Autostart autostart;
1189
1190 SnapshotsList llChildSnapshots;
1191
1192 static const struct Snapshot Empty;
1193};
1194
1195/**
1196 * NOTE: If you add any fields in here, you must update a) the constructor and b)
1197 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
1198 * your settings might never get saved.
1199 */
1200struct MachineUserData
1201{
1202 MachineUserData();
1203
1204 bool operator==(const MachineUserData &c) const;
1205
1206 com::Utf8Str strName;
1207 bool fDirectoryIncludesUUID;
1208 bool fNameSync;
1209 com::Utf8Str strDescription;
1210 StringsList llGroups;
1211 com::Utf8Str strOsType;
1212 com::Utf8Str strSnapshotFolder;
1213 bool fTeleporterEnabled;
1214 uint32_t uTeleporterPort;
1215 com::Utf8Str strTeleporterAddress;
1216 com::Utf8Str strTeleporterPassword;
1217 bool fRTCUseUTC;
1218 IconBlob ovIcon;
1219 VMProcPriority_T enmVMPriority;
1220};
1221
1222
1223/**
1224 * MachineConfigFile represents an XML machine configuration. All the machine settings
1225 * that go out to the XML (or are read from it) are in here.
1226 *
1227 * NOTE: If you add any fields in here, you must update a) the constructor and b)
1228 * the operator== which is used by Machine::saveSettings(), or otherwise your settings
1229 * might never get saved.
1230 */
1231class MachineConfigFile : public ConfigFileBase
1232{
1233public:
1234 com::Guid uuid;
1235
1236 MachineUserData machineUserData;
1237
1238 com::Utf8Str strStateFile;
1239 bool fCurrentStateModified; // optional, default is true
1240 RTTIMESPEC timeLastStateChange; // optional, defaults to now
1241 bool fAborted; // optional, default is false
1242
1243 com::Guid uuidCurrentSnapshot;
1244
1245 Hardware hardwareMachine;
1246 MediaRegistry mediaRegistry;
1247 Debugging debugging;
1248 Autostart autostart;
1249
1250 StringsMap mapExtraDataItems;
1251
1252 SnapshotsList llFirstSnapshot; // first snapshot or empty list if there's none
1253
1254 MachineConfigFile(const com::Utf8Str *pstrFilename);
1255
1256 bool operator==(const MachineConfigFile &m) const;
1257
1258 bool canHaveOwnMediaRegistry() const;
1259
1260 void importMachineXML(const xml::ElementNode &elmMachine);
1261
1262 void write(const com::Utf8Str &strFilename);
1263
1264 enum
1265 {
1266 BuildMachineXML_IncludeSnapshots = 0x01,
1267 BuildMachineXML_WriteVBoxVersionAttribute = 0x02,
1268 BuildMachineXML_SkipRemovableMedia = 0x04,
1269 BuildMachineXML_MediaRegistry = 0x08,
1270 BuildMachineXML_SuppressSavedState = 0x10
1271 };
1272 void buildMachineXML(xml::ElementNode &elmMachine,
1273 uint32_t fl,
1274 std::list<xml::ElementNode*> *pllElementsWithUuidAttributes);
1275
1276 static bool isAudioDriverAllowedOnThisHost(AudioDriverType_T drv);
1277 static AudioDriverType_T getHostDefaultAudioDriver();
1278
1279private:
1280 void readNetworkAdapters(const xml::ElementNode &elmHardware, NetworkAdaptersList &ll);
1281 void readAttachedNetworkMode(const xml::ElementNode &pelmMode, bool fEnabled, NetworkAdapter &nic);
1282 void readCpuIdTree(const xml::ElementNode &elmCpuid, CpuIdLeafsList &ll);
1283 void readCpuTree(const xml::ElementNode &elmCpu, CpuList &ll);
1284 void readSerialPorts(const xml::ElementNode &elmUART, SerialPortsList &ll);
1285 void readParallelPorts(const xml::ElementNode &elmLPT, ParallelPortsList &ll);
1286 void readAudioAdapter(const xml::ElementNode &elmAudioAdapter, AudioAdapter &aa);
1287 void readGuestProperties(const xml::ElementNode &elmGuestProperties, Hardware &hw);
1288 void readStorageControllerAttributes(const xml::ElementNode &elmStorageController, StorageController &sctl);
1289 void readHardware(const xml::ElementNode &elmHardware, Hardware &hw);
1290 void readHardDiskAttachments_pre1_7(const xml::ElementNode &elmHardDiskAttachments, Storage &strg);
1291 void readStorageControllers(const xml::ElementNode &elmStorageControllers, Storage &strg);
1292 void readDVDAndFloppies_pre1_9(const xml::ElementNode &elmHardware, Storage &strg);
1293 void readTeleporter(const xml::ElementNode *pElmTeleporter, MachineUserData *pUserData);
1294 void readDebugging(const xml::ElementNode *pElmDbg, Debugging *pDbg);
1295 void readAutostart(const xml::ElementNode *pElmAutostart, Autostart *pAutostart);
1296 void readGroups(const xml::ElementNode *elmGroups, StringsList *pllGroups);
1297 bool readSnapshot(const com::Guid &curSnapshotUuid, uint32_t depth, const xml::ElementNode &elmSnapshot, Snapshot &snap);
1298 void convertOldOSType_pre1_5(com::Utf8Str &str);
1299 void readMachine(const xml::ElementNode &elmMachine);
1300
1301 void buildHardwareXML(xml::ElementNode &elmParent, const Hardware &hw, uint32_t fl, std::list<xml::ElementNode*> *pllElementsWithUuidAttributes);
1302 void buildNetworkXML(NetworkAttachmentType_T mode, bool fEnabled, xml::ElementNode &elmParent, const NetworkAdapter &nic);
1303 void buildStorageControllersXML(xml::ElementNode &elmParent,
1304 const Storage &st,
1305 bool fSkipRemovableMedia,
1306 std::list<xml::ElementNode*> *pllElementsWithUuidAttributes);
1307 void buildDebuggingXML(xml::ElementNode *pElmParent, const Debugging *pDbg);
1308 void buildAutostartXML(xml::ElementNode *pElmParent, const Autostart *pAutostart);
1309 void buildGroupsXML(xml::ElementNode *pElmParent, const StringsList *pllGroups);
1310 void buildSnapshotXML(uint32_t depth, xml::ElementNode &elmParent, const Snapshot &snap);
1311
1312 void bumpSettingsVersionIfNeeded();
1313};
1314
1315} // namespace settings
1316
1317
1318#endif /* !VBOX_INCLUDED_settings_h */
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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