pty.c (171185) | pty.c (173456) |
---|---|
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> | 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 171185 2007-07-03 17:45:52Z kib $"); | 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> | 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> |
|
43#include <sys/lock.h> 44#include <sys/mutex.h> 45#include <sys/sx.h> 46#if defined(COMPAT_43TTY) 47#include <sys/ioctl_compat.h> 48#endif 49#include <sys/priv.h> 50#include <sys/proc.h> --- 71 unchanged lines hidden (view full) --- 122#define TSA_PTS_READ(tp) ((void *)&(tp)->t_canq) 123 124static char *names = "pqrsPQRS"; 125/* 126 * This function creates and initializes a pts/ptc pair 127 * 128 * pts == /dev/tty[pqrsPQRS][0123456789abcdefghijklmnopqrstuv] 129 * ptc == /dev/pty[pqrsPQRS][0123456789abcdefghijklmnopqrstuv] | 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] |
130 * 131 * XXX: define and add mapping of upper minor bits to allow more 132 * than 256 ptys. | |
133 */ 134static struct cdev * 135ptyinit(struct cdev *devc, struct thread *td) 136{ 137 struct ptsc *pt; 138 int n; 139 | 131 */ 132static struct cdev * 133ptyinit(struct cdev *devc, struct thread *td) 134{ 135 struct ptsc *pt; 136 int n; 137 |
140 n = minor(devc); 141 /* For now we only map the lower 8 bits of the minor */ 142 if (n & ~0xff) | 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)) |
143 return (NULL); 144 145 devc->si_flags &= ~SI_CHEAPCLONE; 146 147 /* 148 * Initially do not create a slave endpoint. 149 */ 150 pt = malloc(sizeof(*pt), M_PTY, M_WAITOK | M_ZERO); --- 604 unchanged lines hidden (view full) --- 755 } 756 return (error); 757} 758 759static void 760pty_clone(void *arg, struct ucred *cr, char *name, int namelen, 761 struct cdev **dev) 762{ | 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; | 763 int u; 764 765 if (*dev != NULL) 766 return; 767 if (bcmp(name, "pty", 3) != 0) 768 return; |
769 if (name[5] != '\0') | 769 if (name[5] != '\0' || name[3] == '\0') |
770 return; | 770 return; |
771 switch (name[3]) { 772 case 'p': u = 0; break; 773 case 'q': u = 32; break; 774 case 'r': u = 64; break; 775 case 's': u = 96; break; 776 case 'P': u = 128; break; 777 case 'Q': u = 160; break; 778 case 'R': u = 192; break; 779 case 'S': u = 224; break; 780 default: return; 781 } | 771 cp = index(names, name[3]); 772 if (cp == NULL) 773 return; 774 u = (cp - names) * 32; |
782 if (name[4] >= '0' && name[4] <= '9') 783 u += name[4] - '0'; 784 else if (name[4] >= 'a' && name[4] <= 'v') 785 u += name[4] - 'a' + 10; 786 else 787 return; | 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; |
788 *dev = make_dev_credf(MAKEDEV_REF, &ptc_cdevsw, u, cr, | 781 *dev = make_dev_credf(MAKEDEV_REF, &ptc_cdevsw, unit2minor(u), cr, |
789 UID_ROOT, GID_WHEEL, 0666, "pty%c%r", names[u / 32], u % 32); 790 (*dev)->si_flags |= SI_CHEAPCLONE; 791 return; 792} 793 794static void 795ptc_drvinit(void *unused) 796{ 797 798 EVENTHANDLER_REGISTER(dev_clone, pty_clone, 0, 1000); 799} 800 801SYSINIT(ptcdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE,ptc_drvinit,NULL) | 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) |