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