Memory Map (mmap) Linux device driver in Java / Scala

I have a device driver that controls specific hardware. I would like to access the hardware directly from a custom application running in Java / Scala via MMAP. Here's a stripped-down version of the code I have:

val fc = new RandomAccessFile(new File("/dev/device"),"rw").getChannel()
val buf = fc.map(FileChannel.MapMode.READ_WRITE,0,bufferSize)
fc.read(buf)

      

Here is the error I get when I run the code:

java.io.IOException: Invalid argument
at sun.nio.ch.FileDispatcherImpl.truncate0(Native Method)
at sun.nio.ch.FileDispatcherImpl.truncate(FileDispatcherImpl.java:80)
at sun.nio.ch.FileChannelImpl.map(FileChannelImpl.java:858)
at Main$$anon$1.<init>(mmap.Scala:12)

      

I already looked at a similar post here: How is a memory map (mmap) device of a linux block (like / dev / sdb) in Java? that describe the problem; however, there is no reason to remove it. I am aware of the Java Native Interface (JNI), but it is imperative for me to access the hardware directly from the Java platform. Can anyone suggest a way to modify the Java source file to fix this issue?

+3


source to share





All Articles