Changeset 15366 in vbox for trunk/src/VBox/Frontends/VBoxManage
- Timestamp:
- Dec 12, 2008 1:50:32 PM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 40805
- Location:
- trunk/src/VBox/Frontends/VBoxManage
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxInternalManage.cpp
r14838 r15366 36 36 #include <VBox/com/VirtualBox.h> 37 37 38 #include <VBox/VBoxHDD.h>39 38 #include <VBox/VBoxHDD-new.h> 40 39 #include <VBox/sup.h> … … 140 139 "\n" 141 140 : "", 142 (u64Cmd & USAGE_SET VDIUUID) ?143 " set vdiuuid <filepath>\n"144 " Assigns a new UUID to the given VDIfile. This way, multiple copies\n"145 " of VDI containerscan 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" 146 145 "\n" 147 146 : "", … … 187 186 "\n" 188 187 : "", 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 : "",195 188 #ifdef RT_OS_WINDOWS 196 189 (u64Cmd & USAGE_MODINSTALL) ? … … 469 462 } 470 463 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 else490 {491 RTPrintf("UUID changed to: %s\n", uuid.toString().raw());492 }493 494 return 0;495 }496 497 464 498 465 static DECLCALLBACK(void) handleVDError(void *pvUser, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va) … … 502 469 RTPrintf("\n"); 503 470 RTPrintf("Error code %Rrc at %s(%u) in function %s\n", rc, RT_SRC_POS_ARGS); 471 } 472 473 static 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); 504 531 } 505 532 … … 1164 1191 AssertRC(vrc); 1165 1192 1166 vrc = VDCreate( &vdInterfaceError, &pDisk);1193 vrc = VDCreate(pVDIfs, &pDisk); 1167 1194 if (RT_FAILURE(vrc)) 1168 1195 { … … 1273 1300 AssertRC(vrc); 1274 1301 1275 vrc = VDCreate( &vdInterfaceError, &pDisk);1302 vrc = VDCreate(pVDIfs, &pDisk); 1276 1303 if (RT_FAILURE(vrc)) 1277 1304 { … … 1354 1381 AssertRC(vrc); 1355 1382 1356 vrc = VDCreate( &vdInterfaceError, &pDisk);1383 vrc = VDCreate(pVDIfs, &pDisk); 1357 1384 if (RT_FAILURE(vrc)) 1358 1385 { … … 1456 1483 } 1457 1484 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 else1498 {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 do1521 {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 1584 1485 /** 1585 1486 * Unloads the neccessary driver. … … 1636 1537 //if (!strcmp(pszCmd, "unloadsyms")) 1637 1538 // return CmdUnloadSyms(argc - 1 , &argv[1]); 1638 if (!strcmp(pszCmd, "set vdiuuid"))1639 return handleSet VDIUUID(argc - 1, &argv[1], aVirtualBox, aSession);1539 if (!strcmp(pszCmd, "sethduuid") || !strcmp(pszCmd, "setvdiuuid")) 1540 return handleSetHDUUID(argc - 1, &argv[1], aVirtualBox, aSession); 1640 1541 if (!strcmp(pszCmd, "listpartitions")) 1641 1542 return CmdListPartitions(argc - 1, &argv[1], aVirtualBox, aSession); … … 1646 1547 if (!strcmp(pszCmd, "converttoraw")) 1647 1548 return CmdConvertToRaw(argc - 1, &argv[1], aVirtualBox, aSession); 1648 if (!strcmp(pszCmd, "convertdisk"))1649 return CmdConvertDisk(argc - 1, &argv[1], aVirtualBox, aSession);1650 1549 1651 1550 if (!strcmp(pszCmd, "modinstall")) -
trunk/src/VBox/Frontends/VBoxManage/VBoxManage.cpp
r15267 r15366 54 54 #include <iprt/uuid.h> 55 55 #include <VBox/version.h> 56 #include <VBox/VBoxHDD .h>56 #include <VBox/VBoxHDD-new.h> 57 57 #include <VBox/log.h> 58 58 … … 512 512 RTPrintf("VBoxManage createhd -filename <filename>\n" 513 513 " -size <megabytes>\n" 514 " [-format VDI|VMDK]\n" 514 515 " [-static]\n" 515 516 " [-comment <comment>]\n" … … 533 534 } 534 535 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 535 544 if (u64Cmd & USAGE_CONVERTDD) 536 545 { 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" 539 550 "\n"); 540 551 } … … 550 561 " [-password <password>]\n" 551 562 " [-comment <comment>]\n" 563 " [-intnet]\n" 552 564 "\n"); 553 565 } … … 816 828 } 817 829 830 831 static 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 818 840 static int handleCreateHardDisk(int argc, char *argv[], 819 841 ComPtr<IVirtualBox> virtualBox, ComPtr<ISession> session) … … 822 844 Bstr filename; 823 845 uint64_t sizeMB = 0; 846 Bstr format = "VDI"; 824 847 bool fStatic = false; 825 848 Bstr comment; … … 844 867 sizeMB = RTStrToUInt64(argv[i]); 845 868 } 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 } 846 876 else if (strcmp(argv[i], "-static") == 0) 847 877 { … … 877 907 878 908 ComPtr<IHardDisk2> hardDisk; 879 CHECK_ERROR(virtualBox, CreateHardDisk2( Bstr("VDI"), filename, hardDisk.asOutParam()));909 CHECK_ERROR(virtualBox, CreateHardDisk2(format, filename, hardDisk.asOutParam())); 880 910 if (SUCCEEDED(rc) && hardDisk) 881 911 { … … 939 969 } 940 970 971 #if 0 /* disabled until disk shrinking is implemented based on VBoxHDD-new */ 941 972 static DECLCALLBACK(int) hardDiskProgressCallback(PVM pVM, unsigned uPercent, void *pvUser) 942 973 { … … 954 985 return VINF_SUCCESS; 955 986 } 987 #endif 956 988 957 989 … … 1020 1052 else if (strcmp(argv[1], "compact") == 0) 1021 1053 { 1054 #if 1 1055 RTPrintf("Error: Shrink hard disk operation is temporarily unavailable!\n"); 1056 return 1; 1057 #else 1022 1058 /* the hard disk image might not be registered */ 1023 1059 if (!hardDisk) … … 1048 1084 rc = E_FAIL; 1049 1085 } 1086 #endif 1050 1087 } 1051 1088 else … … 1104 1141 } 1105 1142 1143 static 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 1106 1269 static int handleConvertDDImage(int argc, char *argv[]) 1107 1270 { 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]; 1116 1311 #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"); 1120 1313 #endif 1121 1122 if ((!fReadFromStdIn && argc != arg + 2) || (fReadFromStdIn && argc != arg + 3))1123 return errorSyntax(USAGE_CONVERTDD, "Incorrect number of parameters");1314 } 1315 } 1316 } 1124 1317 1125 1318 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); 1127 1334 1128 1335 /* open raw image file. */ 1129 1336 RTFILE File; 1130 int rc = VINF_SUCCESS;1131 1337 if (fReadFromStdIn) 1132 1338 File = 0; 1133 1339 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); 1135 1341 if (RT_FAILURE(rc)) 1136 1342 { 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; 1139 1345 } 1140 1346 … … 1142 1348 /* get image size. */ 1143 1349 if (fReadFromStdIn) 1144 cbFile = RTStrToUInt64( argv[arg + 2]);1350 cbFile = RTStrToUInt64(filesize); 1145 1351 else 1146 1352 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 ? 1172 1406 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 1419 out: 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); 1203 1428 } 1204 1429 … … 1214 1439 Bstr password; 1215 1440 Bstr comment; 1441 bool fIntNet = false; 1216 1442 1217 1443 /* at least server and target */ … … 1299 1525 comment = argv[i]; 1300 1526 } 1527 else if (strcmp(argv[i], "-intnet") == 0) 1528 { 1529 i++; 1530 fIntNet = true; 1531 } 1301 1532 else 1302 1533 return errorSyntax(USAGE_ADDISCSIDISK, "Invalid parameter '%s'", Utf8Str(argv[i]).raw()); … … 1351 1582 1352 1583 /// @todo add -targetName and -targetPassword options 1584 1585 if (fIntNet) 1586 { 1587 Bstr ("HostIPStack").detachTo (names.appendedRaw()); 1588 Bstr ("0").detachTo (values.appendedRaw()); 1589 } 1353 1590 1354 1591 CHECK_ERROR_BREAK (hardDisk, … … 5567 5804 //////////////////////////////////////////////////////////////////////////// 5568 5805 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. */ 5570 5814 if (argc >= iCmdArg && (strcmp(argv[iCmd], "convertdd") == 0)) 5571 5815 { … … 5623 5867 { "modifyhd", handleModifyHardDisk }, 5624 5868 { "modifyvdi", handleModifyHardDisk }, /* backward compatiblity */ 5869 { "clonehd", handleCloneHardDisk }, 5870 { "clonevdi", handleCloneHardDisk }, /* backward compatiblity */ 5625 5871 { "addiscsidisk", handleAddiSCSIDisk }, 5626 5872 { "createvm", handleCreateVM }, 5627 5873 { "modifyvm", handleModifyVM }, 5628 { "clonehd", handleCloneHardDisk },5629 { "clonevdi", handleCloneHardDisk }, /* backward compatiblity */5630 5874 { "startvm", handleStartVM }, 5631 5875 { "controlvm", handleControlVM }, -
trunk/src/VBox/Frontends/VBoxManage/VBoxManage.h
r14732 r15366 70 70 #define USAGE_LOADSYMS RT_BIT_64(29) 71 71 #define USAGE_UNLOADSYMS RT_BIT_64(30) 72 #define USAGE_SET VDIUUIDRT_BIT_64(31)72 #define USAGE_SETHDUUID RT_BIT_64(31) 73 73 #define USAGE_CONVERTDD RT_BIT_64(32) 74 74 #define USAGE_LISTPARTITIONS RT_BIT_64(33) … … 84 84 #define USAGE_CONVERTTORAW RT_BIT_64(41) 85 85 #define USAGE_METRICS RT_BIT_64(42) 86 #define USAGE_CONVERT DISKRT_BIT_64(43)86 #define USAGE_CONVERTHD RT_BIT_64(43) 87 87 #define USAGE_ALL (~(uint64_t)0) 88 88 /** @} */ -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageInfo.cpp
r14814 r15366 33 33 #include <VBox/com/VirtualBox.h> 34 34 35 #include <VBox/VBoxHDD.h>36 35 #include <VBox/log.h> 37 36 #include <iprt/stream.h>
Note:
See TracChangeset
for help on using the changeset viewer.