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_vfs_h
|
---|
27 | #define ___iprt_vfs_h
|
---|
28 |
|
---|
29 | #include <iprt/cdefs.h>
|
---|
30 | #include <iprt/types.h>
|
---|
31 | #include <iprt/dir.h>
|
---|
32 | #include <iprt/fs.h>
|
---|
33 | #include <iprt/symlink.h>
|
---|
34 | #include <iprt/sg.h>
|
---|
35 | #include <iprt/time.h>
|
---|
36 |
|
---|
37 |
|
---|
38 | RT_C_DECLS_BEGIN
|
---|
39 |
|
---|
40 | /** @defgroup grp_rt_fs RTVfs - Virtual Filesystem
|
---|
41 | * @ingroup grp_rt
|
---|
42 | *
|
---|
43 | * The virtual filesystem APIs are intended to make it possible to work on
|
---|
44 | * container files, file system sub-trees, file system overlays and other custom
|
---|
45 | * filesystem configurations. It also makes it possible to create filters, like
|
---|
46 | * automatically gunzipping a tar.gz file before feeding it to the RTTar API for
|
---|
47 | * unpacking - or wise versa.
|
---|
48 | *
|
---|
49 | * The virtual filesystem APIs are intended to mirror the RTDir, RTFile, RTPath
|
---|
50 | * and RTFs APIs pretty closely so that rewriting a piece of code to work with
|
---|
51 | * it should be easy. However there are some differences to the way the APIs
|
---|
52 | * works and the user should heed the documentation. The differences are
|
---|
53 | * usually motivated by simplification and in some case to make the VFS more
|
---|
54 | * flexible.
|
---|
55 | *
|
---|
56 | * @{
|
---|
57 | */
|
---|
58 |
|
---|
59 | /** Virtual Filesystem handle. */
|
---|
60 | typedef struct RTVFSINTERNAL *RTVFS;
|
---|
61 | /** Pointer to a VFS handle. */
|
---|
62 | typedef RTVFS *PRTVFS;
|
---|
63 | /** A NIL VFS directory handle. */
|
---|
64 | #define NIL_RTVFS ((RTVFS)~(uintptr_t)0)
|
---|
65 |
|
---|
66 | /** Virtual Filesystem directory handle. */
|
---|
67 | typedef struct RTVFSDIRINTERNAL *RTVFSDIR;
|
---|
68 | /** Pointer to a VFS directory handle. */
|
---|
69 | typedef RTVFSDIR *PRTVFSDIR;
|
---|
70 | /** A NIL VFS directory handle. */
|
---|
71 | #define NIL_RTVFSDIR ((RTVFSDIR)~(uintptr_t)0)
|
---|
72 |
|
---|
73 | /** Virtual Filesystem I/O stream handle. */
|
---|
74 | typedef struct RTVFSIOSTREAMINTERNAL *RTVFSIOSTREAM;
|
---|
75 | /** Pointer to a VFS I/O stream handle. */
|
---|
76 | typedef RTVFSIOSTREAM *PRTVFSIOSTREAM;
|
---|
77 | /** A NIL VFS I/O stream handle. */
|
---|
78 | #define NIL_RTVFSIOSTREAM ((RTVFSIOSTREAM)~(uintptr_t)0)
|
---|
79 |
|
---|
80 | /** Virtual Filesystem file handle. */
|
---|
81 | typedef struct RTVFSFILEINTERNAL *RTVFSFILE;
|
---|
82 | /** Pointer to a VFS file handle. */
|
---|
83 | typedef RTVFSFILE *PRTVFSFILE;
|
---|
84 | /** A NIL VFS file handle. */
|
---|
85 | #define NIL_RTVFSFILE ((RTVFSFILE)~(uintptr_t)0)
|
---|
86 |
|
---|
87 | /** Virtual Filesystem symbolic link handle. */
|
---|
88 | typedef struct RTVFSSYMLINKINTERNAL *RTVFSSYMLINK;
|
---|
89 | /** Pointer to a VFS symbolic link handle. */
|
---|
90 | typedef RTVFSSYMLINK *PRTVFSSYMLINK;
|
---|
91 | /** A NIL VFS symbolic link handle. */
|
---|
92 | #define NIL_RTVFSSYMLINK ((RTVFSSYMLINK)~(uintptr_t)0)
|
---|
93 |
|
---|
94 |
|
---|
95 | /** @name RTVfsCreate flags
|
---|
96 | * @{ */
|
---|
97 | /** Whether the file system is read-only. */
|
---|
98 | #define RTVFS_C_READONLY RT_BIT(0)
|
---|
99 | /** Whether we the VFS should be thread safe (i.e. automaticaly employ
|
---|
100 | * locks). */
|
---|
101 | #define RTVFS_C_THREAD_SAFE RT_BIT(1)
|
---|
102 | /** @} */
|
---|
103 |
|
---|
104 | /**
|
---|
105 | * Creates an empty virtual filesystem.
|
---|
106 | *
|
---|
107 | * @returns IPRT status code.
|
---|
108 | * @param pszName Name, for logging and such.
|
---|
109 | * @param fFlags Flags, MBZ.
|
---|
110 | * @param phVfs Where to return the VFS handle. Release the returned
|
---|
111 | * reference by calling RTVfsRelease.
|
---|
112 | */
|
---|
113 | RTDECL(int) RTVfsCreate(const char *pszName, uint32_t fFlags, PRTVFS phVfs);
|
---|
114 | RTDECL(uint32_t) RTVfsRetain(RTVFS phVfs);
|
---|
115 | RTDECL(uint32_t) RTVfsRelease(RTVFS phVfs);
|
---|
116 | RTDECL(int) RTVfsAttach(RTVFS hVfs, const char *pszMountPoint, uint32_t fFlags, RTVFS hVfsAttach);
|
---|
117 | RTDECL(int) RTVfsDetach(RTVFS hVfs, const char *pszMountPoint, RTVFS hVfsToDetach, PRTVFS *phVfsDetached);
|
---|
118 | RTDECL(uint32_t) RTVfsGetAttachmentCount(RTVFS hVfs);
|
---|
119 | RTDECL(int) RTVfsGetAttachment(RTVFS hVfs, uint32_t iOrdinal, PRTVFS *phVfsAttached, uint32_t *pfFlags,
|
---|
120 | char *pszMountPoint, size_t cbMountPoint);
|
---|
121 |
|
---|
122 | /** @defgroup grp_vfs_dir VFS Directory API
|
---|
123 | * @{
|
---|
124 | */
|
---|
125 | /** @} */
|
---|
126 |
|
---|
127 |
|
---|
128 | /** @defgroup grp_vfs_iostream VFS I/O Stream
|
---|
129 | * @{
|
---|
130 | */
|
---|
131 |
|
---|
132 | /**
|
---|
133 | * Retains a reference to the VFS I/O stream handle.
|
---|
134 | *
|
---|
135 | * @returns New reference count on success, UINT32_MAX on failure.
|
---|
136 | * @param hVfsIos The VFS I/O stream handle.
|
---|
137 | */
|
---|
138 | RTDECL(uint32_t) RTVfsIoStrmRetain(RTVFSIOSTREAM hVfsIos);
|
---|
139 |
|
---|
140 | /**
|
---|
141 | * Releases a reference to the VFS I/O stream handle.
|
---|
142 | *
|
---|
143 | * @returns New reference count on success (0 if closed), UINT32_MAX on failure.
|
---|
144 | * @param hVfsIos The VFS I/O stream handle.
|
---|
145 | */
|
---|
146 | RTDECL(uint32_t) RTVfsIoStrmRelease(RTVFSIOSTREAM hVfsIos);
|
---|
147 |
|
---|
148 | /**
|
---|
149 | * Convert the VFS I/O stream handle to a VFS file handle.
|
---|
150 | *
|
---|
151 | * @returns The VFS file handle on success, this must be released.
|
---|
152 | * NIL_RTVFSFILE if the I/O stream handle is invalid.
|
---|
153 | * @param hVfsIos The VFS I/O stream handle.
|
---|
154 | * @sa RTVfsFileToIoStream
|
---|
155 | */
|
---|
156 | RTDECL(RTVFSFILE) RTVfsIoStrmToFile(RTVFSIOSTREAM hVfsIos);
|
---|
157 |
|
---|
158 | /**
|
---|
159 | * Query information about the I/O stream.
|
---|
160 | *
|
---|
161 | * @returns IPRT status code.
|
---|
162 | * @param hVfsIos The VFS I/O stream handle.
|
---|
163 | * @param pObjInfo Where to return the info.
|
---|
164 | * @param enmAddAttr Which additional attributes should be retrieved.
|
---|
165 | * @sa RTFileQueryInfo
|
---|
166 | */
|
---|
167 | RTDECL(int) RTVfsIoStrmQueryInfo(RTVFSIOSTREAM hVfsIos, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr);
|
---|
168 |
|
---|
169 | /**
|
---|
170 | * Read bytes from the I/O stream.
|
---|
171 | *
|
---|
172 | * @returns IPRT status code.
|
---|
173 | * @param hVfsIos The VFS I/O stream handle.
|
---|
174 | * @param pvBuf Where to store the read bytes.
|
---|
175 | * @param cbToRead The number of bytes to read.
|
---|
176 | * @param pcbRead Where to store the number of bytes actually read.
|
---|
177 | * If this is NULL, the call will block until @a
|
---|
178 | * cbToRead bytes are available. If this is non-NULL,
|
---|
179 | * the call will not block and return what is currently
|
---|
180 | * avaiable.
|
---|
181 | * @sa RTFileRead, RTPipeRead, RTPipeReadBlocking, RTSocketRead
|
---|
182 | */
|
---|
183 | RTDECL(int) RTVfsIoStrmRead(RTVFSIOSTREAM hVfsIos, void *pvBuf, size_t cbToRead, size_t *pcbRead);
|
---|
184 |
|
---|
185 | /**
|
---|
186 | * Write bytes to the I/O stream.
|
---|
187 | *
|
---|
188 | * @returns IPRT status code.
|
---|
189 | * @param hVfsIos The VFS I/O stream handle.
|
---|
190 | * @param pvBuf The bytes to write.
|
---|
191 | * @param cbToWrite The number of bytes to write.
|
---|
192 | * @param pcbWritten Where to store the number of bytes actually written.
|
---|
193 | * If this is NULL, the call will block until @a
|
---|
194 | * cbToWrite bytes are available. If this is non-NULL,
|
---|
195 | * the call will not block and return after writing
|
---|
196 | * what is possible.
|
---|
197 | * @sa RTFileWrite, RTPipeWrite, RTPipeWriteBlocking, RTSocketWrite
|
---|
198 | */
|
---|
199 | RTDECL(int) RTVfsIoStrmWrite(RTVFSIOSTREAM hVfsIos, const void *pvBuf, size_t cbToWrite, size_t *pcbWritten);
|
---|
200 |
|
---|
201 | /**
|
---|
202 | * Reads bytes from the I/O stream into a scatter buffer.
|
---|
203 | *
|
---|
204 | * @returns IPRT status code.
|
---|
205 | * @param hVfsIos The VFS I/O stream handle.
|
---|
206 | * @param pSgBuf Pointer to a scatter buffer descriptor. The number
|
---|
207 | * of bytes described by the segments is what will be
|
---|
208 | * attemted read.
|
---|
209 | * @param fBlocking Whether the call is blocking (@c true) or not. If
|
---|
210 | * not, the @a pcbRead parameter must not be NULL.
|
---|
211 | * @param pcbRead Where to store the number of bytes actually read.
|
---|
212 | * This can be NULL if @a fBlocking is true.
|
---|
213 | * @sa RTFileSgRead, RTSocketSgRead
|
---|
214 | */
|
---|
215 | RTDECL(int) RTVfsIoStrmSgRead(RTVFSIOSTREAM hVfsIos, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead);
|
---|
216 |
|
---|
217 | /**
|
---|
218 | * Write bytes to the I/O stream from a gather buffer.
|
---|
219 | *
|
---|
220 | * @returns IPRT status code.
|
---|
221 | * @param hVfsIos The VFS I/O stream handle.
|
---|
222 | * @param pSgBuf Pointer to a gather buffer descriptor. The number
|
---|
223 | * of bytes described by the segments is what will be
|
---|
224 | * attemted written.
|
---|
225 | * @param fBlocking Whether the call is blocking (@c true) or not. If
|
---|
226 | * not, the @a pcbWritten parameter must not be NULL.
|
---|
227 | * @param pcbRead Where to store the number of bytes actually written.
|
---|
228 | * This can be NULL if @a fBlocking is true.
|
---|
229 | * @sa RTFileSgWrite, RTSocketSgWrite
|
---|
230 | */
|
---|
231 | RTDECL(int) RTVfsIoStrmSgWrite(RTVFSIOSTREAM hVfsIos, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten);
|
---|
232 |
|
---|
233 | /**
|
---|
234 | * Flush any buffered data to the I/O stream.
|
---|
235 | *
|
---|
236 | * @returns IPRT status code.
|
---|
237 | * @param hVfsIos The VFS I/O stream handle.
|
---|
238 | * @sa RTFileFlush, RTPipeFlush
|
---|
239 | */
|
---|
240 | RTDECL(int) RTVfsIoStrmFlush(RTVFSIOSTREAM hVfsIos);
|
---|
241 |
|
---|
242 | /**
|
---|
243 | * Poll for events.
|
---|
244 | *
|
---|
245 | * @returns IPRT status code.
|
---|
246 | * @param hVfsIos The VFS I/O stream handle.
|
---|
247 | * @param fEvents The events to poll for (RTPOLL_EVT_XXX).
|
---|
248 | * @param cMillies How long to wait for event to eventuate.
|
---|
249 | * @param fIntr Whether the wait is interruptible and can return
|
---|
250 | * VERR_INTERRUPTED (@c true) or if this condition
|
---|
251 | * should be hidden from the caller (@c false).
|
---|
252 | * @param pfRetEvents Where to return the event mask.
|
---|
253 | * @sa RTPollSetAdd, RTPoll, RTPollNoResume.
|
---|
254 | */
|
---|
255 | RTDECL(RTFOFF) RTVfsIoStrmPoll(RTVFSIOSTREAM hVfsIos, uint32_t fEvents, RTMSINTERVAL cMillies, bool fIntr,
|
---|
256 | uint32_t *pfRetEvents);
|
---|
257 | /**
|
---|
258 | * Tells the current I/O stream position.
|
---|
259 | *
|
---|
260 | * @returns Zero or higher - where to return the I/O stream offset. Values
|
---|
261 | * below zero are IPRT status codes (VERR_XXX).
|
---|
262 | * @param hVfsIos The VFS I/O stream handle.
|
---|
263 | * @sa RTFileTell
|
---|
264 | */
|
---|
265 | RTDECL(RTFOFF) RTVfsIoStrmTell(RTVFSIOSTREAM hVfsIos);
|
---|
266 | /** @} */
|
---|
267 |
|
---|
268 |
|
---|
269 | /** @defgroup grp_vfs_file VFS File API
|
---|
270 | * @{
|
---|
271 | */
|
---|
272 | RTDECL(int) RTVfsFileOpen(RTVFS hVfs, const char *pszFilename, uint32_t fOpen, PRTVFSFILE phVfsFile);
|
---|
273 |
|
---|
274 | /**
|
---|
275 | * Create a VFS file handle from a standard IPRT file handle (RTFILE).
|
---|
276 | *
|
---|
277 | * @returns IPRT status code.
|
---|
278 | * @param hFile The standard IPRT file handle.
|
---|
279 | * @param fOpen The flags the handle was opened with. Pass 0 to
|
---|
280 | * have these detected.
|
---|
281 | * @param fLeaveOpen Whether to leave the handle open when the VFS file
|
---|
282 | * is released, or to close it (@c false).
|
---|
283 | * @param phVfsFile Where to return the VFS file handle.
|
---|
284 | */
|
---|
285 | RTDECL(int) RTVfsFileFromRTFile(RTFILE hFile, uint32_t fOpen, bool fLeaveOpen, PRTVFSFILE phVfsFile);
|
---|
286 | RTDECL(RTHCUINTPTR) RTVfsFileToNative(RTFILE hVfsFile);
|
---|
287 |
|
---|
288 | /**
|
---|
289 | * Convert the VFS file handle to a VFS I/O stream handle.
|
---|
290 | *
|
---|
291 | * @returns The VFS I/O stream handle on success, this must be released.
|
---|
292 | * NIL_RTVFSIOSTREAM if the file handle is invalid.
|
---|
293 | * @param hVfsFile The VFS file handle.
|
---|
294 | * @sa RTVfsIoStrmToFile
|
---|
295 | */
|
---|
296 | RTDECL(RTVFSIOSTREAM) RTVfsFileToIoStream(RTVFSFILE hVfsFile);
|
---|
297 |
|
---|
298 | /**
|
---|
299 | * Retains a reference to the VFS file handle.
|
---|
300 | *
|
---|
301 | * @returns New reference count on success, UINT32_MAX on failure.
|
---|
302 | * @param hVfsFile The VFS file handle.
|
---|
303 | */
|
---|
304 | RTDECL(uint32_t) RTVfsFileRetain(RTVFSFILE hVfsFile);
|
---|
305 |
|
---|
306 | /**
|
---|
307 | * Releases a reference to the VFS file handle.
|
---|
308 | *
|
---|
309 | * @returns New reference count on success (0 if closed), UINT32_MAX on failure.
|
---|
310 | * @param hVfsFile The VFS file handle.
|
---|
311 | */
|
---|
312 | RTDECL(uint32_t) RTVfsFileRelease(RTVFSFILE hVfsFile);
|
---|
313 |
|
---|
314 | RTDECL(int) RTVfsFileQueryInfo(RTVFSFILE hVfsFile, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr);
|
---|
315 | RTDECL(int) RTVfsFileRead(RTVFSFILE hVfsFile, void *pvBuf, size_t cbToRead, size_t *pcbRead);
|
---|
316 | RTDECL(int) RTVfsFileReadAt(RTVFSFILE hVfsFile, RTFOFF off, void *pvBuf, size_t cbToRead, size_t *pcbRead);
|
---|
317 | RTDECL(int) RTVfsFileWrite(RTVFSFILE hVfsFile, const void *pvBuf, size_t cbToWrite, size_t *pcbWritten);
|
---|
318 | RTDECL(int) RTVfsFileWriteAt(RTVFSFILE hVfsFile, RTFOFF off, const void *pvBuf, size_t cbToWrite, size_t *pcbWritten);
|
---|
319 | RTDECL(int) RTVfsFileFlush(RTVFSFILE hVfsFile);
|
---|
320 | RTDECL(RTFOFF) RTVfsFilePoll(RTVFSFILE hVfsFile, uint32_t fEvents, RTMSINTERVAL cMillies, bool fIntr,
|
---|
321 | uint32_t *pfRetEvents);
|
---|
322 | RTDECL(RTFOFF) RTVfsFileTell(RTVFSFILE hVfsFile);
|
---|
323 |
|
---|
324 | RTDECL(int) RTVfsFileSeek(RTVFSFILE hVfsFile, RTFOFF offSeek, uint32_t uMethod, uint64_t *poffActual);
|
---|
325 | RTDECL(int) RTVfsFileSetSize(RTVFSFILE hVfsFile, uint64_t cbSize);
|
---|
326 | RTDECL(int) RTVfsFileGetSize(RTVFSFILE hVfsFile, uint64_t *pcbSize);
|
---|
327 | RTDECL(RTFOFF) RTVfsFileGetMaxSize(RTVFSFILE hVfsFile);
|
---|
328 | RTDECL(int) RTVfsFileGetMaxSizeEx(RTVFSFILE hVfsFile, PRTFOFF pcbMax);
|
---|
329 |
|
---|
330 | /** @} */
|
---|
331 |
|
---|
332 | /** @} */
|
---|
333 |
|
---|
334 | RT_C_DECLS_END
|
---|
335 |
|
---|
336 | #endif /* !___iprt_vfs_h */
|
---|
337 |
|
---|
338 |
|
---|