xref: /csrg-svn/sys/kern/tty_tty.c (revision 37588)
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.3 (Berkeley) 05/01/89
7  */
8 
9 /*
10  * Indirect driver for controlling tty.
11  *
12  * THIS IS GARBAGE: MUST SOON BE DONE WITH struct inode * IN PROC TABLE.
13  */
14 #include "param.h"
15 #include "systm.h"
16 #include "conf.h"
17 #include "dir.h"
18 #include "user.h"
19 #include "ioctl.h"
20 #include "tty.h"
21 #include "proc.h"
22 #include "uio.h"
23 
24 /*ARGSUSED*/
25 syopen(dev, flag)
26 	dev_t dev;
27 	int flag;
28 {
29 
30 	if (u.u_ttyp == NULL)
31 		return (ENXIO);
32 	return ((*cdevsw[major(u.u_ttyd)].d_open)(u.u_ttyd, flag));
33 }
34 
35 /*ARGSUSED*/
36 syread(dev, uio, flag)
37 	dev_t dev;
38 	struct uio *uio;
39 {
40 
41 	if (u.u_ttyp == NULL)
42 		return (ENXIO);
43 	return ((*cdevsw[major(u.u_ttyd)].d_read)(u.u_ttyd, uio, flag));
44 }
45 
46 /*ARGSUSED*/
47 sywrite(dev, uio, flag)
48 	dev_t dev;
49 	struct uio *uio;
50 {
51 
52 	if (u.u_ttyp == NULL)
53 		return (ENXIO);
54 	return ((*cdevsw[major(u.u_ttyd)].d_write)(u.u_ttyd, uio, flag));
55 }
56 
57 /*ARGSUSED*/
58 syioctl(dev, cmd, addr, flag)
59 	dev_t dev;
60 	int cmd;
61 	caddr_t addr;
62 	int flag;
63 {
64 
65 	if (cmd == TIOCNOTTY) {
66 		if (SESS_LEADER(u.u_procp)) {
67 			/*
68 			 * XXX - check posix draft
69 			 */
70 			u.u_ttyp->t_session = 0;
71 			u.u_ttyp->t_pgid = 0;
72 		}
73 		u.u_ttyp = 0;
74 		u.u_ttyd = 0;
75 		return (0);
76 	}
77 	if (u.u_ttyp == NULL)
78 		return (ENXIO);
79 	return ((*cdevsw[major(u.u_ttyd)].d_ioctl)(u.u_ttyd, cmd, addr, flag));
80 }
81 
82 /*ARGSUSED*/
83 syselect(dev, flag)
84 	dev_t dev;
85 	int flag;
86 {
87 
88 	if (u.u_ttyp == NULL) {
89 		u.u_error = ENXIO;
90 		return (0);
91 	}
92 	return ((*cdevsw[major(u.u_ttyd)].d_select)(u.u_ttyd, flag));
93 }
94