Changeset 38469 in vbox for trunk/src/VBox/Storage/QED.cpp
- Timestamp:
- Aug 16, 2011 10:34:32 AM (14 years ago)
- svn:sync-xref-src-repo-rev:
- 73520
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Storage/QED.cpp
r38463 r38469 150 150 /** Storage handle. */ 151 151 PVDIOSTORAGE pStorage; 152 /** I/O interface. */153 PVDINTERFACE pInterfaceIO;154 /** Async I/O interface callbacks. */155 PVDINTERFACEIOINT pInterfaceIOCallbacks;156 152 157 153 /** Pointer to the per-disk VD interface list. */ … … 159 155 /** Pointer to the per-image VD interface list. */ 160 156 PVDINTERFACE pVDIfsImage; 161 162 /** Error callback. */ 163 PVDINTERFACE pInterfaceError; 164 /** Opaque data for error callback. */ 165 PVDINTERFACEERROR pInterfaceErrorCallbacks; 157 /** Error interface. */ 158 PVDINTERFACEERROR pIfError; 159 /** I/O interface. */ 160 PVDINTERFACEIOINT pIfIo; 166 161 167 162 /** Open flags passed by VBoxHD layer. */ … … 186 181 uint64_t cbImage; 187 182 /** Cluster size in bytes. */ 188 size_tcbCluster;183 uint32_t cbCluster; 189 184 /** Number of entries in the L1 and L2 table. */ 190 185 uint32_t cTableEntries; 191 186 /** Size of an L1 or L2 table rounded to the next cluster size. */ 192 size_tcbTable;187 uint32_t cbTable; 193 188 /** Pointer to the L1 table. */ 194 189 uint64_t *paL1Table; … … 272 267 273 268 /** 274 * Internal: signal an error to the frontend.275 */276 DECLINLINE(int) qedError(PQEDIMAGE pImage, int rc, RT_SRC_POS_DECL,277 const char *pszFormat, ...)278 {279 va_list va;280 va_start(va, pszFormat);281 if (pImage->pInterfaceError)282 pImage->pInterfaceErrorCallbacks->pfnError(pImage->pInterfaceError->pvUser, rc, RT_SRC_POS_ARGS,283 pszFormat, va);284 va_end(va);285 return rc;286 }287 288 /**289 * Internal: signal an informational message to the frontend.290 */291 DECLINLINE(int) qedMessage(PQEDIMAGE pImage, const char *pszFormat, ...)292 {293 int rc = VINF_SUCCESS;294 va_list va;295 va_start(va, pszFormat);296 if (pImage->pInterfaceError)297 rc = pImage->pInterfaceErrorCallbacks->pfnMessage(pImage->pInterfaceError->pvUser,298 pszFormat, va);299 va_end(va);300 return rc;301 }302 303 304 DECLINLINE(int) qedFileOpen(PQEDIMAGE pImage, const char *pszFilename,305 uint32_t fOpen)306 {307 return pImage->pInterfaceIOCallbacks->pfnOpen(pImage->pInterfaceIO->pvUser,308 pszFilename, fOpen,309 &pImage->pStorage);310 }311 312 DECLINLINE(int) qedFileClose(PQEDIMAGE pImage)313 {314 return pImage->pInterfaceIOCallbacks->pfnClose(pImage->pInterfaceIO->pvUser,315 pImage->pStorage);316 }317 318 DECLINLINE(int) qedFileDelete(PQEDIMAGE pImage, const char *pszFilename)319 {320 return pImage->pInterfaceIOCallbacks->pfnDelete(pImage->pInterfaceIO->pvUser,321 pszFilename);322 }323 324 DECLINLINE(int) qedFileMove(PQEDIMAGE pImage, const char *pszSrc,325 const char *pszDst, unsigned fMove)326 {327 return pImage->pInterfaceIOCallbacks->pfnMove(pImage->pInterfaceIO->pvUser,328 pszSrc, pszDst, fMove);329 }330 331 DECLINLINE(int) qedFileGetFreeSpace(PQEDIMAGE pImage, const char *pszFilename,332 int64_t *pcbFree)333 {334 return pImage->pInterfaceIOCallbacks->pfnGetFreeSpace(pImage->pInterfaceIO->pvUser,335 pszFilename, pcbFree);336 }337 338 DECLINLINE(int) qedFileGetSize(PQEDIMAGE pImage, uint64_t *pcbSize)339 {340 return pImage->pInterfaceIOCallbacks->pfnGetSize(pImage->pInterfaceIO->pvUser,341 pImage->pStorage, pcbSize);342 }343 344 DECLINLINE(int) qedFileSetSize(PQEDIMAGE pImage, uint64_t cbSize)345 {346 return pImage->pInterfaceIOCallbacks->pfnSetSize(pImage->pInterfaceIO->pvUser,347 pImage->pStorage, cbSize);348 }349 350 DECLINLINE(int) qedFileWriteSync(PQEDIMAGE pImage, uint64_t uOffset,351 const void *pvBuffer, size_t cbBuffer,352 size_t *pcbWritten)353 {354 return pImage->pInterfaceIOCallbacks->pfnWriteSync(pImage->pInterfaceIO->pvUser,355 pImage->pStorage, uOffset,356 pvBuffer, cbBuffer, pcbWritten);357 }358 359 DECLINLINE(int) qedFileReadSync(PQEDIMAGE pImage, uint64_t uOffset,360 void *pvBuffer, size_t cbBuffer, size_t *pcbRead)361 {362 return pImage->pInterfaceIOCallbacks->pfnReadSync(pImage->pInterfaceIO->pvUser,363 pImage->pStorage, uOffset,364 pvBuffer, cbBuffer, pcbRead);365 }366 367 DECLINLINE(int) qedFileFlushSync(PQEDIMAGE pImage)368 {369 return pImage->pInterfaceIOCallbacks->pfnFlushSync(pImage->pInterfaceIO->pvUser,370 pImage->pStorage);371 }372 373 DECLINLINE(int) qedFileReadUserAsync(PQEDIMAGE pImage, uint64_t uOffset,374 PVDIOCTX pIoCtx, size_t cbRead)375 {376 return pImage->pInterfaceIOCallbacks->pfnReadUserAsync(pImage->pInterfaceIO->pvUser,377 pImage->pStorage,378 uOffset, pIoCtx,379 cbRead);380 }381 382 DECLINLINE(int) qedFileWriteUserAsync(PQEDIMAGE pImage, uint64_t uOffset,383 PVDIOCTX pIoCtx, size_t cbWrite,384 PFNVDXFERCOMPLETED pfnComplete,385 void *pvCompleteUser)386 {387 return pImage->pInterfaceIOCallbacks->pfnWriteUserAsync(pImage->pInterfaceIO->pvUser,388 pImage->pStorage,389 uOffset, pIoCtx,390 cbWrite,391 pfnComplete,392 pvCompleteUser);393 }394 395 /**396 * Internal: read metadata (async)397 */398 DECLINLINE(int) qedFileReadMetaAsync(PQEDIMAGE pImage,399 uint64_t uOffset, void *pvBuffer,400 size_t cbBuffer, PVDIOCTX pIoCtx,401 PPVDMETAXFER ppMetaXfer,402 PFNVDXFERCOMPLETED pfnComplete,403 void *pvCompleteUser)404 {405 return pImage->pInterfaceIOCallbacks->pfnReadMetaAsync(pImage->pInterfaceIO->pvUser,406 pImage->pStorage,407 uOffset, pvBuffer,408 cbBuffer, pIoCtx,409 ppMetaXfer,410 pfnComplete,411 pvCompleteUser);412 }413 414 /**415 * Internal: write metadata (async)416 */417 DECLINLINE(int) qedFileWriteMetaAsync(PQEDIMAGE pImage,418 uint64_t uOffset, void *pvBuffer,419 size_t cbBuffer, PVDIOCTX pIoCtx,420 PFNVDXFERCOMPLETED pfnComplete,421 void *pvCompleteUser)422 {423 return pImage->pInterfaceIOCallbacks->pfnWriteMetaAsync(pImage->pInterfaceIO->pvUser,424 pImage->pStorage,425 uOffset, pvBuffer,426 cbBuffer, pIoCtx,427 pfnComplete,428 pvCompleteUser);429 }430 431 /**432 * Internal: releases a metadata transfer handle (async)433 */434 DECLINLINE(void) qedFileMetaXferRelease(PQEDIMAGE pImage, PVDMETAXFER pMetaXfer)435 {436 pImage->pInterfaceIOCallbacks->pfnMetaXferRelease(pImage->pInterfaceIO->pvUser,437 pMetaXfer);438 }439 440 DECLINLINE(int) qedFileFlushAsync(PQEDIMAGE pImage, PVDIOCTX pIoCtx,441 PFNVDXFERCOMPLETED pfnComplete,442 void *pvCompleteUser)443 {444 return pImage->pInterfaceIOCallbacks->pfnFlushAsync(pImage->pInterfaceIO->pvUser,445 pImage->pStorage,446 pIoCtx, pfnComplete,447 pvCompleteUser);448 }449 450 451 /**452 269 * Converts the image header to the host endianess and performs basic checks. 453 270 * … … 753 570 /* Read from the image. */ 754 571 pL2Entry->offL2Tbl = offL2Tbl; 755 rc = qedFileReadSync(pImage, offL2Tbl, pL2Entry->paL2Tbl, pImage->cbTable, NULL); 572 rc = vdIfIoIntFileReadSync(pImage->pIfIo, pImage->pStorage, offL2Tbl, 573 pL2Entry->paL2Tbl, pImage->cbTable, NULL); 756 574 if (RT_SUCCESS(rc)) 757 575 { … … 802 620 803 621 pL2Entry->offL2Tbl = offL2Tbl; 804 rc = qedFileReadMetaAsync(pImage, offL2Tbl, pL2Entry->paL2Tbl, 805 pImage->cbTable, pIoCtx, 806 &pMetaXfer, NULL, NULL); 622 rc = vdIfIoIntFileReadMetaAsync(pImage->pIfIo, pImage->pStorage, 623 offL2Tbl, pL2Entry->paL2Tbl, 624 pImage->cbTable, pIoCtx, 625 &pMetaXfer, NULL, NULL); 807 626 if (RT_SUCCESS(rc)) 808 627 { 809 qedFileMetaXferRelease(pImage, pMetaXfer);628 vdIfIoIntMetaXferRelease(pImage->pIfIo, pMetaXfer); 810 629 #if defined(RT_BIG_ENDIAN) 811 630 qedTableConvertToHostEndianness(pL2Entry->paL2Tbl, pImage->cTableEntries); … … 1040 859 qedTableConvertFromHostEndianess(p1L1TblImg, pImage->paL1Table, 1041 860 pImage->cTableEntries); 1042 rc = qedFileWriteSync(pImage, pImage->offL1Table, paL1TblImg, 1043 pImage->cbTable, NULL); 861 rc = vdIfIoIntFileWriteSync(pImage->pIfIo, pImage->pStorage, 862 pImage->offL1Table, paL1TblImg, 863 pImage->cbTable, NULL); 1044 864 RTMemFree(paL1TblImg); 1045 865 } … … 1048 868 #else 1049 869 /* Write L1 table directly. */ 1050 rc = qedFileWriteSync(pImage, pImage->offL1Table, pImage->paL1Table,1051 pImage->cbTable, NULL);870 rc = vdIfIoIntFileWriteSync(pImage->pIfIo, pImage->pStorage, pImage->offL1Table, 871 pImage->paL1Table, pImage->cbTable, NULL); 1052 872 #endif 1053 873 if (RT_SUCCESS(rc)) … … 1055 875 /* Write header. */ 1056 876 qedHdrConvertFromHostEndianess(pImage, &Header); 1057 rc = qedFileWriteSync(pImage, 0, &Header, sizeof(Header), NULL); 877 rc = vdIfIoIntFileWriteSync(pImage->pIfIo, pImage->pStorage, 0, &Header, 878 sizeof(Header), NULL); 1058 879 if (RT_SUCCESS(rc)) 1059 rc = qedFileFlushSync(pImage);880 rc = vdIfIoIntFileFlushSync(pImage->pIfIo, pImage->pStorage); 1060 881 } 1061 882 } … … 1087 908 qedTableConvertFromHostEndianess(p1L1TblImg, pImage->paL1Table, 1088 909 pImage->cTableEntries); 1089 rc = qedFileWriteMetaAsync(pImage, pImage->offL1Table, paL1TblImg, 1090 pImage->cbTable, pIoCtx, NULL, NULL); 910 rc = vdIfIoIntFileWriteMetaAsync(pImage->pIfIo, pImage->pStorage, 911 pImage->offL1Table, paL1TblImg, 912 pImage->cbTable, pIoCtx, NULL, NULL); 1091 913 RTMemFree(paL1TblImg); 1092 914 } … … 1095 917 #else 1096 918 /* Write L1 table directly. */ 1097 rc = qedFileWriteMetaAsync(pImage, pImage->offL1Table, pImage->paL1Table, 1098 pImage->cbTable, pIoCtx, NULL, NULL); 919 rc = vdIfIoIntFileWriteMetaAsync(pImage->pIfIo, pImage->pStorage, 920 pImage->offL1Table, pImage->paL1Table, 921 pImage->cbTable, pIoCtx, NULL, NULL); 1099 922 #endif 1100 923 if (RT_SUCCESS(rc) || rc == VERR_VD_ASYNC_IO_IN_PROGRESS) … … 1102 925 /* Write header. */ 1103 926 qedHdrConvertFromHostEndianess(pImage, &Header); 1104 rc = qedFileWriteMetaAsync(pImage, 0, &Header, sizeof(Header), 1105 pIoCtx, NULL, NULL); 927 rc = vdIfIoIntFileWriteMetaAsync(pImage->pIfIo, pImage->pStorage, 928 0, &Header, sizeof(Header), 929 pIoCtx, NULL, NULL); 1106 930 if (RT_SUCCESS(rc) || rc == VERR_VD_ASYNC_IO_IN_PROGRESS) 1107 rc = qedFileFlushAsync(pImage, pIoCtx, NULL, NULL); 931 rc = vdIfIoIntFileFlushAsync(pImage->pIfIo, pImage->pStorage, 932 pIoCtx, NULL, NULL); 1108 933 } 1109 934 } … … 1177 1002 { 1178 1003 uint64_t cbFile; 1179 size_t cbTable;1004 uint32_t cbTable; 1180 1005 uint32_t cTableEntries; 1181 1006 uint64_t *paL1Tbl = NULL; … … 1191 1016 do 1192 1017 { 1193 rc = qedFileGetSize(pImage, &cbFile);1018 rc = vdIfIoIntFileGetSize(pImage->pIfIo, pImage->pStorage, &cbFile); 1194 1019 if (RT_FAILURE(rc)) 1195 1020 { 1196 rc = qedError(pImage, rc, RT_SRC_POS,1197 N_("Qed: Querying the file size of image '%s' failed"),1198 pImage->pszFilename);1021 rc = vdIfError(pImage->pIfError, rc, RT_SRC_POS, 1022 N_("Qed: Querying the file size of image '%s' failed"), 1023 pImage->pszFilename); 1199 1024 break; 1200 1025 } … … 1204 1029 if (!paL1Tbl) 1205 1030 { 1206 rc = qedError(pImage, VERR_NO_MEMORY, RT_SRC_POS,1031 rc = vdIfError(pImage->pIfError, VERR_NO_MEMORY, RT_SRC_POS, 1207 1032 N_("Qed: Allocating memory for the L1 table for image '%s' failed"), 1208 1033 pImage->pszFilename); … … 1213 1038 if (!paL2Tbl) 1214 1039 { 1215 rc = qedError(pImage, VERR_NO_MEMORY, RT_SRC_POS,1216 N_("Qed: Allocating memory for the L2 table for image '%s' failed"),1217 pImage->pszFilename);1040 rc = vdIfError(pImage->pIfError, VERR_NO_MEMORY, RT_SRC_POS, 1041 N_("Qed: Allocating memory for the L2 table for image '%s' failed"), 1042 pImage->pszFilename); 1218 1043 break; 1219 1044 } … … 1222 1047 if (!pvClusterBitmap) 1223 1048 { 1224 rc = qedError(pImage, VERR_NO_MEMORY, RT_SRC_POS,1225 N_("Qed: Allocating memory for the cluster bitmap for image '%s' failed"),1226 pImage->pszFilename);1049 rc = vdIfError(pImage->pIfError, VERR_NO_MEMORY, RT_SRC_POS, 1050 N_("Qed: Allocating memory for the cluster bitmap for image '%s' failed"), 1051 pImage->pszFilename); 1227 1052 break; 1228 1053 } … … 1231 1056 if (!qedIsTblOffsetValid(pHeader->u64OffL1Table, cbFile, cbTable, pHeader->u32ClusterSize)) 1232 1057 { 1233 rc = qedError(pImage, VERR_VD_GEN_INVALID_HEADER, RT_SRC_POS,1234 1235 1058 rc = vdIfError(pImage->pIfError, VERR_VD_GEN_INVALID_HEADER, RT_SRC_POS, 1059 N_("Qed: L1 table offset of image '%s' is corrupt (%llu)"), 1060 pImage->pszFilename, pHeader->u64OffL1Table); 1236 1061 break; 1237 1062 } 1238 1063 1239 1064 /* Read L1 table. */ 1240 rc = qedFileReadSync(pImage, pHeader->u64OffL1Table, paL1Tbl, cbTable, NULL); 1065 rc = vdIfIoIntFileReadSync(pImage->pIfIo, pImage->pStorage, 1066 pHeader->u64OffL1Table, paL1Tbl, cbTable, NULL); 1241 1067 if (RT_FAILURE(rc)) 1242 1068 { 1243 rc = qedError(pImage, VERR_VD_GEN_INVALID_HEADER, RT_SRC_POS,1244 1245 1069 rc = vdIfError(pImage->pIfError, VERR_VD_GEN_INVALID_HEADER, RT_SRC_POS, 1070 N_("Qed: Reading the L1 table from image '%s' failed"), 1071 pImage->pszFilename); 1246 1072 break; 1247 1073 } … … 1263 1089 if (!qedIsTblOffsetValid(paL1Tbl[iL1], cbFile, cbTable, pHeader->u32ClusterSize)) 1264 1090 { 1265 rc = qedError(pImage, VERR_VD_GEN_INVALID_HEADER, RT_SRC_POS,1266 N_("Qed: Entry %d of the L1 table from image '%s' is invalid (%llu)"),1267 iL1, pImage->pszFilename, paL1Tbl[iL1]);1091 rc = vdIfError(pImage->pIfError, VERR_VD_GEN_INVALID_HEADER, RT_SRC_POS, 1092 N_("Qed: Entry %d of the L1 table from image '%s' is invalid (%llu)"), 1093 iL1, pImage->pszFilename, paL1Tbl[iL1]); 1268 1094 break; 1269 1095 } … … 1274 1100 if (!fSet) 1275 1101 { 1276 rc = qedError(pImage, VERR_VD_GEN_INVALID_HEADER, RT_SRC_POS,1277 N_("Qed: Entry %d of the L1 table from image '%s' points to a already used cluster (%llu)"),1278 iL1, pImage->pszFilename, paL1Tbl[iL1]);1102 rc = vdIfError(pImage->pIfError, VERR_VD_GEN_INVALID_HEADER, RT_SRC_POS, 1103 N_("Qed: Entry %d of the L1 table from image '%s' points to a already used cluster (%llu)"), 1104 iL1, pImage->pszFilename, paL1Tbl[iL1]); 1279 1105 break; 1280 1106 } 1281 1107 1282 1108 /* Read the linked L2 table and check it. */ 1283 rc = qedFileReadSync(pImage, paL1Tbl[iL1], paL2Tbl, cbTable, NULL); 1109 rc = vdIfIoIntFileReadSync(pImage->pIfIo, pImage->pStorage, 1110 paL1Tbl[iL1], paL2Tbl, cbTable, NULL); 1284 1111 if (RT_FAILURE(rc)) 1285 1112 { 1286 rc = qedError(pImage, rc, RT_SRC_POS,1287 N_("Qed: Reading the L2 table from image '%s' failed"),1288 pImage->pszFilename);1113 rc = vdIfError(pImage->pIfError, rc, RT_SRC_POS, 1114 N_("Qed: Reading the L2 table from image '%s' failed"), 1115 pImage->pszFilename); 1289 1116 break; 1290 1117 } … … 1298 1125 if (!qedIsClusterOffsetValid(paL2Tbl[iL2], cbFile, pHeader->u32ClusterSize)) 1299 1126 { 1300 rc = qedError(pImage, VERR_VD_GEN_INVALID_HEADER, RT_SRC_POS,1301 N_("Qed: Entry %d of the L2 table from image '%s' is invalid (%llu)"),1302 iL2, pImage->pszFilename, paL2Tbl[iL2]);1127 rc = vdIfError(pImage->pIfError, VERR_VD_GEN_INVALID_HEADER, RT_SRC_POS, 1128 N_("Qed: Entry %d of the L2 table from image '%s' is invalid (%llu)"), 1129 iL2, pImage->pszFilename, paL2Tbl[iL2]); 1303 1130 break; 1304 1131 } … … 1309 1136 if (!fSet) 1310 1137 { 1311 rc = qedError(pImage, VERR_VD_GEN_INVALID_HEADER, RT_SRC_POS,1312 N_("Qed: Entry %d of the L2 table from image '%s' points to a already used cluster (%llu)"),1313 iL2, pImage->pszFilename, paL2Tbl[iL2]);1138 rc = vdIfError(pImage->pIfError, VERR_VD_GEN_INVALID_HEADER, RT_SRC_POS, 1139 N_("Qed: Entry %d of the L2 table from image '%s' points to a already used cluster (%llu)"), 1140 iL2, pImage->pszFilename, paL2Tbl[iL2]); 1314 1141 break; 1315 1142 } … … 1346 1173 qedFlushImage(pImage); 1347 1174 1348 qedFileClose(pImage);1175 vdIfIoIntFileClose(pImage->pIfIo, pImage->pStorage); 1349 1176 pImage->pStorage = NULL; 1350 1177 } … … 1359 1186 1360 1187 if (fDelete && pImage->pszFilename) 1361 qedFileDelete(pImage, pImage->pszFilename);1188 vdIfIoIntFileDelete(pImage->pIfIo, pImage->pszFilename); 1362 1189 } 1363 1190 … … 1375 1202 pImage->uOpenFlags = uOpenFlags; 1376 1203 1377 pImage->pInterfaceError = VDInterfaceGet(pImage->pVDIfsDisk, VDINTERFACETYPE_ERROR); 1378 if (pImage->pInterfaceError) 1379 pImage->pInterfaceErrorCallbacks = VDGetInterfaceError(pImage->pInterfaceError); 1380 1381 /* Get I/O interface. */ 1382 pImage->pInterfaceIO = VDInterfaceGet(pImage->pVDIfsImage, VDINTERFACETYPE_IOINT); 1383 AssertPtrReturn(pImage->pInterfaceIO, VERR_INVALID_PARAMETER); 1384 pImage->pInterfaceIOCallbacks = VDGetInterfaceIOInt(pImage->pInterfaceIO); 1385 AssertPtrReturn(pImage->pInterfaceIOCallbacks, VERR_INVALID_PARAMETER); 1204 pImage->pIfError = VDIfErrorGet(pImage->pVDIfsDisk); 1205 pImage->pIfIo = VDIfIoIntGet(pImage->pVDIfsImage); 1206 AssertPtrReturn(pImage->pIfIo, VERR_INVALID_PARAMETER); 1386 1207 1387 1208 /* 1388 1209 * Open the image. 1389 1210 */ 1390 rc = qedFileOpen(pImage, pImage->pszFilename, 1391 VDOpenFlagsToFileOpenFlags(uOpenFlags, 1392 false /* fCreate */)); 1211 rc = vdIfIoIntFileOpen(pImage->pIfIo, pImage->pszFilename, 1212 VDOpenFlagsToFileOpenFlags(uOpenFlags, 1213 false /* fCreate */), 1214 &pImage->pStorage); 1393 1215 if (RT_FAILURE(rc)) 1394 1216 { … … 1400 1222 uint64_t cbFile; 1401 1223 QedHeader Header; 1402 rc = qedFileGetSize(pImage, &cbFile);1224 rc = vdIfIoIntFileGetSize(pImage->pIfIo, pImage->pStorage, &cbFile); 1403 1225 if (RT_FAILURE(rc)) 1404 1226 goto out; 1405 1227 if (cbFile > sizeof(Header)) 1406 1228 { 1407 rc = qedFileReadSync(pImage, 0, &Header, sizeof(Header), NULL);1229 rc = vdIfIoIntFileReadSync(pImage->pIfIo, pImage->pStorage, 0, &Header, sizeof(Header), NULL); 1408 1230 if ( RT_SUCCESS(rc) 1409 1231 && qedHdrConvertToHostEndianess(&Header)) … … 1418 1240 rc = qedCheckImage(pImage, &Header); 1419 1241 else 1420 rc = qedError(pImage, VERR_NOT_SUPPORTED, RT_SRC_POS,1421 N_("Qed: Image '%s' needs checking but is opened readonly"),1422 pImage->pszFilename);1242 rc = vdIfError(pImage->pIfError, VERR_NOT_SUPPORTED, RT_SRC_POS, 1243 N_("Qed: Image '%s' needs checking but is opened readonly"), 1244 pImage->pszFilename); 1423 1245 } 1424 1246 … … 1432 1254 pImage->cbBackingFilename = Header.u32BackingFilenameSize; 1433 1255 pImage->offBackingFilename = Header.u32OffBackingFilename; 1434 rc = qedFileReadSync(pImage, Header.u32OffBackingFilename, pImage->pszBackingFilename, 1435 Header.u32BackingFilenameSize, NULL); 1256 rc = vdIfIoIntFileReadSync(pImage->pIfIo, pImage->pStorage, 1257 Header.u32OffBackingFilename, pImage->pszBackingFilename, 1258 Header.u32BackingFilenameSize, NULL); 1436 1259 } 1437 1260 else … … 1454 1277 { 1455 1278 /* Read from the image. */ 1456 rc = qedFileReadSync(pImage, pImage->offL1Table, pImage->paL1Table, 1457 pImage->cbTable, NULL); 1279 rc = vdIfIoIntFileReadSync(pImage->pIfIo, pImage->pStorage, 1280 pImage->offL1Table, pImage->paL1Table, 1281 pImage->cbTable, NULL); 1458 1282 if (RT_SUCCESS(rc)) 1459 1283 { … … 1467 1291 } 1468 1292 else 1469 rc = qedError(pImage, rc, RT_SRC_POS,1470 N_("Qed: Creating the L2 table cache for image '%s' failed"),1471 pImage->pszFilename);1293 rc = vdIfError(pImage->pIfError, rc, RT_SRC_POS, 1294 N_("Qed: Creating the L2 table cache for image '%s' failed"), 1295 pImage->pszFilename); 1472 1296 } 1473 1297 else 1474 rc = qedError(pImage, rc, RT_SRC_POS,1475 N_("Qed: Reading the L1 table for image '%s' failed"),1476 pImage->pszFilename);1298 rc = vdIfError(pImage->pIfError, rc, RT_SRC_POS, 1299 N_("Qed: Reading the L1 table for image '%s' failed"), 1300 pImage->pszFilename); 1477 1301 } 1478 1302 else 1479 rc = qedError(pImage, VERR_NO_MEMORY, RT_SRC_POS,1480 N_("Qed: Out of memory allocating L1 table for image '%s'"),1481 pImage->pszFilename);1303 rc = vdIfError(pImage->pIfError, VERR_NO_MEMORY, RT_SRC_POS, 1304 N_("Qed: Out of memory allocating L1 table for image '%s'"), 1305 pImage->pszFilename); 1482 1306 } 1483 1307 } 1484 1308 else 1485 rc = qedError(pImage, VERR_NOT_SUPPORTED, RT_SRC_POS,1486 N_("Qed: The image '%s' makes use of unsupported features"),1487 pImage->pszFilename);1309 rc = vdIfError(pImage->pIfError, VERR_NOT_SUPPORTED, RT_SRC_POS, 1310 N_("Qed: The image '%s' makes use of unsupported features"), 1311 pImage->pszFilename); 1488 1312 } 1489 1313 else if (RT_SUCCESS(rc)) … … 1510 1334 { 1511 1335 int rc; 1512 uint64_t uOff;1513 1336 int32_t fOpen; 1514 1337 1515 1338 if (uImageFlags & VD_IMAGE_FLAGS_FIXED) 1516 1339 { 1517 rc = qedError(pImage, VERR_VD_INVALID_TYPE, RT_SRC_POS, N_("Qed: cannot create fixed image '%s'"), pImage->pszFilename);1340 rc = vdIfError(pImage->pIfError, VERR_VD_INVALID_TYPE, RT_SRC_POS, N_("Qed: cannot create fixed image '%s'"), pImage->pszFilename); 1518 1341 goto out; 1519 1342 } … … 1524 1347 pImage->LCHSGeometry = *pLCHSGeometry; 1525 1348 1526 pImage->pInterfaceError = VDInterfaceGet(pImage->pVDIfsDisk, VDINTERFACETYPE_ERROR); 1527 if (pImage->pInterfaceError) 1528 pImage->pInterfaceErrorCallbacks = VDGetInterfaceError(pImage->pInterfaceError); 1529 1530 /* Get I/O interface. */ 1531 pImage->pInterfaceIO = VDInterfaceGet(pImage->pVDIfsImage, VDINTERFACETYPE_IOINT); 1532 AssertPtrReturn(pImage->pInterfaceIO, VERR_INVALID_PARAMETER); 1533 pImage->pInterfaceIOCallbacks = VDGetInterfaceIOInt(pImage->pInterfaceIO); 1534 AssertPtrReturn(pImage->pInterfaceIOCallbacks, VERR_INVALID_PARAMETER); 1349 pImage->pIfError = VDIfErrorGet(pImage->pVDIfsDisk); 1350 pImage->pIfIo = VDIfIoIntGet(pImage->pVDIfsImage); 1351 AssertPtrReturn(pImage->pIfIo, VERR_INVALID_PARAMETER); 1535 1352 1536 1353 /* Create image file. */ 1537 1354 fOpen = VDOpenFlagsToFileOpenFlags(pImage->uOpenFlags, true /* fCreate */); 1538 rc = qedFileOpen(pImage, pImage->pszFilename, fOpen);1355 rc = vdIfIoIntFileOpen(pImage->pIfIo, pImage->pszFilename, fOpen, &pImage->pStorage); 1539 1356 if (RT_FAILURE(rc)) 1540 1357 { 1541 rc = qedError(pImage, rc, RT_SRC_POS, N_("Qed: cannot create image '%s'"), pImage->pszFilename);1358 rc = vdIfError(pImage->pIfError, rc, RT_SRC_POS, N_("Qed: cannot create image '%s'"), pImage->pszFilename); 1542 1359 goto out; 1543 1360 } … … 1558 1375 if (!pImage->paL1Table) 1559 1376 { 1560 rc = qedError(pImage, VERR_NO_MEMORY, RT_SRC_POS, N_("Qed: cannot allocate memory for L1 table of image '%s'"),1561 pImage->pszFilename);1377 rc = vdIfError(pImage->pIfError, VERR_NO_MEMORY, RT_SRC_POS, N_("Qed: cannot allocate memory for L1 table of image '%s'"), 1378 pImage->pszFilename); 1562 1379 goto out; 1563 1380 } … … 1566 1383 if (RT_FAILURE(rc)) 1567 1384 { 1568 rc = qedError(pImage, rc, RT_SRC_POS, N_("Qed: Failed to create L2 cache for image '%s'"),1569 pImage->pszFilename);1385 rc = vdIfError(pImage->pIfError, rc, RT_SRC_POS, N_("Qed: Failed to create L2 cache for image '%s'"), 1386 pImage->pszFilename); 1570 1387 goto out; 1571 1388 } … … 1603 1420 { 1604 1421 /* Assumption right now is that the L1 table is not modified if the link fails. */ 1605 rc = qedFileSetSize(pImage, pClusterAlloc->cbImageOld);1422 rc = vdIfIoIntFileSetSize(pImage->pIfIo, pImage->pStorage, pClusterAlloc->cbImageOld); 1606 1423 qedL2TblCacheEntryRelease(pClusterAlloc->pL2Entry); /* Release L2 cache entry. */ 1607 1424 qedL2TblCacheEntryFree(pImage, pClusterAlloc->pL2Entry); /* Free it, it is not in the cache yet. */ … … 1611 1428 { 1612 1429 /* Assumption right now is that the L2 table is not modified if the link fails. */ 1613 rc = qedFileSetSize(pImage, pClusterAlloc->cbImageOld);1430 rc = vdIfIoIntFileSetSize(pImage->pIfIo, pImage->pStorage, pClusterAlloc->cbImageOld); 1614 1431 qedL2TblCacheEntryRelease(pClusterAlloc->pL2Entry); /* Release L2 cache entry. */ 1615 1432 } … … 1651 1468 /* Update the link in the on disk L1 table now. */ 1652 1469 pClusterAlloc->enmAllocState = QEDCLUSTERASYNCALLOCSTATE_L2_LINK; 1653 rc = qedFileWriteMetaAsync(pImage, pImage->offL1Table + pClusterAlloc->idxL1*sizeof(uint64_t), 1654 &offUpdateLe, sizeof(uint64_t), pIoCtx, 1655 qedAsyncClusterAllocUpdate, pClusterAlloc); 1470 rc = vdIfIoIntFileWriteMetaAsync(pImage->pIfIo, pImage->pStorage, 1471 pImage->offL1Table + pClusterAlloc->idxL1*sizeof(uint64_t), 1472 &offUpdateLe, sizeof(uint64_t), pIoCtx, 1473 qedAsyncClusterAllocUpdate, pClusterAlloc); 1656 1474 if (rc == VERR_VD_ASYNC_IO_IN_PROGRESS) 1657 1475 break; … … 1678 1496 1679 1497 /* Write data. */ 1680 rc = qedFileWriteUserAsync(pImage, offData, pIoCtx, pClusterAlloc->cbToWrite, 1681 qedAsyncClusterAllocUpdate, pClusterAlloc); 1498 rc = vdIfIoIntFileWriteUserAsync(pImage->pIfIo, pImage->pStorage, 1499 offData, pIoCtx, pClusterAlloc->cbToWrite, 1500 qedAsyncClusterAllocUpdate, pClusterAlloc); 1682 1501 if (rc == VERR_VD_ASYNC_IO_IN_PROGRESS) 1683 1502 break; … … 1696 1515 1697 1516 /* Link L2 table and update it. */ 1698 rc = qedFileWriteMetaAsync(pImage, pImage->paL1Table[pClusterAlloc->idxL1] + pClusterAlloc->idxL2*sizeof(uint64_t), 1699 &offUpdateLe, sizeof(uint64_t), pIoCtx, 1700 qedAsyncClusterAllocUpdate, pClusterAlloc); 1517 rc = vdIfIoIntFileWriteMetaAsync(pImage->pIfIo, pImage->pStorage, 1518 pImage->paL1Table[pClusterAlloc->idxL1] + pClusterAlloc->idxL2*sizeof(uint64_t), 1519 &offUpdateLe, sizeof(uint64_t), pIoCtx, 1520 qedAsyncClusterAllocUpdate, pClusterAlloc); 1701 1521 if (rc == VERR_VD_ASYNC_IO_IN_PROGRESS) 1702 1522 break; … … 1735 1555 1736 1556 /* Get I/O interface. */ 1737 PVDINTERFACE pInterfaceIO = VDInterfaceGet(pVDIfsImage, VDINTERFACETYPE_IOINT); 1738 AssertPtrReturn(pInterfaceIO, VERR_INVALID_PARAMETER); 1739 PVDINTERFACEIOINT pInterfaceIOCallbacks = VDGetInterfaceIOInt(pInterfaceIO); 1740 AssertPtrReturn(pInterfaceIOCallbacks, VERR_INVALID_PARAMETER); 1557 PVDINTERFACEIOINT pIfIo = VDIfIoIntGet(pVDIfsImage); 1558 AssertPtrReturn(pIfIo, VERR_INVALID_PARAMETER); 1741 1559 1742 1560 if ( !VALID_PTR(pszFilename) … … 1750 1568 * Open the file and read the footer. 1751 1569 */ 1752 rc = pInterfaceIOCallbacks->pfnOpen(pInterfaceIO->pvUser, pszFilename,1753 1754 1755 1570 rc = vdIfIoIntFileOpen(pIfIo, pszFilename, 1571 VDOpenFlagsToFileOpenFlags(VD_OPEN_FLAGS_READONLY, 1572 false /* fCreate */), 1573 &pStorage); 1756 1574 if (RT_SUCCESS(rc)) 1757 rc = pInterfaceIOCallbacks->pfnGetSize(pInterfaceIO->pvUser, pStorage, 1758 &cbFile); 1575 rc = vdIfIoIntFileGetSize(pIfIo, pStorage, &cbFile); 1759 1576 1760 1577 if ( RT_SUCCESS(rc) … … 1763 1580 QedHeader Header; 1764 1581 1765 rc = pInterfaceIOCallbacks->pfnReadSync(pInterfaceIO->pvUser, pStorage, 0, &Header, 1766 sizeof(Header), NULL); 1582 rc = vdIfIoIntFileReadSync(pIfIo, pStorage, 0, &Header, sizeof(Header), NULL); 1767 1583 if ( RT_SUCCESS(rc) 1768 1584 && qedHdrConvertToHostEndianess(&Header)) … … 1778 1594 1779 1595 if (pStorage) 1780 pInterfaceIOCallbacks->pfnClose(pInterfaceIO->pvUser, pStorage);1596 vdIfIoIntFileClose(pIfIo, pStorage); 1781 1597 1782 1598 out: … … 1848 1664 PFNVDPROGRESS pfnProgress = NULL; 1849 1665 void *pvUser = NULL; 1850 PVDINTERFACE pIfProgress = VDInterfaceGet(pVDIfsOperation, 1851 VDINTERFACETYPE_PROGRESS); 1852 PVDINTERFACEPROGRESS pCbProgress = NULL; 1666 PVDINTERFACEPROGRESS pIfProgress = VDIfProgressGet(pVDIfsOperation); 1853 1667 if (pIfProgress) 1854 1668 { 1855 pCbProgress = VDGetInterfaceProgress(pIfProgress); 1856 if (pCbProgress) 1857 pfnProgress = pCbProgress->pfnProgress; 1858 pvUser = pIfProgress->pvUser; 1669 pfnProgress = pIfProgress->pfnProgress; 1670 pvUser = pIfProgress->Core.pvUser; 1859 1671 } 1860 1672 … … 1936 1748 1937 1749 /* Rename the file. */ 1938 rc = qedFileMove(pImage, pImage->pszFilename, pszFilename, 0);1750 rc = vdIfIoIntFileMove(pImage->pIfIo, pImage->pszFilename, pszFilename, 0); 1939 1751 if (RT_FAILURE(rc)) 1940 1752 { … … 2009 1821 { 2010 1822 LogFlowFunc(("offFile=%llu\n", offFile)); 2011 rc = qedFileReadSync(pImage, offFile, pvBuf, cbToRead, NULL); 1823 rc = vdIfIoIntFileReadSync(pImage->pIfIo, pImage->pStorage, offFile, 1824 pvBuf, cbToRead, NULL); 2012 1825 } 2013 1826 … … 2062 1875 rc = qedConvertToImageOffset(pImage, idxL1, idxL2, offCluster, &offImage); 2063 1876 if (RT_SUCCESS(rc)) 2064 rc = qedFileWriteSync(pImage, offImage, pvBuf, cbToWrite, NULL); 1877 rc = vdIfIoIntFileWriteSync(pImage->pIfIo, pImage->pStorage, offImage, 1878 pvBuf, cbToWrite, NULL); 2065 1879 else if (rc == VERR_VD_BLOCK_FREE) 2066 1880 { … … 2099 1913 * is a leak of some clusters. 2100 1914 */ 2101 rc = qedFileWriteSync(pImage, offL2Tbl, pL2Entry->paL2Tbl, pImage->cbTable, NULL); 1915 rc = vdIfIoIntFileWriteSync(pImage->pIfIo, pImage->pStorage, offL2Tbl, 1916 pL2Entry->paL2Tbl, pImage->cbTable, NULL); 2102 1917 if (RT_FAILURE(rc)) 2103 1918 break; … … 2106 1921 pImage->paL1Table[idxL1] = offL2Tbl; 2107 1922 idxUpdateLe = RT_H2LE_U64(offL2Tbl); 2108 rc = qedFileWriteSync(pImage, pImage->offL1Table + idxL1*sizeof(uint64_t), 2109 &idxUpdateLe, sizeof(uint64_t), NULL); 1923 rc = vdIfIoIntFileWriteSync(pImage->pIfIo, pImage->pStorage, 1924 pImage->offL1Table + idxL1*sizeof(uint64_t), 1925 &idxUpdateLe, sizeof(uint64_t), NULL); 2110 1926 if (RT_FAILURE(rc)) 2111 1927 break; … … 2120 1936 2121 1937 /* Write data. */ 2122 rc = qedFileWriteSync(pImage, offData, pvBuf, cbToWrite, NULL); 1938 rc = vdIfIoIntFileWriteSync(pImage->pIfIo, pImage->pStorage, 1939 offData, pvBuf, cbToWrite, NULL); 2123 1940 if (RT_FAILURE(rc)) 2124 1941 break; … … 2127 1944 pL2Entry->paL2Tbl[idxL2] = offData; 2128 1945 idxUpdateLe = RT_H2LE_U64(offData); 2129 rc = qedFileWriteSync(pImage, pImage->paL1Table[idxL1] + idxL2*sizeof(uint64_t), 2130 &idxUpdateLe, sizeof(uint64_t), NULL); 1946 rc = vdIfIoIntFileWriteSync(pImage->pIfIo, pImage->pStorage, 1947 pImage->paL1Table[idxL1] + idxL2*sizeof(uint64_t), 1948 &idxUpdateLe, sizeof(uint64_t), NULL); 2131 1949 qedL2TblCacheEntryRelease(pL2Entry); 2132 1950 } … … 2210 2028 if (pImage->pStorage) 2211 2029 { 2212 int rc = qedFileGetSize(pImage, &cbFile);2030 int rc = vdIfIoIntFileGetSize(pImage->pIfIo, pImage->pStorage, &cbFile); 2213 2031 if (RT_SUCCESS(rc)) 2214 2032 cb += cbFile; … … 2608 2426 if (pImage) 2609 2427 { 2610 qedMessage(pImage, "Header: Geometry PCHS=%u/%u/%u LCHS=%u/%u/%u cbSector=%llu\n",2611 pImage->PCHSGeometry.cCylinders, pImage->PCHSGeometry.cHeads, pImage->PCHSGeometry.cSectors,2612 pImage->LCHSGeometry.cCylinders, pImage->LCHSGeometry.cHeads, pImage->LCHSGeometry.cSectors,2613 pImage->cbSize / 512);2428 vdIfErrorMessage(pImage->pIfError, "Header: Geometry PCHS=%u/%u/%u LCHS=%u/%u/%u cbSector=%llu\n", 2429 pImage->PCHSGeometry.cCylinders, pImage->PCHSGeometry.cHeads, pImage->PCHSGeometry.cSectors, 2430 pImage->LCHSGeometry.cCylinders, pImage->LCHSGeometry.cHeads, pImage->LCHSGeometry.cSectors, 2431 pImage->cbSize / 512); 2614 2432 } 2615 2433 } … … 2665 2483 pImage->offBackingFilename = (uint32_t)offData; 2666 2484 pImage->cbBackingFilename = strlen(pszParentFilename); 2667 rc = qedFileSetSize(pImage, offData + pImage->cbCluster); 2485 rc = vdIfIoIntFileSetSize(pImage->pIfIo, pImage->pStorage, 2486 offData + pImage->cbCluster); 2668 2487 } 2669 2488 2670 2489 if (RT_SUCCESS(rc)) 2671 rc = qedFileWriteSync(pImage, pImage->offBackingFilename, 2672 pImage->pszBackingFilename, strlen(pImage->pszBackingFilename), 2673 NULL); 2490 rc = vdIfIoIntFileWriteSync(pImage->pIfIo, pImage->pStorage, 2491 pImage->offBackingFilename, 2492 pImage->pszBackingFilename, 2493 strlen(pImage->pszBackingFilename), 2494 NULL); 2674 2495 } 2675 2496 } … … 2720 2541 &offFile); 2721 2542 if (RT_SUCCESS(rc)) 2722 rc = qedFileReadUserAsync(pImage, offFile, pIoCtx, cbToRead); 2543 rc = vdIfIoIntFileReadUserAsync(pImage->pIfIo, pImage->pStorage, offFile, 2544 pIoCtx, cbToRead); 2723 2545 2724 2546 if ( ( RT_SUCCESS(rc) … … 2781 2603 &offImage); 2782 2604 if (RT_SUCCESS(rc)) 2783 rc = qedFileWriteUserAsync(pImage, offImage, pIoCtx, cbToWrite,2784 NULL, NULL);2605 rc = vdIfIoIntFileWriteUserAsync(pImage->pIfIo, pImage->pStorage, 2606 offImage, pIoCtx, cbToWrite, NULL, NULL); 2785 2607 else if (rc == VERR_VD_BLOCK_FREE) 2786 2608 { … … 2837 2659 * is a leak of some clusters. 2838 2660 */ 2839 rc = qedFileWriteMetaAsync(pImage, offL2Tbl, pL2Entry->paL2Tbl, pImage->cbTable, pIoCtx, 2840 qedAsyncClusterAllocUpdate, pL2ClusterAlloc); 2661 rc = vdIfIoIntFileWriteMetaAsync(pImage->pIfIo, pImage->pStorage, 2662 offL2Tbl, pL2Entry->paL2Tbl, pImage->cbTable, pIoCtx, 2663 qedAsyncClusterAllocUpdate, pL2ClusterAlloc); 2841 2664 if (rc == VERR_VD_ASYNC_IO_IN_PROGRESS) 2842 2665 break; … … 2879 2702 2880 2703 /* Write data. */ 2881 rc = qedFileWriteUserAsync(pImage, offData, pIoCtx, cbToWrite, 2882 qedAsyncClusterAllocUpdate, pDataClusterAlloc); 2704 rc = vdIfIoIntFileWriteUserAsync(pImage->pIfIo, pImage->pStorage, 2705 offData, pIoCtx, cbToWrite, 2706 qedAsyncClusterAllocUpdate, pDataClusterAlloc); 2883 2707 if (rc == VERR_VD_ASYNC_IO_IN_PROGRESS) 2884 2708 break; … … 2943 2767 int rc = VINF_SUCCESS; 2944 2768 2945 PFNVDPROGRESS pfnProgress = NULL; 2946 void *pvUser = NULL; 2947 PVDINTERFACE pIfProgress = VDInterfaceGet(pVDIfsOperation, 2948 VDINTERFACETYPE_PROGRESS); 2949 PVDINTERFACEPROGRESS pCbProgress = NULL; 2950 if (pIfProgress) 2951 { 2952 pCbProgress = VDGetInterfaceProgress(pIfProgress); 2953 if (pCbProgress) 2954 pfnProgress = pCbProgress->pfnProgress; 2955 pvUser = pIfProgress->pvUser; 2956 } 2769 PVDINTERFACEPROGRESS pIfProgress = VDIfProgressGet(pVDIfsOperation); 2957 2770 2958 2771 /* Making the image smaller is not supported at the moment. */ … … 2971 2784 */ 2972 2785 if (qedByte2Cluster(pImage, pImage->cbTable)*pImage->cTableEntries*pImage->cTableEntries*pImage->cbCluster < cbSize) 2973 rc = qedError(pImage, VERR_BUFFER_OVERFLOW, RT_SRC_POS,2974 N_("Qed: Resizing the image '%s' is not supported because it would overflow the L1 and L2 table\n"),2975 pImage->pszFilename);2786 rc = vdIfError(pImage->pIfError, VERR_BUFFER_OVERFLOW, RT_SRC_POS, 2787 N_("Qed: Resizing the image '%s' is not supported because it would overflow the L1 and L2 table\n"), 2788 pImage->pszFilename); 2976 2789 else 2977 2790 { … … 2984 2797 pImage->cbSize = cbSizeOld; /* Restore */ 2985 2798 2986 rc = qedError(pImage, rc, RT_SRC_POS, N_("Qed: Resizing the image '%s' failed\n"),2987 pImage->pszFilename);2799 rc = vdIfError(pImage->pIfError, rc, RT_SRC_POS, N_("Qed: Resizing the image '%s' failed\n"), 2800 pImage->pszFilename); 2988 2801 } 2989 2802 }
Note:
See TracChangeset
for help on using the changeset viewer.