/* $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>
#include <VBox/vd-ifs-internal.h>
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/**
* The internal data of an VD I/O to VFS file or I/O stream wrapper.
*/
typedef struct VDIFVFSIOSFILE
{
/** The VD I/O interface we prefer wrap.
* Can be NULL, in which case pVDIfsIoInt must be valid. */
/** The VD I/O interface we alternatively can wrap.
Can be NULL, in which case pVDIfsIo must be valid. */
/** User pointer to pass to the VD I/O interface methods. */
/** The current stream position. */
/** Pointer to a the internal data of a DVM volume file. */
/**
* @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;
rc = vdIfIoFileReadSync(pThis->pVDIfsIo, pThis->pStorage, off, pSgBuf[0].pvSegCur, pSgBuf->paSegs[0].cbSeg, pcbRead);
else
{
rc = vdIfIoIntFileReadSync(pThis->pVDIfsIoInt, (PVDIOSTORAGE)pThis->pStorage, off, pSgBuf[0].pvSegCur, pSgBuf->paSegs[0].cbSeg);
if (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;
rc = vdIfIoFileWriteSync(pThis->pVDIfsIo, pThis->pStorage, off, pSgBuf[0].pvSegCur, pSgBuf->paSegs[0].cbSeg, pcbWritten);
else
{
rc = vdIfIoIntFileWriteSync(pThis->pVDIfsIoInt, pThis->pStorage, off, pSgBuf[0].pvSegCur, pSgBuf->paSegs[0].cbSeg);
if (pcbWritten)
}
if (RT_SUCCESS(rc))
return rc;
}
/**
* @interface_method_impl{RTVFSIOSTREAMOPS,pfnFlush}
*/
{
int rc;
else
return rc;
}
/**
* @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;
}
/**
* VFS I/O stream operations for a VD file or stream.
*/
{
{ /* 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;
}
/**
* @interface_method_impl{RTVFSOBJSETOPS,pfnMode}
*/
{
return VERR_NOT_SUPPORTED;
}
/**
* @interface_method_impl{RTVFSOBJSETOPS,pfnSetTimes}
*/
static DECLCALLBACK(int) vdIfVfsFile_SetTimes(void *pvThis, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
{
return VERR_NOT_SUPPORTED;
}
/**
* @interface_method_impl{RTVFSOBJSETOPS,pfnSetOwner}
*/
{
return VERR_NOT_SUPPORTED;
}
/**
* @interface_method_impl{RTVFSFILEOPS,pfnSeek}
*/
static DECLCALLBACK(int) vdIfVfsFile_Seek(void *pvThis, RTFOFF offSeek, unsigned uMethod, PRTFOFF poffActual)
{
int rc;
else
if (RT_FAILURE(rc))
return rc;
cbFile = RTFOFF_MAX;
/* Recalculate the request to RTFILE_SEEK_BEGIN. */
switch (uMethod)
{
case RTFILE_SEEK_BEGIN:
break;
case RTFILE_SEEK_CURRENT:
break;
case RTFILE_SEEK_END:
break;
default:
}
/* Do limit checks. */
if (offSeek < 0)
offSeek = 0;
/* Apply and return. */
if (poffActual)
*poffActual = offSeek;
return VINF_SUCCESS;
}
/**
* @interface_method_impl{RTVFSFILEOPS,pfnQuerySize}
*/
{
int rc;
else
return rc;
}
/**
* VFS file operations for a VD file.
*/
{
{ /* I/O stream */
{ /* Obj */
"VDIfFile",
},
NULL /*Skip*/,
NULL /*ZeroFill*/,
},
0,
{ /* ObjSet */
},
};
VBOXDDU_DECL(int) VDIfCreateVfsFile(PVDINTERFACEIO pVDIfs, struct VDINTERFACEIOINT *pVDIfsInt, void *pvStorage, uint32_t fFlags, PRTVFSFILE phVfsFile)
{
AssertReturn((pVDIfs != NULL) != (pVDIfsInt != NULL), VERR_INVALID_PARAMETER); /* Exactly one needs to be specified. */
/*
* Create the volume file.
*/
if (RT_SUCCESS(rc))
{
return VINF_SUCCESS;
}
return rc;
}