VirtualBox

Changeset 77235 in vbox for trunk/src/VBox/Runtime/generic


Ignore:
Timestamp:
Feb 9, 2019 6:30:14 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
128742
Message:

IPRT: Implemented RTFileSgWriteAt and RTfileSgReadAt for linux and freebsd. Clearified RTFileWriteAt and RTFileSgWriteAt specs wrt RTFILE_O_APPEND. bugref:9172

Location:
trunk/src/VBox/Runtime/generic
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/generic/fileio-at-generic.cpp

    r77209 r77235  
    3636
    3737
    38 /**
    39  * Read bytes from a file at a given offset.
    40  * This function may modify the file position.
    41  *
    42  * @returns iprt status code.
    43  * @param   File        Handle to the file.
    44  * @param   off         Where to read.
    45  * @param   pvBuf       Where to put the bytes we read.
    46  * @param   cbToRead    How much to read.
    47  * @param   *pcbRead    How much we actually read.
    48  *                      If NULL an error will be returned for a partial read.
    49  */
    5038RTDECL(int)  RTFileReadAt(RTFILE File, RTFOFF off, void *pvBuf, size_t cbToRead, size_t *pcbRead)
    5139{
     
    5745
    5846
    59 /**
    60  * Write bytes to a file at a given offset.
    61  * This function may modify the file position.
    62  *
    63  * @returns iprt status code.
    64  * @param   File        Handle to the file.
    65  * @param   off         Where to write.
    66  * @param   pvBuf       What to write.
    67  * @param   cbToWrite   How much to write.
    68  * @param   *pcbWritten How much we actually wrote.
    69  *                      If NULL an error will be returned for a partial write.
    70  */
    7147RTDECL(int)  RTFileWriteAt(RTFILE File, RTFOFF off, const void *pvBuf, size_t cbToWrite, size_t *pcbWritten)
    7248{
  • trunk/src/VBox/Runtime/generic/fileio-sg-generic.cpp

    r77209 r77235  
    3232#include <iprt/file.h>
    3333
    34 #include <iprt/errcore.h>
     34#include <iprt/assert.h>
     35#include <iprt/err.h>
    3536
    3637
    37 /**
    38  * Read bytes from a file at a given offset into a S/G buffer.
    39  * This function may modify the file position.
    40  *
    41  * @returns iprt status code.
    42  * @param   hFile       Handle to the file.
    43  * @param   off         Where to read.
    44  * @param   pSgBuf      Pointer to the S/G buffer to read into.
    45  * @param   cbToRead    How much to read.
    46  * @param   pcbRead     How much we actually read.
    47  *                      If NULL an error will be returned for a partial read.
    48  */
    4938RTDECL(int)  RTFileSgReadAt(RTFILE hFile, RTFOFF off, PRTSGBUF pSgBuf, size_t cbToRead, size_t *pcbRead)
    5039{
     
    5443    {
    5544        size_t cbBuf = cbToRead;
    56         void  *pvBuf = RTSgBufGetNextSegment(pSgBuf, &cbBuf);
     45        void  *pvBuf = RTSgBufGetNextSegment(pSgBuf, &cbBuf); /** @todo this is wrong as it may advance the buffer past what's actually read. */
    5746
    58         size_t cbThisRead = 0;
     47        size_t cbThisRead = cbBuf;
    5948        rc = RTFileReadAt(hFile, off, pvBuf, cbBuf, pcbRead ? &cbThisRead : NULL);
    6049        if (RT_SUCCESS(rc))
     
    6251        else
    6352            break;
    64         if (   cbThisRead < cbBuf
    65             && pcbRead)
     53        if (cbThisRead < cbBuf)
     54        {
     55            AssertStmt(pcbRead, rc = VERR_INTERNAL_ERROR_2);
    6656            break;
     57        }
     58        Assert(cbBuf == cbThisRead);
    6759
    6860        cbToRead -= cbBuf;
    69         off += cbBuf;
     61        off      += cbBuf;
    7062    }
    7163
     
    7769
    7870
    79 /**
    80  * Write bytes from a S/G buffer to a file at a given offset.
    81  * This function may modify the file position.
    82  *
    83  * @returns iprt status code.
    84  * @param   hFile       Handle to the file.
    85  * @param   off         Where to write.
    86  * @param   pSgBuf      What to write.
    87  * @param   cbToWrite   How much to write.
    88  * @param   pcbWritten  How much we actually wrote.
    89  *                      If NULL an error will be returned for a partial write.
    90  */
    9171RTDECL(int)  RTFileSgWriteAt(RTFILE hFile, RTFOFF off, PRTSGBUF pSgBuf, size_t cbToWrite, size_t *pcbWritten)
    9272{
     
    9676    {
    9777        size_t cbBuf = cbToWrite;
    98         void  *pvBuf = RTSgBufGetNextSegment(pSgBuf, &cbBuf);
     78        void  *pvBuf = RTSgBufGetNextSegment(pSgBuf, &cbBuf); /** @todo this is wrong as it may advance the buffer past what's actually read. */
    9979
    100         size_t cbThisWritten = 0;
     80        size_t cbThisWritten = cbBuf;
    10181        rc = RTFileWriteAt(hFile, off, pvBuf, cbBuf, pcbWritten ? &cbThisWritten : NULL);
    10282        if (RT_SUCCESS(rc))
     
    10484        else
    10585            break;
    106         if (   cbThisWritten < cbBuf
    107             && pcbWritten)
     86        if (cbThisWritten < cbBuf)
     87        {
     88            AssertStmt(pcbWritten, rc = VERR_INTERNAL_ERROR_2);
    10889            break;
     90        }
    10991
     92        Assert(cbBuf == cbThisWritten);
    11093        cbToWrite -= cbBuf;
    111         off += cbBuf;
     94        off       += cbBuf;
    11295    }
    11396
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