VBoxManageStorageController.cpp revision 1207f59aa62006952dbb0bf7700decf34d8caeb2
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore/* $Id$ */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore/** @file
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * VBoxManage - The storage controller related commands.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore/*
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * Copyright (C) 2006-2010 Oracle Corporation
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore *
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
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore#ifndef VBOX_ONLY_DOCS
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore/*******************************************************************************
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore* Header Files *
2c30fa4582c5d6c659e059e719c5f6163f7ef1e3Garrett D'Amore*******************************************************************************/
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore#include <VBox/com/com.h>
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore#include <VBox/com/array.h>
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore#include <VBox/com/ErrorInfo.h>
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore#include <VBox/com/errorprint.h>
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore#include <VBox/com/VirtualBox.h>
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore#include <iprt/path.h>
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore#include <iprt/param.h>
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore#include <iprt/string.h>
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore#include <iprt/ctype.h>
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore#include <iprt/stream.h>
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore#include <iprt/getopt.h>
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore#include <VBox/log.h>
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore#include "VBoxManage.h"
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amoreusing namespace com;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore// funcs
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore///////////////////////////////////////////////////////////////////////////////
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amorestatic const RTGETOPTDEF g_aStorageAttachOptions[] =
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore{
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore { "--storagectl", 's', RTGETOPT_REQ_STRING },
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore { "--port", 'p', RTGETOPT_REQ_UINT32 },
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore { "--device", 'd', RTGETOPT_REQ_UINT32 },
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore { "--medium", 'm', RTGETOPT_REQ_STRING },
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore { "--type", 't', RTGETOPT_REQ_STRING },
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore { "--passthrough", 'h', RTGETOPT_REQ_STRING },
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore { "--forceunmount", 'f', RTGETOPT_REQ_NOTHING },
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore};
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amoreint handleStorageAttach(HandlerArg *a)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore{
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore int c = VERR_INTERNAL_ERROR; /* initialized to shut up gcc */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore HRESULT rc = S_OK;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore ULONG port = ~0U;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore ULONG device = ~0U;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore bool fForceUnmount = false;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore const char *pszCtl = NULL;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore const char *pszType = NULL;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore const char *pszMedium = NULL;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore const char *pszPassThrough = NULL;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore Bstr machineuuid (a->argv[0]);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore RTGETOPTUNION ValueUnion;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore RTGETOPTSTATE GetState;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore ComPtr<IMachine> machine;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore ComPtr<IStorageController> storageCtl;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore ComPtr<ISystemProperties> systemProperties;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (a->argc < 9)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore return errorSyntax(USAGE_STORAGEATTACH, "Too few parameters");
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore else if (a->argc > 13)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore return errorSyntax(USAGE_STORAGEATTACH, "Too many parameters");
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore RTGetOptInit(&GetState, a->argc, a->argv, g_aStorageAttachOptions,
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore RT_ELEMENTS(g_aStorageAttachOptions), 1, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore while ( SUCCEEDED(rc)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore && (c = RTGetOpt(&GetState, &ValueUnion)))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore switch (c)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore case 's': // storage controller name
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (ValueUnion.psz)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore pszCtl = ValueUnion.psz;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore else
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore rc = E_FAIL;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore break;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore case 'p': // port
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore port = ValueUnion.u32;
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore break;
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore }
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore case 'd': // device
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore device = ValueUnion.u32;
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore break;
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore }
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore case 'm': // medium <none|emptydrive|uuid|filename|host:<drive>>
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore {
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore if (ValueUnion.psz)
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore pszMedium = ValueUnion.psz;
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore else
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore rc = E_FAIL;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore break;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore case 't': // type <dvddrive|hdd|fdd>
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (ValueUnion.psz)
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore pszType = ValueUnion.psz;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore else
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore rc = E_FAIL;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore break;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore case 'h': // passthrough <on|off>
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore if (ValueUnion.psz)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore pszPassThrough = ValueUnion.psz;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore else
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore rc = E_FAIL;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore break;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore case 'f': // force unmount medium during runtime
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore fForceUnmount = true;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore break;
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore }
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore default:
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorGetOpt(USAGE_STORAGEATTACH, c, &ValueUnion);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore rc = E_FAIL;
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore break;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (FAILED(rc))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore return 1;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (!pszCtl)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore return errorSyntax(USAGE_STORAGEATTACH, "Storage controller name not specified");
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (port == ~0U)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore return errorSyntax(USAGE_STORAGEATTACH, "Port not specified");
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (device == ~0U)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore return errorSyntax(USAGE_STORAGEATTACH, "Device not specified");
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* get the virtualbox system properties */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR_RET(a->virtualBox, COMGETTER(SystemProperties)(systemProperties.asOutParam()), 1);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* try to find the given machine */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (!Guid(machineuuid).isEmpty())
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR_RET(a->virtualBox, GetMachine(machineuuid.raw(),
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore machine.asOutParam()), 1);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore else
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR_RET(a->virtualBox, FindMachine(Bstr(a->argv[0]).raw(),
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore machine.asOutParam()), 1);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore machine->COMGETTER(Id)(machineuuid.asOutParam());
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
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 SessionType_T st;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR_RET(a->session, COMGETTER(Type)(&st), 1);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore bool fRunTime = (st == SessionType_Shared);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (fRunTime && !RTStrICmp(pszType, "hdd"))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorArgument("Hard disk drives cannot be changed while the VM is running\n");
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore goto leave;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (fRunTime && !RTStrICmp(pszMedium, "none"))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorArgument("Drives cannot be removed while the VM is running\n");
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore goto leave;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (fRunTime && pszPassThrough)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorArgument("Drive passthrough state can't be changed while the VM is running\n");
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore goto leave;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* get the mutable session machine */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore a->session->COMGETTER(Machine)(machine.asOutParam());
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* check if the storage controller is present */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore rc = machine->GetStorageControllerByName(Bstr(pszCtl).raw(),
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore storageCtl.asOutParam());
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (FAILED(rc))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorSyntax(USAGE_STORAGEATTACH, "Couldn't find the controller with the name: '%s'\n", pszCtl);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore goto leave;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
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 */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore ULONG ulPortCount = 0;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore ULONG ulMaxPortCount = 0;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(storageCtl, COMGETTER(MaxPortCount)(&ulMaxPortCount));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(storageCtl, COMGETTER(PortCount)(&ulPortCount));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if ( (ulPortCount != ulMaxPortCount)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore && (port >= ulPortCount)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore && (port < ulMaxPortCount))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(storageCtl, COMSETTER(PortCount)(port + 1));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (!RTStrICmp(pszMedium, "none"))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(machine, DetachDevice(Bstr(pszCtl).raw(), port, device));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore else if (!RTStrICmp(pszMedium, "emptydrive"))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (fRunTime)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore ComPtr<IMediumAttachment> mediumAttachment;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore DeviceType_T deviceType = DeviceType_Null;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore rc = machine->GetMediumAttachment(Bstr(pszCtl).raw(), port, device,
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore mediumAttachment.asOutParam());
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore if (SUCCEEDED(rc))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore mediumAttachment->COMGETTER(Type)(&deviceType);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if ( (deviceType == DeviceType_DVD)
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore || (deviceType == DeviceType_Floppy))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* just unmount the floppy/dvd */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(machine, MountMedium(Bstr(pszCtl).raw(), port,
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore device, Bstr("").raw(),
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore fForceUnmount));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if ( FAILED(rc)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore || !( deviceType == DeviceType_DVD
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore || deviceType == DeviceType_Floppy))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
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 goto leave;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore else
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore StorageBus_T storageBus = StorageBus_Null;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore DeviceType_T deviceType = DeviceType_Null;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore com::SafeArray <DeviceType_T> saDeviceTypes;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore ULONG driveCheck = 0;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
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 {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if ( (saDeviceTypes[i] == DeviceType_DVD)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore || (saDeviceTypes[i] == DeviceType_Floppy))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore driveCheck++;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (!driveCheck)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorArgument("The Attachment is not supported by the Storage Controller: '%s'", pszCtl);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore goto leave;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (storageBus == StorageBus_Floppy)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore deviceType = DeviceType_Floppy;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore else
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore deviceType = DeviceType_DVD;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
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 deviceType, NULL));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore else
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /*
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 */
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 {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /*
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 * host drive
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore */
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore pszType = "fdd";
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore else
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /*
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 */
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore ComPtr<IMediumAttachment> mediumAttachement;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore rc = machine->GetMediumAttachment(Bstr(pszCtl).raw(), port,
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore device,
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore mediumAttachement.asOutParam());
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (SUCCEEDED(rc))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore DeviceType_T deviceType;
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore mediumAttachement->COMGETTER(Type)(&deviceType);
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (deviceType == DeviceType_DVD)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore ComPtr<IMedium> dvdMedium;
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore rc = a->virtualBox->FindMedium(Bstr(pszMedium).raw(),
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore DeviceType_DVD,
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore dvdMedium.asOutParam());
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore if (dvdMedium)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /*
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
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore pszType = "dvddrive";
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore else if (deviceType == DeviceType_HardDisk)
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore ComPtr<IMedium> hardDisk;
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore rc = a->virtualBox->FindMedium(Bstr(pszMedium).raw(),
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore DeviceType_HardDisk,
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore hardDisk.asOutParam());
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (hardDisk)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /*
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 */
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore pszType = "hdd";
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* for all other cases lets ask the user what type of drive it is */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (!pszType)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorSyntax(USAGE_STORAGEATTACH, "Argument --type not specified\n");
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore goto leave;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* check if the device type is supported by the controller */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore StorageBus_T storageBus = StorageBus_Null;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore com::SafeArray <DeviceType_T> saDeviceTypes;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(storageCtl, COMGETTER(Bus)(&storageBus));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(systemProperties, GetDeviceTypesForStorageBus(storageBus, ComSafeArrayAsOutParam(saDeviceTypes)));
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore if (SUCCEEDED(rc))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore ULONG driveCheck = 0;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore for (size_t i = 0; i < saDeviceTypes.size(); ++ i)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if ( !RTStrICmp(pszType, "dvddrive")
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore && (saDeviceTypes[i] == DeviceType_DVD))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore driveCheck++;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if ( !RTStrICmp(pszType, "hdd")
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore && (saDeviceTypes[i] == DeviceType_HardDisk))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore driveCheck++;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if ( !RTStrICmp(pszType, "fdd")
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore && (saDeviceTypes[i] == DeviceType_Floppy))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore driveCheck++;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (!driveCheck)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorArgument("The Attachment is not supported by the Storage Controller: '%s'", pszCtl);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore goto leave;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore else
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore goto leave;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (!RTStrICmp(pszType, "dvddrive"))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore Bstr uuid;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore ComPtr<IMedium> dvdMedium;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (!fRunTime)
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore ComPtr<IMediumAttachment> mediumAttachement;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
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 device,
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore mediumAttachement.asOutParam());
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (SUCCEEDED(rc))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore DeviceType_T deviceType;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore mediumAttachement->COMGETTER(Type)(&deviceType);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (deviceType != DeviceType_DVD)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore machine->DetachDevice(Bstr(pszCtl).raw(), port, device);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore rc = machine->AttachDevice(Bstr(pszCtl).raw(), port,
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore device, DeviceType_DVD, NULL);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore else
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore rc = machine->AttachDevice(Bstr(pszCtl).raw(), port,
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore device, DeviceType_DVD, NULL);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore /* Attach/Detach the dvd medium now */
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore do
55f338e6ff66b050744472388b2b9ee3d320414fGarrett D'Amore {
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore /* host drive? */
55f338e6ff66b050744472388b2b9ee3d320414fGarrett D'Amore if (!RTStrNICmp(pszMedium, "host:", 5))
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore ComPtr<IHost> host;
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore CHECK_ERROR(a->virtualBox, COMGETTER(Host)(host.asOutParam()));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore rc = host->FindHostDVDDrive(Bstr(pszMedium + 5).raw(),
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore dvdMedium.asOutParam());
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (!dvdMedium)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore /* 2nd try: try with the real name, important on Linux+libhal */
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore char szPathReal[RTPATH_MAX];
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (RT_FAILURE(RTPathReal(pszMedium + 5, szPathReal, sizeof(szPathReal))))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorArgument("Invalid host DVD drive name \"%s\"", pszMedium + 5);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore rc = E_FAIL;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore break;
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore rc = host->FindHostDVDDrive(Bstr(szPathReal).raw(),
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore dvdMedium.asOutParam());
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore if (!dvdMedium)
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore {
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore errorArgument("Invalid host DVD drive name \"%s\"", pszMedium + 5);
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore rc = E_FAIL;
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore break;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore else
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore rc = a->virtualBox->FindMedium(Bstr(pszMedium).raw(),
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore DeviceType_DVD,
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore dvdMedium.asOutParam());
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore if (FAILED(rc) || !dvdMedium)
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* not registered, do that on the fly */
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore Bstr emptyUUID;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(a->virtualBox,
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore OpenMedium(Bstr(pszMedium).raw(),
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore DeviceType_DVD,
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore AccessMode_ReadWrite,
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore dvdMedium.asOutParam()));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore if (!dvdMedium)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorArgument("Invalid UUID or filename \"%s\"", pszMedium);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore rc = E_FAIL;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore break;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore } while (0);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (dvdMedium)
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore dvdMedium->COMGETTER(Id)(uuid.asOutParam());
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(machine, MountMedium(Bstr(pszCtl).raw(), port,
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore device, uuid.raw(),
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore fForceUnmount));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore else if ( !RTStrICmp(pszType, "hdd")
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore && !fRunTime)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore ComPtr<IMediumAttachment> mediumAttachement;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* if there is anything attached at the given location, remove it */
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore machine->DetachDevice(Bstr(pszCtl).raw(), port, device);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore /* first guess is that it's a UUID */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore ComPtr<IMedium> hardDisk;
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore rc = a->virtualBox->FindMedium(Bstr(pszMedium).raw(),
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore DeviceType_HardDisk,
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore hardDisk.asOutParam());
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* not successful? Then it must be a filename */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (!hardDisk)
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore {
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore /* open the new hard disk object */
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore CHECK_ERROR(a->virtualBox,
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore OpenMedium(Bstr(pszMedium).raw(),
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore DeviceType_HardDisk,
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore AccessMode_ReadWrite,
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore hardDisk.asOutParam()));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore if (hardDisk)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore CHECK_ERROR(machine, AttachDevice(Bstr(pszCtl).raw(), port,
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore device, DeviceType_HardDisk,
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore hardDisk));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore else
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorArgument("Invalid UUID or filename \"%s\"", pszMedium);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore rc = E_FAIL;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore else if (!RTStrICmp(pszType, "fdd"))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore Bstr uuid;
682cb1044237d21ad6810702564bec833b8c410cGarrett D'Amore ComPtr<IMedium> floppyMedium;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore ComPtr<IMediumAttachment> floppyAttachment;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore machine->GetMediumAttachment(Bstr(pszCtl).raw(), port, device,
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore floppyAttachment.asOutParam());
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if ( !fRunTime
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore && !floppyAttachment)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(machine, AttachDevice(Bstr(pszCtl).raw(), port,
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore device, DeviceType_Floppy,
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore NULL));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* host drive? */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (!RTStrNICmp(pszMedium, "host:", 5))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore ComPtr<IHost> host;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(a->virtualBox, COMGETTER(Host)(host.asOutParam()));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore rc = host->FindHostFloppyDrive(Bstr(pszMedium + 5).raw(),
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore floppyMedium.asOutParam());
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (!floppyMedium)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
682cb1044237d21ad6810702564bec833b8c410cGarrett D'Amore errorArgument("Invalid host floppy drive name \"%s\"", pszMedium + 5);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore rc = E_FAIL;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore else
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* first assume it's a UUID */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore rc = a->virtualBox->FindMedium(Bstr(pszMedium).raw(),
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore DeviceType_Floppy,
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore floppyMedium.asOutParam());
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (FAILED(rc) || !floppyMedium)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* not registered, do that on the fly */
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore Bstr emptyUUID;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(a->virtualBox,
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore OpenMedium(Bstr(pszMedium).raw(),
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore DeviceType_Floppy,
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore AccessMode_ReadWrite,
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore floppyMedium.asOutParam()));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (!floppyMedium)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorArgument("Invalid UUID or filename \"%s\"", pszMedium);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore rc = E_FAIL;
622a30bf9ccf91e4468f9c8a7f5e60d628fee4b2Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (floppyMedium)
622a30bf9ccf91e4468f9c8a7f5e60d628fee4b2Garrett D'Amore {
622a30bf9ccf91e4468f9c8a7f5e60d628fee4b2Garrett D'Amore floppyMedium->COMGETTER(Id)(uuid.asOutParam());
622a30bf9ccf91e4468f9c8a7f5e60d628fee4b2Garrett D'Amore CHECK_ERROR(machine, MountMedium(Bstr(pszCtl).raw(), port,
622a30bf9ccf91e4468f9c8a7f5e60d628fee4b2Garrett D'Amore device, uuid.raw(),
622a30bf9ccf91e4468f9c8a7f5e60d628fee4b2Garrett D'Amore fForceUnmount));
622a30bf9ccf91e4468f9c8a7f5e60d628fee4b2Garrett D'Amore }
622a30bf9ccf91e4468f9c8a7f5e60d628fee4b2Garrett D'Amore }
622a30bf9ccf91e4468f9c8a7f5e60d628fee4b2Garrett D'Amore else
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorArgument("Invalid --type argument '%s'", pszType);
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore rc = E_FAIL;
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if ( pszPassThrough
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore && (SUCCEEDED(rc)))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore ComPtr<IMediumAttachment> mattach;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(machine, GetMediumAttachment(Bstr(pszCtl).raw(), port,
622a30bf9ccf91e4468f9c8a7f5e60d628fee4b2Garrett D'Amore device, mattach.asOutParam()));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (SUCCEEDED(rc))
622a30bf9ccf91e4468f9c8a7f5e60d628fee4b2Garrett D'Amore {
622a30bf9ccf91e4468f9c8a7f5e60d628fee4b2Garrett D'Amore if (!RTStrICmp(pszPassThrough, "on"))
622a30bf9ccf91e4468f9c8a7f5e60d628fee4b2Garrett D'Amore {
622a30bf9ccf91e4468f9c8a7f5e60d628fee4b2Garrett D'Amore CHECK_ERROR(machine, PassthroughDevice(Bstr(pszCtl).raw(),
622a30bf9ccf91e4468f9c8a7f5e60d628fee4b2Garrett D'Amore port, device, TRUE));
622a30bf9ccf91e4468f9c8a7f5e60d628fee4b2Garrett D'Amore }
622a30bf9ccf91e4468f9c8a7f5e60d628fee4b2Garrett D'Amore else if (!RTStrICmp(pszPassThrough, "off"))
622a30bf9ccf91e4468f9c8a7f5e60d628fee4b2Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(machine, PassthroughDevice(Bstr(pszCtl).raw(),
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore port, device, FALSE));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore else
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorArgument("Invalid --passthrough argument '%s'", pszPassThrough);
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore rc = E_FAIL;
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore }
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore else
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore {
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore errorArgument("Couldn't find the controller attachment for the controller '%s'\n", pszCtl);
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore rc = E_FAIL;
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore /* commit changes */
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore if (SUCCEEDED(rc))
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore CHECK_ERROR(machine, SaveSettings());
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amoreleave:
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* it's important to always close sessions */
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore a->session->UnlockMachine();
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore return SUCCEEDED(rc) ? 0 : 1;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore}
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amorestatic const RTGETOPTDEF g_aStorageControllerOptions[] =
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore{
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore { "--name", 'n', RTGETOPT_REQ_STRING },
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore { "--add", 'a', RTGETOPT_REQ_STRING },
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 { "--remove", 'r', RTGETOPT_REQ_NOTHING },
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore { "--hostiocache", 'i', RTGETOPT_REQ_STRING },
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore};
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amoreint handleStorageController(HandlerArg *a)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore{
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore int c;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore HRESULT rc = S_OK;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore const char *pszCtl = NULL;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore const char *pszBusType = NULL;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore const char *pszCtlType = NULL;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore const char *pszHostIOCache = NULL;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore ULONG satabootdev = ~0U;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore ULONG sataidedev = ~0U;
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore ULONG sataportcount = ~0U;
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore bool fRemoveCtl = false;
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore Bstr machineuuid (a->argv[0]);
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore ComPtr<IMachine> machine;
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore RTGETOPTUNION ValueUnion;
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore RTGETOPTSTATE GetState;
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore if (a->argc < 4)
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore return errorSyntax(USAGE_STORAGECONTROLLER, "Too few parameters");
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore
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
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore while ( SUCCEEDED(rc)
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore && (c = RTGetOpt(&GetState, &ValueUnion)))
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore {
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore switch (c)
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore {
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore case 'n': // controller name
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore {
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore if (ValueUnion.psz)
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore pszCtl = ValueUnion.psz;
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore else
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore rc = E_FAIL;
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore break;
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore case 'a': // controller bus type <ide/sata/scsi/floppy>
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore {
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore if (ValueUnion.psz)
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore pszBusType = ValueUnion.psz;
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore else
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore rc = E_FAIL;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore break;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore case 'c': // controller <lsilogic/buslogic/intelahci/piix3/piix4/ich6/i82078>
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (ValueUnion.psz)
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore pszCtlType = ValueUnion.psz;
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore else
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore rc = E_FAIL;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore break;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore case 'e': // sataideemulation
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore satabootdev = GetState.uIndex;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore sataidedev = ValueUnion.u32;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore break;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore case 'p': // sataportcount
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore sataportcount = ValueUnion.u32;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore break;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore case 'r': // remove controller
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore fRemoveCtl = true;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore break;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore case 'i':
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore pszHostIOCache = ValueUnion.psz;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore break;
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore default:
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorGetOpt(USAGE_STORAGECONTROLLER, c, &ValueUnion);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore rc = E_FAIL;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore break;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore if (FAILED(rc))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore return 1;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* try to find the given machine */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (!Guid(machineuuid).isEmpty())
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR_RET(a->virtualBox, GetMachine(machineuuid.raw(),
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore machine.asOutParam()), 1);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore else
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore {
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore CHECK_ERROR_RET(a->virtualBox, FindMachine(Bstr(a->argv[0]).raw(),
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore machine.asOutParam()), 1);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore machine->COMGETTER(Id)(machineuuid.asOutParam());
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* open a session for the VM */
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore CHECK_ERROR_RET(machine, LockMachine(a->session, LockType_Write), 1);
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* get the mutable session machine */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore a->session->COMGETTER(Machine)(machine.asOutParam());
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (!pszCtl)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* it's important to always close sessions */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore a->session->UnlockMachine();
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorSyntax(USAGE_STORAGECONTROLLER, "Storage controller name not specified\n");
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore return 1;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore if (fRemoveCtl)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore com::SafeIfaceArray<IMediumAttachment> mediumAttachments;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(machine,
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 {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore ComPtr<IMediumAttachment> mediumAttach = mediumAttachments[i];
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore LONG port = 0;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore LONG device = 0;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
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 }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (SUCCEEDED(rc))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(machine, RemoveStorageController(Bstr(pszCtl).raw()));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore else
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore errorArgument("Can't detach the devices connected to '%s' Controller\n"
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore "and thus its removal failed.", pszCtl);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore else
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (pszBusType)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore ComPtr<IStorageController> ctl;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore if (!RTStrICmp(pszBusType, "ide"))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(machine, AddStorageController(Bstr(pszCtl).raw(),
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore StorageBus_IDE,
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore ctl.asOutParam()));
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore }
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore else if (!RTStrICmp(pszBusType, "sata"))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(machine, AddStorageController(Bstr(pszCtl).raw(),
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore StorageBus_SATA,
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore ctl.asOutParam()));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore else if (!RTStrICmp(pszBusType, "scsi"))
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore {
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore CHECK_ERROR(machine, AddStorageController(Bstr(pszCtl).raw(),
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore StorageBus_SCSI,
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore ctl.asOutParam()));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore else if (!RTStrICmp(pszBusType, "floppy"))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(machine, AddStorageController(Bstr(pszCtl).raw(),
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore StorageBus_Floppy,
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore ctl.asOutParam()));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore else if (!RTStrICmp(pszBusType, "sas"))
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(machine, AddStorageController(Bstr(pszCtl).raw(),
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore StorageBus_SAS,
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore ctl.asOutParam()));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore else
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorArgument("Invalid --add argument '%s'", pszBusType);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore rc = E_FAIL;
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if ( pszCtlType
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore && SUCCEEDED(rc))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore ComPtr<IStorageController> ctl;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(machine, GetStorageControllerByName(Bstr(pszCtl).raw(),
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore ctl.asOutParam()));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (SUCCEEDED(rc))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (!RTStrICmp(pszCtlType, "lsilogic"))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_LsiLogic));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore else if (!RTStrICmp(pszCtlType, "buslogic"))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_BusLogic));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore else if (!RTStrICmp(pszCtlType, "intelahci"))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_IntelAhci));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore else if (!RTStrICmp(pszCtlType, "piix3"))
622a30bf9ccf91e4468f9c8a7f5e60d628fee4b2Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_PIIX3));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore else if (!RTStrICmp(pszCtlType, "piix4"))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_PIIX4));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore else if (!RTStrICmp(pszCtlType, "ich6"))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_ICH6));
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore else if (!RTStrICmp(pszCtlType, "i82078"))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_I82078));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore else if (!RTStrICmp(pszCtlType, "lsilogicsas"))
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_LsiLogicSas));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore else
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorArgument("Invalid --type argument '%s'", pszCtlType);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore rc = E_FAIL;
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore }
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore else
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorArgument("Couldn't find the controller with the name: '%s'\n", pszCtl);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore rc = E_FAIL;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if ( (sataportcount != ~0U)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore && SUCCEEDED(rc))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore ComPtr<IStorageController> ctl;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(machine, GetStorageControllerByName(Bstr(pszCtl).raw(),
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore ctl.asOutParam()));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (SUCCEEDED(rc))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(ctl, COMSETTER(PortCount)(sataportcount));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore else
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorArgument("Couldn't find the controller with the name: '%s'\n", pszCtl);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore rc = E_FAIL;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if ( (sataidedev != ~0U)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore && (satabootdev != ~0U)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore && SUCCEEDED(rc))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore ComPtr<IStorageController> ctl;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(machine, GetStorageControllerByName(Bstr(pszCtl).raw(),
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore ctl.asOutParam()));
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore if (SUCCEEDED(rc))
622a30bf9ccf91e4468f9c8a7f5e60d628fee4b2Garrett D'Amore {
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore CHECK_ERROR(ctl, SetIDEEmulationPort(satabootdev, sataidedev));
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore }
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore else
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorArgument("Couldn't find the controller with the name: '%s'\n", pszCtl);
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore rc = E_FAIL;
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore }
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if ( pszHostIOCache
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore && SUCCEEDED(rc))
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore ComPtr<IStorageController> ctl;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore CHECK_ERROR(machine, GetStorageControllerByName(Bstr(pszCtl).raw(),
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore ctl.asOutParam()));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore if (SUCCEEDED(rc))
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore {
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore if (!RTStrICmp(pszHostIOCache, "on"))
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore CHECK_ERROR(ctl, COMSETTER(UseHostIOCache)(TRUE));
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore }
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore else if (!RTStrICmp(pszHostIOCache, "off"))
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore {
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore CHECK_ERROR(ctl, COMSETTER(UseHostIOCache)(FALSE));
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore }
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore else
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore {
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore errorArgument("Invalid --hostiocache argument '%s'", pszHostIOCache);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore rc = E_FAIL;
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore }
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore else
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore errorArgument("Couldn't find the controller with the name: '%s'\n", pszCtl);
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore rc = E_FAIL;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
682cb1044237d21ad6810702564bec833b8c410cGarrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore }
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* commit changes */
682cb1044237d21ad6810702564bec833b8c410cGarrett D'Amore if (SUCCEEDED(rc))
682cb1044237d21ad6810702564bec833b8c410cGarrett D'Amore CHECK_ERROR(machine, SaveSettings());
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* it's important to always close sessions */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore a->session->UnlockMachine();
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore return SUCCEEDED(rc) ? 0 : 1;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore}
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore#endif /* !VBOX_ONLY_DOCS */
a19bb1fa9f3f280f4a5e9125331ffb7f0825e4faGarrett D'Amore
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore