VirtualBox

source: vbox/trunk/include/iprt/file.h@ 24603

Last change on this file since 24603 was 24189, checked in by vboxsync, 15 years ago

IPRT: Added RTFileQuerySize.

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

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