ioctl.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. /*++
  2. Copyright (c) 2013 Minoca Corp.
  3. This file is licensed under the terms of the GNU Lesser General Public
  4. License version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details.
  6. Module Name:
  7. ioctl.h
  8. Abstract:
  9. This header contains definitions for sending and receiving IOCTLs to
  10. file descriptors.
  11. Author:
  12. Evan Green 5-Nov-2013
  13. --*/
  14. #ifndef _SYS_IOCTL_H
  15. #define _SYS_IOCTL_H
  16. //
  17. // ------------------------------------------------------------------- Includes
  18. //
  19. #include <libcbase.h>
  20. //
  21. // ---------------------------------------------------------------- Definitions
  22. //
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. //
  27. // Define terminal ioctls.
  28. //
  29. //
  30. // This ioctl is equivalent to tcgetattr(). It takes a struct termios pointer
  31. // as its argument.
  32. //
  33. #define TCGETS 0x7401
  34. //
  35. // This ioctl is equivalent to tcsetattr(fd, TCSANOW, arg). It takes a struct
  36. // termios pointer as its argument.
  37. //
  38. #define TCSETS 0x7402
  39. //
  40. // This ioctl is equivalent to tcsetattr(fd, TCSADRAIN, arg). It takes a
  41. // struct termios pointer as its argument.
  42. //
  43. #define TCSETSW 0x7403
  44. //
  45. // This ioctl is equivalent to tcsetattr(fd, TCSAFLUSH, arg). It takes a
  46. // struct termios pointer as its argument.
  47. //
  48. #define TCSETSF 0x7404
  49. //
  50. // The next four ioctls are just like TCGETS, TCSETS, TCSETSW, and TCSETSF,
  51. // except that they take a struct termio pointer instead of a struct termios
  52. // pointer.
  53. //
  54. #define TCGETA 0x7405
  55. #define TCSETA 0x7406
  56. #define TCSETAW 0x7407
  57. #define TCSETAF 0x7408
  58. //
  59. // This ioctl is equivalent to tcsendbreak(fd, arg). It takes an integer
  60. // argument, which when zero sends a break (stream of zero bits) for between
  61. // 0.25 and 0.5 seconds. When the argument is non-zero, the results are
  62. // undefined. In this implementation, it is treated as tcdrain(fd).
  63. //
  64. #define TCSBRK 0x7409
  65. //
  66. // This ioctl is equivalent to tcflow(fd, arg). It takes an integer argument.
  67. //
  68. #define TCXONC 0x740A
  69. //
  70. // This ioctl is equivalent to tcflush(fd, arg). It takes an integer argument.
  71. //
  72. #define TCFLSH 0x740B
  73. //
  74. // This ioctl puts the terminal into exclusive mode. All further open
  75. // operations will fail with EBUSY, except if the caller is root. This ioctl
  76. // takes no argument.
  77. //
  78. #define TIOCEXCL 0x740C
  79. //
  80. // This ioctl disables exclusive mode. It takes no argument.
  81. //
  82. #define TIOCNXCL 0x740D
  83. //
  84. // This ioctl makes the given terminal the controlling terminal of the calling
  85. // process. The calling process must be a session leader and must not already
  86. // have a controlling terminal. If this terminal is already the controlling
  87. // terminal of a different session then the ioctl fails with EPERM, unless
  88. // the caller is root and the integer argument is one.
  89. //
  90. #define TIOCSCTTY 0x740E
  91. //
  92. // This ioctl is equivalent to *arg = tcgetpgrp(fd). The argument is a pid_t
  93. // pointer.
  94. //
  95. #define TIOCGPGRP 0x740F
  96. //
  97. // This ioctl is equivalent to tcsetpgrp(fd, *argp). The argument is a pointer
  98. // to a pid_t.
  99. //
  100. #define TIOCSPGRP 0x7410
  101. //
  102. // This ioctl returns the number of bytes in the output buffer. The argument
  103. // is a pointer to an integer.
  104. //
  105. #define TIOCOUTQ 0x7411
  106. //
  107. // This ioctl inserts the given byte in the input queue. The argument is a
  108. // pointer to a char.
  109. //
  110. #define TIOCSTI 0x7412
  111. //
  112. // This ioctl gets the window size. The argument is a pointer to a struct
  113. // winsize.
  114. //
  115. #define TIOCGWINSZ 0x7413
  116. //
  117. // This ioctl sets the window size. The argument is a pointer to a struct
  118. // winsize.
  119. //
  120. #define TIOCSWINSZ 0x7414
  121. //
  122. // This ioctl gets the modem status bits. The argument is a pointer to an int.
  123. //
  124. #define TIOCMGET 0x7415
  125. //
  126. // This ioctl ORs in the given modem status bits. The argument is a pointer to
  127. // and int.
  128. //
  129. #define TIOCMBIS 0x7416
  130. //
  131. // This ioctl clears the given modem status bits. The argument is a pointer to
  132. // an int.
  133. //
  134. #define TIOCMBIC 0x7417
  135. //
  136. // This ioctl sets the modem status bits. The argument is a pointer to an int.
  137. //
  138. #define TIOCMSET 0x7418
  139. //
  140. // This ioctl gets the software carrier flag. It gets the status of the CLOCAL
  141. // flag in the c_cflag field of the termios structure. The argument is a
  142. // pointer to an int.
  143. //
  144. #define TIOCGSOFTCAR 0x7419
  145. //
  146. // This ioctl sets the software carrier flag. The argument is a pointer to an
  147. // int. If the CLOCAL flag for a line is off, the hardware carrier detect (DCD)
  148. // signal is significant. An open of the corresponding terminal will block
  149. // until DCD is asserted, unless the O_NONBLOCK flag is given. If CLOCAL is
  150. // set, the line behaves as if DCD is always asserted. If the value at the
  151. // given argument is non-zero, set the CLOCAL flag, otherwise clear the CLOCAL
  152. // flag.
  153. //
  154. #define TIOCSSOFTCAR 0x741A
  155. //
  156. // This ioctl returns the number of bytes in the input buffer. The argument is
  157. // a pointer to an int.
  158. //
  159. #define FIONREAD 0x741B
  160. #define TIOCINQ FIONREAD
  161. //
  162. // This ioctl redirects output that would have gone to the video console or
  163. // primary terminal to the given terminal. The caller must be root to do this.
  164. // This ioctl takes no argument.
  165. //
  166. #define TIOCCONS 0x741D
  167. //
  168. // This ioctl enables or disables packet mode. The argument is a pointer to an
  169. // int which enables (int is non-zero) or disables (int is zero) packet mode.
  170. // In packet mode, each subsequent read of the master side returns a single
  171. // non-zero control byte, and optionally data written by the slave side of the
  172. // terminal. See TIOCPKT_* definitions for possible values and meanings of the
  173. // first control byte.
  174. //
  175. #define TIOCPKT 0x7420
  176. //
  177. // This ioctl enables or disables non-blocking mode on the given descriptor. It
  178. // is the same as using fcntl to enable non-blocking mode. The argument is an
  179. // int, which if zero disables non-blocking mode, or otherwise enables it.
  180. //
  181. #define FIONBIO 0x7421
  182. //
  183. // This ioctl gives up the controlling terminal if the given terminal was
  184. // the controlling terminal of the calling process. If this process was the
  185. // session leader, SIGHUP and SIGCONT are sent to the foreground process group
  186. // and all processes in the current session lose their controlling terminal.
  187. // This ioctl takes no argument.
  188. //
  189. #define TIOCNOTTY 0x7422
  190. //
  191. // This ioctl is the POSIX version of TCSBRK. It treats a non-zero argument
  192. // as a time interval measured in deciseconds, and does nothing when the driver
  193. // does not support breaks. Like TCSBRK, it takes an integer argument.
  194. //
  195. #define TCSBRKP 0x7425
  196. //
  197. // This ioctl turns break on (starts sending zero bits). It takes no arguments.
  198. //
  199. #define TIOCSBRK 0x7427
  200. //
  201. // This ioctl turns break off (stops sending zero bits). It takes no arguments.
  202. //
  203. #define TIOCCBRK 0x7428
  204. //
  205. // This ioctl returns the session ID of the given terminal. This will fail
  206. // with ENOTTY if the terminal is not a master pseudoterminal and not the
  207. // calling process' controlling terminal. The argument is a pointer to a pid_t.
  208. //
  209. #define TIOCGSID 0x7429
  210. //
  211. // This ioctl sets the async mode on the given descriptor. It is the same as
  212. // using fcntl to enable asynchronous mode. The argument is an int, which if
  213. // zero disables asynchronous mode, or otherwise enables it.
  214. //
  215. #define FIOASYNC 0x7452
  216. //
  217. // Define the possible bits for the control byte in packet mode.
  218. //
  219. //
  220. // This byte is returned when there's data to be read (or no data).
  221. //
  222. #define TIOCPKT_DATA 0x00
  223. //
  224. // This flag is returned when the read queue for the terminal is flushed.
  225. //
  226. #define TIOCPKT_FLUSHREAD 0x01
  227. //
  228. // This flag is returned when the write queue for the terminal is flushed.
  229. //
  230. #define TIOCPKT_FLUSHWRITE 0x02
  231. //
  232. // This flag is returned when output to the terminal is stopped.
  233. //
  234. #define TIOCPKT_STOP 0x04
  235. //
  236. // This flag is returned when output to the terminal is restarted.
  237. //
  238. #define TIOCPKT_START 0x08
  239. //
  240. // This flag is returned when the start and stop characters are not ^S and ^Q.
  241. //
  242. #define TIOCPKT_NOSTOP 0x10
  243. //
  244. // This flag is returned when the start and stop characters are ^S and ^Q.
  245. //
  246. #define TIOCPKT_DOSTOP 0x20
  247. //
  248. // This flag is returned when an IOCTL has come in and changed the state of
  249. // the terminal.
  250. //
  251. #define TIOCPKT_IOCTL 0x40
  252. //
  253. // Define modem status bits.
  254. //
  255. //
  256. // Data set ready (line enable).
  257. //
  258. #define TIOCM_LE 0x0001
  259. //
  260. // Data terminal ready.
  261. //
  262. #define TIOCM_DTR 0x0002
  263. //
  264. // Request to send.
  265. //
  266. #define TIOCM_RTS 0x0004
  267. //
  268. // Secondary transmit.
  269. //
  270. #define TIOCM_ST 0x0008
  271. //
  272. // Secondary receive.
  273. //
  274. #define TIOCM_SR 0x0010
  275. //
  276. // Clear to send.
  277. //
  278. #define TIOCM_CTS 0x0020
  279. //
  280. // Data carrier detect (DCD).
  281. //
  282. #define TIOCM_CAR 0x0040
  283. #define TIOCM_CD TIOCM_CAR
  284. //
  285. // Ring.
  286. //
  287. #define TIOCM_RNG 0x0080
  288. #define TIOCM_RI TIOCM_RNG
  289. //
  290. // Data Set Ready.
  291. //
  292. #define TIOCM_DSR 0x0100
  293. //
  294. // Define the size of the control character array for the old termio structure.
  295. //
  296. #define NCC 8
  297. //
  298. // ------------------------------------------------------ Data Type Definitions
  299. //
  300. /*++
  301. Structure Description:
  302. This structure stores the old format of the terminal behavior and settings.
  303. New applications should use struct termios in termios.h.
  304. Members:
  305. c_iflag - Stores the input mode flags.
  306. c_oflag - Stores the output mode flags.
  307. c_cflag - Stores the control mode flags.
  308. c_lflag - Stores the local control flags.
  309. c_line - Stores the line discipline.
  310. c_cc - Stores the characters to use for control characters.
  311. c_ispeed - Stores the input baud rate.
  312. c_ospeed - Stores the output baud rate.
  313. --*/
  314. struct termio {
  315. unsigned short int c_iflag;
  316. unsigned short int c_oflag;
  317. unsigned short int c_cflag;
  318. unsigned short int c_lflag;
  319. unsigned char c_line;
  320. unsigned char c_cc[NCC];
  321. };
  322. /*++
  323. Structure Description:
  324. This structure stores the window size structure passed by the TIOCGWINSZ
  325. and TIOCSWINSZ ioctls.
  326. Members:
  327. ws_row - Stores the count of rows in the window.
  328. ws_col - Stores the count of columns in the window.
  329. ws_xpixel - Stores an unused value. Defined for compatibility sake.
  330. ws_ypixel - Stores an unused value. Defined for compatilibity sake.
  331. --*/
  332. struct winsize {
  333. unsigned short int ws_row;
  334. unsigned short int ws_col;
  335. unsigned short int ws_xpixel;
  336. unsigned short int ws_ypixel;
  337. };
  338. //
  339. // -------------------------------------------------------------------- Globals
  340. //
  341. //
  342. // -------------------------------------------------------- Function Prototypes
  343. //
  344. LIBC_API
  345. int
  346. ioctl (
  347. int FileDescriptor,
  348. int Request,
  349. ...
  350. );
  351. /*++
  352. Routine Description:
  353. This routine sends an I/O control request to the given file descriptor.
  354. Arguments:
  355. FileDescriptor - Supplies the file descriptor to send the control request
  356. to.
  357. Request - Supplies the numeric request to send. This is device-specific.
  358. ... - Supplies a variable number of arguments for historical reasons, but
  359. this routine expects there to be exactly one more argument, a pointer
  360. to memory. The size of this memory is request-specific, but can be no
  361. larger than 4096 bytes. The native version of this routine can specify
  362. larger values.
  363. Return Value:
  364. 0 on success.
  365. -1 on failure, and errno will be set to contain more information.
  366. --*/
  367. #ifdef __cplusplus
  368. }
  369. #endif
  370. #endif