The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * * Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * * Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in |
| 12 | * the documentation and/or other materials provided with the |
| 13 | * distribution. |
| 14 | * |
| 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 16 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 17 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 18 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 19 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
| 22 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
| 23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 25 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 26 | * SUCH DAMAGE. |
| 27 | */ |
Elliott Hughes | e989399 | 2013-10-17 11:45:22 -0700 | [diff] [blame] | 28 | |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame^] | 29 | #pragma once |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 30 | #define _FCNTL_H |
| 31 | |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame^] | 32 | /** |
| 33 | * @file fcntl.h |
| 34 | * @brief File control operations. |
| 35 | */ |
| 36 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 37 | #include <sys/cdefs.h> |
| 38 | #include <sys/types.h> |
Elliott Hughes | 01e505a | 2014-01-07 17:47:20 -0800 | [diff] [blame] | 39 | #include <linux/fadvise.h> |
Nick Desaulniers | 09d900d | 2016-07-19 15:20:24 -0700 | [diff] [blame] | 40 | #include <linux/falloc.h> |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 41 | #include <linux/fcntl.h> |
Elliott Hughes | 64d8382 | 2014-12-29 11:14:38 -0800 | [diff] [blame] | 42 | #include <linux/stat.h> |
Elliott Hughes | 3f525d4 | 2014-06-24 16:32:01 -0700 | [diff] [blame] | 43 | #include <linux/uio.h> |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 44 | |
Josh Gao | ee8d169 | 2016-04-07 14:16:30 -0700 | [diff] [blame] | 45 | #include <bits/fcntl.h> |
Elliott Hughes | fd936ae | 2016-08-12 10:16:34 -0700 | [diff] [blame] | 46 | #include <bits/seek_constants.h> |
Josh Gao | ee8d169 | 2016-04-07 14:16:30 -0700 | [diff] [blame] | 47 | |
Elliott Hughes | 5704c42 | 2016-01-25 18:06:24 -0800 | [diff] [blame] | 48 | #if defined(__USE_GNU) || defined(__USE_BSD) |
| 49 | #include <bits/lockf.h> |
| 50 | #endif |
| 51 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 52 | __BEGIN_DECLS |
| 53 | |
Serban Constantinescu | 48501af | 2014-03-14 13:16:25 +0000 | [diff] [blame] | 54 | #ifdef __LP64__ |
Christopher Ferris | ba8d4f4 | 2014-09-03 19:56:49 -0700 | [diff] [blame] | 55 | /* LP64 kernels don't have F_*64 defines because their flock is 64-bit. */ |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame^] | 56 | /** Flag for flock(). */ |
Serban Constantinescu | 48501af | 2014-03-14 13:16:25 +0000 | [diff] [blame] | 57 | #define F_GETLK64 F_GETLK |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame^] | 58 | /** Flag for flock(). */ |
Serban Constantinescu | 48501af | 2014-03-14 13:16:25 +0000 | [diff] [blame] | 59 | #define F_SETLK64 F_SETLK |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame^] | 60 | /** Flag for flock(). */ |
Serban Constantinescu | 48501af | 2014-03-14 13:16:25 +0000 | [diff] [blame] | 61 | #define F_SETLKW64 F_SETLKW |
| 62 | #endif |
| 63 | |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame^] | 64 | /** Flag for open(). */ |
Elliott Hughes | 3f525d4 | 2014-06-24 16:32:01 -0700 | [diff] [blame] | 65 | #define O_ASYNC FASYNC |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame^] | 66 | /** Flag for open(). */ |
Elliott Hughes | 31165ed | 2014-09-23 17:34:29 -0700 | [diff] [blame] | 67 | #define O_RSYNC O_SYNC |
Elliott Hughes | 3f525d4 | 2014-06-24 16:32:01 -0700 | [diff] [blame] | 68 | |
Elliott Hughes | 9d25072 | 2017-07-05 15:59:58 -0700 | [diff] [blame] | 69 | #if __ANDROID_API__ >= __ANDROID_API_L__ |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame^] | 70 | /** Flag for splice(). */ |
Elliott Hughes | 3f525d4 | 2014-06-24 16:32:01 -0700 | [diff] [blame] | 71 | #define SPLICE_F_MOVE 1 |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame^] | 72 | /** Flag for splice(). */ |
Elliott Hughes | 3f525d4 | 2014-06-24 16:32:01 -0700 | [diff] [blame] | 73 | #define SPLICE_F_NONBLOCK 2 |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame^] | 74 | /** Flag for splice(). */ |
Elliott Hughes | 3f525d4 | 2014-06-24 16:32:01 -0700 | [diff] [blame] | 75 | #define SPLICE_F_MORE 4 |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame^] | 76 | /** Flag for splice(). */ |
Elliott Hughes | 3f525d4 | 2014-06-24 16:32:01 -0700 | [diff] [blame] | 77 | #define SPLICE_F_GIFT 8 |
Elliott Hughes | 9d25072 | 2017-07-05 15:59:58 -0700 | [diff] [blame] | 78 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 79 | |
Elliott Hughes | 9d25072 | 2017-07-05 15:59:58 -0700 | [diff] [blame] | 80 | #if __ANDROID_API__ >= __ANDROID_API_O__ |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame^] | 81 | /** Flag for sync_file_range(). */ |
Elliott Hughes | 3434727 | 2014-02-26 11:10:32 -0800 | [diff] [blame] | 82 | #define SYNC_FILE_RANGE_WAIT_BEFORE 1 |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame^] | 83 | /** Flag for sync_file_range(). */ |
Elliott Hughes | 3434727 | 2014-02-26 11:10:32 -0800 | [diff] [blame] | 84 | #define SYNC_FILE_RANGE_WRITE 2 |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame^] | 85 | /** Flag for sync_file_range(). */ |
Elliott Hughes | 3434727 | 2014-02-26 11:10:32 -0800 | [diff] [blame] | 86 | #define SYNC_FILE_RANGE_WAIT_AFTER 4 |
Elliott Hughes | 9d25072 | 2017-07-05 15:59:58 -0700 | [diff] [blame] | 87 | #endif |
Elliott Hughes | 3434727 | 2014-02-26 11:10:32 -0800 | [diff] [blame] | 88 | |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame^] | 89 | /** |
| 90 | * [creat(2)](http://man7.org/linux/man-pages/man2/creat.2.html) |
| 91 | * creates a file. |
| 92 | * |
| 93 | * Returns a new file descriptor on success and returns -1 and sets `errno` on |
| 94 | * failure. |
| 95 | */ |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 96 | int creat(const char* __path, mode_t __mode); |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame^] | 97 | /** See creat(). */ |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 98 | int creat64(const char* __path, mode_t __mode) __INTRODUCED_IN(21); |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame^] | 99 | |
| 100 | /** |
| 101 | * [openat(2)](http://man7.org/linux/man-pages/man2/openat.2.html) |
| 102 | * opens (and possibly creates) a file. |
| 103 | * |
| 104 | * Returns a new file descriptor on success and returns -1 and sets `errno` on |
| 105 | * failure. |
| 106 | */ |
George Burgess IV | 9024235 | 2018-02-06 12:51:31 -0800 | [diff] [blame] | 107 | int openat(int __dir_fd, const char* __path, int __flags, ...); |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame^] | 108 | /** See openat(). */ |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 109 | int openat64(int __dir_fd, const char* __path, int __flags, ...) __INTRODUCED_IN(21); |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame^] | 110 | |
| 111 | /** |
| 112 | * [open(2)](http://man7.org/linux/man-pages/man2/open.2.html) |
| 113 | * opens (and possibly creates) a file. |
| 114 | * |
| 115 | * Returns a new file descriptor on success and returns -1 and sets `errno` on |
| 116 | * failure. |
| 117 | */ |
George Burgess IV | 9024235 | 2018-02-06 12:51:31 -0800 | [diff] [blame] | 118 | int open(const char* __path, int __flags, ...); |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame^] | 119 | /** See open(). */ |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 120 | int open64(const char* __path, int __flags, ...) __INTRODUCED_IN(21); |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame^] | 121 | |
| 122 | /** |
| 123 | * [splice(2)](http://man7.org/linux/man-pages/man2/splice.2.html) |
| 124 | * splices data to/from a pipe. |
| 125 | * |
| 126 | * Valid flags are `SPLICE_F_MOVE`, `SPLICE_F_NONBLOCK`, `SPLICE_F_MORE`, and |
| 127 | * `SPLICE_F_GIFT`. |
| 128 | * |
| 129 | * Returns the number of bytes spliced on success and returns -1 and sets |
| 130 | * `errno` on failure. |
| 131 | * |
| 132 | * Available since API level 21. |
| 133 | */ |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 134 | ssize_t splice(int __in_fd, off64_t* __in_offset, int __out_fd, off64_t* __out_offset, size_t __length, unsigned int __flags) __INTRODUCED_IN(21); |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame^] | 135 | |
| 136 | /** |
| 137 | * [tee(2)](http://man7.org/linux/man-pages/man2/tee.2.html) |
| 138 | * duplicates data from one pipe to another. |
| 139 | * |
| 140 | * Valid flags are `SPLICE_F_MOVE`, `SPLICE_F_NONBLOCK`, `SPLICE_F_MORE`, and |
| 141 | * `SPLICE_F_GIFT`. |
| 142 | * |
| 143 | * Returns the number of bytes duplicated on success and returns -1 and sets |
| 144 | * `errno` on failure. |
| 145 | * |
| 146 | * Available since API level 21. |
| 147 | */ |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 148 | ssize_t tee(int __in_fd, int __out_fd, size_t __length, unsigned int __flags) __INTRODUCED_IN(21); |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame^] | 149 | |
| 150 | /** |
| 151 | * [vmsplice(2)](http://man7.org/linux/man-pages/man2/vmsplice.2.html) |
| 152 | * splices data to/from a pipe. |
| 153 | * |
| 154 | * Valid flags are `SPLICE_F_MOVE`, `SPLICE_F_NONBLOCK`, `SPLICE_F_MORE`, and |
| 155 | * `SPLICE_F_GIFT`. |
| 156 | * |
| 157 | * Returns the number of bytes spliced on success and returns -1 and sets |
| 158 | * `errno` on failure. |
| 159 | * |
| 160 | * Available since API level 21. |
| 161 | */ |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 162 | ssize_t vmsplice(int __fd, const struct iovec* __iov, size_t __count, unsigned int __flags) __INTRODUCED_IN(21); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 163 | |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame^] | 164 | /** |
| 165 | * [fallocate(2)](http://man7.org/linux/man-pages/man2/fallocate.2.html) |
| 166 | * is a Linux-specific extension of posix_fallocate(). |
| 167 | * |
| 168 | * Valid flags are `FALLOC_FL_KEEP_SIZE`, `FALLOC_FL_PUNCH_HOLE`, |
| 169 | * `FALLOC_FL_NO_HIDE_STALE`, `FALLOC_FL_COLLAPSE_RANGE`, |
| 170 | * `FALLOC_FL_ZERO_RANGE`, `FALLOC_FL_INSERT_RANGE`, and |
| 171 | * `FALLOC_FL_UNSHARE_RANGE`. |
| 172 | * |
| 173 | * Returns 0 on success and returns -1 and sets `errno` on failure. |
| 174 | * |
| 175 | * Available since API level 21. |
| 176 | */ |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 177 | int fallocate(int __fd, int __mode, off_t __offset, off_t __length) __RENAME_IF_FILE_OFFSET64(fallocate64) __INTRODUCED_IN(21); |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame^] | 178 | /** See fallocate(). */ |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 179 | int fallocate64(int __fd, int __mode, off64_t __offset, off64_t __length) __INTRODUCED_IN(21); |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame^] | 180 | |
| 181 | /** |
| 182 | * [posix_fadvise(2)](http://man7.org/linux/man-pages/man2/posix_fadvise.2.html) |
| 183 | * declares an expected access pattern for file data. |
| 184 | * |
| 185 | * Valid flags are `POSIX_FADV_NORMAL`, `POSIX_FADV_RANDOM`, |
| 186 | * `POSIX_FADV_SEQUENTIAL`, `POSIX_FADV_WILLNEED`, `POSIX_FADV_DONTNEED`, |
| 187 | * and `POSIX_FADV_NOREUSE`. |
| 188 | * |
| 189 | * Returns 0 on success and returns an error number on failure. |
| 190 | * |
| 191 | * Available since API level 21. |
| 192 | */ |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 193 | int posix_fadvise(int __fd, off_t __offset, off_t __length, int __advice) __RENAME_IF_FILE_OFFSET64(posix_fadvise64) __INTRODUCED_IN(21); |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame^] | 194 | /** See posix_fadvise(). */ |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 195 | int posix_fadvise64(int __fd, off64_t __offset, off64_t __length, int __advice) __INTRODUCED_IN(21); |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame^] | 196 | |
| 197 | /** |
| 198 | * [posix_fallocate(2)](http://man7.org/linux/man-pages/man2/posix_fallocate.2.html) |
| 199 | * allocates file space. |
| 200 | * |
| 201 | * Returns 0 on success and returns an error number on failure. |
| 202 | * |
| 203 | * Available since API level 21. |
| 204 | */ |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 205 | int posix_fallocate(int __fd, off_t __offset, off_t __length) __RENAME_IF_FILE_OFFSET64(posix_fallocate64) __INTRODUCED_IN(21); |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame^] | 206 | /** See posix_fallocate(). */ |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 207 | int posix_fallocate64(int __fd, off64_t __offset, off64_t __length) __INTRODUCED_IN(21); |
Elliott Hughes | 68dc20d | 2015-02-06 22:28:49 -0800 | [diff] [blame] | 208 | |
Elliott Hughes | 55147ad | 2016-04-05 11:06:02 -0700 | [diff] [blame] | 209 | #if defined(__USE_GNU) |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame^] | 210 | |
| 211 | /** |
| 212 | * [readahead(2)](http://man7.org/linux/man-pages/man2/readahead.2.html) |
| 213 | * initiates readahead for the given file. |
| 214 | * |
| 215 | * Returns 0 on success and returns -1 and sets `errno` on failure. |
| 216 | */ |
| 217 | ssize_t readahead(int __fd, off64_t __offset, size_t __length); |
| 218 | |
| 219 | /** |
| 220 | * [sync_file_range(2)](http://man7.org/linux/man-pages/man2/sync_file_range.2.html) |
| 221 | * syncs part of a file with disk. |
| 222 | * |
| 223 | * Valid flags are `SYNC_FILE_RANGE_WAIT_BEFORE`, `SYNC_FILE_RANGE_WRITE`, and |
| 224 | * `SYNC_FILE_RANGE_WAIT_AFTER`. |
| 225 | * |
| 226 | * Returns 0 on success and returns -1 and sets `errno` on failure. |
| 227 | */ |
Elliott Hughes | ff26a16 | 2017-08-17 22:34:21 +0000 | [diff] [blame] | 228 | int sync_file_range(int __fd, off64_t __offset, off64_t __length, unsigned int __flags) __INTRODUCED_IN(26); |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame^] | 229 | |
Elliott Hughes | 55147ad | 2016-04-05 11:06:02 -0700 | [diff] [blame] | 230 | #endif |
| 231 | |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 232 | #if defined(__BIONIC_INCLUDE_FORTIFY_HEADERS) |
| 233 | #include <bits/fortify/fcntl.h> |
| 234 | #endif |
Nick Kralevich | 8118f62 | 2012-06-26 15:08:06 -0700 | [diff] [blame] | 235 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 236 | __END_DECLS |