VirtualBox

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

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

IPRT: Some more tar vfs writer bits.

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