VBoxManageStorageController.cpp revision 1207f59aa62006952dbb0bf7700decf34d8caeb2
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * VBoxManage - The storage controller related commands.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * Copyright (C) 2006-2010 Oracle Corporation
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * This file is part of VirtualBox Open Source Edition (OSE), as
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * available from http://www.virtualbox.org. This file is free software;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * you can redistribute it and/or modify it under the terms of the GNU
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * General Public License (GPL) as published by the Free Software
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * Foundation, in version 2 as it comes in the "COPYING" file of the
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore/*******************************************************************************
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore* Header Files *
2c30fa4582c5d6c659e059e719c5f6163f7ef1e3Garrett D'Amore*******************************************************************************/
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amoreusing namespace com;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore///////////////////////////////////////////////////////////////////////////////
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amorestatic const RTGETOPTDEF g_aStorageAttachOptions[] =
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore { "--storagectl", 's', RTGETOPT_REQ_STRING },
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore { "--passthrough", 'h', RTGETOPT_REQ_STRING },
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore { "--forceunmount", 'f', RTGETOPT_REQ_NOTHING },
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore int c = VERR_INTERNAL_ERROR; /* initialized to shut up gcc */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore return errorSyntax(USAGE_STORAGEATTACH, "Too few parameters");
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore return errorSyntax(USAGE_STORAGEATTACH, "Too many parameters");
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore RTGetOptInit(&GetState, a->argc, a->argv, g_aStorageAttachOptions,
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore RT_ELEMENTS(g_aStorageAttachOptions), 1, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore case 'm': // medium <none|emptydrive|uuid|filename|host:<drive>>
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore case 'f': // force unmount medium during runtime
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorGetOpt(USAGE_STORAGEATTACH, c, &ValueUnion);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore return errorSyntax(USAGE_STORAGEATTACH, "Storage controller name not specified");
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore return errorSyntax(USAGE_STORAGEATTACH, "Port not specified");
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore return errorSyntax(USAGE_STORAGEATTACH, "Device not specified");
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* get the virtualbox system properties */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR_RET(a->virtualBox, COMGETTER(SystemProperties)(systemProperties.asOutParam()), 1);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* try to find the given machine */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR_RET(a->virtualBox, GetMachine(machineuuid.raw(),
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR_RET(a->virtualBox, FindMachine(Bstr(a->argv[0]).raw(),
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore machine->COMGETTER(Id)(machineuuid.asOutParam());
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* open a session for the VM (new or shared) */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR_RET(machine, LockMachine(a->session, LockType_Shared), 1);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR_RET(a->session, COMGETTER(Type)(&st), 1);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorArgument("Hard disk drives cannot be changed while the VM is running\n");
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (fRunTime && !RTStrICmp(pszMedium, "none"))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorArgument("Drives cannot be removed while the VM is running\n");
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorArgument("Drive passthrough state can't be changed while the VM is running\n");
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* get the mutable session machine */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore a->session->COMGETTER(Machine)(machine.asOutParam());
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* check if the storage controller is present */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore rc = machine->GetStorageControllerByName(Bstr(pszCtl).raw(),
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorSyntax(USAGE_STORAGEATTACH, "Couldn't find the controller with the name: '%s'\n", pszCtl);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* for sata controller check if the port count is big enough
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * to accomodate the current port which is being assigned
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * else just increase the port count
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(storageCtl, COMGETTER(MaxPortCount)(&ulMaxPortCount));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(storageCtl, COMGETTER(PortCount)(&ulPortCount));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(storageCtl, COMSETTER(PortCount)(port + 1));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(machine, DetachDevice(Bstr(pszCtl).raw(), port, device));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore else if (!RTStrICmp(pszMedium, "emptydrive"))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore rc = machine->GetMediumAttachment(Bstr(pszCtl).raw(), port, device,
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore mediumAttachment->COMGETTER(Type)(&deviceType);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* just unmount the floppy/dvd */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(machine, MountMedium(Bstr(pszCtl).raw(), port,
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorArgument("No DVD/Floppy Drive attached to the controller '%s'"
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore "at the port: %u, device: %u", pszCtl, port, device);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore com::SafeArray <DeviceType_T> saDeviceTypes;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* check if the device type is supported by the controller */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(storageCtl, COMGETTER(Bus)(&storageBus));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(systemProperties, GetDeviceTypesForStorageBus(storageBus, ComSafeArrayAsOutParam(saDeviceTypes)));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore for (size_t i = 0; i < saDeviceTypes.size(); ++ i)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorArgument("The Attachment is not supported by the Storage Controller: '%s'", pszCtl);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* attach a empty floppy/dvd drive after removing previous attachment */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore machine->DetachDevice(Bstr(pszCtl).raw(), port, device);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(machine, AttachDevice(Bstr(pszCtl).raw(), port, device,
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * try to determine the type of the drive from the
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * storage controller chipset, the attachment and
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * the medium being attached
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore StorageControllerType_T ctlType = StorageControllerType_Null;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(storageCtl, COMGETTER(ControllerType)(&ctlType));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (ctlType == StorageControllerType_I82078)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * floppy controller found so lets assume the medium
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * given by the user is also a floppy image or floppy
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * for SATA/SCSI/IDE it is hard to tell if it is a harddisk or
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore * a dvd being attached so lets check if the medium attachment
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * and the medium, both are of same type. if yes then we are
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * sure of its type and don't need the user to enter it manually
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore * else ask the user for the type.
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore ComPtr<IMediumAttachment> mediumAttachement;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore rc = machine->GetMediumAttachment(Bstr(pszCtl).raw(), port,
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore mediumAttachement->COMGETTER(Type)(&deviceType);
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore rc = a->virtualBox->FindMedium(Bstr(pszMedium).raw(),
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore * ok so the medium and attachment both are DVD's so it is
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore * safe to assume that we are dealing with a DVD here
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore rc = a->virtualBox->FindMedium(Bstr(pszMedium).raw(),
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * ok so the medium and attachment both are hdd's so it is
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * safe to assume that we are dealing with a hdd here
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* for all other cases lets ask the user what type of drive it is */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorSyntax(USAGE_STORAGEATTACH, "Argument --type not specified\n");
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* check if the device type is supported by the controller */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore com::SafeArray <DeviceType_T> saDeviceTypes;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(storageCtl, COMGETTER(Bus)(&storageBus));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(systemProperties, GetDeviceTypesForStorageBus(storageBus, ComSafeArrayAsOutParam(saDeviceTypes)));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore for (size_t i = 0; i < saDeviceTypes.size(); ++ i)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore && (saDeviceTypes[i] == DeviceType_HardDisk))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorArgument("The Attachment is not supported by the Storage Controller: '%s'", pszCtl);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore ComPtr<IMediumAttachment> mediumAttachement;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* check if there is a dvd drive at the given location, if not attach one */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore rc = machine->GetMediumAttachment(Bstr(pszCtl).raw(), port,
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore mediumAttachement->COMGETTER(Type)(&deviceType);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore machine->DetachDevice(Bstr(pszCtl).raw(), port, device);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore rc = machine->AttachDevice(Bstr(pszCtl).raw(), port,
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore rc = machine->AttachDevice(Bstr(pszCtl).raw(), port,
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore /* Attach/Detach the dvd medium now */
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore /* host drive? */
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore CHECK_ERROR(a->virtualBox, COMGETTER(Host)(host.asOutParam()));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore rc = host->FindHostDVDDrive(Bstr(pszMedium + 5).raw(),
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore /* 2nd try: try with the real name, important on Linux+libhal */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (RT_FAILURE(RTPathReal(pszMedium + 5, szPathReal, sizeof(szPathReal))))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorArgument("Invalid host DVD drive name \"%s\"", pszMedium + 5);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore rc = host->FindHostDVDDrive(Bstr(szPathReal).raw(),
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore errorArgument("Invalid host DVD drive name \"%s\"", pszMedium + 5);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore rc = a->virtualBox->FindMedium(Bstr(pszMedium).raw(),
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* not registered, do that on the fly */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorArgument("Invalid UUID or filename \"%s\"", pszMedium);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore dvdMedium->COMGETTER(Id)(uuid.asOutParam());
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(machine, MountMedium(Bstr(pszCtl).raw(), port,
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore ComPtr<IMediumAttachment> mediumAttachement;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* if there is anything attached at the given location, remove it */
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore machine->DetachDevice(Bstr(pszCtl).raw(), port, device);
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore /* first guess is that it's a UUID */
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore rc = a->virtualBox->FindMedium(Bstr(pszMedium).raw(),
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* not successful? Then it must be a filename */
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore /* open the new hard disk object */
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore CHECK_ERROR(machine, AttachDevice(Bstr(pszCtl).raw(), port,
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorArgument("Invalid UUID or filename \"%s\"", pszMedium);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore machine->GetMediumAttachment(Bstr(pszCtl).raw(), port, device,
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(machine, AttachDevice(Bstr(pszCtl).raw(), port,
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* host drive? */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(a->virtualBox, COMGETTER(Host)(host.asOutParam()));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore rc = host->FindHostFloppyDrive(Bstr(pszMedium + 5).raw(),
682cb1044237d21ad6810702564bec833b8c410cGarrett D'Amore errorArgument("Invalid host floppy drive name \"%s\"", pszMedium + 5);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* first assume it's a UUID */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore rc = a->virtualBox->FindMedium(Bstr(pszMedium).raw(),
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* not registered, do that on the fly */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorArgument("Invalid UUID or filename \"%s\"", pszMedium);
622a30bf9ccf91e4468f9c8a7f5e60d628fee4b2Garrett D'Amore floppyMedium->COMGETTER(Id)(uuid.asOutParam());
622a30bf9ccf91e4468f9c8a7f5e60d628fee4b2Garrett D'Amore CHECK_ERROR(machine, MountMedium(Bstr(pszCtl).raw(), port,
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorArgument("Invalid --type argument '%s'", pszType);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(machine, GetMediumAttachment(Bstr(pszCtl).raw(), port,
622a30bf9ccf91e4468f9c8a7f5e60d628fee4b2Garrett D'Amore CHECK_ERROR(machine, PassthroughDevice(Bstr(pszCtl).raw(),
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(machine, PassthroughDevice(Bstr(pszCtl).raw(),
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorArgument("Invalid --passthrough argument '%s'", pszPassThrough);
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore errorArgument("Couldn't find the controller attachment for the controller '%s'\n", pszCtl);
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore /* commit changes */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* it's important to always close sessions */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amorestatic const RTGETOPTDEF g_aStorageControllerOptions[] =
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore { "--controller", 'c', RTGETOPT_REQ_STRING },
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore { "--sataideemulation", 'e', RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_INDEX },
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore { "--sataportcount", 'p', RTGETOPT_REQ_UINT32 },
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore { "--hostiocache", 'i', RTGETOPT_REQ_STRING },
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore return errorSyntax(USAGE_STORAGECONTROLLER, "Too few parameters");
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore RTGetOptInit (&GetState, a->argc, a->argv, g_aStorageControllerOptions,
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore RT_ELEMENTS(g_aStorageControllerOptions), 1, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore case 'a': // controller bus type <ide/sata/scsi/floppy>
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore case 'c': // controller <lsilogic/buslogic/intelahci/piix3/piix4/ich6/i82078>
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorGetOpt(USAGE_STORAGECONTROLLER, c, &ValueUnion);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* try to find the given machine */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR_RET(a->virtualBox, GetMachine(machineuuid.raw(),
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore CHECK_ERROR_RET(a->virtualBox, FindMachine(Bstr(a->argv[0]).raw(),
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore machine->COMGETTER(Id)(machineuuid.asOutParam());
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* open a session for the VM */
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore CHECK_ERROR_RET(machine, LockMachine(a->session, LockType_Write), 1);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* get the mutable session machine */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore a->session->COMGETTER(Machine)(machine.asOutParam());
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* it's important to always close sessions */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorSyntax(USAGE_STORAGECONTROLLER, "Storage controller name not specified\n");
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore com::SafeIfaceArray<IMediumAttachment> mediumAttachments;
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore GetMediumAttachmentsOfController(Bstr(pszCtl).raw(),
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore ComSafeArrayAsOutParam(mediumAttachments)));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore for (size_t i = 0; i < mediumAttachments.size(); ++ i)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore ComPtr<IMediumAttachment> mediumAttach = mediumAttachments[i];
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(mediumAttach, COMGETTER(Port)(&port));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(mediumAttach, COMGETTER(Device)(&device));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(machine, DetachDevice(Bstr(pszCtl).raw(), port, device));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(machine, RemoveStorageController(Bstr(pszCtl).raw()));
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore errorArgument("Can't detach the devices connected to '%s' Controller\n"
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(machine, AddStorageController(Bstr(pszCtl).raw(),
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(machine, AddStorageController(Bstr(pszCtl).raw(),
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore CHECK_ERROR(machine, AddStorageController(Bstr(pszCtl).raw(),
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(machine, AddStorageController(Bstr(pszCtl).raw(),
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(machine, AddStorageController(Bstr(pszCtl).raw(),
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorArgument("Invalid --add argument '%s'", pszBusType);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(machine, GetStorageControllerByName(Bstr(pszCtl).raw(),
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_LsiLogic));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore else if (!RTStrICmp(pszCtlType, "buslogic"))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_BusLogic));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore else if (!RTStrICmp(pszCtlType, "intelahci"))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_IntelAhci));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_PIIX3));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_PIIX4));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_ICH6));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_I82078));
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore else if (!RTStrICmp(pszCtlType, "lsilogicsas"))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_LsiLogicSas));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorArgument("Invalid --type argument '%s'", pszCtlType);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorArgument("Couldn't find the controller with the name: '%s'\n", pszCtl);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(machine, GetStorageControllerByName(Bstr(pszCtl).raw(),
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(ctl, COMSETTER(PortCount)(sataportcount));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorArgument("Couldn't find the controller with the name: '%s'\n", pszCtl);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(machine, GetStorageControllerByName(Bstr(pszCtl).raw(),
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore CHECK_ERROR(ctl, SetIDEEmulationPort(satabootdev, sataidedev));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorArgument("Couldn't find the controller with the name: '%s'\n", pszCtl);
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore CHECK_ERROR(machine, GetStorageControllerByName(Bstr(pszCtl).raw(),
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(ctl, COMSETTER(UseHostIOCache)(TRUE));
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore CHECK_ERROR(ctl, COMSETTER(UseHostIOCache)(FALSE));
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore errorArgument("Invalid --hostiocache argument '%s'", pszHostIOCache);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorArgument("Couldn't find the controller with the name: '%s'\n", pszCtl);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* commit changes */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* it's important to always close sessions */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore#endif /* !VBOX_ONLY_DOCS */