_IOR and _IOW

_IOR and _IOW

Post by Mahesh Saptharish » Fri, 26 Jul 1996 04:00:00



Hello,

I would like to know what the macros _IOR and _IOW do?

Thanks,
Mahesh.

 
 
 

_IOR and _IOW

Post by James Rayna » Sat, 27 Jul 1996 04:00:00




Quote:

>I would like to know what the macros _IOR and _IOW do?

They're used to declare the commands used for the "request"
argument of ioctl(2).  _IOW is used for an 'in' parameter,
_IOR for an 'out' parameter and there's an _IOWR macro that
combines the two.  See <sys/scsiio.h> for an example of their
use.

--
James Raynard, Edinburgh, Scotland

http://www.freebsd.org/~jraynard/

 
 
 

_IOR and _IOW

Post by J Wuns » Mon, 29 Jul 1996 04:00:00



> >I would like to know what the macros _IOR and _IOW do?

> They're used to declare the commands used for the "request"
> argument of ioctl(2).  _IOW is used for an 'in' parameter,
> _IOR for an 'out' parameter and there's an _IOWR macro that
> combines the two.

... and _IO is used for an ioctl that does not pass any arguments.
(Just to be complete.)

Unlike with SysV, the generic ioctl code in BSD normally handles
argument passing from/to user address space, including the bounds
checking.  This way, the ioctl stub in the driver doesn't need to
copyin()/copyout() the arguments itself (as it must still do it in
SysV, if i'm not totally mistaken).  However, in order to arrange for
this, the generic ioctl code needs to know the size and passing
direction of the arguments, so this information is encoded into the
ioctl command word.  That's what these macros are for.

Btw., this has an additional advantage: if the size of some argument
structure has been changed, obsolete binaries that still use the old
struct will get an ENOTTY (Inappropriate ioctl for this device) since
the new command word is different.  In SysV, they will simply read/
write garbage in this case, since the ioctl is still valid.

--
cheers, J"org


Never trust an operating system you don't have sources for. ;-)