home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / libc / compat / ioctl / ioctl.txh < prev    next >
Encoding:
Text File  |  1996-08-12  |  4.9 KB  |  154 lines

  1. @c File: src/libc/posix/fcntl/ioctl.txh
  2. @c $Id: ioctl.txh 0.1 1996/07/30 09:43:23 DEMMER Exp DEMMER $
  3. @node ioctl (General description), io
  4. @code{ioctl} performs low level calls to communicate with device drivers. As
  5. there are lots of different device drivers, no really general description is
  6. possible.
  7.  
  8. The DJGPP version tries to cope two different flavors of @code{ioctl}, a DOSish
  9. and a UNIXish way. To distinguish between DOS-like and UNIX-like calls, all
  10. valid DOS commands have the 3 MSB set to 0, the UNIX command have at least one
  11. of the 3 MSB set.
  12.  
  13.  
  14. @node ioctl (DOS), io
  15. The DOSish version of @code{ioctl} performs an
  16. interrupt 0x21, function 0x44. It takes care of supplying transfer buffers in
  17. low address regions, if they are needed. For an exhaustive description of the
  18. various commands and subcommands, see Ralph Browns interrupt list.
  19.  
  20. It is highly recommended to use only the DOS_*
  21. functions listed in @file{sys/ioctl.h}.
  22. @subheading Syntax
  23.         ioctl(fd, cmd, ... );
  24.  
  25. @example
  26. #include <sys/ioctl.h>
  27. int main(int argc, char **argv)@{
  28.    char buf[6];
  29.    short *s;
  30.  
  31.    open(fd,"EMMQXXX0",O_RDONLY);
  32.    mybuf[0] = '\0';
  33.    s = mybuf;
  34.    ioctl(fd,DOS_SNDDATA,6, (int) &mybuf);
  35.    if(*s ==0x25 )printf("EMM386 >= 4.45\n");
  36.    mybuf[0]='\x02';
  37.    ioctl(fd,DOS_SNDDATA,2,(int )&mybuf);
  38.    printf("EMM Version %d.%d\n",(int )mybuf[0],(int) mybuf[1]);
  39.    close(fd);
  40. @}
  41. @end example
  42.  
  43. @subheading Description
  44. The parameter @code{fd} must refer to a file descriptor for character device
  45. functions, or the number of a block device (usually current=0, A:=1, ...).
  46.  
  47. The following constants can be used for the @code{cmd} parameter:
  48. @table @code
  49. @item DOS_GETDEVDATA
  50. Get device information. Returns the device information word from @code{DX}.
  51. @item DOS_SETDEVDATA
  52. Set device information. Returns the new device information word form @code{DX}
  53. or -1
  54. @item DOS_RCVDATA
  55. Read from character device control channel. After @code{cmd} must follow the
  56. number of requested bytes to read and a pointer to a buffer. Returns the number
  57. of bytes actually read or -1 on error.
  58. @item DOS_SNDDATA
  59. Write to character device control channel. After @code{cmd} must follow the
  60. number of bytes to write and a pointer to a buffer holding the data.
  61. Returns the number of bytes actually written.
  62. @item DOS_RCVCTLDATA
  63. Read from block device control channel. See @code{DOS_RCVDATA}.
  64. @item DOS_SNDCTLDATA
  65. Write to block device control channel. See @code{DOS_SNDDATA}.
  66. @item DOS_CHKINSTAT
  67. Check the input status of a file. Returns 0 if not ready of at EOF, @code{0xff}
  68. if file is ready.
  69. @item DOS_CHKOUTSTAT
  70. Check the output status of a file. Returns 0 if not ready of at EOF, @code{0xff}
  71. if file is ready.
  72. @item DOS_ISCHANGEABLE
  73. Check if a block device is changeable. Returns 0 for removable or 1 for fixed.
  74. @item DOS_ISREDIRBLK
  75. Check if a block device is remote o local.
  76. @item DOS_ISREDIRHND
  77. Check if a file handle refers to a local or remote device.
  78. @item DOS_SETRETRY
  79. Set the sharing retry count. the first extra parameter specifies the pause
  80. between retries, the second number of retries.
  81. @item DOS_GENCHARREQ
  82. Generic character device request.
  83. @item DOS_GENBLKREQ
  84. Generic block device request.
  85. @item DOS_GLDRVMAP
  86. Get logical drive map.
  87. @item DOS_SLDRVMAP
  88. Set logical drive map.
  89. @item DOS_QGIOCTLCAPH
  90. Query generic ioctl capability (handle). Test if a handle supports ioctl
  91. functions beyond those in the standard DOS 3.2 set.
  92. @item DOS_QGIOCTLCAPD
  93. Query generic ioctl capability (drive). Test if a drive supports ioctl
  94. functions beyond those in the standard DOS 3.2 set.
  95. @end table
  96.  
  97. If your specific device driver requires different commands, they must be or'ed
  98. together with the flags listed in @file{ioctl.h} to tell the drive about
  99. transfer buffers and what to return.
  100.  
  101. @subheading Return Value
  102. See description above.
  103.  
  104. @subheading Device information word
  105. The bits of the device information word have the following meaning:\\
  106. Character device:
  107. @table @asis
  108. 14  Device driver can process IOCTL request
  109.  
  110. 13  output until busy supported
  111.  
  112. 11  driver supports OPEN/CLOSE calls
  113.  
  114. 7   set (indicates device)
  115.  
  116. 6   EOF on input
  117.  
  118. 5   raw (binary) mode
  119.  
  120. 4   device is special (uses INT 29)
  121.  
  122. 3   clock device
  123.  
  124. 2   NUL device
  125.  
  126. 1   standard output
  127.  
  128. 0   standard input
  129. @end table
  130.  
  131. Disk file:
  132. @table @asis
  133. 15  file is remote (DOS 3.0+)
  134.  
  135. 14  don't set file date/time on closing (DOS 3.0+)
  136.  
  137. 11  media not removable
  138.  
  139. 8   (DOS 4 only) generate INT 24 if no disk space on write or read past end of file
  140.  
  141. 7   clear (indicates file)
  142.  
  143. 6   file has not been written
  144.  
  145. 5-0 drive number (0 = A:)
  146. @end table
  147.  
  148. @node ioctl (UNIX), io
  149. The UNIX version first checks if an FSE handler is associated to the file
  150. descriptor. If so, it calls the handler in the usual way @ref{File System
  151. Extensions}. Otherwise it sets @var{errno} to @code{ENOTTY} and returns -1.
  152.  
  153. As this part is still under development, it should not be used exhaustively.
  154.