123393Smckusick /* 229112Smckusick * Copyright (c) 1982, 1986 Regents of the University of California. 323393Smckusick * All rights reserved. The Berkeley software License Agreement 423393Smckusick * specifies the terms and conditions for redistribution. 523393Smckusick * 6*40187Smckusick * @(#)tty_tty.c 7.7 (Berkeley) 02/21/90 723393Smckusick */ 835Sbill 935Sbill /* 103117Swnj * Indirect driver for controlling tty. 1135Sbill */ 1217097Sbloom #include "param.h" 1317097Sbloom #include "systm.h" 1417097Sbloom #include "conf.h" 1517097Sbloom #include "user.h" 1617097Sbloom #include "ioctl.h" 1717097Sbloom #include "tty.h" 1817097Sbloom #include "proc.h" 1939554Smarc #include "vnode.h" 2039554Smarc #include "file.h" 2117097Sbloom #include "uio.h" 2235Sbill 2339554Smarc #define cttyvp(p) ((p)->p_flag&SCTTY ? (p)->p_session->s_ttyvp : NULL) 2439554Smarc 2535Sbill /*ARGSUSED*/ 2635Sbill syopen(dev, flag) 278558Sroot dev_t dev; 288558Sroot int flag; 2935Sbill { 3039554Smarc struct vnode *ttyvp = cttyvp(u.u_procp); 3139554Smarc int error; 3235Sbill 3339554Smarc if (ttyvp == NULL) 348558Sroot return (ENXIO); 3539554Smarc if (error = VOP_ACCESS(ttyvp, 3639554Smarc (flag&FREAD ? VREAD : 0) | (flag&FWRITE ? VWRITE : 0), u.u_cred)) 3739554Smarc return (error); 3839554Smarc return (VOP_OPEN(ttyvp, flag, NOCRED)); 3935Sbill } 4035Sbill 4135Sbill /*ARGSUSED*/ 4237588Smarc syread(dev, uio, flag) 437824Sroot dev_t dev; 447824Sroot struct uio *uio; 4535Sbill { 4639589Smckusick register struct vnode *ttyvp = cttyvp(u.u_procp); 4739589Smckusick int error; 4835Sbill 4939554Smarc if (ttyvp == NULL) 508522Sroot return (ENXIO); 5139589Smckusick VOP_LOCK(ttyvp); 5239589Smckusick error = VOP_READ(ttyvp, uio, flag, NOCRED); 5339589Smckusick VOP_UNLOCK(ttyvp); 5439589Smckusick return (error); 5535Sbill } 5635Sbill 5735Sbill /*ARGSUSED*/ 5837588Smarc sywrite(dev, uio, flag) 597824Sroot dev_t dev; 607824Sroot struct uio *uio; 6135Sbill { 6239589Smckusick register struct vnode *ttyvp = cttyvp(u.u_procp); 6339589Smckusick int error; 6435Sbill 6539554Smarc if (ttyvp == NULL) 668522Sroot return (ENXIO); 6739589Smckusick VOP_LOCK(ttyvp); 6839589Smckusick error = VOP_WRITE(ttyvp, uio, flag, NOCRED); 6939589Smckusick VOP_UNLOCK(ttyvp); 7039589Smckusick return (error); 7135Sbill } 7235Sbill 7335Sbill /*ARGSUSED*/ 7435Sbill syioctl(dev, cmd, addr, flag) 755618Sroot dev_t dev; 765618Sroot int cmd; 775618Sroot caddr_t addr; 785618Sroot int flag; 7935Sbill { 8039554Smarc struct vnode *ttyvp = cttyvp(u.u_procp); 8135Sbill 8239554Smarc if (ttyvp == NULL) 8339554Smarc return (ENXIO); 845390Swnj if (cmd == TIOCNOTTY) { 8539554Smarc if (!SESS_LEADER(u.u_procp)) { 8639554Smarc u.u_procp->p_flag &= ~SCTTY; 8739554Smarc return (0); 8839554Smarc } else 8939554Smarc return (EINVAL); 905390Swnj } 9139554Smarc return (VOP_IOCTL(ttyvp, cmd, addr, flag, NOCRED)); 9235Sbill } 934487Swnj 948591Sroot /*ARGSUSED*/ 954487Swnj syselect(dev, flag) 968591Sroot dev_t dev; 978591Sroot int flag; 984487Swnj { 9939554Smarc struct vnode *ttyvp = cttyvp(u.u_procp); 1004487Swnj 10139554Smarc if (ttyvp == NULL) 10239554Smarc return (ENXIO); 103*40187Smckusick return (VOP_SELECT(ttyvp, flag, FREAD|FWRITE, NOCRED)); 1044487Swnj } 105