xref: /csrg-svn/sys/kern/tty_tty.c (revision 39554)
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*39554Smarc  *	@(#)tty_tty.c	7.5 (Berkeley) 11/20/89
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"
19*39554Smarc #include "vnode.h"
20*39554Smarc #include "file.h"
2117097Sbloom #include "uio.h"
2235Sbill 
23*39554Smarc #define cttyvp(p) ((p)->p_flag&SCTTY ? (p)->p_session->s_ttyvp : NULL)
24*39554Smarc 
25*39554Smarc static off_t dummyoff;
26*39554Smarc 
2735Sbill /*ARGSUSED*/
2835Sbill syopen(dev, flag)
298558Sroot 	dev_t dev;
308558Sroot 	int flag;
3135Sbill {
32*39554Smarc 	struct vnode *ttyvp = cttyvp(u.u_procp);
33*39554Smarc 	int error;
3435Sbill 
35*39554Smarc 	if (ttyvp == NULL)
368558Sroot 		return (ENXIO);
37*39554Smarc 	if (error = VOP_ACCESS(ttyvp,
38*39554Smarc 	   (flag&FREAD ? VREAD : 0) | (flag&FWRITE ? VWRITE : 0), u.u_cred))
39*39554Smarc 		return (error);
40*39554Smarc 	return (VOP_OPEN(ttyvp, flag, NOCRED));
4135Sbill }
4235Sbill 
4335Sbill /*ARGSUSED*/
4437588Smarc syread(dev, uio, flag)
457824Sroot 	dev_t dev;
467824Sroot 	struct uio *uio;
4735Sbill {
48*39554Smarc 	struct vnode *ttyvp = cttyvp(u.u_procp);
4935Sbill 
50*39554Smarc 	if (ttyvp == NULL)
518522Sroot 		return (ENXIO);
52*39554Smarc 	return (VOP_READ(ttyvp, uio, &dummyoff, flag, NOCRED));
5335Sbill }
5435Sbill 
5535Sbill /*ARGSUSED*/
5637588Smarc sywrite(dev, uio, flag)
577824Sroot 	dev_t dev;
587824Sroot 	struct uio *uio;
5935Sbill {
60*39554Smarc 	struct vnode *ttyvp = cttyvp(u.u_procp);
6135Sbill 
62*39554Smarc 	if (ttyvp == NULL)
638522Sroot 		return (ENXIO);
64*39554Smarc 	return (VOP_WRITE(ttyvp, uio, &dummyoff, flag, NOCRED));
6535Sbill }
6635Sbill 
6735Sbill /*ARGSUSED*/
6835Sbill syioctl(dev, cmd, addr, flag)
695618Sroot 	dev_t dev;
705618Sroot 	int cmd;
715618Sroot 	caddr_t addr;
725618Sroot 	int flag;
7335Sbill {
74*39554Smarc 	struct vnode *ttyvp = cttyvp(u.u_procp);
7535Sbill 
76*39554Smarc 	if (ttyvp == NULL)
77*39554Smarc 		return (ENXIO);
785390Swnj 	if (cmd == TIOCNOTTY) {
79*39554Smarc 		if (!SESS_LEADER(u.u_procp)) {
80*39554Smarc 			u.u_procp->p_flag &= ~SCTTY;
81*39554Smarc 			return (0);
82*39554Smarc 		} else
83*39554Smarc 			return (EINVAL);
845390Swnj 	}
85*39554Smarc 	return (VOP_IOCTL(ttyvp, cmd, addr, flag, NOCRED));
8635Sbill }
874487Swnj 
888591Sroot /*ARGSUSED*/
894487Swnj syselect(dev, flag)
908591Sroot 	dev_t dev;
918591Sroot 	int flag;
924487Swnj {
93*39554Smarc 	struct vnode *ttyvp = cttyvp(u.u_procp);
944487Swnj 
95*39554Smarc 	if (ttyvp == NULL)
96*39554Smarc 		return (ENXIO);
97*39554Smarc 	return (VOP_SELECT(ttyvp, flag, NOCRED));
984487Swnj }
99