VirtualBox

Ignore:
Timestamp:
Dec 12, 2008 1:50:32 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
40805
Message:

Storage: Eradicated the last bits using the old VDI only backend, keeping only the testcases for now (no longer built).

Completely removed old iSCSI driver.

Added intnet option to addiscsidisk and adjusted documentation.

Made backend name comparisons case-insensitive.

Detect VMDK files not according to VMDK 1.0 and reject with clear error message.

Changed format probing logic to not fall through to the "unsupported" case if it's a known format, i.e. has valid header.

VBoxManage converthd generic format converter made official.

Added format flag to VBoxManage createhd, allows creating VMDK files.

VBoxManage convertdd reimplemented based on new framework, supporting any image format.

VBoxManage internalcommands sethduuid reimplemented based on new framework, supporting any image format.

Cleaned up error codes.

Location:
trunk/src/VBox/Frontends/VBoxManage
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxManage/VBoxInternalManage.cpp

    r14838 r15366  
    3636#include <VBox/com/VirtualBox.h>
    3737
    38 #include <VBox/VBoxHDD.h>
    3938#include <VBox/VBoxHDD-new.h>
    4039#include <VBox/sup.h>
     
    140139                "\n"
    141140                : "",
    142             (u64Cmd & USAGE_SETVDIUUID) ?
    143                 "  setvdiuuid <filepath>\n"
    144                 "       Assigns a new UUID to the given VDI file. This way, multiple copies\n"
    145                 "       of VDI containers can be registered.\n"
     141            (u64Cmd & USAGE_SETHDUUID) ?
     142                "  sethduuid <filepath>\n"
     143                "       Assigns a new UUID to the given image file. This way, multiple copies\n"
     144                "       of a container can be registered.\n"
    146145                "\n"
    147146                : "",
     
    187186                 "\n"
    188187                 : "",
    189              (u64Cmd & USAGE_CONVERTDISK) ?
    190                  "  convertdisk [-srcformat <fmt>] [-dstformat <fmt>] <inputfile> <outputfile>"
    191                  "\n"
    192                  "       Convert image to another image format.\n"
    193                  "\n"
    194                  : "",
    195188#ifdef RT_OS_WINDOWS
    196189            (u64Cmd & USAGE_MODINSTALL) ?
     
    469462}
    470463
    471 static int handleSetVDIUUID(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession)
    472 {
    473     /* we need exactly one parameter: the vdi file */
    474     if (argc != 1)
    475     {
    476         return errorSyntax(USAGE_SETVDIUUID, "Not enough parameters");
    477     }
    478 
    479     /* generate a new UUID */
    480     Guid uuid;
    481     uuid.create();
    482 
    483     /* just try it */
    484     int rc = VDISetImageUUIDs(argv[0], uuid.raw(), NULL, NULL, NULL);
    485     if (RT_FAILURE(rc))
    486     {
    487         RTPrintf("Error while setting a new UUID: %Rrc (%d)\n", rc, rc);
    488     }
    489     else
    490     {
    491         RTPrintf("UUID changed to: %s\n", uuid.toString().raw());
    492     }
    493 
    494     return 0;
    495 }
    496 
    497464
    498465static DECLCALLBACK(void) handleVDError(void *pvUser, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va)
     
    502469    RTPrintf("\n");
    503470    RTPrintf("Error code %Rrc at %s(%u) in function %s\n", rc, RT_SRC_POS_ARGS);
     471}
     472
     473static int handleSetHDUUID(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession)
     474{
     475    /* we need exactly one parameter: the image file */
     476    if (argc != 1)
     477    {
     478        return errorSyntax(USAGE_SETHDUUID, "Not enough parameters");
     479    }
     480
     481    /* generate a new UUID */
     482    Guid uuid;
     483    uuid.create();
     484
     485    /* just try it */
     486    char *pszFormat = NULL;
     487    int rc = VDGetFormat(argv[0], &pszFormat);
     488    if (RT_FAILURE(rc))
     489    {
     490        RTPrintf("Format autodetect failed: %Rrc\n", rc);
     491        return 1;
     492    }
     493
     494    PVBOXHDD pDisk = NULL;
     495
     496    PVDINTERFACE     pVDIfs = NULL;
     497    VDINTERFACE      vdInterfaceError;
     498    VDINTERFACEERROR vdInterfaceErrorCallbacks;
     499    vdInterfaceErrorCallbacks.cbSize       = sizeof(VDINTERFACEERROR);
     500    vdInterfaceErrorCallbacks.enmInterface = VDINTERFACETYPE_ERROR;
     501    vdInterfaceErrorCallbacks.pfnError     = handleVDError;
     502
     503    rc = VDInterfaceAdd(&vdInterfaceError, "VBoxManage_IError", VDINTERFACETYPE_ERROR,
     504                        &vdInterfaceErrorCallbacks, NULL, &pVDIfs);
     505    AssertRC(rc);
     506
     507    rc = VDCreate(pVDIfs, &pDisk);
     508    if (RT_FAILURE(rc))
     509    {
     510        RTPrintf("Error while creating the virtual disk container: %Rrc\n", rc);
     511        return 1;
     512    }
     513
     514    /* Open the image */
     515    rc = VDOpen(pDisk, pszFormat, argv[0], VD_OPEN_FLAGS_NORMAL, NULL);
     516    if (RT_FAILURE(rc))
     517    {
     518        RTPrintf("Error while opening the image: %Rrc\n", rc);
     519        return 1;
     520    }
     521
     522    rc = VDSetUuid(pDisk, VD_LAST_IMAGE, uuid.raw());
     523    if (RT_FAILURE(rc))
     524        RTPrintf("Error while setting a new UUID: %Rrc\n", rc);
     525    else
     526        RTPrintf("UUID changed to: %s\n", uuid.toString().raw());
     527
     528    VDCloseAll(pDisk);
     529
     530    return RT_FAILURE(rc);
    504531}
    505532
     
    11641191    AssertRC(vrc);
    11651192
    1166     vrc = VDCreate(&vdInterfaceError, &pDisk);
     1193    vrc = VDCreate(pVDIfs, &pDisk);
    11671194    if (RT_FAILURE(vrc))
    11681195    {
     
    12731300    AssertRC(vrc);
    12741301
    1275     vrc = VDCreate(&vdInterfaceError, &pDisk);
     1302    vrc = VDCreate(pVDIfs, &pDisk);
    12761303    if (RT_FAILURE(vrc))
    12771304    {
     
    13541381    AssertRC(vrc);
    13551382
    1356     vrc = VDCreate(&vdInterfaceError, &pDisk);
     1383    vrc = VDCreate(pVDIfs, &pDisk);
    13571384    if (RT_FAILURE(vrc))
    13581385    {
     
    14561483}
    14571484
    1458 static int CmdConvertDisk(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession)
    1459 {
    1460     Bstr srcformat;
    1461     Bstr dstformat;
    1462     Bstr src;
    1463     Bstr dst;
    1464     int vrc;
    1465     PVBOXHDD pSrcDisk = NULL;
    1466     PVBOXHDD pDstDisk = NULL;
    1467 
    1468     /* Parse the arguments. */
    1469     for (int i = 0; i < argc; i++)
    1470     {
    1471         if (strcmp(argv[i], "-srcformat") == 0)
    1472         {
    1473             if (argc <= i + 1)
    1474             {
    1475                 return errorArgument("Missing argument to '%s'", argv[i]);
    1476             }
    1477             i++;
    1478             srcformat = argv[i];
    1479         }
    1480         else if (strcmp(argv[i], "-dstformat") == 0)
    1481         {
    1482             if (argc <= i + 1)
    1483             {
    1484                 return errorArgument("Missing argument to '%s'", argv[i]);
    1485             }
    1486             i++;
    1487             dstformat = argv[i];
    1488         }
    1489         else if (src.isEmpty())
    1490         {
    1491             src = argv[i];
    1492         }
    1493         else if (dst.isEmpty())
    1494         {
    1495             dst = argv[i];
    1496         }
    1497         else
    1498         {
    1499             return errorSyntax(USAGE_CONVERTDISK, "Invalid parameter '%s'", Utf8Str(argv[i]).raw());
    1500         }
    1501     }
    1502 
    1503     if (src.isEmpty())
    1504         return errorSyntax(USAGE_CONVERTDISK, "Mandatory input image parameter missing");
    1505     if (dst.isEmpty())
    1506         return errorSyntax(USAGE_CONVERTDISK, "Mandatory output image parameter missing");
    1507 
    1508 
    1509     PVDINTERFACE     pVDIfs = NULL;
    1510     VDINTERFACE      vdInterfaceError;
    1511     VDINTERFACEERROR vdInterfaceErrorCallbacks;
    1512     vdInterfaceErrorCallbacks.cbSize       = sizeof(VDINTERFACEERROR);
    1513     vdInterfaceErrorCallbacks.enmInterface = VDINTERFACETYPE_ERROR;
    1514     vdInterfaceErrorCallbacks.pfnError     = handleVDError;
    1515 
    1516     vrc = VDInterfaceAdd(&vdInterfaceError, "VBoxManage_IError", VDINTERFACETYPE_ERROR,
    1517                              &vdInterfaceErrorCallbacks, NULL, &pVDIfs);
    1518     AssertRC(vrc);
    1519 
    1520     do
    1521     {
    1522         /* Try to determine input image format */
    1523         if (srcformat.isEmpty())
    1524         {
    1525             char *pszFormat = NULL;
    1526             vrc = VDGetFormat(Utf8Str(src).raw(), &pszFormat);
    1527             if (RT_FAILURE(vrc))
    1528             {
    1529                 RTPrintf("No file format specified and autodetect failed - please specify format: %Rrc\n", vrc);
    1530                 break;
    1531             }
    1532             srcformat = pszFormat;
    1533             RTStrFree(pszFormat);
    1534         }
    1535 
    1536         vrc = VDCreate(&vdInterfaceError, &pSrcDisk);
    1537         if (RT_FAILURE(vrc))
    1538         {
    1539             RTPrintf("Error while creating the source virtual disk container: %Rrc\n", vrc);
    1540             break;
    1541         }
    1542 
    1543         /* Open the input image */
    1544         vrc = VDOpen(pSrcDisk, Utf8Str(srcformat).raw(), Utf8Str(src).raw(), VD_OPEN_FLAGS_READONLY, NULL);
    1545         if (RT_FAILURE(vrc))
    1546         {
    1547             RTPrintf("Error while opening the source image: %Rrc\n", vrc);
    1548             break;
    1549         }
    1550 
    1551         /* Output format defaults to VDI */
    1552         if (dstformat.isEmpty())
    1553             dstformat = "VDI";
    1554 
    1555         vrc = VDCreate(&vdInterfaceError, &pDstDisk);
    1556         if (RT_FAILURE(vrc))
    1557         {
    1558             RTPrintf("Error while creating the destination virtual disk container: %Rrc\n", vrc);
    1559             break;
    1560         }
    1561 
    1562         uint64_t cbSize = VDGetSize(pSrcDisk, VD_LAST_IMAGE);
    1563         RTPrintf("Converting image \"%s\" with size %RU64 bytes (%RU64MB)...\n", Utf8Str(src).raw(), cbSize, (cbSize + _1M - 1) / _1M);
    1564 
    1565         /* Create the output image */
    1566         vrc = VDCopy(pSrcDisk, VD_LAST_IMAGE, pDstDisk, Utf8Str(dstformat).raw(),
    1567                      Utf8Str(dst).raw(), false, 0, NULL, NULL, NULL);
    1568         if (RT_FAILURE(vrc))
    1569         {
    1570             RTPrintf("Error while copying the image: %Rrc\n", vrc);
    1571             break;
    1572         }
    1573     }
    1574     while (0);
    1575 
    1576     if (pDstDisk)
    1577         VDCloseAll(pDstDisk);
    1578     if (pSrcDisk)
    1579         VDCloseAll(pSrcDisk);
    1580 
    1581     return RT_SUCCESS(vrc) ? 0 : 1;
    1582 }
    1583 
    15841485/**
    15851486 * Unloads the neccessary driver.
     
    16361537    //if (!strcmp(pszCmd, "unloadsyms"))
    16371538    //    return CmdUnloadSyms(argc - 1 , &argv[1]);
    1638     if (!strcmp(pszCmd, "setvdiuuid"))
    1639         return handleSetVDIUUID(argc - 1, &argv[1], aVirtualBox, aSession);
     1539    if (!strcmp(pszCmd, "sethduuid") || !strcmp(pszCmd, "setvdiuuid"))
     1540        return handleSetHDUUID(argc - 1, &argv[1], aVirtualBox, aSession);
    16401541    if (!strcmp(pszCmd, "listpartitions"))
    16411542        return CmdListPartitions(argc - 1, &argv[1], aVirtualBox, aSession);
     
    16461547    if (!strcmp(pszCmd, "converttoraw"))
    16471548        return CmdConvertToRaw(argc - 1, &argv[1], aVirtualBox, aSession);
    1648     if (!strcmp(pszCmd, "convertdisk"))
    1649         return CmdConvertDisk(argc - 1, &argv[1], aVirtualBox, aSession);
    16501549
    16511550    if (!strcmp(pszCmd, "modinstall"))
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManage.cpp

    r15267 r15366  
    5454#include <iprt/uuid.h>
    5555#include <VBox/version.h>
    56 #include <VBox/VBoxHDD.h>
     56#include <VBox/VBoxHDD-new.h>
    5757#include <VBox/log.h>
    5858
     
    512512        RTPrintf("VBoxManage createhd         -filename <filename>\n"
    513513                 "                            -size <megabytes>\n"
     514                 "                            [-format VDI|VMDK]\n"
    514515                 "                            [-static]\n"
    515516                 "                            [-comment <comment>]\n"
     
    533534    }
    534535
     536    if (u64Cmd & USAGE_CONVERTHD)
     537    {
     538        RTPrintf("VBoxManage converthd        [-srcformat VDI|VMDK|RAW]\n"
     539                 "                            [-dstformat VDI|VMDK|RAW]\n"
     540                 "                            <inputfile> <outputfile>\n"
     541                 "\n");
     542    }
     543
    535544    if (u64Cmd & USAGE_CONVERTDD)
    536545    {
    537         RTPrintf("VBoxManage convertdd        [-static] <filename> <outputfile>\n"
    538                  "VBoxManage convertdd        [-static] stdin <outputfile> <bytes>\n"
     546        RTPrintf("VBoxManage convertdd        [-static] [-format VDI|VMDK]"
     547                 "                            <filename> <outputfile>\n"
     548                 "VBoxManage convertdd        [-static] [-format VDI|VMDK]"
     549                 "                            stdin <outputfile> <bytes>\n"
    539550                 "\n");
    540551    }
     
    550561                 "                            [-password <password>]\n"
    551562                 "                            [-comment <comment>]\n"
     563                 "                            [-intnet]\n"
    552564                 "\n");
    553565    }
     
    816828}
    817829
     830
     831static DECLCALLBACK(void) handleVDError(void *pvUser, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va)
     832{
     833    RTPrintf("ERROR: ");
     834    RTPrintfV(pszFormat, va);
     835    RTPrintf("\n");
     836    RTPrintf("Error code %Rrc at %s(%u) in function %s\n", rc, RT_SRC_POS_ARGS);
     837}
     838
     839
    818840static int handleCreateHardDisk(int argc, char *argv[],
    819841                                ComPtr<IVirtualBox> virtualBox, ComPtr<ISession> session)
     
    822844    Bstr filename;
    823845    uint64_t sizeMB = 0;
     846    Bstr format = "VDI";
    824847    bool fStatic = false;
    825848    Bstr comment;
     
    844867            sizeMB = RTStrToUInt64(argv[i]);
    845868        }
     869        else if (strcmp(argv[i], "-format") == 0)
     870        {
     871            if (argc <= i + 1)
     872                return errorArgument("Missing argument to '%s'", argv[i]);
     873            i++;
     874            format = argv[i];
     875        }
    846876        else if (strcmp(argv[i], "-static") == 0)
    847877        {
     
    877907
    878908    ComPtr<IHardDisk2> hardDisk;
    879     CHECK_ERROR(virtualBox, CreateHardDisk2(Bstr("VDI"), filename, hardDisk.asOutParam()));
     909    CHECK_ERROR(virtualBox, CreateHardDisk2(format, filename, hardDisk.asOutParam()));
    880910    if (SUCCEEDED(rc) && hardDisk)
    881911    {
     
    939969}
    940970
     971#if 0 /* disabled until disk shrinking is implemented based on VBoxHDD-new */
    941972static DECLCALLBACK(int) hardDiskProgressCallback(PVM pVM, unsigned uPercent, void *pvUser)
    942973{
     
    954985    return VINF_SUCCESS;
    955986}
     987#endif
    956988
    957989
     
    10201052    else if (strcmp(argv[1], "compact") == 0)
    10211053    {
     1054#if 1
     1055        RTPrintf("Error: Shrink hard disk operation is temporarily unavailable!\n");
     1056        return 1;
     1057#else
    10221058        /* the hard disk image might not be registered */
    10231059        if (!hardDisk)
     
    10481084            rc = E_FAIL;
    10491085        }
     1086#endif
    10501087    }
    10511088    else
     
    11041141}
    11051142
     1143static int handleConvertHardDisk(int argc, char **argv)
     1144{
     1145    Bstr srcformat;
     1146    Bstr dstformat;
     1147    Bstr src;
     1148    Bstr dst;
     1149    int vrc;
     1150    PVBOXHDD pSrcDisk = NULL;
     1151    PVBOXHDD pDstDisk = NULL;
     1152
     1153    /* Parse the arguments. */
     1154    for (int i = 0; i < argc; i++)
     1155    {
     1156        if (strcmp(argv[i], "-srcformat") == 0)
     1157        {
     1158            if (argc <= i + 1)
     1159            {
     1160                return errorArgument("Missing argument to '%s'", argv[i]);
     1161            }
     1162            i++;
     1163            srcformat = argv[i];
     1164        }
     1165        else if (strcmp(argv[i], "-dstformat") == 0)
     1166        {
     1167            if (argc <= i + 1)
     1168            {
     1169                return errorArgument("Missing argument to '%s'", argv[i]);
     1170            }
     1171            i++;
     1172            dstformat = argv[i];
     1173        }
     1174        else if (src.isEmpty())
     1175        {
     1176            src = argv[i];
     1177        }
     1178        else if (dst.isEmpty())
     1179        {
     1180            dst = argv[i];
     1181        }
     1182        else
     1183        {
     1184            return errorSyntax(USAGE_CONVERTHD, "Invalid parameter '%s'", Utf8Str(argv[i]).raw());
     1185        }
     1186    }
     1187
     1188    if (src.isEmpty())
     1189        return errorSyntax(USAGE_CONVERTHD, "Mandatory input image parameter missing");
     1190    if (dst.isEmpty())
     1191        return errorSyntax(USAGE_CONVERTHD, "Mandatory output image parameter missing");
     1192
     1193
     1194    PVDINTERFACE     pVDIfs = NULL;
     1195    VDINTERFACE      vdInterfaceError;
     1196    VDINTERFACEERROR vdInterfaceErrorCallbacks;
     1197    vdInterfaceErrorCallbacks.cbSize       = sizeof(VDINTERFACEERROR);
     1198    vdInterfaceErrorCallbacks.enmInterface = VDINTERFACETYPE_ERROR;
     1199    vdInterfaceErrorCallbacks.pfnError     = handleVDError;
     1200
     1201    vrc = VDInterfaceAdd(&vdInterfaceError, "VBoxManage_IError", VDINTERFACETYPE_ERROR,
     1202                         &vdInterfaceErrorCallbacks, NULL, &pVDIfs);
     1203    AssertRC(vrc);
     1204
     1205    do
     1206    {
     1207        /* Try to determine input image format */
     1208        if (srcformat.isEmpty())
     1209        {
     1210            char *pszFormat = NULL;
     1211            vrc = VDGetFormat(Utf8Str(src).raw(), &pszFormat);
     1212            if (RT_FAILURE(vrc))
     1213            {
     1214                RTPrintf("No file format specified and autodetect failed - please specify format: %Rrc\n", vrc);
     1215                break;
     1216            }
     1217            srcformat = pszFormat;
     1218            RTStrFree(pszFormat);
     1219        }
     1220
     1221        vrc = VDCreate(pVDIfs, &pSrcDisk);
     1222        if (RT_FAILURE(vrc))
     1223        {
     1224            RTPrintf("Error while creating the source virtual disk container: %Rrc\n", vrc);
     1225            break;
     1226        }
     1227
     1228        /* Open the input image */
     1229        vrc = VDOpen(pSrcDisk, Utf8Str(srcformat).raw(), Utf8Str(src).raw(), VD_OPEN_FLAGS_READONLY, NULL);
     1230        if (RT_FAILURE(vrc))
     1231        {
     1232            RTPrintf("Error while opening the source image: %Rrc\n", vrc);
     1233            break;
     1234        }
     1235
     1236        /* Output format defaults to VDI */
     1237        if (dstformat.isEmpty())
     1238            dstformat = "VDI";
     1239
     1240        vrc = VDCreate(pVDIfs, &pDstDisk);
     1241        if (RT_FAILURE(vrc))
     1242        {
     1243            RTPrintf("Error while creating the destination virtual disk container: %Rrc\n", vrc);
     1244            break;
     1245        }
     1246
     1247        uint64_t cbSize = VDGetSize(pSrcDisk, VD_LAST_IMAGE);
     1248        RTPrintf("Converting image \"%s\" with size %RU64 bytes (%RU64MB)...\n", Utf8Str(src).raw(), cbSize, (cbSize + _1M - 1) / _1M);
     1249
     1250        /* Create the output image */
     1251        vrc = VDCopy(pSrcDisk, VD_LAST_IMAGE, pDstDisk, Utf8Str(dstformat).raw(),
     1252                     Utf8Str(dst).raw(), false, 0, NULL, NULL, NULL);
     1253        if (RT_FAILURE(vrc))
     1254        {
     1255            RTPrintf("Error while copying the image: %Rrc\n", vrc);
     1256            break;
     1257        }
     1258    }
     1259    while (0);
     1260    if (pDstDisk)
     1261        VDCloseAll(pDstDisk);
     1262    if (pSrcDisk)
     1263        VDCloseAll(pSrcDisk);
     1264
     1265    return RT_SUCCESS(vrc) ? 0 : 1;
     1266}
     1267
     1268
    11061269static int handleConvertDDImage(int argc, char *argv[])
    11071270{
    1108     int arg = 0;
    1109     VDIIMAGETYPE enmImgType = VDI_IMAGE_TYPE_NORMAL;
    1110     if (argc >= 1 && !strcmp(argv[arg], "-static"))
    1111     {
    1112         arg++;
    1113         enmImgType = VDI_IMAGE_TYPE_FIXED;
    1114     }
    1115 
     1271    VDIMAGETYPE enmImgType = VD_IMAGE_TYPE_NORMAL;
     1272    bool fReadFromStdIn = false;
     1273    const char *format = NULL;
     1274    const char *srcfilename = NULL;
     1275    const char *dstfilename = NULL;
     1276    const char *filesize = NULL;
     1277    unsigned uImageFlags = 0; /**< @todo allow creation of non-default image variants */
     1278
     1279    for (int i = 0; i < argc; i++)
     1280    {
     1281        if (!strcmp(argv[i], "-static"))
     1282        {
     1283            enmImgType = VD_IMAGE_TYPE_FIXED;
     1284        }
     1285        else if (strcmp(argv[i], "-format") == 0)
     1286        {
     1287            if (argc <= i + 1)
     1288            {
     1289                return errorArgument("Missing argument to '%s'", argv[i]);
     1290            }
     1291            i++;
     1292            format = argv[i];
     1293        }
     1294        else
     1295        {
     1296            if (srcfilename)
     1297            {
     1298                if (dstfilename)
     1299                {
     1300                    if (fReadFromStdIn && !filesize)
     1301                        filesize = argv[i];
     1302                    else
     1303                        return errorSyntax(USAGE_CONVERTDD, "Incorrect number of parameters");
     1304                }
     1305                else
     1306                    dstfilename = argv[i];
     1307            }
     1308            else
     1309            {
     1310                srcfilename = argv[i];
    11161311#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS)
    1117     const bool fReadFromStdIn = (argc >= arg + 1) && !strcmp(argv[arg], "stdin");
    1118 #else
    1119     const bool fReadFromStdIn = false;
     1312                fReadFromStdIn = !strcmp(srcfilename, "stdin");
    11201313#endif
    1121 
    1122     if ((!fReadFromStdIn && argc != arg + 2) || (fReadFromStdIn && argc != arg + 3))
    1123         return errorSyntax(USAGE_CONVERTDD, "Incorrect number of parameters");
     1314            }
     1315        }
     1316    }
    11241317
    11251318    RTPrintf("Converting VDI: from DD image file=\"%s\" to file=\"%s\"...\n",
    1126              argv[arg], argv[arg + 1]);
     1319             srcfilename, dstfilename);
     1320
     1321    int rc = VINF_SUCCESS;
     1322    PVBOXHDD pDisk = NULL;
     1323
     1324    PVDINTERFACE     pVDIfs = NULL;
     1325    VDINTERFACE      vdInterfaceError;
     1326    VDINTERFACEERROR vdInterfaceErrorCallbacks;
     1327    vdInterfaceErrorCallbacks.cbSize       = sizeof(VDINTERFACEERROR);
     1328    vdInterfaceErrorCallbacks.enmInterface = VDINTERFACETYPE_ERROR;
     1329    vdInterfaceErrorCallbacks.pfnError     = handleVDError;
     1330
     1331    rc = VDInterfaceAdd(&vdInterfaceError, "VBoxManage_IError", VDINTERFACETYPE_ERROR,
     1332                        &vdInterfaceErrorCallbacks, NULL, &pVDIfs);
     1333    AssertRC(rc);
    11271334
    11281335    /* open raw image file. */
    11291336    RTFILE File;
    1130     int rc = VINF_SUCCESS;
    11311337    if (fReadFromStdIn)
    11321338        File = 0;
    11331339    else
    1134         rc = RTFileOpen(&File, argv[arg], RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_WRITE);
     1340        rc = RTFileOpen(&File, srcfilename, RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_WRITE);
    11351341    if (RT_FAILURE(rc))
    11361342    {
    1137         RTPrintf("File=\"%s\" open error: %Rrf\n", argv[arg], rc);
    1138         return rc;
     1343        RTPrintf("File=\"%s\" open error: %Rrf\n", srcfilename, rc);
     1344        goto out;
    11391345    }
    11401346
     
    11421348    /* get image size. */
    11431349    if (fReadFromStdIn)
    1144         cbFile = RTStrToUInt64(argv[arg + 2]);
     1350        cbFile = RTStrToUInt64(filesize);
    11451351    else
    11461352        rc = RTFileGetSize(File, &cbFile);
    1147     if (RT_SUCCESS(rc))
    1148     {
    1149         RTPrintf("Creating %s image with size %RU64 bytes (%RU64MB)...\n", (enmImgType == VDI_IMAGE_TYPE_FIXED) ? "fixed" : "dynamic", cbFile, (cbFile + _1M - 1) / _1M);
    1150         char pszComment[256];
    1151         RTStrPrintf(pszComment, sizeof(pszComment), "Converted image from %s", argv[arg]);
    1152         rc = VDICreateBaseImage(argv[arg + 1],
    1153                                 enmImgType,
    1154                                 cbFile,
    1155                                 pszComment, NULL, NULL);
    1156         if (RT_SUCCESS(rc))
    1157         {
    1158             PVDIDISK pVdi = VDIDiskCreate();
    1159             rc = VDIDiskOpenImage(pVdi, argv[arg + 1], VDI_OPEN_FLAGS_NORMAL);
    1160             if (RT_SUCCESS(rc))
    1161             {
    1162                 /* alloc work buffer. */
    1163                 size_t cbBuffer = VDIDiskGetBufferSize(pVdi);
    1164                 void   *pvBuf = RTMemAlloc(cbBuffer);
    1165                 if (pvBuf)
    1166                 {
    1167                     uint64_t offFile = 0;
    1168                     while (offFile < cbFile)
    1169                     {
    1170                         size_t cbRead = 0;
    1171                         size_t cbToRead = cbFile - offFile >= (uint64_t) cbBuffer ?
     1353    if (RT_FAILURE(rc))
     1354    {
     1355        RTPrintf("Error getting image size for file \"%s\": %Rrc\n", srcfilename, rc);
     1356        goto out;
     1357    }
     1358
     1359    RTPrintf("Creating %s image with size %RU64 bytes (%RU64MB)...\n", (enmImgType == VD_IMAGE_TYPE_FIXED) ? "fixed" : "dynamic", cbFile, (cbFile + _1M - 1) / _1M);
     1360    char pszComment[256];
     1361    RTStrPrintf(pszComment, sizeof(pszComment), "Converted image from %s", srcfilename);
     1362    rc = VDCreate(pVDIfs, &pDisk);
     1363    if (RT_FAILURE(rc))
     1364    {
     1365        RTPrintf("Error while creating the virtual disk container: %Rrc\n", rc);
     1366        goto out;
     1367    }
     1368
     1369    Assert(RT_MIN(cbFile / 512 / 16 / 63, 16383) -
     1370           (unsigned int)RT_MIN(cbFile / 512 / 16 / 63, 16383) == 0);
     1371    PDMMEDIAGEOMETRY PCHS, LCHS;
     1372    PCHS.cCylinders = (unsigned int)RT_MIN(cbFile / 512 / 16 / 63, 16383);
     1373    PCHS.cHeads = 16;
     1374    PCHS.cSectors = 63;
     1375    LCHS.cCylinders = 0;
     1376    LCHS.cHeads = 0;
     1377    LCHS.cSectors = 0;
     1378    rc = VDCreateBase(pDisk, format, dstfilename, enmImgType, cbFile,
     1379                      uImageFlags, pszComment, &PCHS, &LCHS, NULL,
     1380                      VD_OPEN_FLAGS_NORMAL, NULL, NULL);
     1381    if (RT_FAILURE(rc))
     1382    {
     1383        RTPrintf("Error while creating the disk image \"%s\": %Rrc\n", dstfilename, rc);
     1384        goto out;
     1385    }
     1386
     1387    size_t cbBuffer;
     1388    cbBuffer = _1M;
     1389    void *pvBuf;
     1390    pvBuf = RTMemAlloc(cbBuffer);
     1391    if (!pvBuf)
     1392    {
     1393        rc = VERR_NO_MEMORY;
     1394        RTPrintf("Not enough memory allocating buffers for image \"%s\": %Rrc\n", dstfilename, rc);
     1395        goto out;
     1396    }
     1397
     1398    uint64_t offFile;
     1399    offFile = 0;
     1400    while (offFile < cbFile)
     1401    {
     1402        size_t cbRead;
     1403        size_t cbToRead;
     1404        cbRead = 0;
     1405        cbToRead = cbFile - offFile >= (uint64_t)cbBuffer ?
    11721406                            cbBuffer : (size_t) (cbFile - offFile);
    1173                         rc = RTFileRead(File, pvBuf, cbToRead, &cbRead);
    1174                         if (RT_FAILURE(rc) || !cbRead)
    1175                             break;
    1176                         rc = VDIDiskWrite(pVdi, offFile, pvBuf, cbRead);
    1177                         if (RT_FAILURE(rc))
    1178                             break;
    1179                         offFile += cbRead;
    1180                     }
    1181 
    1182                     RTMemFree(pvBuf);
    1183                 }
    1184                 else
    1185                     rc = VERR_NO_MEMORY;
    1186 
    1187                 VDIDiskCloseImage(pVdi);
    1188             }
    1189 
    1190             if (RT_FAILURE(rc))
    1191             {
    1192                 /* delete image on error */
    1193                 RTPrintf("Failed (%Rrc)!\n", rc);
    1194                 VDIDeleteImage(argv[arg + 1]);
    1195             }
    1196         }
    1197         else
    1198             RTPrintf("Failed to create output file (%Rrc)!\n", rc);
    1199     }
    1200     RTFileClose(File);
    1201 
    1202     return rc;
     1407        rc = RTFileRead(File, pvBuf, cbToRead, &cbRead);
     1408        if (RT_FAILURE(rc) || !cbRead)
     1409            break;
     1410        rc = VDWrite(pDisk, offFile, pvBuf, cbRead);
     1411        if (RT_FAILURE(rc))
     1412        {
     1413            RTPrintf("Failed to write to disk image \"%s\": %Rrc\n", dstfilename, rc);
     1414            goto out;
     1415        }
     1416        offFile += cbRead;
     1417    }
     1418
     1419out:
     1420    if (pvBuf)
     1421        RTMemFree(pvBuf);
     1422    if (pDisk)
     1423        VDClose(pDisk, RT_FAILURE(rc));
     1424    if (File != NIL_RTFILE)
     1425        RTFileClose(File);
     1426
     1427    return RT_FAILURE(rc);
    12031428}
    12041429
     
    12141439    Bstr password;
    12151440    Bstr comment;
     1441    bool fIntNet = false;
    12161442
    12171443    /* at least server and target */
     
    12991525            comment = argv[i];
    13001526        }
     1527        else if (strcmp(argv[i], "-intnet") == 0)
     1528        {
     1529            i++;
     1530            fIntNet = true;
     1531        }
    13011532        else
    13021533            return errorSyntax(USAGE_ADDISCSIDISK, "Invalid parameter '%s'", Utf8Str(argv[i]).raw());
     
    13511582
    13521583        /// @todo add -targetName and -targetPassword options
     1584
     1585        if (fIntNet)
     1586        {
     1587            Bstr ("HostIPStack").detachTo (names.appendedRaw());
     1588            Bstr ("0").detachTo (values.appendedRaw());
     1589        }
    13531590
    13541591        CHECK_ERROR_BREAK (hardDisk,
     
    55675804    ////////////////////////////////////////////////////////////////////////////
    55685805
    5569     /* convertdd: does not need a VirtualBox instantiation) */
     5806    /* converthd: does not need a VirtualBox instantiation. */
     5807    if (argc >= iCmdArg && (strcmp(argv[iCmd], "converthd") == 0))
     5808    {
     5809        rc = handleConvertHardDisk(argc - iCmdArg, argv + iCmdArg);
     5810        break;
     5811    }
     5812
     5813    /* convertdd: does not need a VirtualBox instantiation. */
    55705814    if (argc >= iCmdArg && (strcmp(argv[iCmd], "convertdd") == 0))
    55715815    {
     
    56235867        { "modifyhd",         handleModifyHardDisk },
    56245868        { "modifyvdi",        handleModifyHardDisk }, /* backward compatiblity */
     5869        { "clonehd",          handleCloneHardDisk },
     5870        { "clonevdi",         handleCloneHardDisk }, /* backward compatiblity */
    56255871        { "addiscsidisk",     handleAddiSCSIDisk },
    56265872        { "createvm",         handleCreateVM },
    56275873        { "modifyvm",         handleModifyVM },
    5628         { "clonehd",          handleCloneHardDisk },
    5629         { "clonevdi",         handleCloneHardDisk }, /* backward compatiblity */
    56305874        { "startvm",          handleStartVM },
    56315875        { "controlvm",        handleControlVM },
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManage.h

    r14732 r15366  
    7070#define USAGE_LOADSYMS              RT_BIT_64(29)
    7171#define USAGE_UNLOADSYMS            RT_BIT_64(30)
    72 #define USAGE_SETVDIUUID            RT_BIT_64(31)
     72#define USAGE_SETHDUUID             RT_BIT_64(31)
    7373#define USAGE_CONVERTDD             RT_BIT_64(32)
    7474#define USAGE_LISTPARTITIONS        RT_BIT_64(33)
     
    8484#define USAGE_CONVERTTORAW          RT_BIT_64(41)
    8585#define USAGE_METRICS               RT_BIT_64(42)
    86 #define USAGE_CONVERTDISK           RT_BIT_64(43)
     86#define USAGE_CONVERTHD             RT_BIT_64(43)
    8787#define USAGE_ALL                   (~(uint64_t)0)
    8888/** @} */
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageInfo.cpp

    r14814 r15366  
    3333#include <VBox/com/VirtualBox.h>
    3434
    35 #include <VBox/VBoxHDD.h>
    3635#include <VBox/log.h>
    3736#include <iprt/stream.h>
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette