Deleted Added
sdiff udiff text old ( 171185 ) new ( 173456 )
full compact
1/*-
2 * Copyright (c) 1982, 1986, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 16 unchanged lines hidden (view full) ---

25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * @(#)tty_pty.c 8.4 (Berkeley) 2/20/95
30 */
31
32#include <sys/cdefs.h>
33__FBSDID("$FreeBSD: head/sys/kern/tty_pty.c 173456 2007-11-08 15:51:52Z jhb $");
34
35/*
36 * Pseudo-teletype Driver
37 * (Actually two drivers, requiring two entries in 'cdevsw')
38 */
39#include "opt_compat.h"
40#include "opt_tty.h"
41#include <sys/param.h>
42#include <sys/systm.h>
43#include <sys/libkern.h>
44#include <sys/lock.h>
45#include <sys/mutex.h>
46#include <sys/sx.h>
47#if defined(COMPAT_43TTY)
48#include <sys/ioctl_compat.h>
49#endif
50#include <sys/priv.h>
51#include <sys/proc.h>

--- 71 unchanged lines hidden (view full) ---

123#define TSA_PTS_READ(tp) ((void *)&(tp)->t_canq)
124
125static char *names = "pqrsPQRS";
126/*
127 * This function creates and initializes a pts/ptc pair
128 *
129 * pts == /dev/tty[pqrsPQRS][0123456789abcdefghijklmnopqrstuv]
130 * ptc == /dev/pty[pqrsPQRS][0123456789abcdefghijklmnopqrstuv]
131 */
132static struct cdev *
133ptyinit(struct cdev *devc, struct thread *td)
134{
135 struct ptsc *pt;
136 int n;
137
138 n = minor2unit(minor(devc));
139
140 /* We only allow for up to 32 ptys per char in "names". */
141 if (n >= 32 * strlen(names))
142 return (NULL);
143
144 devc->si_flags &= ~SI_CHEAPCLONE;
145
146 /*
147 * Initially do not create a slave endpoint.
148 */
149 pt = malloc(sizeof(*pt), M_PTY, M_WAITOK | M_ZERO);

--- 604 unchanged lines hidden (view full) ---

754 }
755 return (error);
756}
757
758static void
759pty_clone(void *arg, struct ucred *cr, char *name, int namelen,
760 struct cdev **dev)
761{
762 char *cp;
763 int u;
764
765 if (*dev != NULL)
766 return;
767 if (bcmp(name, "pty", 3) != 0)
768 return;
769 if (name[5] != '\0' || name[3] == '\0')
770 return;
771 cp = index(names, name[3]);
772 if (cp == NULL)
773 return;
774 u = (cp - names) * 32;
775 if (name[4] >= '0' && name[4] <= '9')
776 u += name[4] - '0';
777 else if (name[4] >= 'a' && name[4] <= 'v')
778 u += name[4] - 'a' + 10;
779 else
780 return;
781 *dev = make_dev_credf(MAKEDEV_REF, &ptc_cdevsw, unit2minor(u), cr,
782 UID_ROOT, GID_WHEEL, 0666, "pty%c%r", names[u / 32], u % 32);
783 (*dev)->si_flags |= SI_CHEAPCLONE;
784 return;
785}
786
787static void
788ptc_drvinit(void *unused)
789{
790
791 EVENTHANDLER_REGISTER(dev_clone, pty_clone, 0, 1000);
792}
793
794SYSINIT(ptcdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE,ptc_drvinit,NULL)