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/svr4_ttold.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 /*
    2  * Copyright (c) 1998 Mark Newton
    3  * Copyright (c) 1994 Christos Zoulas
    4  * All rights reserved.
    5  *
    6  * Redistribution and use in source and binary forms, with or without
    7  * modification, are permitted provided that the following conditions
    8  * are met:
    9  * 1. Redistributions of source code must retain the above copyright
   10  *    notice, this list of conditions and the following disclaimer.
   11  * 2. Redistributions in binary form must reproduce the above copyright
   12  *    notice, this list of conditions and the following disclaimer in the
   13  *    documentation and/or other materials provided with the distribution.
   14  * 3. The name of the author may not be used to endorse or promote products
   15  *    derived from this software without specific prior written permission
   16  *
   17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   27  * 
   28  * $FreeBSD: releng/5.0/sys/compat/svr4/svr4_ttold.c 102003 2002-08-17 02:36:16Z rwatson $
   29  */
   30 
   31 #include <sys/param.h>
   32 #include <sys/proc.h>
   33 #include <sys/systm.h>
   34 #include <sys/file.h>
   35 #include <sys/filedesc.h>
   36 #include <sys/ioctl_compat.h>
   37 #include <sys/termios.h>
   38 
   39 #include <compat/svr4/svr4.h>
   40 #include <compat/svr4/svr4_util.h>
   41 #include <compat/svr4/svr4_ttold.h>
   42 #include <compat/svr4/svr4_ioctl.h>
   43 
   44 
   45 static void svr4_tchars_to_bsd_tchars(const struct svr4_tchars *st,
   46                                            struct tchars *bt);
   47 static void bsd_tchars_to_svr4_tchars(const struct tchars *bt,
   48                                            struct svr4_tchars *st);
   49 static void svr4_sgttyb_to_bsd_sgttyb(const struct svr4_sgttyb *ss,
   50                                            struct sgttyb *bs);
   51 static void bsd_sgttyb_to_svr4_sgttyb(const struct sgttyb *bs,
   52                                            struct svr4_sgttyb *ss);
   53 static void svr4_ltchars_to_bsd_ltchars(const struct svr4_ltchars *sl,
   54                                              struct ltchars *bl);
   55 static void bsd_ltchars_to_svr4_ltchars(const struct ltchars *bl,
   56                                              struct svr4_ltchars *sl);
   57 
   58 #ifdef DEBUG_SVR4
   59 static void print_svr4_sgttyb(const char *, struct svr4_sgttyb *);
   60 static void print_svr4_tchars(const char *, struct svr4_tchars *);
   61 static void print_svr4_ltchars(const char *, struct svr4_ltchars *);
   62 
   63 static void
   64 print_svr4_sgttyb(str, ss)
   65         const char *str;
   66         struct svr4_sgttyb *ss;
   67 {
   68 
   69         uprintf("%s\nispeed=%o ospeed=%o ", str, ss->sg_ispeed, ss->sg_ospeed);
   70         uprintf("erase=%o kill=%o flags=%o\n", ss->sg_erase, ss->sg_kill,
   71             ss->sg_flags);
   72 }
   73 
   74 static void
   75 print_svr4_tchars(str, st)
   76         const char *str;
   77         struct svr4_tchars *st;
   78 {
   79         uprintf("%s\nintrc=%o quitc=%o ", str, st->t_intrc, st->t_quitc);
   80         uprintf("startc=%o stopc=%o eofc=%o brkc=%o\n", st->t_startc,
   81             st->t_stopc, st->t_eofc, st->t_brkc);
   82 }
   83 
   84 static void
   85 print_svr4_ltchars(str, sl)
   86         const char *str;
   87         struct svr4_ltchars *sl;
   88 {
   89         uprintf("%s\nsuspc=%o dsuspc=%o ", str, sl->t_suspc, sl->t_dsuspc);
   90         uprintf("rprntc=%o flushc=%o werasc=%o lnextc=%o\n", sl->t_rprntc,
   91             sl->t_flushc, sl->t_werasc, sl->t_lnextc);
   92 }
   93 #endif /* DEBUG_SVR4 */
   94 
   95 static void
   96 svr4_tchars_to_bsd_tchars(st, bt)
   97         const struct svr4_tchars        *st;
   98         struct tchars                   *bt;
   99 {
  100         bt->t_intrc  = st->t_intrc;
  101         bt->t_quitc  = st->t_quitc;
  102         bt->t_startc = st->t_startc;
  103         bt->t_stopc  = st->t_stopc;
  104         bt->t_eofc   = st->t_eofc;
  105         bt->t_brkc   = st->t_brkc;
  106 }
  107 
  108 
  109 static void
  110 bsd_tchars_to_svr4_tchars(bt, st)
  111         const struct tchars     *bt;
  112         struct svr4_tchars      *st;
  113 {
  114         st->t_intrc  = bt->t_intrc;
  115         st->t_quitc  = bt->t_quitc;
  116         st->t_startc = bt->t_startc;
  117         st->t_stopc  = bt->t_stopc;
  118         st->t_eofc   = bt->t_eofc;
  119         st->t_brkc   = bt->t_brkc;
  120 }
  121 
  122 
  123 static void
  124 svr4_sgttyb_to_bsd_sgttyb(ss, bs)
  125         const struct svr4_sgttyb        *ss;
  126         struct sgttyb                   *bs;
  127 {
  128         bs->sg_ispeed = ss->sg_ispeed;
  129         bs->sg_ospeed = ss->sg_ospeed;
  130         bs->sg_erase  = ss->sg_erase;   
  131         bs->sg_kill   = ss->sg_kill;
  132         bs->sg_flags  = ss->sg_flags;
  133 };
  134 
  135 
  136 static void
  137 bsd_sgttyb_to_svr4_sgttyb(bs, ss)
  138         const struct sgttyb     *bs;
  139         struct svr4_sgttyb      *ss;
  140 {
  141         ss->sg_ispeed = bs->sg_ispeed;
  142         ss->sg_ospeed = bs->sg_ospeed;
  143         ss->sg_erase  = bs->sg_erase;   
  144         ss->sg_kill   = bs->sg_kill;
  145         ss->sg_flags  = bs->sg_flags;
  146 }
  147 
  148 
  149 static void
  150 svr4_ltchars_to_bsd_ltchars(sl, bl)
  151         const struct svr4_ltchars       *sl;
  152         struct ltchars                  *bl;
  153 {
  154         bl->t_suspc  = sl->t_suspc;
  155         bl->t_dsuspc = sl->t_dsuspc;
  156         bl->t_rprntc = sl->t_rprntc;
  157         bl->t_flushc = sl->t_flushc;
  158         bl->t_werasc = sl->t_werasc;
  159         bl->t_lnextc = sl->t_lnextc;
  160 }
  161 
  162 
  163 static void
  164 bsd_ltchars_to_svr4_ltchars(bl, sl)
  165         const struct ltchars    *bl;
  166         struct svr4_ltchars     *sl;
  167 {
  168         sl->t_suspc  = bl->t_suspc;
  169         sl->t_dsuspc = bl->t_dsuspc;
  170         sl->t_rprntc = bl->t_rprntc;
  171         sl->t_flushc = bl->t_flushc;
  172         sl->t_werasc = bl->t_werasc;
  173         sl->t_lnextc = bl->t_lnextc;
  174 }
  175 
  176 
  177 int
  178 svr4_ttold_ioctl(fp, td, retval, fd, cmd, data)
  179         struct file *fp;
  180         struct thread *td;
  181         register_t *retval;
  182         int fd;
  183         u_long cmd;
  184         caddr_t data;
  185 {
  186         int                     error;
  187 
  188         *retval = 0;
  189 
  190         switch (cmd) {
  191         case SVR4_TIOCGPGRP:
  192                 {
  193                         pid_t pid;
  194 
  195                         if ((error = fo_ioctl(fp, TIOCGPGRP, (caddr_t) &pid,
  196                             td->td_ucred, td)) != 0)
  197                                 return error;
  198 
  199                         DPRINTF(("TIOCGPGRP %d\n", pid));
  200 
  201                         if ((error = copyout(&pid, data, sizeof(pid))) != 0)
  202                                 return error;
  203 
  204                 }
  205 
  206         case SVR4_TIOCSPGRP:
  207                 {
  208                         pid_t pid;
  209 
  210                         if ((error = copyin(data, &pid, sizeof(pid))) != 0)
  211                                 return error;
  212 
  213                         DPRINTF(("TIOCSPGRP %d\n", pid));
  214 
  215                         return fo_ioctl(fp, TIOCSPGRP, (caddr_t) &pid,
  216                             td->td_ucred, td);
  217                 }
  218 
  219         case SVR4_TIOCGSID:
  220                 {
  221 #if defined(TIOCGSID)
  222                         pid_t pid;
  223                         if ((error = fo_ioctl(fp, TIOCGSID, (caddr_t) &pid,
  224                             td->td_ucred, td)) != 0)
  225                                 return error;
  226 
  227                         DPRINTF(("TIOCGSID %d\n", pid));
  228 
  229                         return copyout(&pid, data, sizeof(pid));
  230 #else
  231                         uprintf("ioctl(TIOCGSID) for pid %d unsupported\n", td->td_proc->p_pid);
  232                         return EINVAL;
  233 #endif
  234                 }
  235 
  236         case SVR4_TIOCGETP:
  237                 {
  238                         struct sgttyb bs;
  239                         struct svr4_sgttyb ss;
  240 
  241                         error = fo_ioctl(fp, TIOCGETP, (caddr_t) &bs,
  242                             td->td_ucred, td);
  243                         if (error)
  244                                 return error;
  245 
  246                         bsd_sgttyb_to_svr4_sgttyb(&bs, &ss);
  247 #ifdef DEBUG_SVR4
  248                         print_svr4_sgttyb("SVR4_TIOCGETP", &ss);
  249 #endif /* DEBUG_SVR4 */
  250                         return copyout(&ss, data, sizeof(ss));
  251                 }
  252 
  253         case SVR4_TIOCSETP:
  254         case SVR4_TIOCSETN:
  255                 {
  256                         struct sgttyb bs;
  257                         struct svr4_sgttyb ss;
  258 
  259                         if ((error = copyin(data, &ss, sizeof(ss))) != 0)
  260                                 return error;
  261 
  262                         svr4_sgttyb_to_bsd_sgttyb(&ss, &bs);
  263 #ifdef DEBUG_SVR4
  264                         print_svr4_sgttyb("SVR4_TIOCSET{P,N}", &ss);
  265 #endif /* DEBUG_SVR4 */
  266                         cmd = (cmd == SVR4_TIOCSETP) ? TIOCSETP : TIOCSETN;
  267                         return fo_ioctl(fp, cmd, (caddr_t) &bs,
  268                             td->td_ucred, td);
  269                 }
  270 
  271         case SVR4_TIOCGETC:
  272                 {
  273                         struct tchars bt;
  274                         struct svr4_tchars st;
  275 
  276                         error = fo_ioctl(fp, TIOCGETC, (caddr_t) &bt,
  277                             td->td_ucred, td);
  278                         if (error)
  279                                 return error;
  280 
  281                         bsd_tchars_to_svr4_tchars(&bt, &st);
  282 #ifdef DEBUG_SVR4
  283                         print_svr4_tchars("SVR4_TIOCGETC", &st);
  284 #endif /* DEBUG_SVR4 */
  285                         return copyout(&st, data, sizeof(st));
  286                 }
  287 
  288         case SVR4_TIOCSETC:
  289                 {
  290                         struct tchars bt;
  291                         struct svr4_tchars st;
  292 
  293                         if ((error = copyin(data, &st, sizeof(st))) != 0)
  294                                 return error;
  295 
  296                         svr4_tchars_to_bsd_tchars(&st, &bt);
  297 #ifdef DEBUG_SVR4
  298                         print_svr4_tchars("SVR4_TIOCSETC", &st);
  299 #endif /* DEBUG_SVR4 */
  300                         return fo_ioctl(fp, TIOCSETC, (caddr_t) &bt,
  301                             td->td_ucred, td);
  302                 }
  303 
  304         case SVR4_TIOCGLTC:
  305                 {
  306                         struct ltchars bl;
  307                         struct svr4_ltchars sl;
  308 
  309                         error = fo_ioctl(fp, TIOCGLTC, (caddr_t) &bl,
  310                             td->td_ucred, td);
  311                         if (error)
  312                                 return error;
  313 
  314                         bsd_ltchars_to_svr4_ltchars(&bl, &sl);
  315 #ifdef DEBUG_SVR4
  316                         print_svr4_ltchars("SVR4_TIOCGLTC", &sl);
  317 #endif /* DEBUG_SVR4 */
  318                         return copyout(&sl, data, sizeof(sl));
  319                 }
  320 
  321         case SVR4_TIOCSLTC:
  322                 {
  323                         struct ltchars bl;
  324                         struct svr4_ltchars sl;
  325 
  326                         if ((error = copyin(data, &sl, sizeof(sl))) != 0)
  327                                 return error;
  328 
  329                         svr4_ltchars_to_bsd_ltchars(&sl, &bl);
  330 #ifdef DEBUG_SVR4
  331                         print_svr4_ltchars("SVR4_TIOCSLTC", &sl);
  332 #endif /* DEBUG_SVR4 */
  333                         return fo_ioctl(fp, TIOCSLTC, (caddr_t) &bl,
  334                             td->td_ucred, td);
  335                 }
  336 
  337         case SVR4_TIOCLGET:
  338                 {
  339                         int flags;
  340                         if ((error = fo_ioctl(fp, TIOCLGET, (caddr_t) &flags,
  341                             td->td_ucred, td)) != 0)
  342                                 return error;
  343                         DPRINTF(("SVR4_TIOCLGET %o\n", flags));
  344                         return copyout(&flags, data, sizeof(flags));
  345                 }
  346 
  347         case SVR4_TIOCLSET:
  348         case SVR4_TIOCLBIS:
  349         case SVR4_TIOCLBIC:
  350                 {
  351                         int flags;
  352 
  353                         if ((error = copyin(data, &flags, sizeof(flags))) != 0)
  354                                 return error;
  355 
  356                         switch (cmd) {
  357                         case SVR4_TIOCLSET:
  358                                 cmd = TIOCLSET;
  359                                 break;
  360                         case SVR4_TIOCLBIS:
  361                                 cmd = TIOCLBIS;
  362                                 break;
  363                         case SVR4_TIOCLBIC:
  364                                 cmd = TIOCLBIC;
  365                                 break;
  366                         }
  367 
  368                         DPRINTF(("SVR4_TIOCL{SET,BIS,BIC} %o\n", flags));
  369                         return fo_ioctl(fp, cmd, (caddr_t) &flags,
  370                             td->td_ucred, td);
  371                 }
  372 
  373         default:
  374                 DPRINTF(("Unknown svr4 ttold %lx\n", cmd));
  375                 return 0;       /* ENOSYS really */
  376         }
  377 }

Cache object: 5521c67463a2ffdd34f23f5031bcd2aa


[ 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.