1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_GENERIC_TERMIOS_H
3 #define _ASM_GENERIC_TERMIOS_H
6 #include <linux/uaccess.h>
7 #include <uapi/asm-generic/termios.h>
9 /* intr=^C quit=^\ erase=del kill=^U
10 eof=^D vtime=\0 vmin=\1 sxtc=\0
11 start=^Q stop=^S susp=^Z eol=\0
12 reprint=^R discard=^U werase=^W lnext=^V
15 #define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0"
18 * Translate a "termio" structure into a "termios". Ugh.
20 static inline int user_termio_to_kernel_termios(struct ktermios
*termios
,
21 const struct termio __user
*termio
)
25 if (get_user(tmp
, &termio
->c_iflag
) < 0)
27 termios
->c_iflag
= (0xffff0000 & termios
->c_iflag
) | tmp
;
29 if (get_user(tmp
, &termio
->c_oflag
) < 0)
31 termios
->c_oflag
= (0xffff0000 & termios
->c_oflag
) | tmp
;
33 if (get_user(tmp
, &termio
->c_cflag
) < 0)
35 termios
->c_cflag
= (0xffff0000 & termios
->c_cflag
) | tmp
;
37 if (get_user(tmp
, &termio
->c_lflag
) < 0)
39 termios
->c_lflag
= (0xffff0000 & termios
->c_lflag
) | tmp
;
41 if (get_user(termios
->c_line
, &termio
->c_line
) < 0)
44 if (copy_from_user(termios
->c_cc
, termio
->c_cc
, NCC
) != 0)
54 * Translate a "termios" structure into a "termio". Ugh.
56 static inline int kernel_termios_to_user_termio(struct termio __user
*termio
,
57 struct ktermios
*termios
)
59 if (put_user(termios
->c_iflag
, &termio
->c_iflag
) < 0 ||
60 put_user(termios
->c_oflag
, &termio
->c_oflag
) < 0 ||
61 put_user(termios
->c_cflag
, &termio
->c_cflag
) < 0 ||
62 put_user(termios
->c_lflag
, &termio
->c_lflag
) < 0 ||
63 put_user(termios
->c_line
, &termio
->c_line
) < 0 ||
64 copy_to_user(termio
->c_cc
, termios
->c_cc
, NCC
) != 0)
71 static inline int user_termios_to_kernel_termios(struct ktermios
*k
,
72 struct termios2 __user
*u
)
74 return copy_from_user(k
, u
, sizeof(struct termios2
));
77 static inline int kernel_termios_to_user_termios(struct termios2 __user
*u
,
80 return copy_to_user(u
, k
, sizeof(struct termios2
));
83 static inline int user_termios_to_kernel_termios_1(struct ktermios
*k
,
84 struct termios __user
*u
)
86 return copy_from_user(k
, u
, sizeof(struct termios
));
89 static inline int kernel_termios_to_user_termios_1(struct termios __user
*u
,
92 return copy_to_user(u
, k
, sizeof(struct termios
));
95 static inline int user_termios_to_kernel_termios(struct ktermios
*k
,
96 struct termios __user
*u
)
98 return copy_from_user(k
, u
, sizeof(struct termios
));
101 static inline int kernel_termios_to_user_termios(struct termios __user
*u
,
104 return copy_to_user(u
, k
, sizeof(struct termios
));
108 #endif /* _ASM_GENERIC_TERMIOS_H */