VirtualBox

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


Ignore:
Timestamp:
Aug 11, 2010 1:35:59 PM (14 years ago)
Author:
vboxsync
Message:

Main: combine IVirtualBox::openHardDisk(), openDVDImage(), openFloppyImage() into new IVirtualBox::openMedium(); add new IMedium::setImageUUIDs() method for a rare use case of the old openHardDisk(); optimize client code now that code is mostly the same

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

Legend:

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

    r31539 r31568  
    13421342
    13431343            // First open the existing disk image
    1344             rc = mVirtualBox->OpenHardDisk(Bstr(strSrcFilePath),
    1345                                            AccessMode_ReadOnly,
    1346                                            false,
    1347                                            NULL,
    1348                                            false,
    1349                                            NULL,
    1350                                            pSourceHD.asOutParam());
     1344            rc = mVirtualBox->OpenMedium(Bstr(strSrcFilePath),
     1345                                         DeviceType_HardDisk,
     1346                                         AccessMode_ReadOnly,
     1347                                         pSourceHD.asOutParam());
    13511348            if (FAILED(rc)) DebugBreakThrow(rc);
    13521349            fSourceHdNeedsClosing = true;
  • trunk/src/VBox/Main/MediumImpl.cpp

    r31562 r31568  
    9797          hddOpenMode(OpenReadWrite),
    9898          autoReset(false),
    99           setImageId(false),
    100           setParentId(false),
    10199          hostDrive(false),
    102100          implicit(false),
     
    143141
    144142    /** the following members are invalid after changing UUID on open */
    145     bool setImageId : 1;
    146     bool setParentId : 1;
    147     const Guid imageId;
    148     const Guid parentId;
     143    const Guid uuidImage;
     144    const Guid uuidParentImage;
    149145
    150146    bool hostDrive : 1;
     
    824820 * @param enOpenMode    Whether to open the medium read/write or read-only.
    825821 * @param aDeviceType   Device type of medium.
    826  * @param aSetImageId   Whether to set the medium UUID or not.
    827  * @param aImageId      New medium UUID if @aSetId is true. Empty string means
    828  *                      create a new UUID, and a zero UUID is invalid.
    829  * @param aSetParentId  Whether to set the parent UUID or not.
    830  * @param aParentId     New parent UUID if @aSetParentId is true. Empty string
    831  *                      means create a new UUID, and a zero UUID is valid.
    832822 */
    833823HRESULT Medium::init(VirtualBox *aVirtualBox,
    834824                     const Utf8Str &aLocation,
    835825                     HDDOpenMode enOpenMode,
    836                      DeviceType_T aDeviceType,
    837                      BOOL aSetImageId,
    838                      const Guid &aImageId,
    839                      BOOL aSetParentId,
    840                      const Guid &aParentId)
     826                     DeviceType_T aDeviceType)
    841827{
    842828    AssertReturn(aVirtualBox, E_INVALIDARG);
     
    870856    if (FAILED(rc)) return rc;
    871857
    872     /* save the new uuid values, will be used by queryInfo() */
    873     m->setImageId = !!aSetImageId;
    874     unconst(m->imageId) = aImageId;
    875     m->setParentId = !!aSetParentId;
    876     unconst(m->parentId) = aParentId;
    877 
    878858    /* get all the information about the medium from the storage unit */
    879     rc = queryInfo();
     859    rc = queryInfo(false /* fSetImageId */, false /* fSetParentId */);
    880860
    881861    if (SUCCEEDED(rc))
     
    16551635}
    16561636
     1637STDMETHODIMP Medium::SetIDs(BOOL aSetImageId,
     1638                            IN_BSTR aImageId,
     1639                            BOOL aSetParentId,
     1640                            IN_BSTR aParentId)
     1641{
     1642    AutoCaller autoCaller(this);
     1643    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     1644
     1645    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     1646
     1647    Guid imageId, parentId;
     1648    if (aSetImageId)
     1649    {
     1650        imageId = Guid(aImageId);
     1651        if (imageId.isEmpty())
     1652            return setError(E_INVALIDARG, tr("Argument %s is empty"), "aImageId");
     1653    }
     1654    if (aSetParentId)
     1655        parentId = Guid(aParentId);
     1656
     1657    unconst(m->uuidImage) = imageId;
     1658    unconst(m->uuidParentImage) = parentId;
     1659
     1660    HRESULT rc = queryInfo(!!aSetImageId /* fSetImageId */,
     1661                           !!aSetParentId /* fSetParentId */);
     1662
     1663    return rc;
     1664}
     1665
    16571666STDMETHODIMP Medium::RefreshState(MediumState_T *aState)
    16581667{
     
    16731682        case MediumState_LockedRead:
    16741683        {
    1675             rc = queryInfo();
     1684            rc = queryInfo(false /* fSetImageId */, false /* fSetParentId */);
    16761685            break;
    16771686        }
     
    34373446 *       for the first time). Locks mParent for reading. Locks this object for
    34383447 *       writing.
    3439  */
    3440 HRESULT Medium::queryInfo()
     3448 *
     3449 * @param fSetImageId Whether to reset the UUID contained in the image file to the UUID in the medium instance data (see SetIDs())
     3450 * @param fSetParentId Whether to reset the parent UUID contained in the image file to the parent UUID in the medium instance data (see SetIDs())
     3451 * @return
     3452 */
     3453HRESULT Medium::queryInfo(bool fSetImageId, bool fSetParentId)
    34413454{
    34423455    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     
    35503563                /* Modify the UUIDs if necessary. The associated fields are
    35513564                 * not modified by other code, so no need to copy. */
    3552                 if (m->setImageId)
     3565                if (fSetImageId)
    35533566                {
    3554                     vrc = VDSetUuid(hdd, 0, m->imageId);
     3567                    vrc = VDSetUuid(hdd, 0, m->uuidImage);
    35553568                    ComAssertRCThrow(vrc, E_FAIL);
    35563569                }
    3557                 if (m->setParentId)
     3570                if (fSetParentId)
    35583571                {
    3559                     vrc = VDSetParentUuid(hdd, 0, m->parentId);
     3572                    vrc = VDSetParentUuid(hdd, 0, m->uuidParentImage);
    35603573                    ComAssertRCThrow(vrc, E_FAIL);
    35613574                }
    35623575                /* zap the information, these are no long-term members */
    3563                 m->setImageId = false;
    3564                 unconst(m->imageId).clear();
    3565                 m->setParentId = false;
    3566                 unconst(m->parentId).clear();
     3576                unconst(m->uuidImage).clear();
     3577                unconst(m->uuidParentImage).clear();
    35673578
    35683579                /* check the UUID */
     
    36033614                if (isImport)
    36043615                {
    3605                     if (m->setImageId)
    3606                         mediumId = m->imageId;
     3616                    if (fSetImageId)
     3617                        mediumId = m->uuidImage;
    36073618                    else
    36083619                        mediumId.create();
  • trunk/src/VBox/Main/VirtualBoxImpl.cpp

    r31562 r31568  
    14041404}
    14051405
    1406 STDMETHODIMP VirtualBox::OpenHardDisk(IN_BSTR aLocation,
    1407                                       AccessMode_T accessMode,
    1408                                       BOOL aSetImageId,
    1409                                       IN_BSTR aImageId,
    1410                                       BOOL aSetParentId,
    1411                                       IN_BSTR aParentId,
    1412                                       IMedium **aHardDisk)
     1406STDMETHODIMP VirtualBox::OpenMedium(IN_BSTR aLocation,
     1407                                    DeviceType_T deviceType,
     1408                                    AccessMode_T accessMode,
     1409                                    IMedium **aMedium)
    14131410{
    14141411    CheckComArgStrNotEmptyOrNull(aLocation);
    1415     CheckComArgOutSafeArrayPointerValid(aHardDisk);
     1412    CheckComArgOutSafeArrayPointerValid(aMedium);
    14161413
    14171414    AutoCaller autoCaller(this);
     
    14191416
    14201417    /* we don't access non-const data members so no need to lock */
    1421 
    14221418    HRESULT rc = E_FAIL;
    14231419
    1424     ComObjPtr<Medium> hardDisk;
    1425     hardDisk.createObject();
    1426     Guid imageId, parentId;
    1427     if (aSetImageId)
    1428     {
    1429         imageId = Guid(aImageId);
    1430         if (imageId.isEmpty())
    1431             return setError(E_INVALIDARG, tr("Argument %s is empty"), "aImageId");
    1432     }
    1433     if (aSetParentId)
    1434         parentId = Guid(aParentId);
    1435     rc = hardDisk->init(this,
    1436                         aLocation,
    1437                         (accessMode == AccessMode_ReadWrite) ? Medium::OpenReadWrite : Medium::OpenReadOnly,
    1438                         DeviceType_HardDisk,
    1439                         aSetImageId,
    1440                         imageId,
    1441                         aSetParentId,
    1442                         parentId);
     1420    switch (deviceType)
     1421    {
     1422        case DeviceType_HardDisk:
     1423        case DeviceType_Floppy:
     1424        break;
     1425
     1426        case DeviceType_DVD:
     1427            accessMode = AccessMode_ReadOnly;
     1428        break;
     1429
     1430        default:
     1431            return setError(E_INVALIDARG, "Device type must be HardDisk, DVD or Floppy");
     1432    }
     1433
     1434    ComObjPtr<Medium> pMedium;
     1435    pMedium.createObject();
     1436    rc = pMedium->init(this,
     1437                       aLocation,
     1438                       (accessMode == AccessMode_ReadWrite) ? Medium::OpenReadWrite : Medium::OpenReadOnly,
     1439                       deviceType);
    14431440
    14441441    if (SUCCEEDED(rc))
    14451442    {
    1446         bool fNeedsSaveSettings = false;
    1447         {
    1448             AutoWriteLock treeLock(getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS);
    1449             rc = registerHardDisk(hardDisk, &fNeedsSaveSettings);
    1450         }
     1443        bool fNeedsGlobalSaveSettings = false;
     1444
     1445        AutoWriteLock treeLock(getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS);
     1446
     1447        switch (deviceType)
     1448        {
     1449            case DeviceType_HardDisk:
     1450                rc = registerHardDisk(pMedium, &fNeedsGlobalSaveSettings);
     1451            break;
     1452
     1453            case DeviceType_DVD:
     1454            case DeviceType_Floppy:
     1455                rc = registerImage(pMedium, deviceType, &fNeedsGlobalSaveSettings);
     1456            break;
     1457        }
     1458
     1459        treeLock.release();
    14511460
    14521461        /* Note that it's important to call uninit() on failure to register
     
    14551464
    14561465        if (SUCCEEDED(rc))
    1457             hardDisk.queryInterfaceTo(aHardDisk);
     1466            pMedium.queryInterfaceTo(aMedium);
    14581467        else
    1459             hardDisk->uninit();
    1460 
    1461         if (fNeedsSaveSettings)
     1468            pMedium->uninit();
     1469
     1470        if (fNeedsGlobalSaveSettings)
    14621471        {
    14631472            AutoWriteLock vboxlock(this COMMA_LOCKVAL_SRC_POS);
     
    15081517    /* the below will set *aHardDisk to NULL if hardDisk is null */
    15091518    pMedium.queryInterfaceTo(aMedium);
    1510 
    1511     return rc;
    1512 }
    1513 
    1514 /** @note Doesn't lock anything. */
    1515 STDMETHODIMP VirtualBox::OpenDVDImage(IN_BSTR aLocation,
    1516                                       IN_BSTR aId,
    1517                                       IMedium **aDVDImage)
    1518 {
    1519     CheckComArgStrNotEmptyOrNull(aLocation);
    1520     CheckComArgOutSafeArrayPointerValid(aDVDImage);
    1521 
    1522     AutoCaller autoCaller(this);
    1523     if (FAILED(autoCaller.rc())) return autoCaller.rc();
    1524 
    1525     HRESULT rc = VBOX_E_FILE_ERROR;
    1526 
    1527     Guid id(aId);
    1528     /* generate an UUID if not specified */
    1529     if (id.isEmpty())
    1530         id.create();
    1531 
    1532     ComObjPtr<Medium> image;
    1533     image.createObject();
    1534     rc = image->init(this,
    1535                      aLocation,
    1536                      Medium::OpenReadOnly,
    1537                      DeviceType_DVD,
    1538                      true /* aSetImageId */,
    1539                      id,
    1540                      false /* aSetParentId */,
    1541                      Guid());
    1542     if (SUCCEEDED(rc))
    1543     {
    1544         AutoWriteLock treeLock(getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS);
    1545         bool fNeedsSaveSettings = false;
    1546         rc = registerImage(image, DeviceType_DVD, &fNeedsSaveSettings);
    1547         treeLock.release();
    1548 
    1549         if (SUCCEEDED(rc))
    1550             image.queryInterfaceTo(aDVDImage);
    1551 
    1552         if (fNeedsSaveSettings)
    1553         {
    1554             AutoWriteLock vboxlock(this COMMA_LOCKVAL_SRC_POS);
    1555             saveSettings();
    1556         }
    1557     }
    1558 
    1559     return rc;
    1560 }
    1561 
    1562 /** @note Doesn't lock anything. */
    1563 STDMETHODIMP VirtualBox::OpenFloppyImage(IN_BSTR aLocation,
    1564                                          IN_BSTR aId,
    1565                                          IMedium **aFloppyImage)
    1566 {
    1567     CheckComArgStrNotEmptyOrNull(aLocation);
    1568     CheckComArgOutSafeArrayPointerValid(aFloppyImage);
    1569 
    1570     AutoCaller autoCaller(this);
    1571     if (FAILED(autoCaller.rc())) return autoCaller.rc();
    1572 
    1573     HRESULT rc = VBOX_E_FILE_ERROR;
    1574 
    1575     Guid id(aId);
    1576     /* generate an UUID if not specified */
    1577     if (id.isEmpty())
    1578         id.create();
    1579 
    1580     ComObjPtr<Medium> image;
    1581     image.createObject();
    1582     rc = image->init(this,
    1583                      aLocation,
    1584                      Medium::OpenReadWrite,
    1585                      DeviceType_Floppy,
    1586                      true /* aSetImageId */,
    1587                      id,
    1588                      false /* aSetParentId */,
    1589                      Guid());
    1590     if (SUCCEEDED(rc))
    1591     {
    1592         AutoWriteLock treeLock(getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS);
    1593         bool fNeedsSaveSettings = false;
    1594         rc = registerImage(image, DeviceType_Floppy, &fNeedsSaveSettings);
    1595         treeLock.release();
    1596 
    1597         if (SUCCEEDED(rc))
    1598             image.queryInterfaceTo(aFloppyImage);
    1599 
    1600         if (fNeedsSaveSettings)
    1601         {
    1602             AutoWriteLock vboxlock(this COMMA_LOCKVAL_SRC_POS);
    1603             saveSettings();
    1604         }
    1605     }
    16061519
    16071520    return rc;
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r31562 r31568  
    18061806    </method>
    18071807
    1808     <method name="openHardDisk">
    1809       <desc>
    1810         Opens a medium from an existing location, optionally replacing
    1811         the image UUID and/or parent UUID.
    1812 
    1813         After the medium is successfully opened by this method, it gets
    1814         remembered by (known to) this VirtualBox installation and will be
    1815         accessible through the <link to="#findMedium"/> method. Remembered base media
    1816         are also returned as part of the <link to="#hardDisks"/> array and can
    1817         be attached to virtual machines. See <link to="IMedium" /> for more details.
    1818 
    1819         If a differencing medium is to be opened by this method, the
     1808    <method name="openMedium">
     1809      <desc>
     1810        Opens a medium from an existing storage location.
     1811
     1812        Once a medium has been opened, VirtualBox saves the medium in a media
     1813        registry. Prior to VirtualBox 3.3, this registry had to be the global
     1814        media registry in the VirtualBox.xml file, which was shared between
     1815        all machines and made transporting machines from one host to another
     1816        difficult. Now you can optionally specify an <link to="IMachine" />
     1817        instance, in which case the medium will be remembered in that machine's
     1818        registry. This is the recommended procedure for machines created with
     1819        VirtualBox 3.3 or later. <i>(not yet implemented)</i>
     1820
     1821        Depending on the given device type, the file at the storage location
     1822        must be in one of the media formats understood by VirtualBox:
     1823
     1824        <ul>
     1825          <li>With a "HardDisk" device type, the file must be a hard disk image
     1826            in one of the formats supported by VirtualBox (see
     1827            <link to="ISystemProperties::mediumFormats" />).
     1828            After this method succeeds, if the medium is a base medium, it
     1829            will be added to the <link to="#hardDisks"/> array attribute. </li>
     1830          <li>With a "DVD" device type, the file must be an ISO 9960 CD/DVD image.
     1831            After this method succeeds, the medium will be added to the
     1832            <link to="#DVDImages"/> array attribute.</li>
     1833          <li>With a "Floppy" device type, the file must be an RAW floppy image.
     1834            After this method succeeds, the medium will be added to the
     1835            <link to="#floppyImages"/> array attribute.</li>
     1836        </ul>
     1837
     1838        After having been opened, the medium can be found by the <link to="#findMedium"/>
     1839        method and can be attached to virtual machines. See <link to="IMedium" /> for more details.
     1840
     1841        The UUID of the newly opened medium will either be retrieved from the
     1842        storage location, if the format supports it (e.g. for hard disk images),
     1843        or a new UUID will be randomly generated (e.g. for ISO and RAW files).
     1844        If for some reason you need to change the medium's UUID, use
     1845        <link to="IMedium::setIDs" />.
     1846
     1847        If a differencing hard disk medium is to be opened by this method, the
    18201848        operation will succeed only if its parent medium and all ancestors,
    18211849        if any, are already known to this VirtualBox installation (for example,
    18221850        were opened by this method before).
    18231851
    1824         This method tries to guess the storage format of the specified medium
     1852        This method attempts to guess the storage format of the specified medium
    18251853        by reading medium data at the specified location.
    18261854
    1827         If @a accessMode is ReadWrite (which it should be), the image is opened
    1828         for read/write access and must have according permissions, as VirtualBox
    1829         may actually write status information into the disk's metadata sections.
    1830 
    1831         Note that write access is required for all typical image usage in VirtualBox,
     1855        If @a accessMode is ReadWrite (which it should be for hard disks and floppies),
     1856        the image is opened for read/write access and must have according permissions,
     1857        as VirtualBox may actually write status information into the disk's metadata
     1858        sections.
     1859
     1860        Note that write access is required for all typical hard disk usage in VirtualBox,
    18321861        since VirtualBox may need to write metadata such as a UUID into the image.
    18331862        The only exception is opening a source image temporarily for copying and
    1834         cloning when the image will quickly be closed again.
    1835 
    1836         Note that the format of the location string is storage format specific.
    1837         See <link to="IMedium::location"/>, IMedium and
     1863        cloning (see <link to="IMedium::cloneTo" /> when the image will be closed
     1864        again soon.
     1865
     1866        The format of the location string is storage format specific. See
     1867        <link to="IMedium::location"/>, IMedium and
    18381868        <link to="ISystemProperties::defaultHardDiskFolder"/> for more details.
    18391869
     
    18481878          Invalid medium storage format.
    18491879        </result>
    1850 
     1880        <result name="VBOX_E_INVALID_OBJECT_STATE">
     1881          Medium has already been added to a media registry.
     1882        </result>
    18511883      </desc>
    18521884      <param name="location" type="wstring" dir="in">
     
    18561888        </desc>
    18571889      </param>
     1890      <param name="deviceType" type="DeviceType" dir="in">
     1891        <desc>
     1892          Must be one of "HardDisk", "DVD" or "Floppy".
     1893        </desc>
     1894      </param>
    18581895      <param name="accessMode" type="AccessMode" dir="in">
    1859           <desc>
    1860               Determines whether to open the image in read/write or read-only mode.
    1861           </desc>
    1862       </param>
    1863       <param name="setImageId" type="boolean" dir="in">
    1864           <desc>
    1865               Select whether a new image UUID is set or not.
    1866           </desc>
    1867       </param>
    1868       <param name="imageId" type="uuid" mod="string" dir="in">
    1869           <desc>
    1870               New UUID for the image. If an empty string is passed, then a new
    1871               UUID is automatically created. Specifying a zero UUIDs is not valid.
    1872           </desc>
    1873       </param>
    1874       <param name="setParentId" type="boolean" dir="in">
    1875           <desc>
    1876               Select whether a new parent UUID is set or not.
    1877           </desc>
    1878       </param>
    1879       <param name="parentId" type="uuid" mod="string" dir="in">
    1880           <desc>
    1881               New parent UUID for the image. If an empty string is passed, then a
    1882               new UUID is automatically created, provided @a setParentId is
    1883               @c true. A zero UUID is valid.
    1884           </desc>
     1896        <desc>Whether to open the image in read/write or read-only mode. For
     1897        a "DVD" device type, this is ignored and read-only mode is always assumed.</desc>
    18851898      </param>
    18861899      <param name="medium" type="IMedium" dir="return">
     
    18961909        The given medium must be known to this VirtualBox installation, i.e.
    18971910        it must be previously created by <link to="#createHardDisk"/> or opened
    1898         by <link to="#openHardDisk"/> or <link to="#openDVDImage" /> or
    1899         <link to="#openFloppyImage" />.
     1911        by <link to="#openMedium"/>.
    19001912
    19011913        The search is done by comparing the value of the @a location argument to
     
    19241936      <param name="medium" type="IMedium" dir="return">
    19251937        <desc>Medium object, if found.</desc>
    1926       </param>
    1927     </method>
    1928 
    1929     <method name="openDVDImage">
    1930       <desc>
    1931         Opens a CD/DVD image contained in the specified file of the supported
    1932         format and assigns it the given UUID.
    1933 
    1934         After the image is successfully opened by this method, it gets
    1935         remembered by (known to) this VirtualBox installation and will be
    1936         accessible through the <link to="#findMedium"/> method.
    1937         Remembered images are also returned as part of the <link to="#DVDImages"/>
    1938         array and can be mounted to virtual machines. See <link to="IMedium" />
    1939         for more details.
    1940 
    1941         See <link to="IMedium::location"/> to get more details about the format
    1942         of the location string.
    1943 
    1944         <note>
    1945           Currently only ISO 9960 CD/DVD images are supported by VirtualBox.
    1946         </note>
    1947 
    1948         <result name="VBOX_E_FILE_ERROR">
    1949           Invalid CD/DVD image file location or could not find the CD/DVD
    1950           image at the specified location.
    1951         </result>
    1952         <result name="VBOX_E_INVALID_OBJECT_STATE">
    1953           CD/DVD image already exists in the media registry.
    1954         </result>
    1955 
    1956       </desc>
    1957       <param name="location" type="wstring" dir="in">
    1958         <desc>
    1959           Full path to the file that contains a valid CD/DVD image.
    1960         </desc>
    1961       </param>
    1962       <param name="id" type="uuid" mod="string" dir="in">
    1963         <desc>
    1964           UUID to assign to the given image within this VirtualBox installation.
    1965           If an empty (@c null) UUID is specified, the system will randomly
    1966           generate a new UUID.
    1967         </desc>
    1968       </param>
    1969       <param name="image" type="IMedium" dir="return">
    1970         <desc>Opened CD/DVD image object.</desc>
    1971       </param>
    1972     </method>
    1973 
    1974     <method name="openFloppyImage">
    1975       <desc>
    1976         Opens a floppy image contained in the specified file of the supported
    1977         format and assigns it the given UUID.
    1978 
    1979         After the image is successfully opened by this method, it gets
    1980         remembered by (known to) this VirtualBox installation and will be
    1981         accessible through the <link to="#findMedium"/> method.
    1982         Remembered images are also returned as part of the <link to="#floppyImages"/>
    1983         array and can be mounted to virtual machines. See <link to="IMedium" />
    1984         for more details.
    1985 
    1986         See <link to="IMedium::location"/> to get more details about the format
    1987         of the location string.
    1988 
    1989         <result name="VBOX_E_FILE_ERROR">
    1990           Invalid floppy image file location or could not find the floppy
    1991           image at the specified location.
    1992         </result>
    1993         <result name="VBOX_E_INVALID_OBJECT_STATE">
    1994           Floppy image already exists in the media registry.
    1995         </result>
    1996 
    1997         <note>
    1998           Currently, only raw floppy images are supported by VirtualBox.
    1999         </note>
    2000       </desc>
    2001       <param name="location" type="wstring" dir="in">
    2002         <desc>
    2003           Full path to the file that contains a valid floppy image.
    2004         </desc>
    2005       </param>
    2006       <param name="id" type="uuid" mod="string" dir="in">
    2007         <desc>
    2008           UUID to assign to the given image file within this VirtualBox
    2009           installation. If an empty (@c null) UUID is specified, the system will
    2010           randomly generate a new UUID.
    2011         </desc>
    2012       </param>
    2013       <param name="image" type="IMedium" dir="return">
    2014         <desc>Opened floppy image object.</desc>
    20151938      </param>
    20161939    </method>
     
    73427265          IMedium,
    73437266          <link to="IVirtualBox::createHardDisk"/>,
    7344           <link to="IVirtualBox::openHardDisk"/>,
     7267          <link to="IVirtualBox::openMedium"/>,
    73457268          <link to="IMedium::location"/>
    73467269        </see>
     
    85548477      </ul>
    85558478
    8556       Existing media are opened using the following methods, depending on the
    8557       media type:
    8558       <ul>
    8559         <li><link to="IVirtualBox::openHardDisk"/></li>
    8560         <li><link to="IVirtualBox::openDVDImage"/></li>
    8561         <li><link to="IVirtualBox::openFloppyImage"/></li>
    8562       </ul>
    8563 
    8564       New hard disk media can be created with the VirtualBox API using the
     8479      Existing media are opened using <link to="IVirtualBox::openMedium"/>;
     8480      new hard disk media can be created with the VirtualBox API using the
    85658481      <link to="IVirtualBox::createHardDisk"/> method.
    85668482
     
    86538569      New base hard disks are created using
    86548570      <link to="IVirtualBox::createHardDisk"/>. Existing hard disks are
    8655       opened using <link to="IVirtualBox::openHardDisk"/>. Differencing hard
     8571      opened using <link to="IVirtualBox::openMedium"/>. Differencing hard
    86568572      disks are usually implicitly created by VirtualBox when needed but may
    86578573      also be created explicitly using <link to="#createDiffStorage"/>.
     
    91699085    </attribute>
    91709086
     9087    <method name="setIDs">
     9088      <desc>
     9089        Changes the UUID and parent UUID for a hard disk medium.
     9090      </desc>
     9091      <param name="setImageId" type="boolean" dir="in">
     9092        <desc>
     9093          Select whether a new image UUID is set or not.
     9094        </desc>
     9095      </param>
     9096      <param name="imageId" type="uuid" mod="string" dir="in">
     9097        <desc>
     9098          New UUID for the image. If an empty string is passed, then a new
     9099          UUID is automatically created, provided that @a setImageId is @c true.
     9100          Specifying a zero UUID is not allowed.
     9101        </desc>
     9102      </param>
     9103      <param name="setParentId" type="boolean" dir="in">
     9104        <desc>
     9105          Select whether a new parent UUID is set or not.
     9106        </desc>
     9107      </param>
     9108      <param name="parentId" type="uuid" mod="string" dir="in">
     9109        <desc>
     9110          New parent UUID for the image. If an empty string is passed, then a
     9111          new UUID is automatically created, provided @a setParentId is
     9112          @c true. A zero UUID is valid.
     9113        </desc>
     9114      </param>
     9115        <result name="E_INVALIDARG">
     9116          Invalid parameter combination.
     9117        </result>
     9118      <result name="VBOX_E_NOT_SUPPORTED">
     9119        Medium is not a hard disk medium.
     9120      </result>
     9121    </method>
     9122
    91719123    <method name="refreshState">
    91729124      <desc>
     
    93979349        operation will fail.
    93989350
    9399         When the medium is successfully closed, it gets removed from
    9400         the list of remembered media, but its storage unit is not
    9401         deleted. In particular, this means that this medium can be
    9402         later opened again using the <link
    9403         to="IVirtualBox::openHardDisk"/> call.
     9351        When the medium is successfully closed, it is removed from
     9352        the list of registered media, but its storage unit is not
     9353        deleted. In particular, this means that this medium can
     9354        later be opened again using the <link to="IVirtualBox::openMedium"/>
     9355        call.
    94049356
    94059357        Note that after this method successfully returns, the given medium
  • trunk/src/VBox/Main/include/MediumImpl.h

    r31482 r31568  
    7979                 const Utf8Str &aLocation,
    8080                 HDDOpenMode enOpenMode,
    81                  DeviceType_T aDeviceType,
    82                  BOOL aSetImageId,
    83                  const Guid &aImageId,
    84                  BOOL aSetParentId,
    85                  const Guid &aParentId);
     81                 DeviceType_T aDeviceType);
    8682
    8783    // initializer used when loading settings
     
    129125
    130126    // IMedium methods
     127    STDMETHOD(SetIDs)(BOOL aSetImageId, IN_BSTR aImageId,
     128                      BOOL aSetParentId, IN_BSTR aParentId);
    131129    STDMETHOD(RefreshState)(MediumState_T *aState);
    132130    STDMETHOD(GetSnapshotIds)(IN_BSTR aMachineId,
     
    245243private:
    246244
    247     HRESULT queryInfo();
     245    HRESULT queryInfo(bool fSetImageId, bool fSetParentId);
    248246
    249247    HRESULT canClose();
  • trunk/src/VBox/Main/include/VirtualBoxImpl.h

    r31562 r31568  
    132132    STDMETHOD(CreateHardDisk)(IN_BSTR aFormat, IN_BSTR aLocation,
    133133                               IMedium **aHardDisk);
    134     STDMETHOD(OpenHardDisk) (IN_BSTR aLocation, AccessMode_T accessMode,
    135                              BOOL aSetImageId, IN_BSTR aImageId,
    136                              BOOL aSetParentId, IN_BSTR aParentId,
    137                              IMedium **aHardDisk);
    138     STDMETHOD(FindMedium) (IN_BSTR aLocation, DeviceType_T deviceType, IMedium **aMedium);
    139 
    140     STDMETHOD(OpenDVDImage) (IN_BSTR aLocation, IN_BSTR aId,
    141                              IMedium **aDVDImage);
    142     STDMETHOD(OpenFloppyImage) (IN_BSTR aLocation, IN_BSTR aId,
    143                                 IMedium **aFloppyImage);
     134    STDMETHOD(OpenMedium)(IN_BSTR aLocation,
     135                          DeviceType_T deviceType,
     136                          AccessMode_T accessMode,
     137                          IMedium **aMedium);
     138    STDMETHOD(FindMedium)(IN_BSTR aLocation,
     139                          DeviceType_T deviceType,
     140                          IMedium **aMedium);
    144141
    145142    STDMETHOD(GetGuestOSType) (IN_BSTR aId, IGuestOSType **aType);
  • trunk/src/VBox/Main/testcase/tstVBoxAPILinux.cpp

    r31070 r31568  
    356356     */
    357357    nsCOMPtr<IMedium> dvdImage;
    358 
    359     rc = virtualBox->OpenDVDImage(NS_LITERAL_STRING("/home/vbox/isos/winnt4ger.iso").get(),
    360                                   nsnull, /* NULL UUID, i.e. a new one will be created */
    361                                   getter_AddRefs(dvdImage));
     358    rc = virtualBox->OpenMedium(NS_LITERAL_STRING("/home/vbox/isos/winnt4ger.iso").get(),
     359                                DeviceType_DVD,
     360                                AccessMode_ReadOnly,
     361                                getter_AddRefs(dvdImage));
    362362    if (NS_FAILED(rc))
    363     {
    364363        printf("Error: could not open CD image! rc=%08X\n", rc);
    365     }
    366364    else
    367365    {
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