VBoxManageStorageController.cpp revision e64031e20c39650a7bc902a3e1aba613b9415dee
/* $Id$ */
/** @file
* VBoxManage - The storage controller related commands.
*/
/*
* Copyright (C) 2006-2009 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#ifndef VBOX_ONLY_DOCS
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include "VBoxManage.h"
using namespace com;
// funcs
///////////////////////////////////////////////////////////////////////////////
static const RTGETOPTDEF g_aStorageAttachOptions[] =
{
};
int handleStorageAttach(HandlerArg *a)
{
int c = VERR_INTERNAL_ERROR; /* initialized to shut up gcc */
bool fRunTime = false;
bool fForceUnmount = false;
const char *pszPassThrough = NULL;
if (a->argc < 9)
else if (a->argc > 13)
{
switch (c)
{
case 's': // storage controller name
{
if (ValueUnion.psz)
else
break;
}
case 'p': // port
{
break;
}
case 'd': // device
{
break;
}
case 'm': // medium <none|emptydrive|uuid|filename|host:<drive>>
{
if (ValueUnion.psz)
else
break;
}
case 't': // type <dvddrive|hdd|fdd>
{
if (ValueUnion.psz)
else
break;
}
case 'h': // passthrough <on|off>
{
if (ValueUnion.psz)
else
break;
}
case 'f': // force unmount medium during runtime
{
fForceUnmount = true;
break;
}
default:
{
break;
}
}
}
|| !pszCtl
|| port == ~0U
|| device == ~0U)
{
return 1;
}
/* get the virtualbox system properties */
/* try to find the given machine */
{
}
else
{
}
/* open a session for the VM */
{
/* try to open an existing session for the VM */
fRunTime = true;
}
{
errorArgument("Hard disk drives cannot be changed while the VM is running\n");
goto leave;
}
{
errorArgument("Drives cannot be removed while the VM is running\n");
goto leave;
}
if (fRunTime && pszPassThrough)
{
errorArgument("Drive passthrough state can't be changed while the VM is running\n");
goto leave;
}
/* get the mutable session machine */
/* check if the storage controller is present */
{
goto leave;
}
/* for sata controller check if the port count is big enough
* to accomodate the current port which is being assigned
* else just increase the port count
*/
{
ULONG ulPortCount = 0;
ULONG ulMaxPortCount = 0;
if ( (ulPortCount != ulMaxPortCount)
&& (port >= ulPortCount)
&& (port < ulMaxPortCount))
}
{
}
{
if (fRunTime)
{
{
if ( (deviceType == DeviceType_DVD)
|| (deviceType == DeviceType_Floppy))
{
}
}
|| !( deviceType == DeviceType_DVD
|| deviceType == DeviceType_Floppy))
{
errorArgument("No DVD/Floppy Drive attached to the controller '%s'"
goto leave;
}
}
else
{
ULONG driveCheck = 0;
/* check if the device type is supported by the controller */
CHECK_ERROR(systemProperties, GetDeviceTypesForStorageBus(storageBus, ComSafeArrayAsOutParam(saDeviceTypes)));
{
if ( (saDeviceTypes[i] == DeviceType_DVD)
|| (saDeviceTypes[i] == DeviceType_Floppy))
driveCheck++;
}
if (!driveCheck)
{
goto leave;
}
if (storageBus == StorageBus_Floppy)
else
}
}
else
{
{
/*
* try to determine the type of the drive from the
* storage controller chipset, the attachment and
* the medium being attached
*/
if (ctlType == StorageControllerType_I82078)
{
/*
* floppy controller found so lets assume the medium
* given by the user is also a floppy image or floppy
* host drive
*/
pszType = "fdd";
}
else
{
/*
* a dvd being attached so lets check if the medium attachment
* and the medium, both are of same type. if yes then we are
* sure of its type and don't need the user to enter it manually
* else ask the user for the type.
*/
{
if (deviceType == DeviceType_DVD)
{
/* first assume it's a UUID */
{
/* must be a filename, check if it's in the collection */
}
if (dvdMedium)
{
/*
* ok so the medium and attachment both are DVD's so it is
* safe to assume that we are dealing with a DVD here
*/
pszType = "dvddrive";
}
}
else if (deviceType == DeviceType_HardDisk)
{
/* first assume it's a UUID */
{
/* must be a filename, check if it's in the collection */
}
if (hardDisk)
{
/*
* ok so the medium and attachment both are hdd's so it is
* safe to assume that we are dealing with a hdd here
*/
pszType = "hdd";
}
}
}
}
/* for all other cases lets ask the user what type of drive it is */
}
if (!pszType)
{
goto leave;
}
/* check if the device type is supported by the controller */
{
CHECK_ERROR(systemProperties, GetDeviceTypesForStorageBus(storageBus, ComSafeArrayAsOutParam(saDeviceTypes)));
{
ULONG driveCheck = 0;
{
&& (saDeviceTypes[i] == DeviceType_DVD))
driveCheck++;
&& (saDeviceTypes[i] == DeviceType_HardDisk))
driveCheck++;
&& (saDeviceTypes[i] == DeviceType_Floppy))
driveCheck++;
}
if (!driveCheck)
{
goto leave;
}
}
else
goto leave;
}
{
if (!fRunTime)
{
/* check if there is a dvd drive at the given location, if not attach one */
{
if (deviceType != DeviceType_DVD)
{
}
}
else
{
}
}
do
{
/* host drive? */
{
if (!dvdMedium)
{
/* 2nd try: try with the real name, important on Linux+libhal */
char szPathReal[RTPATH_MAX];
{
break;
}
if (!dvdMedium)
{
break;
}
}
}
else
{
/* first assume it's a UUID */
{
/* must be a filename, check if it's in the collection */
/* not registered, do that on the fly */
if (!dvdMedium)
{
}
}
if (!dvdMedium)
{
break;
}
}
} while (0);
if (dvdMedium)
{
}
}
&& !fRunTime)
{
/* if there is anything attached at the given location, remove it */
/* first guess is that it's a UUID */
/* not successful? Then it must be a filename */
if (!hardDisk)
{
{
/* open the new hard disk object */
}
}
if (hardDisk)
{
}
else
{
}
}
{
if ( !fRunTime
&& !floppyAttachment)
/* host drive? */
{
if (!floppyMedium)
{
}
}
else
{
/* first assume it's a UUID */
{
/* must be a filename, check if it's in the collection */
/* not registered, do that on the fly */
if (!floppyMedium)
{
floppyMedium.asOutParam()));
}
}
if (!floppyMedium)
{
}
}
if (floppyMedium)
{
}
}
else
{
}
}
if ( pszPassThrough
{
{
{
}
{
}
else
{
}
}
else
{
}
}
/* commit changes */
/* it's important to always close sessions */
}
static const RTGETOPTDEF g_aStorageControllerOptions[] =
{
};
int handleStorageController(HandlerArg *a)
{
int c;
const char *pszBusType = NULL;
const char *pszCtlType = NULL;
const char *pszIoBackend = NULL;
ULONG satabootdev = ~0U;
ULONG sataidedev = ~0U;
ULONG sataportcount = ~0U;
bool fRemoveCtl = false;
if (a->argc < 4)
{
switch (c)
{
case 'n': // controller name
{
if (ValueUnion.psz)
else
break;
}
{
if (ValueUnion.psz)
else
break;
}
{
if (ValueUnion.psz)
else
break;
}
case 'e': // sataideemulation
{
break;
}
case 'p': // sataportcount
{
break;
}
case 'r': // remove controller
{
fRemoveCtl = true;
break;
}
case 'i':
{
break;
}
default:
{
break;
}
}
}
return 1;
/* try to find the given machine */
{
}
else
{
}
/* open a session for the VM */
/* get the mutable session machine */
if (!pszCtl)
{
/* it's important to always close sessions */
return 1;
}
if (fRemoveCtl)
{
{
}
else
errorArgument("Can't detach the devices connected to '%s' Controller\n"
"and thus its removal failed.", pszCtl);
}
else
{
if (pszBusType)
{
{
}
{
}
{
}
{
}
{
}
else
{
}
}
if ( pszCtlType
{
{
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
else
{
}
}
else
{
}
}
if ( (sataportcount != ~0U)
{
{
}
else
{
}
}
if ( (sataidedev != ~0U)
&& (satabootdev != ~0U)
{
{
}
else
{
}
}
if ( pszIoBackend
{
{
}
{
}
else
{
}
}
}
/* commit changes */
/* it's important to always close sessions */
}
#endif /* !VBOX_ONLY_DOCS */