- Timestamp:
- May 20, 2015 3:57:56 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Storage/testcase/vbox-img.cpp
r55828 r55974 78 78 " [--format VDI|VMDK|VHD] (default: autodetect)\n" 79 79 "\n" 80 " clearcomment --filename <filename>\n", 80 " clearcomment --filename <filename>\n" 81 "\n" 82 " resize --filename <filename>\n" 83 " --size <new size>\n", 81 84 g_pszProgName); 82 85 } … … 1708 1711 1709 1712 1713 static int handleClearResize(HandlerArg *a) 1714 { 1715 int rc = VINF_SUCCESS; 1716 PVBOXHDD pDisk = NULL; 1717 const char *pszFilename = NULL; 1718 uint64_t cbNew = 0; 1719 bool fDryRun = false; 1720 VDGEOMETRY LCHSGeometry, PCHSGeometry; 1721 1722 memset(&LCHSGeometry, 0, sizeof(LCHSGeometry)); 1723 memset(&PCHSGeometry, 0, sizeof(PCHSGeometry)); 1724 1725 /* Parse the command line. */ 1726 static const RTGETOPTDEF s_aOptions[] = 1727 { 1728 { "--filename", 'f', RTGETOPT_REQ_STRING }, 1729 { "--size", 's', RTGETOPT_REQ_UINT64 } 1730 }; 1731 int ch; 1732 RTGETOPTUNION ValueUnion; 1733 RTGETOPTSTATE GetState; 1734 RTGetOptInit(&GetState, a->argc, a->argv, s_aOptions, RT_ELEMENTS(s_aOptions), 0, 0 /* fFlags */); 1735 while ((ch = RTGetOpt(&GetState, &ValueUnion))) 1736 { 1737 switch (ch) 1738 { 1739 case 'f': // --filename 1740 pszFilename = ValueUnion.psz; 1741 break; 1742 1743 case 's': // --size 1744 cbNew = ValueUnion.u64; 1745 break; 1746 1747 default: 1748 ch = RTGetOptPrintError(ch, &ValueUnion); 1749 printUsage(g_pStdErr); 1750 return ch; 1751 } 1752 } 1753 1754 /* Check for mandatory parameters. */ 1755 if (!pszFilename) 1756 return errorSyntax("Mandatory --filename option missing\n"); 1757 1758 if (!cbNew) 1759 return errorSyntax("Mandatory --size option missing or invalid\n"); 1760 1761 /* just try it */ 1762 char *pszFormat = NULL; 1763 VDTYPE enmType = VDTYPE_INVALID; 1764 rc = VDGetFormat(NULL, NULL, pszFilename, &pszFormat, &enmType); 1765 if (RT_FAILURE(rc)) 1766 return errorSyntax("Format autodetect failed: %Rrc\n", rc); 1767 1768 rc = VDCreate(pVDIfs, enmType, &pDisk); 1769 if (RT_FAILURE(rc)) 1770 return errorRuntime("Error while creating the virtual disk container: %Rrc\n", rc); 1771 1772 /* Open the image */ 1773 rc = VDOpen(pDisk, pszFormat, pszFilename, VD_OPEN_FLAGS_NORMAL, NULL); 1774 if (RT_FAILURE(rc)) 1775 return errorRuntime("Error while opening the image: %Rrc\n", rc); 1776 1777 rc = VDResize(pDisk, cbNew, &PCHSGeometry, &LCHSGeometry, NULL); 1778 if (RT_FAILURE(rc)) 1779 rc = errorRuntime("Error while resizing the virtual disk: %Rrc\n", rc); 1780 1781 VDDestroy(pDisk); 1782 return rc; 1783 } 1784 1785 1710 1786 int main(int argc, char *argv[]) 1711 1787 { … … 1799 1875 { "repair", handleRepair }, 1800 1876 { "clearcomment", handleClearComment }, 1801 { NULL, NULL } 1877 { "resize", handleClearResize }, 1878 { NULL, NULL } 1802 1879 }; 1803 1880
Note:
See TracChangeset
for help on using the changeset viewer.