1 /* 2 * Copyright (c) 1982, 1986 Regents of the University of California. 3 * All rights reserved. The Berkeley software License Agreement 4 * specifies the terms and conditions for redistribution. 5 * 6 * @(#)tty_tty.c 7.7 (Berkeley) 02/21/90 7 */ 8 9 /* 10 * Indirect driver for controlling tty. 11 */ 12 #include "param.h" 13 #include "systm.h" 14 #include "conf.h" 15 #include "user.h" 16 #include "ioctl.h" 17 #include "tty.h" 18 #include "proc.h" 19 #include "vnode.h" 20 #include "file.h" 21 #include "uio.h" 22 23 #define cttyvp(p) ((p)->p_flag&SCTTY ? (p)->p_session->s_ttyvp : NULL) 24 25 /*ARGSUSED*/ 26 syopen(dev, flag) 27 dev_t dev; 28 int flag; 29 { 30 struct vnode *ttyvp = cttyvp(u.u_procp); 31 int error; 32 33 if (ttyvp == NULL) 34 return (ENXIO); 35 if (error = VOP_ACCESS(ttyvp, 36 (flag&FREAD ? VREAD : 0) | (flag&FWRITE ? VWRITE : 0), u.u_cred)) 37 return (error); 38 return (VOP_OPEN(ttyvp, flag, NOCRED)); 39 } 40 41 /*ARGSUSED*/ 42 syread(dev, uio, flag) 43 dev_t dev; 44 struct uio *uio; 45 { 46 register struct vnode *ttyvp = cttyvp(u.u_procp); 47 int error; 48 49 if (ttyvp == NULL) 50 return (ENXIO); 51 VOP_LOCK(ttyvp); 52 error = VOP_READ(ttyvp, uio, flag, NOCRED); 53 VOP_UNLOCK(ttyvp); 54 return (error); 55 } 56 57 /*ARGSUSED*/ 58 sywrite(dev, uio, flag) 59 dev_t dev; 60 struct uio *uio; 61 { 62 register struct vnode *ttyvp = cttyvp(u.u_procp); 63 int error; 64 65 if (ttyvp == NULL) 66 return (ENXIO); 67 VOP_LOCK(ttyvp); 68 error = VOP_WRITE(ttyvp, uio, flag, NOCRED); 69 VOP_UNLOCK(ttyvp); 70 return (error); 71 } 72 73 /*ARGSUSED*/ 74 syioctl(dev, cmd, addr, flag) 75 dev_t dev; 76 int cmd; 77 caddr_t addr; 78 int flag; 79 { 80 struct vnode *ttyvp = cttyvp(u.u_procp); 81 82 if (ttyvp == NULL) 83 return (ENXIO); 84 if (cmd == TIOCNOTTY) { 85 if (!SESS_LEADER(u.u_procp)) { 86 u.u_procp->p_flag &= ~SCTTY; 87 return (0); 88 } else 89 return (EINVAL); 90 } 91 return (VOP_IOCTL(ttyvp, cmd, addr, flag, NOCRED)); 92 } 93 94 /*ARGSUSED*/ 95 syselect(dev, flag) 96 dev_t dev; 97 int flag; 98 { 99 struct vnode *ttyvp = cttyvp(u.u_procp); 100 101 if (ttyvp == NULL) 102 return (ENXIO); 103 return (VOP_SELECT(ttyvp, flag, FREAD|FWRITE, NOCRED)); 104 } 105