VirtualBox

Changeset 22213 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Aug 12, 2009 5:00:56 PM (15 years ago)
Author:
vboxsync
Message:

Main: make XML settings parser support settings format 1.6 for reading (written by VirtualBox 2.1.4)

Location:
trunk/src/VBox/Main
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/Makefile.kmk

    r22187 r22213  
    281281        AutoLock.cpp \
    282282        Matching.cpp \
     283        xml/Settings.cpp \
    283284        VirtualBoxBase.cpp \
    284285        VirtualBoxErrorInfoImpl.cpp \
     
    314315        Version.cpp \
    315316        HostPower.cpp \
    316         xml/Settings.cpp \
    317317        $(if $(VBOX_WITH_VRDP),VRDPServerImpl.cpp,) \
    318318        $(if $(VBOX_WITH_XPCOM),xpcom/server.cpp,) \
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r22211 r22213  
    379379      <!-- 2008-09-04: 2.0.0 released
    380380           2008-11-20: settings version 1.5 introduced
    381            2008-12-17: 2.1.0 released -->
     381           2008-12-17: 2.1.0 released
     382      -->
    382383    </const>
    383384    <const name="v1_6"     value="8">
    384       <desc>Intermediate settings version "1.6", understood by VirtualBox 2.2 and above.</desc>
     385      <desc>Settings version "1.6", written by VirtualBox 2.1.4 (at least).</desc>
    385386      <!-- 2008-12-17: 2.1.0 released
    386            2008-12-19: settings version 1.6 introduced (is in 2.2 branch)
    387            2009-04-08: 2.2.0 released -->
     387           2008-12-19: settings version 1.6 introduced (is in 2.1 branch)
     388           2009-04-08: 2.2.0 released
     389      -->
    388390    </const>
    389391    <const name="v1_7"     value="9">
  • trunk/src/VBox/Main/xml/Settings.cpp

    r22198 r22213  
    128128            const char *pcsz = m->strSettingsVersionFull.c_str();
    129129            if (    (pcsz[0] == '1')
    130                 && (pcsz[1] == '.')
    131                 && (pcsz[3] == '-')
     130                 && (pcsz[1] == '.')
     131                 && (pcsz[3] == '-')
    132132            )
    133133            {
    134                 if (pcsz[2] == '7')
     134                if (pcsz[2] == '6')
     135                    m->sv = SettingsVersion_v1_6;
     136                else if (pcsz[2] == '7')
    135137                    m->sv = SettingsVersion_v1_7;
    136138                else if (pcsz[2] == '8')
     
    371373    m->pelmRoot->setAttribute("xmlns", VBOX_XML_NAMESPACE);
    372374
    373     const char *pcszVersion = "1.7";
     375    // we always write at least version 1.7; we write 1.8
     376    // if that was requested thru setRequiredSettingsVersion().
     377    // we make no attempt at writing earlier versions.
     378    // Writing 1.6 would be messy for machine files because
     379    // of the hard disk attachment changes which are not
     380    // necessarily backwards compatible and we don't want to
     381    // introduce complex logic to see whether they are.
     382    const char *pcszVersion = NULL;
    374383    switch (m->sv)
    375384    {
    376385        case SettingsVersion_v1_8:
    377386            pcszVersion = "1.8";
     387        break;
     388
     389        default:
     390            pcszVersion = "1.7";
     391            m->sv = SettingsVersion_v1_7;
    378392        break;
    379393    }
     
    10891103
    10901104/**
     1105 * Helper function to read attributes that are common to <SATAController> (pre-1.7)
     1106 * and <StorageController>.
     1107 * @param elmStorageController
     1108 * @param strg
     1109 */
     1110void MachineConfigFile::readStorageControllerAttributes(const xml::ElementNode &elmStorageController,
     1111                                                        StorageController &sctl)
     1112{
     1113    elmStorageController.getAttributeValue("PortCount", sctl.ulPortCount);
     1114    elmStorageController.getAttributeValue("IDE0MasterEmulationPort", sctl.lIDE0MasterEmulationPort);
     1115    elmStorageController.getAttributeValue("IDE0SlaveEmulationPort", sctl.lIDE0SlaveEmulationPort);
     1116    elmStorageController.getAttributeValue("IDE1MasterEmulationPort", sctl.lIDE1MasterEmulationPort);
     1117    elmStorageController.getAttributeValue("IDE1SlaveEmulationPort", sctl.lIDE1SlaveEmulationPort);
     1118}
     1119
     1120/**
    10911121 * Reads in a <Hardware> block and stores it in the given structure. Used
    10921122 * both directly from readMachine and from readSnapshot, since snapshots
    10931123 * have their own hardware sections.
     1124 *
     1125 * For legacy pre-1.7 settings we also need a storage structure because
     1126 * the IDE and SATA controllers used to be defined under <Hardware>.
     1127 *
    10941128 * @param elmHardware
    10951129 * @param hw
    10961130 */
    10971131void MachineConfigFile::readHardware(const xml::ElementNode &elmHardware,
    1098                                      Hardware &hw)
     1132                                     Hardware &hw,
     1133                                     Storage &strg)
    10991134{
    11001135    elmHardware.getAttributeValue("version", hw.strVersion);
     
    12151250            if ((pelmBIOSChild = pelmHwChild->findChildElement("TimeOffset")))
    12161251                pelmBIOSChild->getAttributeValue("value", hw.biosSettings.llTimeOffset);
     1252
     1253            // legacy BIOS/IDEController (pre 1.7)
     1254            if (    (m->sv < SettingsVersion_v1_7)
     1255                 && ((pelmBIOSChild = pelmHwChild->findChildElement("IDEController")))
     1256               )
     1257            {
     1258                StorageController sctl;
     1259                sctl.strName = "IDE";
     1260                sctl.storageBus = StorageBus_IDE;
     1261
     1262                Utf8Str strType;
     1263                if (pelmBIOSChild->getAttributeValue("type", strType))
     1264                {
     1265                    if (strType == "PIIX3")
     1266                        sctl.controllerType = StorageControllerType_PIIX3;
     1267                    else if (strType == "PIIX4")
     1268                        sctl.controllerType = StorageControllerType_PIIX4;
     1269                    else if (strType == "ICH6")
     1270                        sctl.controllerType = StorageControllerType_ICH6;
     1271                    else
     1272                        throw ConfigFileError(this, N_("Invalid value %s for IDEController/type attribute"), strType.c_str());
     1273                }
     1274                sctl.ulPortCount = 2;
     1275                strg.llStorageControllers.push_back(sctl);
     1276            }
    12171277        }
    12181278        else if (pelmHwChild->nameEquals("DVDDrive"))
     
    12471307            readUSBDeviceFilters(*pelmHwChild,
    12481308                                 hw.usbController.llDeviceFilters);
     1309        }
     1310        else if (    (m->sv < SettingsVersion_v1_7)
     1311                  && (pelmHwChild->nameEquals("SATAController"))
     1312                )
     1313        {
     1314            bool f;
     1315            if (    (pelmHwChild->getAttributeValue("enabled", f))
     1316                 && (f)
     1317               )
     1318            {
     1319                StorageController sctl;
     1320                sctl.strName = "SATA";
     1321                sctl.storageBus = StorageBus_SATA;
     1322                sctl.controllerType = StorageControllerType_IntelAhci;
     1323
     1324                readStorageControllerAttributes(*pelmHwChild, sctl);
     1325
     1326                strg.llStorageControllers.push_back(sctl);
     1327            }
    12491328        }
    12501329        else if (pelmHwChild->nameEquals("Network"))
     
    13381417
    13391418/**
     1419 * This gets called instead of readStorageControllers() for legacy pre-1.7 settings
     1420 * files which have a <HardDiskAttachments> node and storage controller settings
     1421 * hidden in the <Hardware> settings. We set the StorageControllers fields just the
     1422 * same, just from different sources.
     1423 * @param elmHardware <Hardware> XML node.
     1424 * @param elmHardDiskAttachments  <HardDiskAttachments> XML node.
     1425 * @param strg
     1426 */
     1427void MachineConfigFile::readHardDiskAttachments_pre1_7(const xml::ElementNode &elmHardDiskAttachments,
     1428                                                       Storage &strg)
     1429{
     1430    StorageController *pIDEController = NULL;
     1431    StorageController *pSATAController = NULL;
     1432
     1433    for (StorageControllersList::iterator it = strg.llStorageControllers.begin();
     1434         it != strg.llStorageControllers.end();
     1435         ++it)
     1436    {
     1437        StorageController &s = *it;
     1438        if (s.storageBus == StorageBus_IDE)
     1439            pIDEController = &s;
     1440        else if (s.storageBus == StorageBus_SATA)
     1441            pSATAController = &s;
     1442    }
     1443
     1444    xml::NodesLoop nl1(elmHardDiskAttachments, "HardDiskAttachment");
     1445    const xml::ElementNode *pelmAttachment;
     1446    while ((pelmAttachment = nl1.forAllNodes()))
     1447    {
     1448        AttachedDevice att;
     1449        Utf8Str strUUID, strBus;
     1450
     1451        if (!pelmAttachment->getAttributeValue("hardDisk", strUUID))
     1452            throw ConfigFileError(this, N_("Required HardDiskAttachment/hardDisk attribute is missing"));
     1453        parseUUID(att.uuid, strUUID);
     1454
     1455        if (!pelmAttachment->getAttributeValue("bus", strBus))
     1456            throw ConfigFileError(this, N_("Required HardDiskAttachment/bus attribute is missing"));
     1457        // pre-1.7 'channel' is now port
     1458        if (!pelmAttachment->getAttributeValue("channel", att.lPort))
     1459            throw ConfigFileError(this, N_("Required HardDiskAttachment/channel attribute is missing"));
     1460        // pre-1.7 'device' is still device
     1461        if (!pelmAttachment->getAttributeValue("device", att.lDevice))
     1462            throw ConfigFileError(this, N_("Required HardDiskAttachment/device attribute is missing"));
     1463
     1464        if (strBus == "IDE")
     1465        {
     1466            if (!pIDEController)
     1467                throw ConfigFileError(this, N_("HardDiskAttachment/bus is 'IDE' but cannot find IDE controller"));
     1468            pIDEController->llAttachedDevices.push_back(att);
     1469        }
     1470        else if (strBus == "SATA")
     1471        {
     1472            if (!pSATAController)
     1473                throw ConfigFileError(this, N_("HardDiskAttachment/bus is 'SATA' but cannot find SATA controller"));
     1474            pSATAController->llAttachedDevices.push_back(att);
     1475        }
     1476        else
     1477            throw ConfigFileError(this, N_("HardDiskAttachment/bus attribute has illegal value '%s'"), strBus.c_str());
     1478    }
     1479}
     1480
     1481/**
    13401482 * Reads in a <StorageControllers> block and stores it in the given Storage structure.
    13411483 * Used both directly from readMachine and from readSnapshot, since snapshots
    13421484 * have their own storage controllers sections.
     1485 *
     1486 * This is only called for settings version 1.7 and above; see readHardDiskAttachments_pre1_7
     1487 * for earlier versions.
    13431488 *
    13441489 * @param elmStorageControllers
     
    13921537            throw ConfigFileError(this, N_("Invalid value %s for StorageController/type attribute"), strType.c_str());
    13931538
    1394         pelmController->getAttributeValue("PortCount", sctl.ulPortCount);
    1395 
    1396         pelmController->getAttributeValue("IDE0MasterEmulationPort", sctl.lIDE0MasterEmulationPort);
    1397         pelmController->getAttributeValue("IDE0SlaveEmulationPort", sctl.lIDE0SlaveEmulationPort);
    1398         pelmController->getAttributeValue("IDE1MasterEmulationPort", sctl.lIDE1MasterEmulationPort);
    1399         pelmController->getAttributeValue("IDE1SlaveEmulationPort", sctl.lIDE1SlaveEmulationPort);
     1539        readStorageControllerAttributes(*pelmController, sctl);
    14001540
    14011541        xml::NodesLoop nlAttached(*pelmController, "AttachedDevice");
     
    14611601    elmSnapshot.getAttributeValue("stateFile", snap.strStateFile);      // online snapshots only
    14621602
     1603    // parse Hardware before the other elements because other things depend on it
     1604    const xml::ElementNode *pelmHardware;
     1605    if (!(pelmHardware = elmSnapshot.findChildElement("Hardware")))
     1606        throw ConfigFileError(this, N_("Required Snapshot/Hardware element is missing"));
     1607    readHardware(*pelmHardware, snap.hardware, snap.storage);
     1608
    14631609    xml::NodesLoop nlSnapshotChildren(elmSnapshot);
    14641610    const xml::ElementNode *pelmSnapshotChild;
     
    14671613        if (pelmSnapshotChild->nameEquals("Description"))
    14681614            snap.strDescription = pelmSnapshotChild->getValue();
    1469         else if (pelmSnapshotChild->nameEquals("Hardware"))
    1470             readHardware(*pelmSnapshotChild, snap.hardware);
    1471         else if (pelmSnapshotChild->nameEquals("StorageControllers"))
     1615        else if (    (m->sv < SettingsVersion_v1_7)
     1616                  && (pelmSnapshotChild->nameEquals("HardDiskAttachments"))
     1617                )
     1618            readHardDiskAttachments_pre1_7(*pelmSnapshotChild, snap.storage);
     1619        else if (    (m->sv >= SettingsVersion_v1_7)
     1620                  && (pelmSnapshotChild->nameEquals("StorageControllers"))
     1621                )
    14721622            readStorageControllers(*pelmSnapshotChild, snap.storage);
    14731623        else if (pelmSnapshotChild->nameEquals("Snapshots"))
     
    14871637            }
    14881638        }
     1639        else if (pelmSnapshotChild->nameEquals("Hardware"))
     1640            ; // handled above
    14891641        else
    14901642            throw ConfigFileError(this, N_("Invalid element %s under Snapshot element"), pelmSnapshotChild->getName());
     
    15221674            // constructor has called RTTimeNow(&timeLastStateChange) before
    15231675
     1676        // parse Hardware before the other elements because other things depend on it
     1677        const xml::ElementNode *pelmHardware;
     1678        if (!(pelmHardware = elmMachine.findChildElement("Hardware")))
     1679            throw ConfigFileError(this, N_("Required Machine/Hardware element is missing"));
     1680        readHardware(*pelmHardware, hardwareMachine, storageMachine);
     1681
    15241682        xml::NodesLoop nlRootChildren(elmMachine);
    15251683        const xml::ElementNode *pelmMachineChild;
     
    15291687                readExtraData(*pelmMachineChild,
    15301688                              mapExtraDataItems);
    1531             else if (pelmMachineChild->nameEquals("Hardware"))
    1532                 readHardware(*pelmMachineChild, hardwareMachine);
    1533             else if (pelmMachineChild->nameEquals("StorageControllers"))
     1689            else if (    (m->sv < SettingsVersion_v1_7)
     1690                      && (pelmMachineChild->nameEquals("HardDiskAttachments"))
     1691                    )
     1692                readHardDiskAttachments_pre1_7(*pelmMachineChild, storageMachine);
     1693            else if (    (m->sv >= SettingsVersion_v1_7)
     1694                      && (pelmMachineChild->nameEquals("StorageControllers"))
     1695                    )
    15341696                readStorageControllers(*pelmMachineChild, storageMachine);
    15351697            else if (pelmMachineChild->nameEquals("Snapshot"))
     
    15421704            else if (pelmMachineChild->nameEquals("Description"))
    15431705                strDescription = pelmMachineChild->getValue();
     1706            else if (pelmMachineChild->nameEquals("Hardware"))
     1707                ; // read above
    15441708            else
    15451709                throw ConfigFileError(this, N_("Invalid element %s under Machine element"), pelmMachineChild->getName());
Note: See TracChangeset for help on using the changeset viewer.

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