Thread View: comp.sys.next.programmer
3 messages
3 total messages
Started by Jeff Bytof
Wed, 19 Aug 1992 19:23
_IO, _IOR, _IOW and _IOWR functions
Author: Jeff Bytof
Date: Wed, 19 Aug 1992 19:23
Date: Wed, 19 Aug 1992 19:23
4 lines
711 bytes
711 bytes
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.
Re: _IO, _IOR, _IOW and _IOWR functions
Author: 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. ::
Re: _IO, _IOR, _IOW and _IOWR functions
Author: Louis A. Mamakos
Date: Wed, 19 Aug 1992 21:07
Date: Wed, 19 Aug 1992 21:07
13 lines
1168 bytes
1168 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. These are macros defined in /usr/include/sys/ioctl.h (at least until 3.0 comes out, when them move to some god-forsaken part of the file system). These macros are used to construct arguments to the ioctl() system call. That's all they are used for, generally, on UNIX systems. louie
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads