VirtualBox

Changeset 38787 in vbox


Ignore:
Timestamp:
Sep 19, 2011 10:08:15 AM (13 years ago)
Author:
vboxsync
Message:

Frontends/VBoxManage: add support for explicitly creating diff images (feature for expert users only)

Location:
trunk/src/VBox/Frontends/VBoxManage
Files:
2 edited

Legend:

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

    r38735 r38787  
    245245    { "--filename",     'f', RTGETOPT_REQ_STRING },
    246246    { "-filename",      'f', RTGETOPT_REQ_STRING },     // deprecated
     247    { "--diffparent",   'd', RTGETOPT_REQ_STRING },
    247248    { "--size",         's', RTGETOPT_REQ_UINT64 },
    248249    { "-size",          's', RTGETOPT_REQ_UINT64 },     // deprecated
     
    261262    int vrc;
    262263    const char *filename = NULL;
     264    const char *diffparent = NULL;
    263265    uint64_t size = 0;
    264     const char *format = "VDI";
     266    const char *format = NULL;
     267    bool fBase = true;
    265268    MediumVariant_T DiskVariant = MediumVariant_Standard;
    266269
     
    277280            case 'f':   // --filename
    278281                filename = ValueUnion.psz;
     282                break;
     283
     284            case 'd':   // --diffparent
     285                diffparent = ValueUnion.psz;
     286                fBase = false;
    279287                break;
    280288
     
    326334
    327335    /* check the outcome */
    328     if (   !filename
    329         || !*filename
    330         || size == 0)
    331         return errorSyntax(USAGE_CREATEHD, "Parameters --filename and --size are required");
    332 
     336    bool fUnknownParent = false;
     337    ComPtr<IMedium> parentHardDisk;
     338    if (fBase)
     339    {
     340        if (   !filename
     341            || !*filename
     342            || size == 0)
     343            return errorSyntax(USAGE_CREATEHD, "Parameters --filename and --size are required");
     344        if (!format || !*format)
     345            format = "VDI";
     346    }
     347    else
     348    {
     349        if (   !filename
     350            || !*filename)
     351            return errorSyntax(USAGE_CREATEHD, "Parameters --filename is required");
     352        size = 0;
     353        DiskVariant = MediumVariant_Diff;
     354        if (!format || !*format)
     355        {
     356            const char *pszExt = RTPathExt(filename);
     357            /* Skip over . if there is an extension. */
     358            if (pszExt)
     359                pszExt++;
     360            if (!pszExt || !*pszExt)
     361                format = "VDI";
     362            else
     363                format = pszExt;
     364        }
     365        rc = findOrOpenMedium(a, diffparent, DeviceType_HardDisk,
     366                              parentHardDisk, false /* fForceNewUuidOnOpen */,
     367                              &fUnknownParent);
     368        if (FAILED(rc))
     369            return 1;
     370        if (parentHardDisk.isNull())
     371        {
     372            RTMsgError("Invalid parent hard disk reference, avoiding crash");
     373            return 1;
     374        }
     375        MediumState_T state;
     376        CHECK_ERROR(parentHardDisk, COMGETTER(State)(&state));
     377        if (FAILED(rc))
     378            return 1;
     379        if (state == MediumState_Inaccessible)
     380        {
     381            CHECK_ERROR(parentHardDisk, RefreshState(&state));
     382            if (FAILED(rc))
     383                return 1;
     384        }
     385    }
    333386    /* check for filename extension */
    334387    /** @todo use IMediumFormat to cover all extensions generically */
     
    351404    {
    352405        ComPtr<IProgress> progress;
    353         CHECK_ERROR(hardDisk, CreateBaseStorage(size, DiskVariant, progress.asOutParam()));
     406        if (fBase)
     407            CHECK_ERROR(hardDisk, CreateBaseStorage(size, DiskVariant, progress.asOutParam()));
     408        else
     409            CHECK_ERROR(parentHardDisk, CreateDiffStorage(hardDisk, DiskVariant, progress.asOutParam()));
    354410        if (SUCCEEDED(rc) && progress)
    355411        {
     
    363419            }
    364420        }
     421
    365422        CHECK_ERROR(hardDisk, Close());
     423        if (!fBase && fUnknownParent)
     424            CHECK_ERROR(parentHardDisk, Close());
    366425    }
    367426    return SUCCEEDED(rc) ? 0 : 1;
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp

    r38726 r38787  
    515515        RTStrmPrintf(pStrm,
    516516                     "VBoxManage createhd         --filename <filename>\n"
    517                      "                            --size <megabytes>|--sizebyte <bytes>\n"
     517                     "                            --diffparent <uuid>|<filename>\n"
     518                     "                            [--size <megabytes>|--sizebyte <bytes>]\n"
    518519                     "                            [--format VDI|VMDK|VHD] (default: VDI)\n"
    519520                     "                            [--variant Standard,Fixed,Split2G,Stream,ESX]\n"
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