VirtualBox

Changeset 20842 in vbox


Ignore:
Timestamp:
Jun 23, 2009 2:48:10 PM (15 years ago)
Author:
vboxsync
Message:

API and Frontends: change IVirtualBox::openHardDisk to allow modifying the image UUID and parent UUID on open

Location:
trunk/src/VBox
Files:
11 edited

Legend:

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

    r20629 r20842  
    12651265    {
    12661266        ComPtr<IHardDisk> hardDisk;
    1267         CHECK_ERROR(aVirtualBox, OpenHardDisk(filename, AccessMode_ReadWrite, hardDisk.asOutParam()));
     1267        CHECK_ERROR(aVirtualBox, OpenHardDisk(filename, AccessMode_ReadWrite, false, Bstr(""), false, Bstr(""), hardDisk.asOutParam()));
    12681268    }
    12691269
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageDisk.cpp

    r20221 r20842  
    447447        {
    448448            unknown = true;
    449             rc = a->virtualBox->OpenHardDisk(Bstr(FilenameOrUuid), AccessMode_ReadWrite, hardDisk.asOutParam());
     449            rc = a->virtualBox->OpenHardDisk(Bstr(FilenameOrUuid), AccessMode_ReadWrite, false, Bstr(""), false, Bstr(""), hardDisk.asOutParam());
    450450            if (rc == VBOX_E_FILE_ERROR)
    451451            {
     
    457457                    return 1;
    458458                }
    459                 CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(szFilenameAbs), AccessMode_ReadWrite, hardDisk.asOutParam()));
     459                CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(szFilenameAbs), AccessMode_ReadWrite, false, Bstr(""), false, Bstr(""), hardDisk.asOutParam()));
    460460            }
    461461            else if (FAILED(rc))
    462                 CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(FilenameOrUuid), AccessMode_ReadWrite, hardDisk.asOutParam()));
     462                CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(FilenameOrUuid), AccessMode_ReadWrite, false, Bstr(""), false, Bstr(""), hardDisk.asOutParam()));
    463463        }
    464464        if (SUCCEEDED(rc) && hardDisk)
     
    594594        if (FAILED (rc))
    595595        {
    596             rc = a->virtualBox->OpenHardDisk(src, AccessMode_ReadWrite, srcDisk.asOutParam());
     596            rc = a->virtualBox->OpenHardDisk(src, AccessMode_ReadWrite, false, Bstr(""), false, Bstr(""), srcDisk.asOutParam());
    597597            if (rc == VBOX_E_FILE_ERROR)
    598598            {
     
    604604                    return 1;
    605605                }
    606                 CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(szFilenameAbs), AccessMode_ReadWrite, srcDisk.asOutParam()));
     606                CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(szFilenameAbs), AccessMode_ReadWrite, false, Bstr(""), false, Bstr(""), srcDisk.asOutParam()));
    607607            }
    608608            else if (FAILED(rc))
    609                 CHECK_ERROR(a->virtualBox, OpenHardDisk(src, AccessMode_ReadWrite, srcDisk.asOutParam()));
     609                CHECK_ERROR(a->virtualBox, OpenHardDisk(src, AccessMode_ReadWrite, false, Bstr(""), false, Bstr(""), srcDisk.asOutParam()));
    610610            if (SUCCEEDED (rc))
    611611            {
     
    11111111        if (FAILED (rc))
    11121112        {
    1113             rc = a->virtualBox->OpenHardDisk(Bstr(FilenameOrUuid), AccessMode_ReadWrite, hardDisk.asOutParam());
     1113            rc = a->virtualBox->OpenHardDisk(Bstr(FilenameOrUuid), AccessMode_ReadWrite, false, Bstr(""), false, Bstr(""), hardDisk.asOutParam());
    11141114            if (rc == VBOX_E_FILE_ERROR)
    11151115            {
     
    11211121                    return 1;
    11221122                }
    1123                 CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(szFilenameAbs), AccessMode_ReadWrite, hardDisk.asOutParam()));
     1123                CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(szFilenameAbs), AccessMode_ReadWrite, false, Bstr(""), false, Bstr(""), hardDisk.asOutParam()));
    11241124            }
    11251125            else if (FAILED(rc))
    1126                 CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(FilenameOrUuid), AccessMode_ReadWrite, hardDisk.asOutParam()));
     1126                CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(FilenameOrUuid), AccessMode_ReadWrite, false, Bstr(""), false, Bstr(""), hardDisk.asOutParam()));
    11271127            if (SUCCEEDED (rc))
    11281128            {
     
    12441244    { "--type",         't', RTGETOPT_REQ_STRING },
    12451245    { "-type",          't', RTGETOPT_REQ_STRING },     // deprecated
     1246    { "--uuid",         'u', RTGETOPT_REQ_UUID },
     1247    { "--parentuuid",   'p', RTGETOPT_REQ_UUID },
    12461248};
    12471249
     
    12591261    HardDiskType_T DiskType = HardDiskType_Normal;
    12601262    bool fDiskType = false;
     1263    bool fSetImageId = false;
     1264    bool fSetParentId = false;
     1265    Guid ImageId;
     1266    ImageId.clear();
     1267    Guid ParentId;
     1268    ParentId.clear();
    12611269
    12621270    int c;
     
    12921300                    return errorArgument("Invalid hard disk type '%s'", ValueUnion.psz);
    12931301                fDiskType = true;
     1302                break;
     1303
     1304            case 'u':   // --uuid
     1305                ImageId = ValueUnion.Uuid;
     1306                fSetImageId = true;
     1307                break;
     1308
     1309            case 'p':   // --parentuuid
     1310                ParentId = ValueUnion.Uuid;
     1311                fSetParentId = true;
    12941312                break;
    12951313
     
    13341352    {
    13351353        ComPtr<IHardDisk> hardDisk;
    1336         rc = a->virtualBox->OpenHardDisk(Bstr(Filename), AccessMode_ReadWrite, hardDisk.asOutParam());
     1354        Bstr ImageIdStr = BstrFmt("%RTuuid", &ImageId);
     1355        Bstr ParentIdStr = BstrFmt("%RTuuid", &ParentId);
     1356        rc = a->virtualBox->OpenHardDisk(Bstr(Filename), AccessMode_ReadWrite, fSetImageId, ImageIdStr, fSetParentId, ParentIdStr, hardDisk.asOutParam());
    13371357        if (rc == VBOX_E_FILE_ERROR)
    13381358        {
     
    13441364                return 1;
    13451365            }
    1346             CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(szFilenameAbs), AccessMode_ReadWrite, hardDisk.asOutParam()));
     1366            CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(szFilenameAbs), AccessMode_ReadWrite, fSetImageId, ImageIdStr, fSetParentId, ParentIdStr, hardDisk.asOutParam()));
    13471367        }
    13481368        else if (FAILED(rc))
    1349             CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(Filename), AccessMode_ReadWrite, hardDisk.asOutParam()));
     1369            CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(Filename), AccessMode_ReadWrite, fSetImageId, ImageIdStr, fSetParentId, ParentIdStr, hardDisk.asOutParam()));
    13501370        if (SUCCEEDED(rc) && hardDisk)
    13511371        {
     
    13591379    else if (cmd == CMD_DVD)
    13601380    {
    1361         if (fDiskType)
     1381        if (fDiskType || fSetImageId || fSetParentId)
    13621382            return errorSyntax(USAGE_OPENMEDIUM, "Invalid option for DVD images");
    13631383        ComPtr<IDVDImage> dvdImage;
     
    13791399    else if (cmd == CMD_FLOPPY)
    13801400    {
    1381         if (fDiskType)
    1382             return errorSyntax(USAGE_OPENMEDIUM, "Invalid option for DVD images");
     1401        if (fDiskType || fSetImageId || fSetParentId)
     1402            return errorSyntax(USAGE_OPENMEDIUM, "Invalid option for floppy images");
    13831403        ComPtr<IFloppyImage> floppyImage;
    13841404         rc = a->virtualBox->OpenFloppyImage(Bstr(Filename), Bstr(), floppyImage.asOutParam());
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageModifyVM.cpp

    r20501 r20842  
    11351135                    {
    11361136                        /* open the new hard disk object */
    1137                         CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(hdds[0]), AccessMode_ReadWrite, hardDisk.asOutParam()));
     1137                        CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(hdds[0]), AccessMode_ReadWrite, false, Bstr(""), false, Bstr(""), hardDisk.asOutParam()));
    11381138                    }
    11391139                }
     
    11681168                    {
    11691169                        /* open the new hard disk object */
    1170                         CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(hdds[1]), AccessMode_ReadWrite, hardDisk.asOutParam()));
     1170                        CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(hdds[1]), AccessMode_ReadWrite, false, Bstr(""), false, Bstr(""), hardDisk.asOutParam()));
    11711171                    }
    11721172                }
     
    12011201                    {
    12021202                        /* open the new hard disk object */
    1203                         CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(hdds[2]), AccessMode_ReadWrite, hardDisk.asOutParam()));
     1203                        CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(hdds[2]), AccessMode_ReadWrite, false, Bstr(""), false, Bstr(""), hardDisk.asOutParam()));
    12041204                    }
    12051205                }
     
    19301930                        {
    19311931                            /* open the new hard disk object */
    1932                             CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(hdds[i]), AccessMode_ReadWrite, hardDisk.asOutParam()));
     1932                            CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(hdds[i]), AccessMode_ReadWrite, false, Bstr(""), false, Bstr(""), hardDisk.asOutParam()));
    19331933                        }
    19341934                    }
     
    20192019                        {
    20202020                            /* open the new hard disk object */
    2021                             CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(hdds[i]), AccessMode_ReadWrite, hardDisk.asOutParam()));
     2021                            CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(hdds[i]), AccessMode_ReadWrite, false, Bstr(""), false, Bstr(""), hardDisk.asOutParam()));
    20222022                        }
    20232023                    }
  • trunk/src/VBox/Frontends/VBoxSDL/VBoxSDL.cpp

    r20627 r20842  
    17431743            /* we've not found the image */
    17441744            RTPrintf("Adding hard disk '%S'...\n", hdaFile);
    1745             virtualBox->OpenHardDisk(hdaFileBstr, AccessMode_ReadWrite, hardDisk.asOutParam());
     1745            virtualBox->OpenHardDisk(hdaFileBstr, AccessMode_ReadWrite, false, Bstr(""), false, Bstr(""), hardDisk.asOutParam());
    17461746        }
    17471747        /* do we have the right image now? */
     
    24522452                }
    24532453            }
    2454 #else 
     2454#else
    24552455            case SDL_VIDEOEXPOSE:
    24562456            {
     
    29722972
    29732973    for (unsigned i = 0; i < gcMonitors; i++)
    2974     {     
     2974    {
    29752975        if (gpFramebuffer[i])
    29762976        {
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxMediaManagerDlg.cpp

    r20078 r20842  
    15491549        case VBoxDefs::MediaType_HardDisk:
    15501550        {
    1551             CHardDisk hd = mVBox.OpenHardDisk(aLocation, KAccessMode_ReadWrite);
     1551            CHardDisk hd = mVBox.OpenHardDisk(aLocation, KAccessMode_ReadWrite, false, "", false, "");
    15521552            if (mVBox.isOk())
    15531553            {
  • trunk/src/VBox/Main/ApplianceImpl.cpp

    r20576 r20842  
    23302330                            rc = pVirtualBox->OpenHardDisk(Bstr(strSrcFilePath),
    23312331                                                           AccessMode_ReadOnly,
     2332                                                           false, Bstr(""), false, Bstr(""),
    23322333                                                           srcHdVBox.asOutParam());
    23332334                            if (FAILED(rc)) throw rc;
  • trunk/src/VBox/Main/HardDiskImpl.cpp

    r20215 r20842  
    737737 *
    738738 * @param aVirtualBox   VirtualBox object.
    739  * @param aLocaiton     Storage unit location.
     739 * @param aLocation     Storage unit location.
    740740 */
    741741HRESULT HardDisk::init (VirtualBox *aVirtualBox,
     
    811811/**
    812812 * Initializes the hard disk object by opening the storage unit at the specified
    813  * location. If the fWrite parameter is true, then the image will be opened
    814  * read/write, otherwise it will be opened read-only.
     813 * location. The enOpenMode parameter defines whether the image will be opened
     814 * read/write or read-only.
    815815 *
    816816 * Note that the UUID, format and the parent of this hard disk will be
    817  * determined when reading the hard disk storage unit. If the detected parent is
     817 * determined when reading the hard disk storage unit, unless new values are
     818 * specified by the parameters. If the detected or set parent is
    818819 * not known to VirtualBox, then this method will fail.
    819820 *
    820821 * @param aVirtualBox   VirtualBox object.
    821  * @param aLocaiton     Storage unit location.
     822 * @param aLocation     Storage unit location.
     823 * @param enOpenMode    Whether to open the image read/write or read-only.
     824 * @param aSetImageId   Whether to set the image UUID or not.
     825 * @param aImageId      New image UUID if @aSetId is true. Empty string means
     826 *                      create a new UUID, and a zero UUID is invalid.
     827 * @param aSetParentId  Whether to set the parent UUID or not.
     828 * @param aParentId     New parent UUID if @aSetParentId is true. Empty string
     829 *                      means create a new UUID, and a zero UUID is valid.
    822830 */
    823831HRESULT HardDisk::init(VirtualBox *aVirtualBox,
    824832                       CBSTR aLocation,
    825                        HDDOpenMode enOpenMode)
     833                       HDDOpenMode enOpenMode,
     834                       BOOL aSetImageId,
     835                       const Guid &aImageId,
     836                       BOOL aSetParentId,
     837                       const Guid &aParentId)
    826838{
    827839    AssertReturn (aVirtualBox, E_INVALIDARG);
     
    849861    rc = setLocation (aLocation);
    850862    CheckComRCReturnRC (rc);
     863
     864    /* save the new uuid values, will be used by queryInfo() */
     865    mm.setImageId = aSetImageId;
     866    unconst(mm.imageId) = aImageId;
     867    mm.setParentId = aSetParentId;
     868    unconst(mm.parentId) = aParentId;
    851869
    852870    /* get all the information about the medium from the storage unit */
     
    32073225                flags |= VD_OPEN_FLAGS_READONLY;
    32083226
     3227            /** @todo This kind of opening of images is assuming that diff
     3228             * images can be opened as base images. Not very clean, and should
     3229             * be fixed eventually. */
    32093230            vrc = VDOpen(hdd,
    32103231                         Utf8Str(mm.format),
     
    32223243            if (mm.formatObj->capabilities() & HardDiskFormatCapabilities_Uuid)
    32233244            {
     3245                /* modify the UUIDs if necessary */
     3246                if (mm.setImageId)
     3247                {
     3248                    vrc = VDSetUuid(hdd, 0, mm.imageId);
     3249                    ComAssertRCThrow(vrc, E_FAIL);
     3250                }
     3251                if (mm.setParentId)
     3252                {
     3253                    vrc = VDSetUuid(hdd, 0, mm.parentId);
     3254                    ComAssertRCThrow(vrc, E_FAIL);
     3255                }
     3256                /* zap the information, these are no long-term members */
     3257                mm.setImageId = false;
     3258                unconst(mm.imageId).clear();
     3259                mm.setParentId = false;
     3260                unconst(mm.parentId).clear();
     3261
    32243262                /* check the UUID */
    32253263                RTUUID uuid;
     
    32583296                /* generate an UUID for an imported UUID-less hard disk */
    32593297                if (isImport)
    3260                     unconst(m.id).create();
     3298                {
     3299                    if (mm.setImageId)
     3300                        unconst(m.id) = mm.imageId;
     3301                    else
     3302                        unconst(m.id).create();
     3303                }
    32613304            }
    32623305
  • trunk/src/VBox/Main/VirtualBoxImpl.cpp

    r20630 r20842  
    11361136STDMETHODIMP VirtualBox::OpenHardDisk(IN_BSTR aLocation,
    11371137                                      AccessMode_T accessMode,
     1138                                      BOOL aSetImageId, IN_BSTR aImageId,
     1139                                      BOOL aSetParentId, IN_BSTR aParentId,
    11381140                                      IHardDisk **aHardDisk)
    11391141{
    11401142    CheckComArgNotNull(aLocation);
     1143    CheckComArgNotNull(aImageId);
     1144    CheckComArgNotNull(aParentId);
    11411145    CheckComArgOutSafeArrayPointerValid(aHardDisk);
    11421146
     
    11501154    ComObjPtr<HardDisk> hardDisk;
    11511155    hardDisk.createObject();
     1156    Guid imageId, parentId;
     1157    if (aSetImageId)
     1158    {
     1159        imageId = Guid(aImageId);
     1160        if (imageId.isEmpty())
     1161            return setError (E_INVALIDARG, tr ("Argument %s is empty"), "aImageId");
     1162    }
     1163    if (aSetParentId)
     1164        parentId = Guid(aParentId);
    11521165    rc = hardDisk->init(this,
    11531166                        aLocation,
    1154                         (accessMode == AccessMode_ReadWrite) ? HardDisk::OpenReadWrite : HardDisk::OpenReadOnly );
     1167                        (accessMode == AccessMode_ReadWrite) ? HardDisk::OpenReadWrite : HardDisk::OpenReadOnly,
     1168                        aSetImageId, imageId,
     1169                        aSetParentId, parentId);
    11551170
    11561171    if (SUCCEEDED (rc))
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r20831 r20842  
    19031903    <method name="openHardDisk">
    19041904      <desc>
    1905         Opens a hard disk from an existing location.
     1905        Opens a hard disk from an existing location, optionally replacing
     1906        the image UUID and/or parent UUID.
    19061907
    19071908        After the hard disk is successfully opened by this method, it gets
     
    19541955          <desc>
    19551956              Determines whether to open the image in read/write or read-only mode.
     1957          </desc>
     1958      </param>
     1959      <param name="setImageId" type="boolean" dir="in">
     1960          <desc>
     1961              Select whether a new image UUID is set or not.
     1962          </desc>
     1963      </param>
     1964      <param name="imageId" type="wstring" dir="in">
     1965          <desc>
     1966              New UUID for the image. If an empty string is passed, then a new
     1967              UUID is automatically created. Specifying a zero UUIDs is not valid.
     1968          </desc>
     1969      </param>
     1970      <param name="setParentId" type="boolean" dir="in">
     1971          <desc>
     1972              Select whether a new parent UUID is set or not.
     1973          </desc>
     1974      </param>
     1975      <param name="parentId" type="wstring" dir="in">
     1976          <desc>
     1977              New parent UUID for the image. If an empty string is passed, then a
     1978              new UUID is automatically created, provided @a setParentId is
     1979              @c true. A zero UUID is valid.
    19561980          </desc>
    19571981      </param>
  • trunk/src/VBox/Main/include/HardDiskImpl.h

    r19239 r20842  
    9090    HRESULT init(VirtualBox *aVirtualBox,
    9191                 CBSTR aLocation,
    92                  HDDOpenMode enOpenMode);
     92                 HDDOpenMode enOpenMode,
     93                 BOOL aSetImageId,
     94                 const Guid &aImageId,
     95                 BOOL aSetParentId,
     96                 const Guid &aParentId);
    9397    HRESULT init(VirtualBox *aVirtualBox,
    9498                 HardDisk *aParent,
     
    294298              hddOpenMode(OpenReadWrite),
    295299              autoReset(false),
     300              setImageId(false),
     301              setParentId(false),
    296302              implicit(false),
    297303              numCreateDiffTasks(0),
     
    310316        BOOL autoReset : 1;
    311317
     318        /** the following members are invalid after changing UUID on open */
     319        BOOL setImageId : 1;
     320        BOOL setParentId : 1;
     321        const Guid imageId;
     322        const Guid parentId;
     323
    312324        typedef std::map <Bstr, Bstr> PropertyMap;
    313325        PropertyMap properties;
  • trunk/src/VBox/Main/include/VirtualBoxImpl.h

    r20630 r20842  
    151151    STDMETHOD(CreateHardDisk)(IN_BSTR aFormat, IN_BSTR aLocation,
    152152                               IHardDisk **aHardDisk);
    153     STDMETHOD(OpenHardDisk) (IN_BSTR aLocation, AccessMode_T accessMode, IHardDisk **aHardDisk);
     153    STDMETHOD(OpenHardDisk) (IN_BSTR aLocation, AccessMode_T accessMode,
     154                             BOOL aSetImageId, IN_BSTR aImageId,
     155                             BOOL aSetParentId, IN_BSTR aParentId,
     156                             IHardDisk **aHardDisk);
    154157    STDMETHOD(GetHardDisk) (IN_BSTR aId, IHardDisk **aHardDisk);
    155158    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