VBoxManage.cpp revision 07bf154df97af02974bb89d4f1ad36afa2b45443
/* $Id$ */
/** @file
* VBoxManage - VirtualBox's command-line interface.
*/
/*
* Copyright (C) 2006-2009 Sun Microsystems, Inc.
*
* 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.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#ifndef VBOX_ONLY_DOCS
#include <vector>
#include <list>
#endif /* !VBOX_ONLY_DOCS */
#include <iprt/initterm.h>
#include "VBoxManage.h"
#ifndef VBOX_ONLY_DOCS
using namespace com;
/* missing XPCOM <-> COM wrappers */
#ifndef STDMETHOD_
#endif
#ifndef NS_GET_IID
# define NS_GET_IID(I) IID_##I
#endif
#ifndef RT_OS_WINDOWS
#define IUnknown nsISupports
#endif
/** command handler type */
typedef int (*PFNHANDLER)(HandlerArg *a);
/**
* Quick IUSBDevice implementation for detaching / attaching
* devices to the USB Controller.
*/
class MyUSBDevice : public IUSBDevice
{
public:
// public initializer/uninitializer for internal purposes only
MyUSBDevice(uint16_t a_u16VendorId, uint16_t a_u16ProductId, uint16_t a_bcdRevision, uint64_t a_u64SerialHash, const char *a_pszComment)
m_cRefs(0)
{
}
{
return ASMAtomicIncU32(&m_cRefs);
}
{
if (!cRefs)
delete this;
return cRefs;
}
{
*ppvObject = (IUSBDevice *)this;
else
return E_NOINTERFACE;
AddRef();
return S_OK;
}
STDMETHOD(COMGETTER(VendorId))(USHORT *a_pusVendorId) { *a_pusVendorId = m_usVendorId; return S_OK; }
STDMETHOD(COMGETTER(ProductId))(USHORT *a_pusProductId) { *a_pusProductId = m_usProductId; return S_OK; }
STDMETHOD(COMGETTER(Revision))(USHORT *a_pusRevision) { *a_pusRevision = m_bcdRevision; return S_OK; }
STDMETHOD(COMGETTER(SerialHash))(ULONG64 *a_pullSerialHash) { *a_pullSerialHash = m_u64SerialHash; return S_OK; }
private:
/** The vendor id of this USB device. */
/** The product id of this USB device. */
/** The product revision number of this USB device.
* (high byte = integer; low byte = decimal) */
/** The USB serial hash of the device. */
/** The user comment string. */
/** Reference counter. */
};
// types
///////////////////////////////////////////////////////////////////////////////
template <typename T>
class Nullable
{
public:
operator const T&() const { return mValue; }
{
mIsNull = false;
return *this;
}
private:
bool mIsNull;
T mValue;
};
/** helper structure to encapsulate USB filter manipulation commands */
struct USBFilterCmd
{
struct USBFilter
{
USBFilter ()
{}
};
/** flag whether the command target is a global filter */
bool mGlobal;
/** machine this command is targeted at (null for global filters) */
};
#endif /* !VBOX_ONLY_DOCS */
// funcs
///////////////////////////////////////////////////////////////////////////////
static void showLogo(void)
{
static bool fShown; /* show only once */
if (!fShown)
{
RTPrintf("VirtualBox Command Line Management Interface Version "
VBOX_VERSION_STRING "\n"
"(C) 2005-2009 Sun Microsystems, Inc.\n"
"All rights reserved.\n"
"\n");
fShown = true;
}
}
{
#ifdef RT_OS_LINUX
bool fLinux = true;
#else
bool fLinux = false;
#endif
#ifdef RT_OS_WINDOWS
bool fWin = true;
#else
bool fWin = false;
#endif
#ifdef RT_OS_SOLARIS
bool fSolaris = true;
#else
bool fSolaris = false;
#endif
#ifdef RT_OS_DARWIN
bool fDarwin = true;
#else
bool fDarwin = false;
#endif
#ifdef VBOX_WITH_VRDP
bool fVRDP = true;
#else
bool fVRDP = false;
#endif
if (u64Cmd == USAGE_DUMPOPTS)
{
fLinux = true;
fWin = true;
fSolaris = true;
fDarwin = true;
fVRDP = true;
}
RTPrintf("Usage:\n"
"\n");
{
RTPrintf("VBoxManage [-v|-version] print version number and exit\n"
"VBoxManage -nologo ... suppress the logo\n"
"\n"
"VBoxManage -convertSettings ... allow to auto-convert settings files\n"
"VBoxManage -convertSettingsBackup ... allow to auto-convert settings files\n"
" but create backup copies before\n"
"VBoxManage -convertSettingsIgnore ... allow to auto-convert settings files\n"
" but don't explicitly save the results\n"
"\n");
}
if (u64Cmd & USAGE_LIST)
{
RTPrintf("VBoxManage list vms|runningvms|ostypes|hostdvds|hostfloppies|\n"
" hostifs|hostinfo|hddbackends|hdds|dvds|floppies|\n"
" usbhost|usbfilters|systemproperties\n"
"\n");
}
if (u64Cmd & USAGE_SHOWVMINFO)
{
RTPrintf("VBoxManage showvminfo <uuid>|<name>\n"
" [-details]\n"
" [-statistics]\n"
" [-machinereadable]\n"
"\n");
}
if (u64Cmd & USAGE_REGISTERVM)
{
RTPrintf("VBoxManage registervm <filename>\n"
"\n");
}
if (u64Cmd & USAGE_UNREGISTERVM)
{
RTPrintf("VBoxManage unregistervm <uuid>|<name>\n"
" [-delete]\n"
"\n");
}
if (u64Cmd & USAGE_CREATEVM)
{
RTPrintf("VBoxManage createvm -name <name>\n"
" [-ostype <ostype>]\n"
" [-register]\n"
" [-basefolder <path> | -settingsfile <path>]\n"
" [-uuid <uuid>]\n"
"\n");
}
if (u64Cmd & USAGE_IMPORTAPPLIANCE)
{
RTPrintf("VBoxManage import <ovf>\n"
"\n");
}
if (u64Cmd & USAGE_MODIFYVM)
{
RTPrintf("VBoxManage modifyvm <uuid|name>\n"
" [-name <name>]\n"
" [-ostype <ostype>]\n"
" [-memory <memorysize in MB>]\n"
" [-vram <vramsize in MB>]\n"
" [-acpi on|off]\n"
" [-ioapic on|off]\n"
" [-pae on|off]\n"
" [-hwvirtex on|off|default]\n"
" [-nestedpaging on|off]\n"
" [-vtxvpid on|off]\n"
" [-monitorcount <number>]\n"
" [-accelerate3d <on|off>]\n"
" [-bioslogofadein on|off]\n"
" [-bioslogofadeout on|off]\n"
" [-bioslogodisplaytime <msec>]\n"
" [-bioslogoimagepath <imagepath>]\n"
" [-biosbootmenu disabled|menuonly|messageandmenu]\n"
" [-biossystemtimeoffset <msec>]\n"
" [-biospxedebug on|off]\n"
" [-boot<1-4> none|floppy|dvd|disk|net>]\n"
" [-hd<a|b|d> none|<uuid>|<filename>]\n"
" [-idecontroller PIIX3|PIIX4]\n"
#ifdef VBOX_WITH_AHCI
" [-sata on|off]\n"
" [-sataportcount <1-30>]\n"
" [-sataport<1-30> none|<uuid>|<filename>]\n"
" [-sataideemulation<1-4> <1-30>]\n"
#endif
" [-dvd none|<uuid>|<filename>|host:<drive>]\n"
" [-dvdpassthrough on|off]\n"
" [-floppy disabled|empty|<uuid>|\n"
" <filename>|host:<drive>]\n"
#ifdef RT_OS_LINUX
" [-nic<1-N> none|null|nat|hostif|intnet|hostonly]\n"
#else /* !RT_OS_LINUX */
" [-nic<1-N> none|null|nat|hostif|intnet]\n"
#endif /* !RT_OS_LINUX */
" [-nictype<1-N> Am79C970A|Am79C973"
#ifdef VBOX_WITH_E1000
"|82540EM|82543GC"
#endif
"]\n"
" [-cableconnected<1-N> on|off]\n"
" [-nictrace<1-N> on|off]\n"
" [-nictracefile<1-N> <filename>]\n"
" [-nicspeed<1-N> <kbps>]\n"
" [-hostifdev<1-N> none|<devicename>]\n"
" [-intnet<1-N> <network name>]\n"
" [-natnet<1-N> <network>|default]\n"
" [-macaddress<1-N> auto|<mac>]\n"
" [-uart<1-N> off|<I/O base> <IRQ>]\n"
" [-uartmode<1-N> disconnected|\n"
" server <pipe>|\n"
" client <pipe>|\n"
" <devicename>]\n"
#ifdef VBOX_WITH_MEM_BALLOONING
" [-guestmemoryballoon <balloonsize in MB>]\n"
#endif
" [-gueststatisticsinterval <seconds>]\n"
);
RTPrintf(" [-audio none|null");
if (fWin)
{
#ifdef VBOX_WITH_WINMM
RTPrintf( "|winmm|dsound");
#else
RTPrintf( "|dsound");
#endif
}
if (fSolaris)
{
RTPrintf( "|solaudio");
}
if (fLinux)
{
RTPrintf( "|oss"
#ifdef VBOX_WITH_ALSA
"|alsa"
#endif
#ifdef VBOX_WITH_PULSE
"|pulse"
#endif
);
}
if (fDarwin)
{
RTPrintf( "|coreaudio");
}
RTPrintf( "]\n");
RTPrintf(" [-audiocontroller ac97|sb16]\n"
" [-clipboard disabled|hosttoguest|guesttohost|\n"
" bidirectional]\n");
if (fVRDP)
{
RTPrintf(" [-vrdp on|off]\n"
" [-vrdpport default|<port>]\n"
" [-vrdpaddress <host>]\n"
" [-vrdpauthtype null|external|guest]\n"
" [-vrdpmulticon on|off]\n"
" [-vrdpreusecon on|off]\n");
}
RTPrintf(" [-usb on|off]\n"
" [-usbehci on|off]\n"
" [-snapshotfolder default|<path>]\n");
RTPrintf("\n");
}
if (u64Cmd & USAGE_STARTVM)
{
RTPrintf("VBoxManage startvm <uuid>|<name>\n");
if (fVRDP)
RTPrintf(" [-type gui|vrdp]\n");
RTPrintf("\n");
}
if (u64Cmd & USAGE_CONTROLVM)
{
RTPrintf("VBoxManage controlvm <uuid>|<name>\n"
" pause|resume|reset|poweroff|savestate|\n"
" acpipowerbutton|acpisleepbutton|\n"
" keyboardputscancode <hex> [<hex> ...]|\n"
" injectnmi|\n"
" setlinkstate<1-4> on|off |\n"
" usbattach <uuid>|<address> |\n"
" usbdetach <uuid>|<address> |\n"
" dvdattach none|<uuid>|<filename>|host:<drive> |\n"
" floppyattach none|<uuid>|<filename>|host:<drive> |\n");
if (fVRDP)
{
RTPrintf(" vrdp on|off] |\n");
}
RTPrintf(" setvideomodehint <xres> <yres> <bpp> [display]|\n"
" setcredentials <username> <password> <domain>\n"
" [-allowlocallogon <yes|no>]\n"
"\n");
}
if (u64Cmd & USAGE_DISCARDSTATE)
{
RTPrintf("VBoxManage discardstate <uuid>|<name>\n"
"\n");
}
if (u64Cmd & USAGE_ADOPTSTATE)
{
RTPrintf("VBoxManage adoptstate <uuid>|<name> <state_file>\n"
"\n");
}
if (u64Cmd & USAGE_SNAPSHOT)
{
RTPrintf("VBoxManage snapshot <uuid>|<name>\n"
" take <name> [-desc <desc>] |\n"
" discard <uuid>|<name> |\n"
" discardcurrent -state|-all |\n"
" edit <uuid>|<name>|-current\n"
" [-newname <name>]\n"
" [-newdesc <desc>] |\n"
" showvminfo <uuid>|<name>\n"
"\n");
}
if (u64Cmd & USAGE_REGISTERIMAGE)
{
RTPrintf("VBoxManage openmedium disk|dvd|floppy <filename>\n"
" [-type normal|immutable|writethrough] (disk only)\n"
"\n");
}
if (u64Cmd & USAGE_UNREGISTERIMAGE)
{
RTPrintf("VBoxManage closemedium disk|dvd|floppy <uuid>|<filename>\n"
"\n");
}
if (u64Cmd & USAGE_SHOWHDINFO)
{
RTPrintf("VBoxManage showhdinfo <uuid>|<filename>\n"
"\n");
}
if (u64Cmd & USAGE_CREATEHD)
{
/// @todo NEWMEDIA add -format to specify the hard disk backend
RTPrintf("VBoxManage createhd -filename <filename>\n"
" -size <megabytes>\n"
" [-format VDI|VMDK|VHD]\n"
" [-static]\n"
" [-comment <comment>]\n"
" [-register]\n"
" [-type normal|writethrough] (default: normal)\n"
"\n");
}
if (u64Cmd & USAGE_MODIFYHD)
{
RTPrintf("VBoxManage modifyhd <uuid>|<filename>\n"
" settype normal|writethrough|immutable |\n"
" compact\n"
"\n");
}
if (u64Cmd & USAGE_CLONEHD)
{
RTPrintf("VBoxManage clonehd <uuid>|<filename> <outputfile>\n"
" [-format VDI|VMDK|VHD|RAW|<other>]\n"
" [-remember]\n"
"\n");
}
if (u64Cmd & USAGE_CONVERTFROMRAW)
{
RTPrintf("VBoxManage convertfromraw [-static] [-format VDI|VMDK|VHD]\n"
" <filename> <outputfile>\n"
"VBoxManage convertfromraw [-static] [-format VDI|VMDK|VHD]\n"
" stdin <outputfile> <bytes>\n"
"\n");
}
if (u64Cmd & USAGE_ADDISCSIDISK)
{
RTPrintf("VBoxManage addiscsidisk -server <name>|<ip>\n"
" -target <target>\n"
" [-port <port>]\n"
" [-lun <lun>]\n"
" [-encodedlun <lun>]\n"
" [-username <username>]\n"
" [-password <password>]\n"
" [-comment <comment>]\n"
" [-intnet]\n"
"\n");
}
if (u64Cmd & USAGE_GETEXTRADATA)
{
RTPrintf("VBoxManage getextradata global|<uuid>|<name>\n"
" <key>|enumerate\n"
"\n");
}
if (u64Cmd & USAGE_SETEXTRADATA)
{
RTPrintf("VBoxManage setextradata global|<uuid>|<name>\n"
" <key>\n"
" [<value>] (no value deletes key)\n"
"\n");
}
if (u64Cmd & USAGE_SETPROPERTY)
{
RTPrintf("VBoxManage setproperty hdfolder default|<folder> |\n"
" machinefolder default|<folder> |\n"
" vrdpauthlibrary default|<library> |\n"
" websrvauthlibrary default|null|<library> |\n"
" hwvirtexenabled yes|no\n"
" loghistorycount <value>\n"
"\n");
}
if (u64Cmd & USAGE_USBFILTER_ADD)
{
RTPrintf("VBoxManage usbfilter add <index,0-N>\n"
" -target <uuid>|<name>|global\n"
" -name <string>\n"
" -action ignore|hold (global filters only)\n"
" [-active yes|no] (yes)\n"
" [-vendorid <XXXX>] (null)\n"
" [-productid <XXXX>] (null)\n"
" [-revision <IIFF>] (null)\n"
" [-manufacturer <string>] (null)\n"
" [-product <string>] (null)\n"
" [-remote yes|no] (null, VM filters only)\n"
" [-serialnumber <string>] (null)\n"
" [-maskedinterfaces <XXXXXXXX>]\n"
"\n");
}
if (u64Cmd & USAGE_USBFILTER_MODIFY)
{
RTPrintf("VBoxManage usbfilter modify <index,0-N>\n"
" -target <uuid>|<name>|global\n"
" [-name <string>]\n"
" [-action ignore|hold] (global filters only)\n"
" [-active yes|no]\n"
" [-vendorid <XXXX>|\"\"]\n"
" [-productid <XXXX>|\"\"]\n"
" [-revision <IIFF>|\"\"]\n"
" [-manufacturer <string>|\"\"]\n"
" [-product <string>|\"\"]\n"
" [-remote yes|no] (null, VM filters only)\n"
" [-serialnumber <string>|\"\"]\n"
" [-maskedinterfaces <XXXXXXXX>]\n"
"\n");
}
if (u64Cmd & USAGE_USBFILTER_REMOVE)
{
RTPrintf("VBoxManage usbfilter remove <index,0-N>\n"
" -target <uuid>|<name>|global\n"
"\n");
}
if (u64Cmd & USAGE_SHAREDFOLDER_ADD)
{
RTPrintf("VBoxManage sharedfolder add <vmname>|<uuid>\n"
" -name <name> -hostpath <hostpath>\n"
" [-transient] [-readonly]\n"
"\n");
}
if (u64Cmd & USAGE_SHAREDFOLDER_REMOVE)
{
RTPrintf("VBoxManage sharedfolder remove <vmname>|<uuid>\n"
" -name <name> [-transient]\n"
"\n");
}
if (u64Cmd & USAGE_VM_STATISTICS)
{
RTPrintf("VBoxManage vmstatistics <vmname>|<uuid> [-reset]\n"
" [-pattern <pattern>] [-descriptions]\n"
"\n");
}
#ifdef VBOX_WITH_GUEST_PROPS
if (u64Cmd & USAGE_GUESTPROPERTY)
#endif /* VBOX_WITH_GUEST_PROPS defined */
if (u64Cmd & USAGE_METRICS)
{
RTPrintf("VBoxManage metrics list [*|host|<vmname> [<metric_list>]] (comma-separated)\n\n"
"VBoxManage metrics setup\n"
" [-period <seconds>]\n"
" [-samples <count>]\n"
" [-list]\n"
" [*|host|<vmname> [<metric_list>]]\n\n"
"VBoxManage metrics query [*|host|<vmname> [<metric_list>]]\n\n"
"VBoxManage metrics collect\n"
" [-period <seconds>]\n"
" [-samples <count>]\n"
" [-list]\n"
" [-detach]\n"
" [*|host|<vmname> [<metric_list>]]\n"
"\n");
}
}
/**
* Print a usage synopsis and the syntax error message.
*/
{
showLogo(); // show logo even if suppressed
#ifndef VBOX_ONLY_DOCS
if (g_fInternalMode)
else
#endif /* !VBOX_ONLY_DOCS */
RTPrintf("\n"
return 1;
}
/**
* Print an error message without the syntax stuff.
*/
int errorArgument(const char *pszFormat, ...)
{
return 1;
}
#ifndef VBOX_ONLY_DOCS
/**
* Print out progress on the console
*/
{
LONG lastPercent = 0;
RTPrintf("0%%...");
{
/* did we cross a 10% mark? */
{
/* make sure to also print out missed steps */
for (LONG curVal = (lastPercent / 10) * 10 + 10; curVal <= (currentPercent / 10) * 10; curVal += 10)
{
if (curVal < 100)
{
}
}
}
if (fCompleted)
break;
/* make sure the loop is not too tight */
}
/* complete the line. */
{
RTPrintf("100%%\n");
else
RTPrintf("FAILED\n");
}
else
RTPrintf("\n");
}
static int handleRegisterVM(HandlerArg *a)
{
if (a->argc != 1)
{
}
}
static int handleUnregisterVM(HandlerArg *a)
{
/* assume it's a UUID */
{
/* must be a name */
}
if (machine)
{
{
/* are we supposed to delete the config file? */
{
}
}
}
}
static int handleCreateVM(HandlerArg *a)
{
bool fRegister = false;
RTUuidClear(&id);
for (int i = 0; i < a->argc; i++)
{
{
if (a->argc <= i + 1)
i++;
baseFolder = a->argv[i];
}
{
if (a->argc <= i + 1)
i++;
settingsFile = a->argv[i];
}
{
if (a->argc <= i + 1)
i++;
}
{
if (a->argc <= i + 1)
i++;
}
{
if (a->argc <= i + 1)
i++;
}
{
fRegister = true;
}
else
}
if (!name)
if (!!baseFolder && !!settingsFile)
do
{
if (!settingsFile)
else
if (fRegister)
{
}
RTPrintf("Virtual machine '%ls' is created%s.\n"
"UUID: %s\n"
"Settings file: '%ls'\n",
}
while (0);
}
/**
* Parses a number.
*
* @returns Valid number on success.
* @returns 0 if invalid number. All necesary bitching has been done.
* @param psz Pointer to the nic number.
*/
{
char *pszNext;
if ( RT_SUCCESS(rc)
&& *pszNext == '\0'
&& u32 >= 1
return (unsigned)u32;
return 0;
}
/** @todo refine this after HDD changes; MSC 8.0/64 has trouble with handleModifyVM. */
#if defined(_MSC_VER)
#endif
static int handleStartVM(HandlerArg *a)
{
if (a->argc < 1)
/* assume it's a UUID */
{
/* must be a name */
}
if (machine)
{
/* default to GUI session type */
/* has a session type been specified? */
{
{
sessionType = "gui";
}
{
sessionType = "vrdp";
}
{
sessionType = "capture";
}
else
}
#ifdef RT_OS_LINUX
/* make sure the VM process will start on the same display as VBoxManage */
{
if (display)
}
#endif
RTPrintf("Waiting for the remote session to open...\n");
if (FAILED(resultCode))
{
}
else
{
RTPrintf("Remote session has been successfully opened.\n");
}
}
/* it's important to always close sessions */
}
static int handleControlVM(HandlerArg *a)
{
if (a->argc < 2)
/* try to find the given machine */
{
}
else
{
}
return 1;
/* open a session for the VM */
do
{
/* get the associated console */
/* ... and session machine */
/* which command? */
{
}
{
}
{
}
{
}
{
{
if (info.isBasicAvailable())
{
}
else
{
RTPrintf("Error: failed to save machine state. No error message available!\n");
}
}
}
{
}
{
}
{
/* get the machine debugger. */
}
{
{
errorArgument("Missing argument to '%s'. Expected IBM PC AT set 2 keyboard scancode(s) as hex byte(s).", a->argv[1]);
break;
}
/* Arbitrary restrict the length of a sequence of scancodes to 1024. */
int cScancodes = 0;
/* Process the command line. */
int i;
{
if ( RT_C_IS_XDIGIT (a->argv[i][0])
&& a->argv[i][2] == 0)
{
if (RT_FAILURE (rc))
{
break;
}
}
else
{
break;
}
}
break;
&& i < a->argc)
{
break;
}
/* Send scancodes to the VM.
* Note: 'PutScancodes' did not work here. Only the first scancode was transmitted.
*/
for (i = 0; i < cScancodes; i++)
{
}
}
{
/* Get the number of network adapters */
ULONG NetworkAdapterCount = 0;
if (!n)
{
break;
}
{
break;
}
/* get the corresponding network adapter */
if (adapter)
{
{
}
{
}
else
{
break;
}
}
}
#ifdef VBOX_WITH_VRDP
{
{
break;
}
/* get the corresponding VRDP server */
if (vrdpServer)
{
{
}
{
}
else
{
break;
}
}
}
#endif /* VBOX_WITH_VRDP */
{
if (a->argc < 3)
{
break;
}
{
// assume address
if (attach)
{
}
else
{
}
}
if (attach)
else
{
}
}
{
{
break;
}
uint32_t displayIdx = 0;
if (a->argc == 6)
}
{
bool fAllowLocalLogon = true;
if (a->argc == 7)
{
{
break;
}
fAllowLocalLogon = false;
}
else if (a->argc != 5)
{
break;
}
CHECK_ERROR_BREAK(guest, SetCredentials(Bstr(a->argv[2]), Bstr(a->argv[3]), Bstr(a->argv[4]), fAllowLocalLogon));
}
{
if (a->argc != 3)
{
break;
}
/* unmount? */
{
}
/* host drive? */
{
if (!hostDVDDrive)
{
errorArgument("Invalid host DVD drive name");
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 (!dvdImage)
{
}
}
if (!dvdImage)
{
break;
}
}
}
{
if (a->argc != 3)
{
break;
}
/* unmount? */
{
}
/* host drive? */
{
if (!hostFloppyDrive)
{
errorArgument("Invalid host floppy drive name");
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 (!floppyImage)
{
}
}
if (!floppyImage)
{
break;
}
}
}
#ifdef VBOX_WITH_MEM_BALLOONING
{
if (a->argc != 3)
{
break;
}
int vrc;
if (vrc != VINF_SUCCESS)
{
break;
}
/* guest is running; update IGuest */
}
#endif
{
if (a->argc != 3)
{
break;
}
int vrc;
if (vrc != VINF_SUCCESS)
{
break;
}
/* guest is running; update IGuest */
}
else
{
}
}
while (0);
}
static int handleDiscardState(HandlerArg *a)
{
if (a->argc != 1)
/* assume it's a UUID */
{
/* must be a name */
}
if (machine)
{
do
{
/* we have to open a session for this task */
do
{
}
while (0);
}
while (0);
}
}
static int handleAdoptdState(HandlerArg *a)
{
if (a->argc != 2)
/* assume it's a UUID */
{
/* must be a name */
}
if (machine)
{
do
{
/* we have to open a session for this task */
do
{
}
while (0);
}
while (0);
}
}
static int handleSnapshot(HandlerArg *a)
{
/* we need at least a VM and a command */
if (a->argc < 2)
/* the first argument must be the VM */
/* assume it's a UUID */
{
/* must be a name */
}
if (!machine)
return 1;
do
{
/* we have to open a session for this task. First try an existing session */
/* switch based on the command */
{
/* there must be a name */
if (a->argc < 3)
{
break;
}
{
break;
}
if (a->argc == 5)
{
if (info.isBasicAvailable())
else
RTPrintf("Error: failed to take snapshot. No error message available!\n");
}
}
{
/* exactly one parameter: snapshot name */
if (a->argc != 3)
{
break;
}
/* assume it's a UUID */
{
}
else
{
/* then it must be a name */
}
{
if (info.isBasicAvailable())
else
RTPrintf("Error: failed to discard snapshot. No error message available!\n");
}
}
{
if ( (a->argc != 3)
{
break;
}
bool fAll = false;
fAll = true;
if (fAll)
{
}
else
{
}
{
if (info.isBasicAvailable())
else
RTPrintf("Error: failed to discard. No error message available!\n");
}
}
{
if (a->argc < 3)
{
break;
}
{
}
else
{
/* assume it's a UUID */
{
}
else
{
/* then it must be a name */
}
}
/* parse options */
for (int i = 3; i < a->argc; i++)
{
{
if (a->argc <= i + 1)
{
break;
}
i++;
}
{
if (a->argc <= i + 1)
{
break;
}
i++;
}
else
{
break;
}
}
}
{
/* exactly one parameter: snapshot name */
if (a->argc != 3)
{
break;
}
/* assume it's a UUID */
{
}
else
{
/* then it must be a name */
}
/* get the machine of the given snapshot */
}
else
{
}
} while (0);
}
static int handleGetExtraData(HandlerArg *a)
{
if (a->argc != 2)
/* global data? */
{
/* enumeration? */
{
do
{
} while (extraDataKey);
}
else
{
if (value)
else
RTPrintf("No value set!\n");
}
}
else
{
/* assume it's a UUID */
{
/* must be a name */
}
if (machine)
{
/* enumeration? */
{
do
{
{
}
} while (extraDataKey);
}
else
{
if (value)
else
RTPrintf("No value set!\n");
}
}
}
}
static int handleSetExtraData(HandlerArg *a)
{
if (a->argc < 2)
/* global data? */
{
if (a->argc < 3)
else if (a->argc == 3)
else
}
else
{
/* assume it's a UUID */
{
/* must be a name */
}
if (machine)
{
if (a->argc < 3)
else if (a->argc == 3)
else
}
}
}
static int handleSetProperty(HandlerArg *a)
{
/* there must be two arguments: property name and value */
if (a->argc != 2)
{
/* reset to default? */
else
}
{
/* reset to default? */
else
}
{
/* reset to default? */
else
}
{
/* reset to default? */
else
}
{
else
}
{
int vrc;
if (vrc != VINF_SUCCESS)
}
else
}
static int handleUSBFilter (HandlerArg *a)
{
/* at least: 0: command, 1: index, 2: -target, 3: <target value> */
if (a->argc < 4)
/* which command? */
/* which index? */
{
case USBFilterCmd::Add:
case USBFilterCmd::Modify:
{
/* at least: 0: command, 1: index, 2: -target, 3: <target value>, 4: -name, 5: <name value> */
if (a->argc < 6)
{
}
// set Active to true by default
// (assuming that the user sets up all necessary attributes
// at once and wants the filter to be active immediately)
for (int i = 2; i < a->argc; i++)
{
{
i++;
else
{
/* assume it's a UUID of a machine */
{
/* must be a name */
}
}
}
{
i++;
}
{
if (a->argc <= i + 1)
i++;
else
}
{
if (a->argc <= i + 1)
i++;
}
{
if (a->argc <= i + 1)
i++;
}
{
if (a->argc <= i + 1)
i++;
}
{
if (a->argc <= i + 1)
i++;
}
{
if (a->argc <= i + 1)
i++;
}
{
if (a->argc <= i + 1)
i++;
}
{
if (a->argc <= i + 1)
i++;
}
{
if (a->argc <= i + 1)
i++;
if (RT_FAILURE(rc))
return errorArgument("Failed to convert the -maskedinterfaces value '%s' to a number, rc=%Rrc", a->argv[i], rc);
}
{
if (a->argc <= i + 1)
i++;
else
}
else
"Unknown option '%s'", a->argv[i]);
}
{
||
)
)
{
}
}
break;
}
case USBFilterCmd::Remove:
{
/* at least: 0: command, 1: index, 2: -target, 3: <target value> */
if (a->argc < 4)
for (int i = 2; i < a->argc; i++)
{
{
i++;
else
{
/* assume it's a UUID of a machine */
{
/* must be a name */
}
}
}
}
// mandatory options
break;
}
default: break;
}
else
{
/* open a session for the VM */
/* get the mutable session machine */
/* and get the USB controller */
}
{
case USBFilterCmd::Add:
{
{
if (!f.mProductId.isNull())
if (!f.mManufacturer.isNull())
if (!f.mSerialNumber.isNull())
if (!f.mMaskedInterfaces.isNull())
if (f.mAction != USBDeviceFilterAction_Null)
}
else
{
if (!f.mProductId.isNull())
if (!f.mManufacturer.isNull())
if (!f.mSerialNumber.isNull())
if (!f.mMaskedInterfaces.isNull())
}
break;
}
case USBFilterCmd::Modify:
{
{
if (!f.mProductId.isNull())
if (!f.mManufacturer.isNull())
if (!f.mSerialNumber.isNull())
if (!f.mMaskedInterfaces.isNull())
if (f.mAction != USBDeviceFilterAction_Null)
}
else
{
if (!f.mProductId.isNull())
if (!f.mManufacturer.isNull())
if (!f.mSerialNumber.isNull())
if (!f.mMaskedInterfaces.isNull())
}
break;
}
case USBFilterCmd::Remove:
{
{
}
else
{
}
break;
}
default:
break;
}
{
/* commit and close the session */
}
}
static int handleSharedFolder (HandlerArg *a)
{
/* we need at least a command and target */
if (a->argc < 2)
/* assume it's a UUID */
{
/* must be a name */
}
if (!machine)
return 1;
{
/* we need at least four more parameters */
if (a->argc < 5)
bool fTransient = false;
bool fWritable = true;
for (int i = 2; i < a->argc; i++)
{
{
i++;
}
{
i++;
}
{
fWritable = false;
}
{
fTransient = true;
}
else
}
/* required arguments */
{
}
if (fTransient)
{
/* open an existing session for the VM */
/* get the session machine */
/* get the session console */
if (console)
}
else
{
/* open a session for the VM */
/* get the mutable session machine */
}
}
{
/* we need at least two more parameters */
if (a->argc < 3)
bool fTransient = false;
for (int i = 2; i < a->argc; i++)
{
{
i++;
}
{
fTransient = true;
}
else
}
/* required arguments */
if (!name)
if (fTransient)
{
/* open an existing session for the VM */
/* get the session machine */
/* get the session console */
if (console)
}
else
{
/* open a session for the VM */
/* get the mutable session machine */
/* commit and close the session */
}
}
else
return 0;
}
static int handleVMStatistics(HandlerArg *a)
{
/* at least one option: the UUID or name of the VM */
if (a->argc < 1)
/* try to find the given machine */
else
{
}
return 1;
/* parse arguments. */
bool fReset = false;
bool fWithDescriptions = false;
for (int i = 1; i < a->argc; i++)
{
{
if (pszPattern)
if (i + 1 >= a->argc)
pszPattern = a->argv[++i];
}
fWithDescriptions = true;
/* add: -file <filename> and -formatted */
fReset = true;
else
}
if (fReset && fWithDescriptions)
/* open an existing session for the VM. */
{
/* get the session console. */
{
/* get the machine debugger. */
{
if (fReset)
else
{
{
/* if (fFormatted)
{ big mess }
else
*/
}
}
}
}
}
}
#endif /* !VBOX_ONLY_DOCS */
enum ConvertSettings
{
ConvertSettings_No = 0,
ConvertSettings_Yes = 1,
};
#ifndef VBOX_ONLY_DOCS
/**
* Checks if any of the settings files were auto-converted and informs the
* user if so.
*
* @return @false if the program should terminate and @true otherwise.
*/
{
/* return early if nothing to do */
return true;
do
{
bool isGlobalConverted = false;
{
if (!accessible)
continue;
if (version != formatVersion)
{
}
}
break;
if (version != formatVersion)
{
isGlobalConverted = true;
}
{
switch (fConvertSettings)
{
case ConvertSettings_No:
{
RTPrintf (
"WARNING! The following VirtualBox settings files have been automatically\n"
"converted to the new settings file format version '%ls':\n"
"\n",
formatVersion.raw());
RTPrintf (
"\n"
"The current command was aborted to prevent overwriting the above settings\n"
"files with the results of the auto-conversion without your permission.\n"
"Please put one of the following command line switches to the beginning of\n"
"the VBoxManage command line and repeat the command:\n"
"\n"
" -convertSettings - to save all auto-converted files (it will not\n"
" be possible to use these settings files with an\n"
" older version of VirtualBox in the future);\n"
" -convertSettingsBackup - to create backup copies of the settings files in\n"
" the old format before saving them in the new format;\n"
" -convertSettingsIgnore - to not save the auto-converted settings files.\n"
"\n"
"Note that if you use -convertSettingsIgnore, the auto-converted settings files\n"
"will be implicitly saved in the new format anyway once you change a setting or\n"
"start a virtual machine, but NO backup copies will be created in this case.\n");
return false;
}
case ConvertSettings_Yes:
case ConvertSettings_Backup:
{
break;
}
default:
AssertFailedReturn (false);
}
m != cvtMachines.end(); ++ m)
{
/* open a session for the VM */
else
break;
}
break;
if (isGlobalConverted)
{
else
}
break;
}
}
while (0);
}
#endif /* !VBOX_ONLY_DOCS */
// main
///////////////////////////////////////////////////////////////////////////////
{
/*
* Before we do anything, init the runtime without loading
* the support driver.
*/
RTR3Init();
bool fShowLogo = true;
int iCmd = 1;
int iCmdArg;
/* global options */
{
{
showLogo();
return 0;
}
{
/* Print version number, and do nothing else. */
return 0;
}
{
/* Special option to dump really all commands,
* even the ones not understood on this platform. */
return 0;
}
{
/* suppress the logo */
fShowLogo = false;
iCmd++;
}
{
iCmd++;
}
{
iCmd++;
}
{
iCmd++;
}
else
{
break;
}
}
if (fShowLogo)
showLogo();
#ifdef VBOX_ONLY_DOCS
int rc = 0;
#else /* !VBOX_ONLY_DOCS */
{
RTPrintf("ERROR: failed to initialize COM!\n");
return rc;
}
/*
* The input is in the host OS'es codepage (NT guarantees ACP).
* For VBox we use UTF-8 and convert to UCS-2 when calling (XP)COM APIs.
* For simplicity, just convert the argv[] array here.
*/
{
char *converted;
}
do
{
// scopes all the stuff till shutdown
////////////////////////////////////////////////////////////////////////////
/* convertfromraw: does not need a VirtualBox instantiation. */
{
break;
}
RTPrintf("ERROR: failed to create the VirtualBox object!\n");
else
{
RTPrintf("ERROR: failed to create a session object!\n");
}
{
{
RTPrintf("Most likely, the VirtualBox COM server is not running or failed to start.\n");
}
else
break;
}
/* create the event queue
* after the session is closed) */
#ifdef USE_XPCOM_QUEUE
#endif
break;
#ifdef USE_XPCOM_QUEUE
#else
#endif
/*
* All registered command handlers
*/
struct
{
const char *command;
} commandHandlers[] =
{
{ "internalcommands", handleInternalCommands },
{ "list", handleList },
{ "showvminfo", handleShowVMInfo },
{ "registervm", handleRegisterVM },
{ "unregistervm", handleUnregisterVM },
{ "createhd", handleCreateHardDisk },
{ "modifyhd", handleModifyHardDisk },
{ "clonehd", handleCloneHardDisk },
{ "addiscsidisk", handleAddiSCSIDisk },
{ "createvm", handleCreateVM },
{ "modifyvm", handleModifyVM },
{ "startvm", handleStartVM },
{ "controlvm", handleControlVM },
{ "discardstate", handleDiscardState },
{ "adoptstate", handleAdoptdState },
{ "snapshot", handleSnapshot },
{ "openmedium", handleOpenMedium },
{ "closemedium", handleCloseMedium },
{ "showhdinfo", handleShowHardDiskInfo },
{ "getextradata", handleGetExtraData },
{ "setextradata", handleSetExtraData },
{ "setproperty", handleSetProperty },
{ "usbfilter", handleUSBFilter },
{ "sharedfolder", handleSharedFolder },
{ "vmstatistics", handleVMStatistics },
#ifdef VBOX_WITH_GUEST_PROPS
{ "guestproperty", handleGuestProperty },
#endif /* VBOX_WITH_GUEST_PROPS defined */
{ "metrics", handleMetrics },
{ "import", handleImportAppliance },
};
int commandIndex;
{
{
break;
}
}
{
}
/* Although all handlers should always close the session if they open it,
* we do it here just in case if some of the handlers contains a bug --
* leaving the direct session not closed will turn the machine state to
* Aborted which may have unwanted side effects like killing the saved
* state file (if the machine was in the Saved state before). */
#ifdef USE_XPCOM_QUEUE
#endif
// end "all-stuff" scope
////////////////////////////////////////////////////////////////////////////
}
while (0);
#endif /* !VBOX_ONLY_DOCS */
/*
* Free converted argument vector
*/
return rc != 0;
}