This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: bug in read in a device file


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]