VirtualBox

Changeset 14929 in vbox for trunk/src


Ignore:
Timestamp:
Dec 2, 2008 10:29:29 PM (16 years ago)
Author:
vboxsync
Message:

Main: Pass custom hard disk parameters to the backend.

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

Legend:

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

    r14866 r14929  
    3737#include <iprt/path.h>
    3838#include <iprt/file.h>
     39#include <iprt/tcp.h>
    3940
    4041#include <list>
     
    440441
    441442    /* Initialize the callbacks of the VD config interface */
    442     mm.vdIfCallsConfig.cbSize = sizeof (VDINTERFACEPROGRESS);
     443    mm.vdIfCallsConfig.cbSize = sizeof (VDINTERFACECONFIG);
    443444    mm.vdIfCallsConfig.enmInterface = VDINTERFACETYPE_CONFIG;
    444 /// @todo later
    445 //  mm.vdIfCallsConfig.pfnAreValuesValid = ...;
    446 //  mm.vdIfCallsConfig.pfnQueryBytes = ...;
     445    mm.vdIfCallsConfig.pfnAreKeysValid = vdConfigAreKeysValid;
     446    mm.vdIfCallsConfig.pfnQuerySize = vdConfigQuerySize;
     447    mm.vdIfCallsConfig.pfnQuery = vdConfigQuery;
     448
     449    /* Initialize the callbacks of the VD TCP interface (we always use the host
     450     * IP stack for now) */
     451    mm.vdIfCallsTcpNet.cbSize = sizeof (VDINTERFACETCPNET);
     452    mm.vdIfCallsTcpNet.enmInterface = VDINTERFACETYPE_TCPNET;
     453    mm.vdIfCallsTcpNet.pfnClientConnect = RTTcpClientConnect;
     454    mm.vdIfCallsTcpNet.pfnClientClose = RTTcpClientClose;
     455    mm.vdIfCallsTcpNet.pfnSelectOne = RTTcpSelectOne;
     456    mm.vdIfCallsTcpNet.pfnRead = RTTcpRead;
     457    mm.vdIfCallsTcpNet.pfnWrite = RTTcpWrite;
     458    mm.vdIfCallsTcpNet.pfnFlush = RTTcpFlush;
    447459
    448460    /* Initialize the per-disk interface chain */
     
    453465                          &mm.vdIfCallsError, this, &mm.vdDiskIfaces);
    454466    AssertRCReturn (vrc, E_FAIL);
     467
    455468    vrc = VDInterfaceAdd (&mm.vdIfProgress,
    456469                          "HardDisk2::vdInterfaceProgress",
    457470                          VDINTERFACETYPE_PROGRESS,
    458471                          &mm.vdIfCallsProgress, this, &mm.vdDiskIfaces);
     472    AssertRCReturn (vrc, E_FAIL);
     473
     474    vrc = VDInterfaceAdd (&mm.vdIfConfig,
     475                          "HardDisk2::vdInterfaceConfig",
     476                          VDINTERFACETYPE_CONFIG,
     477                          &mm.vdIfCallsConfig, this, &mm.vdDiskIfaces);
     478    AssertRCReturn (vrc, E_FAIL);
     479
     480    vrc = VDInterfaceAdd (&mm.vdIfTcpNet,
     481                          "HardDisk2::vdInterfaceTcpNet",
     482                          VDINTERFACETYPE_TCPNET,
     483                          &mm.vdIfCallsTcpNet, this, &mm.vdDiskIfaces);
    459484    AssertRCReturn (vrc, E_FAIL);
    460485
     
    26512676                flags |= VD_OPEN_FLAGS_READONLY;
    26522677
    2653             vrc = VDOpen (hdd, Utf8Str (mm.format), location, flags, NULL);
     2678            vrc = VDOpen (hdd, Utf8Str (mm.format), location, flags,
     2679                          mm.vdDiskIfaces);
    26542680            if (RT_FAILURE (vrc))
    26552681            {
     
    29302956        error = Utf8StrFmt (" (%Rrc)", aVRC);
    29312957    else
    2932         error = Utf8StrFmt (". %s (%Rrc)", mm.vdError.raw(), aVRC);
     2958        error = Utf8StrFmt (".\n%s", mm.vdError.raw());
    29332959
    29342960    mm.vdError.setNull();
     
    29582984    AssertReturnVoid (that != NULL);
    29592985
    2960     that->mm.vdError = Utf8StrFmtVA (pszFormat, va);
     2986    if (that->mm.vdError.isEmpty())
     2987        that->mm.vdError =
     2988            Utf8StrFmt ("%s (%Rrc)", Utf8StrFmtVA (pszFormat, va).raw(), rc);
     2989    else
     2990        that->mm.vdError =
     2991            Utf8StrFmt ("%s.\n%s (%Rrc)", that->mm.vdError.raw(),
     2992                        Utf8StrFmtVA (pszFormat, va).raw(), rc);
    29612993}
    29622994
     
    29803012        that->mm.vdProgress->notifyProgress (RT_MIN (uPercent, 99));
    29813013    }
     3014
     3015    return VINF_SUCCESS;
     3016}
     3017
     3018/* static */
     3019DECLCALLBACK(bool) HardDisk2::vdConfigAreKeysValid (void *pvUser,
     3020                                                    const char *pszzValid)
     3021{
     3022    HardDisk2 *that = static_cast <HardDisk2 *> (pvUser);
     3023    AssertReturn (that != NULL, VERR_GENERAL_FAILURE);
     3024
     3025    /* we always return true since the only keys we have are those found in
     3026     * VDBACKENDINFO */
     3027    return true;
     3028}
     3029
     3030/* static */
     3031DECLCALLBACK(int) HardDisk2::vdConfigQuerySize (void *pvUser, const char *pszName,
     3032                                                size_t *pcbValue)
     3033{
     3034    AssertReturn (VALID_PTR (pcbValue), VERR_INVALID_POINTER);
     3035
     3036    HardDisk2 *that = static_cast <HardDisk2 *> (pvUser);
     3037    AssertReturn (that != NULL, VERR_GENERAL_FAILURE);
     3038
     3039    Data::PropertyMap::const_iterator it =
     3040        that->mm.properties.find (Bstr (pszName));
     3041    if (it == that->mm.properties.end())
     3042        return VERR_CFGM_VALUE_NOT_FOUND;
     3043
     3044    /* we interpret null values as "no value" in HardDisk2 */
     3045    if (it->second.isNull())
     3046        return VERR_CFGM_VALUE_NOT_FOUND;
     3047
     3048    *pcbValue = it->second.length() + 1 /* include terminator */;
     3049
     3050    return VINF_SUCCESS;
     3051}
     3052
     3053/* static */
     3054DECLCALLBACK(int) HardDisk2::vdConfigQuery (void *pvUser, const char *pszName,
     3055                                            char *pszValue, size_t cchValue)
     3056{
     3057    AssertReturn (VALID_PTR (pszValue), VERR_INVALID_POINTER);
     3058
     3059    HardDisk2 *that = static_cast <HardDisk2 *> (pvUser);
     3060    AssertReturn (that != NULL, VERR_GENERAL_FAILURE);
     3061
     3062    Data::PropertyMap::const_iterator it =
     3063        that->mm.properties.find (Bstr (pszName));
     3064    if (it == that->mm.properties.end())
     3065        return VERR_CFGM_VALUE_NOT_FOUND;
     3066
     3067    Utf8Str value = it->second;
     3068    if (value.length() >= cchValue)
     3069        return VERR_CFGM_NOT_ENOUGH_SPACE;
     3070
     3071    /* we interpret null values as "no value" in HardDisk2 */
     3072    if (it->second.isNull())
     3073        return VERR_CFGM_VALUE_NOT_FOUND;
     3074
     3075    memcpy (pszValue, value, value.length());
    29823076
    29833077    return VINF_SUCCESS;
  • trunk/src/VBox/Main/include/HardDisk2Impl.h

    r14783 r14929  
    249249                                             void *pvUser);
    250250
     251    static DECLCALLBACK(bool) vdConfigAreKeysValid (void *pvUser,
     252                                                    const char *pszzValid);
     253    static DECLCALLBACK(int) vdConfigQuerySize (void *pvUser, const char *pszName,
     254                                                size_t *pcbValue);
     255    static DECLCALLBACK(int) vdConfigQuery (void *pvUser, const char *pszName,
     256                                            char *pszValue, size_t cchValue);
     257
    251258    static DECLCALLBACK(int) taskThread (RTTHREAD thread, void *pvUser);
    252259
     
    288295        VDINTERFACECONFIG vdIfCallsConfig;
    289296
     297        VDINTERFACE vdIfTcpNet;
     298        VDINTERFACETCPNET vdIfCallsTcpNet;
     299
    290300        PVDINTERFACE vdDiskIfaces;
    291301    };
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