VirtualBox

source: vbox/trunk/include/iprt/vfs.h@ 70286

Last change on this file since 70286 was 69977, checked in by vboxsync, 7 years ago

IPRT/vfs: Implemented RTVFsFileSetSize, RTVfsFileGetMaxSize and RTvfsFileQueryMaxSize.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 76.6 KB
Line 
1/** @file
2 * IPRT - Virtual Filesystem.
3 */
4
5/*
6 * Copyright (C) 2010-2017 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef ___iprt_vfs_h
27#define ___iprt_vfs_h
28
29#include <iprt/cdefs.h>
30#include <iprt/types.h>
31#include <iprt/dir.h>
32#include <iprt/fs.h>
33#include <iprt/handle.h>
34#include <iprt/symlink.h>
35#include <iprt/sg.h>
36#include <iprt/time.h>
37
38
39RT_C_DECLS_BEGIN
40
41/** @defgroup grp_rt_vfs RTVfs - Virtual Filesystem
42 * @ingroup grp_rt
43 *
44 * The virtual filesystem APIs are intended to make it possible to work on
45 * container files, file system sub-trees, file system overlays and other custom
46 * filesystem configurations. It also makes it possible to create filters, like
47 * automatically gunzipping a tar.gz file before feeding it to the RTTar API for
48 * unpacking - or wise versa.
49 *
50 * The virtual filesystem APIs are intended to mirror the RTDir, RTFile, RTPath
51 * and RTFs APIs pretty closely so that rewriting a piece of code to work with
52 * it should be easy. However there are some differences to the way the APIs
53 * works and the user should heed the documentation. The differences are
54 * usually motivated by simplification and in some case to make the VFS more
55 * flexible.
56 *
57 * @{
58 */
59
60/**
61 * The object type.
62 */
63typedef enum RTVFSOBJTYPE
64{
65 /** Invalid type. */
66 RTVFSOBJTYPE_INVALID = 0,
67 /** Pure base object.
68 * This is returned by the filesystem stream to represent directories,
69 * devices, fifos and similar that needs to be created. */
70 RTVFSOBJTYPE_BASE,
71 /** Virtual filesystem. */
72 RTVFSOBJTYPE_VFS,
73 /** Filesystem stream. */
74 RTVFSOBJTYPE_FS_STREAM,
75 /** Pure I/O stream. */
76 RTVFSOBJTYPE_IO_STREAM,
77 /** Directory. */
78 RTVFSOBJTYPE_DIR,
79 /** File. */
80 RTVFSOBJTYPE_FILE,
81 /** Symbolic link. */
82 RTVFSOBJTYPE_SYMLINK,
83 /** End of valid object types. */
84 RTVFSOBJTYPE_END,
85 /** Pure I/O stream. */
86 RTVFSOBJTYPE_32BIT_HACK = 0x7fffffff
87} RTVFSOBJTYPE;
88/** Pointer to a VFS object type. */
89typedef RTVFSOBJTYPE *PRTVFSOBJTYPE;
90
91
92
93/** @name RTVfsCreate flags
94 * @{ */
95/** Whether the file system is read-only. */
96#define RTVFS_C_READONLY RT_BIT(0)
97/** Whether we the VFS should be thread safe (i.e. automaticaly employ
98 * locks). */
99#define RTVFS_C_THREAD_SAFE RT_BIT(1)
100/** @} */
101
102/**
103 * Creates an empty virtual filesystem.
104 *
105 * @returns IPRT status code.
106 * @param pszName Name, for logging and such.
107 * @param fFlags Flags, MBZ.
108 * @param phVfs Where to return the VFS handle. Release the returned
109 * reference by calling RTVfsRelease.
110 */
111RTDECL(int) RTVfsCreate(const char *pszName, uint32_t fFlags, PRTVFS phVfs);
112RTDECL(uint32_t) RTVfsRetain(RTVFS hVfs);
113RTDECL(uint32_t) RTVfsRetainDebug(RTVFS hVfs, RT_SRC_POS_DECL);
114RTDECL(uint32_t) RTVfsRelease(RTVFS hVfs);
115
116/** @name RTVFSMNT_F_XXX - Flags for RTVfsMount
117 * @{ */
118/** Mount read-only. */
119#define RTVFSMNT_F_READ_ONLY RT_BIT_32(0)
120/** Purpose is . */
121#define RTVFSMNT_F_FOR_RANGE_IN_USE RT_BIT_32(1)
122/** Valid mask. */
123#define RTVFSMNT_F_VALID_MASK UINT32_C(0x00000003)
124/** @} */
125
126/**
127 * Does the file system detection and mounting.
128 *
129 * @returns IPRT status code.
130 * @retval VERR_VFS_UNSUPPORTED_FORMAT if not recognized as a support file
131 * system.
132 * @param hVfsFileIn The file handle of the volume.
133 * @param fFlags RTVFSMTN_F_XXX.
134 * @param phVfs Where to return the VFS handle on success.
135 * @param pErrInfo Where to return additional error information.
136 * Optional.
137 */
138RTDECL(int) RTVfsMountVol(RTVFSFILE hVfsFileIn, uint32_t fFlags, PRTVFS phVfs, PRTERRINFO pErrInfo);
139
140RTDECL(int) RTVfsAttach(RTVFS hVfs, const char *pszMountPoint, uint32_t fFlags, RTVFS hVfsAttach);
141RTDECL(int) RTVfsDetach(RTVFS hVfs, const char *pszMountPoint, RTVFS hVfsToDetach, PRTVFS *phVfsDetached);
142RTDECL(uint32_t) RTVfsGetAttachmentCount(RTVFS hVfs);
143RTDECL(int) RTVfsGetAttachment(RTVFS hVfs, uint32_t iOrdinal, PRTVFS *phVfsAttached, uint32_t *pfFlags,
144 char *pszMountPoint, size_t cbMountPoint);
145
146/**
147 * Queries information about a object in the virtual filesystem.
148 *
149 * @returns IPRT Status code.
150 * @param hVfs VFS handle.
151 * relative to.
152 * @param pszPath Path to the object, relative to the VFS root.
153 * @param pObjInfo Where to return info.
154 * @param enmAddAttr What to return.
155 * @param fFlags RTPATH_F_XXX.
156 * @sa RTPathQueryInfoEx, RTVfsDirQueryPathInfo, RTVfsObjQueryInfo
157 */
158RTDECL(int) RTVfsQueryPathInfo(RTVFS hVfs, const char *pszPath, PRTFSOBJINFO pObjInfo,
159 RTFSOBJATTRADD enmAddAttr, uint32_t fFlags);
160
161/**
162 * Checks whether a given range is in use by the virtual filesystem.
163 *
164 * @returns IPRT status code.
165 * @param hVfs VFS handle.
166 * @param off Start offset to check.
167 * @param cb Number of bytes to check.
168 * @param pfUsed Where to store the result.
169 */
170RTDECL(int) RTVfsQueryRangeState(RTVFS hVfs, uint64_t off, size_t cb, bool *pfUsed);
171
172
173/** @defgroup grp_vfs_obj VFS Base Object API
174 * @{
175 */
176
177/**
178 * Retains a reference to the VFS base object handle.
179 *
180 * @returns New reference count on success, UINT32_MAX on failure.
181 * @param hVfsObj The VFS base object handle.
182 */
183RTDECL(uint32_t) RTVfsObjRetain(RTVFSOBJ hVfsObj);
184RTDECL(uint32_t) RTVfsObjRetainDebug(RTVFSOBJ hVfsObj, RT_SRC_POS_DECL);
185
186/**
187 * Releases a reference to the VFS base handle.
188 *
189 * @returns New reference count on success (0 if closed), UINT32_MAX on failure.
190 * @param hVfsObj The VFS base object handle.
191 */
192RTDECL(uint32_t) RTVfsObjRelease(RTVFSOBJ hVfsObj);
193
194/** @name RTVFSOBJ_F_XXX - Flags or RTVfsObjOpen and RTVfsDirOpenObj.
195 * @note Must leave space for RTPATH_F_XXX.
196 * @{ */
197/** Directory (RTFS_TYPE_DIRECTORY). */
198#define RTVFSOBJ_F_OPEN_DIRECTORY RT_BIT_32(8)
199/** Symbolic link (RTFS_TYPE_SYMLINK). */
200#define RTVFSOBJ_F_OPEN_SYMLINK RT_BIT_32(9)
201/** Regular file (RTFS_TYPE_FILE). */
202#define RTVFSOBJ_F_OPEN_FILE RT_BIT_32(10)
203/** Character device (RTFS_TYPE_DEV_CHAR). */
204#define RTVFSOBJ_F_OPEN_DEV_CHAR RT_BIT_32(11)
205/** Block device (RTFS_TYPE_DEV_BLOCK). */
206#define RTVFSOBJ_F_OPEN_DEV_BLOCK RT_BIT_32(12)
207/** Named pipe (fifo) (RTFS_TYPE_FIFO). */
208#define RTVFSOBJ_F_OPEN_FIFO RT_BIT_32(13)
209/** Socket (RTFS_TYPE_SOCKET). */
210#define RTVFSOBJ_F_OPEN_SOCKET RT_BIT_32(14)
211/** Mounted VFS. */
212#define RTVFSOBJ_F_OPEN_MOUNT RT_BIT_32(15)
213/** Mask object types we wish to open. */
214#define RTVFSOBJ_F_OPEN_MASK UINT32_C(0x0000ff00)
215/** Any kind of object that translates to RTVFSOBJTYPE_FILE. */
216#define RTVFSOBJ_F_OPEN_ANY_FILE (RTVFSOBJ_F_OPEN_FILE | RTVFSOBJ_F_OPEN_DEV_BLOCK)
217/** Any kind of object that translates to RTVFSOBJTYPE_IOS or
218 * RTVFSOBJTYPE_FILE. */
219#define RTVFSOBJ_F_OPEN_ANY_IO_STREAM ( RTVFSOBJ_F_ANY_OPEN_FILE | RTVFSOBJ_F_DEV_OPEN_BLOCK \
220 | RTVFSOBJ_F_OPEN_FIFO | RTVFSOBJ_F_OPEN_SOCKET)
221/** Any kind of object. */
222#define RTVFSOBJ_F_OPEN_ANY RTVFSOBJ_F_OPEN_MASK
223
224/** Do't create anything, return file not found. */
225#define RTVFSOBJ_F_CREATE_NOTHING UINT32_C(0x00000000)
226/** Create a file if the if the object was not found and the RTFILE_O_XXX
227 * flags allows it. */
228#define RTVFSOBJ_F_CREATE_FILE UINT32_C(0x00010000)
229/** Create a directory if the object was not found and the RTFILE_O_XXX
230 * flags allows it. */
231#define RTVFSOBJ_F_CREATE_DIRECTORY UINT32_C(0x00020000)
232/** The creation type mask. */
233#define RTVFSOBJ_F_CREATE_MASK UINT32_C(0x00070000)
234
235/** Indicate that this call is for traversal.
236 * @internal only */
237#define RTVFSOBJ_F_TRAVERSAL RT_BIT_32(31)
238/** Valid mask for external callers. */
239#define RTVFSOBJ_F_VALID_MASK UINT32_C(0x0007ff00)
240/** @} */
241
242/**
243 * Opens any file system object in the given VFS.
244 *
245 * @returns IPRT status code.
246 * @param hVfs The VFS to open the object within.
247 * @param pszPath Path to the file.
248 * @param fFileOpen RTFILE_O_XXX flags.
249 * @param fObjFlags More flags: RTVFSOBJ_F_XXX, RTPATH_F_XXX.
250 * @param phVfsObj Where to return the object handle.
251 * @sa RTVfsDirOpenObj, RTVfsDirOpenDir, RTVfsDirOpenFile
252 */
253RTDECL(int) RTVfsObjOpen(RTVFS hVfs, const char *pszPath, uint64_t fFileOpen, uint32_t fObjFlags, PRTVFSOBJ phVfsObj);
254
255/**
256 * Query information about the object.
257 *
258 * @returns IPRT status code.
259 * @retval VERR_NOT_SUPPORTED if the @a enmAddAttr value is not handled by the
260 * implementation.
261 *
262 * @param hVfsObj The VFS object handle.
263 * @param pObjInfo Where to return the info.
264 * @param enmAddAttr Which additional attributes should be retrieved.
265 * @sa RTVfsIoStrmQueryInfo, RTVfsFileQueryInfo, RTFileQueryInfo,
266 * RTPathQueryInfo
267 */
268RTDECL(int) RTVfsObjQueryInfo(RTVFSOBJ hVfsObj, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr);
269
270/**
271 * Sets the file mode for the given VFS object.
272 *
273 * @returns IPRT status code.
274 * @retval VERR_INVALID_FUNCTION if the object type has no file mode to set.
275 * Only directories, files and symbolic links support this operation.
276 *
277 * @param hVfsObj The VFS object handle.
278 * @param fMode The mode mask.
279 * @param fMask The bits in the mode mask which should be changed.
280 */
281RTDECL(int) RTVfsObjSetMode(RTVFSOBJ hVfsObj, RTFMODE fMode, RTFMODE fMask);
282
283/**
284 * Sets one or more timestamps for the given VFS object.
285 *
286 * @returns IPRT status code.
287 * @retval VERR_INVALID_FUNCTION if the object type has no file mode to set.
288 * Only directories, files and symbolic links support this operation.
289 *
290 * @param hVfsObj The VFS object handle.
291 * @param pAccessTime Pointer to the new access time. NULL if not to
292 * be changed.
293 * @param pModificationTime Pointer to the new modifcation time. NULL if not
294 * to be changed.
295 * @param pChangeTime Pointer to the new change time. NULL if not to
296 * be changed.
297 * @param pBirthTime Pointer to the new time of birth. NULL if not to
298 * be changed.
299 *
300 * @remarks See RTFileSetTimes for restrictions and behavior imposed by the
301 * host OS or underlying VFS provider.
302 * @sa RTFileSetTimes, RTPathSetTimes
303 */
304RTDECL(int) RTVfsObjSetTimes(RTVFSOBJ hVfsObj, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
305 PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime);
306
307/**
308 * Set the unix style owner and group on the given VFS object.
309 *
310 * @returns IPRT status code.
311 * @retval VERR_INVALID_FUNCTION if the object type has no file mode to set.
312 * Only directories, files and symbolic links support this operation.
313 *
314 * @param hVfsObj The VFS object handle.
315 * @param uid The user ID of the new owner. NIL_RTUID if
316 * unchanged.
317 * @param gid The group ID of the new owner group. NIL_RTGID if
318 * unchanged.
319 *
320 * @sa RTFileSetOwner, RTPathSetOwner.
321 */
322RTDECL(int) RTVfsObjSetOwner(RTVFSOBJ hVfsObj, RTUID uid, RTGID gid);
323
324
325/**
326 * Gets the type of a VFS object.
327 *
328 * @returns The VFS object type on success, RTVFSOBJTYPE_INVALID on failure.
329 * @param hVfsObj The VFS base object handle.
330 */
331RTDECL(RTVFSOBJTYPE) RTVfsObjGetType(RTVFSOBJ hVfsObj);
332
333/**
334 * Converts a VFS base object handle to a VFS handle.
335 *
336 * @returns Referenced handle on success, NIL on failure.
337 * @param hVfsObj The VFS base object handle.
338 */
339RTDECL(RTVFS) RTVfsObjToVfs(RTVFSOBJ hVfsObj);
340
341/**
342 * Converts a VFS base object handle to a VFS filesystem stream handle.
343 *
344 * @returns Referenced handle on success, NIL on failure.
345 * @param hVfsObj The VFS base object handle.
346 */
347RTDECL(RTVFSFSSTREAM) RTVfsObjToFsStream(RTVFSOBJ hVfsObj);
348
349/**
350 * Converts a VFS base object handle to a VFS directory handle.
351 *
352 * @returns Referenced handle on success, NIL on failure.
353 * @param hVfsObj The VFS base object handle.
354 */
355RTDECL(RTVFSDIR) RTVfsObjToDir(RTVFSOBJ hVfsObj);
356
357/**
358 * Converts a VFS base object handle to a VFS I/O stream handle.
359 *
360 * @returns Referenced handle on success, NIL on failure.
361 * @param hVfsObj The VFS base object handle.
362 */
363RTDECL(RTVFSIOSTREAM) RTVfsObjToIoStream(RTVFSOBJ hVfsObj);
364
365/**
366 * Converts a VFS base object handle to a VFS file handle.
367 *
368 * @returns Referenced handle on success, NIL on failure.
369 * @param hVfsObj The VFS base object handle.
370 */
371RTDECL(RTVFSFILE) RTVfsObjToFile(RTVFSOBJ hVfsObj);
372
373/**
374 * Converts a VFS base object handle to a VFS symbolic link handle.
375 *
376 * @returns Referenced handle on success, NIL on failure.
377 * @param hVfsObj The VFS base object handle.
378 */
379RTDECL(RTVFSSYMLINK) RTVfsObjToSymlink(RTVFSOBJ hVfsObj);
380
381
382/**
383 * Converts a VFS handle to a VFS base object handle.
384 *
385 * @returns Referenced handle on success, NIL if the input handle was invalid.
386 * @param hVfs The VFS handle.
387 */
388RTDECL(RTVFSOBJ) RTVfsObjFromVfs(RTVFS hVfs);
389
390/**
391 * Converts a VFS filesystem stream handle to a VFS base object handle.
392 *
393 * @returns Referenced handle on success, NIL if the input handle was invalid.
394 * @param hVfsFss The VFS filesystem stream handle.
395 */
396RTDECL(RTVFSOBJ) RTVfsObjFromFsStream(RTVFSFSSTREAM hVfsFss);
397
398/**
399 * Converts a VFS directory handle to a VFS base object handle.
400 *
401 * @returns Referenced handle on success, NIL if the input handle was invalid.
402 * @param hVfsDir The VFS directory handle.
403 */
404RTDECL(RTVFSOBJ) RTVfsObjFromDir(RTVFSDIR hVfsDir);
405
406/**
407 * Converts a VFS I/O stream handle to a VFS base object handle.
408 *
409 * @returns Referenced handle on success, NIL if the input handle was invalid.
410 * @param hVfsIos The VFS I/O stream handle.
411 */
412RTDECL(RTVFSOBJ) RTVfsObjFromIoStream(RTVFSIOSTREAM hVfsIos);
413
414/**
415 * Converts a VFS file handle to a VFS base object handle.
416 *
417 * @returns Referenced handle on success, NIL if the input handle was invalid.
418 * @param hVfsFile The VFS file handle.
419 */
420RTDECL(RTVFSOBJ) RTVfsObjFromFile(RTVFSFILE hVfsFile);
421
422/**
423 * Converts a VFS symbolic link handle to a VFS base object handle.
424 *
425 * @returns Referenced handle on success, NIL if the input handle was invalid.
426 * @param hVfsSym The VFS symbolic link handle.
427 */
428RTDECL(RTVFSOBJ) RTVfsObjFromSymlink(RTVFSSYMLINK hVfsSym);
429
430/** @} */
431
432
433/** @defgroup grp_vfs_fsstream VFS Filesystem Stream API
434 *
435 * Filesystem streams are for tar, cpio and similar. Any virtual filesystem can
436 * be turned into a filesystem stream using RTVfsFsStrmFromVfs.
437 *
438 * @{
439 */
440
441RTDECL(uint32_t) RTVfsFsStrmRetain(RTVFSFSSTREAM hVfsFss);
442RTDECL(uint32_t) RTVfsFsStrmRetainDebug(RTVFSFSSTREAM hVfsFss, RT_SRC_POS_DECL);
443RTDECL(uint32_t) RTVfsFsStrmRelease(RTVFSFSSTREAM hVfsFss);
444RTDECL(int) RTVfsFsStrmQueryInfo(RTVFSFSSTREAM hVfsFss, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr);
445
446/**
447 * Gets the next object in the stream.
448 *
449 * This call may affect the stream posision of a previously returned object.
450 *
451 * The type of object returned here typically boils down to three types:
452 * - I/O streams (representing files),
453 * - symbolic links
454 * - base object
455 * The base objects represent anything not convered by the two other, i.e.
456 * directories, device nodes, fifos, sockets and whatnot. The details can be
457 * queried using RTVfsObjQueryInfo.
458 *
459 * That said, absolutely any object except for filesystem stream objects can be
460 * returned by this call. Any generic code is adviced to just deal with it all.
461 *
462 * @returns IPRT status code.
463 * @retval VINF_SUCCESS if a new object was retrieved.
464 * @retval VERR_EOF when there are no more objects.
465 * @retval VERR_INVALID_FUNCTION if called on a non-readable stream.
466 *
467 * @param hVfsFss The file system stream handle.
468 * @param ppszName Where to return the object name. Must be freed by
469 * calling RTStrFree.
470 * @param penmType Where to return the object type.
471 * @param phVfsObj Where to return the object handle (referenced). This
472 * must be cast to the desired type before use.
473 */
474RTDECL(int) RTVfsFsStrmNext(RTVFSFSSTREAM hVfsFss, char **ppszName, RTVFSOBJTYPE *penmType, PRTVFSOBJ phVfsObj);
475
476/**
477 * Appends a VFS object to the stream.
478 *
479 * The stream must be writable.
480 *
481 * @returns IPRT status code.
482 * @retval VERR_INVALID_FUNCTION if called on a non-writable stream.
483 * @param hVfsFss The file system stream handle.
484 * @param pszPath The path.
485 * @param hVfsObj The VFS object to add.
486 * @param fFlags RTVFSFSSTRM_ADD_F_XXX.
487 */
488RTDECL(int) RTVfsFsStrmAdd(RTVFSFSSTREAM hVfsFss, const char *pszPath, RTVFSOBJ hVfsObj, uint32_t fFlags);
489
490/** @name RTVFSFSSTRM_ADD_F_XXX - Flags for RTVfsFsStrmAdd.
491 * @{ */
492/** Input is an I/O stream of indeterminate length, read to the end and then
493 * update the file header.
494 * @note This is *only* possible if the output stream is actually a file. */
495#define RTVFSFSSTRM_ADD_F_STREAM RT_BIT_32(0)
496/** Mask of flags specific to the target stream. */
497#define RTVFSFSSTRM_ADD_F_SPECIFIC_MASK UINT32_C(0xff000000)
498/** Valid bits. */
499#define RTVFSFSSTRM_ADD_F_VALID_MASK UINT32_C(0xff000001)
500/** @} */
501
502/**
503 * Pushes an byte stream onto the stream.
504 *
505 * The stream must be writable.
506 *
507 * This differs from RTVfsFsStrmAdd() in that it will create a regular file in
508 * the output file system stream and provide the actual content bytes via the
509 * returned I/O stream object.
510 *
511 * @returns IPRT status code.
512 * @retval VERR_INVALID_FUNCTION if called on a non-writable stream.
513 * @param hVfsFss The file system stream handle.
514 * @param pszPath The path to the file.
515 * @param cbFile The file size. This can also be set to UINT64_MAX if
516 * the file system stream is backed by a file.
517 * @param paObjInfo Array of zero or more RTFSOBJINFO structures containing
518 * different pieces of information about the file. If any
519 * provided, the first one should be a RTFSOBJATTRADD_UNIX
520 * one, additional can be supplied if wanted. What exactly
521 * is needed depends on the underlying FS stream
522 * implementation.
523 * @param cObjInfo Number of items in the array @a paObjInfo points at.
524 * @param fFlags RTVFSFSSTRM_PUSH_F_XXX.
525 * @param phVfsIos Where to return the I/O stream to feed the file content
526 * to. If the FS stream is backed by a file, the returned
527 * handle can be cast to a file if necessary.
528 */
529RTDECL(int) RTVfsFsStrmPushFile(RTVFSFSSTREAM hVfsFss, const char *pszPath, uint64_t cbFile,
530 PCRTFSOBJINFO paObjInfo, uint32_t cObjInfo, uint32_t fFlags, PRTVFSIOSTREAM phVfsIos);
531
532/** @name RTVFSFSSTRM_PUSH_F_XXX - Flags for RTVfsFsStrmPushFile.
533 * @{ */
534/** Input is an I/O stream of indeterminate length, read to the end and then
535 * update the file header.
536 * @note This is *only* possible if the output stream is actually a file. */
537#define RTVFSFSSTRM_PUSH_F_STREAM RT_BIT_32(0)
538/** Mask of flags specific to the target stream. */
539#define RTVFSFSSTRM_PUSH_F_SPECIFIC_MASK UINT32_C(0xff000000)
540/** Valid bits. */
541#define RTVFSFSSTRM_PUSH_F_VALID_MASK UINT32_C(0xff000001)
542/** @} */
543
544/**
545 * Marks the end of the stream.
546 *
547 * The stream must be writable.
548 *
549 * @returns IPRT status code.
550 * @retval VERR_INVALID_FUNCTION if called on a non-writable stream.
551 * @param hVfsFss The file system stream handle.
552 */
553RTDECL(int) RTVfsFsStrmEnd(RTVFSFSSTREAM hVfsFss);
554
555/** @} */
556
557
558/** @defgroup grp_vfs_dir VFS Directory API
559 * @{
560 */
561
562/**
563 * Retains a reference to the VFS directory handle.
564 *
565 * @returns New reference count on success, UINT32_MAX on failure.
566 * @param hVfsDir The VFS directory handle.
567 */
568RTDECL(uint32_t) RTVfsDirRetain(RTVFSDIR hVfsDir);
569RTDECL(uint32_t) RTVfsDirRetainDebug(RTVFSDIR hVfsDir, RT_SRC_POS_DECL);
570
571/**
572 * Releases a reference to the VFS directory handle.
573 *
574 * @returns New reference count on success (0 if closed), UINT32_MAX on failure.
575 * @param hVfsDir The VFS directory handle.
576 */
577RTDECL(uint32_t) RTVfsDirRelease(RTVFSDIR hVfsDir);
578
579/**
580 * Opens a directory in the specified file system.
581 *
582 * @returns IPRT status code.
583 * @param hVfs The VFS to open the directory within.
584 * @param pszPath Path to the directory, relative to the root.
585 * @param fFlags Reserved, MBZ.
586 * @param phVfsDir Where to return the directory.
587 */
588RTDECL(int) RTVfsDirOpen(RTVFS hVfs, const char *pszPath, uint32_t fFlags, PRTVFSDIR phVfsDir);
589
590/**
591 * Opens any file system object in or under the given directory.
592 *
593 * @returns IPRT status code.
594 * @param hVfsDir The VFS directory start walking the @a pszPath
595 * relative to.
596 * @param pszPath Path to the file.
597 * @param fFileOpen RTFILE_O_XXX flags.
598 * @param fObjFlags More flags: RTVFSOBJ_F_XXX, RTPATH_F_XXX.
599 * @param phVfsObj Where to return the object handle.
600 * @sa RTVfsObjOpen, RTVfsDirOpenDir, RTVfsDirOpenFile
601 */
602RTDECL(int) RTVfsDirOpenObj(RTVFSDIR hVfsDir, const char *pszPath, uint64_t fFileOpen, uint32_t fObjFlags, PRTVFSOBJ phVfsObj);
603
604/**
605 * Opens a file in or under the given directory.
606 *
607 * @returns IPRT status code.
608 * @param hVfsDir The VFS directory start walking the @a pszPath
609 * relative to.
610 * @param pszPath Path to the file.
611 * @param fOpen RTFILE_O_XXX flags.
612 * @param phVfsFile Where to return the file.
613 * @sa RTVfsDirOpenFileAsIoStream
614 */
615RTDECL(int) RTVfsDirOpenFile(RTVFSDIR hVfsDir, const char *pszPath, uint64_t fOpen, PRTVFSFILE phVfsFile);
616
617/**
618 * Convenience wrapper around RTVfsDirOpenFile that returns an I/O stream.
619 *
620 * @returns IPRT status code.
621 * @param hVfsDir The VFS directory start walking the @a pszPath
622 * relative to.
623 * @param pszPath Path to the file.
624 * @param fOpen RTFILE_O_XXX flags.
625 * @param phVfsIos Where to return the I/O stream handle of the file.
626 * @sa RTVfsDirOpenFile
627 */
628RTDECL(int) RTVfsDirOpenFileAsIoStream(RTVFSDIR hVfsDir, const char *pszPath, uint64_t fOpen, PRTVFSIOSTREAM phVfsIos);
629
630/**
631 * Opens a directory in or under the given directory.
632 *
633 * @returns IPRT status code.
634 * @param hVfsDir The VFS directory start walking the @a pszPath
635 * relative to.
636 * @param pszPath Path to the file.
637 * @param fFlags Reserved, MBZ.
638 * @param phVfsDir Where to return the directory.
639 */
640RTDECL(int) RTVfsDirOpenDir(RTVFSDIR hVfsDir, const char *pszPath, uint32_t fFlags, PRTVFSDIR phVfsDir);
641
642/**
643 * Creates a directory relative to @a hVfsDir.
644 *
645 * @returns IPRT status code
646 * @param hVfsDir The directory the path is relative to.
647 * @param pszRelPath The relative path to the new directory.
648 * @param fMode The file mode for the new directory.
649 * @param fFlags Directory creation flags, RTDIRCREATE_FLAGS_XXX.
650 * @param phVfsDir Where to return the handle to the newly created
651 * directory. Optional.
652 * @sa RTDirCreate, RTDirRelDirCreate
653 */
654RTDECL(int) RTVfsDirCreateDir(RTVFSDIR hVfsDir, const char *pszRelPath, RTFMODE fMode, uint32_t fFlags, PRTVFSDIR phVfsDir);
655
656/**
657 * Create a VFS directory handle from a standard IPRT directory handle (RTDIR).
658 *
659 * @returns IPRT status code.
660 * @param hDir The standard IPRT directory handle.
661 * @param fLeaveOpen Whether to leave the handle open when the VFS
662 * directory is released, or to close it (@c false).
663 * @param phVfsDir Where to return the VFS directory handle.
664 */
665RTDECL(int) RTVfsDirFromRTDir(RTDIR hDir, bool fLeaveOpen, PRTVFSDIR phVfsDir);
666
667/**
668 * RTDirOpen + RTVfsDirFromRTDir.
669 *
670 * @returns IPRT status code.
671 * @param pszPath The path to the directory.
672 * @param fFlags RTDIR_F_XXX.
673 * @param phVfsDir Where to return the VFS directory handle.
674 */
675RTDECL(int) RTVfsDirOpenNormal(const char *pszPath, uint32_t fFlags, PRTVFSDIR phVfsDir);
676
677/**
678 * Queries information about a object in or under the given directory.
679 *
680 * @returns IPRT Status code.
681 * @param hVfsDir The VFS directory start walking the @a pszPath
682 * relative to.
683 * @param pszPath Path to the object.
684 * @param pObjInfo Where to return info.
685 * @param enmAddAttr What to return.
686 * @param fFlags RTPATH_F_XXX.
687 * @sa RTPathQueryInfoEx, RTVfsQueryPathInfo, RTVfsObjQueryInfo
688 */
689RTDECL(int) RTVfsDirQueryPathInfo(RTVFSDIR hVfsDir, const char *pszPath, PRTFSOBJINFO pObjInfo,
690 RTFSOBJATTRADD enmAddAttr, uint32_t fFlags);
691
692/**
693 * Removes a directory relative to @a hVfsDir.
694 *
695 * @returns IPRT status code.
696 * @param hVfsDir The VFS directory to start walking the @a pszRelPath
697 * relative to.
698 * @param pszRelPath The path to the directory that should be removed.
699 * @param fFlags Reserved, MBZ.
700 */
701RTDECL(int) RTVfsDirRemoveDir(RTVFSDIR hVfsDir, const char *pszRelPath, uint32_t fFlags);
702
703/**
704 * Reads the next entry in the directory returning extended information.
705 *
706 * @returns VINF_SUCCESS and data in pDirEntry on success.
707 * @returns VERR_NO_MORE_FILES when the end of the directory has been reached.
708 * @returns VERR_BUFFER_OVERFLOW if the buffer is too small to contain the filename. If
709 * pcbDirEntry is specified it will be updated with the required buffer size.
710 * @returns suitable iprt status code on other errors.
711 *
712 * @param hVfsDir The VFS directory.
713 * @param pDirEntry Where to store the information about the next
714 * directory entry on success.
715 * @param pcbDirEntry Optional parameter used for variable buffer size.
716 *
717 * On input the variable pointed to contains the size of the pDirEntry
718 * structure. This must be at least OFFSET(RTDIRENTRYEX, szName[2]) bytes.
719 *
720 * On successful output the field is updated to
721 * OFFSET(RTDIRENTRYEX, szName[pDirEntry->cbName + 1]).
722 *
723 * When the data doesn't fit in the buffer and VERR_BUFFER_OVERFLOW is
724 * returned, this field contains the required buffer size.
725 *
726 * The value is unchanged in all other cases.
727 * @param enmAddAttr Which set of additional attributes to request.
728 * Use RTFSOBJATTRADD_NOTHING if this doesn't matter.
729 *
730 * @sa RTDirReadEx
731 */
732RTDECL(int) RTVfsDirReadEx(RTVFSDIR hVfsDir, PRTDIRENTRYEX pDirEntry, size_t *pcbDirEntry, RTFSOBJATTRADD enmAddAttr);
733
734/** @} */
735
736
737/** @defgroup grp_vfs_symlink VFS Symbolic Link API
738 *
739 * @remarks The TAR VFS and filesystem stream uses symbolic links for
740 * describing hard links as well. The users must use RTFS_IS_SYMLINK
741 * to check if it is a real symlink in those cases.
742 *
743 * @remarks Any VFS which is backed by a real file system may be subject to
744 * races with other processes or threads, so the user may get
745 * unexpected errors when this happends. This is a bit host specific,
746 * i.e. it might be prevent on windows if we care.
747 *
748 * @{
749 */
750
751
752/**
753 * Retains a reference to the VFS symbolic link handle.
754 *
755 * @returns New reference count on success, UINT32_MAX on failure.
756 * @param hVfsSym The VFS symbolic link handle.
757 */
758RTDECL(uint32_t) RTVfsSymlinkRetain(RTVFSSYMLINK hVfsSym);
759RTDECL(uint32_t) RTVfsSymlinkRetainDebug(RTVFSSYMLINK hVfsSym, RT_SRC_POS_DECL);
760
761/**
762 * Releases a reference to the VFS symbolic link handle.
763 *
764 * @returns New reference count on success (0 if closed), UINT32_MAX on failure.
765 * @param hVfsSym The VFS symbolic link handle.
766 */
767RTDECL(uint32_t) RTVfsSymlinkRelease(RTVFSSYMLINK hVfsSym);
768
769/**
770 * Query information about the symbolic link.
771 *
772 * @returns IPRT status code.
773 * @param hVfsSym The VFS symbolic link handle.
774 * @param pObjInfo Where to return the info.
775 * @param enmAddAttr Which additional attributes should be retrieved.
776 *
777 * @sa RTFileQueryInfo, RTPathQueryInfo, RTPathQueryInfoEx
778 */
779RTDECL(int) RTVfsSymlinkQueryInfo(RTVFSSYMLINK hVfsSym, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr);
780
781/**
782 * Set the unix style owner and group.
783 *
784 * @returns IPRT status code.
785 * @param hVfsSym The VFS symbolic link handle.
786 * @param fMode The new mode bits.
787 * @param fMask The mask indicating which bits we are changing.
788 * @sa RTFileSetMode, RTPathSetMode
789 */
790RTDECL(int) RTVfsSymlinkSetMode(RTVFSSYMLINK hVfsSym, RTFMODE fMode, RTFMODE fMask);
791
792/**
793 * Set the timestamps associated with the object.
794 *
795 * @returns IPRT status code.
796 * @param hVfsSym The VFS symbolic link handle.
797 * @param pAccessTime Pointer to the new access time. NULL if not
798 * to be changed.
799 * @param pModificationTime Pointer to the new modifcation time. NULL if
800 * not to be changed.
801 * @param pChangeTime Pointer to the new change time. NULL if not to be
802 * changed.
803 * @param pBirthTime Pointer to the new time of birth. NULL if not to be
804 * changed.
805 * @remarks See RTFileSetTimes for restrictions and behavior imposed by the
806 * host OS or underlying VFS provider.
807 * @sa RTFileSetTimes, RTPathSetTimes
808 */
809RTDECL(int) RTVfsSymlinkSetTimes(RTVFSSYMLINK hVfsSym, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
810 PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime);
811
812/**
813 * Set the unix style owner and group.
814 *
815 * @returns IPRT status code.
816 * @param hVfsSym The VFS symbolic link handle.
817 * @param uid The user ID of the new owner. NIL_RTUID if
818 * unchanged.
819 * @param gid The group ID of the new owner group. NIL_RTGID if
820 * unchanged.
821 * @sa RTFileSetOwner, RTPathSetOwner.
822 */
823RTDECL(int) RTVfsSymlinkSetOwner(RTVFSSYMLINK hVfsSym, RTUID uid, RTGID gid);
824
825/**
826 * Read the symbolic link target.
827 *
828 * @returns IPRT status code.
829 * @param hVfsSym The VFS symbolic link handle.
830 * @param pszTarget The target buffer.
831 * @param cbTarget The size of the target buffer.
832 * @sa RTSymlinkRead
833 */
834RTDECL(int) RTVfsSymlinkRead(RTVFSSYMLINK hVfsSym, char *pszTarget, size_t cbTarget);
835
836/** @} */
837
838
839
840/** @defgroup grp_vfs_iostream VFS I/O Stream API
841 * @{
842 */
843
844/**
845 * Creates a VFS file from a memory buffer.
846 *
847 * @returns IPRT status code.
848 *
849 * @param fFlags A combination of RTFILE_O_READ and RTFILE_O_WRITE.
850 * @param pvBuf The buffer. This will be copied and not referenced
851 * after this function returns.
852 * @param cbBuf The buffer size.
853 * @param phVfsIos Where to return the VFS I/O stream handle.
854 */
855RTDECL(int) RTVfsIoStrmFromBuffer(uint32_t fFlags, void const *pvBuf, size_t cbBuf, PRTVFSIOSTREAM phVfsIos);
856
857/**
858 * Creates a VFS I/O stream handle from a standard IPRT file handle (RTFILE).
859 *
860 * @returns IPRT status code.
861 * @param hFile The standard IPRT file handle.
862 * @param fOpen The flags the handle was opened with. Pass 0 to
863 * have these detected.
864 * @param fLeaveOpen Whether to leave the handle open when the VFS file
865 * is released, or to close it (@c false).
866 * @param phVfsIos Where to return the VFS I/O stream handle.
867 */
868RTDECL(int) RTVfsIoStrmFromRTFile(RTFILE hFile, uint64_t fOpen, bool fLeaveOpen, PRTVFSIOSTREAM phVfsIos);
869
870/**
871 * Creates a VFS I/O stream handle from a standard IPRT pipe handle (RTPIPE).
872 *
873 * @returns IPRT status code.
874 * @param hPipe The standard IPRT pipe handle.
875 * @param fLeaveOpen Whether to leave the handle open when the VFS file
876 * is released, or to close it (@c false).
877 * @param phVfsIos Where to return the VFS I/O stream handle.
878 */
879RTDECL(int) RTVfsIoStrmFromRTPipe(RTPIPE hPipe, bool fLeaveOpen, PRTVFSIOSTREAM phVfsIos);
880
881/**
882 * Convenience function combining RTFileOpen with RTVfsIoStrmFromRTFile.
883 *
884 * @returns IPRT status code.
885 * @param pszFilename The path to the file in the normal file system.
886 * @param fOpen The flags to pass to RTFileOpen when opening the
887 * file, i.e. RTFILE_O_XXX.
888 * @param phVfsIos Where to return the VFS I/O stream handle.
889 */
890RTDECL(int) RTVfsIoStrmOpenNormal(const char *pszFilename, uint64_t fOpen, PRTVFSIOSTREAM phVfsIos);
891
892/**
893 * Create a VFS I/O stream handle from one of the standard handles.
894 *
895 * @returns IPRT status code.
896 * @param enmStdHandle The standard IPRT file handle.
897 * @param fOpen The flags the handle was opened with. Pass 0 to
898 * have these detected.
899 * @param fLeaveOpen Whether to leave the handle open when the VFS file
900 * is released, or to close it (@c false).
901 * @param phVfsIos Where to return the VFS I/O stream handle.
902 */
903RTDECL(int) RTVfsIoStrmFromStdHandle(RTHANDLESTD enmStdHandle, uint64_t fOpen, bool fLeaveOpen,
904 PRTVFSIOSTREAM phVfsIos);
905
906/**
907 * Retains a reference to the VFS I/O stream handle.
908 *
909 * @returns New reference count on success, UINT32_MAX on failure.
910 * @param hVfsIos The VFS I/O stream handle.
911 */
912RTDECL(uint32_t) RTVfsIoStrmRetain(RTVFSIOSTREAM hVfsIos);
913RTDECL(uint32_t) RTVfsIoStrmRetainDebug(RTVFSIOSTREAM hVfsIos, RT_SRC_POS_DECL);
914
915/**
916 * Releases a reference to the VFS I/O stream handle.
917 *
918 * @returns New reference count on success (0 if closed), UINT32_MAX on failure.
919 * @param hVfsIos The VFS I/O stream handle.
920 */
921RTDECL(uint32_t) RTVfsIoStrmRelease(RTVFSIOSTREAM hVfsIos);
922
923/**
924 * Convert the VFS I/O stream handle to a VFS file handle.
925 *
926 * @returns The VFS file handle on success, this must be released.
927 * NIL_RTVFSFILE if the I/O stream handle is invalid.
928 * @param hVfsIos The VFS I/O stream handle.
929 * @sa RTVfsFileToIoStream
930 */
931RTDECL(RTVFSFILE) RTVfsIoStrmToFile(RTVFSIOSTREAM hVfsIos);
932
933/**
934 * Query information about the I/O stream.
935 *
936 * @returns IPRT status code.
937 * @param hVfsIos The VFS I/O stream handle.
938 * @param pObjInfo Where to return the info.
939 * @param enmAddAttr Which additional attributes should be retrieved.
940 * @sa RTFileQueryInfo
941 */
942RTDECL(int) RTVfsIoStrmQueryInfo(RTVFSIOSTREAM hVfsIos, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr);
943
944/**
945 * Read bytes from the I/O stream.
946 *
947 * @returns IPRT status code.
948 * @retval VINF_SUCCESS and the number of bytes read written to @a pcbRead.
949 * @retval VINF_TRY_AGAIN if @a fBlocking is @c false, @a pcbRead is not NULL,
950 * and no data was available. @a *pcbRead will be set to 0.
951 * @retval VINF_EOF when trying to read __beyond__ the end of the stream and
952 * @a pcbRead is not NULL (it will be set to the number of bytes read,
953 * or 0 if the end of the stream was reached before this call).
954 * When the last byte of the read request is the last byte in the
955 * stream, this status code will not be used. However, VINF_EOF is
956 * returned when attempting to read 0 bytes while standing at the end
957 * of the stream.
958 * @retval VERR_EOF when trying to read __beyond__ the end of the stream and
959 * @a pcbRead is NULL.
960 * @retval VERR_ACCESS_DENIED if the stream is not readable.
961 *
962 * @param hVfsIos The VFS I/O stream handle.
963 * @param pvBuf Where to store the read bytes.
964 * @param cbToRead The number of bytes to read.
965 * @param fBlocking Whether the call is blocking (@c true) or not. If
966 * not, the @a pcbRead parameter must not be NULL.
967 * @param pcbRead Where to always store the number of bytes actually
968 * read. This can be NULL if @a fBlocking is true.
969 * @sa RTVfsFileRead, RTFileRead, RTPipeRead, RTPipeReadBlocking,
970 * RTSocketRead
971 */
972RTDECL(int) RTVfsIoStrmRead(RTVFSIOSTREAM hVfsIos, void *pvBuf, size_t cbToRead, bool fBlocking, size_t *pcbRead);
973
974/**
975 * Read bytes from the I/O stream, optionally with offset.
976 *
977 * @returns IPRT status code.
978 * @retval VINF_SUCCESS and the number of bytes read written to @a pcbRead.
979 * @retval VINF_TRY_AGAIN if @a fBlocking is @c false, @a pcbRead is not NULL,
980 * and no data was available. @a *pcbRead will be set to 0.
981 * @retval VINF_EOF when trying to read __beyond__ the end of the stream and
982 * @a pcbRead is not NULL (it will be set to the number of bytes read,
983 * or 0 if the end of the stream was reached before this call).
984 * When the last byte of the read request is the last byte in the
985 * stream, this status code will not be used. However, VINF_EOF is
986 * returned when attempting to read 0 bytes while standing at the end
987 * of the stream.
988 * @retval VERR_EOF when trying to read __beyond__ the end of the stream and
989 * @a pcbRead is NULL.
990 * @retval VERR_ACCESS_DENIED if the stream is not readable.
991 *
992 * @param hVfsIos The VFS I/O stream handle.
993 * @param off Where to read at, -1 for the current position.
994 * @param pvBuf Where to store the read bytes.
995 * @param cbToRead The number of bytes to read.
996 * @param fBlocking Whether the call is blocking (@c true) or not. If
997 * not, the @a pcbRead parameter must not be NULL.
998 * @param pcbRead Where to always store the number of bytes actually
999 * read. This can be NULL if @a fBlocking is true.
1000 * @sa RTVfsFileRead, RTFileRead, RTPipeRead, RTPipeReadBlocking,
1001 * RTSocketRead
1002 */
1003RTDECL(int) RTVfsIoStrmReadAt(RTVFSIOSTREAM hVfsIos, RTFOFF off, void *pvBuf, size_t cbToRead, bool fBlocking, size_t *pcbRead);
1004
1005/**
1006 * Reads the remainder of the stream into a memory buffer.
1007 *
1008 * For simplifying string-style processing, the is a zero byte after the
1009 * returned buffer, making sure it can be used as a zero terminated string.
1010 *
1011 * @returns IPRT status code.
1012 * @param hVfsIos The VFS I/O stream handle.
1013 * @param ppvBuf Where to return the buffer. Must pass to
1014 * RTVfsIoStrmReadAllFree for freeing, not RTMemFree!
1015 * @param pcbBuf Where to return the buffer size.
1016 */
1017RTDECL(int) RTVfsIoStrmReadAll(RTVFSIOSTREAM hVfsIos, void **ppvBuf, size_t *pcbBuf);
1018
1019/**
1020 * Free memory buffer returned by RTVfsIoStrmReadAll.
1021 *
1022 * @param pvBuf What RTVfsIoStrmReadAll returned.
1023 * @param cbBuf What RTVfsIoStrmReadAll returned.
1024 */
1025RTDECL(void) RTVfsIoStrmReadAllFree(void *pvBuf, size_t cbBuf);
1026
1027/**
1028 * Write bytes to the I/O stream.
1029 *
1030 * @returns IPRT status code.
1031 * @retval VERR_ACCESS_DENIED if the stream is not writable.
1032 *
1033 * @param hVfsIos The VFS I/O stream handle.
1034 * @param pvBuf The bytes to write.
1035 * @param cbToWrite The number of bytes to write.
1036 * @param fBlocking Whether the call is blocking (@c true) or not. If
1037 * not, the @a pcbWritten parameter must not be NULL.
1038 * @param pcbWritten Where to always store the number of bytes actually
1039 * written. This can be NULL if @a fBlocking is true.
1040 * @sa RTVfsFileWrite, RTFileWrite, RTPipeWrite, RTPipeWriteBlocking,
1041 * RTSocketWrite
1042 */
1043RTDECL(int) RTVfsIoStrmWrite(RTVFSIOSTREAM hVfsIos, const void *pvBuf, size_t cbToWrite, bool fBlocking, size_t *pcbWritten);
1044RTDECL(int) RTVfsIoStrmWriteAt(RTVFSIOSTREAM hVfsIos, RTFOFF off, const void *pvBuf, size_t cbToWrite, bool fBlocking, size_t *pcbWritten);
1045
1046/**
1047 * Reads bytes from the I/O stream into a scatter buffer.
1048 *
1049 * @returns IPRT status code.
1050 * @retval VINF_SUCCESS and the number of bytes read written to @a pcbRead.
1051 * @retval VINF_TRY_AGAIN if @a fBlocking is @c false, @a pcbRead is not NULL,
1052 * and no data was available. @a *pcbRead will be set to 0.
1053 * @retval VINF_EOF when trying to read __beyond__ the end of the stream and
1054 * @a pcbRead is not NULL (it will be set to the number of bytes read,
1055 * or 0 if the end of the stream was reached before this call).
1056 * When the last byte of the read request is the last byte in the
1057 * stream, this status code will not be used. However, VINF_EOF is
1058 * returned when attempting to read 0 bytes while standing at the end
1059 * of the stream.
1060 * @retval VERR_EOF when trying to read __beyond__ the end of the stream and
1061 * @a pcbRead is NULL.
1062 * @retval VERR_ACCESS_DENIED if the stream is not readable.
1063 *
1064 * @param hVfsIos The VFS I/O stream handle.
1065 * @param off Where to read at, -1 for the current position.
1066 * @param pSgBuf Pointer to a scatter buffer descriptor. The number
1067 * of bytes described by the segments is what will be
1068 * attemted read.
1069 * @param fBlocking Whether the call is blocking (@c true) or not. If
1070 * not, the @a pcbRead parameter must not be NULL.
1071 * @param pcbRead Where to always store the number of bytes actually
1072 * read. This can be NULL if @a fBlocking is true.
1073 * @sa RTFileSgRead, RTSocketSgRead, RTPipeRead, RTPipeReadBlocking
1074 */
1075RTDECL(int) RTVfsIoStrmSgRead(RTVFSIOSTREAM hVfsIos, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead);
1076
1077/**
1078 * Write bytes to the I/O stream from a gather buffer.
1079 *
1080 * @returns IPRT status code.
1081 * @retval VERR_ACCESS_DENIED if the stream is not writable.
1082 *
1083 * @param hVfsIos The VFS I/O stream handle.
1084 * @param off Where to write at, -1 for the current position.
1085 * @param pSgBuf Pointer to a gather buffer descriptor. The number
1086 * of bytes described by the segments is what will be
1087 * attemted written.
1088 * @param fBlocking Whether the call is blocking (@c true) or not. If
1089 * not, the @a pcbWritten parameter must not be NULL.
1090 * @param pcbWritten Where to always store the number of bytes actually
1091 * written. This can be NULL if @a fBlocking is true.
1092 * @sa RTFileSgWrite, RTSocketSgWrite
1093 */
1094RTDECL(int) RTVfsIoStrmSgWrite(RTVFSIOSTREAM hVfsIos, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten);
1095
1096/**
1097 * Flush any buffered data to the I/O stream.
1098 *
1099 * @returns IPRT status code.
1100 * @param hVfsIos The VFS I/O stream handle.
1101 * @sa RTVfsFileFlush, RTFileFlush, RTPipeFlush
1102 */
1103RTDECL(int) RTVfsIoStrmFlush(RTVFSIOSTREAM hVfsIos);
1104
1105/**
1106 * Poll for events.
1107 *
1108 * @returns IPRT status code.
1109 * @param hVfsIos The VFS I/O stream handle.
1110 * @param fEvents The events to poll for (RTPOLL_EVT_XXX).
1111 * @param cMillies How long to wait for event to eventuate.
1112 * @param fIntr Whether the wait is interruptible and can return
1113 * VERR_INTERRUPTED (@c true) or if this condition
1114 * should be hidden from the caller (@c false).
1115 * @param pfRetEvents Where to return the event mask.
1116 * @sa RTVfsFilePoll, RTPollSetAdd, RTPoll, RTPollNoResume.
1117 */
1118RTDECL(int) RTVfsIoStrmPoll(RTVFSIOSTREAM hVfsIos, uint32_t fEvents, RTMSINTERVAL cMillies, bool fIntr,
1119 uint32_t *pfRetEvents);
1120/**
1121 * Tells the current I/O stream position.
1122 *
1123 * @returns Zero or higher - where to return the I/O stream offset. Values
1124 * below zero are IPRT status codes (VERR_XXX).
1125 * @param hVfsIos The VFS I/O stream handle.
1126 * @sa RTFileTell
1127 */
1128RTDECL(RTFOFF) RTVfsIoStrmTell(RTVFSIOSTREAM hVfsIos);
1129
1130/**
1131 * Skips @a cb ahead in the stream.
1132 *
1133 * @returns IPRT status code.
1134 * @param hVfsIos The VFS I/O stream handle.
1135 * @param cb The number bytes to skip.
1136 */
1137RTDECL(int) RTVfsIoStrmSkip(RTVFSIOSTREAM hVfsIos, RTFOFF cb);
1138
1139/**
1140 * Fills the stream with @a cb zeros.
1141 *
1142 * @returns IPRT status code.
1143 * @param hVfsIos The VFS I/O stream handle.
1144 * @param cb The number of zero bytes to insert.
1145 */
1146RTDECL(int) RTVfsIoStrmZeroFill(RTVFSIOSTREAM hVfsIos, RTFOFF cb);
1147
1148/**
1149 * Checks if we're at the end of the I/O stream.
1150 *
1151 * @returns true if at EOS, otherwise false.
1152 * @param hVfsIos The VFS I/O stream handle.
1153 */
1154RTDECL(bool) RTVfsIoStrmIsAtEnd(RTVFSIOSTREAM hVfsIos);
1155
1156/**
1157 * Get the RTFILE_O_XXX flags for the I/O stream.
1158 *
1159 * @returns RTFILE_O_XXX, 0 on failure.
1160 * @param hVfsIos The VFS I/O stream handle.
1161 */
1162RTDECL(uint64_t) RTVfsIoStrmGetOpenFlags(RTVFSIOSTREAM hVfsIos);
1163
1164/**
1165 * Process the rest of the stream, checking if it's all valid UTF-8 encoding.
1166 *
1167 * @returns IPRT status code.
1168 *
1169 * @param hVfsIos The VFS I/O stream handle.
1170 * @param fFlags Flags governing the validation, see
1171 * RTVFS_VALIDATE_UTF8_XXX.
1172 * @param poffError Where to return the error offset. Optional.
1173 */
1174RTDECL(int) RTVfsIoStrmValidateUtf8Encoding(RTVFSIOSTREAM hVfsIos, uint32_t fFlags, PRTFOFF poffError);
1175
1176/** @defgroup RTVFS_VALIDATE_UTF8_XXX RTVfsIoStrmValidateUtf8Encoding flags.
1177 * @{ */
1178/** The text must not contain any null terminator codepoints. */
1179#define RTVFS_VALIDATE_UTF8_NO_NULL RT_BIT_32(0)
1180/** The codepoints must be in the range covered by RTC-3629. */
1181#define RTVFS_VALIDATE_UTF8_BY_RTC_3629 RT_BIT_32(1)
1182/** Mask of valid flags. */
1183#define RTVFS_VALIDATE_UTF8_VALID_MASK UINT32_C(0x00000003)
1184/** @} */
1185
1186/** @} */
1187
1188
1189/** @defgroup grp_vfs_file VFS File API
1190 * @{
1191 */
1192RTDECL(int) RTVfsFileOpen(RTVFS hVfs, const char *pszFilename, uint64_t fOpen, PRTVFSFILE phVfsFile);
1193
1194/**
1195 * Create a VFS file handle from a standard IPRT file handle (RTFILE).
1196 *
1197 * @returns IPRT status code.
1198 * @param hFile The standard IPRT file handle.
1199 * @param fOpen The flags the handle was opened with. Pass 0 to
1200 * have these detected.
1201 * @param fLeaveOpen Whether to leave the handle open when the VFS file
1202 * is released, or to close it (@c false).
1203 * @param phVfsFile Where to return the VFS file handle.
1204 */
1205RTDECL(int) RTVfsFileFromRTFile(RTFILE hFile, uint64_t fOpen, bool fLeaveOpen, PRTVFSFILE phVfsFile);
1206RTDECL(RTHCUINTPTR) RTVfsFileToNative(RTFILE hVfsFile);
1207
1208/**
1209 * Convenience function combining RTFileOpen with RTVfsFileFromRTFile.
1210 *
1211 * @returns IPRT status code.
1212 * @param pszFilename The path to the file in the normal file system.
1213 * @param fOpen The flags to pass to RTFileOpen when opening the
1214 * file, i.e. RTFILE_O_XXX.
1215 * @param phVfsFile Where to return the VFS file handle.
1216 */
1217RTDECL(int) RTVfsFileOpenNormal(const char *pszFilename, uint64_t fOpen, PRTVFSFILE phVfsFile);
1218
1219/**
1220 * Convert the VFS file handle to a VFS I/O stream handle.
1221 *
1222 * @returns The VFS I/O stream handle on success, this must be released.
1223 * NIL_RTVFSIOSTREAM if the file handle is invalid.
1224 * @param hVfsFile The VFS file handle.
1225 * @sa RTVfsIoStrmToFile
1226 */
1227RTDECL(RTVFSIOSTREAM) RTVfsFileToIoStream(RTVFSFILE hVfsFile);
1228
1229/**
1230 * Retains a reference to the VFS file handle.
1231 *
1232 * @returns New reference count on success, UINT32_MAX on failure.
1233 * @param hVfsFile The VFS file handle.
1234 */
1235RTDECL(uint32_t) RTVfsFileRetain(RTVFSFILE hVfsFile);
1236RTDECL(uint32_t) RTVfsFileRetainDebug(RTVFSFILE hVfsFile, RT_SRC_POS_DECL);
1237
1238/**
1239 * Releases a reference to the VFS file handle.
1240 *
1241 * @returns New reference count on success (0 if closed), UINT32_MAX on failure.
1242 * @param hVfsFile The VFS file handle.
1243 */
1244RTDECL(uint32_t) RTVfsFileRelease(RTVFSFILE hVfsFile);
1245
1246/**
1247 * Query information about the object.
1248 *
1249 * @returns IPRT status code.
1250 * @retval VERR_NOT_SUPPORTED if the @a enmAddAttr value is not handled by the
1251 * implementation.
1252 *
1253 * @param hVfsFile The VFS file handle.
1254 * @param pObjInfo Where to return the info.
1255 * @param enmAddAttr Which additional attributes should be retrieved.
1256 * @sa RTVfsObjQueryInfo, RTVfsFsStrmQueryInfo, RTVfsDirQueryInfo,
1257 * RTVfsIoStrmQueryInfo, RTVfsFileQueryInfo, RTFileQueryInfo,
1258 * RTPathQueryInfo.
1259 */
1260RTDECL(int) RTVfsFileQueryInfo(RTVFSFILE hVfsFile, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr);
1261
1262/**
1263 * Read bytes from the file at the current position.
1264 *
1265 * @returns IPRT status code.
1266 * @retval VINF_SUCCESS and the number of bytes read written to @a pcbRead.
1267 * @retval VINF_EOF when trying to read __beyond__ the end of the file and
1268 * @a pcbRead is not NULL (it will be set to the number of bytes read,
1269 * or 0 if the end of the file was reached before this call).
1270 * When the last byte of the read request is the last byte in the
1271 * file, this status code will not be used. However, VINF_EOF is
1272 * returned when attempting to read 0 bytes while standing at the end
1273 * of the file.
1274 * @retval VERR_EOF when trying to read __beyond__ the end of the file and
1275 * @a pcbRead is NULL.
1276 * @retval VERR_ACCESS_DENIED if the file is not readable.
1277 *
1278 * @param hVfsFile The VFS file handle.
1279 * @param pvBuf Where to store the read bytes.
1280 * @param cbToRead The number of bytes to read.
1281 * @param pcbRead Where to always store the number of bytes actually
1282 * read. Optional.
1283 * @sa RTVfsIoStrmRead, RTFileRead, RTPipeRead, RTPipeReadBlocking,
1284 * RTSocketRead
1285 */
1286RTDECL(int) RTVfsFileRead(RTVFSFILE hVfsFile, void *pvBuf, size_t cbToRead, size_t *pcbRead);
1287RTDECL(int) RTVfsFileReadAt(RTVFSFILE hVfsFile, RTFOFF off, void *pvBuf, size_t cbToRead, size_t *pcbRead);
1288
1289/**
1290 * Write bytes to the file at the current position.
1291 *
1292 * @returns IPRT status code.
1293 * @retval VERR_ACCESS_DENIED if the file is not writable.
1294 *
1295 * @param hVfsFile The VFS file handle.
1296 * @param pvBuf The bytes to write.
1297 * @param cbToWrite The number of bytes to write.
1298 * @param pcbWritten Where to always store the number of bytes actually
1299 * written. This can be NULL.
1300 * @sa RTVfsIoStrmRead, RTFileWrite, RTPipeWrite, RTPipeWriteBlocking,
1301 * RTSocketWrite
1302 */
1303RTDECL(int) RTVfsFileWrite(RTVFSFILE hVfsFile, const void *pvBuf, size_t cbToWrite, size_t *pcbWritten);
1304RTDECL(int) RTVfsFileWriteAt(RTVFSFILE hVfsFile, RTFOFF off, const void *pvBuf, size_t cbToWrite, size_t *pcbWritten);
1305
1306
1307/**
1308 * Reads bytes from the file into a scatter buffer.
1309 *
1310 * @returns IPRT status code.
1311 * @retval VINF_SUCCESS and the number of bytes read written to @a pcbRead.
1312 * @retval VINF_TRY_AGAIN if @a fBlocking is @c false, @a pcbRead is not NULL,
1313 * and no data was available. @a *pcbRead will be set to 0.
1314 * @retval VINF_EOF when trying to read __beyond__ the end of the stream and
1315 * @a pcbRead is not NULL (it will be set to the number of bytes read,
1316 * or 0 if the end of the stream was reached before this call).
1317 * When the last byte of the read request is the last byte in the
1318 * stream, this status code will not be used. However, VINF_EOF is
1319 * returned when attempting to read 0 bytes while standing at the end
1320 * of the stream.
1321 * @retval VERR_EOF when trying to read __beyond__ the end of the stream and
1322 * @a pcbRead is NULL.
1323 * @retval VERR_ACCESS_DENIED if the stream is not readable.
1324 *
1325 * @param hVfsFile The VFS file handle.
1326 * @param off Where to read at, -1 for the current position.
1327 * @param pSgBuf Pointer to a scatter buffer descriptor. The number
1328 * of bytes described by the segments is what will be
1329 * attemted read.
1330 * @param fBlocking Whether the call is blocking (@c true) or not. If
1331 * not, the @a pcbRead parameter must not be NULL.
1332 * @param pcbRead Where to always store the number of bytes actually
1333 * read. This can be NULL if @a fBlocking is true.
1334 * @sa RTFileSgRead, RTSocketSgRead, RTPipeRead, RTPipeReadBlocking
1335 */
1336RTDECL(int) RTVfsFileSgRead(RTVFSFILE hVfsFile, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead);
1337
1338/**
1339 * Write bytes to the file from a gather buffer.
1340 *
1341 * @returns IPRT status code.
1342 * @retval VERR_ACCESS_DENIED if the stream is not writable.
1343 *
1344 * @param hVfsFile The VFS file handle.
1345 * @param off Where to write at, -1 for the current position.
1346 * @param pSgBuf Pointer to a gather buffer descriptor. The number
1347 * of bytes described by the segments is what will be
1348 * attemted written.
1349 * @param fBlocking Whether the call is blocking (@c true) or not. If
1350 * not, the @a pcbWritten parameter must not be NULL.
1351 * @param pcbWritten Where to always store the number of bytes actually
1352 * written. This can be NULL if @a fBlocking is true.
1353 * @sa RTFileSgWrite, RTSocketSgWrite
1354 */
1355RTDECL(int) RTVfsFileSgWrite(RTVFSFILE hVfsFile, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten);
1356
1357/**
1358 * Flush any buffered data to the file.
1359 *
1360 * @returns IPRT status code.
1361 * @param hVfsFile The VFS file handle.
1362 * @sa RTVfsIoStrmFlush, RTFileFlush, RTPipeFlush
1363 */
1364RTDECL(int) RTVfsFileFlush(RTVFSFILE hVfsFile);
1365
1366/**
1367 * Poll for events.
1368 *
1369 * @returns IPRT status code.
1370 * @param hVfsFile The VFS file handle.
1371 * @param fEvents The events to poll for (RTPOLL_EVT_XXX).
1372 * @param cMillies How long to wait for event to eventuate.
1373 * @param fIntr Whether the wait is interruptible and can return
1374 * VERR_INTERRUPTED (@c true) or if this condition
1375 * should be hidden from the caller (@c false).
1376 * @param pfRetEvents Where to return the event mask.
1377 * @sa RTVfsIoStrmPoll, RTPollSetAdd, RTPoll, RTPollNoResume.
1378 */
1379RTDECL(RTFOFF) RTVfsFilePoll(RTVFSFILE hVfsFile, uint32_t fEvents, RTMSINTERVAL cMillies, bool fIntr,
1380 uint32_t *pfRetEvents);
1381
1382/**
1383 * Tells the current file position.
1384 *
1385 * @returns Zero or higher - where to return the file offset. Values
1386 * below zero are IPRT status codes (VERR_XXX).
1387 * @param hVfsFile The VFS file handle.
1388 * @sa RTFileTell, RTVfsIoStrmTell.
1389 */
1390RTDECL(RTFOFF) RTVfsFileTell(RTVFSFILE hVfsFile);
1391
1392/**
1393 * Changes the current read/write position of a file.
1394 *
1395 * @returns IPRT status code.
1396 *
1397 * @param hVfsFile The VFS file handle.
1398 * @param offSeek The seek offset.
1399 * @param uMethod The seek emthod.
1400 * @param poffActual Where to optionally return the new file offset.
1401 *
1402 * @sa RTFileSeek
1403 */
1404RTDECL(int) RTVfsFileSeek(RTVFSFILE hVfsFile, RTFOFF offSeek, uint32_t uMethod, uint64_t *poffActual);
1405
1406/**
1407 * Sets the size of a file.
1408 *
1409 * This may also be used for preallocating space
1410 * (RTVFSFILE_SIZE_F_PREALLOC_KEEP_SIZE).
1411 *
1412 * @returns IPRT status code.
1413 * @retval VERR_ACCESS_DENIED if handle isn't writable.
1414 * @retval VERR_WRITE_PROTECT if read-only file system.
1415 * @retval VERR_FILE_TOO_BIG if cbSize is larger than what the file system can
1416 * theoretically deal with.
1417 * @retval VERR_DISK_FULL if the file system if full.
1418 * @retval VERR_NOT_SUPPORTED if fFlags indicates some operation that's not
1419 * supported by the file system / host operating system.
1420 *
1421 * @param hVfsFile The VFS file handle.
1422 * @param cbSize The new file size.
1423 * @param fFlags RTVFSFILE_SIZE_F_NORMAL, RTVFSFILE_SIZE_F_GROW, or
1424 * RTVFSFILE_SIZE_F_GROW_KEEP_SIZE.
1425 *
1426 * @sa RTFileSetSize, RTFileSetAllocationSize
1427 */
1428RTDECL(int) RTVfsFileSetSize(RTVFSFILE hVfsFile, uint64_t cbSize, uint32_t fFlags);
1429
1430/** @name RTVFSFILE_SIZE_F_XXX - RTVfsFileSetSize flags.
1431 * @{ */
1432/** Normal truncate or grow (zero'ed) like RTFileSetSize . */
1433#define RTVFSFILE_SIZE_F_NORMAL UINT32_C(0x00000001)
1434/** Only grow the file, ignore call if cbSize would trunacte the file.
1435 * This is what RTFileSetAllocationSize does by default. */
1436#define RTVFSFILE_SIZE_F_GROW UINT32_C(0x00000002)
1437/** Only grow the file, ignore call if cbSize would trunacte the file.
1438 * This is what RTFileSetAllocationSize does by default. */
1439#define RTVFSFILE_SIZE_F_GROW_KEEP_SIZE UINT32_C(0x00000003)
1440/** Action mask. */
1441#define RTVFSFILE_SIZE_F_ACTION_MASK UINT32_C(0x00000003)
1442/** Validate the flags.
1443 * Will reference @a a_fFlags more than once. */
1444#define RTVFSFILE_SIZE_F_IS_VALID(a_fFlags) \
1445 ( !((a_fFlags) & ~RTVFSFILE_SIZE_F_ACTION_MASK) && ((a_fFlags) & RTVFSFILE_SIZE_F_ACTION_MASK) != 0 )
1446/** @} */
1447
1448
1449/** Mask of valid flags. */
1450#define RTFILE_ALLOC_SIZE_F_VALID (RTFILE_ALLOC_SIZE_F_KEEP_SIZE)
1451/** @} */
1452
1453
1454RTDECL(int) RTVfsFileGetSize(RTVFSFILE hVfsFile, uint64_t *pcbSize);
1455RTDECL(RTFOFF) RTVfsFileGetMaxSize(RTVFSFILE hVfsFile);
1456RTDECL(int) RTVfsFileQueryMaxSize(RTVFSFILE hVfsFile, uint64_t *pcbMax);
1457
1458/**
1459 * Get the RTFILE_O_XXX flags for the I/O stream.
1460 *
1461 * @returns RTFILE_O_XXX, 0 on failure.
1462 * @param hVfsFile The VFS file handle.
1463 */
1464RTDECL(uint64_t) RTVfsFileGetOpenFlags(RTVFSFILE hVfsFile);
1465
1466/** @} */
1467
1468
1469#ifdef DEBUG
1470# undef RTVfsRetain
1471# define RTVfsRetain(hVfs) RTVfsRetainDebug(hVfs, RT_SRC_POS)
1472# undef RTVfsObjRetain
1473# define RTVfsObjRetain(hVfsObj) RTVfsObjRetainDebug(hVfsObj, RT_SRC_POS)
1474# undef RTVfsDirRetain
1475# define RTVfsDirRetain(hVfsDir) RTVfsDirRetainDebug(hVfsDir, RT_SRC_POS)
1476# undef RTVfsFileRetain
1477# define RTVfsFileRetain(hVfsFile) RTVfsFileRetainDebug(hVfsFile, RT_SRC_POS)
1478# undef RTVfsIoStrmRetain
1479# define RTVfsIoStrmRetain(hVfsIos) RTVfsIoStrmRetainDebug(hVfsIos, RT_SRC_POS)
1480# undef RTVfsFsStrmRetain
1481# define RTVfsFsStrmRetain(hVfsFss) RTVfsFsStrmRetainDebug(hVfsFss, RT_SRC_POS)
1482#endif
1483
1484
1485
1486/** @defgroup grp_vfs_misc VFS Miscellaneous
1487 * @{
1488 */
1489
1490/**
1491 * Memorizes the I/O stream as a file backed by memory.
1492 *
1493 * @returns IPRT status code.
1494 *
1495 * @param hVfsIos The VFS I/O stream to memorize. This will be read
1496 * to the end on success, on failure its position is
1497 * undefined.
1498 * @param fFlags A combination of RTFILE_O_READ and RTFILE_O_WRITE.
1499 * @param phVfsFile Where to return the handle to the memory file on
1500 * success.
1501 */
1502RTDECL(int) RTVfsMemorizeIoStreamAsFile(RTVFSIOSTREAM hVfsIos, uint32_t fFlags, PRTVFSFILE phVfsFile);
1503
1504/**
1505 * Creates a VFS file from a memory buffer.
1506 *
1507 * @returns IPRT status code.
1508 *
1509 * @param fFlags A combination of RTFILE_O_READ and RTFILE_O_WRITE.
1510 * @param pvBuf The buffer. This will be copied and not referenced
1511 * after this function returns.
1512 * @param cbBuf The buffer size.
1513 * @param phVfsFile Where to return the handle to the memory file on
1514 * success.
1515 */
1516RTDECL(int) RTVfsFileFromBuffer(uint32_t fFlags, void const *pvBuf, size_t cbBuf, PRTVFSFILE phVfsFile);
1517
1518/**
1519 * Creates a memory backed VFS file object for read and write.
1520 *
1521 * @returns IPRT status code.
1522 *
1523 * @param hVfsIos The VFS I/O stream to memorize. This will be read
1524 * to the end on success, on failure its position is
1525 * undefined.
1526 * @param cbEstimate The estimated file size.
1527 * @param phVfsFile Where to return the handle to the memory file on
1528 * success.
1529 * @sa RTVfsMemIoStrmCreate
1530 */
1531RTDECL(int) RTVfsMemFileCreate(RTVFSIOSTREAM hVfsIos, size_t cbEstimate, PRTVFSFILE phVfsFile);
1532
1533/**
1534 * Creates a memory backed VFS file object for read and write.
1535 *
1536 * @returns IPRT status code.
1537 *
1538 * @param hVfsIos The VFS I/O stream to memorize. This will be read
1539 * to the end on success, on failure its position is
1540 * undefined.
1541 * @param cbEstimate The estimated file size.
1542 * @param phVfsIos Where to return the handle to the memory I/O stream
1543 * on success.
1544 * @sa RTVfsMemFileCreate
1545 */
1546RTDECL(int) RTVfsMemIoStrmCreate(RTVFSIOSTREAM hVfsIos, size_t cbEstimate, PRTVFSIOSTREAM phVfsIos);
1547
1548/**
1549 * Pumps data from one I/O stream to another.
1550 *
1551 * The data is read in chunks from @a hVfsIosSrc and written to @a hVfsIosDst
1552 * until @a hVfsIosSrc indicates end of stream.
1553 *
1554 * @returns IPRT status code
1555 *
1556 * @param hVfsIosSrc The input stream.
1557 * @param hVfsIosDst The output stream.
1558 * @param cbBufHint Hints at a good temporary buffer size, pass 0 if
1559 * clueless.
1560 */
1561RTDECL(int) RTVfsUtilPumpIoStreams(RTVFSIOSTREAM hVfsIosSrc, RTVFSIOSTREAM hVfsIosDst, size_t cbBufHint);
1562
1563
1564/**
1565 * Creates a progress wrapper for an I/O stream.
1566 *
1567 * @returns IRPT status code.
1568 * @param hVfsIos The I/O stream to wrap.
1569 * @param pfnProgress The progress callback. The return code is
1570 * ignored by default, see
1571 * RTVFSPROGRESS_F_CANCELABLE.
1572 * @param pvUser The user argument to @a pfnProgress.
1573 * @param fFlags RTVFSPROGRESS_F_XXX
1574 * @param cbExpectedRead The expected number of bytes read.
1575 * @param cbExpectedWritten The execpted number of bytes written.
1576 * @param phVfsIos Where to return the I/O stream handle.
1577 */
1578RTDECL(int) RTVfsCreateProgressForIoStream(RTVFSIOSTREAM hVfsIos, PFNRTPROGRESS pfnProgress, void *pvUser, uint32_t fFlags,
1579 uint64_t cbExpectedRead, uint64_t cbExpectedWritten, PRTVFSIOSTREAM phVfsIos);
1580
1581/**
1582 * Creates a progress wrapper for a file stream.
1583 *
1584 * @returns IRPT status code.
1585 * @param hVfsFile The file to wrap.
1586 * @param pfnProgress The progress callback. The return code is
1587 * ignored by default, see
1588 * RTVFSPROGRESS_F_CANCELABLE.
1589 * @param pvUser The user argument to @a pfnProgress.
1590 * @param fFlags RTVFSPROGRESS_F_XXX
1591 * @param cbExpectedRead The expected number of bytes read.
1592 * @param cbExpectedWritten The execpted number of bytes written.
1593 * @param phVfsFile Where to return the file handle.
1594 */
1595RTDECL(int) RTVfsCreateProgressForFile(RTVFSFILE hVfsFile, PFNRTPROGRESS pfnProgress, void *pvUser, uint32_t fFlags,
1596 uint64_t cbExpectedRead, uint64_t cbExpectedWritten, PRTVFSFILE phVfsFile);
1597
1598/** @name RTVFSPROGRESS_F_XXX - Flags for RTVfsCreateProcessForIoStream and
1599 * RTVfsCreateProcessForFile.
1600 * @{ */
1601/** Cancel if the callback returns a failure status code.
1602 * This isn't default behavior because the cancelation is delayed one I/O
1603 * operation in most cases and it's uncertain how the VFS user will handle the
1604 * cancellation status code. */
1605#define RTVFSPROGRESS_F_CANCELABLE RT_BIT_32(0)
1606/** Account forward seeks as reads. */
1607#define RTVFSPROGRESS_F_FORWARD_SEEK_AS_READ RT_BIT_32(1)
1608/** Account fprward seeks as writes. */
1609#define RTVFSPROGRESS_F_FORWARD_SEEK_AS_WRITE RT_BIT_32(2)
1610/** Valid bits. */
1611#define RTVFSPROGRESS_F_VALID_MASK UINT32_C(0x00000007)
1612/** @} */
1613
1614
1615/**
1616 * Create an I/O stream instance performing simple sequential read-ahead.
1617 *
1618 * @returns IPRT status code.
1619 * @param hVfsIos The input stream to perform read ahead on. If this is
1620 * actually for a file object, the returned I/O stream
1621 * handle can also be cast to a file handle.
1622 * @param fFlags Flags reserved for future use, MBZ.
1623 * @param cBuffers How many read ahead buffers to use. Specify 0 for
1624 * default value.
1625 * @param cbBuffer The size of each read ahead buffer. Specify 0 for
1626 * default value.
1627 * @param phVfsIos Where to return the read ahead I/O stream handle.
1628 *
1629 * @remarks Careful using this on a message pipe or socket. The reads are
1630 * performed in blocked mode and it may be host and/or implementation
1631 * dependent whether they will return ready data immediate or wait
1632 * until there's a whole @a cbBuffer (or default) worth ready.
1633 *
1634 * @sa RTVfsCreateReadAheadForFile
1635 */
1636RTDECL(int) RTVfsCreateReadAheadForIoStream(RTVFSIOSTREAM hVfsIos, uint32_t fFlags, uint32_t cBuffers, uint32_t cbBuffer,
1637 PRTVFSIOSTREAM phVfsIos);
1638
1639/**
1640 * Create an I/O stream instance performing simple sequential read-ahead.
1641 *
1642 * @returns IPRT status code.
1643 * @param hVfsFile The input file to perform read ahead on.
1644 * @param fFlags Flags reserved for future use, MBZ.
1645 * @param cBuffers How many read ahead buffers to use. Specify 0 for
1646 * default value.
1647 * @param cbBuffer The size of each read ahead buffer. Specify 0 for
1648 * default value.
1649 * @param phVfsFile Where to return the read ahead file handle.
1650 * @sa RTVfsCreateReadAheadForIoStream
1651 */
1652RTDECL(int) RTVfsCreateReadAheadForFile(RTVFSFILE hVfsFile, uint32_t fFlags, uint32_t cBuffers, uint32_t cbBuffer,
1653 PRTVFSFILE phVfsFile);
1654
1655
1656/**
1657 * Create a file system stream for writing to a directory.
1658 *
1659 * This is just supposed to be a drop in replacement for the TAR creator stream
1660 * that instead puts the files and stuff in a directory instead of a TAR
1661 * archive. In addition, it has an undo feature for simplying cleaning up after
1662 * a botched run
1663 *
1664 * @returns IPRT status code.
1665 * @param hVfsBaseDir The base directory.
1666 * @param fFlags RTVFSFSS2DIR_F_XXX
1667 * @param phVfsFss Where to return the FSS handle.
1668 * @sa RTVfsFsStrmToNormalDir, RTVfsFsStrmToDirUndo
1669 */
1670RTDECL(int) RTVfsFsStrmToDir(RTVFSDIR hVfsBaseDir, uint32_t fFlags, PRTVFSFSSTREAM phVfsFss);
1671
1672/**
1673 * Create a file system stream for writing to a normal directory.
1674 *
1675 * This is just supposed to be a drop in replacement for the TAR creator stream
1676 * that instead puts the files and stuff in a directory instead of a TAR
1677 * archive. In addition, it has an undo feature for simplying cleaning up after
1678 * a botched run
1679 *
1680 * @returns IPRT status code.
1681 * @param pszBaseDir The base directory. Must exist.
1682 * @param fFlags RTVFSFSS2DIR_F_XXX
1683 * @param phVfsFss Where to return the FSS handle.
1684 * @sa RTVfsFsStrmToDir, RTVfsFsStrmToDirUndo
1685 */
1686RTDECL(int) RTVfsFsStrmToNormalDir(const char *pszBaseDir, uint32_t fFlags, PRTVFSFSSTREAM phVfsFss);
1687
1688/** @name RTVFSFSS2DIR_F_XXX - Flags for RTVfsFsStrmToNormalDir
1689 * @{ */
1690/** Overwrite existing files (default is to not overwrite anything). */
1691#define RTVFSFSS2DIR_F_OVERWRITE_FILES RT_BIT_32(0)
1692/** Valid bits. */
1693#define RTVFSFSS2DIR_F_VALID_MASK UINT32_C(0x00000001)
1694/** @} */
1695
1696/**
1697 * Deletes files, directories, symlinks and stuff created by a FSS returned by
1698 * RTVfsFsStrmToNormalDir or RTVfsFsStrmToDir.
1699 *
1700 * @returns IPRT status code.
1701 * @param hVfsFss The write-to-directory FSS handle.
1702 */
1703RTDECL(int) RTVfsFsStrmToDirUndo(RTVFSFSSTREAM hVfsFss);
1704
1705
1706
1707/** @} */
1708
1709
1710/** @defgroup grp_rt_vfs_chain VFS Chains
1711 *
1712 * VFS chains is for doing pipe like things with VFS objects from the command
1713 * line. Imagine you want to cat the readme.gz of an ISO you could do
1714 * something like:
1715 * RTCat :iprtvfs:file(stdfile,live.iso)|vfs(isofs)|iso(open,readme.gz)|ios(gunzip)
1716 * or
1717 * RTCat :iprtvfs:file(stdfile,live.iso)|ios(isofs,readme.gz)|ios(gunzip)
1718 *
1719 * Or say you want to read the README.TXT on a floppy image:
1720 * RTCat :iprtvfs:file(stdfile,floppy.img,r)|vfs(fat)|ios(open,README.TXT)
1721 * or
1722 * RTCat :iprtvfs:file(stdfile,floppy.img,r)|vfs(fat)|README.TXT
1723 *
1724 * Or in the other direction, you want to write a STUFF.TGZ file to the above
1725 * floppy image, using a lazy writer thread for compressing the data:
1726 * RTTar cf :iprtvfs:file(stdfile,floppy.img,rw)|ios(fat,STUFF.TGZ)|ios(gzip)|ios(push) .
1727 *
1728 *
1729 * A bit more formally:
1730 * :iprtvfs:{type}({provider}[,provider-args])[{separator}{type}...][{separator}{path}]
1731 *
1732 * The @c type refers to VFS object that should be created by the @c provider.
1733 * Valid types:
1734 * - vfs: A virtual file system (volume).
1735 * - fss: A file system stream (e.g. tar).
1736 * - ios: An I/O stream.
1737 * - file: A file.
1738 * - dir: A directory.
1739 * - sym: A symbolic link (not sure how useful this is).
1740 *
1741 * The @c provider refers to registered chain element providers (see
1742 * RTVFSCHAINELEMENTREG for how that works internally). These are asked to
1743 * create a VFS object of the specified type using the given arguments (if any).
1744 * Default providers:
1745 * - std: Standard file, directory and file system.
1746 * - open: Opens a file, I/O stream or directory in a vfs or directory object.
1747 * - pull: Read-ahead buffering thread on file or I/O stream.
1748 * - push: Lazy-writer buffering thread on file or I/O stream.
1749 * - gzip: Compresses an I/O stream.
1750 * - gunzip: Decompresses an I/O stream.
1751 * - fat: FAT file system accessor.
1752 * - isofs: ISOFS file system accessor.
1753 *
1754 * As element @c separator we allow both colon (':') and the pipe character
1755 * ('|'). The latter the conventional one, but since it's inconvenient on the
1756 * command line, colon is provided as an alternative.
1757 *
1758 * In the final element we allow a simple @a path to be specified instead of the
1759 * type-provider-arguments stuff. The previous object must be a directory, file
1760 * system or file system stream. The application will determin exactly which
1761 * operation or operations which will be performed.
1762 *
1763 * @{
1764 */
1765
1766/** The path prefix used to identify an VFS chain specification. */
1767#define RTVFSCHAIN_SPEC_PREFIX ":iprtvfs:"
1768
1769RTDECL(int) RTVfsChainOpenVfs(const char *pszSpec, PRTVFS phVfs, uint32_t *poffError, PRTERRINFO pErrInfo);
1770RTDECL(int) RTVfsChainOpenFsStream(const char *pszSpec, PRTVFSFSSTREAM phVfsFss, uint32_t *poffError, PRTERRINFO pErrInfo);
1771
1772/**
1773 * Opens any kind of file system object.
1774 *
1775 * @returns IPRT status code.
1776 * @param pszSpec The VFS chain specification or plain path.
1777 * @param fFileOpen RTFILE_O_XXX flags.
1778 * @param fObjFlags More flags: RTVFSOBJ_F_XXX, RTPATH_F_XXX.
1779 * @param phVfsObj Where to return the handle to the opened object.
1780 * @param poffError Where to on error return an offset into @a pszSpec
1781 * of what cause the error. Optional.
1782 * @param pErrInfo Where to return additional error information.
1783 * Optional.
1784 */
1785RTDECL(int) RTVfsChainOpenObj(const char *pszSpec, uint64_t fFileOpen, uint32_t fObjFlags,
1786 PRTVFSOBJ phVfsObj, uint32_t *poffError, PRTERRINFO pErrInfo);
1787
1788RTDECL(int) RTVfsChainOpenDir(const char *pszSpec, uint32_t fOpen, PRTVFSDIR phVfsDir, uint32_t *poffError, PRTERRINFO pErrInfo);
1789RTDECL(int) RTVfsChainOpenParentDir(const char *pszSpec, uint32_t fOpen, PRTVFSDIR phVfsDir, const char **ppszChild,
1790 uint32_t *poffError, PRTERRINFO pErrInfo);
1791RTDECL(int) RTVfsChainOpenFile(const char *pszSpec, uint64_t fOpen, PRTVFSFILE phVfsFile, uint32_t *poffError, PRTERRINFO pErrInfo);
1792RTDECL(int) RTVfsChainOpenIoStream(const char *pszSpec, uint64_t fOpen, PRTVFSIOSTREAM phVfsIos, uint32_t *poffError, PRTERRINFO pErrInfo);
1793RTDECL(int) RTVfsChainOpenSymlink(const char *pszSpec, PRTVFSSYMLINK phVfsSym, uint32_t *poffError, PRTERRINFO pErrInfo);
1794
1795RTDECL(int) RTVfsChainQueryInfo(const char *pszSpec, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAdditionalAttribs,
1796 uint32_t fFlags, uint32_t *poffError, PRTERRINFO pErrInfo);
1797
1798/**
1799 * Tests if the given string is a chain specification or not.
1800 *
1801 * @returns true if it is, false if it isn't.
1802 * @param pszSpec The alleged chain spec.
1803 */
1804RTDECL(bool) RTVfsChainIsSpec(const char *pszSpec);
1805
1806/**
1807 * Queries the path from the final element.
1808 *
1809 * @returns IPRT status code.
1810 * @retval VERR_VFS_CHAIN_NOT_PATH_ONLY if the final element isn't just a
1811 * simple path.
1812 * @param pszSpec The chain spec.
1813 * @param ppszFinalPath Where to return a copy of the final path on success.
1814 * Call RTStrFree when done.
1815 * @param poffError Where to on error return an offset into @a pszSpec
1816 * of what cause the error. Optional.
1817 *
1818 */
1819RTDECL(int) RTVfsChainQueryFinalPath(const char *pszSpec, char **ppszFinalPath, uint32_t *poffError);
1820
1821/**
1822 * Splits the given chain spec into a final path and the preceeding spec.
1823 *
1824 * This works on plain paths too.
1825 *
1826 * @returns IPRT status code.
1827 * @param pszSpec The chain spec to split. This will be modified!
1828 * @param ppszSpec Where to return the pointer to the chain spec part.
1829 * This is set to NULL if it's a plain path or a chain
1830 * spec with only a final-path element.
1831 * @param ppszFinalPath Where to return the pointer to the final path. This
1832 * is set to NULL if no final path.
1833 * @param poffError Where to on error return an offset into @a pszSpec
1834 * of what cause the error. Optional.
1835 */
1836RTDECL(int) RTVfsChainSplitOffFinalPath(char *pszSpec, char **ppszSpec, char **ppszFinalPath, uint32_t *poffError);
1837
1838/**
1839 * Common code for reporting errors of a RTVfsChainOpen* API.
1840 *
1841 * @param pszFunction The API called.
1842 * @param pszSpec The VFS chain specification or file path passed to the.
1843 * @param rc The return code.
1844 * @param offError The error offset value returned (0 if not captured).
1845 * @param pErrInfo Additional error information. Optional.
1846 *
1847 * @sa RTVfsChainMsgErrorExitFailure
1848 * @sa RTVfsChainOpenVfs, RTVfsChainOpenFsStream, RTVfsChainOpenDir,
1849 * RTVfsChainOpenFile, RTVfsChainOpenIoStream, RTVfsChainOpenSymlink
1850 */
1851RTDECL(void) RTVfsChainMsgError(const char *pszFunction, const char *pszSpec, int rc, uint32_t offError, PRTERRINFO pErrInfo);
1852
1853/**
1854 * Common code for reporting errors of a RTVfsChainOpen* API.
1855 *
1856 * @returns RTEXITCODE_FAILURE
1857 *
1858 * @param pszFunction The API called.
1859 * @param pszSpec The VFS chain specification or file path passed to the.
1860 * @param rc The return code.
1861 * @param offError The error offset value returned (0 if not captured).
1862 * @param pErrInfo Additional error information. Optional.
1863 *
1864 * @sa RTVfsChainMsgError
1865 * @sa RTVfsChainOpenVfs, RTVfsChainOpenFsStream, RTVfsChainOpenDir,
1866 * RTVfsChainOpenFile, RTVfsChainOpenIoStream, RTVfsChainOpenSymlink
1867 */
1868RTDECL(RTEXITCODE) RTVfsChainMsgErrorExitFailure(const char *pszFunction, const char *pszSpec,
1869 int rc, uint32_t offError, PRTERRINFO pErrInfo);
1870
1871
1872/** @} */
1873
1874
1875/** @} */
1876
1877RT_C_DECLS_END
1878
1879#endif /* !___iprt_vfs_h */
1880
Note: See TracBrowser for help on using the repository browser.

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