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