VirtualBox

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

Last change on this file since 9800 was 8925, checked in by vboxsync, 17 years ago

New file APIs for reading (or mapping) a file into memory: RTFileReadAll, RTFileReadAllEx, RTFileReadAllByHandle, RTFileReadAllByHandleEx and RTFileReadAllFree.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 27.2 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
39/** @todo rename this file to iprt/file.h */
40
41__BEGIN_DECLS
42
43/** @defgroup grp_rt_fileio RTFile - File I/O
44 * @ingroup grp_rt
45 * @{
46 */
47
48/** Platform specific text line break.
49 * @deprecated Use text I/O streams and '\\n'. See iprt/stream.h. */
50#if defined(RT_OS_OS2) || defined(RT_OS_WINDOWS)
51# define RTFILE_LINEFEED "\r\n"
52#else
53# define RTFILE_LINEFEED "\n"
54#endif
55
56
57#ifdef IN_RING3
58
59/** @name Open flags
60 * @{ */
61/** Open the file with read access. */
62#define RTFILE_O_READ 0x00000001
63/** Open the file with write access. */
64#define RTFILE_O_WRITE 0x00000002
65/** Open the file with read & write access. */
66#define RTFILE_O_READWRITE 0x00000003
67/** The file access mask.
68 * @remark The value 0 is invalid. */
69#define RTFILE_O_ACCESS_MASK 0x00000003
70
71/** Sharing mode: deny none (the default mode). */
72#define RTFILE_O_DENY_NONE 0x00000000
73/** Sharing mode: deny read. */
74#define RTFILE_O_DENY_READ 0x00000010
75/** Sharing mode: deny write. */
76#define RTFILE_O_DENY_WRITE 0x00000020
77/** Sharing mode: deny read and write. */
78#define RTFILE_O_DENY_READWRITE 0x00000030
79/** Sharing mode: deny all. */
80#define RTFILE_O_DENY_ALL RTFILE_O_DENY_READWRITE
81/** Sharing mode: do NOT deny delete (NT).
82 * @remark This might not be implemented on all platforms,
83 * and will be defaulted & ignored on those.
84 */
85#define RTFILE_O_DENY_NOT_DELETE 0x00000040
86/** Sharing mode mask. */
87#define RTFILE_O_DENY_MASK 0x00000070
88
89/** Action: Open an existing file (the default action). */
90#define RTFILE_O_OPEN 0x00000000
91/** Action: Create a new file or open an existing one. */
92#define RTFILE_O_OPEN_CREATE 0x00000100
93/** Action: Create a new a file. */
94#define RTFILE_O_CREATE 0x00000200
95/** Action: Create a new file or replace an existing one. */
96#define RTFILE_O_CREATE_REPLACE 0x00000300
97/** Action mask. */
98#define RTFILE_O_ACTION_MASK 0x00000300
99
100/** Turns off indexing of files on Windows hosts, *CREATE* only.
101 * @remark This might not be implemented on all platforms,
102 * and will be ignored on those.
103 */
104#define RTFILE_O_NOT_CONTENT_INDEXED 0x00000800
105/** Truncate the file.
106 * @remark This will not truncate files opened for read-only.
107 * @remark The trunction doesn't have to be atomically, so anyone
108 * else opening the file may be racing us. The caller is
109 * responsible for not causing this race. */
110#define RTFILE_O_TRUNCATE 0x00001000
111/** Make the handle inheritable on RTProcessCreate(/exec). */
112#define RTFILE_O_INHERIT 0x00002000
113/** Open file in non-blocking mode - non-portable.
114 * @remark This flag may not be supported on all platforms, in which
115 * case it's considered an invalid parameter.
116 */
117#define RTFILE_O_NON_BLOCK 0x00004000
118/** Write through directly to disk. Workaround to avoid iSCSI
119 * initiator deadlocks on Windows hosts.
120 * @remark This might not be implemented on all platforms,
121 * and will be ignored on those.
122 */
123#define RTFILE_O_WRITE_THROUGH 0x00008000
124/** Mask of all valid flags.
125 * @remark This doesn't validate the access mode properly.
126 */
127#define RTFILE_O_VALID_MASK 0x0000FB73
128
129/** @} */
130
131
132/**
133 * Force the use of open flags for all files opened after the setting is
134 * changed. The caller is responsible for not causing races with RTFileOpen().
135 *
136 * @returns iprt status code.
137 * @param fOpenForAccess Access mode to which the set/mask settings apply.
138 * @param fSet Open flags to be forced set.
139 * @param fMask Open flags to be masked out.
140 */
141RTR3DECL(int) RTFileSetForceFlags(unsigned fOpenForAccess, unsigned fSet, unsigned fMask);
142
143/**
144 * Open a file.
145 *
146 * @returns iprt status code.
147 * @param pFile Where to store the handle to the opened file.
148 * @param pszFilename Path to the file which is to be opened. (UTF-8)
149 * @param fOpen Open flags, i.e a combination of the RTFILE_O_* defines.
150 */
151RTR3DECL(int) RTFileOpen(PRTFILE pFile, const char *pszFilename, unsigned fOpen);
152
153/**
154 * Close a file opened by RTFileOpen().
155 *
156 * @returns iprt status code.
157 * @param File The file handle to close.
158 */
159RTR3DECL(int) RTFileClose(RTFILE File);
160
161/**
162 * Creates an IPRT file handle from a native one.
163 *
164 * @returns IPRT status code.
165 * @param pFile Where to store the IPRT file handle.
166 * @param uNative The native handle.
167 */
168RTR3DECL(int) RTFileFromNative(PRTFILE pFile, RTHCINTPTR uNative);
169
170/**
171 * Gets the native handle for an IPRT file handle.
172 *
173 * @return The native handle.
174 * @params File The IPRT file handle.
175 */
176RTR3DECL(RTHCINTPTR) RTFileToNative(RTFILE File);
177
178/**
179 * Delete a file.
180 *
181 * @returns iprt status code.
182 * @param pszFilename Path to the file which is to be deleted. (UTF-8)
183 * @todo This is a RTPath api!
184 */
185RTR3DECL(int) RTFileDelete(const char *pszFilename);
186
187/** @name Seek flags.
188 * @{ */
189/** Seek from the start of the file. */
190#define RTFILE_SEEK_BEGIN 0x00
191/** Seek from the current file position. */
192#define RTFILE_SEEK_CURRENT 0x01
193/** Seek from the end of the file. */
194#define RTFILE_SEEK_END 0x02
195/** @internal */
196#define RTFILE_SEEK_FIRST RTFILE_SEEK_BEGIN
197/** @internal */
198#define RTFILE_SEEK_LAST RTFILE_SEEK_END
199/** @} */
200
201
202/**
203 * Changes the read & write position in a file.
204 *
205 * @returns iprt status code.
206 * @param File Handle to the file.
207 * @param offSeek Offset to seek.
208 * @param uMethod Seek method, i.e. one of the RTFILE_SEEK_* defines.
209 * @param poffActual Where to store the new file position.
210 * NULL is allowed.
211 */
212RTR3DECL(int) RTFileSeek(RTFILE File, int64_t offSeek, unsigned uMethod, uint64_t *poffActual);
213
214/**
215 * Read bytes from a file.
216 *
217 * @returns iprt status code.
218 * @param File Handle to the file.
219 * @param pvBuf Where to put the bytes we read.
220 * @param cbToRead How much to read.
221 * @param *pcbRead How much we actually read .
222 * If NULL an error will be returned for a partial read.
223 */
224RTR3DECL(int) RTFileRead(RTFILE File, void *pvBuf, size_t cbToRead, size_t *pcbRead);
225
226/**
227 * Read bytes from a file at a given offset.
228 * This function may modify the file position.
229 *
230 * @returns iprt status code.
231 * @param File Handle to the file.
232 * @param off Where to read.
233 * @param pvBuf Where to put the bytes we read.
234 * @param cbToRead How much to read.
235 * @param *pcbRead How much we actually read .
236 * If NULL an error will be returned for a partial read.
237 */
238RTR3DECL(int) RTFileReadAt(RTFILE File, RTFOFF off, void *pvBuf, size_t cbToRead, size_t *pcbRead);
239
240/**
241 * Write bytes to a file.
242 *
243 * @returns iprt status code.
244 * @param File Handle to the file.
245 * @param pvBuf What to write.
246 * @param cbToWrite How much to write.
247 * @param *pcbWritten How much we actually wrote.
248 * If NULL an error will be returned for a partial write.
249 */
250RTR3DECL(int) RTFileWrite(RTFILE File, const void *pvBuf, size_t cbToWrite, size_t *pcbWritten);
251
252/**
253 * Write bytes to a file at a given offset.
254 * This function may modify the file position.
255 *
256 * @returns iprt status code.
257 * @param File Handle to the file.
258 * @param off Where to write.
259 * @param pvBuf What to write.
260 * @param cbToWrite How much to write.
261 * @param *pcbWritten How much we actually wrote.
262 * If NULL an error will be returned for a partial write.
263 */
264RTR3DECL(int) RTFileWriteAt(RTFILE File, RTFOFF off, const void *pvBuf, size_t cbToWrite, size_t *pcbWritten);
265
266/**
267 * Flushes the buffers for the specified file.
268 *
269 * @returns iprt status code.
270 * @param File Handle to the file.
271 */
272RTR3DECL(int) RTFileFlush(RTFILE File);
273
274/**
275 * Set the size of the file.
276 *
277 * @returns iprt status code.
278 * @param File Handle to the file.
279 * @param cbSize The new file size.
280 */
281RTR3DECL(int) RTFileSetSize(RTFILE File, uint64_t cbSize);
282
283/**
284 * Query the size of the file.
285 *
286 * @returns iprt status code.
287 * @param File Handle to the file.
288 * @param pcbSize Where to store the filesize.
289 */
290RTR3DECL(int) RTFileGetSize(RTFILE File, uint64_t *pcbSize);
291
292/**
293 * Determine the maximum file size.
294 *
295 * @returns The max size of the file.
296 * -1 on failure, the file position is undefined.
297 * @param File Handle to the file.
298 * @see RTFileGetMaxSizeEx.
299 */
300RTR3DECL(RTFOFF) RTFileGetMaxSize(RTFILE File);
301
302/**
303 * Determine the maximum file size.
304 *
305 * @returns IPRT status code.
306 * @param File Handle to the file.
307 * @param pcbMax Where to store the max file size.
308 * @see RTFileGetMaxSize.
309 */
310RTR3DECL(int) RTFileGetMaxSizeEx(RTFILE File, PRTFOFF pcbMax);
311
312/**
313 * Determine the maximum file size depending on the file system the file is stored on.
314 *
315 * @returns The max size of the file.
316 * -1 on failure.
317 * @param File Handle to the file.
318 */
319RTR3DECL(RTFOFF) RTFileGetMaxSize(RTFILE File);
320
321/**
322 * Gets the current file position.
323 *
324 * @returns File offset.
325 * @returns ~0UUL on failure.
326 * @param File Handle to the file.
327 */
328RTDECL(uint64_t) RTFileTell(RTFILE File);
329
330/**
331 * Checks if the supplied handle is valid.
332 *
333 * @returns true if valid.
334 * @returns false if invalid.
335 * @param File The file handle
336 */
337RTR3DECL(bool) RTFileIsValid(RTFILE File);
338
339/**
340 * Copies a file.
341 *
342 * @returns VERR_ALREADY_EXISTS if the destination file exists.
343 * @returns VBox Status code.
344 *
345 * @param pszSrc The path to the source file.
346 * @param pszDst The path to the destination file.
347 * This file will be created.
348 */
349RTDECL(int) RTFileCopy(const char *pszSrc, const char *pszDst);
350
351/**
352 * Copies a file given the handles to both files.
353 *
354 * @returns VBox Status code.
355 *
356 * @param FileSrc The source file. The file position is unaltered.
357 * @param FileDst The destination file.
358 * On successful returns the file position is at the end of the file.
359 * On failures the file position and size is undefined.
360 */
361RTDECL(int) RTFileCopyByHandles(RTFILE FileSrc, RTFILE FileDst);
362
363/** Flags for RTFileCopyEx().
364 * @{ */
365/** Do not use RTFILE_O_DENY_WRITE on the source file to allow for copying files opened for writing. */
366#define RTFILECOPY_FLAGS_NO_SRC_DENY_WRITE RT_BIT(0)
367/** Do not use RTFILE_O_DENY_WRITE on the target file. */
368#define RTFILECOPY_FLAGS_NO_DST_DENY_WRITE RT_BIT(1)
369/** Do not use RTFILE_O_DENY_WRITE on either of the two files. */
370#define RTFILECOPY_FLAGS_NO_DENY_WRITE ( RTFILECOPY_FLAGS_NO_SRC_DENY_WRITE | RTFILECOPY_FLAGS_NO_DST_DENY_WRITE )
371/** */
372#define RTFILECOPY_FLAGS_MASK UINT32_C(0x00000003)
373/** @} */
374
375/**
376 * Copies a file.
377 *
378 * @returns VERR_ALREADY_EXISTS if the destination file exists.
379 * @returns VBox Status code.
380 *
381 * @param pszSrc The path to the source file.
382 * @param pszDst The path to the destination file.
383 * This file will be created.
384 * @param fFlags Flags (RTFILECOPY_*).
385 * @param pfnProgress Pointer to callback function for reporting progress.
386 * @param pvUser User argument to pass to pfnProgress along with the completion precentage.
387 */
388RTDECL(int) RTFileCopyEx(const char *pszSrc, const char *pszDst, uint32_t fFlags, PFNRTPROGRESS pfnProgress, void *pvUser);
389
390/**
391 * Copies a file given the handles to both files and
392 * provide progress callbacks.
393 *
394 * @returns IPRT status code.
395 *
396 * @param FileSrc The source file. The file position is unaltered.
397 * @param FileDst The destination file.
398 * On successful returns the file position is at the end of the file.
399 * On failures the file position and size is undefined.
400 * @param pfnProgress Pointer to callback function for reporting progress.
401 * @param pvUser User argument to pass to pfnProgress along with the completion precentage.
402 */
403RTDECL(int) RTFileCopyByHandlesEx(RTFILE FileSrc, RTFILE FileDst, PFNRTPROGRESS pfnProgress, void *pvUser);
404
405/**
406 * Renames a file.
407 *
408 * Identical to RTPathRename except that it will ensure that the source is not a directory.
409 *
410 * @returns IPRT status code.
411 * @returns VERR_ALREADY_EXISTS if the destination file exists.
412 *
413 * @param pszSrc The path to the source file.
414 * @param pszDst The path to the destination file.
415 * This file will be created.
416 * @param fRename See RTPathRename.
417 */
418RTDECL(int) RTFileRename(const char *pszSrc, const char *pszDst, unsigned fRename);
419
420
421/** @name RTFileMove flags (bit masks).
422 * @{ */
423/** Replace destination file if present. */
424#define RTFILEMOVE_FLAGS_REPLACE 0x1
425/** @} */
426
427/**
428 * Moves a file.
429 *
430 * RTFileMove differs from RTFileRename in that it works across volumes.
431 *
432 * @returns IPRT status code.
433 * @returns VERR_ALREADY_EXISTS if the destination file exists.
434 *
435 * @param pszSrc The path to the source file.
436 * @param pszDst The path to the destination file.
437 * This file will be created.
438 * @param fMove A combination of the RTFILEMOVE_* flags.
439 */
440RTDECL(int) RTFileMove(const char *pszSrc, const char *pszDst, unsigned fMove);
441
442
443/** @page pg_rt_filelock RT File locking API description
444 *
445 * File locking general rules:
446 *
447 * Region to lock or unlock can be located beyond the end of file, this can be used for
448 * growing files.
449 * Read (or Shared) locks can be acquired held by an unlimited number of processes at the
450 * same time, but a Write (or Exclusive) lock can only be acquired by one process, and
451 * cannot coexist with a Shared lock. To acquire a Read lock, a process must wait until
452 * there are no processes holding any Write locks. To acquire a Write lock, a process must
453 * wait until there are no processes holding either kind of lock.
454 * By default, RTFileLock and RTFileChangeLock calls returns error immediately if the lock
455 * can't be acquired due to conflict with other locks, however they can be called in wait mode.
456 *
457 * Differences in implementation:
458 *
459 * Win32, OS/2: Locking is mandatory, since locks are enforced by the operating system.
460 * I.e. when file region is locked in Read mode, any write in it will fail; in case of Write
461 * lock - region can be readed and writed only by lock's owner.
462 *
463 * Win32: File size change (RTFileSetSize) is not controlled by locking at all (!) in the
464 * operation system. Also see comments to RTFileChangeLock API call.
465 *
466 * Linux/Posix: By default locks in Unixes are advisory. This means that cooperating processes
467 * may use locks to coordonate access to a file between themselves, but programs are also free
468 * to ignore locks and access the file in any way they choose to.
469 *
470 * Additional reading:
471 * http://en.wikipedia.org/wiki/File_locking
472 * http://unixhelp.ed.ac.uk/CGI/man-cgi?fcntl+2
473 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/lockfileex.asp
474 */
475
476/** @name Lock flags (bit masks).
477 * @{ */
478/** Read access, can be shared with others. */
479#define RTFILE_LOCK_READ 0x00
480/** Write access, one at a time. */
481#define RTFILE_LOCK_WRITE 0x01
482/** Don't wait for other locks to be released. */
483#define RTFILE_LOCK_IMMEDIATELY 0x00
484/** Wait till conflicting locks have been released. */
485#define RTFILE_LOCK_WAIT 0x02
486/** Valid flags mask */
487#define RTFILE_LOCK_MASK 0x03
488/** @} */
489
490
491/**
492 * Locks a region of file for read (shared) or write (exclusive) access.
493 *
494 * @returns iprt status code.
495 * @returns VERR_FILE_LOCK_VIOLATION if lock can't be acquired.
496 * @param File Handle to the file.
497 * @param fLock Lock method and flags, see RTFILE_LOCK_* defines.
498 * @param offLock Offset of lock start.
499 * @param cbLock Length of region to lock, may overlap the end of file.
500 */
501RTR3DECL(int) RTFileLock(RTFILE File, unsigned fLock, int64_t offLock, uint64_t cbLock);
502
503/**
504 * Changes a lock type from read to write or from write to read.
505 * The region to type change must correspond exactly to an existing locked region.
506 * If change can't be done due to locking conflict and non-blocking mode is used, error is
507 * returned and lock keeps its state (see next warning).
508 *
509 * WARNING: win32 implementation of this call is not atomic, it transforms to a pair of
510 * calls RTFileUnlock and RTFileLock. Potentially the previously acquired lock can be
511 * lost, i.e. function is called in non-blocking mode, previous lock is freed, new lock can't
512 * be acquired, and old lock (previous state) can't be acquired back too. This situation
513 * may occurs _only_ if the other process is acquiring a _write_ lock in blocking mode or
514 * in race condition with the current call.
515 * In this very bad case special error code VERR_FILE_LOCK_LOST will be returned.
516 *
517 * @returns iprt status code.
518 * @returns VERR_FILE_NOT_LOCKED if region was not locked.
519 * @returns VERR_FILE_LOCK_VIOLATION if lock type can't be changed, lock remains its type.
520 * @returns VERR_FILE_LOCK_LOST if lock was lost, we haven't this lock anymore :(
521 * @param File Handle to the file.
522 * @param fLock Lock method and flags, see RTFILE_LOCK_* defines.
523 * @param offLock Offset of lock start.
524 * @param cbLock Length of region to lock, may overlap the end of file.
525 */
526RTR3DECL(int) RTFileChangeLock(RTFILE File, unsigned fLock, int64_t offLock, uint64_t cbLock);
527
528/**
529 * Unlocks previously locked region of file.
530 * The region to unlock must correspond exactly to an existing locked region.
531 *
532 * @returns iprt status code.
533 * @returns VERR_FILE_NOT_LOCKED if region was not locked.
534 * @param File Handle to the file.
535 * @param offLock Offset of lock start.
536 * @param cbLock Length of region to unlock, may overlap the end of file.
537 */
538RTR3DECL(int) RTFileUnlock(RTFILE File, int64_t offLock, uint64_t cbLock);
539
540
541/**
542 * Query information about an open file.
543 *
544 * @returns iprt status code.
545 *
546 * @param File Handle to the file.
547 * @param pObjInfo Object information structure to be filled on successful return.
548 * @param enmAdditionalAttribs Which set of additional attributes to request.
549 * Use RTFSOBJATTRADD_NOTHING if this doesn't matter.
550 */
551RTR3DECL(int) RTFileQueryInfo(RTFILE File, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAdditionalAttribs);
552
553/**
554 * Changes one or more of the timestamps associated of file system object.
555 *
556 * @returns iprt status code.
557 * @returns VERR_NOT_SUPPORTED is returned if the operation isn't supported by the OS.
558 *
559 * @param File Handle to the file.
560 * @param pAccessTime Pointer to the new access time. NULL if not to be changed.
561 * @param pModificationTime Pointer to the new modifcation time. NULL if not to be changed.
562 * @param pChangeTime Pointer to the new change time. NULL if not to be changed.
563 * @param pBirthTime Pointer to the new time of birth. NULL if not to be changed.
564 *
565 * @remark The file system might not implement all these time attributes,
566 * the API will ignore the ones which aren't supported.
567 *
568 * @remark The file system might not implement the time resolution
569 * employed by this interface, the time will be chopped to fit.
570 *
571 * @remark The file system may update the change time even if it's
572 * not specified.
573 *
574 * @remark POSIX can only set Access & Modification and will always set both.
575 */
576RTR3DECL(int) RTFileSetTimes(RTFILE File, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
577 PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime);
578
579/**
580 * Gets one or more of the timestamps associated of file system object.
581 *
582 * @returns iprt status code.
583 * @param File Handle to the file.
584 * @param pAccessTime Where to store the access time. NULL is ok.
585 * @param pModificationTime Where to store the modifcation time. NULL is ok.
586 * @param pChangeTime Where to store the change time. NULL is ok.
587 * @param pBirthTime Where to store the time of birth. NULL is ok.
588 *
589 * @remark This is wrapper around RTFileQueryInfo() and exists to complement RTFileSetTimes().
590 */
591RTR3DECL(int) RTFileGetTimes(RTFILE File, PRTTIMESPEC pAccessTime, PRTTIMESPEC pModificationTime,
592 PRTTIMESPEC pChangeTime, PRTTIMESPEC pBirthTime);
593
594/**
595 * Changes the mode flags of an open file.
596 *
597 * The API requires at least one of the mode flag sets (Unix/Dos) to
598 * be set. The type is ignored.
599 *
600 * @returns iprt status code.
601 * @param File Handle to the file.
602 * @param fMode The new file mode, see @ref grp_rt_fs for details.
603 */
604RTR3DECL(int) RTFileSetMode(RTFILE File, RTFMODE fMode);
605
606/**
607 * Gets the mode flags of an open file.
608 *
609 * @returns iprt status code.
610 * @param File Handle to the file.
611 * @param pfMode Where to store the file mode, see @ref grp_rt_fs for details.
612 *
613 * @remark This is wrapper around RTFileQueryInfo()
614 * and exists to complement RTFileSetMode().
615 */
616RTR3DECL(int) RTFileGetMode(RTFILE File, uint32_t *pfMode);
617
618/**
619 * Changes the owner and/or group of an open file.
620 *
621 * @returns iprt status code.
622 * @param File Handle to the file.
623 * @param uid The new file owner user id. Use -1 (or ~0) to leave this unchanged.
624 * @param gid The new group id. Use -1 (or ~0) to leave this unchanged.
625 */
626RTR3DECL(int) RTFileSetOwner(RTFILE File, uint32_t uid, uint32_t gid);
627
628/**
629 * Gets the owner and/or group of an open file.
630 *
631 * @returns iprt status code.
632 * @param File Handle to the file.
633 * @param pUid Where to store the owner user id. NULL is ok.
634 * @param pGid Where to store the group id. NULL is ok.
635 *
636 * @remark This is wrapper around RTFileQueryInfo() and exists to complement RTFileGetOwner().
637 */
638RTR3DECL(int) RTFileGetOwner(RTFILE File, uint32_t *pUid, uint32_t *pGid);
639
640/**
641 * Executes an IOCTL on a file descriptor.
642 *
643 * This function is currently only available in L4 and posix environments.
644 * Attemps at calling it from code shared with any other platforms will break things!
645 *
646 * The rational for defining this API is to simplify L4 porting of audio drivers,
647 * and to remove some of the assumptions on RTFILE being a file descriptor on
648 * platforms using the posix file implementation.
649 *
650 * @returns iprt status code.
651 * @param File Handle to the file.
652 * @param iRequest IOCTL request to carry out.
653 * @param pvData IOCTL data.
654 * @param cbData Size of the IOCTL data.
655 * @param piRet Return value of the IOCTL request.
656 */
657RTR3DECL(int) RTFileIoCtl(RTFILE File, int iRequest, void *pvData, unsigned cbData, int *piRet);
658
659/**
660 * Reads the file into memory.
661 *
662 * The caller must free the memory using RTFileReadAllFree().
663 *
664 * @returns IPRT status code.
665 * @param pszFilename The name of the file.
666 * @param ppvFile Where to store the pointer to the memory on successful return.
667 * @param pcbFile Where to store the size of the file on successful return.
668 *
669 * @remarks Note that this function may be implemented using memory mapping, which means
670 * that the file may remain open until RTFileReadAllFree() is called. It also
671 * means that the return memory may reflect the state of the file when it's
672 * accessed instead of when this call was done. So, in short, don't use this
673 * API for volatile files, then rather use the extended variant with a
674 * yet-to-be-defined.
675 */
676RTDECL(int) RTFileReadAll(const char *pszFilename, void **ppvFile, size_t *pcbFile);
677
678/**
679 * Reads the file into memory.
680 *
681 * The caller must free the memory using RTFileReadAllFree().
682 *
683 * @returns IPRT status code.
684 * @param pszFilename The name of the file.
685 * @param off The offset to start reading at.
686 * @param cbMax The maximum number of bytes to read into memory. Specify RTFOFF_MAX
687 * to read to the end of the file.
688 * @param fFlags Flags for the future, must be 0.
689 * @param ppvFile Where to store the pointer to the memory on successful return.
690 * @param pcbFile Where to store the size of the file on successful return.
691 *
692 * @remarks See the remarks for RTFileReadAll.
693 */
694RTDECL(int) RTFileReadAllEx(const char *pszFilename, RTFOFF off, RTFOFF cbMax, uint32_t fFlags, void **ppvFile, size_t *pcbFile);
695
696/**
697 * Reads the file into memory.
698 *
699 * The caller must free the memory using RTFileReadAllFree().
700 *
701 * @returns IPRT status code.
702 * @param File The handle to the file.
703 * @param ppvFile Where to store the pointer to the memory on successful return.
704 * @param pcbFile Where to store the size of the file on successful return.
705 *
706 * @remarks See the remarks for RTFileReadAll.
707 */
708RTDECL(int) RTFileReadAllByHandle(RTFILE File, void **ppvFile, size_t *pcbFile);
709
710/**
711 * Reads the file into memory.
712 *
713 * The caller must free the memory using RTFileReadAllFree().
714 *
715 * @returns IPRT status code.
716 * @param File The handle to the file.
717 * @param off The offset to start reading at.
718 * @param cbMax The maximum number of bytes to read into memory. Specify RTFOFF_MAX
719 * to read to the end of the file.
720 * @param fFlags Flags for the future, must be 0.
721 * @param ppvFile Where to store the pointer to the memory on successful return.
722 * @param pcbFile Where to store the size of the file on successful return.
723 *
724 * @remarks See the remarks for RTFileReadAll.
725 */
726RTDECL(int) RTFileReadAllByHandleEx(RTFILE File, RTFOFF off, RTFOFF cbMax, uint32_t fFlags, void **ppvFile, size_t *pcbFile);
727
728/**
729 * Frees the memory returned by one of the RTFileReadAll(), RTFileReadAllEx(),
730 * RTFileReadAllByHandle() and RTFileReadAllByHandleEx() functions.
731 *
732 * @param pvFile Pointer to the memory.
733 * @param cbFile The size of the memory.
734 */
735RTDECL(int) RTFileReadAllFree(void **ppvFile, size_t *pcbFile);
736
737#endif /* IN_RING3 */
738
739/** @} */
740
741__END_DECLS
742
743#endif
744
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