Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * This file is subject to the terms and conditions of the GNU General Public
0003  * License.  See the file "COPYING" in the main directory of this archive
0004  * for more details.
0005  *
0006  * Copyright (C) 1995, 1996, 2000, 2001 by Ralf Baechle
0007  * Copyright (C) 2000, 2001 Silicon Graphics, Inc.
0008  */
0009 #ifndef _ASM_TERMIOS_H
0010 #define _ASM_TERMIOS_H
0011 
0012 #include <linux/uaccess.h>
0013 #include <uapi/asm/termios.h>
0014 
0015 /*
0016  *  intr=^C     quit=^\     erase=del   kill=^U
0017  *  vmin=\1     vtime=\0    eol2=\0     swtc=\0
0018  *  start=^Q    stop=^S     susp=^Z     vdsusp=
0019  *  reprint=^R  discard=^U  werase=^W   lnext=^V
0020  *  eof=^D      eol=\0
0021  */
0022 #define INIT_C_CC "\003\034\177\025\1\0\0\0\021\023\032\0\022\017\027\026\004\0"
0023 
0024 #include <linux/string.h>
0025 
0026 /*
0027  * Translate a "termio" structure into a "termios". Ugh.
0028  */
0029 static inline int user_termio_to_kernel_termios(struct ktermios *termios,
0030     struct termio __user *termio)
0031 {
0032     unsigned short iflag, oflag, cflag, lflag;
0033     unsigned int err;
0034 
0035     if (!access_ok(termio, sizeof(struct termio)))
0036         return -EFAULT;
0037 
0038     err = __get_user(iflag, &termio->c_iflag);
0039     termios->c_iflag = (termios->c_iflag & 0xffff0000) | iflag;
0040     err |=__get_user(oflag, &termio->c_oflag);
0041     termios->c_oflag = (termios->c_oflag & 0xffff0000) | oflag;
0042     err |=__get_user(cflag, &termio->c_cflag);
0043     termios->c_cflag = (termios->c_cflag & 0xffff0000) | cflag;
0044     err |=__get_user(lflag, &termio->c_lflag);
0045     termios->c_lflag = (termios->c_lflag & 0xffff0000) | lflag;
0046     err |=__get_user(termios->c_line, &termio->c_line);
0047     if (err)
0048         return -EFAULT;
0049 
0050     if (__copy_from_user(termios->c_cc, termio->c_cc, NCC))
0051         return -EFAULT;
0052 
0053     return 0;
0054 }
0055 
0056 /*
0057  * Translate a "termios" structure into a "termio". Ugh.
0058  */
0059 static inline int kernel_termios_to_user_termio(struct termio __user *termio,
0060     struct ktermios *termios)
0061 {
0062     int err;
0063 
0064     if (!access_ok(termio, sizeof(struct termio)))
0065         return -EFAULT;
0066 
0067     err = __put_user(termios->c_iflag, &termio->c_iflag);
0068     err |= __put_user(termios->c_oflag, &termio->c_oflag);
0069     err |= __put_user(termios->c_cflag, &termio->c_cflag);
0070     err |= __put_user(termios->c_lflag, &termio->c_lflag);
0071     err |= __put_user(termios->c_line, &termio->c_line);
0072     if (err)
0073         return -EFAULT;
0074 
0075     if (__copy_to_user(termio->c_cc, termios->c_cc, NCC))
0076         return -EFAULT;
0077 
0078     return 0;
0079 }
0080 
0081 static inline int user_termios_to_kernel_termios(struct ktermios __user *k,
0082     struct termios2 *u)
0083 {
0084     return copy_from_user(k, u, sizeof(struct termios2)) ? -EFAULT : 0;
0085 }
0086 
0087 static inline int kernel_termios_to_user_termios(struct termios2 __user *u,
0088     struct ktermios *k)
0089 {
0090     return copy_to_user(u, k, sizeof(struct termios2)) ? -EFAULT : 0;
0091 }
0092 
0093 static inline int user_termios_to_kernel_termios_1(struct ktermios *k,
0094     struct termios __user *u)
0095 {
0096     return copy_from_user(k, u, sizeof(struct termios)) ? -EFAULT : 0;
0097 }
0098 
0099 static inline int kernel_termios_to_user_termios_1(struct termios __user *u,
0100     struct ktermios *k)
0101 {
0102     return copy_to_user(u, k, sizeof(struct termios)) ? -EFAULT : 0;
0103 }
0104 
0105 #endif /* _ASM_TERMIOS_H */