1 /* 2 * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package sun.nio.ch; 27 28 import dalvik.system.BlockGuard; 29 30 import java.io.FileDescriptor; 31 import java.io.IOException; 32 33 class FileDispatcherImpl extends FileDispatcher { 34 35 // Android-removed: Code to load native libraries, doesn't make sense on Android. 36 /* 37 static { 38 IOUtil.load(); 39 init(); 40 } 41 */ 42 FileDispatcherImpl()43 FileDispatcherImpl() { 44 } 45 read(FileDescriptor fd, long address, int len)46 int read(FileDescriptor fd, long address, int len) throws IOException { 47 // Android-added: BlockGuard support. 48 BlockGuard.getThreadPolicy().onReadFromDisk(); 49 return read0(fd, address, len); 50 } 51 pread(FileDescriptor fd, long address, int len, long position)52 int pread(FileDescriptor fd, long address, int len, long position) 53 throws IOException 54 { 55 // Android-added: BlockGuard support. 56 BlockGuard.getThreadPolicy().onReadFromDisk(); 57 return pread0(fd, address, len, position); 58 } 59 readv(FileDescriptor fd, long address, int len)60 long readv(FileDescriptor fd, long address, int len) throws IOException { 61 // Android-added: BlockGuard support. 62 BlockGuard.getThreadPolicy().onReadFromDisk(); 63 return readv0(fd, address, len); 64 } 65 write(FileDescriptor fd, long address, int len)66 int write(FileDescriptor fd, long address, int len) throws IOException { 67 // Android-added: BlockGuard support. 68 BlockGuard.getThreadPolicy().onWriteToDisk(); 69 return write0(fd, address, len); 70 } 71 pwrite(FileDescriptor fd, long address, int len, long position)72 int pwrite(FileDescriptor fd, long address, int len, long position) 73 throws IOException 74 { 75 // Android-added: BlockGuard support. 76 BlockGuard.getThreadPolicy().onWriteToDisk(); 77 return pwrite0(fd, address, len, position); 78 } 79 writev(FileDescriptor fd, long address, int len)80 long writev(FileDescriptor fd, long address, int len) 81 throws IOException 82 { 83 // Android-added: BlockGuard support. 84 BlockGuard.getThreadPolicy().onWriteToDisk(); 85 return writev0(fd, address, len); 86 } 87 force(FileDescriptor fd, boolean metaData)88 int force(FileDescriptor fd, boolean metaData) throws IOException { 89 // Android-added: BlockGuard support. 90 BlockGuard.getThreadPolicy().onWriteToDisk(); 91 return force0(fd, metaData); 92 } 93 truncate(FileDescriptor fd, long size)94 int truncate(FileDescriptor fd, long size) throws IOException { 95 // Android-added: BlockGuard support. 96 BlockGuard.getThreadPolicy().onWriteToDisk(); 97 return truncate0(fd, size); 98 } 99 size(FileDescriptor fd)100 long size(FileDescriptor fd) throws IOException { 101 // Android-added: BlockGuard support. 102 BlockGuard.getThreadPolicy().onReadFromDisk(); 103 return size0(fd); 104 } 105 lock(FileDescriptor fd, boolean blocking, long pos, long size, boolean shared)106 int lock(FileDescriptor fd, boolean blocking, long pos, long size, 107 boolean shared) throws IOException 108 { 109 // Android-added: BlockGuard support. 110 BlockGuard.getThreadPolicy().onWriteToDisk(); 111 return lock0(fd, blocking, pos, size, shared); 112 } 113 release(FileDescriptor fd, long pos, long size)114 void release(FileDescriptor fd, long pos, long size) throws IOException { 115 // Android-added: BlockGuard support. 116 BlockGuard.getThreadPolicy().onWriteToDisk(); 117 release0(fd, pos, size); 118 } 119 close(FileDescriptor fd)120 void close(FileDescriptor fd) throws IOException { 121 close0(fd); 122 } 123 preClose(FileDescriptor fd)124 void preClose(FileDescriptor fd) throws IOException { 125 preClose0(fd); 126 } 127 duplicateForMapping(FileDescriptor fd)128 FileDescriptor duplicateForMapping(FileDescriptor fd) { 129 // file descriptor not required for mapping operations; okay 130 // to return invalid file descriptor. 131 return new FileDescriptor(); 132 } 133 canTransferToDirectly(java.nio.channels.SelectableChannel sc)134 boolean canTransferToDirectly(java.nio.channels.SelectableChannel sc) { 135 return true; 136 } 137 transferToDirectlyNeedsPositionLock()138 boolean transferToDirectlyNeedsPositionLock() { 139 return false; 140 } 141 142 // -- Native methods -- 143 read0(FileDescriptor fd, long address, int len)144 static native int read0(FileDescriptor fd, long address, int len) 145 throws IOException; 146 pread0(FileDescriptor fd, long address, int len, long position)147 static native int pread0(FileDescriptor fd, long address, int len, 148 long position) throws IOException; 149 readv0(FileDescriptor fd, long address, int len)150 static native long readv0(FileDescriptor fd, long address, int len) 151 throws IOException; 152 write0(FileDescriptor fd, long address, int len)153 static native int write0(FileDescriptor fd, long address, int len) 154 throws IOException; 155 pwrite0(FileDescriptor fd, long address, int len, long position)156 static native int pwrite0(FileDescriptor fd, long address, int len, 157 long position) throws IOException; 158 writev0(FileDescriptor fd, long address, int len)159 static native long writev0(FileDescriptor fd, long address, int len) 160 throws IOException; 161 force0(FileDescriptor fd, boolean metaData)162 static native int force0(FileDescriptor fd, boolean metaData) 163 throws IOException; 164 truncate0(FileDescriptor fd, long size)165 static native int truncate0(FileDescriptor fd, long size) 166 throws IOException; 167 size0(FileDescriptor fd)168 static native long size0(FileDescriptor fd) throws IOException; 169 lock0(FileDescriptor fd, boolean blocking, long pos, long size, boolean shared)170 static native int lock0(FileDescriptor fd, boolean blocking, long pos, 171 long size, boolean shared) throws IOException; 172 release0(FileDescriptor fd, long pos, long size)173 static native void release0(FileDescriptor fd, long pos, long size) 174 throws IOException; 175 close0(FileDescriptor fd)176 static native void close0(FileDescriptor fd) throws IOException; 177 preClose0(FileDescriptor fd)178 static native void preClose0(FileDescriptor fd) throws IOException; 179 closeIntFD(int fd)180 static native void closeIntFD(int fd) throws IOException; 181 182 // Android-removed: Code to load native libraries, doesn't make sense on Android. 183 // static native void init(); 184 185 } 186