|
|
1.1 root 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.9 (Berkeley) 6/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: VOP_LOCK(ttyvp);
36: error = VOP_ACCESS(ttyvp,
37: (flag&FREAD ? VREAD : 0) | (flag&FWRITE ? VWRITE : 0), u.u_cred);
38: VOP_UNLOCK(ttyvp);
39: if (error)
40: return (error);
41: return (VOP_OPEN(ttyvp, flag, NOCRED));
42: }
43:
44: /*ARGSUSED*/
45: syread(dev, uio, flag)
46: dev_t dev;
47: struct uio *uio;
48: {
49: register struct vnode *ttyvp = cttyvp(u.u_procp);
50: int error;
51:
52: if (ttyvp == NULL)
53: return (ENXIO);
54: VOP_LOCK(ttyvp);
55: error = VOP_READ(ttyvp, uio, flag, NOCRED);
56: VOP_UNLOCK(ttyvp);
57: return (error);
58: }
59:
60: /*ARGSUSED*/
61: sywrite(dev, uio, flag)
62: dev_t dev;
63: struct uio *uio;
64: {
65: register struct vnode *ttyvp = cttyvp(u.u_procp);
66: int error;
67:
68: if (ttyvp == NULL)
69: return (ENXIO);
70: VOP_LOCK(ttyvp);
71: error = VOP_WRITE(ttyvp, uio, flag, NOCRED);
72: VOP_UNLOCK(ttyvp);
73: return (error);
74: }
75:
76: /*ARGSUSED*/
77: syioctl(dev, cmd, addr, flag)
78: dev_t dev;
79: int cmd;
80: caddr_t addr;
81: int flag;
82: {
83: struct vnode *ttyvp = cttyvp(u.u_procp);
84:
85: if (ttyvp == NULL)
86: return (ENXIO);
87: if (cmd == TIOCNOTTY) {
88: if (!SESS_LEADER(u.u_procp)) {
89: u.u_procp->p_flag &= ~SCTTY;
90: return (0);
91: } else
92: return (EINVAL);
93: }
94: return (VOP_IOCTL(ttyvp, cmd, addr, flag, NOCRED));
95: }
96:
97: /*ARGSUSED*/
98: syselect(dev, flag)
99: dev_t dev;
100: int flag;
101: {
102: struct vnode *ttyvp = cttyvp(u.u_procp);
103:
104: if (ttyvp == NULL)
105: return (1); /* try operation to get EOF/failure */
106: return (VOP_SELECT(ttyvp, flag, FREAD|FWRITE, NOCRED));
107: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.