[erlang-questions] Getting {error, eisdir} when opening devices/pipes/etc, was RE: Unix domain sockets

Erik Reitsma erik.reitsma@REDACTED
Tue Mar 31 08:51:51 CEST 2009


I've been struggling with this issue too, trying to read from Linux
devices. I have written a port driver to open files (and do ioctl calls
on them if they are actually devices), returning a file descriptor. Then
I can read from the file using erlang:open_port({fd, In, Out}, []). In
this case, In and Out would both be the file descriptor I got from the
driver.

Another possibility is erlang:open_port({command, "cat /dev/net/tun"},
[]), but that is not very pretty or efficient either.

| Apparently this doesn't work for character or block devices, see here:
| [running beam as root]
| 1> FOut = file:open("/dev/net/tun", [read, write]).
| {error,eisdir}
| 2> FOut1 = file:open("/dev/net/tun", [read, write, raw]).
| {error,eisdir}
| 3> FOut3 = file:open("/dev/sda", [read, write, raw]).
| {error,eisdir}
| 4> FOut3 = file:open("/dev/sda", [read, write]).
| {error,eisdir}
| 
| lucifer ~ # ls -l /dev/net/tun
| crw-rw-rw- 1 root root 10, 200 Mar 30 16:51 /dev/net/tun 
| lucifer ~ # ls -l /dev/sda
| brw-r----- 1 root disk 8, 0 Mar 30 09:27 /dev/sda
| 
| Any ideas on how to read this? Do I need to break out a port driver?
| 

Regards,
*Erik.



More information about the erlang-questions mailing list