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 android.system.ErrnoException; 20 import android.system.GaiException; 21 import android.system.Int32Ref; 22 import android.system.Int64Ref; 23 import android.system.StructAddrinfo; 24 import android.system.StructCapUserData; 25 import android.system.StructCapUserHeader; 26 import android.system.StructFlock; 27 import android.system.StructGroupReq; 28 import android.system.StructIfaddrs; 29 import android.system.StructLinger; 30 import android.system.StructPasswd; 31 import android.system.StructPollfd; 32 import android.system.StructRlimit; 33 import android.system.StructStat; 34 import android.system.StructStatVfs; 35 import android.system.StructTimeval; 36 import android.system.StructUcred; 37 import android.system.StructUtsname; 38 39 import java.io.FileDescriptor; 40 import java.io.InterruptedIOException; 41 import java.net.InetAddress; 42 import java.net.InetSocketAddress; 43 import java.net.SocketAddress; 44 import java.net.SocketException; 45 import java.nio.ByteBuffer; 46 47 public interface Os { 48 public FileDescriptor accept(FileDescriptor fd, SocketAddress peerAddress) throws ErrnoException, SocketException; 49 public boolean access(String path, int mode) throws ErrnoException; 50 public InetAddress[] android_getaddrinfo(String node, StructAddrinfo hints, int netId) throws GaiException; 51 public void bind(FileDescriptor fd, InetAddress address, int port) throws ErrnoException, SocketException; 52 public void bind(FileDescriptor fd, SocketAddress address) throws ErrnoException, SocketException; 53 public StructCapUserData[] capget(StructCapUserHeader hdr) throws ErrnoException; 54 public void capset(StructCapUserHeader hdr, StructCapUserData[] data) throws ErrnoException; 55 public void chmod(String path, int mode) throws ErrnoException; 56 public void chown(String path, int uid, int gid) throws ErrnoException; 57 public void close(FileDescriptor fd) throws ErrnoException; 58 public void connect(FileDescriptor fd, InetAddress address, int port) throws ErrnoException, SocketException; 59 public void connect(FileDescriptor fd, SocketAddress address) throws ErrnoException, SocketException; 60 public FileDescriptor dup(FileDescriptor oldFd) throws ErrnoException; 61 public FileDescriptor dup2(FileDescriptor oldFd, int newFd) throws ErrnoException; 62 public String[] environ(); 63 public void execv(String filename, String[] argv) throws ErrnoException; 64 public void execve(String filename, String[] argv, String[] envp) throws ErrnoException; 65 public void fchmod(FileDescriptor fd, int mode) throws ErrnoException; 66 public void fchown(FileDescriptor fd, int uid, int gid) throws ErrnoException; 67 public int fcntlFlock(FileDescriptor fd, int cmd, StructFlock arg) throws ErrnoException, InterruptedIOException; 68 public int fcntlInt(FileDescriptor fd, int cmd, int arg) throws ErrnoException; 69 public int fcntlVoid(FileDescriptor fd, int cmd) throws ErrnoException; 70 public void fdatasync(FileDescriptor fd) throws ErrnoException; 71 public StructStat fstat(FileDescriptor fd) throws ErrnoException; 72 public StructStatVfs fstatvfs(FileDescriptor fd) throws ErrnoException; 73 public void fsync(FileDescriptor fd) throws ErrnoException; 74 public void ftruncate(FileDescriptor fd, long length) throws ErrnoException; 75 public String gai_strerror(int error); 76 public int getegid(); 77 public int geteuid(); 78 public int getgid(); 79 public String getenv(String name); 80 /* TODO: break into getnameinfoHost and getnameinfoService? */ 81 public String getnameinfo(InetAddress address, int flags) throws GaiException; 82 public SocketAddress getpeername(FileDescriptor fd) throws ErrnoException; 83 public int getpgid(int pid) throws ErrnoException; 84 public int getpid(); 85 public int getppid(); 86 public StructPasswd getpwnam(String name) throws ErrnoException; 87 public StructPasswd getpwuid(int uid) throws ErrnoException; 88 public StructRlimit getrlimit(int resource) throws ErrnoException; 89 public SocketAddress getsockname(FileDescriptor fd) throws ErrnoException; 90 public int getsockoptByte(FileDescriptor fd, int level, int option) throws ErrnoException; 91 public InetAddress getsockoptInAddr(FileDescriptor fd, int level, int option) throws ErrnoException; 92 public int getsockoptInt(FileDescriptor fd, int level, int option) throws ErrnoException; 93 public StructLinger getsockoptLinger(FileDescriptor fd, int level, int option) throws ErrnoException; 94 public StructTimeval getsockoptTimeval(FileDescriptor fd, int level, int option) throws ErrnoException; 95 public StructUcred getsockoptUcred(FileDescriptor fd, int level, int option) throws ErrnoException; 96 public int gettid(); 97 public int getuid(); 98 public byte[] getxattr(String path, String name) throws ErrnoException; 99 public StructIfaddrs[] getifaddrs() throws ErrnoException; 100 public String if_indextoname(int index); 101 public int if_nametoindex(String name); 102 public InetAddress inet_pton(int family, String address); 103 public int ioctlFlags(FileDescriptor fd, String interfaceName) throws ErrnoException; 104 public InetAddress ioctlInetAddress(FileDescriptor fd, int cmd, String interfaceName) throws ErrnoException; 105 public int ioctlInt(FileDescriptor fd, int cmd, Int32Ref arg) throws ErrnoException; 106 public int ioctlMTU(FileDescriptor fd, String interfaceName) throws ErrnoException; 107 public boolean isatty(FileDescriptor fd); 108 public void kill(int pid, int signal) throws ErrnoException; 109 public void lchown(String path, int uid, int gid) throws ErrnoException; 110 public void link(String oldPath, String newPath) throws ErrnoException; 111 public void listen(FileDescriptor fd, int backlog) throws ErrnoException; 112 public String[] listxattr(String path) throws ErrnoException; 113 public long lseek(FileDescriptor fd, long offset, int whence) throws ErrnoException; 114 public StructStat lstat(String path) throws ErrnoException; 115 public void mincore(long address, long byteCount, byte[] vector) throws ErrnoException; 116 public void mkdir(String path, int mode) throws ErrnoException; 117 public void mkfifo(String path, int mode) throws ErrnoException; 118 public void mlock(long address, long byteCount) throws ErrnoException; 119 public long mmap(long address, long byteCount, int prot, int flags, FileDescriptor fd, long offset) throws ErrnoException; 120 public void msync(long address, long byteCount, int flags) throws ErrnoException; 121 public void munlock(long address, long byteCount) throws ErrnoException; 122 public void munmap(long address, long byteCount) throws ErrnoException; 123 public FileDescriptor open(String path, int flags, int mode) throws ErrnoException; 124 public FileDescriptor[] pipe2(int flags) throws ErrnoException; 125 /* TODO: if we used the non-standard ppoll(2) behind the scenes, we could take a long timeout. */ 126 public int poll(StructPollfd[] fds, int timeoutMs) throws ErrnoException; 127 public void posix_fallocate(FileDescriptor fd, long offset, long length) throws ErrnoException; 128 public int prctl(int option, long arg2, long arg3, long arg4, long arg5) throws ErrnoException; 129 public int pread(FileDescriptor fd, ByteBuffer buffer, long offset) throws ErrnoException, InterruptedIOException; 130 public int pread(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, long offset) throws ErrnoException, InterruptedIOException; 131 public int pwrite(FileDescriptor fd, ByteBuffer buffer, long offset) throws ErrnoException, InterruptedIOException; 132 public int pwrite(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, long offset) throws ErrnoException, InterruptedIOException; 133 public int read(FileDescriptor fd, ByteBuffer buffer) throws ErrnoException, InterruptedIOException; 134 public int read(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount) throws ErrnoException, InterruptedIOException; 135 public String readlink(String path) throws ErrnoException; 136 public String realpath(String path) throws ErrnoException; 137 public int readv(FileDescriptor fd, Object[] buffers, int[] offsets, int[] byteCounts) throws ErrnoException, InterruptedIOException; 138 public int recvfrom(FileDescriptor fd, ByteBuffer buffer, int flags, InetSocketAddress srcAddress) throws ErrnoException, SocketException; 139 public int recvfrom(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, InetSocketAddress srcAddress) throws ErrnoException, SocketException; 140 public void remove(String path) throws ErrnoException; 141 public void removexattr(String path, String name) throws ErrnoException; 142 public void rename(String oldPath, String newPath) throws ErrnoException; 143 public int sendto(FileDescriptor fd, ByteBuffer buffer, int flags, InetAddress inetAddress, int port) throws ErrnoException, SocketException; 144 public int sendto(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, InetAddress inetAddress, int port) throws ErrnoException, SocketException; 145 public int sendto(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, SocketAddress address) throws ErrnoException, SocketException; 146 public long sendfile(FileDescriptor outFd, FileDescriptor inFd, Int64Ref offset, long byteCount) throws ErrnoException; 147 public void setegid(int egid) throws ErrnoException; 148 public void setenv(String name, String value, boolean overwrite) throws ErrnoException; 149 public void seteuid(int euid) throws ErrnoException; 150 public void setgid(int gid) throws ErrnoException; 151 public void setpgid(int pid, int pgid) throws ErrnoException; 152 public void setregid(int rgid, int egid) throws ErrnoException; 153 public void setreuid(int ruid, int euid) throws ErrnoException; 154 public int setsid() throws ErrnoException; 155 public void setsockoptByte(FileDescriptor fd, int level, int option, int value) throws ErrnoException; 156 public void setsockoptIfreq(FileDescriptor fd, int level, int option, String value) throws ErrnoException; 157 public void setsockoptInt(FileDescriptor fd, int level, int option, int value) throws ErrnoException; 158 public void setsockoptIpMreqn(FileDescriptor fd, int level, int option, int value) throws ErrnoException; 159 public void setsockoptGroupReq(FileDescriptor fd, int level, int option, StructGroupReq value) throws ErrnoException; 160 public void setsockoptLinger(FileDescriptor fd, int level, int option, StructLinger value) throws ErrnoException; 161 public void setsockoptTimeval(FileDescriptor fd, int level, int option, StructTimeval value) throws ErrnoException; 162 public void setuid(int uid) throws ErrnoException; 163 public void setxattr(String path, String name, byte[] value, int flags) throws ErrnoException; 164 public void shutdown(FileDescriptor fd, int how) throws ErrnoException; 165 public FileDescriptor socket(int domain, int type, int protocol) throws ErrnoException; 166 public void socketpair(int domain, int type, int protocol, FileDescriptor fd1, FileDescriptor fd2) throws ErrnoException; 167 public long splice(FileDescriptor fdIn, Int64Ref offIn, FileDescriptor fdOut, Int64Ref offOut, long len, int flags) throws ErrnoException; 168 public StructStat stat(String path) throws ErrnoException; 169 public StructStatVfs statvfs(String path) throws ErrnoException; 170 public String strerror(int errno); 171 public String strsignal(int signal); 172 public void symlink(String oldPath, String newPath) throws ErrnoException; 173 public long sysconf(int name); 174 public void tcdrain(FileDescriptor fd) throws ErrnoException; 175 public void tcsendbreak(FileDescriptor fd, int duration) throws ErrnoException; 176 public int umask(int mask); 177 public StructUtsname uname(); 178 public void unlink(String pathname) throws ErrnoException; 179 public void unsetenv(String name) throws ErrnoException; 180 public int waitpid(int pid, Int32Ref status, int options) throws ErrnoException; 181 public int write(FileDescriptor fd, ByteBuffer buffer) throws ErrnoException, InterruptedIOException; 182 public int write(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount) throws ErrnoException, InterruptedIOException; 183 public int writev(FileDescriptor fd, Object[] buffers, int[] offsets, int[] byteCounts) throws ErrnoException, InterruptedIOException; 184 } 185