Changeset 32395 in vbox for trunk/src/VBox/Devices/Storage/testcase
- Timestamp:
- Sep 10, 2010 12:17:06 PM (14 years ago)
- svn:sync-xref-src-repo-rev:
- 65754
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Storage/testcase/vbox-img.cpp
r32380 r32395 47 47 " [--srcformat VDI|VMDK|VHD|RAW|..]\n" 48 48 " [--dstformat VDI|VMDK|VHD|RAW|..]\n" 49 " [--variant Standard,Fixed,Split2G,Stream,ESX]\n", 49 " [--variant Standard,Fixed,Split2G,Stream,ESX]\n" 50 "\n" 51 " info --filename <filename>\n" 52 "\n" 53 " compact --filename <filename>\n", 50 54 g_pszProgName); 51 55 } … … 73 77 va_list args; 74 78 va_start(args, pszFormat); 75 RT MsgWarningV(pszFormat, args);79 RTPrintfV(pszFormat, args); 76 80 va_end(args); 77 81 return VINF_SUCCESS; … … 89 93 "Syntax error: %N\n", pszFormat, &args); 90 94 va_end(args); 95 showUsage(); 91 96 return 1; 92 97 } 98 int errorRuntime(const char *pszFormat, ...) 99 { 100 va_list args; 101 102 va_start(args, pszFormat); 103 RTPrintf("\n" 104 "Error: %N\n", pszFormat, &args); 105 va_end(args); 106 return 1; 107 } 108 93 109 94 110 … … 163 179 rc = VDGetFormat(NULL, pszFilename, &pszFormat); 164 180 if (RT_FAILURE(rc)) 165 return error Syntax("Format autodetect failed: %Rrc\n", rc);181 return errorRuntime("Format autodetect failed: %Rrc\n", rc); 166 182 } 167 183 … … 169 185 rc = VDCreate(pVDIfs, &pVD); 170 186 if (RT_FAILURE(rc)) 171 return error Syntax("Cannot create the virtual disk container: %Rrc\n", rc);187 return errorRuntime("Cannot create the virtual disk container: %Rrc\n", rc); 172 188 173 189 174 190 rc = VDOpen(pVD, pszFormat, pszFilename, VD_OPEN_FLAGS_NORMAL, NULL); 175 191 if (RT_FAILURE(rc)) 176 return error Syntax("Cannot open the virtual disk image \"%s\": %Rrc\n",177 pszFilename, rc);192 return errorRuntime("Cannot open the virtual disk image \"%s\": %Rrc\n", 193 pszFilename, rc); 178 194 179 195 RTUUID oldImageUuid; 180 196 rc = VDGetUuid(pVD, VD_LAST_IMAGE, &oldImageUuid); 181 197 if (RT_FAILURE(rc)) 182 return error Syntax("Cannot get UUID of virtual disk image \"%s\": %Rrc\n",183 pszFilename, rc);198 return errorRuntime("Cannot get UUID of virtual disk image \"%s\": %Rrc\n", 199 pszFilename, rc); 184 200 185 201 RTPrintf("Old image UUID: %RTuuid\n", &oldImageUuid); … … 188 204 rc = VDGetParentUuid(pVD, VD_LAST_IMAGE, &oldParentUuid); 189 205 if (RT_FAILURE(rc)) 190 return error Syntax("Cannot get parent UUID of virtual disk image \"%s\": %Rrc\n",191 pszFilename, rc);206 return errorRuntime("Cannot get parent UUID of virtual disk image \"%s\": %Rrc\n", 207 pszFilename, rc); 192 208 193 209 RTPrintf("Old parent UUID: %RTuuid\n", &oldParentUuid); … … 198 214 rc = VDSetUuid(pVD, VD_LAST_IMAGE, &imageUuid); 199 215 if (RT_FAILURE(rc)) 200 return error Syntax("Cannot set UUID of virtual disk image \"%s\": %Rrc\n",201 pszFilename, rc);216 return errorRuntime("Cannot set UUID of virtual disk image \"%s\": %Rrc\n", 217 pszFilename, rc); 202 218 } 203 219 … … 207 223 rc = VDSetParentUuid(pVD, VD_LAST_IMAGE, &parentUuid); 208 224 if (RT_FAILURE(rc)) 209 return error Syntax("Cannot set parent UUID of virtual disk image \"%s\": %Rrc\n",210 pszFilename, rc);225 return errorRuntime("Cannot set parent UUID of virtual disk image \"%s\": %Rrc\n", 226 pszFilename, rc); 211 227 } 212 228 213 229 rc = VDCloseAll(pVD); 214 230 if (RT_FAILURE(rc)) 215 return error Syntax("Closing image failed! rc=%Rrc\n", rc);231 return errorRuntime("Closing image failed! rc=%Rrc\n", rc); 216 232 217 233 if (pszFormat) … … 333 349 if (RT_FAILURE(rc)) 334 350 { 335 error Syntax("Error while creating source disk container: %Rrc\n", rc);351 errorRuntime("Error while creating source disk container: %Rrc\n", rc); 336 352 break; 337 353 } … … 340 356 if (RT_FAILURE(rc)) 341 357 { 342 error Syntax("Error while opening source image: %Rrc\n", rc);358 errorRuntime("Error while opening source image: %Rrc\n", rc); 343 359 break; 344 360 } … … 351 367 if (RT_FAILURE(rc)) 352 368 { 353 error Syntax("Error while creating the destination disk container: %Rrc\n", rc);369 errorRuntime("Error while creating the destination disk container: %Rrc\n", rc); 354 370 break; 355 371 } … … 363 379 if (RT_FAILURE(rc)) 364 380 { 365 error Syntax("Error while copying the image: %Rrc\n", rc);381 errorRuntime("Error while copying the image: %Rrc\n", rc); 366 382 break; 367 383 } … … 376 392 377 393 return RT_SUCCESS(rc) ? 0 : 1; 394 } 395 396 397 int handleInfo(HandlerArg *a) 398 { 399 int rc = VINF_SUCCESS; 400 PVBOXHDD pDisk = NULL; 401 const char *pszFilename = NULL; 402 403 /* Parse the command line. */ 404 static const RTGETOPTDEF s_aOptions[] = 405 { 406 { "--filename", 'f', RTGETOPT_REQ_STRING } 407 }; 408 int ch; 409 RTGETOPTUNION ValueUnion; 410 RTGETOPTSTATE GetState; 411 RTGetOptInit(&GetState, a->argc, a->argv, s_aOptions, RT_ELEMENTS(s_aOptions), 0, 0 /* fFlags */); 412 while ((ch = RTGetOpt(&GetState, &ValueUnion))) 413 { 414 switch (ch) 415 { 416 case 'f': // --filename 417 pszFilename = ValueUnion.psz; 418 break; 419 420 default: 421 ch = RTGetOptPrintError(ch, &ValueUnion); 422 showUsage(); 423 return ch; 424 } 425 } 426 427 /* Check for mandatory parameters. */ 428 if (!pszFilename) 429 return errorSyntax("Mandatory --filename option missing\n"); 430 431 /* just try it */ 432 char *pszFormat = NULL; 433 rc = VDGetFormat(NULL, pszFilename, &pszFormat); 434 if (RT_FAILURE(rc)) 435 return errorSyntax("Format autodetect failed: %Rrc\n", rc); 436 437 rc = VDCreate(pVDIfs, &pDisk); 438 if (RT_FAILURE(rc)) 439 return errorRuntime("Error while creating the virtual disk container: %Rrc\n", rc); 440 441 /* Open the image */ 442 rc = VDOpen(pDisk, pszFormat, pszFilename, VD_OPEN_FLAGS_INFO, NULL); 443 if (RT_FAILURE(rc)) 444 return errorRuntime("Error while opening the image: %Rrc\n", rc); 445 446 VDDumpImages(pDisk); 447 448 VDCloseAll(pDisk); 449 450 return rc; 451 } 452 453 int handleCompact(HandlerArg *a) 454 { 455 int rc = VINF_SUCCESS; 456 PVBOXHDD pDisk = NULL; 457 const char *pszFilename = NULL; 458 459 /* Parse the command line. */ 460 static const RTGETOPTDEF s_aOptions[] = 461 { 462 { "--filename", 'f', RTGETOPT_REQ_STRING } 463 }; 464 int ch; 465 RTGETOPTUNION ValueUnion; 466 RTGETOPTSTATE GetState; 467 RTGetOptInit(&GetState, a->argc, a->argv, s_aOptions, RT_ELEMENTS(s_aOptions), 0, 0 /* fFlags */); 468 while ((ch = RTGetOpt(&GetState, &ValueUnion))) 469 { 470 switch (ch) 471 { 472 case 'f': // --filename 473 pszFilename = ValueUnion.psz; 474 break; 475 476 default: 477 ch = RTGetOptPrintError(ch, &ValueUnion); 478 showUsage(); 479 return ch; 480 } 481 } 482 483 /* Check for mandatory parameters. */ 484 if (!pszFilename) 485 return errorSyntax("Mandatory --filename option missing\n"); 486 487 /* just try it */ 488 char *pszFormat = NULL; 489 rc = VDGetFormat(NULL, pszFilename, &pszFormat); 490 if (RT_FAILURE(rc)) 491 return errorSyntax("Format autodetect failed: %Rrc\n", rc); 492 493 rc = VDCreate(pVDIfs, &pDisk); 494 if (RT_FAILURE(rc)) 495 return errorRuntime("Error while creating the virtual disk container: %Rrc\n", rc); 496 497 /* Open the image */ 498 rc = VDOpen(pDisk, pszFormat, pszFilename, VD_OPEN_FLAGS_NORMAL, NULL); 499 if (RT_FAILURE(rc)) 500 return errorRuntime("Error while opening the image: %Rrc\n", rc); 501 502 rc = VDCompact(pDisk, 0, NULL); 503 if (RT_FAILURE(rc)) 504 errorRuntime("Error while compacting image: %Rrc\n", rc); 505 506 VDCloseAll(pDisk); 507 508 return rc; 378 509 } 379 510 … … 470 601 { "setuuid", handleSetUUID }, 471 602 { "convert", handleConvert }, 603 { "info", handleInfo }, 604 { "compact", handleCompact }, 472 605 { NULL, NULL } 473 606 };
Note:
See TracChangeset
for help on using the changeset viewer.