1*49594Sbostic /*- 2*49594Sbostic * Copyright (c) 1982, 1986, 1991 The Regents of the University of California. 3*49594Sbostic * All rights reserved. 423393Smckusick * 5*49594Sbostic * %sccs.include.redist.c% 6*49594Sbostic * 7*49594Sbostic * @(#)tty_tty.c 7.14 (Berkeley) 05/09/91 823393Smckusick */ 935Sbill 1035Sbill /* 113117Swnj * Indirect driver for controlling tty. 1235Sbill */ 1317097Sbloom #include "param.h" 1417097Sbloom #include "systm.h" 1517097Sbloom #include "conf.h" 1617097Sbloom #include "ioctl.h" 1717097Sbloom #include "tty.h" 1817097Sbloom #include "proc.h" 1939554Smarc #include "vnode.h" 2039554Smarc #include "file.h" 2135Sbill 2239554Smarc #define cttyvp(p) ((p)->p_flag&SCTTY ? (p)->p_session->s_ttyvp : NULL) 2339554Smarc 2435Sbill /*ARGSUSED*/ 2547648Skarels cttyopen(dev, flag, mode, p) 268558Sroot dev_t dev; 2747648Skarels int flag, mode; 2847648Skarels struct proc *p; 2935Sbill { 3047545Skarels struct vnode *ttyvp = cttyvp(p); 3139554Smarc int error; 3235Sbill 3339554Smarc if (ttyvp == NULL) 348558Sroot return (ENXIO); 3541191Smckusick VOP_LOCK(ttyvp); 3641191Smckusick error = VOP_ACCESS(ttyvp, 3748018Smckusick (flag&FREAD ? VREAD : 0) | (flag&FWRITE ? VWRITE : 0), p->p_ucred, p); 3841191Smckusick VOP_UNLOCK(ttyvp); 3941191Smckusick if (error) 4039554Smarc return (error); 4148018Smckusick return (VOP_OPEN(ttyvp, flag, NOCRED, p)); 4235Sbill } 4335Sbill 4435Sbill /*ARGSUSED*/ 4549177Skarels cttyread(dev, uio, flag) 467824Sroot dev_t dev; 477824Sroot struct uio *uio; 4835Sbill { 4949177Skarels register struct vnode *ttyvp = cttyvp(uio->uio_procp); 5039589Smckusick int error; 5135Sbill 5239554Smarc if (ttyvp == NULL) 5347648Skarels return (EIO); 5439589Smckusick VOP_LOCK(ttyvp); 5539589Smckusick error = VOP_READ(ttyvp, uio, flag, NOCRED); 5639589Smckusick VOP_UNLOCK(ttyvp); 5739589Smckusick return (error); 5835Sbill } 5935Sbill 6035Sbill /*ARGSUSED*/ 6149177Skarels cttywrite(dev, uio, flag) 627824Sroot dev_t dev; 637824Sroot struct uio *uio; 6435Sbill { 6549177Skarels register struct vnode *ttyvp = cttyvp(uio->uio_procp); 6639589Smckusick int error; 6735Sbill 6839554Smarc if (ttyvp == NULL) 6947648Skarels return (EIO); 7039589Smckusick VOP_LOCK(ttyvp); 7139589Smckusick error = VOP_WRITE(ttyvp, uio, flag, NOCRED); 7239589Smckusick VOP_UNLOCK(ttyvp); 7339589Smckusick return (error); 7435Sbill } 7535Sbill 7635Sbill /*ARGSUSED*/ 7747648Skarels cttyioctl(dev, cmd, addr, flag, p) 785618Sroot dev_t dev; 795618Sroot int cmd; 805618Sroot caddr_t addr; 815618Sroot int flag; 8247648Skarels struct proc *p; 8335Sbill { 8447648Skarels struct vnode *ttyvp = cttyvp(p); 8535Sbill 8639554Smarc if (ttyvp == NULL) 8747648Skarels return (EIO); 885390Swnj if (cmd == TIOCNOTTY) { 8947648Skarels if (!SESS_LEADER(p)) { 9047648Skarels p->p_flag &= ~SCTTY; 9139554Smarc return (0); 9239554Smarc } else 9339554Smarc return (EINVAL); 945390Swnj } 9548018Smckusick return (VOP_IOCTL(ttyvp, cmd, addr, flag, NOCRED, p)); 9635Sbill } 974487Swnj 988591Sroot /*ARGSUSED*/ 9947648Skarels cttyselect(dev, flag, p) 1008591Sroot dev_t dev; 1018591Sroot int flag; 10247648Skarels struct proc *p; 1034487Swnj { 10447648Skarels struct vnode *ttyvp = cttyvp(p); 1054487Swnj 10639554Smarc if (ttyvp == NULL) 10743382Skarels return (1); /* try operation to get EOF/failure */ 10848018Smckusick return (VOP_SELECT(ttyvp, flag, FREAD|FWRITE, NOCRED, p)); 1094487Swnj } 110