public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] bug in read in a device file
@ 2001-05-13 18:36 wangwei
  2001-05-14 11:07 ` Jonathan Larmour
  0 siblings, 1 reply; 3+ messages in thread
From: wangwei @ 2001-05-13 18:36 UTC (permalink / raw)
  To: ecos-discuss

I think I found a bug in read() when a device file is set to NON_BLOCK
When I use read() to get more than one data from device ,such as :
      read(devfd,buf,3);
it will read nothing for ever .

The reason is :
    in file io/fileio/src/devfs.cxx, linenumber 324

//-----------------------------------------------------------------------

static int dev_fo_read      (struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG
*uio)
{
    Cyg_ErrNo err = 0;
    int i;

    // Now loop over the iovecs until they are all done, or
    // we get an error.
    for( i = 0; i < uio->uio_iovcnt; i++ )
    {
        cyg_iovec *iov = &uio->uio_iov[i];
        cyg_uint32 len = iov->iov_len;

        err = cyg_io_read( (cyg_io_handle_t)fp->f_data,
                           iov->iov_base,
                           &len);

        if( err < 0 ) break;

        uio->uio_resid -= len;
    }

    return -err;
}
//-------------------------------------------------------------------

now len=3, if just one byte in the read buffer of drivers . after called
cyg_io_read ,
,it will return one byte in iov->iov_base,and len =1(because set
NON_BLOCK),but
err < 0,
so the byte will lost .
I use function "select" and "read" to get device data , and the device speed
isn't quick
enough , when function select decide there are some data in device driver,
function "read"
will be call, but only one byte in the read buffer now .so the read function
will return
failure always .

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [ECOS] bug in read in a device file
  2001-05-13 18:36 [ECOS] bug in read in a device file wangwei
@ 2001-05-14 11:07 ` Jonathan Larmour
  2001-05-14 23:39   ` [ECOS] Bug in read/write in the io.cxx file Boris V. Guzhov
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Larmour @ 2001-05-14 11:07 UTC (permalink / raw)
  To: wangwei; +Cc: ecos-discuss, Nick Garnett

wangwei wrote:
> 
> I think I found a bug in read() when a device file is set to NON_BLOCK
> When I use read() to get more than one data from device ,such as :
>       read(devfd,buf,3);
> it will read nothing for ever .
> 
> The reason is :
>     in file io/fileio/src/devfs.cxx, linenumber 324
> 
> //-----------------------------------------------------------------------
> 
> static int dev_fo_read      (struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG
> *uio)
> {
[smo[
>         err = cyg_io_read( (cyg_io_handle_t)fp->f_data,
>                            iov->iov_base,
>                            &len);
> 
>         if( err < 0 ) break;
> 
>         uio->uio_resid -= len;
>     }
> 
>     return -err;
> }
> //-------------------------------------------------------------------
> 
> now len=3, if just one byte in the read buffer of drivers . after called
> cyg_io_read ,
> ,it will return one byte in iov->iov_base,and len =1(because set
> NON_BLOCK),but
> err < 0,
> so the byte will lost .

I believe if you just swap round the "if (err < 0) break;" and
"uio->uio_resid -= len;" lines it should work. Try it and let us know.

Nick, is this the correct permanent fix? I think so. Obviously the same
would apply to dev_fo_write().

Jifl
-- 
Red Hat, Rustat House, Clifton Road, Cambridge, UK. Tel: +44 (1223) 271062
Maybe this world is another planet's Hell -Aldous Huxley || Opinions==mine

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ECOS] Bug in read/write in the io.cxx file
  2001-05-14 11:07 ` Jonathan Larmour
@ 2001-05-14 23:39   ` Boris V. Guzhov
  0 siblings, 0 replies; 3+ messages in thread
From: Boris V. Guzhov @ 2001-05-14 23:39 UTC (permalink / raw)
  To: ecos-discuss

The readwrite() function in the io/fileio/current/src/io.cxx file never
returns any error code from op() function.

I think that it's necessary to add some lines in readwrite() function::
....
    if ( ret != ENOERR )              // two new lines
        FILEIO_RETURN(ret);

    CYG_REPORT_RETVAL(cnt);
    return cnt;
}

That's right?

--
Boris Guzhov,
St.Petersburg, Russia


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2001-05-14 23:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-05-13 18:36 [ECOS] bug in read in a device file wangwei
2001-05-14 11:07 ` Jonathan Larmour
2001-05-14 23:39   ` [ECOS] Bug in read/write in the io.cxx file Boris V. Guzhov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).