VirtualBox

Changeset 14783 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Nov 28, 2008 2:55:59 PM (16 years ago)
Author:
vboxsync
Message:

Main: Treat hard disks with no Create capabilities as Created right after IVirtualBox::createHardDisk2() and don't allow IHardDisk2::create*Storage()/deleteStorage() for them.

Location:
trunk/src/VBox/Main
Files:
5 edited

Legend:

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

    r14772 r14783  
    438438    mm.vdIfCallsProgress.enmInterface = VDINTERFACETYPE_PROGRESS;
    439439    mm.vdIfCallsProgress.pfnProgress = vdProgressCall;
     440
     441    /* Initialize the callbacks of the VD config interface */
     442    mm.vdIfCallsConfig.cbSize = sizeof (VDINTERFACEPROGRESS);
     443    mm.vdIfCallsConfig.enmInterface = VDINTERFACETYPE_CONFIG;
     444/// @todo later
     445//  mm.vdIfCallsConfig.pfnAreValuesValid = ...;
     446//  mm.vdIfCallsConfig.pfnQueryBytes = ...;
    440447
    441448    /* Initialize the per-disk interface chain */
     
    467474 * storage unit.
    468475 *
     476 * For hard disks that don't have the VD_CAP_CREATE_FIXED or
     477 * VD_CAP_CREATE_DYNAMIC capability (and therefore cannot be created or deleted
     478 * with the means of VirtualBox) the associated storage unit is assumed to be
     479 * ready for use so the state of the hard disk object will be set to Created.
     480 *
    469481 * @param aVirtualBox   VirtualBox object.
    470482 * @param aLocaiton     Storage unit location.
     
    473485                         const BSTR aLocation)
    474486{
    475     AssertReturn (aVirtualBox != NULL, E_INVALIDARG);
    476     AssertReturn (aLocation != NULL, E_INVALIDARG);
    477     AssertReturn (aFormat != NULL && *aFormat != '\0', E_INVALIDARG);
     487    AssertReturn (aVirtualBox != NULL, E_FAIL);
     488    AssertReturn (aFormat != NULL && *aFormat != '\0', E_FAIL);
    478489
    479490    /* Enclose the state transition NotReady->InInit->Ready */
     
    498509    CheckComRCReturnRC (rc);
    499510
    500     rc = setLocation (aLocation);
    501     CheckComRCReturnRC (rc);
     511    if (mm.formatObj->capabilities() & HardDiskFormatCapabilities_File)
     512    {
     513        rc = setLocation (aLocation);
     514        CheckComRCReturnRC (rc);
     515    }
     516    else
     517    {
     518        rc = setLocation (aLocation);
     519        CheckComRCReturnRC (rc);
     520
     521        /// @todo later we may want to use a pfnComposeLocation backend info
     522        /// callback to generate a well-formed location value (based on the hard
     523        /// disk properties we have) rather than allowing each caller to invent
     524        /// its own (pseudo-)location.
     525    }
     526
     527    if (!(mm.formatObj->capabilities() &
     528          (HardDiskFormatCapabilities_CreateFixed |
     529           HardDiskFormatCapabilities_CreateDynamic)))
     530    {
     531        /* storage for hard disks of this format can neither be explicitly
     532         * created by VirtualBox nor deleted, so we place the hard disk to
     533         * Created state here and also add it to the registry */
     534        m.state = MediaState_Created;
     535        unconst (m.id).create();
     536        rc = mVirtualBox->registerHardDisk2 (this);
     537
     538        /// @todo later we may want to use a pfnIsConfigSufficient backend info
     539        /// callback that would tell us when we have enough properties to work
     540        /// with the hard disk and this information could be used to actually
     541        /// move such hard disks from NotCreated to Created state. Instead of
     542        /// pfnIsConfigSufficient we can use HardDiskFormat property
     543        /// descriptions to see which properties are mandatory
     544    }
    502545
    503546    /* Confirm a successful initialization when it's the case */
     
    626669    CheckComRCReturnRC (rc);
    627670
    628     /* properties (note: after setting the format as it populates the map) */
     671    /* properties (after setting the format as it populates the map). Note that
     672     * if some properties are not supported but preseint in the settings file,
     673     * they will still be read and accessible (for possible backward
     674     * compatibility; we can also clean them up from the XML upon next
     675     * XML format versino change if we wish) */
    629676    Key::List properties = aNode.keys ("Property");
    630677    for (Key::List::const_iterator it = properties.begin();
     
    10241071    AutoWriteLock alock (this);
    10251072
     1073    if (!(mm.formatObj->capabilities() &
     1074          HardDiskFormatCapabilities_CreateDynamic))
     1075        return setError (VBOX_E_NOT_SUPPORTED,
     1076            tr ("Hard disk format '%ls' does not support dynamic storage "
     1077                "creation"), mm.format.raw());
     1078
    10261079    switch (m.state)
    10271080    {
     
    10311084            return setStateError();
    10321085    }
    1033 
    1034     /// @todo NEWMEDIA use backend capabilities to decide if dynamic storage
    1035     /// is supported
    10361086
    10371087    ComObjPtr <Progress> progress;
     
    10761126
    10771127    AutoWriteLock alock (this);
     1128
     1129    if (!(mm.formatObj->capabilities() &
     1130          HardDiskFormatCapabilities_CreateFixed))
     1131        return setError (VBOX_E_NOT_SUPPORTED,
     1132            tr ("Hard disk format '%ls' does not support fixed storage "
     1133                "creation"), mm.format.raw());
    10781134
    10791135    switch (m.state)
     
    14691525    return name;
    14701526}
    1471 
    1472 /// @todo NEWMEDIA remove, should not need anymore
    1473 #if 0
    1474 
    1475 /**
    1476  * Returns @c true if the given location is a file in the host's filesystem.
    1477  *
    1478  * @param aLocation     Location to check.
    1479  */
    1480 /*static*/
    1481 bool HardDisk2::isFileLocation (const char *aLocation)
    1482 {
    1483     /// @todo NEWMEDIA need some library that deals with URLs in a generic way
    1484 
    1485     if (aLocation == NULL)
    1486         return false;
    1487 
    1488     size_t len = strlen (aLocation);
    1489 
    1490     /* unix-like paths */
    1491     if (len >= 1 && RTPATH_IS_SLASH (aLocation [0]))
    1492         return true;
    1493 
    1494     /* dos-like paths */
    1495     if (len >= 2 && RTPATH_IS_VOLSEP (aLocation [1]) &&
    1496         ((aLocation [0] >= 'A' && aLocation [0] <= 'Z') ||
    1497          (aLocation [0] >= 'a' && aLocation [0] <= 'z')))
    1498         return true;
    1499 
    1500     /* if there is a '<protocol>:' suffux which is not 'file:', return false */
    1501     const char *s = strchr (aLocation, ':');
    1502     if (s != NULL)
    1503     {
    1504         if (s - aLocation != 4)
    1505             return false;
    1506         if ((aLocation [0] != 'f' && aLocation [0] == 'F') ||
    1507             (aLocation [1] != 'i' && aLocation [1] == 'I') ||
    1508             (aLocation [2] != 'l' && aLocation [2] == 'L') ||
    1509             (aLocation [3] != 'e' && aLocation [3] == 'E'))
    1510             return false;
    1511     }
    1512 
    1513     /* everything else is treaten as file */
    1514     return true;
    1515 }
    1516 
    1517 #endif /* if 0 */
    15181527
    15191528/**
     
    18351844
    18361845    AutoWriteLock alock (this);
     1846
     1847    if (!(mm.formatObj->capabilities() &
     1848          (HardDiskFormatCapabilities_CreateDynamic |
     1849           HardDiskFormatCapabilities_CreateFixed)))
     1850        return setError (VBOX_E_NOT_SUPPORTED,
     1851            tr ("Hard disk format '%ls' does not support storage deletion "),
     1852            mm.format.raw());
    18371853
    18381854    switch (m.state)
     
    23532369HRESULT HardDisk2::setLocation (const BSTR aLocation)
    23542370{
    2355     if (aLocation == NULL)
    2356         return E_INVALIDARG;
     2371    /// @todo so far, we assert but later it makes sense to support null
     2372    /// locations for hard disks that are not yet created fail to create a
     2373    /// storage unit instead
     2374    CheckComArgStrNotEmptyOrNull (aLocation);
    23572375
    23582376    AutoCaller autoCaller (this);
     
    25042522            = mVirtualBox->systemProperties()->hardDiskFormat (aFormat);
    25052523        if (mm.formatObj.isNull())
    2506             return setError (E_FAIL,
     2524            return setError (VBOX_E_OBJECT_NOT_FOUND,
    25072525                tr ("Invalid hard disk storage format '%ls'"), aFormat);
    25082526
  • trunk/src/VBox/Main/VirtualBoxImpl.cpp

    r14772 r14783  
    10871087                                          IHardDisk2 **aHardDisk)
    10881088{
    1089     if (!aFormat)
    1090         return E_INVALIDARG;
    1091     if (!aLocation)
    1092         return E_INVALIDARG;
    1093     if (!aHardDisk)
    1094         return E_POINTER;
     1089    CheckComArgStrNotEmptyOrNull (aFormat);
     1090    CheckComArgOutPointerValid (aHardDisk);
    10951091
    10961092    AutoCaller autoCaller (this);
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r14778 r14783  
    316316  </result>
    317317
     318  <result name="VBOX_E_NOT_SUPPORTED" value="0x80BB0009">
     319    <desc>
     320       Requested operation is not supported.
     321    </desc>
     322  </result>
     323
    318324  <!--
    319325    Note that src/VBox/Runtime/common/err/errmsgvboxcom.xsl will ignore
     
    16021608        See <link to="IMedium::location"/>, IHardDisk2 and
    16031609        <link to="ISystemProperties::defaultHardDiskFolder"/> for more details.
     1610
     1611        <result name="VBOX_E_OBJECT_NOT_FOUND">
     1612          @a format identifier is invalid. See
     1613          <link to="ISystemProperties::hardDiskFormats"/>.
     1614        </result>
     1615        <result name="VBOX_E_FILE_ERROR">
     1616          @a location is a not valid file name (for file-based formats only).
     1617        </result>
     1618        <result name="E_INVALIDARG">
     1619          @a format is a null or empty string.
     1620        </result>
    16041621      </desc>
    16051622      <param name="format" type="wstring" dir="in">
     
    73897406        to="MediaState::Created"/>, the hard disk will be remembered by this
    73907407        VirtualBox installation and may be attached to virtual machines.
     7408
     7409        <result name="VBOX_E_NOT_SUPPORTED">
     7410          Dynamic storage creation operation is not supported. See <link
     7411          to="IHardDiskFormat::capabilities"/>.
     7412        </result>
    73917413      </desc>
    73927414      <param name="logicalSize" type="unsigned long long" dir="in">
     
    74147436        to="MediaState::Created"/>, the hard disk will be remembered by this
    74157437        VirtualBox installation and may be attached to virtual machines.
     7438
     7439        <result name="VBOX_E_NOT_SUPPORTED">
     7440          Fixed storage creation operation is not supported. See
     7441          <link to="IHardDiskFormat::capabilities"/>.
     7442        </result>
    74167443      </desc>
    74177444      <param name="logicalSize" type="unsigned long long" dir="in">
     
    74497476        <result name="VBOX_E_OBJECT_IN_USE">
    74507477          Hard disk is attached to a virtual machine.
     7478        </result>
     7479        <result name="VBOX_E_NOT_SUPPORTED">
     7480          Storage deletion is not allowed because neither of storage creation
     7481          operations are supported. See
     7482          <link to="IHardDiskFormat::capabilities"/>.
    74517483        </result>
    74527484      </desc>
  • trunk/src/VBox/Main/include/HardDisk2Impl.h

    r14628 r14783  
    285285        VDINTERFACEPROGRESS vdIfCallsProgress;
    286286
     287        VDINTERFACE vdIfConfig;
     288        VDINTERFACECONFIG vdIfCallsConfig;
     289
    287290        PVDINTERFACE vdDiskIfaces;
    288291    };
  • trunk/src/VBox/Main/testcase/tstAPI.cpp

    r14698 r14783  
    641641                    printf (" <none>\n");
    642642
     643#if 0
    643644                Bstr name ("TargetAddress");
    644645                Bstr value = Utf8StrFmt ("lalala (%llu)", RTTimeMilliTS());
     
    646647                printf ("Settings property %ls to %ls...\n", name.raw(), value.raw());
    647648                CHECK_ERROR (hd, SetProperty (name, value));
     649#endif
    648650            }
    649651            else
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