VirtualBox

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

Last change on this file since 67116 was 67116, checked in by vboxsync, 8 years ago

IPRT: Started on VFS file system output streams for implementing TAR creation.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 54.8 KB
Line 
1/** @file
2 * IPRT - Virtual Filesystem.
3 */
4
5/*
6 * Copyright (C) 2010-2016 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 Flags for the future, MBZ.
338 */
339RTDECL(int) RTVfsFsStrmAdd(RTVFSFSSTREAM hVfsFss, const char *pszPath, RTVFSOBJ hVfsObj, uint32_t fFlags);
340
341/** @} */
342
343
344/** @defgroup grp_vfs_dir VFS Directory API
345 * @{
346 */
347
348/**
349 * Retains a reference to the VFS directory handle.
350 *
351 * @returns New reference count on success, UINT32_MAX on failure.
352 * @param hVfsDir The VFS directory handle.
353 */
354RTDECL(uint32_t) RTVfsDirRetain(RTVFSDIR hVfsDir);
355RTDECL(uint32_t) RTVfsDirRetainDebug(RTVFSDIR hVfsDir, RT_SRC_POS_DECL);
356
357/**
358 * Releases a reference to the VFS directory handle.
359 *
360 * @returns New reference count on success (0 if closed), UINT32_MAX on failure.
361 * @param hVfsDir The VFS directory handle.
362 */
363RTDECL(uint32_t) RTVfsDirRelease(RTVFSDIR hVfsDir);
364
365/**
366 * Opens a directory in the specified file system.
367 *
368 * @returns IPRT status code.
369 * @param hVfs The VFS to open the directory within.
370 * @param pszPath Path to the directory, relative to the root.
371 * @param fFlags Reserved, MBZ.
372 * @param phVfsDir Where to return the directory.
373 */
374RTDECL(int) RTVfsDirOpen(RTVFS hVfs, const char *pszPath, uint32_t fFlags, PRTVFSDIR phVfsDir);
375
376/**
377 * Opens a file in or under the given directory.
378 *
379 * @returns IPRT status code.
380 * @param hVfsDir The VFS directory start walking the @a pszPath
381 * relative to.
382 * @param pszPath Path to the file.
383 * @param fOpen RTFILE_O_XXX flags.
384 * @param phVfsFile Where to return the file.
385 */
386RTDECL(int) RTVfsDirOpenFile(RTVFSDIR hVfsDir, const char *pszPath, uint64_t fOpen, PRTVFSFILE phVfsFile);
387
388/**
389 * Opens a directory in or under the given directory.
390 *
391 * @returns IPRT status code.
392 * @param hVfsDir The VFS directory start walking the @a pszPath
393 * relative to.
394 * @param pszPath Path to the file.
395 * @param fFlags Reserved, MBZ.
396 * @param phVfsDir Where to return the directory.
397 */
398RTDECL(int) RTVfsDirOpenDir(RTVFSDIR hVfsDir, const char *pszPath, uint32_t fFlags, PRTVFSDIR phVfsDir);
399
400/**
401 * Queries information about a object in or under the given directory.
402 *
403 * @returns IPRT Status code.
404 * @param hVfsDir The VFS directory start walking the @a pszPath
405 * relative to.
406 * @param pszPath Path to the object.
407 * @param pObjInfo Where to return info.
408 * @param enmAddAttr What to return.
409 * @param fFlags RTPATH_F_XXX.
410 * @sa RTPathQueryInfoEx, RTVfsQueryPathInfo, RTVfsObjQueryInfo
411 */
412RTDECL(int) RTVfsDirQueryPathInfo(RTVFSDIR hVfsDir, const char *pszPath, PRTFSOBJINFO pObjInfo,
413 RTFSOBJATTRADD enmAddAttr, uint32_t fFlags);
414
415/**
416 * Reads the next entry in the directory returning extended information.
417 *
418 * @returns VINF_SUCCESS and data in pDirEntry on success.
419 * @returns VERR_NO_MORE_FILES when the end of the directory has been reached.
420 * @returns VERR_BUFFER_OVERFLOW if the buffer is too small to contain the filename. If
421 * pcbDirEntry is specified it will be updated with the required buffer size.
422 * @returns suitable iprt status code on other errors.
423 *
424 * @param hVfsDir The VFS directory.
425 * @param pDirEntry Where to store the information about the next
426 * directory entry on success.
427 * @param pcbDirEntry Optional parameter used for variable buffer size.
428 *
429 * On input the variable pointed to contains the size of the pDirEntry
430 * structure. This must be at least OFFSET(RTDIRENTRYEX, szName[2]) bytes.
431 *
432 * On successful output the field is updated to
433 * OFFSET(RTDIRENTRYEX, szName[pDirEntry->cbName + 1]).
434 *
435 * When the data doesn't fit in the buffer and VERR_BUFFER_OVERFLOW is
436 * returned, this field contains the required buffer size.
437 *
438 * The value is unchanged in all other cases.
439 * @param enmAddAttr Which set of additional attributes to request.
440 * Use RTFSOBJATTRADD_NOTHING if this doesn't matter.
441 *
442 * @sa RTDirReadEx
443 */
444RTDECL(int) RTVfsDirReadEx(RTVFSDIR hVfsDir, PRTDIRENTRYEX pDirEntry, size_t *pcbDirEntry, RTFSOBJATTRADD enmAddAttr);
445
446/** @} */
447
448
449/** @defgroup grp_vfs_symlink VFS Symbolic Link API
450 *
451 * @remarks The TAR VFS and filesystem stream uses symbolic links for
452 * describing hard links as well. The users must use RTFS_IS_SYMLINK
453 * to check if it is a real symlink in those cases.
454 *
455 * @remarks Any VFS which is backed by a real file system may be subject to
456 * races with other processes or threads, so the user may get
457 * unexpected errors when this happends. This is a bit host specific,
458 * i.e. it might be prevent on windows if we care.
459 *
460 * @{
461 */
462
463
464/**
465 * Retains a reference to the VFS symbolic link handle.
466 *
467 * @returns New reference count on success, UINT32_MAX on failure.
468 * @param hVfsSym The VFS symbolic link handle.
469 */
470RTDECL(uint32_t) RTVfsSymlinkRetain(RTVFSSYMLINK hVfsSym);
471RTDECL(uint32_t) RTVfsSymlinkRetainDebug(RTVFSSYMLINK hVfsSym, RT_SRC_POS_DECL);
472
473/**
474 * Releases a reference to the VFS symbolic link handle.
475 *
476 * @returns New reference count on success (0 if closed), UINT32_MAX on failure.
477 * @param hVfsSym The VFS symbolic link handle.
478 */
479RTDECL(uint32_t) RTVfsSymlinkRelease(RTVFSSYMLINK hVfsSym);
480
481/**
482 * Query information about the symbolic link.
483 *
484 * @returns IPRT status code.
485 * @param hVfsSym The VFS symbolic link handle.
486 * @param pObjInfo Where to return the info.
487 * @param enmAddAttr Which additional attributes should be retrieved.
488 *
489 * @sa RTFileQueryInfo, RTPathQueryInfo, RTPathQueryInfoEx
490 */
491RTDECL(int) RTVfsSymlinkQueryInfo(RTVFSSYMLINK hVfsSym, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr);
492
493/**
494 * Set the unix style owner and group.
495 *
496 * @returns IPRT status code.
497 * @param hVfsSym The VFS symbolic link handle.
498 * @param fMode The new mode bits.
499 * @param fMask The mask indicating which bits we are changing.
500 * @sa RTFileSetMode, RTPathSetMode
501 */
502RTDECL(int) RTVfsSymlinkSetMode(RTVFSSYMLINK hVfsSym, RTFMODE fMode, RTFMODE fMask);
503
504/**
505 * Set the timestamps associated with the object.
506 *
507 * @returns IPRT status code.
508 * @param hVfsSym The VFS symbolic link handle.
509 * @param pAccessTime Pointer to the new access time. NULL if not
510 * to be changed.
511 * @param pModificationTime Pointer to the new modifcation time. NULL if
512 * not to be changed.
513 * @param pChangeTime Pointer to the new change time. NULL if not to be
514 * changed.
515 * @param pBirthTime Pointer to the new time of birth. NULL if not to be
516 * changed.
517 * @remarks See RTFileSetTimes for restrictions and behavior imposed by the
518 * host OS or underlying VFS provider.
519 * @sa RTFileSetTimes, RTPathSetTimes
520 */
521RTDECL(int) RTVfsSymlinkSetTimes(RTVFSSYMLINK hVfsSym, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
522 PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime);
523
524/**
525 * Set the unix style owner and group.
526 *
527 * @returns IPRT status code.
528 * @param hVfsSym The VFS symbolic link handle.
529 * @param uid The user ID of the new owner. NIL_RTUID if
530 * unchanged.
531 * @param gid The group ID of the new owner group. NIL_RTGID if
532 * unchanged.
533 * @sa RTFileSetOwner, RTPathSetOwner.
534 */
535RTDECL(int) RTVfsSymlinkSetOwner(RTVFSSYMLINK hVfsSym, RTUID uid, RTGID gid);
536
537/**
538 * Read the symbolic link target.
539 *
540 * @returns IPRT status code.
541 * @param hVfsSym The VFS symbolic link handle.
542 * @param pszTarget The target buffer.
543 * @param cbTarget The size of the target buffer.
544 * @sa RTSymlinkRead
545 */
546RTDECL(int) RTVfsSymlinkRead(RTVFSSYMLINK hVfsSym, char *pszTarget, size_t cbTarget);
547
548/** @} */
549
550
551
552/** @defgroup grp_vfs_iostream VFS I/O Stream API
553 * @{
554 */
555
556/**
557 * Creates a VFS file from a memory buffer.
558 *
559 * @returns IPRT status code.
560 *
561 * @param fFlags A combination of RTFILE_O_READ and RTFILE_O_WRITE.
562 * @param pvBuf The buffer. This will be copied and not referenced
563 * after this function returns.
564 * @param cbBuf The buffer size.
565 * @param phVfsIos Where to return the VFS I/O stream handle.
566 */
567RTDECL(int) RTVfsIoStrmFromBuffer(uint32_t fFlags, void const *pvBuf, size_t cbBuf, PRTVFSIOSTREAM phVfsIos);
568
569/**
570 * Creates a VFS I/O stream handle from a standard IPRT file handle (RTFILE).
571 *
572 * @returns IPRT status code.
573 * @param hFile The standard IPRT file handle.
574 * @param fOpen The flags the handle was opened with. Pass 0 to
575 * have these detected.
576 * @param fLeaveOpen Whether to leave the handle open when the VFS file
577 * is released, or to close it (@c false).
578 * @param phVfsIos Where to return the VFS I/O stream handle.
579 */
580RTDECL(int) RTVfsIoStrmFromRTFile(RTFILE hFile, uint64_t fOpen, bool fLeaveOpen, PRTVFSIOSTREAM phVfsIos);
581
582/**
583 * Creates a VFS I/O stream handle from a standard IPRT pipe handle (RTPIPE).
584 *
585 * @returns IPRT status code.
586 * @param hPipe The standard IPRT pipe handle.
587 * @param fLeaveOpen Whether to leave the handle open when the VFS file
588 * is released, or to close it (@c false).
589 * @param phVfsIos Where to return the VFS I/O stream handle.
590 */
591RTDECL(int) RTVfsIoStrmFromRTPipe(RTPIPE hPipe, bool fLeaveOpen, PRTVFSIOSTREAM phVfsIos);
592
593/**
594 * Convenience function combining RTFileOpen with RTVfsIoStrmFromRTFile.
595 *
596 * @returns IPRT status code.
597 * @param pszFilename The path to the file in the normal file system.
598 * @param fOpen The flags to pass to RTFileOpen when opening the
599 * file, i.e. RTFILE_O_XXX.
600 * @param phVfsIos Where to return the VFS I/O stream handle.
601 */
602RTDECL(int) RTVfsIoStrmOpenNormal(const char *pszFilename, uint64_t fOpen, PRTVFSIOSTREAM phVfsIos);
603
604/**
605 * Create a VFS I/O stream handle from one of the standard handles.
606 *
607 * @returns IPRT status code.
608 * @param enmStdHandle The standard IPRT file handle.
609 * @param fOpen The flags the handle was opened with. Pass 0 to
610 * have these detected.
611 * @param fLeaveOpen Whether to leave the handle open when the VFS file
612 * is released, or to close it (@c false).
613 * @param phVfsIos Where to return the VFS I/O stream handle.
614 */
615RTDECL(int) RTVfsIoStrmFromStdHandle(RTHANDLESTD enmStdHandle, uint64_t fOpen, bool fLeaveOpen,
616 PRTVFSIOSTREAM phVfsIos);
617
618/**
619 * Retains a reference to the VFS I/O stream handle.
620 *
621 * @returns New reference count on success, UINT32_MAX on failure.
622 * @param hVfsIos The VFS I/O stream handle.
623 */
624RTDECL(uint32_t) RTVfsIoStrmRetain(RTVFSIOSTREAM hVfsIos);
625RTDECL(uint32_t) RTVfsIoStrmRetainDebug(RTVFSIOSTREAM hVfsIos, RT_SRC_POS_DECL);
626
627/**
628 * Releases a reference to the VFS I/O stream handle.
629 *
630 * @returns New reference count on success (0 if closed), UINT32_MAX on failure.
631 * @param hVfsIos The VFS I/O stream handle.
632 */
633RTDECL(uint32_t) RTVfsIoStrmRelease(RTVFSIOSTREAM hVfsIos);
634
635/**
636 * Convert the VFS I/O stream handle to a VFS file handle.
637 *
638 * @returns The VFS file handle on success, this must be released.
639 * NIL_RTVFSFILE if the I/O stream handle is invalid.
640 * @param hVfsIos The VFS I/O stream handle.
641 * @sa RTVfsFileToIoStream
642 */
643RTDECL(RTVFSFILE) RTVfsIoStrmToFile(RTVFSIOSTREAM hVfsIos);
644
645/**
646 * Query information about the I/O stream.
647 *
648 * @returns IPRT status code.
649 * @param hVfsIos The VFS I/O stream handle.
650 * @param pObjInfo Where to return the info.
651 * @param enmAddAttr Which additional attributes should be retrieved.
652 * @sa RTFileQueryInfo
653 */
654RTDECL(int) RTVfsIoStrmQueryInfo(RTVFSIOSTREAM hVfsIos, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr);
655
656/**
657 * Read bytes from the I/O stream.
658 *
659 * @returns IPRT status code.
660 * @retval VINF_SUCCESS and the number of bytes read written to @a pcbRead.
661 * @retval VINF_TRY_AGAIN if @a fBlocking is @c false, @a pcbRead is not NULL,
662 * and no data was available. @a *pcbRead will be set to 0.
663 * @retval VINF_EOF when trying to read __beyond__ the end of the stream and
664 * @a pcbRead is not NULL (it will be set to the number of bytes read,
665 * or 0 if the end of the stream was reached before this call).
666 * When the last byte of the read request is the last byte in the
667 * stream, this status code will not be used. However, VINF_EOF is
668 * returned when attempting to read 0 bytes while standing at the end
669 * of the stream.
670 * @retval VERR_EOF when trying to read __beyond__ the end of the stream and
671 * @a pcbRead is NULL.
672 * @retval VERR_ACCESS_DENIED if the stream is not readable.
673 *
674 * @param hVfsIos The VFS I/O stream handle.
675 * @param pvBuf Where to store the read bytes.
676 * @param cbToRead The number of bytes to read.
677 * @param fBlocking Whether the call is blocking (@c true) or not. If
678 * not, the @a pcbRead parameter must not be NULL.
679 * @param pcbRead Where to always store the number of bytes actually
680 * read. This can be NULL if @a fBlocking is true.
681 * @sa RTVfsFileRead, RTFileRead, RTPipeRead, RTPipeReadBlocking,
682 * RTSocketRead
683 */
684RTDECL(int) RTVfsIoStrmRead(RTVFSIOSTREAM hVfsIos, void *pvBuf, size_t cbToRead, bool fBlocking, size_t *pcbRead);
685
686/**
687 * Read bytes from the I/O stream, optionally with offset.
688 *
689 * @returns IPRT status code.
690 * @retval VINF_SUCCESS and the number of bytes read written to @a pcbRead.
691 * @retval VINF_TRY_AGAIN if @a fBlocking is @c false, @a pcbRead is not NULL,
692 * and no data was available. @a *pcbRead will be set to 0.
693 * @retval VINF_EOF when trying to read __beyond__ the end of the stream and
694 * @a pcbRead is not NULL (it will be set to the number of bytes read,
695 * or 0 if the end of the stream was reached before this call).
696 * When the last byte of the read request is the last byte in the
697 * stream, this status code will not be used. However, VINF_EOF is
698 * returned when attempting to read 0 bytes while standing at the end
699 * of the stream.
700 * @retval VERR_EOF when trying to read __beyond__ the end of the stream and
701 * @a pcbRead is NULL.
702 * @retval VERR_ACCESS_DENIED if the stream is not readable.
703 *
704 * @param hVfsIos The VFS I/O stream handle.
705 * @param off Where to read at, -1 for the current position.
706 * @param pvBuf Where to store the read bytes.
707 * @param cbToRead The number of bytes to read.
708 * @param fBlocking Whether the call is blocking (@c true) or not. If
709 * not, the @a pcbRead parameter must not be NULL.
710 * @param pcbRead Where to always store the number of bytes actually
711 * read. This can be NULL if @a fBlocking is true.
712 * @sa RTVfsFileRead, RTFileRead, RTPipeRead, RTPipeReadBlocking,
713 * RTSocketRead
714 */
715RTDECL(int) RTVfsIoStrmReadAt(RTVFSIOSTREAM hVfsIos, RTFOFF off, void *pvBuf, size_t cbToRead, bool fBlocking, size_t *pcbRead);
716
717/**
718 * Reads the remainder of the stream into a memory buffer.
719 *
720 * For simplifying string-style processing, the is a zero byte after the
721 * returned buffer, making sure it can be used as a zero terminated string.
722 *
723 * @returns IPRT status code.
724 * @param hVfsIos The VFS I/O stream handle.
725 * @param ppvBuf Where to return the buffer. Must pass to
726 * RTVfsIoStrmReadAllFree for freeing, not RTMemFree!
727 * @param pcbBuf Where to return the buffer size.
728 */
729RTDECL(int) RTVfsIoStrmReadAll(RTVFSIOSTREAM hVfsIos, void **ppvBuf, size_t *pcbBuf);
730
731/**
732 * Free memory buffer returned by RTVfsIoStrmReadAll.
733 *
734 * @param pvBuf What RTVfsIoStrmReadAll returned.
735 * @param cbBuf What RTVfsIoStrmReadAll returned.
736 */
737RTDECL(void) RTVfsIoStrmReadAllFree(void *pvBuf, size_t cbBuf);
738
739/**
740 * Write bytes to the I/O stream.
741 *
742 * @returns IPRT status code.
743 * @retval VERR_ACCESS_DENIED if the stream is not writable.
744 *
745 * @param hVfsIos The VFS I/O stream handle.
746 * @param pvBuf The bytes to write.
747 * @param cbToWrite The number of bytes to write.
748 * @param fBlocking Whether the call is blocking (@c true) or not. If
749 * not, the @a pcbWritten parameter must not be NULL.
750 * @param pcbWritten Where to always store the number of bytes actually
751 * written. This can be NULL if @a fBlocking is true.
752 * @sa RTVfsFileWrite, RTFileWrite, RTPipeWrite, RTPipeWriteBlocking,
753 * RTSocketWrite
754 */
755RTDECL(int) RTVfsIoStrmWrite(RTVFSIOSTREAM hVfsIos, const void *pvBuf, size_t cbToWrite, bool fBlocking, size_t *pcbWritten);
756RTDECL(int) RTVfsIoStrmWriteAt(RTVFSIOSTREAM hVfsIos, RTFOFF off, const void *pvBuf, size_t cbToWrite, bool fBlocking, size_t *pcbWritten);
757
758/**
759 * Reads bytes from the I/O stream into a scatter buffer.
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 off Where to read at, -1 for the current position.
778 * @param pSgBuf Pointer to a scatter buffer descriptor. The number
779 * of bytes described by the segments is what will be
780 * attemted read.
781 * @param fBlocking Whether the call is blocking (@c true) or not. If
782 * not, the @a pcbRead parameter must not be NULL.
783 * @param pcbRead Where to always store the number of bytes actually
784 * read. This can be NULL if @a fBlocking is true.
785 * @sa RTFileSgRead, RTSocketSgRead, RTPipeRead, RTPipeReadBlocking
786 */
787RTDECL(int) RTVfsIoStrmSgRead(RTVFSIOSTREAM hVfsIos, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead);
788
789/**
790 * Write bytes to the I/O stream from a gather buffer.
791 *
792 * @returns IPRT status code.
793 * @retval VERR_ACCESS_DENIED if the stream is not writable.
794 *
795 * @param hVfsIos The VFS I/O stream handle.
796 * @param off Where to write at, -1 for the current position.
797 * @param pSgBuf Pointer to a gather buffer descriptor. The number
798 * of bytes described by the segments is what will be
799 * attemted written.
800 * @param fBlocking Whether the call is blocking (@c true) or not. If
801 * not, the @a pcbWritten parameter must not be NULL.
802 * @param pcbWritten Where to always store the number of bytes actually
803 * written. This can be NULL if @a fBlocking is true.
804 * @sa RTFileSgWrite, RTSocketSgWrite
805 */
806RTDECL(int) RTVfsIoStrmSgWrite(RTVFSIOSTREAM hVfsIos, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten);
807
808/**
809 * Flush any buffered data to the I/O stream.
810 *
811 * @returns IPRT status code.
812 * @param hVfsIos The VFS I/O stream handle.
813 * @sa RTVfsFileFlush, RTFileFlush, RTPipeFlush
814 */
815RTDECL(int) RTVfsIoStrmFlush(RTVFSIOSTREAM hVfsIos);
816
817/**
818 * Poll for events.
819 *
820 * @returns IPRT status code.
821 * @param hVfsIos The VFS I/O stream handle.
822 * @param fEvents The events to poll for (RTPOLL_EVT_XXX).
823 * @param cMillies How long to wait for event to eventuate.
824 * @param fIntr Whether the wait is interruptible and can return
825 * VERR_INTERRUPTED (@c true) or if this condition
826 * should be hidden from the caller (@c false).
827 * @param pfRetEvents Where to return the event mask.
828 * @sa RTVfsFilePoll, RTPollSetAdd, RTPoll, RTPollNoResume.
829 */
830RTDECL(int) RTVfsIoStrmPoll(RTVFSIOSTREAM hVfsIos, uint32_t fEvents, RTMSINTERVAL cMillies, bool fIntr,
831 uint32_t *pfRetEvents);
832/**
833 * Tells the current I/O stream position.
834 *
835 * @returns Zero or higher - where to return the I/O stream offset. Values
836 * below zero are IPRT status codes (VERR_XXX).
837 * @param hVfsIos The VFS I/O stream handle.
838 * @sa RTFileTell
839 */
840RTDECL(RTFOFF) RTVfsIoStrmTell(RTVFSIOSTREAM hVfsIos);
841
842/**
843 * Skips @a cb ahead in the stream.
844 *
845 * @returns IPRT status code.
846 * @param hVfsIos The VFS I/O stream handle.
847 * @param cb The number bytes to skip.
848 */
849RTDECL(int) RTVfsIoStrmSkip(RTVFSIOSTREAM hVfsIos, RTFOFF cb);
850
851/**
852 * Fills the stream with @a cb zeros.
853 *
854 * @returns IPRT status code.
855 * @param hVfsIos The VFS I/O stream handle.
856 * @param cb The number of zero bytes to insert.
857 */
858RTDECL(int) RTVfsIoStrmZeroFill(RTVFSIOSTREAM hVfsIos, RTFOFF cb);
859
860/**
861 * Checks if we're at the end of the I/O stream.
862 *
863 * @returns true if at EOS, otherwise false.
864 * @param hVfsIos The VFS I/O stream handle.
865 */
866RTDECL(bool) RTVfsIoStrmIsAtEnd(RTVFSIOSTREAM hVfsIos);
867
868/**
869 * Process the rest of the stream, checking if it's all valid UTF-8 encoding.
870 *
871 * @returns IPRT status code.
872 *
873 * @param hVfsIos The VFS I/O stream handle.
874 * @param fFlags Flags governing the validation, see
875 * RTVFS_VALIDATE_UTF8_XXX.
876 * @param poffError Where to return the error offset. Optional.
877 */
878RTDECL(int) RTVfsIoStrmValidateUtf8Encoding(RTVFSIOSTREAM hVfsIos, uint32_t fFlags, PRTFOFF poffError);
879
880/** @defgroup RTVFS_VALIDATE_UTF8_XXX RTVfsIoStrmValidateUtf8Encoding flags.
881 * @{ */
882/** The text must not contain any null terminator codepoints. */
883#define RTVFS_VALIDATE_UTF8_NO_NULL RT_BIT_32(0)
884/** The codepoints must be in the range covered by RTC-3629. */
885#define RTVFS_VALIDATE_UTF8_BY_RTC_3629 RT_BIT_32(1)
886/** Mask of valid flags. */
887#define RTVFS_VALIDATE_UTF8_VALID_MASK UINT32_C(0x00000003)
888/** @} */
889
890/** @} */
891
892
893/** @defgroup grp_vfs_file VFS File API
894 * @{
895 */
896RTDECL(int) RTVfsFileOpen(RTVFS hVfs, const char *pszFilename, uint64_t fOpen, PRTVFSFILE phVfsFile);
897
898/**
899 * Create a VFS file handle from a standard IPRT file handle (RTFILE).
900 *
901 * @returns IPRT status code.
902 * @param hFile The standard IPRT file handle.
903 * @param fOpen The flags the handle was opened with. Pass 0 to
904 * have these detected.
905 * @param fLeaveOpen Whether to leave the handle open when the VFS file
906 * is released, or to close it (@c false).
907 * @param phVfsFile Where to return the VFS file handle.
908 */
909RTDECL(int) RTVfsFileFromRTFile(RTFILE hFile, uint64_t fOpen, bool fLeaveOpen, PRTVFSFILE phVfsFile);
910RTDECL(RTHCUINTPTR) RTVfsFileToNative(RTFILE hVfsFile);
911
912/**
913 * Convenience function combining RTFileOpen with RTVfsFileFromRTFile.
914 *
915 * @returns IPRT status code.
916 * @param pszFilename The path to the file in the normal file system.
917 * @param fOpen The flags to pass to RTFileOpen when opening the
918 * file, i.e. RTFILE_O_XXX.
919 * @param phVfsFile Where to return the VFS file handle.
920 */
921RTDECL(int) RTVfsFileOpenNormal(const char *pszFilename, uint64_t fOpen, PRTVFSFILE phVfsFile);
922
923/**
924 * Convert the VFS file handle to a VFS I/O stream handle.
925 *
926 * @returns The VFS I/O stream handle on success, this must be released.
927 * NIL_RTVFSIOSTREAM if the file handle is invalid.
928 * @param hVfsFile The VFS file handle.
929 * @sa RTVfsIoStrmToFile
930 */
931RTDECL(RTVFSIOSTREAM) RTVfsFileToIoStream(RTVFSFILE hVfsFile);
932
933/**
934 * Retains a reference to the VFS file handle.
935 *
936 * @returns New reference count on success, UINT32_MAX on failure.
937 * @param hVfsFile The VFS file handle.
938 */
939RTDECL(uint32_t) RTVfsFileRetain(RTVFSFILE hVfsFile);
940RTDECL(uint32_t) RTVfsFileRetainDebug(RTVFSFILE hVfsFile, RT_SRC_POS_DECL);
941
942/**
943 * Releases a reference to the VFS file handle.
944 *
945 * @returns New reference count on success (0 if closed), UINT32_MAX on failure.
946 * @param hVfsFile The VFS file handle.
947 */
948RTDECL(uint32_t) RTVfsFileRelease(RTVFSFILE hVfsFile);
949
950/**
951 * Query information about the object.
952 *
953 * @returns IPRT status code.
954 * @retval VERR_NOT_SUPPORTED if the @a enmAddAttr value is not handled by the
955 * implementation.
956 *
957 * @param hVfsFile The VFS file handle.
958 * @param pObjInfo Where to return the info.
959 * @param enmAddAttr Which additional attributes should be retrieved.
960 * @sa RTVfsObjQueryInfo, RTVfsFsStrmQueryInfo, RTVfsDirQueryInfo,
961 * RTVfsIoStrmQueryInfo, RTVfsFileQueryInfo, RTFileQueryInfo,
962 * RTPathQueryInfo.
963 */
964RTDECL(int) RTVfsFileQueryInfo(RTVFSFILE hVfsFile, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr);
965
966/**
967 * Read bytes from the file at the current position.
968 *
969 * @returns IPRT status code.
970 * @retval VINF_SUCCESS and the number of bytes read written to @a pcbRead.
971 * @retval VINF_EOF when trying to read __beyond__ the end of the file and
972 * @a pcbRead is not NULL (it will be set to the number of bytes read,
973 * or 0 if the end of the file was reached before this call).
974 * When the last byte of the read request is the last byte in the
975 * file, this status code will not be used. However, VINF_EOF is
976 * returned when attempting to read 0 bytes while standing at the end
977 * of the file.
978 * @retval VERR_EOF when trying to read __beyond__ the end of the file and
979 * @a pcbRead is NULL.
980 * @retval VERR_ACCESS_DENIED if the file is not readable.
981 *
982 * @param hVfsFile The VFS file handle.
983 * @param pvBuf Where to store the read bytes.
984 * @param cbToRead The number of bytes to read.
985 * @param pcbRead Where to always store the number of bytes actually
986 * read. Optional.
987 * @sa RTVfsIoStrmRead, RTFileRead, RTPipeRead, RTPipeReadBlocking,
988 * RTSocketRead
989 */
990RTDECL(int) RTVfsFileRead(RTVFSFILE hVfsFile, void *pvBuf, size_t cbToRead, size_t *pcbRead);
991RTDECL(int) RTVfsFileReadAt(RTVFSFILE hVfsFile, RTFOFF off, void *pvBuf, size_t cbToRead, size_t *pcbRead);
992
993/**
994 * Write bytes to the file at the current position.
995 *
996 * @returns IPRT status code.
997 * @retval VERR_ACCESS_DENIED if the file is not writable.
998 *
999 * @param hVfsFile The VFS file handle.
1000 * @param pvBuf The bytes to write.
1001 * @param cbToWrite The number of bytes to write.
1002 * @param pcbWritten Where to always store the number of bytes actually
1003 * written. This can be NULL.
1004 * @sa RTVfsIoStrmRead, RTFileWrite, RTPipeWrite, RTPipeWriteBlocking,
1005 * RTSocketWrite
1006 */
1007RTDECL(int) RTVfsFileWrite(RTVFSFILE hVfsFile, const void *pvBuf, size_t cbToWrite, size_t *pcbWritten);
1008RTDECL(int) RTVfsFileWriteAt(RTVFSFILE hVfsFile, RTFOFF off, const void *pvBuf, size_t cbToWrite, size_t *pcbWritten);
1009
1010
1011/**
1012 * Reads bytes from the file into a scatter buffer.
1013 *
1014 * @returns IPRT status code.
1015 * @retval VINF_SUCCESS and the number of bytes read written to @a pcbRead.
1016 * @retval VINF_TRY_AGAIN if @a fBlocking is @c false, @a pcbRead is not NULL,
1017 * and no data was available. @a *pcbRead will be set to 0.
1018 * @retval VINF_EOF when trying to read __beyond__ the end of the stream and
1019 * @a pcbRead is not NULL (it will be set to the number of bytes read,
1020 * or 0 if the end of the stream was reached before this call).
1021 * When the last byte of the read request is the last byte in the
1022 * stream, this status code will not be used. However, VINF_EOF is
1023 * returned when attempting to read 0 bytes while standing at the end
1024 * of the stream.
1025 * @retval VERR_EOF when trying to read __beyond__ the end of the stream and
1026 * @a pcbRead is NULL.
1027 * @retval VERR_ACCESS_DENIED if the stream is not readable.
1028 *
1029 * @param hVfsFile The VFS file handle.
1030 * @param off Where to read at, -1 for the current position.
1031 * @param pSgBuf Pointer to a scatter buffer descriptor. The number
1032 * of bytes described by the segments is what will be
1033 * attemted read.
1034 * @param fBlocking Whether the call is blocking (@c true) or not. If
1035 * not, the @a pcbRead parameter must not be NULL.
1036 * @param pcbRead Where to always store the number of bytes actually
1037 * read. This can be NULL if @a fBlocking is true.
1038 * @sa RTFileSgRead, RTSocketSgRead, RTPipeRead, RTPipeReadBlocking
1039 */
1040RTDECL(int) RTVfsFileSgRead(RTVFSFILE hVfsFile, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead);
1041
1042/**
1043 * Write bytes to the file from a gather buffer.
1044 *
1045 * @returns IPRT status code.
1046 * @retval VERR_ACCESS_DENIED if the stream is not writable.
1047 *
1048 * @param hVfsFile The VFS file handle.
1049 * @param off Where to write at, -1 for the current position.
1050 * @param pSgBuf Pointer to a gather buffer descriptor. The number
1051 * of bytes described by the segments is what will be
1052 * attemted written.
1053 * @param fBlocking Whether the call is blocking (@c true) or not. If
1054 * not, the @a pcbWritten parameter must not be NULL.
1055 * @param pcbWritten Where to always store the number of bytes actually
1056 * written. This can be NULL if @a fBlocking is true.
1057 * @sa RTFileSgWrite, RTSocketSgWrite
1058 */
1059RTDECL(int) RTVfsFileSgWrite(RTVFSFILE hVfsFile, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten);
1060
1061/**
1062 * Flush any buffered data to the file.
1063 *
1064 * @returns IPRT status code.
1065 * @param hVfsFile The VFS file handle.
1066 * @sa RTVfsIoStrmFlush, RTFileFlush, RTPipeFlush
1067 */
1068RTDECL(int) RTVfsFileFlush(RTVFSFILE hVfsFile);
1069
1070/**
1071 * Poll for events.
1072 *
1073 * @returns IPRT status code.
1074 * @param hVfsFile The VFS file handle.
1075 * @param fEvents The events to poll for (RTPOLL_EVT_XXX).
1076 * @param cMillies How long to wait for event to eventuate.
1077 * @param fIntr Whether the wait is interruptible and can return
1078 * VERR_INTERRUPTED (@c true) or if this condition
1079 * should be hidden from the caller (@c false).
1080 * @param pfRetEvents Where to return the event mask.
1081 * @sa RTVfsIoStrmPoll, RTPollSetAdd, RTPoll, RTPollNoResume.
1082 */
1083RTDECL(RTFOFF) RTVfsFilePoll(RTVFSFILE hVfsFile, uint32_t fEvents, RTMSINTERVAL cMillies, bool fIntr,
1084 uint32_t *pfRetEvents);
1085
1086/**
1087 * Tells the current file position.
1088 *
1089 * @returns Zero or higher - where to return the file offset. Values
1090 * below zero are IPRT status codes (VERR_XXX).
1091 * @param hVfsFile The VFS file handle.
1092 * @sa RTFileTell, RTVfsIoStrmTell.
1093 */
1094RTDECL(RTFOFF) RTVfsFileTell(RTVFSFILE hVfsFile);
1095
1096/**
1097 * Changes the current read/write position of a file.
1098 *
1099 * @returns IPRT status code.
1100 *
1101 * @param hVfsFile The VFS file handle.
1102 * @param offSeek The seek offset.
1103 * @param uMethod The seek emthod.
1104 * @param poffActual Where to optionally return the new file offset.
1105 *
1106 * @sa RTFileSeek
1107 */
1108RTDECL(int) RTVfsFileSeek(RTVFSFILE hVfsFile, RTFOFF offSeek, uint32_t uMethod, uint64_t *poffActual);
1109
1110RTDECL(int) RTVfsFileSetSize(RTVFSFILE hVfsFile, uint64_t cbSize);
1111RTDECL(int) RTVfsFileGetSize(RTVFSFILE hVfsFile, uint64_t *pcbSize);
1112RTDECL(RTFOFF) RTVfsFileGetMaxSize(RTVFSFILE hVfsFile);
1113RTDECL(int) RTVfsFileGetMaxSizeEx(RTVFSFILE hVfsFile, PRTFOFF pcbMax);
1114
1115/** @} */
1116
1117
1118#ifdef DEBUG
1119# undef RTVfsRetain
1120# define RTVfsRetain(hVfs) RTVfsRetainDebug(hVfs, RT_SRC_POS)
1121# undef RTVfsObjRetain
1122# define RTVfsObjRetain(hVfsObj) RTVfsObjRetainDebug(hVfsObj, RT_SRC_POS)
1123# undef RTVfsDirRetain
1124# define RTVfsDirRetain(hVfsDir) RTVfsDirRetainDebug(hVfsDir, RT_SRC_POS)
1125# undef RTVfsFileRetain
1126# define RTVfsFileRetain(hVfsFile) RTVfsFileRetainDebug(hVfsFile, RT_SRC_POS)
1127# undef RTVfsIoStrmRetain
1128# define RTVfsIoStrmRetain(hVfsIos) RTVfsIoStrmRetainDebug(hVfsIos, RT_SRC_POS)
1129# undef RTVfsFsStrmRetain
1130# define RTVfsFsStrmRetain(hVfsFss) RTVfsFsStrmRetainDebug(hVfsFss, RT_SRC_POS)
1131#endif
1132
1133
1134
1135/** @defgroup grp_vfs_misc VFS Miscellaneous
1136 * @{
1137 */
1138
1139/**
1140 * Memorizes the I/O stream as a file backed by memory.
1141 *
1142 * @returns IPRT status code.
1143 *
1144 * @param hVfsIos The VFS I/O stream to memorize. This will be read
1145 * to the end on success, on failure its position is
1146 * undefined.
1147 * @param fFlags A combination of RTFILE_O_READ and RTFILE_O_WRITE.
1148 * @param phVfsFile Where to return the handle to the memory file on
1149 * success.
1150 */
1151RTDECL(int) RTVfsMemorizeIoStreamAsFile(RTVFSIOSTREAM hVfsIos, uint32_t fFlags, PRTVFSFILE phVfsFile);
1152
1153
1154/**
1155 * Creates a VFS file from a memory buffer.
1156 *
1157 * @returns IPRT status code.
1158 *
1159 * @param fFlags A combination of RTFILE_O_READ and RTFILE_O_WRITE.
1160 * @param pvBuf The buffer. This will be copied and not referenced
1161 * after this function returns.
1162 * @param cbBuf The buffer size.
1163 * @param phVfsFile Where to return the handle to the memory file on
1164 * success.
1165 */
1166RTDECL(int) RTVfsFileFromBuffer(uint32_t fFlags, void const *pvBuf, size_t cbBuf, PRTVFSFILE phVfsFile);
1167
1168/**
1169 * Creates a memory backed VFS file object for read and write.
1170 *
1171 * @returns IPRT status code.
1172 *
1173 * @param hVfsIos The VFS I/O stream to memorize. This will be read
1174 * to the end on success, on failure its position is
1175 * undefined.
1176 * @param cbEstimate The estimated file size.
1177 * @param phVfsFile Where to return the handle to the memory file on
1178 * success.
1179 */
1180RTDECL(int) RTVfsMemFileCreate(RTVFSIOSTREAM hVfsIos, size_t cbEstimate, PRTVFSFILE phVfsFile);
1181
1182/**
1183 * Pumps data from one I/O stream to another.
1184 *
1185 * The data is read in chunks from @a hVfsIosSrc and written to @a hVfsIosDst
1186 * until @a hVfsIosSrc indicates end of stream.
1187 *
1188 * @returns IPRT status code
1189 *
1190 * @param hVfsIosSrc The input stream.
1191 * @param hVfsIosDst The output stream.
1192 * @param cbBufHint Hints at a good temporary buffer size, pass 0 if
1193 * clueless.
1194 */
1195RTDECL(int) RTVfsUtilPumpIoStreams(RTVFSIOSTREAM hVfsIosSrc, RTVFSIOSTREAM hVfsIosDst, size_t cbBufHint);
1196
1197/**
1198 * Create an I/O stream instance performing simple sequential read-ahead.
1199 *
1200 * @returns IPRT status code.
1201 * @param hVfsIos The input stream to perform read ahead on. If this is
1202 * actually for a file object, the returned I/O stream
1203 * handle can also be cast to a file handle.
1204 * @param fFlags Flags reserved for future use, MBZ.
1205 * @param cBuffers How many read ahead buffers to use. Specify 0 for
1206 * default value.
1207 * @param cbBuffer The size of each read ahead buffer. Specify 0 for
1208 * default value.
1209 * @param phVfsIos Where to return the read ahead I/O stream handle.
1210 *
1211 * @remarks Careful using this on a message pipe or socket. The reads are
1212 * performed in blocked mode and it may be host and/or implementation
1213 * dependent whether they will return ready data immediate or wait
1214 * until there's a whole @a cbBuffer (or default) worth ready.
1215 *
1216 * @sa RTVfsCreateReadAheadForFile
1217 */
1218RTDECL(int) RTVfsCreateReadAheadForIoStream(RTVFSIOSTREAM hVfsIos, uint32_t fFlags, uint32_t cBuffers, uint32_t cbBuffer,
1219 PRTVFSIOSTREAM phVfsIos);
1220
1221/**
1222 * Create an I/O stream instance performing simple sequential read-ahead.
1223 *
1224 * @returns IPRT status code.
1225 * @param hVfsFile The input file to perform read ahead on.
1226 * @param fFlags Flags reserved for future use, MBZ.
1227 * @param cBuffers How many read ahead buffers to use. Specify 0 for
1228 * default value.
1229 * @param cbBuffer The size of each read ahead buffer. Specify 0 for
1230 * default value.
1231 * @param phVfsFile Where to return the read ahead file handle.
1232 * @sa RTVfsCreateReadAheadForIoStream
1233 */
1234RTDECL(int) RTVfsCreateReadAheadForFile(RTVFSFILE hVfsFile, uint32_t fFlags, uint32_t cBuffers, uint32_t cbBuffer,
1235 PRTVFSFILE phVfsFile);
1236
1237/** @} */
1238
1239
1240/** @defgroup grp_rt_vfs_chain VFS Chains
1241 *
1242 * VFS chains is for doing pipe like things with VFS objects from the command
1243 * line. Imagine you want to cat the readme.gz of an ISO you could do
1244 * something like:
1245 * RTCat :iprtvfs:file(stdfile,live.iso)|vfs(isofs)|iso(open,readme.gz)|ios(gunzip)
1246 * or
1247 * RTCat :iprtvfs:file(stdfile,live.iso)|ios(isofs,readme.gz)|ios(gunzip)
1248 *
1249 * Or say you want to read the README.TXT on a floppy image:
1250 * RTCat :iprtvfs:file(stdfile,floppy.img,r)|vfs(fat)|ios(open,README.TXT)
1251 * or
1252 * RTCat :iprtvfs:file(stdfile,floppy.img,r)|vfs(fat)|README.TXT
1253 *
1254 * Or in the other direction, you want to write a STUFF.TGZ file to the above
1255 * floppy image, using a lazy writer thread for compressing the data:
1256 * RTTar cf :iprtvfs:file(stdfile,floppy.img,rw)|ios(fat,STUFF.TGZ)|ios(gzip)|ios(push) .
1257 *
1258 *
1259 * A bit more formally:
1260 * :iprtvfs:{type}({provider}[,provider-args])[{separator}{type}...][{separator}{path}]
1261 *
1262 * The @c type refers to VFS object that should be created by the @c provider.
1263 * Valid types:
1264 * - vfs: A virtual file system (volume).
1265 * - fss: A file system stream (e.g. tar).
1266 * - ios: An I/O stream.
1267 * - file: A file.
1268 * - dir: A directory.
1269 * - sym: A symbolic link (not sure how useful this is).
1270 *
1271 * The @c provider refers to registered chain element providers (see
1272 * RTVFSCHAINELEMENTREG for how that works internally). These are asked to
1273 * create a VFS object of the specified type using the given arguments (if any).
1274 * Default providers:
1275 * - std: Standard file, directory and file system.
1276 * - open: Opens a file, I/O stream or directory in a vfs or directory object.
1277 * - pull: Read-ahead buffering thread on file or I/O stream.
1278 * - push: Lazy-writer buffering thread on file or I/O stream.
1279 * - gzip: Compresses an I/O stream.
1280 * - gunzip: Decompresses an I/O stream.
1281 * - fat: FAT file system accessor.
1282 * - isofs: ISOFS file system accessor.
1283 *
1284 * As element @c separator we allow both colon (':') and the pipe character
1285 * ('|'). The latter the conventional one, but since it's inconvenient on the
1286 * command line, colon is provided as an alternative.
1287 *
1288 * In the final element we allow a simple @a path to be specified instead of the
1289 * type-provider-arguments stuff. The previous object must be a directory, file
1290 * system or file system stream. The application will determin exactly which
1291 * operation or operations which will be performed.
1292 *
1293 * @{
1294 */
1295
1296/** The path prefix used to identify an VFS chain specification. */
1297#define RTVFSCHAIN_SPEC_PREFIX ":iprtvfs:"
1298
1299RTDECL(int) RTVfsChainOpenVfs(const char *pszSpec, PRTVFS phVfs, uint32_t *poffError, PRTERRINFO pErrInfo);
1300RTDECL(int) RTVfsChainOpenFsStream(const char *pszSpec, PRTVFSFSSTREAM phVfsFss, uint32_t *poffError, PRTERRINFO pErrInfo);
1301RTDECL(int) RTVfsChainOpenDir(const char *pszSpec, uint32_t fOpen, PRTVFSDIR phVfsDir, uint32_t *poffError, PRTERRINFO pErrInfo);
1302RTDECL(int) RTVfsChainOpenFile(const char *pszSpec, uint64_t fOpen, PRTVFSFILE phVfsFile, uint32_t *poffError, PRTERRINFO pErrInfo);
1303RTDECL(int) RTVfsChainOpenIoStream(const char *pszSpec, uint64_t fOpen, PRTVFSIOSTREAM phVfsIos, uint32_t *poffError, PRTERRINFO pErrInfo);
1304RTDECL(int) RTVfsChainOpenSymlink(const char *pszSpec, PRTVFSSYMLINK phVfsSym, uint32_t *poffError, PRTERRINFO pErrInfo);
1305
1306RTDECL(int) RTVfsChainQueryInfo(const char *pszSpec, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAdditionalAttribs,
1307 uint32_t fFlags, uint32_t *poffError, PRTERRINFO pErrInfo);
1308
1309/**
1310 * Tests if the given string is a chain specification or not.
1311 *
1312 * @returns true if it is, false if it isn't.
1313 * @param pszSpec The alleged chain spec.
1314 */
1315RTDECL(bool) RTVfsChainIsSpec(const char *pszSpec);
1316
1317/**
1318 * Common code for reporting errors of a RTVfsChainOpen* API.
1319 *
1320 * @param pszFunction The API called.
1321 * @param pszSpec The VFS chain specification or file path passed to the.
1322 * @param rc The return code.
1323 * @param offError The error offset value returned (0 if not captured).
1324 * @param pErrInfo Additional error information. Optional.
1325 *
1326 * @sa RTVfsChainMsgErrorExitFailure
1327 * @sa RTVfsChainOpenVfs, RTVfsChainOpenFsStream, RTVfsChainOpenDir,
1328 * RTVfsChainOpenFile, RTVfsChainOpenIoStream, RTVfsChainOpenSymlink
1329 */
1330RTDECL(void) RTVfsChainMsgError(const char *pszFunction, const char *pszSpec, int rc, uint32_t offError, PRTERRINFO pErrInfo);
1331
1332/**
1333 * Common code for reporting errors of a RTVfsChainOpen* API.
1334 *
1335 * @returns RTEXITCODE_FAILURE
1336 *
1337 * @param pszFunction The API called.
1338 * @param pszSpec The VFS chain specification or file path passed to the.
1339 * @param rc The return code.
1340 * @param offError The error offset value returned (0 if not captured).
1341 * @param pErrInfo Additional error information. Optional.
1342 *
1343 * @sa RTVfsChainMsgError
1344 * @sa RTVfsChainOpenVfs, RTVfsChainOpenFsStream, RTVfsChainOpenDir,
1345 * RTVfsChainOpenFile, RTVfsChainOpenIoStream, RTVfsChainOpenSymlink
1346 */
1347RTDECL(RTEXITCODE) RTVfsChainMsgErrorExitFailure(const char *pszFunction, const char *pszSpec,
1348 int rc, uint32_t offError, PRTERRINFO pErrInfo);
1349
1350
1351/** @} */
1352
1353
1354/** @} */
1355
1356RT_C_DECLS_END
1357
1358#endif /* !___iprt_vfs_h */
1359
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