Changeset 38939 in vbox
- Timestamp:
- Oct 5, 2011 12:57:44 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Storage/testcase/vbox-img.cpp
r38636 r38939 5 5 6 6 /* 7 * Copyright (C) 2010 Oracle Corporation7 * Copyright (C) 2010-2011 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 54 54 " compact --filename <filename>\n" 55 55 " createcache --filename <filename>\n" 56 " --size <cache size>\n", 56 " --size <cache size>\n" 57 " createbase --filename <filename>\n" 58 " --size <size in bytes>\n" 59 " [--format VDI|VMDK|VHD] (default: VDI)\n" 60 " [--variant Standard,Fixed,Split2G,Stream,ESX]\n", 57 61 g_pszProgName); 58 62 } … … 120 124 } 121 125 126 static int parseDiskVariant(const char *psz, unsigned *puImageFlags) 127 { 128 int rc = VINF_SUCCESS; 129 unsigned uImageFlags = *puImageFlags; 130 131 while (psz && *psz && RT_SUCCESS(rc)) 132 { 133 size_t len; 134 const char *pszComma = strchr(psz, ','); 135 if (pszComma) 136 len = pszComma - psz; 137 else 138 len = strlen(psz); 139 if (len > 0) 140 { 141 /* 142 * Parsing is intentionally inconsistent: "standard" resets the 143 * variant, whereas the other flags are cumulative. 144 */ 145 if (!RTStrNICmp(psz, "standard", len)) 146 uImageFlags = VD_IMAGE_FLAGS_NONE; 147 else if ( !RTStrNICmp(psz, "fixed", len) 148 || !RTStrNICmp(psz, "static", len)) 149 uImageFlags |= VD_IMAGE_FLAGS_FIXED; 150 else if (!RTStrNICmp(psz, "Diff", len)) 151 uImageFlags |= VD_IMAGE_FLAGS_DIFF; 152 else if (!RTStrNICmp(psz, "split2g", len)) 153 uImageFlags |= VD_VMDK_IMAGE_FLAGS_SPLIT_2G; 154 else if ( !RTStrNICmp(psz, "stream", len) 155 || !RTStrNICmp(psz, "streamoptimized", len)) 156 uImageFlags |= VD_VMDK_IMAGE_FLAGS_STREAM_OPTIMIZED; 157 else if (!RTStrNICmp(psz, "esx", len)) 158 uImageFlags |= VD_VMDK_IMAGE_FLAGS_ESX; 159 else 160 rc = VERR_PARSE_ERROR; 161 } 162 if (pszComma) 163 psz += len + 1; 164 else 165 psz += len; 166 } 167 168 if (RT_SUCCESS(rc)) 169 *puImageFlags = uImageFlags; 170 return rc; 171 } 122 172 123 173 … … 241 291 } 242 292 243 rc = VDCloseAll(pVD); 244 if (RT_FAILURE(rc)) 245 return errorRuntime("Closing image failed! rc=%Rrc\n", rc); 293 VDDestroy(pVD); 246 294 247 295 if (pszFormat) … … 839 887 840 888 if (pDstDisk) 841 VD CloseAll(pDstDisk);889 VDDestroy(pDstDisk); 842 890 if (pSrcDisk) 843 VD CloseAll(pSrcDisk);891 VDDestroy(pSrcDisk); 844 892 845 893 return RT_SUCCESS(rc) ? 0 : 1; … … 899 947 VDDumpImages(pDisk); 900 948 901 VD CloseAll(pDisk);949 VDDestroy(pDisk); 902 950 903 951 return rc; … … 959 1007 errorRuntime("Error while compacting image: %Rrc\n", rc); 960 1008 961 VD CloseAll(pDisk);1009 VDDestroy(pDisk); 962 1010 963 1011 return rc; … … 1018 1066 return errorRuntime("Error while creating the virtual disk cache: %Rrc\n", rc); 1019 1067 1020 VDCloseAll(pDisk); 1068 VDDestroy(pDisk); 1069 1070 return rc; 1071 } 1072 1073 1074 int handleCreateBase(HandlerArg *a) 1075 { 1076 int rc = VINF_SUCCESS; 1077 PVBOXHDD pDisk = NULL; 1078 const char *pszFilename = NULL; 1079 const char *pszBackend = "VDI"; 1080 const char *pszVariant = NULL; 1081 unsigned uImageFlags = VD_IMAGE_FLAGS_NONE; 1082 uint64_t cbSize = 0; 1083 VDGEOMETRY LCHSGeometry, PCHSGeometry; 1084 1085 memset(&LCHSGeometry, 0, sizeof(VDGEOMETRY)); 1086 memset(&PCHSGeometry, 0, sizeof(VDGEOMETRY)); 1087 1088 /* Parse the command line. */ 1089 static const RTGETOPTDEF s_aOptions[] = 1090 { 1091 { "--filename", 'f', RTGETOPT_REQ_STRING }, 1092 { "--size", 's', RTGETOPT_REQ_UINT64 }, 1093 { "--format", 'b', RTGETOPT_REQ_STRING }, 1094 { "--variant", 'v', RTGETOPT_REQ_STRING } 1095 }; 1096 int ch; 1097 RTGETOPTUNION ValueUnion; 1098 RTGETOPTSTATE GetState; 1099 RTGetOptInit(&GetState, a->argc, a->argv, s_aOptions, RT_ELEMENTS(s_aOptions), 0, 0 /* fFlags */); 1100 while ((ch = RTGetOpt(&GetState, &ValueUnion))) 1101 { 1102 switch (ch) 1103 { 1104 case 'f': // --filename 1105 pszFilename = ValueUnion.psz; 1106 break; 1107 1108 case 's': // --size 1109 cbSize = ValueUnion.u64; 1110 break; 1111 1112 case 'b': // --format 1113 pszBackend = ValueUnion.psz; 1114 break; 1115 1116 case 'v': // --variant 1117 pszVariant = ValueUnion.psz; 1118 break; 1119 1120 default: 1121 ch = RTGetOptPrintError(ch, &ValueUnion); 1122 printUsage(g_pStdErr); 1123 return ch; 1124 } 1125 } 1126 1127 /* Check for mandatory parameters. */ 1128 if (!pszFilename) 1129 return errorSyntax("Mandatory --filename option missing\n"); 1130 1131 if (!cbSize) 1132 return errorSyntax("Mandatory --size option missing\n"); 1133 1134 if (pszVariant) 1135 { 1136 rc = parseDiskVariant(pszVariant, &uImageFlags); 1137 if (RT_FAILURE(rc)) 1138 return errorSyntax("Invalid variant %s given\n", pszVariant); 1139 } 1140 1141 /* just try it */ 1142 rc = VDCreate(pVDIfs, VDTYPE_HDD, &pDisk); 1143 if (RT_FAILURE(rc)) 1144 return errorRuntime("Error while creating the virtual disk container: %Rrc\n", rc); 1145 1146 rc = VDCreateBase(pDisk, pszBackend, pszFilename, cbSize, uImageFlags, 1147 NULL, &PCHSGeometry, &LCHSGeometry, NULL, VD_OPEN_FLAGS_NORMAL, 1148 NULL, NULL); 1149 if (RT_FAILURE(rc)) 1150 return errorRuntime("Error while creating the virtual disk: %Rrc\n", rc); 1151 1152 VDDestroy(pDisk); 1021 1153 1022 1154 return rc; … … 1111 1243 { "compact", handleCompact }, 1112 1244 { "createcache", handleCreateCache }, 1245 { "createbase", handleCreateBase }, 1113 1246 { NULL, NULL } 1114 1247 };
Note:
See TracChangeset
for help on using the changeset viewer.