vfsstdfile.cpp revision 4e38f78b4916ef128a3902ed2a8d7e8d7f947d8d
/* $Id$ */
/** @file
* IPRT - Virtual File System, Standard File Implementation.
*/
/*
* Copyright (C) 2010 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.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <iprt/vfslowlevel.h>
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/**
* Private data of a standard file.
*/
typedef struct RTVFSSTDFILE
{
/** The file handle. */
/** Whether to leave the handle open when the VFS handle is closed. */
bool fLeaveOpen;
} RTVFSSTDFILE;
/** Pointer to the private data of a standard file. */
typedef RTVFSSTDFILE *PRTVFSSTDFILE;
/**
* @interface_method_impl{RTVFSOBJOPS,pfnClose}
*/
{
int rc;
if (!pThis->fLeaveOpen)
else
rc = VINF_SUCCESS;
return rc;
}
/**
* @interface_method_impl{RTVFSOBJOPS,pfnQueryInfo}
*/
static DECLCALLBACK(int) rtVfsStdFile_QueryInfo(void *pvThis, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr)
{
}
/**
* @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead}
*/
static DECLCALLBACK(int) rtVfsStdFile_Read(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
{
int rc;
{
if (off < 0)
else
}
else
{
{
cbReadSeg = 0;
if (off < 0)
else
{
}
if (RT_FAILURE(rc))
break;
if (pcbRead)
{
break;
}
}
if (pcbRead)
}
return rc;
}
/**
* @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite}
*/
static DECLCALLBACK(int) rtVfsStdFile_Write(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
{
int rc;
{
if (off < 0)
else
rc = RTFileWriteAt(pThis->hFile, off, pSgBuf->paSegs[0].pvSeg, pSgBuf->paSegs[0].cbSeg, pcbWritten);
}
else
{
{
cbWrittenSeg = 0;
if (off < 0)
else
{
}
if (RT_FAILURE(rc))
break;
if (pcbWritten)
{
if (cbWrittenSeg != cbSeg)
break;
}
}
if (pcbWritten)
*pcbWritten = cbWritten;
}
return rc;
}
/**
* @interface_method_impl{RTVFSIOSTREAMOPS,pfnFlush}
*/
{
}
/**
* @interface_method_impl{RTVFSIOSTREAMOPS,pfnPollOne}
*/
static DECLCALLBACK(int) rtVfsStdFile_PollOne(void *pvThis, uint32_t fEvents, RTMSINTERVAL cMillies, bool fIntr,
{
int rc;
if (fEvents != RTPOLL_EVT_ERROR)
{
rc = VINF_SUCCESS;
}
else if (fIntr)
else
{
do
while ( rc == VERR_INTERRUPTED
&& !fIntr
if (rc == VERR_INTERRUPTED)
rc = VERR_TIMEOUT;
}
return rc;
}
/**
* @interface_method_impl{RTVFSIOSTREAMOPS,pfnTell}
*/
{
}
/**
* @interface_method_impl{RTVFSOBJSETOPS,pfnMode}
*/
{
if (fMask != ~RTFS_TYPE_MASK)
{
#if 0
if (RT_FAILURE(rc))
return rc;
#else
if (RT_FAILURE(rc))
return rc;
#endif
}
}
/**
* @interface_method_impl{RTVFSOBJSETOPS,pfnSetTimes}
*/
static DECLCALLBACK(int) rtVfsStdFile_SetTimes(void *pvThis, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
{
}
/**
* @interface_method_impl{RTVFSOBJSETOPS,pfnSetOwner}
*/
{
#if 0
#else
return VERR_NOT_IMPLEMENTED;
#endif
}
/**
* @interface_method_impl{RTVFSFILEOPS,pfnSeek}
*/
static DECLCALLBACK(int) rtVfsStdFile_Seek(void *pvThis, RTFOFF offSeek, unsigned uMethod, PRTFOFF poffActual)
{
if (RT_SUCCESS(rc))
*poffActual = offActual;
return rc;
}
/**
* @interface_method_impl{RTVFSFILEOPS,pfnQuerySize}
*/
{
}
/**
* Standard file operations.
*/
{
{ /* Stream */
/** The basic object operation. */
{ /* Obj */
"StdFile",
},
0,
},
0,
{ /* ObjSet */
},
};
RTDECL(int) RTVfsFileFromRTFile(RTFILE hFile, uint32_t fOpen, bool fLeaveOpen, PRTVFSFILE phVfsFile)
{
/*
* Check the handle validity.
*/
if (RT_FAILURE(rc))
return rc;
/*
* Set up some fake fOpen flags.
*/
if (!fOpen)
/*
* Create the handle.
*/
rc = RTVfsNewFile(&g_rtVfsStdFileOps, sizeof(RTVFSSTDFILE), fOpen, NIL_RTVFS, &hVfsFile, (void **)&pThis);
if (RT_FAILURE(rc))
return rc;
return VINF_SUCCESS;
}