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