[Mono-list] UnixStream + hiddev

Jonathan Pryor jonpryor at vt.edu
Fri Jan 11 09:38:32 EST 2008

On Fri, 2008-01-11 at 04:56 -0800, ghell wrote:
> Is it possible to use a Mono.Unix.UnixStream to write to human interface
> devices (eg /dev/usb/hiddev0)? Even if I have permissions (or su) and obtain
> the file descriptor from Syscall.open(path, OpenFlags.O_RDWR), CanWrite
> still returns false and hence Write throws an exception. I have also tried
> UnixFileInfo.OpenWrite but that fails instantly by using OpenFlags.O_CREAT
> and other UnixFileInfo Open calls still give me no CanWrite.

This might be an instance of UnixStream (and me) being too "smart" for
our own good.  CanSeek, CanRead, and CanWrite are initialized by trying
lseek(2), read(2), or write(2) 0 bytes to the underlying stream.  (So
nothing is actually modified, but we can see if anything can be

So this logic may be wrong, because some (expected) "error" is being

So instead of using UnixStream, what happens if you use Syscall.write()
directly?  Does that work, or does that also return in an error?

If Syscall.write() works, then there's a UnixStream bug (in which case,
please provide more information, such as the return of
Stdlib.GetLastError(), etc.).  If Syscall.write() fails, then it's NOT a
UnixStream problem, there's something more fundamental going on (in
which case you'll likely need to write an equivalent C app to see where
the error is).

 - Jon

More information about the Mono-list mailing list