Changeset 12775 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Sep 26, 2008 5:04:24 PM (16 years ago)
- Location:
- trunk/src/VBox/Frontends/VBoxManage
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxInternalManage.cpp
r11444 r12775 184 184 "\n" 185 185 : "", 186 (u64Cmd & USAGE_CONVERTDISK) ? 187 " convertdisk [-srcformat <fmt>] [-dstformat <fmt>] <inputfile> <outputfile>" 188 "\n" 189 " Convert image to another image format.\n" 190 "\n" 191 : "", 186 192 #ifdef RT_OS_WINDOWS 187 193 (u64Cmd & USAGE_MODINSTALL) ? … … 1452 1458 } 1453 1459 1460 static int CmdConvertDisk(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession) 1461 { 1462 Bstr srcformat; 1463 Bstr dstformat; 1464 Bstr src; 1465 Bstr dst; 1466 int vrc; 1467 PVBOXHDD pSrcDisk = NULL; 1468 PVBOXHDD pDstDisk = NULL; 1469 1470 /* Parse the arguments. */ 1471 for (int i = 0; i < argc; i++) 1472 { 1473 if (strcmp(argv[i], "-srcformat") == 0) 1474 { 1475 if (argc <= i + 1) 1476 { 1477 return errorArgument("Missing argument to '%s'", argv[i]); 1478 } 1479 i++; 1480 srcformat = argv[i]; 1481 } 1482 else if (strcmp(argv[i], "-dstformat") == 0) 1483 { 1484 if (argc <= i + 1) 1485 { 1486 return errorArgument("Missing argument to '%s'", argv[i]); 1487 } 1488 i++; 1489 dstformat = argv[i]; 1490 } 1491 else if (src.isEmpty()) 1492 { 1493 src = argv[i]; 1494 } 1495 else if (dst.isEmpty()) 1496 { 1497 dst = argv[i]; 1498 } 1499 else 1500 { 1501 return errorSyntax(USAGE_CONVERTDISK, "Invalid parameter '%s'", Utf8Str(argv[i]).raw()); 1502 } 1503 } 1504 1505 if (src.isEmpty()) 1506 return errorSyntax(USAGE_CONVERTDISK, "Mandatory input image parameter missing"); 1507 if (dst.isEmpty()) 1508 return errorSyntax(USAGE_CONVERTDISK, "Mandatory output image parameter missing"); 1509 1510 1511 PVDINTERFACE pVDIfs = NULL; 1512 VDINTERFACE vdInterfaceError; 1513 VDINTERFACEERROR vdInterfaceErrorCallbacks; 1514 vdInterfaceErrorCallbacks.cbSize = sizeof(VDINTERFACEERROR); 1515 vdInterfaceErrorCallbacks.enmInterface = VDINTERFACETYPE_ERROR; 1516 vdInterfaceErrorCallbacks.pfnError = handleVDError; 1517 1518 vrc = VDInterfaceAdd(&vdInterfaceError, "VBoxManage_IError", VDINTERFACETYPE_ERROR, 1519 &vdInterfaceErrorCallbacks, NULL, &pVDIfs); 1520 AssertRC(vrc); 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 (VBOX_FAILURE(vrc)) 1528 { 1529 RTPrintf("No file format specified and autodetect failed - please specify format: %Vrc\n", vrc); 1530 goto cleanup; 1531 } 1532 srcformat = pszFormat; 1533 RTStrFree(pszFormat); 1534 } 1535 1536 vrc = VDCreate(&vdInterfaceError, &pSrcDisk); 1537 if (VBOX_FAILURE(vrc)) 1538 { 1539 RTPrintf("Error while creating the source virtual disk container: %Vrc\n", vrc); 1540 goto cleanup; 1541 } 1542 1543 /* Open the input image */ 1544 vrc = VDOpen(pSrcDisk, Utf8Str(srcformat).raw(), Utf8Str(src).raw(), VD_OPEN_FLAGS_READONLY, NULL); 1545 if (VBOX_FAILURE(vrc)) 1546 { 1547 RTPrintf("Error while opening the source image: %Vrc\n", vrc); 1548 goto cleanup; 1549 } 1550 1551 /* Output format defaults to VDI */ 1552 if (dstformat.isEmpty()) 1553 dstformat = "VDI"; 1554 1555 vrc = VDCreate(&vdInterfaceError, &pDstDisk); 1556 if (VBOX_FAILURE(vrc)) 1557 { 1558 RTPrintf("Error while creating the destination virtual disk container: %Vrc\n", vrc); 1559 goto cleanup; 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 (VBOX_FAILURE(vrc)) 1569 { 1570 RTPrintf("Error while copying the image: %Vrc\n", vrc); 1571 } 1572 1573 cleanup: 1574 if (pDstDisk) 1575 VDCloseAll(pDstDisk); 1576 if (pSrcDisk) 1577 VDCloseAll(pSrcDisk); 1578 return VBOX_SUCCESS(vrc) ? 0 : 1; 1579 } 1580 1454 1581 /** 1455 1582 * Unloads the neccessary driver. … … 1516 1643 if (!strcmp(pszCmd, "converttoraw")) 1517 1644 return CmdConvertToRaw(argc - 1, &argv[1], aVirtualBox, aSession); 1645 if (!strcmp(pszCmd, "convertdisk")) 1646 return CmdConvertDisk(argc - 1, &argv[1], aVirtualBox, aSession); 1518 1647 1519 1648 if (!strcmp(pszCmd, "modinstall")) -
trunk/src/VBox/Frontends/VBoxManage/VBoxManage.h
r11703 r12775 77 77 #define USAGE_CONVERTTORAW RT_BIT_64(41) 78 78 #define USAGE_METRICS RT_BIT_64(42) 79 #define USAGE_CONVERTDISK RT_BIT_64(43) 79 80 #define USAGE_ALL (~(uint64_t)0) 80 81 /** @} */
Note:
See TracChangeset
for help on using the changeset viewer.