[Haskell-cafe] reading from the cdrom drive on Red Hat

Adam Langley agl at imperialviolet.org
Fri Feb 1 16:28:06 EST 2008

2008/2/1 Galchin Vasili <vigalchin at gmail.com>:
>       I wrote a simple program to read the contents of a cdrom:

(Note that this is a terribly inefficient way of reading large amounts
of binary data. Of course, if this is just meant as an example, that's
fine. Otherwise, see the struff about ByteStrings at

The error you are seeing comes from the operating system. You could
run the resulting Haskell program under strace to see the exact error,
but what's happening is that the kernel is getting an error from the
CD drive itself. This is pretty much unique to CDs I guess. If you
were reading a hard drive, the kernel knows exactly how large the disk
is (see /proc/partitions) and would return EOF (zero bytes).

As an aside, hitting EOF in your code would result in an infinite
loop, since you don't handle actualByteCount == 0.

You can catch and handle the resulting exception with the functions in:


Adam Langley                                      agl at imperialviolet.org
http://www.imperialviolet.org                       650-283-9641

More information about the Haskell-Cafe mailing list