termios.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1995, 1996, 2000, 2001 by Ralf Baechle
  7. * Copyright (C) 2000, 2001 Silicon Graphics, Inc.
  8. */
  9. #ifndef _ASM_TERMIOS_H
  10. #define _ASM_TERMIOS_H
  11. #include <linux/errno.h>
  12. #include <asm/termbits.h>
  13. #include <asm/ioctls.h>
  14. struct sgttyb {
  15. char sg_ispeed;
  16. char sg_ospeed;
  17. char sg_erase;
  18. char sg_kill;
  19. int sg_flags; /* SGI special - int, not short */
  20. };
  21. struct tchars {
  22. char t_intrc;
  23. char t_quitc;
  24. char t_startc;
  25. char t_stopc;
  26. char t_eofc;
  27. char t_brkc;
  28. };
  29. struct ltchars {
  30. char t_suspc; /* stop process signal */
  31. char t_dsuspc; /* delayed stop process signal */
  32. char t_rprntc; /* reprint line */
  33. char t_flushc; /* flush output (toggles) */
  34. char t_werasc; /* word erase */
  35. char t_lnextc; /* literal next character */
  36. };
  37. /* TIOCGSIZE, TIOCSSIZE not defined yet. Only needed for SunOS source
  38. compatibility anyway ... */
  39. struct winsize {
  40. unsigned short ws_row;
  41. unsigned short ws_col;
  42. unsigned short ws_xpixel;
  43. unsigned short ws_ypixel;
  44. };
  45. #define NCC 8
  46. struct termio {
  47. unsigned short c_iflag; /* input mode flags */
  48. unsigned short c_oflag; /* output mode flags */
  49. unsigned short c_cflag; /* control mode flags */
  50. unsigned short c_lflag; /* local mode flags */
  51. char c_line; /* line discipline */
  52. unsigned char c_cc[NCCS]; /* control characters */
  53. };
  54. #ifdef __KERNEL__
  55. #include <linux/module.h>
  56. /*
  57. * intr=^C quit=^\ erase=del kill=^U
  58. * vmin=\1 vtime=\0 eol2=\0 swtc=\0
  59. * start=^Q stop=^S susp=^Z vdsusp=
  60. * reprint=^R discard=^U werase=^W lnext=^V
  61. * eof=^D eol=\0
  62. */
  63. #define INIT_C_CC "\003\034\177\025\1\0\0\0\021\023\032\0\022\017\027\026\004\0"
  64. #endif
  65. /* modem lines */
  66. #define TIOCM_LE 0x001 /* line enable */
  67. #define TIOCM_DTR 0x002 /* data terminal ready */
  68. #define TIOCM_RTS 0x004 /* request to send */
  69. #define TIOCM_ST 0x010 /* secondary transmit */
  70. #define TIOCM_SR 0x020 /* secondary receive */
  71. #define TIOCM_CTS 0x040 /* clear to send */
  72. #define TIOCM_CAR 0x100 /* carrier detect */
  73. #define TIOCM_CD TIOCM_CAR
  74. #define TIOCM_RNG 0x200 /* ring */
  75. #define TIOCM_RI TIOCM_RNG
  76. #define TIOCM_DSR 0x400 /* data set ready */
  77. #define TIOCM_OUT1 0x2000
  78. #define TIOCM_OUT2 0x4000
  79. #define TIOCM_LOOP 0x8000
  80. #ifdef __KERNEL__
  81. #include <linux/string.h>
  82. /*
  83. * Translate a "termio" structure into a "termios". Ugh.
  84. */
  85. static inline int user_termio_to_kernel_termios(struct ktermios *termios,
  86. struct termio __user *termio)
  87. {
  88. unsigned short iflag, oflag, cflag, lflag;
  89. unsigned int err;
  90. if (!access_ok(VERIFY_READ, termio, sizeof(struct termio)))
  91. return -EFAULT;
  92. err = __get_user(iflag, &termio->c_iflag);
  93. termios->c_iflag = (termios->c_iflag & 0xffff0000) | iflag;
  94. err |=__get_user(oflag, &termio->c_oflag);
  95. termios->c_oflag = (termios->c_oflag & 0xffff0000) | oflag;
  96. err |=__get_user(cflag, &termio->c_cflag);
  97. termios->c_cflag = (termios->c_cflag & 0xffff0000) | cflag;
  98. err |=__get_user(lflag, &termio->c_lflag);
  99. termios->c_lflag = (termios->c_lflag & 0xffff0000) | lflag;
  100. err |=__get_user(termios->c_line, &termio->c_line);
  101. if (err)
  102. return -EFAULT;
  103. if (__copy_from_user(termios->c_cc, termio->c_cc, NCC))
  104. return -EFAULT;
  105. return 0;
  106. }
  107. /*
  108. * Translate a "termios" structure into a "termio". Ugh.
  109. */
  110. static inline int kernel_termios_to_user_termio(struct termio __user *termio,
  111. struct ktermios *termios)
  112. {
  113. int err;
  114. if (!access_ok(VERIFY_WRITE, termio, sizeof(struct termio)))
  115. return -EFAULT;
  116. err = __put_user(termios->c_iflag, &termio->c_iflag);
  117. err |= __put_user(termios->c_oflag, &termio->c_oflag);
  118. err |= __put_user(termios->c_cflag, &termio->c_cflag);
  119. err |= __put_user(termios->c_lflag, &termio->c_lflag);
  120. err |= __put_user(termios->c_line, &termio->c_line);
  121. if (err)
  122. return -EFAULT;
  123. if (__copy_to_user(termio->c_cc, termios->c_cc, NCC))
  124. return -EFAULT;
  125. return 0;
  126. }
  127. static inline int user_termios_to_kernel_termios(struct ktermios __user *k,
  128. struct termios2 *u)
  129. {
  130. return copy_from_user(k, u, sizeof(struct termios2)) ? -EFAULT : 0;
  131. }
  132. static inline int kernel_termios_to_user_termios(struct termios2 __user *u,
  133. struct ktermios *k)
  134. {
  135. return copy_to_user(u, k, sizeof(struct termios2)) ? -EFAULT : 0;
  136. }
  137. static inline int user_termios_to_kernel_termios_1(struct ktermios *k,
  138. struct termios __user *u)
  139. {
  140. return copy_from_user(k, u, sizeof(struct termios)) ? -EFAULT : 0;
  141. }
  142. static inline int kernel_termios_to_user_termios_1(struct termios __user *u,
  143. struct ktermios *k)
  144. {
  145. return copy_to_user(u, k, sizeof(struct termios)) ? -EFAULT : 0;
  146. }
  147. #endif /* defined(__KERNEL__) */
  148. #endif /* _ASM_TERMIOS_H */