1 /*- 2 * Copyright (c) 1982, 1986, 1991 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * @(#)tty_tty.c 7.18 (Berkeley) 05/14/92 8 */ 9 10 /* 11 * Indirect driver for controlling tty. 12 */ 13 #include "param.h" 14 #include "systm.h" 15 #include "conf.h" 16 #include "ioctl.h" 17 #include "proc.h" 18 #include "tty.h" 19 #include "vnode.h" 20 #include "file.h" 21 22 #define cttyvp(p) ((p)->p_flag&SCTTY ? (p)->p_session->s_ttyvp : NULL) 23 24 /*ARGSUSED*/ 25 cttyopen(dev, flag, mode, p) 26 dev_t dev; 27 int flag, mode; 28 struct proc *p; 29 { 30 USES_VOP_ACCESS; 31 USES_VOP_LOCK; 32 USES_VOP_OPEN; 33 USES_VOP_UNLOCK; 34 struct vnode *ttyvp = cttyvp(p); 35 int error; 36 37 if (ttyvp == NULL) 38 return (ENXIO); 39 VOP_LOCK(ttyvp); 40 error = VOP_ACCESS(ttyvp, 41 (flag&FREAD ? VREAD : 0) | (flag&FWRITE ? VWRITE : 0), p->p_ucred, p); 42 if (!error) 43 error = VOP_OPEN(ttyvp, flag, NOCRED, p); 44 VOP_UNLOCK(ttyvp); 45 return (error); 46 } 47 48 /*ARGSUSED*/ 49 cttyread(dev, uio, flag) 50 dev_t dev; 51 struct uio *uio; 52 int flag; 53 { 54 USES_VOP_LOCK; 55 USES_VOP_READ; 56 USES_VOP_UNLOCK; 57 register struct vnode *ttyvp = cttyvp(uio->uio_procp); 58 int error; 59 60 if (ttyvp == NULL) 61 return (EIO); 62 VOP_LOCK(ttyvp); 63 error = VOP_READ(ttyvp, uio, flag, NOCRED); 64 VOP_UNLOCK(ttyvp); 65 return (error); 66 } 67 68 /*ARGSUSED*/ 69 cttywrite(dev, uio, flag) 70 dev_t dev; 71 struct uio *uio; 72 int flag; 73 { 74 USES_VOP_LOCK; 75 USES_VOP_UNLOCK; 76 USES_VOP_WRITE; 77 register struct vnode *ttyvp = cttyvp(uio->uio_procp); 78 int error; 79 80 if (ttyvp == NULL) 81 return (EIO); 82 VOP_LOCK(ttyvp); 83 error = VOP_WRITE(ttyvp, uio, flag, NOCRED); 84 VOP_UNLOCK(ttyvp); 85 return (error); 86 } 87 88 /*ARGSUSED*/ 89 cttyioctl(dev, cmd, addr, flag, p) 90 dev_t dev; 91 int cmd; 92 caddr_t addr; 93 int flag; 94 struct proc *p; 95 { 96 USES_VOP_IOCTL; 97 struct vnode *ttyvp = cttyvp(p); 98 99 if (ttyvp == NULL) 100 return (EIO); 101 if (cmd == TIOCNOTTY) { 102 if (!SESS_LEADER(p)) { 103 p->p_flag &= ~SCTTY; 104 return (0); 105 } else 106 return (EINVAL); 107 } 108 return (VOP_IOCTL(ttyvp, cmd, addr, flag, NOCRED, p)); 109 } 110 111 /*ARGSUSED*/ 112 cttyselect(dev, flag, p) 113 dev_t dev; 114 int flag; 115 struct proc *p; 116 { 117 USES_VOP_SELECT; 118 struct vnode *ttyvp = cttyvp(p); 119 120 if (ttyvp == NULL) 121 return (1); /* try operation to get EOF/failure */ 122 return (VOP_SELECT(ttyvp, flag, FREAD|FWRITE, NOCRED, p)); 123 } 124