VirtualBox

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

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

iprt: A bunch of basic function for working the file system relative to an open directory. There is only a default implementation currently, the path race conditions will first be eliminated/reduced with platform specific implementations (POSIX, NT). Also added a VFS wrapper around RTDIR handles, completing RTVfsChainOpenDir and making RTLs work on normal directories too (instead of only isofs and fat).

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

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