This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: bug in read in a device file
- To: wangwei <wangw at start dot com dot cn>
- Subject: Re: [ECOS] bug in read in a device file
- From: Jonathan Larmour <jlarmour at redhat dot com>
- Date: Mon, 14 May 2001 19:07:31 +0100
- Cc: ecos-discuss at sources dot redhat dot com, Nick Garnett <nickg at redhat dot com>
- Organization: Red Hat UK Ltd.
- References: <003801c0dc15$87d549a0$592da8c0@start.com.cn>
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