VDIfVfs.cpp revision ab72c8adeca8d8053cacd95ad7afe3328cb6f86a
/* $Id$ */
/** @file
* Virtual Disk Image (VDI), I/O interface to IPRT VFS I/O stream glue.
*/
/*
* Copyright (C) 2012-2013 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <iprt/vfslowlevel.h>
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/**
* The internal data of a DVM volume I/O stream.
*/
typedef struct VDIFVFSIOS
{
/** The VD I/O interface we wrap. */
/** User pointer to pass to the VD I/O interface methods. */
void *pvStorage;
/** The current stream position relative to the VDIfCreateVfsStream call. */
} VDIFVFSIOS;
/** Pointer to a the internal data of a DVM volume file. */
typedef VDIFVFSIOS *PVDIFVFSIOS;
/**
* @interface_method_impl{RTVFSOBJOPS,pfnClose}
*/
{
/* We don't close anything. */
return VINF_SUCCESS;
}
/**
* @interface_method_impl{RTVFSOBJOPS,pfnQueryInfo}
*/
static DECLCALLBACK(int) vdIfVfsIos_QueryInfo(void *pvThis, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr)
{
return VERR_NOT_SUPPORTED;
}
/**
* @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead}
*/
static DECLCALLBACK(int) vdIfVfsIos_Read(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
{
/*
* This may end up being a little more complicated, esp. wrt VERR_EOF.
*/
if (off == -1)
int rc = vdIfIoFileReadSync(pThis->pVDIfsIo, pThis->pvStorage, off, pSgBuf[0].pvSegCur, pSgBuf->paSegs[0].cbSeg, pcbRead);
if (RT_SUCCESS(rc))
return rc;
}
/**
* @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite}
*/
static DECLCALLBACK(int) vdIfVfsIos_Write(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
{
/*
* This may end up being a little more complicated, esp. wrt VERR_EOF.
*/
if (off == -1)
int rc = vdIfIoFileWriteSync(pThis->pVDIfsIo, pThis->pvStorage, off, pSgBuf[0].pvSegCur, pSgBuf->paSegs[0].cbSeg, pcbWritten);
if (RT_SUCCESS(rc))
return rc;
}
/**
* @interface_method_impl{RTVFSIOSTREAMOPS,pfnFlush}
*/
{
}
/**
* @interface_method_impl{RTVFSIOSTREAMOPS,pfnPollOne}
*/
static DECLCALLBACK(int) vdIfVfsIos_PollOne(void *pvThis, uint32_t fEvents, RTMSINTERVAL cMillies, bool fIntr,
{
int rc;
if (fEvents != RTPOLL_EVT_ERROR)
{
rc = VINF_SUCCESS;
}
else
return rc;
}
/**
* @interface_method_impl{RTVFSIOSTREAMOPS,pfnTell}
*/
{
return VINF_SUCCESS;
}
/**
* Standard file operations.
*/
{
{ /* Obj */
"VDIfIos",
},
NULL /*Skip*/,
NULL /*ZeroFill*/,
};
VBOXDDU_DECL(int) VDIfCreateVfsStream(PVDINTERFACEIO pVDIfsIo, void *pvStorage, uint32_t fFlags, PRTVFSIOSTREAM phVfsIos)
{
/*
* Create the volume file.
*/
if (RT_SUCCESS(rc))
{
return VINF_SUCCESS;
}
return rc;
}