VBoxManageDisk.cpp revision 4e5fcef7c6a2263e90ed7b67a5770ae87523e4e2
/* $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 <VBox/VBoxHDD-new.h>
#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");
}
{
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++;
}
{
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)
{
}
}
}
#if 0 /* disabled until disk shrinking is implemented based on VBoxHDD-new */
{
{
RTPrintf(".");
}
return VINF_SUCCESS;
}
#endif
{
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");
}
{
#if 1
RTPrintf("Error: Shrink hard disk operation is temporarily unavailable!\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
}
{
#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 vrc;
/* Parse the arguments. */
for (int i = 0; i < argc; i++)
{
{
if (argc <= i + 1)
{
}
i++;
}
{
if (argc <= i + 1)
{
}
i++;
}
{
}
{
}
else
{
}
}
do
{
/* Try to determine input image format */
{
if (RT_FAILURE(vrc))
{
break;
}
}
if (RT_FAILURE(vrc))
{
break;
}
/* Open the input image */
if (RT_FAILURE(vrc))
{
break;
}
/* Output format defaults to VDI */
dstformat = "VDI";
if (RT_FAILURE(vrc))
{
break;
}
RTPrintf("Converting image \"%s\" with size %RU64 bytes (%RU64MB)...\n", Utf8Str(src).raw(), cbSize, (cbSize + _1M - 1) / _1M);
/* Create the output image */
if (RT_FAILURE(vrc))
{
break;
}
}
while (0);
if (pDstDisk)
if (pSrcDisk)
}
{
bool fReadFromStdIn = false;
const char *srcfilename = NULL;
const char *dstfilename = NULL;
unsigned uImageFlags = 0; /**< @todo allow creation of non-default image variants */
for (int i = 0; i < argc; i++)
{
{
}
{
if (argc <= i + 1)
{
}
i++;
}
else
{
if (srcfilename)
{
if (dstfilename)
{
if (fReadFromStdIn && !filesize)
else
}
else
dstfilename = argv[i];
}
else
{
srcfilename = argv[i];
#endif
}
}
}
RTPrintf("Converting VDI: from DD image file=\"%s\" to file=\"%s\"...\n",
int rc = VINF_SUCCESS;
/* 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", (enmImgType == VD_IMAGE_TYPE_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);
}
{
bool fIntNet = false;
/* 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++;
}
{
if (argc <= i + 1)
i++;
}
{
if (argc <= i + 1)
i++;
lun = L"enc";
}
{
if (argc <= i + 1)
i++;
}
{
if (argc <= i + 1)
i++;
}
{
if (argc <= i + 1)
i++;
}
{
i++;
fIntNet = true;
}
else
}
/* check for required options */
do
{
hardDisk.asOutParam()));
{
}
{
}
{
}
/// @todo add -initiator option
/// @todo add -targetName and -targetPassword options
if (fIntNet)
{
}
}
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
}
#endif /* !VBOX_ONLY_DOCS */