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 */ 28 29 #pragma once 30 #define _FCNTL_H 31 32 /** 33 * @file fcntl.h 34 * @brief File control operations. 35 */ 36 37 #include <sys/cdefs.h> 38 #include <sys/types.h> 39 #include <linux/fadvise.h> 40 #include <linux/falloc.h> 41 #include <linux/fcntl.h> 42 #include <linux/stat.h> 43 #include <linux/uio.h> 44 45 #include <bits/fcntl.h> 46 #include <bits/seek_constants.h> 47 48 #if defined(__USE_GNU) || defined(__USE_BSD) 49 #include <bits/lockf.h> 50 #endif 51 52 __BEGIN_DECLS 53 54 #if defined(__LP64__) 55 56 /* LP64 kernels don't have F_*64 defines because their flock is 64-bit. */ 57 58 /** Flag for flock(). */ 59 #define F_GETLK64 F_GETLK 60 /** Flag for flock(). */ 61 #define F_SETLK64 F_SETLK 62 /** Flag for flock(). */ 63 #define F_SETLKW64 F_SETLKW 64 65 #elif defined(__USE_FILE_OFFSET64) 66 67 /* For _FILE_OFFSET_BITS=64, redirect the constants to the off64_t variants. */ 68 69 #undef F_GETLK 70 #undef F_SETLK 71 #undef F_SETLKW 72 73 /** Flag for flock(). */ 74 #define F_GETLK F_GETLK64 75 /** Flag for flock(). */ 76 #define F_SETLK F_SETLK64 77 /** Flag for flock(). */ 78 #define F_SETLKW F_SETLKW64 79 80 #endif 81 82 /** Flag for open(). */ 83 #define O_ASYNC FASYNC 84 /** Flag for open(). */ 85 #define O_RSYNC O_SYNC 86 87 /** Flag for splice(). */ 88 #define SPLICE_F_MOVE 1 89 /** Flag for splice(). */ 90 #define SPLICE_F_NONBLOCK 2 91 /** Flag for splice(). */ 92 #define SPLICE_F_MORE 4 93 /** Flag for splice(). */ 94 #define SPLICE_F_GIFT 8 95 96 #if __ANDROID_API__ >= 26 97 /** Flag for sync_file_range(). */ 98 #define SYNC_FILE_RANGE_WAIT_BEFORE 1 99 /** Flag for sync_file_range(). */ 100 #define SYNC_FILE_RANGE_WRITE 2 101 /** Flag for sync_file_range(). */ 102 #define SYNC_FILE_RANGE_WAIT_AFTER 4 103 #endif 104 105 /** 106 * [creat(2)](http://man7.org/linux/man-pages/man2/creat.2.html) 107 * creates a file. 108 * 109 * Returns a new file descriptor on success and returns -1 and sets `errno` on 110 * failure. 111 */ 112 int creat(const char* _Nonnull __path, mode_t __mode); 113 /** See creat(). */ 114 int creat64(const char* _Nonnull __path, mode_t __mode) __INTRODUCED_IN(21); 115 116 /** 117 * [openat(2)](http://man7.org/linux/man-pages/man2/openat.2.html) 118 * opens (and possibly creates) a file. 119 * 120 * Returns a new file descriptor on success and returns -1 and sets `errno` on 121 * failure. 122 */ 123 int openat(int __dir_fd, const char* _Nonnull __path, int __flags, ...); 124 /** See openat(). */ 125 int openat64(int __dir_fd, const char* _Nonnull __path, int __flags, ...) __INTRODUCED_IN(21); 126 127 /** 128 * [open(2)](http://man7.org/linux/man-pages/man2/open.2.html) 129 * opens (and possibly creates) a file. 130 * 131 * Returns a new file descriptor on success and returns -1 and sets `errno` on 132 * failure. 133 */ 134 int open(const char* _Nonnull __path, int __flags, ...); 135 /** See open(). */ 136 int open64(const char* _Nonnull __path, int __flags, ...) __INTRODUCED_IN(21); 137 138 /** 139 * [splice(2)](http://man7.org/linux/man-pages/man2/splice.2.html) 140 * splices data to/from a pipe. 141 * 142 * Valid flags are `SPLICE_F_MOVE`, `SPLICE_F_NONBLOCK`, `SPLICE_F_MORE`, and 143 * `SPLICE_F_GIFT`. 144 * 145 * Returns the number of bytes spliced on success and returns -1 and sets 146 * `errno` on failure. 147 * 148 * Available since API level 21. 149 */ 150 ssize_t splice(int __in_fd, off64_t* __BIONIC_COMPLICATED_NULLNESS __in_offset, int __out_fd, off64_t* __BIONIC_COMPLICATED_NULLNESS __out_offset, size_t __length, unsigned int __flags) __INTRODUCED_IN(21); 151 152 /** 153 * [tee(2)](http://man7.org/linux/man-pages/man2/tee.2.html) 154 * duplicates data from one pipe to another. 155 * 156 * Valid flags are `SPLICE_F_MOVE`, `SPLICE_F_NONBLOCK`, `SPLICE_F_MORE`, and 157 * `SPLICE_F_GIFT`. 158 * 159 * Returns the number of bytes duplicated on success and returns -1 and sets 160 * `errno` on failure. 161 * 162 * Available since API level 21. 163 */ 164 ssize_t tee(int __in_fd, int __out_fd, size_t __length, unsigned int __flags) __INTRODUCED_IN(21); 165 166 /** 167 * [vmsplice(2)](http://man7.org/linux/man-pages/man2/vmsplice.2.html) 168 * splices data to/from a pipe. 169 * 170 * Valid flags are `SPLICE_F_MOVE`, `SPLICE_F_NONBLOCK`, `SPLICE_F_MORE`, and 171 * `SPLICE_F_GIFT`. 172 * 173 * Returns the number of bytes spliced on success and returns -1 and sets 174 * `errno` on failure. 175 * 176 * Available since API level 21. 177 */ 178 ssize_t vmsplice(int __fd, const struct iovec* _Nonnull __iov, size_t __count, unsigned int __flags) __INTRODUCED_IN(21); 179 180 /** 181 * [fallocate(2)](http://man7.org/linux/man-pages/man2/fallocate.2.html) 182 * is a Linux-specific extension of posix_fallocate(). 183 * 184 * Valid flags are `FALLOC_FL_KEEP_SIZE`, `FALLOC_FL_PUNCH_HOLE`, 185 * `FALLOC_FL_NO_HIDE_STALE`, `FALLOC_FL_COLLAPSE_RANGE`, 186 * `FALLOC_FL_ZERO_RANGE`, `FALLOC_FL_INSERT_RANGE`, and 187 * `FALLOC_FL_UNSHARE_RANGE`. 188 * 189 * Returns 0 on success and returns -1 and sets `errno` on failure. 190 * 191 * Available since API level 21. 192 */ 193 int fallocate(int __fd, int __mode, off_t __offset, off_t __length) __RENAME_IF_FILE_OFFSET64(fallocate64) __INTRODUCED_IN(21); 194 /** See fallocate(). */ 195 int fallocate64(int __fd, int __mode, off64_t __offset, off64_t __length) __INTRODUCED_IN(21); 196 197 /** 198 * [posix_fadvise(2)](http://man7.org/linux/man-pages/man2/posix_fadvise.2.html) 199 * declares an expected access pattern for file data. 200 * 201 * Valid flags are `POSIX_FADV_NORMAL`, `POSIX_FADV_RANDOM`, 202 * `POSIX_FADV_SEQUENTIAL`, `POSIX_FADV_WILLNEED`, `POSIX_FADV_DONTNEED`, 203 * and `POSIX_FADV_NOREUSE`. 204 * 205 * Returns 0 on success and returns an error number on failure. 206 * 207 * Available since API level 21. 208 */ 209 int posix_fadvise(int __fd, off_t __offset, off_t __length, int __advice) __RENAME_IF_FILE_OFFSET64(posix_fadvise64) __INTRODUCED_IN(21); 210 /** See posix_fadvise(). */ 211 int posix_fadvise64(int __fd, off64_t __offset, off64_t __length, int __advice) __INTRODUCED_IN(21); 212 213 /** 214 * [posix_fallocate(2)](http://man7.org/linux/man-pages/man2/posix_fallocate.2.html) 215 * allocates file space. 216 * 217 * Returns 0 on success and returns an error number on failure. 218 * 219 * Available since API level 21. 220 */ 221 int posix_fallocate(int __fd, off_t __offset, off_t __length) __RENAME_IF_FILE_OFFSET64(posix_fallocate64) __INTRODUCED_IN(21); 222 /** See posix_fallocate(). */ 223 int posix_fallocate64(int __fd, off64_t __offset, off64_t __length) __INTRODUCED_IN(21); 224 225 #if defined(__USE_GNU) 226 227 /** 228 * [readahead(2)](http://man7.org/linux/man-pages/man2/readahead.2.html) 229 * initiates readahead for the given file. 230 * 231 * Returns 0 on success and returns -1 and sets `errno` on failure. 232 */ 233 ssize_t readahead(int __fd, off64_t __offset, size_t __length); 234 235 /** 236 * [sync_file_range(2)](http://man7.org/linux/man-pages/man2/sync_file_range.2.html) 237 * syncs part of a file with disk. 238 * 239 * Valid flags are `SYNC_FILE_RANGE_WAIT_BEFORE`, `SYNC_FILE_RANGE_WRITE`, and 240 * `SYNC_FILE_RANGE_WAIT_AFTER`. 241 * 242 * Returns 0 on success and returns -1 and sets `errno` on failure. 243 */ 244 int sync_file_range(int __fd, off64_t __offset, off64_t __length, unsigned int __flags) __INTRODUCED_IN(26); 245 246 #endif 247 248 #if defined(__BIONIC_INCLUDE_FORTIFY_HEADERS) 249 #include <bits/fortify/fcntl.h> 250 #endif 251 252 __END_DECLS 253