VirtualBox

Changeset 2029 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Apr 11, 2007 1:23:03 PM (18 years ago)
Author:
vboxsync
Message:

Main: Added IVirtualBox::findHardDisk().
VBoxSDL: Fixed so that .vmdk images can be passed using the -hda switch.

Location:
trunk/src/VBox
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxSDL/VBoxSDL.cpp

    r2019 r2029  
    13301330        Bstr hdaFileBstr = hdaFile;
    13311331        ComPtr<IHardDisk> hardDisk;
    1332         ComPtr<IVirtualDiskImage> vdi;
    1333         virtualBox->FindVirtualDiskImage(hdaFileBstr, vdi.asOutParam());
    1334         if (vdi)
    1335         {
    1336             vdi.queryInterfaceTo (hardDisk.asOutParam());
    1337         }
    1338         else
     1332        virtualBox->FindHardDisk(hdaFileBstr, hardDisk.asOutParam());
     1333        if (!hardDisk)
    13391334        {
    13401335            /* we've not found the image */
    13411336            RTPrintf("Registering hard disk image %s\n", hdaFile);
    1342             virtualBox->OpenVirtualDiskImage (hdaFileBstr, vdi.asOutParam());
    1343             if (vdi)
    1344             {
    1345                 vdi.queryInterfaceTo (hardDisk.asOutParam());
     1337            virtualBox->OpenHardDisk (hdaFileBstr, hardDisk.asOutParam());
     1338            if (hardDisk)
    13461339                virtualBox->RegisterHardDisk (hardDisk);
    1347             }
    13481340        }
    13491341        /* do we have the right image now? */
  • trunk/src/VBox/Main/VirtualBoxImpl.cpp

    r1491 r2029  
    10821082    Guid id = aId;
    10831083    ComObjPtr <HardDisk> hd;
    1084     HRESULT rc = findHardDisk (id, true /* setError */, &hd);
     1084    HRESULT rc = findHardDisk (&id, NULL, true /* setError */, &hd);
    10851085
    10861086    /* the below will set *aHardDisk to NULL if hd is null */
    10871087    hd.queryInterfaceTo (aHardDisk);
     1088
     1089    return rc;
     1090}
     1091
     1092/** @note Locks objects! */
     1093STDMETHODIMP VirtualBox::FindHardDisk (INPTR BSTR aLocation,
     1094                                       IHardDisk **aHardDisk)
     1095{
     1096   if (!aLocation)
     1097        return E_INVALIDARG;
     1098   if (!aHardDisk)
     1099        return E_POINTER;
     1100
     1101    AutoCaller autoCaller (this);
     1102    CheckComRCReturnRC (autoCaller.rc());
     1103
     1104    Utf8Str location = aLocation;
     1105    if (strncmp (location, "iscsi:", 6) == 0)
     1106    {
     1107        /* nothing special */
     1108    }
     1109    else
     1110    {
     1111        /* For locations represented by file paths, append the default path if
     1112         * only a name is given, and then get the full path. */
     1113        if (!RTPathHavePath (location))
     1114        {
     1115            AutoLock propsLock (mData.mSystemProperties);
     1116            location = Utf8StrFmt ("%ls%c%s",
     1117                                   mData.mSystemProperties->defaultVDIFolder().raw(),
     1118                                   RTPATH_DELIMITER,
     1119                                   location.raw());
     1120        }
     1121
     1122        /* get the full file name */
     1123        char buf [RTPATH_MAX];
     1124        int vrc = RTPathAbsEx (mData.mHomeDir, location, buf, sizeof (buf));
     1125        if (VBOX_FAILURE (vrc))
     1126            return setError (E_FAIL, tr ("Invalid hard disk location '%ls' (%Vrc)"),
     1127                             aLocation, vrc);
     1128        location = buf;
     1129    }
     1130
     1131    ComObjPtr <HardDisk> hardDisk;
     1132    HRESULT rc = findHardDisk (NULL, Bstr (location), true /* setError */,
     1133                               &hardDisk);
     1134
     1135    /* the below will set *aHardDisk to NULL if hardDisk is null */
     1136    hardDisk.queryInterfaceTo (aHardDisk);
    10881137
    10891138    return rc;
     
    11461195    Guid id = aId;
    11471196    ComObjPtr <HardDisk> hd;
    1148     HRESULT rc = findHardDisk (id, true /* setError */, &hd);
     1197    HRESULT rc = findHardDisk (&id, NULL, true /* setError */, &hd);
    11491198    CheckComRCReturnRC (rc);
    11501199
     
    29623011}
    29633012
    2964 /** @note Locks this object for reading. */
    2965 HRESULT VirtualBox::findHardDisk (const Guid &aId, bool aSetError,
    2966                                   ComObjPtr <HardDisk> *aHardDisk /* = NULL */)
    2967 {
    2968     AutoCaller autoCaller (this);
    2969     AssertComRCReturn (autoCaller.rc(), autoCaller.rc());
     3013/**
     3014 *  Searches for a HardDisk object with the given ID or location specification
     3015 *  in the collection of registered hard disks. If both ID and location are
     3016 *  specified, the first object that matches either of them (not necessarily
     3017 *  both) is returned.
     3018 *
     3019 *  @param aId          ID of the hard disk (NULL when unused)
     3020 *  @param aLocation    full location specification (NULL when unused)
     3021 *  @param aSetError    if TRUE, the appropriate error info is set in case when
     3022 *                      the disk is not found and only one search criteria (ID
     3023 *                      or file name) is specified.
     3024 *  @param aHardDisk    where to store the found hard disk object (can be NULL)
     3025 *
     3026 *  @return
     3027 *      S_OK when found or E_INVALIDARG when not found
     3028 *
     3029 *  @note Locks objects for reading!
     3030 */
     3031HRESULT VirtualBox::
     3032findHardDisk (const Guid *aId, const BSTR aLocation,
     3033              bool aSetError, ComObjPtr <HardDisk> *aHardDisk /* = NULL */)
     3034{
     3035    ComAssertRet (aId || aLocation, E_INVALIDARG);
    29703036
    29713037    AutoReaderLock alock (this);
    29723038
    2973     HardDiskMap::const_iterator it = mData.mHardDiskMap.find (aId);
    2974 
    2975     if (it != mData.mHardDiskMap.end())
    2976     {
    2977         if (aHardDisk)
    2978             *aHardDisk = (*it).second;
    2979         return S_OK;
    2980     }
    2981 
    2982     if (aSetError)
    2983     {
    2984         setError (E_INVALIDARG,
    2985             tr ("Could not find a registered hard disk with UUID {%Vuuid}"),
    2986             aId.raw());
    2987     }
    2988 
    2989     return E_INVALIDARG;
    2990 }
    2991 
    2992 /**
     3039    /* first lookup the map by UUID if UUID is provided */
     3040    if (aId)
     3041    {
     3042        HardDiskMap::const_iterator it = mData.mHardDiskMap.find (*aId);
     3043        if (it != mData.mHardDiskMap.end())
     3044        {
     3045            if (aHardDisk)
     3046                *aHardDisk = (*it).second;
     3047            return S_OK;
     3048        }
     3049    }
     3050
     3051    /* then iterate and find by location */
     3052    bool found = false;
     3053    if (aLocation)
     3054    {
     3055        Utf8Str location = aLocation;
     3056
     3057        for (HardDiskMap::const_iterator it = mData.mHardDiskMap.begin();
     3058             !found && it != mData.mHardDiskMap.end();
     3059             ++ it)
     3060        {
     3061            const ComObjPtr <HardDisk> &hd = (*it).second;
     3062            AutoReaderLock hdLock (hd);
     3063
     3064            if (hd->storageType() == HardDiskStorageType_VirtualDiskImage ||
     3065                hd->storageType() == HardDiskStorageType_VMDKImage)
     3066            {
     3067                /* locations of VDI and VMDK hard disks for now are just
     3068                 * file paths */
     3069                found = RTPathCompare (location,
     3070                                       Utf8Str (hd->toString
     3071                                                (false /* aShort */))) == 0;
     3072            }
     3073            else
     3074            {
     3075                found = aLocation == hd->toString (false /* aShort */);
     3076            }
     3077
     3078            if (found && aHardDisk)
     3079                *aHardDisk = hd;
     3080        }
     3081    }
     3082
     3083    HRESULT rc = found ? S_OK : E_INVALIDARG;
     3084
     3085    if (aSetError && !found)
     3086    {
     3087        if (aId && !aLocation)
     3088            setError (rc, tr ("Could not find a registered hard disk "
     3089                              "with UUID {%Vuuid}"), aId->raw());
     3090        else if (aLocation && !aId)
     3091            setError (rc, tr ("Could not find a registered hard disk "
     3092                              "with location '%ls'"), aLocation);
     3093    }
     3094
     3095    return rc;
     3096}
     3097
     3098/**
     3099 *  @deprecated Use #findHardDisk() instead.
     3100 *
    29933101 *  Searches for a HVirtualDiskImage object with the given ID or file path in the
    29943102 *  collection of registered hard disks. If both ID and file path are specified,
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r1721 r2029  
    617617    <interface
    618618        name="IVirtualBox" extends="$dispatched"
    619         uuid="00f4e8eb-d737-4c88-9ccb-b434edf8b912"
     619        uuid="ce54ff3d-0e46-41ae-a0de-202ed0c3c668"
    620620    >
    621621      <desc> The main interface exposed by the product that provides virtual
     
    969969                until <link to="#registerHardDisk()"/> is called.
    970970
     971                @deprecated Use <link to="#openHardDisk()"/> instead.
     972
    971973                <note>Opening differencing images is not supported.</note>
    972974
     
    10161018        </method>
    10171019
     1020        <method name="findHardDisk">
     1021            <desc>
     1022
     1023                Returns a registered hard disk that uses the given location to
     1024                store data. The search is done by comparing the
     1025                value of the @a location argument to the
     1026                <link to="IHardDisk::location"/> attribute of each registered
     1027                hard disk.
     1028
     1029                For locations repesented by file paths (such as VDI and VMDK
     1030                images), the specified location can be either an absolute file
     1031                path or a path relative to
     1032                the <link to="IVirtualBox::homeFolder"> VirtualBox home
     1033                directory</link>. If only a file name without any path is
     1034                given, the <link to="ISystemProperties::defaultVDIFolder">
     1035                default VDI folder</link> will be used as a path to construct
     1036                the absolute image file name to search for. Note that on host
     1037                systems with case sensitive filesystems, a case sensitive
     1038                comparison is performed, otherwise the case of symbols in the
     1039                file path is ignored.
     1040
     1041            </desc>
     1042            <param name="location" type="wstring" dir="in">
     1043                <desc>Hard disk location specification to search for.</desc>
     1044            </param>
     1045            <param name="hardDisk" type="IHardDisk" dir="return">
     1046                <desc>Found hard disk object.</desc>
     1047            </param>
     1048        </method>
     1049
    10181050        <method name="findVirtualDiskImage">
    10191051            <desc>
    10201052
    10211053                Returns a registered hard disk that uses the given image file.
     1054
     1055                @deprecated Use <link to="#findHardDisk()"/> instead.
    10221056
    10231057                <note>The specified file path can be absolute (full path) or
  • trunk/src/VBox/Main/include/VirtualBoxImpl.h

    r953 r2029  
    141141    STDMETHOD(OpenVirtualDiskImage) (INPTR BSTR aFilePath, IVirtualDiskImage **aImage);
    142142    STDMETHOD(RegisterHardDisk) (IHardDisk *aHardDisk);
    143     STDMETHOD(GetHardDisk) (INPTR GUIDPARAM id, IHardDisk **hardDisk);
     143    STDMETHOD(GetHardDisk) (INPTR GUIDPARAM aId, IHardDisk **aHardDisk);
     144    STDMETHOD(FindHardDisk) (INPTR BSTR aLocation, IHardDisk **aHardDisk);
    144145    STDMETHOD(FindVirtualDiskImage) (INPTR BSTR aFilePath, IVirtualDiskImage **aImage);
    145146    STDMETHOD(UnregisterHardDisk) (INPTR GUIDPARAM aId, IHardDisk **aHardDisk);
     
    229230    HRESULT getHardDisk (const Guid &aId, ComObjPtr <HardDisk> &aHardDisk)
    230231    {
    231         return findHardDisk (aId, true /* aDoSetError */, &aHardDisk);
     232        return findHardDisk (&aId, NULL, true /* aDoSetError */, &aHardDisk);
    232233    }
    233234
     
    274275                         ComObjPtr <Machine> *machine = NULL);
    275276
    276     HRESULT findHardDisk (const Guid &aId, bool aSetError,
    277                           ComObjPtr <HardDisk> *aHardDisk = NULL);
     277    HRESULT findHardDisk (const Guid *aId, const BSTR aLocation,
     278                          bool aSetError, ComObjPtr <HardDisk> *aHardDisk = NULL);
    278279
    279280    HRESULT findVirtualDiskImage (const Guid *aId, const BSTR aFilePathFull,
  • trunk/src/VBox/Main/testcase/tstAPI.cpp

    r1471 r2029  
    448448            vdi->COMGETTER(FilePath) (dst.asOutParam());
    449449            RTPrintf ("Actual clone path is '%ls'\n", dst.raw());
     450        }
     451    }
     452    while (FALSE);
     453    printf ("\n");
     454#endif
     455
     456#if 1
     457    // find a registered hard disk by location
     458    ///////////////////////////////////////////////////////////////////////////
     459    do
     460    {
     461        ComPtr <IHardDisk> hd;
     462        static wchar_t *Names[] =
     463        {
     464#ifndef __LINUX__
     465            L"E:/Develop/innotek/images/thinker/freedos.vdi",
     466            L"E:/Develop/innotek/images/thinker/fReeDoS.vDI",
     467            L"E:/Develop/innotek/images/vmdk/haiku.vmdk",
     468#else
     469            L"/mnt/host/common/Develop/innotek/images/maggot/freedos.vdi",
     470            L"/mnt/host/common/Develop/innotek/images/maggot/fReeDoS.vDI",
     471#endif
     472        };
     473        for (size_t i = 0; i < ELEMENTS (Names); ++ i)
     474        {
     475            Bstr src = Names [i];
     476            printf ("Searching for hard disk '%ls'...\n", src.raw());
     477            rc = virtualBox->FindHardDisk (src, hd.asOutParam());
     478            if (SUCCEEDED (rc))
     479            {
     480                Guid id;
     481                Bstr location;
     482                CHECK_ERROR_BREAK (hd, COMGETTER(Id) (id.asOutParam()));
     483                CHECK_ERROR_BREAK (hd, COMGETTER(Location) (location.asOutParam()));
     484                printf ("Found, UUID={%Vuuid}, location='%ls'.\n",
     485                        id.raw(), location.raw());
     486            }
     487            else
     488            {
     489                PRINT_ERROR_INFO (com::ErrorInfo (virtualBox));
     490            }
    450491        }
    451492    }
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