Lines Matching refs:pDisk

96     PVBOXHDD            pDisk;
313 PVBOXHDD pDisk;
348 PVBOXHDD pDisk;
665 static void vdDiskProcessBlockedIoCtx(PVBOXHDD pDisk);
666 static int vdDiskUnlock(PVBOXHDD pDisk, PVDIOCTX pIoCtxRc);
771 static int vdError(PVBOXHDD pDisk, int rc, RT_SRC_POS_DECL,
776 if (pDisk->pInterfaceError)
777 pDisk->pInterfaceError->pfnError(pDisk->pInterfaceError->Core.pvUser, rc, RT_SRC_POS_ARGS, pszFormat, va);
785 DECLINLINE(int) vdThreadStartRead(PVBOXHDD pDisk)
788 if (RT_UNLIKELY(pDisk->pInterfaceThreadSync))
789 rc = pDisk->pInterfaceThreadSync->pfnStartRead(pDisk->pInterfaceThreadSync->Core.pvUser);
796 DECLINLINE(int) vdThreadFinishRead(PVBOXHDD pDisk)
799 if (RT_UNLIKELY(pDisk->pInterfaceThreadSync))
800 rc = pDisk->pInterfaceThreadSync->pfnFinishRead(pDisk->pInterfaceThreadSync->Core.pvUser);
807 DECLINLINE(int) vdThreadStartWrite(PVBOXHDD pDisk)
810 if (RT_UNLIKELY(pDisk->pInterfaceThreadSync))
811 rc = pDisk->pInterfaceThreadSync->pfnStartWrite(pDisk->pInterfaceThreadSync->Core.pvUser);
818 DECLINLINE(int) vdThreadFinishWrite(PVBOXHDD pDisk)
821 if (RT_UNLIKELY(pDisk->pInterfaceThreadSync))
822 rc = pDisk->pInterfaceThreadSync->pfnFinishWrite(pDisk->pInterfaceThreadSync->Core.pvUser);
896 static void vdAddImageToList(PVBOXHDD pDisk, PVDIMAGE pImage)
901 if (pDisk->pBase)
903 Assert(pDisk->cImages > 0);
904 pImage->pPrev = pDisk->pLast;
905 pDisk->pLast->pNext = pImage;
906 pDisk->pLast = pImage;
910 Assert(pDisk->cImages == 0);
911 pDisk->pBase = pImage;
912 pDisk->pLast = pImage;
915 pDisk->cImages++;
921 static void vdRemoveImageFromList(PVBOXHDD pDisk, PVDIMAGE pImage)
923 Assert(pDisk->cImages > 0);
928 pDisk->pBase = pImage->pNext;
933 pDisk->pLast = pImage->pPrev;
938 pDisk->cImages--;
974 static PVDIMAGE vdGetImageByNumber(PVBOXHDD pDisk, unsigned nImage)
976 PVDIMAGE pImage = pDisk->pBase;
978 return pDisk->pLast;
991 * @param pDisk The HDD container.
996 static int vdFilterChainApplyWrite(PVBOXHDD pDisk, uint64_t uOffset, size_t cbWrite,
1001 VD_IS_LOCKED(pDisk);
1004 RTListForEach(&pDisk->ListFilterChainWrite, pFilter, VDFILTER, ListNodeChainWrite)
1020 * @param pDisk The HDD container.
1025 static int vdFilterChainApplyRead(PVBOXHDD pDisk, uint64_t uOffset, size_t cbRead,
1030 VD_IS_LOCKED(pDisk);
1036 RTListForEach(&pDisk->ListFilterChainRead, pFilter, VDFILTER, ListNodeChainRead)
1048 DECLINLINE(void) vdIoCtxRootComplete(PVBOXHDD pDisk, PVDIOCTX pIoCtx)
1052 pIoCtx->rcReq = vdFilterChainApplyRead(pDisk, pIoCtx->Req.Io.uOffsetXferOrig,
1063 DECLINLINE(void) vdIoCtxInit(PVDIOCTX pIoCtx, PVBOXHDD pDisk, VDIOCTXTXDIR enmTxDir,
1068 pIoCtx->pDisk = pDisk;
1206 * @param pDisk VD disk container.
1211 static int vdDiscardRemoveBlocks(PVBOXHDD pDisk, PVDDISCARDSTATE pDiscard, size_t cbDiscardingNew)
1215 LogFlowFunc(("pDisk=%#p pDiscard=%#p cbDiscardingNew=%zu\n",
1216 pDisk, pDiscard, cbDiscardingNew));
1255 vdIoCtxInit(&IoCtx, pDisk, VDIOCTXTXDIR_DISCARD, 0, 0, NULL,
1257 rc = pDisk->pLast->Backend->pfnDiscard(pDisk->pLast->pBackendData,
1294 * @param pDisk VD disk container.
1296 static int vdDiscardStateDestroy(PVBOXHDD pDisk)
1300 if (pDisk->pDiscard)
1302 rc = vdDiscardRemoveBlocks(pDisk, pDisk->pDiscard, 0 /* Remove all blocks. */);
1304 RTMemFree(pDisk->pDiscard->pTreeBlocks);
1305 RTMemFree(pDisk->pDiscard);
1306 pDisk->pDiscard = NULL;
1318 * @param pDisk VD container data.
1322 static int vdDiscardSetRangeAllocated(PVBOXHDD pDisk, uint64_t uOffset, size_t cbRange)
1324 PVDDISCARDSTATE pDiscard = pDisk->pDiscard;
1364 DECLINLINE(PVDIOCTX) vdIoCtxAlloc(PVBOXHDD pDisk, VDIOCTXTXDIR enmTxDir,
1372 pIoCtx = (PVDIOCTX)RTMemCacheAlloc(pDisk->hMemCacheIoCtx);
1375 vdIoCtxInit(pIoCtx, pDisk, enmTxDir, uOffset, cbTransfer, pImageStart,
1382 DECLINLINE(PVDIOCTX) vdIoCtxRootAlloc(PVBOXHDD pDisk, VDIOCTXTXDIR enmTxDir,
1391 PVDIOCTX pIoCtx = vdIoCtxAlloc(pDisk, enmTxDir, uOffset, cbTransfer, pImageStart,
1406 DECLINLINE(void) vdIoCtxDiscardInit(PVDIOCTX pIoCtx, PVBOXHDD pDisk, PCRTRANGE paRanges,
1412 pIoCtx->pDisk = pDisk;
1435 DECLINLINE(PVDIOCTX) vdIoCtxDiscardAlloc(PVBOXHDD pDisk, PCRTRANGE paRanges,
1445 pIoCtx = (PVDIOCTX)RTMemCacheAlloc(pDisk->hMemCacheIoCtx);
1448 vdIoCtxDiscardInit(pIoCtx, pDisk, paRanges, cRanges, pfnComplete, pvUser1,
1456 DECLINLINE(PVDIOCTX) vdIoCtxChildAlloc(PVBOXHDD pDisk, VDIOCTXTXDIR enmTxDir,
1463 PVDIOCTX pIoCtx = vdIoCtxAlloc(pDisk, enmTxDir, uOffset, cbTransfer, pImageStart,
1486 pIoTask = (PVDIOTASK)RTMemCacheAlloc(pIoStorage->pVDIo->pDisk->hMemCacheIoTask);
1504 pIoTask = (PVDIOTASK)RTMemCacheAlloc(pIoStorage->pVDIo->pDisk->hMemCacheIoTask);
1517 DECLINLINE(void) vdIoCtxFree(PVBOXHDD pDisk, PVDIOCTX pIoCtx)
1526 memset(&pIoCtx->pDisk, 0xff, sizeof(void *));
1528 RTMemCacheFree(pDisk->hMemCacheIoCtx, pIoCtx);
1532 DECLINLINE(void) vdIoTaskFree(PVBOXHDD pDisk, PVDIOTASK pIoTask)
1537 RTMemCacheFree(pDisk->hMemCacheIoTask, pIoTask);
1584 DECLINLINE(void) vdIoCtxDefer(PVBOXHDD pDisk, PVDIOCTX pIoCtx)
1590 vdIoCtxAddToWaitingList(&pDisk->pIoCtxBlockedHead, pIoCtx);
1629 VD_IS_LOCKED(pIoCtx->pDisk);
1718 * @param pDisk The disk structure.
1723 static int vdDiskProcessWaitingIoCtx(PVBOXHDD pDisk, PVDIOCTX pIoCtxRc)
1727 LogFlowFunc(("pDisk=%#p pIoCtxRc=%#p\n", pDisk, pIoCtxRc));
1729 VD_IS_LOCKED(pDisk);
1732 PVDIOCTX pIoCtxHead = ASMAtomicXchgPtrT(&pDisk->pIoCtxHead, NULL, PVDIOCTX);
1775 int rc2 = vdFilterChainApplyRead(pDisk, pTmp->Req.Io.uOffsetXferOrig,
1792 vdThreadFinishWrite(pDisk);
1793 vdIoCtxRootComplete(pDisk, pTmp);
1794 vdIoCtxFree(pDisk, pTmp);
1806 * @param pDisk The disk structure.
1808 static void vdDiskProcessBlockedIoCtx(PVBOXHDD pDisk)
1810 LogFlowFunc(("pDisk=%#p\n", pDisk));
1812 VD_IS_LOCKED(pDisk);
1815 PVDIOCTX pIoCtxHead = ASMAtomicXchgPtrT(&pDisk->pIoCtxBlockedHead, NULL, PVDIOCTX);
1847 vdThreadFinishWrite(pDisk);
1848 vdIoCtxRootComplete(pDisk, pTmp);
1849 vdIoCtxFree(pDisk, pTmp);
1866 PVBOXHDD pDisk = pIoCtx->pDisk;
1871 vdIoCtxAddToWaitingList(&pDisk->pIoCtxHead, pIoCtx);
1873 if (ASMAtomicCmpXchgBool(&pDisk->fLocked, true, false))
1877 rc = vdDiskUnlock(pDisk, pIoCtx);
1899 PVBOXHDD pDisk = pIoCtx->pDisk;
1917 vdIoCtxFree(pDisk, pIoCtx);
1922 DECLINLINE(bool) vdIoCtxIsDiskLockOwner(PVBOXHDD pDisk, PVDIOCTX pIoCtx)
1924 return pDisk->pIoCtxLockOwner == pIoCtx;
1927 static int vdIoCtxLockDisk(PVBOXHDD pDisk, PVDIOCTX pIoCtx)
1931 VD_IS_LOCKED(pDisk);
1933 LogFlowFunc(("pDisk=%#p pIoCtx=%#p\n", pDisk, pIoCtx));
1935 if (!ASMAtomicCmpXchgPtr(&pDisk->pIoCtxLockOwner, pIoCtx, NIL_VDIOCTX))
1937 Assert(pDisk->pIoCtxLockOwner != pIoCtx); /* No nesting allowed. */
1938 vdIoCtxDefer(pDisk, pIoCtx);
1946 static void vdIoCtxUnlockDisk(PVBOXHDD pDisk, PVDIOCTX pIoCtx, bool fProcessBlockedReqs)
1948 LogFlowFunc(("pDisk=%#p pIoCtx=%#p fProcessBlockedReqs=%RTbool\n",
1949 pDisk, pIoCtx, fProcessBlockedReqs));
1951 VD_IS_LOCKED(pDisk);
1953 LogFlow(("Unlocking disk lock owner is %#p\n", pDisk->pIoCtxLockOwner));
1954 Assert(pDisk->pIoCtxLockOwner == pIoCtx);
1955 ASMAtomicXchgPtrT(&pDisk->pIoCtxLockOwner, NIL_VDIOCTX, PVDIOCTX);
1960 vdDiskProcessBlockedIoCtx(pDisk);
1969 static int vdDiskReadHelper(PVBOXHDD pDisk, PVDIMAGE pImage, PVDIMAGE pImageParentOverride,
2012 PVBOXHDD pDisk = pIoCtx->pDisk;
2025 if ( pDisk->pIoCtxLockOwner != NIL_VDIOCTX
2026 && uOffset >= pDisk->uOffsetStartLocked
2027 && uOffset < pDisk->uOffsetEndLocked
2029 || pIoCtx->pIoCtxParent != pDisk->pIoCtxLockOwner))
2032 vdIoCtxDefer(pDisk, pIoCtx);
2044 if ( pDisk->pCache
2047 rc = vdCacheReadHelper(pDisk->pCache, uOffset, cbThisRead,
2051 rc = vdDiskReadHelper(pDisk, pCurrImage, NULL, uOffset, cbThisRead,
2058 rc = vdCacheWriteHelper(pDisk->pCache, uOffset, cbThisRead,
2172 bool fLocked = ASMAtomicXchgBool(&pParentState->pDisk->fLocked, true);
2185 vdIoCtxInit(&IoCtx, pParentState->pDisk, VDIOCTXTXDIR_READ, uOffset, cbRead, pParentState->pImage,
2188 ASMAtomicXchgBool(&pParentState->pDisk->fLocked, false);
2197 * @param pDisk The disk to read from.
2217 static int vdReadHelperEx(PVBOXHDD pDisk, PVDIMAGE pImage, PVDIMAGE pImageParentOverride,
2240 vdIoCtxInit(&IoCtx, pDisk, VDIOCTXTXDIR_READ, uOffset, cbRead, pImage, &SgBuf,
2246 IoCtx.Type.Root.pvUser1 = pDisk;
2257 static int vdReadHelper(PVBOXHDD pDisk, PVDIMAGE pImage, uint64_t uOffset,
2260 return vdReadHelperEx(pDisk, pImage, NULL, uOffset, pvBuf, cbRead,
2267 static void vdResetModifiedFlag(PVBOXHDD pDisk)
2269 if (pDisk->uModified & VD_IMAGE_MODIFIED_FLAG)
2272 if (!(pDisk->uModified & VD_IMAGE_MODIFIED_DISABLE_UUID_UPDATE))
2277 pDisk->pLast->Backend->pfnSetModificationUuid(pDisk->pLast->pBackendData,
2280 if (pDisk->pCache)
2281 pDisk->pCache->Backend->pfnSetModificationUuid(pDisk->pCache->pBackendData,
2285 pDisk->uModified &= ~VD_IMAGE_MODIFIED_FLAG;
2292 static void vdSetModifiedFlag(PVBOXHDD pDisk)
2294 pDisk->uModified |= VD_IMAGE_MODIFIED_FLAG;
2295 if (pDisk->uModified & VD_IMAGE_MODIFIED_FIRST)
2297 pDisk->uModified &= ~VD_IMAGE_MODIFIED_FIRST;
2300 vdResetModifiedFlag(pDisk);
2302 if (!(pDisk->uModified & VD_IMAGE_MODIFIED_DISABLE_UUID_UPDATE))
2305 vdIoCtxInit(&IoCtx, pDisk, VDIOCTXTXDIR_FLUSH, 0, 0, NULL,
2307 pDisk->pLast->Backend->pfnFlush(pDisk->pLast->pBackendData, &IoCtx);
2316 static int vdWriteHelperEx(PVBOXHDD pDisk, PVDIMAGE pImage,
2336 vdIoCtxInit(&IoCtx, pDisk, VDIOCTXTXDIR_WRITE, uOffset, cbWrite, pImage, &SgBuf,
2343 IoCtx.Type.Root.pvUser1 = pDisk;
2356 static int vdWriteHelper(PVBOXHDD pDisk, PVDIMAGE pImage, uint64_t uOffset,
2359 return vdWriteHelperEx(pDisk, pImage, NULL, uOffset, pvBuf, cbWrite,
2523 PVBOXHDD pDisk = pIoCtx->pDisk;
2536 static int vdSetModifiedFlagAsync(PVBOXHDD pDisk, PVDIOCTX pIoCtx)
2540 VD_IS_LOCKED(pDisk);
2542 pDisk->uModified |= VD_IMAGE_MODIFIED_FLAG;
2543 if (pDisk->uModified & VD_IMAGE_MODIFIED_FIRST)
2545 rc = vdIoCtxLockDisk(pDisk, pIoCtx);
2548 pDisk->uModified &= ~VD_IMAGE_MODIFIED_FIRST;
2551 vdResetModifiedFlag(pDisk);
2553 if (!(pDisk->uModified & VD_IMAGE_MODIFIED_DISABLE_UUID_UPDATE))
2555 PVDIOCTX pIoCtxFlush = vdIoCtxChildAlloc(pDisk, VDIOCTXTXDIR_FLUSH,
2556 0, 0, pDisk->pLast,
2565 vdIoCtxUnlockDisk(pDisk, pIoCtx, false /* fProcessDeferredReqs */);
2566 vdIoCtxFree(pDisk, pIoCtxFlush);
2574 vdIoCtxFree(pDisk, pIoCtxFlush);
2722 PVBOXHDD pDisk = pIoCtx->pDisk;
2742 if (uOffset + cbThisWrite + cbPostRead > pDisk->cbSize)
2743 cbFill = uOffset + cbThisWrite + cbPostRead - pDisk->cbSize;
2892 PVBOXHDD pDisk = pIoCtx->pDisk;
2920 if (uOffset + cbThisWrite + cbPostRead > pDisk->cbSize)
2921 cbFill = uOffset + cbThisWrite + cbPostRead - pDisk->cbSize;
2957 PVBOXHDD pDisk = pIoCtx->pDisk;
2965 rc = vdFilterChainApplyWrite(pDisk, uOffset, cbWrite, pIoCtx);
2973 rc = vdSetModifiedFlagAsync(pDisk, pIoCtx);
2978 rc = vdDiscardSetRangeAllocated(pDisk, uOffset, cbWrite);
2997 if ( pDisk->pIoCtxLockOwner != NIL_VDIOCTX
2998 && uOffset >= pDisk->uOffsetStartLocked
2999 && uOffset < pDisk->uOffsetEndLocked)
3002 vdIoCtxDefer(pDisk, pIoCtx);
3015 rc = vdIoCtxLockDisk(pDisk, pIoCtx);
3030 PVDIOCTX pIoCtxWrite = vdIoCtxChildAlloc(pDisk, VDIOCTXTXDIR_WRITE,
3050 pDisk->uOffsetStartLocked = uOffset - cbPreRead;
3051 pDisk->uOffsetEndLocked = uOffset + cbThisWrite + cbPostRead;
3062 vdIoCtxUnlockDisk(pDisk, pIoCtx, false /* fProcessDeferredReqs*/ );
3063 vdIoCtxFree(pDisk, pIoCtxWrite);
3074 vdIoCtxUnlockDisk(pDisk, pIoCtx, false /* fProcessDeferredReqs*/ );
3075 vdIoCtxFree(pDisk, pIoCtxWrite);
3134 PVBOXHDD pDisk = pIoCtx->pDisk;
3137 rc = vdIoCtxLockDisk(pDisk, pIoCtx);
3141 pDisk->uOffsetStartLocked = 0;
3142 pDisk->uOffsetEndLocked = UINT64_C(0xffffffffffffffff);
3144 vdResetModifiedFlag(pDisk);
3149 && pDisk->pCache)
3151 rc = pDisk->pCache->Backend->pfnFlush(pDisk->pCache->pBackendData, pIoCtx);
3155 vdIoCtxUnlockDisk(pDisk, pIoCtx, true /* fProcessBlockedReqs */);
3162 vdIoCtxUnlockDisk(pDisk, pIoCtx, true /* fProcessBlockedReqs */);
3178 PVBOXHDD pDisk = pIoCtx->pDisk;
3179 PVDDISCARDSTATE pDiscard = pDisk->pDiscard;
3187 rc = pDisk->pLast->Backend->pfnDiscard(pDisk->pLast->pBackendData, pIoCtx,
3221 * @param pDisk VD disk container.
3226 static int vdDiscardRemoveBlocksAsync(PVBOXHDD pDisk, PVDIOCTX pIoCtx, size_t cbDiscardingNew)
3229 PVDDISCARDSTATE pDiscard = pDisk->pDiscard;
3231 LogFlowFunc(("pDisk=%#p pDiscard=%#p cbDiscardingNew=%zu\n",
3232 pDisk, pDiscard, cbDiscardingNew));
3269 rc = pDisk->pLast->Backend->pfnDiscard(pDisk->pLast->pBackendData, pIoCtx,
3315 PVBOXHDD pDisk = pIoCtx->pDisk;
3316 PVDDISCARDSTATE pDiscard = pDisk->pDiscard;
3326 rc = pDisk->pLast->Backend->pfnDiscard(pDisk->pLast->pBackendData, pIoCtx,
3352 rc = vdDiscardRemoveBlocksAsync(pDisk, pIoCtx, VD_DISCARD_REMOVE_THRESHOLD);
3389 PVBOXHDD pDisk = pIoCtx->pDisk;
3392 PVDDISCARDSTATE pDiscard = pDisk->pDiscard;
3401 vdIoCtxUnlockDisk(pDisk, pIoCtx, true /* fProcessDeferredReqs*/);
3405 if (pDisk->pIoCtxLockOwner != pIoCtx)
3406 rc = vdIoCtxLockDisk(pDisk, pIoCtx);
3414 pDisk->uOffsetStartLocked = offStart;
3415 pDisk->uOffsetEndLocked = offStart + cbDiscardLeft;
3423 pDisk->pDiscard = pDiscard;
4068 PVBOXHDD pDisk = pIoCtx->pDisk;
4071 VD_IS_LOCKED(pDisk);
4111 vdIoCtxUnlockDisk(pDisk, pIoCtxParent, false /* fProcessDeferredReqs */);
4122 vdIoCtxRootComplete(pDisk, pIoCtxParent);
4123 vdThreadFinishWrite(pDisk);
4124 vdIoCtxFree(pDisk, pIoCtxParent);
4125 vdDiskProcessBlockedIoCtx(pDisk);
4127 else if (!vdIoCtxIsDiskLockOwner(pDisk, pIoCtx))
4130 vdDiskProcessBlockedIoCtx(pDisk);
4137 vdIoCtxUnlockDisk(pDisk, pIoCtx, true /* fProcessDerredReqs */);
4138 vdThreadFinishWrite(pDisk);
4142 vdThreadFinishWrite(pDisk);
4146 vdThreadFinishRead(pDisk);
4150 vdIoCtxRootComplete(pDisk, pIoCtx);
4153 vdIoCtxFree(pDisk, pIoCtx);
4169 PVBOXHDD pDisk = pIoCtx->pDisk;
4174 VD_IS_LOCKED(pDisk);
4229 PVBOXHDD pDisk = pIoStorage->pVDIo->pDisk;
4236 VD_IS_LOCKED(pDisk);
4307 vdIoTaskFree(pDisk, pIoTask);
4343 * @param pDisk The disk to process the list for.
4345 static void vdIoTaskProcessWaitingList(PVBOXHDD pDisk)
4347 LogFlowFunc(("pDisk=%#p\n", pDisk));
4349 VD_IS_LOCKED(pDisk);
4351 PVDIOTASK pHead = ASMAtomicXchgPtrT(&pDisk->pIoTasksPendingHead, NULL, PVDIOTASK);
4380 vdIoTaskFree(pDisk, pCur);
4388 * @param pDisk The disk.
4390 static void vdIoCtxProcessHaltedList(PVBOXHDD pDisk)
4392 LogFlowFunc(("pDisk=%#p\n", pDisk));
4394 VD_IS_LOCKED(pDisk);
4397 PVDIOCTX pIoCtxHead = ASMAtomicXchgPtrT(&pDisk->pIoCtxHaltedHead, NULL, PVDIOCTX);
4429 * @param pDisk The disk to unlock.
4431 static int vdDiskUnlock(PVBOXHDD pDisk, PVDIOCTX pIoCtxRc)
4435 VD_IS_LOCKED(pDisk);
4443 vdIoTaskProcessWaitingList(pDisk);
4444 vdIoCtxProcessHaltedList(pDisk);
4445 rc = vdDiskProcessWaitingIoCtx(pDisk, pIoCtxRc);
4446 ASMAtomicXchgBool(&pDisk->fLocked, false);
4453 while ( ASMAtomicUoReadPtrT(&pDisk->pIoCtxHead, PVDIOCTX) != NULL
4454 || ASMAtomicUoReadPtrT(&pDisk->pIoTasksPendingHead, PVDIOTASK) != NULL
4455 || ASMAtomicUoReadPtrT(&pDisk->pIoCtxHaltedHead, PVDIOCTX) != NULL)
4458 if (ASMAtomicCmpXchgBool(&pDisk->fLocked, true, false))
4460 vdIoTaskProcessWaitingList(pDisk);
4461 vdIoCtxProcessHaltedList(pDisk);
4462 vdDiskProcessWaitingIoCtx(pDisk, NULL);
4463 ASMAtomicXchgBool(&pDisk->fLocked, false);
4482 PVBOXHDD pDisk = pIoStorage->pVDIo->pDisk;
4487 PVDIOTASK pNext = ASMAtomicUoReadPtrT(&pDisk->pIoTasksPendingHead, PVDIOTASK);
4490 while (!ASMAtomicCmpXchgExPtr(&pDisk->pIoTasksPendingHead, pIoTask, pNext, &pHeadOld))
4498 if (ASMAtomicCmpXchgBool(&pDisk->fLocked, true, false))
4501 vdDiskUnlock(pDisk, NULL);
4624 PVBOXHDD pDisk = pVDIo->pDisk;
4631 VD_IS_LOCKED(pDisk);
4698 vdIoTaskFree(pDisk, pIoTask);
4703 vdIoTaskFree(pDisk, pIoTask);
4722 PVBOXHDD pDisk = pVDIo->pDisk;
4729 VD_IS_LOCKED(pDisk);
4798 vdIoTaskFree(pDisk, pIoTask);
4803 vdIoTaskFree(pDisk, pIoTask);
4822 PVBOXHDD pDisk = pVDIo->pDisk;
4840 VD_IS_LOCKED(pDisk);
4896 vdIoTaskFree(pDisk, pIoTask);
4943 PVBOXHDD pDisk = pVDIo->pDisk;
4962 VD_IS_LOCKED(pDisk);
5014 vdIoTaskFree(pDisk, pIoTask);
5099 PVBOXHDD pDisk = pVDIo->pDisk;
5111 VD_IS_LOCKED(pDisk);
5135 PVBOXHDD pDisk = pVDIo->pDisk;
5152 VD_IS_LOCKED(pDisk);
5196 vdIoTaskFree(pDisk, pIoTask);
5212 PVBOXHDD pDisk = pVDIo->pDisk;
5217 VD_IS_LOCKED(pDisk);
5232 PVBOXHDD pDisk = pVDIo->pDisk;
5237 VD_IS_LOCKED(pDisk);
5251 PVBOXHDD pDisk = pVDIo->pDisk;
5256 VD_IS_LOCKED(pDisk);
5272 PVBOXHDD pDisk = pVDIo->pDisk;
5280 VD_IS_LOCKED(pDisk);
5293 PVBOXHDD pDisk = pVDIo->pDisk;
5319 vdIoCtxAddToWaitingList(&pDisk->pIoCtxHaltedHead, pIoCtx);
5320 if (ASMAtomicCmpXchgBool(&pDisk->fLocked, true, false))
5323 vdDiskUnlock(pDisk, NULL);
5348 PVBOXHDD pDisk = pVDIo->pDisk;
5350 PVDIMAGE pImage = vdGetImageByNumber(pDisk, VD_LAST_IMAGE);
5519 DECLINLINE(int) vdMessageWrapper(PVBOXHDD pDisk, const char *pszFormat, ...)
5523 int rc = pDisk->pInterfaceError->pfnMessage(pDisk->pInterfaceError->Core.pvUser,
5646 PVBOXHDD pDisk = (PVBOXHDD)pvUser1;
5964 PVBOXHDD pDisk = NULL;
5974 pDisk = (PVBOXHDD)RTMemAllocZ(sizeof(VBOXHDD));
5975 if (pDisk)
5977 pDisk->u32Signature = VBOXHDDDISK_SIGNATURE;
5978 pDisk->enmType = enmType;
5979 pDisk->cImages = 0;
5980 pDisk->pBase = NULL;
5981 pDisk->pLast = NULL;
5982 pDisk->cbSize = 0;
5983 pDisk->PCHSGeometry.cCylinders = 0;
5984 pDisk->PCHSGeometry.cHeads = 0;
5985 pDisk->PCHSGeometry.cSectors = 0;
5986 pDisk->LCHSGeometry.cCylinders = 0;
5987 pDisk->LCHSGeometry.cHeads = 0;
5988 pDisk->LCHSGeometry.cSectors = 0;
5989 pDisk->pVDIfsDisk = pVDIfsDisk;
5990 pDisk->pInterfaceError = NULL;
5991 pDisk->pInterfaceThreadSync = NULL;
5992 pDisk->pIoCtxLockOwner = NULL;
5993 pDisk->pIoCtxHead = NULL;
5994 pDisk->fLocked = false;
5995 pDisk->hMemCacheIoCtx = NIL_RTMEMCACHE;
5996 pDisk->hMemCacheIoTask = NIL_RTMEMCACHE;
5997 RTListInit(&pDisk->ListFilterChainWrite);
5998 RTListInit(&pDisk->ListFilterChainRead);
6001 rc = RTMemCacheCreate(&pDisk->hMemCacheIoCtx, sizeof(VDIOCTX), 0, UINT32_MAX,
6007 rc = RTMemCacheCreate(&pDisk->hMemCacheIoTask, sizeof(VDIOTASK), 0, UINT32_MAX,
6012 pDisk->pInterfaceError = VDIfErrorGet(pVDIfsDisk);
6013 pDisk->pInterfaceThreadSync = VDIfThreadSyncGet(pVDIfsDisk);
6015 *ppDisk = pDisk;
6025 && pDisk)
6027 if (pDisk->hMemCacheIoCtx != NIL_RTMEMCACHE)
6028 RTMemCacheDestroy(pDisk->hMemCacheIoCtx);
6029 if (pDisk->hMemCacheIoTask != NIL_RTMEMCACHE)
6030 RTMemCacheDestroy(pDisk->hMemCacheIoTask);
6033 LogFlowFunc(("returns %Rrc (pDisk=%#p)\n", rc, pDisk));
6042 * @param pDisk Pointer to HDD container.
6044 VBOXDDU_DECL(int) VDDestroy(PVBOXHDD pDisk)
6047 LogFlowFunc(("pDisk=%#p\n", pDisk));
6051 AssertPtrBreak(pDisk);
6052 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
6053 Assert(!pDisk->fLocked);
6055 rc = VDCloseAll(pDisk);
6056 int rc2 = VDFilterRemoveAll(pDisk);
6060 RTMemCacheDestroy(pDisk->hMemCacheIoCtx);
6061 RTMemCacheDestroy(pDisk->hMemCacheIoTask);
6062 RTMemFree(pDisk);
6221 * @param pDisk Pointer to HDD container.
6227 VBOXDDU_DECL(int) VDOpen(PVBOXHDD pDisk, const char *pszBackend,
6236 LogFlowFunc(("pDisk=%#p pszBackend=\"%s\" pszFilename=\"%s\" uOpenFlags=%#x, pVDIfsImage=%#p\n",
6237 pDisk, pszBackend, pszFilename, uOpenFlags, pVDIfsImage));
6242 AssertPtrBreakStmt(pDisk, rc = VERR_INVALID_PARAMETER);
6243 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
6264 /* Lock disk for writing, as we modify pDisk information below. */
6265 rc2 = vdThreadStartWrite(pDisk);
6268 rc = vdDiscardStateDestroy(pDisk);
6271 rc2 = vdThreadFinishWrite(pDisk);
6289 pImage->VDIo.pDisk = pDisk;
6297 rc = vdError(pDisk, VERR_INVALID_PARAMETER, RT_SRC_POS,
6309 rc = vdError(pDisk, VERR_NOT_SUPPORTED, RT_SRC_POS,
6321 rc = vdError(pDisk, VERR_VD_DISCARD_NOT_SUPPORTED, RT_SRC_POS,
6332 pDisk, sizeof(VDINTERFACEIO), &pVDIfsImage);
6347 pDisk->pVDIfsDisk,
6349 pDisk->enmType,
6359 rc = pImage->Backend->pfnRepair(pszFilename, pDisk->pVDIfsDisk, pImage->pVDIfsImage, 0 /* fFlags */);
6363 pDisk->pVDIfsDisk,
6365 pDisk->enmType,
6369 rc = vdError(pDisk, rc, RT_SRC_POS,
6376 rc = vdError(pDisk, rc, RT_SRC_POS,
6393 pDisk->pVDIfsDisk,
6395 pDisk->enmType,
6399 rc = vdError(pDisk, rc, RT_SRC_POS,
6405 /* Lock disk for writing, as we modify pDisk information below. */
6406 rc2 = vdThreadStartWrite(pDisk);
6424 if ( pDisk->cImages == 0
6430 else if (pDisk->cImages != 0)
6461 pDisk->cbSize = pImage->Backend->pfnGetSize(pImage->pBackendData);
6465 &pDisk->PCHSGeometry);
6468 pDisk->PCHSGeometry.cCylinders = 0;
6469 pDisk->PCHSGeometry.cHeads = 0;
6470 pDisk->PCHSGeometry.cSectors = 0;
6475 pDisk->PCHSGeometry.cCylinders = RT_MIN(pDisk->PCHSGeometry.cCylinders, 16383);
6476 pDisk->PCHSGeometry.cHeads = RT_MIN(pDisk->PCHSGeometry.cHeads, 16);
6477 pDisk->PCHSGeometry.cSectors = RT_MIN(pDisk->PCHSGeometry.cSectors, 63);
6482 &pDisk->LCHSGeometry);
6485 pDisk->LCHSGeometry.cCylinders = 0;
6486 pDisk->LCHSGeometry.cHeads = 0;
6487 pDisk->LCHSGeometry.cSectors = 0;
6492 pDisk->LCHSGeometry.cHeads = RT_MIN(pDisk->LCHSGeometry.cHeads, 255);
6493 pDisk->LCHSGeometry.cSectors = RT_MIN(pDisk->LCHSGeometry.cSectors, 63);
6496 if (pDisk->cImages != 0)
6500 uOpenFlagsPrevImg = pDisk->pLast->Backend->pfnGetOpenFlags(pDisk->pLast->pBackendData);
6504 rc = pDisk->pLast->Backend->pfnSetOpenFlags(pDisk->pLast->pBackendData, uOpenFlagsPrevImg);
6511 vdAddImageToList(pDisk, pImage);
6513 pDisk->uModified = VD_IMAGE_MODIFIED_FIRST;
6526 rc2 = vdThreadFinishWrite(pDisk);
6548 * @param pDisk Pointer to the HDD container which should use the cache image.
6554 VBOXDDU_DECL(int) VDCacheOpen(PVBOXHDD pDisk, const char *pszBackend,
6563 LogFlowFunc(("pDisk=%#p pszBackend=\"%s\" pszFilename=\"%s\" uOpenFlags=%#x, pVDIfsCache=%#p\n",
6564 pDisk, pszBackend, pszFilename, uOpenFlags, pVDIfsCache));
6569 AssertPtrBreakStmt(pDisk, rc = VERR_INVALID_PARAMETER);
6570 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
6597 pCache->VDIo.pDisk = pDisk;
6605 rc = vdError(pDisk, VERR_INVALID_PARAMETER, RT_SRC_POS,
6616 pDisk, sizeof(VDINTERFACEIO), &pVDIfsCache);
6630 pDisk->pVDIfsDisk,
6645 pDisk->pVDIfsDisk,
6650 rc = vdError(pDisk, rc, RT_SRC_POS,
6656 /* Lock disk for writing, as we modify pDisk information below. */
6657 rc2 = vdThreadStartWrite(pDisk);
6672 rc = pDisk->pLast->Backend->pfnGetModificationUuid(pDisk->pLast->pBackendData,
6691 if (!pDisk->pCache)
6692 pDisk->pCache = pCache;
6708 rc2 = vdThreadFinishWrite(pDisk);
6726 VBOXDDU_DECL(int) VDFilterAdd(PVBOXHDD pDisk, const char *pszFilter, uint32_t fFlags,
6734 LogFlowFunc(("pDisk=%#p pszFilter=\"%s\" pVDIfsFilter=%#p\n",
6735 pDisk, pszFilter, pVDIfsFilter));
6740 AssertPtrBreakStmt(pDisk, rc = VERR_INVALID_PARAMETER);
6741 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
6765 rc = vdError(pDisk, VERR_INVALID_PARAMETER, RT_SRC_POS,
6770 pFilter->VDIo.pDisk = pDisk;
6780 rc = pFilter->pBackend->pfnCreate(pDisk->pVDIfsDisk, fFlags & VD_FILTER_FLAGS_INFO,
6785 /* Lock disk for writing, as we modify pDisk information below. */
6786 rc2 = vdThreadStartWrite(pDisk);
6793 RTListAppend(&pDisk->ListFilterChainWrite, &pFilter->ListNodeChainWrite);
6799 RTListAppend(&pDisk->ListFilterChainRead, &pFilter->ListNodeChainRead);
6806 rc2 = vdThreadFinishWrite(pDisk);
6824 * @param pDisk Pointer to HDD container.
6837 VBOXDDU_DECL(int) VDCreateBase(PVBOXHDD pDisk, const char *pszBackend,
6852 LogFlowFunc(("pDisk=%#p pszBackend=\"%s\" pszFilename=\"%s\" cbSize=%llu uImageFlags=%#x pszComment=\"%s\" PCHS=%u/%u/%u LCHS=%u/%u/%u Uuid=%RTuuid uOpenFlags=%#x pVDIfsImage=%#p pVDIfsOperation=%#p\n",
6853 pDisk, pszBackend, pszFilename, cbSize, uImageFlags, pszComment,
6864 AssertPtrBreakStmt(pDisk, rc = VERR_INVALID_PARAMETER);
6865 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
6907 rc2 = vdThreadStartRead(pDisk);
6910 AssertMsgBreakStmt(pDisk->cImages == 0,
6913 rc2 = vdThreadFinishRead(pDisk);
6930 pImage->VDIo.pDisk = pDisk;
6939 pDisk, sizeof(VDINTERFACEIO), &pVDIfsImage);
6955 rc = vdError(pDisk, VERR_INVALID_PARAMETER, RT_SRC_POS,
6962 rc = vdError(pDisk, VERR_INVALID_PARAMETER, RT_SRC_POS,
6973 rc = vdError(pDisk, rc, RT_SRC_POS,
6989 pDisk->pVDIfsDisk,
6992 pDisk->enmType,
7005 /* Lock disk for writing, as we modify pDisk information below. */
7006 rc2 = vdThreadStartWrite(pDisk);
7014 AssertMsgStmt(pDisk->cImages == 0,
7022 pDisk->cbSize = pImage->Backend->pfnGetSize(pImage->pBackendData);
7026 &pDisk->PCHSGeometry);
7029 pDisk->PCHSGeometry.cCylinders = 0;
7030 pDisk->PCHSGeometry.cHeads = 0;
7031 pDisk->PCHSGeometry.cSectors = 0;
7036 pDisk->PCHSGeometry.cCylinders = RT_MIN(pDisk->PCHSGeometry.cCylinders, 16383);
7037 pDisk->PCHSGeometry.cHeads = RT_MIN(pDisk->PCHSGeometry.cHeads, 16);
7038 pDisk->PCHSGeometry.cSectors = RT_MIN(pDisk->PCHSGeometry.cSectors, 63);
7043 &pDisk->LCHSGeometry);
7046 pDisk->LCHSGeometry.cCylinders = 0;
7047 pDisk->LCHSGeometry.cHeads = 0;
7048 pDisk->LCHSGeometry.cSectors = 0;
7053 pDisk->LCHSGeometry.cHeads = RT_MIN(pDisk->LCHSGeometry.cHeads, 255);
7054 pDisk->LCHSGeometry.cSectors = RT_MIN(pDisk->LCHSGeometry.cSectors, 63);
7058 vdAddImageToList(pDisk, pImage);
7060 pDisk->uModified = VD_IMAGE_MODIFIED_FIRST;
7077 rc2 = vdThreadFinishWrite(pDisk);
7082 rc2 = vdThreadFinishRead(pDisk);
7108 * @param pDisk Pointer to HDD container.
7119 VBOXDDU_DECL(int) VDCreateDiff(PVBOXHDD pDisk, const char *pszBackend,
7132 LogFlowFunc(("pDisk=%#p pszBackend=\"%s\" pszFilename=\"%s\" uImageFlags=%#x pszComment=\"%s\" Uuid=%RTuuid uOpenFlags=%#x pVDIfsImage=%#p pVDIfsOperation=%#p\n",
7133 pDisk, pszBackend, pszFilename, uImageFlags, pszComment, pUuid, uOpenFlags, pVDIfsImage, pVDIfsOperation));
7140 AssertPtrBreakStmt(pDisk, rc = VERR_INVALID_PARAMETER);
7141 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
7167 rc2 = vdThreadStartRead(pDisk);
7170 AssertMsgBreakStmt(pDisk->cImages != 0,
7173 rc2 = vdThreadFinishRead(pDisk);
7181 /* Lock disk for writing, as we modify pDisk information below. */
7182 rc2 = vdThreadStartWrite(pDisk);
7185 rc = vdDiscardStateDestroy(pDisk);
7188 rc2 = vdThreadFinishWrite(pDisk);
7211 rc = vdError(pDisk, VERR_INVALID_PARAMETER, RT_SRC_POS,
7219 rc = vdError(pDisk, VERR_INVALID_PARAMETER, RT_SRC_POS,
7224 pImage->VDIo.pDisk = pDisk;
7233 pDisk, sizeof(VDINTERFACEIO), &pVDIfsImage);
7250 rc = vdError(pDisk, rc, RT_SRC_POS,
7261 rc = pImage->Backend->pfnCreate(pImage->pszFilename, pDisk->cbSize,
7263 pszComment, &pDisk->PCHSGeometry,
7264 &pDisk->LCHSGeometry, pUuid,
7267 pDisk->pVDIfsDisk,
7270 pDisk->enmType,
7278 /* Lock disk for writing, as we modify pDisk information below. */
7279 rc2 = vdThreadStartWrite(pDisk);
7285 uOpenFlagsPrevImg = pDisk->pLast->Backend->pfnGetOpenFlags(pDisk->pLast->pBackendData);
7289 rc = pDisk->pLast->Backend->pfnSetOpenFlags(pDisk->pLast->pBackendData, uOpenFlagsPrevImg);
7296 AssertMsgStmt(pDisk->cImages != 0,
7313 rc2 = pDisk->pLast->Backend->pfnGetUuid(pDisk->pLast->pBackendData,
7318 rc2 = pDisk->pLast->Backend->pfnGetModificationUuid(pDisk->pLast->pBackendData,
7323 if (pDisk->pLast->Backend->pfnGetTimeStamp)
7324 rc2 = pDisk->pLast->Backend->pfnGetTimeStamp(pDisk->pLast->pBackendData,
7332 rc2 = pImage->Backend->pfnSetParentFilename(pImage->pBackendData, pDisk->pLast->pszFilename);
7338 vdAddImageToList(pDisk, pImage);
7340 pDisk->uModified = VD_IMAGE_MODIFIED_FIRST;
7353 rc2 = vdThreadFinishWrite(pDisk);
7358 rc2 = vdThreadFinishRead(pDisk);
7384 * @param pDisk Name of the cache file backend to use (case insensitive).
7394 VBOXDDU_DECL(int) VDCreateCache(PVBOXHDD pDisk, const char *pszBackend,
7406 LogFlowFunc(("pDisk=%#p pszBackend=\"%s\" pszFilename=\"%s\" cbSize=%llu uImageFlags=%#x pszComment=\"%s\" Uuid=%RTuuid uOpenFlags=%#x pVDIfsImage=%#p pVDIfsOperation=%#p\n",
7407 pDisk, pszBackend, pszFilename, cbSize, uImageFlags, pszComment, pUuid, uOpenFlags, pVDIfsCache, pVDIfsOperation));
7414 AssertPtrBreakStmt(pDisk, rc = VERR_INVALID_PARAMETER);
7415 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
7440 rc2 = vdThreadStartRead(pDisk);
7443 AssertMsgBreakStmt(!pDisk->pCache,
7446 rc2 = vdThreadFinishRead(pDisk);
7469 rc = vdError(pDisk, VERR_INVALID_PARAMETER, RT_SRC_POS,
7474 pCache->VDIo.pDisk = pDisk;
7483 pDisk, sizeof(VDINTERFACEIO), &pVDIfsCache);
7500 rc = vdError(pDisk, rc, RT_SRC_POS,
7515 pDisk->pVDIfsDisk,
7522 /* Lock disk for writing, as we modify pDisk information below. */
7523 rc2 = vdThreadStartWrite(pDisk);
7531 AssertMsgStmt(!pDisk->pCache,
7537 && pDisk->pLast)
7542 rc = pDisk->pLast->Backend->pfnGetModificationUuid(pDisk->pLast->pBackendData,
7557 pDisk->pCache = pCache;
7570 rc2 = vdThreadFinishWrite(pDisk);
7575 rc2 = vdThreadFinishRead(pDisk);
7604 * @param pDisk Pointer to HDD container.
7609 VBOXDDU_DECL(int) VDMerge(PVBOXHDD pDisk, unsigned nImageFrom,
7617 LogFlowFunc(("pDisk=%#p nImageFrom=%u nImageTo=%u pVDIfsOperation=%#p\n",
7618 pDisk, nImageFrom, nImageTo, pVDIfsOperation));
7625 AssertPtrBreakStmt(pDisk, rc = VERR_INVALID_PARAMETER);
7626 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
7630 rc2 = vdThreadStartWrite(pDisk);
7633 PVDIMAGE pImageFrom = vdGetImageByNumber(pDisk, nImageFrom);
7634 PVDIMAGE pImageTo = vdGetImageByNumber(pDisk, nImageTo);
7659 rc2 = vdThreadFinishWrite(pDisk);
7690 vdIoCtxInit(&IoCtx, pDisk, VDIOCTXTXDIR_READ, 0, 0, NULL,
7694 rc2 = vdThreadStartWrite(pDisk);
7721 rc = vdWriteHelperEx(pDisk, pImageTo, pImageFrom->pPrev,
7733 rc2 = vdThreadFinishWrite(pDisk);
7766 rc2 = vdThreadStartWrite(pDisk);
7782 rc2 = vdThreadFinishWrite(pDisk);
7793 rc2 = vdThreadStartWrite(pDisk);
7797 pDisk->pImageRelay = pImageTo;
7799 rc2 = vdThreadFinishWrite(pDisk);
7821 vdIoCtxInit(&IoCtx, pDisk, VDIOCTXTXDIR_READ, 0, 0, NULL,
7825 rc2 = vdThreadStartWrite(pDisk);
7846 rc = vdWriteHelper(pDisk, pImageTo, uOffset, pvBuf,
7854 rc2 = vdThreadFinishWrite(pDisk);
7878 rc2 = vdThreadStartWrite(pDisk);
7882 pDisk->pImageRelay = NULL;
7884 rc2 = vdThreadFinishWrite(pDisk);
7898 rc2 = vdThreadStartWrite(pDisk);
7963 vdRemoveImageFromList(pDisk, pImg);
7971 if (pImageTo != pDisk->pLast)
7988 && pImageChild != pDisk->pLast)
8001 rc2 = vdThreadFinishWrite(pDisk);
8006 rc2 = vdThreadFinishRead(pDisk);
8416 * @param pDisk Pointer to HDD container.
8420 VBOXDDU_DECL(int) VDCompact(PVBOXHDD pDisk, unsigned nImage,
8429 LogFlowFunc(("pDisk=%#p nImage=%u pVDIfsOperation=%#p\n",
8430 pDisk, nImage, pVDIfsOperation));
8436 AssertMsgBreakStmt(VALID_PTR(pDisk), ("pDisk=%#p\n", pDisk),
8438 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE,
8439 ("u32Signature=%08x\n", pDisk->u32Signature));
8441 rc2 = vdThreadStartRead(pDisk);
8445 PVDIMAGE pImage = vdGetImageByNumber(pDisk, nImage);
8467 ParentUser.pDisk = pDisk;
8474 rc2 = vdThreadFinishRead(pDisk);
8478 rc2 = vdThreadStartWrite(pDisk);
8484 pDisk->pVDIfsDisk,
8491 rc2 = vdThreadFinishWrite(pDisk);
8496 rc2 = vdThreadFinishRead(pDisk);
8522 * @param pDisk Pointer to the HDD container.
8528 VBOXDDU_DECL(int) VDResize(PVBOXHDD pDisk, uint64_t cbSize,
8538 LogFlowFunc(("pDisk=%#p cbSize=%llu pVDIfsOperation=%#p\n",
8539 pDisk, cbSize, pVDIfsOperation));
8545 AssertMsgBreakStmt(VALID_PTR(pDisk), ("pDisk=%#p\n", pDisk),
8547 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE,
8548 ("u32Signature=%08x\n", pDisk->u32Signature));
8550 rc2 = vdThreadStartRead(pDisk);
8555 AssertMsgBreakStmt(pDisk->cImages >= 1, ("cImages=%u\n", pDisk->cImages),
8558 PVDIMAGE pImage = pDisk->pLast;
8572 rc2 = vdThreadFinishRead(pDisk);
8576 rc2 = vdThreadStartWrite(pDisk);
8619 pDisk->pVDIfsDisk,
8626 rc2 = vdThreadFinishWrite(pDisk);
8631 rc2 = vdThreadFinishRead(pDisk);
8640 pDisk->cbSize = cbSize;
8647 VBOXDDU_DECL(int) VDPrepareWithFilters(PVBOXHDD pDisk, PVDINTERFACE pVDIfsOperation)
8653 LogFlowFunc(("pDisk=%#p pVDIfsOperation=%#p\n", pDisk, pVDIfsOperation));
8659 AssertMsgBreakStmt(VALID_PTR(pDisk), ("pDisk=%#p\n", pDisk),
8661 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE,
8662 ("u32Signature=%08x\n", pDisk->u32Signature));
8664 rc2 = vdThreadStartRead(pDisk);
8669 AssertMsgBreakStmt(pDisk->cImages >= 1, ("cImages=%u\n", pDisk->cImages),
8672 unsigned uOpenFlags = pDisk->pLast->Backend->pfnGetOpenFlags(pDisk->pLast->pBackendData);
8677 rc2 = vdThreadFinishRead(pDisk);
8681 rc2 = vdThreadStartWrite(pDisk);
8689 PVDIMAGE pImage = pDisk->pBase;
8712 unsigned uPercentSpan = 100 / pDisk->cImages - 1;
8722 pImage = pDisk->pBase;
8723 pDisk->fLocked = true;
8745 vdIoCtxInit(&IoCtx, pDisk, VDIOCTXTXDIR_READ, 0, 0, NULL,
8756 rc = vdFilterChainApplyRead(pDisk, uOffset, cbThisRead, &IoCtx);
8760 rc = vdFilterChainApplyWrite(pDisk, uOffset, cbThisRead, &IoCtx);
8795 pDisk->fLocked = false;
8801 pImage = pDisk->pBase;
8802 while ( pImage != pDisk->pLast
8820 rc2 = vdThreadFinishWrite(pDisk);
8825 rc2 = vdThreadFinishRead(pDisk);
8846 * @param pDisk Pointer to HDD container.
8849 VBOXDDU_DECL(int) VDClose(PVBOXHDD pDisk, bool fDelete)
8855 LogFlowFunc(("pDisk=%#p fDelete=%d\n", pDisk, fDelete));
8859 AssertPtrBreakStmt(pDisk, rc = VERR_INVALID_PARAMETER);
8860 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
8865 rc2 = vdThreadStartWrite(pDisk);
8869 PVDIMAGE pImage = pDisk->pLast;
8877 rc = vdDiscardStateDestroy(pDisk);
8883 vdRemoveImageFromList(pDisk, pImage);
8890 pImage = pDisk->pLast;
8905 pDisk->cbSize = pImage->Backend->pfnGetSize(pImage->pBackendData);
8909 &pDisk->PCHSGeometry);
8912 pDisk->PCHSGeometry.cCylinders = 0;
8913 pDisk->PCHSGeometry.cHeads = 0;
8914 pDisk->PCHSGeometry.cSectors = 0;
8919 pDisk->PCHSGeometry.cCylinders = RT_MIN(pDisk->PCHSGeometry.cCylinders, 16383);
8920 pDisk->PCHSGeometry.cHeads = RT_MIN(pDisk->PCHSGeometry.cHeads, 16);
8921 pDisk->PCHSGeometry.cSectors = RT_MIN(pDisk->PCHSGeometry.cSectors, 63);
8926 &pDisk->LCHSGeometry);
8929 pDisk->LCHSGeometry.cCylinders = 0;
8930 pDisk->LCHSGeometry.cHeads = 0;
8931 pDisk->LCHSGeometry.cSectors = 0;
8936 pDisk->LCHSGeometry.cHeads = RT_MIN(pDisk->LCHSGeometry.cHeads, 255);
8937 pDisk->LCHSGeometry.cSectors = RT_MIN(pDisk->LCHSGeometry.cSectors, 63);
8943 rc2 = vdThreadFinishWrite(pDisk);
8956 * @param pDisk Pointer to HDD container.
8959 VBOXDDU_DECL(int) VDCacheClose(PVBOXHDD pDisk, bool fDelete)
8966 LogFlowFunc(("pDisk=%#p fDelete=%d\n", pDisk, fDelete));
8971 AssertPtrBreakStmt(pDisk, rc = VERR_INVALID_PARAMETER);
8972 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
8974 rc2 = vdThreadStartWrite(pDisk);
8978 AssertPtrBreakStmt(pDisk->pCache, rc = VERR_VD_CACHE_NOT_FOUND);
8980 pCache = pDisk->pCache;
8981 pDisk->pCache = NULL;
8991 rc2 = vdThreadFinishWrite(pDisk);
8999 VBOXDDU_DECL(int) VDFilterRemove(PVBOXHDD pDisk, uint32_t fFlags)
9006 LogFlowFunc(("pDisk=%#p\n", pDisk));
9011 AssertPtrBreakStmt(pDisk, rc = VERR_INVALID_PARAMETER);
9012 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
9018 rc2 = vdThreadStartWrite(pDisk);
9024 AssertBreakStmt(!RTListIsEmpty(&pDisk->ListFilterChainWrite), rc = VERR_VD_NOT_OPENED);
9025 pFilter = RTListGetLast(&pDisk->ListFilterChainWrite, VDFILTER, ListNodeChainWrite);
9033 AssertBreakStmt(!RTListIsEmpty(&pDisk->ListFilterChainRead), rc = VERR_VD_NOT_OPENED);
9034 pFilter = RTListGetLast(&pDisk->ListFilterChainRead, VDFILTER, ListNodeChainRead);
9043 rc2 = vdThreadFinishWrite(pDisk);
9055 * @param pDisk Pointer to HDD container.
9057 VBOXDDU_DECL(int) VDCloseAll(PVBOXHDD pDisk)
9063 LogFlowFunc(("pDisk=%#p\n", pDisk));
9067 AssertPtrBreakStmt(pDisk, rc = VERR_INVALID_PARAMETER);
9068 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
9071 rc2 = vdThreadStartWrite(pDisk);
9075 PVDCACHE pCache = pDisk->pCache;
9087 PVDIMAGE pImage = pDisk->pLast;
9092 vdRemoveImageFromList(pDisk, pImage);
9102 Assert(!VALID_PTR(pDisk->pLast));
9107 rc2 = vdThreadFinishWrite(pDisk);
9119 * @param pDisk Pointer to HDD container.
9121 VBOXDDU_DECL(int) VDFilterRemoveAll(PVBOXHDD pDisk)
9127 LogFlowFunc(("pDisk=%#p\n", pDisk));
9131 AssertPtrBreakStmt(pDisk, rc = VERR_INVALID_PARAMETER);
9132 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
9135 rc2 = vdThreadStartWrite(pDisk);
9140 RTListForEachSafe(&pDisk->ListFilterChainWrite, pFilter, pFilterNext, VDFILTER, ListNodeChainWrite)
9146 RTListForEachSafe(&pDisk->ListFilterChainRead, pFilter, pFilterNext, VDFILTER, ListNodeChainRead)
9151 Assert(RTListIsEmpty(&pDisk->ListFilterChainRead));
9152 Assert(RTListIsEmpty(&pDisk->ListFilterChainWrite));
9157 rc2 = vdThreadFinishWrite(pDisk);
9170 * @param pDisk Pointer to HDD container.
9175 VBOXDDU_DECL(int) VDRead(PVBOXHDD pDisk, uint64_t uOffset, void *pvBuf,
9182 LogFlowFunc(("pDisk=%#p uOffset=%llu pvBuf=%p cbRead=%zu\n",
9183 pDisk, uOffset, pvBuf, cbRead));
9187 AssertPtrBreakStmt(pDisk, rc = VERR_INVALID_PARAMETER);
9188 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
9198 rc2 = vdThreadStartRead(pDisk);
9202 PVDIMAGE pImage = pDisk->pLast;
9205 if (uOffset + cbRead > pDisk->cbSize)
9209 AssertMsgBreakStmt(pDisk->enmType == VDTYPE_FLOPPY,
9210 ("uOffset=%llu cbRead=%zu pDisk->cbSize=%llu\n",
9211 uOffset, cbRead, pDisk->cbSize),
9214 if (uOffset >= pDisk->cbSize)
9216 cbRead = pDisk->cbSize - uOffset;
9219 rc = vdReadHelper(pDisk, pImage, uOffset, pvBuf, cbRead,
9225 rc2 = vdThreadFinishRead(pDisk);
9238 * @param pDisk Pointer to HDD container.
9244 VBOXDDU_DECL(int) VDWrite(PVBOXHDD pDisk, uint64_t uOffset, const void *pvBuf,
9251 LogFlowFunc(("pDisk=%#p uOffset=%llu pvBuf=%p cbWrite=%zu\n",
9252 pDisk, uOffset, pvBuf, cbWrite));
9256 AssertPtrBreakStmt(pDisk, rc = VERR_INVALID_PARAMETER);
9257 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
9267 rc2 = vdThreadStartWrite(pDisk);
9271 AssertMsgBreakStmt(uOffset + cbWrite <= pDisk->cbSize,
9272 ("uOffset=%llu cbWrite=%zu pDisk->cbSize=%llu\n",
9273 uOffset, cbWrite, pDisk->cbSize),
9276 PVDIMAGE pImage = pDisk->pLast;
9279 vdSetModifiedFlag(pDisk);
9280 rc = vdWriteHelper(pDisk, pImage, uOffset, pvBuf, cbWrite,
9293 if (RT_UNLIKELY(pDisk->pImageRelay))
9294 rc = vdWriteHelper(pDisk, pDisk->pImageRelay, uOffset,
9300 rc2 = vdThreadFinishWrite(pDisk);
9313 * @param pDisk Pointer to HDD container.
9315 VBOXDDU_DECL(int) VDFlush(PVBOXHDD pDisk)
9321 LogFlowFunc(("pDisk=%#p\n", pDisk));
9325 AssertPtrBreakStmt(pDisk, rc = VERR_INVALID_PARAMETER);
9326 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
9328 rc2 = vdThreadStartWrite(pDisk);
9332 PVDIMAGE pImage = pDisk->pLast;
9342 vdIoCtxInit(&IoCtx, pDisk, VDIOCTXTXDIR_FLUSH, 0, 0, pImage, NULL,
9346 IoCtx.Type.Root.pvUser1 = pDisk;
9355 rc2 = vdThreadFinishWrite(pDisk);
9367 * @param pDisk Pointer to HDD container.
9369 VBOXDDU_DECL(unsigned) VDGetCount(PVBOXHDD pDisk)
9375 LogFlowFunc(("pDisk=%#p\n", pDisk));
9379 AssertPtrBreakStmt(pDisk, cImages = 0);
9380 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
9382 rc2 = vdThreadStartRead(pDisk);
9386 cImages = pDisk->cImages;
9391 rc2 = vdThreadFinishRead(pDisk);
9404 * @param pDisk Pointer to HDD container.
9406 VBOXDDU_DECL(bool) VDIsReadOnly(PVBOXHDD pDisk)
9412 LogFlowFunc(("pDisk=%#p\n", pDisk));
9416 AssertPtrBreakStmt(pDisk, fReadOnly = false);
9417 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
9419 rc2 = vdThreadStartRead(pDisk);
9423 PVDIMAGE pImage = pDisk->pLast;
9427 uOpenFlags = pDisk->pLast->Backend->pfnGetOpenFlags(pDisk->pLast->pBackendData);
9433 rc2 = vdThreadFinishRead(pDisk);
9446 * @param pDisk Pointer to HDD container.
9449 VBOXDDU_DECL(uint32_t) VDGetSectorSize(PVBOXHDD pDisk, unsigned nImage)
9455 LogFlowFunc(("pDisk=%#p nImage=%u\n", pDisk, nImage));
9459 AssertPtrBreakStmt(pDisk, cbSector = 0);
9460 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
9462 rc2 = vdThreadStartRead(pDisk);
9466 PVDIMAGE pImage = vdGetImageByNumber(pDisk, nImage);
9473 rc2 = vdThreadFinishRead(pDisk);
9486 * @param pDisk Pointer to HDD container.
9489 VBOXDDU_DECL(uint64_t) VDGetSize(PVBOXHDD pDisk, unsigned nImage)
9495 LogFlowFunc(("pDisk=%#p nImage=%u\n", pDisk, nImage));
9499 AssertPtrBreakStmt(pDisk, cbSize = 0);
9500 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
9502 rc2 = vdThreadStartRead(pDisk);
9506 PVDIMAGE pImage = vdGetImageByNumber(pDisk, nImage);
9513 rc2 = vdThreadFinishRead(pDisk);
9526 * @param pDisk Pointer to HDD container.
9529 VBOXDDU_DECL(uint64_t) VDGetFileSize(PVBOXHDD pDisk, unsigned nImage)
9535 LogFlowFunc(("pDisk=%#p nImage=%u\n", pDisk, nImage));
9539 AssertPtrBreakStmt(pDisk, cbSize = 0);
9540 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
9542 rc2 = vdThreadStartRead(pDisk);
9546 PVDIMAGE pImage = vdGetImageByNumber(pDisk, nImage);
9553 rc2 = vdThreadFinishRead(pDisk);
9567 * @param pDisk Pointer to HDD container.
9571 VBOXDDU_DECL(int) VDGetPCHSGeometry(PVBOXHDD pDisk, unsigned nImage,
9578 LogFlowFunc(("pDisk=%#p nImage=%u pPCHSGeometry=%#p\n",
9579 pDisk, nImage, pPCHSGeometry));
9583 AssertPtrBreakStmt(pDisk, rc = VERR_INVALID_PARAMETER);
9584 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
9591 rc2 = vdThreadStartRead(pDisk);
9595 PVDIMAGE pImage = vdGetImageByNumber(pDisk, nImage);
9598 if (pImage == pDisk->pLast)
9601 if (pDisk->PCHSGeometry.cCylinders != 0)
9602 *pPCHSGeometry = pDisk->PCHSGeometry;
9613 rc2 = vdThreadFinishRead(pDisk);
9618 pDisk->PCHSGeometry.cCylinders, pDisk->PCHSGeometry.cHeads,
9619 pDisk->PCHSGeometry.cSectors));
9631 * @param pDisk Pointer to HDD container.
9635 VBOXDDU_DECL(int) VDSetPCHSGeometry(PVBOXHDD pDisk, unsigned nImage,
9642 LogFlowFunc(("pDisk=%#p nImage=%u pPCHSGeometry=%#p PCHS=%u/%u/%u\n",
9643 pDisk, nImage, pPCHSGeometry, pPCHSGeometry->cCylinders,
9648 AssertPtrBreakStmt(pDisk, rc = VERR_INVALID_PARAMETER);
9649 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
9660 rc2 = vdThreadStartWrite(pDisk);
9664 PVDIMAGE pImage = vdGetImageByNumber(pDisk, nImage);
9667 if (pImage == pDisk->pLast)
9669 if ( pPCHSGeometry->cCylinders != pDisk->PCHSGeometry.cCylinders
9670 || pPCHSGeometry->cHeads != pDisk->PCHSGeometry.cHeads
9671 || pPCHSGeometry->cSectors != pDisk->PCHSGeometry.cSectors)
9683 &pDisk->PCHSGeometry);
9686 pDisk->PCHSGeometry.cCylinders = 0;
9687 pDisk->PCHSGeometry.cHeads = 0;
9688 pDisk->PCHSGeometry.cSectors = 0;
9693 pDisk->PCHSGeometry.cHeads = RT_MIN(pDisk->PCHSGeometry.cHeads, 255);
9694 pDisk->PCHSGeometry.cSectors = RT_MIN(pDisk->PCHSGeometry.cSectors, 63);
9721 rc2 = vdThreadFinishWrite(pDisk);
9735 * @param pDisk Pointer to HDD container.
9739 VBOXDDU_DECL(int) VDGetLCHSGeometry(PVBOXHDD pDisk, unsigned nImage,
9746 LogFlowFunc(("pDisk=%#p nImage=%u pLCHSGeometry=%#p\n",
9747 pDisk, nImage, pLCHSGeometry));
9751 AssertPtrBreakStmt(pDisk, rc = VERR_INVALID_PARAMETER);
9752 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
9759 rc2 = vdThreadStartRead(pDisk);
9763 PVDIMAGE pImage = vdGetImageByNumber(pDisk, nImage);
9766 if (pImage == pDisk->pLast)
9769 if (pDisk->LCHSGeometry.cCylinders != 0)
9770 *pLCHSGeometry = pDisk->LCHSGeometry;
9781 rc2 = vdThreadFinishRead(pDisk);
9786 pDisk->LCHSGeometry.cCylinders, pDisk->LCHSGeometry.cHeads,
9787 pDisk->LCHSGeometry.cSectors));
9799 * @param pDisk Pointer to HDD container.
9803 VBOXDDU_DECL(int) VDSetLCHSGeometry(PVBOXHDD pDisk, unsigned nImage,
9810 LogFlowFunc(("pDisk=%#p nImage=%u pLCHSGeometry=%#p LCHS=%u/%u/%u\n",
9811 pDisk, nImage, pLCHSGeometry, pLCHSGeometry->cCylinders,
9816 AssertPtrBreakStmt(pDisk, rc = VERR_INVALID_PARAMETER);
9817 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
9828 rc2 = vdThreadStartWrite(pDisk);
9832 PVDIMAGE pImage = vdGetImageByNumber(pDisk, nImage);
9835 if (pImage == pDisk->pLast)
9837 if ( pLCHSGeometry->cCylinders != pDisk->LCHSGeometry.cCylinders
9838 || pLCHSGeometry->cHeads != pDisk->LCHSGeometry.cHeads
9839 || pLCHSGeometry->cSectors != pDisk->LCHSGeometry.cSectors)
9851 &pDisk->LCHSGeometry);
9854 pDisk->LCHSGeometry.cCylinders = 0;
9855 pDisk->LCHSGeometry.cHeads = 0;
9856 pDisk->LCHSGeometry.cSectors = 0;
9861 pDisk->LCHSGeometry.cHeads = RT_MIN(pDisk->LCHSGeometry.cHeads, 255);
9862 pDisk->LCHSGeometry.cSectors = RT_MIN(pDisk->LCHSGeometry.cSectors, 63);
9889 rc2 = vdThreadFinishWrite(pDisk);
9902 * @param pDisk Pointer to HDD container.
9906 VBOXDDU_DECL(int) VDGetVersion(PVBOXHDD pDisk, unsigned nImage,
9913 LogFlowFunc(("pDisk=%#p nImage=%u puVersion=%#p\n",
9914 pDisk, nImage, puVersion));
9918 AssertPtrBreakStmt(pDisk, rc = VERR_INVALID_PARAMETER);
9919 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
9926 rc2 = vdThreadStartRead(pDisk);
9930 PVDIMAGE pImage = vdGetImageByNumber(pDisk, nImage);
9938 rc2 = vdThreadFinishRead(pDisk);
9951 * @param pDisk Pointer to the HDD container.
9955 VBOXDDU_DECL(int) VDBackendInfoSingle(PVBOXHDD pDisk, unsigned nImage,
9962 LogFlowFunc(("pDisk=%#p nImage=%u pBackendInfo=%#p\n",
9963 pDisk, nImage, pBackendInfo));
9967 AssertPtrBreakStmt(pDisk, rc = VERR_INVALID_PARAMETER);
9968 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
9975 rc2 = vdThreadStartRead(pDisk);
9979 PVDIMAGE pImage = vdGetImageByNumber(pDisk, nImage);
9990 rc2 = vdThreadFinishRead(pDisk);
10003 * @param pDisk Pointer to HDD container.
10007 VBOXDDU_DECL(int) VDGetImageFlags(PVBOXHDD pDisk, unsigned nImage,
10014 LogFlowFunc(("pDisk=%#p nImage=%u puImageFlags=%#p\n",
10015 pDisk, nImage, puImageFlags));
10019 AssertPtrBreakStmt(pDisk, rc = VERR_INVALID_PARAMETER);
10020 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
10027 rc2 = vdThreadStartRead(pDisk);
10031 PVDIMAGE pImage = vdGetImageByNumber(pDisk, nImage);
10039 rc2 = vdThreadFinishRead(pDisk);
10052 * @param pDisk Pointer to HDD container.
10056 VBOXDDU_DECL(int) VDGetOpenFlags(PVBOXHDD pDisk, unsigned nImage,
10063 LogFlowFunc(("pDisk=%#p nImage=%u puOpenFlags=%#p\n",
10064 pDisk, nImage, puOpenFlags));
10068 AssertPtrBreakStmt(pDisk, rc = VERR_INVALID_PARAMETER);
10069 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
10076 rc2 = vdThreadStartRead(pDisk);
10080 PVDIMAGE pImage = vdGetImageByNumber(pDisk, nImage);
10088 rc2 = vdThreadFinishRead(pDisk);
10103 * @param pDisk Pointer to HDD container.
10107 VBOXDDU_DECL(int) VDSetOpenFlags(PVBOXHDD pDisk, unsigned nImage,
10114 LogFlowFunc(("pDisk=%#p uOpenFlags=%#u\n", pDisk, uOpenFlags));
10118 AssertPtrBreakStmt(pDisk, rc = VERR_INVALID_PARAMETER);
10119 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
10126 rc2 = vdThreadStartWrite(pDisk);
10131 rc = vdDiscardStateDestroy(pDisk);
10135 PVDIMAGE pImage = vdGetImageByNumber(pDisk, nImage);
10146 rc2 = vdThreadFinishWrite(pDisk);
10162 * @param pDisk Pointer to HDD container.
10167 VBOXDDU_DECL(int) VDGetFilename(PVBOXHDD pDisk, unsigned nImage,
10174 LogFlowFunc(("pDisk=%#p nImage=%u pszFilename=%#p cbFilename=%u\n",
10175 pDisk, nImage, pszFilename, cbFilename));
10179 AssertPtrBreakStmt(pDisk, rc = VERR_INVALID_PARAMETER);
10180 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
10190 rc2 = vdThreadStartRead(pDisk);
10194 PVDIMAGE pImage = vdGetImageByNumber(pDisk, nImage);
10213 rc2 = vdThreadFinishRead(pDisk);
10227 * @param pDisk Pointer to HDD container.
10232 VBOXDDU_DECL(int) VDGetComment(PVBOXHDD pDisk, unsigned nImage,
10239 LogFlowFunc(("pDisk=%#p nImage=%u pszComment=%#p cbComment=%u\n",
10240 pDisk, nImage, pszComment, cbComment));
10244 AssertPtrBreakStmt(pDisk, rc = VERR_INVALID_PARAMETER);
10245 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
10255 rc2 = vdThreadStartRead(pDisk);
10259 PVDIMAGE pImage = vdGetImageByNumber(pDisk, nImage);
10268 rc2 = vdThreadFinishRead(pDisk);
10281 * @param pDisk Pointer to HDD container.
10285 VBOXDDU_DECL(int) VDSetComment(PVBOXHDD pDisk, unsigned nImage,
10292 LogFlowFunc(("pDisk=%#p nImage=%u pszComment=%#p \"%s\"\n",
10293 pDisk, nImage, pszComment, pszComment));
10297 AssertPtrBreakStmt(pDisk, rc = VERR_INVALID_PARAMETER);
10298 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
10305 rc2 = vdThreadStartWrite(pDisk);
10309 PVDIMAGE pImage = vdGetImageByNumber(pDisk, nImage);
10317 rc2 = vdThreadFinishWrite(pDisk);
10331 * @param pDisk Pointer to HDD container.
10335 VBOXDDU_DECL(int) VDGetUuid(PVBOXHDD pDisk, unsigned nImage, PRTUUID pUuid)
10341 LogFlowFunc(("pDisk=%#p nImage=%u pUuid=%#p\n", pDisk, nImage, pUuid));
10345 AssertPtrBreakStmt(pDisk, rc = VERR_INVALID_PARAMETER);
10346 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
10353 rc2 = vdThreadStartRead(pDisk);
10357 PVDIMAGE pImage = vdGetImageByNumber(pDisk, nImage);
10365 rc2 = vdThreadFinishRead(pDisk);
10378 * @param pDisk Pointer to HDD container.
10382 VBOXDDU_DECL(int) VDSetUuid(PVBOXHDD pDisk, unsigned nImage, PCRTUUID pUuid)
10388 LogFlowFunc(("pDisk=%#p nImage=%u pUuid=%#p {%RTuuid}\n",
10389 pDisk, nImage, pUuid, pUuid));
10393 AssertPtrBreakStmt(pDisk, rc = VERR_INVALID_PARAMETER);
10394 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
10400 rc2 = vdThreadStartWrite(pDisk);
10404 PVDIMAGE pImage = vdGetImageByNumber(pDisk, nImage);
10418 rc2 = vdThreadFinishWrite(pDisk);
10431 * @param pDisk Pointer to HDD container.
10435 VBOXDDU_DECL(int) VDGetModificationUuid(PVBOXHDD pDisk, unsigned nImage, PRTUUID pUuid)
10441 LogFlowFunc(("pDisk=%#p nImage=%u pUuid=%#p\n", pDisk, nImage, pUuid));
10445 AssertPtrBreakStmt(pDisk, rc = VERR_INVALID_PARAMETER);
10446 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
10453 rc2 = vdThreadStartRead(pDisk);
10457 PVDIMAGE pImage = vdGetImageByNumber(pDisk, nImage);
10466 rc2 = vdThreadFinishRead(pDisk);
10479 * @param pDisk Pointer to HDD container.
10483 VBOXDDU_DECL(int) VDSetModificationUuid(PVBOXHDD pDisk, unsigned nImage, PCRTUUID pUuid)
10489 LogFlowFunc(("pDisk=%#p nImage=%u pUuid=%#p {%RTuuid}\n",
10490 pDisk, nImage, pUuid, pUuid));
10494 AssertPtrBreakStmt(pDisk, rc = VERR_INVALID_PARAMETER);
10495 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
10502 rc2 = vdThreadStartWrite(pDisk);
10506 PVDIMAGE pImage = vdGetImageByNumber(pDisk, nImage);
10521 rc2 = vdThreadFinishWrite(pDisk);
10534 * @param pDisk Pointer to HDD container.
10538 VBOXDDU_DECL(int) VDGetParentUuid(PVBOXHDD pDisk, unsigned nImage,
10545 LogFlowFunc(("pDisk=%#p nImage=%u pUuid=%#p\n", pDisk, nImage, pUuid));
10549 AssertPtrBreakStmt(pDisk, rc = VERR_INVALID_PARAMETER);
10550 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
10557 rc2 = vdThreadStartRead(pDisk);
10561 PVDIMAGE pImage = vdGetImageByNumber(pDisk, nImage);
10569 rc2 = vdThreadFinishRead(pDisk);
10581 * @param pDisk Pointer to HDD container.
10585 VBOXDDU_DECL(int) VDSetParentUuid(PVBOXHDD pDisk, unsigned nImage,
10592 LogFlowFunc(("pDisk=%#p nImage=%u pUuid=%#p {%RTuuid}\n",
10593 pDisk, nImage, pUuid, pUuid));
10597 AssertPtrBreakStmt(pDisk, rc = VERR_INVALID_PARAMETER);
10598 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
10605 rc2 = vdThreadStartWrite(pDisk);
10609 PVDIMAGE pImage = vdGetImageByNumber(pDisk, nImage);
10623 rc2 = vdThreadFinishWrite(pDisk);
10635 * @param pDisk Pointer to HDD container.
10637 VBOXDDU_DECL(void) VDDumpImages(PVBOXHDD pDisk)
10645 AssertPtrBreak(pDisk);
10646 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
10648 if (!pDisk->pInterfaceError || !VALID_PTR(pDisk->pInterfaceError->pfnMessage))
10649 pDisk->pInterfaceError->pfnMessage = vdLogMessage;
10651 rc2 = vdThreadStartRead(pDisk);
10655 vdMessageWrapper(pDisk, "--- Dumping VD Disk, Images=%u\n", pDisk->cImages);
10656 for (PVDIMAGE pImage = pDisk->pBase; pImage; pImage = pImage->pNext)
10658 vdMessageWrapper(pDisk, "Dumping VD image \"%s\" (Backend=%s)\n",
10666 rc2 = vdThreadFinishRead(pDisk);
10672 VBOXDDU_DECL(int) VDDiscardRanges(PVBOXHDD pDisk, PCRTRANGE paRanges, unsigned cRanges)
10678 LogFlowFunc(("pDisk=%#p paRanges=%#p cRanges=%u\n",
10679 pDisk, paRanges, cRanges));
10683 AssertPtrBreakStmt(pDisk, rc = VERR_INVALID_PARAMETER);
10684 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
10694 rc2 = vdThreadStartWrite(pDisk);
10698 AssertPtrBreakStmt(pDisk->pLast, rc = VERR_VD_NOT_OPENED);
10700 AssertMsgBreakStmt(pDisk->pLast->uOpenFlags & VD_OPEN_FLAGS_DISCARD,
10711 vdIoCtxDiscardInit(&IoCtx, pDisk, paRanges, cRanges,
10712 vdIoCtxSyncComplete, pDisk, hEventComplete, NULL,
10721 rc2 = vdThreadFinishWrite(pDisk);
10730 VBOXDDU_DECL(int) VDAsyncRead(PVBOXHDD pDisk, uint64_t uOffset, size_t cbRead,
10740 LogFlowFunc(("pDisk=%#p uOffset=%llu pcSgBuf=%#p cbRead=%zu pvUser1=%#p pvUser2=%#p\n",
10741 pDisk, uOffset, pcSgBuf, cbRead, pvUser1, pvUser2));
10746 AssertPtrBreakStmt(pDisk, rc = VERR_INVALID_PARAMETER);
10747 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
10757 rc2 = vdThreadStartRead(pDisk);
10761 AssertMsgBreakStmt(uOffset + cbRead <= pDisk->cbSize,
10762 ("uOffset=%llu cbRead=%zu pDisk->cbSize=%llu\n",
10763 uOffset, cbRead, pDisk->cbSize),
10765 AssertPtrBreakStmt(pDisk->pLast, rc = VERR_VD_NOT_OPENED);
10767 pIoCtx = vdIoCtxRootAlloc(pDisk, VDIOCTXTXDIR_READ, uOffset,
10768 cbRead, pDisk->pLast, pcSgBuf,
10782 vdIoCtxFree(pDisk, pIoCtx);
10787 vdIoCtxFree(pDisk, pIoCtx);
10794 rc2 = vdThreadFinishRead(pDisk);
10803 VBOXDDU_DECL(int) VDAsyncWrite(PVBOXHDD pDisk, uint64_t uOffset, size_t cbWrite,
10813 LogFlowFunc(("pDisk=%#p uOffset=%llu cSgBuf=%#p cbWrite=%zu pvUser1=%#p pvUser2=%#p\n",
10814 pDisk, uOffset, pcSgBuf, cbWrite, pvUser1, pvUser2));
10818 AssertPtrBreakStmt(pDisk, rc = VERR_INVALID_PARAMETER);
10819 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
10829 rc2 = vdThreadStartWrite(pDisk);
10833 AssertMsgBreakStmt(uOffset + cbWrite <= pDisk->cbSize,
10834 ("uOffset=%llu cbWrite=%zu pDisk->cbSize=%llu\n",
10835 uOffset, cbWrite, pDisk->cbSize),
10837 AssertPtrBreakStmt(pDisk->pLast, rc = VERR_VD_NOT_OPENED);
10839 pIoCtx = vdIoCtxRootAlloc(pDisk, VDIOCTXTXDIR_WRITE, uOffset,
10840 cbWrite, pDisk->pLast, pcSgBuf,
10854 vdIoCtxFree(pDisk, pIoCtx);
10859 vdIoCtxFree(pDisk, pIoCtx);
10865 rc2 = vdThreadFinishWrite(pDisk);
10874 VBOXDDU_DECL(int) VDAsyncFlush(PVBOXHDD pDisk, PFNVDASYNCTRANSFERCOMPLETE pfnComplete,
10882 LogFlowFunc(("pDisk=%#p\n", pDisk));
10887 AssertPtrBreakStmt(pDisk, rc = VERR_INVALID_PARAMETER);
10888 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
10890 rc2 = vdThreadStartWrite(pDisk);
10894 AssertPtrBreakStmt(pDisk->pLast, rc = VERR_VD_NOT_OPENED);
10896 pIoCtx = vdIoCtxRootAlloc(pDisk, VDIOCTXTXDIR_FLUSH, 0,
10897 0, pDisk->pLast, NULL,
10911 vdIoCtxFree(pDisk, pIoCtx);
10916 vdIoCtxFree(pDisk, pIoCtx);
10922 rc2 = vdThreadFinishWrite(pDisk);
10930 VBOXDDU_DECL(int) VDAsyncDiscardRanges(PVBOXHDD pDisk, PCRTRANGE paRanges, unsigned cRanges,
10939 LogFlowFunc(("pDisk=%#p\n", pDisk));
10944 AssertPtrBreakStmt(pDisk, rc = VERR_INVALID_PARAMETER);
10945 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));
10947 rc2 = vdThreadStartWrite(pDisk);
10951 AssertPtrBreakStmt(pDisk->pLast, rc = VERR_VD_NOT_OPENED);
10953 pIoCtx = vdIoCtxDiscardAlloc(pDisk, paRanges, cRanges,
10967 vdIoCtxFree(pDisk, pIoCtx);
10972 vdIoCtxFree(pDisk, pIoCtx);
10978 rc2 = vdThreadFinishWrite(pDisk);