home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / sys / next / programm / 5700 < prev    next >
Encoding:
Text File  |  1992-08-19  |  2.8 KB  |  61 lines

  1. Newsgroups: comp.sys.next.programmer
  2. Path: sparky!uunet!caen!nic.umass.edu!titan.ucc.umass.edu!a74k110
  3. From: a74k110@titan.ucc.umass.edu (Chris Lloyd)
  4. Subject: Re: _IO, _IOR, _IOW and _IOWR functions
  5. Message-ID: <1992Aug19.204211.8496@nic.umass.edu>
  6. Keywords: low level NeXT system functions
  7. Sender: usenet@nic.umass.edu (USENET News System)
  8. Nntp-Posting-Host: titan.ucc.umass.edu
  9. Organization: University of Massachusetts, Amherst
  10. References: <rabjab.11.0@golem.ucsd.edu>
  11. Date: Wed, 19 Aug 1992 20:42:11 GMT
  12. Lines: 47
  13.  
  14. In article <rabjab.11.0@golem.ucsd.edu> rabjab@golem.ucsd.edu (Jeff Bytof) writes:
  15. >Does anyone have good documentation for the NeXT low-level system
  16. >functions _IO,_IOR, _IOW and _IOWR?  They are mentioned extensively
  17. >in various include files in /usr/include but not in sufficient detail
  18. >to get a really good handle on them.
  19.  
  20. From /usr/include/ioctl.h:
  21. #define IOCPARM_MASK    0x7f            /* parameters must be < 128 bytes */
  22. #define IOC_VOID        0x20000000      /* no parameters */
  23. #define IOC_OUT         0x40000000      /* copy out parameters */
  24. #define IOC_IN          0x80000000      /* copy in parameters */
  25. #define IOC_INOUT       (IOC_IN|IOC_OUT)
  26. /* the 0x20000000 is so we can distinguish new ioctl's from old */
  27. #define _IO(x,y)        (IOC_VOID|(x<<8)|y)
  28. #define _IOR(x,y,t)     (IOC_OUT|((sizeof(t)&IOCPARM_MASK)<<16)|(x<<8)|y)
  29. #define _IOW(x,y,t)     (IOC_IN|((sizeof(t)&IOCPARM_MASK)<<16)|(x<<8)|y)
  30. /* this should be _IORW, but stdio got there first */
  31. #define _IOWR(x,y,t)    (IOC_INOUT|((sizeof(t)&IOCPARM_MASK)<<16)|(x<<8)|y)
  32.  
  33. These are macros used to construct ioctl commands.  If you take a good
  34. look, the macros are used to construct a 32 bit integer composed of
  35. various bitfields which hold different information for the command.
  36. For example, the definition of TIOCGETD (get tty line discipline) is:
  37.  
  38. #define TIOCGETD    _IOR('t', 0, int)
  39.  
  40. If you expand this, you get:
  41.  
  42. (IOC_OUT|((sizeof(int)&IOCPARM_MASK)<<16)|(x<<8)|y)
  43.  
  44. Which packs 4 distinct bit fields into a 32 bit command number, the first
  45. being how the parameter is passed (in/out/inout), the next being the
  46. size of the parameter (up to 127 chars), then a character major
  47. command identifier and then a minor number for the command, if you
  48. look at a bunch of ioctl command definitions you'll see the patterns
  49. and just common usage.  The major/minor command fields are device specific
  50. and are uninterpreted by the syscall mechanism, whereas the first two
  51. command parameters are used by the syscall trap mechanism to determine how
  52. much data to copy from/to user space to/from kernel space on trap, plus
  53. in which direction the data is to be copied.
  54.  
  55. Unless your writing a driver and need to construct your own ioctl()
  56. commands, these macros aren't of much use really.
  57.  
  58. la la la,
  59. -- 
  60. :: Christopher Lloyd :: a74k110@titan.ucc.umass.edu :: Yrrid, Inc. ::
  61.