Yes, I should have mentioned it wasn't a problem until about the
fourth iteration in the loop.  Thanks for the workaround!

robert

On Sat, Dec 16, 2000 at 02:04:08PM +0900, Yukihiro Matsumoto wrote:
> Hi,
> 
> In message "[ruby-talk:7370] BUG? IO.seek conflicts with IO.sysread"
>     on 00/12/16, Robert Read <rread / datarithm.net> writes:
> 
> |The error comes from io.c:rb_io_sysread around line 1157:
> |
> |    if (READ_DATA_PENDING(fptr->f)) {
> |	rb_raise(rb_eIOError, "sysread for buffered IO");
> |    }
> |
> |READ_DATA_PENDING seems to be confused by the seek.  I'm new to Ruby,
> |so I'm not sure if this is my fault or a real bug.
> 
> Hmm, the simple case like
> 
>   ruby -e 'f=open("ChangeLog"); p f.sysread(10); f.seek(100,0); p f.sysread(10)'
> 
> works.  But fseek(3) sometimes fill the buffer in certain case.
> It will be fixed in the future version, which will not use stdio.
> 
> Anyway here's the workaround.
> 
> class DCheck 
>   def initialize(dev, blk_size, blk_count)
>     @dev = dev
>     @blk_size = blk_size
>     @blk_count = blk_count
>   end
>   
>   def verifyBlocks()
>     disk = File.new(@dev)
>     fd = disk.fileno
>     disk.sync = true
>     begin
>       for i in 0..@blk_count
> 	f = IO.new(fd)
> 	f.seek(i*@blk_size)
> 	block = f.sysread(@blk_size)
>         f.close
>       end
>     rescue
>       $stderr.print "IO failed: " + $! + "\n"
>       disk.close
>       raise
>     end
>   end
> end