Results 1 to 2 of 2
  1. #1
    amess is offline Member
    Join Date
    Oct 2011
    Rep Power

    Default MappedByteBuffer to access Linux device driver through MMAP

    Hello. I'd like to access the mmap method of a file using the FileChannel -> MappedByteBuffer class. The kicker though is that what I want to access isn't really a file, but a character device on Linux. My understanding is that on Linux /dev/zero for example should be appear just like any other file (implements read/write/mmap/ioctl/llseek etc). This doesn't quite work though, the following code will run ...

    FileChannel fc = new FileInputStream("/dev/zero").getChannel();
    ByteBuffer bb =, 0, fc.size());

    ... but the file channel size is zero. If I try to hard code a non zero number it will throw an IO exception (invalid argument). It looks like the method is actually checking the size of the file before it implements the the low level "mmap" system call. I guess my question is, how is java getting the size of the file? If it's from the file-system then I'm out of luck, but if it's through some kind of normal file operation I could mimic that behavior in my driver (I realize /dev/zero probably does return that it has no size, but a custom char driver could possibly look like it does have >0 bytes).

    Perhaps if I really want to use MMAP fromJava for char drivers I need to use JNI (??)

    Thanks for reading this
    Last edited by amess; 10-01-2011 at 08:39 PM.

  2. #2
    derassea is offline Member
    Join Date
    Oct 2011
    Rep Power

    Default Re: MappedByteBuffer to access Linux device driver through MMAP


    I have the same problem : Need to MMAP a linux device driver using java.
    Did you get an answer to your question ?

    Do we have to use JNI or you found a solution with FileChannel for instance ?


Similar Threads

  1. Replies: 1
    Last Post: 08-03-2011, 03:36 PM
  2. Replies: 0
    Last Post: 02-25-2011, 11:46 AM
  3. Replies: 7
    Last Post: 11-20-2009, 03:02 AM
  4. How to access driver in Windows like a file?
    By pthoonen in forum New To Java
    Replies: 6
    Last Post: 01-15-2009, 03:28 AM
  5. Access Linux shared folder from Windows OS
    By nitinpjairaj in forum Networking
    Replies: 3
    Last Post: 08-26-2008, 06:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts