VirtualBox

Changeset 33973 in vbox


Ignore:
Timestamp:
Nov 11, 2010 11:10:10 AM (14 years ago)
Author:
vboxsync
Message:

vfs: the gunzip stream works, except for some double frees somewhere.

Location:
trunk
Files:
3 added
13 edited

Legend:

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

    r28800 r33973  
    4747RTDECL(int) RTHandleClose(PRTHANDLE ph);
    4848
     49/**
     50 * Gets one of the standard handles.
     51 *
     52 * @returns IPRT status code.
     53 * @param   enmStdHandle    The standard handle.
     54 * @param   ph              Pointer to the generic handle.  This will contain
     55 *                          the most appropriate IPRT handle on success.
     56 */
     57RTDECL(int) RTHandleGetStandard(RTHANDLESTD enmStdHandle, PRTHANDLE ph);
     58
    4959/** @} */
    5060
  • trunk/include/iprt/pipe.h

    r28800 r33973  
    8888#define RTPIPE_N_INHERIT            RT_BIT(2)
    8989/** Mask of valid flags. */
    90 #define RTPIPE_N_VALID_MASK         UINT32_C(0x00000003)
     90#define RTPIPE_N_VALID_MASK         UINT32_C(0x00000007)
    9191/** @} */
    9292
  • trunk/include/iprt/types.h

    r33871 r33973  
    14821482#define RTSTRCACHE_DEFAULT                          ((RTSTRCACHE)-2)
    14831483
     1484
     1485/** Virtual Filesystem handle. */
     1486typedef struct RTVFSINTERNAL                       *RTVFS;
     1487/** Pointer to a VFS handle. */
     1488typedef RTVFS                                      *PRTVFS;
     1489/** A NIL VFS handle. */
     1490#define NIL_RTVFS                                   ((RTVFS)~(uintptr_t)0)
     1491
     1492/** Virtual Filesystem base object handle. */
     1493typedef struct RTVFSOBJINTERNAL                    *RTVFSOBJ;
     1494/** Pointer to a VFS base object handle. */
     1495typedef RTVFSOBJ                                   *PRTVFSOBJ;
     1496/** A NIL VFS base object handle. */
     1497#define NIL_RTVFSOBJ                                ((RTVFSOBJ)~(uintptr_t)0)
     1498
     1499/** Virtual Filesystem directory handle. */
     1500typedef struct RTVFSDIRINTERNAL                    *RTVFSDIR;
     1501/** Pointer to a VFS directory handle. */
     1502typedef RTVFSDIR                                   *PRTVFSDIR;
     1503/** A NIL VFS directory handle. */
     1504#define NIL_RTVFSDIR                                ((RTVFSDIR)~(uintptr_t)0)
     1505
     1506/** Virtual Filesystem filesystem stream handle. */
     1507typedef struct RTVFSFSSTREAMINTERNAL               *RTVFSFSSTREAM;
     1508/** Pointer to a VFS filesystem stream handle. */
     1509typedef RTVFSFSSTREAM                              *PRTVFSFSSTREAM;
     1510/** A NIL VFS filesystem stream handle. */
     1511#define NIL_RTVFSFSSTREAM                           ((RTVFSFSSTREAM)~(uintptr_t)0)
     1512
     1513/** Virtual Filesystem I/O stream handle. */
     1514typedef struct RTVFSIOSTREAMINTERNAL               *RTVFSIOSTREAM;
     1515/** Pointer to a VFS I/O stream handle. */
     1516typedef RTVFSIOSTREAM                              *PRTVFSIOSTREAM;
     1517/** A NIL VFS I/O stream handle. */
     1518#define NIL_RTVFSIOSTREAM                           ((RTVFSIOSTREAM)~(uintptr_t)0)
     1519
     1520/** Virtual Filesystem file handle. */
     1521typedef struct RTVFSFILEINTERNAL                   *RTVFSFILE;
     1522/** Pointer to a VFS file handle. */
     1523typedef RTVFSFILE                                  *PRTVFSFILE;
     1524/** A NIL VFS file handle. */
     1525#define NIL_RTVFSFILE                               ((RTVFSFILE)~(uintptr_t)0)
     1526
     1527/** Virtual Filesystem symbolic link handle. */
     1528typedef struct RTVFSSYMLINKINTERNAL                *RTVFSSYMLINK;
     1529/** Pointer to a VFS symbolic link handle. */
     1530typedef RTVFSSYMLINK                               *PRTVFSSYMLINK;
     1531/** A NIL VFS symbolic link handle. */
     1532#define NIL_RTVFSSYMLINK                            ((RTVFSSYMLINK)~(uintptr_t)0)
     1533
     1534
    14841535/**
    14851536 * Handle type.
     
    15421593/** Pointer to a const generic handle. */
    15431594typedef RTHANDLE const *PCRTHANDLE;
     1595
     1596
     1597/**
     1598 * Standard handles.
     1599 *
     1600 * @remarks These have the correct file descriptor values for unixy systems and
     1601 *          can be used directly in code specific to those platforms.
     1602 */
     1603typedef enum RTHANDLESTD
     1604{
     1605    /** Invalid standard handle. */
     1606    RTHANDLESTD_INVALID = -1,
     1607    /** The standard input handle. */
     1608    RTHANDLESTD_INPUT = 0,
     1609    /** The standard output handle. */
     1610    RTHANDLESTD_OUTPUT,
     1611    /** The standard error handle. */
     1612    RTHANDLESTD_ERROR,
     1613    /** The typical 32-bit type hack. */
     1614    RTHANDLESTD_32BIT_HACK = 0x7fffffff
     1615} RTHANDLESTD;
    15441616
    15451617
  • trunk/include/iprt/vfs.h

    r33948 r33973  
    3131#include <iprt/dir.h>
    3232#include <iprt/fs.h>
     33#include <iprt/handle.h>
    3334#include <iprt/symlink.h>
    3435#include <iprt/sg.h>
     
    5657 * @{
    5758 */
    58 
    59 /** Virtual Filesystem handle. */
    60 typedef struct RTVFSINTERNAL           *RTVFS;
    61 /** Pointer to a VFS handle. */
    62 typedef RTVFS                          *PRTVFS;
    63 /** A NIL VFS handle. */
    64 #define NIL_RTVFS                       ((RTVFS)~(uintptr_t)0)
    65 
    66 /** Virtual Filesystem base object handle. */
    67 typedef struct RTVFSOBJINTERNAL        *RTVFSOBJ;
    68 /** Pointer to a VFS base object handle. */
    69 typedef RTVFSOBJ                       *PRTVFSOBJ;
    70 /** A NIL VFS base object handle. */
    71 #define NIL_RTVFSOBJ                    ((RTVFSOBJ)~(uintptr_t)0)
    72 
    73 /** Virtual Filesystem directory handle. */
    74 typedef struct RTVFSDIRINTERNAL        *RTVFSDIR;
    75 /** Pointer to a VFS directory handle. */
    76 typedef RTVFSDIR                       *PRTVFSDIR;
    77 /** A NIL VFS directory handle. */
    78 #define NIL_RTVFSDIR                    ((RTVFSDIR)~(uintptr_t)0)
    79 
    80 /** Virtual Filesystem filesystem stream handle. */
    81 typedef struct RTVFSFSSTREAMINTERNAL   *RTVFSFSSTREAM;
    82 /** Pointer to a VFS filesystem stream handle. */
    83 typedef RTVFSFSSTREAM                  *PRTVFSFSSTREAM;
    84 /** A NIL VFS filesystem stream handle. */
    85 #define NIL_RTVFSFSSTREAM               ((RTVFSFSSTREAM)~(uintptr_t)0)
    86 
    87 /** Virtual Filesystem I/O stream handle. */
    88 typedef struct RTVFSIOSTREAMINTERNAL   *RTVFSIOSTREAM;
    89 /** Pointer to a VFS I/O stream handle. */
    90 typedef RTVFSIOSTREAM                  *PRTVFSIOSTREAM;
    91 /** A NIL VFS I/O stream handle. */
    92 #define NIL_RTVFSIOSTREAM               ((RTVFSIOSTREAM)~(uintptr_t)0)
    93 
    94 /** Virtual Filesystem file handle. */
    95 typedef struct RTVFSFILEINTERNAL       *RTVFSFILE;
    96 /** Pointer to a VFS file handle. */
    97 typedef RTVFSFILE                      *PRTVFSFILE;
    98 /** A NIL VFS file handle. */
    99 #define NIL_RTVFSFILE                   ((RTVFSFILE)~(uintptr_t)0)
    100 
    101 /** Virtual Filesystem symbolic link handle. */
    102 typedef struct RTVFSSYMLINKINTERNAL    *RTVFSSYMLINK;
    103 /** Pointer to a VFS symbolic link handle. */
    104 typedef RTVFSSYMLINK                   *PRTVFSSYMLINK;
    105 /** A NIL VFS symbolic link handle. */
    106 #define NIL_RTVFSSYMLINK                ((RTVFSSYMLINK)~(uintptr_t)0)
    10759
    10860/**
     
    13991
    14092
    141 
    14293/** @name RTVfsCreate flags
    14394 * @{ */
     
    293244
    294245/**
     246 * Create a VFS I/O stream handle from a standard IPRT file handle (RTFILE).
     247 *
     248 * @returns IPRT status code.
     249 * @param   hFile           The standard IPRT file handle.
     250 * @param   fOpen           The flags the handle was opened with.  Pass 0 to
     251 *                          have these detected.
     252 * @param   fLeaveOpen      Whether to leave the handle open when the VFS file
     253 *                          is released, or to close it (@c false).
     254 * @param   phVfsIos        Where to return the VFS I/O stream handle.
     255 */
     256RTDECL(int)         RTVfsIoStrmFromRTFile(RTFILE hFile, uint32_t fOpen, bool fLeaveOpen, PRTVFSIOSTREAM phVfsIos);
     257
     258/**
     259 * Create a VFS I/O stream handle from one of the standard handles.
     260 *
     261 * @returns IPRT status code.
     262 * @param   enmStdHandle    The standard IPRT file handle.
     263 * @param   fOpen           The flags the handle was opened with.  Pass 0 to
     264 *                          have these detected.
     265 * @param   fLeaveOpen      Whether to leave the handle open when the VFS file
     266 *                          is released, or to close it (@c false).
     267 * @param   phVfsIos        Where to return the VFS I/O stream handle.
     268 */
     269RTDECL(int)         RTVfsIoStrmFromStdHandle(RTHANDLESTD enmStdHandle, uint32_t fOpen, bool fLeaveOpen,
     270                                             PRTVFSIOSTREAM phVfsIos);
     271
     272/**
    295273 * Retains a reference to the VFS I/O stream handle.
    296274 *
     
    316294 * @sa      RTVfsFileToIoStream
    317295 */
    318 RTDECL(RTVFSFILE)   RTVfsIoStrmToFile(RTVFSIOSTREAM hVfsIos);
     296RTDECL(RTVFSFILE) RTVfsIoStrmToFile(RTVFSIOSTREAM hVfsIos);
    319297
    320298/**
     
    327305 * @sa      RTFileQueryInfo
    328306 */
    329 RTDECL(int)         RTVfsIoStrmQueryInfo(RTVFSIOSTREAM hVfsIos, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr);
     307RTDECL(int) RTVfsIoStrmQueryInfo(RTVFSIOSTREAM hVfsIos, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr);
    330308
    331309/**
    332310 * Read bytes from the I/O stream.
    333  *
    334  * @returns IPRT status code.
    335  * @param   hVfsIos         The VFS I/O stream handle.
    336  * @param   pvBuf           Where to store the read bytes.
    337  * @param   cbToRead        The number of bytes to read.
    338  * @param   pcbRead         Where to always store the number of bytes actually
    339  *                          read.  If this is NULL, the call will block until
    340  *                          @a cbToRead bytes are available.  If this is
    341  *                          non-NULL, the call will not block and return what
    342  *                          is currently avaiable.
    343  * @sa      RTFileRead, RTPipeRead, RTPipeReadBlocking, RTSocketRead
    344  */
    345 RTDECL(int)         RTVfsIoStrmRead(RTVFSIOSTREAM hVfsIos, void *pvBuf, size_t cbToRead, size_t *pcbRead);
    346 
    347 /**
    348  * Write bytes to the I/O stream.
    349  *
    350  * @returns IPRT status code.
    351  * @param   hVfsIos         The VFS I/O stream handle.
    352  * @param   pvBuf           The bytes to write.
    353  * @param   cbToWrite       The number of bytes to write.
    354  * @param   pcbWritten      Where to always store the number of bytes actually
    355  *                          written.  If this is NULL, the call will block
    356  *                          until
    357  *                          @a cbToWrite bytes are available.  If this is
    358  *                          non-NULL, the call will not block and return after
    359  *                          writing what is possible.
    360  * @sa      RTFileWrite, RTPipeWrite, RTPipeWriteBlocking, RTSocketWrite
    361  */
    362 RTDECL(int)         RTVfsIoStrmWrite(RTVFSIOSTREAM hVfsIos, const void *pvBuf, size_t cbToWrite, size_t *pcbWritten);
    363 
    364 /**
    365  * Reads bytes from the I/O stream into a scatter buffer.
    366311 *
    367312 * @returns IPRT status code.
     
    380325 *
    381326 * @param   hVfsIos         The VFS I/O stream handle.
     327 * @param   pvBuf           Where to store the read bytes.
     328 * @param   cbToRead        The number of bytes to read.
     329 * @param   fBlocking       Whether the call is blocking (@c true) or not.  If
     330 *                          not, the @a pcbRead parameter must not be NULL.
     331 * @param   pcbRead         Where to always store the number of bytes actually
     332 *                          read.  This can be NULL if @a fBlocking is true.
     333 * @sa      RTFileRead, RTPipeRead, RTPipeReadBlocking, RTSocketRead
     334 */
     335RTDECL(int) RTVfsIoStrmRead(RTVFSIOSTREAM hVfsIos, void *pvBuf, size_t cbToRead, bool fBlocking, size_t *pcbRead);
     336
     337/**
     338 * Write bytes to the I/O stream.
     339 *
     340 * @returns IPRT status code.
     341 * @param   hVfsIos         The VFS I/O stream handle.
     342 * @param   pvBuf           The bytes to write.
     343 * @param   cbToWrite       The number of bytes to write.
     344 * @param   fBlocking       Whether the call is blocking (@c true) or not.  If
     345 *                          not, the @a pcbWritten parameter must not be NULL.
     346 * @param   pcbRead         Where to always store the number of bytes actually
     347 *                          written.  This can be NULL if @a fBlocking is true.
     348 * @sa      RTFileWrite, RTPipeWrite, RTPipeWriteBlocking, RTSocketWrite
     349 */
     350RTDECL(int) RTVfsIoStrmWrite(RTVFSIOSTREAM hVfsIos, const void *pvBuf, size_t cbToWrite, bool fBlocking, size_t *pcbWritten);
     351
     352/**
     353 * Reads bytes from the I/O stream into a scatter buffer.
     354 *
     355 * @returns IPRT status code.
     356 * @retval  VINF_SUCCESS and the number of bytes read written to @a pcbRead.
     357 * @retval  VINF_TRY_AGAIN if @a fBlocking is @c false, @a pcbRead is not NULL,
     358 *          and no data was available. @a *pcbRead will be set to 0.
     359 * @retval  VINF_EOF when trying to read __beyond__ the end of the stream and
     360 *          @a pcbRead is not NULL (it will be set to the number of bytes read,
     361 *          or 0 if the end of the stream was reached before this call).
     362 *          When the last byte of the read request is the last byte in the
     363 *          stream, this status code will not be used.  However, VINF_EOF is
     364 *          returned when attempting to read 0 bytes while standing at the end
     365 *          of the stream.
     366 * @retval  VERR_EOF when trying to read __beyond__ the end of the stream and
     367 *          @a pcbRead is NULL.
     368 *
     369 * @param   hVfsIos         The VFS I/O stream handle.
    382370 * @param   pSgBuf          Pointer to a scatter buffer descriptor.  The number
    383371 *                          of bytes described by the segments is what will be
     
    550538RTDECL(int) RTVfsChainOpenIoStream( const char *pszSpec, uint32_t fOpen, PRTVFSIOSTREAM  phVfsIos,  const char **ppszError);
    551539
     540/**
     541 * Tests if the given string is a chain specification or not.
     542 *
     543 * @returns true if it is, false if it isn't.
     544 * @param   pszSpec         The alleged chain spec.
     545 */
     546RTDECL(bool)    RTVfsChainIsSpec(const char *pszSpec);
     547
    552548/** @}  */
    553549
  • trunk/include/iprt/vfslowlevel.h

    r33949 r33973  
    735735{
    736736    /** Invalid action. */
    737     RTVFSCHAINACTION_INVALID,
     737    RTVFSCHAINACTION_INVALID = 0,
    738738    /** No action (start of the chain). */
    739739    RTVFSCHAINACTION_NONE,
  • trunk/include/iprt/zip.h

    r28800 r33973  
    217217
    218218
     219/**
     220 * Opens a gzip decompression I/O stream.
     221 *
     222 * @returns IPRT status code.
     223 *
     224 * @param   hVfsIosIn           The compressed input stream.  The reference is
     225 *                              not consumed, instead another one is retained.
     226 * @param   fFlags              Flags, MBZ.
     227 * @param   phVfsIosOut         Where to return the handle to the gzip I/O
     228 *                              stream.
     229 */
     230RTDECL(int) RTZipGzipDecompressIoStream(RTVFSIOSTREAM hVfsIosIn, uint32_t fFlags, PRTVFSIOSTREAM phVfsIosOut);
     231
    219232/** @} */
    220233
  • trunk/src/VBox/Runtime/Makefile.kmk

    r33945 r33973  
    371371        common/vfs/vfsbase.cpp \
    372372        common/vfs/vfschain.cpp \
     373        common/vfs/vfsmisc.cpp \
    373374        common/vfs/vfsstdfile.cpp \
    374375        common/zip/zipgzip.cpp \
     
    479480        nt/RTErrConvertFromNtStatus.cpp \
    480481        r3/posix/env-posix.cpp \
     482        r3/win/RTHandleGetStandard-win.cpp \
    481483        r3/win/RTSystemQueryOSInfo-win.cpp \
    482484        r3/win/RTSystemQueryDmiString-win.cpp \
     
    537539        r3/linux/RTSystemQueryDmiString-linux.cpp \
    538540        r3/posix/RTFileQueryFsSizes-posix.cpp \
     541        r3/posix/RTHandleGetStandard-posix.cpp \
    539542        r3/posix/RTMemProtect-posix.cpp \
    540543        r3/posix/RTPathUserHome-posix.cpp \
     
    622625        r3/os2/time-os2.cpp \
    623626        r3/posix/RTFileQueryFsSizes-posix.cpp \
     627        r3/posix/RTHandleGetStandard-posix.cpp \
    624628        r3/posix/RTMemProtect-posix.cpp \
    625629        r3/posix/RTPathUserHome-posix.cpp \
     
    671675        r3/darwin/time-darwin.cpp \
    672676        r3/posix/RTFileQueryFsSizes-posix.cpp \
     677        r3/posix/RTHandleGetStandard-posix.cpp \
    673678        r3/posix/RTMemProtect-posix.cpp \
    674679        r3/posix/RTPathUserHome-posix.cpp \
     
    720725        r3/freebsd/rtProcInitExePath-freebsd.cpp \
    721726        r3/posix/RTFileQueryFsSizes-posix.cpp \
     727        r3/posix/RTHandleGetStandard-posix.cpp \
    722728        r3/posix/RTMemProtect-posix.cpp \
    723729        r3/posix/RTPathUserHome-posix.cpp \
     
    769775        generic/RTThreadGetNativeState-generic.cpp \
    770776        r3/posix/RTFileQueryFsSizes-posix.cpp \
     777        r3/posix/RTHandleGetStandard-posix.cpp \
    771778        r3/posix/RTMemProtect-posix.cpp \
    772779        r3/posix/RTPathUserHome-posix.cpp \
  • trunk/src/VBox/Runtime/common/vfs/vfsbase.cpp

    r33948 r33973  
    10841084
    10851085
    1086 RTDECL(int) RTVfsNewIoStream(PCRTVFSFSSTREAMOPS pFsStreamOps, size_t cbInstance, RTVFS hVfs, RTSEMRW hSemRW,
     1086RTDECL(int) RTVfsNewFsStream(PCRTVFSFSSTREAMOPS pFsStreamOps, size_t cbInstance, RTVFS hVfs, RTSEMRW hSemRW,
    10871087                             PRTVFSFSSTREAM phVfsFss, void **ppvInstance)
    10881088{
     
    12311231
    12321232    RTVFSINTERNAL *pVfs = NULL;
    1233     if (hVfs == NIL_RTVFS)
     1233    if (hVfs != NIL_RTVFS)
    12341234    {
    12351235        pVfs = hVfs;
     
    12521252    pThis->Base.uMagic  = RTVFSOBJ_MAGIC;
    12531253    pThis->Base.pvThis  = (char *)pThis + RT_ALIGN_Z(sizeof(*pThis), RTVFS_INST_ALIGNMENT);
     1254    pThis->Base.pOps    = &pIoStreamOps->Obj;
    12541255    pThis->Base.hSemRW  = hSemRW != NIL_RTSEMRW ? hSemRW : pVfs ? pVfs->Base.hSemRW : NIL_RTSEMRW;
    12551256    pThis->Base.hVfs    = hVfs;
     
    12991300
    13001301
    1301 RTDECL(int)         RTVfsIoStrmQueryInfo(RTVFSIOSTREAM hVfsIos, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr)
     1302RTDECL(int) RTVfsIoStrmQueryInfo(RTVFSIOSTREAM hVfsIos, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr)
    13021303{
    13031304    RTVFSIOSTREAMINTERNAL *pThis = hVfsIos;
     
    13081309
    13091310
    1310 RTDECL(int)         RTVfsIoStrmRead(RTVFSIOSTREAM hVfsIos, void *pvBuf, size_t cbToRead, size_t *pcbRead)
     1311RTDECL(int) RTVfsIoStrmRead(RTVFSIOSTREAM hVfsIos, void *pvBuf, size_t cbToRead, bool fBlocking, size_t *pcbRead)
    13111312{
    13121313    AssertPtrNullReturn(pcbRead, VERR_INVALID_POINTER);
     
    13161317    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
    13171318    AssertReturn(pThis->uMagic == RTVFSIOSTREAM_MAGIC, VERR_INVALID_HANDLE);
     1319    AssertReturn(fBlocking || pcbRead, VERR_INVALID_PARAMETER);
    13181320
    13191321    RTSGSEG Seg = { pvBuf, cbToRead };
     
    13221324
    13231325    rtVfsObjWriteLock(&pThis->Base);
    1324     int rc = pThis->pOps->pfnRead(pThis->Base.pvThis, -1 /*off*/, &SgBuf, pcbRead == NULL /*fBlocking*/, pcbRead);
     1326    int rc = pThis->pOps->pfnRead(pThis->Base.pvThis, -1 /*off*/, &SgBuf, fBlocking, pcbRead);
    13251327    rtVfsObjWriteUnlock(&pThis->Base);
    13261328    return rc;
     
    13281330
    13291331
    1330 RTDECL(int)         RTVfsIoStrmWrite(RTVFSIOSTREAM hVfsIos, const void *pvBuf, size_t cbToWrite, size_t *pcbWritten)
     1332RTDECL(int) RTVfsIoStrmWrite(RTVFSIOSTREAM hVfsIos, const void *pvBuf, size_t cbToWrite, bool fBlocking, size_t *pcbWritten)
    13311333{
    13321334    AssertPtrNullReturn(pcbWritten, VERR_INVALID_POINTER);
     
    13361338    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
    13371339    AssertReturn(pThis->uMagic == RTVFSIOSTREAM_MAGIC, VERR_INVALID_HANDLE);
     1340    AssertReturn(fBlocking || pcbWritten, VERR_INVALID_PARAMETER);
    13381341
    13391342    RTSGSEG Seg = { (void *)pvBuf, cbToWrite };
     
    13421345
    13431346    rtVfsObjWriteLock(&pThis->Base);
    1344     int rc = pThis->pOps->pfnWrite(pThis->Base.pvThis, -1 /*off*/, &SgBuf, pcbWritten == NULL /*fBlocking*/, pcbWritten);
     1347    int rc = pThis->pOps->pfnWrite(pThis->Base.pvThis, -1 /*off*/, &SgBuf, fBlocking, pcbWritten);
    13451348    rtVfsObjWriteUnlock(&pThis->Base);
    13461349    return rc;
     
    13481351
    13491352
    1350 RTDECL(int)         RTVfsIoStrmSgRead(RTVFSIOSTREAM hVfsIos, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
     1353RTDECL(int) RTVfsIoStrmSgRead(RTVFSIOSTREAM hVfsIos, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
    13511354{
    13521355    AssertPtrNullReturn(pcbRead, VERR_INVALID_POINTER);
     
    13661369
    13671370
    1368 RTDECL(int)         RTVfsIoStrmSgWrite(RTVFSIOSTREAM hVfsIos, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
     1371RTDECL(int) RTVfsIoStrmSgWrite(RTVFSIOSTREAM hVfsIos, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
    13691372{
    13701373    AssertPtrNullReturn(pcbWritten, VERR_INVALID_POINTER);
     
    13841387
    13851388
    1386 RTDECL(int)         RTVfsIoStrmFlush(RTVFSIOSTREAM hVfsIos)
     1389RTDECL(int) RTVfsIoStrmFlush(RTVFSIOSTREAM hVfsIos)
    13871390{
    13881391    RTVFSIOSTREAMINTERNAL *pThis = hVfsIos;
     
    13971400
    13981401
    1399 RTDECL(RTFOFF)      RTVfsIoStrmPoll(RTVFSIOSTREAM hVfsIos, uint32_t fEvents, RTMSINTERVAL cMillies, bool fIntr,
    1400                                     uint32_t *pfRetEvents)
     1402RTDECL(RTFOFF) RTVfsIoStrmPoll(RTVFSIOSTREAM hVfsIos, uint32_t fEvents, RTMSINTERVAL cMillies, bool fIntr,
     1403                               uint32_t *pfRetEvents)
    14011404{
    14021405    RTVFSIOSTREAMINTERNAL *pThis = hVfsIos;
     
    14111414
    14121415
    1413 RTDECL(RTFOFF)      RTVfsIoStrmTell(RTVFSIOSTREAM hVfsIos)
     1416RTDECL(RTFOFF) RTVfsIoStrmTell(RTVFSIOSTREAM hVfsIos)
    14141417{
    14151418    RTVFSIOSTREAMINTERNAL *pThis = hVfsIos;
     
    14271430
    14281431
    1429 RTDECL(int)         RTVfsIoStrmSkip(RTVFSIOSTREAM hVfsIos, RTFOFF cb)
     1432RTDECL(int) RTVfsIoStrmSkip(RTVFSIOSTREAM hVfsIos, RTFOFF cb)
    14301433{
    14311434    RTVFSIOSTREAMINTERNAL *pThis = hVfsIos;
     
    14511454                size_t cbToRead = RT_MIN(cb, _64K);
    14521455                rtVfsObjWriteLock(&pThis->Base);
    1453                 rc = RTVfsIoStrmRead(hVfsIos, pvBuf, cbToRead, NULL);
     1456                rc = RTVfsIoStrmRead(hVfsIos, pvBuf, cbToRead, true /*fBlocking*/, NULL);
    14541457                rtVfsObjWriteUnlock(&pThis->Base);
    14551458                if (RT_FAILURE(rc))
     
    14671470
    14681471
    1469 RTDECL(int)         RTVfsIoStrmZeroFill(RTVFSIOSTREAM hVfsIos, RTFOFF cb)
     1472RTDECL(int) RTVfsIoStrmZeroFill(RTVFSIOSTREAM hVfsIos, RTFOFF cb)
    14701473{
    14711474    RTVFSIOSTREAMINTERNAL *pThis = hVfsIos;
     
    14901493                size_t cbToWrite = RT_MIN(cb, _64K);
    14911494                rtVfsObjWriteLock(&pThis->Base);
    1492                 rc = RTVfsIoStrmWrite(hVfsIos, pvBuf, cbToWrite, NULL);
     1495                rc = RTVfsIoStrmWrite(hVfsIos, pvBuf, cbToWrite, true /*fBlocking*/, NULL);
    14931496                rtVfsObjWriteUnlock(&pThis->Base);
    14941497                if (RT_FAILURE(rc))
     
    15341537
    15351538    RTVFSINTERNAL *pVfs = NULL;
    1536     if (hVfs == NIL_RTVFS)
     1539    if (hVfs != NIL_RTVFS)
    15371540    {
    15381541        pVfs = hVfs;
     
    15571560    pThis->Stream.pOps          = &pFileOps->Stream;
    15581561    pThis->Stream.Base.pvThis   = (char *)pThis + RT_ALIGN_Z(sizeof(*pThis), RTVFS_INST_ALIGNMENT);
     1562    pThis->Stream.Base.pOps     = &pFileOps->Stream.Obj;
    15591563    pThis->Stream.Base.hSemRW   = pVfs ? pVfs->Base.hSemRW : NIL_RTSEMRW;
    15601564    pThis->Stream.Base.hVfs     = hVfs;
  • trunk/src/VBox/Runtime/common/vfs/vfschain.cpp

    r33950 r33973  
    431431        }
    432432
    433 
    434433        /*
    435434         * Ok, there should be an element here so add one to the return struct.
     
    440439        pElement->enmAction = enmAction;
    441440
    442         /* First comes a type which is followed by a '('. */
     441        /*
     442         * First up is the VFS object type followed by a parentheses.
     443         */
    443444        if (strncmp(pszSrc, "base", cch = 4) == 0)
    444445            pElement->enmTypeOut = RTVFSOBJTYPE_BASE;
     
    495496        }
    496497
    497         /* Must end with a right parantheses. */
     498        /* Must end with a right parentheses. */
    498499        if (*pszSrc != ')')
    499500        {
     
    657658
    658659
     660RTDECL(bool) RTVfsChainIsSpec(const char *pszSpec)
     661{
     662    return pszSpec
     663        && strcmp(pszSpec, RTVFSCHAIN_SPEC_PREFIX) == 0;
     664}
     665
  • trunk/src/VBox/Runtime/common/vfs/vfsstdfile.cpp

    r33903 r33973  
    446446}
    447447
     448
     449RTDECL(int)         RTVfsIoStrmFromRTFile(RTFILE hFile, uint32_t fOpen, bool fLeaveOpen, PRTVFSIOSTREAM phVfsIos)
     450{
     451    RTVFSFILE hVfsFile;
     452    int rc = RTVfsFileFromRTFile(hFile, fOpen, fLeaveOpen, &hVfsFile);
     453    if (RT_SUCCESS(rc))
     454        *phVfsIos = RTVfsFileToIoStream(hVfsFile);
     455    return rc;
     456}
     457
     458
     459
  • trunk/src/VBox/Runtime/common/zip/zipgzip.cpp

    r33945 r33973  
    3030*******************************************************************************/
    3131#include "internal/iprt.h"
    32 #include <iprt/vfslowlevel.h>
     32#include <iprt/zip.h>
    3333
    3434#include <iprt/assert.h>
     
    3737#include <iprt/poll.h>
    3838#include <iprt/string.h>
     39#include <iprt/vfslowlevel.h>
     40
    3941#include <zlib.h>
    4042
     
    477479    AssertPtrReturn(phVfsIosOut, VERR_INVALID_POINTER);
    478480
     481    uint32_t cRefs = RTVfsIoStrmRetain(hVfsIosIn);
     482    AssertReturn(cRefs != UINT32_MAX, VERR_INVALID_HANDLE);
     483
    479484    /*
    480485     * Create the decompression I/O stream.
     
    507512             */
    508513            size_t cbRead = 0;
    509             rc = RTVfsIoStrmRead(pThis->hVfsIos, pThis->abBuffer, sizeof(RTZIPGZIPHDR), NULL /*pcbRead*/);
     514            rc = RTVfsIoStrmRead(pThis->hVfsIos, pThis->abBuffer, sizeof(RTZIPGZIPHDR), true /*fBlocking*/, NULL /*pcbRead*/);
    510515            if (RT_SUCCESS(rc))
    511516            {
     
    539544        }
    540545        else
    541             rc = rtZipGzipConvertErrFromZlib(pThis, rc);
     546            rc = rtZipGzipConvertErrFromZlib(pThis, rc); /** @todo cleaning up in this situation is going to go wrong. */
     547        RTVfsIoStrmRelease(hVfsIos);
    542548    }
     549    else
     550        RTVfsIoStrmRelease(hVfsIosIn);
    543551    return rc;
    544552}
  • trunk/src/VBox/Runtime/testcase/Makefile.kmk

    r33678 r33973  
    572572RTLdrFlt_SOURCES = RTLdrFlt.cpp
    573573
     574# RTGzip - our gzip clone (for testing the gzip/gunzip streaming code)
     575PROGRAMS += RTGzip
     576RTGzip_TEMPLATE = VBOXR3TSTEXE
     577RTGzip_SOURCES = RTGzip.cpp
     578
    574579
    575580
  • trunk/src/VBox/Runtime/testcase/RTGzip.cpp

    r33911 r33973  
    3131#include <iprt/zip.h>
    3232
     33#include <iprt/buildconfig.h>
     34#include <iprt/file.h>
    3335#include <iprt/getopt.h>
    34 #include <iprt/init.h>
     36#include <iprt/initterm.h>
    3537#include <iprt/message.h>
     38#include <iprt/param.h>
     39#include <iprt/stream.h>
    3640#include <iprt/string.h>
    3741#include <iprt/vfs.h>
     42#include <iprt/zip.h>
    3843
    3944
     
    4348    return false;
    4449}
     50
     51
     52/**
     53 * Pushes data from the input to the output I/O streams.
     54 *
     55 * @returns RTEXITCODE_SUCCESS or RTEXITCODE_FAILURE.
     56 * @param   hVfsIn              The input I/O stream.
     57 * @param   hVfsOut             The input I/O stream.
     58 */
     59static RTEXITCODE gzipPush(RTVFSIOSTREAM hVfsIn, RTVFSIOSTREAM hVfsOut)
     60{
     61    for (;;)
     62    {
     63        uint8_t abBuf[_64K];
     64        size_t  cbRead;
     65        int rc = RTVfsIoStrmRead(hVfsIn, abBuf, sizeof(abBuf), true /*fBlocking*/, &cbRead);
     66        if (RT_FAILURE(rc))
     67            return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTVfsIoStrmRead failed: %Rrc", rc);
     68        if (rc == VINF_EOF && cbRead == 0)
     69            return RTEXITCODE_SUCCESS;
     70
     71        rc = RTVfsIoStrmWrite(hVfsOut, abBuf, cbRead, true /*fBlocking*/, NULL /*cbWritten*/);
     72        if (RT_FAILURE(rc))
     73            return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTVfsIoStrmWrite failed: %Rrc", rc);
     74    }
     75}
     76
     77static RTEXITCODE gzipCompress(RTVFSIOSTREAM hVfsIn, RTVFSIOSTREAM hVfsOut)
     78{
     79    return RTMsgErrorExit(RTEXITCODE_FAILURE, "Compression is not yet implemented, sorry.");
     80}
     81
     82
     83static RTEXITCODE gzipCompressFile(const char *pszFile, bool fStdOut, bool fForce, PRTVFSIOSTREAM phVfsStdOut)
     84{
     85    return RTMsgErrorExit(RTEXITCODE_FAILURE, "Compression is not yet implemented, sorry.");
     86}
     87
     88
     89static RTEXITCODE gzipDecompress(RTVFSIOSTREAM hVfsIn, RTVFSIOSTREAM hVfsOut)
     90{
     91    RTEXITCODE      rcExit;
     92    RTVFSIOSTREAM   hVfsGunzip;
     93    int rc = RTZipGzipDecompressIoStream(hVfsIn, 0 /*fFlags*/, &hVfsGunzip);
     94    if (RT_SUCCESS(rc))
     95    {
     96        rcExit = gzipPush(hVfsGunzip, hVfsOut);
     97        RTVfsIoStrmRelease(hVfsGunzip);
     98    }
     99    else
     100        rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "RTZipGzipDecompressIoStream failed: %Rrc", rc);
     101    return rcExit;
     102}
     103
     104
     105/**
     106 * Handles a file on the command line.
     107 *
     108 * @returns exit code.
     109 * @param   pszFile             The file to handle.
     110 * @param   fStdOut             Whether to output to standard output or not.
     111 * @param   fForce              Whether to output to or input from terminals.
     112 * @param   phVfsStdOut         Pointer to the standard out handle.
     113 *                              (input/output)
     114 */
     115static RTEXITCODE gzipDecompressFile(const char *pszFile, bool fStdOut, bool fForce, PRTVFSIOSTREAM phVfsStdOut)
     116{
     117    /*
     118     * Open the specified input file.
     119     */
     120    const char *pszError;
     121    RTVFSIOSTREAM hVfsIn;
     122    int rc = RTVfsChainOpenIoStream(pszFile, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE, &hVfsIn, &pszError);
     123    if (RT_FAILURE(rc))
     124    {
     125        if (pszError && *pszError)
     126            return RTMsgErrorExit(RTEXITCODE_FAILURE,
     127                                  "RTVfsChainOpenIoStream failed with rc=%Rrc:\n"
     128                                  "    '%s'\n",
     129                                  "     %*s^\n",
     130                                  rc, pszFile, pszError - pszFile, "");
     131        return RTMsgErrorExit(RTEXITCODE_FAILURE,
     132                              "RTVfsChainOpenIoStream failed with rc=%Rrc: '%s'",
     133                              rc, pszFile);
     134    }
     135
     136    /*
     137     * Output the output file.
     138     */
     139    RTVFSIOSTREAM hVfsOut;
     140    char szFinal[RTPATH_MAX];
     141    if (fStdOut)
     142    {
     143        if (*phVfsStdOut == NIL_RTVFSIOSTREAM)
     144        {
     145            rc = RTVfsIoStrmFromStdHandle(RTHANDLESTD_OUTPUT, 0 /*fOpen*/, true /*fLeaveOpen*/, phVfsStdOut);
     146            if (RT_FAILURE(rc))
     147                return RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed to set up standard out: %Rrc", rc);
     148        }
     149        hVfsOut = *phVfsStdOut;
     150        szFinal[0] = '\0';
     151    }
     152    else
     153    {
     154        rc = RTStrCopy(szFinal, sizeof(szFinal), pszFile);
     155        /** @todo remove the extension?  Or are we supposed
     156         *        to get the org name from the gzip stream? */
     157        return RTMsgErrorExit(RTEXITCODE_FAILURE, "Decompressing to file is not implemented");
     158    }
     159
     160    /*
     161     * Do the decompressing, then flush and close the output stream (unless
     162     * it is stdout).
     163     */
     164    RTEXITCODE rcExit = gzipDecompress(hVfsIn, hVfsOut);
     165    RTVfsIoStrmRelease(hVfsIn);
     166    rc = RTVfsIoStrmFlush(hVfsOut);
     167    if (RT_FAILURE(rc))
     168        rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed to flush the output file: %Rrc", rc);
     169    RTVfsIoStrmRelease(hVfsOut);
     170
     171    /*
     172     * Remove the input file, if that's the desire of the caller, or
     173     * remove the output file on decompression failure.
     174     */
     175    if (!fStdOut)
     176    {
     177        if (rcExit == RTEXITCODE_SUCCESS)
     178        {
     179            rc = RTFileDelete(pszFile);
     180            if (RT_FAILURE(rc))
     181                rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "RTFileDelete failed with %rc: '%s'", rc, pszFile);
     182        }
     183        else
     184        {
     185            /* should we do this? */
     186            rc = RTFileDelete(szFinal);
     187            if (RT_FAILURE(rc))
     188                RTMsgError("RTFileDelete failed with %rc: '%s'", rc, pszFile);
     189        }
     190    }
     191
     192    return rcExit;
     193}
     194
     195
     196static RTEXITCODE gzipTestFile(const char *pszFile, bool fForce)
     197{
     198    return RTMsgErrorExit(RTEXITCODE_FAILURE, "Testiong has not been implemented");
     199}
     200
     201
     202static RTEXITCODE gzipListFile(const char *pszFile, bool fForce)
     203{
     204    return RTMsgErrorExit(RTEXITCODE_FAILURE, "Listing has not been implemented");
     205}
     206
    45207
    46208int main(int argc, char **argv)
     
    53215     * Parse the command line.
    54216     */
    55     static const RTGETOPTDEF s_aOptions[]
     217    static const RTGETOPTDEF s_aOptions[] =
    56218    {
    57219        { "--ascii",        'a', RTGETOPT_REQ_NOTHING },
     
    96258    RTEXITCODE  rcExit      = RTEXITCODE_SUCCESS;
    97259    unsigned    cProcessed  = 0;
    98 
    99     RTGETOPTSTAT GetState;
    100     int rc = RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1,
    101                           RTGETOPTINIT_FLAGS_OPTS_FIRST);
     260    RTVFSIOSTREAM hVfsStdOut= NIL_RTVFSIOSTREAM;
     261
     262    RTGETOPTSTATE GetState;
     263    rc = RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1,
     264                      RTGETOPTINIT_FLAGS_OPTS_FIRST);
    102265    for (;;)
    103266    {
     
    112275                 * input from stdin and write the output to stdout.
    113276                 */
    114                 if (cProcessed)
     277                if (cProcessed > 0)
    115278                    return rcExit;
    116 
    117                 RTVFSIOSTREAM hVfsIn;
    118                 RTVFSIOSTREAM hVfsOut;
     279#if 0
     280                rc = RTVfsFileFromRTFile(1,
     281                                         RTFILE_O_WRITE | RTFILE_O_OPEN | RTFILE_O_DENY_NONE,
     282                                         true /*fLeaveOpen*/,
     283                                         &hVfsOut);
     284
    119285
    120286                if (!fForce && isStdHandleATty(fDecompress ? 0 : 1))
     
    123289                                          fDecompress ? "reading" : "writing",
    124290                                          fDecompress ? "from"    : "to");
     291#else
     292                rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "reading from standard input has not yet been implemented");
     293#endif
    125294                return rcExit;
    126295            }
     
    128297            case VINF_GETOPT_NOT_OPTION:
    129298            {
    130                 RTVFSIOSTREAM hVfsSrc;
    131                 rc = RTVfsOpenIoStreamFromSpec(ValueUnion.psz, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE, &hVfsSrc);
     299                if (!*pszSuff && !fStdOut)
     300                    return RTMsgErrorExit(RTEXITCODE_SYNTAX, "The --suffix option specified an empty string");
     301                if (!fStdOut && RTVfsChainIsSpec(ValueUnion.psz))
     302                    return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Must use standard out with VFS chain specifications");
     303
     304                RTEXITCODE rcExit2;
     305                if (fList)
     306                    rcExit2 = gzipListFile(ValueUnion.psz, fForce);
     307                else if (fTest)
     308                    rcExit2 = gzipTestFile(ValueUnion.psz, fForce);
     309                else if (fDecompress)
     310                    rcExit2 = gzipDecompressFile(ValueUnion.psz, fStdOut, fForce, &hVfsStdOut);
     311                else
     312                    rcExit2 = gzipCompressFile(ValueUnion.psz, fStdOut, fForce, &hVfsStdOut);
     313                if (rcExit2 != RTEXITCODE_SUCCESS)
     314                    rcExit = rcExit2;
    132315
    133316                cProcessed++;
    134                 if (fDecompress)
    135                 {
    136                 }
    137                 else
    138                 {
    139                     if (!*pszSuff && !fStdOut)
    140                         return
    141                     {
    142                     }
    143                 }
    144317                break;
    145318            }
     
    167340            case '9':   uLevel      = 9;     break;
    168341
     342            case 'h':
     343                RTPrintf("Usage: to be written\nOption dump:\n");
     344                for (unsigned i = 0; i < RT_ELEMENTS(s_aOptions); i++)
     345                    RTPrintf(" -%c,%s\n", s_aOptions[i].iShort, s_aOptions[i].pszLong);
     346                return RTEXITCODE_SUCCESS;
     347
     348            case 'V':
     349                RTPrintf("%sr%d\n", RTBldCfgVersion(), RTBldCfgRevision());
     350                return RTEXITCODE_SUCCESS;
     351
    169352            default:
    170                 return RTGetOptPrintError(ch, &ValueUnion);
     353                return RTGetOptPrintError(rc, &ValueUnion);
    171354        }
    172355    }
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