Changeset 51286 in vbox
- Timestamp:
- May 19, 2014 11:29:30 AM (11 years ago)
- svn:sync-xref-src-repo-rev:
- 93754
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Storage/testcase/vbox-img.cpp
r48847 r51286 5 5 6 6 /* 7 * Copyright (C) 2010-201 2Oracle Corporation7 * Copyright (C) 2010-2014 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 35 35 #include <iprt/vfs.h> 36 36 37 const char *g_pszProgName = "";37 static const char *g_pszProgName = ""; 38 38 static void printUsage(PRTSTREAM pStrm) 39 39 { … … 45 45 " [--parentuuid <uuid>]\n" 46 46 " [--zeroparentuuid]\n" 47 "\n" 48 " geometry --filename <filename>\n" 49 " [--format VDI|VMDK|VHD|...]\n" 50 " [--clearchs]\n" 51 " [--cylinders <number>]\n" 52 " [--heads <number>]\n" 53 " [--sectors <number>]\n" 47 54 "\n" 48 55 " convert --srcfilename <filename>\n" … … 75 82 } 76 83 77 void showLogo(PRTSTREAM pStrm)84 static void showLogo(PRTSTREAM pStrm) 78 85 { 79 86 static bool s_fShown; /* show only once */ … … 96 103 }; 97 104 98 PVDINTERFACE pVDIfs;105 static PVDINTERFACE pVDIfs; 99 106 100 107 static DECLCALLBACK(void) handleVDError(void *pvUser, int rc, RT_SRC_POS_DECL, … … 116 123 * Print a usage synopsis and the syntax error message. 117 124 */ 118 int errorSyntax(const char *pszFormat, ...)125 static int errorSyntax(const char *pszFormat, ...) 119 126 { 120 127 va_list args; … … 127 134 } 128 135 129 int errorRuntime(const char *pszFormat, ...)136 static int errorRuntime(const char *pszFormat, ...) 130 137 { 131 138 va_list args; … … 185 192 186 193 187 int handleSetUUID(HandlerArg *a)194 static int handleSetUUID(HandlerArg *a) 188 195 { 189 196 const char *pszFilename = NULL; … … 301 308 if (RT_FAILURE(rc)) 302 309 return errorRuntime("Cannot set parent UUID of virtual disk image \"%s\": %Rrc\n", 310 pszFilename, rc); 311 } 312 313 VDDestroy(pVD); 314 315 if (pszFormat) 316 { 317 RTStrFree(pszFormat); 318 pszFormat = NULL; 319 } 320 321 return 0; 322 } 323 324 325 static int handleGeometry(HandlerArg *a) 326 { 327 const char *pszFilename = NULL; 328 char *pszFormat = NULL; 329 VDTYPE enmType = VDTYPE_INVALID; 330 uint16_t cCylinders = 0; 331 uint8_t cHeads = 0; 332 uint8_t cSectors = 0; 333 bool fCylinders = false; 334 bool fHeads = false; 335 bool fSectors = false; 336 int rc; 337 338 /* Parse the command line. */ 339 static const RTGETOPTDEF s_aOptions[] = 340 { 341 { "--filename", 'f', RTGETOPT_REQ_STRING }, 342 { "--format", 'o', RTGETOPT_REQ_STRING }, 343 { "--clearchs", 'C', RTGETOPT_REQ_NOTHING }, 344 { "--cylinders", 'c', RTGETOPT_REQ_UINT16 }, 345 { "--heads", 'e', RTGETOPT_REQ_UINT8 }, 346 { "--sectors", 's', RTGETOPT_REQ_UINT8 } 347 }; 348 int ch; 349 RTGETOPTUNION ValueUnion; 350 RTGETOPTSTATE GetState; 351 RTGetOptInit(&GetState, a->argc, a->argv, s_aOptions, RT_ELEMENTS(s_aOptions), 0, 0 /* fFlags */); 352 while ((ch = RTGetOpt(&GetState, &ValueUnion))) 353 { 354 switch (ch) 355 { 356 case 'f': // --filename 357 pszFilename = ValueUnion.psz; 358 break; 359 case 'o': // --format 360 pszFormat = RTStrDup(ValueUnion.psz); 361 break; 362 case 'C': // --clearchs 363 cCylinders = 0; 364 cHeads = 0; 365 cSectors = 0; 366 fCylinders = true; 367 fHeads = true; 368 fSectors = true; 369 break; 370 case 'c': // --cylinders 371 cCylinders = ValueUnion.u16; 372 fCylinders = true; 373 break; 374 case 'e': // --heads 375 cHeads = ValueUnion.u8; 376 fHeads = true; 377 break; 378 case 's': // --sectors 379 cSectors = ValueUnion.u8; 380 fSectors = true; 381 break; 382 383 default: 384 ch = RTGetOptPrintError(ch, &ValueUnion); 385 printUsage(g_pStdErr); 386 return ch; 387 } 388 } 389 390 /* Check for mandatory parameters. */ 391 if (!pszFilename) 392 return errorSyntax("Mandatory --filename option missing\n"); 393 394 /* Autodetect image format. */ 395 if (!pszFormat) 396 { 397 /* Don't pass error interface, as that would triggers error messages 398 * because some backends fail to open the image. */ 399 rc = VDGetFormat(NULL, NULL, pszFilename, &pszFormat, &enmType); 400 if (RT_FAILURE(rc)) 401 return errorRuntime("Format autodetect failed: %Rrc\n", rc); 402 } 403 404 PVBOXHDD pVD = NULL; 405 rc = VDCreate(pVDIfs, enmType, &pVD); 406 if (RT_FAILURE(rc)) 407 return errorRuntime("Cannot create the virtual disk container: %Rrc\n", rc); 408 409 /* Open in info mode to be able to open diff images without their parent. */ 410 rc = VDOpen(pVD, pszFormat, pszFilename, VD_OPEN_FLAGS_INFO, NULL); 411 if (RT_FAILURE(rc)) 412 return errorRuntime("Cannot open the virtual disk image \"%s\": %Rrc\n", 413 pszFilename, rc); 414 415 VDGEOMETRY oldLCHSGeometry; 416 rc = VDGetLCHSGeometry(pVD, VD_LAST_IMAGE, &oldLCHSGeometry); 417 if (rc == VERR_VD_GEOMETRY_NOT_SET) 418 { 419 memset(&oldLCHSGeometry, 0, sizeof(oldLCHSGeometry)); 420 rc = VINF_SUCCESS; 421 } 422 if (RT_FAILURE(rc)) 423 return errorRuntime("Cannot get LCHS geometry of virtual disk image \"%s\": %Rrc\n", 424 pszFilename, rc); 425 426 RTPrintf("Old image LCHS: %u/%u/%u\n", oldLCHSGeometry.cCylinders, oldLCHSGeometry.cHeads, oldLCHSGeometry.cSectors); 427 428 VDGEOMETRY newLCHSGeometry = oldLCHSGeometry; 429 if (fCylinders) 430 newLCHSGeometry.cCylinders = cCylinders; 431 if (fHeads) 432 newLCHSGeometry.cHeads = cHeads; 433 if (fSectors) 434 newLCHSGeometry.cSectors = cSectors; 435 436 if (fCylinders || fHeads || fSectors) 437 { 438 RTPrintf("New image LCHS: %u/%u/%u\n", newLCHSGeometry.cCylinders, newLCHSGeometry.cHeads, newLCHSGeometry.cSectors); 439 440 rc = VDSetLCHSGeometry(pVD, VD_LAST_IMAGE, &newLCHSGeometry); 441 if (RT_FAILURE(rc)) 442 return errorRuntime("Cannot set LCHS geometry of virtual disk image \"%s\": %Rrc\n", 303 443 pszFilename, rc); 304 444 } … … 688 828 } 689 829 690 int handleConvert(HandlerArg *a)830 static int handleConvert(HandlerArg *a) 691 831 { 692 832 const char *pszSrcFilename = NULL; … … 914 1054 915 1055 916 int handleInfo(HandlerArg *a)1056 static int handleInfo(HandlerArg *a) 917 1057 { 918 1058 int rc = VINF_SUCCESS; … … 1063 1203 } VBOXIMGVFS, *PVBOXIMGVFS; 1064 1204 1065 int handleCompact(HandlerArg *a)1205 static int handleCompact(HandlerArg *a) 1066 1206 { 1067 1207 int rc = VINF_SUCCESS; … … 1244 1384 1245 1385 1246 int handleCreateCache(HandlerArg *a)1386 static int handleCreateCache(HandlerArg *a) 1247 1387 { 1248 1388 int rc = VINF_SUCCESS; … … 1339 1479 } 1340 1480 1341 int handleCreateBase(HandlerArg *a)1481 static int handleCreateBase(HandlerArg *a) 1342 1482 { 1343 1483 int rc = VINF_SUCCESS; … … 1353 1493 VDINTERFACECONFIG vdIfCfg; 1354 1494 1355 memset(&LCHSGeometry, 0, sizeof( VDGEOMETRY));1356 memset(&PCHSGeometry, 0, sizeof( VDGEOMETRY));1495 memset(&LCHSGeometry, 0, sizeof(LCHSGeometry)); 1496 memset(&PCHSGeometry, 0, sizeof(PCHSGeometry)); 1357 1497 1358 1498 /* Parse the command line. */ … … 1441 1581 1442 1582 1443 int handleRepair(HandlerArg *a)1583 static int handleRepair(HandlerArg *a) 1444 1584 { 1445 1585 int rc = VINF_SUCCESS; … … 1508 1648 1509 1649 1510 int handleClearComment(HandlerArg *a)1650 static int handleClearComment(HandlerArg *a) 1511 1651 { 1512 1652 int rc = VINF_SUCCESS; … … 1649 1789 { 1650 1790 { "setuuid", handleSetUUID }, 1791 { "geometry", handleGeometry }, 1651 1792 { "convert", handleConvert }, 1652 1793 { "info", handleInfo },
Note:
See TracChangeset
for help on using the changeset viewer.