1 | /** @file
|
---|
2 | * IPRT - Virtual Filesystem.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2010 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 |
|
---|
35 | RT_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 | */
|
---|
50 | typedef 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. */
|
---|
67 | typedef struct RTVFSLOCKINTERNAL *RTVFSLOCK;
|
---|
68 | /** Pointer to a VFS lock handle. */
|
---|
69 | typedef 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 | */
|
---|
86 | RTDECL(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 | */
|
---|
94 | RTDECL(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 | */
|
---|
103 | RTDECL(RTVFSLOCKTYPE) RTVfsLockGetType(RTVFSLOCK hLock);
|
---|
104 |
|
---|
105 |
|
---|
106 |
|
---|
107 | RTDECL(void) RTVfsLockAcquireReadSlow(RTVFSLOCK hLock);
|
---|
108 | RTDECL(void) RTVfsLockReleaseReadSlow(RTVFSLOCK hLock);
|
---|
109 | RTDECL(void) RTVfsLockAcquireWriteSlow(RTVFSLOCK hLock);
|
---|
110 | RTDECL(void) RTVfsLockReleaseWriteSlow(RTVFSLOCK hLock);
|
---|
111 | /** @} */
|
---|
112 |
|
---|
113 | /**
|
---|
114 | * Acquire a read lock.
|
---|
115 | *
|
---|
116 | * @param hLock The lock handle, can be NIL.
|
---|
117 | */
|
---|
118 | DECLINLINE(void) RTVfsLockAcquireRead(RTVFSLOCK hLock)
|
---|
119 | {
|
---|
120 | if (hLock != NIL_RTVFSLOCK)
|
---|
121 | RTVfsLockAcquireReadSlow(hLock);
|
---|
122 | }
|
---|
123 |
|
---|
124 |
|
---|
125 | /**
|
---|
126 | * Release a read lock.
|
---|
127 | *
|
---|
128 | * @param hLock The lock handle, can be NIL.
|
---|
129 | */
|
---|
130 | DECLINLINE(void) RTVfsLockReleaseRead(RTVFSLOCK hLock)
|
---|
131 | {
|
---|
132 | if (hLock != NIL_RTVFSLOCK)
|
---|
133 | RTVfsLockReleaseReadSlow(hLock);
|
---|
134 | }
|
---|
135 |
|
---|
136 |
|
---|
137 | /**
|
---|
138 | * Acquire a write lock.
|
---|
139 | *
|
---|
140 | * @param hLock The lock handle, can be NIL.
|
---|
141 | */
|
---|
142 | DECLINLINE(void) RTVfsLockAcquireWrite(RTVFSLOCK hLock)
|
---|
143 | {
|
---|
144 | if (hLock != NIL_RTVFSLOCK)
|
---|
145 | RTVfsLockAcquireWriteSlow(hLock);
|
---|
146 | }
|
---|
147 |
|
---|
148 |
|
---|
149 | /**
|
---|
150 | * Release a write lock.
|
---|
151 | *
|
---|
152 | * @param hLock The lock handle, can be NIL.
|
---|
153 | */
|
---|
154 | DECLINLINE(void) RTVfsLockReleaseWrite(RTVFSLOCK hLock)
|
---|
155 | {
|
---|
156 | if (hLock != NIL_RTVFSLOCK)
|
---|
157 | RTVfsLockReleaseWriteSlow(hLock);
|
---|
158 | }
|
---|
159 |
|
---|
160 | /** @} */
|
---|
161 |
|
---|
162 | /**
|
---|
163 | * The VFS operations.
|
---|
164 | */
|
---|
165 | typedef struct RTVFSOPS
|
---|
166 | {
|
---|
167 | /** The structure version (RTVFSOPS_VERSION). */
|
---|
168 | uint32_t uVersion;
|
---|
169 | /** The virtual file system feature mask. */
|
---|
170 | uint32_t fFeatures;
|
---|
171 | /** The name of the operations. */
|
---|
172 | const char *pszName;
|
---|
173 |
|
---|
174 | /**
|
---|
175 | * Destructor.
|
---|
176 | *
|
---|
177 | * @param pvThis The implementation specific data.
|
---|
178 | */
|
---|
179 | DECLCALLBACKMEMBER(void, pfnDestroy)(void *pvThis);
|
---|
180 |
|
---|
181 | /**
|
---|
182 | * Opens the root directory.
|
---|
183 | *
|
---|
184 | * @returns IPRT status code.
|
---|
185 | * @param pvThis The implementation specific data.
|
---|
186 | * @param phVfsDir Where to return the handle to the root directory.
|
---|
187 | */
|
---|
188 | DECLCALLBACKMEMBER(int, pfnOpenRoot)(void *pvThis, PRTVFSDIR phVfsDir);
|
---|
189 |
|
---|
190 | /** @todo There will be more methods here to optimize opening and
|
---|
191 | * querying. */
|
---|
192 |
|
---|
193 | #if 0
|
---|
194 | /**
|
---|
195 | * Optional entry point for optimizing path traversal within the file system.
|
---|
196 | *
|
---|
197 | * @returns IPRT status code.
|
---|
198 | * @param pvThis The implementation specific data.
|
---|
199 | * @param pszPath The path to resolve.
|
---|
200 | * @param poffPath The current path offset on input, what we've
|
---|
201 | * traversed to on successful return.
|
---|
202 | * @param phVfs??? Return handle to what we've traversed.
|
---|
203 | * @param p??? Return other stuff...
|
---|
204 | */
|
---|
205 | DECLCALLBACKMEMBER(int, pfnTraverse)(void *pvThis, const char *pszPath, size_t *poffPath, PRTVFS??? phVfs?, ???* p???);
|
---|
206 | #endif
|
---|
207 |
|
---|
208 | /** Marks the end of the structure (RTVFSOPS_VERSION). */
|
---|
209 | uintptr_t uEndMarker;
|
---|
210 | } RTVFSOPS;
|
---|
211 | /** Pointer to constant VFS operations. */
|
---|
212 | typedef RTVFSOPS const *PCRTVFSOPS;
|
---|
213 |
|
---|
214 | /** The RTVFSOPS structure version. */
|
---|
215 | #define RTVFSOPS_VERSION RT_MAKE_U32_FROM_U8(0xff,0x0f,1,0)
|
---|
216 |
|
---|
217 | /** @name RTVFSOPS::fFeatures
|
---|
218 | * @{ */
|
---|
219 | /** The VFS supports attaching other systems. */
|
---|
220 | #define RTVFSOPS_FEAT_ATTACH RT_BIT_32(0)
|
---|
221 | /** @} */
|
---|
222 |
|
---|
223 |
|
---|
224 | /**
|
---|
225 | * The basis for all virtual file system objects except RTVFS.
|
---|
226 | */
|
---|
227 | typedef struct RTVFSOBJOPS
|
---|
228 | {
|
---|
229 | /** The structure version (RTVFSOBJOPS_VERSION). */
|
---|
230 | uint32_t uVersion;
|
---|
231 | /** The object type for type introspection. */
|
---|
232 | RTVFSOBJTYPE enmType;
|
---|
233 | /** The name of the operations. */
|
---|
234 | const char *pszName;
|
---|
235 |
|
---|
236 | /**
|
---|
237 | * Close the object.
|
---|
238 | *
|
---|
239 | * @returns IPRT status code.
|
---|
240 | * @param pvThis The implementation specific file data.
|
---|
241 | */
|
---|
242 | DECLCALLBACKMEMBER(int, pfnClose)(void *pvThis);
|
---|
243 |
|
---|
244 | /**
|
---|
245 | * Get information about the file.
|
---|
246 | *
|
---|
247 | * @returns IPRT status code. See RTVfsObjQueryInfo.
|
---|
248 | * @param pvThis The implementation specific file data.
|
---|
249 | * @param pObjInfo Where to return the object info on success.
|
---|
250 | * @param enmAddAttr Which set of additional attributes to request.
|
---|
251 | * @sa RTVfsObjQueryInfo, RTFileQueryInfo, RTPathQueryInfo
|
---|
252 | */
|
---|
253 | DECLCALLBACKMEMBER(int, pfnQueryInfo)(void *pvThis, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr);
|
---|
254 |
|
---|
255 | /** Marks the end of the structure (RTVFSOBJOPS_VERSION). */
|
---|
256 | uintptr_t uEndMarker;
|
---|
257 | } RTVFSOBJOPS;
|
---|
258 | /** Pointer to constant VFS object operations. */
|
---|
259 | typedef RTVFSOBJOPS const *PCRTVFSOBJOPS;
|
---|
260 |
|
---|
261 | /** The RTVFSOBJOPS structure version. */
|
---|
262 | #define RTVFSOBJOPS_VERSION RT_MAKE_U32_FROM_U8(0xff,0x1f,1,0)
|
---|
263 |
|
---|
264 |
|
---|
265 | /**
|
---|
266 | * Creates a new VFS base object handle.
|
---|
267 | *
|
---|
268 | * @returns IPRT status code
|
---|
269 | * @param pObjOps The base object operations.
|
---|
270 | * @param cbInstance The size of the instance data.
|
---|
271 | * @param hVfs The VFS handle to associate this base object
|
---|
272 | * with. NIL_VFS is ok.
|
---|
273 | * @param hLock Handle to a custom lock to be used with the new
|
---|
274 | * object. The reference is consumed. NIL and
|
---|
275 | * special lock handles are fine.
|
---|
276 | * @param phVfsFss Where to return the new handle.
|
---|
277 | * @param ppvInstance Where to return the pointer to the instance data
|
---|
278 | * (size is @a cbInstance).
|
---|
279 | */
|
---|
280 | RTDECL(int) RTVfsNewBaseObj(PCRTVFSOBJOPS pObjOps, size_t cbInstance, RTVFS hVfs, RTVFSLOCK hLock,
|
---|
281 | PRTVFSOBJ phVfsObj, void **ppvInstance);
|
---|
282 |
|
---|
283 |
|
---|
284 | /**
|
---|
285 | * Additional operations for setting object attributes.
|
---|
286 | */
|
---|
287 | typedef struct RTVFSOBJSETOPS
|
---|
288 | {
|
---|
289 | /** The structure version (RTVFSOBJSETOPS_VERSION). */
|
---|
290 | uint32_t uVersion;
|
---|
291 | /** The offset to the RTVFSOBJOPS structure. */
|
---|
292 | int32_t offObjOps;
|
---|
293 |
|
---|
294 | /**
|
---|
295 | * Set the unix style owner and group.
|
---|
296 | *
|
---|
297 | * @returns IPRT status code.
|
---|
298 | * @param pvThis The implementation specific file data.
|
---|
299 | * @param fMode The new mode bits.
|
---|
300 | * @param fMask The mask indicating which bits we are
|
---|
301 | * changing.
|
---|
302 | * @sa RTFileSetMode
|
---|
303 | */
|
---|
304 | DECLCALLBACKMEMBER(int, pfnSetMode)(void *pvThis, RTFMODE fMode, RTFMODE fMask);
|
---|
305 |
|
---|
306 | /**
|
---|
307 | * Set the timestamps associated with the object.
|
---|
308 | *
|
---|
309 | * @returns IPRT status code.
|
---|
310 | * @param pvThis The implementation specific file data.
|
---|
311 | * @param pAccessTime Pointer to the new access time. NULL if not
|
---|
312 | * to be changed.
|
---|
313 | * @param pModificationTime Pointer to the new modifcation time. NULL if
|
---|
314 | * not to be changed.
|
---|
315 | * @param pChangeTime Pointer to the new change time. NULL if not
|
---|
316 | * to be changed.
|
---|
317 | * @param pBirthTime Pointer to the new time of birth. NULL if
|
---|
318 | * not to be changed.
|
---|
319 | * @remarks See RTFileSetTimes for restrictions and behavior imposed by the
|
---|
320 | * host OS or underlying VFS provider.
|
---|
321 | * @sa RTFileSetTimes
|
---|
322 | */
|
---|
323 | DECLCALLBACKMEMBER(int, pfnSetTimes)(void *pvThis, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
|
---|
324 | PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime);
|
---|
325 |
|
---|
326 | /**
|
---|
327 | * Set the unix style owner and group.
|
---|
328 | *
|
---|
329 | * @returns IPRT status code.
|
---|
330 | * @param pvThis The implementation specific file data.
|
---|
331 | * @param uid The user ID of the new owner. NIL_RTUID if
|
---|
332 | * unchanged.
|
---|
333 | * @param gid The group ID of the new owner group. NIL_RTGID if
|
---|
334 | * unchanged.
|
---|
335 | * @sa RTFileSetOwner
|
---|
336 | */
|
---|
337 | DECLCALLBACKMEMBER(int, pfnSetOwner)(void *pvThis, RTUID uid, RTGID gid);
|
---|
338 |
|
---|
339 | /** Marks the end of the structure (RTVFSOBJSETOPS_VERSION). */
|
---|
340 | uintptr_t uEndMarker;
|
---|
341 | } RTVFSOBJSETOPS;
|
---|
342 | /** Pointer to const object attribute setter operations. */
|
---|
343 | typedef RTVFSOBJSETOPS const *PCRTVFSOBJSETOPS;
|
---|
344 |
|
---|
345 | /** The RTVFSOBJSETOPS structure version. */
|
---|
346 | #define RTVFSOBJSETOPS_VERSION RT_MAKE_U32_FROM_U8(0xff,0x2f,1,0)
|
---|
347 |
|
---|
348 |
|
---|
349 | /**
|
---|
350 | * The filesystem stream operations.
|
---|
351 | *
|
---|
352 | * @extends RTVFSOBJOPS
|
---|
353 | */
|
---|
354 | typedef struct RTVFSFSSTREAMOPS
|
---|
355 | {
|
---|
356 | /** The basic object operation. */
|
---|
357 | RTVFSOBJOPS Obj;
|
---|
358 | /** The structure version (RTVFSFSSTREAMOPS_VERSION). */
|
---|
359 | uint32_t uVersion;
|
---|
360 | /** Reserved field, MBZ. */
|
---|
361 | uint32_t fReserved;
|
---|
362 |
|
---|
363 | /**
|
---|
364 | * Gets the next object in the stream.
|
---|
365 | *
|
---|
366 | * @returns IPRT status code.
|
---|
367 | * @retval VINF_SUCCESS if a new object was retrieved.
|
---|
368 | * @retval VERR_EOF when there are no more objects.
|
---|
369 | * @param pvThis The implementation specific directory data.
|
---|
370 | * @param ppszName Where to return the object name. Must be freed by
|
---|
371 | * calling RTStrFree.
|
---|
372 | * @param penmType Where to return the object type.
|
---|
373 | * @param hVfsObj Where to return the object handle (referenced).
|
---|
374 | * This must be cast to the desired type before use.
|
---|
375 | * @sa RTVfsFsStrmNext
|
---|
376 | */
|
---|
377 | DECLCALLBACKMEMBER(int, pfnNext)(void *pvThis, char **ppszName, RTVFSOBJTYPE *penmType, PRTVFSOBJ phVfsObj);
|
---|
378 |
|
---|
379 | /** Marks the end of the structure (RTVFSFSSTREAMOPS_VERSION). */
|
---|
380 | uintptr_t uEndMarker;
|
---|
381 | } RTVFSFSSTREAMOPS;
|
---|
382 | /** Pointer to const object attribute setter operations. */
|
---|
383 | typedef RTVFSFSSTREAMOPS const *PCRTVFSFSSTREAMOPS;
|
---|
384 |
|
---|
385 | /** The RTVFSFSSTREAMOPS structure version. */
|
---|
386 | #define RTVFSFSSTREAMOPS_VERSION RT_MAKE_U32_FROM_U8(0xff,0x3f,1,0)
|
---|
387 |
|
---|
388 |
|
---|
389 | /**
|
---|
390 | * Creates a new VFS filesystem stream handle.
|
---|
391 | *
|
---|
392 | * @returns IPRT status code
|
---|
393 | * @param pFsStreamOps The filesystem stream operations.
|
---|
394 | * @param cbInstance The size of the instance data.
|
---|
395 | * @param hVfs The VFS handle to associate this filesystem
|
---|
396 | * stream with. NIL_VFS is ok.
|
---|
397 | * @param hLock Handle to a custom lock to be used with the new
|
---|
398 | * object. The reference is consumed. NIL and
|
---|
399 | * special lock handles are fine.
|
---|
400 | * @param phVfsFss Where to return the new handle.
|
---|
401 | * @param ppvInstance Where to return the pointer to the instance data
|
---|
402 | * (size is @a cbInstance).
|
---|
403 | */
|
---|
404 | RTDECL(int) RTVfsNewFsStream(PCRTVFSFSSTREAMOPS pFsStreamOps, size_t cbInstance, RTVFS hVfs, RTVFSLOCK hLock,
|
---|
405 | PRTVFSFSSTREAM phVfsFss, void **ppvInstance);
|
---|
406 |
|
---|
407 |
|
---|
408 | /**
|
---|
409 | * The directory operations.
|
---|
410 | *
|
---|
411 | * @extends RTVFSOBJOPS
|
---|
412 | * @extends RTVFSOBJSETOPS
|
---|
413 | */
|
---|
414 | typedef struct RTVFSDIROPS
|
---|
415 | {
|
---|
416 | /** The basic object operation. */
|
---|
417 | RTVFSOBJOPS Obj;
|
---|
418 | /** The structure version (RTVFSDIROPS_VERSION). */
|
---|
419 | uint32_t uVersion;
|
---|
420 | /** Reserved field, MBZ. */
|
---|
421 | uint32_t fReserved;
|
---|
422 | /** The object setter operations. */
|
---|
423 | RTVFSOBJSETOPS ObjSet;
|
---|
424 |
|
---|
425 | /**
|
---|
426 | * Opens a directory entry for traversal purposes.
|
---|
427 | *
|
---|
428 | * Method which sole purpose is helping the path traversal. Only one of
|
---|
429 | * the three output variables will be set, the others will left untouched
|
---|
430 | * (caller sets them to NIL).
|
---|
431 | *
|
---|
432 | * @returns IPRT status code.
|
---|
433 | * @retval VERR_PATH_NOT_FOUND if @a pszEntry was not found.
|
---|
434 | * @param pvThis The implementation specific directory data.
|
---|
435 | * @param pszEntry The name of the directory entry to remove.
|
---|
436 | * @param phVfsDir If not NULL and it is a directory, open it and
|
---|
437 | * return the handle here.
|
---|
438 | * @param phVfsSymlink If not NULL and it is a symbolic link, open it
|
---|
439 | * and return the handle here.
|
---|
440 | * @param phVfsMounted If not NULL and it is a mounted VFS directory,
|
---|
441 | * reference it and return the handle here.
|
---|
442 | * @todo Should com dir, symlinks and mount points using some common
|
---|
443 | * ancestor "class".
|
---|
444 | */
|
---|
445 | DECLCALLBACKMEMBER(int, pfnTraversalOpen)(void *pvThis, const char *pszEntry, PRTVFSDIR phVfsDir,
|
---|
446 | PRTVFSSYMLINK phVfsSymlink, PRTVFS phVfsMounted);
|
---|
447 |
|
---|
448 | /**
|
---|
449 | * Open or create a file.
|
---|
450 | *
|
---|
451 | * @returns IPRT status code.
|
---|
452 | * @param pvThis The implementation specific directory data.
|
---|
453 | * @param pszFilename The name of the immediate file to open or create.
|
---|
454 | * @param fOpen The open flags (RTFILE_O_XXX).
|
---|
455 | * @param phVfsFile Where to return the thandle to the opened file.
|
---|
456 | * @sa RTFileOpen.
|
---|
457 | */
|
---|
458 | DECLCALLBACKMEMBER(int, pfnOpenFile)(void *pvThis, const char *pszFilename, uint32_t fOpen, PRTVFSFILE phVfsFile);
|
---|
459 |
|
---|
460 | /**
|
---|
461 | * Open an existing subdirectory.
|
---|
462 | *
|
---|
463 | * @returns IPRT status code.
|
---|
464 | * @param pvThis The implementation specific directory data.
|
---|
465 | * @param pszSubDir The name of the immediate subdirectory to open.
|
---|
466 | * @param phVfsDir Where to return the handle to the opened directory.
|
---|
467 | * @sa RTDirOpen.
|
---|
468 | */
|
---|
469 | DECLCALLBACKMEMBER(int, pfnOpenDir)(void *pvThis, const char *pszSubDir, PRTVFSDIR phVfsDir);
|
---|
470 |
|
---|
471 | /**
|
---|
472 | * Creates a new subdirectory.
|
---|
473 | *
|
---|
474 | * @returns IPRT status code.
|
---|
475 | * @param pvThis The implementation specific directory data.
|
---|
476 | * @param pszSubDir The name of the immediate subdirectory to create.
|
---|
477 | * @param fMode The mode mask of the new directory.
|
---|
478 | * @param phVfsDir Where to optionally return the handle to the newly
|
---|
479 | * create directory.
|
---|
480 | * @sa RTDirCreate.
|
---|
481 | */
|
---|
482 | DECLCALLBACKMEMBER(int, pfnCreateDir)(void *pvThis, const char *pszSubDir, RTFMODE fMode, PRTVFSDIR phVfsDir);
|
---|
483 |
|
---|
484 | /**
|
---|
485 | * Opens an existing symbolic link.
|
---|
486 | *
|
---|
487 | * @returns IPRT status code.
|
---|
488 | * @param pvThis The implementation specific directory data.
|
---|
489 | * @param pszSymlink The name of the immediate symbolic link to open.
|
---|
490 | * @param phVfsSymlink Where to optionally return the handle to the
|
---|
491 | * newly create symbolic link.
|
---|
492 | * @sa RTSymlinkCreate.
|
---|
493 | */
|
---|
494 | DECLCALLBACKMEMBER(int, pfnOpenSymlink)(void *pvThis, const char *pszSymlink, PRTVFSSYMLINK phVfsSymlink);
|
---|
495 |
|
---|
496 | /**
|
---|
497 | * Creates a new symbolic link.
|
---|
498 | *
|
---|
499 | * @returns IPRT status code.
|
---|
500 | * @param pvThis The implementation specific directory data.
|
---|
501 | * @param pszSymlink The name of the immediate symbolic link to create.
|
---|
502 | * @param pszTarget The symbolic link target.
|
---|
503 | * @param enmType The symbolic link type.
|
---|
504 | * @param phVfsSymlink Where to optionally return the handle to the
|
---|
505 | * newly create symbolic link.
|
---|
506 | * @sa RTSymlinkCreate.
|
---|
507 | */
|
---|
508 | DECLCALLBACKMEMBER(int, pfnCreateSymlink)(void *pvThis, const char *pszSymlink, const char *pszTarget,
|
---|
509 | RTSYMLINKTYPE enmType, PRTVFSSYMLINK phVfsSymlink);
|
---|
510 |
|
---|
511 | /**
|
---|
512 | * Removes a directory entry.
|
---|
513 | *
|
---|
514 | * @returns IPRT status code.
|
---|
515 | * @param pvThis The implementation specific directory data.
|
---|
516 | * @param pszEntry The name of the directory entry to remove.
|
---|
517 | * @param fType If non-zero, this restricts the type of the entry to
|
---|
518 | * the object type indicated by the mask
|
---|
519 | * (RTFS_TYPE_XXX).
|
---|
520 | * @sa RTFileRemove, RTDirRemove, RTSymlinkRemove.
|
---|
521 | */
|
---|
522 | DECLCALLBACKMEMBER(int, pfnUnlinkEntry)(void *pvThis, const char *pszEntry, RTFMODE fType, PRTVFSDIR phVfsDir);
|
---|
523 |
|
---|
524 | /**
|
---|
525 | * Rewind the directory stream so that the next read returns the first
|
---|
526 | * entry.
|
---|
527 | *
|
---|
528 | * @returns IPRT status code.
|
---|
529 | * @param pvThis The implementation specific directory data.
|
---|
530 | */
|
---|
531 | DECLCALLBACKMEMBER(int, pfnRewindDir)(void *pvThis);
|
---|
532 |
|
---|
533 | /**
|
---|
534 | * Rewind the directory stream so that the next read returns the first
|
---|
535 | * entry.
|
---|
536 | *
|
---|
537 | * @returns IPRT status code.
|
---|
538 | * @param pvThis The implementation specific directory data.
|
---|
539 | * @param pDirEntry Output buffer.
|
---|
540 | * @param pcbDirEntry Complicated, see RTDirReadEx.
|
---|
541 | * @param enmAddAttr Which set of additional attributes to request.
|
---|
542 | * @sa RTDirReadEx
|
---|
543 | */
|
---|
544 | DECLCALLBACKMEMBER(int, pfnReadDir)(void *pvThis, PRTDIRENTRYEX pDirEntry, size_t *pcbDirEntry, RTFSOBJATTRADD enmAddAttr);
|
---|
545 |
|
---|
546 | /** Marks the end of the structure (RTVFSDIROPS_VERSION). */
|
---|
547 | uintptr_t uEndMarker;
|
---|
548 | } RTVFSDIROPS;
|
---|
549 | /** Pointer to const directory operations. */
|
---|
550 | typedef RTVFSDIROPS const *PCRTVFSDIROPS;
|
---|
551 | /** The RTVFSDIROPS structure version. */
|
---|
552 | #define RTVFSDIROPS_VERSION RT_MAKE_U32_FROM_U8(0xff,0x4f,1,0)
|
---|
553 |
|
---|
554 |
|
---|
555 | /**
|
---|
556 | * The symbolic link operations.
|
---|
557 | *
|
---|
558 | * @extends RTVFSOBJOPS
|
---|
559 | * @extends RTVFSOBJSETOPS
|
---|
560 | */
|
---|
561 | typedef struct RTVFSSYMLINKOPS
|
---|
562 | {
|
---|
563 | /** The basic object operation. */
|
---|
564 | RTVFSOBJOPS Obj;
|
---|
565 | /** The structure version (RTVFSSYMLINKOPS_VERSION). */
|
---|
566 | uint32_t uVersion;
|
---|
567 | /** Reserved field, MBZ. */
|
---|
568 | uint32_t fReserved;
|
---|
569 | /** The object setter operations. */
|
---|
570 | RTVFSOBJSETOPS ObjSet;
|
---|
571 |
|
---|
572 | /**
|
---|
573 | * Read the symbolic link target.
|
---|
574 | *
|
---|
575 | * @returns IPRT status code.
|
---|
576 | * @param pvThis The implementation specific symbolic link data.
|
---|
577 | * @param pszTarget The target buffer.
|
---|
578 | * @param cbTarget The size of the target buffer.
|
---|
579 | * @sa RTSymlinkRead
|
---|
580 | */
|
---|
581 | DECLCALLBACKMEMBER(int, pfnRead)(void *pvThis, char *pszTarget, size_t cbTarget);
|
---|
582 |
|
---|
583 | /** Marks the end of the structure (RTVFSSYMLINKOPS_VERSION). */
|
---|
584 | uintptr_t uEndMarker;
|
---|
585 | } RTVFSSYMLINKOPS;
|
---|
586 | /** Pointer to const symbolic link operations. */
|
---|
587 | typedef RTVFSSYMLINKOPS const *PCRTVFSSYMLINKOPS;
|
---|
588 | /** The RTVFSSYMLINKOPS structure version. */
|
---|
589 | #define RTVFSSYMLINKOPS_VERSION RT_MAKE_U32_FROM_U8(0xff,0x5f,1,0)
|
---|
590 |
|
---|
591 |
|
---|
592 | /**
|
---|
593 | * Creates a new VFS symlink handle.
|
---|
594 | *
|
---|
595 | * @returns IPRT status code
|
---|
596 | * @param pSymlinkOps The symlink operations.
|
---|
597 | * @param cbInstance The size of the instance data.
|
---|
598 | * @param hVfs The VFS handle to associate this symlink object
|
---|
599 | * with. NIL_VFS is ok.
|
---|
600 | * @param hLock Handle to a custom lock to be used with the new
|
---|
601 | * object. The reference is consumed. NIL and
|
---|
602 | * special lock handles are fine.
|
---|
603 | * @param phVfsSym Where to return the new handle.
|
---|
604 | * @param ppvInstance Where to return the pointer to the instance data
|
---|
605 | * (size is @a cbInstance).
|
---|
606 | */
|
---|
607 | RTDECL(int) RTVfsNewSymlink(PCRTVFSSYMLINKOPS pSymlinkOps, size_t cbInstance, RTVFS hVfs, RTVFSLOCK hLock,
|
---|
608 | PRTVFSSYMLINK phVfsSym, void **ppvInstance);
|
---|
609 |
|
---|
610 |
|
---|
611 | /**
|
---|
612 | * The basis for all I/O objects (files, pipes, sockets, devices, ++).
|
---|
613 | *
|
---|
614 | * @extends RTVFSOBJOPS
|
---|
615 | */
|
---|
616 | typedef struct RTVFSIOSTREAMOPS
|
---|
617 | {
|
---|
618 | /** The basic object operation. */
|
---|
619 | RTVFSOBJOPS Obj;
|
---|
620 | /** The structure version (RTVFSIOSTREAMOPS_VERSION). */
|
---|
621 | uint32_t uVersion;
|
---|
622 | /** Feature field. */
|
---|
623 | uint32_t fFeatures;
|
---|
624 |
|
---|
625 | /**
|
---|
626 | * Reads from the file/stream.
|
---|
627 | *
|
---|
628 | * @returns IPRT status code. See RTVfsIoStrmRead.
|
---|
629 | * @param pvThis The implementation specific file data.
|
---|
630 | * @param off Where to read at, -1 for the current position.
|
---|
631 | * @param pSgBuf Gather buffer describing the bytes that are to be
|
---|
632 | * written.
|
---|
633 | * @param fBlocking If @c true, the call is blocking, if @c false it
|
---|
634 | * should not block.
|
---|
635 | * @param pcbRead Where return the number of bytes actually read.
|
---|
636 | * This is set it 0 by the caller. If NULL, try read
|
---|
637 | * all and fail if incomplete.
|
---|
638 | * @sa RTVfsIoStrmRead, RTVfsIoStrmSgRead, RTVfsFileRead,
|
---|
639 | * RTVfsFileReadAt, RTFileRead, RTFileReadAt.
|
---|
640 | */
|
---|
641 | DECLCALLBACKMEMBER(int, pfnRead)(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead);
|
---|
642 |
|
---|
643 | /**
|
---|
644 | * Writes to the file/stream.
|
---|
645 | *
|
---|
646 | * @returns IPRT status code.
|
---|
647 | * @param pvThis The implementation specific file data.
|
---|
648 | * @param off Where to start wrinting, -1 for the current
|
---|
649 | * position.
|
---|
650 | * @param pSgBuf Gather buffers describing the bytes that are to be
|
---|
651 | * written.
|
---|
652 | * @param fBlocking If @c true, the call is blocking, if @c false it
|
---|
653 | * should not block.
|
---|
654 | * @param pcbWritten Where to return the number of bytes actually
|
---|
655 | * written. This is set it 0 by the caller. If
|
---|
656 | * NULL, try write it all and fail if incomplete.
|
---|
657 | * @sa RTFileWrite, RTFileWriteAt.
|
---|
658 | */
|
---|
659 | DECLCALLBACKMEMBER(int, pfnWrite)(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten);
|
---|
660 |
|
---|
661 | /**
|
---|
662 | * Flushes any pending data writes to the stream.
|
---|
663 | *
|
---|
664 | * @returns IPRT status code.
|
---|
665 | * @param pvThis The implementation specific file data.
|
---|
666 | * @sa RTFileFlush.
|
---|
667 | */
|
---|
668 | DECLCALLBACKMEMBER(int, pfnFlush)(void *pvThis);
|
---|
669 |
|
---|
670 | /**
|
---|
671 | * Poll for events.
|
---|
672 | *
|
---|
673 | * @returns IPRT status code.
|
---|
674 | * @param pvThis The implementation specific file data.
|
---|
675 | * @param fEvents The events to poll for (RTPOLL_EVT_XXX).
|
---|
676 | * @param cMillies How long to wait for event to eventuate.
|
---|
677 | * @param fIntr Whether the wait is interruptible and can return
|
---|
678 | * VERR_INTERRUPTED (@c true) or if this condition
|
---|
679 | * should be hidden from the caller (@c false).
|
---|
680 | * @param pfRetEvents Where to return the event mask.
|
---|
681 | * @sa RTPollSetAdd, RTPoll, RTPollNoResume.
|
---|
682 | */
|
---|
683 | DECLCALLBACKMEMBER(int, pfnPollOne)(void *pvThis, uint32_t fEvents, RTMSINTERVAL cMillies, bool fIntr,
|
---|
684 | uint32_t *pfRetEvents);
|
---|
685 |
|
---|
686 | /**
|
---|
687 | * Tells the current file/stream position.
|
---|
688 | *
|
---|
689 | * @returns IPRT status code.
|
---|
690 | * @param pvThis The implementation specific file data.
|
---|
691 | * @param poffActual Where to return the actual offset.
|
---|
692 | * @sa RTFileTell
|
---|
693 | */
|
---|
694 | DECLCALLBACKMEMBER(int, pfnTell)(void *pvThis, PRTFOFF poffActual);
|
---|
695 |
|
---|
696 | /**
|
---|
697 | * Skips @a cb ahead in the stream.
|
---|
698 | *
|
---|
699 | * @returns IPRT status code.
|
---|
700 | * @param pvThis The implementation specific file data.
|
---|
701 | * @param cb The number bytes to skip.
|
---|
702 | * @remarks This is optional and can be NULL.
|
---|
703 | */
|
---|
704 | DECLCALLBACKMEMBER(int, pfnSkip)(void *pvThis, RTFOFF cb);
|
---|
705 |
|
---|
706 | /**
|
---|
707 | * Fills the stream with @a cb zeros.
|
---|
708 | *
|
---|
709 | * @returns IPRT status code.
|
---|
710 | * @param pvThis The implementation specific file data.
|
---|
711 | * @param cb The number of zero bytes to insert.
|
---|
712 | * @remarks This is optional and can be NULL.
|
---|
713 | */
|
---|
714 | DECLCALLBACKMEMBER(int, pfnZeroFill)(void *pvThis, RTFOFF cb);
|
---|
715 |
|
---|
716 | /** Marks the end of the structure (RTVFSIOSTREAMOPS_VERSION). */
|
---|
717 | uintptr_t uEndMarker;
|
---|
718 | } RTVFSIOSTREAMOPS;
|
---|
719 | /** Pointer to const I/O stream operations. */
|
---|
720 | typedef RTVFSIOSTREAMOPS const *PCRTVFSIOSTREAMOPS;
|
---|
721 |
|
---|
722 | /** The RTVFSIOSTREAMOPS structure version. */
|
---|
723 | #define RTVFSIOSTREAMOPS_VERSION RT_MAKE_U32_FROM_U8(0xff,0x6f,1,0)
|
---|
724 |
|
---|
725 | /** @name RTVFSIOSTREAMOPS::fFeatures
|
---|
726 | * @{ */
|
---|
727 | /** No scatter gather lists, thank you. */
|
---|
728 | #define RTVFSIOSTREAMOPS_FEAT_NO_SG RT_BIT_32(0)
|
---|
729 | /** Mask of the valid I/O stream feature flags. */
|
---|
730 | #define RTVFSIOSTREAMOPS_FEAT_VALID_MASK UINT32_C(0x00000001)
|
---|
731 | /** @} */
|
---|
732 |
|
---|
733 |
|
---|
734 | /**
|
---|
735 | * Creates a new VFS I/O stream handle.
|
---|
736 | *
|
---|
737 | * @returns IPRT status code
|
---|
738 | * @param pIoStreamOps The I/O stream operations.
|
---|
739 | * @param cbInstance The size of the instance data.
|
---|
740 | * @param fOpen The open flags. The minimum is the access mask.
|
---|
741 | * @param hVfs The VFS handle to associate this I/O stream
|
---|
742 | * with. NIL_VFS is ok.
|
---|
743 | * @param hLock Handle to a custom lock to be used with the new
|
---|
744 | * object. The reference is consumed. NIL and
|
---|
745 | * special lock handles are fine.
|
---|
746 | * @param phVfsIos Where to return the new handle.
|
---|
747 | * @param ppvInstance Where to return the pointer to the instance data
|
---|
748 | * (size is @a cbInstance).
|
---|
749 | */
|
---|
750 | RTDECL(int) RTVfsNewIoStream(PCRTVFSIOSTREAMOPS pIoStreamOps, size_t cbInstance, uint32_t fOpen, RTVFS hVfs, RTVFSLOCK hLock,
|
---|
751 | PRTVFSIOSTREAM phVfsIos, void **ppvInstance);
|
---|
752 |
|
---|
753 |
|
---|
754 | /**
|
---|
755 | * Gets the private data of an I/O stream.
|
---|
756 | *
|
---|
757 | * @returns Pointer to the private data. NULL if the handle is invalid in some
|
---|
758 | * way.
|
---|
759 | * @param hVfsIos The I/O stream handle.
|
---|
760 | * @param pIoStreamOps The I/O stream operations. This servers as a
|
---|
761 | * sort of password.
|
---|
762 | */
|
---|
763 | RTDECL(void *) RTVfsIoStreamToPrivate(RTVFSIOSTREAM hVfsIos, PCRTVFSIOSTREAMOPS pIoStreamOps);
|
---|
764 |
|
---|
765 |
|
---|
766 | /**
|
---|
767 | * The file operations.
|
---|
768 | *
|
---|
769 | * @extends RTVFSIOSTREAMOPS
|
---|
770 | * @extends RTVFSOBJSETOPS
|
---|
771 | */
|
---|
772 | typedef struct RTVFSFILEOPS
|
---|
773 | {
|
---|
774 | /** The I/O stream and basis object operations. */
|
---|
775 | RTVFSIOSTREAMOPS Stream;
|
---|
776 | /** The structure version (RTVFSFILEOPS_VERSION). */
|
---|
777 | uint32_t uVersion;
|
---|
778 | /** Reserved field, MBZ. */
|
---|
779 | uint32_t fReserved;
|
---|
780 | /** The object setter operations. */
|
---|
781 | RTVFSOBJSETOPS ObjSet;
|
---|
782 |
|
---|
783 | /**
|
---|
784 | * Changes the current file position.
|
---|
785 | *
|
---|
786 | * @returns IPRT status code.
|
---|
787 | * @param pvThis The implementation specific file data.
|
---|
788 | * @param offSeek The offset to seek.
|
---|
789 | * @param uMethod The seek method, i.e. what the seek is relative to.
|
---|
790 | * @param poffActual Where to return the actual offset.
|
---|
791 | * @sa RTFileSeek
|
---|
792 | */
|
---|
793 | DECLCALLBACKMEMBER(int, pfnSeek)(void *pvThis, RTFOFF offSeek, unsigned uMethod, PRTFOFF poffActual);
|
---|
794 |
|
---|
795 | /**
|
---|
796 | * Get the current file/stream size.
|
---|
797 | *
|
---|
798 | * @returns IPRT status code.
|
---|
799 | * @param pvThis The implementation specific file data.
|
---|
800 | * @param pcbFile Where to store the current file size.
|
---|
801 | * @sa RTFileGetSize
|
---|
802 | */
|
---|
803 | DECLCALLBACKMEMBER(int, pfnQuerySize)(void *pvThis, uint64_t *pcbFile);
|
---|
804 |
|
---|
805 | /** @todo There will be more methods here. */
|
---|
806 |
|
---|
807 | /** Marks the end of the structure (RTVFSFILEOPS_VERSION). */
|
---|
808 | uintptr_t uEndMarker;
|
---|
809 | } RTVFSFILEOPS;
|
---|
810 | /** Pointer to const file operations. */
|
---|
811 | typedef RTVFSFILEOPS const *PCRTVFSFILEOPS;
|
---|
812 |
|
---|
813 | /** The RTVFSFILEOPS structure version. */
|
---|
814 | #define RTVFSFILEOPS_VERSION RT_MAKE_U32_FROM_U8(0xff,0x7f,1,0)
|
---|
815 |
|
---|
816 | /**
|
---|
817 | * Creates a new VFS file handle.
|
---|
818 | *
|
---|
819 | * @returns IPRT status code
|
---|
820 | * @param pFileOps The file operations.
|
---|
821 | * @param cbInstance The size of the instance data.
|
---|
822 | * @param fOpen The open flags. The minimum is the access mask.
|
---|
823 | * @param hVfs The VFS handle to associate this file with.
|
---|
824 | * NIL_VFS is ok.
|
---|
825 | * @param hLock Handle to a custom lock to be used with the new
|
---|
826 | * object. The reference is consumed. NIL and
|
---|
827 | * special lock handles are fine.
|
---|
828 | * @param phVfsFile Where to return the new handle.
|
---|
829 | * @param ppvInstance Where to return the pointer to the instance data
|
---|
830 | * (size is @a cbInstance).
|
---|
831 | */
|
---|
832 | RTDECL(int) RTVfsNewFile(PCRTVFSFILEOPS pFileOps, size_t cbInstance, uint32_t fOpen, RTVFS hVfs, RTVFSLOCK hLock,
|
---|
833 | PRTVFSFILE phVfsFile, void **ppvInstance);
|
---|
834 |
|
---|
835 |
|
---|
836 | /** @defgroup grp_rt_vfs_ll_util VFS Utility APIs
|
---|
837 | * @{ */
|
---|
838 |
|
---|
839 | /**
|
---|
840 | * Parsed path.
|
---|
841 | */
|
---|
842 | typedef struct RTVFSPARSEDPATH
|
---|
843 | {
|
---|
844 | /** The length of the path in szCopy. */
|
---|
845 | uint16_t cch;
|
---|
846 | /** The number of path components. */
|
---|
847 | uint16_t cComponents;
|
---|
848 | /** Set if the path ends with slash, indicating that it's a directory
|
---|
849 | * reference and not a file reference. The slash has been removed from
|
---|
850 | * the copy. */
|
---|
851 | bool fDirSlash;
|
---|
852 | /** The offset where each path component starts, i.e. the char after the
|
---|
853 | * slash. The array has cComponents + 1 entries, where the final one is
|
---|
854 | * cch + 1 so that one can always terminate the current component by
|
---|
855 | * szPath[aoffComponent[i] - 1] = '\0'. */
|
---|
856 | uint16_t aoffComponents[RTPATH_MAX / 2 + 1];
|
---|
857 | /** A normalized copy of the path.
|
---|
858 | * Reserve some extra space so we can be more relaxed about overflow
|
---|
859 | * checks and terminator paddings, especially when recursing. */
|
---|
860 | char szPath[RTPATH_MAX];
|
---|
861 | } RTVFSPARSEDPATH;
|
---|
862 | /** Pointer to a parsed path. */
|
---|
863 | typedef RTVFSPARSEDPATH *PRTVFSPARSEDPATH;
|
---|
864 |
|
---|
865 | /** The max accepted path length.
|
---|
866 | * This must be a few chars shorter than RTVFSPARSEDPATH::szPath because we
|
---|
867 | * use two terminators and wish be a little bit lazy with checking. */
|
---|
868 | #define RTVFSPARSEDPATH_MAX (RTPATH_MAX - 4)
|
---|
869 |
|
---|
870 | /**
|
---|
871 | * Appends @a pszPath (relative) to the already parsed path @a pPath.
|
---|
872 | *
|
---|
873 | * @retval VINF_SUCCESS
|
---|
874 | * @retval VERR_FILENAME_TOO_LONG
|
---|
875 | * @retval VERR_INTERNAL_ERROR_4
|
---|
876 | * @param pPath The parsed path to append @a pszPath onto.
|
---|
877 | * This is both input and output.
|
---|
878 | * @param pszPath The path to append. This must be relative.
|
---|
879 | * @param piRestartComp The component to restart parsing at. This is
|
---|
880 | * input/output. The input does not have to be
|
---|
881 | * within the valid range. Optional.
|
---|
882 | */
|
---|
883 | RTDECL(int) RTVfsParsePathAppend(PRTVFSPARSEDPATH pPath, const char *pszPath, uint16_t *piRestartComp);
|
---|
884 |
|
---|
885 | /**
|
---|
886 | * Parses a path.
|
---|
887 | *
|
---|
888 | * @retval VINF_SUCCESS
|
---|
889 | * @retval VERR_FILENAME_TOO_LONG
|
---|
890 | * @param pPath Where to store the parsed path.
|
---|
891 | * @param pszPath The path to parse. Absolute or relative to @a
|
---|
892 | * pszCwd.
|
---|
893 | * @param pszCwd The current working directory. Must be
|
---|
894 | * absolute.
|
---|
895 | */
|
---|
896 | RTDECL(int) RTVfsParsePath(PRTVFSPARSEDPATH pPath, const char *pszPath, const char *pszCwd);
|
---|
897 |
|
---|
898 | /**
|
---|
899 | * Same as RTVfsParsePath except that it allocates a temporary buffer.
|
---|
900 | *
|
---|
901 | * @retval VINF_SUCCESS
|
---|
902 | * @retval VERR_NO_TMP_MEMORY
|
---|
903 | * @retval VERR_FILENAME_TOO_LONG
|
---|
904 | * @param pszPath The path to parse. Absolute or relative to @a
|
---|
905 | * pszCwd.
|
---|
906 | * @param pszCwd The current working directory. Must be
|
---|
907 | * absolute.
|
---|
908 | * @param ppPath Where to store the pointer to the allocated
|
---|
909 | * buffer containing the parsed path. This must
|
---|
910 | * be freed by calling RTVfsParsePathFree. NULL
|
---|
911 | * will be stored on failured.
|
---|
912 | */
|
---|
913 | RTDECL(int) RTVfsParsePathA(const char *pszPath, const char *pszCwd, PRTVFSPARSEDPATH *ppPath);
|
---|
914 |
|
---|
915 | /**
|
---|
916 | * Frees a buffer returned by RTVfsParsePathA.
|
---|
917 | *
|
---|
918 | * @param pPath The parsed path buffer to free. NULL is fine.
|
---|
919 | */
|
---|
920 | RTDECL(void) RTVfsParsePathFree(PRTVFSPARSEDPATH pPath);
|
---|
921 |
|
---|
922 | /**
|
---|
923 | * Dummy implementation of RTVFSIOSTREAMOPS::pfnPollOne.
|
---|
924 | *
|
---|
925 | * This handles the case where there is no chance any events my be raised and
|
---|
926 | * all that is required is to wait according to the parameters.
|
---|
927 | *
|
---|
928 | * @returns IPRT status code.
|
---|
929 | * @param pvThis The implementation specific file data.
|
---|
930 | * @param fEvents The events to poll for (RTPOLL_EVT_XXX).
|
---|
931 | * @param cMillies How long to wait for event to eventuate.
|
---|
932 | * @param fIntr Whether the wait is interruptible and can return
|
---|
933 | * VERR_INTERRUPTED (@c true) or if this condition
|
---|
934 | * should be hidden from the caller (@c false).
|
---|
935 | * @param pfRetEvents Where to return the event mask.
|
---|
936 | * @sa RTVFSIOSTREAMOPS::pfnPollOne, RTPollSetAdd, RTPoll, RTPollNoResume.
|
---|
937 | */
|
---|
938 | RTDECL(int) RTVfsUtilDummyPollOne(uint32_t fEvents, RTMSINTERVAL cMillies, bool fIntr, uint32_t *pfRetEvents);
|
---|
939 |
|
---|
940 | /** @} */
|
---|
941 |
|
---|
942 |
|
---|
943 | /** @defgroup grp_rt_vfs_lowlevel_chain VFS Chains
|
---|
944 | * @ref grp_rt_vfs_chain
|
---|
945 | * @{
|
---|
946 | */
|
---|
947 |
|
---|
948 |
|
---|
949 | /**
|
---|
950 | * Chain element input actions.
|
---|
951 | */
|
---|
952 | typedef enum RTVFSCHAINACTION
|
---|
953 | {
|
---|
954 | /** Invalid action. */
|
---|
955 | RTVFSCHAINACTION_INVALID = 0,
|
---|
956 | /** No action (start of the chain). */
|
---|
957 | RTVFSCHAINACTION_NONE,
|
---|
958 | /** Passive filtering (expressed by pipe symbol). */
|
---|
959 | RTVFSCHAINACTION_PASSIVE,
|
---|
960 | /** Push filtering (expressed by redirection-out symbol). */
|
---|
961 | RTVFSCHAINACTION_PUSH,
|
---|
962 | /** The end of the valid actions. */
|
---|
963 | RTVFSCHAINACTION_END,
|
---|
964 | /** Make sure it's a 32-bit type. */
|
---|
965 | RTVFSCHAINACTION_32BIT_HACK = 0x7fffffff
|
---|
966 | } RTVFSCHAINACTION;
|
---|
967 |
|
---|
968 |
|
---|
969 | /**
|
---|
970 | * VFS chain element specification.
|
---|
971 | */
|
---|
972 | typedef struct RTVFSCHAINELEMSPEC
|
---|
973 | {
|
---|
974 | /** The provider name. */
|
---|
975 | char *pszProvider;
|
---|
976 | /** The input type. */
|
---|
977 | RTVFSOBJTYPE enmTypeIn;
|
---|
978 | /** The output type. */
|
---|
979 | RTVFSOBJTYPE enmTypeOut;
|
---|
980 | /** The action to take (or not). */
|
---|
981 | RTVFSCHAINACTION enmAction;
|
---|
982 | /** The number of arguments. */
|
---|
983 | uint32_t cArgs;
|
---|
984 | /** Arguments. */
|
---|
985 | char **papszArgs;
|
---|
986 | } RTVFSCHAINELEMSPEC;
|
---|
987 | /** Pointer to a chain element specification. */
|
---|
988 | typedef RTVFSCHAINELEMSPEC *PRTVFSCHAINELEMSPEC;
|
---|
989 | /** Pointer to a const chain element specification. */
|
---|
990 | typedef RTVFSCHAINELEMSPEC const *PCRTVFSCHAINELEMSPEC;
|
---|
991 |
|
---|
992 |
|
---|
993 | /**
|
---|
994 | * Parsed VFS chain specification.
|
---|
995 | */
|
---|
996 | typedef struct RTVFSCHAINSPEC
|
---|
997 | {
|
---|
998 | /** The action element, UINT32_MAX if none.
|
---|
999 | * Currently we only support one action element (RTVFSCHAINACTION_PASSIVE
|
---|
1000 | * is not considered). */
|
---|
1001 | uint32_t iActionElement;
|
---|
1002 | /** The number of elements. */
|
---|
1003 | uint32_t cElements;
|
---|
1004 | /** The elements. */
|
---|
1005 | PRTVFSCHAINELEMSPEC paElements;
|
---|
1006 | } RTVFSCHAINSPEC;
|
---|
1007 | /** Pointer to a parsed VFS chain specification. */
|
---|
1008 | typedef RTVFSCHAINSPEC *PRTVFSCHAINSPEC;
|
---|
1009 | /** Pointer to a const, parsed VFS chain specification. */
|
---|
1010 | typedef RTVFSCHAINSPEC const *PCRTVFSCHAINSPEC;
|
---|
1011 |
|
---|
1012 |
|
---|
1013 | /**
|
---|
1014 | * A chain element provider registration record.
|
---|
1015 | */
|
---|
1016 | typedef struct RTVFSCHAINELEMENTREG
|
---|
1017 | {
|
---|
1018 | /** The version (RTVFSCHAINELEMENTREG_VERSION). */
|
---|
1019 | uint32_t uVersion;
|
---|
1020 | /** Reserved, MBZ. */
|
---|
1021 | uint32_t fReserved;
|
---|
1022 | /** The provider name (unique). */
|
---|
1023 | const char *pszName;
|
---|
1024 | /** For chaining the providers. */
|
---|
1025 | RTLISTNODE ListEntry;
|
---|
1026 |
|
---|
1027 | /**
|
---|
1028 | * Create a VFS from the given chain element specficiation.
|
---|
1029 | *
|
---|
1030 | * @returns IPRT status code.
|
---|
1031 | * @param pSpec The chain element specification.
|
---|
1032 | * @param phVfs Where to returned the VFS handle.
|
---|
1033 | */
|
---|
1034 | DECLCALLBACKMEMBER(int, pfnOpenVfs)( PCRTVFSCHAINELEMSPEC pSpec, PRTVFS phVfs);
|
---|
1035 |
|
---|
1036 | /**
|
---|
1037 | * Open a directory from the given chain element specficiation.
|
---|
1038 | *
|
---|
1039 | * @returns IPRT status code.
|
---|
1040 | * @param pSpec The chain element specification.
|
---|
1041 | * @param phVfsDir Where to returned the directory handle.
|
---|
1042 | */
|
---|
1043 | DECLCALLBACKMEMBER(int, pfnOpenDir)( PCRTVFSCHAINELEMSPEC pSpec, PRTVFSDIR phVfsDir);
|
---|
1044 |
|
---|
1045 | /**
|
---|
1046 | * Open a file from the given chain element specficiation.
|
---|
1047 | *
|
---|
1048 | * @returns IPRT status code.
|
---|
1049 | * @param pSpec The chain element specification.
|
---|
1050 | * @param fOpen The open flag. Can be zero and the
|
---|
1051 | * specification may modify it.
|
---|
1052 | * @param phVfsFile Where to returned the file handle.
|
---|
1053 | */
|
---|
1054 | DECLCALLBACKMEMBER(int, pfnOpenFile)( PCRTVFSCHAINELEMSPEC pSpec, uint32_t fOpen, PRTVFSFILE phVfsFile);
|
---|
1055 |
|
---|
1056 | /**
|
---|
1057 | * Open a symlink from the given chain element specficiation.
|
---|
1058 | *
|
---|
1059 | * @returns IPRT status code.
|
---|
1060 | * @param pSpec The chain element specification.
|
---|
1061 | * @param phVfsSym Where to returned the symlink handle.
|
---|
1062 | */
|
---|
1063 | DECLCALLBACKMEMBER(int, pfnOpenSymlink)( PCRTVFSCHAINELEMSPEC pSpec, PRTVFSSYMLINK phVfsSym);
|
---|
1064 |
|
---|
1065 | /**
|
---|
1066 | * Open a I/O stream from the given chain element specficiation.
|
---|
1067 | *
|
---|
1068 | * @returns IPRT status code.
|
---|
1069 | * @param pSpec The chain element specification.
|
---|
1070 | * @param fOpen The open flag. Can be zero and the
|
---|
1071 | * specification may modify it.
|
---|
1072 | * @param phVfsIos Where to returned the I/O stream handle.
|
---|
1073 | */
|
---|
1074 | DECLCALLBACKMEMBER(int, pfnOpenIoStream)(PCRTVFSCHAINELEMSPEC pSpec, uint32_t fOpen, PRTVFSIOSTREAM phVfsIos);
|
---|
1075 |
|
---|
1076 | /**
|
---|
1077 | * Open a filesystem stream from the given chain element specficiation.
|
---|
1078 | *
|
---|
1079 | * @returns IPRT status code.
|
---|
1080 | * @param pSpec The chain element specification.
|
---|
1081 | * @param phVfsFss Where to returned the filesystem stream handle.
|
---|
1082 | */
|
---|
1083 | DECLCALLBACKMEMBER(int, pfnOpenFsStream)(PCRTVFSCHAINELEMSPEC pSpec, PRTVFSFSSTREAM phVfsFss);
|
---|
1084 |
|
---|
1085 | /** End marker (RTVFSCHAINELEMENTREG_VERSION). */
|
---|
1086 | uintptr_t uEndMarker;
|
---|
1087 | } RTVFSCHAINELEMENTREG;
|
---|
1088 | /** Pointer to a VFS chain element registration record. */
|
---|
1089 | typedef RTVFSCHAINELEMENTREG *PRTVFSCHAINELEMENTREG;
|
---|
1090 | /** Pointer to a const VFS chain element registration record. */
|
---|
1091 | typedef RTVFSCHAINELEMENTREG const *PCRTVFSCHAINELEMENTREG;
|
---|
1092 |
|
---|
1093 | /** The VFS chain element registration record version number. */
|
---|
1094 | #define RTVFSCHAINELEMENTREG_VERSION RT_MAKE_U32_FROM_U8(0xff, 0x7f, 1, 0)
|
---|
1095 |
|
---|
1096 |
|
---|
1097 | /**
|
---|
1098 | * Parses the specification.
|
---|
1099 | *
|
---|
1100 | * @returns IPRT status code.
|
---|
1101 | * @param pszSpec The specification string to parse.
|
---|
1102 | * @param fFlags Flags, see RTVFSCHAIN_PF_XXX.
|
---|
1103 | * @param enmLeadingAction The only allowed leading action type.
|
---|
1104 | * @param enmTrailingAction The only allowed trailing action type.
|
---|
1105 | * @param ppSpec Where to return the pointer to the parsed
|
---|
1106 | * specification. This must be freed by calling
|
---|
1107 | * RTVfsChainSpecFree. Will always be set (unless
|
---|
1108 | * invalid parameters.)
|
---|
1109 | * @param ppszError On failure, this will point at the error
|
---|
1110 | * location in @a pszSpec. Optional.
|
---|
1111 | */
|
---|
1112 | RTDECL(int) RTVfsChainSpecParse(const char *pszSpec, RTVFSCHAINACTION enmLeadingAction,
|
---|
1113 | RTVFSCHAINACTION enmTrailingAction,
|
---|
1114 | PRTVFSCHAINSPEC *ppSpec, const char *ppszError);
|
---|
1115 |
|
---|
1116 | /** @name RTVfsChainSpecParse
|
---|
1117 | * @{ */
|
---|
1118 | /** No real action is permitted, i.e. only passive filtering (aka pipe). */
|
---|
1119 | #define RTVFSCHAIN_PF_NO_REAL_ACTION RT_BIT_32(0)
|
---|
1120 | /** The specified leading action is optional. */
|
---|
1121 | #define RTVFSCHAIN_PF_LEADING_ACTION_OPTIONAL RT_BIT_32(1)
|
---|
1122 | /** The specified trailing action is optional. */
|
---|
1123 | #define RTVFSCHAIN_PF_TRAILING_ACTION_OPTIONAL RT_BIT_32(2)
|
---|
1124 | /** Mask of valid flags. */
|
---|
1125 | #define RTVFSCHAIN_PF_VALID_MASK UINT32_C(0x00000007)
|
---|
1126 | /** @}*/
|
---|
1127 |
|
---|
1128 | /**
|
---|
1129 | * Frees a parsed chain specification.
|
---|
1130 | *
|
---|
1131 | * @param pSpec What RTVfsChainSpecParse returned. NULL is
|
---|
1132 | * quietly ignored.
|
---|
1133 | */
|
---|
1134 | RTDECL(void) RTVfsChainSpecFree(PRTVFSCHAINSPEC pSpec);
|
---|
1135 |
|
---|
1136 | /**
|
---|
1137 | * Registers a chain element provider.
|
---|
1138 | *
|
---|
1139 | * @returns IPRT status code
|
---|
1140 | * @param pRegRec The registration record.
|
---|
1141 | * @param fFromCtor Indicates where we're called from.
|
---|
1142 | */
|
---|
1143 | RTDECL(int) RTVfsChainElementRegisterProvider(PRTVFSCHAINELEMENTREG pRegRec, bool fFromCtor);
|
---|
1144 |
|
---|
1145 | /**
|
---|
1146 | * Deregisters a chain element provider.
|
---|
1147 | *
|
---|
1148 | * @returns IPRT status code
|
---|
1149 | * @param pRegRec The registration record.
|
---|
1150 | * @param fFromDtor Indicates where we're called from.
|
---|
1151 | */
|
---|
1152 | RTDECL(int) RTVfsChainElementDeregisterProvider(PRTVFSCHAINELEMENTREG pRegRec, bool fFromDtor);
|
---|
1153 |
|
---|
1154 |
|
---|
1155 | /** @def RTVFSCHAIN_AUTO_REGISTER_ELEMENT_PROVIDER
|
---|
1156 | * Automatically registers a chain element provider using a global constructor
|
---|
1157 | * and destructor hack.
|
---|
1158 | *
|
---|
1159 | * @param pRegRec Pointer to the registration record.
|
---|
1160 | * @param name Some unique variable name prefix.
|
---|
1161 | */
|
---|
1162 |
|
---|
1163 | #ifdef __cplusplus
|
---|
1164 | /**
|
---|
1165 | * Class used for registering a VFS chain element provider.
|
---|
1166 | */
|
---|
1167 | class RTVfsChainElementAutoRegisterHack
|
---|
1168 | {
|
---|
1169 | private:
|
---|
1170 | /** The registration record, NULL if registration failed. */
|
---|
1171 | PRTVFSCHAINELEMENTREG m_pRegRec;
|
---|
1172 |
|
---|
1173 | public:
|
---|
1174 | RTVfsChainElementAutoRegisterHack(PRTVFSCHAINELEMENTREG a_pRegRec)
|
---|
1175 | : m_pRegRec(a_pRegRec)
|
---|
1176 | {
|
---|
1177 | int rc = RTVfsChainElementRegisterProvider(m_pRegRec, true);
|
---|
1178 | if (RT_FAILURE(rc))
|
---|
1179 | m_pRegRec = NULL;
|
---|
1180 | }
|
---|
1181 |
|
---|
1182 | ~RTVfsChainElementAutoRegisterHack()
|
---|
1183 | {
|
---|
1184 | RTVfsChainElementDeregisterProvider(m_pRegRec, true);
|
---|
1185 | m_pRegRec = NULL;
|
---|
1186 | }
|
---|
1187 | };
|
---|
1188 |
|
---|
1189 | # define RTVFSCHAIN_AUTO_REGISTER_ELEMENT_PROVIDER(pRegRec, name) \
|
---|
1190 | static RTVfsChainElementAutoRegisterHack name ## AutoRegistrationHack(pRegRec)
|
---|
1191 |
|
---|
1192 | #else
|
---|
1193 | # define RTVFSCHAIN_AUTO_REGISTER_ELEMENT_PROVIDER(pRegRec, name) \
|
---|
1194 | extern void *name ## AutoRegistrationHack = \
|
---|
1195 | &Sorry_but_RTVFSCHAIN_AUTO_REGISTER_ELEMENT_PROVIDER_does_not_work_in_c_source_files
|
---|
1196 | #endif
|
---|
1197 |
|
---|
1198 |
|
---|
1199 | /** @} */
|
---|
1200 |
|
---|
1201 |
|
---|
1202 | /** @} */
|
---|
1203 |
|
---|
1204 | RT_C_DECLS_END
|
---|
1205 |
|
---|
1206 | #endif /* !___iprt_vfslowlevel_h */
|
---|
1207 |
|
---|