VirtualBox

Ignore:
Timestamp:
Mar 26, 2009 1:59:14 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
45082
Message:

Main: a different approach to opening images read-only for import which does not assert on empty UUIDs

File:
1 edited

Legend:

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

    r18269 r18313  
    729729    m.state = MediaState_Created;
    730730
     731    /* remember the open mode (defaults to ReadWrite) */
     732    mm.hddOpenMode = enOpenMode;
     733
    731734    rc = setLocation (aLocation);
    732735    CheckComRCReturnRC (rc);
    733736
    734737    /* get all the information about the medium from the storage unit */
    735     rc = queryInfo((enOpenMode == OpenReadWrite) /* fWrite */ );
    736     if (SUCCEEDED (rc))
     738    rc = queryInfo();
     739
     740    if (SUCCEEDED(rc))
    737741    {
    738742        /* if the storage unit is not accessible, it's not acceptable for the
     
    745749        else
    746750        {
    747             /* storage format must be detected by queryInfo() if the medium is
    748             * accessible */
    749             AssertReturn (!m.id.isEmpty() && !mm.format.isNull(), E_FAIL);
     751            AssertReturn(!m.id.isEmpty(), E_FAIL);
     752
     753            /* storage format must be detected by queryInfo() if the medium is accessible */
     754            AssertReturn(!mm.format.isNull(), E_FAIL);
    750755        }
    751756    }
     
    29963001 *       writing.
    29973002 */
    2998 HRESULT HardDisk::queryInfo(bool fWrite)
     3003HRESULT HardDisk::queryInfo()
    29993004{
    30003005    AutoWriteLock alock (this);
     
    30793084             * time in VirtualBox (such as VMDK for which VDOpen() needs to
    30803085             * generate an UUID if it is missing) */
    3081             if (!fWrite || !isImport)
     3086            if (    (mm.hddOpenMode == OpenReadOnly)
     3087                 || !isImport
     3088               )
    30823089                flags |= VD_OPEN_FLAGS_READONLY;
    30833090
    3084             vrc = VDOpen (hdd, Utf8Str (mm.format), location, flags,
    3085                           mm.vdDiskIfaces);
     3091            vrc = VDOpen(hdd,
     3092                         Utf8Str(mm.format),
     3093                         location,
     3094                         flags,
     3095                         mm.vdDiskIfaces);
    30863096            if (RT_FAILURE (vrc))
    30873097            {
     
    30963106                /* check the UUID */
    30973107                RTUUID uuid;
    3098                 vrc = VDGetUuid (hdd, 0, &uuid);
    3099                 ComAssertRCThrow (vrc, E_FAIL);
     3108                vrc = VDGetUuid(hdd, 0, &uuid);
     3109                ComAssertRCThrow(vrc, E_FAIL);
    31003110
    31013111                if (isImport)
    31023112                {
    3103                     unconst (m.id) = uuid;
     3113                    unconst(m.id) = uuid;
     3114
     3115                    if (m.id.isEmpty() && (mm.hddOpenMode == OpenReadOnly))
     3116                        // only when importing a VDMK that has no UUID, create one in memory
     3117                        unconst(m.id).create();
    31043118                }
    31053119                else
     
    31263140                /* generate an UUID for an imported UUID-less hard disk */
    31273141                if (isImport)
    3128                     unconst (m.id).create();
     3142                    unconst(m.id).create();
    31293143            }
    31303144
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