1 /*
   2  * Copyright (c) 2000, 2018, 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 java.io.FileDescriptor;
  29 import java.io.IOException;
  30 
  31 class FileDispatcherImpl extends FileDispatcher {
  32 
  33     static {
  34         IOUtil.load();
  35         init();
  36     }
  37 
  38     FileDispatcherImpl(boolean append) {
  39         /* append is ignored */
  40     }
  41 
  42     FileDispatcherImpl() {
  43     }
  44 
  45     int read(FileDescriptor fd, long address, int len) throws IOException {
  46         return read0(fd, address, len);
  47     }
  48 
  49     int pread(FileDescriptor fd, long address, int len, long position)
  50         throws IOException
  51     {
  52         return pread0(fd, address, len, position);
  53     }
  54 
  55     long readv(FileDescriptor fd, long address, int len) throws IOException {
  56         return readv0(fd, address, len);
  57     }
  58 
  59     int write(FileDescriptor fd, long address, int len) throws IOException {
  60         return write0(fd, address, len);
  61     }
  62 
  63     int pwrite(FileDescriptor fd, long address, int len, long position)
  64         throws IOException
  65     {
  66         return pwrite0(fd, address, len, position);
  67     }
  68 
  69     long writev(FileDescriptor fd, long address, int len)
  70         throws IOException
  71     {
  72         return writev0(fd, address, len);
  73     }
  74 
  75     int force(FileDescriptor fd, boolean metaData) throws IOException {
  76         return force0(fd, metaData);
  77     }
  78 
  79     int truncate(FileDescriptor fd, long size) throws IOException {
  80         return truncate0(fd, size);
  81     }
  82 
  83     int allocate(FileDescriptor fd, long size) throws IOException {
  84         return allocate0(fd, size);
  85     }
  86 
  87     long size(FileDescriptor fd) throws IOException {
  88         return size0(fd);
  89     }
  90 
  91     int lock(FileDescriptor fd, boolean blocking, long pos, long size,
  92              boolean shared) throws IOException
  93     {
  94         return lock0(fd, blocking, pos, size, shared);
  95     }
  96 
  97     void release(FileDescriptor fd, long pos, long size) throws IOException {
  98         release0(fd, pos, size);
  99     }
 100 
 101     void close(FileDescriptor fd) throws IOException {
 102         close0(fd);
 103     }
 104 
 105     void preClose(FileDescriptor fd) throws IOException {
 106         preClose0(fd);
 107     }
 108 
 109     FileDescriptor duplicateForMapping(FileDescriptor fd) {
 110         // file descriptor not required for mapping operations; okay
 111         // to return invalid file descriptor.
 112         return new FileDescriptor();
 113     }
 114 
 115     boolean canTransferToDirectly(java.nio.channels.SelectableChannel sc) {
 116         return true;
 117     }
 118 
 119     boolean transferToDirectlyNeedsPositionLock() {
 120         return false;
 121     }
 122 
 123     // -- Native methods --
 124 
 125     static native int read0(FileDescriptor fd, long address, int len)
 126         throws IOException;
 127 
 128     static native int pread0(FileDescriptor fd, long address, int len,
 129                              long position) throws IOException;
 130 
 131     static native long readv0(FileDescriptor fd, long address, int len)
 132         throws IOException;
 133 
 134     static native int write0(FileDescriptor fd, long address, int len)
 135         throws IOException;
 136 
 137     static native int pwrite0(FileDescriptor fd, long address, int len,
 138                              long position) throws IOException;
 139 
 140     static native long writev0(FileDescriptor fd, long address, int len)
 141         throws IOException;
 142 
 143     static native int force0(FileDescriptor fd, boolean metaData)
 144         throws IOException;
 145 
 146     static native int truncate0(FileDescriptor fd, long size)
 147         throws IOException;
 148 
 149     static native int allocate0(FileDescriptor fd, long size)
 150         throws IOException;
 151 
 152     static native long size0(FileDescriptor fd) throws IOException;
 153 
 154     static native int lock0(FileDescriptor fd, boolean blocking, long pos,
 155                             long size, boolean shared) throws IOException;
 156 
 157     static native void release0(FileDescriptor fd, long pos, long size)
 158         throws IOException;
 159 
 160     static native void close0(FileDescriptor fd) throws IOException;
 161 
 162     static native void preClose0(FileDescriptor fd) throws IOException;
 163 
 164     static native void closeIntFD(int fd) throws IOException;
 165 
 166     static native void init();
 167 
 168 }