VirtualBox

Changeset 33524 in vbox for trunk/src/VBox/Main/xml


Ignore:
Timestamp:
Oct 27, 2010 4:44:37 PM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
67121
Message:

Storage: Implement offical support for other disk types like DVD and floppy images. DMG images can be used now without hacks

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/xml/Settings.cpp

    r33504 r33524  
    671671            else if (strType == "SHAREABLE")
    672672                med.hdType = MediumType_Shareable;
     673            else if (strType == "READONLY")
     674                med.hdType = MediumType_Readonly;
    673675            else
    674676                throw ConfigFileError(this, &elmMedium, N_("HardDisk/@type attribute must be one of Normal, Immutable or Writethrough"));
    675677        }
    676678    }
    677     else if (m->sv < SettingsVersion_v1_4)
    678     {
    679         // DVD and floppy images before 1.4 had "src" attribute instead of "location"
    680         if (!(elmMedium.getAttributeValue("src", med.strLocation)))
    681             throw ConfigFileError(this, &elmMedium, N_("Required %s/@src attribute is missing"), elmMedium.getName());
    682 
    683         fNeedsLocation = false;
     679    else
     680    {
     681        if (m->sv < SettingsVersion_v1_4)
     682        {
     683            // DVD and floppy images before 1.4 had "src" attribute instead of "location"
     684            if (!(elmMedium.getAttributeValue("src", med.strLocation)))
     685                throw ConfigFileError(this, &elmMedium, N_("Required %s/@src attribute is missing"), elmMedium.getName());
     686
     687            fNeedsLocation = false;
     688        }
     689
     690        if (!(elmMedium.getAttributeValue("format", med.strFormat)))
     691        {
     692            // DVD and floppy images before 1.11 had no format attribute. assign the default.
     693            med.strFormat = "RAW";
     694        }
    684695    }
    685696
     
    979990 * @param level
    980991 */
    981 void ConfigFileBase::buildHardDisk(xml::ElementNode &elmMedium,
    982                                    const Medium &mdm,
    983                                    uint32_t level)          // 0 for "root" call, incremented with each recursion
    984 {
    985     xml::ElementNode *pelmHardDisk = elmMedium.createChild("HardDisk");
    986     pelmHardDisk->setAttribute("uuid", mdm.uuid.toStringCurly());
    987     pelmHardDisk->setAttribute("location", mdm.strLocation);
    988     pelmHardDisk->setAttribute("format", mdm.strFormat);
     992void ConfigFileBase::buildMedium(xml::ElementNode &elmMedium,
     993                                 DeviceType_T devType,
     994                                 const Medium &mdm,
     995                                 uint32_t level)          // 0 for "root" call, incremented with each recursion
     996{
     997    xml::ElementNode *pelmMedium;
     998
     999    if (devType == DeviceType_HardDisk)
     1000        pelmMedium = elmMedium.createChild("HardDisk");
     1001    else
     1002        pelmMedium = elmMedium.createChild("Image");
     1003
     1004    pelmMedium->setAttribute("uuid", mdm.uuid.toStringCurly());
     1005    pelmMedium->setAttribute("location", mdm.strLocation);
     1006    pelmMedium->setAttribute("format", mdm.strFormat);
    9891007    if (mdm.fAutoReset)
    990         pelmHardDisk->setAttribute("autoReset", mdm.fAutoReset);
     1008        pelmMedium->setAttribute("autoReset", mdm.fAutoReset);
    9911009    if (mdm.strDescription.length())
    992         pelmHardDisk->setAttribute("Description", mdm.strDescription);
     1010        pelmMedium->setAttribute("Description", mdm.strDescription);
    9931011
    9941012    for (StringsMap::const_iterator it = mdm.properties.begin();
     
    9961014         ++it)
    9971015    {
    998         xml::ElementNode *pelmProp = pelmHardDisk->createChild("Property");
     1016        xml::ElementNode *pelmProp = pelmMedium->createChild("Property");
    9991017        pelmProp->setAttribute("name", it->first);
    10001018        pelmProp->setAttribute("value", it->second);
     
    10081026            mdm.hdType == MediumType_Immutable ? "Immutable" :
    10091027            mdm.hdType == MediumType_Writethrough ? "Writethrough" :
    1010             mdm.hdType == MediumType_Shareable ? "Shareable" : "INVALID";
    1011         pelmHardDisk->setAttribute("type", pcszType);
     1028            mdm.hdType == MediumType_Shareable ? "Shareable" :
     1029            mdm.hdType == MediumType_Readonly ? "Readonly" : "INVALID";
     1030        pelmMedium->setAttribute("type", pcszType);
    10121031    }
    10131032
     
    10171036    {
    10181037        // recurse for children
    1019         buildHardDisk(*pelmHardDisk, // parent
    1020                       *it,           // settings::Medium
    1021                       ++level);      // recursion level
     1038        buildMedium(*pelmMedium, // parent
     1039                    devType,     // device type
     1040                    *it,         // settings::Medium
     1041                    ++level);    // recursion level
    10221042    }
    10231043}
     
    10441064         ++it)
    10451065    {
    1046         buildHardDisk(*pelmHardDisks, *it, 0);
     1066        buildMedium(*pelmHardDisks, DeviceType_HardDisk, *it, 0);
    10471067    }
    10481068
     
    10521072         ++it)
    10531073    {
    1054         const Medium &mdm = *it;
    1055         xml::ElementNode *pelmMedium = pelmDVDImages->createChild("Image");
    1056         pelmMedium->setAttribute("uuid", mdm.uuid.toStringCurly());
    1057         pelmMedium->setAttribute("location", mdm.strLocation);
    1058         if (mdm.strDescription.length())
    1059             pelmMedium->setAttribute("Description", mdm.strDescription);
     1074        buildMedium(*pelmDVDImages, DeviceType_DVD, *it, 0);
    10601075    }
    10611076
     
    10651080         ++it)
    10661081    {
    1067         const Medium &mdm = *it;
    1068         xml::ElementNode *pelmMedium = pelmFloppyImages->createChild("Image");
    1069         pelmMedium->setAttribute("uuid", mdm.uuid.toStringCurly());
    1070         pelmMedium->setAttribute("location", mdm.strLocation);
    1071         if (mdm.strDescription.length())
    1072             pelmMedium->setAttribute("Description", mdm.strDescription);
     1082        buildMedium(*pelmFloppyImages, DeviceType_Floppy, *it, 0);
    10731083    }
    10741084}
Note: See TracChangeset for help on using the changeset viewer.

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