<div>Hello,</div>
<div>&nbsp;</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I wrote a simple program to read the contents of a cdrom:</div>
<div>&nbsp;</div>
<div>module Main where</div>
<div>&nbsp;</div>
<div>import Text.Printf</div>
<div>import System.IO</div>
<div>import System.Posix.Types</div>
<div>import <a href="http://System.Posix.IO">System.Posix.IO</a></div>
<div>&nbsp;</div>
<div>main = do</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fd &lt;- openFd &quot;/dev/cdrom&quot; ReadOnly Nothing defaultFileFlags</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; readCdRom fd 4096</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; closeFd fd</div>
<div>&nbsp;</div>
<div>readCdRom fd byteCount = do</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (buf, actualByteCount) = fdRead fd bytecount</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; readCdRom fd byteCount</div>
<div>&nbsp;</div>
<div>When it executed it read thousands of 4096 blocks as I expected. It then got a &quot;hardware error&quot; which I suspect was the &quot;end of the CD&quot;, i.e. the begininng of the &quot;unlasered&quot; part of the CD. Is there a better and more graceful way to detect and handle &quot;end of data&quot;?</div>

<div>&nbsp;</div>
<div>Thanks, ,Vasili</div>