- Timestamp:
- Apr 18, 2014 9:57:44 AM (11 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/vd-ifs-internal.h
r50988 r51102 407 407 size_t cbCheck, bool fAdvance)); 408 408 409 /** 410 * Returns the data unit size, i.e. the smallest size for a transfer. 411 * (similar to the sector size of disks). 412 * 413 * @returns The data unit size. 414 * @param pvUser The opaque user data passed on container creation. 415 * @param pIoCtx The I/O context. 416 */ 417 DECLR3CALLBACKMEMBER(size_t, pfnIoCtxGetDataUnitSize, (void *pvUser, PVDIOCTX pIoCtx)); 418 409 419 } VDINTERFACEIOINT, *PVDINTERFACEIOINT; 410 420 … … 585 595 } 586 596 597 DECLINLINE(size_t) vdIfIoIntIoCtxGetDataUnitSize(PVDINTERFACEIOINT pIfIoInt, PVDIOCTX pIoCtx) 598 { 599 return pIfIoInt->pfnIoCtxGetDataUnitSize(pIfIoInt->Core.pvUser, pIoCtx); 600 } 587 601 588 602 /** -
trunk/include/VBox/vd-ifs.h
r50988 r51102 743 743 */ 744 744 DECLR3CALLBACKMEMBER(int, pfnQuery, (void *pvUser, const char *pszName, char *pszValue, size_t cchValue)); 745 746 /** 747 * Query the bytes value associated with a key. 748 * 749 * @return VBox status code. 750 * VERR_CFGM_VALUE_NOT_FOUND means that the key is not known. 751 * VERR_CFGM_NOT_ENOUGH_SPACE means that the buffer is not big enough. 752 * @param pvUser The opaque user data associated with this interface. 753 * @param pszName Name of the key to query. 754 * @param ppvData Pointer to buffer where to store the data. 755 * @param cbData Length of data buffer. 756 */ 757 DECLR3CALLBACKMEMBER(int, pfnQueryBytes, (void *pvUser, const char *pszName, void *ppvData, size_t cbData)); 745 758 746 759 } VDINTERFACECONFIG, *PVDINTERFACECONFIG; … … 951 964 if (pbData) 952 965 { 953 rc = pCfgIf->pfnQuery(pCfgIf->Core.pvUser, pszName, pbData, cb); 966 if(pCfgIf->pfnQueryBytes) 967 rc = pCfgIf->pfnQueryBytes(pCfgIf->Core.pvUser, pszName, pbData, cb); 968 else 969 rc = pCfgIf->pfnQuery(pCfgIf->Core.pvUser, pszName, pbData, cb); 970 954 971 if (RT_SUCCESS(rc)) 955 972 { 956 973 *ppvData = pbData; 957 *pcbData = cb - 1; /* Exclude terminator of the queried string. */974 *pcbData = cb; 958 975 } 959 976 else … … 964 981 } 965 982 return rc; 983 } 984 985 /** 986 * Query configuration, dynamically allocated (RTMemAlloc) zero terminated 987 * character value - the memory is locked to prevent paging to disk, 988 * useful for memory which holds keys, passwords, etc. 989 * 990 * @return VBox status code. 991 * @param pCfgIf Pointer to configuration callback table. 992 * @param pszName Name of an zero terminated character value 993 * @param ppszString Where to store the string pointer. Not set on failure. 994 * Free this using RTMemFree(). 995 */ 996 DECLINLINE(int) VDCFGQueryStringAllocLocked(PVDINTERFACECONFIG pCfgIf, 997 const char *pszName, char **ppszString) 998 { 999 size_t cb; 1000 int rc = pCfgIf->pfnQuerySize(pCfgIf->Core.pvUser, pszName, &cb); 1001 if (RT_SUCCESS(rc)) 1002 { 1003 char *pszString = (char *)RTMemLockedAlloc(cb); 1004 if (pszString) 1005 { 1006 rc = pCfgIf->pfnQuery(pCfgIf->Core.pvUser, pszName, pszString, cb); 1007 if (RT_SUCCESS(rc)) 1008 *ppszString = pszString; 1009 else 1010 RTMemFree(pszString); 1011 } 1012 else 1013 rc = VERR_NO_MEMORY; 1014 } 1015 return rc; 1016 } 1017 1018 /** 1019 * Query configuration, dynamically allocated (RTMemAlloc) zero terminated 1020 * character value with default - the memory is locked to prevent paging to disk, 1021 * useful for memory which holds keys, passwords, etc. 1022 * 1023 * @return VBox status code. 1024 * @param pCfgIf Pointer to configuration callback table. 1025 * @param pszName Name of an zero terminated character value 1026 * @param ppszString Where to store the string pointer. Not set on failure. 1027 * Free this using RTMemFree(). 1028 * @param pszDef The default value. 1029 */ 1030 DECLINLINE(int) VDCFGQueryStringAllocLockedDef(PVDINTERFACECONFIG pCfgIf, 1031 const char *pszName, 1032 char **ppszString, 1033 const char *pszDef) 1034 { 1035 size_t cb; 1036 int rc = pCfgIf->pfnQuerySize(pCfgIf->Core.pvUser, pszName, &cb); 1037 if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT) 1038 { 1039 cb = strlen(pszDef) + 1; 1040 rc = VINF_SUCCESS; 1041 } 1042 if (RT_SUCCESS(rc)) 1043 { 1044 char *pszString = (char *)RTMemLockedAlloc(cb); 1045 if (pszString) 1046 { 1047 rc = pCfgIf->pfnQuery(pCfgIf->Core.pvUser, pszName, pszString, cb); 1048 if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT) 1049 { 1050 memcpy(pszString, pszDef, cb); 1051 rc = VINF_SUCCESS; 1052 } 1053 if (RT_SUCCESS(rc)) 1054 *ppszString = pszString; 1055 else 1056 RTMemFree(pszString); 1057 } 1058 else 1059 rc = VERR_NO_MEMORY; 1060 } 1061 return rc; 1062 } 1063 1064 /** 1065 * Query configuration, dynamically allocated (RTMemAlloc) byte string value - 1066 * the memory is locked to prevent paging to disk, useful for memory which holds 1067 * keys, passwords, etc.. 1068 * 1069 * @return VBox status code. 1070 * @param pCfgIf Pointer to configuration callback table. 1071 * @param pszName Name of an zero terminated character value 1072 * @param ppvData Where to store the byte string pointer. Not set on failure. 1073 * Free this using RTMemFree(). 1074 * @param pcbData Where to store the byte string length. 1075 */ 1076 DECLINLINE(int) VDCFGQueryBytesAllocLocked(PVDINTERFACECONFIG pCfgIf, 1077 const char *pszName, void **ppvData, size_t *pcbData) 1078 { 1079 size_t cb; 1080 int rc = pCfgIf->pfnQuerySize(pCfgIf->Core.pvUser, pszName, &cb); 1081 if (RT_SUCCESS(rc)) 1082 { 1083 char *pbData; 1084 Assert(cb); 1085 1086 pbData = (char *)RTMemLockedAlloc(cb); 1087 if (pbData) 1088 { 1089 if(pCfgIf->pfnQueryBytes) 1090 rc = pCfgIf->pfnQueryBytes(pCfgIf->Core.pvUser, pszName, pbData, cb); 1091 else 1092 rc = pCfgIf->pfnQuery(pCfgIf->Core.pvUser, pszName, pbData, cb); 1093 1094 if (RT_SUCCESS(rc)) 1095 { 1096 *ppvData = pbData; 1097 *pcbData = cb; 1098 } 1099 else 1100 RTMemFree(pbData); 1101 } 1102 else 1103 rc = VERR_NO_MEMORY; 1104 } 1105 return rc; 1106 } 1107 1108 /** 1109 * Frees memory allocated using one of the VDCFGQuery*AllocLocked methods. 1110 */ 1111 DECLINLINE(void) VDCFGMemLockedFree(void *pvData) 1112 { 1113 RTMemLockedFree(pvData); 966 1114 } 967 1115 -
trunk/src/VBox/Storage/VD.cpp
r51073 r51102 4919 4919 } 4920 4920 4921 static DECLCALLBACK(size_t) vdIOIntIoCtxGetDataUnitSize(void *pvUser, PVDIOCTX pIoCtx) 4922 { 4923 PVDIO pVDIo = (PVDIO)pvUser; 4924 PVBOXHDD pDisk = pVDIo->pDisk; 4925 4926 PVDIMAGE pImage = vdGetImageByNumber(pDisk, VD_LAST_IMAGE); 4927 AssertPtrReturn(pImage, 0); 4928 return pImage->Backend->pfnGetSectorSize(pImage->pBackendData); 4929 } 4930 4921 4931 /** 4922 4932 * VD I/O interface callback for opening a file (limited version for VDGetFormat). … … 5181 5191 static void vdIfIoIntCallbacksSetup(PVDINTERFACEIOINT pIfIoInt) 5182 5192 { 5183 pIfIoInt->pfnOpen = vdIOIntOpen; 5184 pIfIoInt->pfnClose = vdIOIntClose; 5185 pIfIoInt->pfnDelete = vdIOIntDelete; 5186 pIfIoInt->pfnMove = vdIOIntMove; 5187 pIfIoInt->pfnGetFreeSpace = vdIOIntGetFreeSpace; 5188 pIfIoInt->pfnGetModificationTime = vdIOIntGetModificationTime; 5189 pIfIoInt->pfnGetSize = vdIOIntGetSize; 5190 pIfIoInt->pfnSetSize = vdIOIntSetSize; 5191 pIfIoInt->pfnReadUser = vdIOIntReadUser; 5192 pIfIoInt->pfnWriteUser = vdIOIntWriteUser; 5193 pIfIoInt->pfnReadMeta = vdIOIntReadMeta; 5194 pIfIoInt->pfnWriteMeta = vdIOIntWriteMeta; 5195 pIfIoInt->pfnMetaXferRelease = vdIOIntMetaXferRelease; 5196 pIfIoInt->pfnFlush = vdIOIntFlush; 5197 pIfIoInt->pfnIoCtxCopyFrom = vdIOIntIoCtxCopyFrom; 5198 pIfIoInt->pfnIoCtxCopyTo = vdIOIntIoCtxCopyTo; 5199 pIfIoInt->pfnIoCtxSet = vdIOIntIoCtxSet; 5200 pIfIoInt->pfnIoCtxSegArrayCreate = vdIOIntIoCtxSegArrayCreate; 5201 pIfIoInt->pfnIoCtxCompleted = vdIOIntIoCtxCompleted; 5202 pIfIoInt->pfnIoCtxIsSynchronous = vdIOIntIoCtxIsSynchronous; 5203 pIfIoInt->pfnIoCtxIsZero = vdIOIntIoCtxIsZero; 5193 pIfIoInt->pfnOpen = vdIOIntOpen; 5194 pIfIoInt->pfnClose = vdIOIntClose; 5195 pIfIoInt->pfnDelete = vdIOIntDelete; 5196 pIfIoInt->pfnMove = vdIOIntMove; 5197 pIfIoInt->pfnGetFreeSpace = vdIOIntGetFreeSpace; 5198 pIfIoInt->pfnGetModificationTime = vdIOIntGetModificationTime; 5199 pIfIoInt->pfnGetSize = vdIOIntGetSize; 5200 pIfIoInt->pfnSetSize = vdIOIntSetSize; 5201 pIfIoInt->pfnReadUser = vdIOIntReadUser; 5202 pIfIoInt->pfnWriteUser = vdIOIntWriteUser; 5203 pIfIoInt->pfnReadMeta = vdIOIntReadMeta; 5204 pIfIoInt->pfnWriteMeta = vdIOIntWriteMeta; 5205 pIfIoInt->pfnMetaXferRelease = vdIOIntMetaXferRelease; 5206 pIfIoInt->pfnFlush = vdIOIntFlush; 5207 pIfIoInt->pfnIoCtxCopyFrom = vdIOIntIoCtxCopyFrom; 5208 pIfIoInt->pfnIoCtxCopyTo = vdIOIntIoCtxCopyTo; 5209 pIfIoInt->pfnIoCtxSet = vdIOIntIoCtxSet; 5210 pIfIoInt->pfnIoCtxSegArrayCreate = vdIOIntIoCtxSegArrayCreate; 5211 pIfIoInt->pfnIoCtxCompleted = vdIOIntIoCtxCompleted; 5212 pIfIoInt->pfnIoCtxIsSynchronous = vdIOIntIoCtxIsSynchronous; 5213 pIfIoInt->pfnIoCtxIsZero = vdIOIntIoCtxIsZero; 5214 pIfIoInt->pfnIoCtxGetDataUnitSize = vdIOIntIoCtxGetDataUnitSize; 5204 5215 } 5205 5216
Note:
See TracChangeset
for help on using the changeset viewer.