VirtualBox

Changeset 18162 in vbox for trunk/src


Ignore:
Timestamp:
Mar 23, 2009 7:28:13 PM (16 years ago)
Author:
vboxsync
Message:

Main: add read/write param to OpenHardDisk to allow for opening disk images during import without requiring write access

Location:
trunk/src/VBox
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxManage/VBoxInternalManage.cpp

    r17970 r18162  
    12491249    {
    12501250        ComPtr<IHardDisk> hardDisk;
    1251         CHECK_ERROR(aVirtualBox, OpenHardDisk(filename, hardDisk.asOutParam()));
     1251        CHECK_ERROR(aVirtualBox, OpenHardDisk(filename, TRUE /* fWrite */, hardDisk.asOutParam()));
    12521252    }
    12531253
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageDisk.cpp

    r18108 r18162  
    521521        if (FAILED (rc))
    522522        {
    523             CHECK_ERROR(a->virtualBox, OpenHardDisk(src, srcDisk.asOutParam()));
     523            CHECK_ERROR(a->virtualBox, OpenHardDisk(src, TRUE /* fWrite */, srcDisk.asOutParam()));
    524524            if (SUCCEEDED (rc))
    525525            {
     
    943943        if (FAILED (rc))
    944944        {
    945             CHECK_ERROR(a->virtualBox, OpenHardDisk(filepath, hardDisk.asOutParam()));
     945            CHECK_ERROR(a->virtualBox, OpenHardDisk(filepath, TRUE /* fWrite */, hardDisk.asOutParam()));
    946946            if (SUCCEEDED (rc))
    947947            {
     
    10831083
    10841084        ComPtr<IHardDisk> hardDisk;
    1085         CHECK_ERROR(a->virtualBox, OpenHardDisk(filepath, hardDisk.asOutParam()));
     1085        CHECK_ERROR(a->virtualBox, OpenHardDisk(filepath, TRUE /* fWrite */, hardDisk.asOutParam()));
    10861086        if (SUCCEEDED(rc) && hardDisk)
    10871087        {
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageModifyVM.cpp

    r18072 r18162  
    10541054                    {
    10551055                        /* open the new hard disk object */
    1056                         CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(hdds[0]), hardDisk.asOutParam()));
     1056                        CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(hdds[0]), TRUE /* fWrite */, hardDisk.asOutParam()));
    10571057                    }
    10581058                }
     
    10871087                    {
    10881088                        /* open the new hard disk object */
    1089                         CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(hdds[1]), hardDisk.asOutParam()));
     1089                        CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(hdds[1]), TRUE /* fWrite */, hardDisk.asOutParam()));
    10901090                    }
    10911091                }
     
    11201120                    {
    11211121                        /* open the new hard disk object */
    1122                         CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(hdds[2]), hardDisk.asOutParam()));
     1122                        CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(hdds[2]), TRUE /* fWrite */, hardDisk.asOutParam()));
    11231123                    }
    11241124                }
     
    18331833                        {
    18341834                            /* open the new hard disk object */
    1835                             CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(hdds[i]), hardDisk.asOutParam()));
     1835                            CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(hdds[i]), TRUE /* fWrite */, hardDisk.asOutParam()));
    18361836                        }
    18371837                    }
     
    19221922                        {
    19231923                            /* open the new hard disk object */
    1924                             CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(hdds[i]), hardDisk.asOutParam()));
     1924                            CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(hdds[i]), TRUE /* fWrite */, hardDisk.asOutParam()));
    19251925                        }
    19261926                    }
  • trunk/src/VBox/Frontends/VBoxSDL/VBoxSDL.cpp

    r17737 r18162  
    16701670            /* we've not found the image */
    16711671            RTPrintf("Adding hard disk '%S'...\n", hdaFile);
    1672             virtualBox->OpenHardDisk(hdaFileBstr, hardDisk.asOutParam());
     1672            virtualBox->OpenHardDisk(hdaFileBstr, TRUE /* fWrite */, hardDisk.asOutParam());
    16731673        }
    16741674        /* do we have the right image now? */
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxMediaManagerDlg.cpp

    r17669 r18162  
    15451545        case VBoxDefs::MediaType_HardDisk:
    15461546        {
    1547             CHardDisk hd = mVBox.OpenHardDisk(aLocation);
     1547            CHardDisk hd = mVBox.OpenHardDisk(aLocation, TRUE /* fWrite */);
    15481548            if (mVBox.isOk())
    15491549            {
  • trunk/src/VBox/Main/ApplianceImpl.cpp

    r18153 r18162  
    23112311
    23122312                            /* First open the existing disk image */
    2313                             rc = pVirtualBox->OpenHardDisk(Bstr(strSrcFilePath), srcHdVBox.asOutParam());
     2313                            rc = pVirtualBox->OpenHardDisk(Bstr(strSrcFilePath),
     2314                                                           FALSE,           // read-only
     2315                                                           srcHdVBox.asOutParam());
    23142316                            if (FAILED(rc)) throw rc;
    23152317                            fSourceHdNeedsClosing = true;
  • trunk/src/VBox/Main/HardDiskImpl.cpp

    r18121 r18162  
    624624 * @param aLocaiton     Storage unit location.
    625625 */
    626 HRESULT HardDisk::init (VirtualBox *aVirtualBox, CBSTR aFormat,
     626HRESULT HardDisk::init (VirtualBox *aVirtualBox,
     627                        CBSTR aFormat,
    627628                        CBSTR aLocation)
    628629{
     
    695696/**
    696697 * Initializes the hard disk object by opening the storage unit at the specified
    697  * location.
     698 * location. If the fWrite parameter is true, then the image will be opened
     699 * read/write, otherwise it will be opened read-only.
    698700 *
    699701 * Note that the UUID, format and the parent of this hard disk will be
     
    704706 * @param aLocaiton     Storage unit location.
    705707 */
    706 HRESULT HardDisk::init (VirtualBox *aVirtualBox, CBSTR aLocation)
     708HRESULT HardDisk::init(VirtualBox *aVirtualBox,
     709                       CBSTR aLocation,
     710                       HDDOpenMode enOpenMode)
    707711{
    708712    AssertReturn (aVirtualBox, E_INVALIDARG);
     
    729733
    730734    /* get all the information about the medium from the storage unit */
    731     rc = queryInfo();
     735    rc = queryInfo((enOpenMode == OpenReadWrite) /* fWrite */ );
    732736    if (SUCCEEDED (rc))
    733737    {
     
    756760/**
    757761 * Initializes the hard disk object by loading its data from the given settings
    758  * node.
     762 * node. In this mode, the image will always be opened read/write.
    759763 *
    760764 * @param aVirtualBox   VirtualBox object.
     
    764768 * @note Locks VirtualBox lock for writing, treeLock() for writing.
    765769 */
    766 HRESULT HardDisk::init (VirtualBox *aVirtualBox, HardDisk *aParent,
     770HRESULT HardDisk::init (VirtualBox *aVirtualBox,
     771                        HardDisk *aParent,
    767772                        const settings::Key &aNode)
    768773{
     
    869874        ComObjPtr<HardDisk> hardDisk;
    870875        hardDisk.createObject();
    871         rc = hardDisk->init (aVirtualBox, this, *it);
     876        rc = hardDisk->init(aVirtualBox, this, *it);
    872877        CheckComRCBreakRC (rc);
    873878
     
    29912996 *       writing.
    29922997 */
    2993 HRESULT HardDisk::queryInfo()
     2998HRESULT HardDisk::queryInfo(bool fWrite)
    29942999{
    29953000    AutoWriteLock alock (this);
     
    30743079             * time in VirtualBox (such as VMDK for which VDOpen() needs to
    30753080             * generate an UUID if it is missing) */
    3076             if (!isImport)
     3081            if (!fWrite || !isImport)
    30773082                flags |= VD_OPEN_FLAGS_READONLY;
    30783083
  • trunk/src/VBox/Main/MachineImpl.cpp

    r18158 r18162  
    21522152        ComObjPtr<HardDisk> diff;
    21532153        diff.createObject();
    2154         rc = diff->init (mParent, hd->preferredDiffFormat(),
    2155                          BstrFmt ("%ls"RTPATH_SLASH_STR,
    2156                                   mUserData->mSnapshotFolderFull.raw()));
     2154        rc = diff->init(mParent,
     2155                        hd->preferredDiffFormat(),
     2156                        BstrFmt ("%ls"RTPATH_SLASH_STR,
     2157                                 mUserData->mSnapshotFolderFull.raw()));
    21572158        CheckComRCReturnRC (rc);
    21582159
  • trunk/src/VBox/Main/VirtualBoxImpl.cpp

    r18049 r18162  
    11251125    ComObjPtr<HardDisk> hardDisk;
    11261126    hardDisk.createObject();
    1127     rc = hardDisk->init (this, format, aLocation);
     1127    rc = hardDisk->init(this, format, aLocation);
    11281128
    11291129    if (SUCCEEDED (rc))
     
    11331133}
    11341134
    1135 STDMETHODIMP VirtualBox::OpenHardDisk(IN_BSTR aLocation,
    1136                                       IHardDisk **aHardDisk)
     1135STDMETHODIMP VirtualBox::OpenHardDisk(IN_BSTR aLocation, BOOL fWrite, IHardDisk **aHardDisk)
    11371136{
    11381137    CheckComArgNotNull(aLocation);
     
    11481147    ComObjPtr<HardDisk> hardDisk;
    11491148    hardDisk.createObject();
    1150     rc = hardDisk->init (this, aLocation);
     1149    rc = hardDisk->init(this,
     1150                        aLocation,
     1151                        (fWrite) ? HardDisk::OpenReadWrite : HardDisk::OpenReadOnly );
    11511152
    11521153    if (SUCCEEDED (rc))
     
    30913092                ComObjPtr<HardDisk> hardDisk;
    30923093                hardDisk.createObject();
    3093                 rc = hardDisk->init (this, NULL, *it);
     3094                rc = hardDisk->init(this, NULL, *it);
    30943095                CheckComRCBreakRC (rc);
    30953096
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r18107 r18162  
    18741874        by reading hard disk data at the specified location.
    18751875
     1876        If @write is true, the image is opened for read/write access and must
     1877        have according permissions, as VirtualBox may actually write status
     1878        information into the disk's metadata sections. Note that write access
     1879        is required for all typical image usage in VirtualBox, since VirtualBox
     1880        may need to write metadata such as a UUID into the image. The only
     1881        exception is opening a source image temporarily for copying and
     1882        cloning when the image will quickly be closed againl.
     1883
    18761884        Note that the format of the location string is storage format specific.
    18771885        See <link to="IMedium::location"/>, IHardDisk and
    18781886        <link to="ISystemProperties::defaultHardDiskFolder"/> for more details.
    18791887
    1880 
    18811888        <result name="VBOX_E_FILE_ERROR">
    18821889          Invalid hard disk storage file location.
     
    18951902          the supported storage formats.
    18961903        </desc>
     1904      </param>
     1905      <param name="write" type="boolean" dir="in">
     1906          <desc>
     1907              If true, opens for read/write access. If false, opens for read access only.
     1908          </desc>
    18971909      </param>
    18981910      <param name="hardDisk" type="IHardDisk" dir="return">
     
    33523364
    33533365    <method name="getDescriptionByType">
    3354       <desc>This is the same as <link to="getDescription" /> except that you can specify which types 
     3366      <desc>This is the same as <link to="getDescription" /> except that you can specify which types
    33553367      should be returned.</desc>
    33563368
  • trunk/src/VBox/Main/include/HardDiskImpl.h

    r18115 r18162  
    7777    void FinalRelease();
    7878
     79    enum HDDOpenMode  { OpenReadWrite, OpenReadOnly };
     80                // have to use a special enum or otherwise the overloaded init() is ambiguous
     81
    7982    // public initializer/uninitializer for internal purposes only
    80     HRESULT init (VirtualBox *aVirtualBox, CBSTR aFormat,
    81                   CBSTR aLocation);
    82     HRESULT init (VirtualBox *aVirtualBox,
    83                   CBSTR aLocation);
    84     HRESULT init (VirtualBox *aVirtualBox, HardDisk *aParent,
    85                   const settings::Key &aNode);
     83    HRESULT init(VirtualBox *aVirtualBox,
     84                 CBSTR aFormat,
     85                 CBSTR aLocation);
     86    HRESULT init(VirtualBox *aVirtualBox,
     87                 CBSTR aLocation,
     88                 HDDOpenMode enOpenMode);
     89    HRESULT init(VirtualBox *aVirtualBox,
     90                 HardDisk *aParent,
     91                 const settings::Key &aNode);
    8692    void uninit();
    8793
     
    248254    HRESULT setFormat (CBSTR aFormat);
    249255
    250     HRESULT queryInfo();
     256    HRESULT queryInfo(bool fWrite);
    251257
    252258    HRESULT canClose();
  • trunk/src/VBox/Main/include/VirtualBoxImpl.h

    r18023 r18162  
    151151    STDMETHOD(CreateHardDisk)(IN_BSTR aFormat, IN_BSTR aLocation,
    152152                               IHardDisk **aHardDisk);
    153     STDMETHOD(OpenHardDisk) (IN_BSTR aLocation, IHardDisk **aHardDisk);
     153    STDMETHOD(OpenHardDisk) (IN_BSTR aLocation, BOOL fWrite, IHardDisk **aHardDisk);
    154154    STDMETHOD(GetHardDisk) (IN_GUID aId, IHardDisk **aHardDisk);
    155155    STDMETHOD(FindHardDisk) (IN_BSTR aLocation, IHardDisk **aHardDisk);
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