Settings.cpp revision 3a0bc95d0adf57baefd303e94b8f1b7b31a8f080
2N/A * Two classes, MainConfigFile and MachineConfigFile, represent the VirtualBox.xml and
* available from http://www.virtualbox.org. This file is free software;
* Clara, CA 95054 USA or visit http://www.sun.com if you need
#include "VBox/settings.h"
#include "SchemaDefs.h"
#include "Logging.h"
using namespace com;
using namespace settings;
#if defined (RT_OS_DARWIN)
Data()
~Data()
cleanup();
bool fFileExists;
void cleanup()
if (pDoc)
delete pDoc;
if (pParser)
delete pParser;
const char *pcszFormat, ...)
if (pNode)
: m(new Data)
m->fFileExists = false;
if (pstrFilename)
*m->pDoc);
m->fFileExists = true;
throw ConfigFileError(this, NULL, N_("Root element in VirtualBox settings files must be \"VirtualBox\"."));
LogRel(("Loading settings file \"%s\" with version \"%s\"\n", m->strFilename.c_str(), m->strSettingsVersionFull.c_str()));
while ( (c = *pcsz)
&& RT_C_IS_DIGIT(c)
++pcsz;
while ( (c = *pcsz)
&& RT_C_IS_DIGIT(c)
++pcsz;
throw ConfigFileError(this, m->pelmRoot, N_("Cannot handle settings version '%s'"), m->strSettingsVersionFull.c_str());
m = NULL;
throw ConfigFileError(this, NULL, N_("Cannot handle ISO timestamp '%s': is not UTC date"), str.c_str());
int rc;
throw ConfigFileError(this, NULL, N_("Cannot parse ISO timestamp '%s': runtime error, %Rra"), str.c_str(), rc);
throw ConfigFileError(this, NULL, N_("Cannot parse ISO timestamp '%s': invalid format"), str.c_str());
return str;
// <ExtraDataItem name="GUI/LastWindowPostion" value="97,88,981,858"/>
throw ConfigFileError(this, pelmExtraDataItem, N_("Required ExtraDataItem/@name or @value attribute is missing"));
throw ConfigFileError(this, pelmLevel4Child, N_("Invalid value '%s' in DeviceFilter/@action attribute"), strAction.c_str());
switch (m->sv)
case SettingsVersion_v1_8:
case SettingsVersion_v1_9:
case SettingsVersion_Future: // can be set if this code runs on XML files that were created by a future version of VBox;
// and append something likd "-1.3-linux.xml"
++it)
bool fHostMode)
++it)
if (fHostMode)
const char *pcsz =
m->cleanup();
return m->fFileExists;
* Reads one <MachineEntry> from the main VirtualBox.xml file.
throw ConfigFileError(this, pelmChild1, N_("Required MachineEntry/@uuid or @src attribute is missing"));
* Reads a media registry entry from the main VirtualBox.xml file.
// <HardDisk uuid="{5471ecdb-1ddb-4012-a801-6d98e226868b}" location="/mnt/innotek-unix/vdis/Windows XP.vdi" format="VDI" type="Normal">
throw ConfigFileError(this, &elmMedium, N_("Required %s/@uuid attribute is missing"), elmMedium.getName());
bool fNeedsLocation = true;
if (t == HardDisk)
fNeedsLocation = false;
bool fNeedsFilePath = true;
fNeedsFilePath = false;
fNeedsFilePath = false;
fNeedsLocation = true;
throw ConfigFileError(this, &elmMedium, N_("Required %s/VirtualDiskImage element is missing"), elmMedium.getName());
if (fNeedsFilePath)
throw ConfigFileError(this, &elmMedium, N_("Required %s/@filePath attribute is missing"), elmMedium.getName());
throw ConfigFileError(this, &elmMedium, N_("Required %s/@format attribute is missing"), elmMedium.getName());
throw ConfigFileError(this, &elmMedium, N_("HardDisk/@type attribute must be one of Normal, Immutable or Writethrough"));
throw ConfigFileError(this, &elmMedium, N_("Required %s/@src attribute is missing"), elmMedium.getName());
fNeedsLocation = false;
if (fNeedsLocation)
throw ConfigFileError(this, &elmMedium, N_("Required %s/@location attribute is missing"), elmMedium.getName());
if ( t == HardDisk
readMedium(t,
throw ConfigFileError(this, pelmHDChild, N_("Required HardDisk/Property/@name or @value attribute is missing"));
t = HardDisk;
t = DVDImage;
t = FloppyImage;
if ( t == HardDisk
readMedium(t,
else if ( t == DVDImage
readMedium(t,
else if ( t == FloppyImage
readMedium(t,
throw ConfigFileError(this, pelmServer, N_("Required DHCPServer/@networkName, @IPAddress, @networkMask, @lowerIP, @upperIP or @enabled attribute is missing"));
if (pstrFilename)
pelmGlobalChild->getAttributeValue("defaultMachineFolder", systemProperties.strDefaultMachineFolder);
if (!pelmGlobalChild->getAttributeValue("defaultHardDiskFolder", systemProperties.strDefaultHardDiskFolder))
pelmGlobalChild->getAttributeValue("defaultHardDiskFormat", systemProperties.strDefaultHardDiskFormat);
pelmGlobalChild->getAttributeValue("remoteDisplayAuthLibrary", systemProperties.strRemoteDisplayAuthLibrary);
pelmGlobalChild->getAttributeValue("webServiceAuthLibrary", systemProperties.strWebServiceAuthLibrary);
#ifdef RT_OS_WINDOWS
const Medium &m,
if (m.fAutoReset)
++it)
if (level == 0)
const char *pcszType =
++it)
* Called from the IVirtualBox interface to write out VirtualBox.xml. This
++it)
// <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"/>
++it)
++it)
++it)
++it)
pelmSysProps->setAttribute("remoteDisplayAuthLibrary", systemProperties.strRemoteDisplayAuthLibrary);
m->fFileExists = true;
#define HWVIRTEXCLUSIVEDEFAULT false
#define HWVIRTEXCLUSIVEDEFAULT true
fHardwareVirt(true),
fNestedPaging(false),
fVPID(false),
fSyntheticCpu(false),
fPAE(false),
fAccelerate3D(false),
fAccelerate2DVideo(false),
* - 32 bits host -> true for Windows & Darwin (masked off if the host cpu doesn't support it anyway)
fPAE = true;
throw ConfigFileError(this, pelmAdapter, N_("Invalid value '%s' in Adapter/@type attribute"), strTemp.c_str());
throw ConfigFileError(this, pelmAdapterChild, N_("Required InternalNetwork/@name element is missing"));
throw ConfigFileError(this, pelmAdapterChild, N_("Required HostOnlyInterface/@name element is missing"));
++it)
throw ConfigFileError(this, pelmPort, N_("Invalid value %RU32 in UART/Port/@slot attribute: value is not unique"), port.ulSlot);
throw ConfigFileError(this, pelmPort, N_("Invalid value '%s' in UART/Port/@hostMode attribute"), strPortMode.c_str());
++it)
throw ConfigFileError(this, pelmPort, N_("Invalid value %RU32 in LPT/Port/@slot attribute: value is not unique"), port.ulSlot);
void MachineConfigFile::readStorageControllerAttributes(const xml::ElementNode &elmStorageController,
throw ConfigFileError(this,
throw ConfigFileError(this,
--ulPos;
throw ConfigFileError(this, pelmOrder, N_("Invalid value '%RU32' in Boot/Order/@position: value is not unique"), ulPos);
throw ConfigFileError(this, pelmOrder, N_("Invalid value '%s' in Boot/Order/@device attribute"), strDevice.c_str());
throw ConfigFileError(this, pelmHwChild, N_("Invalid value '%s' in RemoteDisplay/@authType attribute"), strAuthType.c_str());
throw ConfigFileError(this, pelmBIOSChild, N_("Invalid value '%s' in BootMenu/@mode attribute"), strBootMenuMode.c_str());
// legacy BIOS/IDEController (pre 1.7)
throw ConfigFileError(this, pelmBIOSChild, N_("Invalid value '%s' for IDEController/@type attribute"), strType.c_str());
throw ConfigFileError(this, pelmHwChild, N_("Invalid value '%s' in AudioAdapter/@controller attribute"), strTemp.c_str());
throw ConfigFileError(this, pelmHwChild, N_("Invalid value '%s' in AudioAdapter/@driver attribute"), strTemp.c_str());
throw ConfigFileError(this, pelmHwChild, N_("Invalid value '%s' in Clipbord/@mode attribute"), strTemp.c_str());
throw ConfigFileError(this, &elmHardware, N_("Required Memory/@RAMSize element/attribute is missing"));
void MachineConfigFile::readHardDiskAttachments_pre1_7(const xml::ElementNode &elmHardDiskAttachments,
++it)
pIDEController = &s;
pSATAController = &s;
throw ConfigFileError(this, pelmAttachment, N_("Required HardDiskAttachment/@hardDisk attribute is missing"));
throw ConfigFileError(this, pelmAttachment, N_("Required HardDiskAttachment/@bus attribute is missing"));
throw ConfigFileError(this, pelmAttachment, N_("Required HardDiskAttachment/@channel attribute is missing"));
throw ConfigFileError(this, pelmAttachment, N_("Required HardDiskAttachment/@device attribute is missing"));
if (!pIDEController)
throw ConfigFileError(this, pelmAttachment, N_("HardDiskAttachment/@bus is 'IDE' but cannot find IDE controller"));
if (!pSATAController)
throw ConfigFileError(this, pelmAttachment, N_("HardDiskAttachment/@bus is 'SATA' but cannot find SATA controller"));
throw ConfigFileError(this, pelmAttachment, N_("HardDiskAttachment/@bus attribute has illegal value '%s'"), strBus.c_str());
throw ConfigFileError(this, pelmController, N_("Required StorageController/@name attribute is missing"));
throw ConfigFileError(this, pelmController, N_("Required StorageController/@type attribute is missing"));
throw ConfigFileError(this, pelmController, N_("Invalid value '%s' for StorageController/@type attribute"), strType.c_str());
throw ConfigFileError(this, pelmHostDrive, N_("Required AttachedDevice/HostDrive/@src attribute is missing"));
throw ConfigFileError(this, pelmImage, N_("Required AttachedDevice/Image/@uuid attribute is missing"));
bool fFound = false;
++it)
fFound = true;
if (!fFound)
throw ConfigFileError(this, pelmHwChild, N_("Internal error: found DVD drive but IDE controller does not exist"));
// shouldn't happen because pre-1.9 settings files always had at least one IDE controller in the settings
bool fEnabled;
&& (fEnabled)
// earlier 3.1 trunk builds had a bug and added Description as an attribute, read it silently and write it back as an element
fNameSync = true;
fCurrentStateModified = true;
fTeleporterEnabled = false;
uTeleporterPort = 0;
fTeleporterEnabled = false;
uTeleporterPort = 0;
throw ConfigFileError(this, &elmMachine, N_("Required Machine/@uuid or @name attributes is missing"));
fNameSync(true),
fTeleporterEnabled(false),
uTeleporterPort(0),
fCurrentStateModified(true),
fAborted(false)
if (pstrFilename)
++it)
const char *pcszFirmware;
++it)
const char *pcszDevice;
switch (type)
const char *pcszAuthType;
const char *pcszBootMenu;
++it)
++it2)
if (cDVDs > 0)
throw ConfigFileError(this, NULL, N_("Internal error: cannot save more than one DVD drive with old settings format"));
++cDVDs;
throw ConfigFileError(this, NULL, N_("Internal error: floppy controller cannot have more than one device attachment"));
if (cFloppiesHere)
if (cFloppies == 0)
throw ConfigFileError(this, NULL, N_("Internal error: cannot save more than one floppy drive with old settings format"));
++it)
const char *pcszType;
++it)
const char *pcszHostMode;
case PortMode_HostPipe:
case PortMode_HostDevice:
case PortMode_RawFile:
++it)
pelmAudio->setAttribute("controller", (hw.audioAdapter.controllerType == AudioControllerType_SB16) ? "SB16" : "AC97");
const char *pcszDriver;
++it)
const char *pcszClip;
++it)
++it)
const char *pcszType;
++it2)
case DeviceType_HardDisk:
case DeviceType_DVD:
case DeviceType_Floppy:
* Writes a single snapshot into the DOM tree. Initially this gets called from MachineConfigFile::write()
* for the root snapshot of a machine, if present; elmParent then points to the <Snapshots> node under the
++it)
++it)
++it2)
++cDVDs;
++cFloppies;
if (!fNameSync)
if (!fCurrentStateModified)
if (fAborted)
&& ( fTeleporterEnabled
m->fFileExists = true;