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.5 (Berkeley) 11/20/89 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 static off_t dummyoff; 26 27 /*ARGSUSED*/ 28 syopen(dev, flag) 29 dev_t dev; 30 int flag; 31 { 32 struct vnode *ttyvp = cttyvp(u.u_procp); 33 int error; 34 35 if (ttyvp == NULL) 36 return (ENXIO); 37 if (error = VOP_ACCESS(ttyvp, 38 (flag&FREAD ? VREAD : 0) | (flag&FWRITE ? VWRITE : 0), u.u_cred)) 39 return (error); 40 return (VOP_OPEN(ttyvp, flag, NOCRED)); 41 } 42 43 /*ARGSUSED*/ 44 syread(dev, uio, flag) 45 dev_t dev; 46 struct uio *uio; 47 { 48 struct vnode *ttyvp = cttyvp(u.u_procp); 49 50 if (ttyvp == NULL) 51 return (ENXIO); 52 return (VOP_READ(ttyvp, uio, &dummyoff, flag, NOCRED)); 53 } 54 55 /*ARGSUSED*/ 56 sywrite(dev, uio, flag) 57 dev_t dev; 58 struct uio *uio; 59 { 60 struct vnode *ttyvp = cttyvp(u.u_procp); 61 62 if (ttyvp == NULL) 63 return (ENXIO); 64 return (VOP_WRITE(ttyvp, uio, &dummyoff, flag, NOCRED)); 65 } 66 67 /*ARGSUSED*/ 68 syioctl(dev, cmd, addr, flag) 69 dev_t dev; 70 int cmd; 71 caddr_t addr; 72 int flag; 73 { 74 struct vnode *ttyvp = cttyvp(u.u_procp); 75 76 if (ttyvp == NULL) 77 return (ENXIO); 78 if (cmd == TIOCNOTTY) { 79 if (!SESS_LEADER(u.u_procp)) { 80 u.u_procp->p_flag &= ~SCTTY; 81 return (0); 82 } else 83 return (EINVAL); 84 } 85 return (VOP_IOCTL(ttyvp, cmd, addr, flag, NOCRED)); 86 } 87 88 /*ARGSUSED*/ 89 syselect(dev, flag) 90 dev_t dev; 91 int flag; 92 { 93 struct vnode *ttyvp = cttyvp(u.u_procp); 94 95 if (ttyvp == NULL) 96 return (ENXIO); 97 return (VOP_SELECT(ttyvp, flag, NOCRED)); 98 } 99