return values of device driver routines

Till Straumann strauman at slac.stanford.edu
Fri Jan 4 23:07:21 UTC 2008


hwulf at et-inf.fho-emden.de wrote:
> Hi there,
>
> how do the return values work in the RTEMS device driver routines  
> (open, close, read, write, ioctl)?
>
> When I wanted to return the value (-1), do I have to execute "return  
> (-1);" or do I have to set a appropriate variable of the argument  
> structures (rtems_libio_open_close_args_t, rtems_libio_rw_args_t,  
> rtems_libio_ioctl_args_t)?
>
>   
E.g., for 'open':

If the device file resides in the IMFS filesystem,

open -> libfs/src/imfs/deviceio.c: device_open() -> 
sapi/src/ioopen.c:rtems_io_open() -> driver 'open_entry'

rtems_io_open() passes the return value of your driver's 'open_entry' 
back to device_open().

device_open() inspects this return value and

a) returns 0 if open_entry returned 0
b) tries to map the return value of open_entry() into an 'errno' by looking
    at the 'errno_assoc' table defined in deviceio.c.
    If the lookup succeeds then errno is set (otherwise it isn't).
    Either way, device_open() returns -1

Unfortunately, the 'open' syscall again maps the return value of
device_open() (which is always either 0 or -1 ) into an 'errno'
so that the 'errno' value set in step b) is eventually lost (looks like 
a bug).

This is my quick and dirty 5min. analysis and may be incorrect.

HTH
-- Till
> Thank you very much and kind regards,
>   Hank
>
> _______________________________________________
> rtems-users mailing list
> rtems-users at rtems.com
> http://rtems.rtems.org/mailman/listinfo/rtems-users
>   





More information about the users mailing list