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