VirtualBox

Changeset 77632 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Mar 10, 2019 1:33:52 PM (6 years ago)
Author:
vboxsync
Message:

IPRT: Adding RTFileSgRead and RTFileSgWrite (for FsPerf). bugref:9172

Location:
trunk/src/VBox/Runtime
Files:
3 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/Makefile.kmk

    r77545 r77632  
    816816        generic/RTDirSetTimes-generic.cpp \
    817817        generic/fileio-sg-generic.cpp \
     818        generic/fileio-sg-at-generic.cpp \
    818819        generic/RTFileExists-generic.cpp \
    819820        generic/RTFileSetAllocationSize-generic.cpp \
     
    955956        r3/posix/fileio-at-posix.cpp \
    956957        r3/posix/fileio-sg-posix.cpp \
     958        r3/posix/fileio-sg-at-posix.cpp \
    957959        r3/posix/filelock-posix.cpp \
    958960        r3/posix/fs-posix.cpp \
     
    10091011        generic/fileio-at-generic.cpp \
    10101012        generic/fileio-sg-generic.cpp \
     1013        generic/fileio-sg-at-generic.cpp \
    10111014        generic/RTFileMove-generic.cpp \
    10121015        generic/RTFileSetAllocationSize-generic.cpp \
     
    11421145        r3/posix/fileio-at-posix.cpp \
    11431146        r3/posix/fileio-sg-posix.cpp \
     1147        r3/posix/fileio-sg-at-posix.cpp \
    11441148        r3/posix/fs-posix.cpp \
    11451149        r3/posix/fs2-posix.cpp \
     
    12221226        r3/posix/fileio-at-posix.cpp \
    12231227        r3/posix/fileio-sg-posix.cpp \
     1228        r3/posix/fileio-sg-at-posix.cpp \
    12241229        r3/posix/filelock-posix.cpp \
    12251230        r3/posix/fs-posix.cpp \
     
    13021307        r3/posix/fileio-at-posix.cpp \
    13031308        r3/posix/fileio-sg-posix.cpp \
     1309        r3/posix/fileio-sg-at-posix.cpp \
    13041310        r3/posix/filelock-posix.cpp \
    13051311        r3/posix/fs-posix.cpp \
     
    13731379        r3/posix/fileio-at-posix.cpp \
    13741380        r3/posix/fileio-sg-posix.cpp \
     1381        r3/posix/fileio-sg-at-posix.cpp \
    13751382        r3/posix/filelock-posix.cpp \
    13761383        r3/posix/fs-posix.cpp \
     
    14291436        generic/fileio-at-generic.cpp \
    14301437        generic/fileio-sg-generic.cpp \
     1438        generic/fileio-sg-at-generic.cpp \
    14311439        generic/RTFileMove-generic.cpp \
    14321440        generic/RTFileSetAllocationSize-generic.cpp \
  • trunk/src/VBox/Runtime/generic/fileio-sg-generic.cpp

    r77235 r77632  
    11/* $Id$ */
    22/** @file
    3  * IPRT - File I/O, RTFileSgReadAt & RTFileSgWriteAt, generic.
     3 * IPRT - File I/O, RTFileSgRead & RTFileSgWrite, generic.
    44 */
    55
     
    3636
    3737
    38 RTDECL(int)  RTFileSgReadAt(RTFILE hFile, RTFOFF off, PRTSGBUF pSgBuf, size_t cbToRead, size_t *pcbRead)
     38RTDECL(int)  RTFileSgRead(RTFILE hFile, PRTSGBUF pSgBuf, size_t cbToRead, size_t *pcbRead)
    3939{
    4040    int rc = VINF_SUCCESS;
     
    4646
    4747        size_t cbThisRead = cbBuf;
    48         rc = RTFileReadAt(hFile, off, pvBuf, cbBuf, pcbRead ? &cbThisRead : NULL);
     48        rc = RTFileRead(hFile, pvBuf, cbBuf, pcbRead ? &cbThisRead : NULL);
    4949        if (RT_SUCCESS(rc))
    5050            cbRead += cbThisRead;
     
    5959
    6060        cbToRead -= cbBuf;
    61         off      += cbBuf;
    6261    }
    6362
     
    6968
    7069
    71 RTDECL(int)  RTFileSgWriteAt(RTFILE hFile, RTFOFF off, PRTSGBUF pSgBuf, size_t cbToWrite, size_t *pcbWritten)
     70RTDECL(int)  RTFileSgWrite(RTFILE hFile, PRTSGBUF pSgBuf, size_t cbToWrite, size_t *pcbWritten)
    7271{
    7372    int rc = VINF_SUCCESS;
     
    7978
    8079        size_t cbThisWritten = cbBuf;
    81         rc = RTFileWriteAt(hFile, off, pvBuf, cbBuf, pcbWritten ? &cbThisWritten : NULL);
     80        rc = RTFileWrite(hFile, pvBuf, cbBuf, pcbWritten ? &cbThisWritten : NULL);
    8281        if (RT_SUCCESS(rc))
    8382            cbWritten += cbThisWritten;
     
    9291        Assert(cbBuf == cbThisWritten);
    9392        cbToWrite -= cbBuf;
    94         off       += cbBuf;
    9593    }
    9694
  • trunk/src/VBox/Runtime/r3/posix/fileio-sg-posix.cpp

    r77244 r77632  
    11/* $Id$ */
    22/** @file
    3  * IPRT - File I/O, RTFileSgReadAt & RTFileSgWriteAt, posixy.
     3 * IPRT - File I/O, RTFileSgRead & RTFileSgWrite, posixy.
    44 */
    55
     
    2929*   Header Files                                                                                                                 *
    3030*********************************************************************************************************************************/
    31 /*
    32  * Determin whether we've got preadv and pwritev.
    33  */
    3431#include <iprt/cdefs.h>
    35 #ifdef RT_OS_LINUX
    36 /* Linux has these since glibc 2.10 and Linux 2.6.30: */
    37 # include <features.h>
    38 # ifdef __GLIBC_PREREQ
    39 #  if __GLIBC_PREREQ(2,10)
    40 #   define HAVE_PREADV_AND_PWRITEV 1
    41 #else
    42 #  endif
    43 # endif
    44 
    45 #elif defined(RT_OS_FREEBSD)
    46 /* FreeBSD has these since 6.0: */
    47 # include <osreldate.h>
    48 # ifdef __FreeBSD_version
    49 #  if __FreeBSD_version >= 600000
    50 #   define HAVE_PREADV_AND_PWRITEV 1
    51 #  endif
    52 # endif
    53 
     32#include <errno.h>
     33#include <sys/types.h>
     34#include <sys/uio.h>
     35#include <unistd.h>
     36
     37#include "internal/iprt.h"
     38#include <iprt/file.h>
     39
     40#include <iprt/assert.h>
     41#include <iprt/err.h>
     42#include <iprt/log.h>
     43
     44#ifndef UIO_MAXIOV
     45# error "UIO_MAXIOV is undefined"
    5446#endif
    55 
    56 #ifndef HAVE_PREADV_AND_PWRITEV
    57 
    58 # include "../../generic/fileio-sg-generic.cpp"
    59 
    60 #else /* HAVE_PREADV_AND_PWRITEV - rest of the file */
    61 
    62 # include <errno.h>
    63 # include <sys/types.h>
    64 # include <sys/uio.h>
    65 # include <unistd.h>
    66 
    67 # include "internal/iprt.h"
    68 # include <iprt/file.h>
    69 
    70 # include <iprt/assert.h>
    71 # include <iprt/err.h>
    72 # include <iprt/log.h>
    73 
    74 # ifndef UIO_MAXIOV
    75 #  error "UIO_MAXIOV is undefined"
    76 # endif
    7747
    7848
     
    8252
    8353
    84 RTDECL(int)  RTFileSgReadAt(RTFILE hFile, RTFOFF off, PRTSGBUF pSgBuf, size_t cbToRead, size_t *pcbRead)
     54RTDECL(int)  RTFileSgRead(RTFILE hFile, PRTSGBUF pSgBuf, size_t cbToRead, size_t *pcbRead)
    8555{
    8656    /*
     
    9161
    9262    /*
    93      * Special case: Zero read == seek.
     63     * Special case: Zero read == nop.
    9464     */
    9565    if (cbToRead == 0)
    96         return RTFileSeek(hFile, off, RTFILE_SEEK_BEGIN, NULL);
     66        return VINF_SUCCESS;
    9767
    9868    /*
     
    10979        {
    11080            size_t const cSegsLeft  = pSgBuf->cSegs - pSgBuf->idxSeg;
    111             ssize_t      cbThisRead = preadv(RTFileToNative(hFile), (const struct iovec *)&pSgBuf->paSegs[pSgBuf->idxSeg],
    112                                              RT_MIN(cSegsLeft, UIO_MAXIOV), off);
     81            ssize_t      cbThisRead = readv(RTFileToNative(hFile), (const struct iovec *)&pSgBuf->paSegs[pSgBuf->idxSeg],
     82                                            RT_MIN(cSegsLeft, UIO_MAXIOV));
    11383            if (cbThisRead >= 0)
    11484            {
     
    134104                if (cbThisRead == 0)
    135105                    return VERR_EOF;
    136 
    137                 off += cbThisRead;
    138106            }
    139107            else if (cbTotalRead > 0 && pcbRead)
     
    156124        void  *pvSeg = RTSgBufGetCurrentSegment(pSgBuf, cbToRead, &cbSeg);
    157125        size_t cbThisRead = cbSeg;
    158         rc = RTFileReadAt(hFile, off, pvSeg, cbSeg, pcbRead ? &cbThisRead : NULL);
     126        rc = RTFileRead(hFile, pvSeg, cbSeg, pcbRead ? &cbThisRead : NULL);
    159127        if (RT_SUCCESS(rc))
    160128        {
     
    172140        Assert(cbSeg == cbThisRead);
    173141        cbToRead -= cbSeg;
    174         off      += cbSeg;
    175142    }
    176143    if (pcbRead)
     
    180147
    181148
    182 RTDECL(int)  RTFileSgWriteAt(RTFILE hFile, RTFOFF off, PRTSGBUF pSgBuf, size_t cbToWrite, size_t *pcbWritten)
     149RTDECL(int)  RTFileSgWrite(RTFILE hFile, PRTSGBUF pSgBuf, size_t cbToWrite, size_t *pcbWritten)
    183150{
    184151    /*
     
    189156
    190157    /*
    191      * Special case: Zero write == seek.
     158     * Special case: Zero write == nop.
    192159     */
    193160    if (cbToWrite == 0)
    194         return RTFileSeek(hFile, off, RTFILE_SEEK_BEGIN, NULL);
     161        return VINF_SUCCESS;
    195162
    196163    /*
     
    207174        {
    208175            size_t const cSegsLeft     = pSgBuf->cSegs - pSgBuf->idxSeg;
    209             ssize_t      cbThisWritten = pwritev(RTFileToNative(hFile), (const struct iovec *)&pSgBuf->paSegs[pSgBuf->idxSeg],
    210                                                  RT_MIN(cSegsLeft, UIO_MAXIOV), off);
     176            ssize_t      cbThisWritten = writev(RTFileToNative(hFile), (const struct iovec *)&pSgBuf->paSegs[pSgBuf->idxSeg],
     177                                                RT_MIN(cSegsLeft, UIO_MAXIOV));
    211178            if (cbThisWritten >= 0)
    212179            {
     
    232199                if (cbThisWritten == 0)
    233200                    return VERR_TRY_AGAIN;
    234 
    235                 off += cbThisWritten;
    236201            }
    237202            else if (cbTotalWritten > 0 && pcbWritten)
     
    254219        void  *pvSeg = RTSgBufGetCurrentSegment(pSgBuf, cbToWrite, &cbSeg);
    255220        size_t cbThisWritten = cbSeg;
    256         rc = RTFileWriteAt(hFile, off, pvSeg, cbSeg, pcbWritten ? &cbThisWritten : NULL);
     221        rc = RTFileWrite(hFile, pvSeg, cbSeg, pcbWritten ? &cbThisWritten : NULL);
    257222        if (RT_SUCCESS(rc))
    258223        {
     
    270235        Assert(cbSeg == cbThisWritten);
    271236        cbToWrite -= cbSeg;
    272         off       += cbSeg;
    273237    }
    274238    if (pcbWritten)
     
    277241}
    278242
    279 #endif /* HAVE_PREADV_AND_PWRITEV */
    280 
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