The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/compat/svr4_32/svr4_32_termios.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: svr4_32_termios.c,v 1.10 2005/12/11 12:20:26 christos Exp $     */
    2 
    3 /*-
    4  * Copyright (c) 1994 The NetBSD Foundation, Inc.
    5  * All rights reserved.
    6  *
    7  * This code is derived from software contributed to The NetBSD Foundation
    8  * by Christos Zoulas.
    9  *
   10  * Redistribution and use in source and binary forms, with or without
   11  * modification, are permitted provided that the following conditions
   12  * are met:
   13  * 1. Redistributions of source code must retain the above copyright
   14  *    notice, this list of conditions and the following disclaimer.
   15  * 2. Redistributions in binary form must reproduce the above copyright
   16  *    notice, this list of conditions and the following disclaimer in the
   17  *    documentation and/or other materials provided with the distribution.
   18  * 3. All advertising materials mentioning features or use of this software
   19  *    must display the following acknowledgement:
   20  *        This product includes software developed by the NetBSD
   21  *        Foundation, Inc. and its contributors.
   22  * 4. Neither the name of The NetBSD Foundation nor the names of its
   23  *    contributors may be used to endorse or promote products derived
   24  *    from this software without specific prior written permission.
   25  *
   26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
   27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
   30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   36  * POSSIBILITY OF SUCH DAMAGE.
   37  */
   38 
   39 #include <sys/cdefs.h>
   40 __KERNEL_RCSID(0, "$NetBSD: svr4_32_termios.c,v 1.10 2005/12/11 12:20:26 christos Exp $");
   41 
   42 #include <sys/param.h>
   43 #include <sys/proc.h>
   44 #include <sys/systm.h>
   45 #include <sys/file.h>
   46 #include <sys/filedesc.h>
   47 #include <sys/ioctl.h>
   48 #include <sys/termios.h>
   49 #include <sys/tty.h>
   50 #include <sys/socket.h>
   51 #include <sys/ioctl.h>
   52 #include <sys/mount.h>
   53 #include <net/if.h>
   54 #include <sys/malloc.h>
   55 
   56 #include <sys/sa.h>
   57 #include <sys/syscallargs.h>
   58 
   59 #include <compat/svr4_32/svr4_32_types.h>
   60 #include <compat/svr4_32/svr4_32_util.h>
   61 #include <compat/svr4_32/svr4_32_signal.h>
   62 #include <compat/svr4_32/svr4_32_ioctl.h>
   63 #include <compat/svr4_32/svr4_32_lwp.h>
   64 #include <compat/svr4_32/svr4_32_ucontext.h>
   65 #include <compat/svr4_32/svr4_32_syscallargs.h>
   66 #include <compat/svr4_32/svr4_32_stropts.h>
   67 #include <compat/svr4_32/svr4_32_termios.h>
   68 
   69 
   70 #ifndef __CONCAT3
   71 # if __STDC__
   72 #  define __CONCAT3(a,b,c)      a ## b ## c
   73 # else
   74 #  define __CONCAT3(a,b,c)      a/**/b/**/c
   75 # endif
   76 #endif
   77 
   78 static u_long bsd_to_svr4_32_speed __P((u_long, u_long));
   79 static u_long svr4_32_to_bsd_speed __P((u_long, u_long));
   80 static void svr4_32_to_bsd_termios __P((const struct svr4_32_termios *,
   81                                      struct termios *, int));
   82 static void bsd_to_svr4_32_termios __P((const struct termios *,
   83                                      struct svr4_32_termios *));
   84 static void svr4_termio_to_termios __P((const struct svr4_termio *,
   85                                         struct svr4_32_termios *));
   86 static void svr4_32_termios_to_termio __P((const struct svr4_32_termios *,
   87                                         struct svr4_termio *));
   88 #ifdef DEBUG_SVR4
   89 static void print_svr4_32_termios __P((const struct svr4_32_termios *));
   90 static void print_bsd_termios __P((const struct termios *));
   91 #endif /* DEBUG_SVR4 */
   92 
   93 #define undefined_char(a,b)                             /**/
   94 #define undefined_flag1(f,a,b)                          /**/
   95 #define undefined_flag2(f,a,b,c1,t1,c2,t2)              /**/
   96 #define undefined_flag4(f,a,b,c1,t1,c2,t2,c3,t3,c4,t4)  /**/
   97 
   98 #define svr4_to_bsd_char(a,b) \
   99         if (new || __CONCAT3(SVR4_,a,b) < SVR4_NCC) { \
  100                 if (st->c_cc[__CONCAT3(SVR4_,a,b)] == SVR4_POSIX_VDISABLE) \
  101                         bt->c_cc[__CONCAT(a,b)] = _POSIX_VDISABLE; \
  102                 else \
  103                         bt->c_cc[__CONCAT(a,b)] = st->c_cc[__CONCAT3(SVR4_,a,b)]; \
  104         }
  105 
  106 #define svr4_to_bsd_flag1(f,a,b) \
  107         if (new || __CONCAT3(SVR4_,a,b) < 0200000) { \
  108                 if (st->f & __CONCAT3(SVR4_,a,b)) \
  109                         bt->f |= __CONCAT(a,b); \
  110                 else \
  111                         bt->f &= ~__CONCAT(a,b); \
  112         }
  113 
  114 #define svr4_to_bsd_flag2(f,a,b,c1,t1,c2,t2) \
  115         if (new || __CONCAT3(SVR4_,a,b) < 0200000) { \
  116                 bt->f &= ~__CONCAT(a,b); \
  117                 switch (st->f & __CONCAT3(SVR4_,a,b)) { \
  118                 case __CONCAT3(SVR4_,c1,t1): bt->f |= __CONCAT(c1,t1); break; \
  119                 case __CONCAT3(SVR4_,c2,t2): bt->f |= __CONCAT(c2,t2); break; \
  120                 } \
  121         }
  122 
  123 #define svr4_to_bsd_flag4(f,a,b,c1,t1,c2,t2,c3,t3,c4,t4) \
  124         if (new || __CONCAT3(SVR4_,a,b) < 0200000) { \
  125                 bt->f &= ~__CONCAT(a,b); \
  126                 switch (st->f & __CONCAT3(SVR4_,a,b)) { \
  127                 case __CONCAT3(SVR4_,c1,t1): bt->f |= __CONCAT(c1,t1); break; \
  128                 case __CONCAT3(SVR4_,c2,t2): bt->f |= __CONCAT(c2,t2); break; \
  129                 case __CONCAT3(SVR4_,c3,t3): bt->f |= __CONCAT(c3,t3); break; \
  130                 case __CONCAT3(SVR4_,c4,t4): bt->f |= __CONCAT(c4,t4); break; \
  131                 } \
  132         }
  133 
  134 
  135 #define bsd_to_svr4_char(a,b) \
  136         if (bt->c_cc[__CONCAT(a,b)] == _POSIX_VDISABLE) \
  137                 st->c_cc[__CONCAT3(SVR4_,a,b)] = SVR4_POSIX_VDISABLE; \
  138         else \
  139                 st->c_cc[__CONCAT3(SVR4_,a,b)] = bt->c_cc[__CONCAT(a,b)]
  140 
  141 #define bsd_to_svr4_flag1(f,a,b) \
  142         if (bt->f & __CONCAT(a,b)) \
  143                 st->f |= __CONCAT3(SVR4_,a,b); \
  144         else \
  145                 st->f &= ~__CONCAT3(SVR4_,a,b)
  146 
  147 #define bsd_to_svr4_flag2(f,a,b,c1,t1,c2,t2) \
  148         st->f &= ~__CONCAT(a,b); \
  149         switch (bt->f & __CONCAT(a,b)) { \
  150         case __CONCAT(c1,t1): st->f |= __CONCAT3(SVR4_,c1,t1); break; \
  151         case __CONCAT(c2,t2): st->f |= __CONCAT3(SVR4_,c2,t2); break; \
  152         }
  153 
  154 #define bsd_to_svr4_flag4(f,a,b,c1,t1,c2,t2,c3,t3,c4,t4) \
  155         st->f &= ~__CONCAT(a,b); \
  156         switch (bt->f & __CONCAT(a,b)) { \
  157         case __CONCAT(c1,t1): st->f |= __CONCAT3(SVR4_,c1,t1); break; \
  158         case __CONCAT(c2,t2): st->f |= __CONCAT3(SVR4_,c2,t2); break; \
  159         case __CONCAT(c3,t3): st->f |= __CONCAT3(SVR4_,c3,t3); break; \
  160         case __CONCAT(c4,t4): st->f |= __CONCAT3(SVR4_,c4,t4); break; \
  161         }
  162 
  163 #ifdef DEBUG_SVR4
  164 static void
  165 print_svr4_32_termios(st)
  166         const struct svr4_32_termios *st;
  167 {
  168         int i;
  169         uprintf("SVR4_32\niflag=%lo oflag=%lo cflag=%lo lflag=%lo\n",
  170             st->c_iflag, st->c_oflag, st->c_cflag, st->c_lflag);
  171         uprintf("cc: ");
  172         for (i = 0; i < SVR4_NCCS; i++)
  173                 uprintf("%o ", st->c_cc[i]);
  174         uprintf("\n");
  175 }
  176 
  177 
  178 static void
  179 print_bsd_termios(bt)
  180         const struct termios *bt;
  181 {
  182         int i;
  183         uprintf("BSD\niflag=%o oflag=%o cflag=%o lflag=%o\n",
  184             bt->c_iflag, bt->c_oflag, bt->c_cflag, bt->c_lflag);
  185         uprintf("cc: ");
  186         for (i = 0; i < NCCS; i++)
  187                 uprintf("%o ", bt->c_cc[i]);
  188         uprintf("\n");
  189 }
  190 #endif /* DEBUG_SVR4 */
  191 
  192 static u_long
  193 bsd_to_svr4_32_speed(sp, mask)
  194         u_long sp;
  195         u_long mask;
  196 {
  197         switch (sp) {
  198 #undef getval
  199 #define getval(a,b)     case __CONCAT(a,b):     sp = __CONCAT3(SVR4_,a,b)
  200         getval(B,0);
  201         getval(B,50);
  202         getval(B,75);
  203         getval(B,110);
  204         getval(B,134);
  205         getval(B,150);
  206         getval(B,200);
  207         getval(B,300);
  208         getval(B,600);
  209         getval(B,1200);
  210         getval(B,1800);
  211         getval(B,2400);
  212         getval(B,4800);
  213         getval(B,9600);
  214         getval(B,19200);
  215         getval(B,38400);
  216         getval(B,57600);
  217         getval(B,115200);
  218         default: sp = SVR4_B9600;       /* XXX */
  219         }
  220 
  221         while ((mask & 1) == 0) {
  222                 mask >>= 1;
  223                 sp <<= 1;
  224         }
  225 
  226         return sp;
  227 }
  228 
  229 
  230 static u_long
  231 svr4_32_to_bsd_speed(sp, mask)
  232         u_long sp;
  233         u_long mask;
  234 {
  235         while ((mask & 1) == 0) {
  236                 mask >>= 1;
  237                 sp >>= 1;
  238         }
  239 
  240         switch (sp & mask) {
  241 #undef getval
  242 #define getval(a,b)     case __CONCAT3(SVR4_,a,b):      return __CONCAT(a,b)
  243         getval(B,0);
  244         getval(B,50);
  245         getval(B,75);
  246         getval(B,110);
  247         getval(B,134);
  248         getval(B,150);
  249         getval(B,200);
  250         getval(B,300);
  251         getval(B,600);
  252         getval(B,1200);
  253         getval(B,1800);
  254         getval(B,2400);
  255         getval(B,4800);
  256         getval(B,9600);
  257         getval(B,19200);
  258         getval(B,38400);
  259         getval(B,57600);
  260         getval(B,115200);
  261         default: return B9600;  /* XXX */
  262         }
  263 }
  264 
  265 
  266 static void
  267 svr4_32_to_bsd_termios(st, bt, new)
  268         const struct svr4_32_termios    *st;
  269         struct termios                  *bt;
  270         int                              new;
  271 {
  272         /* control characters */
  273         /*
  274          * We process VMIN and VTIME first,
  275          * because they are shared with VEOF and VEOL
  276          */
  277         svr4_to_bsd_char(V,MIN);
  278         svr4_to_bsd_char(V,TIME);
  279 
  280         svr4_to_bsd_char(V,INTR);
  281         svr4_to_bsd_char(V,QUIT);
  282         svr4_to_bsd_char(V,ERASE);
  283         svr4_to_bsd_char(V,KILL);
  284         svr4_to_bsd_char(V,EOF);
  285         svr4_to_bsd_char(V,EOL);
  286         svr4_to_bsd_char(V,EOL2);
  287         undefined_char(V,SWTCH);
  288         svr4_to_bsd_char(V,START);
  289         svr4_to_bsd_char(V,STOP);
  290         svr4_to_bsd_char(V,SUSP);
  291         svr4_to_bsd_char(V,DSUSP);
  292         svr4_to_bsd_char(V,REPRINT);
  293         svr4_to_bsd_char(V,DISCARD);
  294         svr4_to_bsd_char(V,WERASE);
  295         svr4_to_bsd_char(V,LNEXT);
  296 
  297         /* Input modes */
  298         svr4_to_bsd_flag1(c_iflag,I,GNBRK);
  299         svr4_to_bsd_flag1(c_iflag,B,RKINT);
  300         svr4_to_bsd_flag1(c_iflag,I,GNPAR);
  301         svr4_to_bsd_flag1(c_iflag,P,ARMRK);
  302         svr4_to_bsd_flag1(c_iflag,I,NPCK);
  303         svr4_to_bsd_flag1(c_iflag,I,STRIP);
  304         svr4_to_bsd_flag1(c_iflag,I,NLCR);
  305         svr4_to_bsd_flag1(c_iflag,I,GNCR);
  306         svr4_to_bsd_flag1(c_iflag,I,CRNL);
  307         undefined_flag1(c_iflag,I,UCLC);
  308         svr4_to_bsd_flag1(c_iflag,I,XON);
  309         svr4_to_bsd_flag1(c_iflag,I,XANY);
  310         svr4_to_bsd_flag1(c_iflag,I,XOFF);
  311         svr4_to_bsd_flag1(c_iflag,I,MAXBEL);
  312         undefined_flag1(c_iflag,D,OSMODE);
  313 
  314         /* Output modes */
  315         svr4_to_bsd_flag1(c_oflag,O,POST);
  316         undefined_flag1(c_oflag,O,LCUC);
  317         svr4_to_bsd_flag1(c_oflag,O,NLCR);
  318         undefined_flag1(c_oflag,O,CRNL);
  319         undefined_flag1(c_oflag,O,NOCR);
  320         undefined_flag1(c_oflag,O,NLRET);
  321         undefined_flag1(c_oflag,O,FILL);
  322         undefined_flag1(c_oflag,O,FDEL);
  323         undefined_flag2(c_oflag,N,LDLY,N,L0,N,L1);
  324         undefined_flag4(c_oflag,C,RDLY,C,R0,C,R1,C,R2,C,R3);
  325         undefined_flag4(c_oflag,T,ABDLY,T,AB0,T,AB1,T,AB2,T,AB3);
  326         undefined_flag2(c_oflag,B,SDLY,B,S0,B,S1);
  327         undefined_flag2(c_oflag,V,TDLY,V,T0,V,T1);
  328         undefined_flag2(c_oflag,F,FDLY,F,F0,F,F1);
  329         undefined_flag1(c_oflag,P,AGEOUT);
  330         undefined_flag1(c_oflag,W,RAP);
  331 
  332         /* Control modes */
  333         bt->c_ospeed = svr4_32_to_bsd_speed(st->c_cflag, SVR4_CBAUD);
  334         svr4_to_bsd_flag4(c_cflag,C,SIZE,C,S5,C,S6,C,S7,C,S8)
  335         svr4_to_bsd_flag1(c_cflag,C,STOPB);
  336         svr4_to_bsd_flag1(c_cflag,C,READ);
  337         svr4_to_bsd_flag1(c_cflag,P,ARENB);
  338         svr4_to_bsd_flag1(c_cflag,P,ARODD);
  339         svr4_to_bsd_flag1(c_cflag,H,UPCL);
  340         svr4_to_bsd_flag1(c_cflag,C,LOCAL);
  341         undefined_flag1(c_cflag,R,CV1EN);
  342         undefined_flag1(c_cflag,X,MT1EN);
  343         undefined_flag1(c_cflag,L,OBLK);
  344         undefined_flag1(c_cflag,X,CLUDE);
  345         bt->c_ispeed = svr4_32_to_bsd_speed(st->c_cflag, SVR4_CIBAUD);
  346         undefined_flag1(c_cflag,P,AREXT);
  347 
  348         /* line discipline modes */
  349         svr4_to_bsd_flag1(c_lflag,I,SIG);
  350         svr4_to_bsd_flag1(c_lflag,I,CANON);
  351         undefined_flag1(c_lflag,X,CASE);
  352         svr4_to_bsd_flag1(c_lflag,E,CHO);
  353         svr4_to_bsd_flag1(c_lflag,E,CHOE);
  354         svr4_to_bsd_flag1(c_lflag,E,CHOK);
  355         svr4_to_bsd_flag1(c_lflag,E,CHONL);
  356         svr4_to_bsd_flag1(c_lflag,N,OFLSH);
  357         svr4_to_bsd_flag1(c_lflag,T,OSTOP);
  358         svr4_to_bsd_flag1(c_lflag,E,CHOCTL);
  359         svr4_to_bsd_flag1(c_lflag,E,CHOPRT);
  360         svr4_to_bsd_flag1(c_lflag,E,CHOKE);
  361         undefined_flag1(c_lflag,D,EFECHO);
  362         svr4_to_bsd_flag1(c_lflag,F,LUSHO);
  363         svr4_to_bsd_flag1(c_lflag,P,ENDIN);
  364         svr4_to_bsd_flag1(c_lflag,I,EXTEN);
  365 }
  366 
  367 
  368 static void
  369 bsd_to_svr4_32_termios(bt, st)
  370         const struct termios    *bt;
  371         struct svr4_32_termios  *st;
  372 {
  373         /* control characters */
  374         /*
  375          * We process VMIN and VTIME first,
  376          * because they are shared with VEOF and VEOL
  377          */
  378         bsd_to_svr4_char(V,MIN);
  379         bsd_to_svr4_char(V,TIME);
  380         bsd_to_svr4_char(V,INTR);
  381         bsd_to_svr4_char(V,QUIT);
  382         bsd_to_svr4_char(V,ERASE);
  383         bsd_to_svr4_char(V,KILL);
  384         bsd_to_svr4_char(V,EOF);
  385         bsd_to_svr4_char(V,EOL);
  386         bsd_to_svr4_char(V,EOL2);
  387         undefined_char(V,SWTCH);
  388         bsd_to_svr4_char(V,START);
  389         bsd_to_svr4_char(V,STOP);
  390         bsd_to_svr4_char(V,SUSP);
  391         bsd_to_svr4_char(V,DSUSP);
  392         bsd_to_svr4_char(V,REPRINT);
  393         bsd_to_svr4_char(V,DISCARD);
  394         bsd_to_svr4_char(V,WERASE);
  395         bsd_to_svr4_char(V,LNEXT);
  396 
  397         /* Input modes */
  398         bsd_to_svr4_flag1(c_iflag,I,GNBRK);
  399         bsd_to_svr4_flag1(c_iflag,B,RKINT);
  400         bsd_to_svr4_flag1(c_iflag,I,GNPAR);
  401         bsd_to_svr4_flag1(c_iflag,P,ARMRK);
  402         bsd_to_svr4_flag1(c_iflag,I,NPCK);
  403         bsd_to_svr4_flag1(c_iflag,I,STRIP);
  404         bsd_to_svr4_flag1(c_iflag,I,NLCR);
  405         bsd_to_svr4_flag1(c_iflag,I,GNCR);
  406         bsd_to_svr4_flag1(c_iflag,I,CRNL);
  407         undefined_flag1(c_iflag,I,UCLC);
  408         bsd_to_svr4_flag1(c_iflag,I,XON);
  409         bsd_to_svr4_flag1(c_iflag,I,XANY);
  410         bsd_to_svr4_flag1(c_iflag,I,XOFF);
  411         bsd_to_svr4_flag1(c_iflag,I,MAXBEL);
  412         undefined_flag1(c_iflag,D,OSMODE);
  413 
  414         /* Output modes */
  415         bsd_to_svr4_flag1(c_oflag,O,POST);
  416         undefined_flag1(c_oflag,O,LCUC);
  417         bsd_to_svr4_flag1(c_oflag,O,NLCR);
  418         undefined_flag1(c_oflag,O,CRNL);
  419         undefined_flag1(c_oflag,O,NOCR);
  420         undefined_flag1(c_oflag,O,NLRET);
  421         undefined_flag1(c_oflag,O,FILL);
  422         undefined_flag1(c_oflag,O,FDEL);
  423         undefined_flag2(c_oflag,N,LDLY,N,L0,N,L1);
  424         undefined_flag4(c_oflag,C,RDLY,C,R0,C,R1,C,R2,C,R3);
  425         undefined_flag4(c_oflag,T,ABDLY,T,AB0,T,AB1,T,AB2,T,AB3);
  426         undefined_flag2(c_oflag,B,SDLY,B,S0,B,S1);
  427         undefined_flag2(c_oflag,V,TDLY,V,T0,V,T1);
  428         undefined_flag2(c_oflag,F,FDLY,F,F0,F,F1);
  429         undefined_flag1(c_oflag,P,AGEOUT);
  430         undefined_flag1(c_oflag,W,RAP);
  431 
  432         /* Control modes */
  433         st->c_cflag &= ~SVR4_CBAUD;
  434         st->c_cflag |= bsd_to_svr4_32_speed(bt->c_ospeed, SVR4_CBAUD);
  435         bsd_to_svr4_flag4(c_cflag,C,SIZE,C,S5,C,S6,C,S7,C,S8)
  436         bsd_to_svr4_flag1(c_cflag,C,STOPB);
  437         bsd_to_svr4_flag1(c_cflag,C,READ);
  438         bsd_to_svr4_flag1(c_cflag,P,ARENB);
  439         bsd_to_svr4_flag1(c_cflag,P,ARODD);
  440         bsd_to_svr4_flag1(c_cflag,H,UPCL);
  441         bsd_to_svr4_flag1(c_cflag,C,LOCAL);
  442         undefined_flag1(c_cflag,R,CV1EN);
  443         undefined_flag1(c_cflag,X,MT1EN);
  444         undefined_flag1(c_cflag,L,OBLK);
  445         undefined_flag1(c_cflag,X,CLUDE);
  446         st->c_cflag &= ~SVR4_CIBAUD;
  447         st->c_cflag |= bsd_to_svr4_32_speed(bt->c_ispeed, SVR4_CIBAUD);
  448 
  449         undefined_flag1(c_oflag,P,AREXT);
  450 
  451         /* line discipline modes */
  452         bsd_to_svr4_flag1(c_lflag,I,SIG);
  453         bsd_to_svr4_flag1(c_lflag,I,CANON);
  454         undefined_flag1(c_lflag,X,CASE);
  455         bsd_to_svr4_flag1(c_lflag,E,CHO);
  456         bsd_to_svr4_flag1(c_lflag,E,CHOE);
  457         bsd_to_svr4_flag1(c_lflag,E,CHOK);
  458         bsd_to_svr4_flag1(c_lflag,E,CHONL);
  459         bsd_to_svr4_flag1(c_lflag,N,OFLSH);
  460         bsd_to_svr4_flag1(c_lflag,T,OSTOP);
  461         bsd_to_svr4_flag1(c_lflag,E,CHOCTL);
  462         bsd_to_svr4_flag1(c_lflag,E,CHOPRT);
  463         bsd_to_svr4_flag1(c_lflag,E,CHOKE);
  464         undefined_flag1(c_lflag,D,EFECHO);
  465         bsd_to_svr4_flag1(c_lflag,F,LUSHO);
  466         bsd_to_svr4_flag1(c_lflag,P,ENDIN);
  467         bsd_to_svr4_flag1(c_lflag,I,EXTEN);
  468 }
  469 
  470 
  471 static void
  472 svr4_termio_to_termios(t, ts)
  473         const struct svr4_termio        *t;
  474         struct svr4_32_termios          *ts;
  475 {
  476         int i;
  477 
  478         ts->c_iflag = (svr4_32_tcflag_t) t->c_iflag;
  479         ts->c_oflag = (svr4_32_tcflag_t) t->c_oflag;
  480         ts->c_cflag = (svr4_32_tcflag_t) t->c_cflag;
  481         ts->c_lflag = (svr4_32_tcflag_t) t->c_lflag;
  482 
  483         for (i = 0; i < SVR4_NCC; i++)
  484                 ts->c_cc[i] = (svr4_cc_t) t->c_cc[i];
  485 }
  486 
  487 
  488 static void
  489 svr4_32_termios_to_termio(ts, t)
  490         const struct svr4_32_termios    *ts;
  491         struct svr4_termio              *t;
  492 {
  493         int i;
  494 
  495         t->c_iflag = (u_short) ts->c_iflag;
  496         t->c_oflag = (u_short) ts->c_oflag;
  497         t->c_cflag = (u_short) ts->c_cflag;
  498         t->c_lflag = (u_short) ts->c_lflag;
  499         t->c_line = 0;  /* XXX */
  500 
  501         for (i = 0; i < SVR4_NCC; i++)
  502                 t->c_cc[i] = (u_char) ts->c_cc[i];
  503 }
  504 
  505 int
  506 svr4_32_term_ioctl(fp, l, retval, fd, cmd, data)
  507         struct file *fp;
  508         struct lwp *l;
  509         register_t *retval;
  510         int fd;
  511         u_long cmd;
  512         caddr_t data;
  513 {
  514         struct termios          bt;
  515         struct svr4_32_termios  st;
  516         struct svr4_termio      t;
  517         int                     error, new;
  518         int (*ctl)(struct file *, u_long, void *, struct lwp *) =
  519                         fp->f_ops->fo_ioctl;
  520 
  521         *retval = 0;
  522 
  523         switch (cmd) {
  524         case SVR4_TCGETA:
  525         case SVR4_TCGETS:
  526                 if ((error = (*ctl)(fp, TIOCGETA,  &bt, l)) != 0)
  527                         return error;
  528 
  529                 memset(&st, 0, sizeof(st));
  530                 bsd_to_svr4_32_termios(&bt, &st);
  531 
  532                 DPRINTF(("ioctl(TCGET%c);\n", cmd == SVR4_TCGETA ? 'A' : 'S'));
  533 #ifdef DEBUG_SVR4
  534                 print_bsd_termios(&bt);
  535                 print_svr4_32_termios(&st);
  536 #endif /* DEBUG_SVR4 */
  537 
  538                 if (cmd == SVR4_TCGETA) {
  539                     svr4_32_termios_to_termio(&st, &t);
  540                     return copyout(&t, data, sizeof(t));
  541                 }
  542                 else  {
  543                     return copyout(&st, data, sizeof(st));
  544                 }
  545 
  546         case SVR4_TCSETA:
  547         case SVR4_TCSETS:
  548         case SVR4_TCSETAW:
  549         case SVR4_TCSETSW:
  550         case SVR4_TCSETAF:
  551         case SVR4_TCSETSF:
  552                 /* get full BSD termios so we don't lose information */
  553                 if ((error = (*ctl)(fp, TIOCGETA,  &bt, l)) != 0)
  554                         return error;
  555 
  556                 switch (cmd) {
  557                 case SVR4_TCSETS:
  558                 case SVR4_TCSETSW:
  559                 case SVR4_TCSETSF:
  560                         if ((error = copyin(data, &st, sizeof(st))) != 0)
  561                                 return error;
  562                         new = 1;
  563                         break;
  564 
  565                 case SVR4_TCSETA:
  566                 case SVR4_TCSETAW:
  567                 case SVR4_TCSETAF:
  568                         if ((error = copyin(data, &t, sizeof(t))) != 0)
  569                                 return error;
  570 
  571                         svr4_termio_to_termios(&t, &st);
  572                         new = 0;
  573                         break;
  574 
  575                 default:
  576                         return EINVAL;
  577                 }
  578 
  579                 svr4_32_to_bsd_termios(&st, &bt, new);
  580 
  581                 switch (cmd) {
  582                 case SVR4_TCSETA:
  583                 case SVR4_TCSETS:
  584                         DPRINTF(("ioctl(TCSET[A|S]);\n"));
  585                         cmd = TIOCSETA;
  586                         break;
  587                 case SVR4_TCSETAW:
  588                 case SVR4_TCSETSW:
  589                         DPRINTF(("ioctl(TCSET[A|S]W);\n"));
  590                         cmd = TIOCSETAW;
  591                         break;
  592                 case SVR4_TCSETAF:
  593                 case SVR4_TCSETSF:
  594                         DPRINTF(("ioctl(TCSET[A|S]F);\n"));
  595                         cmd = TIOCSETAF;
  596                         break;
  597                 }
  598 
  599 #ifdef DEBUG_SVR4
  600                 print_bsd_termios(&bt);
  601                 print_svr4_32_termios(&st);
  602 #endif /* DEBUG_SVR4 */
  603 
  604                 return (*ctl)(fp, cmd,  &bt, l);
  605 
  606         case SVR4_TIOCGWINSZ:
  607                 {
  608                         struct svr4_winsize ws;
  609 
  610                         error = (*ctl)(fp, TIOCGWINSZ,  &ws, l);
  611                         if (error)
  612                                 return error;
  613                         return copyout(&ws, data, sizeof(ws));
  614                 }
  615 
  616         case SVR4_TIOCSWINSZ:
  617                 {
  618                         struct svr4_winsize ws;
  619 
  620                         if ((error = copyin(data, &ws, sizeof(ws))) != 0)
  621                                 return error;
  622                         return (*ctl)(fp, TIOCSWINSZ,  &ws, l);
  623                 }
  624 
  625         default:
  626                 return svr4_32_stream_ti_ioctl(fp, l, retval, fd, cmd, data);
  627         }
  628 }

Cache object: 26117a612e529a37a1ca9f3da25e149d


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.