1995-02-14 21:21:26 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1995 Ugen J.S.Antsilevich
|
|
|
|
*
|
|
|
|
* Redistribution and use in source forms, with and without modification,
|
|
|
|
* are permitted provided that this entire comment appears intact.
|
|
|
|
*
|
|
|
|
* Redistribution in binary form may occur without any restrictions.
|
|
|
|
* Obviously, it would be nice if you gave credit where credit is due
|
|
|
|
* but requiring it would be too onerous.
|
|
|
|
*
|
|
|
|
* This software is provided ``AS IS'' without any warranties of any kind.
|
|
|
|
*
|
|
|
|
* Snoop stuff.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "snp.h"
|
|
|
|
|
1995-02-15 16:35:38 +00:00
|
|
|
#if NSNP > 0
|
1995-02-14 21:21:26 +00:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/ioctl.h>
|
1995-02-15 16:35:38 +00:00
|
|
|
#include <sys/ioctl_compat.h> /* Oooh..We need O/NTTYDISC */
|
1995-02-14 21:21:26 +00:00
|
|
|
#include <sys/proc.h>
|
|
|
|
#define TTYDEFCHARS
|
|
|
|
#include <sys/tty.h>
|
|
|
|
#undef TTYDEFCHARS
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
|
|
|
|
#include <sys/snoop.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef ST_PTY
|
|
|
|
/*
|
|
|
|
* This should be same as in "kern/tty_pty.c"
|
|
|
|
*/
|
|
|
|
#include "pty.h"
|
|
|
|
|
|
|
|
#if NPTY == 1
|
|
|
|
#undef NPTY
|
|
|
|
#define NPTY 32
|
|
|
|
#endif
|
|
|
|
|
1995-02-15 16:35:38 +00:00
|
|
|
extern struct tty pt_tty[];
|
|
|
|
#endif /* ST_PTY */
|
1995-02-14 21:21:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef ST_SIO
|
|
|
|
/*
|
|
|
|
* This should be same as "i386/isa/sio.c"
|
|
|
|
*/
|
|
|
|
#include "sio.h"
|
|
|
|
|
1995-02-15 16:35:38 +00:00
|
|
|
extern struct tty sio_tty[];
|
|
|
|
#endif /* ST_SIO */
|
1995-02-14 21:21:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef ST_VTY
|
|
|
|
/*
|
|
|
|
* This should match "i386/isa/sc.c"
|
|
|
|
*/
|
1995-02-15 16:35:38 +00:00
|
|
|
|
|
|
|
#if !defined(MAXCONS)
|
|
|
|
#define MAXCONS 16
|
1995-02-14 21:21:26 +00:00
|
|
|
#endif
|
|
|
|
|
1995-02-15 16:35:38 +00:00
|
|
|
extern struct tty sccons[];
|
|
|
|
#endif /* ST_VTY */
|
1995-02-14 21:21:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
1995-02-15 16:35:38 +00:00
|
|
|
* This is local structure to hold data for all tty arrays we serve.
|
1995-02-14 21:21:26 +00:00
|
|
|
*/
|
1995-02-15 16:35:38 +00:00
|
|
|
typedef struct tty tty_arr[];
|
1995-02-14 21:21:26 +00:00
|
|
|
struct tty_tab {
|
1995-02-15 16:35:38 +00:00
|
|
|
int lt_max;
|
|
|
|
tty_arr *lt_tab;
|
1995-02-14 21:21:26 +00:00
|
|
|
};
|
|
|
|
|
1995-02-15 16:35:38 +00:00
|
|
|
static struct tty_tab tty_tabs[] = {
|
1995-02-14 21:21:26 +00:00
|
|
|
#ifdef ST_PTY
|
1995-02-15 16:35:38 +00:00
|
|
|
{NPTY, &pt_tty},
|
1995-02-14 21:21:26 +00:00
|
|
|
#else
|
1995-02-15 16:35:38 +00:00
|
|
|
{-1, NULL},
|
1995-02-14 21:21:26 +00:00
|
|
|
#endif
|
|
|
|
#ifdef ST_VTY
|
1995-02-15 16:35:38 +00:00
|
|
|
{MAXCONS, &sccons},
|
1995-02-14 21:21:26 +00:00
|
|
|
#else
|
1995-02-15 16:35:38 +00:00
|
|
|
{-1, NULL},
|
1995-02-14 21:21:26 +00:00
|
|
|
#endif
|
|
|
|
#ifdef ST_SIO
|
1995-02-15 16:35:38 +00:00
|
|
|
{NSIO, &sio_tty}
|
1995-02-14 21:21:26 +00:00
|
|
|
#else
|
1995-02-15 16:35:38 +00:00
|
|
|
{-1, NULL}
|
1995-02-14 21:21:26 +00:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef MIN
|
|
|
|
#define MIN(a,b) (((a)<(b))?(a):(b))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
static struct snoop snoopsw[NSNP];
|
|
|
|
|
|
|
|
int
|
|
|
|
snpread(dev, uio, flag)
|
1995-02-15 16:35:38 +00:00
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
|
|
|
int flag;
|
1995-02-14 21:21:26 +00:00
|
|
|
{
|
1995-02-15 16:35:38 +00:00
|
|
|
int unit = minor(dev), s;
|
|
|
|
struct snoop *snp = &snoopsw[unit];
|
|
|
|
int len, n, nblen, error = 0;
|
|
|
|
caddr_t from;
|
|
|
|
char *nbuf;
|
|
|
|
|
1995-02-14 21:21:26 +00:00
|
|
|
#ifdef DIAGNOSTIC
|
1995-02-15 16:35:38 +00:00
|
|
|
if ((snp->snp_len + snp->snp_base) > snp->snp_blen)
|
1995-02-14 21:21:26 +00:00
|
|
|
panic("snoop buffer error");
|
|
|
|
#endif
|
1995-02-15 16:35:38 +00:00
|
|
|
if (snp->snp_unit == -1)
|
1995-02-14 21:21:26 +00:00
|
|
|
return (EIO);
|
|
|
|
|
1995-02-15 16:35:38 +00:00
|
|
|
snp->snp_flags &= ~SNOOP_RWAIT;
|
1995-02-14 21:21:26 +00:00
|
|
|
|
|
|
|
do {
|
1995-02-15 16:35:38 +00:00
|
|
|
if (snp->snp_len == 0) {
|
1995-02-14 21:21:26 +00:00
|
|
|
if (snp->snp_flags & SNOOP_NBIO) {
|
|
|
|
return EWOULDBLOCK;
|
|
|
|
}
|
1995-02-15 16:35:38 +00:00
|
|
|
snp->snp_flags |= SNOOP_RWAIT;
|
|
|
|
tsleep((caddr_t) snp, (PZERO + 1) | PCATCH, "snoopread", 0);
|
1995-02-14 21:21:26 +00:00
|
|
|
}
|
|
|
|
} while (snp->snp_len == 0);
|
|
|
|
|
1995-02-15 16:35:38 +00:00
|
|
|
n = snp->snp_len;
|
1995-02-14 21:21:26 +00:00
|
|
|
|
1995-02-15 16:35:38 +00:00
|
|
|
while (snp->snp_len > 0 && uio->uio_resid > 0 && error == 0) {
|
|
|
|
len = MIN(uio->uio_resid, snp->snp_len);
|
|
|
|
from = (caddr_t) (snp->snp_buf + snp->snp_base);
|
1995-02-14 21:21:26 +00:00
|
|
|
if (len == 0)
|
|
|
|
break;
|
|
|
|
|
1995-02-15 16:35:38 +00:00
|
|
|
error = uiomove(from, len, uio);
|
|
|
|
snp->snp_base += len;
|
|
|
|
snp->snp_len -= len;
|
1995-02-14 21:21:26 +00:00
|
|
|
}
|
1995-02-15 16:35:38 +00:00
|
|
|
if ((snp->snp_flags & SNOOP_OFLOW) && (n < snp->snp_len)) {
|
1995-02-14 21:21:26 +00:00
|
|
|
snp->snp_flags &= ~SNOOP_OFLOW;
|
1995-02-15 16:35:38 +00:00
|
|
|
}
|
|
|
|
s = spltty();
|
|
|
|
nblen = snp->snp_blen;
|
|
|
|
if (((nblen / 2) >= SNOOP_MINLEN) && (nblen / 2) >= snp->snp_len) {
|
|
|
|
while (((nblen / 2) >= snp->snp_len) && ((nblen / 2) >= SNOOP_MINLEN))
|
|
|
|
nblen = nblen / 2;
|
|
|
|
if (nbuf = malloc(nblen, M_TTYS, M_NOWAIT)) {
|
|
|
|
bcopy(snp->snp_buf + snp->snp_base, nbuf, snp->snp_len);
|
|
|
|
free(snp->snp_buf, M_TTYS);
|
|
|
|
snp->snp_buf = nbuf;
|
|
|
|
snp->snp_blen = nblen;
|
|
|
|
snp->snp_base = 0;
|
1995-02-14 21:21:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
1995-02-15 16:35:38 +00:00
|
|
|
snpin(snp, buf, n)
|
|
|
|
struct snoop *snp;
|
|
|
|
char *buf;
|
|
|
|
int n;
|
1995-02-14 21:21:26 +00:00
|
|
|
{
|
1995-02-15 16:35:38 +00:00
|
|
|
int s_free, s_tail;
|
|
|
|
int s, len, nblen;
|
|
|
|
caddr_t from, to;
|
|
|
|
char *nbuf;
|
|
|
|
struct tty_tab *l_tty;
|
|
|
|
struct tty *tp;
|
1995-02-14 21:21:26 +00:00
|
|
|
|
|
|
|
|
1995-02-15 16:35:38 +00:00
|
|
|
if (n == 0)
|
1995-02-14 21:21:26 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (n < 0)
|
|
|
|
panic("bad snoop char count");
|
|
|
|
|
1995-02-15 16:35:38 +00:00
|
|
|
if (!(snp->snp_flags & SNOOP_OPEN)) {
|
|
|
|
printf("Snoop: data coming to closed device.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (snp->snp_flags & SNOOP_DOWN) {
|
|
|
|
printf("Snoop: more data to down interface.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
1995-02-15 18:41:57 +00:00
|
|
|
|
1995-02-15 16:35:38 +00:00
|
|
|
if (snp->snp_flags & SNOOP_OFLOW) {
|
|
|
|
printf("Snoop: buffer overflow.\n");
|
|
|
|
/*
|
|
|
|
* On overflow we just repeat the standart close
|
|
|
|
* procedure...yes , this is waste of space but.. Then next
|
|
|
|
* read from device will fail if one would recall he is
|
|
|
|
* snooping and retry...
|
|
|
|
*/
|
|
|
|
|
1995-02-15 18:41:57 +00:00
|
|
|
return (snpdown(snp));
|
1995-02-15 16:35:38 +00:00
|
|
|
}
|
|
|
|
s_tail = snp->snp_blen - (snp->snp_len + snp->snp_base);
|
|
|
|
s_free = snp->snp_blen - snp->snp_len;
|
1995-02-14 21:21:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (n > s_free) {
|
1995-02-15 16:35:38 +00:00
|
|
|
s = spltty();
|
|
|
|
nblen = snp->snp_blen;
|
|
|
|
while ((n > s_free) && ((nblen * 2) <= SNOOP_MAXLEN)) {
|
|
|
|
nblen = snp->snp_blen * 2;
|
|
|
|
s_free = nblen - (snp->snp_len + snp->snp_base);
|
1995-02-14 21:21:26 +00:00
|
|
|
}
|
1995-02-15 16:35:38 +00:00
|
|
|
if ((n <= s_free) && (nbuf = malloc(nblen, M_TTYS, M_NOWAIT))) {
|
|
|
|
bcopy(snp->snp_buf + snp->snp_base, nbuf, snp->snp_len);
|
|
|
|
free(snp->snp_buf, M_TTYS);
|
|
|
|
snp->snp_buf = nbuf;
|
|
|
|
snp->snp_blen = nblen;
|
|
|
|
snp->snp_base = 0;
|
1995-02-14 21:21:26 +00:00
|
|
|
} else {
|
1995-02-15 16:35:38 +00:00
|
|
|
snp->snp_flags |= SNOOP_OFLOW;
|
1995-02-14 21:21:26 +00:00
|
|
|
if (snp->snp_flags & SNOOP_RWAIT) {
|
1995-02-15 16:35:38 +00:00
|
|
|
snp->snp_flags &= ~SNOOP_RWAIT;
|
|
|
|
wakeup((caddr_t) snp);
|
|
|
|
}
|
1995-02-14 21:21:26 +00:00
|
|
|
splx(s);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
if (n > s_tail) {
|
1995-02-15 16:35:38 +00:00
|
|
|
from = (caddr_t) (snp->snp_buf + snp->snp_base);
|
|
|
|
to = (caddr_t) (snp->snp_buf);
|
|
|
|
len = snp->snp_len;
|
|
|
|
bcopy(from, to, len);
|
|
|
|
snp->snp_base = 0;
|
1995-02-14 21:21:26 +00:00
|
|
|
}
|
1995-02-15 16:35:38 +00:00
|
|
|
to = (caddr_t) (snp->snp_buf + snp->snp_base + snp->snp_len);
|
|
|
|
bcopy(buf, to, n);
|
|
|
|
snp->snp_len += n;
|
1995-02-14 21:21:26 +00:00
|
|
|
|
|
|
|
if (snp->snp_flags & SNOOP_RWAIT) {
|
1995-02-15 16:35:38 +00:00
|
|
|
snp->snp_flags &= ~SNOOP_RWAIT;
|
|
|
|
wakeup((caddr_t) snp);
|
|
|
|
}
|
1995-02-14 21:21:26 +00:00
|
|
|
selwakeup(&snp->snp_sel);
|
1995-02-15 16:35:38 +00:00
|
|
|
snp->snp_sel.si_pid = 0;
|
1995-02-14 21:21:26 +00:00
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
snpopen(dev, flag, mode, p)
|
1995-02-15 16:35:38 +00:00
|
|
|
dev_t dev;
|
|
|
|
int flag, mode;
|
|
|
|
struct proc *p;
|
1995-02-14 21:21:26 +00:00
|
|
|
{
|
1995-02-15 16:35:38 +00:00
|
|
|
struct snoop *snp;
|
|
|
|
register int unit, error;
|
1995-02-14 21:21:26 +00:00
|
|
|
|
|
|
|
if (error = suser(p->p_ucred, &p->p_acflag))
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
if ((unit = minor(dev)) >= NSNP)
|
|
|
|
return (ENXIO);
|
|
|
|
snp = &snoopsw[unit];
|
|
|
|
if (snp->snp_flags & SNOOP_OPEN)
|
|
|
|
return (ENXIO);
|
1995-02-15 16:35:38 +00:00
|
|
|
/*
|
|
|
|
* We intentionally do not OR flags with SNOOP_OPEN,but set them so
|
|
|
|
* all previous settings (especially SNOOP_OFLOW) will be cleared.
|
|
|
|
*/
|
|
|
|
snp->snp_flags = SNOOP_OPEN;
|
1995-02-14 21:21:26 +00:00
|
|
|
|
1995-02-15 16:35:38 +00:00
|
|
|
snp->snp_buf = malloc(SNOOP_MINLEN, M_TTYS, M_WAITOK);
|
|
|
|
snp->snp_blen = SNOOP_MINLEN;
|
|
|
|
snp->snp_base = 0;
|
|
|
|
snp->snp_len = 0;
|
1995-02-14 21:21:26 +00:00
|
|
|
|
|
|
|
/*
|
1995-02-15 16:35:38 +00:00
|
|
|
* unit == -1 is for inactive snoop devices.
|
1995-02-14 21:21:26 +00:00
|
|
|
*/
|
1995-02-15 16:35:38 +00:00
|
|
|
snp->snp_unit = -1;
|
1995-02-14 21:21:26 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1995-02-15 16:35:38 +00:00
|
|
|
|
1995-02-14 21:21:26 +00:00
|
|
|
int
|
1995-02-15 16:35:38 +00:00
|
|
|
snp_detach(snp)
|
|
|
|
struct snoop *snp;
|
1995-02-14 21:21:26 +00:00
|
|
|
{
|
1995-02-15 16:35:38 +00:00
|
|
|
struct tty *tp;
|
|
|
|
struct tty_tab *l_tty;
|
|
|
|
|
1995-02-14 21:21:26 +00:00
|
|
|
|
|
|
|
snp->snp_base = 0;
|
|
|
|
snp->snp_len = 0;
|
|
|
|
|
|
|
|
/*
|
1995-02-15 16:35:38 +00:00
|
|
|
* If line disc. changed we do not touch this pointer,SLIP/PPP will
|
|
|
|
* change it anyway.
|
1995-02-14 21:21:26 +00:00
|
|
|
*/
|
|
|
|
|
1995-02-15 16:35:38 +00:00
|
|
|
if (snp->snp_unit == -1)
|
1995-02-15 18:41:57 +00:00
|
|
|
goto detach_notty;
|
1995-02-15 16:35:38 +00:00
|
|
|
|
1995-02-14 21:21:26 +00:00
|
|
|
|
1995-02-15 16:35:38 +00:00
|
|
|
l_tty = &tty_tabs[snp->snp_type];
|
|
|
|
tp = &((*l_tty->lt_tab)[snp->snp_unit]);
|
1995-02-14 21:21:26 +00:00
|
|
|
|
1995-02-15 16:35:38 +00:00
|
|
|
if ((tp->t_sc == snp) && (tp->t_state & TS_SNOOP) &&
|
|
|
|
(tp->t_line == OTTYDISC || tp->t_line == NTTYDISC)) {
|
1995-02-14 21:21:26 +00:00
|
|
|
tp->t_sc = NULL;
|
1995-02-15 16:35:38 +00:00
|
|
|
tp->t_state &= ~TS_SNOOP;
|
|
|
|
} else
|
|
|
|
printf("Snoop: bad attached tty data.\n");
|
1995-02-14 21:21:26 +00:00
|
|
|
|
1995-02-15 16:35:38 +00:00
|
|
|
snp->snp_unit = -1;
|
|
|
|
|
1995-02-15 18:41:57 +00:00
|
|
|
detach_notty:
|
1995-02-14 21:21:26 +00:00
|
|
|
selwakeup(&snp->snp_sel);
|
1995-02-15 16:35:38 +00:00
|
|
|
snp->snp_sel.si_pid = 0;
|
1995-02-14 21:21:26 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1995-02-15 16:35:38 +00:00
|
|
|
int
|
|
|
|
snpclose(dev, flag)
|
|
|
|
dev_t dev;
|
|
|
|
int flag;
|
|
|
|
{
|
|
|
|
register int unit = minor(dev);
|
|
|
|
struct snoop *snp = &snoopsw[unit];
|
|
|
|
|
|
|
|
snp->snp_blen = 0;
|
|
|
|
free(snp->snp_buf, M_TTYS);
|
|
|
|
snp->snp_flags &= ~SNOOP_OPEN;
|
|
|
|
|
|
|
|
return (snp_detach(snp));
|
|
|
|
}
|
|
|
|
|
1995-02-15 18:41:57 +00:00
|
|
|
int
|
|
|
|
snpdown(snp)
|
|
|
|
struct snoop *snp;
|
|
|
|
{
|
|
|
|
snp->snp_blen = SNOOP_MINLEN;
|
|
|
|
free(snp->snp_buf, M_TTYS);
|
|
|
|
snp->snp_buf = malloc(SNOOP_MINLEN, M_TTYS, M_WAITOK);
|
|
|
|
snp->snp_flags |= SNOOP_DOWN;
|
1995-02-14 21:21:26 +00:00
|
|
|
|
1995-02-15 18:41:57 +00:00
|
|
|
return (snp_detach(snp));
|
|
|
|
}
|
1995-02-14 21:21:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
snpioctl(dev, cmd, data, flag)
|
1995-02-15 16:35:38 +00:00
|
|
|
dev_t dev;
|
|
|
|
int cmd;
|
|
|
|
caddr_t data;
|
|
|
|
int flag;
|
1995-02-14 21:21:26 +00:00
|
|
|
{
|
1995-02-15 16:35:38 +00:00
|
|
|
int unit = minor(dev), s;
|
|
|
|
int tunit, ttype;
|
|
|
|
struct snoop *snp = &snoopsw[unit];
|
|
|
|
struct tty *tp, *tpo;
|
|
|
|
struct tty_tab *l_tty, *l_otty;
|
1995-02-14 21:21:26 +00:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case SNPSTTY:
|
1995-02-15 16:35:38 +00:00
|
|
|
tunit = ((struct snptty *) data)->st_unit;
|
|
|
|
ttype = ((struct snptty *) data)->st_type;
|
1995-02-14 21:21:26 +00:00
|
|
|
|
1995-02-15 18:41:57 +00:00
|
|
|
if (ttype == -1 || tunit == -1)
|
|
|
|
return (snpdown(snp));
|
|
|
|
|
1995-02-14 21:21:26 +00:00
|
|
|
if (ttype < 0 || ttype > ST_MAXTYPE)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
l_tty = &tty_tabs[ttype];
|
|
|
|
if (l_tty->lt_tab == NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
if (tunit < 0 || tunit >= l_tty->lt_max)
|
|
|
|
return (EINVAL);
|
|
|
|
|
1995-02-15 16:35:38 +00:00
|
|
|
tp = &((*l_tty->lt_tab)[tunit]);
|
1995-02-14 21:21:26 +00:00
|
|
|
|
1995-02-15 16:35:38 +00:00
|
|
|
if (tp->t_sc != (caddr_t) snp && (tp->t_state & TS_SNOOP))
|
1995-02-14 21:21:26 +00:00
|
|
|
return (EBUSY);
|
|
|
|
|
1995-02-15 16:35:38 +00:00
|
|
|
if (tp->t_line != OTTYDISC && tp->t_line != NTTYDISC)
|
1995-02-14 21:21:26 +00:00
|
|
|
return (EBUSY);
|
|
|
|
|
1995-02-15 16:35:38 +00:00
|
|
|
s = spltty();
|
1995-02-14 21:21:26 +00:00
|
|
|
if (snp->snp_unit != -1) {
|
1995-02-15 16:35:38 +00:00
|
|
|
l_otty = &tty_tabs[snp->snp_type];
|
|
|
|
tpo = &((*l_otty->lt_tab)[snp->snp_unit]);
|
|
|
|
tpo->t_state &= ~TS_SNOOP;
|
1995-02-14 21:21:26 +00:00
|
|
|
}
|
1995-02-15 16:35:38 +00:00
|
|
|
tp->t_sc = (caddr_t) snp;
|
1995-02-14 21:21:26 +00:00
|
|
|
tp->t_state |= TS_SNOOP;
|
|
|
|
snp->snp_unit = tunit;
|
1995-02-15 16:35:38 +00:00
|
|
|
snp->snp_type = ttype;
|
1995-02-15 18:41:57 +00:00
|
|
|
/*
|
|
|
|
* Clean overflow and down flags -
|
|
|
|
* we'll have a chance to get them in the future :)))
|
|
|
|
*/
|
|
|
|
snp->snp_flags &= ~SNOOP_OFLOW;
|
1995-02-15 16:35:38 +00:00
|
|
|
snp->snp_flags &= ~SNOOP_DOWN;
|
1995-02-14 21:21:26 +00:00
|
|
|
splx(s);
|
|
|
|
|
|
|
|
break;
|
|
|
|
case SNPGTTY:
|
1995-02-15 16:35:38 +00:00
|
|
|
((struct snptty *) data)->st_unit = snp->snp_unit;
|
|
|
|
((struct snptty *) data)->st_type = snp->snp_type;
|
1995-02-14 21:21:26 +00:00
|
|
|
break;
|
1995-02-15 16:35:38 +00:00
|
|
|
|
1995-02-14 21:21:26 +00:00
|
|
|
case FIONBIO:
|
1995-02-15 16:35:38 +00:00
|
|
|
if (*(int *) data)
|
1995-02-14 21:21:26 +00:00
|
|
|
snp->snp_flags |= SNOOP_NBIO;
|
|
|
|
else
|
|
|
|
snp->snp_flags &= ~SNOOP_NBIO;
|
|
|
|
break;
|
|
|
|
case FIOASYNC:
|
1995-02-15 16:35:38 +00:00
|
|
|
if (*(int *) data)
|
1995-02-14 21:21:26 +00:00
|
|
|
snp->snp_flags |= SNOOP_ASYNC;
|
|
|
|
else
|
|
|
|
snp->snp_flags &= ~SNOOP_ASYNC;
|
|
|
|
break;
|
|
|
|
case FIONREAD:
|
|
|
|
s = spltty();
|
1995-02-15 16:35:38 +00:00
|
|
|
if (snp->snp_unit != -1)
|
|
|
|
*(int *) data = snp->snp_len;
|
1995-02-15 18:41:57 +00:00
|
|
|
else
|
|
|
|
if (snp->snp_flags&SNOOP_DOWN) {
|
|
|
|
if (snp->snp_flags&SNOOP_OFLOW)
|
|
|
|
*(int *) data = SNP_OFLOW;
|
|
|
|
else
|
|
|
|
*(int *) data = SNP_TTYCLOSE;
|
|
|
|
} else {
|
|
|
|
*(int *) data = SNP_DETACH;
|
|
|
|
}
|
1995-02-14 21:21:26 +00:00
|
|
|
splx(s);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (ENOTTY);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
snpselect(dev, rw, p)
|
1995-02-15 16:35:38 +00:00
|
|
|
dev_t dev;
|
|
|
|
int rw;
|
|
|
|
struct proc *p;
|
1995-02-14 21:21:26 +00:00
|
|
|
{
|
1995-02-15 16:35:38 +00:00
|
|
|
int unit = minor(dev), s;
|
|
|
|
struct snoop *snp = &snoopsw[unit];
|
1995-02-14 21:21:26 +00:00
|
|
|
|
1995-02-15 16:35:38 +00:00
|
|
|
if (rw != FREAD) {
|
|
|
|
return 0;
|
1995-02-14 21:21:26 +00:00
|
|
|
}
|
|
|
|
if (snp->snp_len > 0) {
|
1995-02-15 16:35:38 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If snoop is down,we don't want to select() forever so we return 1.
|
|
|
|
* Caller should see if we down via FIONREAD ioctl().The last should
|
|
|
|
* return -1 to indicate down state.
|
|
|
|
*/
|
|
|
|
if (snp->snp_flags & SNOOP_DOWN) {
|
|
|
|
return 1;
|
|
|
|
}
|
1995-02-14 21:21:26 +00:00
|
|
|
selrecord(p, &snp->snp_sel);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|