VBoxManageDisk.cpp revision 78dfd747e1837f5de0bc5625c39dff4b98e3d4d4
/* $Id$ */
/** @file
* VBoxManage - The disk delated commands.
*/
/*
* Copyright (C) 2006-2008 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.
*/
#ifndef VBOX_ONLY_DOCS
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include "VBoxManage.h"
using namespace com;
// funcs
///////////////////////////////////////////////////////////////////////////////
static DECLCALLBACK(void) handleVDError(void *pvUser, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va)
{
RTPrintf("ERROR: ");
RTPrintf("\n");
}
{
int rc = VINF_SUCCESS;
unsigned DiskVariant = (unsigned)(*pDiskVariant);
{
if (pszComma)
else
if (len > 0)
{
// Parsing is intentionally inconsistent: "standard" resets the
// variant, whereas the other flags are cumulative.
else
}
if (pszComma)
else
}
if (RT_SUCCESS(rc))
return rc;
}
{
int rc = VINF_SUCCESS;
else
if (RT_SUCCESS(rc))
return rc;
}
static const RTGETOPTDEF g_aCreateHardDiskOptions[] =
{
};
int handleCreateHardDisk(HandlerArg *a)
{
bool fRemember = false;
int c;
// start at 0 because main() has hacked both the argc and argv given to us
RTGetOptInit(&GetState, a->argc, a->argv, g_aCreateHardDiskOptions, RT_ELEMENTS(g_aCreateHardDiskOptions), 0, 0 /* fFlags */);
{
switch (c)
{
case 'f': // --filename
break;
case 's': // --size
break;
case 'o': // --format
break;
case 'F': // --static ("fixed"/"flat")
{
unsigned uDiskVariant = (unsigned)DiskVariant;
break;
}
case 'm': // --variant
if (RT_FAILURE(rc))
break;
case 'c': // --comment
break;
case 'r': // --remember
fRemember = true;
break;
case 't': // --type
if ( RT_FAILURE(rc)
break;
case VINF_GETOPT_NOT_OPTION:
default:
if (c > 0)
{
if (RT_C_IS_PRINT(c))
else
}
else if (ValueUnion.pDef)
else
}
}
/* check the outcome */
{
/* we will close the hard disk after the storage has been successfully
* created unless fRemember is set */
bool doClose = false;
{
}
{
{
{
if (info.isBasicAvailable())
else
RTPrintf("Error: failed to create hard disk. No error message available!\n");
}
else
{
if (DiskType == HardDiskType_Writethrough)
{
}
}
}
}
if (doClose)
{
}
}
}
#if 0 /* disabled until disk shrinking is implemented based on VBoxHDD */
{
{
RTPrintf(".");
}
return VINF_SUCCESS;
}
#endif
int handleModifyHardDisk(HandlerArg *a)
{
if (a->argc < 2)
/* first guess is that it's a UUID */
/* no? then it must be a filename */
if (!hardDisk)
{
return 1;
}
/* let's find out which command */
{
/* hard disk must be registered */
{
if (a->argc <= 2)
return errorArgument("Missing argument for settype");
{
if (hddType != HardDiskType_Normal)
}
{
if (hddType != HardDiskType_Writethrough)
}
{
if (hddType != HardDiskType_Immutable)
}
else
{
}
}
else
return errorArgument("Hard disk image not registered");
}
{
if (a->argc <= 2)
return errorArgument("Missing argument for autoreset");
{
}
{
}
else
{
return errorArgument("Invalid autoreset argument '%s' specified",
}
}
{
#if 1
RTPrintf("Error: Shrink hard disk operation is not implemented!\n");
return 1;
#else
/* 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))
{
}
#endif
}
else
}
static const RTGETOPTDEF g_aCloneHardDiskOptions[] =
{
};
int handleCloneHardDisk(HandlerArg *a)
{
bool fRemember = false;
int c;
// start at 0 because main() has hacked both the argc and argv given to us
RTGetOptInit(&GetState, a->argc, a->argv, g_aCloneHardDiskOptions, RT_ELEMENTS(g_aCloneHardDiskOptions), 0, 0 /* fFlags */);
{
switch (c)
{
case 'o': // --format
break;
case 'm': // --variant
if (RT_FAILURE(rc))
break;
case 'r': // --remember
fRemember = true;
break;
case 't': // --type
if (RT_FAILURE(rc))
break;
case VINF_GETOPT_NOT_OPTION:
else
break;
default:
if (c > 0)
{
if (RT_C_IS_GRAPH(c))
else
}
else if (c == VERR_GETOPT_UNKNOWN_OPTION)
else if (ValueUnion.pDef)
else
}
}
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;
{
/* get the format of the source hard disk */
}
{
if (info.isBasicAvailable())
else
RTPrintf("Error: failed to clone hard disk. No error message available!\n");
break;
}
RTPrintf("Clone hard disk created in format '%ls'. UUID: %s\n",
}
while (0);
{
/* forget the created clone */
}
if (unknown)
{
/* close the unknown hard disk to forget it again */
}
}
static const RTGETOPTDEF g_aConvertFromRawHardDiskOptions[] =
{
};
{
int rc = VINF_SUCCESS;
bool fReadFromStdIn = false;
const char *format = "VDI";
const char *srcfilename = NULL;
const char *dstfilename = NULL;
unsigned uImageFlags = VD_IMAGE_FLAGS_NONE;
int c;
// start at 0 because main() has hacked both the argc and argv given to us
RTGetOptInit(&GetState, argc, argv, g_aConvertFromRawHardDiskOptions, RT_ELEMENTS(g_aConvertFromRawHardDiskOptions), 0, 0 /* fFlags */);
{
switch (c)
{
case 'o': // --format
break;
case 'm': // --variant
if (RT_FAILURE(rc))
/// @todo cleaner solution than assuming 1:1 mapping?
uImageFlags = (unsigned)DiskVariant;
break;
case VINF_GETOPT_NOT_OPTION:
if (!srcfilename)
{
#endif
}
else if (!dstfilename)
else if (fReadFromStdIn && !filesize)
else
break;
default:
if (c > 0)
{
if (RT_C_IS_PRINT(c))
else
}
else if (ValueUnion.pDef)
else
}
}
RTPrintf("Converting from raw image file=\"%s\" to file=\"%s\"...\n",
/* open raw image file. */
if (fReadFromStdIn)
File = 0;
else
if (RT_FAILURE(rc))
{
goto out;
}
/* get image size. */
if (fReadFromStdIn)
else
if (RT_FAILURE(rc))
{
goto out;
}
RTPrintf("Creating %s image with size %RU64 bytes (%RU64MB)...\n", (uImageFlags & VD_IMAGE_FLAGS_FIXED) ? "fixed" : "dynamic", cbFile, (cbFile + _1M - 1) / _1M);
char pszComment[256];
if (RT_FAILURE(rc))
{
goto out;
}
LCHS.cCylinders = 0;
if (RT_FAILURE(rc))
{
goto out;
}
if (!pvBuf)
{
rc = VERR_NO_MEMORY;
goto out;
}
offFile = 0;
{
cbRead = 0;
break;
if (RT_FAILURE(rc))
{
goto out;
}
}
out:
if (pvBuf)
if (pDisk)
if (File != NIL_RTFILE)
return RT_FAILURE(rc);
}
int handleAddiSCSIDisk(HandlerArg *a)
{
bool fIntNet = false;
/* at least server and target */
if (a->argc < 4)
/* let's have a closer look at the arguments */
for (int i = 0; i < a->argc; 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 (a->argc <= i + 1)
i++;
}
{
i++;
fIntNet = true;
}
else
}
/* check for required options */
do
{
/** @todo move the location stuff to Main, which can use pfnComposeName
* from the disk backends to construct the location properly. */
hardDisk.asOutParam()));
{
}
{
}
{
}
/// @todo add -initiator option
/// @todo add -targetName and -targetPassword options
if (fIntNet)
{
}
}
while (0);
}
int handleShowHardDiskInfo(HandlerArg *a)
{
if (a->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 (differencing)";
else
typeStr = "normal (base)";
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
}
/* print out information specific for differencing hard disks */
{
}
}
while (0);
if (unknown)
{
/* close the unknown hard disk to forget it again */
}
}
int handleOpenMedium(HandlerArg *a)
{
if (a->argc < 2)
{
/* there can be a type parameter */
if (a->argc == 4)
{
}
{
/* change the type if requested */
if (type)
{
}
}
}
{
}
{
}
else
}
int handleCloseMedium(HandlerArg *a)
{
if (a->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
}
#endif /* !VBOX_ONLY_DOCS */