Changeset 39660 in vbox for trunk/src/VBox/Frontends/VBoxManage
- Timestamp:
- Dec 20, 2011 11:10:43 AM (13 years ago)
- svn:sync-xref-src-repo-rev:
- 75481
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxInternalManage.cpp
r39576 r39660 1116 1116 else 1117 1117 { 1118 /* 1119 * Could be raw image, remember error code and try to get the size first 1120 * before failing. 1121 */ 1118 1122 vrc = RTErrConvertFromWin32(GetLastError()); 1119 RTMsgError("Cannot get the geometry of the raw disk '%s': %Rrc", rawdisk.c_str(), vrc); 1120 goto out; 1123 if (RT_FAILURE(RTFileGetSize(hRawFile, &cbSize))) 1124 { 1125 RTMsgError("Cannot get the geometry of the raw disk '%s': %Rrc", rawdisk.c_str(), vrc); 1126 goto out; 1127 } 1128 else 1129 vrc = VINF_SUCCESS; 1121 1130 } 1122 1131 #elif defined(RT_OS_LINUX) 1123 1132 struct stat DevStat; 1124 if (!fstat(RTFileToNative(hRawFile), &DevStat) && S_ISBLK(DevStat.st_mode)) 1125 { 1133 if(!fstat(RTFileToNative(hRawFile), &DevStat)) 1134 { 1135 if (S_ISBLK(DevStat.st_mode)) 1136 { 1126 1137 #ifdef BLKGETSIZE64 1127 /* BLKGETSIZE64 is broken up to 2.4.17 and in many 2.5.x. In 2.6.01128 * it works without problems. */1129 struct utsname utsname;1130 if ( uname(&utsname) == 01131 && ( (strncmp(utsname.release, "2.5.", 4) == 0 && atoi(&utsname.release[4]) >= 18)1132 || (strncmp(utsname.release, "2.", 2) == 0 && atoi(&utsname.release[2]) >= 6)))1133 {1134 uint64_t cbBlk;1135 if (!ioctl(RTFileToNative(hRawFile), BLKGETSIZE64, &cbBlk))1136 cbSize = cbBlk;1137 }1138 /* BLKGETSIZE64 is broken up to 2.4.17 and in many 2.5.x. In 2.6.0 1139 * it works without problems. */ 1140 struct utsname utsname; 1141 if ( uname(&utsname) == 0 1142 && ( (strncmp(utsname.release, "2.5.", 4) == 0 && atoi(&utsname.release[4]) >= 18) 1143 || (strncmp(utsname.release, "2.", 2) == 0 && atoi(&utsname.release[2]) >= 6))) 1144 { 1145 uint64_t cbBlk; 1146 if (!ioctl(RTFileToNative(hRawFile), BLKGETSIZE64, &cbBlk)) 1147 cbSize = cbBlk; 1148 } 1138 1149 #endif /* BLKGETSIZE64 */ 1139 if (!cbSize) 1140 { 1141 long cBlocks; 1142 if (!ioctl(RTFileToNative(hRawFile), BLKGETSIZE, &cBlocks)) 1143 cbSize = (uint64_t)cBlocks << 9; 1150 if (!cbSize) 1151 { 1152 long cBlocks; 1153 if (!ioctl(RTFileToNative(hRawFile), BLKGETSIZE, &cBlocks)) 1154 cbSize = (uint64_t)cBlocks << 9; 1155 else 1156 { 1157 vrc = RTErrConvertFromErrno(errno); 1158 RTMsgError("Cannot get the size of the raw disk '%s': %Rrc", rawdisk.c_str(), vrc); 1159 goto out; 1160 } 1161 } 1162 } 1163 else if (S_ISREG(DevStat.st_mode)) 1164 { 1165 vrc = RTFileGetSize(hRawFile, &cbSize); 1166 if (RT_FAILURE(vrc)) 1167 { 1168 RTMsgError("Failed to get size of file '%s': %Rrc", rawdisk.c_str(), vrc); 1169 goto out; 1170 } 1171 else if (fRelative) 1172 { 1173 RTMsgError("The -relative parameter is invalid for raw images"); 1174 vrc = VERR_INVALID_PARAMETER; 1175 goto out; 1176 } 1177 } 1178 else 1179 { 1180 RTMsgError("File '%s' is no block device", rawdisk.c_str()); 1181 vrc = VERR_INVALID_PARAMETER; 1182 goto out; 1183 } 1184 } 1185 else 1186 { 1187 vrc = RTErrConvertFromErrno(errno); 1188 RTMsgError("Failed to get file informtation for raw disk '%s': %Rrc", 1189 rawdisk.c_str(), vrc); 1190 } 1191 #elif defined(RT_OS_DARWIN) 1192 struct stat DevStat; 1193 if (!fstat(RTFileToNative(hRawFile), &DevStat)) 1194 { 1195 if (S_ISBLK(DevStat.st_mode)) 1196 { 1197 uint64_t cBlocks; 1198 uint32_t cbBlock; 1199 if (!ioctl(RTFileToNative(hRawFile), DKIOCGETBLOCKCOUNT, &cBlocks)) 1200 { 1201 if (!ioctl(RTFileToNative(hRawFile), DKIOCGETBLOCKSIZE, &cbBlock)) 1202 cbSize = cBlocks * cbBlock; 1203 else 1204 { 1205 RTMsgError("Cannot get the block size for file '%s': %Rrc", rawdisk.c_str(), vrc); 1206 vrc = RTErrConvertFromErrno(errno); 1207 goto out; 1208 } 1209 } 1210 else 1211 { 1212 vrc = RTErrConvertFromErrno(errno); 1213 RTMsgError("Cannot get the block count for file '%s': %Rrc", rawdisk.c_str(), vrc); 1214 goto out; 1215 } 1216 } 1217 else if (S_ISREG(DevStat.st_mode)) 1218 { 1219 fRelative = false; /* Must be false for raw image files. */ 1220 vrc = RTFileGetSize(hRawFile, &cbSize); 1221 if (RT_FAILURE(vrc)) 1222 { 1223 RTMsgError("Failed to get size of file '%s': %Rrc", rawdisk.c_str(), vrc); 1224 goto out; 1225 } 1226 } 1227 else 1228 { 1229 RTMsgError("File '%s' is neither block device nor regular file", rawdisk.c_str()); 1230 vrc = VERR_INVALID_PARAMETER; 1231 goto out; 1232 } 1233 } 1234 else 1235 { 1236 vrc = RTErrConvertFromErrno(errno); 1237 RTMsgError("Failed to get file informtation for raw disk '%s': %Rrc", 1238 rawdisk.c_str(), vrc); 1239 } 1240 #elif defined(RT_OS_SOLARIS) 1241 struct stat DevStat; 1242 if (!fstat(RTFileToNative(hRawFile), &DevStat)) 1243 { 1244 if (S_ISBLK(DevStat.st_mode) || S_ISCHR(DevStat.st_mode)) 1245 { 1246 struct dk_minfo mediainfo; 1247 if (!ioctl(RTFileToNative(hRawFile), DKIOCGMEDIAINFO, &mediainfo)) 1248 cbSize = mediainfo.dki_capacity * mediainfo.dki_lbsize; 1144 1249 else 1145 1250 { … … 1149 1254 } 1150 1255 } 1256 else if (S_ISREG(DevStat.st_mode)) 1257 { 1258 vrc = RTFileGetSize(hRawFile, &cbSize); 1259 if (RT_FAILURE(vrc)) 1260 { 1261 RTMsgError("Failed to get size of file '%s': %Rrc", rawdisk.c_str(), vrc); 1262 goto out; 1263 } 1264 } 1265 else 1266 { 1267 RTMsgError("File '%s' is no block or char device", rawdisk.c_str()); 1268 vrc = VERR_INVALID_PARAMETER; 1269 goto out; 1270 } 1151 1271 } 1152 1272 else 1153 1273 { 1154 RTMsgError("File '%s' is no block device", rawdisk.c_str()); 1155 vrc = VERR_INVALID_PARAMETER; 1156 goto out; 1157 } 1158 #elif defined(RT_OS_DARWIN) 1159 struct stat DevStat; 1160 if (!fstat(RTFileToNative(hRawFile), &DevStat) && S_ISBLK(DevStat.st_mode)) 1161 { 1162 uint64_t cBlocks; 1163 uint32_t cbBlock; 1164 if (!ioctl(RTFileToNative(hRawFile), DKIOCGETBLOCKCOUNT, &cBlocks)) 1165 { 1166 if (!ioctl(RTFileToNative(hRawFile), DKIOCGETBLOCKSIZE, &cbBlock)) 1167 cbSize = cBlocks * cbBlock; 1168 else 1169 { 1170 RTMsgError("Cannot get the block size for file '%s': %Rrc", rawdisk.c_str(), vrc); 1171 vrc = RTErrConvertFromErrno(errno); 1172 goto out; 1173 } 1174 } 1175 else 1176 { 1177 vrc = RTErrConvertFromErrno(errno); 1178 RTMsgError("Cannot get the block count for file '%s': %Rrc", rawdisk.c_str(), vrc); 1179 goto out; 1180 } 1181 } 1182 else 1183 { 1184 RTMsgError("File '%s' is no block device", rawdisk.c_str()); 1185 vrc = VERR_INVALID_PARAMETER; 1186 goto out; 1187 } 1188 #elif defined(RT_OS_SOLARIS) 1189 struct stat DevStat; 1190 if (!fstat(RTFileToNative(hRawFile), &DevStat) && ( S_ISBLK(DevStat.st_mode) 1191 || S_ISCHR(DevStat.st_mode))) 1192 { 1193 struct dk_minfo mediainfo; 1194 if (!ioctl(RTFileToNative(hRawFile), DKIOCGMEDIAINFO, &mediainfo)) 1195 cbSize = mediainfo.dki_capacity * mediainfo.dki_lbsize; 1196 else 1197 { 1198 vrc = RTErrConvertFromErrno(errno); 1199 RTMsgError("Cannot get the size of the raw disk '%s': %Rrc", rawdisk.c_str(), vrc); 1200 goto out; 1201 } 1202 } 1203 else 1204 { 1205 RTMsgError("File '%s' is no block or char device", rawdisk.c_str()); 1206 vrc = VERR_INVALID_PARAMETER; 1207 goto out; 1274 vrc = RTErrConvertFromErrno(errno); 1275 RTMsgError("Failed to get file informtation for raw disk '%s': %Rrc", 1276 rawdisk.c_str(), vrc); 1208 1277 } 1209 1278 #elif defined(RT_OS_FREEBSD) 1210 1279 struct stat DevStat; 1211 if (!fstat(RTFileToNative(hRawFile), &DevStat) && S_ISCHR(DevStat.st_mode)) 1212 { 1213 off_t cbMedia = 0; 1214 if (!ioctl(RTFileToNative(hRawFile), DIOCGMEDIASIZE, &cbMedia)) 1215 { 1216 cbSize = cbMedia; 1280 if (!fstat(RTFileToNative(hRawFile), &DevStat)) 1281 { 1282 if (S_ISCHR(DevStat.st_mode)) 1283 { 1284 off_t cbMedia = 0; 1285 if (!ioctl(RTFileToNative(hRawFile), DIOCGMEDIASIZE, &cbMedia)) 1286 cbSize = cbMedia; 1287 else 1288 { 1289 vrc = RTErrConvertFromErrno(errno); 1290 RTMsgError("Cannot get the block count for file '%s': %Rrc", rawdisk.c_str(), vrc); 1291 goto out; 1292 } 1293 } 1294 else if (S_ISREG(DevStat.st_mode)) 1295 { 1296 if (fRelative) 1297 { 1298 RTMsgError("The -relative parameter is invalid for raw images"); 1299 vrc = VERR_INVALID_PARAMETER; 1300 goto out; 1301 } 1302 cbSize = DevStat.st_size; 1217 1303 } 1218 1304 else 1219 1305 { 1220 vrc = RTErrConvertFromErrno(errno);1221 RTMsgError("Cannot get the block count for file '%s': %Rrc", rawdisk.c_str(), vrc);1306 RTMsgError("File '%s' is neither character device nor regular file", rawdisk.c_str()); 1307 vrc = VERR_INVALID_PARAMETER; 1222 1308 goto out; 1223 1309 } … … 1225 1311 else 1226 1312 { 1227 RTMsgError("File '%s' is no character device", rawdisk.c_str());1228 vrc = VERR_INVALID_PARAMETER;1229 goto out;1313 vrc = RTErrConvertFromErrno(errno); 1314 RTMsgError("Failed to get file informtation for raw disk '%s': %Rrc", 1315 rawdisk.c_str(), vrc); 1230 1316 } 1231 1317 #else /* all unrecognized OSes */
Note:
See TracChangeset
for help on using the changeset viewer.