From: matz@... (Yukihiro Matsumoto) Date: 2000-12-16T14:04:08+09:00 Subject: [ruby-talk:7396] Re: BUG? IO.seek conflicts with IO.sysread Hi, In message "[ruby-talk:7370] BUG? IO.seek conflicts with IO.sysread" on 00/12/16, Robert Read 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