[1] | 1 | /** @file
|
---|
[8245] | 2 | * IPRT - File I/O.
|
---|
[1] | 3 | */
|
---|
| 4 |
|
---|
| 5 | /*
|
---|
[76553] | 6 | * Copyright (C) 2006-2019 Oracle Corporation
|
---|
[1] | 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
|
---|
[5999] | 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.
|
---|
[1] | 24 | */
|
---|
| 25 |
|
---|
[76557] | 26 | #ifndef IPRT_INCLUDED_file_h
|
---|
| 27 | #define IPRT_INCLUDED_file_h
|
---|
[76507] | 28 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
| 29 | # pragma once
|
---|
| 30 | #endif
|
---|
[1] | 31 |
|
---|
| 32 | #include <iprt/cdefs.h>
|
---|
| 33 | #include <iprt/types.h>
|
---|
[26060] | 34 | #include <iprt/stdarg.h>
|
---|
[37559] | 35 | #include <iprt/fs.h>
|
---|
[46245] | 36 | #include <iprt/sg.h>
|
---|
[1] | 37 |
|
---|
[20374] | 38 | RT_C_DECLS_BEGIN
|
---|
[1] | 39 |
|
---|
| 40 | /** @defgroup grp_rt_fileio RTFile - File I/O
|
---|
| 41 | * @ingroup grp_rt
|
---|
| 42 | * @{
|
---|
| 43 | */
|
---|
| 44 |
|
---|
| 45 | /** Platform specific text line break.
|
---|
| 46 | * @deprecated Use text I/O streams and '\\n'. See iprt/stream.h. */
|
---|
[3636] | 47 | #if defined(RT_OS_OS2) || defined(RT_OS_WINDOWS)
|
---|
[1] | 48 | # define RTFILE_LINEFEED "\r\n"
|
---|
| 49 | #else
|
---|
| 50 | # define RTFILE_LINEFEED "\n"
|
---|
| 51 | #endif
|
---|
| 52 |
|
---|
[33233] | 53 | /** Platform specific native standard input "handle". */
|
---|
| 54 | #ifdef RT_OS_WINDOWS
|
---|
| 55 | # define RTFILE_NATIVE_STDIN ((uint32_t)-10)
|
---|
| 56 | #else
|
---|
| 57 | # define RTFILE_NATIVE_STDIN 0
|
---|
| 58 | #endif
|
---|
[1] | 59 |
|
---|
[39195] | 60 | /** Platform specific native standard out "handle". */
|
---|
[33233] | 61 | #ifdef RT_OS_WINDOWS
|
---|
| 62 | # define RTFILE_NATIVE_STDOUT ((uint32_t)-11)
|
---|
| 63 | #else
|
---|
| 64 | # define RTFILE_NATIVE_STDOUT 1
|
---|
| 65 | #endif
|
---|
| 66 |
|
---|
| 67 | /** Platform specific native standard error "handle". */
|
---|
| 68 | #ifdef RT_OS_WINDOWS
|
---|
| 69 | # define RTFILE_NATIVE_STDERR ((uint32_t)-12)
|
---|
| 70 | #else
|
---|
| 71 | # define RTFILE_NATIVE_STDERR 2
|
---|
| 72 | #endif
|
---|
| 73 |
|
---|
| 74 |
|
---|
[22516] | 75 | /**
|
---|
| 76 | * Checks if the specified file name exists and is a regular file.
|
---|
| 77 | *
|
---|
| 78 | * Symbolic links will be resolved.
|
---|
| 79 | *
|
---|
| 80 | * @returns true if it's a regular file, false if it isn't.
|
---|
| 81 | * @param pszPath The path to the file.
|
---|
| 82 | *
|
---|
| 83 | * @sa RTDirExists, RTPathExists, RTSymlinkExists.
|
---|
| 84 | */
|
---|
| 85 | RTDECL(bool) RTFileExists(const char *pszPath);
|
---|
| 86 |
|
---|
[24189] | 87 | /**
|
---|
| 88 | * Queries the size of a file, given the path to it.
|
---|
| 89 | *
|
---|
| 90 | * Symbolic links will be resolved.
|
---|
| 91 | *
|
---|
| 92 | * @returns IPRT status code.
|
---|
| 93 | * @param pszPath The path to the file.
|
---|
| 94 | * @param pcbFile Where to return the file size (bytes).
|
---|
| 95 | *
|
---|
| 96 | * @sa RTFileGetSize, RTPathQueryInfoEx.
|
---|
| 97 | */
|
---|
| 98 | RTDECL(int) RTFileQuerySize(const char *pszPath, uint64_t *pcbFile);
|
---|
[22516] | 99 |
|
---|
[24189] | 100 |
|
---|
[1] | 101 | /** @name Open flags
|
---|
| 102 | * @{ */
|
---|
[58768] | 103 | /** Attribute access only.
|
---|
| 104 | * @remarks Only accepted on windows, requires RTFILE_O_ACCESS_ATTR_MASK
|
---|
| 105 | * to yield a non-zero result. Otherwise, this is invalid. */
|
---|
| 106 | #define RTFILE_O_ATTR_ONLY UINT32_C(0x00000000)
|
---|
[1] | 107 | /** Open the file with read access. */
|
---|
[23974] | 108 | #define RTFILE_O_READ UINT32_C(0x00000001)
|
---|
[1] | 109 | /** Open the file with write access. */
|
---|
[23974] | 110 | #define RTFILE_O_WRITE UINT32_C(0x00000002)
|
---|
[1] | 111 | /** Open the file with read & write access. */
|
---|
[23974] | 112 | #define RTFILE_O_READWRITE UINT32_C(0x00000003)
|
---|
[1] | 113 | /** The file access mask.
|
---|
[58768] | 114 | * @remarks The value 0 is invalid, except for windows special case. */
|
---|
[23974] | 115 | #define RTFILE_O_ACCESS_MASK UINT32_C(0x00000003)
|
---|
[1] | 116 |
|
---|
[21582] | 117 | /** Open file in APPEND mode, so all writes to the file handle will
|
---|
| 118 | * append data at the end of the file.
|
---|
[21616] | 119 | * @remarks It is ignored if write access is not requested, that is
|
---|
| 120 | * RTFILE_O_WRITE is not set. */
|
---|
[23974] | 121 | #define RTFILE_O_APPEND UINT32_C(0x00000004)
|
---|
| 122 | /* UINT32_C(0x00000008) is unused atm. */
|
---|
[21582] | 123 |
|
---|
[23973] | 124 | /** Sharing mode: deny none. */
|
---|
[23974] | 125 | #define RTFILE_O_DENY_NONE UINT32_C(0x00000080)
|
---|
[1] | 126 | /** Sharing mode: deny read. */
|
---|
[23974] | 127 | #define RTFILE_O_DENY_READ UINT32_C(0x00000010)
|
---|
[1] | 128 | /** Sharing mode: deny write. */
|
---|
[23974] | 129 | #define RTFILE_O_DENY_WRITE UINT32_C(0x00000020)
|
---|
[1] | 130 | /** Sharing mode: deny read and write. */
|
---|
[23974] | 131 | #define RTFILE_O_DENY_READWRITE UINT32_C(0x00000030)
|
---|
[1] | 132 | /** Sharing mode: deny all. */
|
---|
[21616] | 133 | #define RTFILE_O_DENY_ALL RTFILE_O_DENY_READWRITE
|
---|
[1] | 134 | /** Sharing mode: do NOT deny delete (NT).
|
---|
[21616] | 135 | * @remarks This might not be implemented on all platforms, and will be
|
---|
| 136 | * defaulted & ignored on those.
|
---|
[1] | 137 | */
|
---|
[23974] | 138 | #define RTFILE_O_DENY_NOT_DELETE UINT32_C(0x00000040)
|
---|
[1] | 139 | /** Sharing mode mask. */
|
---|
[23974] | 140 | #define RTFILE_O_DENY_MASK UINT32_C(0x000000f0)
|
---|
[1] | 141 |
|
---|
[77681] | 142 | /** Action: Open an existing file. */
|
---|
[23974] | 143 | #define RTFILE_O_OPEN UINT32_C(0x00000700)
|
---|
[1] | 144 | /** Action: Create a new file or open an existing one. */
|
---|
[23974] | 145 | #define RTFILE_O_OPEN_CREATE UINT32_C(0x00000100)
|
---|
[1] | 146 | /** Action: Create a new a file. */
|
---|
[23974] | 147 | #define RTFILE_O_CREATE UINT32_C(0x00000200)
|
---|
[1] | 148 | /** Action: Create a new file or replace an existing one. */
|
---|
[23974] | 149 | #define RTFILE_O_CREATE_REPLACE UINT32_C(0x00000300)
|
---|
[1] | 150 | /** Action mask. */
|
---|
[23974] | 151 | #define RTFILE_O_ACTION_MASK UINT32_C(0x00000700)
|
---|
[1] | 152 |
|
---|
[6992] | 153 | /** Turns off indexing of files on Windows hosts, *CREATE* only.
|
---|
[21616] | 154 | * @remarks Window only. */
|
---|
[23974] | 155 | #define RTFILE_O_NOT_CONTENT_INDEXED UINT32_C(0x00000800)
|
---|
[1] | 156 | /** Truncate the file.
|
---|
[21616] | 157 | * @remarks This will not truncate files opened for read-only.
|
---|
[47735] | 158 | * @remarks The truncation doesn't have to be atomically, so anyone else opening
|
---|
[21616] | 159 | * the file may be racing us. The caller is responsible for not causing
|
---|
| 160 | * this race. */
|
---|
[23974] | 161 | #define RTFILE_O_TRUNCATE UINT32_C(0x00001000)
|
---|
[1] | 162 | /** Make the handle inheritable on RTProcessCreate(/exec). */
|
---|
[23974] | 163 | #define RTFILE_O_INHERIT UINT32_C(0x00002000)
|
---|
[1] | 164 | /** Open file in non-blocking mode - non-portable.
|
---|
[21616] | 165 | * @remarks This flag may not be supported on all platforms, in which case it's
|
---|
| 166 | * considered an invalid parameter. */
|
---|
[23974] | 167 | #define RTFILE_O_NON_BLOCK UINT32_C(0x00004000)
|
---|
[1] | 168 | /** Write through directly to disk. Workaround to avoid iSCSI
|
---|
| 169 | * initiator deadlocks on Windows hosts.
|
---|
[21616] | 170 | * @remarks This might not be implemented on all platforms, and will be ignored
|
---|
| 171 | * on those. */
|
---|
[23974] | 172 | #define RTFILE_O_WRITE_THROUGH UINT32_C(0x00008000)
|
---|
[18128] | 173 |
|
---|
[21616] | 174 | /** Attribute access: Attributes can be read if the file is being opened with
|
---|
| 175 | * read access, and can be written with write access. */
|
---|
[23974] | 176 | #define RTFILE_O_ACCESS_ATTR_DEFAULT UINT32_C(0x00000000)
|
---|
[21616] | 177 | /** Attribute access: Attributes can be read.
|
---|
| 178 | * @remarks Windows only. */
|
---|
[23974] | 179 | #define RTFILE_O_ACCESS_ATTR_READ UINT32_C(0x00010000)
|
---|
[21616] | 180 | /** Attribute access: Attributes can be written.
|
---|
| 181 | * @remarks Windows only. */
|
---|
[23974] | 182 | #define RTFILE_O_ACCESS_ATTR_WRITE UINT32_C(0x00020000)
|
---|
[21616] | 183 | /** Attribute access: Attributes can be both read & written.
|
---|
| 184 | * @remarks Windows only. */
|
---|
[23974] | 185 | #define RTFILE_O_ACCESS_ATTR_READWRITE UINT32_C(0x00030000)
|
---|
[21616] | 186 | /** Attribute access: The file attributes access mask.
|
---|
| 187 | * @remarks Windows only. */
|
---|
[23974] | 188 | #define RTFILE_O_ACCESS_ATTR_MASK UINT32_C(0x00030000)
|
---|
[18128] | 189 |
|
---|
[21582] | 190 | /** Open file for async I/O
|
---|
[21616] | 191 | * @remarks This flag may not be needed on all platforms, and will be ignored on
|
---|
| 192 | * those. */
|
---|
[23974] | 193 | #define RTFILE_O_ASYNC_IO UINT32_C(0x00040000)
|
---|
[21582] | 194 |
|
---|
[21573] | 195 | /** Disables caching.
|
---|
| 196 | *
|
---|
| 197 | * Useful when using very big files which might bring the host I/O scheduler to
|
---|
| 198 | * its knees during high I/O load.
|
---|
| 199 | *
|
---|
| 200 | * @remarks This flag might impose restrictions
|
---|
[21493] | 201 | * on the buffer alignment, start offset and/or transfer size.
|
---|
[21573] | 202 | *
|
---|
[21493] | 203 | * On Linux the buffer needs to be aligned to the 512 sector
|
---|
| 204 | * boundary.
|
---|
[21573] | 205 | *
|
---|
| 206 | * On Windows the FILE_FLAG_NO_BUFFERING is used (see
|
---|
| 207 | * http://msdn.microsoft.com/en-us/library/cc644950(VS.85).aspx ).
|
---|
[34435] | 208 | * The buffer address, the transfer size and offset needs to be aligned
|
---|
| 209 | * to the sector size of the volume. Furthermore FILE_APPEND_DATA is
|
---|
| 210 | * disabled. To write beyond the size of file use RTFileSetSize prior
|
---|
[23047] | 211 | * writing the data to the file.
|
---|
[21573] | 212 | *
|
---|
[34435] | 213 | * This flag does not work on Solaris if the target filesystem is ZFS.
|
---|
| 214 | * RTFileOpen will return an error with that configuration. When used
|
---|
| 215 | * with UFS the same alginment restrictions apply like Linux and
|
---|
| 216 | * Windows.
|
---|
[23047] | 217 | *
|
---|
[34435] | 218 | * @remarks This might not be implemented on all platforms, and will be ignored
|
---|
| 219 | * on those.
|
---|
[21493] | 220 | */
|
---|
[23974] | 221 | #define RTFILE_O_NO_CACHE UINT32_C(0x00080000)
|
---|
[10526] | 222 |
|
---|
[39641] | 223 | /** Don't allow symbolic links as part of the path.
|
---|
| 224 | * @remarks this flag is currently not implemented and will be ignored. */
|
---|
[39612] | 225 | #define RTFILE_O_NO_SYMLINKS UINT32_C(0x20000000)
|
---|
| 226 |
|
---|
[21616] | 227 | /** Unix file mode mask for use when creating files. */
|
---|
[23974] | 228 | #define RTFILE_O_CREATE_MODE_MASK UINT32_C(0x1ff00000)
|
---|
[21616] | 229 | /** The number of bits to shift to get the file mode mask.
|
---|
| 230 | * To extract it: (fFlags & RTFILE_O_CREATE_MODE_MASK) >> RTFILE_O_CREATE_MODE_SHIFT.
|
---|
| 231 | */
|
---|
| 232 | #define RTFILE_O_CREATE_MODE_SHIFT 20
|
---|
| 233 |
|
---|
[39612] | 234 | /* UINT32_C(0x40000000)
|
---|
| 235 | and UINT32_C(0x80000000) are unused atm. */
|
---|
[21616] | 236 |
|
---|
[1] | 237 | /** Mask of all valid flags.
|
---|
| 238 | * @remark This doesn't validate the access mode properly.
|
---|
| 239 | */
|
---|
[39612] | 240 | #define RTFILE_O_VALID_MASK UINT32_C(0x3ffffff7)
|
---|
[1] | 241 |
|
---|
| 242 | /** @} */
|
---|
| 243 |
|
---|
| 244 |
|
---|
[77681] | 245 | /** Action taken by RTFileOpenEx. */
|
---|
| 246 | typedef enum RTFILEACTION
|
---|
| 247 | {
|
---|
| 248 | /** Invalid zero value. */
|
---|
| 249 | RTFILEACTION_INVALID = 0,
|
---|
| 250 | /** Existing file was opened (returned by RTFILE_O_OPEN and
|
---|
| 251 | * RTFILE_O_OPEN_CREATE). */
|
---|
| 252 | RTFILEACTION_OPENED,
|
---|
| 253 | /** New file was created (returned by RTFILE_O_CREATE and
|
---|
| 254 | * RTFILE_O_OPEN_CREATE). */
|
---|
| 255 | RTFILEACTION_CREATED,
|
---|
| 256 | /** Existing file was replaced (returned by RTFILE_O_CREATE_REPLACE). */
|
---|
| 257 | RTFILEACTION_REPLACED,
|
---|
| 258 | /** Existing file was truncated (returned if RTFILE_O_TRUNCATE take effect). */
|
---|
| 259 | RTFILEACTION_TRUNCATED,
|
---|
| 260 | /** The file already exists (returned by RTFILE_O_CREATE on failure). */
|
---|
| 261 | RTFILEACTION_ALREADY_EXISTS,
|
---|
| 262 | /** End of valid values. */
|
---|
| 263 | RTFILEACTION_END,
|
---|
| 264 | /** Type size hack. */
|
---|
| 265 | RTFILEACTION_32BIT_HACK = 0x7fffffff
|
---|
| 266 | } RTFILEACTION;
|
---|
| 267 | /** Pointer to action taken value (RTFileOpenEx). */
|
---|
| 268 | typedef RTFILEACTION *PRTFILEACTION;
|
---|
| 269 |
|
---|
| 270 |
|
---|
[37559] | 271 | #ifdef IN_RING3
|
---|
[1] | 272 | /**
|
---|
| 273 | * Force the use of open flags for all files opened after the setting is
|
---|
| 274 | * changed. The caller is responsible for not causing races with RTFileOpen().
|
---|
| 275 | *
|
---|
| 276 | * @returns iprt status code.
|
---|
| 277 | * @param fOpenForAccess Access mode to which the set/mask settings apply.
|
---|
| 278 | * @param fSet Open flags to be forced set.
|
---|
| 279 | * @param fMask Open flags to be masked out.
|
---|
| 280 | */
|
---|
| 281 | RTR3DECL(int) RTFileSetForceFlags(unsigned fOpenForAccess, unsigned fSet, unsigned fMask);
|
---|
[37559] | 282 | #endif /* IN_RING3 */
|
---|
[1] | 283 |
|
---|
| 284 | /**
|
---|
| 285 | * Open a file.
|
---|
| 286 | *
|
---|
| 287 | * @returns iprt status code.
|
---|
| 288 | * @param pFile Where to store the handle to the opened file.
|
---|
| 289 | * @param pszFilename Path to the file which is to be opened. (UTF-8)
|
---|
| 290 | * @param fOpen Open flags, i.e a combination of the RTFILE_O_* defines.
|
---|
[23973] | 291 | * The ACCESS, ACTION and DENY flags are mandatory!
|
---|
[1] | 292 | */
|
---|
[37596] | 293 | RTDECL(int) RTFileOpen(PRTFILE pFile, const char *pszFilename, uint64_t fOpen);
|
---|
[1] | 294 |
|
---|
| 295 | /**
|
---|
[26060] | 296 | * Open a file given as a format string.
|
---|
| 297 | *
|
---|
| 298 | * @returns iprt status code.
|
---|
| 299 | * @param pFile Where to store the handle to the opened file.
|
---|
| 300 | * @param fOpen Open flags, i.e a combination of the RTFILE_O_* defines.
|
---|
| 301 | * The ACCESS, ACTION and DENY flags are mandatory!
|
---|
| 302 | * @param pszFilenameFmt Format string givin the path to the file which is to
|
---|
| 303 | * be opened. (UTF-8)
|
---|
| 304 | * @param ... Arguments to the format string.
|
---|
| 305 | */
|
---|
[57004] | 306 | RTDECL(int) RTFileOpenF(PRTFILE pFile, uint64_t fOpen, const char *pszFilenameFmt, ...) RT_IPRT_FORMAT_ATTR(3, 4);
|
---|
[26060] | 307 |
|
---|
| 308 | /**
|
---|
| 309 | * Open a file given as a format string.
|
---|
| 310 | *
|
---|
| 311 | * @returns iprt status code.
|
---|
| 312 | * @param pFile Where to store the handle to the opened file.
|
---|
| 313 | * @param fOpen Open flags, i.e a combination of the RTFILE_O_* defines.
|
---|
| 314 | * The ACCESS, ACTION and DENY flags are mandatory!
|
---|
| 315 | * @param pszFilenameFmt Format string givin the path to the file which is to
|
---|
| 316 | * be opened. (UTF-8)
|
---|
| 317 | * @param va Arguments to the format string.
|
---|
| 318 | */
|
---|
[57004] | 319 | RTDECL(int) RTFileOpenV(PRTFILE pFile, uint64_t fOpen, const char *pszFilenameFmt, va_list va) RT_IPRT_FORMAT_ATTR(3, 0);
|
---|
[26060] | 320 |
|
---|
| 321 | /**
|
---|
[77681] | 322 | * Open a file, extended version.
|
---|
| 323 | *
|
---|
| 324 | * @returns iprt status code.
|
---|
| 325 | * @param pszFilename Path to the file which is to be opened. (UTF-8)
|
---|
| 326 | * @param fOpen Open flags, i.e a combination of the RTFILE_O_* defines.
|
---|
| 327 | * The ACCESS, ACTION and DENY flags are mandatory!
|
---|
| 328 | * @param phFile Where to store the handle to the opened file.
|
---|
| 329 | * @param penmActionTaken Where to return an indicator of which action was
|
---|
| 330 | * taken. This is optional and it is recommended to
|
---|
| 331 | * pass NULL when not strictly needed as it adds
|
---|
| 332 | * complexity (slower) on posix systems.
|
---|
| 333 | */
|
---|
| 334 | RTDECL(int) RTFileOpenEx(const char *pszFilename, uint64_t fOpen, PRTFILE phFile, PRTFILEACTION penmActionTaken);
|
---|
| 335 |
|
---|
| 336 | /**
|
---|
[26732] | 337 | * Open the bit bucket (aka /dev/null or nul).
|
---|
| 338 | *
|
---|
| 339 | * @returns IPRT status code.
|
---|
[26774] | 340 | * @param phFile Where to store the handle to the opened file.
|
---|
[26732] | 341 | * @param fAccess The desired access only, i.e. read, write or both.
|
---|
| 342 | */
|
---|
[37596] | 343 | RTDECL(int) RTFileOpenBitBucket(PRTFILE phFile, uint64_t fAccess);
|
---|
[26732] | 344 |
|
---|
| 345 | /**
|
---|
[1] | 346 | * Close a file opened by RTFileOpen().
|
---|
| 347 | *
|
---|
| 348 | * @returns iprt status code.
|
---|
| 349 | * @param File The file handle to close.
|
---|
| 350 | */
|
---|
[37559] | 351 | RTDECL(int) RTFileClose(RTFILE File);
|
---|
[1] | 352 |
|
---|
| 353 | /**
|
---|
[8558] | 354 | * Creates an IPRT file handle from a native one.
|
---|
| 355 | *
|
---|
| 356 | * @returns IPRT status code.
|
---|
| 357 | * @param pFile Where to store the IPRT file handle.
|
---|
| 358 | * @param uNative The native handle.
|
---|
| 359 | */
|
---|
[37559] | 360 | RTDECL(int) RTFileFromNative(PRTFILE pFile, RTHCINTPTR uNative);
|
---|
[8558] | 361 |
|
---|
| 362 | /**
|
---|
| 363 | * Gets the native handle for an IPRT file handle.
|
---|
| 364 | *
|
---|
| 365 | * @return The native handle.
|
---|
[25645] | 366 | * @param File The IPRT file handle.
|
---|
[8558] | 367 | */
|
---|
[37559] | 368 | RTDECL(RTHCINTPTR) RTFileToNative(RTFILE File);
|
---|
[8558] | 369 |
|
---|
| 370 | /**
|
---|
[1] | 371 | * Delete a file.
|
---|
| 372 | *
|
---|
| 373 | * @returns iprt status code.
|
---|
| 374 | * @param pszFilename Path to the file which is to be deleted. (UTF-8)
|
---|
| 375 | * @todo This is a RTPath api!
|
---|
| 376 | */
|
---|
[37559] | 377 | RTDECL(int) RTFileDelete(const char *pszFilename);
|
---|
[1] | 378 |
|
---|
| 379 | /** @name Seek flags.
|
---|
| 380 | * @{ */
|
---|
| 381 | /** Seek from the start of the file. */
|
---|
| 382 | #define RTFILE_SEEK_BEGIN 0x00
|
---|
| 383 | /** Seek from the current file position. */
|
---|
| 384 | #define RTFILE_SEEK_CURRENT 0x01
|
---|
| 385 | /** Seek from the end of the file. */
|
---|
| 386 | #define RTFILE_SEEK_END 0x02
|
---|
| 387 | /** @internal */
|
---|
| 388 | #define RTFILE_SEEK_FIRST RTFILE_SEEK_BEGIN
|
---|
| 389 | /** @internal */
|
---|
| 390 | #define RTFILE_SEEK_LAST RTFILE_SEEK_END
|
---|
| 391 | /** @} */
|
---|
| 392 |
|
---|
| 393 |
|
---|
| 394 | /**
|
---|
| 395 | * Changes the read & write position in a file.
|
---|
| 396 | *
|
---|
| 397 | * @returns iprt status code.
|
---|
| 398 | * @param File Handle to the file.
|
---|
| 399 | * @param offSeek Offset to seek.
|
---|
| 400 | * @param uMethod Seek method, i.e. one of the RTFILE_SEEK_* defines.
|
---|
| 401 | * @param poffActual Where to store the new file position.
|
---|
| 402 | * NULL is allowed.
|
---|
| 403 | */
|
---|
[37559] | 404 | RTDECL(int) RTFileSeek(RTFILE File, int64_t offSeek, unsigned uMethod, uint64_t *poffActual);
|
---|
[1] | 405 |
|
---|
| 406 | /**
|
---|
| 407 | * Read bytes from a file.
|
---|
| 408 | *
|
---|
| 409 | * @returns iprt status code.
|
---|
| 410 | * @param File Handle to the file.
|
---|
| 411 | * @param pvBuf Where to put the bytes we read.
|
---|
| 412 | * @param cbToRead How much to read.
|
---|
[77632] | 413 | * @param pcbRead How much we actually read .
|
---|
[1] | 414 | * If NULL an error will be returned for a partial read.
|
---|
| 415 | */
|
---|
[37559] | 416 | RTDECL(int) RTFileRead(RTFILE File, void *pvBuf, size_t cbToRead, size_t *pcbRead);
|
---|
[1] | 417 |
|
---|
| 418 | /**
|
---|
| 419 | * Read bytes from a file at a given offset.
|
---|
| 420 | *
|
---|
| 421 | * @returns iprt status code.
|
---|
| 422 | * @param File Handle to the file.
|
---|
| 423 | * @param off Where to read.
|
---|
| 424 | * @param pvBuf Where to put the bytes we read.
|
---|
| 425 | * @param cbToRead How much to read.
|
---|
[77632] | 426 | * @param pcbRead How much we actually read .
|
---|
[1] | 427 | * If NULL an error will be returned for a partial read.
|
---|
[77632] | 428 | *
|
---|
| 429 | * @note OS/2 requires separate seek and write calls.
|
---|
| 430 | *
|
---|
[77236] | 431 | * @note Whether the file position is modified or not is host specific.
|
---|
[1] | 432 | */
|
---|
[37559] | 433 | RTDECL(int) RTFileReadAt(RTFILE File, RTFOFF off, void *pvBuf, size_t cbToRead, size_t *pcbRead);
|
---|
[1] | 434 |
|
---|
| 435 | /**
|
---|
[46245] | 436 | * Read bytes from a file at a given offset into a S/G buffer.
|
---|
| 437 | *
|
---|
| 438 | * @returns iprt status code.
|
---|
| 439 | * @param hFile Handle to the file.
|
---|
[77632] | 440 | * @param pSgBuf Pointer to the S/G buffer to read into.
|
---|
| 441 | * @param cbToRead How much to read.
|
---|
| 442 | * @param pcbRead How much we actually read .
|
---|
| 443 | * If NULL an error will be returned for a partial read.
|
---|
| 444 | *
|
---|
| 445 | * @note It is not possible to guarantee atomicity on all platforms, so
|
---|
| 446 | * caller must take care wrt concurrent access to @a hFile.
|
---|
| 447 | */
|
---|
| 448 | RTDECL(int) RTFileSgRead(RTFILE hFile, PRTSGBUF pSgBuf, size_t cbToRead, size_t *pcbRead);
|
---|
| 449 |
|
---|
| 450 | /**
|
---|
| 451 | * Read bytes from a file at a given offset into a S/G buffer.
|
---|
| 452 | *
|
---|
| 453 | * @returns iprt status code.
|
---|
| 454 | * @param hFile Handle to the file.
|
---|
[46245] | 455 | * @param off Where to read.
|
---|
| 456 | * @param pSgBuf Pointer to the S/G buffer to read into.
|
---|
| 457 | * @param cbToRead How much to read.
|
---|
[77632] | 458 | * @param pcbRead How much we actually read .
|
---|
[46245] | 459 | * If NULL an error will be returned for a partial read.
|
---|
[77632] | 460 | *
|
---|
[77236] | 461 | * @note Whether the file position is modified or not is host specific.
|
---|
[77632] | 462 | *
|
---|
| 463 | * @note It is not possible to guarantee atomicity on all platforms, so
|
---|
| 464 | * caller must take care wrt concurrent access to @a hFile.
|
---|
[46245] | 465 | */
|
---|
| 466 | RTDECL(int) RTFileSgReadAt(RTFILE hFile, RTFOFF off, PRTSGBUF pSgBuf, size_t cbToRead, size_t *pcbRead);
|
---|
| 467 |
|
---|
| 468 | /**
|
---|
[1] | 469 | * Write bytes to a file.
|
---|
| 470 | *
|
---|
| 471 | * @returns iprt status code.
|
---|
| 472 | * @param File Handle to the file.
|
---|
| 473 | * @param pvBuf What to write.
|
---|
| 474 | * @param cbToWrite How much to write.
|
---|
[77632] | 475 | * @param pcbWritten How much we actually wrote.
|
---|
[1] | 476 | * If NULL an error will be returned for a partial write.
|
---|
| 477 | */
|
---|
[37559] | 478 | RTDECL(int) RTFileWrite(RTFILE File, const void *pvBuf, size_t cbToWrite, size_t *pcbWritten);
|
---|
[1] | 479 |
|
---|
| 480 | /**
|
---|
| 481 | * Write bytes to a file at a given offset.
|
---|
| 482 | *
|
---|
| 483 | * @returns iprt status code.
|
---|
[77236] | 484 | * @param hFile Handle to the file.
|
---|
[1] | 485 | * @param off Where to write.
|
---|
| 486 | * @param pvBuf What to write.
|
---|
| 487 | * @param cbToWrite How much to write.
|
---|
[77632] | 488 | * @param pcbWritten How much we actually wrote.
|
---|
[1] | 489 | * If NULL an error will be returned for a partial write.
|
---|
[77236] | 490 | *
|
---|
[77632] | 491 | * @note OS/2 requires separate seek and write calls.
|
---|
| 492 | *
|
---|
[77236] | 493 | * @note Whether the file position is modified or not is host specific.
|
---|
[77632] | 494 | *
|
---|
[77236] | 495 | * @note Whether @a off is used when @a hFile was opened with RTFILE_O_APPEND
|
---|
| 496 | * is also host specific. Currently Linux is the the only one
|
---|
| 497 | * documented to ignore @a off.
|
---|
[1] | 498 | */
|
---|
[77236] | 499 | RTDECL(int) RTFileWriteAt(RTFILE hFile, RTFOFF off, const void *pvBuf, size_t cbToWrite, size_t *pcbWritten);
|
---|
[1] | 500 |
|
---|
| 501 | /**
|
---|
[77632] | 502 | * Write bytes from a S/G buffer to a file.
|
---|
| 503 | *
|
---|
| 504 | * @returns iprt status code.
|
---|
| 505 | * @param hFile Handle to the file.
|
---|
| 506 | * @param pSgBuf What to write.
|
---|
| 507 | * @param cbToWrite How much to write.
|
---|
| 508 | * @param pcbWritten How much we actually wrote.
|
---|
| 509 | * If NULL an error will be returned for a partial write.
|
---|
| 510 | *
|
---|
| 511 | * @note It is not possible to guarantee atomicity on all platforms, so
|
---|
| 512 | * caller must take care wrt concurrent access to @a hFile.
|
---|
| 513 | */
|
---|
| 514 | RTDECL(int) RTFileSgWrite(RTFILE hFile, PRTSGBUF pSgBuf, size_t cbToWrite, size_t *pcbWritten);
|
---|
| 515 |
|
---|
| 516 | /**
|
---|
[46245] | 517 | * Write bytes from a S/G buffer to a file at a given offset.
|
---|
| 518 | *
|
---|
| 519 | * @returns iprt status code.
|
---|
| 520 | * @param hFile Handle to the file.
|
---|
| 521 | * @param off Where to write.
|
---|
| 522 | * @param pSgBuf What to write.
|
---|
| 523 | * @param cbToWrite How much to write.
|
---|
[77632] | 524 | * @param pcbWritten How much we actually wrote.
|
---|
[46245] | 525 | * If NULL an error will be returned for a partial write.
|
---|
[77236] | 526 | *
|
---|
[77632] | 527 | * @note It is not possible to guarantee atomicity on all platforms, so
|
---|
| 528 | * caller must take care wrt concurrent access to @a hFile.
|
---|
| 529 | *
|
---|
[77236] | 530 | * @note Whether the file position is modified or not is host specific.
|
---|
[77632] | 531 | *
|
---|
[77236] | 532 | * @note Whether @a off is used when @a hFile was opened with RTFILE_O_APPEND
|
---|
| 533 | * is also host specific. Currently Linux is the the only one
|
---|
| 534 | * documented to ignore @a off.
|
---|
[46245] | 535 | */
|
---|
| 536 | RTDECL(int) RTFileSgWriteAt(RTFILE hFile, RTFOFF off, PRTSGBUF pSgBuf, size_t cbToWrite, size_t *pcbWritten);
|
---|
| 537 |
|
---|
| 538 | /**
|
---|
[1] | 539 | * Flushes the buffers for the specified file.
|
---|
| 540 | *
|
---|
| 541 | * @returns iprt status code.
|
---|
| 542 | * @param File Handle to the file.
|
---|
| 543 | */
|
---|
[37559] | 544 | RTDECL(int) RTFileFlush(RTFILE File);
|
---|
[1] | 545 |
|
---|
| 546 | /**
|
---|
| 547 | * Set the size of the file.
|
---|
| 548 | *
|
---|
| 549 | * @returns iprt status code.
|
---|
| 550 | * @param File Handle to the file.
|
---|
| 551 | * @param cbSize The new file size.
|
---|
| 552 | */
|
---|
[37559] | 553 | RTDECL(int) RTFileSetSize(RTFILE File, uint64_t cbSize);
|
---|
[1] | 554 |
|
---|
| 555 | /**
|
---|
| 556 | * Query the size of the file.
|
---|
| 557 | *
|
---|
| 558 | * @returns iprt status code.
|
---|
| 559 | * @param File Handle to the file.
|
---|
| 560 | * @param pcbSize Where to store the filesize.
|
---|
| 561 | */
|
---|
[37559] | 562 | RTDECL(int) RTFileGetSize(RTFILE File, uint64_t *pcbSize);
|
---|
[1] | 563 |
|
---|
| 564 | /**
|
---|
[6992] | 565 | * Determine the maximum file size.
|
---|
| 566 | *
|
---|
| 567 | * @returns The max size of the file.
|
---|
[6429] | 568 | * -1 on failure, the file position is undefined.
|
---|
[6992] | 569 | * @param File Handle to the file.
|
---|
| 570 | * @see RTFileGetMaxSizeEx.
|
---|
[6421] | 571 | */
|
---|
[37559] | 572 | RTDECL(RTFOFF) RTFileGetMaxSize(RTFILE File);
|
---|
[6421] | 573 |
|
---|
| 574 | /**
|
---|
[6992] | 575 | * Determine the maximum file size.
|
---|
| 576 | *
|
---|
[6429] | 577 | * @returns IPRT status code.
|
---|
[6992] | 578 | * @param File Handle to the file.
|
---|
| 579 | * @param pcbMax Where to store the max file size.
|
---|
[6429] | 580 | * @see RTFileGetMaxSize.
|
---|
| 581 | */
|
---|
[37559] | 582 | RTDECL(int) RTFileGetMaxSizeEx(RTFILE File, PRTFOFF pcbMax);
|
---|
[6429] | 583 |
|
---|
| 584 | /**
|
---|
[6992] | 585 | * Determine the maximum file size depending on the file system the file is stored on.
|
---|
| 586 | *
|
---|
| 587 | * @returns The max size of the file.
|
---|
[6429] | 588 | * -1 on failure.
|
---|
[6992] | 589 | * @param File Handle to the file.
|
---|
[6429] | 590 | */
|
---|
[37559] | 591 | RTDECL(RTFOFF) RTFileGetMaxSize(RTFILE File);
|
---|
[6429] | 592 |
|
---|
| 593 | /**
|
---|
[1] | 594 | * Gets the current file position.
|
---|
| 595 | *
|
---|
| 596 | * @returns File offset.
|
---|
| 597 | * @returns ~0UUL on failure.
|
---|
| 598 | * @param File Handle to the file.
|
---|
| 599 | */
|
---|
| 600 | RTDECL(uint64_t) RTFileTell(RTFILE File);
|
---|
| 601 |
|
---|
| 602 | /**
|
---|
| 603 | * Checks if the supplied handle is valid.
|
---|
| 604 | *
|
---|
| 605 | * @returns true if valid.
|
---|
| 606 | * @returns false if invalid.
|
---|
| 607 | * @param File The file handle
|
---|
| 608 | */
|
---|
[37559] | 609 | RTDECL(bool) RTFileIsValid(RTFILE File);
|
---|
[1] | 610 |
|
---|
| 611 | /**
|
---|
| 612 | * Copies a file.
|
---|
| 613 | *
|
---|
[49033] | 614 | * @returns IPRT status code
|
---|
| 615 | * @retval VERR_ALREADY_EXISTS if the destination file exists.
|
---|
[1] | 616 | *
|
---|
| 617 | * @param pszSrc The path to the source file.
|
---|
| 618 | * @param pszDst The path to the destination file.
|
---|
| 619 | * This file will be created.
|
---|
| 620 | */
|
---|
| 621 | RTDECL(int) RTFileCopy(const char *pszSrc, const char *pszDst);
|
---|
| 622 |
|
---|
| 623 | /**
|
---|
| 624 | * Copies a file given the handles to both files.
|
---|
| 625 | *
|
---|
[49033] | 626 | * @returns IPRT status code
|
---|
[1] | 627 | *
|
---|
| 628 | * @param FileSrc The source file. The file position is unaltered.
|
---|
| 629 | * @param FileDst The destination file.
|
---|
| 630 | * On successful returns the file position is at the end of the file.
|
---|
| 631 | * On failures the file position and size is undefined.
|
---|
| 632 | */
|
---|
| 633 | RTDECL(int) RTFileCopyByHandles(RTFILE FileSrc, RTFILE FileDst);
|
---|
| 634 |
|
---|
[7340] | 635 | /** Flags for RTFileCopyEx().
|
---|
| 636 | * @{ */
|
---|
| 637 | /** Do not use RTFILE_O_DENY_WRITE on the source file to allow for copying files opened for writing. */
|
---|
[7370] | 638 | #define RTFILECOPY_FLAGS_NO_SRC_DENY_WRITE RT_BIT(0)
|
---|
| 639 | /** Do not use RTFILE_O_DENY_WRITE on the target file. */
|
---|
| 640 | #define RTFILECOPY_FLAGS_NO_DST_DENY_WRITE RT_BIT(1)
|
---|
[7371] | 641 | /** Do not use RTFILE_O_DENY_WRITE on either of the two files. */
|
---|
[7370] | 642 | #define RTFILECOPY_FLAGS_NO_DENY_WRITE ( RTFILECOPY_FLAGS_NO_SRC_DENY_WRITE | RTFILECOPY_FLAGS_NO_DST_DENY_WRITE )
|
---|
| 643 | /** */
|
---|
| 644 | #define RTFILECOPY_FLAGS_MASK UINT32_C(0x00000003)
|
---|
[7340] | 645 | /** @} */
|
---|
| 646 |
|
---|
[1] | 647 | /**
|
---|
| 648 | * Copies a file.
|
---|
| 649 | *
|
---|
[49033] | 650 | * @returns IPRT status code
|
---|
| 651 | * @retval VERR_ALREADY_EXISTS if the destination file exists.
|
---|
[1] | 652 | *
|
---|
| 653 | * @param pszSrc The path to the source file.
|
---|
| 654 | * @param pszDst The path to the destination file.
|
---|
| 655 | * This file will be created.
|
---|
[7340] | 656 | * @param fFlags Flags (RTFILECOPY_*).
|
---|
[1] | 657 | * @param pfnProgress Pointer to callback function for reporting progress.
|
---|
[33540] | 658 | * @param pvUser User argument to pass to pfnProgress along with the completion percentage.
|
---|
[1] | 659 | */
|
---|
[7340] | 660 | RTDECL(int) RTFileCopyEx(const char *pszSrc, const char *pszDst, uint32_t fFlags, PFNRTPROGRESS pfnProgress, void *pvUser);
|
---|
[1] | 661 |
|
---|
| 662 | /**
|
---|
| 663 | * Copies a file given the handles to both files and
|
---|
| 664 | * provide progress callbacks.
|
---|
| 665 | *
|
---|
| 666 | * @returns IPRT status code.
|
---|
| 667 | *
|
---|
| 668 | * @param FileSrc The source file. The file position is unaltered.
|
---|
| 669 | * @param FileDst The destination file.
|
---|
| 670 | * On successful returns the file position is at the end of the file.
|
---|
| 671 | * On failures the file position and size is undefined.
|
---|
| 672 | * @param pfnProgress Pointer to callback function for reporting progress.
|
---|
[33540] | 673 | * @param pvUser User argument to pass to pfnProgress along with the completion percentage.
|
---|
[1] | 674 | */
|
---|
| 675 | RTDECL(int) RTFileCopyByHandlesEx(RTFILE FileSrc, RTFILE FileDst, PFNRTPROGRESS pfnProgress, void *pvUser);
|
---|
| 676 |
|
---|
[77797] | 677 | /**
|
---|
| 678 | * Copies a part of a file to another one.
|
---|
| 679 | *
|
---|
| 680 | * @returns IPRT status code.
|
---|
| 681 | * @retval VERR_EOF if @a pcbCopied is NULL and the end-of-file is reached
|
---|
| 682 | * before @a cbToCopy bytes have been copied.
|
---|
| 683 | *
|
---|
| 684 | * @param hFileSrc Handle to the source file. Must be readable.
|
---|
| 685 | * @param offSrc The source file offset.
|
---|
| 686 | * @param hFileDst Handle to the destination file. Must be writable and
|
---|
| 687 | * RTFILE_O_APPEND must be be in effect.
|
---|
| 688 | * @param offDst The destination file offset.
|
---|
| 689 | * @param cbToCopy How many bytes to copy.
|
---|
| 690 | * @param fFlags Reserved for the future, must be zero.
|
---|
| 691 | * @param pcbCopied Where to return the exact number of bytes copied.
|
---|
| 692 | * Optional.
|
---|
| 693 | *
|
---|
| 694 | * @note The file positions of @a hFileSrc and @a hFileDst are undefined
|
---|
| 695 | * upon return of this function.
|
---|
| 696 | *
|
---|
| 697 | * @sa RTFileCopyPartEx.
|
---|
| 698 | */
|
---|
| 699 | RTDECL(int) RTFileCopyPart(RTFILE hFileSrc, RTFOFF offSrc, RTFILE hFileDst, RTFOFF offDst, uint64_t cbToCopy,
|
---|
| 700 | uint32_t fFlags, uint64_t *pcbCopied);
|
---|
[49033] | 701 |
|
---|
[77797] | 702 |
|
---|
| 703 | /** Copy buffer state for RTFileCopyPartEx.
|
---|
| 704 | * @note The fields are considered internal!
|
---|
| 705 | */
|
---|
| 706 | typedef struct RTFILECOPYPARTBUFSTATE
|
---|
| 707 | {
|
---|
| 708 | /** Magic value (RTFILECOPYPARTBUFSTATE_MAGIC).
|
---|
| 709 | * @internal */
|
---|
| 710 | uint32_t uMagic;
|
---|
| 711 | /** Allocation type (internal).
|
---|
| 712 | * @internal */
|
---|
| 713 | int32_t iAllocType;
|
---|
| 714 | /** Buffer pointer.
|
---|
| 715 | * @internal */
|
---|
| 716 | uint8_t *pbBuf;
|
---|
| 717 | /** Buffer size.
|
---|
| 718 | * @internal */
|
---|
| 719 | size_t cbBuf;
|
---|
| 720 | /** Reserved.
|
---|
| 721 | * @internal */
|
---|
| 722 | void *papReserved[3];
|
---|
| 723 | } RTFILECOPYPARTBUFSTATE;
|
---|
| 724 | /** Pointer to copy buffer state for RTFileCopyPartEx(). */
|
---|
| 725 | typedef RTFILECOPYPARTBUFSTATE *PRTFILECOPYPARTBUFSTATE;
|
---|
| 726 | /** Magic value for the RTFileCopyPartEx() buffer state structure (Stephen John Fry). */
|
---|
| 727 | #define RTFILECOPYPARTBUFSTATE_MAGIC UINT32_C(0x19570857)
|
---|
| 728 |
|
---|
[1] | 729 | /**
|
---|
[77797] | 730 | * Prepares buffer state for one or more RTFileCopyPartEx() calls.
|
---|
| 731 | *
|
---|
| 732 | * Caller must call RTFileCopyPartCleanup() after the final RTFileCopyPartEx()
|
---|
| 733 | * call.
|
---|
| 734 | *
|
---|
| 735 | * @returns IPRT status code.
|
---|
| 736 | * @param pBufState The buffer state to prepare.
|
---|
| 737 | * @param cbToCopy The number of bytes we typically to copy in one
|
---|
| 738 | * RTFileCopyPartEx call.
|
---|
| 739 | */
|
---|
| 740 | RTDECL(int) RTFileCopyPartPrep(PRTFILECOPYPARTBUFSTATE pBufState, uint64_t cbToCopy);
|
---|
| 741 |
|
---|
| 742 | /**
|
---|
| 743 | * Cleans up after RTFileCopyPartPrep() once the final RTFileCopyPartEx()
|
---|
| 744 | * call has been made.
|
---|
| 745 | *
|
---|
| 746 | * @param pBufState The buffer state to clean up.
|
---|
| 747 | */
|
---|
| 748 | RTDECL(void) RTFileCopyPartCleanup(PRTFILECOPYPARTBUFSTATE pBufState);
|
---|
| 749 |
|
---|
| 750 | /**
|
---|
| 751 | * Copies a part of a file to another one, extended version.
|
---|
| 752 | *
|
---|
| 753 | * @returns IPRT status code.
|
---|
| 754 | * @retval VERR_EOF if @a pcbCopied is NULL and the end-of-file is reached
|
---|
| 755 | * before @a cbToCopy bytes have been copied.
|
---|
| 756 | *
|
---|
| 757 | * @param hFileSrc Handle to the source file. Must be readable.
|
---|
| 758 | * @param offSrc The source file offset.
|
---|
| 759 | * @param hFileDst Handle to the destination file. Must be writable and
|
---|
| 760 | * RTFILE_O_APPEND must be be in effect.
|
---|
| 761 | * @param offDst The destination file offset.
|
---|
| 762 | * @param cbToCopy How many bytes to copy.
|
---|
| 763 | * @param fFlags Reserved for the future, must be zero.
|
---|
| 764 | * @param pBufState Copy buffer state prepared by RTFileCopyPartPrep().
|
---|
| 765 | * @param pcbCopied Where to return the exact number of bytes copied.
|
---|
| 766 | * Optional.
|
---|
| 767 | *
|
---|
| 768 | * @note The file positions of @a hFileSrc and @a hFileDst are undefined
|
---|
| 769 | * upon return of this function.
|
---|
| 770 | *
|
---|
| 771 | * @sa RTFileCopyPartEx.
|
---|
| 772 | */
|
---|
| 773 | RTDECL(int) RTFileCopyPartEx(RTFILE hFileSrc, RTFOFF offSrc, RTFILE hFileDst, RTFOFF offDst, uint64_t cbToCopy,
|
---|
| 774 | uint32_t fFlags, PRTFILECOPYPARTBUFSTATE pBufState, uint64_t *pcbCopied);
|
---|
| 775 |
|
---|
| 776 | /**
|
---|
[49033] | 777 | * Compares two file given the paths to both files.
|
---|
| 778 | *
|
---|
| 779 | * @returns IPRT status code.
|
---|
| 780 | * @retval VINF_SUCCESS if equal.
|
---|
| 781 | * @retval VERR_NOT_EQUAL if not equal.
|
---|
| 782 | *
|
---|
| 783 | * @param pszFile1 The path to the first file.
|
---|
| 784 | * @param pszFile2 The path to the second file.
|
---|
| 785 | */
|
---|
| 786 | RTDECL(int) RTFileCompare(const char *pszFile1, const char *pszFile2);
|
---|
| 787 |
|
---|
| 788 | /**
|
---|
| 789 | * Compares two file given the handles to both files.
|
---|
| 790 | *
|
---|
| 791 | * @returns IPRT status code.
|
---|
| 792 | * @retval VINF_SUCCESS if equal.
|
---|
| 793 | * @retval VERR_NOT_EQUAL if not equal.
|
---|
| 794 | *
|
---|
| 795 | * @param hFile1 The first file. Undefined return position.
|
---|
| 796 | * @param hFile2 The second file. Undefined return position.
|
---|
| 797 | */
|
---|
| 798 | RTDECL(int) RTFileCompareByHandles(RTFILE hFile1, RTFILE hFile2);
|
---|
| 799 |
|
---|
| 800 | /** Flags for RTFileCompareEx().
|
---|
| 801 | * @{ */
|
---|
| 802 | /** Do not use RTFILE_O_DENY_WRITE on the first file. */
|
---|
| 803 | #define RTFILECOMP_FLAGS_NO_DENY_WRITE_FILE1 RT_BIT(0)
|
---|
| 804 | /** Do not use RTFILE_O_DENY_WRITE on the second file. */
|
---|
| 805 | #define RTFILECOMP_FLAGS_NO_DENY_WRITE_FILE2 RT_BIT(1)
|
---|
| 806 | /** Do not use RTFILE_O_DENY_WRITE on either of the two files. */
|
---|
| 807 | #define RTFILECOMP_FLAGS_NO_DENY_WRITE ( RTFILECOMP_FLAGS_NO_DENY_WRITE_FILE1 | RTFILECOMP_FLAGS_NO_DENY_WRITE_FILE2 )
|
---|
| 808 | /** */
|
---|
| 809 | #define RTFILECOMP_FLAGS_MASK UINT32_C(0x00000003)
|
---|
| 810 | /** @} */
|
---|
| 811 |
|
---|
| 812 | /**
|
---|
| 813 | * Compares two files, extended version with progress callback.
|
---|
| 814 | *
|
---|
| 815 | * @returns IPRT status code.
|
---|
| 816 | * @retval VINF_SUCCESS if equal.
|
---|
| 817 | * @retval VERR_NOT_EQUAL if not equal.
|
---|
| 818 | *
|
---|
| 819 | * @param pszFile1 The path to the source file.
|
---|
| 820 | * @param pszFile2 The path to the destination file. This file will be
|
---|
| 821 | * created.
|
---|
| 822 | * @param fFlags Flags, any of the RTFILECOMP_FLAGS_ \#defines.
|
---|
| 823 | * @param pfnProgress Pointer to callback function for reporting progress.
|
---|
| 824 | * @param pvUser User argument to pass to pfnProgress along with the completion percentage.
|
---|
| 825 | */
|
---|
| 826 | RTDECL(int) RTFileCompareEx(const char *pszFile1, const char *pszFile2, uint32_t fFlags, PFNRTPROGRESS pfnProgress, void *pvUser);
|
---|
| 827 |
|
---|
| 828 | /**
|
---|
| 829 | * Compares two files given their handles, extended version with progress
|
---|
| 830 | * callback.
|
---|
| 831 | *
|
---|
| 832 | * @returns IPRT status code.
|
---|
| 833 | * @retval VINF_SUCCESS if equal.
|
---|
| 834 | * @retval VERR_NOT_EQUAL if not equal.
|
---|
| 835 | *
|
---|
| 836 | * @param hFile1 The first file. Undefined return position.
|
---|
| 837 | * @param hFile2 The second file. Undefined return position.
|
---|
| 838 | *
|
---|
| 839 | * @param fFlags Flags, any of the RTFILECOMP_FLAGS_ \#defines, flags
|
---|
| 840 | * related to opening of the files will be ignored.
|
---|
| 841 | * @param pfnProgress Pointer to callback function for reporting progress.
|
---|
| 842 | * @param pvUser User argument to pass to pfnProgress along with the completion percentage.
|
---|
| 843 | */
|
---|
| 844 | RTDECL(int) RTFileCompareByHandlesEx(RTFILE hFile1, RTFILE hFile2, uint32_t fFlags, PFNRTPROGRESS pfnProgress, void *pvUser);
|
---|
| 845 |
|
---|
| 846 | /**
|
---|
[1] | 847 | * Renames a file.
|
---|
| 848 | *
|
---|
| 849 | * Identical to RTPathRename except that it will ensure that the source is not a directory.
|
---|
| 850 | *
|
---|
| 851 | * @returns IPRT status code.
|
---|
| 852 | * @returns VERR_ALREADY_EXISTS if the destination file exists.
|
---|
| 853 | *
|
---|
| 854 | * @param pszSrc The path to the source file.
|
---|
| 855 | * @param pszDst The path to the destination file.
|
---|
| 856 | * This file will be created.
|
---|
| 857 | * @param fRename See RTPathRename.
|
---|
| 858 | */
|
---|
| 859 | RTDECL(int) RTFileRename(const char *pszSrc, const char *pszDst, unsigned fRename);
|
---|
| 860 |
|
---|
| 861 |
|
---|
| 862 | /** @name RTFileMove flags (bit masks).
|
---|
| 863 | * @{ */
|
---|
| 864 | /** Replace destination file if present. */
|
---|
[39612] | 865 | #define RTFILEMOVE_FLAGS_REPLACE 0x1
|
---|
[39641] | 866 | /** Don't allow symbolic links as part of the path.
|
---|
| 867 | * @remarks this flag is currently not implemented and will be ignored. */
|
---|
[39612] | 868 | #define RTFILEMOVE_FLAGS_NO_SYMLINKS 0x2
|
---|
[1] | 869 | /** @} */
|
---|
| 870 |
|
---|
| 871 | /**
|
---|
[47762] | 872 | * Converts file opening modes (used by fopen, for example) to IPRT
|
---|
| 873 | * compatible flags, which then can be used with RTFileOpen* APIs.
|
---|
| 874 | *
|
---|
[62559] | 875 | * @note Handling sharing modes is not supported yet, so RTFILE_O_DENY_NONE
|
---|
| 876 | * will always be used.
|
---|
[47783] | 877 | *
|
---|
[47762] | 878 | * @return IPRT status code.
|
---|
| 879 | * @param pszMode Mode string to convert.
|
---|
[62559] | 880 | * @param pfMode Where to store the converted mode flags on
|
---|
| 881 | * success.
|
---|
[47762] | 882 | */
|
---|
[62559] | 883 | RTDECL(int) RTFileModeToFlags(const char *pszMode, uint64_t *pfMode);
|
---|
[47762] | 884 |
|
---|
| 885 | /**
|
---|
| 886 | * Converts file opening modes along with a separate disposition command
|
---|
| 887 | * to IPRT compatible flags, which then can be used with RTFileOpen* APIs.
|
---|
| 888 | *
|
---|
| 889 | * Access modes:
|
---|
[66592] | 890 | * - "r": Opens a file for reading.
|
---|
| 891 | * - "r+": Opens a file for reading and writing.
|
---|
| 892 | * - "w": Opens a file for writing.
|
---|
| 893 | * - "w+": Opens a file for writing and reading.
|
---|
[47762] | 894 | *
|
---|
| 895 | * Disposition modes:
|
---|
[66592] | 896 | * - "oe", "open": Opens an existing file or fail if it does not exist.
|
---|
| 897 | * - "oc", "open-create": Opens an existing file or create it if it does
|
---|
| 898 | * not exist.
|
---|
| 899 | * - "oa", "open-append": Opens an existing file and places the file
|
---|
| 900 | * pointer at the end of the file, if opened with write access. Create
|
---|
| 901 | * the file if it does not exist.
|
---|
| 902 | * - "ot", "open-truncate": Opens and truncate an existing file or fail if
|
---|
| 903 | * it does not exist.
|
---|
| 904 | * - "ce", "create": Creates a new file if it does not exist. Fail if
|
---|
| 905 | * exist.
|
---|
| 906 | * - "ca", "create-replace": Creates a new file, always. Overwrites an
|
---|
| 907 | * existing file.
|
---|
[47762] | 908 | *
|
---|
[66592] | 909 | * Sharing mode:
|
---|
| 910 | * - "nr": Deny read.
|
---|
| 911 | * - "nw": Deny write.
|
---|
| 912 | * - "nrw": Deny both read and write.
|
---|
| 913 | * - "d": Allow delete.
|
---|
| 914 | * - "", NULL: Deny none, except delete.
|
---|
[47762] | 915 | *
|
---|
| 916 | * @return IPRT status code.
|
---|
[66592] | 917 | * @param pszAccess Access mode string to convert.
|
---|
| 918 | * @param pszDisposition Disposition mode string to convert.
|
---|
| 919 | * @param pszSharing Sharing mode string to convert.
|
---|
| 920 | * @param pfMode Where to store the converted mode flags on success.
|
---|
[47762] | 921 | */
|
---|
[62559] | 922 | RTDECL(int) RTFileModeToFlagsEx(const char *pszAccess, const char *pszDisposition, const char *pszSharing, uint64_t *pfMode);
|
---|
[47762] | 923 |
|
---|
| 924 | /**
|
---|
[1] | 925 | * Moves a file.
|
---|
| 926 | *
|
---|
| 927 | * RTFileMove differs from RTFileRename in that it works across volumes.
|
---|
| 928 | *
|
---|
| 929 | * @returns IPRT status code.
|
---|
| 930 | * @returns VERR_ALREADY_EXISTS if the destination file exists.
|
---|
| 931 | *
|
---|
| 932 | * @param pszSrc The path to the source file.
|
---|
| 933 | * @param pszDst The path to the destination file.
|
---|
| 934 | * This file will be created.
|
---|
| 935 | * @param fMove A combination of the RTFILEMOVE_* flags.
|
---|
| 936 | */
|
---|
| 937 | RTDECL(int) RTFileMove(const char *pszSrc, const char *pszDst, unsigned fMove);
|
---|
| 938 |
|
---|
| 939 |
|
---|
[42712] | 940 | /**
|
---|
| 941 | * Creates a new file with a unique name using the given template.
|
---|
| 942 | *
|
---|
| 943 | * One or more trailing X'es in the template will be replaced by random alpha
|
---|
| 944 | * numeric characters until a RTFileOpen with RTFILE_O_CREATE succeeds or we
|
---|
| 945 | * run out of patience.
|
---|
| 946 | * For instance:
|
---|
| 947 | * "/tmp/myprog-XXXXXX"
|
---|
| 948 | *
|
---|
| 949 | * As an alternative to trailing X'es, it is possible to put 3 or more X'es
|
---|
| 950 | * somewhere inside the file name. In the following string only the last
|
---|
| 951 | * bunch of X'es will be modified:
|
---|
| 952 | * "/tmp/myprog-XXX-XXX.tmp"
|
---|
| 953 | *
|
---|
| 954 | * @returns iprt status code.
|
---|
| 955 | * @param pszTemplate The file name template on input. The actual file
|
---|
| 956 | * name on success. Empty string on failure.
|
---|
| 957 | * @param fMode The mode to create the file with. Use 0600 unless
|
---|
| 958 | * you have reason not to.
|
---|
| 959 | */
|
---|
| 960 | RTDECL(int) RTFileCreateTemp(char *pszTemplate, RTFMODE fMode);
|
---|
| 961 |
|
---|
| 962 | /**
|
---|
| 963 | * Secure version of @a RTFileCreateTemp with a fixed mode of 0600.
|
---|
| 964 | *
|
---|
| 965 | * This function behaves in the same way as @a RTFileCreateTemp with two
|
---|
| 966 | * additional points. Firstly the mode is fixed to 0600. Secondly it will
|
---|
| 967 | * fail if it is not possible to perform the operation securely. Possible
|
---|
| 968 | * reasons include that the file could be removed by another unprivileged
|
---|
| 969 | * user before it is used (e.g. if is created in a non-sticky /tmp directory)
|
---|
| 970 | * or that the path contains symbolic links which another unprivileged user
|
---|
| 971 | * could manipulate; however the exact criteria will be specified on a
|
---|
| 972 | * platform-by-platform basis as platform support is added.
|
---|
| 973 | * @see RTPathIsSecure for the current list of criteria.
|
---|
| 974 | * @returns iprt status code.
|
---|
| 975 | * @returns VERR_NOT_SUPPORTED if the interface can not be supported on the
|
---|
| 976 | * current platform at this time.
|
---|
| 977 | * @returns VERR_INSECURE if the file could not be created securely.
|
---|
| 978 | * @param pszTemplate The file name template on input. The actual
|
---|
| 979 | * file name on success. Empty string on failure.
|
---|
| 980 | */
|
---|
| 981 | RTDECL(int) RTFileCreateTempSecure(char *pszTemplate);
|
---|
| 982 |
|
---|
[57613] | 983 | /**
|
---|
| 984 | * Opens a new file with a unique name in the temp directory.
|
---|
| 985 | *
|
---|
[57926] | 986 | * Unlike the other temp file creation APIs, this does not allow you any control
|
---|
| 987 | * over the name. Nor do you have to figure out where the temporary directory
|
---|
| 988 | * is.
|
---|
| 989 | *
|
---|
[57613] | 990 | * @returns iprt status code.
|
---|
[57926] | 991 | * @param phFile Where to return the handle to the file.
|
---|
| 992 | * @param pszFilename Where to return the name (+path) of the file .
|
---|
| 993 | * @param cbFilename The size of the buffer @a pszFilename points to.
|
---|
| 994 | * @param fOpen The RTFILE_O_XXX flags to open the file with.
|
---|
[57613] | 995 | *
|
---|
| 996 | * @remarks If actual control over the filename or location is required, we'll
|
---|
| 997 | * create an extended edition of this API.
|
---|
| 998 | */
|
---|
[57926] | 999 | RTDECL(int) RTFileOpenTemp(PRTFILE phFile, char *pszFilename, size_t cbFilename, uint64_t fOpen);
|
---|
[42712] | 1000 |
|
---|
[57613] | 1001 |
|
---|
[1] | 1002 | /** @page pg_rt_filelock RT File locking API description
|
---|
| 1003 | *
|
---|
| 1004 | * File locking general rules:
|
---|
| 1005 | *
|
---|
| 1006 | * Region to lock or unlock can be located beyond the end of file, this can be used for
|
---|
| 1007 | * growing files.
|
---|
| 1008 | * Read (or Shared) locks can be acquired held by an unlimited number of processes at the
|
---|
| 1009 | * same time, but a Write (or Exclusive) lock can only be acquired by one process, and
|
---|
| 1010 | * cannot coexist with a Shared lock. To acquire a Read lock, a process must wait until
|
---|
| 1011 | * there are no processes holding any Write locks. To acquire a Write lock, a process must
|
---|
| 1012 | * wait until there are no processes holding either kind of lock.
|
---|
| 1013 | * By default, RTFileLock and RTFileChangeLock calls returns error immediately if the lock
|
---|
| 1014 | * can't be acquired due to conflict with other locks, however they can be called in wait mode.
|
---|
| 1015 | *
|
---|
| 1016 | * Differences in implementation:
|
---|
| 1017 | *
|
---|
| 1018 | * Win32, OS/2: Locking is mandatory, since locks are enforced by the operating system.
|
---|
| 1019 | * I.e. when file region is locked in Read mode, any write in it will fail; in case of Write
|
---|
[33540] | 1020 | * lock - region can be read and writed only by lock's owner.
|
---|
[1] | 1021 | *
|
---|
| 1022 | * Win32: File size change (RTFileSetSize) is not controlled by locking at all (!) in the
|
---|
| 1023 | * operation system. Also see comments to RTFileChangeLock API call.
|
---|
| 1024 | *
|
---|
| 1025 | * Linux/Posix: By default locks in Unixes are advisory. This means that cooperating processes
|
---|
[14872] | 1026 | * may use locks to coordinate access to a file between themselves, but programs are also free
|
---|
[1] | 1027 | * to ignore locks and access the file in any way they choose to.
|
---|
| 1028 | *
|
---|
| 1029 | * Additional reading:
|
---|
| 1030 | * http://en.wikipedia.org/wiki/File_locking
|
---|
| 1031 | * http://unixhelp.ed.ac.uk/CGI/man-cgi?fcntl+2
|
---|
| 1032 | * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/lockfileex.asp
|
---|
| 1033 | */
|
---|
| 1034 |
|
---|
| 1035 | /** @name Lock flags (bit masks).
|
---|
| 1036 | * @{ */
|
---|
| 1037 | /** Read access, can be shared with others. */
|
---|
| 1038 | #define RTFILE_LOCK_READ 0x00
|
---|
| 1039 | /** Write access, one at a time. */
|
---|
| 1040 | #define RTFILE_LOCK_WRITE 0x01
|
---|
| 1041 | /** Don't wait for other locks to be released. */
|
---|
| 1042 | #define RTFILE_LOCK_IMMEDIATELY 0x00
|
---|
| 1043 | /** Wait till conflicting locks have been released. */
|
---|
| 1044 | #define RTFILE_LOCK_WAIT 0x02
|
---|
| 1045 | /** Valid flags mask */
|
---|
| 1046 | #define RTFILE_LOCK_MASK 0x03
|
---|
| 1047 | /** @} */
|
---|
| 1048 |
|
---|
| 1049 |
|
---|
| 1050 | /**
|
---|
| 1051 | * Locks a region of file for read (shared) or write (exclusive) access.
|
---|
| 1052 | *
|
---|
| 1053 | * @returns iprt status code.
|
---|
| 1054 | * @returns VERR_FILE_LOCK_VIOLATION if lock can't be acquired.
|
---|
| 1055 | * @param File Handle to the file.
|
---|
| 1056 | * @param fLock Lock method and flags, see RTFILE_LOCK_* defines.
|
---|
| 1057 | * @param offLock Offset of lock start.
|
---|
| 1058 | * @param cbLock Length of region to lock, may overlap the end of file.
|
---|
| 1059 | */
|
---|
[37559] | 1060 | RTDECL(int) RTFileLock(RTFILE File, unsigned fLock, int64_t offLock, uint64_t cbLock);
|
---|
[1] | 1061 |
|
---|
| 1062 | /**
|
---|
| 1063 | * Changes a lock type from read to write or from write to read.
|
---|
| 1064 | * The region to type change must correspond exactly to an existing locked region.
|
---|
| 1065 | * If change can't be done due to locking conflict and non-blocking mode is used, error is
|
---|
| 1066 | * returned and lock keeps its state (see next warning).
|
---|
| 1067 | *
|
---|
| 1068 | * WARNING: win32 implementation of this call is not atomic, it transforms to a pair of
|
---|
| 1069 | * calls RTFileUnlock and RTFileLock. Potentially the previously acquired lock can be
|
---|
| 1070 | * lost, i.e. function is called in non-blocking mode, previous lock is freed, new lock can't
|
---|
| 1071 | * be acquired, and old lock (previous state) can't be acquired back too. This situation
|
---|
| 1072 | * may occurs _only_ if the other process is acquiring a _write_ lock in blocking mode or
|
---|
| 1073 | * in race condition with the current call.
|
---|
| 1074 | * In this very bad case special error code VERR_FILE_LOCK_LOST will be returned.
|
---|
| 1075 | *
|
---|
| 1076 | * @returns iprt status code.
|
---|
| 1077 | * @returns VERR_FILE_NOT_LOCKED if region was not locked.
|
---|
| 1078 | * @returns VERR_FILE_LOCK_VIOLATION if lock type can't be changed, lock remains its type.
|
---|
| 1079 | * @returns VERR_FILE_LOCK_LOST if lock was lost, we haven't this lock anymore :(
|
---|
| 1080 | * @param File Handle to the file.
|
---|
| 1081 | * @param fLock Lock method and flags, see RTFILE_LOCK_* defines.
|
---|
| 1082 | * @param offLock Offset of lock start.
|
---|
| 1083 | * @param cbLock Length of region to lock, may overlap the end of file.
|
---|
| 1084 | */
|
---|
[37559] | 1085 | RTDECL(int) RTFileChangeLock(RTFILE File, unsigned fLock, int64_t offLock, uint64_t cbLock);
|
---|
[1] | 1086 |
|
---|
| 1087 | /**
|
---|
| 1088 | * Unlocks previously locked region of file.
|
---|
| 1089 | * The region to unlock must correspond exactly to an existing locked region.
|
---|
| 1090 | *
|
---|
| 1091 | * @returns iprt status code.
|
---|
| 1092 | * @returns VERR_FILE_NOT_LOCKED if region was not locked.
|
---|
| 1093 | * @param File Handle to the file.
|
---|
| 1094 | * @param offLock Offset of lock start.
|
---|
| 1095 | * @param cbLock Length of region to unlock, may overlap the end of file.
|
---|
| 1096 | */
|
---|
[37559] | 1097 | RTDECL(int) RTFileUnlock(RTFILE File, int64_t offLock, uint64_t cbLock);
|
---|
[1] | 1098 |
|
---|
| 1099 |
|
---|
| 1100 | /**
|
---|
| 1101 | * Query information about an open file.
|
---|
| 1102 | *
|
---|
| 1103 | * @returns iprt status code.
|
---|
| 1104 | *
|
---|
| 1105 | * @param File Handle to the file.
|
---|
| 1106 | * @param pObjInfo Object information structure to be filled on successful return.
|
---|
| 1107 | * @param enmAdditionalAttribs Which set of additional attributes to request.
|
---|
| 1108 | * Use RTFSOBJATTRADD_NOTHING if this doesn't matter.
|
---|
| 1109 | */
|
---|
[37559] | 1110 | RTDECL(int) RTFileQueryInfo(RTFILE File, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAdditionalAttribs);
|
---|
[1] | 1111 |
|
---|
| 1112 | /**
|
---|
| 1113 | * Changes one or more of the timestamps associated of file system object.
|
---|
| 1114 | *
|
---|
| 1115 | * @returns iprt status code.
|
---|
[24889] | 1116 | * @retval VERR_NOT_SUPPORTED is returned if the operation isn't supported by
|
---|
| 1117 | * the OS.
|
---|
[1] | 1118 | *
|
---|
| 1119 | * @param File Handle to the file.
|
---|
| 1120 | * @param pAccessTime Pointer to the new access time. NULL if not to be changed.
|
---|
| 1121 | * @param pModificationTime Pointer to the new modifcation time. NULL if not to be changed.
|
---|
| 1122 | * @param pChangeTime Pointer to the new change time. NULL if not to be changed.
|
---|
| 1123 | * @param pBirthTime Pointer to the new time of birth. NULL if not to be changed.
|
---|
| 1124 | *
|
---|
| 1125 | * @remark The file system might not implement all these time attributes,
|
---|
| 1126 | * the API will ignore the ones which aren't supported.
|
---|
| 1127 | *
|
---|
| 1128 | * @remark The file system might not implement the time resolution
|
---|
| 1129 | * employed by this interface, the time will be chopped to fit.
|
---|
| 1130 | *
|
---|
| 1131 | * @remark The file system may update the change time even if it's
|
---|
| 1132 | * not specified.
|
---|
| 1133 | *
|
---|
| 1134 | * @remark POSIX can only set Access & Modification and will always set both.
|
---|
| 1135 | */
|
---|
[37559] | 1136 | RTDECL(int) RTFileSetTimes(RTFILE File, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
|
---|
| 1137 | PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime);
|
---|
[1] | 1138 |
|
---|
| 1139 | /**
|
---|
| 1140 | * Gets one or more of the timestamps associated of file system object.
|
---|
| 1141 | *
|
---|
| 1142 | * @returns iprt status code.
|
---|
| 1143 | * @param File Handle to the file.
|
---|
| 1144 | * @param pAccessTime Where to store the access time. NULL is ok.
|
---|
| 1145 | * @param pModificationTime Where to store the modifcation time. NULL is ok.
|
---|
| 1146 | * @param pChangeTime Where to store the change time. NULL is ok.
|
---|
| 1147 | * @param pBirthTime Where to store the time of birth. NULL is ok.
|
---|
| 1148 | *
|
---|
| 1149 | * @remark This is wrapper around RTFileQueryInfo() and exists to complement RTFileSetTimes().
|
---|
| 1150 | */
|
---|
[37559] | 1151 | RTDECL(int) RTFileGetTimes(RTFILE File, PRTTIMESPEC pAccessTime, PRTTIMESPEC pModificationTime,
|
---|
| 1152 | PRTTIMESPEC pChangeTime, PRTTIMESPEC pBirthTime);
|
---|
[1] | 1153 |
|
---|
| 1154 | /**
|
---|
| 1155 | * Changes the mode flags of an open file.
|
---|
| 1156 | *
|
---|
| 1157 | * The API requires at least one of the mode flag sets (Unix/Dos) to
|
---|
| 1158 | * be set. The type is ignored.
|
---|
| 1159 | *
|
---|
| 1160 | * @returns iprt status code.
|
---|
| 1161 | * @param File Handle to the file.
|
---|
| 1162 | * @param fMode The new file mode, see @ref grp_rt_fs for details.
|
---|
| 1163 | */
|
---|
[37559] | 1164 | RTDECL(int) RTFileSetMode(RTFILE File, RTFMODE fMode);
|
---|
[1] | 1165 |
|
---|
| 1166 | /**
|
---|
| 1167 | * Gets the mode flags of an open file.
|
---|
| 1168 | *
|
---|
| 1169 | * @returns iprt status code.
|
---|
| 1170 | * @param File Handle to the file.
|
---|
| 1171 | * @param pfMode Where to store the file mode, see @ref grp_rt_fs for details.
|
---|
| 1172 | *
|
---|
| 1173 | * @remark This is wrapper around RTFileQueryInfo()
|
---|
| 1174 | * and exists to complement RTFileSetMode().
|
---|
| 1175 | */
|
---|
[37559] | 1176 | RTDECL(int) RTFileGetMode(RTFILE File, uint32_t *pfMode);
|
---|
[1] | 1177 |
|
---|
| 1178 | /**
|
---|
| 1179 | * Changes the owner and/or group of an open file.
|
---|
| 1180 | *
|
---|
| 1181 | * @returns iprt status code.
|
---|
| 1182 | * @param File Handle to the file.
|
---|
[34230] | 1183 | * @param uid The new file owner user id. Pass NIL_RTUID to leave
|
---|
| 1184 | * this unchanged.
|
---|
| 1185 | * @param gid The new group id. Pass NIL_RTGID to leave this
|
---|
| 1186 | * unchanged.
|
---|
[1] | 1187 | */
|
---|
[37559] | 1188 | RTDECL(int) RTFileSetOwner(RTFILE File, uint32_t uid, uint32_t gid);
|
---|
[1] | 1189 |
|
---|
| 1190 | /**
|
---|
| 1191 | * Gets the owner and/or group of an open file.
|
---|
| 1192 | *
|
---|
| 1193 | * @returns iprt status code.
|
---|
| 1194 | * @param File Handle to the file.
|
---|
| 1195 | * @param pUid Where to store the owner user id. NULL is ok.
|
---|
| 1196 | * @param pGid Where to store the group id. NULL is ok.
|
---|
| 1197 | *
|
---|
| 1198 | * @remark This is wrapper around RTFileQueryInfo() and exists to complement RTFileGetOwner().
|
---|
| 1199 | */
|
---|
[37559] | 1200 | RTDECL(int) RTFileGetOwner(RTFILE File, uint32_t *pUid, uint32_t *pGid);
|
---|
[1] | 1201 |
|
---|
| 1202 | /**
|
---|
| 1203 | * Executes an IOCTL on a file descriptor.
|
---|
| 1204 | *
|
---|
| 1205 | * This function is currently only available in L4 and posix environments.
|
---|
| 1206 | * Attemps at calling it from code shared with any other platforms will break things!
|
---|
| 1207 | *
|
---|
| 1208 | * The rational for defining this API is to simplify L4 porting of audio drivers,
|
---|
| 1209 | * and to remove some of the assumptions on RTFILE being a file descriptor on
|
---|
| 1210 | * platforms using the posix file implementation.
|
---|
| 1211 | *
|
---|
| 1212 | * @returns iprt status code.
|
---|
| 1213 | * @param File Handle to the file.
|
---|
[57926] | 1214 | * @param ulRequest IOCTL request to carry out.
|
---|
[1] | 1215 | * @param pvData IOCTL data.
|
---|
| 1216 | * @param cbData Size of the IOCTL data.
|
---|
| 1217 | * @param piRet Return value of the IOCTL request.
|
---|
| 1218 | */
|
---|
[37559] | 1219 | RTDECL(int) RTFileIoCtl(RTFILE File, unsigned long ulRequest, void *pvData, unsigned cbData, int *piRet);
|
---|
[1] | 1220 |
|
---|
[8925] | 1221 | /**
|
---|
[24889] | 1222 | * Query the sizes of a filesystem.
|
---|
| 1223 | *
|
---|
| 1224 | * @returns iprt status code.
|
---|
| 1225 | * @retval VERR_NOT_SUPPORTED is returned if the operation isn't supported by
|
---|
| 1226 | * the OS.
|
---|
| 1227 | *
|
---|
| 1228 | * @param hFile The file handle.
|
---|
| 1229 | * @param pcbTotal Where to store the total filesystem space. (Optional)
|
---|
| 1230 | * @param pcbFree Where to store the remaining free space in the filesystem. (Optional)
|
---|
| 1231 | * @param pcbBlock Where to store the block size. (Optional)
|
---|
| 1232 | * @param pcbSector Where to store the sector size. (Optional)
|
---|
| 1233 | *
|
---|
| 1234 | * @sa RTFsQuerySizes
|
---|
| 1235 | */
|
---|
[37559] | 1236 | RTDECL(int) RTFileQueryFsSizes(RTFILE hFile, PRTFOFF pcbTotal, RTFOFF *pcbFree,
|
---|
| 1237 | uint32_t *pcbBlock, uint32_t *pcbSector);
|
---|
[24889] | 1238 |
|
---|
| 1239 | /**
|
---|
[8925] | 1240 | * Reads the file into memory.
|
---|
| 1241 | *
|
---|
| 1242 | * The caller must free the memory using RTFileReadAllFree().
|
---|
| 1243 | *
|
---|
| 1244 | * @returns IPRT status code.
|
---|
| 1245 | * @param pszFilename The name of the file.
|
---|
| 1246 | * @param ppvFile Where to store the pointer to the memory on successful return.
|
---|
[21801] | 1247 | * @param pcbFile Where to store the size of the returned memory.
|
---|
[8925] | 1248 | *
|
---|
| 1249 | * @remarks Note that this function may be implemented using memory mapping, which means
|
---|
| 1250 | * that the file may remain open until RTFileReadAllFree() is called. It also
|
---|
| 1251 | * means that the return memory may reflect the state of the file when it's
|
---|
| 1252 | * accessed instead of when this call was done. So, in short, don't use this
|
---|
| 1253 | * API for volatile files, then rather use the extended variant with a
|
---|
[25922] | 1254 | * yet-to-be-defined flag.
|
---|
[8925] | 1255 | */
|
---|
| 1256 | RTDECL(int) RTFileReadAll(const char *pszFilename, void **ppvFile, size_t *pcbFile);
|
---|
| 1257 |
|
---|
| 1258 | /**
|
---|
| 1259 | * Reads the file into memory.
|
---|
| 1260 | *
|
---|
| 1261 | * The caller must free the memory using RTFileReadAllFree().
|
---|
| 1262 | *
|
---|
| 1263 | * @returns IPRT status code.
|
---|
| 1264 | * @param pszFilename The name of the file.
|
---|
| 1265 | * @param off The offset to start reading at.
|
---|
| 1266 | * @param cbMax The maximum number of bytes to read into memory. Specify RTFOFF_MAX
|
---|
| 1267 | * to read to the end of the file.
|
---|
[19350] | 1268 | * @param fFlags See RTFILE_RDALL_*.
|
---|
[8925] | 1269 | * @param ppvFile Where to store the pointer to the memory on successful return.
|
---|
[21801] | 1270 | * @param pcbFile Where to store the size of the returned memory.
|
---|
[8925] | 1271 | *
|
---|
| 1272 | * @remarks See the remarks for RTFileReadAll.
|
---|
| 1273 | */
|
---|
| 1274 | RTDECL(int) RTFileReadAllEx(const char *pszFilename, RTFOFF off, RTFOFF cbMax, uint32_t fFlags, void **ppvFile, size_t *pcbFile);
|
---|
| 1275 |
|
---|
| 1276 | /**
|
---|
| 1277 | * Reads the file into memory.
|
---|
| 1278 | *
|
---|
| 1279 | * The caller must free the memory using RTFileReadAllFree().
|
---|
| 1280 | *
|
---|
| 1281 | * @returns IPRT status code.
|
---|
| 1282 | * @param File The handle to the file.
|
---|
| 1283 | * @param ppvFile Where to store the pointer to the memory on successful return.
|
---|
[21801] | 1284 | * @param pcbFile Where to store the size of the returned memory.
|
---|
[8925] | 1285 | *
|
---|
| 1286 | * @remarks See the remarks for RTFileReadAll.
|
---|
| 1287 | */
|
---|
| 1288 | RTDECL(int) RTFileReadAllByHandle(RTFILE File, void **ppvFile, size_t *pcbFile);
|
---|
| 1289 |
|
---|
| 1290 | /**
|
---|
| 1291 | * Reads the file into memory.
|
---|
| 1292 | *
|
---|
| 1293 | * The caller must free the memory using RTFileReadAllFree().
|
---|
| 1294 | *
|
---|
| 1295 | * @returns IPRT status code.
|
---|
| 1296 | * @param File The handle to the file.
|
---|
| 1297 | * @param off The offset to start reading at.
|
---|
| 1298 | * @param cbMax The maximum number of bytes to read into memory. Specify RTFOFF_MAX
|
---|
| 1299 | * to read to the end of the file.
|
---|
[19350] | 1300 | * @param fFlags See RTFILE_RDALL_*.
|
---|
[8925] | 1301 | * @param ppvFile Where to store the pointer to the memory on successful return.
|
---|
[21801] | 1302 | * @param pcbFile Where to store the size of the returned memory.
|
---|
[8925] | 1303 | *
|
---|
| 1304 | * @remarks See the remarks for RTFileReadAll.
|
---|
| 1305 | */
|
---|
| 1306 | RTDECL(int) RTFileReadAllByHandleEx(RTFILE File, RTFOFF off, RTFOFF cbMax, uint32_t fFlags, void **ppvFile, size_t *pcbFile);
|
---|
| 1307 |
|
---|
| 1308 | /**
|
---|
| 1309 | * Frees the memory returned by one of the RTFileReadAll(), RTFileReadAllEx(),
|
---|
| 1310 | * RTFileReadAllByHandle() and RTFileReadAllByHandleEx() functions.
|
---|
| 1311 | *
|
---|
| 1312 | * @param pvFile Pointer to the memory.
|
---|
| 1313 | * @param cbFile The size of the memory.
|
---|
| 1314 | */
|
---|
[16997] | 1315 | RTDECL(void) RTFileReadAllFree(void *pvFile, size_t cbFile);
|
---|
[8925] | 1316 |
|
---|
[19350] | 1317 | /** @name RTFileReadAllEx and RTFileReadAllHandleEx flags
|
---|
| 1318 | * The open flags are ignored by RTFileReadAllHandleEx.
|
---|
| 1319 | * @{ */
|
---|
| 1320 | #define RTFILE_RDALL_O_DENY_NONE RTFILE_O_DENY_NONE
|
---|
| 1321 | #define RTFILE_RDALL_O_DENY_READ RTFILE_O_DENY_READ
|
---|
| 1322 | #define RTFILE_RDALL_O_DENY_WRITE RTFILE_O_DENY_WRITE
|
---|
| 1323 | #define RTFILE_RDALL_O_DENY_READWRITE RTFILE_O_DENY_READWRITE
|
---|
| 1324 | #define RTFILE_RDALL_O_DENY_ALL RTFILE_O_DENY_ALL
|
---|
| 1325 | #define RTFILE_RDALL_O_DENY_NOT_DELETE RTFILE_O_DENY_NOT_DELETE
|
---|
| 1326 | #define RTFILE_RDALL_O_DENY_MASK RTFILE_O_DENY_MASK
|
---|
[75045] | 1327 | /** Fail with VERR_OUT_OF_RANGE if the file size exceeds the specified maximum
|
---|
| 1328 | * size. The default behavior is to cap the size at cbMax. */
|
---|
| 1329 | #define RTFILE_RDALL_F_FAIL_ON_MAX_SIZE RT_BIT_32(30)
|
---|
[68183] | 1330 | /** Add a trailing zero byte to facilitate reading text files. */
|
---|
| 1331 | #define RTFILE_RDALL_F_TRAILING_ZERO_BYTE RT_BIT_32(31)
|
---|
[19350] | 1332 | /** Mask of valid flags. */
|
---|
[75045] | 1333 | #define RTFILE_RDALL_VALID_MASK (RTFILE_RDALL_O_DENY_MASK | UINT32_C(0xc0000000))
|
---|
[19350] | 1334 | /** @} */
|
---|
[18961] | 1335 |
|
---|
[59459] | 1336 | /**
|
---|
| 1337 | * Sets the current size of the file ensuring that all required blocks
|
---|
| 1338 | * are allocated on the underlying medium.
|
---|
| 1339 | *
|
---|
| 1340 | * @returns IPRT status code.
|
---|
[69977] | 1341 | * @retval VERR_NOT_SUPPORTED if either this operation is not supported on the
|
---|
| 1342 | * current host in an efficient manner or the given combination of
|
---|
| 1343 | * flags is not supported.
|
---|
[59459] | 1344 | * @param hFile The handle to the file.
|
---|
| 1345 | * @param cbSize The new size of the file to allocate.
|
---|
| 1346 | * @param fFlags Combination of RTFILE_ALLOC_SIZE_F_*
|
---|
| 1347 | */
|
---|
| 1348 | RTDECL(int) RTFileSetAllocationSize(RTFILE hFile, uint64_t cbSize, uint32_t fFlags);
|
---|
| 1349 |
|
---|
[69977] | 1350 | /** @name RTFILE_ALLOC_SIZE_F_XXX - RTFileSetAllocationSize flags
|
---|
| 1351 | * @{ */
|
---|
| 1352 | /** Default flags. */
|
---|
| 1353 | #define RTFILE_ALLOC_SIZE_F_DEFAULT 0
|
---|
| 1354 | /** Do not change the size of the file if the given size is bigger than the
|
---|
| 1355 | * current file size.
|
---|
| 1356 | *
|
---|
| 1357 | * Useful to preallocate blocks beyond the current size for appending data in an
|
---|
| 1358 | * efficient manner. Might not be supported on all hosts and will return
|
---|
| 1359 | * VERR_NOT_SUPPORTED in that case. */
|
---|
| 1360 | #define RTFILE_ALLOC_SIZE_F_KEEP_SIZE RT_BIT(0)
|
---|
| 1361 | /** Mask of valid flags. */
|
---|
| 1362 | #define RTFILE_ALLOC_SIZE_F_VALID (RTFILE_ALLOC_SIZE_F_KEEP_SIZE)
|
---|
| 1363 | /** @} */
|
---|
| 1364 |
|
---|
| 1365 |
|
---|
[37559] | 1366 | #ifdef IN_RING3
|
---|
| 1367 |
|
---|
[18909] | 1368 | /** @page pg_rt_asyncio RT File async I/O API
|
---|
| 1369 | *
|
---|
[19125] | 1370 | * File operations are usually blocking the calling thread until
|
---|
| 1371 | * they completed making it impossible to let the thread do anything
|
---|
[33540] | 1372 | * else in-between.
|
---|
[19125] | 1373 | * The RT File async I/O API provides an easy and efficient way to
|
---|
| 1374 | * access files asynchronously using the native facilities provided
|
---|
| 1375 | * by each operating system.
|
---|
| 1376 | *
|
---|
[19562] | 1377 | * @section sec_rt_asyncio_objects Objects
|
---|
| 1378 | *
|
---|
[19125] | 1379 | * There are two objects used in this API.
|
---|
| 1380 | * The first object is the request. A request contains every information
|
---|
| 1381 | * needed two complete the file operation successfully like the start offset
|
---|
| 1382 | * and pointer to the source or destination buffer.
|
---|
| 1383 | * Requests are created with RTFileAioReqCreate() and destroyed with
|
---|
| 1384 | * RTFileAioReqDestroy().
|
---|
| 1385 | * Because creating a request may require allocating various operating
|
---|
[33540] | 1386 | * system dependent resources and may be quite expensive it is possible
|
---|
[19125] | 1387 | * to use a request more than once to save CPU cycles.
|
---|
| 1388 | * A request is constructed with either RTFileAioReqPrepareRead()
|
---|
| 1389 | * which will set up a request to read from the given file or
|
---|
| 1390 | * RTFileAioReqPrepareWrite() which will write to a given file.
|
---|
| 1391 | *
|
---|
[19185] | 1392 | * The second object is the context. A file is associated with a context
|
---|
| 1393 | * and requests for this file may complete only on the context the file
|
---|
| 1394 | * was associated with and not on the context given in RTFileAioCtxSubmit()
|
---|
| 1395 | * (see below for further information).
|
---|
[19125] | 1396 | * RTFileAioCtxWait() is used to wait for completion of requests which were
|
---|
| 1397 | * associated with the context. While waiting for requests the thread can not
|
---|
[33540] | 1398 | * respond to global state changes. That's why the API provides a way to let
|
---|
[19125] | 1399 | * RTFileAioCtxWait() return immediately no matter how many requests
|
---|
| 1400 | * have finished through RTFileAioCtxWakeup(). The return code is
|
---|
| 1401 | * VERR_INTERRUPTED to let the thread know that he got interrupted.
|
---|
| 1402 | *
|
---|
[19562] | 1403 | * @section sec_rt_asyncio_request_states Request states
|
---|
[19125] | 1404 | *
|
---|
[19562] | 1405 | * Created:
|
---|
| 1406 | * After a request was created with RTFileAioReqCreate() it is in the same state
|
---|
| 1407 | * like it just completed successfully. RTFileAioReqGetRC() will return VINF_SUCCESS
|
---|
| 1408 | * and a transfer size of 0. RTFileAioReqGetUser() will return NULL. The request can be
|
---|
| 1409 | * destroyed RTFileAioReqDestroy(). It is also allowed to prepare a the request
|
---|
| 1410 | * for a data transfer with the RTFileAioReqPrepare* methods.
|
---|
| 1411 | * Calling any other method like RTFileAioCtxSubmit() will return VERR_FILE_AIO_NOT_PREPARED
|
---|
| 1412 | * and RTFileAioReqCancel() returns VERR_FILE_AIO_NOT_SUBMITTED.
|
---|
| 1413 | *
|
---|
| 1414 | * Prepared:
|
---|
| 1415 | * A request will enter this state if one of the RTFileAioReqPrepare* methods
|
---|
| 1416 | * is called. In this state you can still destroy and retrieve the user data
|
---|
| 1417 | * associated with the request but trying to cancel the request or getting
|
---|
| 1418 | * the result of the operation will return VERR_FILE_AIO_NOT_SUBMITTED.
|
---|
| 1419 | *
|
---|
| 1420 | * Submitted:
|
---|
| 1421 | * A prepared request can be submitted with RTFileAioCtxSubmit(). If the operation
|
---|
[33540] | 1422 | * succeeds it is not allowed to touch the request or free any resources until
|
---|
[19562] | 1423 | * it completed through RTFileAioCtxWait(). The only allowed method is RTFileAioReqCancel()
|
---|
| 1424 | * which tries to cancel the request. The request will go into the completed state
|
---|
| 1425 | * and RTFileAioReqGetRC() will return VERR_FILE_AIO_CANCELED.
|
---|
| 1426 | * If the request completes not matter if successfully or with an error it will
|
---|
| 1427 | * switch into the completed state. RTFileReqDestroy() fails if the given request
|
---|
| 1428 | * is in this state.
|
---|
| 1429 | *
|
---|
| 1430 | * Completed:
|
---|
| 1431 | * The request will be in this state after it completed and returned through
|
---|
| 1432 | * RTFileAioCtxWait(). RTFileAioReqGetRC() returns the final result code
|
---|
[33540] | 1433 | * and the number of bytes transferred.
|
---|
[19562] | 1434 | * The request can be used for new data transfers.
|
---|
| 1435 | *
|
---|
| 1436 | * @section sec_rt_asyncio_threading Threading
|
---|
| 1437 | *
|
---|
[19125] | 1438 | * The API is a thin wrapper around the specific host OS APIs and therefore
|
---|
| 1439 | * relies on the thread safety of the underlying API.
|
---|
| 1440 | * The interesting functions with regards to thread safety are RTFileAioCtxSubmit()
|
---|
| 1441 | * and RTFileAioCtxWait(). RTFileAioCtxWait() must not be called from different
|
---|
| 1442 | * threads at the same time with the same context handle. The same applies to
|
---|
| 1443 | * RTFileAioCtxSubmit(). However it is possible to submit new requests from a different
|
---|
| 1444 | * thread while waiting for completed requests on another thread with RTFileAioCtxWait().
|
---|
| 1445 | *
|
---|
[19562] | 1446 | * @section sec_rt_asyncio_implementations Differences in implementation
|
---|
| 1447 | *
|
---|
[19125] | 1448 | * Because the host APIs are quite different on every OS and every API has other limitations
|
---|
| 1449 | * there are some things to consider to make the code as portable as possible.
|
---|
| 1450 | *
|
---|
[19185] | 1451 | * The first restriction at the moment is that every buffer has to be aligned to a 512 byte boundary.
|
---|
[19125] | 1452 | * This limitation comes from the Linux io_* interface. To use the interface the file
|
---|
| 1453 | * must be opened with O_DIRECT. This flag disables the kernel cache too which may
|
---|
| 1454 | * degrade performance but is unfortunately the only way to make asynchronous
|
---|
| 1455 | * I/O work till today (if O_DIRECT is omitted io_submit will revert to sychronous behavior
|
---|
| 1456 | * and will return when the requests finished and when they are queued).
|
---|
| 1457 | * It is mostly used by DBMS which do theire own caching.
|
---|
| 1458 | * Furthermore there is no filesystem independent way to discover the restrictions at least
|
---|
| 1459 | * for the 2.4 kernel series. Since 2.6 the 512 byte boundary seems to be used by all
|
---|
| 1460 | * file systems. So Linus comment about this flag is comprehensible but Linux
|
---|
| 1461 | * lacks an alternative at the moment.
|
---|
[19185] | 1462 | *
|
---|
[19562] | 1463 | * The next limitation applies only to Windows. Requests are not associated with the
|
---|
[19185] | 1464 | * I/O context they are associated with but with the file the request is for.
|
---|
| 1465 | * The file needs to be associated with exactly one I/O completion port and requests
|
---|
| 1466 | * for this file will only arrive at that context after they completed and not on
|
---|
| 1467 | * the context the request was submitted.
|
---|
| 1468 | * To associate a file with a specific context RTFileAioCtxAssociateWithFile() is
|
---|
| 1469 | * used. It is only implemented on Windows and does nothing on the other platforms.
|
---|
| 1470 | * If the file needs to be associated with different context for some reason
|
---|
| 1471 | * the file must be closed first. After it was opened again the new context
|
---|
| 1472 | * can be associated with the other context.
|
---|
| 1473 | * This can't be done by the API because there is no way to retrieve the flags
|
---|
| 1474 | * the file was opened with.
|
---|
[18909] | 1475 | */
|
---|
| 1476 |
|
---|
| 1477 | /**
|
---|
[19562] | 1478 | * Global limits for the AIO API.
|
---|
| 1479 | */
|
---|
| 1480 | typedef struct RTFILEAIOLIMITS
|
---|
| 1481 | {
|
---|
| 1482 | /** Global number of simultaneous outstanding requests allowed.
|
---|
| 1483 | * RTFILEAIO_UNLIMITED_REQS means no limit. */
|
---|
| 1484 | uint32_t cReqsOutstandingMax;
|
---|
| 1485 | /** The alignment data buffers need to have.
|
---|
| 1486 | * 0 means no alignment restrictions. */
|
---|
| 1487 | uint32_t cbBufferAlignment;
|
---|
| 1488 | } RTFILEAIOLIMITS;
|
---|
| 1489 | /** A pointer to a AIO limits structure. */
|
---|
| 1490 | typedef RTFILEAIOLIMITS *PRTFILEAIOLIMITS;
|
---|
| 1491 |
|
---|
| 1492 | /**
|
---|
| 1493 | * Returns the global limits for the AIO API.
|
---|
| 1494 | *
|
---|
| 1495 | * @returns IPRT status code.
|
---|
| 1496 | * @retval VERR_NOT_SUPPORTED if the host does not support the async I/O API.
|
---|
| 1497 | *
|
---|
| 1498 | * @param pAioLimits Where to store the global limit information.
|
---|
| 1499 | */
|
---|
| 1500 | RTDECL(int) RTFileAioGetLimits(PRTFILEAIOLIMITS pAioLimits);
|
---|
| 1501 |
|
---|
| 1502 | /**
|
---|
[18961] | 1503 | * Creates an async I/O request handle.
|
---|
[18909] | 1504 | *
|
---|
| 1505 | * @returns IPRT status code.
|
---|
[18961] | 1506 | * @param phReq Where to store the request handle.
|
---|
[18909] | 1507 | */
|
---|
[18961] | 1508 | RTDECL(int) RTFileAioReqCreate(PRTFILEAIOREQ phReq);
|
---|
[18909] | 1509 |
|
---|
| 1510 | /**
|
---|
[18961] | 1511 | * Destroys an async I/O request handle.
|
---|
[18909] | 1512 | *
|
---|
[19562] | 1513 | * @returns IPRT status code.
|
---|
| 1514 | * @retval VERR_FILE_AIO_IN_PROGRESS if the request is still in progress.
|
---|
| 1515 | *
|
---|
[18961] | 1516 | * @param hReq The request handle.
|
---|
[18909] | 1517 | */
|
---|
[19562] | 1518 | RTDECL(int) RTFileAioReqDestroy(RTFILEAIOREQ hReq);
|
---|
[18909] | 1519 |
|
---|
| 1520 | /**
|
---|
[18961] | 1521 | * Prepares an async read request.
|
---|
[18909] | 1522 | *
|
---|
| 1523 | * @returns IPRT status code.
|
---|
[19562] | 1524 | * @retval VERR_FILE_AIO_IN_PROGRESS if the request is still in progress.
|
---|
[18961] | 1525 | *
|
---|
| 1526 | * @param hReq The request handle.
|
---|
| 1527 | * @param hFile The file to read from.
|
---|
[18909] | 1528 | * @param off The offset to start reading at.
|
---|
| 1529 | * @param pvBuf Where to store the read bits.
|
---|
| 1530 | * @param cbRead Number of bytes to read.
|
---|
| 1531 | * @param pvUser Opaque user data associated with this request which
|
---|
[18961] | 1532 | * can be retrieved with RTFileAioReqGetUser().
|
---|
[18909] | 1533 | */
|
---|
[18961] | 1534 | RTDECL(int) RTFileAioReqPrepareRead(RTFILEAIOREQ hReq, RTFILE hFile, RTFOFF off,
|
---|
| 1535 | void *pvBuf, size_t cbRead, void *pvUser);
|
---|
[18909] | 1536 |
|
---|
| 1537 | /**
|
---|
[18961] | 1538 | * Prepares an async write request.
|
---|
[18909] | 1539 | *
|
---|
| 1540 | * @returns IPRT status code.
|
---|
[19562] | 1541 | * @retval VERR_FILE_AIO_IN_PROGRESS if the request is still in progress.
|
---|
[18961] | 1542 | *
|
---|
| 1543 | * @param hReq The request handle.
|
---|
| 1544 | * @param hFile The file to write to.
|
---|
[18909] | 1545 | * @param off The offset to start writing at.
|
---|
[25645] | 1546 | * @param pvBuf The bits to write.
|
---|
| 1547 | * @param cbWrite Number of bytes to write.
|
---|
[18909] | 1548 | * @param pvUser Opaque user data associated with this request which
|
---|
[18961] | 1549 | * can be retrieved with RTFileAioReqGetUser().
|
---|
[18909] | 1550 | */
|
---|
[18961] | 1551 | RTDECL(int) RTFileAioReqPrepareWrite(RTFILEAIOREQ hReq, RTFILE hFile, RTFOFF off,
|
---|
[25645] | 1552 | void const *pvBuf, size_t cbWrite, void *pvUser);
|
---|
[18909] | 1553 |
|
---|
| 1554 | /**
|
---|
[18961] | 1555 | * Prepares an async flush of all cached data associated with a file handle.
|
---|
[18909] | 1556 | *
|
---|
| 1557 | * @returns IPRT status code.
|
---|
[19562] | 1558 | * @retval VERR_FILE_AIO_IN_PROGRESS if the request is still in progress.
|
---|
[18961] | 1559 | *
|
---|
| 1560 | * @param hReq The request handle.
|
---|
| 1561 | * @param hFile The file to flush.
|
---|
[18909] | 1562 | * @param pvUser Opaque user data associated with this request which
|
---|
[18961] | 1563 | * can be retrieved with RTFileAioReqGetUser().
|
---|
| 1564 | *
|
---|
| 1565 | * @remarks May also flush other caches on some platforms.
|
---|
[18909] | 1566 | */
|
---|
[18961] | 1567 | RTDECL(int) RTFileAioReqPrepareFlush(RTFILEAIOREQ hReq, RTFILE hFile, void *pvUser);
|
---|
[18909] | 1568 |
|
---|
| 1569 | /**
|
---|
[18961] | 1570 | * Gets the opaque user data associated with the given request.
|
---|
[18909] | 1571 | *
|
---|
| 1572 | * @returns Opaque user data.
|
---|
[18961] | 1573 | * @retval NULL if the request hasn't been prepared yet.
|
---|
| 1574 | *
|
---|
| 1575 | * @param hReq The request handle.
|
---|
[18909] | 1576 | */
|
---|
[18961] | 1577 | RTDECL(void *) RTFileAioReqGetUser(RTFILEAIOREQ hReq);
|
---|
[18909] | 1578 |
|
---|
| 1579 | /**
|
---|
| 1580 | * Cancels a pending request.
|
---|
| 1581 | *
|
---|
| 1582 | * @returns IPRT status code.
|
---|
| 1583 | * @retval VINF_SUCCESS If the request was canceled.
|
---|
[19562] | 1584 | * @retval VERR_FILE_AIO_NOT_SUBMITTED If the request wasn't submitted yet.
|
---|
[18909] | 1585 | * @retval VERR_FILE_AIO_IN_PROGRESS If the request could not be canceled because it is already processed.
|
---|
| 1586 | * @retval VERR_FILE_AIO_COMPLETED If the request could not be canceled because it already completed.
|
---|
| 1587 | *
|
---|
[18961] | 1588 | * @param hReq The request to cancel.
|
---|
[18909] | 1589 | */
|
---|
[18961] | 1590 | RTDECL(int) RTFileAioReqCancel(RTFILEAIOREQ hReq);
|
---|
[18909] | 1591 |
|
---|
| 1592 | /**
|
---|
[18961] | 1593 | * Gets the status of a completed request.
|
---|
[18909] | 1594 | *
|
---|
| 1595 | * @returns The IPRT status code of the given request.
|
---|
[19562] | 1596 | * @retval VERR_FILE_AIO_NOT_SUBMITTED if the request wasn't submitted yet.
|
---|
| 1597 | * @retval VERR_FILE_AIO_CANCELED if the request was canceled.
|
---|
[18961] | 1598 | * @retval VERR_FILE_AIO_IN_PROGRESS if the request isn't yet completed.
|
---|
| 1599 | *
|
---|
| 1600 | * @param hReq The request handle.
|
---|
[33540] | 1601 | * @param pcbTransferred Where to store the number of bytes transferred.
|
---|
[18961] | 1602 | * Optional since it is not relevant for all kinds of
|
---|
| 1603 | * requests.
|
---|
[18909] | 1604 | */
|
---|
[25645] | 1605 | RTDECL(int) RTFileAioReqGetRC(RTFILEAIOREQ hReq, size_t *pcbTransferred);
|
---|
[18909] | 1606 |
|
---|
[18961] | 1607 |
|
---|
| 1608 |
|
---|
[18909] | 1609 | /**
|
---|
[18961] | 1610 | * Creates an async I/O context.
|
---|
[18909] | 1611 | *
|
---|
[18961] | 1612 | * @todo briefly explain what an async context is here or in the page
|
---|
| 1613 | * above.
|
---|
| 1614 | *
|
---|
[18909] | 1615 | * @returns IPRT status code.
|
---|
[18961] | 1616 | * @param phAioCtx Where to store the async I/O context handle.
|
---|
[18909] | 1617 | * @param cAioReqsMax How many async I/O requests the context should be capable
|
---|
[18961] | 1618 | * to handle. Pass RTFILEAIO_UNLIMITED_REQS if the
|
---|
| 1619 | * context should support an unlimited number of
|
---|
| 1620 | * requests.
|
---|
[45678] | 1621 | * @param fFlags Combination of RTFILEAIOCTX_FLAGS_*.
|
---|
[18909] | 1622 | */
|
---|
[45678] | 1623 | RTDECL(int) RTFileAioCtxCreate(PRTFILEAIOCTX phAioCtx, uint32_t cAioReqsMax,
|
---|
| 1624 | uint32_t fFlags);
|
---|
[18909] | 1625 |
|
---|
[18961] | 1626 | /** Unlimited number of requests.
|
---|
| 1627 | * Used with RTFileAioCtxCreate and RTFileAioCtxGetMaxReqCount. */
|
---|
| 1628 | #define RTFILEAIO_UNLIMITED_REQS UINT32_MAX
|
---|
| 1629 |
|
---|
[45678] | 1630 | /** When set RTFileAioCtxWait() will always wait for completing requests,
|
---|
[47735] | 1631 | * even when there is none waiting currently, instead of returning
|
---|
[45678] | 1632 | * VERR_FILE_AIO_NO_REQUEST. */
|
---|
| 1633 | #define RTFILEAIOCTX_FLAGS_WAIT_WITHOUT_PENDING_REQUESTS RT_BIT_32(0)
|
---|
| 1634 | /** mask of valid flags. */
|
---|
| 1635 | #define RTFILEAIOCTX_FLAGS_VALID_MASK (RTFILEAIOCTX_FLAGS_WAIT_WITHOUT_PENDING_REQUESTS)
|
---|
| 1636 |
|
---|
[18909] | 1637 | /**
|
---|
[18961] | 1638 | * Destroys an async I/O context.
|
---|
[18909] | 1639 | *
|
---|
| 1640 | * @returns IPRT status code.
|
---|
[18961] | 1641 | * @param hAioCtx The async I/O context handle.
|
---|
[18909] | 1642 | */
|
---|
[18961] | 1643 | RTDECL(int) RTFileAioCtxDestroy(RTFILEAIOCTX hAioCtx);
|
---|
[18909] | 1644 |
|
---|
| 1645 | /**
|
---|
| 1646 | * Get the maximum number of requests one aio context can handle.
|
---|
| 1647 | *
|
---|
| 1648 | * @returns Maximum number of tasks the context can handle.
|
---|
[18961] | 1649 | * RTFILEAIO_UNLIMITED_REQS if there is no limit.
|
---|
[18909] | 1650 | *
|
---|
[18961] | 1651 | * @param hAioCtx The async I/O context handle.
|
---|
[18909] | 1652 | * If NIL_RTAIOCONTEXT is passed the maximum value
|
---|
[18912] | 1653 | * which can be passed to RTFileAioCtxCreate()
|
---|
[18909] | 1654 | * is returned.
|
---|
| 1655 | */
|
---|
[18961] | 1656 | RTDECL(uint32_t) RTFileAioCtxGetMaxReqCount(RTFILEAIOCTX hAioCtx);
|
---|
[18909] | 1657 |
|
---|
| 1658 | /**
|
---|
[36573] | 1659 | * Associates a file with an async I/O context.
|
---|
[19185] | 1660 | * Requests for this file will arrive at the completion port
|
---|
| 1661 | * associated with the file.
|
---|
| 1662 | *
|
---|
| 1663 | * @returns IPRT status code.
|
---|
| 1664 | *
|
---|
| 1665 | * @param hAioCtx The async I/O context handle.
|
---|
| 1666 | * @param hFile The file handle.
|
---|
| 1667 | */
|
---|
| 1668 | RTDECL(int) RTFileAioCtxAssociateWithFile(RTFILEAIOCTX hAioCtx, RTFILE hFile);
|
---|
| 1669 |
|
---|
| 1670 | /**
|
---|
[18961] | 1671 | * Submits a set of requests to an async I/O context for processing.
|
---|
[18909] | 1672 | *
|
---|
| 1673 | * @returns IPRT status code.
|
---|
[21493] | 1674 | * @returns VERR_FILE_AIO_INSUFFICIENT_RESSOURCES if the maximum number of
|
---|
| 1675 | * simultaneous outstanding requests would be exceeded.
|
---|
[18961] | 1676 | *
|
---|
| 1677 | * @param hAioCtx The async I/O context handle.
|
---|
| 1678 | * @param pahReqs Pointer to an array of request handles.
|
---|
| 1679 | * @param cReqs The number of entries in the array.
|
---|
| 1680 | *
|
---|
[19562] | 1681 | * @remarks It is possible that some requests could be submitted successfully
|
---|
| 1682 | * even if the method returns an error code. In that case RTFileAioReqGetRC()
|
---|
| 1683 | * can be used to determine the status of a request.
|
---|
| 1684 | * If it returns VERR_FILE_AIO_IN_PROGRESS it was submitted successfully.
|
---|
| 1685 | * Any other error code may indicate why the request failed.
|
---|
| 1686 | * VERR_FILE_AIO_NOT_SUBMITTED indicates that a request wasn't submitted
|
---|
| 1687 | * probably because the previous request encountered an error.
|
---|
| 1688 | *
|
---|
[18961] | 1689 | * @remarks @a cReqs uses the type size_t while it really is a uint32_t, this is
|
---|
| 1690 | * to avoid annoying warnings when using RT_ELEMENTS and similar
|
---|
| 1691 | * macros.
|
---|
[18909] | 1692 | */
|
---|
[19562] | 1693 | RTDECL(int) RTFileAioCtxSubmit(RTFILEAIOCTX hAioCtx, PRTFILEAIOREQ pahReqs, size_t cReqs);
|
---|
[18909] | 1694 |
|
---|
| 1695 | /**
|
---|
[18961] | 1696 | * Waits for request completion.
|
---|
[18909] | 1697 | *
|
---|
[19039] | 1698 | * Only one thread at a time may call this API on a context.
|
---|
| 1699 | *
|
---|
[18909] | 1700 | * @returns IPRT status code.
|
---|
[18961] | 1701 | * @retval VERR_INVALID_POINTER If pcReqs or/and pahReqs are invalid.
|
---|
| 1702 | * @retval VERR_INVALID_HANDLE If hAioCtx is invalid.
|
---|
| 1703 | * @retval VERR_OUT_OF_RANGE If cMinReqs is larger than cReqs.
|
---|
| 1704 | * @retval VERR_INVALID_PARAMETER If cReqs is 0.
|
---|
| 1705 | * @retval VERR_TIMEOUT If cMinReqs didn't complete before the
|
---|
| 1706 | * timeout expired.
|
---|
| 1707 | * @retval VERR_INTERRUPTED If the completion context was interrupted
|
---|
| 1708 | * by RTFileAioCtxWakeup().
|
---|
| 1709 | * @retval VERR_FILE_AIO_NO_REQUEST If there are no pending request.
|
---|
[18909] | 1710 | *
|
---|
[18961] | 1711 | * @param hAioCtx The async I/O context handle to wait and get
|
---|
| 1712 | * completed requests from.
|
---|
| 1713 | * @param cMinReqs The minimum number of requests which have to
|
---|
| 1714 | * complete before this function returns.
|
---|
[25724] | 1715 | * @param cMillies The number of milliseconds to wait before returning
|
---|
| 1716 | * VERR_TIMEOUT. Use RT_INDEFINITE_WAIT to wait
|
---|
[18961] | 1717 | * forever.
|
---|
| 1718 | * @param pahReqs Pointer to an array where the handles of the
|
---|
| 1719 | * completed requests will be stored on success.
|
---|
| 1720 | * @param cReqs The number of entries @a pahReqs can hold.
|
---|
| 1721 | * @param pcReqs Where to store the number of returned (complete)
|
---|
| 1722 | * requests. This will always be set.
|
---|
| 1723 | *
|
---|
| 1724 | * @remarks The wait will be resume if interrupted by a signal. An
|
---|
| 1725 | * RTFileAioCtxWaitNoResume variant can be added later if it becomes
|
---|
| 1726 | * necessary.
|
---|
| 1727 | *
|
---|
| 1728 | * @remarks @a cMinReqs and @a cReqs use the type size_t while they really are
|
---|
| 1729 | * uint32_t's, this is to avoid annoying warnings when using
|
---|
| 1730 | * RT_ELEMENTS and similar macros.
|
---|
[18909] | 1731 | */
|
---|
[25724] | 1732 | RTDECL(int) RTFileAioCtxWait(RTFILEAIOCTX hAioCtx, size_t cMinReqs, RTMSINTERVAL cMillies,
|
---|
[18999] | 1733 | PRTFILEAIOREQ pahReqs, size_t cReqs, uint32_t *pcReqs);
|
---|
[18909] | 1734 |
|
---|
| 1735 | /**
|
---|
[19039] | 1736 | * Forces any RTFileAioCtxWait() call on another thread to return immediately.
|
---|
[18909] | 1737 | *
|
---|
| 1738 | * @returns IPRT status code.
|
---|
[18961] | 1739 | *
|
---|
| 1740 | * @param hAioCtx The handle of the async I/O context to wakeup.
|
---|
[18909] | 1741 | */
|
---|
[18961] | 1742 | RTDECL(int) RTFileAioCtxWakeup(RTFILEAIOCTX hAioCtx);
|
---|
[18909] | 1743 |
|
---|
[1] | 1744 | #endif /* IN_RING3 */
|
---|
| 1745 |
|
---|
| 1746 | /** @} */
|
---|
| 1747 |
|
---|
[20374] | 1748 | RT_C_DECLS_END
|
---|
[1] | 1749 |
|
---|
[76585] | 1750 | #endif /* !IPRT_INCLUDED_file_h */
|
---|
[1] | 1751 |
|
---|