VirtualBox

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

Last change on this file since 76094 was 70395, checked in by vboxsync, 7 years ago

IPRT/VISO: Pass a the directory of a VISO file to the ISO maker to allow for relative file/dir specification from it. Nested push-iso now possible. Tweak importer code to handle NT 3.1 iso where the big endian volume sequence number wasn't set.

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