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 libcore.io; 18 19 import static android.annotation.SystemApi.Client.MODULE_LIBRARIES; 20 21 import android.system.ErrnoException; 22 import android.system.GaiException; 23 import android.system.Int32Ref; 24 import android.system.Int64Ref; 25 import android.system.StructAddrinfo; 26 import android.system.StructCapUserData; 27 import android.system.StructCapUserHeader; 28 import android.system.StructGroupReq; 29 import android.system.StructIfaddrs; 30 import android.system.StructLinger; 31 import android.system.StructMsghdr; 32 import android.system.StructPasswd; 33 import android.system.StructPollfd; 34 import android.system.StructRlimit; 35 import android.system.StructStat; 36 import android.system.StructStatVfs; 37 import android.system.StructTimeval; 38 import android.system.StructUcred; 39 import android.system.StructUtsname; 40 41 import android.annotation.SystemApi; 42 import android.compat.annotation.UnsupportedAppUsage; 43 import java.io.FileDescriptor; 44 import java.io.InterruptedIOException; 45 import java.net.InetAddress; 46 import java.net.InetSocketAddress; 47 import java.net.SocketAddress; 48 import java.net.SocketException; 49 import java.nio.ByteBuffer; 50 import java.util.Objects; 51 52 import libcore.util.NonNull; 53 import libcore.util.Nullable; 54 55 /** 56 * Subclass this if you want to override some {@link Os} methods but otherwise delegate. 57 * 58 * @hide 59 */ 60 @SystemApi(client = MODULE_LIBRARIES) 61 public class ForwardingOs implements Os { 62 @UnsupportedAppUsage 63 private final Os os; 64 65 /** 66 * Constructs new {@link ForwardingOs}. 67 * 68 * @param os {@link Os} delegate for not overridden methods 69 * 70 * @hide 71 */ 72 @UnsupportedAppUsage 73 @SystemApi(client = MODULE_LIBRARIES) ForwardingOs(@onNull Os os)74 protected ForwardingOs(@NonNull Os os) { 75 this.os = Objects.requireNonNull(os); 76 } 77 78 /** 79 * @return the delegate object passed to the constructor. 80 * 81 * @hide 82 */ delegate()83 protected final Os delegate() { 84 return os; 85 } 86 87 /** 88 * 89 * @hide 90 */ accept(FileDescriptor fd, SocketAddress peerAddress)91 public FileDescriptor accept(FileDescriptor fd, SocketAddress peerAddress) throws ErrnoException, SocketException { return os.accept(fd, peerAddress); } 92 93 /** 94 * Checks whether the calling process can access the file 95 * {@code path}. If {@code path} is a symbolic link, it is dereferenced. 96 * 97 * The mode specifies the accessibility check(s) to be performed, 98 * and is either the value {@link android.system.OsConstants#F_OK}, 99 * or a mask consisting of the bitwise OR of one or more of 100 * {@link android.system.OsConstants#R_OK}, {@link android.system.OsConstants#W_OK}, 101 * and {@link android.system.OsConstants#X_OK}. 102 * 103 * {@link android.system.OsConstants#F_OK} tests for the 104 * existence of the file. {@link android.system.OsConstants#R_OK}, 105 * {@link android.system.OsConstants#W_OK}, and {@link android.system.OsConstants#X_OK} 106 * test whether the file exists and grants read, write, and execute permissions, respectively. 107 * 108 * @see <a href="https://man7.org/linux/man-pages/man2/access.2.html">access(2)</a>. 109 * 110 * @param path path of the file to check access for 111 * @param mode accessibility checks mask 112 * @return {@code true} if file is accessible (all requested permissions granted, 113 * or mode is {@link android.system.OsConstants#F_OK} and the file exists)); 114 * and throws otherwise 115 * @throws ErrnoException if at least one bit in mode asked for a permission that is denied, 116 * or mode is {@link android.system.OsConstants#F_OK} and the file 117 * does not exist, or some other error occurred. See the full list 118 * of errors in the "See Also" list. 119 * 120 * @hide 121 */ 122 @UnsupportedAppUsage 123 @SystemApi(client = MODULE_LIBRARIES) 124 125 /** 126 * @hide 127 */ access(@ullable String path, int mode)128 public boolean access(@Nullable String path, int mode) throws ErrnoException { return os.access(path, mode); } 129 130 /** 131 * @hide 132 */ android_getaddrinfo(String node, StructAddrinfo hints, int netId)133 public InetAddress[] android_getaddrinfo(String node, StructAddrinfo hints, int netId) throws GaiException { return os.android_getaddrinfo(node, hints, netId); } 134 135 /** 136 * @hide 137 */ bind(FileDescriptor fd, InetAddress address, int port)138 public void bind(FileDescriptor fd, InetAddress address, int port) throws ErrnoException, SocketException { os.bind(fd, address, port); } 139 140 /** 141 * @hide 142 */ bind(FileDescriptor fd, SocketAddress address)143 public void bind(FileDescriptor fd, SocketAddress address) throws ErrnoException, SocketException { os.bind(fd, address); } 144 145 /** 146 * @hide 147 */ 148 @Override capget(StructCapUserHeader hdr)149 public StructCapUserData[] capget(StructCapUserHeader hdr) throws ErrnoException { 150 return os.capget(hdr); 151 } 152 153 /** 154 * @hide 155 */ 156 @Override capset(StructCapUserHeader hdr, StructCapUserData[] data)157 public void capset(StructCapUserHeader hdr, StructCapUserData[] data) throws ErrnoException { 158 os.capset(hdr, data); 159 } 160 161 /** 162 * @hide 163 */ 164 @UnsupportedAppUsage chmod(String path, int mode)165 public void chmod(String path, int mode) throws ErrnoException { os.chmod(path, mode); } 166 167 /** 168 * @hide 169 */ 170 @UnsupportedAppUsage chown(String path, int uid, int gid)171 public void chown(String path, int uid, int gid) throws ErrnoException { os.chown(path, uid, gid); } 172 173 /** 174 * @hide 175 */ close(FileDescriptor fd)176 public void close(FileDescriptor fd) throws ErrnoException { os.close(fd); } 177 178 /** 179 * @hide 180 */ android_fdsan_exchange_owner_tag(FileDescriptor fd, long previousOwnerId, long newOwnerId)181 public void android_fdsan_exchange_owner_tag(FileDescriptor fd, long previousOwnerId, long newOwnerId) { os.android_fdsan_exchange_owner_tag(fd, previousOwnerId, newOwnerId); } 182 183 /** 184 * @hide 185 */ android_fdsan_get_owner_tag(FileDescriptor fd)186 public long android_fdsan_get_owner_tag(FileDescriptor fd) { return os.android_fdsan_get_owner_tag(fd); } 187 188 /** 189 * @hide 190 */ android_fdsan_get_tag_type(long tag)191 public String android_fdsan_get_tag_type(long tag) { return os.android_fdsan_get_tag_type(tag); } 192 193 /** 194 * @hide 195 */ android_fdsan_get_tag_value(long tag)196 public long android_fdsan_get_tag_value(long tag) { return os.android_fdsan_get_tag_value(tag); } 197 198 /** 199 * @hide 200 */ connect(FileDescriptor fd, InetAddress address, int port)201 public void connect(FileDescriptor fd, InetAddress address, int port) throws ErrnoException, SocketException { os.connect(fd, address, port); } 202 203 /** 204 * @hide 205 */ connect(FileDescriptor fd, SocketAddress address)206 public void connect(FileDescriptor fd, SocketAddress address) throws ErrnoException, SocketException { os.connect(fd, address); } 207 208 /** 209 * @hide 210 */ dup(FileDescriptor oldFd)211 public FileDescriptor dup(FileDescriptor oldFd) throws ErrnoException { return os.dup(oldFd); } 212 213 /** 214 * @hide 215 */ dup2(FileDescriptor oldFd, int newFd)216 public FileDescriptor dup2(FileDescriptor oldFd, int newFd) throws ErrnoException { return os.dup2(oldFd, newFd); } 217 218 /** 219 * @hide 220 */ environ()221 public String[] environ() { return os.environ(); } 222 223 /** 224 * @hide 225 */ execv(String filename, String[] argv)226 public void execv(String filename, String[] argv) throws ErrnoException { os.execv(filename, argv); } 227 228 /** 229 * @hide 230 */ execve(String filename, String[] argv, String[] envp)231 public void execve(String filename, String[] argv, String[] envp) throws ErrnoException { os.execve(filename, argv, envp); } 232 233 /** 234 * @hide 235 */ fchmod(FileDescriptor fd, int mode)236 public void fchmod(FileDescriptor fd, int mode) throws ErrnoException { os.fchmod(fd, mode); } 237 238 /** 239 * @hide 240 */ fchown(FileDescriptor fd, int uid, int gid)241 public void fchown(FileDescriptor fd, int uid, int gid) throws ErrnoException { os.fchown(fd, uid, gid); } 242 243 /** 244 * @hide 245 */ fcntlInt(FileDescriptor fd, int cmd, int arg)246 public int fcntlInt(FileDescriptor fd, int cmd, int arg) throws ErrnoException { return os.fcntlInt(fd, cmd, arg); } 247 248 /** 249 * @hide 250 */ fcntlVoid(FileDescriptor fd, int cmd)251 public int fcntlVoid(FileDescriptor fd, int cmd) throws ErrnoException { return os.fcntlVoid(fd, cmd); } 252 253 /** 254 * @hide 255 */ fdatasync(FileDescriptor fd)256 public void fdatasync(FileDescriptor fd) throws ErrnoException { os.fdatasync(fd); } 257 258 /** 259 * @hide 260 */ fstat(FileDescriptor fd)261 public StructStat fstat(FileDescriptor fd) throws ErrnoException { return os.fstat(fd); } 262 263 /** 264 * @hide 265 */ fstatvfs(FileDescriptor fd)266 public StructStatVfs fstatvfs(FileDescriptor fd) throws ErrnoException { return os.fstatvfs(fd); } 267 268 /** 269 * @hide 270 */ fsync(FileDescriptor fd)271 public void fsync(FileDescriptor fd) throws ErrnoException { os.fsync(fd); } 272 273 /** 274 * @hide 275 */ ftruncate(FileDescriptor fd, long length)276 public void ftruncate(FileDescriptor fd, long length) throws ErrnoException { os.ftruncate(fd, length); } 277 278 /** 279 * @hide 280 */ gai_strerror(int error)281 public String gai_strerror(int error) { return os.gai_strerror(error); } 282 283 /** 284 * @hide 285 */ getegid()286 public int getegid() { return os.getegid(); } 287 288 /** 289 * @hide 290 */ geteuid()291 public int geteuid() { return os.geteuid(); } 292 293 /** 294 * @hide 295 */ getgid()296 public int getgid() { return os.getgid(); } 297 298 /** 299 * @hide 300 */ 301 @UnsupportedAppUsage getenv(String name)302 public String getenv(String name) { return os.getenv(name); } 303 304 /** 305 * @hide 306 */ getnameinfo(InetAddress address, int flags)307 public String getnameinfo(InetAddress address, int flags) throws GaiException { return os.getnameinfo(address, flags); } 308 309 /** 310 * @hide 311 */ getpeername(FileDescriptor fd)312 public SocketAddress getpeername(FileDescriptor fd) throws ErrnoException { return os.getpeername(fd); } 313 314 /** 315 * @hide 316 */ getpgid(int pid)317 public int getpgid(int pid) throws ErrnoException { return os.getpgid(pid); } 318 319 /** 320 * @hide 321 */ getpid()322 public int getpid() { return os.getpid(); } 323 324 /** 325 * @hide 326 */ getppid()327 public int getppid() { return os.getppid(); } 328 329 /** 330 * @hide 331 */ getpwnam(String name)332 public StructPasswd getpwnam(String name) throws ErrnoException { return os.getpwnam(name); } 333 334 /** 335 * @hide 336 */ getpwuid(int uid)337 public StructPasswd getpwuid(int uid) throws ErrnoException { return os.getpwuid(uid); } 338 339 /** 340 * @hide 341 */ getrlimit(int resource)342 public StructRlimit getrlimit(int resource) throws ErrnoException { return os.getrlimit(resource); } 343 344 /** 345 * @hide 346 */ getsockname(FileDescriptor fd)347 public SocketAddress getsockname(FileDescriptor fd) throws ErrnoException { return os.getsockname(fd); } 348 349 /** 350 * @hide 351 */ getsockoptByte(FileDescriptor fd, int level, int option)352 public int getsockoptByte(FileDescriptor fd, int level, int option) throws ErrnoException { return os.getsockoptByte(fd, level, option); } 353 354 /** 355 * @hide 356 */ getsockoptInAddr(FileDescriptor fd, int level, int option)357 public InetAddress getsockoptInAddr(FileDescriptor fd, int level, int option) throws ErrnoException { return os.getsockoptInAddr(fd, level, option); } 358 359 /** 360 * @hide 361 */ getsockoptInt(FileDescriptor fd, int level, int option)362 public int getsockoptInt(FileDescriptor fd, int level, int option) throws ErrnoException { return os.getsockoptInt(fd, level, option); } 363 364 /** 365 * @hide 366 */ getsockoptLinger(FileDescriptor fd, int level, int option)367 public StructLinger getsockoptLinger(FileDescriptor fd, int level, int option) throws ErrnoException { return os.getsockoptLinger(fd, level, option); } 368 369 /** 370 * @hide 371 */ getsockoptTimeval(FileDescriptor fd, int level, int option)372 public StructTimeval getsockoptTimeval(FileDescriptor fd, int level, int option) throws ErrnoException { return os.getsockoptTimeval(fd, level, option); } 373 374 /** 375 * @hide 376 */ getsockoptUcred(FileDescriptor fd, int level, int option)377 public StructUcred getsockoptUcred(FileDescriptor fd, int level, int option) throws ErrnoException { return os.getsockoptUcred(fd, level, option); } 378 379 /** 380 * @hide 381 */ gettid()382 public int gettid() { return os.gettid(); } 383 384 /** 385 * @hide 386 */ getuid()387 public int getuid() { return os.getuid(); } 388 389 /** 390 * @hide 391 */ getxattr(String path, String name)392 public byte[] getxattr(String path, String name) throws ErrnoException { return os.getxattr(path, name); } 393 394 /** 395 * @hide 396 */ getifaddrs()397 public StructIfaddrs[] getifaddrs() throws ErrnoException { return os.getifaddrs(); } 398 399 /** 400 * @hide 401 */ if_indextoname(int index)402 public String if_indextoname(int index) { return os.if_indextoname(index); } 403 404 /** 405 * @hide 406 */ if_nametoindex(String name)407 public int if_nametoindex(String name) { return os.if_nametoindex(name); } 408 409 /** 410 * @hide 411 */ inet_pton(int family, String address)412 public InetAddress inet_pton(int family, String address) { return os.inet_pton(family, address); } 413 414 /** 415 * @hide 416 */ ioctlFlags(FileDescriptor fd, String interfaceName)417 public int ioctlFlags(FileDescriptor fd, String interfaceName) throws ErrnoException { return os.ioctlFlags(fd, interfaceName); } 418 419 /** 420 * @hide 421 */ ioctlInetAddress(FileDescriptor fd, int cmd, String interfaceName)422 public InetAddress ioctlInetAddress(FileDescriptor fd, int cmd, String interfaceName) throws ErrnoException { return os.ioctlInetAddress(fd, cmd, interfaceName); } 423 424 /** 425 * @hide 426 */ ioctlInt(FileDescriptor fd, int cmd)427 public int ioctlInt(FileDescriptor fd, int cmd) throws ErrnoException { return os.ioctlInt(fd, cmd); } 428 429 /** 430 * @hide 431 */ ioctlMTU(FileDescriptor fd, String interfaceName)432 public int ioctlMTU(FileDescriptor fd, String interfaceName) throws ErrnoException { return os.ioctlMTU(fd, interfaceName); } 433 434 /** 435 * @hide 436 */ isatty(FileDescriptor fd)437 public boolean isatty(FileDescriptor fd) { return os.isatty(fd); } 438 439 /** 440 * @hide 441 */ kill(int pid, int signal)442 public void kill(int pid, int signal) throws ErrnoException { os.kill(pid, signal); } 443 444 /** 445 * @hide 446 */ 447 @UnsupportedAppUsage lchown(String path, int uid, int gid)448 public void lchown(String path, int uid, int gid) throws ErrnoException { os.lchown(path, uid, gid); } 449 450 /** 451 * @hide 452 */ 453 @UnsupportedAppUsage link(String oldPath, String newPath)454 public void link(String oldPath, String newPath) throws ErrnoException { os.link(oldPath, newPath); } 455 456 /** 457 * @hide 458 */ listen(FileDescriptor fd, int backlog)459 public void listen(FileDescriptor fd, int backlog) throws ErrnoException { os.listen(fd, backlog); } 460 461 /** 462 * @hide 463 */ listxattr(String path)464 public String[] listxattr(String path) throws ErrnoException { return os.listxattr(path); } 465 466 /** 467 * @hide 468 */ lseek(FileDescriptor fd, long offset, int whence)469 public long lseek(FileDescriptor fd, long offset, int whence) throws ErrnoException { return os.lseek(fd, offset, whence); } 470 471 /** 472 * @hide 473 */ 474 @UnsupportedAppUsage lstat(String path)475 public StructStat lstat(String path) throws ErrnoException { return os.lstat(path); } 476 477 /** 478 * @hide 479 */ memfd_create(String name, int flags)480 public FileDescriptor memfd_create(String name, int flags) throws ErrnoException { return os.memfd_create(name, flags); } 481 482 /** 483 * @hide 484 */ mincore(long address, long byteCount, byte[] vector)485 public void mincore(long address, long byteCount, byte[] vector) throws ErrnoException { os.mincore(address, byteCount, vector); } 486 487 /** 488 * @hide 489 */ 490 @UnsupportedAppUsage mkdir(String path, int mode)491 public void mkdir(String path, int mode) throws ErrnoException { os.mkdir(path, mode); } 492 493 /** 494 * @hide 495 */ 496 @UnsupportedAppUsage mkfifo(String path, int mode)497 public void mkfifo(String path, int mode) throws ErrnoException { os.mkfifo(path, mode); } 498 499 /** 500 * @hide 501 */ mlock(long address, long byteCount)502 public void mlock(long address, long byteCount) throws ErrnoException { os.mlock(address, byteCount); } 503 504 /** 505 * @hide 506 */ mmap(long address, long byteCount, int prot, int flags, FileDescriptor fd, long offset)507 public long mmap(long address, long byteCount, int prot, int flags, FileDescriptor fd, long offset) throws ErrnoException { return os.mmap(address, byteCount, prot, flags, fd, offset); } 508 509 /** 510 * @hide 511 */ msync(long address, long byteCount, int flags)512 public void msync(long address, long byteCount, int flags) throws ErrnoException { os.msync(address, byteCount, flags); } 513 514 /** 515 * @hide 516 */ munlock(long address, long byteCount)517 public void munlock(long address, long byteCount) throws ErrnoException { os.munlock(address, byteCount); } 518 519 /** 520 * @hide 521 */ munmap(long address, long byteCount)522 public void munmap(long address, long byteCount) throws ErrnoException { os.munmap(address, byteCount); } 523 524 /** 525 * Opens the file specified by {@code path}. 526 * 527 * If the specified file does not exist, it may optionally (if 528 * {@link android.system.OsConstants#O_CREAT} is specified in flags) 529 * be created by {@link #open(String, int, int)}. 530 * 531 * The argument flags must include one of the following access 532 * modes: {@link android.system.OsConstants#O_RDONLY}, 533 * {@link android.system.OsConstants#O_WRONLY}, or 534 * {@link android.system.OsConstants#O_RDWR}. These request opening the 535 * file read-only, write-only, or read/write, respectively. 536 * 537 * In addition, zero or more file creation flags and file status 538 * flags can be bitwise-or'd in flags. The file creation flags are 539 * {@link android.system.OsConstants#O_CLOEXEC}, {@link android.system.OsConstants#O_CREAT}, 540 * {@link android.system.OsConstants#O_DIRECTORY}, {@link android.system.OsConstants#O_EXCL}, 541 * {@link android.system.OsConstants#O_NOCTTY}, {@link android.system.OsConstants#O_NOFOLLOW}, 542 * {@link android.system.OsConstants#O_TMPFILE}, and {@link android.system.OsConstants#O_TRUNC}. 543 * 544 * @see <a href="https://man7.org/linux/man-pages/man2/open.2.html">open(2)</a>. 545 * 546 * @param path path of the file to be opened 547 * @param flags bitmask of the access, file creation and file status flags 548 * @param mode specifies the file mode bits to be applied when a new file is 549 * created. If neither {@link android.system.OsConstants#O_CREAT} 550 * nor {@link android.system.OsConstants#O_TMPFILE} is specified in 551 * flags, then mode is ignored (and can thus be specified as 0, or simply omitted). 552 * @return {@link FileDescriptor} of an opened file 553 * @throws ErrnoException if requested access to the file is not allowed, or search 554 * permission is denied for one of the directories in the 555 * path prefix of {@code path}, or the file did not exist yet and 556 * write access to the parent directory is not allowed, or other error. 557 * See the full list of errors in the "See Also" list. 558 * 559 * @hide 560 */ 561 @UnsupportedAppUsage 562 @SystemApi(client = MODULE_LIBRARIES) open(@ullable String path, int flags, int mode)563 public FileDescriptor open(@Nullable String path, int flags, int mode) throws ErrnoException { return os.open(path, flags, mode); } 564 565 /** 566 * @hide 567 */ pipe2(int flags)568 public FileDescriptor[] pipe2(int flags) throws ErrnoException { return os.pipe2(flags); } 569 570 /** 571 * @hide 572 */ poll(StructPollfd[] fds, int timeoutMs)573 public int poll(StructPollfd[] fds, int timeoutMs) throws ErrnoException { return os.poll(fds, timeoutMs); } 574 575 /** 576 * @hide 577 */ posix_fallocate(FileDescriptor fd, long offset, long length)578 public void posix_fallocate(FileDescriptor fd, long offset, long length) throws ErrnoException { os.posix_fallocate(fd, offset, length); } 579 580 /** 581 * @hide 582 */ prctl(int option, long arg2, long arg3, long arg4, long arg5)583 public int prctl(int option, long arg2, long arg3, long arg4, long arg5) throws ErrnoException { return os.prctl(option, arg2, arg3, arg4, arg5); } 584 585 /** 586 * @hide 587 */ pread(FileDescriptor fd, ByteBuffer buffer, long offset)588 public int pread(FileDescriptor fd, ByteBuffer buffer, long offset) throws ErrnoException, InterruptedIOException { return os.pread(fd, buffer, offset); } 589 590 /** 591 * @hide 592 */ pread(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, long offset)593 public int pread(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, long offset) throws ErrnoException, InterruptedIOException { return os.pread(fd, bytes, byteOffset, byteCount, offset); } 594 595 /** 596 * @hide 597 */ pwrite(FileDescriptor fd, ByteBuffer buffer, long offset)598 public int pwrite(FileDescriptor fd, ByteBuffer buffer, long offset) throws ErrnoException, InterruptedIOException { return os.pwrite(fd, buffer, offset); } 599 600 /** 601 * @hide 602 */ pwrite(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, long offset)603 public int pwrite(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, long offset) throws ErrnoException, InterruptedIOException { return os.pwrite(fd, bytes, byteOffset, byteCount, offset); } 604 605 /** 606 * @hide 607 */ read(FileDescriptor fd, ByteBuffer buffer)608 public int read(FileDescriptor fd, ByteBuffer buffer) throws ErrnoException, InterruptedIOException { return os.read(fd, buffer); } 609 610 /** 611 * @hide 612 */ read(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount)613 public int read(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount) throws ErrnoException, InterruptedIOException { return os.read(fd, bytes, byteOffset, byteCount); } 614 615 /** 616 * @hide 617 */ 618 @UnsupportedAppUsage readlink(String path)619 public String readlink(String path) throws ErrnoException { return os.readlink(path); } 620 621 /** 622 * @hide 623 */ realpath(String path)624 public String realpath(String path) throws ErrnoException { return os.realpath(path); } 625 626 /** 627 * @hide 628 */ readv(FileDescriptor fd, Object[] buffers, int[] offsets, int[] byteCounts)629 public int readv(FileDescriptor fd, Object[] buffers, int[] offsets, int[] byteCounts) throws ErrnoException, InterruptedIOException { return os.readv(fd, buffers, offsets, byteCounts); } 630 631 /** 632 * @hide 633 */ recvfrom(FileDescriptor fd, ByteBuffer buffer, int flags, InetSocketAddress srcAddress)634 public int recvfrom(FileDescriptor fd, ByteBuffer buffer, int flags, InetSocketAddress srcAddress) throws ErrnoException, SocketException { return os.recvfrom(fd, buffer, flags, srcAddress); } 635 636 /** 637 * @hide 638 */ recvfrom(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, InetSocketAddress srcAddress)639 public int recvfrom(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, InetSocketAddress srcAddress) throws ErrnoException, SocketException { return os.recvfrom(fd, bytes, byteOffset, byteCount, flags, srcAddress); } 640 641 /** 642 * @hide 643 */ recvmsg(FileDescriptor fd, StructMsghdr msg, int flags)644 public int recvmsg(FileDescriptor fd, StructMsghdr msg, int flags) throws ErrnoException, SocketException { return os.recvmsg(fd, msg, flags); } 645 646 /** 647 * Deletes a name from the filesystem. 648 * 649 * If the removed name was the last link to a file and no processes 650 * have the file open, the file is deleted and the space it was 651 * using is made available for reuse. 652 * 653 * If the name was the last link to a file, but any processes still 654 * have the file open, the file will remain in existence until the 655 * last file descriptor referring to it is closed. 656 * 657 * If the name referred to a symbolic link, the link is removed. 658 * 659 * If the name referred to a socket, FIFO, or device, the name is 660 * removed, but processes which have the object open may continue to 661 * use it. 662 * 663 * @see <a href="https://man7.org/linux/man-pages/man3/remove.3.html">remove(3)</a>. 664 * 665 * @param path file to delete 666 * @throws ErrnoException if access to {@code path} is not allowed, an I/O error occurred. 667 * See the full list of errors in the "See Also" list. 668 * 669 * @hide 670 */ 671 @UnsupportedAppUsage 672 @SystemApi(client = MODULE_LIBRARIES) remove(@ullable String path)673 public void remove(@Nullable String path) throws ErrnoException { os.remove(path); } 674 675 /** 676 * @hide 677 */ 678 @UnsupportedAppUsage removexattr(String path, String name)679 public void removexattr(String path, String name) throws ErrnoException { os.removexattr(path, name); } 680 681 /** 682 * Renames a file, moving it between directories if required. 683 * 684 * @see <a href="https://man7.org/linux/man-pages/man2/rename.2.html">rename(2)</a>. 685 * 686 * @param oldPath file to be moved to a new location {@code newPath} 687 * @param newPath destination to move file {@code oldPath} 688 * @throws ErrnoException if write permission is denied for the directory containing 689 * {@code oldPath} or {@code newPath}, or, search permission is denied for 690 * one of the directories in the path prefix of {@code oldPath} or 691 * {@code newPath}, or {@code oldPath} is a directory and does not allow 692 * write permission. See the full list of errors in the "See Also" list. 693 * 694 * @hide 695 */ 696 @UnsupportedAppUsage 697 @SystemApi(client = MODULE_LIBRARIES) rename(@ullable String oldPath, @Nullable String newPath)698 public void rename(@Nullable String oldPath, @Nullable String newPath) throws ErrnoException { os.rename(oldPath, newPath); } 699 700 /** 701 * @hide 702 */ sendfile(FileDescriptor outFd, FileDescriptor inFd, Int64Ref offset, long byteCount)703 public long sendfile(FileDescriptor outFd, FileDescriptor inFd, Int64Ref offset, long byteCount) throws ErrnoException { return os.sendfile(outFd, inFd, offset, byteCount); } 704 705 /** 706 * @hide 707 */ sendmsg(FileDescriptor fd, StructMsghdr msg, int flags)708 public int sendmsg(FileDescriptor fd, StructMsghdr msg, int flags) throws ErrnoException, SocketException { return os.sendmsg(fd, msg, flags); } 709 710 /** 711 * @hide 712 */ sendto(FileDescriptor fd, ByteBuffer buffer, int flags, InetAddress inetAddress, int port)713 public int sendto(FileDescriptor fd, ByteBuffer buffer, int flags, InetAddress inetAddress, int port) throws ErrnoException, SocketException { return os.sendto(fd, buffer, flags, inetAddress, port); } 714 715 /** 716 * @hide 717 */ sendto(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, InetAddress inetAddress, int port)718 public int sendto(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, InetAddress inetAddress, int port) throws ErrnoException, SocketException { return os.sendto(fd, bytes, byteOffset, byteCount, flags, inetAddress, port); } 719 720 /** 721 * @hide 722 */ sendto(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, SocketAddress address)723 public int sendto(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, SocketAddress address) throws ErrnoException, SocketException { return os.sendto(fd, bytes, byteOffset, byteCount, flags, address); } 724 725 /** 726 * @hide 727 */ setegid(int egid)728 public void setegid(int egid) throws ErrnoException { os.setegid(egid); } 729 730 /** 731 * @hide 732 */ 733 @UnsupportedAppUsage setenv(String name, String value, boolean overwrite)734 public void setenv(String name, String value, boolean overwrite) throws ErrnoException { os.setenv(name, value, overwrite); } 735 736 /** 737 * @hide 738 */ seteuid(int euid)739 public void seteuid(int euid) throws ErrnoException { os.seteuid(euid); } 740 741 /** 742 * @hide 743 */ setgid(int gid)744 public void setgid(int gid) throws ErrnoException { os.setgid(gid); } 745 746 /** 747 * @hide 748 */ setpgid(int pid, int pgid)749 public void setpgid(int pid, int pgid) throws ErrnoException { os.setpgid(pid, pgid); } 750 751 /** 752 * @hide 753 */ setregid(int rgid, int egid)754 public void setregid(int rgid, int egid) throws ErrnoException { os.setregid(rgid, egid); } 755 756 /** 757 * @hide 758 */ setreuid(int ruid, int euid)759 public void setreuid(int ruid, int euid) throws ErrnoException { os.setreuid(ruid, euid); } 760 761 /** 762 * @hide 763 */ setsid()764 public int setsid() throws ErrnoException { return os.setsid(); } 765 766 /** 767 * @hide 768 */ setsockoptByte(FileDescriptor fd, int level, int option, int value)769 public void setsockoptByte(FileDescriptor fd, int level, int option, int value) throws ErrnoException { os.setsockoptByte(fd, level, option, value); } 770 771 /** 772 * @hide 773 */ setsockoptIfreq(FileDescriptor fd, int level, int option, String value)774 public void setsockoptIfreq(FileDescriptor fd, int level, int option, String value) throws ErrnoException { os.setsockoptIfreq(fd, level, option, value); } 775 776 /** 777 * @hide 778 */ setsockoptInt(FileDescriptor fd, int level, int option, int value)779 public void setsockoptInt(FileDescriptor fd, int level, int option, int value) throws ErrnoException { os.setsockoptInt(fd, level, option, value); } 780 781 /** 782 * @hide 783 */ setsockoptIpMreqn(FileDescriptor fd, int level, int option, int value)784 public void setsockoptIpMreqn(FileDescriptor fd, int level, int option, int value) throws ErrnoException { os.setsockoptIpMreqn(fd, level, option, value); } 785 786 /** 787 * @hide 788 */ setsockoptGroupReq(FileDescriptor fd, int level, int option, StructGroupReq value)789 public void setsockoptGroupReq(FileDescriptor fd, int level, int option, StructGroupReq value) throws ErrnoException { os.setsockoptGroupReq(fd, level, option, value); } 790 791 /** 792 * @hide 793 */ setsockoptLinger(FileDescriptor fd, int level, int option, StructLinger value)794 public void setsockoptLinger(FileDescriptor fd, int level, int option, StructLinger value) throws ErrnoException { os.setsockoptLinger(fd, level, option, value); } 795 796 /** 797 * @hide 798 */ 799 @UnsupportedAppUsage setsockoptTimeval(FileDescriptor fd, int level, int option, StructTimeval value)800 public void setsockoptTimeval(FileDescriptor fd, int level, int option, StructTimeval value) throws ErrnoException { os.setsockoptTimeval(fd, level, option, value); } 801 802 /** 803 * @hide 804 */ setuid(int uid)805 public void setuid(int uid) throws ErrnoException { os.setuid(uid); } 806 807 /** 808 * @hide 809 */ 810 @UnsupportedAppUsage setxattr(String path, String name, byte[] value, int flags)811 public void setxattr(String path, String name, byte[] value, int flags) throws ErrnoException { os.setxattr(path, name, value, flags); } 812 813 /** 814 * @hide 815 */ shutdown(FileDescriptor fd, int how)816 public void shutdown(FileDescriptor fd, int how) throws ErrnoException { os.shutdown(fd, how); } 817 818 /** 819 * @hide 820 */ socket(int domain, int type, int protocol)821 public FileDescriptor socket(int domain, int type, int protocol) throws ErrnoException { return os.socket(domain, type, protocol); } 822 823 /** 824 * @hide 825 */ socketpair(int domain, int type, int protocol, FileDescriptor fd1, FileDescriptor fd2)826 public void socketpair(int domain, int type, int protocol, FileDescriptor fd1, FileDescriptor fd2) throws ErrnoException { os.socketpair(domain, type, protocol, fd1, fd2); } 827 828 /** 829 * @hide 830 */ splice(FileDescriptor fdIn, Int64Ref offIn, FileDescriptor fdOut, Int64Ref offOut, long len, int flags)831 public long splice(FileDescriptor fdIn, Int64Ref offIn, FileDescriptor fdOut, Int64Ref offOut, long len, int flags) throws ErrnoException { return os.splice(fdIn, offIn, fdOut, offOut, len, flags); } 832 833 /** 834 * Returns information about a file. 835 * 836 * @see <a href="https://man7.org/linux/man-pages/man2/lstat.2.html">stat(2)</a>. 837 * 838 * @param path path to file to get info about 839 * @return {@link StructStat} containing information about the file 840 * @throws ErrnoException See the full list of errors in the "See Also" list. 841 * 842 * @hide 843 */ 844 @UnsupportedAppUsage 845 @SystemApi(client = MODULE_LIBRARIES) stat(@ullable String path)846 public @Nullable StructStat stat(@Nullable String path) throws ErrnoException { return os.stat(path); } 847 848 /** 849 * @hide 850 */ 851 @UnsupportedAppUsage statvfs(String path)852 public StructStatVfs statvfs(String path) throws ErrnoException { return os.statvfs(path); } 853 854 /** 855 * @hide 856 */ strerror(int errno)857 public String strerror(int errno) { return os.strerror(errno); } 858 859 /** 860 * @hide 861 */ strsignal(int signal)862 public String strsignal(int signal) { return os.strsignal(signal); } 863 864 /** 865 * @hide 866 */ 867 @UnsupportedAppUsage symlink(String oldPath, String newPath)868 public void symlink(String oldPath, String newPath) throws ErrnoException { os.symlink(oldPath, newPath); } 869 870 /** 871 * @hide 872 */ 873 @UnsupportedAppUsage sysconf(int name)874 public long sysconf(int name) { return os.sysconf(name); } 875 876 /** 877 * @hide 878 */ tcdrain(FileDescriptor fd)879 public void tcdrain(FileDescriptor fd) throws ErrnoException { os.tcdrain(fd); } 880 881 /** 882 * @hide 883 */ tcsendbreak(FileDescriptor fd, int duration)884 public void tcsendbreak(FileDescriptor fd, int duration) throws ErrnoException { os.tcsendbreak(fd, duration); } 885 886 /** 887 * @hide 888 */ umask(int mask)889 public int umask(int mask) { return os.umask(mask); } 890 891 /** 892 * @hide 893 */ uname()894 public StructUtsname uname() { return os.uname(); } 895 896 /** 897 * Deletes a name from the filesystem. 898 * 899 * If the removed name was the last link to a file and no processes 900 * have the file open, the file is deleted and the space it was 901 * using is made available for reuse. 902 * 903 * If the name was the last link to a file, but any processes still 904 * have the file open, the file will remain in existence until the 905 * last file descriptor referring to it is closed. 906 * 907 * If the name referred to a symbolic link, the link is removed. 908 * 909 * If the name referred to a socket, FIFO, or device, the name is 910 * removed, but processes which have the object open may continue to 911 * use it. 912 * 913 * @see <a href="https://man7.org/linux/man-pages/man2/unlink.2.html">unlink(2)</a>. 914 * 915 * @param pathname file to unlink 916 * @throws ErrnoException if access to {@code pathname} is not allowed, an I/O error occurred. 917 * See the full list of errors in the "See Also" list. 918 * 919 * @hide 920 */ 921 @UnsupportedAppUsage 922 @SystemApi(client = MODULE_LIBRARIES) unlink(@ullable String pathname)923 public void unlink(@Nullable String pathname) throws ErrnoException { os.unlink(pathname); } 924 925 /** 926 * @hide 927 */ unsetenv(String name)928 public void unsetenv(String name) throws ErrnoException { os.unsetenv(name); } 929 930 /** 931 * @hide 932 */ waitpid(int pid, Int32Ref status, int options)933 public int waitpid(int pid, Int32Ref status, int options) throws ErrnoException { return os.waitpid(pid, status, options); } 934 935 /** 936 * @hide 937 */ write(FileDescriptor fd, ByteBuffer buffer)938 public int write(FileDescriptor fd, ByteBuffer buffer) throws ErrnoException, InterruptedIOException { return os.write(fd, buffer); } 939 940 /** 941 * @hide 942 */ write(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount)943 public int write(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount) throws ErrnoException, InterruptedIOException { return os.write(fd, bytes, byteOffset, byteCount); } 944 945 /** 946 * @hide 947 */ writev(FileDescriptor fd, Object[] buffers, int[] offsets, int[] byteCounts)948 public int writev(FileDescriptor fd, Object[] buffers, int[] offsets, int[] byteCounts) throws ErrnoException, InterruptedIOException { return os.writev(fd, buffers, offsets, byteCounts); } 949 950 951 /** 952 * @hide 953 */ toString()954 public String toString() { return "ForwardingOs{os=" + os + "}"; } 955 } 956