pty.c (49992) | pty.c (50092) |
---|---|
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 --- 17 unchanged lines hidden (view full) --- 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)tty_pty.c 8.4 (Berkeley) 2/20/95 | 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 --- 17 unchanged lines hidden (view full) --- 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)tty_pty.c 8.4 (Berkeley) 2/20/95 |
34 * $Id: tty_pty.c,v 1.63 1999/08/08 19:47:32 phk Exp $ | 34 * $Id: tty_pty.c,v 1.64 1999/08/17 23:08:51 julian Exp $ |
35 */ 36 37/* 38 * Pseudo-teletype Driver 39 * (Actually two drivers, requiring two entries in 'cdevsw') 40 */ 41#include "pty.h" /* XXX */ 42#include "opt_compat.h" --- 9 unchanged lines hidden (view full) --- 52#include <sys/conf.h> 53#include <sys/fcntl.h> 54#include <sys/poll.h> 55#include <sys/kernel.h> 56#include <sys/vnode.h> 57#include <sys/signalvar.h> 58#include <sys/malloc.h> 59 | 35 */ 36 37/* 38 * Pseudo-teletype Driver 39 * (Actually two drivers, requiring two entries in 'cdevsw') 40 */ 41#include "pty.h" /* XXX */ 42#include "opt_compat.h" --- 9 unchanged lines hidden (view full) --- 52#include <sys/conf.h> 53#include <sys/fcntl.h> 54#include <sys/poll.h> 55#include <sys/kernel.h> 56#include <sys/vnode.h> 57#include <sys/signalvar.h> 58#include <sys/malloc.h> 59 |
60#ifdef DEVFS 61#include <sys/devfsext.h> 62#endif /*DEVFS*/ 63 | |
64MALLOC_DEFINE(M_PTY, "ptys", "pty data structures"); 65 66static void ptsstart __P((struct tty *tp)); 67static void ptcwakeup __P((struct tty *tp, int flag)); 68static void ptyinit __P((int n)); 69 70static d_open_t ptsopen; 71static d_close_t ptsclose; --- 57 unchanged lines hidden (view full) --- 129#define BUFSIZ 100 /* Chunk size iomoved to/from user */ 130 131struct pt_ioctl { 132 int pt_flags; 133 struct selinfo pt_selr, pt_selw; 134 u_char pt_send; 135 u_char pt_ucntl; 136 struct tty pt_tty; | 60MALLOC_DEFINE(M_PTY, "ptys", "pty data structures"); 61 62static void ptsstart __P((struct tty *tp)); 63static void ptcwakeup __P((struct tty *tp, int flag)); 64static void ptyinit __P((int n)); 65 66static d_open_t ptsopen; 67static d_close_t ptsclose; --- 57 unchanged lines hidden (view full) --- 125#define BUFSIZ 100 /* Chunk size iomoved to/from user */ 126 127struct pt_ioctl { 128 int pt_flags; 129 struct selinfo pt_selr, pt_selw; 130 u_char pt_send; 131 u_char pt_ucntl; 132 struct tty pt_tty; |
137#ifdef DEVFS 138 void *devfs_token_pts; 139 void *devfs_token_ptc; 140#endif /* DEVFS */ | 133 dev_t devs, devc; |
141}; 142 143#define PF_PKT 0x08 /* packet mode */ 144#define PF_STOPPED 0x10 /* user told stopped */ 145#define PF_REMOTE 0x20 /* remote and flow controlled input */ 146#define PF_NOSTOP 0x40 147#define PF_UCNTL 0x80 /* user control mode */ 148 --- 13 unchanged lines hidden (view full) --- 162 dev_t devs, devc; 163 char *names = "pqrsPQRS"; 164 struct pt_ioctl *pt; 165 166 /* For now we only map the lower 8 bits of the minor */ 167 if (n & ~0xff) 168 return; 169 | 134}; 135 136#define PF_PKT 0x08 /* packet mode */ 137#define PF_STOPPED 0x10 /* user told stopped */ 138#define PF_REMOTE 0x20 /* remote and flow controlled input */ 139#define PF_NOSTOP 0x40 140#define PF_UCNTL 0x80 /* user control mode */ 141 --- 13 unchanged lines hidden (view full) --- 155 dev_t devs, devc; 156 char *names = "pqrsPQRS"; 157 struct pt_ioctl *pt; 158 159 /* For now we only map the lower 8 bits of the minor */ 160 if (n & ~0xff) 161 return; 162 |
170 devs = make_dev(&pts_cdevsw, n, | 163 pt = malloc(sizeof(*pt), M_PTY, M_WAITOK); 164 bzero(pt, sizeof(*pt)); 165 pt->devs = devs = make_dev(&pts_cdevsw, n, |
171 0, 0, 0666, "tty%c%r", names[n / 32], n % 32); | 166 0, 0, 0666, "tty%c%r", names[n / 32], n % 32); |
172 devc = make_dev(&ptc_cdevsw, n, | 167 pt->devc = devc = make_dev(&ptc_cdevsw, n, |
173 0, 0, 0666, "pty%c%r", names[n / 32], n % 32); 174 | 168 0, 0, 0666, "pty%c%r", names[n / 32], n % 32); 169 |
175 pt = malloc(sizeof(*pt), M_PTY, M_WAITOK); 176 bzero(pt, sizeof(*pt)); | |
177 devs->si_drv1 = devc->si_drv1 = pt; 178 devs->si_tty_tty = devc->si_tty_tty = &pt->pt_tty; 179 ttyregister(&pt->pt_tty); | 170 devs->si_drv1 = devc->si_drv1 = pt; 171 devs->si_tty_tty = devc->si_tty_tty = &pt->pt_tty; 172 ttyregister(&pt->pt_tty); |
180#ifdef DEVFS 181 pt->devfs_token_pts = devfs_add_devswf(&pts_cdevsw,n, 182 DV_CHR,0,0,0666, 183 devs->si_name); 184 pt->devfs_token_ptc = devfs_add_devswf(&ptc_cdevsw,n, 185 DV_CHR,0,0,0666, 186 devc->si_name); 187#endif /* DEVFS */ | |
188} 189 190/*ARGSUSED*/ 191static int 192ptsopen(dev, flag, devtype, p) 193 dev_t dev; 194 int flag, devtype; 195 struct proc *p; 196{ 197 register struct tty *tp; 198 int error; | 173} 174 175/*ARGSUSED*/ 176static int 177ptsopen(dev, flag, devtype, p) 178 dev_t dev; 179 int flag, devtype; 180 struct proc *p; 181{ 182 register struct tty *tp; 183 int error; |
199#ifdef DEVFS | |
200 int minr; 201 dev_t nextdev; 202 203 /* 204 * If we openned this device, ensure we have the 205 * next ready in the DEVFS (up to 256 of them). | 184 int minr; 185 dev_t nextdev; 186 187 /* 188 * If we openned this device, ensure we have the 189 * next ready in the DEVFS (up to 256 of them). |
190 * XXX probably a more efficient way of know if the next one has 191 * been made already would be to just keep track.. |
|
206 */ 207 minr = lminor(dev); 208 if (minr < 255) { 209 nextdev = makedev(major(dev), minr + 1); 210 if (!nextdev->si_drv1) { 211 ptyinit(minr + 1); 212 } 213 } | 192 */ 193 minr = lminor(dev); 194 if (minr < 255) { 195 nextdev = makedev(major(dev), minr + 1); 196 if (!nextdev->si_drv1) { 197 ptyinit(minr + 1); 198 } 199 } |
214#endif /* DEVFS */ | |
215 if (!dev->si_drv1) 216 ptyinit(minor(dev)); 217 if (!dev->si_drv1) 218 return(ENXIO); 219 tp = dev->si_tty_tty; 220 if ((tp->t_state & TS_ISOPEN) == 0) { 221 ttychars(tp); /* Set up default chars */ 222 tp->t_iflag = TTYDEF_IFLAG; --- 631 unchanged lines hidden (view full) --- 854{ 855 static int ptc_devsw_installed; 856 857 if( ! ptc_devsw_installed ) { 858 cdevsw_add(&pts_cdevsw); 859 cdevsw_add(&ptc_cdevsw); 860 ptc_devsw_installed = 1; 861 } | 200 if (!dev->si_drv1) 201 ptyinit(minor(dev)); 202 if (!dev->si_drv1) 203 return(ENXIO); 204 tp = dev->si_tty_tty; 205 if ((tp->t_state & TS_ISOPEN) == 0) { 206 ttychars(tp); /* Set up default chars */ 207 tp->t_iflag = TTYDEF_IFLAG; --- 631 unchanged lines hidden (view full) --- 839{ 840 static int ptc_devsw_installed; 841 842 if( ! ptc_devsw_installed ) { 843 cdevsw_add(&pts_cdevsw); 844 cdevsw_add(&ptc_cdevsw); 845 ptc_devsw_installed = 1; 846 } |
862#ifdef DEVFS | |
863 ptyinit(0); /* Add the first pty into the system.. prime the pump */ | 847 ptyinit(0); /* Add the first pty into the system.. prime the pump */ |
864#endif /* DEVFS */ | |
865} 866 867SYSINIT(ptcdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR_C,ptc_drvinit,NULL) | 848} 849 850SYSINIT(ptcdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR_C,ptc_drvinit,NULL) |