VirtualBox

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

Last change on this file since 83941 was 82968, checked in by vboxsync, 5 years ago

Copyright year updates by scm.

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