GuestHost/installation/VBoxWinDrvInst.cpp: Try harder if DiInstallDriverW() returns...
[vbox.git] / include / iprt / vfslowlevel.h
blobf64fa23c7a9220a246e0a5dfeeb4170658c9e786
1 /** @file
2 * IPRT - Virtual Filesystem.
3 */
5 /*
6 * Copyright (C) 2010-2024 Oracle and/or its affiliates.
8 * This file is part of VirtualBox base platform packages, as
9 * available from https://www.virtualbox.org.
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation, in version 3 of the
14 * License.
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 * The contents of this file may alternatively be used under the terms
25 * of the Common Development and Distribution License Version 1.0
26 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
27 * in the VirtualBox distribution, in which case the provisions of the
28 * CDDL are applicable instead of those of the GPL.
30 * You may elect to license modified versions of this file under the
31 * terms and conditions of either the GPL or the CDDL or both.
33 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
36 #ifndef IPRT_INCLUDED_vfslowlevel_h
37 #define IPRT_INCLUDED_vfslowlevel_h
38 #ifndef RT_WITHOUT_PRAGMA_ONCE
39 # pragma once
40 #endif
42 #include <iprt/vfs.h>
43 #include <iprt/errcore.h>
44 #include <iprt/list.h>
45 #include <iprt/param.h>
48 RT_C_DECLS_BEGIN
50 /** @defgroup grp_rt_vfs_lowlevel RTVfs - Low-level Interface.
51 * @ingroup grp_rt_vfs
52 * @{
56 /** @name VFS Lock Abstraction
57 * @todo This should be moved somewhere else as it is of general use.
58 * @{ */
60 /**
61 * VFS lock types.
63 typedef enum RTVFSLOCKTYPE
65 /** Invalid lock type. */
66 RTVFSLOCKTYPE_INVALID = 0,
67 /** Read write semaphore. */
68 RTVFSLOCKTYPE_RW,
69 /** Fast mutex semaphore (critical section in ring-3). */
70 RTVFSLOCKTYPE_FASTMUTEX,
71 /** Full fledged mutex semaphore. */
72 RTVFSLOCKTYPE_MUTEX,
73 /** The end of valid lock types. */
74 RTVFSLOCKTYPE_END,
75 /** The customary 32-bit type hack. */
76 RTVFSLOCKTYPE_32BIT_HACK = 0x7fffffff
77 } RTVFSLOCKTYPE;
79 /** VFS lock handle. */
80 typedef struct RTVFSLOCKINTERNAL *RTVFSLOCK;
81 /** Pointer to a VFS lock handle. */
82 typedef RTVFSLOCK *PRTVFSLOCK;
83 /** Nil VFS lock handle. */
84 #define NIL_RTVFSLOCK ((RTVFSLOCK)~(uintptr_t)0)
86 /** Special handle value for creating a new read/write semaphore based lock. */
87 #define RTVFSLOCK_CREATE_RW ((RTVFSLOCK)~(uintptr_t)1)
88 /** Special handle value for creating a new fast mutex semaphore based lock. */
89 #define RTVFSLOCK_CREATE_FASTMUTEX ((RTVFSLOCK)~(uintptr_t)2)
90 /** Special handle value for creating a new mutex semaphore based lock. */
91 #define RTVFSLOCK_CREATE_MUTEX ((RTVFSLOCK)~(uintptr_t)3)
93 /**
94 * Retains a reference to the VFS lock handle.
96 * @returns New reference count on success, UINT32_MAX on failure.
97 * @param hLock The VFS lock handle.
99 RTDECL(uint32_t) RTVfsLockRetain(RTVFSLOCK hLock);
102 * Releases a reference to the VFS lock handle.
104 * @returns New reference count on success (0 if closed), UINT32_MAX on failure.
105 * @param hLock The VFS lock handle.
107 RTDECL(uint32_t) RTVfsLockRelease(RTVFSLOCK hLock);
110 * Gets the lock type.
112 * @returns The lock type on success, RTVFSLOCKTYPE_INVALID if the handle is
113 * not valid.
114 * @param hLock The lock handle.
116 RTDECL(RTVFSLOCKTYPE) RTVfsLockGetType(RTVFSLOCK hLock);
120 RTDECL(void) RTVfsLockAcquireReadSlow(RTVFSLOCK hLock);
121 RTDECL(void) RTVfsLockReleaseReadSlow(RTVFSLOCK hLock);
122 RTDECL(void) RTVfsLockAcquireWriteSlow(RTVFSLOCK hLock);
123 RTDECL(void) RTVfsLockReleaseWriteSlow(RTVFSLOCK hLock);
126 * Acquire a read lock.
128 * @param hLock The lock handle, can be NIL.
130 DECLINLINE(void) RTVfsLockAcquireRead(RTVFSLOCK hLock)
132 if (hLock != NIL_RTVFSLOCK)
133 RTVfsLockAcquireReadSlow(hLock);
138 * Release a read lock.
140 * @param hLock The lock handle, can be NIL.
142 DECLINLINE(void) RTVfsLockReleaseRead(RTVFSLOCK hLock)
144 if (hLock != NIL_RTVFSLOCK)
145 RTVfsLockReleaseReadSlow(hLock);
150 * Acquire a write lock.
152 * @param hLock The lock handle, can be NIL.
154 DECLINLINE(void) RTVfsLockAcquireWrite(RTVFSLOCK hLock)
156 if (hLock != NIL_RTVFSLOCK)
157 RTVfsLockAcquireWriteSlow(hLock);
162 * Release a write lock.
164 * @param hLock The lock handle, can be NIL.
166 DECLINLINE(void) RTVfsLockReleaseWrite(RTVFSLOCK hLock)
168 if (hLock != NIL_RTVFSLOCK)
169 RTVfsLockReleaseWriteSlow(hLock);
172 /** @} */
175 * Info queried via RTVFSOBJOPS::pfnQueryInfoEx, ++.
177 typedef enum RTVFSQIEX
179 /** Invalid zero value. */
180 RTVFSQIEX_INVALID = 0,
181 /** Volume label.
182 * Returns a UTF-8 string. */
183 RTVFSQIEX_VOL_LABEL,
184 /** Alternative volume label, the primary one for ISOs, otherwise treated same
185 * as RTVFSQIEX_VOL_LABEL. */
186 RTVFSQIEX_VOL_LABEL_ALT,
187 /** Volume serial number.
188 * Returns a uint32_t, uint64_t or RTUUID. */
189 RTVFSQIEX_VOL_SERIAL,
190 /** End of valid queries. */
191 RTVFSQIEX_END,
193 /** The usual 32-bit hack. */
194 RTVFSQIEX_32BIT_SIZE_HACK = 0x7fffffff
195 } RTVFSQIEX;
199 * The basis for all virtual file system objects.
201 typedef struct RTVFSOBJOPS
203 /** The structure version (RTVFSOBJOPS_VERSION). */
204 uint32_t uVersion;
205 /** The object type for type introspection. */
206 RTVFSOBJTYPE enmType;
207 /** The name of the operations. */
208 const char *pszName;
211 * Close the object.
213 * @returns IPRT status code.
214 * @param pvThis The implementation specific file data.
216 DECLCALLBACKMEMBER(int, pfnClose,(void *pvThis));
219 * Get information about the file.
221 * @returns IPRT status code. See RTVfsObjQueryInfo.
222 * @retval VERR_WRONG_TYPE if file system or file system stream.
224 * @param pvThis The implementation specific file data.
225 * @param pObjInfo Where to return the object info on success.
226 * @param enmAddAttr Which set of additional attributes to request.
227 * @sa RTVfsObjQueryInfo, RTFileQueryInfo, RTPathQueryInfo
229 DECLCALLBACKMEMBER(int, pfnQueryInfo,(void *pvThis, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr));
232 * Query arbritray information about the file, volume, or whatever.
234 * @returns IPRT status code.
235 * @retval VERR_BUFFER_OVERFLOW sets pcbRet.
237 * @param pvThis The implementation specific file data.
238 * @param enmInfo The information being queried.
239 * @param pvInfo Where to return the info.
240 * @param cbInfo The size of the @a pvInfo buffer.
241 * @param pcbRet The size of the returned data. In case of
242 * VERR_BUFFER_OVERFLOW this will be set to the required
243 * buffer size.
245 DECLCALLBACKMEMBER(int, pfnQueryInfoEx,(void *pvThis, RTVFSQIEX enmInfo, void *pvInfo, size_t cbInfo, size_t *pcbRet));
247 /** Marks the end of the structure (RTVFSOBJOPS_VERSION). */
248 uintptr_t uEndMarker;
249 } RTVFSOBJOPS;
250 /** Pointer to constant VFS object operations. */
251 typedef RTVFSOBJOPS const *PCRTVFSOBJOPS;
253 /** The RTVFSOBJOPS structure version. */
254 #define RTVFSOBJOPS_VERSION RT_MAKE_U32_FROM_U8(0xff,0x1f,2,0)
258 * The VFS operations.
260 typedef struct RTVFSOPS
262 /** The basic object operation. */
263 RTVFSOBJOPS Obj;
264 /** The structure version (RTVFSOPS_VERSION). */
265 uint32_t uVersion;
266 /** The virtual file system feature mask. */
267 uint32_t fFeatures;
270 * Opens the root directory.
272 * @returns IPRT status code.
273 * @param pvThis The implementation specific data.
274 * @param phVfsDir Where to return the handle to the root directory.
276 DECLCALLBACKMEMBER(int, pfnOpenRoot,(void *pvThis, PRTVFSDIR phVfsDir));
279 * Query the status of the given storage range (optional).
281 * This can be used by the image compaction utilites to evict non-zero blocks
282 * that aren't currently being used by the file system.
284 * @returns IPRT status code.
285 * @param pvThis The implementation specific data.
286 * @param off Start offset to check.
287 * @param cb Number of bytes to check.
288 * @param pfUsed Where to store whether the given range is in use.
290 DECLCALLBACKMEMBER(int, pfnQueryRangeState,(void *pvThis, uint64_t off, size_t cb, bool *pfUsed));
292 /** @todo There will be more methods here to optimize opening and
293 * querying. */
295 #if 0
297 * Optional entry point for optimizing path traversal within the file system.
299 * @returns IPRT status code.
300 * @param pvThis The implementation specific data.
301 * @param pszPath The path to resolve.
302 * @param poffPath The current path offset on input, what we've
303 * traversed to on successful return.
304 * @param phVfs??? Return handle to what we've traversed.
305 * @param p??? Return other stuff...
307 DECLCALLBACKMEMBER(int, pfnTraverse,(void *pvThis, const char *pszPath, size_t *poffPath, PRTVFS??? phVfs?, ???* p???));
308 #endif
310 /** @todo need rename API */
312 /** Marks the end of the structure (RTVFSOPS_VERSION). */
313 uintptr_t uEndMarker;
314 } RTVFSOPS;
315 /** Pointer to constant VFS operations. */
316 typedef RTVFSOPS const *PCRTVFSOPS;
318 /** The RTVFSOPS structure version. */
319 #define RTVFSOPS_VERSION RT_MAKE_U32_FROM_U8(0xff,0x0f,1,0)
321 /** @name RTVFSOPS::fFeatures
322 * @{ */
323 /** The VFS supports attaching other systems. */
324 #define RTVFSOPS_FEAT_ATTACH RT_BIT_32(0)
325 /** @} */
328 * Creates a new VFS handle.
330 * @returns IPRT status code
331 * @param pVfsOps The VFS operations.
332 * @param cbInstance The size of the instance data.
333 * @param hVfs The VFS handle to associate this VFS with.
334 * NIL_VFS is ok.
335 * @param hLock Handle to a custom lock to be used with the new
336 * object. The reference is consumed. NIL and
337 * special lock handles are fine.
338 * @param phVfs Where to return the new handle.
339 * @param ppvInstance Where to return the pointer to the instance data
340 * (size is @a cbInstance).
342 RTDECL(int) RTVfsNew(PCRTVFSOPS pVfsOps, size_t cbInstance, RTVFS hVfs, RTVFSLOCK hLock,
343 PRTVFS phVfs, void **ppvInstance);
347 * Creates a new VFS base object handle.
349 * @returns IPRT status code
350 * @param pObjOps The base object operations.
351 * @param cbInstance The size of the instance data.
352 * @param hVfs The VFS handle to associate this base object
353 * with. NIL_VFS is ok.
354 * @param hLock Handle to a custom lock to be used with the new
355 * object. The reference is consumed. NIL and
356 * special lock handles are fine.
357 * @param phVfsObj Where to return the new handle.
358 * @param ppvInstance Where to return the pointer to the instance data
359 * (size is @a cbInstance).
361 RTDECL(int) RTVfsNewBaseObj(PCRTVFSOBJOPS pObjOps, size_t cbInstance, RTVFS hVfs, RTVFSLOCK hLock,
362 PRTVFSOBJ phVfsObj, void **ppvInstance);
366 * Gets the private data of a base object.
368 * @returns Pointer to the private data. NULL if the handle is invalid in some
369 * way.
370 * @param hVfsObj The I/O base object handle.
371 * @param pObjOps The base object operations. This servers as a
372 * sort of password.
374 RTDECL(void *) RTVfsObjToPrivate(RTVFSOBJ hVfsObj, PCRTVFSOBJOPS pObjOps);
377 * Additional operations for setting object attributes.
379 typedef struct RTVFSOBJSETOPS
381 /** The structure version (RTVFSOBJSETOPS_VERSION). */
382 uint32_t uVersion;
383 /** The offset back to the RTVFSOBJOPS structure. */
384 uint32_t offObjOps;
387 * Set the unix style owner and group.
389 * @returns IPRT status code.
390 * @param pvThis The implementation specific file data.
391 * @param fMode The new mode bits.
392 * @param fMask The mask indicating which bits we are
393 * changing.
394 * @note Optional, failing with VERR_WRITE_PROTECT if NULL.
395 * @sa RTFileSetMode
397 DECLCALLBACKMEMBER(int, pfnSetMode,(void *pvThis, RTFMODE fMode, RTFMODE fMask));
400 * Set the timestamps associated with the object.
402 * @returns IPRT status code.
403 * @param pvThis The implementation specific file data.
404 * @param pAccessTime Pointer to the new access time. NULL if not
405 * to be changed.
406 * @param pModificationTime Pointer to the new modifcation time. NULL if
407 * not to be changed.
408 * @param pChangeTime Pointer to the new change time. NULL if not
409 * to be changed.
410 * @param pBirthTime Pointer to the new time of birth. NULL if
411 * not to be changed.
412 * @remarks See RTFileSetTimes for restrictions and behavior imposed by the
413 * host OS or underlying VFS provider.
414 * @note Optional, failing with VERR_WRITE_PROTECT if NULL.
415 * @sa RTFileSetTimes
417 DECLCALLBACKMEMBER(int, pfnSetTimes,(void *pvThis, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
418 PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime));
421 * Set the unix style owner and group.
423 * @returns IPRT status code.
424 * @param pvThis The implementation specific file data.
425 * @param uid The user ID of the new owner. NIL_RTUID if
426 * unchanged.
427 * @param gid The group ID of the new owner group. NIL_RTGID if
428 * unchanged.
429 * @note Optional, failing with VERR_WRITE_PROTECT if NULL.
430 * @sa RTFileSetOwner
432 DECLCALLBACKMEMBER(int, pfnSetOwner,(void *pvThis, RTUID uid, RTGID gid));
434 /** Marks the end of the structure (RTVFSOBJSETOPS_VERSION). */
435 uintptr_t uEndMarker;
436 } RTVFSOBJSETOPS;
437 /** Pointer to const object attribute setter operations. */
438 typedef RTVFSOBJSETOPS const *PCRTVFSOBJSETOPS;
440 /** The RTVFSOBJSETOPS structure version. */
441 #define RTVFSOBJSETOPS_VERSION RT_MAKE_U32_FROM_U8(0xff,0x2f,1,0)
445 * The filesystem stream operations.
447 * @extends RTVFSOBJOPS
449 typedef struct RTVFSFSSTREAMOPS
451 /** The basic object operation. */
452 RTVFSOBJOPS Obj;
453 /** The structure version (RTVFSFSSTREAMOPS_VERSION). */
454 uint32_t uVersion;
455 /** Reserved field, MBZ. */
456 uint32_t fReserved;
459 * Gets the next object in the stream.
461 * Readable streams only.
463 * @returns IPRT status code.
464 * @retval VINF_SUCCESS if a new object was retrieved.
465 * @retval VERR_EOF when there are no more objects.
466 * @param pvThis The implementation specific directory data.
467 * @param ppszName Where to return the object name. Must be freed by
468 * calling RTStrFree.
469 * @param penmType Where to return the object type.
470 * @param phVfsObj Where to return the object handle (referenced). This
471 * must be cast to the desired type before use.
472 * @sa RTVfsFsStrmNext
474 * @note Setting this member to NULL is okay for write-only streams.
476 DECLCALLBACKMEMBER(int, pfnNext,(void *pvThis, char **ppszName, RTVFSOBJTYPE *penmType, PRTVFSOBJ phVfsObj));
479 * Adds another object into the stream.
481 * Writable streams only.
483 * @returns IPRT status code.
484 * @param pvThis The implementation specific directory data.
485 * @param pszPath The path to the object.
486 * @param hVfsObj The object to add.
487 * @param fFlags Reserved for the future, MBZ.
488 * @sa RTVfsFsStrmAdd
490 * @note Setting this member to NULL is okay for read-only streams.
492 DECLCALLBACKMEMBER(int, pfnAdd,(void *pvThis, const char *pszPath, RTVFSOBJ hVfsObj, uint32_t fFlags));
495 * Pushes an byte stream onto the stream (optional).
497 * Writable streams only.
499 * This differs from RTVFSFSSTREAMOPS::pfnAdd() in that it will create a regular
500 * file in the output file system stream and provide the actual content bytes
501 * via the returned I/O stream object.
503 * @returns IPRT status code.
504 * @param pvThis The implementation specific directory data.
505 * @param pszPath The path to the file.
506 * @param cbFile The file size. This can also be set to UINT64_MAX if
507 * the file system stream is backed by a file.
508 * @param paObjInfo Array of zero or more RTFSOBJINFO structures containing
509 * different pieces of information about the file. If any
510 * provided, the first one should be a RTFSOBJATTRADD_UNIX
511 * one, additional can be supplied if wanted. What exactly
512 * is needed depends on the underlying FS stream
513 * implementation.
514 * @param cObjInfo Number of items in the array @a paObjInfo points at.
515 * @param fFlags RTVFSFSSTRM_PUSH_F_XXX.
516 * @param phVfsIos Where to return the I/O stream to feed the file content
517 * to. If the FS stream is backed by a file, the returned
518 * handle can be cast to a file if necessary.
520 DECLCALLBACKMEMBER(int, pfnPushFile,(void *pvThis, const char *pszPath, uint64_t cbFile,
521 PCRTFSOBJINFO paObjInfo, uint32_t cObjInfo, uint32_t fFlags, PRTVFSIOSTREAM phVfsIos));
524 * Marks the end of the stream.
526 * Writable streams only.
528 * @returns IPRT status code.
529 * @param pvThis The implementation specific directory data.
530 * @sa RTVfsFsStrmEnd
532 * @note Setting this member to NULL is okay for read-only streams.
534 DECLCALLBACKMEMBER(int, pfnEnd,(void *pvThis));
536 /** Marks the end of the structure (RTVFSFSSTREAMOPS_VERSION). */
537 uintptr_t uEndMarker;
538 } RTVFSFSSTREAMOPS;
539 /** Pointer to const object attribute setter operations. */
540 typedef RTVFSFSSTREAMOPS const *PCRTVFSFSSTREAMOPS;
542 /** The RTVFSFSSTREAMOPS structure version. */
543 #define RTVFSFSSTREAMOPS_VERSION RT_MAKE_U32_FROM_U8(0xff,0x3f,2,0)
547 * Creates a new VFS filesystem stream handle.
549 * @returns IPRT status code
550 * @param pFsStreamOps The filesystem stream operations.
551 * @param cbInstance The size of the instance data.
552 * @param hVfs The VFS handle to associate this filesystem
553 * stream with. NIL_VFS is ok.
554 * @param hLock Handle to a custom lock to be used with the new
555 * object. The reference is consumed. NIL and
556 * special lock handles are fine.
557 * @param fAccess RTFILE_O_READ and/or RTFILE_O_WRITE.
558 * @param phVfsFss Where to return the new handle.
559 * @param ppvInstance Where to return the pointer to the instance data
560 * (size is @a cbInstance).
562 RTDECL(int) RTVfsNewFsStream(PCRTVFSFSSTREAMOPS pFsStreamOps, size_t cbInstance, RTVFS hVfs, RTVFSLOCK hLock, uint32_t fAccess,
563 PRTVFSFSSTREAM phVfsFss, void **ppvInstance);
566 * Gets the private data of an filesystem stream.
568 * @returns Pointer to the private data. NULL if the handle is invalid in some
569 * way.
570 * @param hVfsFss The FS stream handle.
571 * @param pFsStreamOps The FS stream operations. This servers as a
572 * sort of password.
574 RTDECL(void *) RTVfsFsStreamToPrivate(RTVFSFSSTREAM hVfsFss, PCRTVFSFSSTREAMOPS pFsStreamOps);
578 * The directory operations.
580 * @extends RTVFSOBJOPS
581 * @extends RTVFSOBJSETOPS
583 typedef struct RTVFSDIROPS
585 /** The basic object operation. */
586 RTVFSOBJOPS Obj;
587 /** The structure version (RTVFSDIROPS_VERSION). */
588 uint32_t uVersion;
589 /** Reserved field, MBZ. */
590 uint32_t fReserved;
591 /** The object setter operations. */
592 RTVFSOBJSETOPS ObjSet;
595 * Generic method for opening any kind of file system object.
597 * Can also create files and directories. Symbolic links, devices and such
598 * needs to be created using special methods or this would end up being way more
599 * complicated than it already is.
601 * There are optional specializations available.
603 * @returns IPRT status code.
604 * @retval VERR_PATH_NOT_FOUND or VERR_FILE_NOT_FOUND if @a pszEntry was not
605 * found.
606 * @retval VERR_IS_A_FILE if @a pszEntry is a file or similar but @a fFlags
607 * indicates that the type of object should not be opened.
608 * @retval VERR_IS_A_DIRECTORY if @a pszEntry is a directory but @a fFlags
609 * indicates that directories should not be opened.
610 * @retval VERR_IS_A_SYMLINK if @a pszEntry is a symbolic link but @a fFlags
611 * indicates that symbolic links should not be opened (or followed).
612 * @retval VERR_IS_A_FIFO if @a pszEntry is a FIFO but @a fFlags indicates that
613 * FIFOs should not be opened.
614 * @retval VERR_IS_A_SOCKET if @a pszEntry is a socket but @a fFlags indicates
615 * that sockets should not be opened.
616 * @retval VERR_IS_A_BLOCK_DEVICE if @a pszEntry is a block device but
617 * @a fFlags indicates that block devices should not be opened, or vice
618 * versa.
620 * @param pvThis The implementation specific directory data.
621 * @param pszEntry The name of the immediate file to open or create.
622 * @param fOpenFile RTFILE_O_XXX combination.
623 * @param fObjFlags More flags: RTVFSOBJ_F_XXX, RTPATH_F_XXX.
624 * The meaning of RTPATH_F_FOLLOW_LINK differs here, if
625 * @a pszEntry is a symlink it should be opened for
626 * traversal rather than according to @a fOpenFile.
627 * @param phVfsObj Where to return the handle to the opened object.
628 * @sa RTFileOpen, RTDirOpen
630 DECLCALLBACKMEMBER(int, pfnOpen,(void *pvThis, const char *pszEntry, uint64_t fOpenFile,
631 uint32_t fObjFlags, PRTVFSOBJ phVfsObj));
634 * Optional method for symbolic link handling in the vfsstddir.cpp.
636 * This is really just a hack to make symbolic link handling work when working
637 * with directory objects that doesn't have an associated VFS. It also helps
638 * deal with drive letters in symbolic links on Windows and OS/2.
640 * @returns IPRT status code.
641 * @retval VERR_PATH_IS_RELATIVE if @a pszPath isn't absolute and should be
642 * handled using pfnOpen().
644 * @param pvThis The implementation specific directory data.
645 * @param pszRoot Path to the alleged root.
646 * @param phVfsDir Where to return the handle to the specified root
647 * directory (or may current dir on a drive letter).
649 DECLCALLBACKMEMBER(int, pfnFollowAbsoluteSymlink,(void *pvThis, const char *pszRoot, PRTVFSDIR phVfsDir));
652 * Open or create a file.
654 * @returns IPRT status code.
655 * @param pvThis The implementation specific directory data.
656 * @param pszFilename The name of the immediate file to open or create.
657 * @param fOpen The open flags (RTFILE_O_XXX).
658 * @param phVfsFile Where to return the handle to the opened file.
659 * @note Optional. RTVFSDIROPS::pfnOpenObj will be used if NULL.
660 * @sa RTFileOpen.
662 DECLCALLBACKMEMBER(int, pfnOpenFile,(void *pvThis, const char *pszFilename, uint64_t fOpen, PRTVFSFILE phVfsFile));
665 * Open an existing subdirectory.
667 * @returns IPRT status code.
668 * @retval VERR_IS_A_SYMLINK if @a pszSubDir is a symbolic link.
669 * @retval VERR_NOT_A_DIRECTORY is okay for symbolic links too.
671 * @param pvThis The implementation specific directory data.
672 * @param pszSubDir The name of the immediate subdirectory to open.
673 * @param fFlags RTDIR_F_XXX.
674 * @param phVfsDir Where to return the handle to the opened directory.
675 * Optional.
676 * @note Optional. RTVFSDIROPS::pfnOpenObj will be used if NULL.
677 * @sa RTDirOpen.
679 DECLCALLBACKMEMBER(int, pfnOpenDir,(void *pvThis, const char *pszSubDir, uint32_t fFlags, PRTVFSDIR phVfsDir));
682 * Creates a new subdirectory.
684 * @returns IPRT status code.
685 * @param pvThis The implementation specific directory data.
686 * @param pszSubDir The name of the immediate subdirectory to create.
687 * @param fMode The mode mask of the new directory.
688 * @param phVfsDir Where to optionally return the handle to the newly
689 * create directory.
690 * @note Optional. RTVFSDIROPS::pfnOpenObj will be used if NULL.
691 * @sa RTDirCreate.
693 DECLCALLBACKMEMBER(int, pfnCreateDir,(void *pvThis, const char *pszSubDir, RTFMODE fMode, PRTVFSDIR phVfsDir));
696 * Opens an existing symbolic link.
698 * @returns IPRT status code.
699 * @param pvThis The implementation specific directory data.
700 * @param pszSymlink The name of the immediate symbolic link to open.
701 * @param phVfsSymlink Where to optionally return the handle to the
702 * newly create symbolic link.
703 * @note Optional. RTVFSDIROPS::pfnOpenObj will be used if NULL.
704 * @sa RTSymlinkCreate.
706 DECLCALLBACKMEMBER(int, pfnOpenSymlink,(void *pvThis, const char *pszSymlink, PRTVFSSYMLINK phVfsSymlink));
709 * Creates a new symbolic link.
711 * @returns IPRT status code.
712 * @param pvThis The implementation specific directory data.
713 * @param pszSymlink The name of the immediate symbolic link to create.
714 * @param pszTarget The symbolic link target.
715 * @param enmType The symbolic link type.
716 * @param phVfsSymlink Where to optionally return the handle to the
717 * newly create symbolic link.
718 * @sa RTSymlinkCreate.
720 DECLCALLBACKMEMBER(int, pfnCreateSymlink,(void *pvThis, const char *pszSymlink, const char *pszTarget,
721 RTSYMLINKTYPE enmType, PRTVFSSYMLINK phVfsSymlink));
724 * Query information about an entry.
726 * @returns IPRT status code.
727 * @param pvThis The implementation specific directory data.
728 * @param pszEntry The name of the directory entry to remove.
729 * @param pObjInfo Where to return the info on success.
730 * @param enmAddAttr Which set of additional attributes to request.
731 * @note Optional. RTVFSDIROPS::pfnOpenObj and RTVFSOBJOPS::pfnQueryInfo
732 * will be used if NULL.
733 * @sa RTPathQueryInfo, RTVFSOBJOPS::pfnQueryInfo
735 DECLCALLBACKMEMBER(int, pfnQueryEntryInfo,(void *pvThis, const char *pszEntry,
736 PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr));
739 * Removes a directory entry.
741 * @returns IPRT status code.
742 * @param pvThis The implementation specific directory data.
743 * @param pszEntry The name of the directory entry to remove.
744 * @param fType If non-zero, this restricts the type of the entry to
745 * the object type indicated by the mask
746 * (RTFS_TYPE_XXX).
747 * @sa RTFileRemove, RTDirRemove, RTSymlinkRemove.
749 DECLCALLBACKMEMBER(int, pfnUnlinkEntry,(void *pvThis, const char *pszEntry, RTFMODE fType));
752 * Renames a directory entry.
754 * @returns IPRT status code.
755 * @param pvThis The implementation specific directory data.
756 * @param pszEntry The name of the directory entry to rename.
757 * @param fType If non-zero, this restricts the type of the entry to
758 * the object type indicated by the mask
759 * (RTFS_TYPE_XXX).
760 * @param pszNewName The new entry name.
761 * @sa RTPathRename
763 * @todo This API is not flexible enough, must be able to rename between
764 * directories within a file system.
766 DECLCALLBACKMEMBER(int, pfnRenameEntry,(void *pvThis, const char *pszEntry, RTFMODE fType, const char *pszNewName));
769 * Rewind the directory stream so that the next read returns the first
770 * entry.
772 * @returns IPRT status code.
773 * @param pvThis The implementation specific directory data.
775 DECLCALLBACKMEMBER(int, pfnRewindDir,(void *pvThis));
778 * Rewind the directory stream so that the next read returns the first
779 * entry.
781 * @returns IPRT status code.
782 * @param pvThis The implementation specific directory data.
783 * @param pDirEntry Output buffer.
784 * @param pcbDirEntry Complicated, see RTDirReadEx.
785 * @param enmAddAttr Which set of additional attributes to request.
786 * @sa RTDirReadEx
788 DECLCALLBACKMEMBER(int, pfnReadDir,(void *pvThis, PRTDIRENTRYEX pDirEntry, size_t *pcbDirEntry, RTFSOBJATTRADD enmAddAttr));
790 /** Marks the end of the structure (RTVFSDIROPS_VERSION). */
791 uintptr_t uEndMarker;
792 } RTVFSDIROPS;
793 /** Pointer to const directory operations. */
794 typedef RTVFSDIROPS const *PCRTVFSDIROPS;
795 /** The RTVFSDIROPS structure version. */
796 #define RTVFSDIROPS_VERSION RT_MAKE_U32_FROM_U8(0xff,0x4f,1,0)
800 * Creates a new VFS directory handle.
802 * @returns IPRT status code
803 * @param pDirOps The directory operations.
804 * @param cbInstance The size of the instance data.
805 * @param fFlags RTVFSDIR_F_XXX
806 * @param hVfs The VFS handle to associate this directory with.
807 * NIL_VFS is ok.
808 * @param hLock Handle to a custom lock to be used with the new
809 * object. The reference is consumed. NIL and
810 * special lock handles are fine.
811 * @param phVfsDir Where to return the new handle.
812 * @param ppvInstance Where to return the pointer to the instance data
813 * (size is @a cbInstance).
815 RTDECL(int) RTVfsNewDir(PCRTVFSDIROPS pDirOps, size_t cbInstance, uint32_t fFlags, RTVFS hVfs, RTVFSLOCK hLock,
816 PRTVFSDIR phVfsDir, void **ppvInstance);
818 /** @name RTVFSDIR_F_XXX
819 * @{ */
820 /** Don't reference the @a hVfs parameter passed to RTVfsNewDir.
821 * This is a permanent root directory hack. */
822 #define RTVFSDIR_F_NO_VFS_REF RT_BIT_32(0)
823 /** @} */
826 * Gets the private data of a directory.
828 * @returns Pointer to the private data. NULL if the handle is invalid in some
829 * way.
830 * @param hVfsDir The directory handle.
831 * @param pDirOps The directory operations. This servers as a
832 * sort of password.
834 RTDECL(void *) RTVfsDirToPrivate(RTVFSDIR hVfsDir, PCRTVFSDIROPS pDirOps);
838 * The symbolic link operations.
840 * @extends RTVFSOBJOPS
841 * @extends RTVFSOBJSETOPS
843 typedef struct RTVFSSYMLINKOPS
845 /** The basic object operation. */
846 RTVFSOBJOPS Obj;
847 /** The structure version (RTVFSSYMLINKOPS_VERSION). */
848 uint32_t uVersion;
849 /** Reserved field, MBZ. */
850 uint32_t fReserved;
851 /** The object setter operations. */
852 RTVFSOBJSETOPS ObjSet;
855 * Read the symbolic link target.
857 * @returns IPRT status code.
858 * @param pvThis The implementation specific symbolic link data.
859 * @param pszTarget The target buffer.
860 * @param cbTarget The size of the target buffer.
861 * @sa RTSymlinkRead
863 DECLCALLBACKMEMBER(int, pfnRead,(void *pvThis, char *pszTarget, size_t cbTarget));
865 /** Marks the end of the structure (RTVFSSYMLINKOPS_VERSION). */
866 uintptr_t uEndMarker;
867 } RTVFSSYMLINKOPS;
868 /** Pointer to const symbolic link operations. */
869 typedef RTVFSSYMLINKOPS const *PCRTVFSSYMLINKOPS;
870 /** The RTVFSSYMLINKOPS structure version. */
871 #define RTVFSSYMLINKOPS_VERSION RT_MAKE_U32_FROM_U8(0xff,0x5f,1,0)
875 * Creates a new VFS symlink handle.
877 * @returns IPRT status code
878 * @param pSymlinkOps The symlink operations.
879 * @param cbInstance The size of the instance data.
880 * @param hVfs The VFS handle to associate this symlink object
881 * with. NIL_VFS is ok.
882 * @param hLock Handle to a custom lock to be used with the new
883 * object. The reference is consumed. NIL and
884 * special lock handles are fine.
885 * @param phVfsSym Where to return the new handle.
886 * @param ppvInstance Where to return the pointer to the instance data
887 * (size is @a cbInstance).
889 RTDECL(int) RTVfsNewSymlink(PCRTVFSSYMLINKOPS pSymlinkOps, size_t cbInstance, RTVFS hVfs, RTVFSLOCK hLock,
890 PRTVFSSYMLINK phVfsSym, void **ppvInstance);
894 * Gets the private data of a symbolic link.
896 * @returns Pointer to the private data. NULL if the handle is invalid in some
897 * way.
898 * @param hVfsSym The symlink handle.
899 * @param pSymlinkOps The symlink operations. This servers as a sort
900 * of password.
902 RTDECL(void *) RTVfsSymlinkToPrivate(RTVFSSYMLINK hVfsSym, PCRTVFSSYMLINKOPS pSymlinkOps);
905 * The basis for all I/O objects (files, pipes, sockets, devices, ++).
907 * @extends RTVFSOBJOPS
909 typedef struct RTVFSIOSTREAMOPS
911 /** The basic object operation. */
912 RTVFSOBJOPS Obj;
913 /** The structure version (RTVFSIOSTREAMOPS_VERSION). */
914 uint32_t uVersion;
915 /** Feature field. */
916 uint32_t fFeatures;
919 * Reads from the file/stream.
921 * @returns IPRT status code. See RTVfsIoStrmRead.
922 * @param pvThis The implementation specific file data.
923 * @param off Where to read at, -1 for the current position.
924 * @param pSgBuf Gather buffer for the bytes that are to be read.
925 * @param fBlocking If @c true, the call is blocking, if @c false it
926 * should not block.
927 * @param pcbRead Where return the number of bytes actually read.
928 * This is set it 0 by the caller. If NULL, try read
929 * all and fail if incomplete.
930 * @sa RTVfsIoStrmRead, RTVfsIoStrmSgRead, RTVfsFileRead,
931 * RTVfsFileReadAt, RTFileRead, RTFileReadAt.
933 DECLCALLBACKMEMBER(int, pfnRead,(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead));
936 * Writes to the file/stream.
938 * @returns IPRT status code.
939 * @param pvThis The implementation specific file data.
940 * @param off Where to start wrinting, -1 for the current
941 * position.
942 * @param pSgBuf Gather buffers describing the bytes that are to be
943 * written.
944 * @param fBlocking If @c true, the call is blocking, if @c false it
945 * should not block.
946 * @param pcbWritten Where to return the number of bytes actually
947 * written. This is set it 0 by the caller. If
948 * NULL, try write it all and fail if incomplete.
949 * @note Optional, failing with VERR_WRITE_PROTECT if NULL.
950 * @sa RTFileWrite, RTFileWriteAt.
952 DECLCALLBACKMEMBER(int, pfnWrite,(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten));
955 * Flushes any pending data writes to the stream.
957 * @returns IPRT status code.
958 * @param pvThis The implementation specific file data.
959 * @sa RTFileFlush.
961 DECLCALLBACKMEMBER(int, pfnFlush,(void *pvThis));
964 * Poll for events.
966 * @returns IPRT status code.
967 * @param pvThis The implementation specific file data.
968 * @param fEvents The events to poll for (RTPOLL_EVT_XXX).
969 * @param cMillies How long to wait for event to eventuate.
970 * @param fIntr Whether the wait is interruptible and can return
971 * VERR_INTERRUPTED (@c true) or if this condition
972 * should be hidden from the caller (@c false).
973 * @param pfRetEvents Where to return the event mask.
974 * @note Optional. If NULL, immediately return all requested non-error
975 * events, waiting for errors works like sleep.
976 * @sa RTPollSetAdd, RTPoll, RTPollNoResume.
978 DECLCALLBACKMEMBER(int, pfnPollOne,(void *pvThis, uint32_t fEvents, RTMSINTERVAL cMillies, bool fIntr,
979 uint32_t *pfRetEvents));
982 * Tells the current file/stream position.
984 * @returns IPRT status code.
985 * @param pvThis The implementation specific file data.
986 * @param poffActual Where to return the actual offset.
987 * @sa RTFileTell
989 DECLCALLBACKMEMBER(int, pfnTell,(void *pvThis, PRTFOFF poffActual));
992 * Skips @a cb ahead in the stream.
994 * @returns IPRT status code.
995 * @param pvThis The implementation specific file data.
996 * @param cb The number bytes to skip.
997 * @remarks This is optional and can be NULL.
999 DECLCALLBACKMEMBER(int, pfnSkip,(void *pvThis, RTFOFF cb));
1002 * Fills the stream with @a cb zeros.
1004 * @returns IPRT status code.
1005 * @param pvThis The implementation specific file data.
1006 * @param cb The number of zero bytes to insert.
1007 * @remarks This is optional and can be NULL.
1009 DECLCALLBACKMEMBER(int, pfnZeroFill,(void *pvThis, RTFOFF cb));
1011 /** Marks the end of the structure (RTVFSIOSTREAMOPS_VERSION). */
1012 uintptr_t uEndMarker;
1013 } RTVFSIOSTREAMOPS;
1014 /** Pointer to const I/O stream operations. */
1015 typedef RTVFSIOSTREAMOPS const *PCRTVFSIOSTREAMOPS;
1017 /** The RTVFSIOSTREAMOPS structure version. */
1018 #define RTVFSIOSTREAMOPS_VERSION RT_MAKE_U32_FROM_U8(0xff,0x6f,1,0)
1020 /** @name RTVFSIOSTREAMOPS::fFeatures
1021 * @{ */
1022 /** No scatter gather lists, thank you. */
1023 #define RTVFSIOSTREAMOPS_FEAT_NO_SG RT_BIT_32(0)
1024 /** Mask of the valid I/O stream feature flags. */
1025 #define RTVFSIOSTREAMOPS_FEAT_VALID_MASK UINT32_C(0x00000001)
1026 /** @} */
1030 * Creates a new VFS I/O stream handle.
1032 * @returns IPRT status code
1033 * @param pIoStreamOps The I/O stream operations.
1034 * @param cbInstance The size of the instance data.
1035 * @param fOpen The open flags. The minimum is the access mask.
1036 * @param hVfs The VFS handle to associate this I/O stream
1037 * with. NIL_VFS is ok.
1038 * @param hLock Handle to a custom lock to be used with the new
1039 * object. The reference is consumed. NIL and
1040 * special lock handles are fine.
1041 * @param phVfsIos Where to return the new handle.
1042 * @param ppvInstance Where to return the pointer to the instance data
1043 * (size is @a cbInstance).
1045 RTDECL(int) RTVfsNewIoStream(PCRTVFSIOSTREAMOPS pIoStreamOps, size_t cbInstance, uint32_t fOpen, RTVFS hVfs, RTVFSLOCK hLock,
1046 PRTVFSIOSTREAM phVfsIos, void **ppvInstance);
1050 * Gets the private data of an I/O stream.
1052 * @returns Pointer to the private data. NULL if the handle is invalid in some
1053 * way.
1054 * @param hVfsIos The I/O stream handle.
1055 * @param pIoStreamOps The I/O stream operations. This servers as a
1056 * sort of password.
1058 RTDECL(void *) RTVfsIoStreamToPrivate(RTVFSIOSTREAM hVfsIos, PCRTVFSIOSTREAMOPS pIoStreamOps);
1062 * The file operations.
1064 * @extends RTVFSIOSTREAMOPS
1065 * @extends RTVFSOBJSETOPS
1067 typedef struct RTVFSFILEOPS
1069 /** The I/O stream and basis object operations. */
1070 RTVFSIOSTREAMOPS Stream;
1071 /** The structure version (RTVFSFILEOPS_VERSION). */
1072 uint32_t uVersion;
1073 /** Reserved field, MBZ. */
1074 uint32_t fReserved;
1075 /** The object setter operations. */
1076 RTVFSOBJSETOPS ObjSet;
1079 * Changes the current file position.
1081 * @returns IPRT status code.
1082 * @param pvThis The implementation specific file data.
1083 * @param offSeek The offset to seek.
1084 * @param uMethod The seek method, i.e. what the seek is relative to.
1085 * @param poffActual Where to return the actual offset.
1086 * @sa RTFileSeek
1088 DECLCALLBACKMEMBER(int, pfnSeek,(void *pvThis, RTFOFF offSeek, unsigned uMethod, PRTFOFF poffActual));
1091 * Get the current file size.
1093 * @returns IPRT status code.
1094 * @param pvThis The implementation specific file data.
1095 * @param pcbFile Where to store the current file size.
1096 * @sa RTFileQuerySize
1098 DECLCALLBACKMEMBER(int, pfnQuerySize,(void *pvThis, uint64_t *pcbFile));
1101 * Change the file size.
1103 * @returns IPRT status code.
1104 * @retval VERR_ACCESS_DENIED if handle isn't writable.
1105 * @retval VERR_WRITE_PROTECT if read-only file system.
1106 * @retval VERR_FILE_TOO_BIG if cbSize is larger than what the file system can
1107 * theoretically deal with.
1108 * @retval VERR_DISK_FULL if the file system if full.
1109 * @retval VERR_NOT_SUPPORTED if fFlags indicates some operation that's not
1110 * supported by the file system / host operating system.
1112 * @param pvThis The implementation specific file data.
1113 * @param pcbFile Where to store the current file size.
1114 * @param fFlags RTVFSFILE_SET_SIZE_F_XXX.
1115 * @note Optional. If NULL, VERR_WRITE_PROTECT will be returned.
1116 * @sa RTFileSetSize, RTFileSetAllocationSize
1118 DECLCALLBACKMEMBER(int, pfnSetSize,(void *pvThis, uint64_t cbFile, uint32_t fFlags));
1121 * Determine the maximum file size.
1123 * This won't take amount of freespace into account, just the limitations of the
1124 * underlying file system / host operating system.
1126 * @returns IPRT status code.
1127 * @param pvThis The implementation specific file data.
1128 * @param pcbMax Where to return the max file size.
1129 * @note Optional. If NULL, VERR_NOT_IMPLEMENTED will be returned.
1130 * @sa RTFileQueryMaxSizeEx
1132 DECLCALLBACKMEMBER(int, pfnQueryMaxSize,(void *pvThis, uint64_t *pcbMax));
1134 /** @todo There will be more methods here. */
1136 /** Marks the end of the structure (RTVFSFILEOPS_VERSION). */
1137 uintptr_t uEndMarker;
1138 } RTVFSFILEOPS;
1139 /** Pointer to const file operations. */
1140 typedef RTVFSFILEOPS const *PCRTVFSFILEOPS;
1142 /** The RTVFSFILEOPS structure version. */
1143 #define RTVFSFILEOPS_VERSION RT_MAKE_U32_FROM_U8(0xff,0x7f,2,0)
1146 * Creates a new VFS file handle.
1148 * @returns IPRT status code
1149 * @param pFileOps The file operations.
1150 * @param cbInstance The size of the instance data.
1151 * @param fOpen The open flags. The minimum is the access mask.
1152 * @param hVfs The VFS handle to associate this file with.
1153 * NIL_VFS is ok.
1154 * @param hLock Handle to a custom lock to be used with the new
1155 * object. The reference is consumed. NIL and
1156 * special lock handles are fine.
1157 * @param phVfsFile Where to return the new handle.
1158 * @param ppvInstance Where to return the pointer to the instance data
1159 * (size is @a cbInstance).
1161 RTDECL(int) RTVfsNewFile(PCRTVFSFILEOPS pFileOps, size_t cbInstance, uint32_t fOpen, RTVFS hVfs, RTVFSLOCK hLock,
1162 PRTVFSFILE phVfsFile, void **ppvInstance);
1165 /** @defgroup grp_rt_vfs_ll_util VFS Utility APIs
1166 * @{ */
1169 * Parsed path.
1171 typedef struct RTVFSPARSEDPATH
1173 /** The length of the path in szCopy. */
1174 uint16_t cch;
1175 /** The number of path components. */
1176 uint16_t cComponents;
1177 /** Set if the path ends with slash, indicating that it's a directory
1178 * reference and not a file reference. The slash has been removed from
1179 * the copy. */
1180 bool fDirSlash;
1181 /** Set if absolute. */
1182 bool fAbsolute;
1183 /** The offset where each path component starts, i.e. the char after the
1184 * slash. The array has cComponents + 1 entries, where the final one is
1185 * cch + 1 so that one can always terminate the current component by
1186 * szPath[aoffComponent[i] - 1] = '\0'. */
1187 uint16_t aoffComponents[RTPATH_MAX / 2 + 1];
1188 /** A normalized copy of the path.
1189 * Reserve some extra space so we can be more relaxed about overflow
1190 * checks and terminator paddings, especially when recursing. */
1191 char szPath[RTPATH_MAX];
1192 } RTVFSPARSEDPATH;
1193 /** Pointer to a parsed path. */
1194 typedef RTVFSPARSEDPATH *PRTVFSPARSEDPATH;
1196 /** The max accepted path length.
1197 * This must be a few chars shorter than RTVFSPARSEDPATH::szPath because we
1198 * use two terminators and wish be a little bit lazy with checking. */
1199 #define RTVFSPARSEDPATH_MAX (RTPATH_MAX - 4)
1202 * Appends @a pszPath (relative) to the already parsed path @a pPath.
1204 * @retval VINF_SUCCESS
1205 * @retval VERR_FILENAME_TOO_LONG
1206 * @retval VERR_INTERNAL_ERROR_4
1207 * @param pPath The parsed path to append @a pszPath onto.
1208 * This is both input and output.
1209 * @param pszPath The path to append. This must be relative.
1210 * @param piRestartComp The component to restart parsing at. This is
1211 * input/output. The input does not have to be
1212 * within the valid range. Optional.
1214 RTDECL(int) RTVfsParsePathAppend(PRTVFSPARSEDPATH pPath, const char *pszPath, uint16_t *piRestartComp);
1217 * Parses a path.
1219 * @retval VINF_SUCCESS
1220 * @retval VERR_FILENAME_TOO_LONG
1221 * @param pPath Where to store the parsed path.
1222 * @param pszPath The path to parse. Absolute or relative to @a
1223 * pszCwd.
1224 * @param pszCwd The current working directory. Must be
1225 * absolute.
1227 RTDECL(int) RTVfsParsePath(PRTVFSPARSEDPATH pPath, const char *pszPath, const char *pszCwd);
1230 * Same as RTVfsParsePath except that it allocates a temporary buffer.
1232 * @retval VINF_SUCCESS
1233 * @retval VERR_NO_TMP_MEMORY
1234 * @retval VERR_FILENAME_TOO_LONG
1235 * @param pszPath The path to parse. Absolute or relative to @a
1236 * pszCwd.
1237 * @param pszCwd The current working directory. Must be
1238 * absolute.
1239 * @param ppPath Where to store the pointer to the allocated
1240 * buffer containing the parsed path. This must
1241 * be freed by calling RTVfsParsePathFree. NULL
1242 * will be stored on failured.
1244 RTDECL(int) RTVfsParsePathA(const char *pszPath, const char *pszCwd, PRTVFSPARSEDPATH *ppPath);
1247 * Frees a buffer returned by RTVfsParsePathA.
1249 * @param pPath The parsed path buffer to free. NULL is fine.
1251 RTDECL(void) RTVfsParsePathFree(PRTVFSPARSEDPATH pPath);
1254 * Dummy implementation of RTVFSIOSTREAMOPS::pfnPollOne.
1256 * This handles the case where there is no chance any events my be raised and
1257 * all that is required is to wait according to the parameters.
1259 * @returns IPRT status code.
1260 * @param fEvents The events to poll for (RTPOLL_EVT_XXX).
1261 * @param cMillies How long to wait for event to eventuate.
1262 * @param fIntr Whether the wait is interruptible and can return
1263 * VERR_INTERRUPTED (@c true) or if this condition
1264 * should be hidden from the caller (@c false).
1265 * @param pfRetEvents Where to return the event mask.
1266 * @sa RTVFSIOSTREAMOPS::pfnPollOne, RTPollSetAdd, RTPoll, RTPollNoResume.
1268 RTDECL(int) RTVfsUtilDummyPollOne(uint32_t fEvents, RTMSINTERVAL cMillies, bool fIntr, uint32_t *pfRetEvents);
1270 /** @} */
1273 /** @defgroup grp_rt_vfs_lowlevel_chain VFS Chains (Low Level)
1274 * @ref grp_rt_vfs_chain
1275 * @{
1278 /** Pointer to a VFS chain element registration record. */
1279 typedef struct RTVFSCHAINELEMENTREG *PRTVFSCHAINELEMENTREG;
1280 /** Pointer to a const VFS chain element registration record. */
1281 typedef struct RTVFSCHAINELEMENTREG const *PCRTVFSCHAINELEMENTREG;
1284 * VFS chain element argument.
1286 typedef struct RTVFSCHAINELEMENTARG
1288 /** The string argument value. */
1289 char *psz;
1290 /** The specification offset of this argument. */
1291 uint16_t offSpec;
1292 /** Provider specific value. */
1293 uint64_t uProvider;
1294 } RTVFSCHAINELEMENTARG;
1295 /** Pointer to a VFS chain element argument. */
1296 typedef RTVFSCHAINELEMENTARG *PRTVFSCHAINELEMENTARG;
1300 * VFS chain element specification.
1302 typedef struct RTVFSCHAINELEMSPEC
1304 /** The provider name.
1305 * This can be NULL if this is the final component and it's just a path. */
1306 char *pszProvider;
1307 /** The input type, RTVFSOBJTYPE_INVALID if first. */
1308 RTVFSOBJTYPE enmTypeIn;
1309 /** The element type.
1310 * RTVFSOBJTYPE_END if this is the final component and it's just a path. */
1311 RTVFSOBJTYPE enmType;
1312 /** The input spec offset of this element. */
1313 uint16_t offSpec;
1314 /** The length of the input spec. */
1315 uint16_t cchSpec;
1316 /** The number of arguments. */
1317 uint32_t cArgs;
1318 /** Arguments. */
1319 PRTVFSCHAINELEMENTARG paArgs;
1321 /** The provider. */
1322 PCRTVFSCHAINELEMENTREG pProvider;
1323 /** Provider specific value. */
1324 uint64_t uProvider;
1325 /** The object (with reference). */
1326 RTVFSOBJ hVfsObj;
1327 } RTVFSCHAINELEMSPEC;
1328 /** Pointer to a chain element specification. */
1329 typedef RTVFSCHAINELEMSPEC *PRTVFSCHAINELEMSPEC;
1330 /** Pointer to a const chain element specification. */
1331 typedef RTVFSCHAINELEMSPEC const *PCRTVFSCHAINELEMSPEC;
1335 * Parsed VFS chain specification.
1337 typedef struct RTVFSCHAINSPEC
1339 /** Open directory flags (RTFILE_O_XXX). */
1340 uint64_t fOpenFile;
1341 /** To be defined. */
1342 uint32_t fOpenDir;
1343 /** The type desired by the caller. */
1344 RTVFSOBJTYPE enmDesiredType;
1345 /** The number of elements. */
1346 uint32_t cElements;
1347 /** The elements. */
1348 PRTVFSCHAINELEMSPEC paElements;
1349 } RTVFSCHAINSPEC;
1350 /** Pointer to a parsed VFS chain specification. */
1351 typedef RTVFSCHAINSPEC *PRTVFSCHAINSPEC;
1352 /** Pointer to a const, parsed VFS chain specification. */
1353 typedef RTVFSCHAINSPEC const *PCRTVFSCHAINSPEC;
1357 * A chain element provider registration record.
1359 typedef struct RTVFSCHAINELEMENTREG
1361 /** The version (RTVFSCHAINELEMENTREG_VERSION). */
1362 uint32_t uVersion;
1363 /** Reserved, MBZ. */
1364 uint32_t fReserved;
1365 /** The provider name (unique). */
1366 const char *pszName;
1367 /** For chaining the providers. */
1368 RTLISTNODE ListEntry;
1369 /** Help text. */
1370 const char *pszHelp;
1373 * Checks the element specification.
1375 * This is allowed to parse arguments and use pSpec->uProvider and
1376 * pElement->paArgs[].uProvider to store information that pfnInstantiate and
1377 * pfnCanReuseElement may use later on, thus avoiding duplicating work/code.
1379 * @returns IPRT status code.
1380 * @param pProviderReg Pointer to the element provider registration.
1381 * @param pSpec The chain specification.
1382 * @param pElement The chain element specification to validate.
1383 * @param poffError Where to return error offset on failure. This is
1384 * set to the pElement->offSpec on input, so it only
1385 * needs to be adjusted if an argument is at fault.
1386 * @param pErrInfo Where to return additional error information, if
1387 * available. Optional.
1389 DECLCALLBACKMEMBER(int, pfnValidate,(PCRTVFSCHAINELEMENTREG pProviderReg, PRTVFSCHAINSPEC pSpec,
1390 PRTVFSCHAINELEMSPEC pElement, uint32_t *poffError, PRTERRINFO pErrInfo));
1393 * Create a VFS object according to the element specification.
1395 * @returns IPRT status code.
1396 * @param pProviderReg Pointer to the element provider registration.
1397 * @param pSpec The chain specification.
1398 * @param pElement The chain element specification to instantiate.
1399 * @param hPrevVfsObj Handle to the previous VFS object, NIL_RTVFSOBJ if
1400 * first.
1401 * @param phVfsObj Where to return the VFS object handle.
1402 * @param poffError Where to return error offset on failure. This is
1403 * set to the pElement->offSpec on input, so it only
1404 * needs to be adjusted if an argument is at fault.
1405 * @param pErrInfo Where to return additional error information, if
1406 * available. Optional.
1408 DECLCALLBACKMEMBER(int, pfnInstantiate,(PCRTVFSCHAINELEMENTREG pProviderReg, PCRTVFSCHAINSPEC pSpec,
1409 PCRTVFSCHAINELEMSPEC pElement, RTVFSOBJ hPrevVfsObj,
1410 PRTVFSOBJ phVfsObj, uint32_t *poffError, PRTERRINFO pErrInfo));
1413 * Determins whether the element can be reused.
1415 * This is for handling situations accessing the same file system twice, like
1416 * for both the source and destiation of a copy operation. This allows not only
1417 * sharing resources and avoid doing things twice, but also helps avoid file
1418 * sharing violations and inconsistencies araising from the image being updated
1419 * and read independently.
1421 * @returns true if the element from @a pReuseSpec an be reused, false if not.
1422 * @param pProviderReg Pointer to the element provider registration.
1423 * @param pSpec The chain specification.
1424 * @param pElement The chain element specification.
1425 * @param pReuseSpec The chain specification of the existing chain.
1426 * @param pReuseElement The chain element specification of the existing
1427 * element that is being considered for reuse.
1429 DECLCALLBACKMEMBER(bool, pfnCanReuseElement,(PCRTVFSCHAINELEMENTREG pProviderReg,
1430 PCRTVFSCHAINSPEC pSpec, PCRTVFSCHAINELEMSPEC pElement,
1431 PCRTVFSCHAINSPEC pReuseSpec, PCRTVFSCHAINELEMSPEC pReuseElement));
1433 /** End marker (RTVFSCHAINELEMENTREG_VERSION). */
1434 uintptr_t uEndMarker;
1435 } RTVFSCHAINELEMENTREG;
1437 /** The VFS chain element registration record version number. */
1438 #define RTVFSCHAINELEMENTREG_VERSION RT_MAKE_U32_FROM_U8(0xff, 0x7f, 1, 0)
1442 * Parses the specification.
1444 * @returns IPRT status code.
1445 * @param pszSpec The specification string to parse.
1446 * @param fFlags Flags, see RTVFSCHAIN_PF_XXX.
1447 * @param enmDesiredType The object type the caller wants to interface with.
1448 * @param ppSpec Where to return the pointer to the parsed
1449 * specification. This must be freed by calling
1450 * RTVfsChainSpecFree. Will always be set (unless
1451 * invalid parameters.)
1452 * @param poffError Where to return the offset into the input
1453 * specification of what's causing trouble. Always
1454 * set, unless this argument causes an invalid pointer
1455 * error.
1457 RTDECL(int) RTVfsChainSpecParse(const char *pszSpec, uint32_t fFlags, RTVFSOBJTYPE enmDesiredType,
1458 PRTVFSCHAINSPEC *ppSpec, uint32_t *poffError);
1460 /** @name RTVfsChainSpecParse
1461 * @{ */
1462 /** Mask of valid flags. */
1463 #define RTVFSCHAIN_PF_VALID_MASK UINT32_C(0x00000000)
1464 /** @} */
1467 * Checks and setups the chain.
1469 * @returns IPRT status code.
1470 * @param pSpec The parsed specification.
1471 * @param pReuseSpec Spec to reuse if applicable. Optional.
1472 * @param phVfsObj Where to return the VFS object.
1473 * @param ppszFinalPath Where to return the pointer to the final path if
1474 * applicable. The caller needs to check whether this
1475 * is NULL or a path, in the former case nothing more
1476 * needs doing, whereas in the latter the caller must
1477 * perform the desired operation(s) on *phVfsObj using
1478 * the final path.
1479 * @param poffError Where to return the offset into the input
1480 * specification of what's causing trouble. Always
1481 * set, unless this argument causes an invalid pointer
1482 * error.
1483 * @param pErrInfo Where to return additional error information, if
1484 * available. Optional.
1486 RTDECL(int) RTVfsChainSpecCheckAndSetup(PRTVFSCHAINSPEC pSpec, PCRTVFSCHAINSPEC pReuseSpec,
1487 PRTVFSOBJ phVfsObj, const char **ppszFinalPath, uint32_t *poffError, PRTERRINFO pErrInfo);
1490 * Frees a parsed chain specification.
1492 * @param pSpec What RTVfsChainSpecParse returned. NULL is
1493 * quietly ignored.
1495 RTDECL(void) RTVfsChainSpecFree(PRTVFSCHAINSPEC pSpec);
1498 * Registers a chain element provider.
1500 * @returns IPRT status code
1501 * @param pRegRec The registration record.
1502 * @param fFromCtor Indicates where we're called from.
1504 RTDECL(int) RTVfsChainElementRegisterProvider(PRTVFSCHAINELEMENTREG pRegRec, bool fFromCtor);
1507 * Deregisters a chain element provider.
1509 * @returns IPRT status code
1510 * @param pRegRec The registration record.
1511 * @param fFromDtor Indicates where we're called from.
1513 RTDECL(int) RTVfsChainElementDeregisterProvider(PRTVFSCHAINELEMENTREG pRegRec, bool fFromDtor);
1516 /** @def RTVFSCHAIN_AUTO_REGISTER_ELEMENT_PROVIDER
1517 * Automatically registers a chain element provider using a global constructor
1518 * and destructor hack.
1520 * @param pRegRec Pointer to the registration record.
1521 * @param name Some unique variable name prefix.
1524 #ifdef __cplusplus
1526 * Class used for registering a VFS chain element provider.
1528 class RTVfsChainElementAutoRegisterHack
1530 private:
1531 /** The registration record, NULL if registration failed. */
1532 PRTVFSCHAINELEMENTREG m_pRegRec;
1534 public:
1535 RTVfsChainElementAutoRegisterHack(PRTVFSCHAINELEMENTREG a_pRegRec)
1536 : m_pRegRec(a_pRegRec)
1538 int rc = RTVfsChainElementRegisterProvider(m_pRegRec, true);
1539 if (RT_FAILURE(rc))
1540 m_pRegRec = NULL;
1543 ~RTVfsChainElementAutoRegisterHack()
1545 RTVfsChainElementDeregisterProvider(m_pRegRec, true);
1546 m_pRegRec = NULL;
1550 # define RTVFSCHAIN_AUTO_REGISTER_ELEMENT_PROVIDER(pRegRec, name) \
1551 static RTVfsChainElementAutoRegisterHack name ## AutoRegistrationHack(pRegRec)
1553 #else
1554 # define RTVFSCHAIN_AUTO_REGISTER_ELEMENT_PROVIDER(pRegRec, name) \
1555 extern void *name ## AutoRegistrationHack = \
1556 &Sorry_but_RTVFSCHAIN_AUTO_REGISTER_ELEMENT_PROVIDER_does_not_work_in_c_source_files
1557 #endif
1561 * Common worker for the 'stdfile' and 'open' providers for implementing
1562 * RTVFSCHAINELEMENTREG::pfnValidate.
1564 * Stores the RTFILE_O_XXX flags in pSpec->uProvider.
1566 * @returns IPRT status code.
1567 * @param pSpec The chain specification.
1568 * @param pElement The chain element specification to validate.
1569 * @param poffError Where to return error offset on failure. This is set to
1570 * the pElement->offSpec on input, so it only needs to be
1571 * adjusted if an argument is at fault.
1572 * @param pErrInfo Where to return additional error information, if
1573 * available. Optional.
1575 RTDECL(int) RTVfsChainValidateOpenFileOrIoStream(PRTVFSCHAINSPEC pSpec, PRTVFSCHAINELEMSPEC pElement,
1576 uint32_t *poffError, PRTERRINFO pErrInfo);
1579 /** @} */
1582 /** @} */
1584 RT_C_DECLS_END
1586 #endif /* !IPRT_INCLUDED_vfslowlevel_h */