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/kern/tty_bsdpty.c

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: tty_bsdpty.c,v 1.3.2.1 2006/04/04 22:14:44 tron Exp $  */
    2 
    3 /*-
    4  * Copyright (c) 2004 The NetBSD Foundation, Inc.
    5  * All rights reserved.
    6  *
    7  * Redistribution and use in source and binary forms, with or without
    8  * modification, are permitted provided that the following conditions
    9  * are met:
   10  * 1. Redistributions of source code must retain the above copyright
   11  *    notice, this list of conditions and the following disclaimer.
   12  * 2. Redistributions in binary form must reproduce the above copyright
   13  *    notice, this list of conditions and the following disclaimer in the
   14  *    documentation and/or other materials provided with the distribution.
   15  * 3. All advertising materials mentioning features or use of this software
   16  *    must display the following acknowledgement:
   17  *        This product includes software developed by the NetBSD
   18  *        Foundation, Inc. and its contributors.
   19  * 4. Neither the name of The NetBSD Foundation nor the names of its
   20  *    contributors may be used to endorse or promote products derived
   21  *    from this software without specific prior written permission.
   22  *
   23  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
   24  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   25  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   26  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
   27  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   33  * POSSIBILITY OF SUCH DAMAGE.
   34  */
   35 
   36 #include <sys/cdefs.h>
   37 __KERNEL_RCSID(0, "$NetBSD: tty_bsdpty.c,v 1.3.2.1 2006/04/04 22:14:44 tron Exp $");
   38 
   39 #include "opt_ptm.h"
   40 
   41 #ifdef COMPAT_BSDPTY
   42 /* bsd tty implementation for pty multiplexor driver /dev/ptm{,x} */
   43 
   44 #include <sys/param.h>
   45 #include <sys/systm.h>
   46 #include <sys/ioctl.h>
   47 #include <sys/proc.h>
   48 #include <sys/tty.h>
   49 #include <sys/stat.h>
   50 #include <sys/file.h>
   51 #include <sys/uio.h>
   52 #include <sys/kernel.h>
   53 #include <sys/vnode.h>
   54 #include <sys/namei.h>
   55 #include <sys/signalvar.h>
   56 #include <sys/uio.h>
   57 #include <sys/filedesc.h>
   58 #include <sys/conf.h>
   59 #include <sys/poll.h>
   60 #include <sys/malloc.h>
   61 #include <sys/pty.h>
   62 
   63 /*
   64  * pts == /dev/tty[pqrs]?
   65  * ptc == /dev/pty[pqrs]?
   66  */
   67 
   68 /*
   69  * All this hard-coding is really evil.
   70  */
   71 #define TTY_GID         4
   72 #define TTY_PERM        (S_IRUSR|S_IWUSR|S_IWGRP)
   73 #define TTY_TEMPLATE    "/dev/XtyXX"
   74 #define TTY_NAMESIZE    sizeof(TTY_TEMPLATE)
   75 #define TTY_LETTERS     "pqrstuvwxyzPQRST"
   76 #define TTY_OLD_SUFFIX  "0123456789abcdef"
   77 #define TTY_NEW_SUFFIX  "ghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
   78 
   79 static int pty_makename(struct ptm_pty *, char *, size_t, dev_t, char);
   80 static int pty_allocvp(struct ptm_pty *, struct proc *, struct vnode **,
   81     dev_t, char);
   82 static void pty_getvattr(struct ptm_pty *, struct proc *, struct vattr *);
   83 
   84 struct ptm_pty ptm_bsdpty = {
   85         pty_allocvp,
   86         pty_makename,
   87         pty_getvattr,
   88         NULL
   89 };
   90 
   91 static int
   92 /*ARGSUSED*/
   93 pty_makename(struct ptm_pty *ptm, char *bf, size_t bufsiz, dev_t dev, char c)
   94 {
   95         size_t nt;
   96         dev_t minor = minor(dev);
   97         const char *suffix;
   98 
   99         if (bufsiz < TTY_NAMESIZE)
  100                 return EINVAL;
  101 
  102         (void)memcpy(bf, TTY_TEMPLATE, TTY_NAMESIZE);
  103 
  104         if (minor < 256) {
  105                 suffix = TTY_OLD_SUFFIX;
  106                 nt = sizeof(TTY_OLD_SUFFIX) - 1;
  107         } else {
  108                 minor -= 256;
  109                 suffix = TTY_NEW_SUFFIX;
  110                 nt = sizeof(TTY_NEW_SUFFIX) - 1;
  111         }
  112 
  113         bf[5] = c;
  114         bf[8] = TTY_LETTERS[minor / nt];
  115         bf[9] = suffix[minor % nt];
  116         return 0;
  117 }
  118 
  119 
  120 static int
  121 /*ARGSUSED*/
  122 pty_allocvp(struct ptm_pty *ptm, struct proc *p, struct vnode **vp, dev_t dev,
  123     char ms)
  124 {
  125         int error;
  126         struct nameidata nd;
  127         char name[TTY_NAMESIZE];
  128 
  129         error = (*ptm->makename)(ptm, name, sizeof(name), dev, ms);
  130         if (error)
  131                 return error;
  132 
  133         NDINIT(&nd, LOOKUP, NOFOLLOW|LOCKLEAF, UIO_SYSSPACE, name, p);
  134         if ((error = namei(&nd)) != 0)
  135                 return error;
  136         *vp = nd.ni_vp;
  137         return 0;
  138 }
  139 
  140 
  141 static void
  142 /*ARGSUSED*/
  143 pty_getvattr(struct ptm_pty *ptm, struct proc *p, struct vattr *vattr)
  144 {
  145         VATTR_NULL(vattr);
  146         /* get real uid */
  147         vattr->va_uid = p->p_cred->p_ruid;
  148         vattr->va_gid = TTY_GID;
  149         vattr->va_mode = TTY_PERM;
  150 }
  151 #endif

Cache object: 04c15f84cd8482df722d8fd13223a00c


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