BUG? IO.seek conflicts with IO.sysread 
Author Message
 BUG? IO.seek conflicts with IO.sysread

I'm writing a simple tool to test a disk driver.  I want to write lots
of blocks and then read them back to verify them.  When I use seek and
sysread like this, it fails after 3 or four reads.  Sample code:

class DCheck
  def initialize(dev, blk_size, blk_count)



  end

  def verifyBlocks()

    disk.sync = true
    begin



      end
    rescue
      $stderr.print "IO failed: " + $! + "\n"
      disk.close
      raise
    end
  end
end

I realize that in this simple case the seek is not needed, but the
final version will need to do more random io.

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.

thanks,
 robert



Wed, 04 Jun 2003 09:53:14 GMT  
 BUG? IO.seek conflicts with IO.sysread
Hi,

In message "[ruby-talk:7370] BUG? IO.seek conflicts with IO.sysread"

|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)



  end

  def verifyBlocks()

    fd = disk.fileno
    disk.sync = true
    begin

        f = IO.new(fd)


        f.close
      end
    rescue
      $stderr.print "IO failed: " + $! + "\n"
      disk.close
      raise
    end
  end
end



Wed, 04 Jun 2003 13:04:08 GMT  
 BUG? IO.seek conflicts with IO.sysread
Yes, I should have mentioned it wasn't a problem until about the
fourth iteration in the loop.  Thanks for the workaround!

robert

Quote:

> Hi,

> In message "[ruby-talk:7370] BUG? IO.seek conflicts with IO.sysread"

> |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)



>   end

>   def verifyBlocks()

>     fd = disk.fileno
>     disk.sync = true
>     begin

>    f = IO.new(fd)


>         f.close
>       end
>     rescue
>       $stderr.print "IO failed: " + $! + "\n"
>       disk.close
>       raise
>     end
>   end
> end



Thu, 05 Jun 2003 05:57:38 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. BUG?: HP-UX 10.20 and IO#gets followed by IO#puts

2. mixing IO#read and IO#syswrite

3. Perl IO to Ruby IO help needed

4. IMPORT IO, FROM IO IMPORT ?

5. IMPORT IO, FROM IO IMPORT ?

6. IMPORT IO, FROM IO IMPORT ?

7. VAX Ada sequential IO and Direct IO - (nf)

8. VAX Ada sequential IO and Direct IO

9. VAX Ada sequential IO and Direct IO

10. Not DOS interrupts, I want direct IO (memory mapped IO)

11. IO in gofer - Seeking help!!

12. io.read_line bug in SE?

 

 
Powered by phpBB® Forum Software