Changeset 33973 in vbox
- Timestamp:
- Nov 11, 2010 11:10:10 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/handle.h
r28800 r33973 47 47 RTDECL(int) RTHandleClose(PRTHANDLE ph); 48 48 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 */ 57 RTDECL(int) RTHandleGetStandard(RTHANDLESTD enmStdHandle, PRTHANDLE ph); 58 49 59 /** @} */ 50 60 -
trunk/include/iprt/pipe.h
r28800 r33973 88 88 #define RTPIPE_N_INHERIT RT_BIT(2) 89 89 /** Mask of valid flags. */ 90 #define RTPIPE_N_VALID_MASK UINT32_C(0x0000000 3)90 #define RTPIPE_N_VALID_MASK UINT32_C(0x00000007) 91 91 /** @} */ 92 92 -
trunk/include/iprt/types.h
r33871 r33973 1482 1482 #define RTSTRCACHE_DEFAULT ((RTSTRCACHE)-2) 1483 1483 1484 1485 /** Virtual Filesystem handle. */ 1486 typedef struct RTVFSINTERNAL *RTVFS; 1487 /** Pointer to a VFS handle. */ 1488 typedef RTVFS *PRTVFS; 1489 /** A NIL VFS handle. */ 1490 #define NIL_RTVFS ((RTVFS)~(uintptr_t)0) 1491 1492 /** Virtual Filesystem base object handle. */ 1493 typedef struct RTVFSOBJINTERNAL *RTVFSOBJ; 1494 /** Pointer to a VFS base object handle. */ 1495 typedef RTVFSOBJ *PRTVFSOBJ; 1496 /** A NIL VFS base object handle. */ 1497 #define NIL_RTVFSOBJ ((RTVFSOBJ)~(uintptr_t)0) 1498 1499 /** Virtual Filesystem directory handle. */ 1500 typedef struct RTVFSDIRINTERNAL *RTVFSDIR; 1501 /** Pointer to a VFS directory handle. */ 1502 typedef RTVFSDIR *PRTVFSDIR; 1503 /** A NIL VFS directory handle. */ 1504 #define NIL_RTVFSDIR ((RTVFSDIR)~(uintptr_t)0) 1505 1506 /** Virtual Filesystem filesystem stream handle. */ 1507 typedef struct RTVFSFSSTREAMINTERNAL *RTVFSFSSTREAM; 1508 /** Pointer to a VFS filesystem stream handle. */ 1509 typedef 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. */ 1514 typedef struct RTVFSIOSTREAMINTERNAL *RTVFSIOSTREAM; 1515 /** Pointer to a VFS I/O stream handle. */ 1516 typedef RTVFSIOSTREAM *PRTVFSIOSTREAM; 1517 /** A NIL VFS I/O stream handle. */ 1518 #define NIL_RTVFSIOSTREAM ((RTVFSIOSTREAM)~(uintptr_t)0) 1519 1520 /** Virtual Filesystem file handle. */ 1521 typedef struct RTVFSFILEINTERNAL *RTVFSFILE; 1522 /** Pointer to a VFS file handle. */ 1523 typedef RTVFSFILE *PRTVFSFILE; 1524 /** A NIL VFS file handle. */ 1525 #define NIL_RTVFSFILE ((RTVFSFILE)~(uintptr_t)0) 1526 1527 /** Virtual Filesystem symbolic link handle. */ 1528 typedef struct RTVFSSYMLINKINTERNAL *RTVFSSYMLINK; 1529 /** Pointer to a VFS symbolic link handle. */ 1530 typedef RTVFSSYMLINK *PRTVFSSYMLINK; 1531 /** A NIL VFS symbolic link handle. */ 1532 #define NIL_RTVFSSYMLINK ((RTVFSSYMLINK)~(uintptr_t)0) 1533 1534 1484 1535 /** 1485 1536 * Handle type. … … 1542 1593 /** Pointer to a const generic handle. */ 1543 1594 typedef 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 */ 1603 typedef 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; 1544 1616 1545 1617 -
trunk/include/iprt/vfs.h
r33948 r33973 31 31 #include <iprt/dir.h> 32 32 #include <iprt/fs.h> 33 #include <iprt/handle.h> 33 34 #include <iprt/symlink.h> 34 35 #include <iprt/sg.h> … … 56 57 * @{ 57 58 */ 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)107 59 108 60 /** … … 139 91 140 92 141 142 93 /** @name RTVfsCreate flags 143 94 * @{ */ … … 293 244 294 245 /** 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 */ 256 RTDECL(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 */ 269 RTDECL(int) RTVfsIoStrmFromStdHandle(RTHANDLESTD enmStdHandle, uint32_t fOpen, bool fLeaveOpen, 270 PRTVFSIOSTREAM phVfsIos); 271 272 /** 295 273 * Retains a reference to the VFS I/O stream handle. 296 274 * … … 316 294 * @sa RTVfsFileToIoStream 317 295 */ 318 RTDECL(RTVFSFILE) 296 RTDECL(RTVFSFILE) RTVfsIoStrmToFile(RTVFSIOSTREAM hVfsIos); 319 297 320 298 /** … … 327 305 * @sa RTFileQueryInfo 328 306 */ 329 RTDECL(int) 307 RTDECL(int) RTVfsIoStrmQueryInfo(RTVFSIOSTREAM hVfsIos, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr); 330 308 331 309 /** 332 310 * 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 actually339 * read. If this is NULL, the call will block until340 * @a cbToRead bytes are available. If this is341 * non-NULL, the call will not block and return what342 * is currently avaiable.343 * @sa RTFileRead, RTPipeRead, RTPipeReadBlocking, RTSocketRead344 */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 actually355 * written. If this is NULL, the call will block356 * until357 * @a cbToWrite bytes are available. If this is358 * non-NULL, the call will not block and return after359 * writing what is possible.360 * @sa RTFileWrite, RTPipeWrite, RTPipeWriteBlocking, RTSocketWrite361 */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.366 311 * 367 312 * @returns IPRT status code. … … 380 325 * 381 326 * @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 */ 335 RTDECL(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 */ 350 RTDECL(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. 382 370 * @param pSgBuf Pointer to a scatter buffer descriptor. The number 383 371 * of bytes described by the segments is what will be … … 550 538 RTDECL(int) RTVfsChainOpenIoStream( const char *pszSpec, uint32_t fOpen, PRTVFSIOSTREAM phVfsIos, const char **ppszError); 551 539 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 */ 546 RTDECL(bool) RTVfsChainIsSpec(const char *pszSpec); 547 552 548 /** @} */ 553 549 -
trunk/include/iprt/vfslowlevel.h
r33949 r33973 735 735 { 736 736 /** Invalid action. */ 737 RTVFSCHAINACTION_INVALID ,737 RTVFSCHAINACTION_INVALID = 0, 738 738 /** No action (start of the chain). */ 739 739 RTVFSCHAINACTION_NONE, -
trunk/include/iprt/zip.h
r28800 r33973 217 217 218 218 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 */ 230 RTDECL(int) RTZipGzipDecompressIoStream(RTVFSIOSTREAM hVfsIosIn, uint32_t fFlags, PRTVFSIOSTREAM phVfsIosOut); 231 219 232 /** @} */ 220 233 -
trunk/src/VBox/Runtime/Makefile.kmk
r33945 r33973 371 371 common/vfs/vfsbase.cpp \ 372 372 common/vfs/vfschain.cpp \ 373 common/vfs/vfsmisc.cpp \ 373 374 common/vfs/vfsstdfile.cpp \ 374 375 common/zip/zipgzip.cpp \ … … 479 480 nt/RTErrConvertFromNtStatus.cpp \ 480 481 r3/posix/env-posix.cpp \ 482 r3/win/RTHandleGetStandard-win.cpp \ 481 483 r3/win/RTSystemQueryOSInfo-win.cpp \ 482 484 r3/win/RTSystemQueryDmiString-win.cpp \ … … 537 539 r3/linux/RTSystemQueryDmiString-linux.cpp \ 538 540 r3/posix/RTFileQueryFsSizes-posix.cpp \ 541 r3/posix/RTHandleGetStandard-posix.cpp \ 539 542 r3/posix/RTMemProtect-posix.cpp \ 540 543 r3/posix/RTPathUserHome-posix.cpp \ … … 622 625 r3/os2/time-os2.cpp \ 623 626 r3/posix/RTFileQueryFsSizes-posix.cpp \ 627 r3/posix/RTHandleGetStandard-posix.cpp \ 624 628 r3/posix/RTMemProtect-posix.cpp \ 625 629 r3/posix/RTPathUserHome-posix.cpp \ … … 671 675 r3/darwin/time-darwin.cpp \ 672 676 r3/posix/RTFileQueryFsSizes-posix.cpp \ 677 r3/posix/RTHandleGetStandard-posix.cpp \ 673 678 r3/posix/RTMemProtect-posix.cpp \ 674 679 r3/posix/RTPathUserHome-posix.cpp \ … … 720 725 r3/freebsd/rtProcInitExePath-freebsd.cpp \ 721 726 r3/posix/RTFileQueryFsSizes-posix.cpp \ 727 r3/posix/RTHandleGetStandard-posix.cpp \ 722 728 r3/posix/RTMemProtect-posix.cpp \ 723 729 r3/posix/RTPathUserHome-posix.cpp \ … … 769 775 generic/RTThreadGetNativeState-generic.cpp \ 770 776 r3/posix/RTFileQueryFsSizes-posix.cpp \ 777 r3/posix/RTHandleGetStandard-posix.cpp \ 771 778 r3/posix/RTMemProtect-posix.cpp \ 772 779 r3/posix/RTPathUserHome-posix.cpp \ -
trunk/src/VBox/Runtime/common/vfs/vfsbase.cpp
r33948 r33973 1084 1084 1085 1085 1086 RTDECL(int) RTVfsNew IoStream(PCRTVFSFSSTREAMOPS pFsStreamOps, size_t cbInstance, RTVFS hVfs, RTSEMRW hSemRW,1086 RTDECL(int) RTVfsNewFsStream(PCRTVFSFSSTREAMOPS pFsStreamOps, size_t cbInstance, RTVFS hVfs, RTSEMRW hSemRW, 1087 1087 PRTVFSFSSTREAM phVfsFss, void **ppvInstance) 1088 1088 { … … 1231 1231 1232 1232 RTVFSINTERNAL *pVfs = NULL; 1233 if (hVfs == NIL_RTVFS)1233 if (hVfs != NIL_RTVFS) 1234 1234 { 1235 1235 pVfs = hVfs; … … 1252 1252 pThis->Base.uMagic = RTVFSOBJ_MAGIC; 1253 1253 pThis->Base.pvThis = (char *)pThis + RT_ALIGN_Z(sizeof(*pThis), RTVFS_INST_ALIGNMENT); 1254 pThis->Base.pOps = &pIoStreamOps->Obj; 1254 1255 pThis->Base.hSemRW = hSemRW != NIL_RTSEMRW ? hSemRW : pVfs ? pVfs->Base.hSemRW : NIL_RTSEMRW; 1255 1256 pThis->Base.hVfs = hVfs; … … 1299 1300 1300 1301 1301 RTDECL(int) 1302 RTDECL(int) RTVfsIoStrmQueryInfo(RTVFSIOSTREAM hVfsIos, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr) 1302 1303 { 1303 1304 RTVFSIOSTREAMINTERNAL *pThis = hVfsIos; … … 1308 1309 1309 1310 1310 RTDECL(int) RTVfsIoStrmRead(RTVFSIOSTREAM hVfsIos, void *pvBuf, size_t cbToRead, size_t *pcbRead)1311 RTDECL(int) RTVfsIoStrmRead(RTVFSIOSTREAM hVfsIos, void *pvBuf, size_t cbToRead, bool fBlocking, size_t *pcbRead) 1311 1312 { 1312 1313 AssertPtrNullReturn(pcbRead, VERR_INVALID_POINTER); … … 1316 1317 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 1317 1318 AssertReturn(pThis->uMagic == RTVFSIOSTREAM_MAGIC, VERR_INVALID_HANDLE); 1319 AssertReturn(fBlocking || pcbRead, VERR_INVALID_PARAMETER); 1318 1320 1319 1321 RTSGSEG Seg = { pvBuf, cbToRead }; … … 1322 1324 1323 1325 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); 1325 1327 rtVfsObjWriteUnlock(&pThis->Base); 1326 1328 return rc; … … 1328 1330 1329 1331 1330 RTDECL(int) RTVfsIoStrmWrite(RTVFSIOSTREAM hVfsIos, const void *pvBuf, size_t cbToWrite, size_t *pcbWritten)1332 RTDECL(int) RTVfsIoStrmWrite(RTVFSIOSTREAM hVfsIos, const void *pvBuf, size_t cbToWrite, bool fBlocking, size_t *pcbWritten) 1331 1333 { 1332 1334 AssertPtrNullReturn(pcbWritten, VERR_INVALID_POINTER); … … 1336 1338 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 1337 1339 AssertReturn(pThis->uMagic == RTVFSIOSTREAM_MAGIC, VERR_INVALID_HANDLE); 1340 AssertReturn(fBlocking || pcbWritten, VERR_INVALID_PARAMETER); 1338 1341 1339 1342 RTSGSEG Seg = { (void *)pvBuf, cbToWrite }; … … 1342 1345 1343 1346 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); 1345 1348 rtVfsObjWriteUnlock(&pThis->Base); 1346 1349 return rc; … … 1348 1351 1349 1352 1350 RTDECL(int) 1353 RTDECL(int) RTVfsIoStrmSgRead(RTVFSIOSTREAM hVfsIos, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead) 1351 1354 { 1352 1355 AssertPtrNullReturn(pcbRead, VERR_INVALID_POINTER); … … 1366 1369 1367 1370 1368 RTDECL(int) 1371 RTDECL(int) RTVfsIoStrmSgWrite(RTVFSIOSTREAM hVfsIos, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten) 1369 1372 { 1370 1373 AssertPtrNullReturn(pcbWritten, VERR_INVALID_POINTER); … … 1384 1387 1385 1388 1386 RTDECL(int) 1389 RTDECL(int) RTVfsIoStrmFlush(RTVFSIOSTREAM hVfsIos) 1387 1390 { 1388 1391 RTVFSIOSTREAMINTERNAL *pThis = hVfsIos; … … 1397 1400 1398 1401 1399 RTDECL(RTFOFF) 1400 1402 RTDECL(RTFOFF) RTVfsIoStrmPoll(RTVFSIOSTREAM hVfsIos, uint32_t fEvents, RTMSINTERVAL cMillies, bool fIntr, 1403 uint32_t *pfRetEvents) 1401 1404 { 1402 1405 RTVFSIOSTREAMINTERNAL *pThis = hVfsIos; … … 1411 1414 1412 1415 1413 RTDECL(RTFOFF) 1416 RTDECL(RTFOFF) RTVfsIoStrmTell(RTVFSIOSTREAM hVfsIos) 1414 1417 { 1415 1418 RTVFSIOSTREAMINTERNAL *pThis = hVfsIos; … … 1427 1430 1428 1431 1429 RTDECL(int) 1432 RTDECL(int) RTVfsIoStrmSkip(RTVFSIOSTREAM hVfsIos, RTFOFF cb) 1430 1433 { 1431 1434 RTVFSIOSTREAMINTERNAL *pThis = hVfsIos; … … 1451 1454 size_t cbToRead = RT_MIN(cb, _64K); 1452 1455 rtVfsObjWriteLock(&pThis->Base); 1453 rc = RTVfsIoStrmRead(hVfsIos, pvBuf, cbToRead, NULL);1456 rc = RTVfsIoStrmRead(hVfsIos, pvBuf, cbToRead, true /*fBlocking*/, NULL); 1454 1457 rtVfsObjWriteUnlock(&pThis->Base); 1455 1458 if (RT_FAILURE(rc)) … … 1467 1470 1468 1471 1469 RTDECL(int) 1472 RTDECL(int) RTVfsIoStrmZeroFill(RTVFSIOSTREAM hVfsIos, RTFOFF cb) 1470 1473 { 1471 1474 RTVFSIOSTREAMINTERNAL *pThis = hVfsIos; … … 1490 1493 size_t cbToWrite = RT_MIN(cb, _64K); 1491 1494 rtVfsObjWriteLock(&pThis->Base); 1492 rc = RTVfsIoStrmWrite(hVfsIos, pvBuf, cbToWrite, NULL);1495 rc = RTVfsIoStrmWrite(hVfsIos, pvBuf, cbToWrite, true /*fBlocking*/, NULL); 1493 1496 rtVfsObjWriteUnlock(&pThis->Base); 1494 1497 if (RT_FAILURE(rc)) … … 1534 1537 1535 1538 RTVFSINTERNAL *pVfs = NULL; 1536 if (hVfs == NIL_RTVFS)1539 if (hVfs != NIL_RTVFS) 1537 1540 { 1538 1541 pVfs = hVfs; … … 1557 1560 pThis->Stream.pOps = &pFileOps->Stream; 1558 1561 pThis->Stream.Base.pvThis = (char *)pThis + RT_ALIGN_Z(sizeof(*pThis), RTVFS_INST_ALIGNMENT); 1562 pThis->Stream.Base.pOps = &pFileOps->Stream.Obj; 1559 1563 pThis->Stream.Base.hSemRW = pVfs ? pVfs->Base.hSemRW : NIL_RTSEMRW; 1560 1564 pThis->Stream.Base.hVfs = hVfs; -
trunk/src/VBox/Runtime/common/vfs/vfschain.cpp
r33950 r33973 431 431 } 432 432 433 434 433 /* 435 434 * Ok, there should be an element here so add one to the return struct. … … 440 439 pElement->enmAction = enmAction; 441 440 442 /* First comes a type which is followed by a '('. */ 441 /* 442 * First up is the VFS object type followed by a parentheses. 443 */ 443 444 if (strncmp(pszSrc, "base", cch = 4) == 0) 444 445 pElement->enmTypeOut = RTVFSOBJTYPE_BASE; … … 495 496 } 496 497 497 /* Must end with a right par antheses. */498 /* Must end with a right parentheses. */ 498 499 if (*pszSrc != ')') 499 500 { … … 657 658 658 659 660 RTDECL(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 446 446 } 447 447 448 449 RTDECL(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 30 30 *******************************************************************************/ 31 31 #include "internal/iprt.h" 32 #include <iprt/ vfslowlevel.h>32 #include <iprt/zip.h> 33 33 34 34 #include <iprt/assert.h> … … 37 37 #include <iprt/poll.h> 38 38 #include <iprt/string.h> 39 #include <iprt/vfslowlevel.h> 40 39 41 #include <zlib.h> 40 42 … … 477 479 AssertPtrReturn(phVfsIosOut, VERR_INVALID_POINTER); 478 480 481 uint32_t cRefs = RTVfsIoStrmRetain(hVfsIosIn); 482 AssertReturn(cRefs != UINT32_MAX, VERR_INVALID_HANDLE); 483 479 484 /* 480 485 * Create the decompression I/O stream. … … 507 512 */ 508 513 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*/); 510 515 if (RT_SUCCESS(rc)) 511 516 { … … 539 544 } 540 545 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); 542 548 } 549 else 550 RTVfsIoStrmRelease(hVfsIosIn); 543 551 return rc; 544 552 } -
trunk/src/VBox/Runtime/testcase/Makefile.kmk
r33678 r33973 572 572 RTLdrFlt_SOURCES = RTLdrFlt.cpp 573 573 574 # RTGzip - our gzip clone (for testing the gzip/gunzip streaming code) 575 PROGRAMS += RTGzip 576 RTGzip_TEMPLATE = VBOXR3TSTEXE 577 RTGzip_SOURCES = RTGzip.cpp 578 574 579 575 580 -
trunk/src/VBox/Runtime/testcase/RTGzip.cpp
r33911 r33973 31 31 #include <iprt/zip.h> 32 32 33 #include <iprt/buildconfig.h> 34 #include <iprt/file.h> 33 35 #include <iprt/getopt.h> 34 #include <iprt/init .h>36 #include <iprt/initterm.h> 35 37 #include <iprt/message.h> 38 #include <iprt/param.h> 39 #include <iprt/stream.h> 36 40 #include <iprt/string.h> 37 41 #include <iprt/vfs.h> 42 #include <iprt/zip.h> 38 43 39 44 … … 43 48 return false; 44 49 } 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 */ 59 static 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 77 static RTEXITCODE gzipCompress(RTVFSIOSTREAM hVfsIn, RTVFSIOSTREAM hVfsOut) 78 { 79 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Compression is not yet implemented, sorry."); 80 } 81 82 83 static 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 89 static 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 */ 115 static 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 196 static RTEXITCODE gzipTestFile(const char *pszFile, bool fForce) 197 { 198 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Testiong has not been implemented"); 199 } 200 201 202 static RTEXITCODE gzipListFile(const char *pszFile, bool fForce) 203 { 204 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Listing has not been implemented"); 205 } 206 45 207 46 208 int main(int argc, char **argv) … … 53 215 * Parse the command line. 54 216 */ 55 static const RTGETOPTDEF s_aOptions[] 217 static const RTGETOPTDEF s_aOptions[] = 56 218 { 57 219 { "--ascii", 'a', RTGETOPT_REQ_NOTHING }, … … 96 258 RTEXITCODE rcExit = RTEXITCODE_SUCCESS; 97 259 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); 102 265 for (;;) 103 266 { … … 112 275 * input from stdin and write the output to stdout. 113 276 */ 114 if (cProcessed )277 if (cProcessed > 0) 115 278 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 119 285 120 286 if (!fForce && isStdHandleATty(fDecompress ? 0 : 1)) … … 123 289 fDecompress ? "reading" : "writing", 124 290 fDecompress ? "from" : "to"); 291 #else 292 rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "reading from standard input has not yet been implemented"); 293 #endif 125 294 return rcExit; 126 295 } … … 128 297 case VINF_GETOPT_NOT_OPTION: 129 298 { 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; 132 315 133 316 cProcessed++; 134 if (fDecompress)135 {136 }137 else138 {139 if (!*pszSuff && !fStdOut)140 return141 {142 }143 }144 317 break; 145 318 } … … 167 340 case '9': uLevel = 9; break; 168 341 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 169 352 default: 170 return RTGetOptPrintError( ch, &ValueUnion);353 return RTGetOptPrintError(rc, &ValueUnion); 171 354 } 172 355 }
Note:
See TracChangeset
for help on using the changeset viewer.