VirtualBox

Changeset 77606 in vbox for trunk/src


Ignore:
Timestamp:
Mar 8, 2019 2:55:07 AM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
129234
Message:

Added AllocationBlockSize property to VDI backend, and ability to set properties with VBoxManage --property key=value

Location:
trunk/src/VBox
Files:
4 edited

Legend:

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

    r76553 r77606  
     1#include <signal.h>
    12/* $Id$ */
    23/** @file
     
    5051    MEDIUMCATEGORY_FLOPPY
    5152} MEDIUMCATEGORY;
    52 
    53 
    5453
    5554// funcs
     
    244243    { "--variant",      'm', RTGETOPT_REQ_STRING },
    245244    { "-variant",       'm', RTGETOPT_REQ_STRING },     // deprecated
     245    { "--property",     'p', RTGETOPT_REQ_STRING }
    246246};
    247247
     
    253253    const char *diffparent = NULL;
    254254    uint64_t size = 0;
     255    typedef struct MEDIUMPROPERTY_LIST {
     256        struct MEDIUMPROPERTY_LIST *next;
     257        char *key;
     258        char *value;
     259    } MEDIUMPROPERTY, *PMEDIUMPROPERTY;
     260    PMEDIUMPROPERTY pMediumProps = NULL;
    255261    enum {
    256262        CMD_NONE,
     
    312318                break;
    313319
     320            case 'p':   // --property
     321            {
     322                /* allocate property kvp, parse, and append to end of singly linked list */
     323# define PROP_MAXLEN 256
     324                PMEDIUMPROPERTY pNewProp = (PMEDIUMPROPERTY)RTMemAlloc(sizeof(MEDIUMPROPERTY));
     325                if (!pNewProp)
     326                    return errorArgument("Can't allocate memory for property '%s'", ValueUnion.psz);
     327                int cbKvp = RTStrNLen(ValueUnion.psz, PROP_MAXLEN);
     328                char *cp;
     329                for (cp = (char *)ValueUnion.psz; *cp != '=' && cp < ValueUnion.psz + cbKvp; cp++)
     330                    continue;
     331                if (cp < ValueUnion.psz + cbKvp)
     332                {
     333                    *cp = '\0';
     334                    pNewProp->next = NULL;
     335                    pNewProp->key = (char *)ValueUnion.psz;
     336                    pNewProp->value = cp + 1;
     337                }
     338                if (pMediumProps) {
     339                    PMEDIUMPROPERTY pProp;
     340                    for (pProp = pMediumProps; pProp->next; pProp = pProp->next)
     341                        continue;
     342                    pProp->next = pNewProp;
     343                }
     344                else
     345                    pMediumProps = pNewProp;
     346            }
    314347            case 'F':   // --static ("fixed"/"flat")
    315348            {
     
    441474        rc = E_INVALIDARG; /* cannot happen but make gcc happy */
    442475
     476
    443477    if (SUCCEEDED(rc) && pMedium)
    444478    {
     479        if (pMediumProps)
     480            for (PMEDIUMPROPERTY pProp = pMediumProps; pProp; pProp = pProp->next)
     481                CHECK_ERROR(pMedium, SetProperty(Bstr(pProp->key).raw(), Bstr(pProp->value).raw()));
     482        }
     483
    445484        ComPtr<IProgress> pProgress;
    446485        com::SafeArray<MediumVariant_T> l_variants(sizeof(MediumVariant_T)*8);
     
    461500            rc = showProgress(pProgress);
    462501            CHECK_PROGRESS_ERROR(pProgress, ("Failed to create medium"));
    463         }
    464502    }
    465503
     
    10001038            else if (cmd == CMD_DVD)
    10011039                rc = createMedium(a, strFormat.c_str(), pszDst, DeviceType_DVD,
    1002                                   AccessMode_ReadOnly, pDstMedium);
     1040                                  AccessMode_ReadOnly,  pDstMedium);
    10031041            else if (cmd == CMD_FLOPPY)
    10041042                rc = createMedium(a, strFormat.c_str(), pszDst, DeviceType_Floppy,
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp

    r77595 r77606  
    993993                     "                            [--variant Standard,Fixed,Split2G,Stream,ESX,\n"
    994994                     "                                       Formatted]\n"
     995                     "                            [[--property <name>=<value>] --property <name>=<value]...\n"
    995996                     "\n", SEP);
    996997
  • trunk/src/VBox/Main/src-server/MediumImpl.cpp

    r76592 r77606  
    24392439    switch (m->state)
    24402440    {
     2441        case MediumState_NotCreated:
    24412442        case MediumState_Created:
    24422443        case MediumState_Inaccessible:
  • trunk/src/VBox/Storage/VDI.cpp

    r76553 r77606  
    3939#define SET_ENDIAN_U32(conv, u32) (conv == VDIECONV_H2F ? RT_H2LE_U32(u32) : RT_LE2H_U32(u32))
    4040#define SET_ENDIAN_U64(conv, u64) (conv == VDIECONV_H2F ? RT_H2LE_U64(u64) : RT_LE2H_U64(u64))
     41
     42static const char *vdiAllocationBlockSize = "1048576";
     43
     44static const VDCONFIGINFO vdiConfigInfo[] = {
     45    { "AllocationBlockSize",            vdiAllocationBlockSize,           VDCFGVALUETYPE_INTEGER,      0 }
     46};
    4147
    4248
     
    178184}
    179185
     186
    180187/**
    181188 * Internal: Set the appropriate endianess on all the Blocks pointed.
     
    549556 */
    550557static int vdiSetupImageState(PVDIIMAGEDESC pImage, unsigned uImageFlags, const char *pszComment,
    551                               uint64_t cbSize, uint32_t cbDataAlign, PCVDGEOMETRY pPCHSGeometry,
     558                              uint64_t cbSize, uint32_t cbAllocationBlock, uint32_t cbDataAlign, PCVDGEOMETRY pPCHSGeometry,
    552559                              PCVDGEOMETRY pLCHSGeometry)
    553560{
     
    555562
    556563    vdiInitPreHeader(&pImage->PreHeader);
    557     vdiInitHeader(&pImage->Header, uImageFlags, pszComment, cbSize, VDI_IMAGE_DEFAULT_BLOCK_SIZE, 0,
     564    vdiInitHeader(&pImage->Header, uImageFlags, pszComment, cbSize, cbAllocationBlock, 0,
    558565                  cbDataAlign);
    559566    /* Save PCHS geometry. Not much work, and makes the flow of information
     
    696703    int rc = VINF_SUCCESS;
    697704    uint32_t cbDataAlign = VDI_DATA_ALIGN;
    698 
     705    uint32_t cbAllocationBlock = VDI_IMAGE_DEFAULT_BLOCK_SIZE;
    699706    AssertPtr(pPCHSGeometry);
    700707    AssertPtr(pLCHSGeometry);
     
    710717                       N_("VDI: comment is too long for '%s'"), pImage->pszFilename);
    711718
     719    PVDINTERFACECONFIG pImgCfg = VDIfConfigGet(pImage->pVDIfsImage);
     720    if (pImgCfg) {
     721        rc = VDCFGQueryU32Def(pImgCfg, "AllocationBlockSize", &cbAllocationBlock, VDI_IMAGE_DEFAULT_BLOCK_SIZE);
     722        if (RT_FAILURE(rc))
     723            rc = vdIfError(pImage->pIfError, rc, RT_SRC_POS,
     724                           N_("VDI: Getting AllocationBlockSize for '%s' failed (%Rrc)"), pImage->pszFilename, rc);
     725    }
     726
    712727    if (pIfCfg)
    713728    {
     
    720735    if (RT_SUCCESS(rc))
    721736    {
    722         rc = vdiSetupImageState(pImage, uImageFlags, pszComment, cbSize, cbDataAlign,
    723                                 pPCHSGeometry, pLCHSGeometry);
     737
     738        rc = vdiSetupImageState(pImage, uImageFlags, pszComment, cbSize,
     739                cbAllocationBlock, cbDataAlign, pPCHSGeometry, pLCHSGeometry);
    724740        if (RT_SUCCESS(rc))
    725741        {
     
    14841500        PVDINTERFACEPROGRESS pIfProgress = VDIfProgressGet(pVDIfsOperation);
    14851501        PVDINTERFACECONFIG pIfCfg = VDIfConfigGet(pVDIfsOperation);
    1486 
    14871502        pImage->pszFilename = pszFilename;
    14881503        pImage->pStorage = NULL;
     
    31323147    s_aVdiFileExtensions,
    31333148    /* paConfigInfo */
    3134     NULL,
     3149    vdiConfigInfo,
    31353150    /* pfnProbe */
    31363151    vdiProbe,
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette