How to open device as a IO Handle
Simon Marlow
simonmar at microsoft.com
Thu Jun 9 05:18:37 EDT 2005
On 09 June 2005 02:47, Lei Pan wrote:
> Could anyone tell me how to open a block device (e.g., /dev/hda1)
> into a
> IO Handle by using GHC (version > 5.0)? I want to open a block/char
> device and return a handle. Apparently, openFile function can't do the
> job. It will be very appreciated if someone could give me a hint.
>
> An earlier post pointed out the problem, but got no reply.
>
http://www.haskell.org/pipermail/glasgow-haskell-users/2001-November/002
624.html
>
> Something I played in GHCI-6.2.2
>
> *Main> openFile "/dev/hdb2" ReadMode >>= \hin -> hGetPosn hin >>=
> \pos -> print pos
>
> *** Exception: /dev/hdb2: openFile: unsupported operation (unknown
> file type)
>
> (I already set /dev/hdb2 globally read/write)
I'll look into fixing this. In the meantime, you should be able to use
the System.Posix library to open the file directly, and then convert the
FD to a Handle using GHC.Handle.openFd (I don't think fdToHandle will
work in this case, because it checks the file type). Bear in mind that
GHC.Handle.openFd is an internal undocumented interface, so may change
in the future.
Cheers,
Simon
More information about the Glasgow-haskell-users
mailing list