VirtualBox

source: vbox/trunk/include/iprt/vfslowlevel.h@ 69826

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

IPRT/VFS: More path parsing work. Symlinks should work better now.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 56.6 KB
Line 
1/** @file
2 * IPRT - Virtual Filesystem.
3 */
4
5/*
6 * Copyright (C) 2010-2017 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef ___iprt_vfslowlevel_h
27#define ___iprt_vfslowlevel_h
28
29#include <iprt/vfs.h>
30#include <iprt/err.h>
31#include <iprt/list.h>
32#include <iprt/param.h>
33
34
35RT_C_DECLS_BEGIN
36
37/** @defgroup grp_rt_vfs_lowlevel RTVfs - Low-level Interface.
38 * @ingroup grp_rt_vfs
39 * @{
40 */
41
42
43/** @name VFS Lock Abstraction
44 * @todo This should be moved somewhere else as it is of general use.
45 * @{ */
46
47/**
48 * VFS lock types.
49 */
50typedef enum RTVFSLOCKTYPE
51{
52 /** Invalid lock type. */
53 RTVFSLOCKTYPE_INVALID = 0,
54 /** Read write semaphore. */
55 RTVFSLOCKTYPE_RW,
56 /** Fast mutex semaphore (critical section in ring-3). */
57 RTVFSLOCKTYPE_FASTMUTEX,
58 /** Full fledged mutex semaphore. */
59 RTVFSLOCKTYPE_MUTEX,
60 /** The end of valid lock types. */
61 RTVFSLOCKTYPE_END,
62 /** The customary 32-bit type hack. */
63 RTVFSLOCKTYPE_32BIT_HACK = 0x7fffffff
64} RTVFSLOCKTYPE;
65
66/** VFS lock handle. */
67typedef struct RTVFSLOCKINTERNAL *RTVFSLOCK;
68/** Pointer to a VFS lock handle. */
69typedef RTVFSLOCK *PRTVFSLOCK;
70/** Nil VFS lock handle. */
71#define NIL_RTVFSLOCK ((RTVFSLOCK)~(uintptr_t)0)
72
73/** Special handle value for creating a new read/write semaphore based lock. */
74#define RTVFSLOCK_CREATE_RW ((RTVFSLOCK)~(uintptr_t)1)
75/** Special handle value for creating a new fast mutex semaphore based lock. */
76#define RTVFSLOCK_CREATE_FASTMUTEX ((RTVFSLOCK)~(uintptr_t)2)
77/** Special handle value for creating a new mutex semaphore based lock. */
78#define RTVFSLOCK_CREATE_MUTEX ((RTVFSLOCK)~(uintptr_t)3)
79
80/**
81 * Retains a reference to the VFS lock handle.
82 *
83 * @returns New reference count on success, UINT32_MAX on failure.
84 * @param hLock The VFS lock handle.
85 */
86RTDECL(uint32_t) RTVfsLockRetain(RTVFSLOCK hLock);
87
88/**
89 * Releases a reference to the VFS lock handle.
90 *
91 * @returns New reference count on success (0 if closed), UINT32_MAX on failure.
92 * @param hLock The VFS lock handle.
93 */
94RTDECL(uint32_t) RTVfsLockRelease(RTVFSLOCK hLock);
95
96/**
97 * Gets the lock type.
98 *
99 * @returns The lock type on success, RTVFSLOCKTYPE_INVALID if the handle is
100 * not valid.
101 * @param hLock The lock handle.
102 */
103RTDECL(RTVFSLOCKTYPE) RTVfsLockGetType(RTVFSLOCK hLock);
104
105
106
107RTDECL(void) RTVfsLockAcquireReadSlow(RTVFSLOCK hLock);
108RTDECL(void) RTVfsLockReleaseReadSlow(RTVFSLOCK hLock);
109RTDECL(void) RTVfsLockAcquireWriteSlow(RTVFSLOCK hLock);
110RTDECL(void) RTVfsLockReleaseWriteSlow(RTVFSLOCK hLock);
111
112/**
113 * Acquire a read lock.
114 *
115 * @param hLock The lock handle, can be NIL.
116 */
117DECLINLINE(void) RTVfsLockAcquireRead(RTVFSLOCK hLock)
118{
119 if (hLock != NIL_RTVFSLOCK)
120 RTVfsLockAcquireReadSlow(hLock);
121}
122
123
124/**
125 * Release a read lock.
126 *
127 * @param hLock The lock handle, can be NIL.
128 */
129DECLINLINE(void) RTVfsLockReleaseRead(RTVFSLOCK hLock)
130{
131 if (hLock != NIL_RTVFSLOCK)
132 RTVfsLockReleaseReadSlow(hLock);
133}
134
135
136/**
137 * Acquire a write lock.
138 *
139 * @param hLock The lock handle, can be NIL.
140 */
141DECLINLINE(void) RTVfsLockAcquireWrite(RTVFSLOCK hLock)
142{
143 if (hLock != NIL_RTVFSLOCK)
144 RTVfsLockAcquireWriteSlow(hLock);
145}
146
147
148/**
149 * Release a write lock.
150 *
151 * @param hLock The lock handle, can be NIL.
152 */
153DECLINLINE(void) RTVfsLockReleaseWrite(RTVFSLOCK hLock)
154{
155 if (hLock != NIL_RTVFSLOCK)
156 RTVfsLockReleaseWriteSlow(hLock);
157}
158
159/** @} */
160
161/**
162 * The basis for all virtual file system objects.
163 */
164typedef struct RTVFSOBJOPS
165{
166 /** The structure version (RTVFSOBJOPS_VERSION). */
167 uint32_t uVersion;
168 /** The object type for type introspection. */
169 RTVFSOBJTYPE enmType;
170 /** The name of the operations. */
171 const char *pszName;
172
173 /**
174 * Close the object.
175 *
176 * @returns IPRT status code.
177 * @param pvThis The implementation specific file data.
178 */
179 DECLCALLBACKMEMBER(int, pfnClose)(void *pvThis);
180
181 /**
182 * Get information about the file.
183 *
184 * @returns IPRT status code. See RTVfsObjQueryInfo.
185 * @retval VERR_WRONG_TYPE if file system or file system stream.
186 * @param pvThis The implementation specific file data.
187 * @param pObjInfo Where to return the object info on success.
188 * @param enmAddAttr Which set of additional attributes to request.
189 * @sa RTVfsObjQueryInfo, RTFileQueryInfo, RTPathQueryInfo
190 */
191 DECLCALLBACKMEMBER(int, pfnQueryInfo)(void *pvThis, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr);
192
193 /** Marks the end of the structure (RTVFSOBJOPS_VERSION). */
194 uintptr_t uEndMarker;
195} RTVFSOBJOPS;
196/** Pointer to constant VFS object operations. */
197typedef RTVFSOBJOPS const *PCRTVFSOBJOPS;
198
199/** The RTVFSOBJOPS structure version. */
200#define RTVFSOBJOPS_VERSION RT_MAKE_U32_FROM_U8(0xff,0x1f,1,0)
201
202
203/**
204 * The VFS operations.
205 */
206typedef struct RTVFSOPS
207{
208 /** The basic object operation. */
209 RTVFSOBJOPS Obj;
210 /** The structure version (RTVFSOPS_VERSION). */
211 uint32_t uVersion;
212 /** The virtual file system feature mask. */
213 uint32_t fFeatures;
214
215 /**
216 * Opens the root directory.
217 *
218 * @returns IPRT status code.
219 * @param pvThis The implementation specific data.
220 * @param phVfsDir Where to return the handle to the root directory.
221 */
222 DECLCALLBACKMEMBER(int, pfnOpenRoot)(void *pvThis, PRTVFSDIR phVfsDir);
223
224 /**
225 * Optional entry point to check whether a given range in the underlying medium
226 * is in use by the virtual filesystem.
227 *
228 * @returns IPRT status code.
229 * @param pvThis The implementation specific data.
230 * @param off Start offset to check.
231 * @param cb Number of bytes to check.
232 * @param pfUsed Where to store whether the given range is in use.
233 */
234 DECLCALLBACKMEMBER(int, pfnIsRangeInUse)(void *pvThis, RTFOFF off, size_t cb, bool *pfUsed);
235
236 /** @todo There will be more methods here to optimize opening and
237 * querying. */
238
239#if 0
240 /**
241 * Optional entry point for optimizing path traversal within the file system.
242 *
243 * @returns IPRT status code.
244 * @param pvThis The implementation specific data.
245 * @param pszPath The path to resolve.
246 * @param poffPath The current path offset on input, what we've
247 * traversed to on successful return.
248 * @param phVfs??? Return handle to what we've traversed.
249 * @param p??? Return other stuff...
250 */
251 DECLCALLBACKMEMBER(int, pfnTraverse)(void *pvThis, const char *pszPath, size_t *poffPath, PRTVFS??? phVfs?, ???* p???);
252#endif
253
254 /** @todo need rename API */
255
256 /** Marks the end of the structure (RTVFSOPS_VERSION). */
257 uintptr_t uEndMarker;
258} RTVFSOPS;
259/** Pointer to constant VFS operations. */
260typedef RTVFSOPS const *PCRTVFSOPS;
261
262/** The RTVFSOPS structure version. */
263#define RTVFSOPS_VERSION RT_MAKE_U32_FROM_U8(0xff,0x0f,1,0)
264
265/** @name RTVFSOPS::fFeatures
266 * @{ */
267/** The VFS supports attaching other systems. */
268#define RTVFSOPS_FEAT_ATTACH RT_BIT_32(0)
269/** @} */
270
271/**
272 * Creates a new VFS handle.
273 *
274 * @returns IPRT status code
275 * @param pVfsOps The VFS operations.
276 * @param cbInstance The size of the instance data.
277 * @param hVfs The VFS handle to associate this VFS with.
278 * NIL_VFS is ok.
279 * @param hLock Handle to a custom lock to be used with the new
280 * object. The reference is consumed. NIL and
281 * special lock handles are fine.
282 * @param phVfs Where to return the new handle.
283 * @param ppvInstance Where to return the pointer to the instance data
284 * (size is @a cbInstance).
285 */
286RTDECL(int) RTVfsNew(PCRTVFSOPS pVfsOps, size_t cbInstance, RTVFS hVfs, RTVFSLOCK hLock,
287 PRTVFS phVfs, void **ppvInstance);
288
289
290/**
291 * Creates a new VFS base object handle.
292 *
293 * @returns IPRT status code
294 * @param pObjOps The base object operations.
295 * @param cbInstance The size of the instance data.
296 * @param hVfs The VFS handle to associate this base object
297 * with. NIL_VFS is ok.
298 * @param hLock Handle to a custom lock to be used with the new
299 * object. The reference is consumed. NIL and
300 * special lock handles are fine.
301 * @param phVfsObj Where to return the new handle.
302 * @param ppvInstance Where to return the pointer to the instance data
303 * (size is @a cbInstance).
304 */
305RTDECL(int) RTVfsNewBaseObj(PCRTVFSOBJOPS pObjOps, size_t cbInstance, RTVFS hVfs, RTVFSLOCK hLock,
306 PRTVFSOBJ phVfsObj, void **ppvInstance);
307
308
309/**
310 * Additional operations for setting object attributes.
311 */
312typedef struct RTVFSOBJSETOPS
313{
314 /** The structure version (RTVFSOBJSETOPS_VERSION). */
315 uint32_t uVersion;
316 /** The offset to the RTVFSOBJOPS structure. */
317 int32_t offObjOps;
318
319 /**
320 * Set the unix style owner and group.
321 *
322 * @returns IPRT status code.
323 * @param pvThis The implementation specific file data.
324 * @param fMode The new mode bits.
325 * @param fMask The mask indicating which bits we are
326 * changing.
327 * @sa RTFileSetMode
328 */
329 DECLCALLBACKMEMBER(int, pfnSetMode)(void *pvThis, RTFMODE fMode, RTFMODE fMask);
330
331 /**
332 * Set the timestamps associated with the object.
333 *
334 * @returns IPRT status code.
335 * @param pvThis The implementation specific file data.
336 * @param pAccessTime Pointer to the new access time. NULL if not
337 * to be changed.
338 * @param pModificationTime Pointer to the new modifcation time. NULL if
339 * not to be changed.
340 * @param pChangeTime Pointer to the new change time. NULL if not
341 * to be changed.
342 * @param pBirthTime Pointer to the new time of birth. NULL if
343 * not to be changed.
344 * @remarks See RTFileSetTimes for restrictions and behavior imposed by the
345 * host OS or underlying VFS provider.
346 * @sa RTFileSetTimes
347 */
348 DECLCALLBACKMEMBER(int, pfnSetTimes)(void *pvThis, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
349 PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime);
350
351 /**
352 * Set the unix style owner and group.
353 *
354 * @returns IPRT status code.
355 * @param pvThis The implementation specific file data.
356 * @param uid The user ID of the new owner. NIL_RTUID if
357 * unchanged.
358 * @param gid The group ID of the new owner group. NIL_RTGID if
359 * unchanged.
360 * @sa RTFileSetOwner
361 */
362 DECLCALLBACKMEMBER(int, pfnSetOwner)(void *pvThis, RTUID uid, RTGID gid);
363
364 /** Marks the end of the structure (RTVFSOBJSETOPS_VERSION). */
365 uintptr_t uEndMarker;
366} RTVFSOBJSETOPS;
367/** Pointer to const object attribute setter operations. */
368typedef RTVFSOBJSETOPS const *PCRTVFSOBJSETOPS;
369
370/** The RTVFSOBJSETOPS structure version. */
371#define RTVFSOBJSETOPS_VERSION RT_MAKE_U32_FROM_U8(0xff,0x2f,1,0)
372
373
374/**
375 * The filesystem stream operations.
376 *
377 * @extends RTVFSOBJOPS
378 */
379typedef struct RTVFSFSSTREAMOPS
380{
381 /** The basic object operation. */
382 RTVFSOBJOPS Obj;
383 /** The structure version (RTVFSFSSTREAMOPS_VERSION). */
384 uint32_t uVersion;
385 /** Reserved field, MBZ. */
386 uint32_t fReserved;
387
388 /**
389 * Gets the next object in the stream.
390 *
391 * Readable streams only.
392 *
393 * @returns IPRT status code.
394 * @retval VINF_SUCCESS if a new object was retrieved.
395 * @retval VERR_EOF when there are no more objects.
396 * @param pvThis The implementation specific directory data.
397 * @param ppszName Where to return the object name. Must be freed by
398 * calling RTStrFree.
399 * @param penmType Where to return the object type.
400 * @param phVfsObj Where to return the object handle (referenced). This
401 * must be cast to the desired type before use.
402 * @sa RTVfsFsStrmNext
403 *
404 * @note Setting this member to NULL is okay for write-only streams.
405 */
406 DECLCALLBACKMEMBER(int, pfnNext)(void *pvThis, char **ppszName, RTVFSOBJTYPE *penmType, PRTVFSOBJ phVfsObj);
407
408 /**
409 * Adds another object into the stream.
410 *
411 * Writable streams only.
412 *
413 * @returns IPRT status code.
414 * @param pvThis The implementation specific directory data.
415 * @param pszPath The path to the object.
416 * @param hVfsObj The object to add.
417 * @param fFlags Reserved for the future, MBZ.
418 * @sa RTVfsFsStrmAdd
419 *
420 * @note Setting this member to NULL is okay for read-only streams.
421 */
422 DECLCALLBACKMEMBER(int, pfnAdd)(void *pvThis, const char *pszPath, RTVFSOBJ hVfsObj, uint32_t fFlags);
423
424 /**
425 * Pushes an byte stream onto the stream (optional).
426 *
427 * Writable streams only.
428 *
429 * This differs from RTVFSFSSTREAMOPS::pfnAdd() in that it will create a regular
430 * file in the output file system stream and provide the actual content bytes
431 * via the returned I/O stream object.
432 *
433 * @returns IPRT status code.
434 * @param pvThis The implementation specific directory data.
435 * @param pszPath The path to the file.
436 * @param cbFile The file size. This can also be set to UINT64_MAX if
437 * the file system stream is backed by a file.
438 * @param paObjInfo Array of zero or more RTFSOBJINFO structures containing
439 * different pieces of information about the file. If any
440 * provided, the first one should be a RTFSOBJATTRADD_UNIX
441 * one, additional can be supplied if wanted. What exactly
442 * is needed depends on the underlying FS stream
443 * implementation.
444 * @param cObjInfo Number of items in the array @a paObjInfo points at.
445 * @param fFlags RTVFSFSSTRM_PUSH_F_XXX.
446 * @param phVfsIos Where to return the I/O stream to feed the file content
447 * to. If the FS stream is backed by a file, the returned
448 * handle can be cast to a file if necessary.
449 */
450 DECLCALLBACKMEMBER(int, pfnPushFile)(void *pvThis, const char *pszPath, uint64_t cbFile,
451 PCRTFSOBJINFO paObjInfo, uint32_t cObjInfo, uint32_t fFlags, PRTVFSIOSTREAM phVfsIos);
452
453 /**
454 * Marks the end of the stream.
455 *
456 * Writable streams only.
457 *
458 * @returns IPRT status code.
459 * @param pvThis The implementation specific directory data.
460 * @sa RTVfsFsStrmEnd
461 *
462 * @note Setting this member to NULL is okay for read-only streams.
463 */
464 DECLCALLBACKMEMBER(int, pfnEnd)(void *pvThis);
465
466 /** Marks the end of the structure (RTVFSFSSTREAMOPS_VERSION). */
467 uintptr_t uEndMarker;
468} RTVFSFSSTREAMOPS;
469/** Pointer to const object attribute setter operations. */
470typedef RTVFSFSSTREAMOPS const *PCRTVFSFSSTREAMOPS;
471
472/** The RTVFSFSSTREAMOPS structure version. */
473#define RTVFSFSSTREAMOPS_VERSION RT_MAKE_U32_FROM_U8(0xff,0x3f,2,0)
474
475
476/**
477 * Creates a new VFS filesystem stream handle.
478 *
479 * @returns IPRT status code
480 * @param pFsStreamOps The filesystem stream operations.
481 * @param cbInstance The size of the instance data.
482 * @param hVfs The VFS handle to associate this filesystem
483 * stream with. NIL_VFS is ok.
484 * @param hLock Handle to a custom lock to be used with the new
485 * object. The reference is consumed. NIL and
486 * special lock handles are fine.
487 * @param fReadOnly Set if read-only, clear if write-only.
488 * @param phVfsFss Where to return the new handle.
489 * @param ppvInstance Where to return the pointer to the instance data
490 * (size is @a cbInstance).
491 */
492RTDECL(int) RTVfsNewFsStream(PCRTVFSFSSTREAMOPS pFsStreamOps, size_t cbInstance, RTVFS hVfs, RTVFSLOCK hLock, bool fReadOnly,
493 PRTVFSFSSTREAM phVfsFss, void **ppvInstance);
494
495/**
496 * Gets the private data of an filesystem stream.
497 *
498 * @returns Pointer to the private data. NULL if the handle is invalid in some
499 * way.
500 * @param hVfsFss The FS stream handle.
501 * @param pFsStreamOps The FS stream operations. This servers as a
502 * sort of password.
503 */
504RTDECL(void *) RTVfsFsStreamToPrivate(RTVFSFSSTREAM hVfsFss, PCRTVFSFSSTREAMOPS pFsStreamOps);
505
506
507/**
508 * The directory operations.
509 *
510 * @extends RTVFSOBJOPS
511 * @extends RTVFSOBJSETOPS
512 */
513typedef struct RTVFSDIROPS
514{
515 /** The basic object operation. */
516 RTVFSOBJOPS Obj;
517 /** The structure version (RTVFSDIROPS_VERSION). */
518 uint32_t uVersion;
519 /** Reserved field, MBZ. */
520 uint32_t fReserved;
521 /** The object setter operations. */
522 RTVFSOBJSETOPS ObjSet;
523
524 /**
525 * Generic method for opening any kind of file system object.
526 *
527 * Can also create files and directories. Symbolic links, devices and such
528 * needs to be created using special methods or this would end up being way more
529 * complicated than it already is.
530 *
531 * There are optional specializations available.
532 *
533 * @returns IPRT status code.
534 * @retval VERR_PATH_NOT_FOUND or VERR_FILE_NOT_FOUND if @a pszEntry was not
535 * found.
536 * @retval VERR_IS_A_FILE if @a pszEntry is a file or similar but @a fFlags
537 * indicates that the type of object should not be opened.
538 * @retval VERR_IS_A_DIRECTORY if @a pszEntry is a directory but @a fFlags
539 * indicates that directories should not be opened.
540 * @retval VERR_IS_A_SYMLINK if @a pszEntry is a symbolic link but @a fFlags
541 * indicates that symbolic links should not be opened (or followed).
542 * @retval VERR_IS_A_FIFO if @a pszEntry is a FIFO but @a fFlags indicates that
543 * FIFOs should not be opened.
544 * @retval VERR_IS_A_SOCKET if @a pszEntry is a socket but @a fFlags indicates
545 * that sockets should not be opened.
546 * @retval VERR_IS_A_BLOCK_DEVICE if @a pszEntry is a block device but
547 * @a fFlags indicates that block devices should not be opened.
548 * @retval VERR_IS_A_BLOCK_DEVICE if @a pszEntry is a character device but
549 * @a fFlags indicates that character devices should not be opened.
550 *
551 * @param pvThis The implementation specific directory data.
552 * @param pszEntry The name of the immediate file to open or create.
553 * @param fOpenFile RTFILE_O_XXX combination.
554 * @param fObjFlags More flags: RTVFSOBJ_F_XXX, RTPATH_F_XXX.
555 * The meaning of RTPATH_F_FOLLOW_LINK differs here, if
556 * @a pszEntry is a symlink it should be opened for
557 * traversal rather than according to @a fOpenFile.
558 * @param phVfsObj Where to return the handle to the opened object.
559 * @sa RTFileOpen, RTDirOpen
560 */
561 DECLCALLBACKMEMBER(int, pfnOpen)(void *pvThis, const char *pszEntry, uint64_t fOpenFile,
562 uint32_t fObjFlags, PRTVFSOBJ phVfsObj);
563
564 /**
565 * Optional method for symbolic link handling in the vfsstddir.cpp.
566 *
567 * This is really just a hack to make symbolic link handling work when working
568 * with directory objects that doesn't have an associated VFS. It also helps
569 * deal with drive letters in symbolic links on Windows and OS/2.
570 *
571 * @returns IPRT status code.
572 * @retval VERR_PATH_IS_RELATIVE if @a pszPath isn't absolute and should be
573 * handled using pfnOpen().
574 *
575 * @param pvThis The implementation specific directory data.
576 * @param pszRoot Path to the alleged root.
577 * @param phVfsDir Where to return the handle to the specified root
578 * directory (or may current dir on a drive letter).
579 */
580 DECLCALLBACKMEMBER(int, pfnFollowAbsoluteSymlink)(void *pvThis, const char *pszRoot, PRTVFSDIR phVfsDir);
581
582 /**
583 * Open or create a file.
584 *
585 * @returns IPRT status code.
586 * @param pvThis The implementation specific directory data.
587 * @param pszFilename The name of the immediate file to open or create.
588 * @param fOpen The open flags (RTFILE_O_XXX).
589 * @param phVfsFile Where to return the handle to the opened file.
590 * @note Optional. RTVFSDIROPS::pfnOpenObj will be used if NULL.
591 * @sa RTFileOpen.
592 */
593 DECLCALLBACKMEMBER(int, pfnOpenFile)(void *pvThis, const char *pszFilename, uint64_t fOpen, PRTVFSFILE phVfsFile);
594
595 /**
596 * Open an existing subdirectory.
597 *
598 * @returns IPRT status code.
599 * @param pvThis The implementation specific directory data.
600 * @param pszSubDir The name of the immediate subdirectory to open.
601 * @param fFlags RTDIR_F_XXX.
602 * @param phVfsDir Where to return the handle to the opened directory.
603 * Optional.
604 * @note Optional. RTVFSDIROPS::pfnOpenObj will be used if NULL.
605 * @sa RTDirOpen.
606 */
607 DECLCALLBACKMEMBER(int, pfnOpenDir)(void *pvThis, const char *pszSubDir, uint32_t fFlags, PRTVFSDIR phVfsDir);
608
609 /**
610 * Creates a new subdirectory.
611 *
612 * @returns IPRT status code.
613 * @param pvThis The implementation specific directory data.
614 * @param pszSubDir The name of the immediate subdirectory to create.
615 * @param fMode The mode mask of the new directory.
616 * @param phVfsDir Where to optionally return the handle to the newly
617 * create directory.
618 * @note Optional. RTVFSDIROPS::pfnOpenObj will be used if NULL.
619 * @sa RTDirCreate.
620 */
621 DECLCALLBACKMEMBER(int, pfnCreateDir)(void *pvThis, const char *pszSubDir, RTFMODE fMode, PRTVFSDIR phVfsDir);
622
623 /**
624 * Opens an existing symbolic link.
625 *
626 * @returns IPRT status code.
627 * @param pvThis The implementation specific directory data.
628 * @param pszSymlink The name of the immediate symbolic link to open.
629 * @param phVfsSymlink Where to optionally return the handle to the
630 * newly create symbolic link.
631 * @note Optional. RTVFSDIROPS::pfnOpenObj will be used if NULL.
632 * @sa RTSymlinkCreate.
633 */
634 DECLCALLBACKMEMBER(int, pfnOpenSymlink)(void *pvThis, const char *pszSymlink, PRTVFSSYMLINK phVfsSymlink);
635
636 /**
637 * Creates a new symbolic link.
638 *
639 * @returns IPRT status code.
640 * @param pvThis The implementation specific directory data.
641 * @param pszSymlink The name of the immediate symbolic link to create.
642 * @param pszTarget The symbolic link target.
643 * @param enmType The symbolic link type.
644 * @param phVfsSymlink Where to optionally return the handle to the
645 * newly create symbolic link.
646 * @sa RTSymlinkCreate.
647 */
648 DECLCALLBACKMEMBER(int, pfnCreateSymlink)(void *pvThis, const char *pszSymlink, const char *pszTarget,
649 RTSYMLINKTYPE enmType, PRTVFSSYMLINK phVfsSymlink);
650
651 /**
652 * Query information about an entry.
653 *
654 * @returns IPRT status code.
655 * @param pvThis The implementation specific directory data.
656 * @param pszEntry The name of the directory entry to remove.
657 * @param pObjInfo Where to return the info on success.
658 * @param enmAddAttr Which set of additional attributes to request.
659 * @note Optional. RTVFSDIROPS::pfnOpenObj and RTVFSOBJOPS::pfnQueryInfo
660 * will be used if NULL.
661 * @sa RTPathQueryInfo, RTVFSOBJOPS::pfnQueryInfo
662 */
663 DECLCALLBACKMEMBER(int, pfnQueryEntryInfo)(void *pvThis, const char *pszEntry,
664 PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr);
665
666 /**
667 * Removes a directory entry.
668 *
669 * @returns IPRT status code.
670 * @param pvThis The implementation specific directory data.
671 * @param pszEntry The name of the directory entry to remove.
672 * @param fType If non-zero, this restricts the type of the entry to
673 * the object type indicated by the mask
674 * (RTFS_TYPE_XXX).
675 * @sa RTFileRemove, RTDirRemove, RTSymlinkRemove.
676 */
677 DECLCALLBACKMEMBER(int, pfnUnlinkEntry)(void *pvThis, const char *pszEntry, RTFMODE fType);
678
679 /**
680 * Renames a directory entry.
681 *
682 * @returns IPRT status code.
683 * @param pvThis The implementation specific directory data.
684 * @param pszEntry The name of the directory entry to rename.
685 * @param fType If non-zero, this restricts the type of the entry to
686 * the object type indicated by the mask
687 * (RTFS_TYPE_XXX).
688 * @param pszNewName The new entry name.
689 * @sa RTPathRename
690 *
691 * @todo This API is not flexible enough, must be able to rename between
692 * directories within a file system.
693 */
694 DECLCALLBACKMEMBER(int, pfnRenameEntry)(void *pvThis, const char *pszEntry, RTFMODE fType, const char *pszNewName);
695
696 /**
697 * Rewind the directory stream so that the next read returns the first
698 * entry.
699 *
700 * @returns IPRT status code.
701 * @param pvThis The implementation specific directory data.
702 */
703 DECLCALLBACKMEMBER(int, pfnRewindDir)(void *pvThis);
704
705 /**
706 * Rewind the directory stream so that the next read returns the first
707 * entry.
708 *
709 * @returns IPRT status code.
710 * @param pvThis The implementation specific directory data.
711 * @param pDirEntry Output buffer.
712 * @param pcbDirEntry Complicated, see RTDirReadEx.
713 * @param enmAddAttr Which set of additional attributes to request.
714 * @sa RTDirReadEx
715 */
716 DECLCALLBACKMEMBER(int, pfnReadDir)(void *pvThis, PRTDIRENTRYEX pDirEntry, size_t *pcbDirEntry, RTFSOBJATTRADD enmAddAttr);
717
718 /** Marks the end of the structure (RTVFSDIROPS_VERSION). */
719 uintptr_t uEndMarker;
720} RTVFSDIROPS;
721/** Pointer to const directory operations. */
722typedef RTVFSDIROPS const *PCRTVFSDIROPS;
723/** The RTVFSDIROPS structure version. */
724#define RTVFSDIROPS_VERSION RT_MAKE_U32_FROM_U8(0xff,0x4f,1,0)
725
726
727/**
728 * Creates a new VFS directory handle.
729 *
730 * @returns IPRT status code
731 * @param pDirOps The directory operations.
732 * @param cbInstance The size of the instance data.
733 * @param fFlags RTVFSDIR_F_XXX
734 * @param hVfs The VFS handle to associate this directory with.
735 * NIL_VFS is ok.
736 * @param hLock Handle to a custom lock to be used with the new
737 * object. The reference is consumed. NIL and
738 * special lock handles are fine.
739 * @param phVfsDir Where to return the new handle.
740 * @param ppvInstance Where to return the pointer to the instance data
741 * (size is @a cbInstance).
742 */
743RTDECL(int) RTVfsNewDir(PCRTVFSDIROPS pDirOps, size_t cbInstance, uint32_t fFlags, RTVFS hVfs, RTVFSLOCK hLock,
744 PRTVFSDIR phVfsDir, void **ppvInstance);
745
746/** @name RTVFSDIR_F_XXX
747 * @{ */
748/** Don't reference the @a hVfs parameter passed to RTVfsNewDir.
749 * This is a permanent root directory hack. */
750#define RTVFSDIR_F_NO_VFS_REF RT_BIT_32(0)
751/** @} */
752
753
754/**
755 * The symbolic link operations.
756 *
757 * @extends RTVFSOBJOPS
758 * @extends RTVFSOBJSETOPS
759 */
760typedef struct RTVFSSYMLINKOPS
761{
762 /** The basic object operation. */
763 RTVFSOBJOPS Obj;
764 /** The structure version (RTVFSSYMLINKOPS_VERSION). */
765 uint32_t uVersion;
766 /** Reserved field, MBZ. */
767 uint32_t fReserved;
768 /** The object setter operations. */
769 RTVFSOBJSETOPS ObjSet;
770
771 /**
772 * Read the symbolic link target.
773 *
774 * @returns IPRT status code.
775 * @param pvThis The implementation specific symbolic link data.
776 * @param pszTarget The target buffer.
777 * @param cbTarget The size of the target buffer.
778 * @sa RTSymlinkRead
779 */
780 DECLCALLBACKMEMBER(int, pfnRead)(void *pvThis, char *pszTarget, size_t cbTarget);
781
782 /** Marks the end of the structure (RTVFSSYMLINKOPS_VERSION). */
783 uintptr_t uEndMarker;
784} RTVFSSYMLINKOPS;
785/** Pointer to const symbolic link operations. */
786typedef RTVFSSYMLINKOPS const *PCRTVFSSYMLINKOPS;
787/** The RTVFSSYMLINKOPS structure version. */
788#define RTVFSSYMLINKOPS_VERSION RT_MAKE_U32_FROM_U8(0xff,0x5f,1,0)
789
790
791/**
792 * Creates a new VFS symlink handle.
793 *
794 * @returns IPRT status code
795 * @param pSymlinkOps The symlink operations.
796 * @param cbInstance The size of the instance data.
797 * @param hVfs The VFS handle to associate this symlink object
798 * with. NIL_VFS is ok.
799 * @param hLock Handle to a custom lock to be used with the new
800 * object. The reference is consumed. NIL and
801 * special lock handles are fine.
802 * @param phVfsSym Where to return the new handle.
803 * @param ppvInstance Where to return the pointer to the instance data
804 * (size is @a cbInstance).
805 */
806RTDECL(int) RTVfsNewSymlink(PCRTVFSSYMLINKOPS pSymlinkOps, size_t cbInstance, RTVFS hVfs, RTVFSLOCK hLock,
807 PRTVFSSYMLINK phVfsSym, void **ppvInstance);
808
809
810/**
811 * The basis for all I/O objects (files, pipes, sockets, devices, ++).
812 *
813 * @extends RTVFSOBJOPS
814 */
815typedef struct RTVFSIOSTREAMOPS
816{
817 /** The basic object operation. */
818 RTVFSOBJOPS Obj;
819 /** The structure version (RTVFSIOSTREAMOPS_VERSION). */
820 uint32_t uVersion;
821 /** Feature field. */
822 uint32_t fFeatures;
823
824 /**
825 * Reads from the file/stream.
826 *
827 * @returns IPRT status code. See RTVfsIoStrmRead.
828 * @param pvThis The implementation specific file data.
829 * @param off Where to read at, -1 for the current position.
830 * @param pSgBuf Gather buffer describing the bytes that are to be
831 * written.
832 * @param fBlocking If @c true, the call is blocking, if @c false it
833 * should not block.
834 * @param pcbRead Where return the number of bytes actually read.
835 * This is set it 0 by the caller. If NULL, try read
836 * all and fail if incomplete.
837 * @sa RTVfsIoStrmRead, RTVfsIoStrmSgRead, RTVfsFileRead,
838 * RTVfsFileReadAt, RTFileRead, RTFileReadAt.
839 */
840 DECLCALLBACKMEMBER(int, pfnRead)(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead);
841
842 /**
843 * Writes to the file/stream.
844 *
845 * @returns IPRT status code.
846 * @param pvThis The implementation specific file data.
847 * @param off Where to start wrinting, -1 for the current
848 * position.
849 * @param pSgBuf Gather buffers describing the bytes that are to be
850 * written.
851 * @param fBlocking If @c true, the call is blocking, if @c false it
852 * should not block.
853 * @param pcbWritten Where to return the number of bytes actually
854 * written. This is set it 0 by the caller. If
855 * NULL, try write it all and fail if incomplete.
856 * @sa RTFileWrite, RTFileWriteAt.
857 */
858 DECLCALLBACKMEMBER(int, pfnWrite)(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten);
859
860 /**
861 * Flushes any pending data writes to the stream.
862 *
863 * @returns IPRT status code.
864 * @param pvThis The implementation specific file data.
865 * @sa RTFileFlush.
866 */
867 DECLCALLBACKMEMBER(int, pfnFlush)(void *pvThis);
868
869 /**
870 * Poll for events.
871 *
872 * @returns IPRT status code.
873 * @param pvThis The implementation specific file data.
874 * @param fEvents The events to poll for (RTPOLL_EVT_XXX).
875 * @param cMillies How long to wait for event to eventuate.
876 * @param fIntr Whether the wait is interruptible and can return
877 * VERR_INTERRUPTED (@c true) or if this condition
878 * should be hidden from the caller (@c false).
879 * @param pfRetEvents Where to return the event mask.
880 * @sa RTPollSetAdd, RTPoll, RTPollNoResume.
881 */
882 DECLCALLBACKMEMBER(int, pfnPollOne)(void *pvThis, uint32_t fEvents, RTMSINTERVAL cMillies, bool fIntr,
883 uint32_t *pfRetEvents);
884
885 /**
886 * Tells the current file/stream position.
887 *
888 * @returns IPRT status code.
889 * @param pvThis The implementation specific file data.
890 * @param poffActual Where to return the actual offset.
891 * @sa RTFileTell
892 */
893 DECLCALLBACKMEMBER(int, pfnTell)(void *pvThis, PRTFOFF poffActual);
894
895 /**
896 * Skips @a cb ahead in the stream.
897 *
898 * @returns IPRT status code.
899 * @param pvThis The implementation specific file data.
900 * @param cb The number bytes to skip.
901 * @remarks This is optional and can be NULL.
902 */
903 DECLCALLBACKMEMBER(int, pfnSkip)(void *pvThis, RTFOFF cb);
904
905 /**
906 * Fills the stream with @a cb zeros.
907 *
908 * @returns IPRT status code.
909 * @param pvThis The implementation specific file data.
910 * @param cb The number of zero bytes to insert.
911 * @remarks This is optional and can be NULL.
912 */
913 DECLCALLBACKMEMBER(int, pfnZeroFill)(void *pvThis, RTFOFF cb);
914
915 /** Marks the end of the structure (RTVFSIOSTREAMOPS_VERSION). */
916 uintptr_t uEndMarker;
917} RTVFSIOSTREAMOPS;
918/** Pointer to const I/O stream operations. */
919typedef RTVFSIOSTREAMOPS const *PCRTVFSIOSTREAMOPS;
920
921/** The RTVFSIOSTREAMOPS structure version. */
922#define RTVFSIOSTREAMOPS_VERSION RT_MAKE_U32_FROM_U8(0xff,0x6f,1,0)
923
924/** @name RTVFSIOSTREAMOPS::fFeatures
925 * @{ */
926/** No scatter gather lists, thank you. */
927#define RTVFSIOSTREAMOPS_FEAT_NO_SG RT_BIT_32(0)
928/** Mask of the valid I/O stream feature flags. */
929#define RTVFSIOSTREAMOPS_FEAT_VALID_MASK UINT32_C(0x00000001)
930/** @} */
931
932
933/**
934 * Creates a new VFS I/O stream handle.
935 *
936 * @returns IPRT status code
937 * @param pIoStreamOps The I/O stream operations.
938 * @param cbInstance The size of the instance data.
939 * @param fOpen The open flags. The minimum is the access mask.
940 * @param hVfs The VFS handle to associate this I/O stream
941 * with. NIL_VFS is ok.
942 * @param hLock Handle to a custom lock to be used with the new
943 * object. The reference is consumed. NIL and
944 * special lock handles are fine.
945 * @param phVfsIos Where to return the new handle.
946 * @param ppvInstance Where to return the pointer to the instance data
947 * (size is @a cbInstance).
948 */
949RTDECL(int) RTVfsNewIoStream(PCRTVFSIOSTREAMOPS pIoStreamOps, size_t cbInstance, uint32_t fOpen, RTVFS hVfs, RTVFSLOCK hLock,
950 PRTVFSIOSTREAM phVfsIos, void **ppvInstance);
951
952
953/**
954 * Gets the private data of an I/O stream.
955 *
956 * @returns Pointer to the private data. NULL if the handle is invalid in some
957 * way.
958 * @param hVfsIos The I/O stream handle.
959 * @param pIoStreamOps The I/O stream operations. This servers as a
960 * sort of password.
961 */
962RTDECL(void *) RTVfsIoStreamToPrivate(RTVFSIOSTREAM hVfsIos, PCRTVFSIOSTREAMOPS pIoStreamOps);
963
964
965/**
966 * The file operations.
967 *
968 * @extends RTVFSIOSTREAMOPS
969 * @extends RTVFSOBJSETOPS
970 */
971typedef struct RTVFSFILEOPS
972{
973 /** The I/O stream and basis object operations. */
974 RTVFSIOSTREAMOPS Stream;
975 /** The structure version (RTVFSFILEOPS_VERSION). */
976 uint32_t uVersion;
977 /** Reserved field, MBZ. */
978 uint32_t fReserved;
979 /** The object setter operations. */
980 RTVFSOBJSETOPS ObjSet;
981
982 /**
983 * Changes the current file position.
984 *
985 * @returns IPRT status code.
986 * @param pvThis The implementation specific file data.
987 * @param offSeek The offset to seek.
988 * @param uMethod The seek method, i.e. what the seek is relative to.
989 * @param poffActual Where to return the actual offset.
990 * @sa RTFileSeek
991 */
992 DECLCALLBACKMEMBER(int, pfnSeek)(void *pvThis, RTFOFF offSeek, unsigned uMethod, PRTFOFF poffActual);
993
994 /**
995 * Get the current file/stream size.
996 *
997 * @returns IPRT status code.
998 * @param pvThis The implementation specific file data.
999 * @param pcbFile Where to store the current file size.
1000 * @sa RTFileGetSize
1001 */
1002 DECLCALLBACKMEMBER(int, pfnQuerySize)(void *pvThis, uint64_t *pcbFile);
1003
1004 /** @todo There will be more methods here. */
1005
1006 /** Marks the end of the structure (RTVFSFILEOPS_VERSION). */
1007 uintptr_t uEndMarker;
1008} RTVFSFILEOPS;
1009/** Pointer to const file operations. */
1010typedef RTVFSFILEOPS const *PCRTVFSFILEOPS;
1011
1012/** The RTVFSFILEOPS structure version. */
1013#define RTVFSFILEOPS_VERSION RT_MAKE_U32_FROM_U8(0xff,0x7f,1,0)
1014
1015/**
1016 * Creates a new VFS file handle.
1017 *
1018 * @returns IPRT status code
1019 * @param pFileOps The file operations.
1020 * @param cbInstance The size of the instance data.
1021 * @param fOpen The open flags. The minimum is the access mask.
1022 * @param hVfs The VFS handle to associate this file with.
1023 * NIL_VFS is ok.
1024 * @param hLock Handle to a custom lock to be used with the new
1025 * object. The reference is consumed. NIL and
1026 * special lock handles are fine.
1027 * @param phVfsFile Where to return the new handle.
1028 * @param ppvInstance Where to return the pointer to the instance data
1029 * (size is @a cbInstance).
1030 */
1031RTDECL(int) RTVfsNewFile(PCRTVFSFILEOPS pFileOps, size_t cbInstance, uint32_t fOpen, RTVFS hVfs, RTVFSLOCK hLock,
1032 PRTVFSFILE phVfsFile, void **ppvInstance);
1033
1034
1035/** @defgroup grp_rt_vfs_ll_util VFS Utility APIs
1036 * @{ */
1037
1038/**
1039 * Parsed path.
1040 */
1041typedef struct RTVFSPARSEDPATH
1042{
1043 /** The length of the path in szCopy. */
1044 uint16_t cch;
1045 /** The number of path components. */
1046 uint16_t cComponents;
1047 /** Set if the path ends with slash, indicating that it's a directory
1048 * reference and not a file reference. The slash has been removed from
1049 * the copy. */
1050 bool fDirSlash;
1051 /** Set if absolute. */
1052 bool fAbsolute;
1053 /** The offset where each path component starts, i.e. the char after the
1054 * slash. The array has cComponents + 1 entries, where the final one is
1055 * cch + 1 so that one can always terminate the current component by
1056 * szPath[aoffComponent[i] - 1] = '\0'. */
1057 uint16_t aoffComponents[RTPATH_MAX / 2 + 1];
1058 /** A normalized copy of the path.
1059 * Reserve some extra space so we can be more relaxed about overflow
1060 * checks and terminator paddings, especially when recursing. */
1061 char szPath[RTPATH_MAX];
1062} RTVFSPARSEDPATH;
1063/** Pointer to a parsed path. */
1064typedef RTVFSPARSEDPATH *PRTVFSPARSEDPATH;
1065
1066/** The max accepted path length.
1067 * This must be a few chars shorter than RTVFSPARSEDPATH::szPath because we
1068 * use two terminators and wish be a little bit lazy with checking. */
1069#define RTVFSPARSEDPATH_MAX (RTPATH_MAX - 4)
1070
1071/**
1072 * Appends @a pszPath (relative) to the already parsed path @a pPath.
1073 *
1074 * @retval VINF_SUCCESS
1075 * @retval VERR_FILENAME_TOO_LONG
1076 * @retval VERR_INTERNAL_ERROR_4
1077 * @param pPath The parsed path to append @a pszPath onto.
1078 * This is both input and output.
1079 * @param pszPath The path to append. This must be relative.
1080 * @param piRestartComp The component to restart parsing at. This is
1081 * input/output. The input does not have to be
1082 * within the valid range. Optional.
1083 */
1084RTDECL(int) RTVfsParsePathAppend(PRTVFSPARSEDPATH pPath, const char *pszPath, uint16_t *piRestartComp);
1085
1086/**
1087 * Parses a path.
1088 *
1089 * @retval VINF_SUCCESS
1090 * @retval VERR_FILENAME_TOO_LONG
1091 * @param pPath Where to store the parsed path.
1092 * @param pszPath The path to parse. Absolute or relative to @a
1093 * pszCwd.
1094 * @param pszCwd The current working directory. Must be
1095 * absolute.
1096 */
1097RTDECL(int) RTVfsParsePath(PRTVFSPARSEDPATH pPath, const char *pszPath, const char *pszCwd);
1098
1099/**
1100 * Same as RTVfsParsePath except that it allocates a temporary buffer.
1101 *
1102 * @retval VINF_SUCCESS
1103 * @retval VERR_NO_TMP_MEMORY
1104 * @retval VERR_FILENAME_TOO_LONG
1105 * @param pszPath The path to parse. Absolute or relative to @a
1106 * pszCwd.
1107 * @param pszCwd The current working directory. Must be
1108 * absolute.
1109 * @param ppPath Where to store the pointer to the allocated
1110 * buffer containing the parsed path. This must
1111 * be freed by calling RTVfsParsePathFree. NULL
1112 * will be stored on failured.
1113 */
1114RTDECL(int) RTVfsParsePathA(const char *pszPath, const char *pszCwd, PRTVFSPARSEDPATH *ppPath);
1115
1116/**
1117 * Frees a buffer returned by RTVfsParsePathA.
1118 *
1119 * @param pPath The parsed path buffer to free. NULL is fine.
1120 */
1121RTDECL(void) RTVfsParsePathFree(PRTVFSPARSEDPATH pPath);
1122
1123/**
1124 * Dummy implementation of RTVFSIOSTREAMOPS::pfnPollOne.
1125 *
1126 * This handles the case where there is no chance any events my be raised and
1127 * all that is required is to wait according to the parameters.
1128 *
1129 * @returns IPRT status code.
1130 * @param fEvents The events to poll for (RTPOLL_EVT_XXX).
1131 * @param cMillies How long to wait for event to eventuate.
1132 * @param fIntr Whether the wait is interruptible and can return
1133 * VERR_INTERRUPTED (@c true) or if this condition
1134 * should be hidden from the caller (@c false).
1135 * @param pfRetEvents Where to return the event mask.
1136 * @sa RTVFSIOSTREAMOPS::pfnPollOne, RTPollSetAdd, RTPoll, RTPollNoResume.
1137 */
1138RTDECL(int) RTVfsUtilDummyPollOne(uint32_t fEvents, RTMSINTERVAL cMillies, bool fIntr, uint32_t *pfRetEvents);
1139
1140/** @} */
1141
1142
1143/** @defgroup grp_rt_vfs_lowlevel_chain VFS Chains (Low Level)
1144 * @ref grp_rt_vfs_chain
1145 * @{
1146 */
1147
1148/** Pointer to a VFS chain element registration record. */
1149typedef struct RTVFSCHAINELEMENTREG *PRTVFSCHAINELEMENTREG;
1150/** Pointer to a const VFS chain element registration record. */
1151typedef struct RTVFSCHAINELEMENTREG const *PCRTVFSCHAINELEMENTREG;
1152
1153/**
1154 * VFS chain element argument.
1155 */
1156typedef struct RTVFSCHAINELEMENTARG
1157{
1158 /** The string argument value. */
1159 char *psz;
1160 /** The specification offset of this argument. */
1161 uint16_t offSpec;
1162 /** Provider specific value. */
1163 uint64_t uProvider;
1164} RTVFSCHAINELEMENTARG;
1165/** Pointer to a VFS chain element argument. */
1166typedef RTVFSCHAINELEMENTARG *PRTVFSCHAINELEMENTARG;
1167
1168
1169/**
1170 * VFS chain element specification.
1171 */
1172typedef struct RTVFSCHAINELEMSPEC
1173{
1174 /** The provider name.
1175 * This can be NULL if this is the final component and it's just a path. */
1176 char *pszProvider;
1177 /** The input type, RTVFSOBJTYPE_INVALID if first. */
1178 RTVFSOBJTYPE enmTypeIn;
1179 /** The element type.
1180 * RTVFSOBJTYPE_END if this is the final component and it's just a path. */
1181 RTVFSOBJTYPE enmType;
1182 /** The input spec offset of this element. */
1183 uint16_t offSpec;
1184 /** The length of the input spec. */
1185 uint16_t cchSpec;
1186 /** The number of arguments. */
1187 uint32_t cArgs;
1188 /** Arguments. */
1189 PRTVFSCHAINELEMENTARG paArgs;
1190
1191 /** The provider. */
1192 PCRTVFSCHAINELEMENTREG pProvider;
1193 /** Provider specific value. */
1194 uint64_t uProvider;
1195 /** The object (with reference). */
1196 RTVFSOBJ hVfsObj;
1197} RTVFSCHAINELEMSPEC;
1198/** Pointer to a chain element specification. */
1199typedef RTVFSCHAINELEMSPEC *PRTVFSCHAINELEMSPEC;
1200/** Pointer to a const chain element specification. */
1201typedef RTVFSCHAINELEMSPEC const *PCRTVFSCHAINELEMSPEC;
1202
1203
1204/**
1205 * Parsed VFS chain specification.
1206 */
1207typedef struct RTVFSCHAINSPEC
1208{
1209 /** Open directory flags (RTFILE_O_XXX). */
1210 uint64_t fOpenFile;
1211 /** To be defined. */
1212 uint32_t fOpenDir;
1213 /** The type desired by the caller. */
1214 RTVFSOBJTYPE enmDesiredType;
1215 /** The number of elements. */
1216 uint32_t cElements;
1217 /** The elements. */
1218 PRTVFSCHAINELEMSPEC paElements;
1219} RTVFSCHAINSPEC;
1220/** Pointer to a parsed VFS chain specification. */
1221typedef RTVFSCHAINSPEC *PRTVFSCHAINSPEC;
1222/** Pointer to a const, parsed VFS chain specification. */
1223typedef RTVFSCHAINSPEC const *PCRTVFSCHAINSPEC;
1224
1225
1226/**
1227 * A chain element provider registration record.
1228 */
1229typedef struct RTVFSCHAINELEMENTREG
1230{
1231 /** The version (RTVFSCHAINELEMENTREG_VERSION). */
1232 uint32_t uVersion;
1233 /** Reserved, MBZ. */
1234 uint32_t fReserved;
1235 /** The provider name (unique). */
1236 const char *pszName;
1237 /** For chaining the providers. */
1238 RTLISTNODE ListEntry;
1239 /** Help text. */
1240 const char *pszHelp;
1241
1242 /**
1243 * Checks the element specification.
1244 *
1245 * This is allowed to parse arguments and use pSpec->uProvider and
1246 * pElement->paArgs[].uProvider to store information that pfnInstantiate and
1247 * pfnCanReuseElement may use later on, thus avoiding duplicating work/code.
1248 *
1249 * @returns IPRT status code.
1250 * @param pProviderReg Pointer to the element provider registration.
1251 * @param pSpec The chain specification.
1252 * @param pElement The chain element specification to validate.
1253 * @param poffError Where to return error offset on failure. This is
1254 * set to the pElement->offSpec on input, so it only
1255 * needs to be adjusted if an argument is at fault.
1256 * @param pErrInfo Where to return additional error information, if
1257 * available. Optional.
1258 */
1259 DECLCALLBACKMEMBER(int, pfnValidate)(PCRTVFSCHAINELEMENTREG pProviderReg, PRTVFSCHAINSPEC pSpec,
1260 PRTVFSCHAINELEMSPEC pElement, uint32_t *poffError, PRTERRINFO pErrInfo);
1261
1262 /**
1263 * Create a VFS object according to the element specification.
1264 *
1265 * @returns IPRT status code.
1266 * @param pProviderReg Pointer to the element provider registration.
1267 * @param pSpec The chain specification.
1268 * @param pElement The chain element specification to instantiate.
1269 * @param hPrevVfsObj Handle to the previous VFS object, NIL_RTVFSOBJ if
1270 * first.
1271 * @param phVfsObj Where to return the VFS object handle.
1272 * @param poffError Where to return error offset on failure. This is
1273 * set to the pElement->offSpec on input, so it only
1274 * needs to be adjusted if an argument is at fault.
1275 * @param pErrInfo Where to return additional error information, if
1276 * available. Optional.
1277 */
1278 DECLCALLBACKMEMBER(int, pfnInstantiate)(PCRTVFSCHAINELEMENTREG pProviderReg, PCRTVFSCHAINSPEC pSpec,
1279 PCRTVFSCHAINELEMSPEC pElement, RTVFSOBJ hPrevVfsObj,
1280 PRTVFSOBJ phVfsObj, uint32_t *poffError, PRTERRINFO pErrInfo);
1281
1282 /**
1283 * Determins whether the element can be reused.
1284 *
1285 * This is for handling situations accessing the same file system twice, like
1286 * for both the source and destiation of a copy operation. This allows not only
1287 * sharing resources and avoid doing things twice, but also helps avoid file
1288 * sharing violations and inconsistencies araising from the image being updated
1289 * and read independently.
1290 *
1291 * @returns true if the element from @a pReuseSpec an be reused, false if not.
1292 * @param pProviderReg Pointer to the element provider registration.
1293 * @param pSpec The chain specification.
1294 * @param pElement The chain element specification.
1295 * @param pReuseSpec The chain specification of the existing chain.
1296 * @param pReuseElement The chain element specification of the existing
1297 * element that is being considered for reuse.
1298 */
1299 DECLCALLBACKMEMBER(bool, pfnCanReuseElement)(PCRTVFSCHAINELEMENTREG pProviderReg,
1300 PCRTVFSCHAINSPEC pSpec, PCRTVFSCHAINELEMSPEC pElement,
1301 PCRTVFSCHAINSPEC pReuseSpec, PCRTVFSCHAINELEMSPEC pReuseElement);
1302
1303 /** End marker (RTVFSCHAINELEMENTREG_VERSION). */
1304 uintptr_t uEndMarker;
1305} RTVFSCHAINELEMENTREG;
1306
1307/** The VFS chain element registration record version number. */
1308#define RTVFSCHAINELEMENTREG_VERSION RT_MAKE_U32_FROM_U8(0xff, 0x7f, 1, 0)
1309
1310
1311/**
1312 * Parses the specification.
1313 *
1314 * @returns IPRT status code.
1315 * @param pszSpec The specification string to parse.
1316 * @param fFlags Flags, see RTVFSCHAIN_PF_XXX.
1317 * @param enmDesiredType The object type the caller wants to interface with.
1318 * @param ppSpec Where to return the pointer to the parsed
1319 * specification. This must be freed by calling
1320 * RTVfsChainSpecFree. Will always be set (unless
1321 * invalid parameters.)
1322 * @param poffError Where to return the offset into the input
1323 * specification of what's causing trouble. Always
1324 * set, unless this argument causes an invalid pointer
1325 * error.
1326 */
1327RTDECL(int) RTVfsChainSpecParse(const char *pszSpec, uint32_t fFlags, RTVFSOBJTYPE enmDesiredType,
1328 PRTVFSCHAINSPEC *ppSpec, uint32_t *poffError);
1329
1330/** @name RTVfsChainSpecParse
1331 * @{ */
1332/** Mask of valid flags. */
1333#define RTVFSCHAIN_PF_VALID_MASK UINT32_C(0x00000000)
1334/** @} */
1335
1336/**
1337 * Checks and setups the chain.
1338 *
1339 * @returns IPRT status code.
1340 * @param pSpec The parsed specification.
1341 * @param pReuseSpec Spec to reuse if applicable. Optional.
1342 * @param phVfsObj Where to return the VFS object.
1343 * @param ppszFinalPath Where to return the pointer to the final path if
1344 * applicable. The caller needs to check whether this
1345 * is NULL or a path, in the former case nothing more
1346 * needs doing, whereas in the latter the caller must
1347 * perform the desired operation(s) on *phVfsObj using
1348 * the final path.
1349 * @param poffError Where to return the offset into the input
1350 * specification of what's causing trouble. Always
1351 * set, unless this argument causes an invalid pointer
1352 * error.
1353 * @param pErrInfo Where to return additional error information, if
1354 * available. Optional.
1355 */
1356RTDECL(int) RTVfsChainSpecCheckAndSetup(PRTVFSCHAINSPEC pSpec, PCRTVFSCHAINSPEC pReuseSpec,
1357 PRTVFSOBJ phVfsObj, const char **ppszFinalPath, uint32_t *poffError, PRTERRINFO pErrInfo);
1358
1359/**
1360 * Frees a parsed chain specification.
1361 *
1362 * @param pSpec What RTVfsChainSpecParse returned. NULL is
1363 * quietly ignored.
1364 */
1365RTDECL(void) RTVfsChainSpecFree(PRTVFSCHAINSPEC pSpec);
1366
1367/**
1368 * Registers a chain element provider.
1369 *
1370 * @returns IPRT status code
1371 * @param pRegRec The registration record.
1372 * @param fFromCtor Indicates where we're called from.
1373 */
1374RTDECL(int) RTVfsChainElementRegisterProvider(PRTVFSCHAINELEMENTREG pRegRec, bool fFromCtor);
1375
1376/**
1377 * Deregisters a chain element provider.
1378 *
1379 * @returns IPRT status code
1380 * @param pRegRec The registration record.
1381 * @param fFromDtor Indicates where we're called from.
1382 */
1383RTDECL(int) RTVfsChainElementDeregisterProvider(PRTVFSCHAINELEMENTREG pRegRec, bool fFromDtor);
1384
1385
1386/** @def RTVFSCHAIN_AUTO_REGISTER_ELEMENT_PROVIDER
1387 * Automatically registers a chain element provider using a global constructor
1388 * and destructor hack.
1389 *
1390 * @param pRegRec Pointer to the registration record.
1391 * @param name Some unique variable name prefix.
1392 */
1393
1394#ifdef __cplusplus
1395/**
1396 * Class used for registering a VFS chain element provider.
1397 */
1398class RTVfsChainElementAutoRegisterHack
1399{
1400private:
1401 /** The registration record, NULL if registration failed. */
1402 PRTVFSCHAINELEMENTREG m_pRegRec;
1403
1404public:
1405 RTVfsChainElementAutoRegisterHack(PRTVFSCHAINELEMENTREG a_pRegRec)
1406 : m_pRegRec(a_pRegRec)
1407 {
1408 int rc = RTVfsChainElementRegisterProvider(m_pRegRec, true);
1409 if (RT_FAILURE(rc))
1410 m_pRegRec = NULL;
1411 }
1412
1413 ~RTVfsChainElementAutoRegisterHack()
1414 {
1415 RTVfsChainElementDeregisterProvider(m_pRegRec, true);
1416 m_pRegRec = NULL;
1417 }
1418};
1419
1420# define RTVFSCHAIN_AUTO_REGISTER_ELEMENT_PROVIDER(pRegRec, name) \
1421 static RTVfsChainElementAutoRegisterHack name ## AutoRegistrationHack(pRegRec)
1422
1423#else
1424# define RTVFSCHAIN_AUTO_REGISTER_ELEMENT_PROVIDER(pRegRec, name) \
1425 extern void *name ## AutoRegistrationHack = \
1426 &Sorry_but_RTVFSCHAIN_AUTO_REGISTER_ELEMENT_PROVIDER_does_not_work_in_c_source_files
1427#endif
1428
1429
1430/**
1431 * Common worker for the 'stdfile' and 'open' providers for implementing
1432 * RTVFSCHAINELEMENTREG::pfnValidate.
1433 *
1434 * Stores the RTFILE_O_XXX flags in pSpec->uProvider.
1435 *
1436 * @returns IPRT status code.
1437 * @param pSpec The chain specification.
1438 * @param pElement The chain element specification to validate.
1439 * @param poffError Where to return error offset on failure. This is set to
1440 * the pElement->offSpec on input, so it only needs to be
1441 * adjusted if an argument is at fault.
1442 * @param pErrInfo Where to return additional error information, if
1443 * available. Optional.
1444 */
1445RTDECL(int) RTVfsChainValidateOpenFileOrIoStream(PRTVFSCHAINSPEC pSpec, PRTVFSCHAINELEMSPEC pElement,
1446 uint32_t *poffError, PRTERRINFO pErrInfo);
1447
1448
1449/** @} */
1450
1451
1452/** @} */
1453
1454RT_C_DECLS_END
1455
1456#endif /* !___iprt_vfslowlevel_h */
1457
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