VirtualBox

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

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

iprt: More vfs bits.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 50.8 KB
Line 
1/** @file
2 * IPRT - Virtual Filesystem.
3 */
4
5/*
6 * Copyright (C) 2010-2016 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef ___iprt_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 /** Marks the end of the structure (RTVFSOPS_VERSION). */
255 uintptr_t uEndMarker;
256} RTVFSOPS;
257/** Pointer to constant VFS operations. */
258typedef RTVFSOPS const *PCRTVFSOPS;
259
260/** The RTVFSOPS structure version. */
261#define RTVFSOPS_VERSION RT_MAKE_U32_FROM_U8(0xff,0x0f,1,0)
262
263/** @name RTVFSOPS::fFeatures
264 * @{ */
265/** The VFS supports attaching other systems. */
266#define RTVFSOPS_FEAT_ATTACH RT_BIT_32(0)
267/** @} */
268
269/**
270 * Creates a new VFS handle.
271 *
272 * @returns IPRT status code
273 * @param pVfsOps The VFS operations.
274 * @param cbInstance The size of the instance data.
275 * @param hVfs The VFS handle to associate this VFS with.
276 * NIL_VFS is ok.
277 * @param hLock Handle to a custom lock to be used with the new
278 * object. The reference is consumed. NIL and
279 * special lock handles are fine.
280 * @param phVfs Where to return the new handle.
281 * @param ppvInstance Where to return the pointer to the instance data
282 * (size is @a cbInstance).
283 */
284RTDECL(int) RTVfsNew(PCRTVFSOPS pVfsOps, size_t cbInstance, RTVFS hVfs, RTVFSLOCK hLock,
285 PRTVFS phVfs, void **ppvInstance);
286
287
288/**
289 * Creates a new VFS base object handle.
290 *
291 * @returns IPRT status code
292 * @param pObjOps The base object operations.
293 * @param cbInstance The size of the instance data.
294 * @param hVfs The VFS handle to associate this base object
295 * with. NIL_VFS is ok.
296 * @param hLock Handle to a custom lock to be used with the new
297 * object. The reference is consumed. NIL and
298 * special lock handles are fine.
299 * @param phVfsObj Where to return the new handle.
300 * @param ppvInstance Where to return the pointer to the instance data
301 * (size is @a cbInstance).
302 */
303RTDECL(int) RTVfsNewBaseObj(PCRTVFSOBJOPS pObjOps, size_t cbInstance, RTVFS hVfs, RTVFSLOCK hLock,
304 PRTVFSOBJ phVfsObj, void **ppvInstance);
305
306
307/**
308 * Additional operations for setting object attributes.
309 */
310typedef struct RTVFSOBJSETOPS
311{
312 /** The structure version (RTVFSOBJSETOPS_VERSION). */
313 uint32_t uVersion;
314 /** The offset to the RTVFSOBJOPS structure. */
315 int32_t offObjOps;
316
317 /**
318 * Set the unix style owner and group.
319 *
320 * @returns IPRT status code.
321 * @param pvThis The implementation specific file data.
322 * @param fMode The new mode bits.
323 * @param fMask The mask indicating which bits we are
324 * changing.
325 * @sa RTFileSetMode
326 */
327 DECLCALLBACKMEMBER(int, pfnSetMode)(void *pvThis, RTFMODE fMode, RTFMODE fMask);
328
329 /**
330 * Set the timestamps associated with the object.
331 *
332 * @returns IPRT status code.
333 * @param pvThis The implementation specific file data.
334 * @param pAccessTime Pointer to the new access time. NULL if not
335 * to be changed.
336 * @param pModificationTime Pointer to the new modifcation time. NULL if
337 * not to be changed.
338 * @param pChangeTime Pointer to the new change time. NULL if not
339 * to be changed.
340 * @param pBirthTime Pointer to the new time of birth. NULL if
341 * not to be changed.
342 * @remarks See RTFileSetTimes for restrictions and behavior imposed by the
343 * host OS or underlying VFS provider.
344 * @sa RTFileSetTimes
345 */
346 DECLCALLBACKMEMBER(int, pfnSetTimes)(void *pvThis, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
347 PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime);
348
349 /**
350 * Set the unix style owner and group.
351 *
352 * @returns IPRT status code.
353 * @param pvThis The implementation specific file data.
354 * @param uid The user ID of the new owner. NIL_RTUID if
355 * unchanged.
356 * @param gid The group ID of the new owner group. NIL_RTGID if
357 * unchanged.
358 * @sa RTFileSetOwner
359 */
360 DECLCALLBACKMEMBER(int, pfnSetOwner)(void *pvThis, RTUID uid, RTGID gid);
361
362 /** Marks the end of the structure (RTVFSOBJSETOPS_VERSION). */
363 uintptr_t uEndMarker;
364} RTVFSOBJSETOPS;
365/** Pointer to const object attribute setter operations. */
366typedef RTVFSOBJSETOPS const *PCRTVFSOBJSETOPS;
367
368/** The RTVFSOBJSETOPS structure version. */
369#define RTVFSOBJSETOPS_VERSION RT_MAKE_U32_FROM_U8(0xff,0x2f,1,0)
370
371
372/**
373 * The filesystem stream operations.
374 *
375 * @extends RTVFSOBJOPS
376 */
377typedef struct RTVFSFSSTREAMOPS
378{
379 /** The basic object operation. */
380 RTVFSOBJOPS Obj;
381 /** The structure version (RTVFSFSSTREAMOPS_VERSION). */
382 uint32_t uVersion;
383 /** Reserved field, MBZ. */
384 uint32_t fReserved;
385
386 /**
387 * Gets the next object in the stream.
388 *
389 * @returns IPRT status code.
390 * @retval VINF_SUCCESS if a new object was retrieved.
391 * @retval VERR_EOF when there are no more objects.
392 * @param pvThis The implementation specific directory data.
393 * @param ppszName Where to return the object name. Must be freed by
394 * calling RTStrFree.
395 * @param penmType Where to return the object type.
396 * @param hVfsObj Where to return the object handle (referenced).
397 * This must be cast to the desired type before use.
398 * @sa RTVfsFsStrmNext
399 */
400 DECLCALLBACKMEMBER(int, pfnNext)(void *pvThis, char **ppszName, RTVFSOBJTYPE *penmType, PRTVFSOBJ phVfsObj);
401
402 /** Marks the end of the structure (RTVFSFSSTREAMOPS_VERSION). */
403 uintptr_t uEndMarker;
404} RTVFSFSSTREAMOPS;
405/** Pointer to const object attribute setter operations. */
406typedef RTVFSFSSTREAMOPS const *PCRTVFSFSSTREAMOPS;
407
408/** The RTVFSFSSTREAMOPS structure version. */
409#define RTVFSFSSTREAMOPS_VERSION RT_MAKE_U32_FROM_U8(0xff,0x3f,1,0)
410
411
412/**
413 * Creates a new VFS filesystem stream handle.
414 *
415 * @returns IPRT status code
416 * @param pFsStreamOps The filesystem stream operations.
417 * @param cbInstance The size of the instance data.
418 * @param hVfs The VFS handle to associate this filesystem
419 * stream with. NIL_VFS is ok.
420 * @param hLock Handle to a custom lock to be used with the new
421 * object. The reference is consumed. NIL and
422 * special lock handles are fine.
423 * @param phVfsFss Where to return the new handle.
424 * @param ppvInstance Where to return the pointer to the instance data
425 * (size is @a cbInstance).
426 */
427RTDECL(int) RTVfsNewFsStream(PCRTVFSFSSTREAMOPS pFsStreamOps, size_t cbInstance, RTVFS hVfs, RTVFSLOCK hLock,
428 PRTVFSFSSTREAM phVfsFss, void **ppvInstance);
429
430
431/**
432 * The directory operations.
433 *
434 * @extends RTVFSOBJOPS
435 * @extends RTVFSOBJSETOPS
436 */
437typedef struct RTVFSDIROPS
438{
439 /** The basic object operation. */
440 RTVFSOBJOPS Obj;
441 /** The structure version (RTVFSDIROPS_VERSION). */
442 uint32_t uVersion;
443 /** Reserved field, MBZ. */
444 uint32_t fReserved;
445 /** The object setter operations. */
446 RTVFSOBJSETOPS ObjSet;
447
448 /**
449 * Opens a directory entry for traversal purposes.
450 *
451 * Method which sole purpose is helping the path traversal. Only one of
452 * the three output variables will be set, the others will left untouched
453 * (caller sets them to NIL).
454 *
455 * @returns IPRT status code.
456 * @retval VERR_PATH_NOT_FOUND if @a pszEntry was not found.
457 * @retval VERR_NOT_A_DIRECTORY if @a pszEntry isn't a directory or symlink.
458 * @param pvThis The implementation specific directory data.
459 * @param pszEntry The name of the directory entry to remove.
460 * @param phVfsDir If not NULL and it is a directory, open it and
461 * return the handle here.
462 * @param phVfsSymlink If not NULL and it is a symbolic link, open it
463 * and return the handle here.
464 * @param phVfsMounted If not NULL and it is a mounted VFS directory,
465 * reference it and return the handle here.
466 * @todo Should com dir, symlinks and mount points using some common
467 * ancestor "class".
468 */
469 DECLCALLBACKMEMBER(int, pfnTraversalOpen)(void *pvThis, const char *pszEntry, PRTVFSDIR phVfsDir,
470 PRTVFSSYMLINK phVfsSymlink, PRTVFS phVfsMounted);
471
472 /**
473 * Open or create a file.
474 *
475 * @returns IPRT status code.
476 * @param pvThis The implementation specific directory data.
477 * @param pszFilename The name of the immediate file to open or create.
478 * @param fOpen The open flags (RTFILE_O_XXX).
479 * @param phVfsFile Where to return the thandle to the opened file.
480 * @sa RTFileOpen.
481 */
482 DECLCALLBACKMEMBER(int, pfnOpenFile)(void *pvThis, const char *pszFilename, uint32_t fOpen, PRTVFSFILE phVfsFile);
483
484 /**
485 * Open an existing subdirectory.
486 *
487 * @returns IPRT status code.
488 * @param pvThis The implementation specific directory data.
489 * @param pszSubDir The name of the immediate subdirectory to open.
490 * @param phVfsDir Where to return the handle to the opened directory.
491 * @sa RTDirOpen.
492 */
493 DECLCALLBACKMEMBER(int, pfnOpenDir)(void *pvThis, const char *pszSubDir, uint32_t fFlags, PRTVFSDIR phVfsDir);
494
495 /**
496 * Creates a new subdirectory.
497 *
498 * @returns IPRT status code.
499 * @param pvThis The implementation specific directory data.
500 * @param pszSubDir The name of the immediate subdirectory to create.
501 * @param fMode The mode mask of the new directory.
502 * @param phVfsDir Where to optionally return the handle to the newly
503 * create directory.
504 * @sa RTDirCreate.
505 */
506 DECLCALLBACKMEMBER(int, pfnCreateDir)(void *pvThis, const char *pszSubDir, RTFMODE fMode, PRTVFSDIR phVfsDir);
507
508 /**
509 * Opens an existing symbolic link.
510 *
511 * @returns IPRT status code.
512 * @param pvThis The implementation specific directory data.
513 * @param pszSymlink The name of the immediate symbolic link to open.
514 * @param phVfsSymlink Where to optionally return the handle to the
515 * newly create symbolic link.
516 * @sa RTSymlinkCreate.
517 */
518 DECLCALLBACKMEMBER(int, pfnOpenSymlink)(void *pvThis, const char *pszSymlink, PRTVFSSYMLINK phVfsSymlink);
519
520 /**
521 * Creates a new symbolic link.
522 *
523 * @returns IPRT status code.
524 * @param pvThis The implementation specific directory data.
525 * @param pszSymlink The name of the immediate symbolic link to create.
526 * @param pszTarget The symbolic link target.
527 * @param enmType The symbolic link type.
528 * @param phVfsSymlink Where to optionally return the handle to the
529 * newly create symbolic link.
530 * @sa RTSymlinkCreate.
531 */
532 DECLCALLBACKMEMBER(int, pfnCreateSymlink)(void *pvThis, const char *pszSymlink, const char *pszTarget,
533 RTSYMLINKTYPE enmType, PRTVFSSYMLINK phVfsSymlink);
534
535 /**
536 * Query information about an entry.
537 *
538 * @returns IPRT status code.
539 * @param pvThis The implementation specific directory data.
540 * @param pszEntry The name of the directory entry to remove.
541 * @param pObjInfo Where to return the info on success.
542 * @param enmAddAttr Which set of additional attributes to request.
543 *
544 * @sa RTPathQueryInfo, RTVFSOBJOPS::pfnQueryInfo
545 */
546 DECLCALLBACKMEMBER(int, pfnQueryEntryInfo)(void *pvThis, const char *pszEntry,
547 PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr);
548
549 /**
550 * Removes a directory entry.
551 *
552 * @returns IPRT status code.
553 * @param pvThis The implementation specific directory data.
554 * @param pszEntry The name of the directory entry to remove.
555 * @param fType If non-zero, this restricts the type of the entry to
556 * the object type indicated by the mask
557 * (RTFS_TYPE_XXX).
558 * @sa RTFileRemove, RTDirRemove, RTSymlinkRemove.
559 */
560 DECLCALLBACKMEMBER(int, pfnUnlinkEntry)(void *pvThis, const char *pszEntry, RTFMODE fType);
561
562 /**
563 * Renames a directory entry.
564 *
565 * @returns IPRT status code.
566 * @param pvThis The implementation specific directory data.
567 * @param pszEntry The name of the directory entry to rename.
568 * @param fType If non-zero, this restricts the type of the entry to
569 * the object type indicated by the mask
570 * (RTFS_TYPE_XXX).
571 * @param pszNewName The new entry name.
572 * @sa RTPathRename
573 */
574 DECLCALLBACKMEMBER(int, pfnRenameEntry)(void *pvThis, const char *pszEntry, RTFMODE fType, const char *pszNewName);
575
576 /**
577 * Rewind the directory stream so that the next read returns the first
578 * entry.
579 *
580 * @returns IPRT status code.
581 * @param pvThis The implementation specific directory data.
582 */
583 DECLCALLBACKMEMBER(int, pfnRewindDir)(void *pvThis);
584
585 /**
586 * Rewind the directory stream so that the next read returns the first
587 * entry.
588 *
589 * @returns IPRT status code.
590 * @param pvThis The implementation specific directory data.
591 * @param pDirEntry Output buffer.
592 * @param pcbDirEntry Complicated, see RTDirReadEx.
593 * @param enmAddAttr Which set of additional attributes to request.
594 * @sa RTDirReadEx
595 */
596 DECLCALLBACKMEMBER(int, pfnReadDir)(void *pvThis, PRTDIRENTRYEX pDirEntry, size_t *pcbDirEntry, RTFSOBJATTRADD enmAddAttr);
597
598 /** Marks the end of the structure (RTVFSDIROPS_VERSION). */
599 uintptr_t uEndMarker;
600} RTVFSDIROPS;
601/** Pointer to const directory operations. */
602typedef RTVFSDIROPS const *PCRTVFSDIROPS;
603/** The RTVFSDIROPS structure version. */
604#define RTVFSDIROPS_VERSION RT_MAKE_U32_FROM_U8(0xff,0x4f,1,0)
605
606
607/**
608 * Creates a new VFS directory handle.
609 *
610 * @returns IPRT status code
611 * @param pDirOps The directory operations.
612 * @param cbInstance The size of the instance data.
613 * @param fFlags RTVFSDIR_F_XXX
614 * @param hVfs The VFS handle to associate this directory with.
615 * NIL_VFS is ok.
616 * @param hLock Handle to a custom lock to be used with the new
617 * object. The reference is consumed. NIL and
618 * special lock handles are fine.
619 * @param phVfsDir Where to return the new handle.
620 * @param ppvInstance Where to return the pointer to the instance data
621 * (size is @a cbInstance).
622 */
623RTDECL(int) RTVfsNewDir(PCRTVFSDIROPS pDirOps, size_t cbInstance, uint32_t fFlags, RTVFS hVfs, RTVFSLOCK hLock,
624 PRTVFSDIR phVfsDir, void **ppvInstance);
625
626/** @name RTVFSDIR_F_XXX
627 * @{ */
628/** Don't reference the @a hVfs parameter passed to RTVfsNewDir.
629 * This is a permanent root directory hack. */
630#define RTVFSDIR_F_NO_VFS_REF RT_BIT_32(0)
631/** @} */
632
633
634/**
635 * The symbolic link operations.
636 *
637 * @extends RTVFSOBJOPS
638 * @extends RTVFSOBJSETOPS
639 */
640typedef struct RTVFSSYMLINKOPS
641{
642 /** The basic object operation. */
643 RTVFSOBJOPS Obj;
644 /** The structure version (RTVFSSYMLINKOPS_VERSION). */
645 uint32_t uVersion;
646 /** Reserved field, MBZ. */
647 uint32_t fReserved;
648 /** The object setter operations. */
649 RTVFSOBJSETOPS ObjSet;
650
651 /**
652 * Read the symbolic link target.
653 *
654 * @returns IPRT status code.
655 * @param pvThis The implementation specific symbolic link data.
656 * @param pszTarget The target buffer.
657 * @param cbTarget The size of the target buffer.
658 * @sa RTSymlinkRead
659 */
660 DECLCALLBACKMEMBER(int, pfnRead)(void *pvThis, char *pszTarget, size_t cbTarget);
661
662 /** Marks the end of the structure (RTVFSSYMLINKOPS_VERSION). */
663 uintptr_t uEndMarker;
664} RTVFSSYMLINKOPS;
665/** Pointer to const symbolic link operations. */
666typedef RTVFSSYMLINKOPS const *PCRTVFSSYMLINKOPS;
667/** The RTVFSSYMLINKOPS structure version. */
668#define RTVFSSYMLINKOPS_VERSION RT_MAKE_U32_FROM_U8(0xff,0x5f,1,0)
669
670
671/**
672 * Creates a new VFS symlink handle.
673 *
674 * @returns IPRT status code
675 * @param pSymlinkOps The symlink operations.
676 * @param cbInstance The size of the instance data.
677 * @param hVfs The VFS handle to associate this symlink object
678 * with. NIL_VFS is ok.
679 * @param hLock Handle to a custom lock to be used with the new
680 * object. The reference is consumed. NIL and
681 * special lock handles are fine.
682 * @param phVfsSym Where to return the new handle.
683 * @param ppvInstance Where to return the pointer to the instance data
684 * (size is @a cbInstance).
685 */
686RTDECL(int) RTVfsNewSymlink(PCRTVFSSYMLINKOPS pSymlinkOps, size_t cbInstance, RTVFS hVfs, RTVFSLOCK hLock,
687 PRTVFSSYMLINK phVfsSym, void **ppvInstance);
688
689
690/**
691 * The basis for all I/O objects (files, pipes, sockets, devices, ++).
692 *
693 * @extends RTVFSOBJOPS
694 */
695typedef struct RTVFSIOSTREAMOPS
696{
697 /** The basic object operation. */
698 RTVFSOBJOPS Obj;
699 /** The structure version (RTVFSIOSTREAMOPS_VERSION). */
700 uint32_t uVersion;
701 /** Feature field. */
702 uint32_t fFeatures;
703
704 /**
705 * Reads from the file/stream.
706 *
707 * @returns IPRT status code. See RTVfsIoStrmRead.
708 * @param pvThis The implementation specific file data.
709 * @param off Where to read at, -1 for the current position.
710 * @param pSgBuf Gather buffer describing the bytes that are to be
711 * written.
712 * @param fBlocking If @c true, the call is blocking, if @c false it
713 * should not block.
714 * @param pcbRead Where return the number of bytes actually read.
715 * This is set it 0 by the caller. If NULL, try read
716 * all and fail if incomplete.
717 * @sa RTVfsIoStrmRead, RTVfsIoStrmSgRead, RTVfsFileRead,
718 * RTVfsFileReadAt, RTFileRead, RTFileReadAt.
719 */
720 DECLCALLBACKMEMBER(int, pfnRead)(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead);
721
722 /**
723 * Writes to the file/stream.
724 *
725 * @returns IPRT status code.
726 * @param pvThis The implementation specific file data.
727 * @param off Where to start wrinting, -1 for the current
728 * position.
729 * @param pSgBuf Gather buffers describing the bytes that are to be
730 * written.
731 * @param fBlocking If @c true, the call is blocking, if @c false it
732 * should not block.
733 * @param pcbWritten Where to return the number of bytes actually
734 * written. This is set it 0 by the caller. If
735 * NULL, try write it all and fail if incomplete.
736 * @sa RTFileWrite, RTFileWriteAt.
737 */
738 DECLCALLBACKMEMBER(int, pfnWrite)(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten);
739
740 /**
741 * Flushes any pending data writes to the stream.
742 *
743 * @returns IPRT status code.
744 * @param pvThis The implementation specific file data.
745 * @sa RTFileFlush.
746 */
747 DECLCALLBACKMEMBER(int, pfnFlush)(void *pvThis);
748
749 /**
750 * Poll for events.
751 *
752 * @returns IPRT status code.
753 * @param pvThis The implementation specific file data.
754 * @param fEvents The events to poll for (RTPOLL_EVT_XXX).
755 * @param cMillies How long to wait for event to eventuate.
756 * @param fIntr Whether the wait is interruptible and can return
757 * VERR_INTERRUPTED (@c true) or if this condition
758 * should be hidden from the caller (@c false).
759 * @param pfRetEvents Where to return the event mask.
760 * @sa RTPollSetAdd, RTPoll, RTPollNoResume.
761 */
762 DECLCALLBACKMEMBER(int, pfnPollOne)(void *pvThis, uint32_t fEvents, RTMSINTERVAL cMillies, bool fIntr,
763 uint32_t *pfRetEvents);
764
765 /**
766 * Tells the current file/stream position.
767 *
768 * @returns IPRT status code.
769 * @param pvThis The implementation specific file data.
770 * @param poffActual Where to return the actual offset.
771 * @sa RTFileTell
772 */
773 DECLCALLBACKMEMBER(int, pfnTell)(void *pvThis, PRTFOFF poffActual);
774
775 /**
776 * Skips @a cb ahead in the stream.
777 *
778 * @returns IPRT status code.
779 * @param pvThis The implementation specific file data.
780 * @param cb The number bytes to skip.
781 * @remarks This is optional and can be NULL.
782 */
783 DECLCALLBACKMEMBER(int, pfnSkip)(void *pvThis, RTFOFF cb);
784
785 /**
786 * Fills the stream with @a cb zeros.
787 *
788 * @returns IPRT status code.
789 * @param pvThis The implementation specific file data.
790 * @param cb The number of zero bytes to insert.
791 * @remarks This is optional and can be NULL.
792 */
793 DECLCALLBACKMEMBER(int, pfnZeroFill)(void *pvThis, RTFOFF cb);
794
795 /** Marks the end of the structure (RTVFSIOSTREAMOPS_VERSION). */
796 uintptr_t uEndMarker;
797} RTVFSIOSTREAMOPS;
798/** Pointer to const I/O stream operations. */
799typedef RTVFSIOSTREAMOPS const *PCRTVFSIOSTREAMOPS;
800
801/** The RTVFSIOSTREAMOPS structure version. */
802#define RTVFSIOSTREAMOPS_VERSION RT_MAKE_U32_FROM_U8(0xff,0x6f,1,0)
803
804/** @name RTVFSIOSTREAMOPS::fFeatures
805 * @{ */
806/** No scatter gather lists, thank you. */
807#define RTVFSIOSTREAMOPS_FEAT_NO_SG RT_BIT_32(0)
808/** Mask of the valid I/O stream feature flags. */
809#define RTVFSIOSTREAMOPS_FEAT_VALID_MASK UINT32_C(0x00000001)
810/** @} */
811
812
813/**
814 * Creates a new VFS I/O stream handle.
815 *
816 * @returns IPRT status code
817 * @param pIoStreamOps The I/O stream operations.
818 * @param cbInstance The size of the instance data.
819 * @param fOpen The open flags. The minimum is the access mask.
820 * @param hVfs The VFS handle to associate this I/O stream
821 * with. NIL_VFS is ok.
822 * @param hLock Handle to a custom lock to be used with the new
823 * object. The reference is consumed. NIL and
824 * special lock handles are fine.
825 * @param phVfsIos Where to return the new handle.
826 * @param ppvInstance Where to return the pointer to the instance data
827 * (size is @a cbInstance).
828 */
829RTDECL(int) RTVfsNewIoStream(PCRTVFSIOSTREAMOPS pIoStreamOps, size_t cbInstance, uint32_t fOpen, RTVFS hVfs, RTVFSLOCK hLock,
830 PRTVFSIOSTREAM phVfsIos, void **ppvInstance);
831
832
833/**
834 * Gets the private data of an I/O stream.
835 *
836 * @returns Pointer to the private data. NULL if the handle is invalid in some
837 * way.
838 * @param hVfsIos The I/O stream handle.
839 * @param pIoStreamOps The I/O stream operations. This servers as a
840 * sort of password.
841 */
842RTDECL(void *) RTVfsIoStreamToPrivate(RTVFSIOSTREAM hVfsIos, PCRTVFSIOSTREAMOPS pIoStreamOps);
843
844
845/**
846 * The file operations.
847 *
848 * @extends RTVFSIOSTREAMOPS
849 * @extends RTVFSOBJSETOPS
850 */
851typedef struct RTVFSFILEOPS
852{
853 /** The I/O stream and basis object operations. */
854 RTVFSIOSTREAMOPS Stream;
855 /** The structure version (RTVFSFILEOPS_VERSION). */
856 uint32_t uVersion;
857 /** Reserved field, MBZ. */
858 uint32_t fReserved;
859 /** The object setter operations. */
860 RTVFSOBJSETOPS ObjSet;
861
862 /**
863 * Changes the current file position.
864 *
865 * @returns IPRT status code.
866 * @param pvThis The implementation specific file data.
867 * @param offSeek The offset to seek.
868 * @param uMethod The seek method, i.e. what the seek is relative to.
869 * @param poffActual Where to return the actual offset.
870 * @sa RTFileSeek
871 */
872 DECLCALLBACKMEMBER(int, pfnSeek)(void *pvThis, RTFOFF offSeek, unsigned uMethod, PRTFOFF poffActual);
873
874 /**
875 * Get the current file/stream size.
876 *
877 * @returns IPRT status code.
878 * @param pvThis The implementation specific file data.
879 * @param pcbFile Where to store the current file size.
880 * @sa RTFileGetSize
881 */
882 DECLCALLBACKMEMBER(int, pfnQuerySize)(void *pvThis, uint64_t *pcbFile);
883
884 /** @todo There will be more methods here. */
885
886 /** Marks the end of the structure (RTVFSFILEOPS_VERSION). */
887 uintptr_t uEndMarker;
888} RTVFSFILEOPS;
889/** Pointer to const file operations. */
890typedef RTVFSFILEOPS const *PCRTVFSFILEOPS;
891
892/** The RTVFSFILEOPS structure version. */
893#define RTVFSFILEOPS_VERSION RT_MAKE_U32_FROM_U8(0xff,0x7f,1,0)
894
895/**
896 * Creates a new VFS file handle.
897 *
898 * @returns IPRT status code
899 * @param pFileOps The file operations.
900 * @param cbInstance The size of the instance data.
901 * @param fOpen The open flags. The minimum is the access mask.
902 * @param hVfs The VFS handle to associate this file with.
903 * NIL_VFS is ok.
904 * @param hLock Handle to a custom lock to be used with the new
905 * object. The reference is consumed. NIL and
906 * special lock handles are fine.
907 * @param phVfsFile Where to return the new handle.
908 * @param ppvInstance Where to return the pointer to the instance data
909 * (size is @a cbInstance).
910 */
911RTDECL(int) RTVfsNewFile(PCRTVFSFILEOPS pFileOps, size_t cbInstance, uint32_t fOpen, RTVFS hVfs, RTVFSLOCK hLock,
912 PRTVFSFILE phVfsFile, void **ppvInstance);
913
914
915/** @defgroup grp_rt_vfs_ll_util VFS Utility APIs
916 * @{ */
917
918/**
919 * Parsed path.
920 */
921typedef struct RTVFSPARSEDPATH
922{
923 /** The length of the path in szCopy. */
924 uint16_t cch;
925 /** The number of path components. */
926 uint16_t cComponents;
927 /** Set if the path ends with slash, indicating that it's a directory
928 * reference and not a file reference. The slash has been removed from
929 * the copy. */
930 bool fDirSlash;
931 /** The offset where each path component starts, i.e. the char after the
932 * slash. The array has cComponents + 1 entries, where the final one is
933 * cch + 1 so that one can always terminate the current component by
934 * szPath[aoffComponent[i] - 1] = '\0'. */
935 uint16_t aoffComponents[RTPATH_MAX / 2 + 1];
936 /** A normalized copy of the path.
937 * Reserve some extra space so we can be more relaxed about overflow
938 * checks and terminator paddings, especially when recursing. */
939 char szPath[RTPATH_MAX];
940} RTVFSPARSEDPATH;
941/** Pointer to a parsed path. */
942typedef RTVFSPARSEDPATH *PRTVFSPARSEDPATH;
943
944/** The max accepted path length.
945 * This must be a few chars shorter than RTVFSPARSEDPATH::szPath because we
946 * use two terminators and wish be a little bit lazy with checking. */
947#define RTVFSPARSEDPATH_MAX (RTPATH_MAX - 4)
948
949/**
950 * Appends @a pszPath (relative) to the already parsed path @a pPath.
951 *
952 * @retval VINF_SUCCESS
953 * @retval VERR_FILENAME_TOO_LONG
954 * @retval VERR_INTERNAL_ERROR_4
955 * @param pPath The parsed path to append @a pszPath onto.
956 * This is both input and output.
957 * @param pszPath The path to append. This must be relative.
958 * @param piRestartComp The component to restart parsing at. This is
959 * input/output. The input does not have to be
960 * within the valid range. Optional.
961 */
962RTDECL(int) RTVfsParsePathAppend(PRTVFSPARSEDPATH pPath, const char *pszPath, uint16_t *piRestartComp);
963
964/**
965 * Parses a path.
966 *
967 * @retval VINF_SUCCESS
968 * @retval VERR_FILENAME_TOO_LONG
969 * @param pPath Where to store the parsed path.
970 * @param pszPath The path to parse. Absolute or relative to @a
971 * pszCwd.
972 * @param pszCwd The current working directory. Must be
973 * absolute.
974 */
975RTDECL(int) RTVfsParsePath(PRTVFSPARSEDPATH pPath, const char *pszPath, const char *pszCwd);
976
977/**
978 * Same as RTVfsParsePath except that it allocates a temporary buffer.
979 *
980 * @retval VINF_SUCCESS
981 * @retval VERR_NO_TMP_MEMORY
982 * @retval VERR_FILENAME_TOO_LONG
983 * @param pszPath The path to parse. Absolute or relative to @a
984 * pszCwd.
985 * @param pszCwd The current working directory. Must be
986 * absolute.
987 * @param ppPath Where to store the pointer to the allocated
988 * buffer containing the parsed path. This must
989 * be freed by calling RTVfsParsePathFree. NULL
990 * will be stored on failured.
991 */
992RTDECL(int) RTVfsParsePathA(const char *pszPath, const char *pszCwd, PRTVFSPARSEDPATH *ppPath);
993
994/**
995 * Frees a buffer returned by RTVfsParsePathA.
996 *
997 * @param pPath The parsed path buffer to free. NULL is fine.
998 */
999RTDECL(void) RTVfsParsePathFree(PRTVFSPARSEDPATH pPath);
1000
1001/**
1002 * Dummy implementation of RTVFSIOSTREAMOPS::pfnPollOne.
1003 *
1004 * This handles the case where there is no chance any events my be raised and
1005 * all that is required is to wait according to the parameters.
1006 *
1007 * @returns IPRT status code.
1008 * @param fEvents The events to poll for (RTPOLL_EVT_XXX).
1009 * @param cMillies How long to wait for event to eventuate.
1010 * @param fIntr Whether the wait is interruptible and can return
1011 * VERR_INTERRUPTED (@c true) or if this condition
1012 * should be hidden from the caller (@c false).
1013 * @param pfRetEvents Where to return the event mask.
1014 * @sa RTVFSIOSTREAMOPS::pfnPollOne, RTPollSetAdd, RTPoll, RTPollNoResume.
1015 */
1016RTDECL(int) RTVfsUtilDummyPollOne(uint32_t fEvents, RTMSINTERVAL cMillies, bool fIntr, uint32_t *pfRetEvents);
1017
1018/** @} */
1019
1020
1021/** @defgroup grp_rt_vfs_lowlevel_chain VFS Chains (Low Level)
1022 * @ref grp_rt_vfs_chain
1023 * @{
1024 */
1025
1026/** Pointer to a VFS chain element registration record. */
1027typedef struct RTVFSCHAINELEMENTREG *PRTVFSCHAINELEMENTREG;
1028/** Pointer to a const VFS chain element registration record. */
1029typedef struct RTVFSCHAINELEMENTREG const *PCRTVFSCHAINELEMENTREG;
1030
1031/**
1032 * VFS chain element argument.
1033 */
1034typedef struct RTVFSCHAINELEMENTARG
1035{
1036 /** The string argument value. */
1037 char *psz;
1038 /** The specification offset of this argument. */
1039 uint16_t offSpec;
1040 /** Provider specific value. */
1041 uint64_t uProvider;
1042} RTVFSCHAINELEMENTARG;
1043/** Pointer to a VFS chain element argument. */
1044typedef RTVFSCHAINELEMENTARG *PRTVFSCHAINELEMENTARG;
1045
1046
1047/**
1048 * VFS chain element specification.
1049 */
1050typedef struct RTVFSCHAINELEMSPEC
1051{
1052 /** The provider name.
1053 * This can be NULL if this is the final component and it's just a path. */
1054 char *pszProvider;
1055 /** The input type, RTVFSOBJTYPE_INVALID if first. */
1056 RTVFSOBJTYPE enmTypeIn;
1057 /** The element type.
1058 * RTVFSOBJTYPE_END if this is the final component and it's just a path. */
1059 RTVFSOBJTYPE enmType;
1060 /** The input spec offset of this element. */
1061 uint16_t offSpec;
1062 /** The length of the input spec. */
1063 uint16_t cchSpec;
1064 /** The number of arguments. */
1065 uint32_t cArgs;
1066 /** Arguments. */
1067 PRTVFSCHAINELEMENTARG paArgs;
1068
1069 /** The provider. */
1070 PCRTVFSCHAINELEMENTREG pProvider;
1071 /** Provider specific value. */
1072 uint64_t uProvider;
1073 /** The object (with reference). */
1074 RTVFSOBJ hVfsObj;
1075} RTVFSCHAINELEMSPEC;
1076/** Pointer to a chain element specification. */
1077typedef RTVFSCHAINELEMSPEC *PRTVFSCHAINELEMSPEC;
1078/** Pointer to a const chain element specification. */
1079typedef RTVFSCHAINELEMSPEC const *PCRTVFSCHAINELEMSPEC;
1080
1081
1082/**
1083 * Parsed VFS chain specification.
1084 */
1085typedef struct RTVFSCHAINSPEC
1086{
1087 /** Open directory flags (RTFILE_O_XXX). */
1088 uint32_t fOpenFile;
1089 /** To be defined. */
1090 uint32_t fOpenDir;
1091 /** The type desired by the caller. */
1092 RTVFSOBJTYPE enmDesiredType;
1093 /** The number of elements. */
1094 uint32_t cElements;
1095 /** The elements. */
1096 PRTVFSCHAINELEMSPEC paElements;
1097} RTVFSCHAINSPEC;
1098/** Pointer to a parsed VFS chain specification. */
1099typedef RTVFSCHAINSPEC *PRTVFSCHAINSPEC;
1100/** Pointer to a const, parsed VFS chain specification. */
1101typedef RTVFSCHAINSPEC const *PCRTVFSCHAINSPEC;
1102
1103
1104/**
1105 * A chain element provider registration record.
1106 */
1107typedef struct RTVFSCHAINELEMENTREG
1108{
1109 /** The version (RTVFSCHAINELEMENTREG_VERSION). */
1110 uint32_t uVersion;
1111 /** Reserved, MBZ. */
1112 uint32_t fReserved;
1113 /** The provider name (unique). */
1114 const char *pszName;
1115 /** For chaining the providers. */
1116 RTLISTNODE ListEntry;
1117 /** Help text. */
1118 const char *pszHelp;
1119
1120 /**
1121 * Checks the element specification.
1122 *
1123 * This is allowed to parse arguments and use pSpec->uProvider and
1124 * pElement->paArgs[].uProvider to store information that pfnInstantiate and
1125 * pfnCanReuseElement may use later on, thus avoiding duplicating work/code.
1126 *
1127 * @returns IPRT status code.
1128 * @param pProviderReg Pointer to the element provider registration.
1129 * @param pSpec The chain specification.
1130 * @param pElement The chain element specification to validate.
1131 * @param poffError Where to return error offset on failure. This is
1132 * set to the pElement->offSpec on input, so it only
1133 * needs to be adjusted if an argument is at fault.
1134 * @param pErrInfo Where to return additional error information, if
1135 * available. Optional.
1136 */
1137 DECLCALLBACKMEMBER(int, pfnValidate)(PCRTVFSCHAINELEMENTREG pProviderReg, PRTVFSCHAINSPEC pSpec,
1138 PRTVFSCHAINELEMSPEC pElement, uint32_t *poffError, PRTERRINFO pErrInfo);
1139
1140 /**
1141 * Create a VFS object according to the element specification.
1142 *
1143 * @returns IPRT status code.
1144 * @param pProviderReg Pointer to the element provider registration.
1145 * @param pSpec The chain specification.
1146 * @param pElement The chain element specification to instantiate.
1147 * @param hPrevVfsObj Handle to the previous VFS object, NIL_RTVFSOBJ if
1148 * first.
1149 * @param phVfsObj Where to return the VFS object handle.
1150 * @param poffError Where to return error offset on failure. This is
1151 * set to the pElement->offSpec on input, so it only
1152 * needs to be adjusted if an argument is at fault.
1153 * @param pErrInfo Where to return additional error information, if
1154 * available. Optional.
1155 */
1156 DECLCALLBACKMEMBER(int, pfnInstantiate)(PCRTVFSCHAINELEMENTREG pProviderReg, PCRTVFSCHAINSPEC pSpec,
1157 PCRTVFSCHAINELEMSPEC pElement, RTVFSOBJ hPrevVfsObj,
1158 PRTVFSOBJ phVfsObj, uint32_t *poffError, PRTERRINFO pErrInfo);
1159
1160 /**
1161 * Determins whether the element can be reused.
1162 *
1163 * This is for handling situations accessing the same file system twice, like
1164 * for both the source and destiation of a copy operation. This allows not only
1165 * sharing resources and avoid doing things twice, but also helps avoid file
1166 * sharing violations and inconsistencies araising from the image being updated
1167 * and read independently.
1168 *
1169 * @returns true if the element from @a pReuseSpec an be reused, false if not.
1170 * @param pProviderReg Pointer to the element provider registration.
1171 * @param pSpec The chain specification.
1172 * @param pElement The chain element specification.
1173 * @param pReuseSpec The chain specification of the existing chain.
1174 * @param pReuseElement The chain element specification of the existing
1175 * element that is being considered for reuse.
1176 */
1177 DECLCALLBACKMEMBER(bool, pfnCanReuseElement)(PCRTVFSCHAINELEMENTREG pProviderReg,
1178 PCRTVFSCHAINSPEC pSpec, PCRTVFSCHAINELEMSPEC pElement,
1179 PCRTVFSCHAINSPEC pReuseSpec, PCRTVFSCHAINELEMSPEC pReuseElement);
1180
1181 /** End marker (RTVFSCHAINELEMENTREG_VERSION). */
1182 uintptr_t uEndMarker;
1183} RTVFSCHAINELEMENTREG;
1184
1185/** The VFS chain element registration record version number. */
1186#define RTVFSCHAINELEMENTREG_VERSION RT_MAKE_U32_FROM_U8(0xff, 0x7f, 1, 0)
1187
1188
1189/**
1190 * Parses the specification.
1191 *
1192 * @returns IPRT status code.
1193 * @param pszSpec The specification string to parse.
1194 * @param fFlags Flags, see RTVFSCHAIN_PF_XXX.
1195 * @param enmDesiredType The object type the caller wants to interface with.
1196 * @param ppSpec Where to return the pointer to the parsed
1197 * specification. This must be freed by calling
1198 * RTVfsChainSpecFree. Will always be set (unless
1199 * invalid parameters.)
1200 * @param poffError Where to return the offset into the input
1201 * specification of what's causing trouble. Always
1202 * set, unless this argument causes an invalid pointer
1203 * error.
1204 */
1205RTDECL(int) RTVfsChainSpecParse(const char *pszSpec, uint32_t fFlags, RTVFSOBJTYPE enmDesiredType,
1206 PRTVFSCHAINSPEC *ppSpec, uint32_t *poffError);
1207
1208/** @name RTVfsChainSpecParse
1209 * @{ */
1210/** Mask of valid flags. */
1211#define RTVFSCHAIN_PF_VALID_MASK UINT32_C(0x00000000)
1212/** @} */
1213
1214/**
1215 * Checks and setups the chain.
1216 *
1217 * @returns IPRT status code.
1218 * @param pSpec The parsed specification.
1219 * @param pReuseSpec Spec to reuse if applicable. Optional.
1220 * @param phVfsObj Where to return the VFS object.
1221 * @param ppszFinalPath Where to return the pointer to the final path if
1222 * applicable. The caller needs to check whether this
1223 * is NULL or a path, in the former case nothing more
1224 * needs doing, whereas in the latter the caller must
1225 * perform the desired operation(s) on *phVfsObj using
1226 * the final path.
1227 * @param poffError Where to return the offset into the input
1228 * specification of what's causing trouble. Always
1229 * set, unless this argument causes an invalid pointer
1230 * error.
1231 * @param pErrInfo Where to return additional error information, if
1232 * available. Optional.
1233 */
1234RTDECL(int) RTVfsChainSpecCheckAndSetup(PRTVFSCHAINSPEC pSpec, PCRTVFSCHAINSPEC pReuseSpec,
1235 PRTVFSOBJ phVfsObj, const char **ppszFinalPath, uint32_t *poffError, PRTERRINFO pErrInfo);
1236
1237/**
1238 * Frees a parsed chain specification.
1239 *
1240 * @param pSpec What RTVfsChainSpecParse returned. NULL is
1241 * quietly ignored.
1242 */
1243RTDECL(void) RTVfsChainSpecFree(PRTVFSCHAINSPEC pSpec);
1244
1245/**
1246 * Registers a chain element provider.
1247 *
1248 * @returns IPRT status code
1249 * @param pRegRec The registration record.
1250 * @param fFromCtor Indicates where we're called from.
1251 */
1252RTDECL(int) RTVfsChainElementRegisterProvider(PRTVFSCHAINELEMENTREG pRegRec, bool fFromCtor);
1253
1254/**
1255 * Deregisters a chain element provider.
1256 *
1257 * @returns IPRT status code
1258 * @param pRegRec The registration record.
1259 * @param fFromDtor Indicates where we're called from.
1260 */
1261RTDECL(int) RTVfsChainElementDeregisterProvider(PRTVFSCHAINELEMENTREG pRegRec, bool fFromDtor);
1262
1263
1264/** @def RTVFSCHAIN_AUTO_REGISTER_ELEMENT_PROVIDER
1265 * Automatically registers a chain element provider using a global constructor
1266 * and destructor hack.
1267 *
1268 * @param pRegRec Pointer to the registration record.
1269 * @param name Some unique variable name prefix.
1270 */
1271
1272#ifdef __cplusplus
1273/**
1274 * Class used for registering a VFS chain element provider.
1275 */
1276class RTVfsChainElementAutoRegisterHack
1277{
1278private:
1279 /** The registration record, NULL if registration failed. */
1280 PRTVFSCHAINELEMENTREG m_pRegRec;
1281
1282public:
1283 RTVfsChainElementAutoRegisterHack(PRTVFSCHAINELEMENTREG a_pRegRec)
1284 : m_pRegRec(a_pRegRec)
1285 {
1286 int rc = RTVfsChainElementRegisterProvider(m_pRegRec, true);
1287 if (RT_FAILURE(rc))
1288 m_pRegRec = NULL;
1289 }
1290
1291 ~RTVfsChainElementAutoRegisterHack()
1292 {
1293 RTVfsChainElementDeregisterProvider(m_pRegRec, true);
1294 m_pRegRec = NULL;
1295 }
1296};
1297
1298# define RTVFSCHAIN_AUTO_REGISTER_ELEMENT_PROVIDER(pRegRec, name) \
1299 static RTVfsChainElementAutoRegisterHack name ## AutoRegistrationHack(pRegRec)
1300
1301#else
1302# define RTVFSCHAIN_AUTO_REGISTER_ELEMENT_PROVIDER(pRegRec, name) \
1303 extern void *name ## AutoRegistrationHack = \
1304 &Sorry_but_RTVFSCHAIN_AUTO_REGISTER_ELEMENT_PROVIDER_does_not_work_in_c_source_files
1305#endif
1306
1307
1308/**
1309 * Common worker for the 'stdfile' and 'open' providers for implementing
1310 * RTVFSCHAINELEMENTREG::pfnValidate.
1311 *
1312 * Stores the RTFILE_O_XXX flags in pSpec->uProvider.
1313 *
1314 * @returns IPRT status code.
1315 * @param pSpec The chain specification.
1316 * @param pElement The chain element specification to validate.
1317 * @param poffError Where to return error offset on failure. This is set to
1318 * the pElement->offSpec on input, so it only needs to be
1319 * adjusted if an argument is at fault.
1320 * @param pErrInfo Where to return additional error information, if
1321 * available. Optional.
1322 */
1323RTDECL(int) RTVfsChainValidateOpenFileOrIoStream(PRTVFSCHAINSPEC pSpec, PRTVFSCHAINELEMSPEC pElement,
1324 uint32_t *poffError, PRTERRINFO pErrInfo);
1325
1326
1327/** @} */
1328
1329
1330/** @} */
1331
1332RT_C_DECLS_END
1333
1334#endif /* !___iprt_vfslowlevel_h */
1335
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