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(boolean append)43 FileDispatcherImpl(boolean append) { 44 /* append is ignored */ 45 } 46 FileDispatcherImpl()47 FileDispatcherImpl() { 48 } 49 read(FileDescriptor fd, long address, int len)50 int read(FileDescriptor fd, long address, int len) throws IOException { 51 // Android-added: BlockGuard support. 52 BlockGuard.getThreadPolicy().onReadFromDisk(); 53 return read0(fd, address, len); 54 } 55 pread(FileDescriptor fd, long address, int len, long position)56 int pread(FileDescriptor fd, long address, int len, long position) 57 throws IOException 58 { 59 // Android-added: BlockGuard support. 60 BlockGuard.getThreadPolicy().onReadFromDisk(); 61 return pread0(fd, address, len, position); 62 } 63 readv(FileDescriptor fd, long address, int len)64 long readv(FileDescriptor fd, long address, int len) throws IOException { 65 // Android-added: BlockGuard support. 66 BlockGuard.getThreadPolicy().onReadFromDisk(); 67 return readv0(fd, address, len); 68 } 69 write(FileDescriptor fd, long address, int len)70 int write(FileDescriptor fd, long address, int len) throws IOException { 71 // Android-added: BlockGuard support. 72 BlockGuard.getThreadPolicy().onWriteToDisk(); 73 return write0(fd, address, len); 74 } 75 pwrite(FileDescriptor fd, long address, int len, long position)76 int pwrite(FileDescriptor fd, long address, int len, long position) 77 throws IOException 78 { 79 // Android-added: BlockGuard support. 80 BlockGuard.getThreadPolicy().onWriteToDisk(); 81 return pwrite0(fd, address, len, position); 82 } 83 writev(FileDescriptor fd, long address, int len)84 long writev(FileDescriptor fd, long address, int len) 85 throws IOException 86 { 87 // Android-added: BlockGuard support. 88 BlockGuard.getThreadPolicy().onWriteToDisk(); 89 return writev0(fd, address, len); 90 } 91 force(FileDescriptor fd, boolean metaData)92 int force(FileDescriptor fd, boolean metaData) throws IOException { 93 // Android-added: BlockGuard support. 94 BlockGuard.getThreadPolicy().onWriteToDisk(); 95 return force0(fd, metaData); 96 } 97 truncate(FileDescriptor fd, long size)98 int truncate(FileDescriptor fd, long size) throws IOException { 99 // Android-added: BlockGuard support. 100 BlockGuard.getThreadPolicy().onWriteToDisk(); 101 return truncate0(fd, size); 102 } 103 size(FileDescriptor fd)104 long size(FileDescriptor fd) throws IOException { 105 // Android-added: BlockGuard support. 106 BlockGuard.getThreadPolicy().onReadFromDisk(); 107 return size0(fd); 108 } 109 lock(FileDescriptor fd, boolean blocking, long pos, long size, boolean shared)110 int lock(FileDescriptor fd, boolean blocking, long pos, long size, 111 boolean shared) throws IOException 112 { 113 // Android-added: BlockGuard support. 114 BlockGuard.getThreadPolicy().onWriteToDisk(); 115 return lock0(fd, blocking, pos, size, shared); 116 } 117 release(FileDescriptor fd, long pos, long size)118 void release(FileDescriptor fd, long pos, long size) throws IOException { 119 // Android-added: BlockGuard support. 120 BlockGuard.getThreadPolicy().onWriteToDisk(); 121 release0(fd, pos, size); 122 } 123 close(FileDescriptor fd)124 void close(FileDescriptor fd) throws IOException { 125 close0(fd); 126 } 127 preClose(FileDescriptor fd)128 void preClose(FileDescriptor fd) throws IOException { 129 preClose0(fd); 130 } 131 duplicateForMapping(FileDescriptor fd)132 FileDescriptor duplicateForMapping(FileDescriptor fd) { 133 // file descriptor not required for mapping operations; okay 134 // to return invalid file descriptor. 135 return new FileDescriptor(); 136 } 137 canTransferToDirectly(java.nio.channels.SelectableChannel sc)138 boolean canTransferToDirectly(java.nio.channels.SelectableChannel sc) { 139 return true; 140 } 141 transferToDirectlyNeedsPositionLock()142 boolean transferToDirectlyNeedsPositionLock() { 143 return false; 144 } 145 146 // -- Native methods -- 147 read0(FileDescriptor fd, long address, int len)148 static native int read0(FileDescriptor fd, long address, int len) 149 throws IOException; 150 pread0(FileDescriptor fd, long address, int len, long position)151 static native int pread0(FileDescriptor fd, long address, int len, 152 long position) throws IOException; 153 readv0(FileDescriptor fd, long address, int len)154 static native long readv0(FileDescriptor fd, long address, int len) 155 throws IOException; 156 write0(FileDescriptor fd, long address, int len)157 static native int write0(FileDescriptor fd, long address, int len) 158 throws IOException; 159 pwrite0(FileDescriptor fd, long address, int len, long position)160 static native int pwrite0(FileDescriptor fd, long address, int len, 161 long position) throws IOException; 162 writev0(FileDescriptor fd, long address, int len)163 static native long writev0(FileDescriptor fd, long address, int len) 164 throws IOException; 165 force0(FileDescriptor fd, boolean metaData)166 static native int force0(FileDescriptor fd, boolean metaData) 167 throws IOException; 168 truncate0(FileDescriptor fd, long size)169 static native int truncate0(FileDescriptor fd, long size) 170 throws IOException; 171 size0(FileDescriptor fd)172 static native long size0(FileDescriptor fd) throws IOException; 173 lock0(FileDescriptor fd, boolean blocking, long pos, long size, boolean shared)174 static native int lock0(FileDescriptor fd, boolean blocking, long pos, 175 long size, boolean shared) throws IOException; 176 release0(FileDescriptor fd, long pos, long size)177 static native void release0(FileDescriptor fd, long pos, long size) 178 throws IOException; 179 close0(FileDescriptor fd)180 static native void close0(FileDescriptor fd) throws IOException; 181 preClose0(FileDescriptor fd)182 static native void preClose0(FileDescriptor fd) throws IOException; 183 closeIntFD(int fd)184 static native void closeIntFD(int fd) throws IOException; 185 186 // Android-removed: Code to load native libraries, doesn't make sense on Android. 187 // static native void init(); 188 189 } 190