*BSD News Article 74901


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!munnari.OZ.AU!news.ecn.uoknor.edu!news.wildstar.net!cancer.vividnet.com!hunter.premier.net!news-res.gsl.net!news.gsl.net!news.mathworks.com!fu-berlin.de!irz401!orion.sax.de!uriah.heep!news
From: j@uriah.heep.sax.de (J Wunsch)
Newsgroups: comp.unix.bsd.freebsd.misc
Subject: Re: _IOR and _IOW
Date: 28 Jul 1996 08:16:47 GMT
Organization: Private BSD site, Dresden
Lines: 33
Message-ID: <4tf7lf$72s@uriah.heep.sax.de>
References: <clxyVBW00YUt0tk340@andrew.cmu.edu>
  <4t95dv$dhe@jraynard.demon.co.uk>
Reply-To: joerg_wunsch@uriah.heep.sax.de (Joerg Wunsch)
NNTP-Posting-Host: localhost.heep.sax.de
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Newsreader: knews 0.9.6
X-Phone: +49-351-2012 669
X-PGP-Fingerprint: DC 47 E6 E4 FF A6 E9 8F  93 21 E0 7D F9 12 D6 4E

james@jraynard.demon.co.uk (James Raynard) wrote:

> >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

joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/ -- NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)