VirtualBox

Changeset 18313 in vbox for trunk/src


Ignore:
Timestamp:
Mar 26, 2009 1:59:14 PM (16 years ago)
Author:
vboxsync
Message:

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

Location:
trunk/src/VBox/Main
Files:
4 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
  • trunk/src/VBox/Main/MediumImpl.cpp

    r18275 r18313  
    115115        case MediaState_LockedWrite:
    116116        {
    117             rc = queryInfo(true /* fWrite */);
     117            rc = queryInfo();
    118118            break;
    119119        }
     
    715715 * size and description will be updated with the current information.
    716716 *
    717  * The fWrite parameter is ignored in this variant, since this always opens
    718  * the medium read-only; it is however acknowledged by HardDisk::queryInfo(),
    719  * which overrides this implementation for hard disk media.
    720  *
    721717 * @note This method may block during a system I/O call that checks image file
    722718 *       accessibility.
     
    724720 * @note Locks this object for writing.
    725721 */
    726 HRESULT MediumBase::queryInfo(bool fWrite)
     722HRESULT MediumBase::queryInfo()
    727723{
    728724    AutoWriteLock alock (this);
     
    966962
    967963    /* get all the information about the medium from the file */
    968     rc = queryInfo(true);
    969     if (SUCCEEDED (rc))
     964    rc = queryInfo();
     965
     966    if (SUCCEEDED(rc))
    970967    {
    971968        /* if the image file is not accessible, it's not acceptable for the
  • trunk/src/VBox/Main/include/HardDiskImpl.h

    r18275 r18313  
    256256    HRESULT setFormat (CBSTR aFormat);
    257257
    258     virtual HRESULT queryInfo(bool fWrite);
     258    virtual HRESULT queryInfo();
    259259
    260260    HRESULT canClose();
     
    289289    struct Data
    290290    {
    291         Data() : type (HardDiskType_Normal), logicalSize (0), autoReset (false)
    292                , implicit (false), numCreateDiffTasks (0)
    293                , vdProgress (NULL) , vdDiskIfaces (NULL) {}
     291        Data()
     292            : type(HardDiskType_Normal),
     293              logicalSize(0),
     294              hddOpenMode(OpenReadWrite),
     295              autoReset(false),
     296              implicit(false),
     297              numCreateDiffTasks(0),
     298              vdProgress(NULL),
     299              vdDiskIfaces(NULL)
     300        {}
    294301
    295302        const Bstr format;
     
    299306        uint64_t logicalSize;   /*< In MBytes. */
    300307
     308        HDDOpenMode hddOpenMode;
     309
    301310        BOOL autoReset : 1;
    302311
  • trunk/src/VBox/Main/include/MediumImpl.h

    r18275 r18313  
    143143
    144144    virtual HRESULT setLocation (CBSTR aLocation);
    145     virtual HRESULT queryInfo(bool fWrite);
     145    virtual HRESULT queryInfo();
    146146
    147147    /**
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