Hi,
this is a patch for vditool util which:
- allow case insensitive string compaisons, more user-friendly from my
own point of view,
- add a SETGEO command to set vdi geometry and allow to shrink or, which
is very often asked on forum, grow a vdi.
I know it's rough and not very clean to do such thing, but I
successfully use a resized vdi (system disk, NTFS formatted) with a
winXP guest without any trouble.
Regards.
Michaƫl.
--- vditool.cpp.orig 2007-05-10 13:23:38.096758351 +0200
+++ vditool.cpp 2007-05-11 11:54:36.391076483 +0200
@@ -33,14 +33,6 @@
#include <stdlib.h>
-
-static void ascii2upper(char *psz)
-{
- for (;*psz; psz++)
- if (*psz >= 'a' && *psz <= 'z')
- *psz += 'A' - 'z';
-}
-
static int UsageExit()
{
RTPrintf("Usage: vditool <Command> [Params]\n" \
@@ -50,6 +42,7 @@
" CONVERT Filename - convert VDI image from old
format;\n" \
" DUMP Filename - debug dump;\n" \
" RESETGEO Filename - reset geometry
information;\n" \
+ " SETGEO Filename - set C/H/S 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");
@@ -200,14 +193,26 @@
return PrintDone(rc);
}
-static int ResetImageGeometry(const char *pszFilename)
+static int SetImageGeometry(const char *pszFilename, const char *strCylinders,
const char *strHeads, const char *strSectors)
{
- RTPrintf("Resetting geometry info of VDI image file=\"%s\"\n",
pszFilename);
+ RTPrintf("(Re)Setting geometry info of VDI image file=\"%s\" with
%s/%s/%s\n", pszFilename, strCylinders, strHeads, strSectors);
PVDIDISK pVdi = VDIDiskCreate();
int rc = VDIDiskOpenImage(pVdi, pszFilename, VDI_OPEN_FLAGS_NORMAL);
+ int cCylinders = 0;
+ int cHeads = 0;
+ int cSectors = 0;
+
if (VBOX_SUCCESS(rc))
{
- rc = VDIDiskSetGeometry(pVdi, 0, 0, 0);
+ if (strCylinders != NULL && strHeads != NULL && strSectors !=
NULL)
+ {
+ cCylinders = RTStrToUInt32 (strCylinders);
+ cHeads = RTStrToUInt32 (strHeads);
+ cSectors = RTStrToUInt32 (strSectors);
+ RTPrintf ("C/H/S = %u:%u:%u\n", cCylinders, cHeads,
cSectors);
+ }
+
+ rc = VDIDiskSetGeometry(pVdi, cCylinders, cHeads, cSectors);
if (VBOX_SUCCESS(rc))
rc = VDIDiskSetTranslation(pVdi, PDMBIOSTRANSLATION_AUTO);
}
@@ -292,7 +297,6 @@
if (strlen(argv[1]) >= sizeof(szCmd))
return SyntaxError("Invalid command!");
strcpy(szCmd, argv[1]);
- ascii2upper(szCmd);
PRTLOGGER pLogger;
static const char * const s_apszGroups[] = VBOX_LOGGROUP_NAMES;
@@ -301,7 +305,7 @@
RTLOGDEST_STDOUT, NULL);
RTLogRelSetDefaultInstance(pLogger);
- if (strcmp(szCmd, "NEW") == 0)
+ if (strcasecmp(szCmd, "NEW") == 0)
{
if (argc != 4)
return SyntaxError("Invalid argument count!");
@@ -320,43 +324,49 @@
rc = NewImage(argv[2], cMBs);
}
- else if (strcmp(szCmd, "DD") == 0)
+ else if (strcasecmp(szCmd, "DD") == 0)
{
if (argc != 4)
return SyntaxError("Invalid argument count!");
rc = ConvertDDImage(argv[2], argv[3]);
}
- else if (strcmp(szCmd, "CONVERT") == 0)
+ else if (strcasecmp(szCmd, "CONVERT") == 0)
{
if (argc != 3)
return SyntaxError("Invalid argument count!");
rc = ConvertOldImage(argv[2]);
}
- else if (strcmp(szCmd, "DUMP") == 0)
+ else if (strcasecmp(szCmd, "DUMP") == 0)
{
if (argc != 3)
return SyntaxError("Invalid argument count!");
rc = DumpImage(argv[2]);
}
- else if (strcmp(szCmd, "RESETGEO") == 0)
+ else if (strcasecmp(szCmd, "RESETGEO") == 0)
{
if (argc != 3)
return SyntaxError("Invalid argument count!");
- rc = ResetImageGeometry(argv[2]);
+ rc = SetImageGeometry(argv[2], NULL, NULL, NULL);
+ }
+ else if (strcasecmp(szCmd, "SETGEO") == 0)
+ {
+ if (argc < 3)
+ return SyntaxError("Invalid argument count!");
+ rc = SetImageGeometry(argv[2], argv[3], argv[4], argv[5]);
}
- else if (strcmp(szCmd, "COPY") == 0)
+ else if (strcasecmp(szCmd, "COPY") == 0)
{
if (argc != 4)
return SyntaxError("Invalid argument count!");
rc = CopyImage(argv[3], argv[2]);
}
- else if (strcmp(szCmd, "COPYDD") == 0)
+ else if (strcasecmp(szCmd, "COPYDD") == 0)
{
if (argc != 4)
return SyntaxError("Invalid argument count!");
rc = CopyToDD(argv[3], argv[2]);
}
- else if (strcmp(szCmd, "SHRINK") == 0)
+ else if (strcasecmp(szCmd, "SHRINK") == 0)
{
if (argc != 3)
return SyntaxError("Invalid argument count!");
_______________________________________________
vbox-dev mailing list
[email protected]
http://vbox.innotek.de/mailman/listinfo/vbox-dev