vditool.cpp revision 97ab79a2d96a137f116a431a1472005201c7bb9b
/** @file
*
* VBox HDD container maintenance/conversion utility
*/
/*
* 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 <stdlib.h>
static void ascii2upper(char *psz)
{
}
static int UsageExit()
{
RTPrintf("Usage: vditool <Command> [Params]\n" \
"Commands and params:\n" \
" NEW Filename Mbytes - create new image;\n" \
" DD Filename DDFilename - create new image from DD format image;\n" \
" CONVERT Filename - convert VDI image from old format;\n" \
" DUMP Filename - debug dump;\n" \
" RESETGEO Filename - reset geometry information;\n" \
" COPY FromImage ToImage - make image copy;\n" \
" COPYDD FromImage DDFilename - make a DD copy of the image;\n" \
" SHRINK Filename - optimize (reduce) VDI image size.\n");
return 1;
}
static int SyntaxError(const char *pszMsg)
{
UsageExit();
return 1;
}
/**
* Our internal functions use UTF8
*/
{
if (VBOX_FAILURE(rc))
RTPrintf("Error converting filename '%s' to UTF8! (rc=%Rrc)\n",
pszFilename, rc);
return rc;
}
/**
* Prints a done message indicating success or failure.
* @returns rc
* @param rc Status code.
*/
{
if (rc == VINF_SUCCESS)
RTPrintf("The operation completed successfully!\n");
else if (VBOX_SUCCESS(rc))
else
return rc;
}
{
RTPrintf("Creating VDI: file=\"%s\" size=%u MB...\n",
pszFilename, cMBs);
/* translate argv[] to UTF8 */
char *pszUtf8Filename;
if (VBOX_FAILURE(rc))
return rc;
}
{
RTPrintf("Converting VDI: from DD image file=\"%s\" to file=\"%s\"...\n",
/* translate argv[] to UTF8 */
char *pszUtf8Filename, *pszUtf8DDFilename;
if (VBOX_FAILURE(rc))
return rc;
if (VBOX_FAILURE(rc))
return rc;
/* open raw image file. */
if (VBOX_FAILURE(rc))
{
return rc;
}
/* get image size. */
if (VBOX_SUCCESS(rc))
{
if (VBOX_SUCCESS(rc))
{
RTPrintf("Writing data...\n");
if (VBOX_SUCCESS(rc))
{
/* alloc work buffer. */
if (pvBuf)
{
{
break;
if (VBOX_FAILURE(rc))
break;
}
}
else
rc = VERR_NO_MEMORY;
}
if (VBOX_FAILURE(rc))
{
/* delete image on error */
}
}
}
return rc;
}
{
{
RTPrintf(".");
}
return VINF_SUCCESS;
}
static int ConvertOldImage(const char *pszFilename)
{
RTPrintf("Converting VDI image file=\"%s\" to a new format...\n"
"progress: 0%%",
/* translate argv[] to UTF8 */
char *pszUtf8Filename;
if (VBOX_FAILURE(rc))
return rc;
unsigned uPercent = 0;
RTPrintf("\n");
}
static int DumpImage(const char *pszFilename)
{
/* translate argv[] to UTF8 */
char *pszUtf8Filename;
if (VBOX_FAILURE(rc))
return rc;
if (VBOX_SUCCESS(rc))
{
}
}
static int ResetImageGeometry(const char *pszFilename)
{
/* translate argv[] to UTF8 */
char *pszUtf8Filename;
if (VBOX_FAILURE(rc))
return rc;
if (VBOX_SUCCESS(rc))
{
if (VBOX_SUCCESS(rc))
}
}
{
RTPrintf("Copying VDI image file=\"%s\" to image file=\"%s\"...\n"
"progress: 0%%",
/* translate argv[] to UTF8 */
char *pszUtf8SrcFile, *pszUtf8DstFile;
if (VBOX_FAILURE(rc))
return rc;
if (VBOX_FAILURE(rc))
return rc;
unsigned uPrecent = 0;
RTPrintf("\n");
}
{
RTPrintf("Copying VDI image file=\"%s\" to DD file=\"%s\"...\n",
/* translate argv[] to UTF8 */
char *pszUtf8SrcFile, *pszUtf8DstFile;
if (VBOX_FAILURE(rc))
return rc;
if (VBOX_FAILURE(rc))
return rc;
if (VBOX_SUCCESS(rc))
{
rc = RTFileOpen(&FileDst, pszUtf8DstFile, RTFILE_O_CREATE | RTFILE_O_READWRITE | RTFILE_O_DENY_WRITE);
if (VBOX_SUCCESS(rc))
{
if (pvBuf)
{
{
if (VBOX_FAILURE(rc))
break;
if (VBOX_FAILURE(rc))
break;
}
}
}
}
}
static int ShrinkImage(const char *pszFilename)
{
RTPrintf("Shrinking VDI image file=\"%s\"...\n"
"progress: 0%%",
/* translate argv[] to UTF8 */
char *pszUtf8Filename;
if (VBOX_FAILURE(rc))
return rc;
unsigned uPrecent;
RTPrintf("\n");
}
{
putenv((char*)"VBOX_LOG_DEST=stdout");
putenv((char*)"VBOX_LOG_FLAGS=");
RTR3Init();
RTPrintf("vditool Copyright (c) 2004-2008 innotek GmbH.\n\n");
/*
* Do cmd line parsing.
*/
if (argc < 2)
return UsageExit();
char szCmd[16];
return SyntaxError("Invalid command!");
static const char * const s_apszGroups[] = VBOX_LOGGROUP_NAMES;
{
if (argc != 4)
return SyntaxError("Invalid argument count!");
if (VBOX_FAILURE(rc))
return SyntaxError("Invalid number!");
if ( cMBs < 2
{
RTPrintf("error: Disk size %RU32 (MB) is not within the range %u-%u!\n",
return 1;
}
}
{
if (argc != 4)
return SyntaxError("Invalid argument count!");
}
{
if (argc != 3)
return SyntaxError("Invalid argument count!");
}
{
if (argc != 3)
return SyntaxError("Invalid argument count!");
}
{
if (argc != 3)
return SyntaxError("Invalid argument count!");
}
{
if (argc != 4)
return SyntaxError("Invalid argument count!");
}
{
if (argc != 4)
return SyntaxError("Invalid argument count!");
}
{
if (argc != 3)
return SyntaxError("Invalid argument count!");
}
else
return SyntaxError("Invalid command!");
return !VBOX_SUCCESS(rc);
}