VirtualBox

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

Last change on this file since 94719 was 94291, checked in by vboxsync, 3 years ago

IPRT,Storage: Adding RTVfsQueryLabel and internally a generic pfnQueryInfoEx method to the RTVFSOBJOPS function table. Untested implementation of the latter for iso/udf. bugref:9781

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