VBoxManage.cpp revision 06067a5d98f6a5d64c908d7d9e79bfde9054d1bb
/* $Id$ */
/** @file
* VBoxManage - VirtualBox's command-line interface.
*/
/*
* Copyright (C) 2006-2007 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 <stdlib.h>
#include <stdarg.h>
#include <vector>
#include <list>
#endif /* !VBOX_ONLY_DOCS */
#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 DECLCALLBACK(int) FNHANDLER(int argc, char *argv[], ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession);
typedef FNHANDLER *PFNHANDLER;
#ifdef USE_XPCOM_QUEUE
/** A pointer to the event queue, set by main() before calling any handlers. */
#endif
/**
* 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-2008 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"
" [-register]\n"
" [-basefolder <path> | -settingsfile <path>]\n"
" [-uuid <uuid>]\n"
" \n"
"\n");
}
if (u64Cmd & USAGE_MODIFYVM)
{
RTPrintf("VBoxManage modifyvm <uuid|name>\n"
" [-name <name>]\n"
" [-ostype <ostype>]\n"
" [-memory <memorysize>]\n"
" [-vram <vramsize>]\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"
" [-nic<1-N> none|null|nat|hostif|intnet]\n"
" [-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>]\n"
#endif
" [-gueststatisticsinterval <seconds>]\n"
);
if (fLinux)
{
RTPrintf(" [-tapsetup<1-N> none|<application>]\n"
" [-tapterminate<1-N> none|<application>]\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"
" 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"
" [-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"
"\n");
}
if (u64Cmd & USAGE_CONVERTDD)
{
RTPrintf("VBoxManage convertdd [-static] <filename> <outputfile>\n"
"VBoxManage convertdd [-static] 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"
"\n");
}
{
RTPrintf("VBoxManage createhostif <name>\n"
"\n");
}
{
RTPrintf("VBoxManage removehostif <uuid>|<name>\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");
}
{
if (argc != 1)
{
}
}
{
/* assume it's a UUID */
{
/* must be a name */
}
if (machine)
{
{
/* are we supposed to delete the config file? */
{
}
}
}
}
{
bool fStatic = false;
bool fRegister = false;
const char *type = "normal";
/* let's have a closer look at the arguments */
for (int i = 0; i < argc; i++)
{
{
if (argc <= i + 1)
i++;
}
{
if (argc <= i + 1)
i++;
}
{
fStatic = true;
}
{
if (argc <= i + 1)
i++;
}
{
fRegister = true;
}
{
if (argc <= i + 1)
i++;
}
else
}
/* check the outcome */
{
/* we will close the hard disk after the storage has been successfully
* created unless fRegister is set */
bool doClose = false;
if (fStatic)
{
}
else
{
}
{
if (fStatic)
else
{
{
if (info.isBasicAvailable())
else
RTPrintf("Error: failed to create hard disk. No error message available!\n");
}
else
{
{
/* nothing required, default */
}
{
}
}
}
}
if (doClose)
{
}
}
}
{
{
RTPrintf(".");
}
return VINF_SUCCESS;
}
{
if (argc < 2)
/* first guess is that it's a UUID */
/* no? then it must be a filename */
if (!hardDisk)
{
}
/* let's find out which command */
{
/* hard disk must be registered */
{
if (argc <= 2)
return errorArgument("Missing argument to for settype");
{
if (hddType != HardDiskType_Normal)
}
{
if (hddType != HardDiskType_Writethrough)
}
{
if (hddType != HardDiskType_Immutable)
}
else
{
}
}
else
return errorArgument("Hard disk image not registered");
}
{
/* the hard disk image might not be registered */
if (!hardDisk)
{
if (!hardDisk)
return errorArgument("Hard disk image not found");
}
if (format != "VDI")
return errorArgument("Invalid hard disk type. The command only works on VDI files\n");
/* make sure the object reference is released */
unsigned uProcent;
if (RT_FAILURE(vrc))
{
}
}
else
}
{
#if 1
RTPrintf("Error: Clone hard disk operation is temporarily unavailable!\n");
return 1;
#else
/* source hard disk and target path */
if (argc != 2)
/* first guess is that it's a UUID */
if (!hardDisk)
{
/* not successful? Then it must be a filename */
}
if (hardDisk)
{
{
{
if (info.isBasicAvailable())
{
}
else
{
RTPrintf("Error: failed to clone disk image. No error message available!\n");
}
}
}
}
#endif
}
{
int arg = 0;
{
arg++;
}
#else
const bool fReadFromStdIn = false;
#endif
RTPrintf("Converting VDI: from DD image file=\"%s\" to file=\"%s\"...\n",
/* open raw image file. */
int rc = VINF_SUCCESS;
if (fReadFromStdIn)
File = 0;
else
if (RT_FAILURE(rc))
{
return rc;
}
/* get image size. */
if (fReadFromStdIn)
else
if (RT_SUCCESS(rc))
{
RTPrintf("Creating %s image with size %RU64 bytes (%RU64MB)...\n", (enmImgType == VDI_IMAGE_TYPE_FIXED) ? "fixed" : "dynamic", cbFile, (cbFile + _1M - 1) / _1M);
char pszComment[256];
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
/* alloc work buffer. */
if (pvBuf)
{
{
break;
if (RT_FAILURE(rc))
break;
}
}
else
rc = VERR_NO_MEMORY;
}
if (RT_FAILURE(rc))
{
/* delete image on error */
}
}
else
}
return rc;
}
{
#if 1
RTPrintf("Error: Create iSCSI hard disk operation is temporarily unavailable!\n");
return 1;
#else
/* at least server and target */
if (argc < 4)
/* let's have a closer look at the arguments */
for (int i = 0; i < argc; i++)
{
{
if (argc <= i + 1)
i++;
}
{
if (argc <= i + 1)
i++;
}
{
if (argc <= i + 1)
i++;
}
{
/** @todo move the LUN encoding algorithm into IISCSIHardDisk, add decoding */
if (argc <= i + 1)
i++;
char *pszNext;
if (lun <= 255)
{
/* Assume bus identifier = 0. */
}
else
{
/* Check above already limited the LUN to 14 bits. */
}
}
{
if (argc <= i + 1)
i++;
char *pszNext;
}
{
if (argc <= i + 1)
i++;
}
{
if (argc <= i + 1)
i++;
}
{
if (argc <= i + 1)
i++;
}
else
}
/* check for required options */
{
if (port != UINT16_MAX)
if (lun != UINT64_MAX)
{
}
{
}
}
#endif
}
{
bool fRegister = false;
RTUuidClear(&id);
for (int i = 0; i < argc; i++)
{
{
if (argc <= i + 1)
i++;
baseFolder = argv[i];
}
{
if (argc <= i + 1)
i++;
settingsFile = argv[i];
}
{
if (argc <= i + 1)
i++;
}
{
if (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;
}
{
ULONG memorySize = 0;
char *nestedpaging = NULL;
int monitorcount = -1;
char *accelerate3d = NULL;
char *bioslogofadein = NULL;
char *bioslogofadeout = NULL;
uint32_t bioslogodisplaytime = ~0;
char *bioslogoimagepath = NULL;
char *biosbootmenumode = NULL;
char *biossystemtimeoffset = NULL;
char *biospxedebug = NULL;
int bootDeviceChanged[4] = { false };
char *hdds[34] = {0};
char *dvdpassthrough = NULL;
char *idecontroller = NULL;
char *audiocontroller = NULL;
#ifdef VBOX_WITH_VRDP
char *vrdpaddress = NULL;
char *vrdpauthtype = NULL;
char *vrdpmulticon = NULL;
char *vrdpreusecon = NULL;
#endif
int fUsbEnabled = -1;
int fUsbEhciEnabled = -1;
char *snapshotFolder = NULL;
int fSataEnabled = -1;
int sataPortCount = -1;
/* VM ID + at least one parameter. Parameter arguments are checked
* individually. */
if (argc < 2)
/* Get the number of network adapters */
ULONG NetworkAdapterCount = 0;
{
}
ULONG SerialPortCount = 0;
{
}
#ifdef RT_OS_LINUX
#endif
for (int i = 1; i < argc; i++)
{
{
if (argc <= i + 1)
i++;
}
{
if (argc <= i + 1)
i++;
}
{
if (argc <= i + 1)
i++;
}
{
if (argc <= i + 1)
i++;
}
{
if (argc <= i + 1)
i++;
}
{
if (argc <= i + 1)
i++;
}
{
if (argc <= i + 1)
i++;
}
{
if (argc <= i + 1)
i++;
nestedpaging = argv[i];
}
{
if (argc <= i + 1)
i++;
}
{
if (argc <= i + 1)
i++;
}
{
if (argc <= i + 1)
i++;
}
{
if (argc <= i + 1)
i++;
accelerate3d = argv[i];
}
{
if (argc <= i + 1)
i++;
bioslogofadein = argv[i];
}
{
if (argc <= i + 1)
i++;
bioslogofadeout = argv[i];
}
{
if (argc <= i + 1)
i++;
}
{
if (argc <= i + 1)
i++;
bioslogoimagepath = argv[i];
}
{
if (argc <= i + 1)
i++;
biosbootmenumode = argv[i];
}
{
if (argc <= i + 1)
i++;
biossystemtimeoffset = argv[i];
}
{
if (argc <= i + 1)
i++;
biospxedebug = argv[i];
}
{
ULONG n = 0;
if (!argv[i][5])
if (argc <= i + 1)
i++;
{
}
{
}
{
}
{
}
{
}
else
bootDeviceChanged[n - 1] = true;
}
{
if (argc <= i + 1)
i++;
}
{
if (argc <= i + 1)
i++;
}
{
if (argc <= i + 1)
i++;
}
{
if (argc <= i + 1)
i++;
}
{
if (argc <= i + 1)
i++;
dvdpassthrough = argv[i];
}
{
if (argc <= i + 1)
i++;
idecontroller = argv[i];
}
{
if (argc <= i + 1)
i++;
}
{
if (argc <= i + 1)
i++;
}
{
if (argc <= i + 1)
i++;
audiocontroller = argv[i];
}
{
if (argc <= i + 1)
i++;
}
{
if (!n)
return 1;
if (argc <= i + 1)
i++;
}
/* watch for the right order of these -nic* comparisons! */
{
if (!n)
return 1;
if (argc <= i + 1)
{
}
i++;
}
{
if (!n)
return 1;
if (argc <= i + 1)
i++;
}
{
if (!n)
return 1;
if (argc <= i + 1)
i++;
}
{
if (!n)
return 1;
if (argc <= i + 1)
i++;
}
{
if (!n)
return 1;
if (argc <= i + 1)
i++;
}
{
if (!n)
return 1;
if (argc <= i + 1)
i++;
}
{
if (!n)
return 1;
if (argc <= i + 1)
i++;
}
{
if (!n)
return 1;
if (argc <= i + 1)
else
{
if (RT_FAILURE(rc))
return errorArgument("Invalid IPv4 network '%s' specified -- CIDR notation expected.\n", argv[i + 1]);
if (Netmask & 0x1f)
return errorArgument("Prefix length of the NAT network must be less than 28.\n");
}
i++;
}
#ifdef RT_OS_LINUX
{
if (!n)
return 1;
if (argc <= i + 1)
i++;
}
{
if (!n)
return 1;
if (argc <= i + 1)
i++;
}
#endif /* RT_OS_LINUX */
{
if (!n)
return 1;
if (argc <= i + 1)
i++;
}
#ifdef VBOX_WITH_VRDP
{
if (argc <= i + 1)
i++;
}
{
if (argc <= i + 1)
i++;
vrdpport = 0;
else
}
{
if (argc <= i + 1)
i++;
vrdpaddress = argv[i];
}
{
if (argc <= i + 1)
i++;
vrdpauthtype = argv[i];
}
{
if (argc <= i + 1)
i++;
vrdpmulticon = argv[i];
}
{
if (argc <= i + 1)
i++;
vrdpreusecon = argv[i];
}
#endif /* VBOX_WITH_VRDP */
{
if (argc <= i + 1)
i++;
fUsbEnabled = 1;
fUsbEnabled = 0;
else
}
{
if (argc <= i + 1)
i++;
fUsbEhciEnabled = 1;
fUsbEhciEnabled = 0;
else
}
{
if (argc <= i + 1)
i++;
snapshotFolder = argv[i];
}
{
if (!n)
return 1;
i++;
{
}
else
{
{
i++;
#ifdef RT_OS_WINDOWS
return errorArgument("Uart pipe must start with \\\\.\\pipe\\");
#endif
}
else
{
}
if (argc <= i)
return errorArgument("Missing argument to -uartmode");
}
}
{
if (!n)
return 1;
if (argc <= i + 1)
i++;
{
}
else
{
if (argc <= i + 1)
int vrc;
i++;
if (vrc != VINF_SUCCESS)
}
}
#ifdef VBOX_WITH_MEM_BALLOONING
{
if (argc <= i + 1)
i++;
int vrc;
if (vrc != VINF_SUCCESS)
}
#endif
{
if (argc <= i + 1)
i++;
int vrc;
if (vrc != VINF_SUCCESS)
}
{
if (argc <= i + 1)
i++;
fSataEnabled = 1;
fSataEnabled = 0;
else
}
{
unsigned n;
if (argc <= i + 1)
i++;
if (!n)
return 1;
sataPortCount = n;
}
{
if (!n)
return 1;
if (argc <= i + 1)
i++;
}
{
unsigned bootDevicePos = 0;
unsigned n;
if (!bootDevicePos)
return 1;
if (argc <= i + 1)
i++;
if (!n)
return 1;
}
else
}
/* try to find the given machine */
{
}
else
{
}
return 1;
/* open a session for the VM */
do
{
/* get the mutable session machine */
if (name)
if (ostype)
{
{
}
else
{
break;
}
}
if (memorySize > 0)
if (vramSize > 0)
if (acpi)
{
{
}
{
}
else
{
break;
}
}
if (ioapic)
{
{
}
{
}
else
{
break;
}
}
if (hwvirtex)
{
{
}
{
}
{
}
else
{
break;
}
}
if (nestedpaging)
{
{
}
{
}
else
{
break;
}
}
if (vtxvpid)
{
{
}
{
}
else
{
break;
}
}
if (pae)
{
{
}
{
}
else
{
break;
}
}
if (monitorcount != -1)
{
}
if (accelerate3d)
{
{
}
{
}
else
{
break;
}
}
if (bioslogofadein)
{
{
}
{
}
else
{
break;
}
}
if (bioslogofadeout)
{
{
}
{
}
else
{
break;
}
}
if (bioslogodisplaytime != ~0U)
{
}
if (bioslogoimagepath)
{
}
if (biosbootmenumode)
{
else
{
break;
}
}
if (biossystemtimeoffset)
{
}
if (biospxedebug)
{
{
}
{
}
else
{
break;
}
}
{
if (bootDeviceChanged[curBootDev])
}
if (hdds[0])
{
{
}
else
{
/* 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
break;
}
}
if (hdds[1])
{
{
}
else
{
/* 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
break;
}
}
if (hdds[2])
{
{
}
else
{
/* 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
break;
}
}
if (dvd)
{
/* unmount? */
{
}
/* host drive? */
{
if (!hostDVDDrive)
{
/* 2nd try: try with the real name, important on Linux+libhal */
char szPathReal[RTPATH_MAX];
{
errorArgument("Invalid host DVD drive name");
break;
}
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 (dvdpassthrough)
{
}
if (idecontroller)
{
{
}
{
}
else
{
break;
}
}
if (floppy)
{
/* disable? */
{
/* disable the controller */
}
else
{
/* enable the controller */
/* 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;
}
}
}
}
if (audio || audiocontroller)
{
if (audio)
{
/* disable? */
{
}
{
}
#ifdef RT_OS_WINDOWS
#ifdef VBOX_WITH_WINMM
{
}
#endif
{
}
#endif /* RT_OS_WINDOWS */
#ifdef RT_OS_LINUX
{
}
# ifdef VBOX_WITH_ALSA
{
}
# endif
# ifdef VBOX_WITH_PULSE
{
}
# endif
#endif /* !RT_OS_LINUX */
#ifdef RT_OS_SOLARIS
{
}
#endif /* !RT_OS_SOLARIS */
#ifdef RT_OS_DARWIN
{
}
#endif /* !RT_OS_DARWIN */
else
{
break;
}
}
if (audiocontroller)
{
else
{
break;
}
}
}
/* Shared clipboard state */
if (clipboard)
{
/* ComPtr<IClipboardMode> clipboardMode;
machine->COMGETTER(ClipboardMode)(clipboardMode.asOutParam());
ASSERT(clipboardMode);
*/
{
}
{
}
{
}
{
}
else
{
break;
}
}
/* iterate through all possible NICs */
for (ULONG n = 0; n < NetworkAdapterCount; n ++)
{
/* something about the NIC? */
if (nics[n])
{
{
}
{
}
{
}
{
}
{
}
else
{
break;
}
}
/* something about the NIC type? */
if (nictype[n])
{
{
}
{
}
#ifdef VBOX_WITH_E1000
{
}
{
}
#endif
else
{
break;
}
}
/* something about the MAC address? */
if (macs[n])
{
/* generate one? */
{
}
else
{
}
}
/* something about the reported link speed? */
if (nicspeed[n])
{
{
break;
}
}
/* the link status flag? */
if (cableconnected[n])
{
{
}
{
}
else
{
break;
}
}
/* the trace flag? */
if (nictrace[n])
{
{
}
{
}
else
{
break;
}
}
/* the tracefile flag? */
if (nictracefile[n])
{
}
/* the host interface device? */
if (hostifdev[n])
{
/* remove it? */
{
}
else
{
}
}
/* the internal network name? */
if (intnet[n])
{
/* remove it? */
{
}
else
{
}
}
/* the network of the NAT */
if (natnet[n])
{
}
#ifdef RT_OS_LINUX
/* the TAP setup application? */
if (tapsetup[n])
{
/* remove it? */
{
}
else
{
}
}
/* the TAP terminate application? */
if (tapterm[n])
{
/* remove it? */
{
}
else
{
}
}
#endif /* RT_OS_LINUX */
}
break;
/* iterate through all possible serial ports */
for (ULONG n = 0; n < SerialPortCount; n ++)
{
if (uarts_base[n])
{
{
}
else
{
}
}
if (uarts_mode[n])
{
{
}
else
{
{
}
{
}
else
{
}
}
}
}
break;
#ifdef VBOX_WITH_VRDP
if (vrdp || (vrdpport != UINT16_MAX) || vrdpaddress || vrdpauthtype || vrdpmulticon || vrdpreusecon)
{
if (vrdpServer)
{
if (vrdp)
{
{
}
{
}
else
{
break;
}
}
if (vrdpport != UINT16_MAX)
{
}
if (vrdpaddress)
{
}
if (vrdpauthtype)
{
{
}
{
}
{
}
else
{
break;
}
}
if (vrdpmulticon)
{
{
}
{
}
else
{
break;
}
}
if (vrdpreusecon)
{
{
}
{
}
else
{
break;
}
}
}
}
#endif /* VBOX_WITH_VRDP */
/*
*/
if (fUsbEnabled != -1)
{
{
}
}
/*
*/
if (fUsbEhciEnabled != -1)
{
{
}
}
if (snapshotFolder)
{
{
}
else
{
}
}
/*
*/
if (fSataEnabled != -1)
{
{
}
}
{
if (hdds[i])
{
{
}
else
{
/* 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
break;
}
}
}
for (uint32_t i = 0; i < 4; i++)
{
if (sataBootDevices[i] != -1)
{
{
}
}
}
if (sataPortCount != -1)
{
{
}
}
/* commit changes */
}
while (0);
/* it's important to always close sessions */
}
{
if (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 */
}
{
if (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).", argv[1]);
break;
}
/* Arbitrary restrict the length of a sequence of scancodes to 1024. */
int cScancodes = 0;
/* Process the command line. */
int i;
{
&& argv[i][2] == 0)
{
if (RT_FAILURE (rc))
{
break;
}
}
else
{
break;
}
}
break;
&& i < 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;
}
}
}
{
if (argc < 3)
{
break;
}
{
// assume address
if (attach)
{
}
else
{
}
}
if (attach)
else
{
}
}
{
{
break;
}
uint32_t displayIdx = 0;
if (argc == 6)
}
{
bool fAllowLocalLogon = true;
if (argc == 7)
{
{
break;
}
fAllowLocalLogon = false;
}
else if (argc != 5)
{
break;
}
CHECK_ERROR_BREAK(guest, SetCredentials(Bstr(argv[2]), Bstr(argv[3]), Bstr(argv[4]), fAllowLocalLogon));
}
{
if (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 (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 (argc != 3)
{
break;
}
int vrc;
if (vrc != VINF_SUCCESS)
{
break;
}
/* guest is running; update IGuest */
}
#endif
{
if (argc != 3)
{
break;
}
int vrc;
if (vrc != VINF_SUCCESS)
{
break;
}
/* guest is running; update IGuest */
}
else
{
}
}
while (0);
}
{
if (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);
}
}
{
if (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);
}
}
{
/* we need at least a VM and a command */
if (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 (argc < 3)
{
break;
}
{
break;
}
if (argc == 5)
{
if (info.isBasicAvailable())
else
RTPrintf("Error: failed to take snapshot. No error message available!\n");
}
}
{
/* exactly one parameter: snapshot name */
if (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 ( (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 (argc < 3)
{
break;
}
{
}
else
{
/* assume it's a UUID */
{
}
else
{
/* then it must be a name */
}
}
/* parse options */
for (int i = 3; i < argc; i++)
{
{
if (argc <= i + 1)
{
break;
}
i++;
}
{
if (argc <= i + 1)
{
break;
}
i++;
}
else
{
break;
}
}
}
{
/* exactly one parameter: snapshot name */
if (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);
}
{
if (argc != 1)
bool unknown = false;
/* first guess is that it's a UUID */
/* no? then it must be a filename */
{
/* no? well, then it's an unkwnown image */
{
{
unknown = true;
}
}
}
do
{
break;
/* check for accessibility */
/// @todo NEWMEDIA check accessibility of all parents
/// @todo NEWMEDIA print the full state value
if (state == MediaState_Inaccessible)
{
}
if (description)
{
}
const char *typeStr = "unknown";
switch (type)
{
case HardDiskType_Normal:
typeStr = "normal";
break;
case HardDiskType_Immutable:
typeStr = "immutable";
break;
typeStr = "writethrough";
break;
}
if (!unknown)
{
{
RTPrintf("%s%lS (UUID: %RTuuid)\n",
j == 0 ? "In use by VMs: " : " ",
}
/// @todo NEWMEDIA check usage in snapshots too
/// @todo NEWMEDIA also list children and say 'differencing' for
/// hard disks with the parent or 'base' otherwise.
}
}
while (0);
if (unknown)
{
/* close the unknown hard disk to forget it again */
}
}
{
if (argc < 2)
{
/* there can be a type parameter */
if (argc == 4)
{
}
{
/* change the type if requested */
if (type)
{
}
}
}
{
}
{
}
else
}
{
if (argc != 2)
/* first guess is that it's a UUID */
{
/* not a UUID or not registered? Then it must be a filename */
if (!hardDisk)
{
}
{
}
}
else
{
/* not a UUID or not registered? Then it must be a filename */
if (!dvdImage)
{
}
{
}
}
else
{
/* not a UUID or not registered? Then it must be a filename */
if (!floppyImage)
{
}
{
}
}
else
}
#ifdef RT_OS_WINDOWS
{
if (argc != 1)
do
{
hostif.asOutParam(),
progress.asOutParam()));
{
}
}
while (0);
}
{
if (argc != 1)
do
{
/* first guess is that it's a UUID */
{
/* not a valid UUID, search for it */
}
hostif.asOutParam(),
progress.asOutParam()));
{
}
}
while (0);
}
#endif /* RT_OS_WINDOWS */
{
if (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");
}
}
}
}
{
if (argc < 2)
/* global data? */
{
if (argc < 3)
else if (argc == 3)
else
}
else
{
/* assume it's a UUID */
{
/* must be a name */
}
if (machine)
{
if (argc < 3)
else if (argc == 3)
else
}
}
}
{
/* there must be two arguments: property name and value */
if (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
}
{
/* at least: 0: command, 1: index, 2: -target, 3: <target value> */
if (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 (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 < argc; i++)
{
{
i++;
else
{
/* assume it's a UUID of a machine */
{
/* must be a name */
}
}
}
{
i++;
}
{
if (argc <= i + 1)
i++;
else
}
{
if (argc <= i + 1)
i++;
}
{
if (argc <= i + 1)
i++;
}
{
if (argc <= i + 1)
i++;
}
{
if (argc <= i + 1)
i++;
}
{
if (argc <= i + 1)
i++;
}
{
if (argc <= i + 1)
i++;
}
{
if (argc <= i + 1)
i++;
}
{
if (argc <= i + 1)
i++;
if (RT_FAILURE(rc))
return errorArgument("Failed to convert the -maskedinterfaces value '%s' to a number, rc=%Rrc", argv[i], rc);
}
{
if (argc <= i + 1)
i++;
else
}
else
"Unknown option '%s'", argv[i]);
}
{
||
)
)
{
}
}
break;
}
case USBFilterCmd::Remove:
{
/* at least: 0: command, 1: index, 2: -target, 3: <target value> */
if (argc < 4)
for (int i = 2; i < 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 */
}
}
{
/* we need at least a command and target */
if (argc < 2)
/* assume it's a UUID */
{
/* must be a name */
}
if (!machine)
return 1;
{
/* we need at least four more parameters */
if (argc < 5)
bool fTransient = false;
bool fWritable = true;
for (int i = 2; i < 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 (argc < 3)
bool fTransient = false;
for (int i = 2; i < 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;
}
{
/* at least one option: the UUID or name of the VM */
if (argc < 1)
/* try to find the given machine */
else
{
}
return 1;
/* parse arguments. */
bool fReset = false;
bool fWithDescriptions = false;
for (int i = 1; i < argc; i++)
{
{
if (pszPattern)
if (i + 1 >= argc)
pszPattern = 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
*/
}
}
}
}
}
}
static char *toBaseMetricNames(const char *metricList)
{
int cSlashes = 0;
bool fSkip = false;
const char *src = metricList;
while ((c = *src++))
if (c == ':')
fSkip = true;
fSkip = true;
else if (c == ',')
{
fSkip = false;
cSlashes = 0;
*dst++ = c;
}
else
if (!fSkip)
*dst++ = c;
*dst = 0;
return newList;
}
{
/* Metric list */
if (argc > 1)
{
if (!tmp)
return VERR_NO_MEMORY;
}
else
{
metricNames = L"*";
baseNames = L"*";
}
/* Object name */
{
{
}
else
{
{
}
else
{
return rc;
}
}
}
return rc;
}
{
return Bstr("host");
{
return name;
}
return Bstr("unknown");
}
{
{
RTPrintf("The following metrics were modified:\n\n"
"Object Metric\n"
"---------- --------------------\n");
{
RTPrintf("%-10ls %-20ls\n",
}
RTPrintf("\n");
}
else
{
RTPrintf("No metrics match the specified filter!\n");
}
}
/**
* list *
*/
{
return 1;
"Object Metric Unit Minimum Maximum Period Count Description\n"
"---------- -------------------- ---- ---------- ---------- ---------- ---------- -----------\n");
{
RTPrintf("%-10ls %-20ls %-4ls %10d %10d %10u %10u %ls\n",
}
return 0;
}
/**
* Metics setup
*/
{
bool listMatches = false;
int i;
for (i = 1; i < argc; i++)
{
{
if (argc <= i + 1)
}
{
if (argc <= i + 1)
}
listMatches = true;
else
break; /* The rest of params should define the filter */
}
return 1;
if (listMatches)
return 0;
}
/**
* metrics query
*/
{
return 1;
RTPrintf("Object Metric Values\n"
"---------- -------------------- --------------------------------------------\n");
{
const char *separator = "";
for (unsigned j = 0; j < retLengths[i]; j++)
{
if (retScales[i] == 1)
else
separator = ", ";
}
RTPrintf("\n");
}
return 0;
}
{
*pts = 0;
*pts++ = ':';
*pts++ = ':';
*pts++ = '.';
*pts = 0;
}
/** Used by the handleMetricsCollect loop. */
static bool volatile g_fKeepGoing = true;
#ifdef RT_OS_WINDOWS
/**
* Handler routine for catching Ctrl-C, Ctrl-Break and closing of
* the console.
*
* @returns true if handled, false if not handled.
* @param dwCtrlType The type of control signal.
*
* @remarks This is called on a new thread.
*/
{
switch (dwCtrlType)
{
/* Ctrl-C or Ctrl-Break or Close */
case CTRL_C_EVENT:
case CTRL_BREAK_EVENT:
case CTRL_CLOSE_EVENT:
/* Let's shut down gracefully. */
ASMAtomicWriteBool(&g_fKeepGoing, false);
return TRUE;
}
/* Don't care about the rest -- let it die a horrible death. */
return FALSE;
}
#endif /* RT_OS_WINDOWS */
/**
* collect
*/
{
bool isDetached = false, listMatches = false;
int i;
for (i = 1; i < argc; i++)
{
{
if (argc <= i + 1)
}
{
if (argc <= i + 1)
}
listMatches = true;
isDetached = true;
else
break; /* The rest of params should define the filter */
}
return 1;
if (listMatches)
if (!affectedMetrics.size())
return 1;
if (isDetached)
{
RTPrintf("Warning! The background process holding collected metrics will shutdown\n"
"in few seconds, discarding all collected data and parameters.\n");
return 0;
}
#ifdef RT_OS_WINDOWS
SetConsoleCtrlHandler(ctrlHandler, true);
#endif /* RT_OS_WINDOWS */
RTPrintf("Time stamp Object Metric Value\n");
while (g_fKeepGoing)
{
RTPrintf("------------ ---------- -------------------- --------------------\n");
char ts[15];
{
RTPrintf("%-12s %-10ls %-20ls ", ts, getObjectName(aVirtualBox, retObjects[i]).raw(), metricName.raw());
const char *separator = "";
for (unsigned j = 0; j < retLengths[i]; j++)
{
if (retScales[i] == 1)
else
separator = ", ";
}
RTPrintf("\n");
}
}
#ifdef RT_OS_WINDOWS
SetConsoleCtrlHandler(ctrlHandler, false);
#endif /* RT_OS_WINDOWS */
return 0;
}
{
int rc;
/* at least one option: subcommand name */
if (argc < 1)
else
return rc;
}
#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;
{
CHECK_RC_BREAK (machines [i]->
if (!accessible)
continue;
CHECK_RC_BREAK (machines [i]->
if (version != formatVersion)
{
CHECK_RC_BREAK (machines [i]->
}
}
CHECK_RC_BREAK (rc);
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
CHECK_RC_BREAK (rc);
}
CHECK_RC_BREAK (rc);
if (isGlobalConverted)
{
else
}
CHECK_RC_BREAK (rc);
}
}
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. */
exit(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 */
/*
* 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
////////////////////////////////////////////////////////////////////////////
/* convertdd: does not need a VirtualBox instantiation) */
{
break;
}
{
RTPrintf ("[!] Failed to create the VirtualBox 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;
/*
* All registered command handlers
*/
struct
{
const char *command;
} commandHandlers[] =
{
{ "internalcommands", handleInternalCommands },
{ "list", handleList },
{ "showvminfo", handleShowVMInfo },
{ "registervm", handleRegisterVM },
{ "unregistervm", handleUnregisterVM },
{ "createhd", handleCreateHardDisk },
{ "modifyhd", handleModifyHardDisk },
{ "addiscsidisk", handleAddiSCSIDisk },
{ "createvm", handleCreateVM },
{ "modifyvm", handleModifyVM },
{ "clonehd", handleCloneHardDisk },
{ "startvm", handleStartVM },
{ "controlvm", handleControlVM },
{ "discardstate", handleDiscardState },
{ "adoptstate", handleAdoptdState },
{ "snapshot", handleSnapshot },
{ "openmedium", handleOpenMedium },
{ "closemedium", handleCloseMedium },
{ "showhdinfo", handleShowHardDiskInfo },
#ifdef RT_OS_WINDOWS
{ "createhostif", handleCreateHostIF },
{ "removehostif", handleRemoveHostIF },
#endif
{ "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 },
};
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;
}