VBoxInternalManage.cpp revision 848b6c64616a9dc0d00e7aaad7b82b8eb58e370e
/** @file
*
* VBox frontends: VBoxManage (command-line interface):
* VBoxInternalManage
*
* VBoxInternalManage used to be a second CLI for doing special tricks,
* not intended for general usage, only for assisting VBox developers.
* It is now integrated into VBoxManage.
*/
/*
* Copyright (C) 2006-2007 innotek GmbH
*
* 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.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include "VBoxManage.h"
#ifndef VBOX_OSE
HRESULT CmdListPartitions(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession);
HRESULT CmdCreateRawVMDK(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession);
#endif /* !VBOX_OSE */
using namespace com;
/** flag whether we're in internal mode */
bool g_fInternalMode;
/**
* Print the usage info.
*/
{
RTPrintf("Usage: VBoxManage internalcommands <command> [command arguments]\n"
"\n"
"Commands:\n"
"\n"
"%s%s%s%s%s%s%s"
"WARNING: This is a development tool and shall only be used to analyse\n"
" problems. It is completely unsupported and will change in\n"
" incompatible ways without warning.\n",
(u64Cmd & USAGE_LOADSYMS) ?
" loadsyms <vmname>|<uuid> <symfile> [delta] [module] [module address]\n"
" This will instruct DBGF to load the given symbolfile\n"
" during initialization.\n"
"\n"
: "",
(u64Cmd & USAGE_UNLOADSYMS) ?
" unloadsyms <vmname>|<uuid> <symfile>\n"
" Removes <symfile> from the list of symbol files that\n"
" should be loaded during DBF initialization.\n"
"\n"
: "",
(u64Cmd & USAGE_SETVDIUUID) ?
" setvdiuuid <filepath>\n"
" Assigns a new UUID to the given VDI file. This way, multiple copies\n"
" of VDI containers can be registered.\n"
"\n"
: "",
(u64Cmd & USAGE_LISTPARTITIONS) ?
" listpartitions -rawdisk <diskname>\n"
" Lists all partitions on <diskname>.\n"
"\n"
: "",
(u64Cmd & USAGE_CREATERAWVMDK) ?
" createrawvmdk -filename <filename> -rawdisk <diskname>\n"
" [-partitions <list of partition numbers> [-mbr <filename>] ]\n"
" [-register] [-relative]\n"
" Creates a new VMDK image which gives access to an entite host disk (if\n"
" the parameter -partitions is not specified) or some partitions of a\n"
" host disk. If access to individual partitions is granted, then the\n"
" parameter -mbr can be used to specify an alternative MBR to be used\n"
" (the partitioning information in the MBR file is ignored).\n"
" \\\\.\\PhysicalDisk0).\n"
" On Linux host the parameter -relative causes a VMDK file to be created\n"
" which refers to individual partitions instead to the entire disk.\n"
" Optionally the created image can be immediately registered.\n"
" The necessary partition numbers can be queried with\n"
" VBoxManage internalcommands listpartitions\n"
"\n"
: "",
#ifdef RT_OS_WINDOWS
(u64Cmd & USAGE_MODINSTALL) ?
" modinstall\n"
" Installs the neccessary driver for the host OS\n"
"\n"
: "",
(u64Cmd & USAGE_MODUNINSTALL) ?
" moduninstall\n"
" Deinstalls the driver\n"
"\n"
: ""
#else
"",
""
#endif
);
}
/** @todo this is no longer necessary, we can enumerate extra data */
/**
* Finds a new unique key name.
*
* I don't think this is 100% race condition proof, but we assumes
* the user is not trying to push this point.
*
* @returns Result from the insert.
* @param pMachine The Machine object.
* @param pszKeyBase The base key.
* @param rKey Reference to the string object in which we will return the key.
*/
{
return hrc;
/* if there are no keys, it's simple. */
{
rKey = "1";
}
/* find a unique number - brute force rulez. */
for (unsigned i = 1; i < 1000000; i++)
{
char szKey[32];
while (psz)
{
)
break;
}
if (!psz)
{
}
}
return E_FAIL;
}
#if 0
/**
* Remove a key.
*
* I don't think this isn't 100% race condition proof, but we assumes
* the user is not trying to push this point.
*
* @returns Result from the insert.
* @param pMachine The machine object.
* @param pszKeyBase The base key.
* @param pszKey The key to remove.
*/
{
return hrc;
/* if there are no keys, it's simple. */
return S_OK;
char *pszKeys;
if (RT_SUCCESS(rc))
{
/* locate it */
while (psz)
{
)
break;
}
if (psz)
{
/* remove it */
if (*pszNext)
else
*psz = '\0';
/* update */
}
return hrc;
}
else
RTPrintf("error: failed to delete key '%s' from '%s', string conversion error %Vrc!\n",
return E_FAIL;
}
#endif
/**
* Sets a key value, does necessary error bitching.
*
* @returns COM status code.
* @param pMachine The Machine object.
* @param pszKeyBase The key base.
* @param pszKey The key.
* @param pszAttribute The attribute name.
* @param pszValue The string value.
*/
static HRESULT SetString(ComPtr<IMachine> pMachine, const char *pszKeyBase, const char *pszKey, const char *pszAttribute, const char *pszValue)
{
HRESULT hrc = pMachine->SetExtraData(Bstr(Utf8StrFmt("%s/%s/%s", pszKeyBase, pszKey, pszAttribute)), Bstr(pszValue));
RTPrintf("error: Failed to set '%s/%s/%s' to '%s'! hrc=%#x\n",
return hrc;
}
/**
* Sets a key value, does necessary error bitching.
*
* @returns COM status code.
* @param pMachine The Machine object.
* @param pszKeyBase The key base.
* @param pszKey The key.
* @param pszAttribute The attribute name.
* @param u64Value The value.
*/
static HRESULT SetUInt64(ComPtr<IMachine> pMachine, const char *pszKeyBase, const char *pszKey, const char *pszAttribute, uint64_t u64Value)
{
char szValue[64];
}
/**
* Sets a key value, does necessary error bitching.
*
* @returns COM status code.
* @param pMachine The Machine object.
* @param pszKeyBase The key base.
* @param pszKey The key.
* @param pszAttribute The attribute name.
* @param i64Value The value.
*/
static HRESULT SetInt64(ComPtr<IMachine> pMachine, const char *pszKeyBase, const char *pszKey, const char *pszAttribute, int64_t i64Value)
{
char szValue[64];
}
/**
* Identical to the 'loadsyms' command.
*/
static int CmdLoadSyms(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession)
{
/*
* Get the VM
*/
/* assume it's a UUID */
{
/* must be a name */
}
/*
* Parse the command.
*/
const char *pszFilename;
uint64_t ModuleAddress = ~0;
uint64_t ModuleSize = 0;
/* filename */
if (argc < 2)
return errorArgument("Missing the filename argument!\n");
/* offDelta */
if (argc >= 3)
{
if (VBOX_FAILURE(rc))
}
/* pszModule */
if (argc >= 4)
/* ModuleAddress */
if (argc >= 5)
{
if (VBOX_FAILURE(rc))
}
/* ModuleSize */
if (argc >= 6)
{
if (VBOX_FAILURE(rc))
}
/*
* Add extra data.
*/
}
static int handleSetVDIUUID(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession)
{
/* we need exactly one parameter: the vdi file */
if (argc != 1)
{
}
/* generate a new UUID */
/* just try it */
if (VBOX_FAILURE(rc))
{
}
else
{
}
return 0;
}
/**
* Unloads the neccessary driver.
*
* @returns VBox status code
*/
int CmdModUninstall(void)
{
int rc = SUPUninstall();
rc = SUPInstall();
if (RT_SUCCESS(rc))
return 0;
if (rc == VERR_NOT_IMPLEMENTED)
return 0;
return E_FAIL;
}
/**
* Loads the neccessary driver.
*
* @returns VBox status code
*/
int CmdModInstall(void)
{
rc = SUPInstall();
if (RT_SUCCESS(rc))
return 0;
if (rc == VERR_NOT_IMPLEMENTED)
return 0;
return E_FAIL;
}
/**
* Wrapper for handling internal commands
*/
{
g_fInternalMode = true;
/* at least a command is required */
if (argc < 1)
/*
* The 'string switch' on command name.
*/
//if (!strcmp(pszCmd, "unloadsyms"))
// return CmdUnloadSyms(argc - 1 , &argv[1]);
#ifndef VBOX_OSE
#endif /* !VBOX_OSE */
return CmdModInstall();
return CmdModUninstall();
/* default: */
}