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

    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 = fc.map(FileChannel.MapMode.READ_ONLY, 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 FileChannel.map 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 09:39 PM.

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

    Default Re: MappedByteBuffer to access Linux device driver through MMAP

    Hello,

    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 ?

    Regards

Similar Threads

  1. Replies: 1
    Last Post: 08-03-2011, 04:36 PM
  2. Replies: 0
    Last Post: 02-25-2011, 12:46 PM
  3. Replies: 7
    Last Post: 11-20-2009, 04: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, 04:28 AM
  5. Access Linux shared folder from Windows OS
    By nitinpjairaj in forum Networking
    Replies: 3
    Last Post: 08-26-2008, 07: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
  •