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