move read/writeblkvp from old ufs_io.c to spec_read/write
[unix-history] / usr / src / sys / kern / tty_tty.c
CommitLineData
da7c5cc6 1/*
0880b18e 2 * Copyright (c) 1982, 1986 Regents of the University of California.
da7c5cc6
KM
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 *
18b87772 6 * @(#)tty_tty.c 7.6 (Berkeley) %G%
da7c5cc6 7 */
63c57592
BJ
8
9/*
964bcfb1 10 * Indirect driver for controlling tty.
63c57592 11 */
94368568
JB
12#include "param.h"
13#include "systm.h"
14#include "conf.h"
94368568
JB
15#include "user.h"
16#include "ioctl.h"
17#include "tty.h"
18#include "proc.h"
232c0273
MT
19#include "vnode.h"
20#include "file.h"
94368568 21#include "uio.h"
63c57592 22
232c0273
MT
23#define cttyvp(p) ((p)->p_flag&SCTTY ? (p)->p_session->s_ttyvp : NULL)
24
63c57592
BJ
25/*ARGSUSED*/
26syopen(dev, flag)
830bbc16
BJ
27 dev_t dev;
28 int flag;
63c57592 29{
232c0273
MT
30 struct vnode *ttyvp = cttyvp(u.u_procp);
31 int error;
63c57592 32
232c0273 33 if (ttyvp == NULL)
830bbc16 34 return (ENXIO);
232c0273
MT
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));
63c57592
BJ
39}
40
41/*ARGSUSED*/
76e0e3c3 42syread(dev, uio, flag)
be3a1208
BJ
43 dev_t dev;
44 struct uio *uio;
63c57592 45{
18b87772
KM
46 register struct vnode *ttyvp = cttyvp(u.u_procp);
47 int error;
63c57592 48
232c0273 49 if (ttyvp == NULL)
840510a3 50 return (ENXIO);
18b87772
KM
51 VOP_LOCK(ttyvp);
52 error = VOP_READ(ttyvp, uio, flag, NOCRED);
53 VOP_UNLOCK(ttyvp);
54 return (error);
63c57592
BJ
55}
56
57/*ARGSUSED*/
76e0e3c3 58sywrite(dev, uio, flag)
be3a1208
BJ
59 dev_t dev;
60 struct uio *uio;
63c57592 61{
18b87772
KM
62 register struct vnode *ttyvp = cttyvp(u.u_procp);
63 int error;
63c57592 64
232c0273 65 if (ttyvp == NULL)
840510a3 66 return (ENXIO);
18b87772
KM
67 VOP_LOCK(ttyvp);
68 error = VOP_WRITE(ttyvp, uio, flag, NOCRED);
69 VOP_UNLOCK(ttyvp);
70 return (error);
63c57592
BJ
71}
72
73/*ARGSUSED*/
74syioctl(dev, cmd, addr, flag)
35c1dcdb
BJ
75 dev_t dev;
76 int cmd;
77 caddr_t addr;
78 int flag;
63c57592 79{
232c0273 80 struct vnode *ttyvp = cttyvp(u.u_procp);
63c57592 81
232c0273
MT
82 if (ttyvp == NULL)
83 return (ENXIO);
9060c89c 84 if (cmd == TIOCNOTTY) {
232c0273
MT
85 if (!SESS_LEADER(u.u_procp)) {
86 u.u_procp->p_flag &= ~SCTTY;
87 return (0);
88 } else
89 return (EINVAL);
4460d508 90 }
232c0273 91 return (VOP_IOCTL(ttyvp, cmd, addr, flag, NOCRED));
63c57592 92}
231ed58b 93
a8d3bf7f 94/*ARGSUSED*/
231ed58b 95syselect(dev, flag)
a8d3bf7f
BJ
96 dev_t dev;
97 int flag;
231ed58b 98{
232c0273 99 struct vnode *ttyvp = cttyvp(u.u_procp);
231ed58b 100
232c0273
MT
101 if (ttyvp == NULL)
102 return (ENXIO);
103 return (VOP_SELECT(ttyvp, flag, NOCRED));
231ed58b 104}