termios.h 2.9 KB

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