VirtualBox

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

Last change on this file since 96811 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

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