VirtualBox

Changeset 34786 in vbox


Ignore:
Timestamp:
Dec 7, 2010 2:49:17 PM (14 years ago)
Author:
vboxsync
Message:

iprt: Implemented most of the RTVfsFile API.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/err.h

    r34418 r34786  
    660660/** The alignment is not really supported, however we got lucky with this
    661661 * allocation. */
    662 #define VINF_UNSUPPORTED_ALIGNMENT          (97)
    663 
     662#define VINF_UNSUPPORTED_ALIGNMENT          97
     663/** Duplicate something. */
     664#define VERR_DUPLICATE                      (-98)
     665/** Something is missing. */
     666#define VERR_MISSING                        (-99)
    664667/** @} */
    665668
     
    751754/** Device or resource is busy. */
    752755#define VERR_RESOURCE_BUSY                  (-138)
     756/** A file operation was attempted on a non-file object. */
     757#define VERR_NOT_A_FILE                     (-139)
     758/** A non-file operation was attempted on a file object. */
     759#define VERR_IS_A_FILE                      (-140)
     760/** Unexpected filesystem object type. */
     761#define VERR_UNEXPECTED_FS_OBJ_TYPE         (-141)
     762/** A path does not start with a root specification. */
     763#define VERR_PATH_DOES_NOT_START_WITH_ROOT  (-142)
     764/** A path is relative, expected an absolute path. */
     765#define VERR_PATH_IS_RELATIVE               (-143)
     766/** A path is not relative (start with root), expected an relative path. */
     767#define VERR_PATH_IS_NOT_RELATIVE           (-144)
    753768/** @} */
    754769
     
    13771392 * @{ */
    13781393/** The VFS chain specification does not have a valid prefix. */
    1379 #define VERR_VFS_CHAIN_NO_PREFIX                (-22100)
     1394#define VERR_VFS_CHAIN_NO_PREFIX                    (-22100)
    13801395/** The VFS chain specification is empty. */
    13811396#define VERR_VFS_CHAIN_EMPTY                        (-22101)
    13821397/** Expected an element. */
    1383 #define VERR_VFS_CHAIN_EXPECTED_ELEMENT              (-22102)
     1398#define VERR_VFS_CHAIN_EXPECTED_ELEMENT             (-22102)
    13841399/** The VFS object type is not known. */
    13851400#define VERR_VFS_CHAIN_UNKNOWN_TYPE                 (-22103)
  • trunk/include/iprt/vfs.h

    r34535 r34786  
    149149 * @param   pObjInfo        Where to return the info.
    150150 * @param   enmAddAttr      Which additional attributes should be retrieved.
    151  * @sa      RTFileQueryInfo, RTPathQueryInfo
     151 * @sa      RTVfsIoStrmQueryInfo, RTVfsFileQueryInfo, RTFileQueryInfo,
     152 *          RTPathQueryInfo
    152153 */
    153154RTDECL(int)             RTVfsObjQueryInfo(RTVFSOBJ hVfsObj, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr);
     
    516517 * @param   pcbRead         Where to always store the number of bytes actually
    517518 *                          read.  This can be NULL if @a fBlocking is true.
    518  * @sa      RTFileRead, RTPipeRead, RTPipeReadBlocking, RTSocketRead
     519 * @sa      RTVfsFileRead, RTFileRead, RTPipeRead, RTPipeReadBlocking,
     520 *          RTSocketRead
    519521 */
    520522RTDECL(int) RTVfsIoStrmRead(RTVFSIOSTREAM hVfsIos, void *pvBuf, size_t cbToRead, bool fBlocking, size_t *pcbRead);
     
    533535 * @param   pcbRead         Where to always store the number of bytes actually
    534536 *                          written.  This can be NULL if @a fBlocking is true.
    535  * @sa      RTFileWrite, RTPipeWrite, RTPipeWriteBlocking, RTSocketWrite
     537 * @sa      RTVfsFileWrite, RTFileWrite, RTPipeWrite, RTPipeWriteBlocking,
     538 *          RTSocketWrite
    536539 */
    537540RTDECL(int) RTVfsIoStrmWrite(RTVFSIOSTREAM hVfsIos, const void *pvBuf, size_t cbToWrite, bool fBlocking, size_t *pcbWritten);
     
    590593 * @returns IPRT status code.
    591594 * @param   hVfsIos         The VFS I/O stream handle.
    592  * @sa      RTFileFlush, RTPipeFlush
     595 * @sa      RTVfsFileFlush, RTFileFlush, RTPipeFlush
    593596 */
    594597RTDECL(int)         RTVfsIoStrmFlush(RTVFSIOSTREAM hVfsIos);
     
    605608 *                          should be hidden from the caller (@c false).
    606609 * @param   pfRetEvents     Where to return the event mask.
    607  * @sa      RTPollSetAdd, RTPoll, RTPollNoResume.
     610 * @sa      RTVfsFilePoll, RTPollSetAdd, RTPoll, RTPollNoResume.
    608611 */
    609612RTDECL(int)      RTVfsIoStrmPoll(RTVFSIOSTREAM hVfsIos, uint32_t fEvents, RTMSINTERVAL cMillies, bool fIntr,
     
    692695RTDECL(uint32_t)    RTVfsFileRelease(RTVFSFILE hVfsFile);
    693696
     697/**
     698 * Query information about the object.
     699 *
     700 * @returns IPRT status code.
     701 * @retval  VERR_NOT_SUPPORTED if the @a enmAddAttr value is not handled by the
     702 *          implementation.
     703 *
     704 * @param   hVfsObj         The VFS object handle.
     705 * @param   pObjInfo        Where to return the info.
     706 * @param   enmAddAttr      Which additional attributes should be retrieved.
     707 * @sa      RTVfsObjQueryInfo, RTVfsFsStrmQueryInfo, RTVfsDirQueryInfo,
     708 *          RTVfsIoStrmQueryInfo, RTVfsFileQueryInfo, RTFileQueryInfo,
     709 *          RTPathQueryInfo.
     710 */
    694711RTDECL(int)         RTVfsFileQueryInfo(RTVFSFILE hVfsFile, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr);
     712
     713/**
     714 * Read bytes from the file at the current position.
     715 *
     716 * @returns IPRT status code.
     717 * @retval  VINF_SUCCESS and the number of bytes read written to @a pcbRead.
     718 * @retval  VINF_TRY_AGAIN if @a fBlocking is @c false, @a pcbRead is not NULL,
     719 *          and no data was available. @a *pcbRead will be set to 0.
     720 * @retval  VINF_EOF when trying to read __beyond__ the end of the file and
     721 *          @a pcbRead is not NULL (it will be set to the number of bytes read,
     722 *          or 0 if the end of the file was reached before this call).
     723 *          When the last byte of the read request is the last byte in the
     724 *          file, this status code will not be used.  However, VINF_EOF is
     725 *          returned when attempting to read 0 bytes while standing at the end
     726 *          of the file.
     727 * @retval  VERR_EOF when trying to read __beyond__ the end of the file and
     728 *          @a pcbRead is NULL.
     729 * @retval  VERR_ACCESS_DENIED if the file is not readable.
     730 *
     731 * @param   hVfsFile        The VFS file handle.
     732 * @param   pvBuf           Where to store the read bytes.
     733 * @param   cbToRead        The number of bytes to read.
     734 * @param   fBlocking       Whether the call is blocking (@c true) or not.  If
     735 *                          not, the @a pcbRead parameter must not be NULL.
     736 * @param   pcbRead         Where to always store the number of bytes actually
     737 *                          read.  This can be NULL if @a fBlocking is true.
     738 * @sa      RTVfsIoStrmRead, RTFileRead, RTPipeRead, RTPipeReadBlocking,
     739 *          RTSocketRead
     740 */
    695741RTDECL(int)         RTVfsFileRead(RTVFSFILE hVfsFile, void *pvBuf, size_t cbToRead, size_t *pcbRead);
    696742RTDECL(int)         RTVfsFileReadAt(RTVFSFILE hVfsFile, RTFOFF off, void *pvBuf, size_t cbToRead, size_t *pcbRead);
     743
     744/**
     745 * Write bytes to the file at the current position.
     746 *
     747 * @returns IPRT status code.
     748 * @retval  VERR_ACCESS_DENIED if the file is not writable.
     749 *
     750 * @param   hVfsFile        The VFS file handle.
     751 * @param   pvBuf           The bytes to write.
     752 * @param   cbToWrite       The number of bytes to write.
     753 * @param   fBlocking       Whether the call is blocking (@c true) or not.  If
     754 *                          not, the @a pcbWritten parameter must not be NULL.
     755 * @param   pcbRead         Where to always store the number of bytes actually
     756 *                          written.  This can be NULL if @a fBlocking is true.
     757 * @sa      RTVfsIoStrmRead, RTFileWrite, RTPipeWrite, RTPipeWriteBlocking,
     758 *          RTSocketWrite
     759 */
    697760RTDECL(int)         RTVfsFileWrite(RTVFSFILE hVfsFile, const void *pvBuf, size_t cbToWrite, size_t *pcbWritten);
    698761RTDECL(int)         RTVfsFileWriteAt(RTVFSFILE hVfsFile, RTFOFF off, const void *pvBuf, size_t cbToWrite, size_t *pcbWritten);
     762
     763/**
     764 * Flush any buffered data to the file.
     765 *
     766 * @returns IPRT status code.
     767 * @param   hVfsFile        The VFS file handle.
     768 * @sa      RTVfsIoStrmFlush, RTFileFlush, RTPipeFlush
     769 */
    699770RTDECL(int)         RTVfsFileFlush(RTVFSFILE hVfsFile);
     771
     772/**
     773 * Poll for events.
     774 *
     775 * @returns IPRT status code.
     776 * @param   hVfsFile        The VFS file handle.
     777 * @param   fEvents         The events to poll for (RTPOLL_EVT_XXX).
     778 * @param   cMillies        How long to wait for event to eventuate.
     779 * @param   fIntr           Whether the wait is interruptible and can return
     780 *                          VERR_INTERRUPTED (@c true) or if this condition
     781 *                          should be hidden from the caller (@c false).
     782 * @param   pfRetEvents     Where to return the event mask.
     783 * @sa      RTVfsIoStrmPoll, RTPollSetAdd, RTPoll, RTPollNoResume.
     784 */
    700785RTDECL(RTFOFF)      RTVfsFilePoll(RTVFSFILE hVfsFile, uint32_t fEvents, RTMSINTERVAL cMillies, bool fIntr,
    701786                                  uint32_t *pfRetEvents);
     787
     788/**
     789 * Tells the current file position.
     790 *
     791 * @returns Zero or higher - where to return the file offset.  Values
     792 *          below zero are IPRT status codes (VERR_XXX).
     793 * @param   hVfsFile        The VFS file handle.
     794 * @sa      RTFileTell, RTVfsIoStrmTell.
     795 */
    702796RTDECL(RTFOFF)      RTVfsFileTell(RTVFSFILE hVfsFile);
    703797
  • trunk/src/VBox/Runtime/common/vfs/vfsbase.cpp

    r34535 r34786  
    24022402
    24032403
     2404RTDECL(int)         RTVfsFileQueryInfo(RTVFSFILE hVfsFile, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr)
     2405{
     2406    RTVFSFILEINTERNAL *pThis = hVfsFile;
     2407    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     2408    AssertReturn(pThis->uMagic == RTVFSFILE_MAGIC, VERR_INVALID_HANDLE);
     2409    return RTVfsObjQueryInfo(&pThis->Stream.Base, pObjInfo, enmAddAttr);
     2410}
     2411
     2412
     2413RTDECL(int)         RTVfsFileRead(RTVFSFILE hVfsFile, void *pvBuf, size_t cbToRead, size_t *pcbRead)
     2414{
     2415    AssertPtrNullReturn(pcbRead, VERR_INVALID_POINTER);
     2416    if (pcbRead)
     2417        *pcbRead = 0;
     2418    RTVFSFILEINTERNAL *pThis = hVfsFile;
     2419    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     2420    AssertReturn(pThis->uMagic == RTVFSFILE_MAGIC, VERR_INVALID_HANDLE);
     2421    return RTVfsIoStrmRead(&pThis->Stream, pvBuf, cbToRead, true /*fBlocking*/, pcbRead);
     2422}
     2423
     2424
     2425RTDECL(int)         RTVfsFileWrite(RTVFSFILE hVfsFile, const void *pvBuf, size_t cbToWrite, size_t *pcbWritten)
     2426{
     2427    AssertPtrNullReturn(pcbWritten, VERR_INVALID_POINTER);
     2428    if (pcbWritten)
     2429        *pcbWritten = 0;
     2430    RTVFSFILEINTERNAL *pThis = hVfsFile;
     2431    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     2432    AssertReturn(pThis->uMagic == RTVFSFILE_MAGIC, VERR_INVALID_HANDLE);
     2433    return RTVfsIoStrmWrite(&pThis->Stream, pvBuf, cbToWrite, true /*fBlocking*/, pcbWritten);
     2434}
     2435
     2436
     2437/// @todo RTDECL(int) RTVfsFileWriteAt(RTVFSFILE hVfsFile, RTFOFF off, const void *pvBuf, size_t cbToWrite, size_t *pcbWritten);
     2438/// @todo RTDECL(int) RTVfsFileReadAt(RTVFSFILE hVfsFile, RTFOFF off, void *pvBuf, size_t cbToRead, size_t *pcbRead);
     2439
     2440
     2441RTDECL(int) RTVfsFileFlush(RTVFSFILE hVfsFile)
     2442{
     2443    RTVFSFILEINTERNAL *pThis = hVfsFile;
     2444    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     2445    AssertReturn(pThis->uMagic == RTVFSFILE_MAGIC, VERR_INVALID_HANDLE);
     2446    return RTVfsIoStrmFlush(&pThis->Stream);
     2447}
     2448
     2449
     2450RTDECL(RTFOFF) RTVfsFilePoll(RTVFSFILE hVfsFile, uint32_t fEvents, RTMSINTERVAL cMillies, bool fIntr,
     2451                                  uint32_t *pfRetEvents)
     2452{
     2453    RTVFSFILEINTERNAL *pThis = hVfsFile;
     2454    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     2455    AssertReturn(pThis->uMagic == RTVFSFILE_MAGIC, VERR_INVALID_HANDLE);
     2456    return RTVfsIoStrmPoll(&pThis->Stream, fEvents, cMillies, fIntr, pfRetEvents);
     2457}
     2458
     2459
     2460RTDECL(RTFOFF) RTVfsFileTell(RTVFSFILE hVfsFile)
     2461{
     2462    RTVFSFILEINTERNAL *pThis = hVfsFile;
     2463    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     2464    AssertReturn(pThis->uMagic == RTVFSFILE_MAGIC, VERR_INVALID_HANDLE);
     2465    return RTVfsIoStrmTell(&pThis->Stream);
     2466}
     2467
     2468
    24042469RTDECL(int) RTVfsFileSeek(RTVFSFILE hVfsFile, RTFOFF offSeek, uint32_t uMethod, uint64_t *poffActual)
    24052470{
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette