VirtualBox

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

Last change on this file since 33021 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

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