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_ioctl.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 
   29 #include <sys/cdefs.h>
   30 __FBSDID("$FreeBSD: releng/8.1/sys/compat/svr4/svr4_ioctl.c 193014 2009-05-29 05:58:46Z delphij $");
   31 
   32 #include <sys/param.h>
   33 #include <sys/proc.h>
   34 #include <sys/file.h>
   35 #include <sys/filedesc.h>
   36 #include <sys/fcntl.h>
   37 #include <sys/socket.h>
   38 #include <sys/socketvar.h>
   39 #include <sys/systm.h>
   40 
   41 #include <compat/svr4/svr4.h>
   42 #include <compat/svr4/svr4_types.h>
   43 #include <compat/svr4/svr4_util.h>
   44 #include <compat/svr4/svr4_signal.h>
   45 #include <compat/svr4/svr4_proto.h>
   46 #include <compat/svr4/svr4_stropts.h>
   47 #include <compat/svr4/svr4_ioctl.h>
   48 #include <compat/svr4/svr4_termios.h>
   49 #include <compat/svr4/svr4_filio.h>
   50 #include <compat/svr4/svr4_sockio.h>
   51 
   52 #ifdef DEBUG_SVR4
   53 static void svr4_decode_cmd(u_long, char *, char *, int *, int *);
   54 /*
   55  * Decode an ioctl command symbolically
   56  */
   57 static void
   58 svr4_decode_cmd(cmd, dir, c, num, argsiz)
   59         u_long            cmd;
   60         char             *dir, *c;
   61         int              *num, *argsiz;
   62 {
   63         if (cmd & SVR4_IOC_VOID)
   64                 *dir++ = 'V';
   65         if (cmd & SVR4_IOC_IN)
   66                 *dir++ = 'R';
   67         if (cmd & SVR4_IOC_OUT)
   68                 *dir++ = 'W';
   69         *dir = '\0';
   70         if (cmd & SVR4_IOC_INOUT)
   71                 *argsiz = (cmd >> 16) & 0xff;
   72         else
   73                 *argsiz = -1;
   74 
   75         *c = (cmd >> 8) & 0xff;
   76         *num = cmd & 0xff;
   77 }
   78 #endif
   79 
   80 int
   81 svr4_sys_ioctl(td, uap)
   82         struct thread *td;
   83         struct svr4_sys_ioctl_args *uap;
   84 {
   85         int             *retval;
   86         struct file     *fp;
   87         u_long           cmd;
   88         int (*fun)(struct file *, struct thread *, register_t *,
   89                         int, u_long, caddr_t);
   90         int error;
   91 #ifdef DEBUG_SVR4
   92         char             dir[4];
   93         char             c;
   94         int              num;
   95         int              argsiz;
   96 
   97         svr4_decode_cmd(uap->com, dir, &c, &num, &argsiz);
   98 
   99         DPRINTF(("svr4_ioctl[%lx](%d, _IO%s(%c, %d, %d), %p);\n", uap->com, uap->fd,
  100             dir, c, num, argsiz, uap->data));
  101 #endif
  102         retval = td->td_retval;
  103         cmd = uap->com;
  104 
  105         if ((error = fget(td, uap->fd, &fp)) != 0)
  106                 return (error);
  107 
  108         if ((fp->f_flag & (FREAD | FWRITE)) == 0) {
  109                 fdrop(fp, td);
  110                 return EBADF;
  111         }
  112 
  113 #if defined(DEBUG_SVR4)
  114         if (fp->f_type == DTYPE_SOCKET) {
  115                 struct socket *so = fp->f_data;
  116                 DPRINTF(("<<< IN: so_state = 0x%x\n", so->so_state));
  117         }
  118 #endif
  119 
  120         switch (cmd & 0xff00) {
  121         case SVR4_TIOC:
  122                 DPRINTF(("term\n"));
  123                 fun = svr4_term_ioctl;
  124                 break;
  125 
  126         case SVR4_STR:
  127                 DPRINTF(("stream\n"));
  128                 fun = svr4_stream_ioctl;
  129                 break;
  130 
  131         case SVR4_FIOC:
  132                 DPRINTF(("file\n"));
  133                 fun = svr4_fil_ioctl;
  134                 break;
  135 
  136         case SVR4_SIOC:
  137                 DPRINTF(("socket\n"));
  138                 fun = svr4_sock_ioctl;
  139                 break;
  140 
  141         case SVR4_XIOC:
  142                 /* We do not support those */
  143                 fdrop(fp, td);
  144                 return EINVAL;
  145 
  146         default:
  147                 fdrop(fp, td);
  148                 DPRINTF(("Unimplemented ioctl %lx\n", cmd));
  149                 return 0;       /* XXX: really ENOSYS */
  150         }
  151 #if defined(DEBUG_SVR4)
  152         if (fp->f_type == DTYPE_SOCKET) {
  153                 struct socket *so;
  154 
  155                 so = fp->f_data;
  156                 DPRINTF((">>> OUT: so_state = 0x%x\n", so->so_state));
  157         }
  158 #endif
  159         error = (*fun)(fp, td, retval, uap->fd, cmd, uap->data);
  160         fdrop(fp, td);
  161         return (error);
  162 }

Cache object: 75cd61551b16a24243fca83af6f2045c


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