Changeset 32431 in vbox for trunk/src/VBox/Devices/Storage/testcase
- Timestamp:
- Sep 11, 2010 6:02:17 PM (14 years ago)
- svn:sync-xref-src-repo-rev:
- 65796
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Storage/testcase/vbox-img.cpp
r32395 r32431 88 88 { 89 89 va_list args; 90 90 91 91 va_start(args, pszFormat); 92 92 RTPrintf("\n" … … 99 99 { 100 100 va_list args; 101 101 102 102 va_start(args, pszFormat); 103 103 RTPrintf("\n" … … 120 120 RTUuidClear(&parentUuid); 121 121 int rc; 122 122 123 123 /* Parse the command line. */ 124 124 static const RTGETOPTDEF s_aOptions[] = … … 163 163 } 164 164 } 165 165 166 166 /* Check for mandatory parameters. */ 167 167 if (!pszFilename) 168 168 return errorSyntax("Mandatory --filename option missing\n"); 169 169 170 170 /* Check for consistency of optional parameters. */ 171 171 if (fSetImageUuid && RTUuidIsNull(&imageUuid)) 172 172 return errorSyntax("Invalid parameter to --uuid option\n"); 173 173 174 174 /* Autodetect image format. */ 175 175 if (!pszFormat) … … 181 181 return errorRuntime("Format autodetect failed: %Rrc\n", rc); 182 182 } 183 183 184 184 PVBOXHDD pVD = NULL; 185 185 rc = VDCreate(pVDIfs, &pVD); 186 186 if (RT_FAILURE(rc)) 187 187 return errorRuntime("Cannot create the virtual disk container: %Rrc\n", rc); 188 189 188 189 190 190 rc = VDOpen(pVD, pszFormat, pszFilename, VD_OPEN_FLAGS_NORMAL, NULL); 191 191 if (RT_FAILURE(rc)) 192 192 return errorRuntime("Cannot open the virtual disk image \"%s\": %Rrc\n", 193 193 pszFilename, rc); 194 194 195 195 RTUUID oldImageUuid; 196 196 rc = VDGetUuid(pVD, VD_LAST_IMAGE, &oldImageUuid); … … 198 198 return errorRuntime("Cannot get UUID of virtual disk image \"%s\": %Rrc\n", 199 199 pszFilename, rc); 200 200 201 201 RTPrintf("Old image UUID: %RTuuid\n", &oldImageUuid); 202 202 203 203 RTUUID oldParentUuid; 204 204 rc = VDGetParentUuid(pVD, VD_LAST_IMAGE, &oldParentUuid); … … 206 206 return errorRuntime("Cannot get parent UUID of virtual disk image \"%s\": %Rrc\n", 207 207 pszFilename, rc); 208 208 209 209 RTPrintf("Old parent UUID: %RTuuid\n", &oldParentUuid); 210 210 211 211 if (fSetImageUuid) 212 212 { … … 217 217 pszFilename, rc); 218 218 } 219 219 220 220 if (fSetParentUuid) 221 221 { … … 226 226 pszFilename, rc); 227 227 } 228 228 229 229 rc = VDCloseAll(pVD); 230 230 if (RT_FAILURE(rc)) 231 231 return errorRuntime("Closing image failed! rc=%Rrc\n", rc); 232 232 233 233 if (pszFormat) 234 234 { … … 236 236 pszFormat = NULL; 237 237 } 238 239 return 0; 238 239 return 0; 240 240 } 241 241 … … 252 252 unsigned uImageFlags = VD_IMAGE_FLAGS_NONE; 253 253 int rc = VINF_SUCCESS; 254 254 255 255 /* Parse the command line. */ 256 256 static const RTGETOPTDEF s_aOptions[] = … … 292 292 } 293 293 } 294 294 295 295 /* Check for mandatory parameters. */ 296 296 if (!pszSrcFilename) … … 298 298 if (!pszDstFilename) 299 299 return errorSyntax("Mandatory --dstfilename option missing\n"); 300 300 301 301 /* check the variant parameter */ 302 302 if (pszVariant) … … 332 332 } 333 333 } 334 334 335 335 do 336 336 { … … 363 363 if (!pszDstFormat) 364 364 pszDstFormat = "VDI"; 365 365 366 366 rc = VDCreate(pVDIfs, &pDstDisk); 367 367 if (RT_FAILURE(rc)) … … 370 370 break; 371 371 } 372 372 373 373 uint64_t cbSize = VDGetSize(pSrcDisk, VD_LAST_IMAGE); 374 374 RTPrintf("Converting image \"%s\" with size %RU64 bytes (%RU64MB)...\n", pszSrcFilename, cbSize, (cbSize + _1M - 1) / _1M); 375 375 376 376 /* Create the output image */ 377 377 rc = VDCopy(pSrcDisk, VD_LAST_IMAGE, pDstDisk, pszDstFormat, … … 382 382 break; 383 383 } 384 384 385 385 } 386 386 while (0); 387 387 388 388 if (pDstDisk) 389 389 VDCloseAll(pDstDisk); 390 390 if (pSrcDisk) 391 391 VDCloseAll(pSrcDisk); 392 392 393 393 return RT_SUCCESS(rc) ? 0 : 1; 394 394 } … … 417 417 pszFilename = ValueUnion.psz; 418 418 break; 419 419 420 420 default: 421 421 ch = RTGetOptPrintError(ch, &ValueUnion); … … 424 424 } 425 425 } 426 426 427 427 /* Check for mandatory parameters. */ 428 428 if (!pszFilename) 429 429 return errorSyntax("Mandatory --filename option missing\n"); 430 430 431 431 /* just try it */ 432 432 char *pszFormat = NULL; … … 438 438 if (RT_FAILURE(rc)) 439 439 return errorRuntime("Error while creating the virtual disk container: %Rrc\n", rc); 440 440 441 441 /* Open the image */ 442 442 rc = VDOpen(pDisk, pszFormat, pszFilename, VD_OPEN_FLAGS_INFO, NULL); 443 443 if (RT_FAILURE(rc)) 444 444 return errorRuntime("Error while opening the image: %Rrc\n", rc); 445 445 446 446 VDDumpImages(pDisk); 447 447 448 448 VDCloseAll(pDisk); 449 449 450 450 return rc; 451 451 } … … 456 456 PVBOXHDD pDisk = NULL; 457 457 const char *pszFilename = NULL; 458 458 459 459 /* Parse the command line. */ 460 460 static const RTGETOPTDEF s_aOptions[] = … … 473 473 pszFilename = ValueUnion.psz; 474 474 break; 475 475 476 476 default: 477 477 ch = RTGetOptPrintError(ch, &ValueUnion); … … 480 480 } 481 481 } 482 482 483 483 /* Check for mandatory parameters. */ 484 484 if (!pszFilename) 485 485 return errorSyntax("Mandatory --filename option missing\n"); 486 486 487 487 /* just try it */ 488 488 char *pszFormat = NULL; … … 490 490 if (RT_FAILURE(rc)) 491 491 return errorSyntax("Format autodetect failed: %Rrc\n", rc); 492 492 493 493 rc = VDCreate(pVDIfs, &pDisk); 494 494 if (RT_FAILURE(rc)) 495 495 return errorRuntime("Error while creating the virtual disk container: %Rrc\n", rc); 496 496 497 497 /* Open the image */ 498 498 rc = VDOpen(pDisk, pszFormat, pszFilename, VD_OPEN_FLAGS_NORMAL, NULL); 499 499 if (RT_FAILURE(rc)) 500 500 return errorRuntime("Error while opening the image: %Rrc\n", rc); 501 501 502 502 rc = VDCompact(pDisk, 0, NULL); 503 503 if (RT_FAILURE(rc)) 504 504 errorRuntime("Error while compacting image: %Rrc\n", rc); 505 505 506 506 VDCloseAll(pDisk); 507 507 508 508 return rc; 509 509 } … … 516 516 "(C) 2005-" VBOX_C_YEAR " " VBOX_VENDOR "\n" 517 517 "All rights reserved.\n" 518 "\n"); 518 "\n"); 519 519 } 520 520 … … 530 530 int iCmd = 1; 531 531 int iCmdArg; 532 532 533 533 /* global options */ 534 534 for (int i = 1; i < argc || argc <= iCmd; i++) … … 545 545 return 0; 546 546 } 547 547 548 548 if ( !strcmp(argv[i], "-v") 549 549 || !strcmp(argv[i], "-version") … … 569 569 } 570 570 } 571 571 572 572 iCmdArg = iCmd + 1; 573 573 574 574 if (fShowLogo) 575 575 showLogo(); … … 582 582 vdInterfaceErrorCallbacks.pfnError = handleVDError; 583 583 vdInterfaceErrorCallbacks.pfnMessage = handleVDMessage; 584 584 585 585 rc = VDInterfaceAdd(&vdInterfaceError, "VBoxManage_IError", VDINTERFACETYPE_ERROR, 586 586 &vdInterfaceErrorCallbacks, NULL, &pVDIfs); 587 587 588 588 rc = VDInit(); 589 589 if (RT_FAILURE(rc)) 590 590 return errorSyntax("Initalizing backends failed! rc=%Rrc\n"); 591 591 592 592 /* 593 593 * All registered command handlers … … 614 614 handlerArg.argc = argc - iCmdArg; 615 615 handlerArg.argv = &argv[iCmdArg]; 616 616 617 617 rc = s_commandHandlers[commandIndex].handler(&handlerArg); 618 618 break; … … 620 620 } 621 621 if (!s_commandHandlers[commandIndex].command) 622 return errorSyntax("Invalid command '%s'", argv[iCmd]); 622 return errorSyntax("Invalid command '%s'", argv[iCmd]); 623 623 624 624 rc = VDShutdown(); 625 625 if (RT_FAILURE(rc)) 626 626 return errorSyntax("Unloading backends failed! rc=%Rrc\n", rc); 627 627 628 628 return rc; 629 629 }
Note:
See TracChangeset
for help on using the changeset viewer.