| 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 |  | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 29 | #ifndef _FCNTL_H | 
 | 30 | #define _FCNTL_H | 
 | 31 |  | 
 | 32 | #include <sys/cdefs.h> | 
 | 33 | #include <sys/types.h> | 
| Elliott Hughes | 01e505a | 2014-01-07 17:47:20 -0800 | [diff] [blame] | 34 | #include <linux/fadvise.h> | 
| Nick Desaulniers | 09d900d | 2016-07-19 15:20:24 -0700 | [diff] [blame] | 35 | #include <linux/falloc.h> | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 36 | #include <linux/fcntl.h> | 
| Elliott Hughes | 64d8382 | 2014-12-29 11:14:38 -0800 | [diff] [blame] | 37 | #include <linux/stat.h> | 
| Elliott Hughes | 3f525d4 | 2014-06-24 16:32:01 -0700 | [diff] [blame] | 38 | #include <linux/uio.h> | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 39 |  | 
| Josh Gao | ee8d169 | 2016-04-07 14:16:30 -0700 | [diff] [blame] | 40 | #include <bits/fcntl.h> | 
| Elliott Hughes | fd936ae | 2016-08-12 10:16:34 -0700 | [diff] [blame] | 41 | #include <bits/seek_constants.h> | 
| Josh Gao | ee8d169 | 2016-04-07 14:16:30 -0700 | [diff] [blame] | 42 |  | 
| Elliott Hughes | 5704c42 | 2016-01-25 18:06:24 -0800 | [diff] [blame] | 43 | #if defined(__USE_GNU) || defined(__USE_BSD) | 
 | 44 | #include <bits/lockf.h> | 
 | 45 | #endif | 
 | 46 |  | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 47 | __BEGIN_DECLS | 
 | 48 |  | 
| Serban Constantinescu | 48501af | 2014-03-14 13:16:25 +0000 | [diff] [blame] | 49 | #ifdef __LP64__ | 
| Christopher Ferris | ba8d4f4 | 2014-09-03 19:56:49 -0700 | [diff] [blame] | 50 | /* LP64 kernels don't have F_*64 defines because their flock is 64-bit. */ | 
| Serban Constantinescu | 48501af | 2014-03-14 13:16:25 +0000 | [diff] [blame] | 51 | #define F_GETLK64  F_GETLK | 
 | 52 | #define F_SETLK64  F_SETLK | 
 | 53 | #define F_SETLKW64 F_SETLKW | 
 | 54 | #endif | 
 | 55 |  | 
| Elliott Hughes | 3f525d4 | 2014-06-24 16:32:01 -0700 | [diff] [blame] | 56 | #define O_ASYNC FASYNC | 
| Elliott Hughes | 31165ed | 2014-09-23 17:34:29 -0700 | [diff] [blame] | 57 | #define O_RSYNC O_SYNC | 
| Elliott Hughes | 3f525d4 | 2014-06-24 16:32:01 -0700 | [diff] [blame] | 58 |  | 
 | 59 | #define SPLICE_F_MOVE 1 | 
 | 60 | #define SPLICE_F_NONBLOCK 2 | 
 | 61 | #define SPLICE_F_MORE 4 | 
 | 62 | #define SPLICE_F_GIFT 8 | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 63 |  | 
| Elliott Hughes | 3434727 | 2014-02-26 11:10:32 -0800 | [diff] [blame] | 64 | #define SYNC_FILE_RANGE_WAIT_BEFORE 1 | 
 | 65 | #define SYNC_FILE_RANGE_WRITE 2 | 
 | 66 | #define SYNC_FILE_RANGE_WAIT_AFTER 4 | 
 | 67 |  | 
| Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 68 | int creat(const char*, mode_t); | 
 | 69 | int creat64(const char*, mode_t) __INTRODUCED_IN(21); | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 70 | int openat(int, const char*, int, ...) __overloadable | 
 | 71 |         __RENAME_CLANG(openat); | 
| Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 72 | int openat64(int, const char*, int, ...) __INTRODUCED_IN(21); | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 73 | int open(const char*, int, ...) __overloadable __RENAME_CLANG(open); | 
| Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 74 | int open64(const char*, int, ...) __INTRODUCED_IN(21); | 
 | 75 | ssize_t splice(int, off64_t*, int, off64_t*, size_t, unsigned int) __INTRODUCED_IN(21); | 
 | 76 | ssize_t tee(int, int, size_t, unsigned int) __INTRODUCED_IN(21); | 
 | 77 | ssize_t vmsplice(int, const struct iovec*, size_t, unsigned int) __INTRODUCED_IN(21); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 78 |  | 
| Elliott Hughes | 68dc20d | 2015-02-06 22:28:49 -0800 | [diff] [blame] | 79 | #if defined(__USE_FILE_OFFSET64) | 
| Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 80 | int fallocate(int, int, off_t, off_t) __RENAME(fallocate64) __INTRODUCED_IN(21); | 
 | 81 | int posix_fadvise(int, off_t, off_t, int) __RENAME(posix_fadvise64) __INTRODUCED_IN(21); | 
| Elliott Hughes | 9bf2497 | 2016-10-25 14:13:32 -0700 | [diff] [blame] | 82 | int posix_fallocate(int, off_t, off_t) __RENAME(posix_fallocate64) __INTRODUCED_IN(21); | 
| Elliott Hughes | 68dc20d | 2015-02-06 22:28:49 -0800 | [diff] [blame] | 83 | #else | 
| Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 84 | int fallocate(int, int, off_t, off_t) __INTRODUCED_IN(21); | 
 | 85 | int posix_fadvise(int, off_t, off_t, int) __INTRODUCED_IN(21); | 
 | 86 | int posix_fallocate(int, off_t, off_t) __INTRODUCED_IN(21); | 
| Elliott Hughes | 68dc20d | 2015-02-06 22:28:49 -0800 | [diff] [blame] | 87 | #endif | 
| Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 88 | int fallocate64(int, int, off64_t, off64_t) __INTRODUCED_IN(21); | 
 | 89 | int posix_fadvise64(int, off64_t, off64_t, int) __INTRODUCED_IN(21); | 
 | 90 | int posix_fallocate64(int, off64_t, off64_t) __INTRODUCED_IN(21); | 
| Elliott Hughes | 68dc20d | 2015-02-06 22:28:49 -0800 | [diff] [blame] | 91 |  | 
| Elliott Hughes | 55147ad | 2016-04-05 11:06:02 -0700 | [diff] [blame] | 92 | #if defined(__USE_GNU) | 
| Josh Gao | 46b4416 | 2016-05-27 11:14:16 -0700 | [diff] [blame] | 93 | ssize_t readahead(int, off64_t, size_t) __INTRODUCED_IN(16); | 
| Josh Gao | cb302f9 | 2017-04-20 12:58:31 -0700 | [diff] [blame^] | 94 | int sync_file_range(int, off64_t, off64_t, unsigned int) __INTRODUCED_IN(26); | 
| Elliott Hughes | 55147ad | 2016-04-05 11:06:02 -0700 | [diff] [blame] | 95 | #endif | 
 | 96 |  | 
| Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 97 | int __open_2(const char*, int) __INTRODUCED_IN(17); | 
| Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 98 | int __openat_2(int, const char*, int) __INTRODUCED_IN(17); | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 99 | /* | 
 | 100 |  * These are the easiest way to call the real open even in clang FORTIFY. | 
 | 101 |  */ | 
 | 102 | int __open_real(const char*, int, ...) __RENAME(open); | 
| Elliott Hughes | 3b2096a | 2016-07-22 18:57:12 -0700 | [diff] [blame] | 103 | int __openat_real(int, const char*, int, ...) __RENAME(openat); | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 104 |  | 
| Elliott Hughes | cd0609f | 2013-12-19 12:21:07 -0800 | [diff] [blame] | 105 |  | 
| Dan Albert | 658727e | 2014-10-07 11:10:36 -0700 | [diff] [blame] | 106 | #if defined(__BIONIC_FORTIFY) | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 107 | #define __open_too_many_args_error "too many arguments" | 
 | 108 | #define __open_too_few_args_error "called with O_CREAT, but missing mode" | 
 | 109 | #if defined(__clang__) | 
| Dan Albert | 658727e | 2014-10-07 11:10:36 -0700 | [diff] [blame] | 110 |  | 
| Dan Albert | 9c2094f | 2017-02-14 19:28:18 -0800 | [diff] [blame] | 111 | #if __ANDROID_API__ >= __ANDROID_API_J_MR1__ | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 112 | __BIONIC_ERROR_FUNCTION_VISIBILITY | 
 | 113 | int open(const char* pathname, int flags, mode_t modes, ...) __overloadable | 
 | 114 |         __errorattr(__open_too_many_args_error); | 
 | 115 |  | 
 | 116 | __BIONIC_ERROR_FUNCTION_VISIBILITY | 
 | 117 | int open(const char* pathname, int flags) __overloadable | 
 | 118 |         __enable_if(flags & O_CREAT, __open_too_few_args_error) | 
 | 119 |         __errorattr(__open_too_few_args_error); | 
 | 120 |  | 
 | 121 | /* | 
 | 122 |  * pass_object_size serves two purposes here, neither of which involve __bos: it | 
 | 123 |  * disqualifies this function from having its address taken (so &open works), | 
 | 124 |  * and it makes overload resolution prefer open(const char *, int) over | 
 | 125 |  * open(const char *, int, ...). | 
 | 126 |  */ | 
 | 127 | __BIONIC_FORTIFY_INLINE | 
 | 128 | int open(const char* const __pass_object_size pathname, | 
 | 129 |          int flags) __overloadable { | 
 | 130 |     return __open_2(pathname, flags); | 
 | 131 | } | 
 | 132 |  | 
 | 133 | __BIONIC_FORTIFY_INLINE | 
 | 134 | int open(const char* const __pass_object_size pathname, int flags, mode_t modes) | 
 | 135 |         __overloadable { | 
 | 136 |     return __open_real(pathname, flags, modes); | 
 | 137 | } | 
 | 138 |  | 
 | 139 | __BIONIC_ERROR_FUNCTION_VISIBILITY | 
 | 140 | int openat(int dirfd, const char* pathname, int flags) __overloadable | 
 | 141 |         __enable_if(flags & O_CREAT, __open_too_few_args_error) | 
 | 142 |         __errorattr(__open_too_few_args_error); | 
 | 143 |  | 
 | 144 | __BIONIC_ERROR_FUNCTION_VISIBILITY | 
 | 145 | int openat(int dirfd, const char* pathname, int flags, mode_t modes, ...) | 
 | 146 |         __overloadable | 
 | 147 |         __errorattr(__open_too_many_args_error); | 
 | 148 |  | 
 | 149 | __BIONIC_FORTIFY_INLINE | 
 | 150 | int openat(int dirfd, const char* const __pass_object_size pathname, | 
 | 151 |            int flags) __overloadable { | 
 | 152 |     return __openat_2(dirfd, pathname, flags); | 
 | 153 | } | 
 | 154 |  | 
 | 155 | __BIONIC_FORTIFY_INLINE | 
 | 156 | int openat(int dirfd, const char* const __pass_object_size pathname, int flags, | 
 | 157 |            mode_t modes) __overloadable { | 
 | 158 |     return __openat_real(dirfd, pathname, flags, modes); | 
 | 159 | } | 
| Dan Albert | 9c2094f | 2017-02-14 19:28:18 -0800 | [diff] [blame] | 160 | #endif /* __ANDROID_API__ >= __ANDROID_API_J_MR1__ */ | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 161 |  | 
 | 162 | #else /* defined(__clang__) */ | 
 | 163 | __errordecl(__creat_missing_mode, __open_too_few_args_error); | 
 | 164 | __errordecl(__creat_too_many_args, __open_too_many_args_error); | 
| Nick Kralevich | 8118f62 | 2012-06-26 15:08:06 -0700 | [diff] [blame] | 165 |  | 
| Dan Albert | 9c2094f | 2017-02-14 19:28:18 -0800 | [diff] [blame] | 166 | #if __ANDROID_API__ >= __ANDROID_API_J_MR1__ | 
| Nick Kralevich | 8118f62 | 2012-06-26 15:08:06 -0700 | [diff] [blame] | 167 | __BIONIC_FORTIFY_INLINE | 
| Elliott Hughes | cd0609f | 2013-12-19 12:21:07 -0800 | [diff] [blame] | 168 | int open(const char* pathname, int flags, ...) { | 
| Nick Kralevich | 8118f62 | 2012-06-26 15:08:06 -0700 | [diff] [blame] | 169 |     if (__builtin_constant_p(flags)) { | 
 | 170 |         if ((flags & O_CREAT) && __builtin_va_arg_pack_len() == 0) { | 
| Elliott Hughes | 3ba55f8 | 2016-06-08 18:11:23 -0700 | [diff] [blame] | 171 |             __creat_missing_mode();  /* Compile time error. */ | 
| Nick Kralevich | 8118f62 | 2012-06-26 15:08:06 -0700 | [diff] [blame] | 172 |         } | 
 | 173 |     } | 
 | 174 |  | 
 | 175 |     if (__builtin_va_arg_pack_len() > 1) { | 
| Elliott Hughes | 3ba55f8 | 2016-06-08 18:11:23 -0700 | [diff] [blame] | 176 |         __creat_too_many_args();  /* Compile time error. */ | 
| Nick Kralevich | 8118f62 | 2012-06-26 15:08:06 -0700 | [diff] [blame] | 177 |     } | 
 | 178 |  | 
| Nick Kralevich | a3e230d | 2012-07-02 12:24:42 -0700 | [diff] [blame] | 179 |     if ((__builtin_va_arg_pack_len() == 0) && !__builtin_constant_p(flags)) { | 
| Nick Kralevich | 8118f62 | 2012-06-26 15:08:06 -0700 | [diff] [blame] | 180 |         return __open_2(pathname, flags); | 
 | 181 |     } | 
 | 182 |  | 
 | 183 |     return __open_real(pathname, flags, __builtin_va_arg_pack()); | 
 | 184 | } | 
 | 185 |  | 
| Nick Kralevich | a3e230d | 2012-07-02 12:24:42 -0700 | [diff] [blame] | 186 | __BIONIC_FORTIFY_INLINE | 
| Elliott Hughes | cd0609f | 2013-12-19 12:21:07 -0800 | [diff] [blame] | 187 | int openat(int dirfd, const char* pathname, int flags, ...) { | 
| Nick Kralevich | a3e230d | 2012-07-02 12:24:42 -0700 | [diff] [blame] | 188 |     if (__builtin_constant_p(flags)) { | 
 | 189 |         if ((flags & O_CREAT) && __builtin_va_arg_pack_len() == 0) { | 
| Elliott Hughes | 3ba55f8 | 2016-06-08 18:11:23 -0700 | [diff] [blame] | 190 |             __creat_missing_mode();  /* Compile time error. */ | 
| Nick Kralevich | a3e230d | 2012-07-02 12:24:42 -0700 | [diff] [blame] | 191 |         } | 
 | 192 |     } | 
 | 193 |  | 
 | 194 |     if (__builtin_va_arg_pack_len() > 1) { | 
| Elliott Hughes | 3ba55f8 | 2016-06-08 18:11:23 -0700 | [diff] [blame] | 195 |         __creat_too_many_args();  /* Compile time error. */ | 
| Nick Kralevich | a3e230d | 2012-07-02 12:24:42 -0700 | [diff] [blame] | 196 |     } | 
 | 197 |  | 
 | 198 |     if ((__builtin_va_arg_pack_len() == 0) && !__builtin_constant_p(flags)) { | 
 | 199 |         return __openat_2(dirfd, pathname, flags); | 
 | 200 |     } | 
 | 201 |  | 
 | 202 |     return __openat_real(dirfd, pathname, flags, __builtin_va_arg_pack()); | 
 | 203 | } | 
| Dan Albert | 9c2094f | 2017-02-14 19:28:18 -0800 | [diff] [blame] | 204 | #endif /* __ANDROID_API__ >= __ANDROID_API_J_MR1__ */ | 
| Nick Kralevich | a3e230d | 2012-07-02 12:24:42 -0700 | [diff] [blame] | 205 |  | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 206 | #endif /* defined(__clang__) */ | 
| Elliott Hughes | cd0609f | 2013-12-19 12:21:07 -0800 | [diff] [blame] | 207 |  | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 208 | #undef __open_too_many_args_error | 
 | 209 | #undef __open_too_few_args_error | 
| Elliott Hughes | cd0609f | 2013-12-19 12:21:07 -0800 | [diff] [blame] | 210 | #endif /* defined(__BIONIC_FORTIFY) */ | 
| Nick Kralevich | 8118f62 | 2012-06-26 15:08:06 -0700 | [diff] [blame] | 211 |  | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 212 | __END_DECLS | 
 | 213 |  | 
 | 214 | #endif /* _FCNTL_H */ |