VirtualBox

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

Last change on this file since 18645 was 18128, checked in by vboxsync, 16 years ago

IPRT, Shared Folders: Implemented file attributes access flags for RTFileOpen on Windows host (xTracker #3739).

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