Just wondering if this patch will get merged to the next version of vbox?<br><br>Thanks,<br>Ribhi<br><br><div class="gmail_quote">On Tue, Sep 6, 2011 at 11:42 AM, Ribhi Kamal <span dir="ltr"><<a href="mailto:rbhkamal@gmail.com">rbhkamal@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">I don't know if there are rules about changing UUIDs for virtual disks, but I think there has to be some control over it. Anyway, I would like to share the following patch with you:<br>
<br>1- Fixed places where stderr was used instead of stdout (Breaks scripts)<br>
2- Added the ability to specify a UUID when converting a raw image to a virtual disk (VDI/VMDK... etc)<br><br>The following patch is licensed under MIT, the changes were tested on all windows platforms (32bit and 64bit):<br>
<br>Index: VBoxInternalManage.cpp
<br>===================================================================
<br>--- VBoxInternalManage.cpp (revision 38578)
<br>+++ VBoxInternalManage.cpp (working copy)
<br>@@ -1675,7 +1675,7 @@
<br> void *pvBuf = RTMemAlloc(cbBuf);<br> if (pvBuf)<br> {<br>- RTStrmPrintf(g_pStdErr, "Converting image \"%s\" with size %RU64 bytes (%RU64MB) to raw...\n", src.c_str(), cbSize, (cbSize + _1M - 1) / _1M);<br>
+ RTStrmPrintf(g_pStdOut, "Converting image \"%s\" with size %RU64 bytes (%RU64MB) to raw...\n", src.c_str(), cbSize, (cbSize + _1M - 1) / _1M);<br> while (offFile < cbSize)<br> {<br>
size_t cb = (size_t)RT_MIN(cbSize - offFile, cbBuf);<br>@@ -1823,7 +1823,7 @@
<br> }<br> <br> uint64_t cbSize = VDGetSize(pSrcDisk, VD_LAST_IMAGE);<br>- RTStrmPrintf(g_pStdErr, "Converting image \"%s\" with size %RU64 bytes (%RU64MB)...\n", src.c_str(), cbSize, (cbSize + _1M - 1) / _1M);<br>
+ RTStrmPrintf(g_pStdOut, "Converting image \"%s\" with size %RU64 bytes (%RU64MB)...\n", src.c_str(), cbSize, (cbSize + _1M - 1) / _1M);<br> <br> /* Create the output image */<br> vrc = VDCopy(pSrcDisk, VD_LAST_IMAGE, pDstDisk, dstformat.c_str(),<br>
Index: VBoxManage.cpp
<br>===================================================================
<br>--- VBoxManage.cpp (revision 38578)
<br>+++ VBoxManage.cpp (working copy)
<br>@@ -101,8 +101,8 @@
<br> <br> if (!g_fDetailedProgress)<br> {<br>- RTStrmPrintf(g_pStdErr, "0%%...");<br>- RTStrmFlush(g_pStdErr);<br>+ RTStrmPrintf(g_pStdOut, "0%%...");<br>+ RTStrmFlush(g_pStdOut);<br>
}<br> <br> /* setup signal handling if cancelable */<br>@@ -151,7 +151,7 @@
<br> LONG lSecsRem = 0;<br> progress->COMGETTER(TimeRemaining)(&lSecsRem);<br> <br>- RTStrmPrintf(g_pStdErr, "(%u/%u) %ls %02u%% => %02u%% (%d s remaining)\n", ulOperation + 1, cOperations, bstrOperationDescription.raw(), ulCurrentOperationPercent, ulCurrentPercent, lSecsRem);<br>
+ RTStrmPrintf(g_pStdOut, "(%u/%u) %ls %02u%% => %02u%% (%d s remaining)\n", ulOperation + 1, cOperations, bstrOperationDescription.raw(), ulCurrentOperationPercent, ulCurrentPercent, lSecsRem);<br>
ulLastPercent = ulCurrentPercent;<br> ulLastOperationPercent = ulCurrentOperationPercent;<br> }<br>@@ -166,8 +166,8 @@
<br> {<br> if (curVal < 100)<br> {<br>- RTStrmPrintf(g_pStdErr, "%u%%...", curVal);<br>- RTStrmFlush(g_pStdErr);<br>
+ RTStrmPrintf(g_pStdOut, "%u%%...", curVal);<br>+ RTStrmFlush(g_pStdOut);<br> }<br> }<br> ulLastPercent = (ulCurrentPercent / 10) * 10;<br>
@@ -208,14 +208,14 @@
<br> if (SUCCEEDED(hrc))<br> {<br> if (SUCCEEDED(iRc))<br>- RTStrmPrintf(g_pStdErr, "100%%\n");<br>+ RTStrmPrintf(g_pStdOut, "100%%\n");<br> else if (g_fCanceled)<br>
RTStrmPrintf(g_pStdErr, "CANCELED\n");<br> else<br> {<br> if (!g_fDetailedProgress)<br>- RTStrmPrintf(g_pStdErr, "\n");<br>- RTStrmPrintf(g_pStdErr, "Progress state: %Rhrc\n", iRc);<br>
+ RTStrmPrintf(g_pStdOut, "\n");<br>+ RTStrmPrintf(g_pStdOut, "Progress state: %Rhrc\n", iRc);<br> }<br> hrc = iRc;<br> }<br>@@ -226,6 +226,7 @@
<br> RTStrmPrintf(g_pStdErr, "Progress object failure: %Rhrc\n", hrc);<br> }<br> RTStrmFlush(g_pStdErr);<br>+ RTStrmFlush(g_pStdOut);<br> return hrc;<br> }<br> <br>Index: VBoxManageAppliance.cpp
<br>===================================================================
<br>--- VBoxManageAppliance.cpp (revision 38578)
<br>+++ VBoxManageAppliance.cpp (working copy)
<br>@@ -309,7 +309,7 @@
<br> CHECK_ERROR_BREAK(pAppliance, COMGETTER(Path)(path.asOutParam()));<br> // call interpret(); this can yield both warnings and errors, so we need<br> // to tinker with the error info a bit<br>- RTStrmPrintf(g_pStdErr, "Interpreting %ls...\n", path.raw());<br>
+ RTStrmPrintf(g_pStdOut, "Interpreting %ls...\n", path.raw());<br> rc = pAppliance->Interpret();<br> com::ErrorInfo info0(pAppliance, COM_IIDOF(IAppliance));<br> <br>@@ -331,7 +331,7 @@
<br> break;<br> }<br> <br>- RTStrmPrintf(g_pStdErr, "OK.\n");<br>+ RTStrmPrintf(g_pStdOut, "OK.\n");<br> <br> // fetch all disks<br> com::SafeArray<BSTR> retDisks;<br>
Index: VBoxManageDisk.cpp
<br>===================================================================
<br>--- VBoxManageDisk.cpp (revision 38578)
<br>+++ VBoxManageDisk.cpp (working copy)
<br>@@ -689,6 +689,8 @@
<br> { "-static", 'F', RTGETOPT_REQ_NOTHING },<br> { "--variant", 'm', RTGETOPT_REQ_STRING },<br> { "-variant", 'm', RTGETOPT_REQ_STRING },<br>
+ { "--uuid", 'u', RTGETOPT_REQ_STRING },<br>+ { "-uuid", 'u', RTGETOPT_REQ_STRING }<br> };<br> <br> RTEXITCODE handleConvertFromRaw(int argc, char *argv[])<br>
@@ -701,6 +703,7 @@
<br> const char *filesize = NULL;<br> unsigned uImageFlags = VD_IMAGE_FLAGS_NONE;<br> void *pvBuf = NULL;<br>+ RTUUID uuid;<br> <br> int c;<br> RTGETOPTUNION ValueUnion;<br>@@ -712,6 +715,13 @@
<br> {<br> switch (c)<br> {<br>+ case 'u': // --uuid<br>+ if (RTUuidFromStr(&uuid, ValueUnion.psz) != VINF_SUCCESS)<br>+ {<br>+ return errorSyntax(USAGE_CONVERTFROMRAW, "Invalid UUID '%s'", ValueUnion.psz);<br>
+ }<br>+ break;<br>+<br> case 'o': // --format<br> format = ValueUnion.psz;<br> break;<br>@@ -749,7 +759,7 @@
<br> <br> if (!srcfilename || !dstfilename || (fReadFromStdIn && !filesize))<br> return errorSyntax(USAGE_CONVERTFROMRAW, "Incorrect number of parameters");<br>- RTStrmPrintf(g_pStdErr, "Converting from raw image file=\"%s\" to file=\"%s\"...\n",<br>
+ RTStrmPrintf(g_pStdOut, "Converting from raw image file=\"%s\" to file=\"%s\"...\n",<br> srcfilename, dstfilename);<br> <br> PVBOXHDD pDisk = NULL;<br>@@ -787,7 +797,7 @@
<br> goto out;<br> }<br> <br>- RTStrmPrintf(g_pStdErr, "Creating %s image with size %RU64 bytes (%RU64MB)...\n",<br>+ RTStrmPrintf(g_pStdOut, "Creating %s image with size %RU64 bytes (%RU64MB)...\n",<br>
(uImageFlags & VD_IMAGE_FLAGS_FIXED) ? "fixed" : "dynamic", cbFile, (cbFile + _1M - 1) / _1M);<br> char pszComment[256];<br> RTStrPrintf(pszComment, sizeof(pszComment), "Converted image from %s", srcfilename);<br>
@@ -808,7 +818,7 @@
<br> LCHS.cHeads = 0;<br> LCHS.cSectors = 0;<br> rc = VDCreateBase(pDisk, format, dstfilename, cbFile,<br>- uImageFlags, pszComment, &PCHS, &LCHS, NULL,<br>+ uImageFlags, pszComment, &PCHS, &LCHS, &uuid,<br>
VD_OPEN_FLAGS_NORMAL, NULL, NULL);<br> if (RT_FAILURE(rc))<br> {<br>Index: VBoxManageHelp.cpp
<br>===================================================================
<br>--- VBoxManageHelp.cpp (revision 38578)
<br>+++ VBoxManageHelp.cpp (working copy)
<br>@@ -542,10 +542,12 @@
<br> "VBoxManage convertfromraw <filename> <outputfile>\n"<br> " [--format VDI|VMDK|VHD]\n"<br> " [--variant Standard,Fixed,Split2G,Stream,ESX]\n"<br>
+ " [--uuid <uuid>]\n"<br> #ifndef RT_OS_WINDOWS<br> "VBoxManage convertfromraw stdin <outputfile> <bytes>\n"<br>
" [--format VDI|VMDK|VHD]\n"<br> " [--variant Standard,Fixed,Split2G,Stream,ESX]\n"<br>+ " [--uuid <uuid>]\n"<br>
#endif<br> "\n");<br> <br>@@ -759,7 +761,7 @@
<br> <br> if (rc == 'h')<br> {<br>- showLogo(g_pStdErr);<br>+ showLogo(g_pStdOut);<br> #ifndef VBOX_ONLY_DOCS<br> if (g_fInternalMode)<br> printUsageInternal(fUsageCategory, g_pStdOut);<br>
</blockquote></div><br><br clear="all"><br>-- <br>-- Ribhi<br>