[vbox-dev] vboxmanage patch -- Stdout vs. StdErr fixes and added ability to use optional UUID with convertfromraw
Klaus Espenlaub
klaus.espenlaub at oracle.com
Fri Sep 9 10:37:08 PDT 2011
On 09.09.2011 19:25, Ribhi Kamal wrote:
> Just wondering if this patch will get merged to the next version of vbox?
No, I will not apply this because all the stderr -> stdout replacements
break intentional VirtualBox behavior. It will make VBoxManage unusable
in pipes, which is a common use on non-windows platforms. I also see no
reason, because Windows learned to deal with stderr redirection quite a
number of years ago.
The UUID part is interesting, and will be included when someone finds time.
Klaus
>
> Thanks,
> Ribhi
>
> On Tue, Sep 6, 2011 at 11:42 AM, Ribhi Kamal <rbhkamal at gmail.com
> <mailto:rbhkamal at gmail.com>> wrote:
>
> 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:
>
> 1- Fixed places where stderr was used instead of stdout (Breaks scripts)
> 2- Added the ability to specify a UUID when converting a raw image
> to a virtual disk (VDI/VMDK... etc)
>
> The following patch is licensed under MIT, the changes were tested
> on all windows platforms (32bit and 64bit):
>
> Index: VBoxInternalManage.cpp
> ===================================================================
> --- VBoxInternalManage.cpp (revision 38578)
> +++ VBoxInternalManage.cpp (working copy)
> @@ -1675,7 +1675,7 @@
> void *pvBuf = RTMemAlloc(cbBuf);
> if (pvBuf)
> {
> - RTStrmPrintf(g_pStdErr, "Converting image \"%s\" with size
> %RU64 bytes (%RU64MB) to raw...\n", src.c_str(), cbSize, (cbSize +
> _1M - 1) / _1M);
> + RTStrmPrintf(g_pStdOut, "Converting image \"%s\" with size
> %RU64 bytes (%RU64MB) to raw...\n", src.c_str(), cbSize, (cbSize +
> _1M - 1) / _1M);
> while (offFile < cbSize)
> {
> size_t cb = (size_t)RT_MIN(cbSize - offFile, cbBuf);
> @@ -1823,7 +1823,7 @@
> }
>
> uint64_t cbSize = VDGetSize(pSrcDisk, VD_LAST_IMAGE);
> - RTStrmPrintf(g_pStdErr, "Converting image \"%s\" with size
> %RU64 bytes (%RU64MB)...\n", src.c_str(), cbSize, (cbSize + _1M - 1)
> / _1M);
> + RTStrmPrintf(g_pStdOut, "Converting image \"%s\" with size
> %RU64 bytes (%RU64MB)...\n", src.c_str(), cbSize, (cbSize + _1M - 1)
> / _1M);
>
> /* Create the output image */
> vrc = VDCopy(pSrcDisk, VD_LAST_IMAGE, pDstDisk,
> dstformat.c_str(),
> Index: VBoxManage.cpp
> ===================================================================
> --- VBoxManage.cpp (revision 38578)
> +++ VBoxManage.cpp (working copy)
> @@ -101,8 +101,8 @@
>
> if (!g_fDetailedProgress)
> {
> - RTStrmPrintf(g_pStdErr, "0%%...");
> - RTStrmFlush(g_pStdErr);
> + RTStrmPrintf(g_pStdOut, "0%%...");
> + RTStrmFlush(g_pStdOut);
> }
>
> /* setup signal handling if cancelable */
> @@ -151,7 +151,7 @@
> LONG lSecsRem = 0;
> progress->COMGETTER(TimeRemaining)(&lSecsRem);
>
> - RTStrmPrintf(g_pStdErr, "(%u/%u) %ls %02u%% =>
> %02u%% (%d s remaining)\n", ulOperation + 1, cOperations,
> bstrOperationDescription.raw(), ulCurrentOperationPercent,
> ulCurrentPercent, lSecsRem);
> + RTStrmPrintf(g_pStdOut, "(%u/%u) %ls %02u%% =>
> %02u%% (%d s remaining)\n", ulOperation + 1, cOperations,
> bstrOperationDescription.raw(), ulCurrentOperationPercent,
> ulCurrentPercent, lSecsRem);
> ulLastPercent = ulCurrentPercent;
> ulLastOperationPercent = ulCurrentOperationPercent;
> }
> @@ -166,8 +166,8 @@
> {
> if (curVal < 100)
> {
> - RTStrmPrintf(g_pStdErr, "%u%%...", curVal);
> - RTStrmFlush(g_pStdErr);
> + RTStrmPrintf(g_pStdOut, "%u%%...", curVal);
> + RTStrmFlush(g_pStdOut);
> }
> }
> ulLastPercent = (ulCurrentPercent / 10) * 10;
> @@ -208,14 +208,14 @@
> if (SUCCEEDED(hrc))
> {
> if (SUCCEEDED(iRc))
> - RTStrmPrintf(g_pStdErr, "100%%\n");
> + RTStrmPrintf(g_pStdOut, "100%%\n");
> else if (g_fCanceled)
> RTStrmPrintf(g_pStdErr, "CANCELED\n");
> else
> {
> if (!g_fDetailedProgress)
> - RTStrmPrintf(g_pStdErr, "\n");
> - RTStrmPrintf(g_pStdErr, "Progress state: %Rhrc\n", iRc);
> + RTStrmPrintf(g_pStdOut, "\n");
> + RTStrmPrintf(g_pStdOut, "Progress state: %Rhrc\n", iRc);
> }
> hrc = iRc;
> }
> @@ -226,6 +226,7 @@
> RTStrmPrintf(g_pStdErr, "Progress object failure:
> %Rhrc\n", hrc);
> }
> RTStrmFlush(g_pStdErr);
> + RTStrmFlush(g_pStdOut);
> return hrc;
> }
>
> Index: VBoxManageAppliance.cpp
> ===================================================================
> --- VBoxManageAppliance.cpp (revision 38578)
> +++ VBoxManageAppliance.cpp (working copy)
> @@ -309,7 +309,7 @@
> CHECK_ERROR_BREAK(pAppliance,
> COMGETTER(Path)(path.asOutParam()));
> // call interpret(); this can yield both warnings and
> errors, so we need
> // to tinker with the error info a bit
> - RTStrmPrintf(g_pStdErr, "Interpreting %ls...\n", path.raw());
> + RTStrmPrintf(g_pStdOut, "Interpreting %ls...\n", path.raw());
> rc = pAppliance->Interpret();
> com::ErrorInfo info0(pAppliance, COM_IIDOF(IAppliance));
>
> @@ -331,7 +331,7 @@
> break;
> }
>
> - RTStrmPrintf(g_pStdErr, "OK.\n");
> + RTStrmPrintf(g_pStdOut, "OK.\n");
>
> // fetch all disks
> com::SafeArray<BSTR> retDisks;
> Index: VBoxManageDisk.cpp
> ===================================================================
> --- VBoxManageDisk.cpp (revision 38578)
> +++ VBoxManageDisk.cpp (working copy)
> @@ -689,6 +689,8 @@
> { "-static", 'F', RTGETOPT_REQ_NOTHING },
> { "--variant", 'm', RTGETOPT_REQ_STRING },
> { "-variant", 'm', RTGETOPT_REQ_STRING },
> + { "--uuid", 'u', RTGETOPT_REQ_STRING },
> + { "-uuid", 'u', RTGETOPT_REQ_STRING }
> };
>
> RTEXITCODE handleConvertFromRaw(int argc, char *argv[])
> @@ -701,6 +703,7 @@
> const char *filesize = NULL;
> unsigned uImageFlags = VD_IMAGE_FLAGS_NONE;
> void *pvBuf = NULL;
> + RTUUID uuid;
>
> int c;
> RTGETOPTUNION ValueUnion;
> @@ -712,6 +715,13 @@
> {
> switch (c)
> {
> + case 'u': // --uuid
> + if (RTUuidFromStr(&uuid, ValueUnion.psz) !=
> VINF_SUCCESS)
> + {
> + return errorSyntax(USAGE_CONVERTFROMRAW,
> "Invalid UUID '%s'", ValueUnion.psz);
> + }
> + break;
> +
> case 'o': // --format
> format = ValueUnion.psz;
> break;
> @@ -749,7 +759,7 @@
>
> if (!srcfilename || !dstfilename || (fReadFromStdIn && !filesize))
> return errorSyntax(USAGE_CONVERTFROMRAW, "Incorrect number
> of parameters");
> - RTStrmPrintf(g_pStdErr, "Converting from raw image file=\"%s\"
> to file=\"%s\"...\n",
> + RTStrmPrintf(g_pStdOut, "Converting from raw image file=\"%s\"
> to file=\"%s\"...\n",
> srcfilename, dstfilename);
>
> PVBOXHDD pDisk = NULL;
> @@ -787,7 +797,7 @@
> goto out;
> }
>
> - RTStrmPrintf(g_pStdErr, "Creating %s image with size %RU64
> bytes (%RU64MB)...\n",
> + RTStrmPrintf(g_pStdOut, "Creating %s image with size %RU64
> bytes (%RU64MB)...\n",
> (uImageFlags & VD_IMAGE_FLAGS_FIXED) ? "fixed" :
> "dynamic", cbFile, (cbFile + _1M - 1) / _1M);
> char pszComment[256];
> RTStrPrintf(pszComment, sizeof(pszComment), "Converted image
> from %s", srcfilename);
> @@ -808,7 +818,7 @@
> LCHS.cHeads = 0;
> LCHS.cSectors = 0;
> rc = VDCreateBase(pDisk, format, dstfilename, cbFile,
> - uImageFlags, pszComment, &PCHS, &LCHS, NULL,
> + uImageFlags, pszComment, &PCHS, &LCHS, &uuid,
> VD_OPEN_FLAGS_NORMAL, NULL, NULL);
> if (RT_FAILURE(rc))
> {
> Index: VBoxManageHelp.cpp
> ===================================================================
> --- VBoxManageHelp.cpp (revision 38578)
> +++ VBoxManageHelp.cpp (working copy)
> @@ -542,10 +542,12 @@
> "VBoxManage convertfromraw <filename> <outputfile>\n"
> " [--format VDI|VMDK|VHD]\n"
> " [--variant
> Standard,Fixed,Split2G,Stream,ESX]\n"
> + " [--uuid <uuid>]\n"
> #ifndef RT_OS_WINDOWS
> "VBoxManage convertfromraw stdin <outputfile> <bytes>\n"
> " [--format VDI|VMDK|VHD]\n"
> " [--variant
> Standard,Fixed,Split2G,Stream,ESX]\n"
> + " [--uuid <uuid>]\n"
> #endif
> "\n");
>
> @@ -759,7 +761,7 @@
>
> if (rc == 'h')
> {
> - showLogo(g_pStdErr);
> + showLogo(g_pStdOut);
> #ifndef VBOX_ONLY_DOCS
> if (g_fInternalMode)
> printUsageInternal(fUsageCategory, g_pStdOut);
>
>
>
>
> --
> -- Ribhi
>
>
>
> _______________________________________________
> vbox-dev mailing list
> vbox-dev at virtualbox.org
> http://vbox.innotek.de/mailman/listinfo/vbox-dev
--
Oracle <http://www.oracle.com>
Dr. Klaus Espenlaub | Snr. Manager Software Development Desktop
Virtualization
Phone: +49 7151 60405 205 <tel:+49715160405205>
Oracle VM VirtualBox
ORACLE Deutschland B.V. & Co. KG | Werkstr. 24 | 71384 Weinstadt
ORACLE Deutschland B.V. & Co. KG
Hauptverwaltung: Riesstr. 25, D-80992 München
Registergericht: Amtsgericht München, HRA 95603
Komplementärin: ORACLE Deutschland Verwaltung B.V.
Hertogswetering 163/167, 3543 AS Utrecht, Niederlande
Handelsregister der Handelskammer Midden-Niederlande, Nr. 30143697
Geschäftsführer: Jürgen Kunz, Marcel van de Molen, Alexander van der Ven
Green Oracle <http://www.oracle.com/commitment> Oracle is committed to
developing practices and products that help protect the environment
More information about the vbox-dev
mailing list