VirtualBox

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

Last change on this file since 24025 was 23974, checked in by vboxsync, 15 years ago

iprt/file.h: Use UINT32_C() for the RTFILE_O flags.

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

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