Changeset 15602 in vbox for trunk/src/VBox
- Timestamp:
- Dec 16, 2008 6:01:38 PM (16 years ago)
- Location:
- trunk/src/VBox/Frontends/VBoxManage
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxInternalManage.cpp
r15529 r15602 123 123 "Commands:\n" 124 124 "\n" 125 "%s%s%s%s%s%s%s%s "125 "%s%s%s%s%s%s%s%s%s" 126 126 "WARNING: This is a development tool and shall only be used to analyse\n" 127 127 " problems. It is completely unsupported and will change in\n" … … 186 186 "\n" 187 187 : "", 188 (u64Cmd & USAGE_CONVERTHD) ? 189 " converthd [-srcformat VDI|VMDK|VHD|RAW]\n" 190 " [-dstformat VDI|VMDK|VHD|RAW]\n" 191 " <inputfile> <outputfile>\n" 192 " converts hard disk images between formats\n" 193 "\n" 194 : "", 188 195 #ifdef RT_OS_WINDOWS 189 196 (u64Cmd & USAGE_MODINSTALL) ? … … 1483 1490 } 1484 1491 1492 static int CmdConvertHardDisk(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession) 1493 { 1494 Bstr srcformat; 1495 Bstr dstformat; 1496 Bstr src; 1497 Bstr dst; 1498 int vrc; 1499 PVBOXHDD pSrcDisk = NULL; 1500 PVBOXHDD pDstDisk = NULL; 1501 1502 /* Parse the arguments. */ 1503 for (int i = 0; i < argc; i++) 1504 { 1505 if (strcmp(argv[i], "-srcformat") == 0) 1506 { 1507 if (argc <= i + 1) 1508 { 1509 return errorArgument("Missing argument to '%s'", argv[i]); 1510 } 1511 i++; 1512 srcformat = argv[i]; 1513 } 1514 else if (strcmp(argv[i], "-dstformat") == 0) 1515 { 1516 if (argc <= i + 1) 1517 { 1518 return errorArgument("Missing argument to '%s'", argv[i]); 1519 } 1520 i++; 1521 dstformat = argv[i]; 1522 } 1523 else if (src.isEmpty()) 1524 { 1525 src = argv[i]; 1526 } 1527 else if (dst.isEmpty()) 1528 { 1529 dst = argv[i]; 1530 } 1531 else 1532 { 1533 return errorSyntax(USAGE_CONVERTHD, "Invalid parameter '%s'", Utf8Str(argv[i]).raw()); 1534 } 1535 } 1536 1537 if (src.isEmpty()) 1538 return errorSyntax(USAGE_CONVERTHD, "Mandatory input image parameter missing"); 1539 if (dst.isEmpty()) 1540 return errorSyntax(USAGE_CONVERTHD, "Mandatory output image parameter missing"); 1541 1542 1543 PVDINTERFACE pVDIfs = NULL; 1544 VDINTERFACE vdInterfaceError; 1545 VDINTERFACEERROR vdInterfaceErrorCallbacks; 1546 vdInterfaceErrorCallbacks.cbSize = sizeof(VDINTERFACEERROR); 1547 vdInterfaceErrorCallbacks.enmInterface = VDINTERFACETYPE_ERROR; 1548 vdInterfaceErrorCallbacks.pfnError = handleVDError; 1549 1550 vrc = VDInterfaceAdd(&vdInterfaceError, "VBoxManage_IError", VDINTERFACETYPE_ERROR, 1551 &vdInterfaceErrorCallbacks, NULL, &pVDIfs); 1552 AssertRC(vrc); 1553 1554 do 1555 { 1556 /* Try to determine input image format */ 1557 if (srcformat.isEmpty()) 1558 { 1559 char *pszFormat = NULL; 1560 vrc = VDGetFormat(Utf8Str(src).raw(), &pszFormat); 1561 if (RT_FAILURE(vrc)) 1562 { 1563 RTPrintf("No file format specified and autodetect failed - please specify format: %Rrc\n", vrc); 1564 break; 1565 } 1566 srcformat = pszFormat; 1567 RTStrFree(pszFormat); 1568 } 1569 1570 vrc = VDCreate(pVDIfs, &pSrcDisk); 1571 if (RT_FAILURE(vrc)) 1572 { 1573 RTPrintf("Error while creating the source virtual disk container: %Rrc\n", vrc); 1574 break; 1575 } 1576 1577 /* Open the input image */ 1578 vrc = VDOpen(pSrcDisk, Utf8Str(srcformat).raw(), Utf8Str(src).raw(), VD_OPEN_FLAGS_READONLY, NULL); 1579 if (RT_FAILURE(vrc)) 1580 { 1581 RTPrintf("Error while opening the source image: %Rrc\n", vrc); 1582 break; 1583 } 1584 1585 /* Output format defaults to VDI */ 1586 if (dstformat.isEmpty()) 1587 dstformat = "VDI"; 1588 1589 vrc = VDCreate(pVDIfs, &pDstDisk); 1590 if (RT_FAILURE(vrc)) 1591 { 1592 RTPrintf("Error while creating the destination virtual disk container: %Rrc\n", vrc); 1593 break; 1594 } 1595 1596 uint64_t cbSize = VDGetSize(pSrcDisk, VD_LAST_IMAGE); 1597 RTPrintf("Converting image \"%s\" with size %RU64 bytes (%RU64MB)...\n", Utf8Str(src).raw(), cbSize, (cbSize + _1M - 1) / _1M); 1598 1599 /* Create the output image */ 1600 vrc = VDCopy(pSrcDisk, VD_LAST_IMAGE, pDstDisk, Utf8Str(dstformat).raw(), 1601 Utf8Str(dst).raw(), false, 0, NULL, NULL, NULL, NULL); 1602 if (RT_FAILURE(vrc)) 1603 { 1604 RTPrintf("Error while copying the image: %Rrc\n", vrc); 1605 break; 1606 } 1607 } 1608 while (0); 1609 if (pDstDisk) 1610 VDCloseAll(pDstDisk); 1611 if (pSrcDisk) 1612 VDCloseAll(pSrcDisk); 1613 1614 return RT_SUCCESS(vrc) ? 0 : 1; 1615 } 1616 1485 1617 /** 1486 1618 * Unloads the neccessary driver. … … 1547 1679 if (!strcmp(pszCmd, "converttoraw")) 1548 1680 return CmdConvertToRaw(argc - 1, &argv[1], aVirtualBox, aSession); 1681 if (!strcmp(pszCmd, "converthd")) 1682 return CmdConvertHardDisk(argc - 1, &argv[1], aVirtualBox, aSession); 1549 1683 1550 1684 if (!strcmp(pszCmd, "modinstall")) -
trunk/src/VBox/Frontends/VBoxManage/VBoxManage.cpp
r15574 r15602 535 535 } 536 536 537 if (u64Cmd & USAGE_CONVERTHD) 538 { 539 RTPrintf("VBoxManage converthd [-srcformat VDI|VMDK|VHD|RAW]\n" 540 " [-dstformat VDI|VMDK|VHD|RAW]\n" 541 " <inputfile> <outputfile>\n" 542 "\n"); 543 } 544 545 if (u64Cmd & USAGE_CONVERTDD) 546 { 547 RTPrintf("VBoxManage convertdd [-static] [-format VDI|VMDK|VHD]" 537 if (u64Cmd & USAGE_CONVERTFROMRAW) 538 { 539 RTPrintf("VBoxManage convertfromraw [-static] [-format VDI|VMDK|VHD]\n" 548 540 " <filename> <outputfile>\n" 549 "VBoxManage convert dd [-static] [-format VDI|VMDK|VHD]"541 "VBoxManage convertfromraw [-static] [-format VDI|VMDK|VHD]\n" 550 542 " stdin <outputfile> <bytes>\n" 551 543 "\n"); … … 4804 4796 //////////////////////////////////////////////////////////////////////////// 4805 4797 4806 /* converthd: does not need a VirtualBox instantiation. */ 4807 if (argc >= iCmdArg && (strcmp(argv[iCmd], "converthd") == 0)) 4808 { 4809 rc = handleConvertHardDisk(argc - iCmdArg, argv + iCmdArg); 4810 break; 4811 } 4812 4813 /* convertdd: does not need a VirtualBox instantiation. */ 4814 if (argc >= iCmdArg && (strcmp(argv[iCmd], "convertdd") == 0)) 4815 { 4816 rc = handleConvertDDImage(argc - iCmdArg, argv + iCmdArg); 4798 /* convertfromraw: does not need a VirtualBox instantiation. */ 4799 if (argc >= iCmdArg && ( !strcmp(argv[iCmd], "convertfromraw") 4800 || !strcmp(argv[iCmd], "convertdd"))) 4801 { 4802 rc = handleConvertFromRaw(argc - iCmdArg, argv + iCmdArg); 4817 4803 break; 4818 4804 } -
trunk/src/VBox/Frontends/VBoxManage/VBoxManage.h
r15499 r15602 71 71 #define USAGE_UNLOADSYMS RT_BIT_64(30) 72 72 #define USAGE_SETHDUUID RT_BIT_64(31) 73 #define USAGE_CONVERT DDRT_BIT_64(32)73 #define USAGE_CONVERTFROMRAW RT_BIT_64(32) 74 74 #define USAGE_LISTPARTITIONS RT_BIT_64(33) 75 75 #define USAGE_CREATERAWVMDK RT_BIT_64(34) … … 156 156 ComPtr<IVirtualBox> virtualBox, ComPtr<ISession> session); 157 157 int handleConvertHardDisk(int argc, char **argv); 158 int handleConvert DDImage(int argc, char *argv[]);158 int handleConvertFromRaw(int argc, char *argv[]); 159 159 int handleAddiSCSIDisk(int argc, char *argv[], 160 160 ComPtr <IVirtualBox> aVirtualBox, ComPtr<ISession> aSession); -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageDisk.cpp
r15567 r15602 428 428 } 429 429 430 int handleConvertHardDisk(int argc, char **argv) 431 { 432 Bstr srcformat; 433 Bstr dstformat; 434 Bstr src; 435 Bstr dst; 436 int vrc; 437 PVBOXHDD pSrcDisk = NULL; 438 PVBOXHDD pDstDisk = NULL; 439 440 /* Parse the arguments. */ 441 for (int i = 0; i < argc; i++) 442 { 443 if (strcmp(argv[i], "-srcformat") == 0) 444 { 445 if (argc <= i + 1) 446 { 447 return errorArgument("Missing argument to '%s'", argv[i]); 448 } 449 i++; 450 srcformat = argv[i]; 451 } 452 else if (strcmp(argv[i], "-dstformat") == 0) 453 { 454 if (argc <= i + 1) 455 { 456 return errorArgument("Missing argument to '%s'", argv[i]); 457 } 458 i++; 459 dstformat = argv[i]; 460 } 461 else if (src.isEmpty()) 462 { 463 src = argv[i]; 464 } 465 else if (dst.isEmpty()) 466 { 467 dst = argv[i]; 468 } 469 else 470 { 471 return errorSyntax(USAGE_CONVERTHD, "Invalid parameter '%s'", Utf8Str(argv[i]).raw()); 472 } 473 } 474 475 if (src.isEmpty()) 476 return errorSyntax(USAGE_CONVERTHD, "Mandatory input image parameter missing"); 477 if (dst.isEmpty()) 478 return errorSyntax(USAGE_CONVERTHD, "Mandatory output image parameter missing"); 479 480 481 PVDINTERFACE pVDIfs = NULL; 482 VDINTERFACE vdInterfaceError; 483 VDINTERFACEERROR vdInterfaceErrorCallbacks; 484 vdInterfaceErrorCallbacks.cbSize = sizeof(VDINTERFACEERROR); 485 vdInterfaceErrorCallbacks.enmInterface = VDINTERFACETYPE_ERROR; 486 vdInterfaceErrorCallbacks.pfnError = handleVDError; 487 488 vrc = VDInterfaceAdd(&vdInterfaceError, "VBoxManage_IError", VDINTERFACETYPE_ERROR, 489 &vdInterfaceErrorCallbacks, NULL, &pVDIfs); 490 AssertRC(vrc); 491 492 do 493 { 494 /* Try to determine input image format */ 495 if (srcformat.isEmpty()) 496 { 497 char *pszFormat = NULL; 498 vrc = VDGetFormat(Utf8Str(src).raw(), &pszFormat); 499 if (RT_FAILURE(vrc)) 500 { 501 RTPrintf("No file format specified and autodetect failed - please specify format: %Rrc\n", vrc); 502 break; 503 } 504 srcformat = pszFormat; 505 RTStrFree(pszFormat); 506 } 507 508 vrc = VDCreate(pVDIfs, &pSrcDisk); 509 if (RT_FAILURE(vrc)) 510 { 511 RTPrintf("Error while creating the source virtual disk container: %Rrc\n", vrc); 512 break; 513 } 514 515 /* Open the input image */ 516 vrc = VDOpen(pSrcDisk, Utf8Str(srcformat).raw(), Utf8Str(src).raw(), VD_OPEN_FLAGS_READONLY, NULL); 517 if (RT_FAILURE(vrc)) 518 { 519 RTPrintf("Error while opening the source image: %Rrc\n", vrc); 520 break; 521 } 522 523 /* Output format defaults to VDI */ 524 if (dstformat.isEmpty()) 525 dstformat = "VDI"; 526 527 vrc = VDCreate(pVDIfs, &pDstDisk); 528 if (RT_FAILURE(vrc)) 529 { 530 RTPrintf("Error while creating the destination virtual disk container: %Rrc\n", vrc); 531 break; 532 } 533 534 uint64_t cbSize = VDGetSize(pSrcDisk, VD_LAST_IMAGE); 535 RTPrintf("Converting image \"%s\" with size %RU64 bytes (%RU64MB)...\n", Utf8Str(src).raw(), cbSize, (cbSize + _1M - 1) / _1M); 536 537 /* Create the output image */ 538 vrc = VDCopy(pSrcDisk, VD_LAST_IMAGE, pDstDisk, Utf8Str(dstformat).raw(), 539 Utf8Str(dst).raw(), false, 0, NULL, NULL, NULL, NULL); 540 if (RT_FAILURE(vrc)) 541 { 542 RTPrintf("Error while copying the image: %Rrc\n", vrc); 543 break; 544 } 545 } 546 while (0); 547 if (pDstDisk) 548 VDCloseAll(pDstDisk); 549 if (pSrcDisk) 550 VDCloseAll(pSrcDisk); 551 552 return RT_SUCCESS(vrc) ? 0 : 1; 553 } 554 555 556 int handleConvertDDImage(int argc, char *argv[]) 430 int handleConvertFromRaw(int argc, char *argv[]) 557 431 { 558 432 VDIMAGETYPE enmImgType = VD_IMAGE_TYPE_NORMAL; … … 589 463 filesize = argv[i]; 590 464 else 591 return errorSyntax(USAGE_CONVERT DD, "Incorrect number of parameters");465 return errorSyntax(USAGE_CONVERTFROMRAW, "Incorrect number of parameters"); 592 466 } 593 467 else … … 604 478 } 605 479 606 RTPrintf("Converting VDI: from DDimage file=\"%s\" to file=\"%s\"...\n",480 RTPrintf("Converting from raw image file=\"%s\" to file=\"%s\"...\n", 607 481 srcfilename, dstfilename); 608 482
Note:
See TracChangeset
for help on using the changeset viewer.