VirtualBox

Changeset 35126 in vbox


Ignore:
Timestamp:
Dec 15, 2010 12:14:15 PM (14 years ago)
Author:
vboxsync
Message:

Main/Medium: Only allow medium type changes which are actually supported. Previously the code assumed the caller knows what he's doing.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/MediumImpl.cpp

    r35082 r35126  
    16391639    }
    16401640
     1641    DeviceType_T devType = getDeviceType();
     1642    // DVD media can only be readonly.
     1643    if (devType == DeviceType_DVD && aType != MediumType_Readonly)
     1644        return setError(VBOX_E_INVALID_OBJECT_STATE,
     1645                        tr("Cannot change the type of DVD medium '%s'"),
     1646                        m->strLocationFull.c_str());
     1647    // Floppy media can only be writethrough or readonly.
     1648    if (   devType == DeviceType_Floppy
     1649        && aType != MediumType_Writethrough
     1650        && aType != MediumType_Readonly)
     1651        return setError(VBOX_E_INVALID_OBJECT_STATE,
     1652                        tr("Cannot change the type of floppy medium '%s'"),
     1653                        m->strLocationFull.c_str());
     1654
    16411655    /* cannot change the type of a differencing medium */
    16421656    if (m->pParent)
     
    16971711                                    m->strLocationFull.c_str());
    16981712            }
     1713            else if (aType == MediumType_Readonly && devType == DeviceType_HardDisk)
     1714            {
     1715                // Readonly hard disks are not allowed, this medium type is reserved for
     1716                // DVDs and floppy images at the moment. Later we might allow readonly hard
     1717                // disks, but that's extremely unusual and many guest OSes will have trouble.
     1718                return setError(VBOX_E_INVALID_OBJECT_STATE,
     1719                                tr("Cannot change type for medium '%s' to 'Readonly' since it is a hard disk"),
     1720                                m->strLocationFull.c_str());
     1721            }
    16991722            break;
    17001723        }
     
    17031726    }
    17041727
    1705     if (    aType == MediumType_MultiAttach
    1706          || aType == MediumType_Readonly
    1707        )
    1708     {
    1709         // These two types are new with VirtualBox 4.0 and therefore require settings
     1728    if (aType == MediumType_MultiAttach)
     1729    {
     1730        // This type is new with VirtualBox 4.0 and therefore requires settings
    17101731        // version 1.11 in the settings backend. Unfortunately it is not enough to do
    17111732        // the usual routine in MachineConfigFile::bumpSettingsVersionIfNeeded() for
     
    17191740        if (isInRegistry(uuidGlobalRegistry))
    17201741            return setError(VBOX_E_INVALID_OBJECT_STATE,
    1721                             tr("Cannot change type for medium '%s': the media types 'MultiAttach' and 'Readonly' can only be used "
     1742                            tr("Cannot change type for medium '%s': the media type 'MultiAttach' can only be used "
    17221743                               "on media registered with a machine that was created with VirtualBox 4.0 or later"),
    17231744                            m->strLocationFull.c_str());
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