termios.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #ifndef _ASM_GENERIC_TERMIOS_H
  2. #define _ASM_GENERIC_TERMIOS_H
  3. /*
  4. * Most architectures have straight copies of the x86 code, with
  5. * varying levels of bug fixes on top. Usually it's a good idea
  6. * to use this generic version instead, but be careful to avoid
  7. * ABI changes.
  8. * New architectures should not provide their own version.
  9. */
  10. #include <asm/termbits.h>
  11. #include <asm/ioctls.h>
  12. struct winsize {
  13. unsigned short ws_row;
  14. unsigned short ws_col;
  15. unsigned short ws_xpixel;
  16. unsigned short ws_ypixel;
  17. };
  18. #define NCC 8
  19. struct termio {
  20. unsigned short c_iflag; /* input mode flags */
  21. unsigned short c_oflag; /* output mode flags */
  22. unsigned short c_cflag; /* control mode flags */
  23. unsigned short c_lflag; /* local mode flags */
  24. unsigned char c_line; /* line discipline */
  25. unsigned char c_cc[NCC]; /* control characters */
  26. };
  27. /* modem lines */
  28. #define TIOCM_LE 0x001
  29. #define TIOCM_DTR 0x002
  30. #define TIOCM_RTS 0x004
  31. #define TIOCM_ST 0x008
  32. #define TIOCM_SR 0x010
  33. #define TIOCM_CTS 0x020
  34. #define TIOCM_CAR 0x040
  35. #define TIOCM_RNG 0x080
  36. #define TIOCM_DSR 0x100
  37. #define TIOCM_CD TIOCM_CAR
  38. #define TIOCM_RI TIOCM_RNG
  39. #define TIOCM_OUT1 0x2000
  40. #define TIOCM_OUT2 0x4000
  41. #define TIOCM_LOOP 0x8000
  42. /* ioctl (fd, TIOCSERGETLSR, &result) where result may be as below */
  43. #ifdef __KERNEL__
  44. #include <asm/uaccess.h>
  45. /* intr=^C quit=^\ erase=del kill=^U
  46. eof=^D vtime=\0 vmin=\1 sxtc=\0
  47. start=^Q stop=^S susp=^Z eol=\0
  48. reprint=^R discard=^U werase=^W lnext=^V
  49. eol2=\0
  50. */
  51. #define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0"
  52. /*
  53. * Translate a "termio" structure into a "termios". Ugh.
  54. */
  55. static inline int user_termio_to_kernel_termios(struct ktermios *termios,
  56. const struct termio __user *termio)
  57. {
  58. unsigned short tmp;
  59. if (get_user(tmp, &termio->c_iflag) < 0)
  60. goto fault;
  61. termios->c_iflag = (0xffff0000 & termios->c_iflag) | tmp;
  62. if (get_user(tmp, &termio->c_oflag) < 0)
  63. goto fault;
  64. termios->c_oflag = (0xffff0000 & termios->c_oflag) | tmp;
  65. if (get_user(tmp, &termio->c_cflag) < 0)
  66. goto fault;
  67. termios->c_cflag = (0xffff0000 & termios->c_cflag) | tmp;
  68. if (get_user(tmp, &termio->c_lflag) < 0)
  69. goto fault;
  70. termios->c_lflag = (0xffff0000 & termios->c_lflag) | tmp;
  71. if (get_user(termios->c_line, &termio->c_line) < 0)
  72. goto fault;
  73. if (copy_from_user(termios->c_cc, termio->c_cc, NCC) != 0)
  74. goto fault;
  75. return 0;
  76. fault:
  77. return -EFAULT;
  78. }
  79. /*
  80. * Translate a "termios" structure into a "termio". Ugh.
  81. */
  82. static inline int kernel_termios_to_user_termio(struct termio __user *termio,
  83. struct ktermios *termios)
  84. {
  85. if (put_user(termios->c_iflag, &termio->c_iflag) < 0 ||
  86. put_user(termios->c_oflag, &termio->c_oflag) < 0 ||
  87. put_user(termios->c_cflag, &termio->c_cflag) < 0 ||
  88. put_user(termios->c_lflag, &termio->c_lflag) < 0 ||
  89. put_user(termios->c_line, &termio->c_line) < 0 ||
  90. copy_to_user(termio->c_cc, termios->c_cc, NCC) != 0)
  91. return -EFAULT;
  92. return 0;
  93. }
  94. #ifdef TCGETS2
  95. static inline int user_termios_to_kernel_termios(struct ktermios *k,
  96. struct termios2 __user *u)
  97. {
  98. return copy_from_user(k, u, sizeof(struct termios2));
  99. }
  100. static inline int kernel_termios_to_user_termios(struct termios2 __user *u,
  101. struct ktermios *k)
  102. {
  103. return copy_to_user(u, k, sizeof(struct termios2));
  104. }
  105. static inline int user_termios_to_kernel_termios_1(struct ktermios *k,
  106. struct termios __user *u)
  107. {
  108. return copy_from_user(k, u, sizeof(struct termios));
  109. }
  110. static inline int kernel_termios_to_user_termios_1(struct termios __user *u,
  111. struct ktermios *k)
  112. {
  113. return copy_to_user(u, k, sizeof(struct termios));
  114. }
  115. #else /* TCGETS2 */
  116. static inline int user_termios_to_kernel_termios(struct ktermios *k,
  117. struct termios __user *u)
  118. {
  119. return copy_from_user(k, u, sizeof(struct termios));
  120. }
  121. static inline int kernel_termios_to_user_termios(struct termios __user *u,
  122. struct ktermios *k)
  123. {
  124. return copy_to_user(u, k, sizeof(struct termios));
  125. }
  126. #endif /* TCGETS2 */
  127. #endif /* __KERNEL__ */
  128. #endif /* _ASM_GENERIC_TERMIOS_H */