VirtualBox

Changeset 23902 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Oct 20, 2009 2:32:19 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
53702
Message:

VBoxManage: changed storageattach behaviour to match the syntax diagram

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

Legend:

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

    r23802 r23902  
    20312031        { "closemedium",      handleCloseMedium },
    20322032        { "unregisterimage",  handleCloseMedium }, /* backward compatiblity */
    2033         { "attachdisk",       handleAttachDisk },
     2033        { "storageattach",    handleStorageAttach },
    20342034        { "storagectl",       handleStorageController },
    20352035        { "showhdinfo",       handleShowHardDiskInfo },
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManage.h

    r23882 r23902  
    9292#define USAGE_DHCPSERVER            RT_BIT_64(47)
    9393#define USAGE_DUMPHDINFO            RT_BIT_64(48)
    94 #define USAGE_ATTACHDISK            RT_BIT_64(49)
     94#define USAGE_STORAGEATTACH         RT_BIT_64(49)
    9595#define USAGE_STORAGECONTROLLER     RT_BIT_64(50)
    9696#define USAGE_ALL                   (~(uint64_t)0)
     
    197197
    198198/* VBoxManageStorageController.cpp */
    199 int handleAttachDisk(HandlerArg *a);
     199int handleStorageAttach(HandlerArg *a);
    200200int handleStorageController(HandlerArg *a);
    201201
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp

    r23882 r23902  
    349349    }
    350350
    351     if (u64Cmd & USAGE_ATTACHDISK)
    352     {
    353         RTPrintf("VBoxManage attachdisk       <uuid|vmname>\n"
    354                  "                            --type <dvd|hdd|fdd>\n"
    355                  "                            --file <null|none|uuid|filename|host:<drive>>\n"
    356                  "                            --controller <name>\n"
     351    if (u64Cmd & USAGE_STORAGEATTACH)
     352    {
     353        RTPrintf("VBoxManage storageattach    <uuid|vmname>\n"
     354                 "                            --storagectl <name>\n"
    357355                 "                            --port <number>\n"
    358356                 "                            --device <number>\n"
     357                 "                            [--type <dvddrive|hdd|fdd>\n"
     358                 "                             --medium <none|emptydrive|uuid|filename|host:<drive>>]\n"
     359                 "                            [--passthrough <on|off>]\n"
    359360                 "\n");
    360361    }
     
    366367                 "                            [--add <ide/sata/scsi/floppy>]\n"
    367368                 "                            [--controller <LsiLogic/BusLogic/IntelAhci/PIIX3/PIIX4/ICH6/I82078>]\n"
    368                  "                            [--passthrough <on|off> --port <number> --device <number>]\n"
    369369                 "                            [--sataideemulation<1-4> <1-30>]\n"
    370370                 "                            [--sataportcount <1-30>]\n"
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageStorageController.cpp

    r23809 r23902  
    4747
    4848
    49 static const RTGETOPTDEF g_aAttachDiskOptions[] =
     49static const RTGETOPTDEF g_aStorageAttachOptions[] =
    5050{
    51     { "--type",           't', RTGETOPT_REQ_STRING },
    52     { "--file",           'f', RTGETOPT_REQ_STRING },
    53     { "--controller",     'c', RTGETOPT_REQ_STRING },
     51    { "--storagectl",     's', RTGETOPT_REQ_STRING },
    5452    { "--port",           'p', RTGETOPT_REQ_UINT32 },
    5553    { "--device",         'd', RTGETOPT_REQ_UINT32 },
     54    { "--medium",         'm', RTGETOPT_REQ_STRING },
     55    { "--type",           't', RTGETOPT_REQ_STRING },
     56    { "--passthrough",    'h', RTGETOPT_REQ_STRING },
    5657};
    5758
    58 int handleAttachDisk(HandlerArg *a)
     59int handleStorageAttach(HandlerArg *a)
    5960{
    6061    int c;
    6162    HRESULT rc = S_OK;
    62     ULONG port   = 0;
    63     ULONG device = 0;
     63    ULONG port   = ~0U;
     64    ULONG device = ~0U;
    6465    bool fRunTime = false;
    6566    const char *pszCtl  = NULL;
    6667    const char *pszType = NULL;
    67     const char *pszFile = NULL;
     68    const char *pszMedium = NULL;
     69    const char *pszPassThrough = NULL;
    6870    Bstr machineuuid (a->argv[0]);
    6971    RTGETOPTUNION ValueUnion;
     
    7274    ComPtr<IStorageController> storageCtl;
    7375
    74     if (a->argc < 11)
    75         return errorSyntax(USAGE_ATTACHDISK, "Too few parameters");
    76     else if (a->argc > 11)
    77         return errorSyntax(USAGE_ATTACHDISK, "Too many parameters");
    78 
    79     RTGetOptInit (&GetState, a->argc, a->argv, g_aAttachDiskOptions,
    80                   RT_ELEMENTS(g_aAttachDiskOptions), 1, 0 /* fFlags */);
     76    if (a->argc < 9)
     77        return errorSyntax(USAGE_STORAGEATTACH, "Too few parameters");
     78    else if (a->argc > 13)
     79        return errorSyntax(USAGE_STORAGEATTACH, "Too many parameters");
     80
     81    RTGetOptInit (&GetState, a->argc, a->argv, g_aStorageAttachOptions,
     82                  RT_ELEMENTS(g_aStorageAttachOptions), 1, 0 /* fFlags */);
    8183
    8284    while (   SUCCEEDED(rc)
     
    8587        switch (c)
    8688        {
    87             case 't':   // type <dvd|hdd|fdd>
     89            case 's':   // storage controller name
     90            {
     91                if (ValueUnion.psz)
     92                    pszCtl = ValueUnion.psz;
     93                else
     94                    rc = E_FAIL;
     95                break;
     96            }
     97
     98            case 'p':   // port
     99            {
     100                port = ValueUnion.u32;
     101                break;
     102            }
     103
     104            case 'd':   // device
     105            {
     106                device = ValueUnion.u32;
     107                break;
     108            }
     109
     110            case 'm':   // medium <none|emptydrive|uuid|filename|host:<drive>>
     111            {
     112                if (ValueUnion.psz)
     113                    pszMedium = ValueUnion.psz;
     114                else
     115                    rc = E_FAIL;
     116                break;
     117            }
     118
     119            case 't':   // type <dvddrive|hdd|fdd>
    88120            {
    89121                if (ValueUnion.psz)
     
    94126            }
    95127
    96             case 'f':   // file <none|uuid|filename|host:<drive>>
     128            case 'h':   // passthrough <on|off>
    97129            {
    98130                if (ValueUnion.psz)
    99                     pszFile = ValueUnion.psz;
    100                 else
    101                     rc = E_FAIL;
    102                 break;
    103             }
    104 
    105             case 'c':   // controller name
    106             {
    107                 if (ValueUnion.psz)
    108                     pszCtl = ValueUnion.psz;
    109                 else
    110                     rc = E_FAIL;
    111                 break;
    112             }
    113 
    114             case 'p':   // port
    115             {
    116                 port = ValueUnion.u32;
    117                 break;
    118             }
    119 
    120             case 'd':   // device
    121             {
    122                 device = ValueUnion.u32;
     131                    pszPassThrough = ValueUnion.psz;
     132                else
     133                    rc = E_FAIL;
    123134                break;
    124135            }
     
    126137            default:
    127138            {
    128                 errorGetOpt(USAGE_ATTACHDISK, c, &ValueUnion);
     139                errorGetOpt(USAGE_STORAGEATTACH, c, &ValueUnion);
    129140                rc = E_FAIL;
    130141                break;
     
    133144    }
    134145
    135     if (FAILED(rc))
    136         return 1;
    137 
    138     if (   fRunTime
    139         && !RTStrICmp(pszType, "hdd"))
    140     {
    141         errorArgument("Harddisk's can't be changed while the VM is still running\n");
     146    if (   FAILED(rc)
     147        || !pszCtl
     148        || port == ~0U
     149        || device == ~0U)
     150    {
     151        errorGetOpt(USAGE_STORAGEATTACH, c, &ValueUnion);
    142152        return 1;
    143153    }
     
    163173    }
    164174
     175    if (fRunTime)
     176    {
     177        if (   !RTStrICmp(pszMedium, "none")
     178            || !RTStrICmp(pszType, "hdd"))
     179            errorArgument("DVD/HardDisk Drives can't be changed while the VM is still running\n");
     180        if (pszPassThrough)
     181            errorArgument("Drive passthrough state can't be changed while the VM is still running\n");
     182
     183        goto leave;
     184    }
     185
    165186    /* get the mutable session machine */
    166187    a->session->COMGETTER(Machine)(machine.asOutParam());
     
    169190    rc = machine->GetStorageControllerByName(Bstr(pszCtl), storageCtl.asOutParam());
    170191    if (FAILED(rc))
    171         return errorSyntax(USAGE_ATTACHDISK, "Couldn't find the controller with the name: '%s'\n", pszCtl);
    172 
    173     if (!RTStrICmp(pszType, "dvd"))
    174     {
    175         if (!RTStrICmp(pszFile, "null"))
    176         {
    177             if (fRunTime)
    178             {
    179                 errorArgument("DVD Drive's can't be removed while the VM is still running\n");
    180                 rc = E_FAIL;
    181             }
    182             else
    183             {
    184                 CHECK_ERROR (machine, DetachDevice(Bstr(pszCtl), port, device));
    185             }
     192    {
     193        errorSyntax(USAGE_STORAGEATTACH, "Couldn't find the controller with the name: '%s'\n", pszCtl);
     194        goto leave;
     195    }
     196
     197    if (!RTStrICmp(pszMedium, "none"))
     198    {
     199        CHECK_ERROR (machine, DetachDevice(Bstr(pszCtl), port, device));
     200    }
     201    else if (!RTStrICmp(pszMedium, "emptydrive"))
     202    {
     203        if (fRunTime)
     204        {
     205            ComPtr<IMediumAttachment> mediumAttachment;
     206            rc = machine->GetMediumAttachment(Bstr(pszCtl), port, device, mediumAttachment.asOutParam());
     207            if (SUCCEEDED(rc))
     208            {
     209                DeviceType_T deviceType;
     210                mediumAttachment->COMGETTER(Type) (&deviceType);
     211
     212                if (   (deviceType == DeviceType_DVD)
     213                    || (deviceType == DeviceType_Floppy))
     214                {
     215                    /* just unmount the floppy/dvd */
     216                    CHECK_ERROR (machine, MountMedium(Bstr(pszCtl), port, device, NULL));
     217                }
     218            }
     219            else
     220            {
     221                errorArgument("No DVD/Floppy Drive attached to the controller '%s'"
     222                              "at the port: %u, device: %u", pszCtl, port, device);
     223                goto leave;
     224            }
     225
    186226        }
    187227        else
     228        {
     229            StorageBus_T storageBus = StorageBus_Null;
     230            DeviceType_T deviceType = DeviceType_Null;
     231
     232            CHECK_ERROR (storageCtl, COMGETTER(Bus)(&storageBus));
     233
     234            if (storageBus == StorageBus_Floppy)
     235                deviceType = DeviceType_Floppy;
     236            else
     237                deviceType = DeviceType_DVD;
     238
     239            /* attach a empty floppy/dvd drive after removing previous attachment */
     240            machine->DetachDevice(Bstr(pszCtl), port, device);
     241            CHECK_ERROR (machine, AttachDevice(Bstr(pszCtl), port, device, deviceType, NULL));
     242        }
     243    }
     244    else
     245    {
     246        if (!pszType)
     247        {
     248            errorSyntax(USAGE_STORAGEATTACH, "Argument --type not specified\n");
     249            goto leave;
     250        }
     251
     252        if (!RTStrICmp(pszType, "dvddrive"))
    188253        {
    189254            Bstr uuid;
     
    216281            do
    217282            {
    218                 /* unmount? */
    219                 if (!RTStrICmp(pszFile, "none"))
    220                 {
    221                     /* nothing to do, NULL object will cause unmount */
    222                 }
    223283                /* host drive? */
    224                 else if (!RTStrNICmp(pszFile, "host:", 5))
     284                if (!RTStrNICmp(pszMedium, "host:", 5))
    225285                {
    226286                    ComPtr<IHost> host;
    227287                    CHECK_ERROR (a->virtualBox, COMGETTER(Host)(host.asOutParam()));
    228                     rc = host->FindHostDVDDrive(Bstr(pszFile + 5), dvdMedium.asOutParam());
     288                    rc = host->FindHostDVDDrive(Bstr(pszMedium + 5), dvdMedium.asOutParam());
    229289                    if (!dvdMedium)
    230290                    {
    231291                        /* 2nd try: try with the real name, important on Linux+libhal */
    232292                        char szPathReal[RTPATH_MAX];
    233                         if (RT_FAILURE(RTPathReal(pszFile + 5, szPathReal, sizeof(szPathReal))))
     293                        if (RT_FAILURE(RTPathReal(pszMedium + 5, szPathReal, sizeof(szPathReal))))
    234294                        {
    235                             errorArgument("Invalid host DVD drive name \"%s\"", pszFile + 5);
     295                            errorArgument("Invalid host DVD drive name \"%s\"", pszMedium + 5);
    236296                            rc = E_FAIL;
    237297                            break;
     
    240300                        if (!dvdMedium)
    241301                        {
    242                             errorArgument("Invalid host DVD drive name \"%s\"", pszFile + 5);
     302                            errorArgument("Invalid host DVD drive name \"%s\"", pszMedium + 5);
    243303                            rc = E_FAIL;
    244304                            break;
     
    249309                {
    250310                    /* first assume it's a UUID */
    251                     uuid = pszFile;
     311                    uuid = pszMedium;
    252312                    rc = a->virtualBox->GetDVDImage(uuid, dvdMedium.asOutParam());
    253313                    if (FAILED(rc) || !dvdMedium)
    254314                    {
    255315                        /* must be a filename, check if it's in the collection */
    256                         rc = a->virtualBox->FindDVDImage(Bstr(pszFile), dvdMedium.asOutParam());
     316                        rc = a->virtualBox->FindDVDImage(Bstr(pszMedium), dvdMedium.asOutParam());
    257317                        /* not registered, do that on the fly */
    258318                        if (!dvdMedium)
    259319                        {
    260320                            Bstr emptyUUID;
    261                             CHECK_ERROR (a->virtualBox, OpenDVDImage(Bstr(pszFile),
     321                            CHECK_ERROR (a->virtualBox, OpenDVDImage(Bstr(pszMedium),
    262322                                         emptyUUID, dvdMedium.asOutParam()));
    263323                        }
     
    265325                    if (!dvdMedium)
    266326                    {
     327                        errorArgument("Invalid UUID or filename \"%s\"", pszMedium);
    267328                        rc = E_FAIL;
    268329                        break;
    269330                    }
    270331                }
    271             }
    272             while (0);
     332            } while (0);
    273333
    274334            if (dvdMedium)
     335            {
    275336                dvdMedium->COMGETTER(Id)(uuid.asOutParam());
    276             if (SUCCEEDED(rc))
    277337                CHECK_ERROR (machine, MountMedium(Bstr(pszCtl), port, device, uuid));
    278         }
    279     }
    280     else if (   !RTStrICmp(pszType, "hdd")
    281              && !fRunTime)
    282     {
    283         Bstr uuid(pszFile);
    284 
    285         if (   !RTStrICmp(pszFile, "none")
    286             || !RTStrICmp(pszFile, "null"))
    287         {
    288             machine->DetachDevice(Bstr(pszCtl), port, device);
    289         }
    290         else
     338            }
     339        }
     340        else if (   !RTStrICmp(pszType, "hdd")
     341                 && !fRunTime)
    291342        {
    292343            ComPtr<IMediumAttachment> mediumAttachement;
     
    304355
    305356            /* first guess is that it's a UUID */
     357            Bstr uuid(pszMedium);
    306358            ComPtr<IMedium> hardDisk;
    307359            rc = a->virtualBox->GetHardDisk(uuid, hardDisk.asOutParam());
     
    310362            if (!hardDisk)
    311363            {
    312                 rc = a->virtualBox->FindHardDisk(Bstr(pszFile), hardDisk.asOutParam());
     364                rc = a->virtualBox->FindHardDisk(Bstr(pszMedium), hardDisk.asOutParam());
    313365                if (FAILED(rc))
    314366                {
    315367                    /* open the new hard disk object */
    316368                    CHECK_ERROR (a->virtualBox,
    317                                  OpenHardDisk(Bstr(pszFile),
     369                                 OpenHardDisk(Bstr(pszMedium),
    318370                                              AccessMode_ReadWrite, false, Bstr(""),
    319371                                              false, Bstr(""), hardDisk.asOutParam()));
     
    327379            }
    328380            else
     381            {
     382                errorArgument("Invalid UUID or filename \"%s\"", pszMedium);
    329383                rc = E_FAIL;
    330         }
    331     }
    332     else if (!RTStrICmp(pszType, "fdd"))
    333     {
    334         ComPtr<IMediumAttachment> floppyAttachment;
    335         machine->GetMediumAttachment(Bstr(pszCtl), port, device, floppyAttachment.asOutParam());
    336 
    337         if (!RTStrICmp(pszFile, "null"))
    338         {
    339             if (fRunTime)
    340             {
    341                 errorArgument("Floppy Drive's can't be removed while the VM is still running\n");
    342                 rc = E_FAIL;
    343             }
    344             else
    345             {
    346                 if (floppyAttachment)
    347                     CHECK_ERROR (machine, DetachDevice(Bstr(pszCtl), port, device));
    348             }
    349         }
    350         else
     384            }
     385        }
     386        else if (!RTStrICmp(pszType, "fdd"))
    351387        {
    352388            Bstr uuid;
    353389            ComPtr<IMedium> floppyMedium;
     390            ComPtr<IMediumAttachment> floppyAttachment;
     391            machine->GetMediumAttachment(Bstr(pszCtl), port, device, floppyAttachment.asOutParam());
    354392
    355393            if (   !fRunTime
     
    357395                CHECK_ERROR (machine, AttachDevice(Bstr(pszCtl), port, device, DeviceType_Floppy, NULL));
    358396
    359             /* unmount? */
    360             if (!RTStrICmp(pszFile, "none"))
    361             {
    362                 /* nothing to do, NULL object will cause unmount */
    363             }
    364397            /* host drive? */
    365             else if (!RTStrNICmp(pszFile, "host:", 5))
     398            if (!RTStrNICmp(pszMedium, "host:", 5))
    366399            {
    367400                ComPtr<IHost> host;
    368401
    369402                CHECK_ERROR (a->virtualBox, COMGETTER(Host)(host.asOutParam()));
    370                 rc = host->FindHostFloppyDrive(Bstr(pszFile + 5), floppyMedium.asOutParam());
     403                rc = host->FindHostFloppyDrive(Bstr(pszMedium + 5), floppyMedium.asOutParam());
    371404                if (!floppyMedium)
    372405                {
    373                     errorArgument("Invalid host floppy drive name \"%s\"", pszFile + 5);
     406                    errorArgument("Invalid host floppy drive name \"%s\"", pszMedium + 5);
    374407                    rc = E_FAIL;
    375408                }
     
    378411            {
    379412                /* first assume it's a UUID */
    380                 uuid = pszFile;
     413                uuid = pszMedium;
    381414                rc = a->virtualBox->GetFloppyImage(uuid, floppyMedium.asOutParam());
    382415                if (FAILED(rc) || !floppyMedium)
    383416                {
    384417                    /* must be a filename, check if it's in the collection */
    385                     rc = a->virtualBox->FindFloppyImage(Bstr(pszFile), floppyMedium.asOutParam());
     418                    rc = a->virtualBox->FindFloppyImage(Bstr(pszMedium), floppyMedium.asOutParam());
    386419                    /* not registered, do that on the fly */
    387420                    if (!floppyMedium)
     
    389422                        Bstr emptyUUID;
    390423                        CHECK_ERROR (a->virtualBox,
    391                                      OpenFloppyImage(Bstr(pszFile),
     424                                     OpenFloppyImage(Bstr(pszMedium),
    392425                                                     emptyUUID,
    393426                                                     floppyMedium.asOutParam()));
     
    396429
    397430                if (!floppyMedium)
    398                     rc = E_FAIL;
     431                {
     432                    errorArgument("Invalid UUID or filename \"%s\"", pszMedium);
     433                    rc = E_FAIL;
     434                }
    399435            }
    400436
    401437            if (floppyMedium)
     438            {
    402439                floppyMedium->COMGETTER(Id)(uuid.asOutParam());
    403             if (SUCCEEDED(rc))
    404440                CHECK_ERROR (machine, MountMedium(Bstr(pszCtl), port, device, uuid));
     441            }
     442        }
     443        else
     444        {
     445            errorArgument("Invalid --type argument '%s'", pszType);
     446            rc = E_FAIL;
     447        }
     448    }
     449
     450    if (   pszPassThrough
     451        && (SUCCEEDED(rc)))
     452    {
     453        ComPtr<IMediumAttachment> mattach;
     454
     455        CHECK_ERROR (machine, GetMediumAttachment(Bstr(pszCtl), port, device, mattach.asOutParam()));
     456
     457        if (SUCCEEDED(rc))
     458        {
     459            if (!RTStrICmp(pszPassThrough, "on"))
     460            {
     461                CHECK_ERROR (mattach, COMSETTER(Passthrough)(true));
     462            }
     463            else if (!RTStrICmp(pszPassThrough, "off"))
     464            {
     465                CHECK_ERROR (mattach, COMSETTER(Passthrough)(false));
     466            }
     467            else
     468            {
     469                errorArgument("Invalid --passthrough argument '%s'", pszPassThrough);
     470                rc = E_FAIL;
     471            }
     472        }
     473        else
     474        {
     475            errorArgument("Couldn't find the controller attachment for the controller '%s'\n", pszCtl);
     476            rc = E_FAIL;
    405477        }
    406478    }
     
    410482        CHECK_ERROR (machine, SaveSettings());
    411483
     484leave:
    412485    /* it's important to always close sessions */
    413486    a->session->Close();
     
    421494    { "--name",             'n', RTGETOPT_REQ_STRING },
    422495    { "--add",              'a', RTGETOPT_REQ_STRING },
    423     { "--controller",       't', RTGETOPT_REQ_STRING },
    424     { "--port",             'p', RTGETOPT_REQ_UINT32 },
    425     { "--device",           'd', RTGETOPT_REQ_UINT32 },
    426     { "--passthrough",      'h', RTGETOPT_REQ_STRING },
     496    { "--controller",       'c', RTGETOPT_REQ_STRING },
    427497    { "--sataideemulation", 'e', RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_INDEX },
    428     { "--sataportcount",    'c', RTGETOPT_REQ_UINT32 },
     498    { "--sataportcount",    'p', RTGETOPT_REQ_UINT32 },
    429499    { "--remove",           'r', RTGETOPT_REQ_NOTHING },
    430500};
     
    437507    const char       *pszBusType     = NULL;
    438508    const char       *pszCtlType     = NULL;
    439     const char       *pszPassThrough = NULL;
    440     ULONG             cPass          = 0;
    441509    ULONG             satabootdev    = ~0U;
    442510    ULONG             sataidedev     = ~0U;
    443511    ULONG             sataportcount  = ~0U;
    444     ULONG             port           = ~0U;
    445     ULONG             device         = ~0U;
    446512    bool              fRemoveCtl     = false;
    447513    Bstr              machineuuid (a->argv[0]);
     
    479545            }
    480546
    481             case 't':   // controller <lsilogic/buslogic/intelahci/piix3/piix4/ich6/i82078>
     547            case 'c':   // controller <lsilogic/buslogic/intelahci/piix3/piix4/ich6/i82078>
    482548            {
    483549                if (ValueUnion.psz)
    484550                    pszCtlType = ValueUnion.psz;
    485                 else
    486                     rc = E_FAIL;
    487                 break;
    488             }
    489 
    490             case 'p':   // port
    491             {
    492                 port = ValueUnion.u32;
    493                 cPass++;
    494                 break;
    495             }
    496 
    497             case 'd':   // device
    498             {
    499                 device = ValueUnion.u32;
    500                 cPass++;
    501                 break;
    502             }
    503 
    504             case 'h':   // passthrough
    505             {
    506                 if (ValueUnion.psz)
    507                 {
    508                     pszPassThrough = ValueUnion.psz;
    509                     cPass++;
    510                 }
    511551                else
    512552                    rc = E_FAIL;
     
    531571            }
    532572
    533             case 'c':   // sataportcount
     573            case 'p':   // sataportcount
    534574            {
    535575                sataportcount = ValueUnion.u32;
     
    574614    if (!pszCtl)
    575615    {
     616        /* it's important to always close sessions */
     617        a->session->Close();
    576618        errorSyntax(USAGE_STORAGECONTROLLER, "Storage Controller Name not specified\n");
    577         return 1;
    578     }
    579 
    580     if (cPass != 0 && cPass != 3)
    581     {
    582         errorSyntax(USAGE_STORAGECONTROLLER,
    583                     "All three options (--passthrough, --port, --device)\n"
    584                     "need to be specified for dvd passthrough to be applied\n");
    585619        return 1;
    586620    }
     
    596630        {
    597631            ComPtr<IMediumAttachment> mediumAttach = mediumAttachments[i];
    598             LONG cPort = 0;
    599             LONG cDevice = 0;
    600 
    601             CHECK_ERROR (mediumAttach, COMGETTER(Port)(&cPort));
    602             CHECK_ERROR (mediumAttach, COMGETTER(Device)(&cDevice));
    603             CHECK_ERROR (machine, DetachDevice(Bstr(pszCtl), cPort, cDevice));
     632            LONG port = 0;
     633            LONG device = 0;
     634
     635            CHECK_ERROR (mediumAttach, COMGETTER(Port)(&port));
     636            CHECK_ERROR (mediumAttach, COMGETTER(Device)(&device));
     637            CHECK_ERROR (machine, DetachDevice(Bstr(pszCtl), port, device));
    604638        }
    605639
     
    689723        }
    690724
    691         if (   (cPass == 3)
    692             && SUCCEEDED(rc))
    693         {
    694             ComPtr<IMediumAttachment> mattach;
    695 
    696             CHECK_ERROR (machine, GetMediumAttachment(Bstr(pszCtl), port, device, mattach.asOutParam()));
    697 
    698             if (SUCCEEDED(rc))
    699             {
    700                 if (!RTStrICmp(pszPassThrough, "on"))
    701                 {
    702                     CHECK_ERROR (mattach, COMSETTER(Passthrough)(true));
    703                 }
    704                 else if (!RTStrICmp(pszPassThrough, "off"))
    705                 {
    706                     CHECK_ERROR (mattach, COMSETTER(Passthrough)(false));
    707                 }
    708                 else
    709                 {
    710                     errorArgument("Invalid --passthrough argument '%s'", pszPassThrough);
    711                     rc = E_FAIL;
    712                 }
    713             }
    714             else
    715             {
    716                 errorArgument("Couldn't find the controller attachment for the controller '%s'\n", pszCtl);
    717                 rc = E_FAIL;
    718             }
    719         }
    720 
    721725        if (   (sataportcount != ~0U)
    722726            && SUCCEEDED(rc))
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