VirtualBox

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

Last change on this file since 33887 was 33887, checked in by vboxsync, 14 years ago

iprt: started hacking a gunzip/gzip I/O stream implementation.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 26.1 KB
Line 
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/param.h>
31
32
33RT_C_DECLS_BEGIN
34
35/** @defgroup grp_rt_vfs_lowlevel RTVfs - Low-level Interface.
36 * @ingroup grp_rt_vfs
37 * @{
38 */
39
40/**
41 * The VFS operations.
42 */
43typedef struct RTVFSOPS
44{
45 /** The structure version (RTVFSOPS_VERSION). */
46 uint32_t uVersion;
47 /** The virtual file system feature mask. */
48 uint32_t fFeatures;
49 /** The name of the operations. */
50 const char *pszName;
51
52 /**
53 * Destructor.
54 *
55 * @param pvThis The implementation specific data.
56 */
57 DECLCALLBACKMEMBER(void, pfnDestroy)(void *pvThis);
58
59 /**
60 * Opens the root directory.
61 *
62 * @returns IPRT status code.
63 * @param pvThis The implementation specific data.
64 * @param phVfsDir Where to return the handle to the root directory.
65 */
66 DECLCALLBACKMEMBER(int, pfnOpenRoot)(void *pvThis, PRTVFSDIR phVfsDir);
67
68 /** @todo There will be more methods here to optimize opening and
69 * querying. */
70
71#if 0
72 /**
73 * Optional entry point for optimizing path traversal within the file system.
74 *
75 * @returns IPRT status code.
76 * @param pvThis The implementation specific data.
77 * @param pszPath The path to resolve.
78 * @param poffPath The current path offset on input, what we've
79 * traversed to on successful return.
80 * @param phVfs??? Return handle to what we've traversed.
81 * @param p??? Return other stuff...
82 */
83 DECLCALLBACKMEMBER(int, pfnTraverse)(void *pvThis, const char *pszPath, size_t *poffPath, PRTVFS??? phVfs?, ???* p???);
84#endif
85
86 /** Marks the end of the structure (RTVFSOPS_VERSION). */
87 uintptr_t uEndMarker;
88} RTVFSOPS;
89/** Pointer to constant VFS operations. */
90typedef RTVFSOPS const *PCRTVFSOPS;
91
92/** The RTVFSOPS structure version. */
93#define RTVFSOPS_VERSION RT_MAKE_U32_FROM_U8(0xff,0x0f,1,0)
94
95/** @name RTVFSOPS::fFeatures
96 * @{ */
97/** The VFS supports attaching other systems. */
98#define RTVFSOPS_FEAT_ATTACH RT_BIT_32(0)
99/** @} */
100
101
102/**
103 * The object type.
104 */
105typedef enum RTVFSOBJTYPE
106{
107 /** Invalid type. */
108 RTVFSOBJTYPE_INVALID = 0,
109 /** Directory. */
110 RTVFSOBJTYPE_DIR,
111 /** Pure I/O stream. */
112 RTVFSOBJTYPE_IOSTREAM,
113 /** File. */
114 RTVFSOBJTYPE_FILE,
115 /** Symbolic link. */
116 RTVFSOBJTYPE_SYMLINK,
117 /** End of valid object types. */
118 RTVFSOBJTYPE_END,
119 /** Pure I/O stream. */
120 RTVFSOBJTYPE_32BIT_HACK = 0x7fffffff
121} RTVFSOBJTYPE;
122
123/**
124 * The basis for all virtual file system objects except RTVFS.
125 */
126typedef struct RTVFSOBJOPS
127{
128 /** The structure version (RTVFSOBJOPS_VERSION). */
129 uint32_t uVersion;
130 /** The object type for type introspection. */
131 RTVFSOBJTYPE enmType;
132 /** The name of the operations. */
133 const char *pszName;
134
135 /**
136 * Close the object.
137 *
138 * @returns IPRT status code.
139 * @param pvThis The implementation specific file data.
140 */
141 DECLCALLBACKMEMBER(int, pfnClose)(void *pvThis);
142
143 /**
144 * Get information about the file.
145 *
146 * @returns IPRT status code.
147 * @param pvThis The implementation specific file data.
148 * @param pObjInfo Where to return the object info on success.
149 * @param enmAddAttr Which set of additional attributes to request.
150 * @sa RTFileQueryInfo
151 */
152 DECLCALLBACKMEMBER(int, pfnQueryInfo)(void *pvThis, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr);
153
154 /** Marks the end of the structure (RTVFSOBJOPS_VERSION). */
155 uintptr_t uEndMarker;
156} RTVFSOBJOPS;
157/** Pointer to constant VFS object operations. */
158typedef RTVFSOBJOPS const *PCRTVFSOBJOPS;
159
160/** The RTVFSOBJOPS structure version. */
161#define RTVFSOBJOPS_VERSION RT_MAKE_U32_FROM_U8(0xff,0x1f,1,0)
162
163
164/**
165 * Additional operations for setting object attributes.
166 */
167typedef struct RTVFSOBJSETOPS
168{
169 /** The structure version (RTVFSOBJSETOPS_VERSION). */
170 uint32_t uVersion;
171 /** The offset to the RTVFSOBJOPS structure. */
172 int32_t offObjOps;
173
174 /**
175 * Set the unix style owner and group.
176 *
177 * @returns IPRT status code.
178 * @param pvThis The implementation specific file data.
179 * @param fMode The new mode bits.
180 * @param fMask The mask indicating which bits we are
181 * changing.
182 * @sa RTFileSetMode
183 */
184 DECLCALLBACKMEMBER(int, pfnSetMode)(void *pvThis, RTFMODE fMode, RTFMODE fMask);
185
186 /**
187 * Set the timestamps associated with the object.
188 *
189 * @returns IPRT status code.
190 * @param pvThis The implementation specific file data.
191 * @param pAccessTime Pointer to the new access time. NULL if not
192 * to be changed.
193 * @param pModificationTime Pointer to the new modifcation time. NULL if
194 * not to be changed.
195 * @param pChangeTime Pointer to the new change time. NULL if not
196 * to be changed.
197 * @param pBirthTime Pointer to the new time of birth. NULL if
198 * not to be changed.
199 * @remarks See RTFileSetTimes for restrictions and behavior imposed by the
200 * host OS or underlying VFS provider.
201 * @sa RTFileSetTimes
202 */
203 DECLCALLBACKMEMBER(int, pfnSetTimes)(void *pvThis, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
204 PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime);
205
206 /**
207 * Set the unix style owner and group.
208 *
209 * @returns IPRT status code.
210 * @param pvThis The implementation specific file data.
211 * @param uid The user ID of the new owner. NIL_RTUID if
212 * unchanged.
213 * @param gid The group ID of the new owner group. NIL_RTGID if
214 * unchanged.
215 * @sa RTFileSetOwner
216 */
217 DECLCALLBACKMEMBER(int, pfnSetOwner)(void *pvThis, RTUID uid, RTGID gid);
218
219 /** Marks the end of the structure (RTVFSOBJSETOPS_VERSION). */
220 uintptr_t uEndMarker;
221} RTVFSOBJSETOPS;
222/** Pointer to const object attribute setter operations. */
223typedef RTVFSOBJSETOPS const *PCRTVFSOBJSETOPS;
224
225/** The RTVFSOBJSETOPS structure version. */
226#define RTVFSOBJSETOPS_VERSION RT_MAKE_U32_FROM_U8(0xff,0x2f,1,0)
227
228
229/**
230 * The directory operations.
231 *
232 * @extends RTVFSOBJOPS
233 * @extends RTVFSOBJSETOPS
234 */
235typedef struct RTVFSDIROPS
236{
237 /** The basic object operation. */
238 RTVFSOBJOPS Obj;
239 /** The structure version (RTVFSDIROPS_VERSION). */
240 uint32_t uVersion;
241 /** Reserved field, MBZ. */
242 uint32_t fReserved;
243 /** The object setter operations. */
244 RTVFSOBJSETOPS ObjSet;
245
246 /**
247 * Opens a directory entry for traversal purposes.
248 *
249 * Method which sole purpose is helping the path traversal. Only one of
250 * the three output variables will be set, the others will left untouched
251 * (caller sets them to NIL).
252 *
253 * @returns IPRT status code.
254 * @retval VERR_PATH_NOT_FOUND if @a pszEntry was not found.
255 * @param pvThis The implementation specific directory data.
256 * @param pszEntry The name of the directory entry to remove.
257 * @param phVfsDir If not NULL and it is a directory, open it and
258 * return the handle here.
259 * @param phVfsSymlink If not NULL and it is a symbolic link, open it
260 * and return the handle here.
261 * @param phVfsMounted If not NULL and it is a mounted VFS directory,
262 * reference it and return the handle here.
263 * @todo Should com dir, symlinks and mount points using some common
264 * ancestor "class".
265 */
266 DECLCALLBACKMEMBER(int, pfnTraversalOpen)(void *pvThis, const char *pszEntry, PRTVFSDIR phVfsDir,
267 PRTVFSSYMLINK phVfsSymlink, PRTVFS phVfsMounted);
268
269 /**
270 * Open or create a file.
271 *
272 * @returns IPRT status code.
273 * @param pvThis The implementation specific directory data.
274 * @param pszFilename The name of the immediate file to open or create.
275 * @param fOpen The open flags (RTFILE_O_XXX).
276 * @param phVfsFile Where to return the thandle to the opened file.
277 * @sa RTFileOpen.
278 */
279 DECLCALLBACKMEMBER(int, pfnOpenFile)(void *pvThis, const char *pszFilename, uint32_t fOpen, PRTVFSFILE phVfsFile);
280
281 /**
282 * Open an existing subdirectory.
283 *
284 * @returns IPRT status code.
285 * @param pvThis The implementation specific directory data.
286 * @param pszSubDir The name of the immediate subdirectory to open.
287 * @param phVfsDir Where to return the handle to the opened directory.
288 * @sa RTDirOpen.
289 */
290 DECLCALLBACKMEMBER(int, pfnOpenDir)(void *pvThis, const char *pszSubDir, PRTVFSDIR phVfsDir);
291
292 /**
293 * Creates a new subdirectory.
294 *
295 * @returns IPRT status code.
296 * @param pvThis The implementation specific directory data.
297 * @param pszSubDir The name of the immediate subdirectory to create.
298 * @param fMode The mode mask of the new directory.
299 * @param phVfsDir Where to optionally return the handle to the newly
300 * create directory.
301 * @sa RTDirCreate.
302 */
303 DECLCALLBACKMEMBER(int, pfnCreateDir)(void *pvThis, const char *pszSubDir, RTFMODE fMode, PRTVFSDIR phVfsDir);
304
305 /**
306 * Opens an existing symbolic link.
307 *
308 * @returns IPRT status code.
309 * @param pvThis The implementation specific directory data.
310 * @param pszSymlink The name of the immediate symbolic link to open.
311 * @param phVfsSymlink Where to optionally return the handle to the
312 * newly create symbolic link.
313 * @sa RTSymlinkCreate.
314 */
315 DECLCALLBACKMEMBER(int, pfnOpenSymlink)(void *pvThis, const char *pszSymlink, PRTVFSSYMLINK phVfsSymlink);
316
317 /**
318 * Creates a new symbolic link.
319 *
320 * @returns IPRT status code.
321 * @param pvThis The implementation specific directory data.
322 * @param pszSymlink The name of the immediate symbolic link to create.
323 * @param pszTarget The symbolic link target.
324 * @param enmType The symbolic link type.
325 * @param phVfsSymlink Where to optionally return the handle to the
326 * newly create symbolic link.
327 * @sa RTSymlinkCreate.
328 */
329 DECLCALLBACKMEMBER(int, pfnCreateSymlink)(void *pvThis, const char *pszSymlink, const char *pszTarget,
330 RTSYMLINKTYPE enmType, PRTVFSSYMLINK phVfsSymlink);
331
332 /**
333 * Removes a directory entry.
334 *
335 * @returns IPRT status code.
336 * @param pvThis The implementation specific directory data.
337 * @param pszEntry The name of the directory entry to remove.
338 * @param fType If non-zero, this restricts the type of the entry to
339 * the object type indicated by the mask
340 * (RTFS_TYPE_XXX).
341 * @sa RTFileRemove, RTDirRemove, RTSymlinkRemove.
342 */
343 DECLCALLBACKMEMBER(int, pfnUnlinkEntry)(void *pvThis, const char *pszEntry, RTFMODE fType, PRTVFSDIR phVfsDir);
344
345 /**
346 * Rewind the directory stream so that the next read returns the first
347 * entry.
348 *
349 * @returns IPRT status code.
350 * @param pvThis The implementation specific directory data.
351 */
352 DECLCALLBACKMEMBER(int, pfnRewindDir)(void *pvThis);
353
354 /**
355 * Rewind the directory stream so that the next read returns the first
356 * entry.
357 *
358 * @returns IPRT status code.
359 * @param pvThis The implementation specific directory data.
360 * @param pDirEntry Output buffer.
361 * @param pcbDirEntry Complicated, see RTDirReadEx.
362 * @param enmAddAttr Which set of additional attributes to request.
363 * @sa RTDirReadEx
364 */
365 DECLCALLBACKMEMBER(int, pfnReadDir)(void *pvThis, PRTDIRENTRYEX pDirEntry, size_t *pcbDirEntry, RTFSOBJATTRADD enmAddAttr);
366
367
368 /** Marks the end of the structure (RTVFSDIROPS_VERSION). */
369 uintptr_t uEndMarker;
370} RTVFSDIROPS;
371/** Pointer to const directory operations. */
372typedef RTVFSDIROPS const *PCRTVFSDIROPS;
373/** The RTVFSDIROPS structure version. */
374#define RTVFSDIROPS_VERSION RT_MAKE_U32_FROM_U8(0xff,0x3f,1,0)
375
376
377/**
378 * The symbolic link operations.
379 *
380 * @extends RTVFSOBJOPS
381 * @extends RTVFSOBJSETOPS
382 */
383typedef struct RTVFSSYMLINKOPS
384{
385 /** The basic object operation. */
386 RTVFSOBJOPS Obj;
387 /** The structure version (RTVFSSYMLINKOPS_VERSION). */
388 uint32_t uVersion;
389 /** Reserved field, MBZ. */
390 uint32_t fReserved;
391 /** The object setter operations. */
392 RTVFSOBJSETOPS ObjSet;
393
394 /**
395 * Read the symbolic link target.
396 *
397 * @returns IPRT status code.
398 * @param pvThis The implementation specific symbolic link data.
399 * @param pszTarget The target buffer.
400 * @param cbTarget The size of the target buffer.
401 * @sa RTSymlinkRead
402 */
403 DECLCALLBACKMEMBER(int, pfnRead)(void *pvThis, char *pszTarget, size_t cbTarget);
404
405 /** Marks the end of the structure (RTVFSSYMLINKOPS_VERSION). */
406 uintptr_t uEndMarker;
407} RTVFSSYMLINKOPS;
408/** Pointer to const symbolic link operations. */
409typedef RTVFSSYMLINKOPS const *PCRTVFSSYMLINKOPS;
410/** The RTVFSSYMLINKOPS structure version. */
411#define RTVFSSYMLINKOPS_VERSION RT_MAKE_U32_FROM_U8(0xff,0x4f,1,0)
412
413
414/**
415 * The basis for all I/O objects (files, pipes, sockets, devices, ++).
416 *
417 * @extends RTVFSOBJOPS
418 */
419typedef struct RTVFSIOSTREAMOPS
420{
421 /** The basic object operation. */
422 RTVFSOBJOPS Obj;
423 /** The structure version (RTVFSIOSTREAMOPS_VERSION). */
424 uint32_t uVersion;
425 /** Reserved field, MBZ. */
426 uint32_t fReserved;
427
428 /**
429 * Reads from the file/stream.
430 *
431 * @returns IPRT status code.
432 * @param pvThis The implementation specific file data.
433 * @param off Where to read at, -1 for the current position.
434 * @param pSgBuf Gather buffer describing the bytes that are to be
435 * written.
436 * @param fBlocking If @c true, the call is blocking, if @c false it
437 * should not block.
438 * @param pcbRead Where return the number of bytes actually read. If
439 * NULL, try read all and fail if incomplete.
440 * @sa RTFileRead, RTFileReadAt.
441 */
442 DECLCALLBACKMEMBER(int, pfnRead)(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead);
443
444 /**
445 * Writes to the file/stream.
446 *
447 * @returns IPRT status code.
448 * @param pvThis The implementation specific file data.
449 * @param off Where to start wrinting, -1 for the current
450 * position.
451 * @param pSgBuf Gather buffers describing the bytes that are to be
452 * written.
453 * @param fBlocking If @c true, the call is blocking, if @c false it
454 * should not block.
455 * @param pcbWrite Where to return the number of bytes actually
456 * written. If NULL, try write it all and fail if
457 * incomplete.
458 * @sa RTFileWrite, RTFileWriteAt.
459 */
460 DECLCALLBACKMEMBER(int, pfnWrite)(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten);
461
462 /**
463 * Flushes any pending data writes to the stream.
464 *
465 * @returns IPRT status code.
466 * @param pvThis The implementation specific file data.
467 * @sa RTFileFlush.
468 */
469 DECLCALLBACKMEMBER(int, pfnFlush)(void *pvThis);
470
471 /**
472 * Poll for events.
473 *
474 * @returns IPRT status code.
475 * @param pvThis The implementation specific file data.
476 * @param fEvents The events to poll for (RTPOLL_EVT_XXX).
477 * @param cMillies How long to wait for event to eventuate.
478 * @param fIntr Whether the wait is interruptible and can return
479 * VERR_INTERRUPTED (@c true) or if this condition
480 * should be hidden from the caller (@c false).
481 * @param pfRetEvents Where to return the event mask.
482 * @sa RTPollSetAdd, RTPoll, RTPollNoResume.
483 */
484 DECLCALLBACKMEMBER(int, pfnPollOne)(void *pvThis, uint32_t fEvents, RTMSINTERVAL cMillies, bool fIntr,
485 uint32_t *pfRetEvents);
486
487 /**
488 * Tells the current file/stream position.
489 *
490 * @returns IPRT status code.
491 * @param pvThis The implementation specific file data.
492 * @param poffActual Where to return the actual offset.
493 * @sa RTFileTell
494 */
495 DECLCALLBACKMEMBER(int, pfnTell)(void *pvThis, PRTFOFF poffActual);
496
497 /**
498 * Skips @a cb ahead in the stream.
499 *
500 * @returns IPRT status code.
501 * @param pvThis The implementation specific file data.
502 * @param cb The number bytes to skip.
503 * @remarks This is optional and can be NULL.
504 */
505 DECLCALLBACKMEMBER(int, pfnSkip)(void *pvThis, RTFOFF cb);
506
507 /**
508 * Fills the stream with @a cb zeros.
509 *
510 * @returns IPRT status code.
511 * @param pvThis The implementation specific file data.
512 * @param cb The number of zero bytes to insert.
513 * @remarks This is optional and can be NULL.
514 */
515 DECLCALLBACKMEMBER(int, pfnZeroFill)(void *pvThis, RTFOFF cb);
516
517 /** Marks the end of the structure (RTVFSIOSTREAMOPS_VERSION). */
518 uintptr_t uEndMarker;
519} RTVFSIOSTREAMOPS;
520/** Pointer to const I/O stream operations. */
521typedef RTVFSIOSTREAMOPS const *PCRTVFSIOSTREAMOPS;
522
523/** The RTVFSIOSTREAMOPS structure version. */
524#define RTVFSIOSTREAMOPS_VERSION RT_MAKE_U32_FROM_U8(0xff,0x5f,1,0)
525
526
527/**
528 * Creates a new VFS I/O stream handle.
529 *
530 * @returns IPRT status code
531 * @param pIoStreamOps The I/O stream operations.
532 * @param cbInstance The size of the instance data.
533 * @param fOpen The open flags. The minimum is the access mask.
534 * @param hVfs The VFS handle to associate this file with.
535 * NIL_VFS is ok.
536 * @param hSemRW The read-write semaphore to use to protect the
537 * handle if this differs from the one the VFS
538 * uses. NIL_RTSEMRW is ok if no locking is
539 * desired.
540 * @param phVfsIos Where to return the new handle.
541 * @param ppvInstance Where to return the pointer to the instance data
542 * (size is @a cbInstance).
543 */
544RTDECL(int) RTVfsNewIoStream(PCRTVFSIOSTREAMOPS pIoStreamOps, size_t cbInstance, uint32_t fOpen, RTVFS hVfs, RTSEMRW hSemRW,
545 PRTVFSIOSTREAM phVfsIos, void **ppvInstance);
546
547
548/**
549 * The file operations.
550 *
551 * @extends RTVFSIOSTREAMOPS
552 * @extends RTVFSOBJSETOPS
553 */
554typedef struct RTVFSFILEOPS
555{
556 /** The I/O stream and basis object operations. */
557 RTVFSIOSTREAMOPS Stream;
558 /** The structure version (RTVFSFILEOPS_VERSION). */
559 uint32_t uVersion;
560 /** Reserved field, MBZ. */
561 uint32_t fReserved;
562 /** The object setter operations. */
563 RTVFSOBJSETOPS ObjSet;
564
565 /**
566 * Changes the current file position.
567 *
568 * @returns IPRT status code.
569 * @param pvThis The implementation specific file data.
570 * @param offSeek The offset to seek.
571 * @param uMethod The seek method, i.e. what the seek is relative to.
572 * @param poffActual Where to return the actual offset.
573 * @sa RTFileSeek
574 */
575 DECLCALLBACKMEMBER(int, pfnSeek)(void *pvThis, RTFOFF offSeek, unsigned uMethod, PRTFOFF poffActual);
576
577 /**
578 * Get the current file/stream size.
579 *
580 * @returns IPRT status code.
581 * @param pvThis The implementation specific file data.
582 * @param pcbFile Where to store the current file size.
583 * @sa RTFileGetSize
584 */
585 DECLCALLBACKMEMBER(int, pfnQuerySize)(void *pvThis, uint64_t *pcbFile);
586
587 /** @todo There will be more methods here. */
588
589 /** Marks the end of the structure (RTVFSFILEOPS_VERSION). */
590 uintptr_t uEndMarker;
591} RTVFSFILEOPS;
592/** Pointer to const file operations. */
593typedef RTVFSFILEOPS const *PCRTVFSFILEOPS;
594
595/** The RTVFSFILEOPS structure version. */
596#define RTVFSFILEOPS_VERSION RT_MAKE_U32_FROM_U8(0xff,0x6f,1,0)
597
598/**
599 * Creates a new VFS file handle.
600 *
601 * @returns IPRT status code
602 * @param pFileOps The file operations.
603 * @param cbInstance The size of the instance data.
604 * @param fOpen The open flags. The minimum is the access mask.
605 * @param hVfs The VFS handle to associate this file with.
606 * NIL_VFS is ok.
607 * @param phVfsFile Where to return the new handle.
608 * @param ppvInstance Where to return the pointer to the instance data
609 * (size is @a cbInstance).
610 */
611RTDECL(int) RTVfsNewFile(PCRTVFSFILEOPS pFileOps, size_t cbInstance, uint32_t fOpen, RTVFS hVfs,
612 PRTVFSFILE phVfsFile, void **ppvInstance);
613
614
615/** @defgroup grp_rt_vfs_ll_util VFS Utility APIs
616 * @{ */
617
618/**
619 * Parsed path.
620 */
621typedef struct RTVFSPARSEDPATH
622{
623 /** The length of the path in szCopy. */
624 uint16_t cch;
625 /** The number of path components. */
626 uint16_t cComponents;
627 /** Set if the path ends with slash, indicating that it's a directory
628 * reference and not a file reference. The slash has been removed from
629 * the copy. */
630 bool fDirSlash;
631 /** The offset where each path component starts, i.e. the char after the
632 * slash. The array has cComponents + 1 entries, where the final one is
633 * cch + 1 so that one can always terminate the current component by
634 * szPath[aoffComponent[i] - 1] = '\0'. */
635 uint16_t aoffComponents[RTPATH_MAX / 2 + 1];
636 /** A normalized copy of the path.
637 * Reserve some extra space so we can be more relaxed about overflow
638 * checks and terminator paddings, especially when recursing. */
639 char szPath[RTPATH_MAX];
640} RTVFSPARSEDPATH;
641/** Pointer to a parsed path. */
642typedef RTVFSPARSEDPATH *PRTVFSPARSEDPATH;
643
644/** The max accepted path length.
645 * This must be a few chars shorter than RTVFSPARSEDPATH::szPath because we
646 * use two terminators and wish be a little bit lazy with checking. */
647#define RTVFSPARSEDPATH_MAX (RTPATH_MAX - 4)
648
649/**
650 * Appends @a pszPath (relative) to the already parsed path @a pPath.
651 *
652 * @retval VINF_SUCCESS
653 * @retval VERR_FILENAME_TOO_LONG
654 * @retval VERR_INTERNAL_ERROR_4
655 * @param pPath The parsed path to append @a pszPath onto.
656 * This is both input and output.
657 * @param pszPath The path to append. This must be relative.
658 * @param piRestartComp The component to restart parsing at. This is
659 * input/output. The input does not have to be
660 * within the valid range. Optional.
661 */
662RTDECL(int) RTVfsParsePathAppend(PRTVFSPARSEDPATH pPath, const char *pszPath, uint16_t *piRestartComp);
663
664/**
665 * Parses a path.
666 *
667 * @retval VINF_SUCCESS
668 * @retval VERR_FILENAME_TOO_LONG
669 * @param pPath Where to store the parsed path.
670 * @param pszPath The path to parse. Absolute or relative to @a
671 * pszCwd.
672 * @param pszCwd The current working directory. Must be
673 * absolute.
674 */
675RTDECL(int) RTVfsParsePath(PRTVFSPARSEDPATH pPath, const char *pszPath, const char *pszCwd);
676
677/**
678 * Same as RTVfsParsePath except that it allocates a temporary buffer.
679 *
680 * @retval VINF_SUCCESS
681 * @retval VERR_NO_TMP_MEMORY
682 * @retval VERR_FILENAME_TOO_LONG
683 * @param pszPath The path to parse. Absolute or relative to @a
684 * pszCwd.
685 * @param pszCwd The current working directory. Must be
686 * absolute.
687 * @param ppPath Where to store the pointer to the allocated
688 * buffer containing the parsed path. This must
689 * be freed by calling RTVfsParsePathFree. NULL
690 * will be stored on failured.
691 */
692RTDECL(int) RTVfsParsePathA(const char *pszPath, const char *pszCwd, PRTVFSPARSEDPATH *ppPath);
693
694/**
695 * Frees a buffer returned by RTVfsParsePathA.
696 *
697 * @param pPath The parsed path buffer to free. NULL is fine.
698 */
699RTDECL(void) RTVfsParsePathFree(PRTVFSPARSEDPATH pPath);
700
701/** @} */
702
703/** @} */
704
705RT_C_DECLS_END
706
707#endif /* !___iprt_vfslowlevel_h */
708
709
710
711
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette