VDVfs.cpp revision 377ed3e71eeab3a362770d7dd24327359e268aec
/* $Id$ */
/** @file
* Virtual Disk Container implementation. - VFS glue.
*/
/*
* Copyright (C) 2012 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 VDVFSFILE
{
/** The volume the VFS file belongs to. */
/** Current position. */
/** Flags given during creation. */
} VDVFSFILE;
/** Pointer to a the internal data of a DVM volume file. */
typedef VDVFSFILE *PVDVFSFILE;
/**
* VD read helper taking care of unaligned accesses.
*
* @return VBox status code.
* @param pDisk VD disk container.
* @param off Offset to start reading from.
* @param pvBuf Pointer to the buffer to read into.
* @param cbRead Amount of bytes to read.
*/
{
int rc = VINF_SUCCESS;
/* Take shortcut if possible. */
if ( off % 512 == 0
&& cbRead % 512 == 0)
else
{
/* Unaligned access, make it aligned. */
if (off % 512 != 0)
{
if (RT_SUCCESS(rc))
{
}
}
if ( RT_SUCCESS(rc)
{
if (RT_SUCCESS(rc))
{
pbBuf += cbReadAligned;
off += cbReadAligned;
cbRead -= cbReadAligned;
}
}
if ( RT_SUCCESS(rc)
&& cbRead)
{
if (RT_SUCCESS(rc))
}
}
return rc;
}
/**
* VD write helper taking care of unaligned accesses.
*
* @return VBox status code.
* @param pDisk VD disk container.
* @param off Offset to start writing to.
* @param pvBuf Pointer to the buffer to read from.
* @param cbWrite Amount of bytes to write.
*/
{
int rc = VINF_SUCCESS;
/* Take shortcut if possible. */
if ( off % 512 == 0
&& cbWrite % 512 == 0)
else
{
/* Unaligned access, make it aligned. */
if (off % 512 != 0)
{
if (RT_SUCCESS(rc))
{
}
}
if ( RT_SUCCESS(rc)
{
if (RT_SUCCESS(rc))
{
pbBuf += cbWriteAligned;
off += cbWriteAligned;
}
}
if ( RT_SUCCESS(rc)
&& cbWrite)
{
if (RT_SUCCESS(rc))
{
}
}
}
return rc;
}
/**
* @interface_method_impl{RTVFSOBJOPS,pfnClose}
*/
{
return VINF_SUCCESS;
}
/**
* @interface_method_impl{RTVFSOBJOPS,pfnQueryInfo}
*/
{
return VERR_NOT_SUPPORTED;
}
/**
* @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead}
*/
static DECLCALLBACK(int) vdVfsFile_Read(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
{
int rc = VINF_SUCCESS;
/*
* Find the current position and check if it's within the volume.
*/
{
if (pcbRead)
{
*pcbRead = 0;
return VINF_EOF;
}
return VERR_EOF;
}
{
if (!pcbRead)
return VERR_EOF;
}
else
{
if (pcbRead)
*pcbRead = cbLeftToRead;
}
/*
* Ok, we've got a valid stretch within the file. Do the reading.
*/
if (cbLeftToRead > 0)
{
if (RT_SUCCESS(rc))
}
return rc;
}
/**
* @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite}
*/
static DECLCALLBACK(int) vdVfsFile_Write(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
{
int rc = VINF_SUCCESS;
/*
* Find the current position and check if it's within the volume.
* Writing beyond the end of a volume is not supported.
*/
{
if (pcbWritten)
{
*pcbWritten = 0;
}
return VERR_NOT_SUPPORTED;
}
{
if (!pcbWritten)
return VERR_EOF;
}
else
{
if (pcbWritten)
}
/*
* Ok, we've got a valid stretch within the file. Do the reading.
*/
if (cbLeftToWrite > 0)
{
if (RT_SUCCESS(rc))
}
return rc;
}
/**
* @interface_method_impl{RTVFSIOSTREAMOPS,pfnFlush}
*/
{
}
/**
* @interface_method_impl{RTVFSIOSTREAMOPS,pfnPollOne}
*/
static DECLCALLBACK(int) vdVfsFile_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;
}
/**
* @interface_method_impl{RTVFSOBJSETOPS,pfnMode}
*/
{
return VERR_NOT_SUPPORTED;
}
/**
* @interface_method_impl{RTVFSOBJSETOPS,pfnSetTimes}
*/
static DECLCALLBACK(int) vdVfsFile_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) vdVfsFile_Seek(void *pvThis, RTFOFF offSeek, unsigned uMethod, PRTFOFF poffActual)
{
/*
* Seek relative to which position.
*/
switch (uMethod)
{
case RTFILE_SEEK_BEGIN:
offWrt = 0;
break;
case RTFILE_SEEK_CURRENT:
break;
case RTFILE_SEEK_END:
break;
default:
return VERR_INTERNAL_ERROR_5;
}
/*
* Calc new position, take care to stay within bounds.
*
* @todo: Setting position beyond the end of the disk does not make sense.
*/
if (offSeek == 0)
else if (offSeek > 0)
{
|| offNew > RTFOFF_MAX)
offNew = RTFOFF_MAX;
}
else
offNew = 0;
/*
* Update the state and set return value.
*/
*poffActual = offNew;
return VINF_SUCCESS;
}
/**
* @interface_method_impl{RTVFSFILEOPS,pfnQuerySize}
*/
{
return VINF_SUCCESS;
}
/**
* Standard file operations.
*/
{
{ /* Stream */
{ /* Obj */
"VDFile",
},
NULL /*Skip*/,
NULL /*ZeroFill*/,
},
/*RTVFSIOFILEOPS_FEAT_NO_AT_OFFSET*/ 0,
{ /* ObjSet */
},
};
{
/*
* Create the volume file.
*/
int rc = RTVfsNewFile(&g_vdVfsStdFileOps, sizeof(*pThis), RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_WRITE,
if (RT_SUCCESS(rc))
{
return VINF_SUCCESS;
}
return rc;
}