Article View: comp.sys.next.programmer
Article #1228Re: _IO, _IOR, _IOW and _IOWR functions
From: Chris Lloyd
Date: Wed, 19 Aug 1992 20:42
Date: Wed, 19 Aug 1992 20:42
47 lines
2918 bytes
2918 bytes
In article <rabjab.11.0@golem.ucsd.edu> rabjab@golem.ucsd.edu (Jeff Bytof) writes:
>Does anyone have good documentation for the NeXT low-level system
>functions _IO,_IOR, _IOW and _IOWR? They are mentioned extensively
>in various include files in /usr/include but not in sufficient detail
>to get a really good handle on them.
From /usr/include/ioctl.h:
#define IOCPARM_MASK 0x7f /* parameters must be < 128 bytes */
#define IOC_VOID 0x20000000 /* no parameters */
#define IOC_OUT 0x40000000 /* copy out parameters */
#define IOC_IN 0x80000000 /* copy in parameters */
#define IOC_INOUT (IOC_IN|IOC_OUT)
/* the 0x20000000 is so we can distinguish new ioctl's from old */
#define _IO(x,y) (IOC_VOID|(x<<8)|y)
#define _IOR(x,y,t) (IOC_OUT|((sizeof(t)&IOCPARM_MASK)<<16)|(x<<8)|y)
#define _IOW(x,y,t) (IOC_IN|((sizeof(t)&IOCPARM_MASK)<<16)|(x<<8)|y)
/* this should be _IORW, but stdio got there first */
#define _IOWR(x,y,t) (IOC_INOUT|((sizeof(t)&IOCPARM_MASK)<<16)|(x<<8)|y)
These are macros used to construct ioctl commands. If you take a good
look, the macros are used to construct a 32 bit integer composed of
various bitfields which hold different information for the command.
For example, the definition of TIOCGETD (get tty line discipline) is:
#define TIOCGETD _IOR('t', 0, int)
If you expand this, you get:
(IOC_OUT|((sizeof(int)&IOCPARM_MASK)<<16)|(x<<8)|y)
Which packs 4 distinct bit fields into a 32 bit command number, the first
being how the parameter is passed (in/out/inout), the next being the
size of the parameter (up to 127 chars), then a character major
command identifier and then a minor number for the command, if you
look at a bunch of ioctl command definitions you'll see the patterns
and just common usage. The major/minor command fields are device specific
and are uninterpreted by the syscall mechanism, whereas the first two
command parameters are used by the syscall trap mechanism to determine how
much data to copy from/to user space to/from kernel space on trap, plus
in which direction the data is to be copied.
Unless your writing a driver and need to construct your own ioctl()
commands, these macros aren't of much use really.
la la la,
--
:: Christopher Lloyd :: a74k110@titan.ucc.umass.edu :: Yrrid, Inc. ::
Technical Details
Message-ID:
<1992Aug19.204211.8496@nic.umass.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!caen!nic.umass.edu!titan.ucc.umass.edu!a74k110References:
<rabjab.11.0@golem.ucsd.edu>Show Full Headers
Complete Article Headers
Newsgroups: comp.sys.next.programmer Path: arc1-ca.pugleaf.net!sparky!uunet!caen!nic.umass.edu!titan.ucc.umass.edu!a74k110 From: a74k110@titan.ucc.umass.edu (Chris Lloyd) Subject: Re: _IO, _IOR, _IOW and _IOWR functions Message-ID: <1992Aug19.204211.8496@nic.umass.edu> Keywords: low level NeXT system functions Sender: usenet@nic.umass.edu (USENET News System) Nntp-Posting-Host: titan.ucc.umass.edu Organization: University of Massachusetts, Amherst References: <rabjab.11.0@golem.ucsd.edu> Date: Wed, 19 Aug 1992 20:42:11 GMT Lines: 47