termios.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #ifndef _ASM_GENERIC_TERMIOS_H
  2. #define _ASM_GENERIC_TERMIOS_H
  3. #include <asm/uaccess.h>
  4. #include <uapi/asm-generic/termios.h>
  5. /* intr=^C quit=^\ erase=del kill=^U
  6. eof=^D vtime=\0 vmin=\1 sxtc=\0
  7. start=^Q stop=^S susp=^Z eol=\0
  8. reprint=^R discard=^U werase=^W lnext=^V
  9. eol2=\0
  10. */
  11. #define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0"
  12. /*
  13. * Translate a "termio" structure into a "termios". Ugh.
  14. */
  15. static inline int user_termio_to_kernel_termios(struct ktermios *termios,
  16. const struct termio __user *termio)
  17. {
  18. unsigned short tmp;
  19. if (get_user(tmp, &termio->c_iflag) < 0)
  20. goto fault;
  21. termios->c_iflag = (0xffff0000 & termios->c_iflag) | tmp;
  22. if (get_user(tmp, &termio->c_oflag) < 0)
  23. goto fault;
  24. termios->c_oflag = (0xffff0000 & termios->c_oflag) | tmp;
  25. if (get_user(tmp, &termio->c_cflag) < 0)
  26. goto fault;
  27. termios->c_cflag = (0xffff0000 & termios->c_cflag) | tmp;
  28. if (get_user(tmp, &termio->c_lflag) < 0)
  29. goto fault;
  30. termios->c_lflag = (0xffff0000 & termios->c_lflag) | tmp;
  31. if (get_user(termios->c_line, &termio->c_line) < 0)
  32. goto fault;
  33. if (copy_from_user(termios->c_cc, termio->c_cc, NCC) != 0)
  34. goto fault;
  35. return 0;
  36. fault:
  37. return -EFAULT;
  38. }
  39. /*
  40. * Translate a "termios" structure into a "termio". Ugh.
  41. */
  42. static inline int kernel_termios_to_user_termio(struct termio __user *termio,
  43. struct ktermios *termios)
  44. {
  45. if (put_user(termios->c_iflag, &termio->c_iflag) < 0 ||
  46. put_user(termios->c_oflag, &termio->c_oflag) < 0 ||
  47. put_user(termios->c_cflag, &termio->c_cflag) < 0 ||
  48. put_user(termios->c_lflag, &termio->c_lflag) < 0 ||
  49. put_user(termios->c_line, &termio->c_line) < 0 ||
  50. copy_to_user(termio->c_cc, termios->c_cc, NCC) != 0)
  51. return -EFAULT;
  52. return 0;
  53. }
  54. #ifdef TCGETS2
  55. static inline int user_termios_to_kernel_termios(struct ktermios *k,
  56. struct termios2 __user *u)
  57. {
  58. return copy_from_user(k, u, sizeof(struct termios2));
  59. }
  60. static inline int kernel_termios_to_user_termios(struct termios2 __user *u,
  61. struct ktermios *k)
  62. {
  63. return copy_to_user(u, k, sizeof(struct termios2));
  64. }
  65. static inline int user_termios_to_kernel_termios_1(struct ktermios *k,
  66. struct termios __user *u)
  67. {
  68. return copy_from_user(k, u, sizeof(struct termios));
  69. }
  70. static inline int kernel_termios_to_user_termios_1(struct termios __user *u,
  71. struct ktermios *k)
  72. {
  73. return copy_to_user(u, k, sizeof(struct termios));
  74. }
  75. #else /* TCGETS2 */
  76. static inline int user_termios_to_kernel_termios(struct ktermios *k,
  77. struct termios __user *u)
  78. {
  79. return copy_from_user(k, u, sizeof(struct termios));
  80. }
  81. static inline int kernel_termios_to_user_termios(struct termios __user *u,
  82. struct ktermios *k)
  83. {
  84. return copy_to_user(u, k, sizeof(struct termios));
  85. }
  86. #endif /* TCGETS2 */
  87. #endif /* _ASM_GENERIC_TERMIOS_H */