5b281ba489ca18f0380d7efc7a5108b606cce449vboxsync * Virtual Disk Container implementation. - VFS glue.
c7814cf6e1240a519cbec0441e033d0e2470ed00vboxsync * Copyright (C) 2012 Oracle Corporation
1a9652a4f7c32959d02f920701281d08b4a6e39fvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
1a9652a4f7c32959d02f920701281d08b4a6e39fvboxsync * available from http://www.virtualbox.org. This file is free software;
1a9652a4f7c32959d02f920701281d08b4a6e39fvboxsync * you can redistribute it and/or modify it under the terms of the GNU
1a9652a4f7c32959d02f920701281d08b4a6e39fvboxsync * General Public License (GPL) as published by the Free Software
1a9652a4f7c32959d02f920701281d08b4a6e39fvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
1a9652a4f7c32959d02f920701281d08b4a6e39fvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
1a9652a4f7c32959d02f920701281d08b4a6e39fvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
1a9652a4f7c32959d02f920701281d08b4a6e39fvboxsync/*******************************************************************************
1a9652a4f7c32959d02f920701281d08b4a6e39fvboxsync* Header Files *
1a9652a4f7c32959d02f920701281d08b4a6e39fvboxsync*******************************************************************************/
1a9652a4f7c32959d02f920701281d08b4a6e39fvboxsync/*******************************************************************************
1a9652a4f7c32959d02f920701281d08b4a6e39fvboxsync* Structures and Typedefs *
1a9652a4f7c32959d02f920701281d08b4a6e39fvboxsync*******************************************************************************/
1a9652a4f7c32959d02f920701281d08b4a6e39fvboxsync * The internal data of a DVM volume I/O stream.
1a9652a4f7c32959d02f920701281d08b4a6e39fvboxsync /** The volume the VFS file belongs to. */
1a9652a4f7c32959d02f920701281d08b4a6e39fvboxsync /** Current position. */
1a9652a4f7c32959d02f920701281d08b4a6e39fvboxsync /** Flags given during creation. */
c4d8b97fbd2cf0b64eb691d8927a704eef129ce2vboxsync/** Pointer to a the internal data of a DVM volume file. */
1a9652a4f7c32959d02f920701281d08b4a6e39fvboxsync * VD read helper taking care of unaligned accesses.
1a9652a4f7c32959d02f920701281d08b4a6e39fvboxsync * @return VBox status code.
1a9652a4f7c32959d02f920701281d08b4a6e39fvboxsync * @param pDisk VD disk container.
1a9652a4f7c32959d02f920701281d08b4a6e39fvboxsync * @param off Offset to start reading from.
11cf162ce505996793736d2b9c7cf1e77ff015b9vboxsync * @param pvBuf Pointer to the buffer to read into.
1a9652a4f7c32959d02f920701281d08b4a6e39fvboxsync * @param cbRead Amount of bytes to read.
1a9652a4f7c32959d02f920701281d08b4a6e39fvboxsyncstatic int vdReadHelper(PVBOXHDD pDisk, uint64_t off, void *pvBuf, size_t cbRead)
1a9652a4f7c32959d02f920701281d08b4a6e39fvboxsync /* Take shortcut if possible. */
1a9652a4f7c32959d02f920701281d08b4a6e39fvboxsync /* Unaligned access, make it aligned. */
1a9652a4f7c32959d02f920701281d08b4a6e39fvboxsync size_t cbReadAligned = cbRead & ~(uint64_t)(512 - 1);
&& cbRead)
return rc;
&& cbWrite)
return rc;
return VINF_SUCCESS;
return VERR_NOT_SUPPORTED;
static DECLCALLBACK(int) vdVfsFile_Read(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
if (pcbRead)
*pcbRead = 0;
return VINF_EOF;
return VERR_EOF;
if (!pcbRead)
return VERR_EOF;
if (pcbRead)
if (cbLeftToRead > 0)
return rc;
static DECLCALLBACK(int) vdVfsFile_Write(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
if (pcbWritten)
*pcbWritten = 0;
return VERR_NOT_SUPPORTED;
if (!pcbWritten)
return VERR_EOF;
if (pcbWritten)
if (cbLeftToWrite > 0)
return rc;
static DECLCALLBACK(int) vdVfsFile_PollOne(void *pvThis, uint32_t fEvents, RTMSINTERVAL cMillies, bool fIntr,
return rc;
return VINF_SUCCESS;
return VERR_NOT_SUPPORTED;
static DECLCALLBACK(int) vdVfsFile_SetTimes(void *pvThis, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
return VERR_NOT_SUPPORTED;
return VERR_NOT_SUPPORTED;
static DECLCALLBACK(int) vdVfsFile_Seek(void *pvThis, RTFOFF offSeek, unsigned uMethod, PRTFOFF poffActual)
switch (uMethod)
case RTFILE_SEEK_BEGIN:
offWrt = 0;
case RTFILE_SEEK_CURRENT:
case RTFILE_SEEK_END:
return VERR_INTERNAL_ERROR_5;
if (offSeek == 0)
else if (offSeek > 0)
offNew = 0;
return VINF_SUCCESS;
return VINF_SUCCESS;
int rc = RTVfsNewFile(&g_vdVfsStdFileOps, sizeof(*pThis), RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_WRITE,
return VINF_SUCCESS;
return rc;