DrvDiskIntegrity.cpp revision 3e88c818fff5c64b5eff43d5daf4596bd87230c5
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync/* $Id$ */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync/** @file
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * VBox storage devices: Disk integrity check.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync/*
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync * Copyright (C) 2006-2010 Oracle Corporation
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync *
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * available from http://www.virtualbox.org. This file is free software;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * you can redistribute it and/or modify it under the terms of the GNU
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * General Public License (GPL) as published by the Free Software
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync/*******************************************************************************
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync* Header Files *
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync*******************************************************************************/
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync#define LOG_GROUP LOG_GROUP_DRV_DISK_INTEGRITY
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync#include <VBox/pdmdrv.h>
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync#include <iprt/assert.h>
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync#include <iprt/string.h>
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync#include <iprt/uuid.h>
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync#include <iprt/avl.h>
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync#include <iprt/mem.h>
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync#include <iprt/message.h>
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync#include <iprt/sg.h>
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync#include <iprt/time.h>
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync#include <iprt/semaphore.h>
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync#include "Builtins.h"
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync/*******************************************************************************
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync* Structures and Typedefs *
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync*******************************************************************************/
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/**
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync * async I/O request.
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsynctypedef struct DRVDISKAIOREQ
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync{
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync /** Flag whether this is a read or write request. */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync bool fRead;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync /** Start offset. */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync uint64_t off;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync /** Transfer size. */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync size_t cbTransfer;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync /** Segment array. */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PCRTSGSEG paSeg;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync /** Number of array entries. */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync unsigned cSeg;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync /** User argument */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync void *pvUser;
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync /** Slot in the array. */
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync unsigned iSlot;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync} DRVDISKAIOREQ, *PDRVDISKAIOREQ;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync/**
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync * I/O log entry.
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync */
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsynctypedef struct IOLOGENT
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync{
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync /** Start offset */
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync uint64_t off;
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync /** Write size */
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync size_t cbWrite;
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync /** Number of references to this entry. */
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync unsigned cRefs;
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync} IOLOGENT, *PIOLOGENT;
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync/**
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * Disk segment.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsynctypedef struct DRVDISKSEGMENT
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync{
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /** AVL core. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync AVLRFOFFNODECORE Core;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /** Size of the segment */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync size_t cbSeg;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /** Data for this segment */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync uint8_t *pbSeg;
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync /** Numbner of entries in the I/O array. */
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync unsigned cIoLogEntries;
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync /** Array of I/O log references. */
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync PIOLOGENT apIoLog[1];
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync} DRVDISKSEGMENT, *PDRVDISKSEGMENT;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync/**
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync * Active requests list entry.
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync */
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsynctypedef struct DRVDISKAIOREQACTIVE
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync{
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync /** Pointer to the request. */
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync volatile PDRVDISKAIOREQ pIoReq;
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync /** Start timestamp. */
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync uint64_t tsStart;
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync} DRVDISKAIOREQACTIVE, *PDRVDISKAIOREQACTIVE;
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync/**
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * Disk integrity driver instance data.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync *
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * @implements PDMIMEDIA
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsynctypedef struct DRVDISKINTEGRITY
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync{
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /** Pointer driver instance. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PPDMDRVINS pDrvIns;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /** Pointer to the media driver below us.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * This is NULL if the media is not mounted. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PPDMIMEDIA pDrvMedia;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /** Our media interface */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PDMIMEDIA IMedia;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync /** Pointer to the media async driver below us.
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync * This is NULL if the media is not mounted. */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PPDMIMEDIAASYNC pDrvMediaAsync;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync /** Our media async interface */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PDMIMEDIAASYNC IMediaAsync;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync /** The async media port interface above. */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PPDMIMEDIAASYNCPORT pDrvMediaAsyncPort;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync /** Our media async port interface */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PDMIMEDIAASYNCPORT IMediaAsyncPort;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync /** Flag whether consistency checks are enabled. */
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync bool fCheckConsistency;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /** AVL tree containing the disk blocks to check. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PAVLRFOFFTREE pTreeSegments;
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync /** Flag whether async request tracing is enabled. */
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync bool fTraceRequests;
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync /** Interval the thread should check for expired requests (milliseconds). */
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync uint32_t uCheckIntervalMs;
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync /** Expire timeout for a request (milliseconds). */
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync uint32_t uExpireIntervalMs;
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync /** Thread which checks for lost requests. */
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync RTTHREAD hThread;
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync /** Event semaphore */
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync RTSEMEVENT SemEvent;
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync /** Flag whether the thread should run. */
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync bool fRunning;
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync /** Array containing active requests. */
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync DRVDISKAIOREQACTIVE apReqActive[128];
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync /** Next free slot in the array */
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync volatile unsigned iNextFreeSlot;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync} DRVDISKINTEGRITY, *PDRVDISKINTEGRITY;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/**
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync * Allocate a new I/O request.
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync *
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync * @returns New I/O request.
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync * @param fRead Flag whether this is a read or a write.
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync * @param off Start offset.
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync * @param paSeg Segment array.
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync * @param cSeg Number of segments.
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync * @param cbTransfer Number of bytes to transfer.
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync * @param pvUser User argument.
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsyncstatic PDRVDISKAIOREQ drvdiskintIoReqAlloc(bool fRead, uint64_t off, PCRTSGSEG paSeg,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync unsigned cSeg, size_t cbTransfer, void *pvUser)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync{
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PDRVDISKAIOREQ pIoReq = (PDRVDISKAIOREQ)RTMemAlloc(sizeof(DRVDISKAIOREQ));
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync if (RT_LIKELY(pIoReq))
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync {
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync pIoReq->fRead = fRead;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync pIoReq->off = off;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync pIoReq->cbTransfer = cbTransfer;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync pIoReq->paSeg = paSeg;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync pIoReq->cSeg = cSeg;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync pIoReq->pvUser = pvUser;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync }
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync return pIoReq;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync}
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/**
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync * Record a successful write to the virtual disk.
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync *
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync * @returns VBox status code.
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync * @param pThis Disk integrity driver instance data.
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync * @param paSeg Segment array of the write to record.
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync * @param cSeg Number of segments.
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync * @param off Start offset.
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync * @param cbWrite Number of bytes to record.
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsyncstatic int drvdiskintWriteRecord(PDRVDISKINTEGRITY pThis, PCRTSGSEG paSeg, unsigned cSeg,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync uint64_t off, size_t cbWrite)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync{
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync int rc = VINF_SUCCESS;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
6114ff5789db75ff28460a056ed422ee03d8f0ebvboxsync LogFlowFunc(("pThis=%#p paSeg=%#p cSeg=%u off=%llx cbWrite=%u\n",
6114ff5789db75ff28460a056ed422ee03d8f0ebvboxsync pThis, paSeg, cSeg, off, cbWrite));
6114ff5789db75ff28460a056ed422ee03d8f0ebvboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /* Update the segments */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync size_t cbLeft = cbWrite;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync RTFOFF offCurr = (RTFOFF)off;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync RTSGBUF SgBuf;
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync PIOLOGENT pIoLogEnt = (PIOLOGENT)RTMemAllocZ(sizeof(IOLOGENT));
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync if (!pIoLogEnt)
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync return VERR_NO_MEMORY;
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync pIoLogEnt->off = off;
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync pIoLogEnt->cbWrite = cbWrite;
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync pIoLogEnt->cRefs = 0;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync RTSgBufInit(&SgBuf, paSeg, cSeg);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync while (cbLeft)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync {
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PDRVDISKSEGMENT pSeg = (PDRVDISKSEGMENT)RTAvlrFileOffsetRangeGet(pThis->pTreeSegments, offCurr);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync size_t cbRange = 0;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync bool fSet = false;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync unsigned offSeg = 0;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync if (!pSeg)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync {
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /* Get next segment */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pSeg = (PDRVDISKSEGMENT)RTAvlrFileOffsetGetBestFit(pThis->pTreeSegments, offCurr, true);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync if ( !pSeg
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync || offCurr + (RTFOFF)cbLeft <= pSeg->Core.Key)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync cbRange = cbLeft;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync else
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync cbRange = pSeg->Core.Key - offCurr;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync Assert(cbRange % 512 == 0);
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /* Create new segment */
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync pSeg = (PDRVDISKSEGMENT)RTMemAllocZ(RT_OFFSETOF(DRVDISKSEGMENT, apIoLog[cbRange / 512]));
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync if (pSeg)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync {
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync pSeg->Core.Key = offCurr;
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync pSeg->Core.KeyLast = offCurr + (RTFOFF)cbRange - 1;
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync pSeg->cbSeg = cbRange;
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync pSeg->pbSeg = (uint8_t *)RTMemAllocZ(cbRange);
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync pSeg->cIoLogEntries = cbRange / 512;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync if (!pSeg->pbSeg)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync RTMemFree(pSeg);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync else
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync {
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync bool fInserted = RTAvlrFileOffsetInsert(pThis->pTreeSegments, &pSeg->Core);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync AssertMsg(fInserted, ("Bug!\n"));
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync fSet = true;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync }
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync }
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync }
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync else
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync {
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync fSet = true;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync offSeg = offCurr - pSeg->Core.Key;
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync cbRange = RT_MIN(cbLeft, (size_t)(pSeg->Core.KeyLast + 1 - offCurr));
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync }
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync if (fSet)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync {
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync AssertPtr(pSeg);
e93dfb5368911523b10cd2f506c44f5fbd47abf3vboxsync size_t cbCopied = RTSgBufCopyToBuf(&SgBuf, pSeg->pbSeg + offSeg, cbRange);
e93dfb5368911523b10cd2f506c44f5fbd47abf3vboxsync Assert(cbCopied == cbRange);
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync /* Update the I/O log pointers */
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync Assert(offSeg % 512 == 0);
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync Assert(cbRange % 512 == 0);
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync while (offSeg < cbRange)
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync {
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync uint32_t uSector = offSeg / 512;
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync PIOLOGENT pIoLogOld = NULL;
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync AssertMsg(uSector < pSeg->cIoLogEntries, ("Internal bug!\n"));
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync pIoLogOld = pSeg->apIoLog[uSector];
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync if (pIoLogOld)
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync {
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync pIoLogOld->cRefs--;
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync if (!pIoLogOld->cRefs)
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync RTMemFree(pIoLogOld);
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync }
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync pSeg->apIoLog[uSector] = pIoLogEnt;
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync pIoLogEnt->cRefs++;
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync offSeg += 512;
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync }
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync }
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync else
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync RTSgBufAdvance(&SgBuf, cbRange);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync offCurr += cbRange;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync cbLeft -= cbRange;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync }
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync return rc;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync}
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/**
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync * Verifies a read request.
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync *
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync * @returns VBox status code.
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync * @param pThis Disk integrity driver instance data.
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync * @param paSeg Segment array of the containing the data buffers to verify.
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync * @param cSeg Number of segments.
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync * @param off Start offset.
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync * @param cbWrite Number of bytes to verify.
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsyncstatic int drvdiskintReadVerify(PDRVDISKINTEGRITY pThis, PCRTSGSEG paSeg, unsigned cSeg,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync uint64_t off, size_t cbRead)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync{
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync int rc = VINF_SUCCESS;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
6114ff5789db75ff28460a056ed422ee03d8f0ebvboxsync LogFlowFunc(("pThis=%#p paSeg=%#p cSeg=%u off=%llx cbRead=%u\n",
6114ff5789db75ff28460a056ed422ee03d8f0ebvboxsync pThis, paSeg, cSeg, off, cbRead));
6114ff5789db75ff28460a056ed422ee03d8f0ebvboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync Assert(off % 512 == 0);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync Assert(cbRead % 512 == 0);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync /* Compare read data */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync size_t cbLeft = cbRead;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync RTFOFF offCurr = (RTFOFF)off;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync RTSGBUF SgBuf;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync RTSgBufInit(&SgBuf, paSeg, cSeg);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync while (cbLeft)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync {
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PDRVDISKSEGMENT pSeg = (PDRVDISKSEGMENT)RTAvlrFileOffsetRangeGet(pThis->pTreeSegments, offCurr);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync size_t cbRange = 0;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync bool fCmp = false;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync unsigned offSeg = 0;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync if (!pSeg)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync {
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync /* Get next segment */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync pSeg = (PDRVDISKSEGMENT)RTAvlrFileOffsetGetBestFit(pThis->pTreeSegments, offCurr, true);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync if (!pSeg)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync {
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync /* No data in the tree for this read. Assume everything is ok. */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync cbRange = cbLeft;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync }
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync else if (offCurr + (RTFOFF)cbLeft <= pSeg->Core.Key)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync cbRange = cbLeft;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync else
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync cbRange = pSeg->Core.Key - offCurr;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync }
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync else
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync {
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync fCmp = true;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync offSeg = offCurr - pSeg->Core.Key;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync cbRange = RT_MIN(cbLeft, (size_t)(pSeg->Core.KeyLast + 1 - offCurr));
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync }
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync if (fCmp)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync {
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync RTSGSEG Seg;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync RTSGBUF SgBufCmp;
1426407ebd84624dd10808b452b19d1fc4f6835avboxsync size_t cbOff = 0;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync Seg.cbSeg = cbRange;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync Seg.pvSeg = pSeg->pbSeg + offSeg;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync RTSgBufInit(&SgBufCmp, &Seg, 1);
1426407ebd84624dd10808b452b19d1fc4f6835avboxsync if (RTSgBufCmpEx(&SgBuf, &SgBufCmp, cbRange, &cbOff, true))
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync {
1426407ebd84624dd10808b452b19d1fc4f6835avboxsync /* Corrupted disk, print I/O log entry of the last write which accessed this range. */
1426407ebd84624dd10808b452b19d1fc4f6835avboxsync uint32_t cSector = (offSeg + cbOff) / 512;
1426407ebd84624dd10808b452b19d1fc4f6835avboxsync AssertMsg(cSector < pSeg->cIoLogEntries, ("Internal bug!\n"));
1426407ebd84624dd10808b452b19d1fc4f6835avboxsync
1426407ebd84624dd10808b452b19d1fc4f6835avboxsync RTMsgError("Corrupted disk at offset %llu (%u bytes in the current read buffer)!\n",
1426407ebd84624dd10808b452b19d1fc4f6835avboxsync offCurr + cbOff, cbOff);
1426407ebd84624dd10808b452b19d1fc4f6835avboxsync RTMsgError("Last write to this sector started at offset %llu with %u bytes (%u references to this log entry)\n",
1426407ebd84624dd10808b452b19d1fc4f6835avboxsync pSeg->apIoLog[cSector]->off,
1426407ebd84624dd10808b452b19d1fc4f6835avboxsync pSeg->apIoLog[cSector]->cbWrite,
1426407ebd84624dd10808b452b19d1fc4f6835avboxsync pSeg->apIoLog[cSector]->cRefs);
1426407ebd84624dd10808b452b19d1fc4f6835avboxsync RTAssertDebugBreak();
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync }
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync }
e93dfb5368911523b10cd2f506c44f5fbd47abf3vboxsync else
e93dfb5368911523b10cd2f506c44f5fbd47abf3vboxsync RTSgBufAdvance(&SgBuf, cbRange);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync offCurr += cbRange;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync cbLeft -= cbRange;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync }
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync return rc;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync}
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync/**
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync * Adds a request to the active list.
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync *
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync * @returns nothing.
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync * @param pThis The driver instance data.
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync * @param pIoReq The request to add.
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync */
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsyncstatic void drvdiskintIoReqAdd(PDRVDISKINTEGRITY pThis, PDRVDISKAIOREQ pIoReq)
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync{
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync PDRVDISKAIOREQACTIVE pReqActive = &pThis->apReqActive[pThis->iNextFreeSlot];
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync Assert(!pReqActive->pIoReq);
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync pReqActive->tsStart = RTTimeSystemMilliTS();
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync pReqActive->pIoReq = pIoReq;
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync pIoReq->iSlot = pThis->iNextFreeSlot;
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync /* Search for the next one. */
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync pThis->iNextFreeSlot++;
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync while (pThis->apReqActive[pThis->iNextFreeSlot].pIoReq)
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync pThis->iNextFreeSlot = pThis->iNextFreeSlot++ % RT_ELEMENTS(pThis->apReqActive);
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync}
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync/**
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync * Removes a request from the active list.
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync *
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync * @returns nothing.
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync * @param pThis The driver instance data.
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync * @param pIoReq The request to remove.
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync */
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsyncstatic void drvdiskintIoReqRemove(PDRVDISKINTEGRITY pThis, PDRVDISKAIOREQ pIoReq)
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync{
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync PDRVDISKAIOREQACTIVE pReqActive = &pThis->apReqActive[pIoReq->iSlot];
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync Assert(pReqActive->pIoReq == pIoReq);
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync ASMAtomicXchgPtr((void * volatile *)&pReqActive->pIoReq, NULL);
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync}
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync/**
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync * Thread checking for expired requests.
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync *
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync * @returns IPRT status code.
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync * @param pThread Thread handle.
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync * @param pvUser Opaque user data.
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync */
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsyncstatic int drvdiskIntIoReqExpiredCheck(RTTHREAD pThread, void *pvUser)
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync{
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync PDRVDISKINTEGRITY pThis = (PDRVDISKINTEGRITY)pvUser;
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync while (pThis->fRunning)
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync {
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync int rc = RTSemEventWait(pThis->SemEvent, pThis->uCheckIntervalMs);
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync if (!pThis->fRunning)
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync break;
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync Assert(rc == VERR_TIMEOUT);
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync /* Get current timestamp for comparison. */
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync uint64_t tsCurr = RTTimeSystemMilliTS();
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync /* Go through the array and check for expired requests. */
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pThis->apReqActive); i++)
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync {
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync PDRVDISKAIOREQACTIVE pReqActive = &pThis->apReqActive[i];
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync PDRVDISKAIOREQ pIoReq = (PDRVDISKAIOREQ)ASMAtomicReadPtr((void * volatile *)&pReqActive->pIoReq);
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync if ( pIoReq
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync && (tsCurr - pReqActive->tsStart) >= pThis->uExpireIntervalMs)
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync {
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync RTMsgError("Request %#p expired (active for %llu ms already)\n",
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync pIoReq, tsCurr - pReqActive->tsStart);
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync RTAssertDebugBreak();
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync }
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync }
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync }
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync return VINF_SUCCESS;
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync}
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/* -=-=-=-=- IMedia -=-=-=-=- */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/** Makes a PDRVDISKINTEGRITY out of a PPDMIMEDIA. */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync#define PDMIMEDIA_2_DRVDISKINTEGRITY(pInterface) ( (PDRVDISKINTEGRITY)((uintptr_t)pInterface - RT_OFFSETOF(DRVDISKINTEGRITY, IMedia)) )
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/** Makes a PDRVDISKINTEGRITY out of a PPDMIMEDIAASYNC. */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync#define PDMIMEDIAASYNC_2_DRVDISKINTEGRITY(pInterface) ( (PDRVDISKINTEGRITY)((uintptr_t)pInterface - RT_OFFSETOF(DRVDISKINTEGRITY, IMediaAsync)) )
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/*******************************************************************************
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync* Media interface methods *
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync*******************************************************************************/
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/** @copydoc PDMIMEDIA::pfnRead */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsyncstatic DECLCALLBACK(int) drvdiskintRead(PPDMIMEDIA pInterface,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync uint64_t off, void *pvBuf, size_t cbRead)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync{
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PDRVDISKINTEGRITY pThis = PDMIMEDIA_2_DRVDISKINTEGRITY(pInterface);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync int rc = pThis->pDrvMedia->pfnRead(pThis->pDrvMedia, off, pvBuf, cbRead);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync if (RT_FAILURE(rc))
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync return rc;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync if (pThis->fCheckConsistency)
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync {
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync /* Verify the read. */
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync RTSGSEG Seg;
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync Seg.cbSeg = cbRead;
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync Seg.pvSeg = pvBuf;
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync rc = drvdiskintReadVerify(pThis, &Seg, 1, off, cbRead);
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync }
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync return rc;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync}
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/** @copydoc PDMIMEDIA::pfnWrite */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsyncstatic DECLCALLBACK(int) drvdiskintWrite(PPDMIMEDIA pInterface,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync uint64_t off, const void *pvBuf,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync size_t cbWrite)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync{
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PDRVDISKINTEGRITY pThis = PDMIMEDIA_2_DRVDISKINTEGRITY(pInterface);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync int rc = pThis->pDrvMedia->pfnWrite(pThis->pDrvMedia, off, pvBuf, cbWrite);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync if (RT_FAILURE(rc))
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync return rc;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync if (pThis->fCheckConsistency)
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync {
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync /* Record the write. */
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync RTSGSEG Seg;
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync Seg.cbSeg = cbWrite;
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync Seg.pvSeg = (void *)pvBuf;
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync rc = drvdiskintWriteRecord(pThis, &Seg, 1, off, cbWrite);
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync }
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync return rc;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync}
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsyncstatic DECLCALLBACK(int) drvdiskintStartRead(PPDMIMEDIAASYNC pInterface, uint64_t uOffset,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PCRTSGSEG paSeg, unsigned cSeg,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync size_t cbRead, void *pvUser)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync{
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync LogFlow(("%s: uOffset=%#llx paSeg=%#p cSeg=%u cbRead=%d\n pvUser=%#p", __FUNCTION__,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync uOffset, paSeg, cSeg, cbRead, pvUser));
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PDRVDISKINTEGRITY pThis = PDMIMEDIAASYNC_2_DRVDISKINTEGRITY(pInterface);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PDRVDISKAIOREQ pIoReq = drvdiskintIoReqAlloc(true, uOffset, paSeg, cSeg, cbRead, pvUser);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync AssertPtr(pIoReq);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync if (pThis->fTraceRequests)
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync drvdiskintIoReqAdd(pThis, pIoReq);
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync int rc = pThis->pDrvMediaAsync->pfnStartRead(pThis->pDrvMediaAsync, uOffset, paSeg, cSeg,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync cbRead, pIoReq);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync if (rc == VINF_VD_ASYNC_IO_FINISHED)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync {
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync /* Verify the read now. */
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync if (pThis->fCheckConsistency)
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync {
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync int rc2 = drvdiskintReadVerify(pThis, paSeg, cSeg, uOffset, cbRead);
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync AssertRC(rc2);
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync }
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync if (pThis->fTraceRequests)
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync drvdiskintIoReqRemove(pThis, pIoReq);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync RTMemFree(pIoReq);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync }
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync else if (RT_FAILURE(rc) && rc != VERR_VD_ASYNC_IO_IN_PROGRESS)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync RTMemFree(pIoReq);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync LogFlow(("%s: returns %Rrc\n", __FUNCTION__, rc));
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync return rc;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync}
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsyncstatic DECLCALLBACK(int) drvdiskintStartWrite(PPDMIMEDIAASYNC pInterface, uint64_t uOffset,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PCRTSGSEG paSeg, unsigned cSeg,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync size_t cbWrite, void *pvUser)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync{
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync LogFlow(("%s: uOffset=%#llx paSeg=%#p cSeg=%u cbWrite=%d\n pvUser=%#p", __FUNCTION__,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync uOffset, paSeg, cSeg, cbWrite, pvUser));
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PDRVDISKINTEGRITY pThis = PDMIMEDIAASYNC_2_DRVDISKINTEGRITY(pInterface);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PDRVDISKAIOREQ pIoReq = drvdiskintIoReqAlloc(false, uOffset, paSeg, cSeg, cbWrite, pvUser);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync AssertPtr(pIoReq);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync if (pThis->fTraceRequests)
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync drvdiskintIoReqAdd(pThis, pIoReq);
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync int rc = pThis->pDrvMediaAsync->pfnStartWrite(pThis->pDrvMediaAsync, uOffset, paSeg, cSeg,
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync cbWrite, pIoReq);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync if (rc == VINF_VD_ASYNC_IO_FINISHED)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync {
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync /* Verify the read now. */
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync if (pThis->fCheckConsistency)
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync {
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync int rc2 = drvdiskintWriteRecord(pThis, paSeg, cSeg, uOffset, cbWrite);
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync AssertRC(rc2);
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync }
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync if (pThis->fTraceRequests)
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync drvdiskintIoReqRemove(pThis, pIoReq);
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync RTMemFree(pIoReq);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync }
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync else if (RT_FAILURE(rc) && rc != VERR_VD_ASYNC_IO_IN_PROGRESS)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync RTMemFree(pIoReq);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync LogFlow(("%s: returns %Rrc\n", __FUNCTION__, rc));
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync return rc;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync}
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync/** @copydoc PDMIMEDIA::pfnFlush */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsyncstatic DECLCALLBACK(int) drvdiskintFlush(PPDMIMEDIA pInterface)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync{
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PDRVDISKINTEGRITY pThis = PDMIMEDIA_2_DRVDISKINTEGRITY(pInterface);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync return pThis->pDrvMedia->pfnFlush(pThis->pDrvMedia);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync}
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync/** @copydoc PDMIMEDIA::pfnGetSize */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsyncstatic DECLCALLBACK(uint64_t) drvdiskintGetSize(PPDMIMEDIA pInterface)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync{
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PDRVDISKINTEGRITY pThis = PDMIMEDIA_2_DRVDISKINTEGRITY(pInterface);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync return pThis->pDrvMedia->pfnGetSize(pThis->pDrvMedia);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync}
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync/** @copydoc PDMIMEDIA::pfnIsReadOnly */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsyncstatic DECLCALLBACK(bool) drvdiskintIsReadOnly(PPDMIMEDIA pInterface)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync{
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PDRVDISKINTEGRITY pThis = PDMIMEDIA_2_DRVDISKINTEGRITY(pInterface);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync return pThis->pDrvMedia->pfnIsReadOnly(pThis->pDrvMedia);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync}
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync/** @copydoc PDMIMEDIA::pfnBiosGetPCHSGeometry */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsyncstatic DECLCALLBACK(int) drvdiskintBiosGetPCHSGeometry(PPDMIMEDIA pInterface,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PPDMMEDIAGEOMETRY pPCHSGeometry)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync{
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PDRVDISKINTEGRITY pThis = PDMIMEDIA_2_DRVDISKINTEGRITY(pInterface);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync return pThis->pDrvMedia->pfnBiosGetPCHSGeometry(pThis->pDrvMedia, pPCHSGeometry);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync}
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync/** @copydoc PDMIMEDIA::pfnBiosSetPCHSGeometry */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsyncstatic DECLCALLBACK(int) drvdiskintBiosSetPCHSGeometry(PPDMIMEDIA pInterface,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PCPDMMEDIAGEOMETRY pPCHSGeometry)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync{
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PDRVDISKINTEGRITY pThis = PDMIMEDIA_2_DRVDISKINTEGRITY(pInterface);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync return pThis->pDrvMedia->pfnBiosSetPCHSGeometry(pThis->pDrvMedia, pPCHSGeometry);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync}
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync/** @copydoc PDMIMEDIA::pfnBiosGetLCHSGeometry */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsyncstatic DECLCALLBACK(int) drvdiskintBiosGetLCHSGeometry(PPDMIMEDIA pInterface,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PPDMMEDIAGEOMETRY pLCHSGeometry)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync{
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PDRVDISKINTEGRITY pThis = PDMIMEDIA_2_DRVDISKINTEGRITY(pInterface);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync return pThis->pDrvMedia->pfnBiosGetLCHSGeometry(pThis->pDrvMedia, pLCHSGeometry);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync}
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync/** @copydoc PDMIMEDIA::pfnBiosSetLCHSGeometry */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsyncstatic DECLCALLBACK(int) drvdiskintBiosSetLCHSGeometry(PPDMIMEDIA pInterface,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PCPDMMEDIAGEOMETRY pLCHSGeometry)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync{
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PDRVDISKINTEGRITY pThis = PDMIMEDIA_2_DRVDISKINTEGRITY(pInterface);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync return pThis->pDrvMedia->pfnBiosSetLCHSGeometry(pThis->pDrvMedia, pLCHSGeometry);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync}
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync/** @copydoc PDMIMEDIA::pfnGetUuid */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsyncstatic DECLCALLBACK(int) drvdiskintGetUuid(PPDMIMEDIA pInterface, PRTUUID pUuid)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync{
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PDRVDISKINTEGRITY pThis = PDMIMEDIA_2_DRVDISKINTEGRITY(pInterface);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync return pThis->pDrvMedia->pfnGetUuid(pThis->pDrvMedia, pUuid);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync}
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/* -=-=-=-=- IMediaAsyncPort -=-=-=-=- */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync/** Makes a PDRVBLOCKASYNC out of a PPDMIMEDIAASYNCPORT. */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync#define PDMIMEDIAASYNCPORT_2_DRVDISKINTEGRITY(pInterface) ( (PDRVDISKINTEGRITY((uintptr_t)pInterface - RT_OFFSETOF(DRVDISKINTEGRITY, IMediaAsyncPort))) )
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
f687f34bd232be13744edbc0cc5155fa5d4540edvboxsyncstatic DECLCALLBACK(int) drvdiskintAsyncTransferCompleteNotify(PPDMIMEDIAASYNCPORT pInterface, void *pvUser, int rcReq)
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync{
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PDRVDISKINTEGRITY pThis = PDMIMEDIAASYNCPORT_2_DRVDISKINTEGRITY(pInterface);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync PDRVDISKAIOREQ pIoReq = (PDRVDISKAIOREQ)pvUser;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync int rc = VINF_SUCCESS;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
6114ff5789db75ff28460a056ed422ee03d8f0ebvboxsync LogFlowFunc(("pIoReq=%#p\n", pIoReq));
6114ff5789db75ff28460a056ed422ee03d8f0ebvboxsync
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync /* Remove from the active list. */
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync if (pThis->fTraceRequests)
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync drvdiskintIoReqRemove(pThis, pIoReq);
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync if (RT_SUCCESS(rcReq) && pThis->fCheckConsistency)
f687f34bd232be13744edbc0cc5155fa5d4540edvboxsync {
f687f34bd232be13744edbc0cc5155fa5d4540edvboxsync if (pIoReq->fRead)
f687f34bd232be13744edbc0cc5155fa5d4540edvboxsync rc = drvdiskintReadVerify(pThis, pIoReq->paSeg, pIoReq->cSeg, pIoReq->off, pIoReq->cbTransfer);
f687f34bd232be13744edbc0cc5155fa5d4540edvboxsync else
f687f34bd232be13744edbc0cc5155fa5d4540edvboxsync rc = drvdiskintWriteRecord(pThis, pIoReq->paSeg, pIoReq->cSeg, pIoReq->off, pIoReq->cbTransfer);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
f687f34bd232be13744edbc0cc5155fa5d4540edvboxsync AssertRC(rc);
f687f34bd232be13744edbc0cc5155fa5d4540edvboxsync }
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
f687f34bd232be13744edbc0cc5155fa5d4540edvboxsync rc = pThis->pDrvMediaAsyncPort->pfnTransferCompleteNotify(pThis->pDrvMediaAsyncPort, pIoReq->pvUser, rcReq);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync RTMemFree(pIoReq);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync return rc;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync}
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync/* -=-=-=-=- IBase -=-=-=-=- */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync/**
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * @interface_method_impl{PDMIBASE,pfnQueryInterface}
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsyncstatic DECLCALLBACK(void *) drvdiskintQueryInterface(PPDMIBASE pInterface, const char *pszIID)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync{
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PDRVDISKINTEGRITY pThis = PDMINS_2_DATA(pDrvIns, PDRVDISKINTEGRITY);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMEDIA, &pThis->IMedia);
6114ff5789db75ff28460a056ed422ee03d8f0ebvboxsync PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMEDIAASYNC, pThis->pDrvMediaAsync ? &pThis->IMediaAsync : NULL);
6114ff5789db75ff28460a056ed422ee03d8f0ebvboxsync PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMEDIAASYNCPORT, &pThis->IMediaAsyncPort);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync return NULL;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync}
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync/* -=-=-=-=- driver interface -=-=-=-=- */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsyncstatic int drvdiskintTreeDestroy(PAVLRFOFFNODECORE pNode, void *pvUser)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync{
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PDRVDISKSEGMENT pSeg = (PDRVDISKSEGMENT)pNode;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync RTMemFree(pSeg->pbSeg);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync RTMemFree(pSeg);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync return VINF_SUCCESS;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync}
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync/**
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * @copydoc FNPDMDRVDESTRUCT
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsyncstatic DECLCALLBACK(void) drvdiskintDestruct(PPDMDRVINS pDrvIns)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync{
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PDRVDISKINTEGRITY pThis = PDMINS_2_DATA(pDrvIns, PDRVDISKINTEGRITY);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync if (pThis->pTreeSegments)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync {
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync RTAvlrFileOffsetDestroy(pThis->pTreeSegments, drvdiskintTreeDestroy, NULL);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync RTMemFree(pThis->pTreeSegments);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync }
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync if (pThis->fTraceRequests)
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync {
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync pThis->fRunning = false;
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync RTSemEventSignal(pThis->SemEvent);
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync RTSemEventDestroy(pThis->SemEvent);
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync }
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync}
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync/**
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * Construct a disk integrity driver instance.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync *
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * @copydoc FNPDMDRVCONSTRUCT
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsyncstatic DECLCALLBACK(int) drvdiskintConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync{
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync int rc = VINF_SUCCESS;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PDRVDISKINTEGRITY pThis = PDMINS_2_DATA(pDrvIns, PDRVDISKINTEGRITY);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync LogFlow(("drvdiskintConstruct: iInstance=%d\n", pDrvIns->iInstance));
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /*
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * Validate configuration.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync */
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync if (!CFGMR3AreValuesValid(pCfg, "CheckConsistency\0"
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync "TraceRequests\0"
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync "CheckIntervalMs\0"
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync "ExpireIntervalMs\0"))
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync rc = CFGMR3QueryBoolDef(pCfg, "CheckConsistency", &pThis->fCheckConsistency, false);
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync AssertRC(rc);
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync rc = CFGMR3QueryBoolDef(pCfg, "TraceRequests", &pThis->fTraceRequests, false);
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync AssertRC(rc);
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync rc = CFGMR3QueryU32Def(pCfg, "CheckIntervalMs", &pThis->uCheckIntervalMs, 5000); /* 5 seconds */
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync AssertRC(rc);
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync rc = CFGMR3QueryU32Def(pCfg, "ExpireIntervalMs", &pThis->uExpireIntervalMs, 20000); /* 20 seconds */
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync AssertRC(rc);
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /*
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * Initialize most of the data members.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->pDrvIns = pDrvIns;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /* IBase. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pDrvIns->IBase.pfnQueryInterface = drvdiskintQueryInterface;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /* IMedia */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->IMedia.pfnRead = drvdiskintRead;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->IMedia.pfnWrite = drvdiskintWrite;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->IMedia.pfnFlush = drvdiskintFlush;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->IMedia.pfnGetSize = drvdiskintGetSize;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->IMedia.pfnIsReadOnly = drvdiskintIsReadOnly;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->IMedia.pfnBiosGetPCHSGeometry = drvdiskintBiosGetPCHSGeometry;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->IMedia.pfnBiosSetPCHSGeometry = drvdiskintBiosSetPCHSGeometry;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->IMedia.pfnBiosGetLCHSGeometry = drvdiskintBiosGetLCHSGeometry;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->IMedia.pfnBiosSetLCHSGeometry = drvdiskintBiosSetLCHSGeometry;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->IMedia.pfnGetUuid = drvdiskintGetUuid;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync /* IMediaAsync */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync pThis->IMediaAsync.pfnStartRead = drvdiskintStartRead;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync pThis->IMediaAsync.pfnStartWrite = drvdiskintStartWrite;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync /* IMediaAsyncPort. */
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync pThis->IMediaAsyncPort.pfnTransferCompleteNotify = drvdiskintAsyncTransferCompleteNotify;
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /*
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * Try attach driver below and query it's media interface.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PPDMIBASE pBase;
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync rc = PDMDrvHlpAttach(pDrvIns, fFlags, &pBase);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync if (RT_FAILURE(rc))
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS,
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync N_("Failed to attach driver below us! %Rrc"), rc);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync pThis->pDrvMedia = PDMIBASE_QUERY_INTERFACE(pBase, PDMIMEDIA);
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync if (!pThis->pDrvMedia)
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync return PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_MISSING_INTERFACE_BELOW,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync N_("No media or async media interface below"));
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync pThis->pDrvMediaAsync = PDMIBASE_QUERY_INTERFACE(pBase, PDMIMEDIAASYNC);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync /* Try to attach async media port interface above.*/
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync pThis->pDrvMediaAsyncPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIMEDIAASYNCPORT);
b26de2ddb274b0e52de6652ad8b45259be2b9913vboxsync
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync if (pThis->fCheckConsistency)
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync {
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync /* Create the AVL tree. */
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync pThis->pTreeSegments = (PAVLRFOFFTREE)RTMemAllocZ(sizeof(AVLRFOFFTREE));
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync if (!pThis->pTreeSegments)
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync rc = VERR_NO_MEMORY;
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync }
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync if (pThis->fTraceRequests)
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync {
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pThis->apReqActive); i++)
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync {
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync pThis->apReqActive[i].pIoReq = NULL;
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync pThis->apReqActive[i].tsStart = 0;
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync }
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync pThis->iNextFreeSlot = 0;
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync /* Init event semaphore. */
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync rc = RTSemEventCreate(&pThis->SemEvent);
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync AssertRC(rc);
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync pThis->fRunning = true;
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync rc = RTThreadCreate(&pThis->hThread, drvdiskIntIoReqExpiredCheck, pThis,
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync 0, RTTHREADTYPE_INFREQUENT_POLLER, 0, "DiskIntegrity");
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync AssertRC(rc);
3e88c818fff5c64b5eff43d5daf4596bd87230c5vboxsync }
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
bf27591c0d413dd4d7ba41cf89f117171968d462vboxsync return rc;
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync}
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync/**
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync * Block driver registration record.
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsyncconst PDMDRVREG g_DrvDiskIntegrity =
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync{
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /* u32Version */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PDM_DRVREG_VERSION,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /* szName */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync "DiskIntegrity",
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /* szRCMod */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync "",
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /* szR0Mod */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync "",
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /* pszDescription */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync "Disk integrity driver.",
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /* fFlags */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /* fClass. */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PDM_DRVREG_CLASS_BLOCK,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /* cMaxInstances */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync ~0,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /* cbInstance */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync sizeof(DRVDISKINTEGRITY),
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /* pfnConstruct */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync drvdiskintConstruct,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /* pfnDestruct */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync drvdiskintDestruct,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /* pfnRelocate */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync NULL,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /* pfnIOCtl */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync NULL,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /* pfnPowerOn */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync NULL,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /* pfnReset */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync NULL,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /* pfnSuspend */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync NULL,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /* pfnResume */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync NULL,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /* pfnAttach */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync NULL,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /* pfnDetach */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync NULL,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /* pfnPowerOff */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync NULL,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /* pfnSoftReset */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync NULL,
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync /* u32EndVersion */
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync PDM_DRVREG_VERSION
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync};
fb7b8c126ea3bc0adf9dd2b2b6a43870ee41853avboxsync