1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.system; 18 19 import static android.annotation.SystemApi.Client.MODULE_LIBRARIES; 20 21 import android.annotation.SystemApi; 22 import android.compat.annotation.UnsupportedAppUsage; 23 24 import libcore.io.Libcore; 25 import libcore.util.NonNull; 26 import libcore.util.Nullable; 27 28 import java.io.FileDescriptor; 29 import java.io.InterruptedIOException; 30 import java.net.InetAddress; 31 import java.net.InetSocketAddress; 32 import java.net.SocketAddress; 33 import java.net.SocketException; 34 import java.nio.ByteBuffer; 35 36 /** 37 * Access to low-level system functionality. Most of these are system calls. Most users will want 38 * to use higher-level APIs where available, but this class provides access to the underlying 39 * primitives used to implement the higher-level APIs. 40 * 41 * <p>The corresponding constants can be found in {@link OsConstants}. 42 */ 43 public final class Os { Os()44 private Os() {} 45 46 // Ideally we'd just have the version that accepts SocketAddress but we're stuck with 47 // this one for legacy reasons. http://b/123568439 48 /** 49 * See <a href="http://man7.org/linux/man-pages/man2/accept.2.html">accept(2)</a>. 50 */ accept(FileDescriptor fd, InetSocketAddress peerAddress)51 public static FileDescriptor accept(FileDescriptor fd, InetSocketAddress peerAddress) throws ErrnoException, SocketException { return accept(fd, (SocketAddress) peerAddress); } 52 53 /** 54 * See <a href="http://man7.org/linux/man-pages/man2/accept.2.html">accept(2)</a>. 55 * @hide 56 */ accept(FileDescriptor fd, SocketAddress peerAddress)57 public static FileDescriptor accept(FileDescriptor fd, SocketAddress peerAddress) throws ErrnoException, SocketException { return Libcore.os.accept(fd, peerAddress); } 58 59 /** 60 * See <a href="http://man7.org/linux/man-pages/man2/access.2.html">access(2)</a>. 61 */ access(String path, int mode)62 public static boolean access(String path, int mode) throws ErrnoException { return Libcore.os.access(path, mode); } 63 64 /** @hide */ android_getaddrinfo(String node, StructAddrinfo hints, int netId)65 public static InetAddress[] android_getaddrinfo(String node, StructAddrinfo hints, int netId) throws GaiException { return Libcore.os.android_getaddrinfo(node, hints, netId); } 66 67 /** 68 * See <a href="http://man7.org/linux/man-pages/man2/bind.2.html">bind(2)</a>. 69 */ bind(FileDescriptor fd, InetAddress address, int port)70 public static void bind(FileDescriptor fd, InetAddress address, int port) throws ErrnoException, SocketException { Libcore.os.bind(fd, address, port); } 71 72 /** 73 * See <a href="http://man7.org/linux/man-pages/man2/bind.2.html">bind(2)</a>. 74 */ bind(@onNull FileDescriptor fd, @NonNull SocketAddress address)75 public static void bind(@NonNull FileDescriptor fd, @NonNull SocketAddress address) throws ErrnoException, SocketException { Libcore.os.bind(fd, address); } 76 77 /** 78 * See <a href="http://man7.org/linux/man-pages/man2/capget.2.html">capget(2)</a>. 79 * 80 * @param hdr capabilities header, containing version and pid 81 * @return list of capabilities data structures, each containing effective, permitted, 82 * and inheritable fields are bit masks of the capabilities 83 * @throws ErrnoException if {@code hdr} structure contains invalid data 84 * 85 * @hide 86 */ 87 @SystemApi(client = MODULE_LIBRARIES) capget(@onNull StructCapUserHeader hdr)88 public static @Nullable StructCapUserData[] capget(@NonNull StructCapUserHeader hdr) throws ErrnoException { 89 return Libcore.os.capget(hdr); 90 } 91 92 /** 93 * See <a href="http://man7.org/linux/man-pages/man2/capset.2.html">capset(2)</a>. 94 * 95 * @param hdr capabilities header, containing version and pid 96 * @param data capabilities data list, containing effective, permitted, 97 * and inheritable fields. Must be the same length as returned value 98 * @throws ErrnoException if {@code hdr} structure contains invalid data; or 99 * an attempt was made to add a capability to the permitted 100 * set, or to set a capability in the effective set that is 101 * not in the permitted set; or 102 * the caller attempted to use 103 * {@link capset(StructCapUserHeader, StructCapUserData[])} 104 * to modify the capabilities of a thread other than itself, 105 * but lacked sufficient privilege; 106 * or there is no such thread. 107 * 108 * @hide 109 */ 110 @SystemApi(client = MODULE_LIBRARIES) capset(@onNull StructCapUserHeader hdr, @NonNull StructCapUserData[] data)111 public static void capset(@NonNull StructCapUserHeader hdr, @NonNull StructCapUserData[] data) 112 throws ErrnoException { 113 Libcore.os.capset(hdr, data); 114 } 115 116 /** 117 * See <a href="http://man7.org/linux/man-pages/man2/chmod.2.html">chmod(2)</a>. 118 */ chmod(String path, int mode)119 public static void chmod(String path, int mode) throws ErrnoException { Libcore.os.chmod(path, mode); } 120 121 /** 122 * See <a href="http://man7.org/linux/man-pages/man2/chown.2.html">chown(2)</a>. 123 */ chown(String path, int uid, int gid)124 public static void chown(String path, int uid, int gid) throws ErrnoException { Libcore.os.chown(path, uid, gid); } 125 126 /** 127 * See <a href="http://man7.org/linux/man-pages/man2/close.2.html">close(2)</a>. 128 */ close(FileDescriptor fd)129 public static void close(FileDescriptor fd) throws ErrnoException { Libcore.os.close(fd); } 130 131 /** 132 * See <a href="http://man7.org/linux/man-pages/man2/connect.2.html">connect(2)</a>. 133 */ connect(FileDescriptor fd, InetAddress address, int port)134 public static void connect(FileDescriptor fd, InetAddress address, int port) throws ErrnoException, SocketException { Libcore.os.connect(fd, address, port); } 135 136 /** 137 * See <a href="http://man7.org/linux/man-pages/man2/connect.2.html">connect(2)</a>. 138 */ connect(@onNull FileDescriptor fd, @NonNull SocketAddress address)139 public static void connect(@NonNull FileDescriptor fd, @NonNull SocketAddress address) throws ErrnoException, SocketException { Libcore.os.connect(fd, address); } 140 141 /** 142 * See <a href="http://man7.org/linux/man-pages/man2/dup.2.html">dup(2)</a>. 143 */ dup(FileDescriptor oldFd)144 public static FileDescriptor dup(FileDescriptor oldFd) throws ErrnoException { return Libcore.os.dup(oldFd); } 145 146 /** 147 * See <a href="http://man7.org/linux/man-pages/man2/dup2.2.html">dup2(2)</a>. 148 */ dup2(FileDescriptor oldFd, int newFd)149 public static FileDescriptor dup2(FileDescriptor oldFd, int newFd) throws ErrnoException { return Libcore.os.dup2(oldFd, newFd); } 150 151 /** 152 * See <a href="http://man7.org/linux/man-pages/man3/environ.3.html">environ(3)</a>. 153 */ environ()154 public static String[] environ() { return Libcore.os.environ(); } 155 156 /** 157 * See <a href="https://man7.org/linux/man-pages/man3/execv.3.html">exec(3)</a>. 158 */ execv(String filename, String[] argv)159 public static void execv(String filename, String[] argv) throws ErrnoException { Libcore.os.execv(filename, argv); } 160 161 /** 162 * See <a href="http://man7.org/linux/man-pages/man2/execve.2.html">execve(2)</a>. 163 */ execve(String filename, String[] argv, String[] envp)164 public static void execve(String filename, String[] argv, String[] envp) throws ErrnoException { Libcore.os.execve(filename, argv, envp); } 165 166 /** 167 * See <a href="http://man7.org/linux/man-pages/man2/fchmod.2.html">fchmod(2)</a>. 168 */ fchmod(FileDescriptor fd, int mode)169 public static void fchmod(FileDescriptor fd, int mode) throws ErrnoException { Libcore.os.fchmod(fd, mode); } 170 171 /** 172 * See <a href="http://man7.org/linux/man-pages/man2/fchown.2.html">fchown(2)</a>. 173 */ fchown(FileDescriptor fd, int uid, int gid)174 public static void fchown(FileDescriptor fd, int uid, int gid) throws ErrnoException { Libcore.os.fchown(fd, uid, gid); } 175 176 /** 177 * See <a href="http://man7.org/linux/man-pages/man2/fcntl.2.html">fcntl(2)</a>. 178 */ fcntlInt(@onNull FileDescriptor fd, int cmd, int arg)179 public static int fcntlInt(@NonNull FileDescriptor fd, int cmd, int arg) throws ErrnoException { return Libcore.os.fcntlInt(fd, cmd, arg); } 180 181 /** @hide */ fcntlVoid(FileDescriptor fd, int cmd)182 public static int fcntlVoid(FileDescriptor fd, int cmd) throws ErrnoException { return Libcore.os.fcntlVoid(fd, cmd); } 183 184 /** 185 * See <a href="http://man7.org/linux/man-pages/man2/fdatasync.2.html">fdatasync(2)</a>. 186 */ fdatasync(FileDescriptor fd)187 public static void fdatasync(FileDescriptor fd) throws ErrnoException { Libcore.os.fdatasync(fd); } 188 189 /** 190 * See <a href="http://man7.org/linux/man-pages/man2/fstat.2.html">fstat(2)</a>. 191 */ fstat(FileDescriptor fd)192 public static StructStat fstat(FileDescriptor fd) throws ErrnoException { return Libcore.os.fstat(fd); } 193 194 /** 195 * See <a href="http://man7.org/linux/man-pages/man2/fstatvfs.2.html">fstatvfs(2)</a>. 196 */ fstatvfs(FileDescriptor fd)197 public static StructStatVfs fstatvfs(FileDescriptor fd) throws ErrnoException { return Libcore.os.fstatvfs(fd); } 198 199 /** 200 * See <a href="http://man7.org/linux/man-pages/man2/fsync.2.html">fsync(2)</a>. 201 */ fsync(FileDescriptor fd)202 public static void fsync(FileDescriptor fd) throws ErrnoException { Libcore.os.fsync(fd); } 203 204 /** 205 * See <a href="http://man7.org/linux/man-pages/man2/ftruncate.2.html">ftruncate(2)</a>. 206 */ ftruncate(FileDescriptor fd, long length)207 public static void ftruncate(FileDescriptor fd, long length) throws ErrnoException { Libcore.os.ftruncate(fd, length); } 208 209 /** 210 * See <a href="http://man7.org/linux/man-pages/man3/gai_strerror.3.html">gai_strerror(3)</a>. 211 */ gai_strerror(int error)212 public static String gai_strerror(int error) { return Libcore.os.gai_strerror(error); } 213 214 /** 215 * See <a href="http://man7.org/linux/man-pages/man2/getegid.2.html">getegid(2)</a>. 216 */ getegid()217 public static int getegid() { return Libcore.os.getegid(); } 218 219 /** 220 * See <a href="http://man7.org/linux/man-pages/man2/geteuid.2.html">geteuid(2)</a>. 221 */ geteuid()222 public static int geteuid() { return Libcore.os.geteuid(); } 223 224 /** 225 * See <a href="http://man7.org/linux/man-pages/man2/getgid.2.html">getgid(2)</a>. 226 */ getgid()227 public static int getgid() { return Libcore.os.getgid(); } 228 229 /** 230 * See <a href="http://man7.org/linux/man-pages/man3/getenv.3.html">getenv(3)</a>. 231 */ getenv(String name)232 public static String getenv(String name) { return Libcore.os.getenv(name); } 233 234 /** 235 * See <a href="http://man7.org/linux/man-pages/man3/getifaddrs.3.html">getifaddrs(3)</a>. 236 * @hide 237 */ getifaddrs()238 public static StructIfaddrs[] getifaddrs() throws ErrnoException { return Libcore.os.getifaddrs(); } 239 240 /** @hide */ getnameinfo(InetAddress address, int flags)241 public static String getnameinfo(InetAddress address, int flags) throws GaiException { return Libcore.os.getnameinfo(address, flags); } 242 243 /** 244 * See <a href="http://man7.org/linux/man-pages/man2/getpeername.2.html">getpeername(2)</a>. 245 */ getpeername(FileDescriptor fd)246 public static SocketAddress getpeername(FileDescriptor fd) throws ErrnoException { return Libcore.os.getpeername(fd); } 247 248 /** 249 * Gets process's pgid (process group ID). 250 * 251 * See <a href="http://man7.org/linux/man-pages/man2/getpgid.2.html">getpgid(2)</a>. 252 * 253 * @param pid process id to get the pgid of 254 * @return process's pgid 255 * @throws ErrnoException if {@code pid} does not match any process 256 * 257 * @hide 258 */ 259 @SystemApi(client = MODULE_LIBRARIES) getpgid(int pid)260 public static int getpgid(int pid) throws ErrnoException { return Libcore.os.getpgid(pid); } 261 262 /** 263 * See <a href="http://man7.org/linux/man-pages/man2/getpid.2.html">getpid(2)</a>. 264 */ getpid()265 public static int getpid() { return Libcore.os.getpid(); } 266 267 /** 268 * See <a href="http://man7.org/linux/man-pages/man2/getppid.2.html">getppid(2)</a>. 269 */ getppid()270 public static int getppid() { return Libcore.os.getppid(); } 271 272 /** @hide */ getpwnam(String name)273 public static StructPasswd getpwnam(String name) throws ErrnoException { return Libcore.os.getpwnam(name); } 274 275 /** @hide */ getpwuid(int uid)276 public static StructPasswd getpwuid(int uid) throws ErrnoException { return Libcore.os.getpwuid(uid); } 277 278 /** 279 * Gets the resource limit. 280 * 281 * See <a href="https://man7.org/linux/man-pages/man3/vlimit.3.html">getrlimit(2)</a>. 282 * 283 * @param resource resource id 284 * @return the limit of the given resource 285 * @throws ErrnoException the value specified in {@code resource} is not valid 286 * 287 * @hide 288 */ 289 @SystemApi(client = MODULE_LIBRARIES) getrlimit(int resource)290 public static @Nullable StructRlimit getrlimit(int resource) throws ErrnoException { return Libcore.os.getrlimit(resource); } 291 292 /** 293 * See <a href="http://man7.org/linux/man-pages/man2/getsockname.2.html">getsockname(2)</a>. 294 */ getsockname(FileDescriptor fd)295 public static SocketAddress getsockname(FileDescriptor fd) throws ErrnoException { return Libcore.os.getsockname(fd); } 296 297 /** @hide */ getsockoptByte(FileDescriptor fd, int level, int option)298 public static int getsockoptByte(FileDescriptor fd, int level, int option) throws ErrnoException { return Libcore.os.getsockoptByte(fd, level, option); } 299 300 /** @hide */ getsockoptInAddr(FileDescriptor fd, int level, int option)301 public static InetAddress getsockoptInAddr(FileDescriptor fd, int level, int option) throws ErrnoException { return Libcore.os.getsockoptInAddr(fd, level, option); } 302 303 /** 304 * Gets socket options for the socket referred to by the file descriptor {@code fd}. 305 * 306 * See <a href="https://man7.org/linux/man-pages/man2/getsockopt.2.html">getsockopt(2)</a>. 307 * For the list of available options see <a href="https://man7.org/linux/man-pages/man7/socket.7.html">socket(7)</a>. 308 * 309 * @param fd file descriptor of the socket to get options of 310 * @param level level at which the {@code option} resides. For example, 311 * to indicate that an option is to be interpreted by the TCP protocol, 312 * level should be set to the protocol number of TCP 313 * @param option name of the option to get 314 * @return socket options for file descriptor {@code fd} 315 * @throws ErrnoException if {@code fd} is invalid; or 316 * {@code option} is unknown at given {@code level} 317 * 318 * @hide 319 */ 320 @SystemApi(client = MODULE_LIBRARIES) getsockoptInt(@onNull FileDescriptor fd, int level, int option)321 public static int getsockoptInt(@NonNull FileDescriptor fd, int level, int option) throws ErrnoException { return Libcore.os.getsockoptInt(fd, level, option); } 322 323 /** 324 * Gets {@link OsConstants#SO_LINGER} option for the socket referred to by the file descriptor {@code fd}. 325 * When enabled, a {@link close(FileDescriptor) or {@link shutdown(FileDescriptor, int)} will 326 * not return until all queued messages for the socket have been successfully sent or the 327 * linger timeout has been reached. Otherwise, the call returns immediately and the closing is 328 * done in the background. 329 * 330 * See <a href="https://man7.org/linux/man-pages/man7/socket.7.html">socket(7)</a>. 331 * 332 * @param fd file descriptor of the socket to get {@code OsConstants.SO_LINGER} option of 333 * @param level level at which the {@code option} resides 334 * @param option name of the option to get 335 * @return {@link StructLinger} associated with given {@code fd} 336 * @throws ErrnoException 337 * 338 * @hide 339 */ 340 @SystemApi(client = MODULE_LIBRARIES) getsockoptLinger(@onNull FileDescriptor fd, int level, int option)341 public static @Nullable StructLinger getsockoptLinger(@NonNull FileDescriptor fd, int level, int option) throws ErrnoException { return Libcore.os.getsockoptLinger(fd, level, option); } 342 343 /** 344 * See <a href="http://man7.org/linux/man-pages/man2/setsockopt.2.html">getsockopt(2)</a>. 345 * 346 * <p>Only for use with {@code option} values that return a {@code struct timeval} such as 347 * {@link OsConstants#SO_RCVTIMEO} and {@link OsConstants#SO_SNDTIMEO}. Use with other 348 * options may throw an {@code IllegalArgumentException} or return junk values. 349 */ getsockoptTimeval(@onNull FileDescriptor fd, int level, int option)350 public static @NonNull StructTimeval getsockoptTimeval(@NonNull FileDescriptor fd, int level, int option) throws ErrnoException { return Libcore.os.getsockoptTimeval(fd, level, option); } 351 352 /** @hide */ getsockoptUcred(FileDescriptor fd, int level, int option)353 public static StructUcred getsockoptUcred(FileDescriptor fd, int level, int option) throws ErrnoException { return Libcore.os.getsockoptUcred(fd, level, option); } 354 355 /** 356 * See <a href="http://man7.org/linux/man-pages/man2/gettid.2.html">gettid(2)</a>. 357 */ gettid()358 public static int gettid() { return Libcore.os.gettid(); } 359 360 /** 361 * See <a href="http://man7.org/linux/man-pages/man2/getuid.2.html">getuid(2)</a>. 362 */ getuid()363 public static int getuid() { return Libcore.os.getuid(); } 364 365 /** 366 * See <a href="http://man7.org/linux/man-pages/man2/getxattr.2.html">getxattr(2)</a> 367 */ getxattr(String path, String name)368 public static byte[] getxattr(String path, String name) throws ErrnoException { return Libcore.os.getxattr(path, name); } 369 370 /** 371 * See <a href="http://man7.org/linux/man-pages/man3/if_indextoname.3.html">if_indextoname(3)</a>. 372 */ if_indextoname(int index)373 public static String if_indextoname(int index) { return Libcore.os.if_indextoname(index); } 374 375 /** 376 * See <a href="http://man7.org/linux/man-pages/man3/if_nametoindex.3.html">if_nametoindex(3)</a>. 377 */ if_nametoindex(String name)378 public static int if_nametoindex(String name) { return Libcore.os.if_nametoindex(name); } 379 380 /** 381 * See <a href="http://man7.org/linux/man-pages/man3/inet_pton.3.html">inet_pton(3)</a>. 382 */ inet_pton(int family, String address)383 public static InetAddress inet_pton(int family, String address) { return Libcore.os.inet_pton(family, address); } 384 385 /** @hide */ ioctlInetAddress(FileDescriptor fd, int cmd, String interfaceName)386 public static InetAddress ioctlInetAddress(FileDescriptor fd, int cmd, String interfaceName) throws ErrnoException { return Libcore.os.ioctlInetAddress(fd, cmd, interfaceName); } 387 388 /** 389 * See <a href="https://man7.org/linux/man-pages/man2/ioctl.2.html">ioctl(3)</a>. 390 * System call manipulates the underlying device parameters of special files. In particular, 391 * many operating characteristics of character special files. 392 * 393 * @param fd an open file descriptor 394 * @param cmd encoded in it whether the argument is an "in" parameter or "out" parameter 395 * @return returns a nonnegative value on success 396 * @throws ErrnoException A checked exception thrown when {@link Os} methods fail. 397 * {@see android.system.ErrnoException} 398 * 399 * @hide 400 */ 401 @SystemApi(client = MODULE_LIBRARIES) ioctlInt(@onNull FileDescriptor fd, int cmd)402 public static int ioctlInt(@NonNull FileDescriptor fd, int cmd) throws ErrnoException { 403 return Libcore.os.ioctlInt(fd, cmd); 404 } 405 406 /** 407 * See <a href="http://man7.org/linux/man-pages/man3/isatty.3.html">isatty(3)</a>. 408 */ isatty(FileDescriptor fd)409 public static boolean isatty(FileDescriptor fd) { return Libcore.os.isatty(fd); } 410 411 /** 412 * See <a href="http://man7.org/linux/man-pages/man2/kill.2.html">kill(2)</a>. 413 */ kill(int pid, int signal)414 public static void kill(int pid, int signal) throws ErrnoException { Libcore.os.kill(pid, signal); } 415 416 /** 417 * See <a href="http://man7.org/linux/man-pages/man2/lchown.2.html">lchown(2)</a>. 418 */ lchown(String path, int uid, int gid)419 public static void lchown(String path, int uid, int gid) throws ErrnoException { Libcore.os.lchown(path, uid, gid); } 420 421 /** 422 * See <a href="http://man7.org/linux/man-pages/man2/link.2.html">link(2)</a>. 423 */ link(String oldPath, String newPath)424 public static void link(String oldPath, String newPath) throws ErrnoException { Libcore.os.link(oldPath, newPath); } 425 426 /** 427 * See <a href="http://man7.org/linux/man-pages/man2/listen.2.html">listen(2)</a>. 428 */ listen(FileDescriptor fd, int backlog)429 public static void listen(FileDescriptor fd, int backlog) throws ErrnoException { Libcore.os.listen(fd, backlog); } 430 431 /** 432 * See <a href="http://man7.org/linux/man-pages/man2/listxattr.2.html">listxattr(2)</a> 433 */ listxattr(String path)434 public static String[] listxattr(String path) throws ErrnoException { return Libcore.os.listxattr(path); } 435 436 /** 437 * See <a href="http://man7.org/linux/man-pages/man2/lseek.2.html">lseek(2)</a>. 438 */ lseek(FileDescriptor fd, long offset, int whence)439 public static long lseek(FileDescriptor fd, long offset, int whence) throws ErrnoException { return Libcore.os.lseek(fd, offset, whence); } 440 441 /** 442 * See <a href="http://man7.org/linux/man-pages/man2/lstat.2.html">lstat(2)</a>. 443 */ lstat(String path)444 public static StructStat lstat(String path) throws ErrnoException { return Libcore.os.lstat(path); } 445 446 /** 447 * See <a href="http://man7.org/linux/man-pages/man2/memfd_create.2.html">memfd_create(2)</a>. 448 */ memfd_create(@onNull String name, int flags)449 public static @NonNull FileDescriptor memfd_create(@NonNull String name, int flags) throws ErrnoException { return Libcore.os.memfd_create(name, flags); } 450 451 /** 452 * See <a href="http://man7.org/linux/man-pages/man2/mincore.2.html">mincore(2)</a>. 453 */ mincore(long address, long byteCount, byte[] vector)454 public static void mincore(long address, long byteCount, byte[] vector) throws ErrnoException { Libcore.os.mincore(address, byteCount, vector); } 455 456 /** 457 * See <a href="http://man7.org/linux/man-pages/man2/mkdir.2.html">mkdir(2)</a>. 458 */ mkdir(String path, int mode)459 public static void mkdir(String path, int mode) throws ErrnoException { Libcore.os.mkdir(path, mode); } 460 461 /** 462 * See <a href="http://man7.org/linux/man-pages/man3/mkfifo.3.html">mkfifo(3)</a>. 463 */ mkfifo(String path, int mode)464 public static void mkfifo(String path, int mode) throws ErrnoException { Libcore.os.mkfifo(path, mode); } 465 466 /** 467 * See <a href="http://man7.org/linux/man-pages/man2/mlock.2.html">mlock(2)</a>. 468 */ mlock(long address, long byteCount)469 public static void mlock(long address, long byteCount) throws ErrnoException { Libcore.os.mlock(address, byteCount); } 470 471 /** 472 * See <a href="http://man7.org/linux/man-pages/man2/mmap.2.html">mmap(2)</a>. 473 */ mmap(long address, long byteCount, int prot, int flags, FileDescriptor fd, long offset)474 public static long mmap(long address, long byteCount, int prot, int flags, FileDescriptor fd, long offset) throws ErrnoException { return Libcore.os.mmap(address, byteCount, prot, flags, fd, offset); } 475 476 /** 477 * See <a href="http://man7.org/linux/man-pages/man2/msync.2.html">msync(2)</a>. 478 */ msync(long address, long byteCount, int flags)479 public static void msync(long address, long byteCount, int flags) throws ErrnoException { Libcore.os.msync(address, byteCount, flags); } 480 481 /** 482 * See <a href="http://man7.org/linux/man-pages/man2/munlock.2.html">munlock(2)</a>. 483 */ munlock(long address, long byteCount)484 public static void munlock(long address, long byteCount) throws ErrnoException { Libcore.os.munlock(address, byteCount); } 485 486 /** 487 * See <a href="http://man7.org/linux/man-pages/man2/munmap.2.html">munmap(2)</a>. 488 */ munmap(long address, long byteCount)489 public static void munmap(long address, long byteCount) throws ErrnoException { Libcore.os.munmap(address, byteCount); } 490 491 /** 492 * See <a href="http://man7.org/linux/man-pages/man2/open.2.html">open(2)</a>. 493 */ open(String path, int flags, int mode)494 public static FileDescriptor open(String path, int flags, int mode) throws ErrnoException { return Libcore.os.open(path, flags, mode); } 495 496 /** 497 * See <a href="http://man7.org/linux/man-pages/man2/pipe.2.html">pipe(2)</a>. 498 */ pipe()499 public static FileDescriptor[] pipe() throws ErrnoException { return Libcore.os.pipe2(0); } 500 501 /** 502 * Creates a pipe, a unidirectional data channel that can be used for interprocess communication. 503 * 504 * See <a href="http://man7.org/linux/man-pages/man2/pipe.2.html">pipe(2)</a>. 505 * 506 * @param flags bitmask of options, e.g. {@link OsConstants#O_CLOEXEC}, {@link OsConstants#O_DIRECT} 507 * or {@link OsConstants#O_NONBLOCK}. 508 * If {@code flags} is {@code 0}, then {@link pipe2(int)} is the same as {@link pipe()}. 509 * @return array of two file descriptors referring to the ends of the pipe, where 510 * first file descriptor is the read end of the pipe, and second is a write end 511 * @throws ErrnoException if {@code flags} contains invalid value; or 512 * the per-process limit on the number of open file 513 * descriptors has been reached; or 514 * the system-wide limit on the total number of open files 515 * has been reached; or 516 * the user hard limit on memory that can be allocated for 517 * pipes has been reached and the caller is not privileged 518 * 519 * @hide 520 */ 521 @SystemApi(client = MODULE_LIBRARIES) pipe2(int flags)522 public static @Nullable FileDescriptor[] pipe2(int flags) throws ErrnoException { return Libcore.os.pipe2(flags); } 523 524 /** 525 * See <a href="http://man7.org/linux/man-pages/man2/poll.2.html">poll(2)</a>. 526 * 527 * <p>Note that in Lollipop this could throw an {@code ErrnoException} with {@code EINTR}. 528 * In later releases, the implementation will automatically just restart the system call with 529 * an appropriately reduced timeout. 530 */ poll(StructPollfd[] fds, int timeoutMs)531 public static int poll(StructPollfd[] fds, int timeoutMs) throws ErrnoException { return Libcore.os.poll(fds, timeoutMs); } 532 533 /** 534 * See <a href="http://man7.org/linux/man-pages/man3/posix_fallocate.3.html">posix_fallocate(3)</a>. 535 */ posix_fallocate(FileDescriptor fd, long offset, long length)536 public static void posix_fallocate(FileDescriptor fd, long offset, long length) throws ErrnoException { Libcore.os.posix_fallocate(fd, offset, length); } 537 538 /** 539 * See <a href="http://man7.org/linux/man-pages/man2/prctl.2.html">prctl(2)</a>. 540 */ prctl(int option, long arg2, long arg3, long arg4, long arg5)541 public static int prctl(int option, long arg2, long arg3, long arg4, long arg5) throws ErrnoException { return Libcore.os.prctl(option, arg2, arg3, arg4, arg5); }; 542 543 /** 544 * See <a href="http://man7.org/linux/man-pages/man2/pread.2.html">pread(2)</a>. 545 */ pread(FileDescriptor fd, ByteBuffer buffer, long offset)546 public static int pread(FileDescriptor fd, ByteBuffer buffer, long offset) throws ErrnoException, InterruptedIOException { return Libcore.os.pread(fd, buffer, offset); } 547 548 /** 549 * See <a href="http://man7.org/linux/man-pages/man2/pread.2.html">pread(2)</a>. 550 */ pread(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, long offset)551 public static int pread(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, long offset) throws ErrnoException, InterruptedIOException { return Libcore.os.pread(fd, bytes, byteOffset, byteCount, offset); } 552 553 /** 554 * See <a href="http://man7.org/linux/man-pages/man2/pwrite.2.html">pwrite(2)</a>. 555 */ pwrite(FileDescriptor fd, ByteBuffer buffer, long offset)556 public static int pwrite(FileDescriptor fd, ByteBuffer buffer, long offset) throws ErrnoException, InterruptedIOException { return Libcore.os.pwrite(fd, buffer, offset); } 557 558 /** 559 * See <a href="http://man7.org/linux/man-pages/man2/pwrite.2.html">pwrite(2)</a>. 560 */ pwrite(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, long offset)561 public static int pwrite(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, long offset) throws ErrnoException, InterruptedIOException { return Libcore.os.pwrite(fd, bytes, byteOffset, byteCount, offset); } 562 563 /** 564 * See <a href="http://man7.org/linux/man-pages/man2/read.2.html">read(2)</a>. 565 */ read(FileDescriptor fd, ByteBuffer buffer)566 public static int read(FileDescriptor fd, ByteBuffer buffer) throws ErrnoException, InterruptedIOException { return Libcore.os.read(fd, buffer); } 567 568 /** 569 * See <a href="http://man7.org/linux/man-pages/man2/read.2.html">read(2)</a>. 570 */ read(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount)571 public static int read(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount) throws ErrnoException, InterruptedIOException { return Libcore.os.read(fd, bytes, byteOffset, byteCount); } 572 573 /** 574 * See <a href="http://man7.org/linux/man-pages/man2/readlink.2.html">readlink(2)</a>. 575 */ readlink(String path)576 public static String readlink(String path) throws ErrnoException { return Libcore.os.readlink(path); } 577 578 /** 579 * Eexpands all symbolic links and resolves references to {@code /./}, 580 * {@code /../} and extra {@code /} characters string named by path 581 * to produce a canonicalized absolute pathname. 582 * 583 * See <a href="http://man7.org/linux/man-pages/man3/realpath.3.html">realpath(3)</a>. 584 * 585 * @param path string to resolve 586 * @return resolved path if no error occurred. Returns {@code null} if {@code path} 587 * is {@code null} 588 * @throws ErrnoException read or search permission was denied for a component of 589 * the path prefix; or an I/O error occurred while reading 590 * from the filesystem; or too many symbolic links were 591 * encountered in translating the pathname; or 592 * the named file does not exist; or a component of the path 593 * prefix is not a directory 594 * 595 * @hide 596 */ 597 @SystemApi(client = MODULE_LIBRARIES) 598 @libcore.api.IntraCoreApi realpath(@ullable String path)599 public static @Nullable String realpath(@Nullable String path) throws ErrnoException { return Libcore.os.realpath(path); } 600 601 /** 602 * See <a href="http://man7.org/linux/man-pages/man2/readv.2.html">readv(2)</a>. 603 */ readv(FileDescriptor fd, Object[] buffers, int[] offsets, int[] byteCounts)604 public static int readv(FileDescriptor fd, Object[] buffers, int[] offsets, int[] byteCounts) throws ErrnoException, InterruptedIOException { return Libcore.os.readv(fd, buffers, offsets, byteCounts); } 605 606 /** 607 * See <a href="http://man7.org/linux/man-pages/man2/recvfrom.2.html">recvfrom(2)</a>. 608 */ recvfrom(FileDescriptor fd, ByteBuffer buffer, int flags, InetSocketAddress srcAddress)609 public static int recvfrom(FileDescriptor fd, ByteBuffer buffer, int flags, InetSocketAddress srcAddress) throws ErrnoException, SocketException { return Libcore.os.recvfrom(fd, buffer, flags, srcAddress); } 610 611 /** 612 * See <a href="http://man7.org/linux/man-pages/man2/recvfrom.2.html">recvfrom(2)</a>. 613 */ recvfrom(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, InetSocketAddress srcAddress)614 public static int recvfrom(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, InetSocketAddress srcAddress) throws ErrnoException, SocketException { return Libcore.os.recvfrom(fd, bytes, byteOffset, byteCount, flags, srcAddress); } 615 616 /** 617 * See <a href="http://man7.org/linux/man-pages/man2/recvmsg.2.html">recvmsg(2)</a>. 618 */ recvmsg(@onNull FileDescriptor fd, @NonNull StructMsghdr msg, int flags)619 public static int recvmsg(@NonNull FileDescriptor fd, @NonNull StructMsghdr msg, int flags) throws ErrnoException, SocketException { return Libcore.os.recvmsg(fd, msg, flags); } 620 621 /** 622 * See <a href="http://man7.org/linux/man-pages/man3/remove.3.html">remove(3)</a>. 623 */ remove(String path)624 public static void remove(String path) throws ErrnoException { Libcore.os.remove(path); } 625 626 /** 627 * See <a href="http://man7.org/linux/man-pages/man2/removexattr.2.html">removexattr(2)</a>. 628 */ removexattr(String path, String name)629 public static void removexattr(String path, String name) throws ErrnoException { Libcore.os.removexattr(path, name); } 630 631 /** 632 * See <a href="http://man7.org/linux/man-pages/man2/rename.2.html">rename(2)</a>. 633 */ rename(String oldPath, String newPath)634 public static void rename(String oldPath, String newPath) throws ErrnoException { Libcore.os.rename(oldPath, newPath); } 635 636 /** 637 * See <a href="http://man7.org/linux/man-pages/man2/sendfile.2.html">sendfile(2)</a>. 638 */ sendfile(FileDescriptor outFd, FileDescriptor inFd, Int64Ref offset, long byteCount)639 public static long sendfile(FileDescriptor outFd, FileDescriptor inFd, Int64Ref offset, long byteCount) throws ErrnoException { 640 return Libcore.os.sendfile(outFd, inFd, offset, byteCount); 641 } 642 643 /** 644 * See <a href="http://man7.org/linux/man-pages/man2/sendmsg.2.html">sendmsg(2)</a>. 645 */ sendmsg(@onNull FileDescriptor fd, @NonNull StructMsghdr msg, int flags)646 public static int sendmsg(@NonNull FileDescriptor fd, @NonNull StructMsghdr msg, int flags) throws ErrnoException, SocketException { 647 return Libcore.os.sendmsg(fd, msg, flags); 648 } 649 650 /** 651 * See <a href="http://man7.org/linux/man-pages/man2/sendto.2.html">sendto(2)</a>. 652 */ sendto(FileDescriptor fd, ByteBuffer buffer, int flags, InetAddress inetAddress, int port)653 public static int sendto(FileDescriptor fd, ByteBuffer buffer, int flags, InetAddress inetAddress, int port) throws ErrnoException, SocketException { return Libcore.os.sendto(fd, buffer, flags, inetAddress, port); } 654 655 /** 656 * See <a href="http://man7.org/linux/man-pages/man2/sendto.2.html">sendto(2)</a>. 657 */ sendto(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, InetAddress inetAddress, int port)658 public static int sendto(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, InetAddress inetAddress, int port) throws ErrnoException, SocketException { return Libcore.os.sendto(fd, bytes, byteOffset, byteCount, flags, inetAddress, port); } 659 660 /** 661 * See <a href="http://man7.org/linux/man-pages/man2/sendto.2.html">sendto(2)</a>. 662 */ sendto(@onNull FileDescriptor fd, @NonNull byte[] bytes, int byteOffset, int byteCount, int flags, @Nullable SocketAddress address)663 public static int sendto(@NonNull FileDescriptor fd, @NonNull byte[] bytes, int byteOffset, int byteCount, int flags, @Nullable SocketAddress address) throws ErrnoException, SocketException { return Libcore.os.sendto(fd, bytes, byteOffset, byteCount, flags, address); } 664 665 /** 666 * See <a href="http://man7.org/linux/man-pages/man2/setegid.2.html">setegid(2)</a>. 667 * @deprecated Android Applications do not have sufficient privileges to call this method. 668 */ 669 @Deprecated setegid(int egid)670 public static void setegid(int egid) throws ErrnoException { Libcore.os.setegid(egid); } 671 672 /** 673 * See <a href="http://man7.org/linux/man-pages/man3/setenv.3.html">setenv(3)</a>. 674 */ setenv(String name, String value, boolean overwrite)675 public static void setenv(String name, String value, boolean overwrite) throws ErrnoException { Libcore.os.setenv(name, value, overwrite); } 676 677 /** 678 * See <a href="http://man7.org/linux/man-pages/man2/seteuid.2.html">seteuid(2)</a>. 679 * @deprecated Android Applications do not have sufficient privileges to call this method. 680 */ 681 @Deprecated seteuid(int euid)682 public static void seteuid(int euid) throws ErrnoException { Libcore.os.seteuid(euid); } 683 684 /** 685 * See <a href="http://man7.org/linux/man-pages/man2/setgid.2.html">setgid(2)</a>. 686 * @deprecated Android Applications do not have sufficient privileges to call this method. 687 */ 688 @Deprecated setgid(int gid)689 public static void setgid(int gid) throws ErrnoException { Libcore.os.setgid(gid); } 690 691 /** 692 * Sets process's pgid (process group ID). 693 * 694 * See <a href="http://man7.org/linux/man-pages/man2/setpgid.2.html">setpgid(2)</a>. 695 * 696 * @param pid process id to set the pgid of 697 * @param pgid new pgid for process {@code pid} 698 * @throws ErrnoException an attempt was made to change the process group ID of one 699 * of the children of the calling process and the child had 700 * already performed an {@link execve(String, String[], String[])}; or 701 * {@code pgid} is less than {@code 0}; or 702 * an attempt was made to move a process into a process group 703 * in a different session, or to change the process group ID 704 * of one of the children of the calling process and the 705 * child was in a different session, or to change the process 706 * group ID of a session leader; or 707 * {@code pid} is not the calling process and not a child 708 * of the calling process 709 * 710 * @hide 711 */ 712 @SystemApi(client = MODULE_LIBRARIES) setpgid(int pid, int pgid)713 public static void setpgid(int pid, int pgid) throws ErrnoException { Libcore.os.setpgid(pid, pgid); } 714 715 /** 716 * Set real and/or effective group ID of the calling process. 717 * 718 * See <a href="http://man7.org/linux/man-pages/man2/setregid.2.html">setregid(2)</a>. 719 * 720 * @param rgid real group ID 721 * @param egid effective group ID 722 * @throws ErrnoException one or more of the target group IDs is not valid 723 * in this user namespace; or the calling process is 724 * not privileged 725 * 726 * @hide 727 */ 728 @SystemApi(client = MODULE_LIBRARIES) setregid(int rgid, int egid)729 public static void setregid(int rgid, int egid) throws ErrnoException { Libcore.os.setregid(rgid, egid); } 730 731 /** 732 * Set real and/or effective user ID of the calling process. 733 * 734 * See <a href="http://man7.org/linux/man-pages/man2/setreuid.2.html">setreuid(2)</a>. 735 * 736 * @param ruid real user ID 737 * @param euid effective user ID 738 * @throws ErrnoException one or more of the target user IDs is not valid 739 * in this user namespace; or the calling process is 740 * not privileged 741 * 742 * @hide 743 */ 744 @SystemApi(client = MODULE_LIBRARIES) setreuid(int ruid, int euid)745 public static void setreuid(int ruid, int euid) throws ErrnoException { Libcore.os.setreuid(ruid, euid); } 746 747 /** 748 * See <a href="http://man7.org/linux/man-pages/man2/setsid.2.html">setsid(2)</a>. 749 */ setsid()750 public static int setsid() throws ErrnoException { return Libcore.os.setsid(); } 751 752 /** @hide */ setsockoptByte(FileDescriptor fd, int level, int option, int value)753 public static void setsockoptByte(FileDescriptor fd, int level, int option, int value) throws ErrnoException { Libcore.os.setsockoptByte(fd, level, option, value); } 754 755 /** 756 * Sets a supplied socket {@code option} to {@code value}. 757 * 758 * See <a href="https://man7.org/linux/man-pages/man2/getsockopt.2.html">getsockopt(2)</a>. 759 * For the list of available options see <a href="https://man7.org/linux/man-pages/man7/socket.7.html">socket(7)</a>. 760 * Corresponding socket options constants reside in {@link OsCosntants}, e.g. {@link OsConstants#SO_REUSEADDR}. 761 * 762 * @param fd file descriptor of the socket to set options of 763 * @param level level at which the {@code option} resides. For example, 764 * to indicate that an option is to be interpreted by the TCP protocol, 765 * level should be set to the protocol number of TCP 766 * @param option name of the option to set 767 * @param value interface name 768 * @return socket options for file descriptor {@code fd} 769 * @throws ErrnoException if {@code fd} is invalid; or 770 * {@code option} is unknown at given {@code level} 771 * 772 * @hide 773 */ 774 @UnsupportedAppUsage 775 @SystemApi(client = MODULE_LIBRARIES) setsockoptIfreq(@onNull FileDescriptor fd, int level, int option, @Nullable String value)776 public static void setsockoptIfreq(@NonNull FileDescriptor fd, int level, int option, @Nullable String value) throws ErrnoException { Libcore.os.setsockoptIfreq(fd, level, option, value); } 777 778 /** 779 * See <a href="http://man7.org/linux/man-pages/man2/setsockopt.2.html">setsockopt(2)</a>. 780 */ setsockoptInt(FileDescriptor fd, int level, int option, int value)781 public static void setsockoptInt(FileDescriptor fd, int level, int option, int value) throws ErrnoException { Libcore.os.setsockoptInt(fd, level, option, value); } 782 783 /** @hide */ setsockoptIpMreqn(FileDescriptor fd, int level, int option, int value)784 public static void setsockoptIpMreqn(FileDescriptor fd, int level, int option, int value) throws ErrnoException { Libcore.os.setsockoptIpMreqn(fd, level, option, value); } 785 786 /** @hide */ setsockoptGroupReq(FileDescriptor fd, int level, int option, StructGroupReq value)787 public static void setsockoptGroupReq(FileDescriptor fd, int level, int option, StructGroupReq value) throws ErrnoException { Libcore.os.setsockoptGroupReq(fd, level, option, value); } 788 789 /** 790 * Sets {@link OsConstants#SO_LINGER} option for the socket referred to by the file descriptor 791 * {@code fd}. 792 * 793 * @param fd file descriptor 794 * @param level level at which the {@code option} resides 795 * @param option name of the option to set 796 * @param value {@link StructLinger} to set for {@code fd} 797 * @throws ErrnoException if {@code fd} is invalid; or 798 * {@code option} is unknown at given {@code level} 799 * 800 * @hide 801 */ 802 @SystemApi(client = MODULE_LIBRARIES) setsockoptLinger(@onNull FileDescriptor fd, int level, int option, @NonNull StructLinger value)803 public static void setsockoptLinger(@NonNull FileDescriptor fd, int level, int option, @NonNull StructLinger value) throws ErrnoException { Libcore.os.setsockoptLinger(fd, level, option, value); } 804 805 /** 806 * See <a href="http://man7.org/linux/man-pages/man2/setsockopt.2.html">setsockopt(2)</a>. 807 * 808 * <p>Only for use with {@code option} values that take a {@code struct timeval} such as 809 * {@link OsConstants#SO_RCVTIMEO} and {@link OsConstants#SO_SNDTIMEO}. Use with other 810 * options is likely to cause incorrect behavior. 811 */ setsockoptTimeval(@onNull FileDescriptor fd, int level, int option, @NonNull StructTimeval value)812 public static void setsockoptTimeval(@NonNull FileDescriptor fd, int level, int option, @NonNull StructTimeval value) throws ErrnoException { Libcore.os.setsockoptTimeval(fd, level, option, value); } 813 814 /** 815 * See <a href="http://man7.org/linux/man-pages/man2/setuid.2.html">setuid(2)</a>. 816 * @deprecated Android Applications do not have sufficient privileges to call this method. 817 */ 818 @Deprecated setuid(int uid)819 public static void setuid(int uid) throws ErrnoException { Libcore.os.setuid(uid); } 820 821 /** 822 * See <a href="http://man7.org/linux/man-pages/man2/setxattr.2.html">setxattr(2)</a> 823 */ setxattr(String path, String name, byte[] value, int flags)824 public static void setxattr(String path, String name, byte[] value, int flags) throws ErrnoException { Libcore.os.setxattr(path, name, value, flags); }; 825 826 /** 827 * See <a href="http://man7.org/linux/man-pages/man2/shutdown.2.html">shutdown(2)</a>. 828 */ shutdown(FileDescriptor fd, int how)829 public static void shutdown(FileDescriptor fd, int how) throws ErrnoException { Libcore.os.shutdown(fd, how); } 830 831 /** 832 * See <a href="http://man7.org/linux/man-pages/man2/socket.2.html">socket(2)</a>. 833 */ socket(int domain, int type, int protocol)834 public static FileDescriptor socket(int domain, int type, int protocol) throws ErrnoException { return Libcore.os.socket(domain, type, protocol); } 835 836 /** 837 * See <a href="http://man7.org/linux/man-pages/man2/socketpair.2.html">socketpair(2)</a>. 838 */ socketpair(int domain, int type, int protocol, FileDescriptor fd1, FileDescriptor fd2)839 public static void socketpair(int domain, int type, int protocol, FileDescriptor fd1, FileDescriptor fd2) throws ErrnoException { Libcore.os.socketpair(domain, type, protocol, fd1, fd2); } 840 841 /** 842 * Moves data between two file descriptors without copying 843 * between kernel address space and user address space. It 844 * transfers up to {@code len} bytes of data from the file descriptor {@code fdIn} 845 * to the file descriptor {@code fdOut}, where one of the file descriptors 846 * must refer to a pipe. 847 * 848 * The following semantics apply for {@code fdIn} and {@code offIn}: 849 * <ul> 850 * <li>If {@code fdIn} refers to a pipe, then {@code offIn} must be {@code null}.</li> 851 * <li>If {@code fdIn} does not refer to a pipe and {@code offIn} is {@code null}, then 852 * bytes are read from {@code fdIn} starting from the file offset, and 853 * the file offset is adjusted appropriately.</li> 854 * <li>If {@code fdIn} does not refer to a pipe and {@code offIn} is not {@code null}, then 855 * {@code offIn} must point to a buffer which specifies the starting 856 * offset from which bytes will be read from {@code fdIn}; in this case, 857 * the file offset of {@code fdIn} is not changed.</li> 858 * </ul> 859 * 860 * Analogous statements apply for {@code fdOut} and {@code offOut}. 861 * 862 * The flags argument is a bit mask that is composed by ORing 863 * together zero or more of the following values: 864 * <ul> 865 * <li>{@link OsConstants#SPLICE_F_MOVE} 866 * Attempt to move pages instead of copying. This is only a 867 * hint to the kernel: pages may still be copied if the 868 * kernel cannot move the pages from the pipe, or if the pipe 869 * buffers don't refer to full pages.</li> 870 * <li>{@link OsConstants#SPLICE_F_NONBLOCK} 871 * Do not block on I/O. This makes the splice pipe 872 * operations nonblocking, but 873 * {@link splice(FileDescriptor, Int64Ref, FileDescriptor, Int64Ref, long, int)} 874 * may nevertheless block because the file descriptors that are spliced 875 * to/from may block (unless they have the {@link OsConstants#O_NONBLOCK} flag set).</li> 876 * <li>{@link OsConstants#SPLICE_F_MORE} 877 * More data will be coming in a subsequent splice.</li> 878 * <li>{@link OsConstants#SPLICE_F_GIFT} Unused</li> 879 * </ul> 880 * 881 * See <a href="http://man7.org/linux/man-pages/man2/splice.2.html">splice(2)</a>. 882 * 883 * @param fdIn file descriptor to read from 884 * @param offIn {@code null} for pipe; file offset; or pointer to a buffer that specifies starting offset 885 * @param fdOut file descriptor to write to 886 * @param offOut {@code null} for pipe; file offset; or pointer to a buffer that specifies starting offset 887 * @param len number of bytes to read/write 888 * @param flags bitmask of options 889 * @return number of bytes spliced on success. A return value of {@code 0} means end of input. 890 * @throws ErrnoException if target fs does not support splicing; or 891 * target file opened in append mode; or 892 * one or both file descriptors are invalid; or 893 * neither of file descriptors refer to a pipe; or 894 * {@code fdIn} and {@code fdOut} refer to a same pipe 895 * 896 * @hide 897 */ 898 @SystemApi(client = MODULE_LIBRARIES) splice(@onNull FileDescriptor fdIn, @Nullable Int64Ref offIn, @NonNull FileDescriptor fdOut, @Nullable Int64Ref offOut, long len, int flags)899 public static long splice(@NonNull FileDescriptor fdIn, @Nullable Int64Ref offIn, @NonNull FileDescriptor fdOut, @Nullable Int64Ref offOut, long len, int flags) throws ErrnoException { return Libcore.os.splice(fdIn, offIn, fdOut, offOut, len, flags); } 900 901 /** 902 * See <a href="http://man7.org/linux/man-pages/man2/stat.2.html">stat(2)</a>. 903 */ stat(String path)904 public static StructStat stat(String path) throws ErrnoException { return Libcore.os.stat(path); } 905 906 /** 907 * See <a href="http://man7.org/linux/man-pages/man2/statvfs.2.html">statvfs(2)</a>. 908 */ statvfs(String path)909 public static StructStatVfs statvfs(String path) throws ErrnoException { return Libcore.os.statvfs(path); } 910 911 /** 912 * See <a href="http://man7.org/linux/man-pages/man3/strerror.3.html">strerror(2)</a>. 913 */ strerror(int errno)914 public static String strerror(int errno) { return Libcore.os.strerror(errno); } 915 916 /** 917 * See <a href="http://man7.org/linux/man-pages/man3/strsignal.3.html">strsignal(3)</a>. 918 */ strsignal(int signal)919 public static String strsignal(int signal) { return Libcore.os.strsignal(signal); } 920 921 /** 922 * See <a href="http://man7.org/linux/man-pages/man2/symlink.2.html">symlink(2)</a>. 923 */ symlink(String oldPath, String newPath)924 public static void symlink(String oldPath, String newPath) throws ErrnoException { Libcore.os.symlink(oldPath, newPath); } 925 926 /** 927 * See <a href="http://man7.org/linux/man-pages/man3/sysconf.3.html">sysconf(3)</a>. 928 */ sysconf(int name)929 public static long sysconf(int name) { return Libcore.os.sysconf(name); } 930 931 /** 932 * See <a href="http://man7.org/linux/man-pages/man3/tcdrain.3.html">tcdrain(3)</a>. 933 */ tcdrain(FileDescriptor fd)934 public static void tcdrain(FileDescriptor fd) throws ErrnoException { Libcore.os.tcdrain(fd); } 935 936 /** 937 * See <a href="http://man7.org/linux/man-pages/man3/tcsendbreak.3.html">tcsendbreak(3)</a>. 938 */ tcsendbreak(FileDescriptor fd, int duration)939 public static void tcsendbreak(FileDescriptor fd, int duration) throws ErrnoException { Libcore.os.tcsendbreak(fd, duration); } 940 941 /** 942 * See <a href="http://man7.org/linux/man-pages/man2/umask.2.html">umask(2)</a>. 943 */ umask(int mask)944 public static int umask(int mask) { return Libcore.os.umask(mask); } 945 946 /** 947 * See <a href="http://man7.org/linux/man-pages/man2/uname.2.html">uname(2)</a>. 948 */ uname()949 public static StructUtsname uname() { return Libcore.os.uname(); } 950 951 /** 952 * Deletes a name from the filesystem. If that name was the last link to a file 953 * and no processes have the file open, the file is deleted and the space it was 954 * using is made available for reuse. 955 * 956 * See <a href="http://man7.org/linux/man-pages/man2/unlink.2.html">unlink(2)</a>. 957 * 958 * @param pathname name in the filesystem to delete 959 * @throws ErrnoException write access to {@code pathname} is not allowed; or 960 * I/O error occurred; or 961 * {@code pathname} refers to directory; or 962 * too many symbolic links were encountered in translating {@code pathname}; or 963 * {@code pathname} is used by the system or another process 964 * 965 * @hide 966 */ 967 @SystemApi(client = MODULE_LIBRARIES) unlink(@ullable String pathname)968 public static void unlink(@Nullable String pathname) throws ErrnoException { Libcore.os.unlink(pathname); } 969 970 /** 971 * See <a href="http://man7.org/linux/man-pages/man3/unsetenv.3.html">unsetenv(3)</a>. 972 */ unsetenv(String name)973 public static void unsetenv(String name) throws ErrnoException { Libcore.os.unsetenv(name); } 974 975 /** 976 * @hide See <a href="http://man7.org/linux/man-pages/man2/waitpid.2.html">waitpid(2)</a>. 977 * 978 * @throws IllegalArgumentException if {@code status != null && status.length != 1} 979 */ waitpid(int pid, Int32Ref status, int options)980 public static int waitpid(int pid, Int32Ref status, int options) throws ErrnoException { 981 return Libcore.os.waitpid(pid, status, options); 982 } 983 984 /** 985 * See <a href="http://man7.org/linux/man-pages/man2/write.2.html">write(2)</a>. 986 */ write(FileDescriptor fd, ByteBuffer buffer)987 public static int write(FileDescriptor fd, ByteBuffer buffer) throws ErrnoException, InterruptedIOException { return Libcore.os.write(fd, buffer); } 988 989 /** 990 * See <a href="http://man7.org/linux/man-pages/man2/write.2.html">write(2)</a>. 991 */ write(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount)992 public static int write(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount) throws ErrnoException, InterruptedIOException { return Libcore.os.write(fd, bytes, byteOffset, byteCount); } 993 994 /** 995 * See <a href="http://man7.org/linux/man-pages/man2/writev.2.html">writev(2)</a>. 996 */ writev(FileDescriptor fd, Object[] buffers, int[] offsets, int[] byteCounts)997 public static int writev(FileDescriptor fd, Object[] buffers, int[] offsets, int[] byteCounts) throws ErrnoException, InterruptedIOException { return Libcore.os.writev(fd, buffers, offsets, byteCounts); } 998 } 999