1 | /** @file
|
---|
2 | * IPRT - File I/O.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
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 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
26 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
27 | * additional information or have any questions.
|
---|
28 | */
|
---|
29 |
|
---|
30 | #ifndef ___iprt_file_h
|
---|
31 | #define ___iprt_file_h
|
---|
32 |
|
---|
33 | #include <iprt/cdefs.h>
|
---|
34 | #include <iprt/types.h>
|
---|
35 | #ifdef IN_RING3
|
---|
36 | # include <iprt/fs.h>
|
---|
37 | #endif
|
---|
38 |
|
---|
39 | __BEGIN_DECLS
|
---|
40 |
|
---|
41 | /** @defgroup grp_rt_fileio RTFile - File I/O
|
---|
42 | * @ingroup grp_rt
|
---|
43 | * @{
|
---|
44 | */
|
---|
45 |
|
---|
46 | /** Platform specific text line break.
|
---|
47 | * @deprecated Use text I/O streams and '\\n'. See iprt/stream.h. */
|
---|
48 | #if defined(RT_OS_OS2) || defined(RT_OS_WINDOWS)
|
---|
49 | # define RTFILE_LINEFEED "\r\n"
|
---|
50 | #else
|
---|
51 | # define RTFILE_LINEFEED "\n"
|
---|
52 | #endif
|
---|
53 |
|
---|
54 |
|
---|
55 | #ifdef IN_RING3
|
---|
56 |
|
---|
57 | /** @name Open flags
|
---|
58 | * @{ */
|
---|
59 | /** Open the file with read access. */
|
---|
60 | #define RTFILE_O_READ 0x00000001
|
---|
61 | /** Open the file with write access. */
|
---|
62 | #define RTFILE_O_WRITE 0x00000002
|
---|
63 | /** Open the file with read & write access. */
|
---|
64 | #define RTFILE_O_READWRITE 0x00000003
|
---|
65 | /** The file access mask.
|
---|
66 | * @remark The value 0 is invalid. */
|
---|
67 | #define RTFILE_O_ACCESS_MASK 0x00000003
|
---|
68 |
|
---|
69 | /** Sharing mode: deny none (the default mode). */
|
---|
70 | #define RTFILE_O_DENY_NONE 0x00000000
|
---|
71 | /** Sharing mode: deny read. */
|
---|
72 | #define RTFILE_O_DENY_READ 0x00000010
|
---|
73 | /** Sharing mode: deny write. */
|
---|
74 | #define RTFILE_O_DENY_WRITE 0x00000020
|
---|
75 | /** Sharing mode: deny read and write. */
|
---|
76 | #define RTFILE_O_DENY_READWRITE 0x00000030
|
---|
77 | /** Sharing mode: deny all. */
|
---|
78 | #define RTFILE_O_DENY_ALL RTFILE_O_DENY_READWRITE
|
---|
79 | /** Sharing mode: do NOT deny delete (NT).
|
---|
80 | * @remark This might not be implemented on all platforms,
|
---|
81 | * and will be defaulted & ignored on those.
|
---|
82 | */
|
---|
83 | #define RTFILE_O_DENY_NOT_DELETE 0x00000040
|
---|
84 | /** Sharing mode mask. */
|
---|
85 | #define RTFILE_O_DENY_MASK 0x00000070
|
---|
86 |
|
---|
87 | /** Action: Open an existing file (the default action). */
|
---|
88 | #define RTFILE_O_OPEN 0x00000000
|
---|
89 | /** Action: Create a new file or open an existing one. */
|
---|
90 | #define RTFILE_O_OPEN_CREATE 0x00000100
|
---|
91 | /** Action: Create a new a file. */
|
---|
92 | #define RTFILE_O_CREATE 0x00000200
|
---|
93 | /** Action: Create a new file or replace an existing one. */
|
---|
94 | #define RTFILE_O_CREATE_REPLACE 0x00000300
|
---|
95 | /** Action mask. */
|
---|
96 | #define RTFILE_O_ACTION_MASK 0x00000300
|
---|
97 |
|
---|
98 | /** Turns off indexing of files on Windows hosts, *CREATE* only.
|
---|
99 | * @remark This might not be implemented on all platforms,
|
---|
100 | * and will be ignored on those.
|
---|
101 | */
|
---|
102 | #define RTFILE_O_NOT_CONTENT_INDEXED 0x00000800
|
---|
103 | /** Truncate the file.
|
---|
104 | * @remark This will not truncate files opened for read-only.
|
---|
105 | * @remark The trunction doesn't have to be atomically, so anyone
|
---|
106 | * else opening the file may be racing us. The caller is
|
---|
107 | * responsible for not causing this race. */
|
---|
108 | #define RTFILE_O_TRUNCATE 0x00001000
|
---|
109 | /** Make the handle inheritable on RTProcessCreate(/exec). */
|
---|
110 | #define RTFILE_O_INHERIT 0x00002000
|
---|
111 | /** Open file in non-blocking mode - non-portable.
|
---|
112 | * @remark This flag may not be supported on all platforms, in which
|
---|
113 | * case it's considered an invalid parameter.
|
---|
114 | */
|
---|
115 | #define RTFILE_O_NON_BLOCK 0x00004000
|
---|
116 | /** Write through directly to disk. Workaround to avoid iSCSI
|
---|
117 | * initiator deadlocks on Windows hosts.
|
---|
118 | * @remark This might not be implemented on all platforms,
|
---|
119 | * and will be ignored on those.
|
---|
120 | */
|
---|
121 | #define RTFILE_O_WRITE_THROUGH 0x00008000
|
---|
122 |
|
---|
123 | /** File attributes access, *CREATE* only.
|
---|
124 | * @remark This might not be implemented on all platforms,
|
---|
125 | * and will be ignored on those.
|
---|
126 | */
|
---|
127 | /** Attributes can be read if the file is being opened
|
---|
128 | * with read access, and can be written with write access.
|
---|
129 | */
|
---|
130 | #define RTFILE_O_ACCESS_ATTR_DEFAULT 0x00000000
|
---|
131 | /** Attributes can be read. */
|
---|
132 | #define RTFILE_O_ACCESS_ATTR_READ 0x00010000
|
---|
133 | /** Attributes can be written. */
|
---|
134 | #define RTFILE_O_ACCESS_ATTR_WRITE 0x00020000
|
---|
135 | /** Attributes can be both read & written. */
|
---|
136 | #define RTFILE_O_ACCESS_ATTR_READWRITE 0x00030000
|
---|
137 | /** The file attributes access mask. */
|
---|
138 | #define RTFILE_O_ACCESS_ATTR_MASK 0x00030000
|
---|
139 |
|
---|
140 | /** Unix file mode mask for use when creating files. */
|
---|
141 | #define RTFILE_O_CREATE_MODE_MASK 0x1ff00000
|
---|
142 | /** The number of bits to shift to get the file mode mask.
|
---|
143 | * To extract it: (fFlags & RTFILE_O_CREATE_MODE_MASK) >> RTFILE_O_CREATE_MODE_SHIFT.
|
---|
144 | */
|
---|
145 | #define RTFILE_O_CREATE_MODE_SHIFT 20
|
---|
146 | /** Open file for async I/O
|
---|
147 | * @remark This flag may not be needed on all platforms,
|
---|
148 | * and will be ignored on those.
|
---|
149 | */
|
---|
150 | #define RTFILE_O_ASYNC_IO 0x00040000
|
---|
151 |
|
---|
152 | /** Mask of all valid flags.
|
---|
153 | * @remark This doesn't validate the access mode properly.
|
---|
154 | */
|
---|
155 | #define RTFILE_O_VALID_MASK 0x1ff7FB73
|
---|
156 |
|
---|
157 | /** @} */
|
---|
158 |
|
---|
159 |
|
---|
160 | /**
|
---|
161 | * Force the use of open flags for all files opened after the setting is
|
---|
162 | * changed. The caller is responsible for not causing races with RTFileOpen().
|
---|
163 | *
|
---|
164 | * @returns iprt status code.
|
---|
165 | * @param fOpenForAccess Access mode to which the set/mask settings apply.
|
---|
166 | * @param fSet Open flags to be forced set.
|
---|
167 | * @param fMask Open flags to be masked out.
|
---|
168 | */
|
---|
169 | RTR3DECL(int) RTFileSetForceFlags(unsigned fOpenForAccess, unsigned fSet, unsigned fMask);
|
---|
170 |
|
---|
171 | /**
|
---|
172 | * Open a file.
|
---|
173 | *
|
---|
174 | * @returns iprt status code.
|
---|
175 | * @param pFile Where to store the handle to the opened file.
|
---|
176 | * @param pszFilename Path to the file which is to be opened. (UTF-8)
|
---|
177 | * @param fOpen Open flags, i.e a combination of the RTFILE_O_* defines.
|
---|
178 | */
|
---|
179 | RTR3DECL(int) RTFileOpen(PRTFILE pFile, const char *pszFilename, unsigned fOpen);
|
---|
180 |
|
---|
181 | /**
|
---|
182 | * Close a file opened by RTFileOpen().
|
---|
183 | *
|
---|
184 | * @returns iprt status code.
|
---|
185 | * @param File The file handle to close.
|
---|
186 | */
|
---|
187 | RTR3DECL(int) RTFileClose(RTFILE File);
|
---|
188 |
|
---|
189 | /**
|
---|
190 | * Creates an IPRT file handle from a native one.
|
---|
191 | *
|
---|
192 | * @returns IPRT status code.
|
---|
193 | * @param pFile Where to store the IPRT file handle.
|
---|
194 | * @param uNative The native handle.
|
---|
195 | */
|
---|
196 | RTR3DECL(int) RTFileFromNative(PRTFILE pFile, RTHCINTPTR uNative);
|
---|
197 |
|
---|
198 | /**
|
---|
199 | * Gets the native handle for an IPRT file handle.
|
---|
200 | *
|
---|
201 | * @return The native handle.
|
---|
202 | * @params File The IPRT file handle.
|
---|
203 | */
|
---|
204 | RTR3DECL(RTHCINTPTR) RTFileToNative(RTFILE File);
|
---|
205 |
|
---|
206 | /**
|
---|
207 | * Delete a file.
|
---|
208 | *
|
---|
209 | * @returns iprt status code.
|
---|
210 | * @param pszFilename Path to the file which is to be deleted. (UTF-8)
|
---|
211 | * @todo This is a RTPath api!
|
---|
212 | */
|
---|
213 | RTR3DECL(int) RTFileDelete(const char *pszFilename);
|
---|
214 |
|
---|
215 | /** @name Seek flags.
|
---|
216 | * @{ */
|
---|
217 | /** Seek from the start of the file. */
|
---|
218 | #define RTFILE_SEEK_BEGIN 0x00
|
---|
219 | /** Seek from the current file position. */
|
---|
220 | #define RTFILE_SEEK_CURRENT 0x01
|
---|
221 | /** Seek from the end of the file. */
|
---|
222 | #define RTFILE_SEEK_END 0x02
|
---|
223 | /** @internal */
|
---|
224 | #define RTFILE_SEEK_FIRST RTFILE_SEEK_BEGIN
|
---|
225 | /** @internal */
|
---|
226 | #define RTFILE_SEEK_LAST RTFILE_SEEK_END
|
---|
227 | /** @} */
|
---|
228 |
|
---|
229 |
|
---|
230 | /**
|
---|
231 | * Changes the read & write position in a file.
|
---|
232 | *
|
---|
233 | * @returns iprt status code.
|
---|
234 | * @param File Handle to the file.
|
---|
235 | * @param offSeek Offset to seek.
|
---|
236 | * @param uMethod Seek method, i.e. one of the RTFILE_SEEK_* defines.
|
---|
237 | * @param poffActual Where to store the new file position.
|
---|
238 | * NULL is allowed.
|
---|
239 | */
|
---|
240 | RTR3DECL(int) RTFileSeek(RTFILE File, int64_t offSeek, unsigned uMethod, uint64_t *poffActual);
|
---|
241 |
|
---|
242 | /**
|
---|
243 | * Read bytes from a file.
|
---|
244 | *
|
---|
245 | * @returns iprt status code.
|
---|
246 | * @param File Handle to the file.
|
---|
247 | * @param pvBuf Where to put the bytes we read.
|
---|
248 | * @param cbToRead How much to read.
|
---|
249 | * @param *pcbRead How much we actually read .
|
---|
250 | * If NULL an error will be returned for a partial read.
|
---|
251 | */
|
---|
252 | RTR3DECL(int) RTFileRead(RTFILE File, void *pvBuf, size_t cbToRead, size_t *pcbRead);
|
---|
253 |
|
---|
254 | /**
|
---|
255 | * Read bytes from a file at a given offset.
|
---|
256 | * This function may modify the file position.
|
---|
257 | *
|
---|
258 | * @returns iprt status code.
|
---|
259 | * @param File Handle to the file.
|
---|
260 | * @param off Where to read.
|
---|
261 | * @param pvBuf Where to put the bytes we read.
|
---|
262 | * @param cbToRead How much to read.
|
---|
263 | * @param *pcbRead How much we actually read .
|
---|
264 | * If NULL an error will be returned for a partial read.
|
---|
265 | */
|
---|
266 | RTR3DECL(int) RTFileReadAt(RTFILE File, RTFOFF off, void *pvBuf, size_t cbToRead, size_t *pcbRead);
|
---|
267 |
|
---|
268 | /**
|
---|
269 | * Write bytes to a file.
|
---|
270 | *
|
---|
271 | * @returns iprt status code.
|
---|
272 | * @param File Handle to the file.
|
---|
273 | * @param pvBuf What to write.
|
---|
274 | * @param cbToWrite How much to write.
|
---|
275 | * @param *pcbWritten How much we actually wrote.
|
---|
276 | * If NULL an error will be returned for a partial write.
|
---|
277 | */
|
---|
278 | RTR3DECL(int) RTFileWrite(RTFILE File, const void *pvBuf, size_t cbToWrite, size_t *pcbWritten);
|
---|
279 |
|
---|
280 | /**
|
---|
281 | * Write bytes to a file at a given offset.
|
---|
282 | * This function may modify the file position.
|
---|
283 | *
|
---|
284 | * @returns iprt status code.
|
---|
285 | * @param File Handle to the file.
|
---|
286 | * @param off Where to write.
|
---|
287 | * @param pvBuf What to write.
|
---|
288 | * @param cbToWrite How much to write.
|
---|
289 | * @param *pcbWritten How much we actually wrote.
|
---|
290 | * If NULL an error will be returned for a partial write.
|
---|
291 | */
|
---|
292 | RTR3DECL(int) RTFileWriteAt(RTFILE File, RTFOFF off, const void *pvBuf, size_t cbToWrite, size_t *pcbWritten);
|
---|
293 |
|
---|
294 | /**
|
---|
295 | * Flushes the buffers for the specified file.
|
---|
296 | *
|
---|
297 | * @returns iprt status code.
|
---|
298 | * @param File Handle to the file.
|
---|
299 | */
|
---|
300 | RTR3DECL(int) RTFileFlush(RTFILE File);
|
---|
301 |
|
---|
302 | /**
|
---|
303 | * Set the size of the file.
|
---|
304 | *
|
---|
305 | * @returns iprt status code.
|
---|
306 | * @param File Handle to the file.
|
---|
307 | * @param cbSize The new file size.
|
---|
308 | */
|
---|
309 | RTR3DECL(int) RTFileSetSize(RTFILE File, uint64_t cbSize);
|
---|
310 |
|
---|
311 | /**
|
---|
312 | * Query the size of the file.
|
---|
313 | *
|
---|
314 | * @returns iprt status code.
|
---|
315 | * @param File Handle to the file.
|
---|
316 | * @param pcbSize Where to store the filesize.
|
---|
317 | */
|
---|
318 | RTR3DECL(int) RTFileGetSize(RTFILE File, uint64_t *pcbSize);
|
---|
319 |
|
---|
320 | /**
|
---|
321 | * Determine the maximum file size.
|
---|
322 | *
|
---|
323 | * @returns The max size of the file.
|
---|
324 | * -1 on failure, the file position is undefined.
|
---|
325 | * @param File Handle to the file.
|
---|
326 | * @see RTFileGetMaxSizeEx.
|
---|
327 | */
|
---|
328 | RTR3DECL(RTFOFF) RTFileGetMaxSize(RTFILE File);
|
---|
329 |
|
---|
330 | /**
|
---|
331 | * Determine the maximum file size.
|
---|
332 | *
|
---|
333 | * @returns IPRT status code.
|
---|
334 | * @param File Handle to the file.
|
---|
335 | * @param pcbMax Where to store the max file size.
|
---|
336 | * @see RTFileGetMaxSize.
|
---|
337 | */
|
---|
338 | RTR3DECL(int) RTFileGetMaxSizeEx(RTFILE File, PRTFOFF pcbMax);
|
---|
339 |
|
---|
340 | /**
|
---|
341 | * Determine the maximum file size depending on the file system the file is stored on.
|
---|
342 | *
|
---|
343 | * @returns The max size of the file.
|
---|
344 | * -1 on failure.
|
---|
345 | * @param File Handle to the file.
|
---|
346 | */
|
---|
347 | RTR3DECL(RTFOFF) RTFileGetMaxSize(RTFILE File);
|
---|
348 |
|
---|
349 | /**
|
---|
350 | * Gets the current file position.
|
---|
351 | *
|
---|
352 | * @returns File offset.
|
---|
353 | * @returns ~0UUL on failure.
|
---|
354 | * @param File Handle to the file.
|
---|
355 | */
|
---|
356 | RTDECL(uint64_t) RTFileTell(RTFILE File);
|
---|
357 |
|
---|
358 | /**
|
---|
359 | * Checks if the supplied handle is valid.
|
---|
360 | *
|
---|
361 | * @returns true if valid.
|
---|
362 | * @returns false if invalid.
|
---|
363 | * @param File The file handle
|
---|
364 | */
|
---|
365 | RTR3DECL(bool) RTFileIsValid(RTFILE File);
|
---|
366 |
|
---|
367 | /**
|
---|
368 | * Copies a file.
|
---|
369 | *
|
---|
370 | * @returns VERR_ALREADY_EXISTS if the destination file exists.
|
---|
371 | * @returns VBox Status code.
|
---|
372 | *
|
---|
373 | * @param pszSrc The path to the source file.
|
---|
374 | * @param pszDst The path to the destination file.
|
---|
375 | * This file will be created.
|
---|
376 | */
|
---|
377 | RTDECL(int) RTFileCopy(const char *pszSrc, const char *pszDst);
|
---|
378 |
|
---|
379 | /**
|
---|
380 | * Copies a file given the handles to both files.
|
---|
381 | *
|
---|
382 | * @returns VBox Status code.
|
---|
383 | *
|
---|
384 | * @param FileSrc The source file. The file position is unaltered.
|
---|
385 | * @param FileDst The destination file.
|
---|
386 | * On successful returns the file position is at the end of the file.
|
---|
387 | * On failures the file position and size is undefined.
|
---|
388 | */
|
---|
389 | RTDECL(int) RTFileCopyByHandles(RTFILE FileSrc, RTFILE FileDst);
|
---|
390 |
|
---|
391 | /** Flags for RTFileCopyEx().
|
---|
392 | * @{ */
|
---|
393 | /** Do not use RTFILE_O_DENY_WRITE on the source file to allow for copying files opened for writing. */
|
---|
394 | #define RTFILECOPY_FLAGS_NO_SRC_DENY_WRITE RT_BIT(0)
|
---|
395 | /** Do not use RTFILE_O_DENY_WRITE on the target file. */
|
---|
396 | #define RTFILECOPY_FLAGS_NO_DST_DENY_WRITE RT_BIT(1)
|
---|
397 | /** Do not use RTFILE_O_DENY_WRITE on either of the two files. */
|
---|
398 | #define RTFILECOPY_FLAGS_NO_DENY_WRITE ( RTFILECOPY_FLAGS_NO_SRC_DENY_WRITE | RTFILECOPY_FLAGS_NO_DST_DENY_WRITE )
|
---|
399 | /** */
|
---|
400 | #define RTFILECOPY_FLAGS_MASK UINT32_C(0x00000003)
|
---|
401 | /** @} */
|
---|
402 |
|
---|
403 | /**
|
---|
404 | * Copies a file.
|
---|
405 | *
|
---|
406 | * @returns VERR_ALREADY_EXISTS if the destination file exists.
|
---|
407 | * @returns VBox Status code.
|
---|
408 | *
|
---|
409 | * @param pszSrc The path to the source file.
|
---|
410 | * @param pszDst The path to the destination file.
|
---|
411 | * This file will be created.
|
---|
412 | * @param fFlags Flags (RTFILECOPY_*).
|
---|
413 | * @param pfnProgress Pointer to callback function for reporting progress.
|
---|
414 | * @param pvUser User argument to pass to pfnProgress along with the completion precentage.
|
---|
415 | */
|
---|
416 | RTDECL(int) RTFileCopyEx(const char *pszSrc, const char *pszDst, uint32_t fFlags, PFNRTPROGRESS pfnProgress, void *pvUser);
|
---|
417 |
|
---|
418 | /**
|
---|
419 | * Copies a file given the handles to both files and
|
---|
420 | * provide progress callbacks.
|
---|
421 | *
|
---|
422 | * @returns IPRT status code.
|
---|
423 | *
|
---|
424 | * @param FileSrc The source file. The file position is unaltered.
|
---|
425 | * @param FileDst The destination file.
|
---|
426 | * On successful returns the file position is at the end of the file.
|
---|
427 | * On failures the file position and size is undefined.
|
---|
428 | * @param pfnProgress Pointer to callback function for reporting progress.
|
---|
429 | * @param pvUser User argument to pass to pfnProgress along with the completion precentage.
|
---|
430 | */
|
---|
431 | RTDECL(int) RTFileCopyByHandlesEx(RTFILE FileSrc, RTFILE FileDst, PFNRTPROGRESS pfnProgress, void *pvUser);
|
---|
432 |
|
---|
433 | /**
|
---|
434 | * Renames a file.
|
---|
435 | *
|
---|
436 | * Identical to RTPathRename except that it will ensure that the source is not a directory.
|
---|
437 | *
|
---|
438 | * @returns IPRT status code.
|
---|
439 | * @returns VERR_ALREADY_EXISTS if the destination file exists.
|
---|
440 | *
|
---|
441 | * @param pszSrc The path to the source file.
|
---|
442 | * @param pszDst The path to the destination file.
|
---|
443 | * This file will be created.
|
---|
444 | * @param fRename See RTPathRename.
|
---|
445 | */
|
---|
446 | RTDECL(int) RTFileRename(const char *pszSrc, const char *pszDst, unsigned fRename);
|
---|
447 |
|
---|
448 |
|
---|
449 | /** @name RTFileMove flags (bit masks).
|
---|
450 | * @{ */
|
---|
451 | /** Replace destination file if present. */
|
---|
452 | #define RTFILEMOVE_FLAGS_REPLACE 0x1
|
---|
453 | /** @} */
|
---|
454 |
|
---|
455 | /**
|
---|
456 | * Moves a file.
|
---|
457 | *
|
---|
458 | * RTFileMove differs from RTFileRename in that it works across volumes.
|
---|
459 | *
|
---|
460 | * @returns IPRT status code.
|
---|
461 | * @returns VERR_ALREADY_EXISTS if the destination file exists.
|
---|
462 | *
|
---|
463 | * @param pszSrc The path to the source file.
|
---|
464 | * @param pszDst The path to the destination file.
|
---|
465 | * This file will be created.
|
---|
466 | * @param fMove A combination of the RTFILEMOVE_* flags.
|
---|
467 | */
|
---|
468 | RTDECL(int) RTFileMove(const char *pszSrc, const char *pszDst, unsigned fMove);
|
---|
469 |
|
---|
470 |
|
---|
471 | /** @page pg_rt_filelock RT File locking API description
|
---|
472 | *
|
---|
473 | * File locking general rules:
|
---|
474 | *
|
---|
475 | * Region to lock or unlock can be located beyond the end of file, this can be used for
|
---|
476 | * growing files.
|
---|
477 | * Read (or Shared) locks can be acquired held by an unlimited number of processes at the
|
---|
478 | * same time, but a Write (or Exclusive) lock can only be acquired by one process, and
|
---|
479 | * cannot coexist with a Shared lock. To acquire a Read lock, a process must wait until
|
---|
480 | * there are no processes holding any Write locks. To acquire a Write lock, a process must
|
---|
481 | * wait until there are no processes holding either kind of lock.
|
---|
482 | * By default, RTFileLock and RTFileChangeLock calls returns error immediately if the lock
|
---|
483 | * can't be acquired due to conflict with other locks, however they can be called in wait mode.
|
---|
484 | *
|
---|
485 | * Differences in implementation:
|
---|
486 | *
|
---|
487 | * Win32, OS/2: Locking is mandatory, since locks are enforced by the operating system.
|
---|
488 | * I.e. when file region is locked in Read mode, any write in it will fail; in case of Write
|
---|
489 | * lock - region can be readed and writed only by lock's owner.
|
---|
490 | *
|
---|
491 | * Win32: File size change (RTFileSetSize) is not controlled by locking at all (!) in the
|
---|
492 | * operation system. Also see comments to RTFileChangeLock API call.
|
---|
493 | *
|
---|
494 | * Linux/Posix: By default locks in Unixes are advisory. This means that cooperating processes
|
---|
495 | * may use locks to coordinate access to a file between themselves, but programs are also free
|
---|
496 | * to ignore locks and access the file in any way they choose to.
|
---|
497 | *
|
---|
498 | * Additional reading:
|
---|
499 | * http://en.wikipedia.org/wiki/File_locking
|
---|
500 | * http://unixhelp.ed.ac.uk/CGI/man-cgi?fcntl+2
|
---|
501 | * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/lockfileex.asp
|
---|
502 | */
|
---|
503 |
|
---|
504 | /** @name Lock flags (bit masks).
|
---|
505 | * @{ */
|
---|
506 | /** Read access, can be shared with others. */
|
---|
507 | #define RTFILE_LOCK_READ 0x00
|
---|
508 | /** Write access, one at a time. */
|
---|
509 | #define RTFILE_LOCK_WRITE 0x01
|
---|
510 | /** Don't wait for other locks to be released. */
|
---|
511 | #define RTFILE_LOCK_IMMEDIATELY 0x00
|
---|
512 | /** Wait till conflicting locks have been released. */
|
---|
513 | #define RTFILE_LOCK_WAIT 0x02
|
---|
514 | /** Valid flags mask */
|
---|
515 | #define RTFILE_LOCK_MASK 0x03
|
---|
516 | /** @} */
|
---|
517 |
|
---|
518 |
|
---|
519 | /**
|
---|
520 | * Locks a region of file for read (shared) or write (exclusive) access.
|
---|
521 | *
|
---|
522 | * @returns iprt status code.
|
---|
523 | * @returns VERR_FILE_LOCK_VIOLATION if lock can't be acquired.
|
---|
524 | * @param File Handle to the file.
|
---|
525 | * @param fLock Lock method and flags, see RTFILE_LOCK_* defines.
|
---|
526 | * @param offLock Offset of lock start.
|
---|
527 | * @param cbLock Length of region to lock, may overlap the end of file.
|
---|
528 | */
|
---|
529 | RTR3DECL(int) RTFileLock(RTFILE File, unsigned fLock, int64_t offLock, uint64_t cbLock);
|
---|
530 |
|
---|
531 | /**
|
---|
532 | * Changes a lock type from read to write or from write to read.
|
---|
533 | * The region to type change must correspond exactly to an existing locked region.
|
---|
534 | * If change can't be done due to locking conflict and non-blocking mode is used, error is
|
---|
535 | * returned and lock keeps its state (see next warning).
|
---|
536 | *
|
---|
537 | * WARNING: win32 implementation of this call is not atomic, it transforms to a pair of
|
---|
538 | * calls RTFileUnlock and RTFileLock. Potentially the previously acquired lock can be
|
---|
539 | * lost, i.e. function is called in non-blocking mode, previous lock is freed, new lock can't
|
---|
540 | * be acquired, and old lock (previous state) can't be acquired back too. This situation
|
---|
541 | * may occurs _only_ if the other process is acquiring a _write_ lock in blocking mode or
|
---|
542 | * in race condition with the current call.
|
---|
543 | * In this very bad case special error code VERR_FILE_LOCK_LOST will be returned.
|
---|
544 | *
|
---|
545 | * @returns iprt status code.
|
---|
546 | * @returns VERR_FILE_NOT_LOCKED if region was not locked.
|
---|
547 | * @returns VERR_FILE_LOCK_VIOLATION if lock type can't be changed, lock remains its type.
|
---|
548 | * @returns VERR_FILE_LOCK_LOST if lock was lost, we haven't this lock anymore :(
|
---|
549 | * @param File Handle to the file.
|
---|
550 | * @param fLock Lock method and flags, see RTFILE_LOCK_* defines.
|
---|
551 | * @param offLock Offset of lock start.
|
---|
552 | * @param cbLock Length of region to lock, may overlap the end of file.
|
---|
553 | */
|
---|
554 | RTR3DECL(int) RTFileChangeLock(RTFILE File, unsigned fLock, int64_t offLock, uint64_t cbLock);
|
---|
555 |
|
---|
556 | /**
|
---|
557 | * Unlocks previously locked region of file.
|
---|
558 | * The region to unlock must correspond exactly to an existing locked region.
|
---|
559 | *
|
---|
560 | * @returns iprt status code.
|
---|
561 | * @returns VERR_FILE_NOT_LOCKED if region was not locked.
|
---|
562 | * @param File Handle to the file.
|
---|
563 | * @param offLock Offset of lock start.
|
---|
564 | * @param cbLock Length of region to unlock, may overlap the end of file.
|
---|
565 | */
|
---|
566 | RTR3DECL(int) RTFileUnlock(RTFILE File, int64_t offLock, uint64_t cbLock);
|
---|
567 |
|
---|
568 |
|
---|
569 | /**
|
---|
570 | * Query information about an open file.
|
---|
571 | *
|
---|
572 | * @returns iprt status code.
|
---|
573 | *
|
---|
574 | * @param File Handle to the file.
|
---|
575 | * @param pObjInfo Object information structure to be filled on successful return.
|
---|
576 | * @param enmAdditionalAttribs Which set of additional attributes to request.
|
---|
577 | * Use RTFSOBJATTRADD_NOTHING if this doesn't matter.
|
---|
578 | */
|
---|
579 | RTR3DECL(int) RTFileQueryInfo(RTFILE File, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAdditionalAttribs);
|
---|
580 |
|
---|
581 | /**
|
---|
582 | * Changes one or more of the timestamps associated of file system object.
|
---|
583 | *
|
---|
584 | * @returns iprt status code.
|
---|
585 | * @returns VERR_NOT_SUPPORTED is returned if the operation isn't supported by the OS.
|
---|
586 | *
|
---|
587 | * @param File Handle to the file.
|
---|
588 | * @param pAccessTime Pointer to the new access time. NULL if not to be changed.
|
---|
589 | * @param pModificationTime Pointer to the new modifcation time. NULL if not to be changed.
|
---|
590 | * @param pChangeTime Pointer to the new change time. NULL if not to be changed.
|
---|
591 | * @param pBirthTime Pointer to the new time of birth. NULL if not to be changed.
|
---|
592 | *
|
---|
593 | * @remark The file system might not implement all these time attributes,
|
---|
594 | * the API will ignore the ones which aren't supported.
|
---|
595 | *
|
---|
596 | * @remark The file system might not implement the time resolution
|
---|
597 | * employed by this interface, the time will be chopped to fit.
|
---|
598 | *
|
---|
599 | * @remark The file system may update the change time even if it's
|
---|
600 | * not specified.
|
---|
601 | *
|
---|
602 | * @remark POSIX can only set Access & Modification and will always set both.
|
---|
603 | */
|
---|
604 | RTR3DECL(int) RTFileSetTimes(RTFILE File, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
|
---|
605 | PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime);
|
---|
606 |
|
---|
607 | /**
|
---|
608 | * Gets one or more of the timestamps associated of file system object.
|
---|
609 | *
|
---|
610 | * @returns iprt status code.
|
---|
611 | * @param File Handle to the file.
|
---|
612 | * @param pAccessTime Where to store the access time. NULL is ok.
|
---|
613 | * @param pModificationTime Where to store the modifcation time. NULL is ok.
|
---|
614 | * @param pChangeTime Where to store the change time. NULL is ok.
|
---|
615 | * @param pBirthTime Where to store the time of birth. NULL is ok.
|
---|
616 | *
|
---|
617 | * @remark This is wrapper around RTFileQueryInfo() and exists to complement RTFileSetTimes().
|
---|
618 | */
|
---|
619 | RTR3DECL(int) RTFileGetTimes(RTFILE File, PRTTIMESPEC pAccessTime, PRTTIMESPEC pModificationTime,
|
---|
620 | PRTTIMESPEC pChangeTime, PRTTIMESPEC pBirthTime);
|
---|
621 |
|
---|
622 | /**
|
---|
623 | * Changes the mode flags of an open file.
|
---|
624 | *
|
---|
625 | * The API requires at least one of the mode flag sets (Unix/Dos) to
|
---|
626 | * be set. The type is ignored.
|
---|
627 | *
|
---|
628 | * @returns iprt status code.
|
---|
629 | * @param File Handle to the file.
|
---|
630 | * @param fMode The new file mode, see @ref grp_rt_fs for details.
|
---|
631 | */
|
---|
632 | RTR3DECL(int) RTFileSetMode(RTFILE File, RTFMODE fMode);
|
---|
633 |
|
---|
634 | /**
|
---|
635 | * Gets the mode flags of an open file.
|
---|
636 | *
|
---|
637 | * @returns iprt status code.
|
---|
638 | * @param File Handle to the file.
|
---|
639 | * @param pfMode Where to store the file mode, see @ref grp_rt_fs for details.
|
---|
640 | *
|
---|
641 | * @remark This is wrapper around RTFileQueryInfo()
|
---|
642 | * and exists to complement RTFileSetMode().
|
---|
643 | */
|
---|
644 | RTR3DECL(int) RTFileGetMode(RTFILE File, uint32_t *pfMode);
|
---|
645 |
|
---|
646 | /**
|
---|
647 | * Changes the owner and/or group of an open file.
|
---|
648 | *
|
---|
649 | * @returns iprt status code.
|
---|
650 | * @param File Handle to the file.
|
---|
651 | * @param uid The new file owner user id. Use -1 (or ~0) to leave this unchanged.
|
---|
652 | * @param gid The new group id. Use -1 (or ~0) to leave this unchanged.
|
---|
653 | */
|
---|
654 | RTR3DECL(int) RTFileSetOwner(RTFILE File, uint32_t uid, uint32_t gid);
|
---|
655 |
|
---|
656 | /**
|
---|
657 | * Gets the owner and/or group of an open file.
|
---|
658 | *
|
---|
659 | * @returns iprt status code.
|
---|
660 | * @param File Handle to the file.
|
---|
661 | * @param pUid Where to store the owner user id. NULL is ok.
|
---|
662 | * @param pGid Where to store the group id. NULL is ok.
|
---|
663 | *
|
---|
664 | * @remark This is wrapper around RTFileQueryInfo() and exists to complement RTFileGetOwner().
|
---|
665 | */
|
---|
666 | RTR3DECL(int) RTFileGetOwner(RTFILE File, uint32_t *pUid, uint32_t *pGid);
|
---|
667 |
|
---|
668 | /**
|
---|
669 | * Executes an IOCTL on a file descriptor.
|
---|
670 | *
|
---|
671 | * This function is currently only available in L4 and posix environments.
|
---|
672 | * Attemps at calling it from code shared with any other platforms will break things!
|
---|
673 | *
|
---|
674 | * The rational for defining this API is to simplify L4 porting of audio drivers,
|
---|
675 | * and to remove some of the assumptions on RTFILE being a file descriptor on
|
---|
676 | * platforms using the posix file implementation.
|
---|
677 | *
|
---|
678 | * @returns iprt status code.
|
---|
679 | * @param File Handle to the file.
|
---|
680 | * @param iRequest IOCTL request to carry out.
|
---|
681 | * @param pvData IOCTL data.
|
---|
682 | * @param cbData Size of the IOCTL data.
|
---|
683 | * @param piRet Return value of the IOCTL request.
|
---|
684 | */
|
---|
685 | RTR3DECL(int) RTFileIoCtl(RTFILE File, int iRequest, void *pvData, unsigned cbData, int *piRet);
|
---|
686 |
|
---|
687 | /**
|
---|
688 | * Reads the file into memory.
|
---|
689 | *
|
---|
690 | * The caller must free the memory using RTFileReadAllFree().
|
---|
691 | *
|
---|
692 | * @returns IPRT status code.
|
---|
693 | * @param pszFilename The name of the file.
|
---|
694 | * @param ppvFile Where to store the pointer to the memory on successful return.
|
---|
695 | * @param pcbFile Where to store the size of the file on successful return.
|
---|
696 | *
|
---|
697 | * @remarks Note that this function may be implemented using memory mapping, which means
|
---|
698 | * that the file may remain open until RTFileReadAllFree() is called. It also
|
---|
699 | * means that the return memory may reflect the state of the file when it's
|
---|
700 | * accessed instead of when this call was done. So, in short, don't use this
|
---|
701 | * API for volatile files, then rather use the extended variant with a
|
---|
702 | * yet-to-be-defined.
|
---|
703 | */
|
---|
704 | RTDECL(int) RTFileReadAll(const char *pszFilename, void **ppvFile, size_t *pcbFile);
|
---|
705 |
|
---|
706 | /**
|
---|
707 | * Reads the file into memory.
|
---|
708 | *
|
---|
709 | * The caller must free the memory using RTFileReadAllFree().
|
---|
710 | *
|
---|
711 | * @returns IPRT status code.
|
---|
712 | * @param pszFilename The name of the file.
|
---|
713 | * @param off The offset to start reading at.
|
---|
714 | * @param cbMax The maximum number of bytes to read into memory. Specify RTFOFF_MAX
|
---|
715 | * to read to the end of the file.
|
---|
716 | * @param fFlags See RTFILE_RDALL_*.
|
---|
717 | * @param ppvFile Where to store the pointer to the memory on successful return.
|
---|
718 | * @param pcbFile Where to store the size of the file on successful return.
|
---|
719 | *
|
---|
720 | * @remarks See the remarks for RTFileReadAll.
|
---|
721 | */
|
---|
722 | RTDECL(int) RTFileReadAllEx(const char *pszFilename, RTFOFF off, RTFOFF cbMax, uint32_t fFlags, void **ppvFile, size_t *pcbFile);
|
---|
723 |
|
---|
724 | /**
|
---|
725 | * Reads the file into memory.
|
---|
726 | *
|
---|
727 | * The caller must free the memory using RTFileReadAllFree().
|
---|
728 | *
|
---|
729 | * @returns IPRT status code.
|
---|
730 | * @param File The handle to the file.
|
---|
731 | * @param ppvFile Where to store the pointer to the memory on successful return.
|
---|
732 | * @param pcbFile Where to store the size of the file on successful return.
|
---|
733 | *
|
---|
734 | * @remarks See the remarks for RTFileReadAll.
|
---|
735 | */
|
---|
736 | RTDECL(int) RTFileReadAllByHandle(RTFILE File, void **ppvFile, size_t *pcbFile);
|
---|
737 |
|
---|
738 | /**
|
---|
739 | * Reads the file into memory.
|
---|
740 | *
|
---|
741 | * The caller must free the memory using RTFileReadAllFree().
|
---|
742 | *
|
---|
743 | * @returns IPRT status code.
|
---|
744 | * @param File The handle to the file.
|
---|
745 | * @param off The offset to start reading at.
|
---|
746 | * @param cbMax The maximum number of bytes to read into memory. Specify RTFOFF_MAX
|
---|
747 | * to read to the end of the file.
|
---|
748 | * @param fFlags See RTFILE_RDALL_*.
|
---|
749 | * @param ppvFile Where to store the pointer to the memory on successful return.
|
---|
750 | * @param pcbFile Where to store the size of the file on successful return.
|
---|
751 | *
|
---|
752 | * @remarks See the remarks for RTFileReadAll.
|
---|
753 | */
|
---|
754 | RTDECL(int) RTFileReadAllByHandleEx(RTFILE File, RTFOFF off, RTFOFF cbMax, uint32_t fFlags, void **ppvFile, size_t *pcbFile);
|
---|
755 |
|
---|
756 | /**
|
---|
757 | * Frees the memory returned by one of the RTFileReadAll(), RTFileReadAllEx(),
|
---|
758 | * RTFileReadAllByHandle() and RTFileReadAllByHandleEx() functions.
|
---|
759 | *
|
---|
760 | * @param pvFile Pointer to the memory.
|
---|
761 | * @param cbFile The size of the memory.
|
---|
762 | */
|
---|
763 | RTDECL(void) RTFileReadAllFree(void *pvFile, size_t cbFile);
|
---|
764 |
|
---|
765 | /** @name RTFileReadAllEx and RTFileReadAllHandleEx flags
|
---|
766 | * The open flags are ignored by RTFileReadAllHandleEx.
|
---|
767 | * @{ */
|
---|
768 | #define RTFILE_RDALL_O_DENY_NONE RTFILE_O_DENY_NONE
|
---|
769 | #define RTFILE_RDALL_O_DENY_READ RTFILE_O_DENY_READ
|
---|
770 | #define RTFILE_RDALL_O_DENY_WRITE RTFILE_O_DENY_WRITE
|
---|
771 | #define RTFILE_RDALL_O_DENY_READWRITE RTFILE_O_DENY_READWRITE
|
---|
772 | #define RTFILE_RDALL_O_DENY_ALL RTFILE_O_DENY_ALL
|
---|
773 | #define RTFILE_RDALL_O_DENY_NOT_DELETE RTFILE_O_DENY_NOT_DELETE
|
---|
774 | #define RTFILE_RDALL_O_DENY_MASK RTFILE_O_DENY_MASK
|
---|
775 | /** Mask of valid flags. */
|
---|
776 | #define RTFILE_RDALL_VALID_MASK RTFILE_RDALL_O_DENY_MASK
|
---|
777 | /** @} */
|
---|
778 |
|
---|
779 |
|
---|
780 | /** @page pg_rt_asyncio RT File async I/O API
|
---|
781 | *
|
---|
782 | * File operations are usually blocking the calling thread until
|
---|
783 | * they completed making it impossible to let the thread do anything
|
---|
784 | * else inbetween.
|
---|
785 | * The RT File async I/O API provides an easy and efficient way to
|
---|
786 | * access files asynchronously using the native facilities provided
|
---|
787 | * by each operating system.
|
---|
788 | *
|
---|
789 | * There are two objects used in this API.
|
---|
790 | * The first object is the request. A request contains every information
|
---|
791 | * needed two complete the file operation successfully like the start offset
|
---|
792 | * and pointer to the source or destination buffer.
|
---|
793 | * Requests are created with RTFileAioReqCreate() and destroyed with
|
---|
794 | * RTFileAioReqDestroy().
|
---|
795 | * Because creating a request may require allocating various operating
|
---|
796 | * system dependent ressources and may be quite expensive it is possible
|
---|
797 | * to use a request more than once to save CPU cycles.
|
---|
798 | * A request is constructed with either RTFileAioReqPrepareRead()
|
---|
799 | * which will set up a request to read from the given file or
|
---|
800 | * RTFileAioReqPrepareWrite() which will write to a given file.
|
---|
801 | *
|
---|
802 | * The second object is the context. A file is associated with a context
|
---|
803 | * and requests for this file may complete only on the context the file
|
---|
804 | * was associated with and not on the context given in RTFileAioCtxSubmit()
|
---|
805 | * (see below for further information).
|
---|
806 | * RTFileAioCtxWait() is used to wait for completion of requests which were
|
---|
807 | * associated with the context. While waiting for requests the thread can not
|
---|
808 | * respond to global state changes. Thatswhy the API provides a way to let
|
---|
809 | * RTFileAioCtxWait() return immediately no matter how many requests
|
---|
810 | * have finished through RTFileAioCtxWakeup(). The return code is
|
---|
811 | * VERR_INTERRUPTED to let the thread know that he got interrupted.
|
---|
812 | *
|
---|
813 | * Threading:
|
---|
814 | *
|
---|
815 | * The API is a thin wrapper around the specific host OS APIs and therefore
|
---|
816 | * relies on the thread safety of the underlying API.
|
---|
817 | * The interesting functions with regards to thread safety are RTFileAioCtxSubmit()
|
---|
818 | * and RTFileAioCtxWait(). RTFileAioCtxWait() must not be called from different
|
---|
819 | * threads at the same time with the same context handle. The same applies to
|
---|
820 | * RTFileAioCtxSubmit(). However it is possible to submit new requests from a different
|
---|
821 | * thread while waiting for completed requests on another thread with RTFileAioCtxWait().
|
---|
822 | *
|
---|
823 | * Differences in implementation:
|
---|
824 | * Because the host APIs are quite different on every OS and every API has other limitations
|
---|
825 | * there are some things to consider to make the code as portable as possible.
|
---|
826 | *
|
---|
827 | * The first restriction at the moment is that every buffer has to be aligned to a 512 byte boundary.
|
---|
828 | * This limitation comes from the Linux io_* interface. To use the interface the file
|
---|
829 | * must be opened with O_DIRECT. This flag disables the kernel cache too which may
|
---|
830 | * degrade performance but is unfortunately the only way to make asynchronous
|
---|
831 | * I/O work till today (if O_DIRECT is omitted io_submit will revert to sychronous behavior
|
---|
832 | * and will return when the requests finished and when they are queued).
|
---|
833 | * It is mostly used by DBMS which do theire own caching.
|
---|
834 | * Furthermore there is no filesystem independent way to discover the restrictions at least
|
---|
835 | * for the 2.4 kernel series. Since 2.6 the 512 byte boundary seems to be used by all
|
---|
836 | * file systems. So Linus comment about this flag is comprehensible but Linux
|
---|
837 | * lacks an alternative at the moment.
|
---|
838 | *
|
---|
839 | * The next limitation applies only to Windows. Reqeusts are not assoicated with the
|
---|
840 | * I/O context they are associated with but with the file the request is for.
|
---|
841 | * The file needs to be associated with exactly one I/O completion port and requests
|
---|
842 | * for this file will only arrive at that context after they completed and not on
|
---|
843 | * the context the request was submitted.
|
---|
844 | * To associate a file with a specific context RTFileAioCtxAssociateWithFile() is
|
---|
845 | * used. It is only implemented on Windows and does nothing on the other platforms.
|
---|
846 | * If the file needs to be associated with different context for some reason
|
---|
847 | * the file must be closed first. After it was opened again the new context
|
---|
848 | * can be associated with the other context.
|
---|
849 | * This can't be done by the API because there is no way to retrieve the flags
|
---|
850 | * the file was opened with.
|
---|
851 | */
|
---|
852 |
|
---|
853 | /**
|
---|
854 | * Creates an async I/O request handle.
|
---|
855 | *
|
---|
856 | * @returns IPRT status code.
|
---|
857 | * @param phReq Where to store the request handle.
|
---|
858 | */
|
---|
859 | RTDECL(int) RTFileAioReqCreate(PRTFILEAIOREQ phReq);
|
---|
860 |
|
---|
861 | /**
|
---|
862 | * Destroys an async I/O request handle.
|
---|
863 | *
|
---|
864 | * @param hReq The request handle.
|
---|
865 | */
|
---|
866 | RTDECL(void) RTFileAioReqDestroy(RTFILEAIOREQ hReq);
|
---|
867 |
|
---|
868 | /**
|
---|
869 | * Prepares an async read request.
|
---|
870 | *
|
---|
871 | * @returns IPRT status code.
|
---|
872 | *
|
---|
873 | * @param hReq The request handle.
|
---|
874 | * @param hFile The file to read from.
|
---|
875 | * @param off The offset to start reading at.
|
---|
876 | * @param pvBuf Where to store the read bits.
|
---|
877 | * @param cbRead Number of bytes to read.
|
---|
878 | * @param pvUser Opaque user data associated with this request which
|
---|
879 | * can be retrieved with RTFileAioReqGetUser().
|
---|
880 | */
|
---|
881 | RTDECL(int) RTFileAioReqPrepareRead(RTFILEAIOREQ hReq, RTFILE hFile, RTFOFF off,
|
---|
882 | void *pvBuf, size_t cbRead, void *pvUser);
|
---|
883 |
|
---|
884 | /**
|
---|
885 | * Prepares an async write request.
|
---|
886 | *
|
---|
887 | * @returns IPRT status code.
|
---|
888 | *
|
---|
889 | * @param hReq The request handle.
|
---|
890 | * @param hFile The file to write to.
|
---|
891 | * @param off The offset to start writing at.
|
---|
892 | * @param pvBuf Where to store the written bits.
|
---|
893 | * @param cbRead Number of bytes to write.
|
---|
894 | * @param pvUser Opaque user data associated with this request which
|
---|
895 | * can be retrieved with RTFileAioReqGetUser().
|
---|
896 | */
|
---|
897 | RTDECL(int) RTFileAioReqPrepareWrite(RTFILEAIOREQ hReq, RTFILE hFile, RTFOFF off,
|
---|
898 | void *pvBuf, size_t cbWrite, void *pvUser);
|
---|
899 |
|
---|
900 | /**
|
---|
901 | * Prepares an async flush of all cached data associated with a file handle.
|
---|
902 | *
|
---|
903 | * @returns IPRT status code.
|
---|
904 | *
|
---|
905 | * @param hReq The request handle.
|
---|
906 | * @param hFile The file to flush.
|
---|
907 | * @param pvUser Opaque user data associated with this request which
|
---|
908 | * can be retrieved with RTFileAioReqGetUser().
|
---|
909 | *
|
---|
910 | * @remarks May also flush other caches on some platforms.
|
---|
911 | */
|
---|
912 | RTDECL(int) RTFileAioReqPrepareFlush(RTFILEAIOREQ hReq, RTFILE hFile, void *pvUser);
|
---|
913 |
|
---|
914 | /**
|
---|
915 | * Gets the opaque user data associated with the given request.
|
---|
916 | *
|
---|
917 | * @returns Opaque user data.
|
---|
918 | * @retval NULL if the request hasn't been prepared yet.
|
---|
919 | *
|
---|
920 | * @param hReq The request handle.
|
---|
921 | */
|
---|
922 | RTDECL(void *) RTFileAioReqGetUser(RTFILEAIOREQ hReq);
|
---|
923 |
|
---|
924 | /**
|
---|
925 | * Cancels a pending request.
|
---|
926 | *
|
---|
927 | * @returns IPRT status code.
|
---|
928 | * @retval VINF_SUCCESS If the request was canceled.
|
---|
929 | * @retval VERR_FILE_AIO_IN_PROGRESS If the request could not be canceled because it is already processed.
|
---|
930 | * @retval VERR_FILE_AIO_COMPLETED If the request could not be canceled because it already completed.
|
---|
931 | *
|
---|
932 | * @param hReq The request to cancel.
|
---|
933 | */
|
---|
934 | RTDECL(int) RTFileAioReqCancel(RTFILEAIOREQ hReq);
|
---|
935 |
|
---|
936 | /**
|
---|
937 | * Gets the status of a completed request.
|
---|
938 | *
|
---|
939 | * @returns The IPRT status code of the given request.
|
---|
940 | * @retval VERR_FILE_AIO_IN_PROGRESS if the request isn't yet completed.
|
---|
941 | *
|
---|
942 | * @param hReq The request handle.
|
---|
943 | * @param pcbTransferred Where to store the number of bytes transfered.
|
---|
944 | * Optional since it is not relevant for all kinds of
|
---|
945 | * requests.
|
---|
946 | */
|
---|
947 | RTDECL(int) RTFileAioReqGetRC(RTFILEAIOREQ hReq, size_t *pcbTransfered);
|
---|
948 |
|
---|
949 |
|
---|
950 |
|
---|
951 | /**
|
---|
952 | * Creates an async I/O context.
|
---|
953 | *
|
---|
954 | * @todo briefly explain what an async context is here or in the page
|
---|
955 | * above.
|
---|
956 | *
|
---|
957 | * @returns IPRT status code.
|
---|
958 | * @param phAioCtx Where to store the async I/O context handle.
|
---|
959 | * @param cAioReqsMax How many async I/O requests the context should be capable
|
---|
960 | * to handle. Pass RTFILEAIO_UNLIMITED_REQS if the
|
---|
961 | * context should support an unlimited number of
|
---|
962 | * requests.
|
---|
963 | */
|
---|
964 | RTDECL(int) RTFileAioCtxCreate(PRTFILEAIOCTX phAioCtx, uint32_t cAioReqsMax);
|
---|
965 |
|
---|
966 | /** Unlimited number of requests.
|
---|
967 | * Used with RTFileAioCtxCreate and RTFileAioCtxGetMaxReqCount. */
|
---|
968 | #define RTFILEAIO_UNLIMITED_REQS UINT32_MAX
|
---|
969 |
|
---|
970 | /**
|
---|
971 | * Destroys an async I/O context.
|
---|
972 | *
|
---|
973 | * @returns IPRT status code.
|
---|
974 | * @param hAioCtx The async I/O context handle.
|
---|
975 | */
|
---|
976 | RTDECL(int) RTFileAioCtxDestroy(RTFILEAIOCTX hAioCtx);
|
---|
977 |
|
---|
978 | /**
|
---|
979 | * Get the maximum number of requests one aio context can handle.
|
---|
980 | *
|
---|
981 | * @returns Maximum number of tasks the context can handle.
|
---|
982 | * RTFILEAIO_UNLIMITED_REQS if there is no limit.
|
---|
983 | *
|
---|
984 | * @param hAioCtx The async I/O context handle.
|
---|
985 | * If NIL_RTAIOCONTEXT is passed the maximum value
|
---|
986 | * which can be passed to RTFileAioCtxCreate()
|
---|
987 | * is returned.
|
---|
988 | */
|
---|
989 | RTDECL(uint32_t) RTFileAioCtxGetMaxReqCount(RTFILEAIOCTX hAioCtx);
|
---|
990 |
|
---|
991 | /**
|
---|
992 | * Associates a file with a async I/O context.
|
---|
993 | * Requests for this file will arrive at the completion port
|
---|
994 | * associated with the file.
|
---|
995 | *
|
---|
996 | * @returns IPRT status code.
|
---|
997 | *
|
---|
998 | * @param hAioCtx The async I/O context handle.
|
---|
999 | * @param hFile The file handle.
|
---|
1000 | */
|
---|
1001 | RTDECL(int) RTFileAioCtxAssociateWithFile(RTFILEAIOCTX hAioCtx, RTFILE hFile);
|
---|
1002 |
|
---|
1003 | /**
|
---|
1004 | * Submits a set of requests to an async I/O context for processing.
|
---|
1005 | *
|
---|
1006 | * @returns IPRT status code.
|
---|
1007 | *
|
---|
1008 | * @param hAioCtx The async I/O context handle.
|
---|
1009 | * @param pahReqs Pointer to an array of request handles.
|
---|
1010 | * @param cReqs The number of entries in the array.
|
---|
1011 | * @param pcReqs Where to store the number of requests
|
---|
1012 | * successfully submitted before an error
|
---|
1013 | * occured. If VINF_SUCCESS is returned
|
---|
1014 | * the value equals cReqs. This value is always
|
---|
1015 | * set.
|
---|
1016 | *
|
---|
1017 | * @remarks @a cReqs uses the type size_t while it really is a uint32_t, this is
|
---|
1018 | * to avoid annoying warnings when using RT_ELEMENTS and similar
|
---|
1019 | * macros.
|
---|
1020 | */
|
---|
1021 | RTDECL(int) RTFileAioCtxSubmit(RTFILEAIOCTX hAioCtx, PRTFILEAIOREQ pahReqs, size_t cReqs, size_t *pcReqs);
|
---|
1022 |
|
---|
1023 | /**
|
---|
1024 | * Waits for request completion.
|
---|
1025 | *
|
---|
1026 | * Only one thread at a time may call this API on a context.
|
---|
1027 | *
|
---|
1028 | * @returns IPRT status code.
|
---|
1029 | * @retval VERR_INVALID_POINTER If pcReqs or/and pahReqs are invalid.
|
---|
1030 | * @retval VERR_INVALID_HANDLE If hAioCtx is invalid.
|
---|
1031 | * @retval VERR_OUT_OF_RANGE If cMinReqs is larger than cReqs.
|
---|
1032 | * @retval VERR_INVALID_PARAMETER If cReqs is 0.
|
---|
1033 | * @retval VERR_TIMEOUT If cMinReqs didn't complete before the
|
---|
1034 | * timeout expired.
|
---|
1035 | * @retval VERR_INTERRUPTED If the completion context was interrupted
|
---|
1036 | * by RTFileAioCtxWakeup().
|
---|
1037 | * @retval VERR_FILE_AIO_NO_REQUEST If there are no pending request.
|
---|
1038 | *
|
---|
1039 | * @param hAioCtx The async I/O context handle to wait and get
|
---|
1040 | * completed requests from.
|
---|
1041 | * @param cMinReqs The minimum number of requests which have to
|
---|
1042 | * complete before this function returns.
|
---|
1043 | * @param cMillisTimeout The number of milliseconds to wait before returning
|
---|
1044 | * VERR_TIMEOUT. Use RT_INDEFINITE_WAIT to wait
|
---|
1045 | * forever.
|
---|
1046 | * @param pahReqs Pointer to an array where the handles of the
|
---|
1047 | * completed requests will be stored on success.
|
---|
1048 | * @param cReqs The number of entries @a pahReqs can hold.
|
---|
1049 | * @param pcReqs Where to store the number of returned (complete)
|
---|
1050 | * requests. This will always be set.
|
---|
1051 | *
|
---|
1052 | * @remarks The wait will be resume if interrupted by a signal. An
|
---|
1053 | * RTFileAioCtxWaitNoResume variant can be added later if it becomes
|
---|
1054 | * necessary.
|
---|
1055 | *
|
---|
1056 | * @remarks @a cMinReqs and @a cReqs use the type size_t while they really are
|
---|
1057 | * uint32_t's, this is to avoid annoying warnings when using
|
---|
1058 | * RT_ELEMENTS and similar macros.
|
---|
1059 | */
|
---|
1060 | RTDECL(int) RTFileAioCtxWait(RTFILEAIOCTX hAioCtx, size_t cMinReqs, unsigned cMillisTimeout,
|
---|
1061 | PRTFILEAIOREQ pahReqs, size_t cReqs, uint32_t *pcReqs);
|
---|
1062 |
|
---|
1063 | /**
|
---|
1064 | * Forces any RTFileAioCtxWait() call on another thread to return immediately.
|
---|
1065 | *
|
---|
1066 | * @returns IPRT status code.
|
---|
1067 | *
|
---|
1068 | * @param hAioCtx The handle of the async I/O context to wakeup.
|
---|
1069 | */
|
---|
1070 | RTDECL(int) RTFileAioCtxWakeup(RTFILEAIOCTX hAioCtx);
|
---|
1071 |
|
---|
1072 | #endif /* IN_RING3 */
|
---|
1073 |
|
---|
1074 | /** @} */
|
---|
1075 |
|
---|
1076 | __END_DECLS
|
---|
1077 |
|
---|
1078 | #endif
|
---|
1079 |
|
---|