diff --git a/sys/adosfs/advnops.c b/sys/adosfs/advnops.c index 9b146ca8fa7c..c87686039e07 100644 --- a/sys/adosfs/advnops.c +++ b/sys/adosfs/advnops.c @@ -1,4 +1,4 @@ -/* $NetBSD: advnops.c,v 1.63 2002/08/04 05:42:43 soren Exp $ */ +/* $NetBSD: advnops.c,v 1.64 2002/10/23 09:10:23 jdolecek Exp $ */ /* * Copyright (c) 1994 Christian E. Hopps @@ -32,7 +32,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: advnops.c,v 1.63 2002/08/04 05:42:43 soren Exp $"); +__KERNEL_RCSID(0, "$NetBSD: advnops.c,v 1.64 2002/10/23 09:10:23 jdolecek Exp $"); #if defined(_KERNEL_OPT) #include "opt_quota.h" @@ -117,6 +117,7 @@ const struct vnodeopv_entry_desc adosfs_vnodeop_entries[] = { { &vop_fcntl_desc, adosfs_fcntl }, /* fcntl */ { &vop_ioctl_desc, adosfs_ioctl }, /* ioctl */ { &vop_poll_desc, adosfs_poll }, /* poll */ + { &vop_kqfilter_desc, genfs_kqfilter }, /* kqfilter */ { &vop_revoke_desc, adosfs_revoke }, /* revoke */ { &vop_mmap_desc, adosfs_mmap }, /* mmap */ { &vop_fsync_desc, adosfs_fsync }, /* fsync */ diff --git a/sys/altq/altq_conf.c b/sys/altq/altq_conf.c index b9051e2101fb..746bfa8a6d25 100644 --- a/sys/altq/altq_conf.c +++ b/sys/altq/altq_conf.c @@ -1,4 +1,4 @@ -/* $NetBSD: altq_conf.c,v 1.9 2002/09/22 20:09:15 jdolecek Exp $ */ +/* $NetBSD: altq_conf.c,v 1.10 2002/10/23 09:10:25 jdolecek Exp $ */ /* $KAME: altq_conf.c,v 1.13 2002/01/29 10:16:01 kjc Exp $ */ /* @@ -28,7 +28,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: altq_conf.c,v 1.9 2002/09/22 20:09:15 jdolecek Exp $"); +__KERNEL_RCSID(0, "$NetBSD: altq_conf.c,v 1.10 2002/10/23 09:10:25 jdolecek Exp $"); #if defined(__FreeBSD__) || defined(__NetBSD__) #include "opt_altq.h" @@ -204,7 +204,7 @@ static struct cdevsw altq_cdevsw = #if defined(__NetBSD__) const struct cdevsw altq_cdevsw = { altqopen, altqclose, noread, nowrite, altqioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter }; #endif diff --git a/sys/arch/acorn26/acorn26/mem.c b/sys/arch/acorn26/acorn26/mem.c index 7fcbeb983778..c390d585e3e5 100644 --- a/sys/arch/acorn26/acorn26/mem.c +++ b/sys/arch/acorn26/acorn26/mem.c @@ -1,4 +1,4 @@ -/* $NetBSD: mem.c,v 1.2 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: mem.c,v 1.3 2002/10/23 09:10:25 jdolecek Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -65,7 +65,7 @@ dev_type_mmap(mmmmap); const struct cdevsw mem_cdevsw = { nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, mmmmap, + nostop, notty, nopoll, mmmmap, nokqfilter, }; /*ARGSUSED*/ diff --git a/sys/arch/acorn26/ioc/arcpp.c b/sys/arch/acorn26/ioc/arcpp.c index 90adc3bd7d92..99ebf89e0ef5 100644 --- a/sys/arch/acorn26/ioc/arcpp.c +++ b/sys/arch/acorn26/ioc/arcpp.c @@ -1,4 +1,4 @@ -/* $NetBSD: arcpp.c,v 1.5 2002/10/02 03:25:47 thorpej Exp $ */ +/* $NetBSD: arcpp.c,v 1.6 2002/10/23 09:10:26 jdolecek Exp $ */ /*- * Copyright (c) 2001 Ben Harris @@ -52,7 +52,7 @@ #include -__KERNEL_RCSID(0, "$NetBSD: arcpp.c,v 1.5 2002/10/02 03:25:47 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: arcpp.c,v 1.6 2002/10/23 09:10:26 jdolecek Exp $"); #include #include @@ -110,7 +110,7 @@ dev_type_write(arcppwrite); const struct cdevsw arcpp_cdevsw = { arcppopen, arcppclose, noread, arcppwrite, noioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; #define ARCPPUNIT(s) (minor(s) & 0x1f) diff --git a/sys/arch/acorn32/mainbus/fd.c b/sys/arch/acorn32/mainbus/fd.c index 97415530cfc1..6850ecced5d1 100644 --- a/sys/arch/acorn32/mainbus/fd.c +++ b/sys/arch/acorn32/mainbus/fd.c @@ -1,4 +1,4 @@ -/* $NetBSD: fd.c,v 1.10 2002/10/02 03:31:58 thorpej Exp $ */ +/* $NetBSD: fd.c,v 1.11 2002/10/23 09:10:27 jdolecek Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -281,7 +281,7 @@ const struct bdevsw fd_bdevsw = { const struct cdevsw fd_cdevsw = { fdopen, fdclose, fdread, fdwrite, fdioctl, - nostop, notty, nopoll, nommap, D_DISK + nostop, notty, nopoll, nommap, nokqfilter, D_DISK }; void fdgetdisklabel __P((struct fd_softc *)); diff --git a/sys/arch/alpha/a12/a12dc.c b/sys/arch/alpha/a12/a12dc.c index b12fbf1ecc46..f19e9665b4ee 100644 --- a/sys/arch/alpha/a12/a12dc.c +++ b/sys/arch/alpha/a12/a12dc.c @@ -1,4 +1,4 @@ -/* $NetBSD: a12dc.c,v 1.9 2002/10/02 04:06:36 thorpej Exp $ */ +/* $NetBSD: a12dc.c,v 1.10 2002/10/23 09:10:28 jdolecek Exp $ */ /* [Notice revision 2.2] * Copyright (c) 1997, 1998 Avalon Computer Systems, Inc. @@ -64,7 +64,7 @@ #ifndef BSIDE #include /* RCS ID & Copyright macro defns */ -__KERNEL_RCSID(0, "$NetBSD: a12dc.c,v 1.9 2002/10/02 04:06:36 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: a12dc.c,v 1.10 2002/10/23 09:10:28 jdolecek Exp $"); #include #include @@ -117,7 +117,7 @@ dev_type_poll(a12dcpoll); const struct cdevsw a12dc_cdevsw = { a12dcopen, a12dcclose, a12dcread, a12dcwrite, a12dcioctl, - a12dcstop, a12dctty, a12dcpoll, nommap, D_TTY + a12dcstop, a12dctty, a12dcpoll, nommap, ttykqfilter, D_TTY }; int a12dcfound; /* There Can Be Only One. */ @@ -164,7 +164,7 @@ a12dcattach(parent, self, aux) /* note that we've attached the chipset; can't have 2 A12Cs. */ a12dcfound = 1; - printf(": driver %s\n", "$Revision: 1.9 $"); + printf(": driver %s\n", "$Revision: 1.10 $"); tp = a12dc_tty[0] = ttymalloc(); tp->t_oproc = a12dcstart; diff --git a/sys/arch/alpha/alpha/mem.c b/sys/arch/alpha/alpha/mem.c index a5018ef109d1..130fac196a99 100644 --- a/sys/arch/alpha/alpha/mem.c +++ b/sys/arch/alpha/alpha/mem.c @@ -1,4 +1,4 @@ -/* $NetBSD: mem.c,v 1.32 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: mem.c,v 1.33 2002/10/23 09:10:28 jdolecek Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -46,7 +46,7 @@ #include /* RCS ID & Copyright macro defns */ -__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.32 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.33 2002/10/23 09:10:28 jdolecek Exp $"); #include #include @@ -72,7 +72,7 @@ dev_type_mmap(mmmmap); const struct cdevsw mem_cdevsw = { nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, mmmmap, + nostop, notty, nopoll, mmmmap, nokqfilter, }; /*ARGSUSED*/ diff --git a/sys/arch/alpha/alpha/promcons.c b/sys/arch/alpha/alpha/promcons.c index a5b52d8b2b51..8245329b55ba 100644 --- a/sys/arch/alpha/alpha/promcons.c +++ b/sys/arch/alpha/alpha/promcons.c @@ -1,4 +1,4 @@ -/* $NetBSD: promcons.c,v 1.20 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: promcons.c,v 1.21 2002/10/23 09:10:29 jdolecek Exp $ */ /* * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University. @@ -29,7 +29,7 @@ #include /* RCS ID & Copyright macro defns */ -__KERNEL_RCSID(0, "$NetBSD: promcons.c,v 1.20 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: promcons.c,v 1.21 2002/10/23 09:10:29 jdolecek Exp $"); #include #include @@ -64,7 +64,7 @@ dev_type_poll(prompoll); const struct cdevsw prom_cdevsw = { promopen, promclose, promread, promwrite, promioctl, - promstop, promtty, prompoll, nommap, D_TTY + promstop, promtty, prompoll, nommap, ttykqfilter, D_TTY }; #define PROM_POLL_HZ 50 diff --git a/sys/arch/amiga/amiga/mem.c b/sys/arch/amiga/amiga/mem.c index cf700d91f249..73fff3e9c2af 100644 --- a/sys/arch/amiga/amiga/mem.c +++ b/sys/arch/amiga/amiga/mem.c @@ -1,4 +1,4 @@ -/* $NetBSD: mem.c,v 1.35 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: mem.c,v 1.36 2002/10/23 09:10:29 jdolecek Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -41,7 +41,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.35 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.36 2002/10/23 09:10:29 jdolecek Exp $"); /* * Memory special file @@ -73,7 +73,7 @@ dev_type_ioctl(mmioctl); const struct cdevsw mem_cdevsw = { nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; /*ARGSUSED*/ diff --git a/sys/arch/amiga/dev/event.c b/sys/arch/amiga/dev/event.c index da4160e67319..1c4dba310256 100644 --- a/sys/arch/amiga/dev/event.c +++ b/sys/arch/amiga/dev/event.c @@ -1,4 +1,4 @@ -/* $NetBSD: event.c,v 1.7 2002/01/28 09:56:54 aymeric Exp $ */ +/* $NetBSD: event.c,v 1.8 2002/10/23 09:10:30 jdolecek Exp $ */ /* * Copyright (c) 1992, 1993 @@ -47,7 +47,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: event.c,v 1.7 2002/01/28 09:56:54 aymeric Exp $"); +__KERNEL_RCSID(0, "$NetBSD: event.c,v 1.8 2002/10/23 09:10:30 jdolecek Exp $"); /* * Internal `Firm_event' interface for the keyboard and mouse drivers. @@ -162,3 +162,61 @@ ev_poll(register struct evvar *ev, int events, struct proc *p) splx(s); return (revents); } + +static void +filt_evrdetach(struct knote *kn) +{ + struct evvar *ev = kn->kn_hook; + int s; + + s = splev(); + SLIST_REMOVE(&ev->ev_sel.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_evread(struct knote *kn, long hint) +{ + struct evvar *ev = kn->kn_hook; + + if (ev->ev_get == ev->ev_put) + return (0); + + if (ev->ev_get < ev->ev_put) + kn->kn_data = ev->ev_put - ev->ev_get; + else + kn->kn_data = (EV_QSIZE - ev->ev_get) + + ev->ev_put; + + kn->kn_data *= sizeof(struct firm_event); + + return (1); +} + +static const struct filterops ev_filtops = + { 1, NULL, filt_evrdetach, filt_evread }; + +int +ev_kqfilter(struct evvar *ev, struct knote *kn) +{ + struct klist *klist; + int s; + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &ev->ev_sel.si_klist; + kn->kn_fop = &ev_filtops; + break; + + default: + return (1); + } + + kn->kn_hook = ev; + + s = splev(); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + splx(s); + + return (0); +} diff --git a/sys/arch/amiga/dev/event_var.h b/sys/arch/amiga/dev/event_var.h index e38b9b5b412e..28dbb445e80d 100644 --- a/sys/arch/amiga/dev/event_var.h +++ b/sys/arch/amiga/dev/event_var.h @@ -1,4 +1,4 @@ -/* $NetBSD: event_var.h,v 1.4 2002/01/26 13:40:53 aymeric Exp $ */ +/* $NetBSD: event_var.h,v 1.5 2002/10/23 09:10:30 jdolecek Exp $ */ /* * Copyright (c) 1992, 1993 @@ -68,7 +68,7 @@ struct evvar { #define splev() spltty() #define EV_WAKEUP(ev) { \ - selwakeup(&(ev)->ev_sel); \ + selnotify(&(ev)->ev_sel, 0); \ if ((ev)->ev_wanted) { \ (ev)->ev_wanted = 0; \ wakeup((caddr_t)(ev)); \ @@ -81,6 +81,7 @@ void ev_init(struct evvar *); void ev_fini(struct evvar *); int ev_read(struct evvar *, struct uio *, int); int ev_poll(struct evvar *, int, struct proc *); +int ev_kqfilter(struct evvar *, struct knote *); /* * PEVENT is set just above PSOCK, which is just above TTIPRI, on the diff --git a/sys/arch/amiga/dev/fd.c b/sys/arch/amiga/dev/fd.c index 36884d0c2099..e35a12a819eb 100644 --- a/sys/arch/amiga/dev/fd.c +++ b/sys/arch/amiga/dev/fd.c @@ -1,4 +1,4 @@ -/* $NetBSD: fd.c,v 1.54 2002/10/02 04:55:49 thorpej Exp $ */ +/* $NetBSD: fd.c,v 1.55 2002/10/23 09:10:31 jdolecek Exp $ */ /* * Copyright (c) 1994 Christian E. Hopps @@ -33,7 +33,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: fd.c,v 1.54 2002/10/02 04:55:49 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: fd.c,v 1.55 2002/10/23 09:10:31 jdolecek Exp $"); #include #include @@ -257,7 +257,7 @@ const struct bdevsw fd_bdevsw = { const struct cdevsw fd_cdevsw = { fdopen, fdclose, fdread, fdwrite, fdioctl, - nostop, notty, nopoll, nommap, D_DISK + nostop, notty, nopoll, nommap, nokqfilter, D_DISK }; struct dkdriver fddkdriver = { fdstrategy }; diff --git a/sys/arch/amiga/dev/grf.c b/sys/arch/amiga/dev/grf.c index 3f7dd375d656..7361ed27b6e0 100644 --- a/sys/arch/amiga/dev/grf.c +++ b/sys/arch/amiga/dev/grf.c @@ -1,4 +1,4 @@ -/* $NetBSD: grf.c,v 1.45 2002/10/10 22:33:15 jdolecek Exp $ */ +/* $NetBSD: grf.c,v 1.46 2002/10/23 09:10:32 jdolecek Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -43,7 +43,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: grf.c,v 1.45 2002/10/10 22:33:15 jdolecek Exp $"); +__KERNEL_RCSID(0, "$NetBSD: grf.c,v 1.46 2002/10/23 09:10:32 jdolecek Exp $"); /* * Graphics display driver for the Amiga @@ -105,7 +105,7 @@ dev_type_mmap(grfmmap); const struct cdevsw grf_cdevsw = { grfopen, grfclose, nullread, nullwrite, grfioctl, - nostop, notty, nopoll, grfmmap, + nostop, notty, nopoll, grfmmap, nokqfilter, }; /* diff --git a/sys/arch/amiga/dev/ite.c b/sys/arch/amiga/dev/ite.c index d69090c11705..140523f66f00 100644 --- a/sys/arch/amiga/dev/ite.c +++ b/sys/arch/amiga/dev/ite.c @@ -1,4 +1,4 @@ -/* $NetBSD: ite.c,v 1.63 2002/10/02 04:55:51 thorpej Exp $ */ +/* $NetBSD: ite.c,v 1.64 2002/10/23 09:10:32 jdolecek Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -50,7 +50,7 @@ #include "opt_ddb.h" #include -__KERNEL_RCSID(0, "$NetBSD: ite.c,v 1.63 2002/10/02 04:55:51 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ite.c,v 1.64 2002/10/23 09:10:32 jdolecek Exp $"); #include #include @@ -169,7 +169,7 @@ dev_type_poll(itepoll); const struct cdevsw ite_cdevsw = { iteopen, iteclose, iteread, itewrite, iteioctl, - nostop, itetty, itepoll, nommap, D_TTY + nostop, itetty, itepoll, nommap, ttykqfilter, D_TTY }; int diff --git a/sys/arch/amiga/dev/kbd.c b/sys/arch/amiga/dev/kbd.c index 30c6c9bb189a..6bd8318cc885 100644 --- a/sys/arch/amiga/dev/kbd.c +++ b/sys/arch/amiga/dev/kbd.c @@ -1,4 +1,4 @@ -/* $NetBSD: kbd.c,v 1.42 2002/10/02 04:55:52 thorpej Exp $ */ +/* $NetBSD: kbd.c,v 1.43 2002/10/23 09:10:33 jdolecek Exp $ */ /* * Copyright (c) 1982, 1986, 1990 The Regents of the University of California. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kbd.c,v 1.42 2002/10/02 04:55:52 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kbd.c,v 1.43 2002/10/23 09:10:33 jdolecek Exp $"); #include #include @@ -170,10 +170,11 @@ dev_type_close(kbdclose); dev_type_read(kbdread); dev_type_ioctl(kbdioctl); dev_type_poll(kbdpoll); +dev_type_kqfilter(kbdkqfilter); const struct cdevsw kbd_cdevsw = { kbdopen, kbdclose, kbdread, nowrite, kbdioctl, - nostop, notty, kbdpoll, nommap, + nostop, notty, kbdpoll, nommap, kbdkqfilter, }; /*ARGSUSED*/ @@ -513,6 +514,14 @@ kbdpoll(dev_t dev, int events, struct proc *p) return ev_poll (&kbd_softc.k_events, events, p); } +int +kbdkqfilter(dev, kn) + dev_t dev; + struct knote *kn; +{ + + return (ev_kqfilter(&kbd_softc.k_events, kn)); +} void kbdintr(int mask) diff --git a/sys/arch/amiga/dev/mfc.c b/sys/arch/amiga/dev/mfc.c index cc18630f79ce..660a1120bbd2 100644 --- a/sys/arch/amiga/dev/mfc.c +++ b/sys/arch/amiga/dev/mfc.c @@ -1,4 +1,4 @@ -/* $NetBSD: mfc.c,v 1.31 2002/10/02 04:55:52 thorpej Exp $ */ +/* $NetBSD: mfc.c,v 1.32 2002/10/23 09:10:34 jdolecek Exp $ */ /* * Copyright (c) 1994 Michael L. Hitch @@ -37,7 +37,7 @@ #include "opt_kgdb.h" #include -__KERNEL_RCSID(0, "$NetBSD: mfc.c,v 1.31 2002/10/02 04:55:52 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mfc.c,v 1.32 2002/10/23 09:10:34 jdolecek Exp $"); #include #include @@ -230,7 +230,7 @@ dev_type_poll(mfcspoll); const struct cdevsw mfcs_cdevsw = { mfcsopen, mfcsclose, mfcsread, mfcswrite, mfcsioctl, - mfcsstop, mfcstty, mfcspoll, nommap, D_TTY + mfcsstop, mfcstty, mfcspoll, nommap, ttykqfilter, D_TTY }; int mfcs_active; diff --git a/sys/arch/amiga/dev/ms.c b/sys/arch/amiga/dev/ms.c index d94f2e0782d7..9fe276888cc5 100644 --- a/sys/arch/amiga/dev/ms.c +++ b/sys/arch/amiga/dev/ms.c @@ -1,4 +1,4 @@ -/* $NetBSD: ms.c,v 1.23 2002/10/02 04:55:52 thorpej Exp $ */ +/* $NetBSD: ms.c,v 1.24 2002/10/23 09:10:34 jdolecek Exp $ */ /* * based on: @@ -49,7 +49,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ms.c,v 1.23 2002/10/02 04:55:52 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ms.c,v 1.24 2002/10/23 09:10:34 jdolecek Exp $"); /* * Mouse driver. @@ -114,10 +114,11 @@ dev_type_close(msclose); dev_type_read(msread); dev_type_ioctl(msioctl); dev_type_poll(mspoll); +dev_type_kqfilter(mskqfilter); const struct cdevsw ms_cdevsw = { msopen, msclose, msread, nowrite, msioctl, - nostop, notty, mspoll, nommap, + nostop, notty, mspoll, nommap, mskqfilter, }; #define MS_UNIT(d) ((minor(d) & ~0x1) >> 1) @@ -446,3 +447,15 @@ mspoll(dev_t dev, int events, struct proc *p) return(ev_poll(&ms->ms_events, events, p)); } + +int +mskqfilter(dev, kn) + dev_t dev; + struct knote *kn; +{ + struct ms_port *ms; + + ms = MS_DEV2MSPORT(dev); + + return (ev_kqfilter(&ms->ms_events, kn)); +} diff --git a/sys/arch/amiga/dev/msc.c b/sys/arch/amiga/dev/msc.c index 78197cc5d009..a21b45f63f69 100644 --- a/sys/arch/amiga/dev/msc.c +++ b/sys/arch/amiga/dev/msc.c @@ -1,4 +1,4 @@ -/* $NetBSD: msc.c,v 1.25 2002/10/02 04:55:52 thorpej Exp $ */ +/* $NetBSD: msc.c,v 1.26 2002/10/23 09:10:35 jdolecek Exp $ */ /* * Copyright (c) 1993 Zik. @@ -52,7 +52,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: msc.c,v 1.25 2002/10/02 04:55:52 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: msc.c,v 1.26 2002/10/23 09:10:35 jdolecek Exp $"); #include "msc.h" @@ -186,7 +186,7 @@ dev_type_poll(mscpoll); const struct cdevsw msc_cdevsw = { mscopen, mscclose, mscread, mscwrite, mscioctl, - mscstop, msctty, mscpoll, nommap, D_TTY + mscstop, msctty, mscpoll, nommap, ttykqfilter, D_TTY }; int diff --git a/sys/arch/amiga/dev/par.c b/sys/arch/amiga/dev/par.c index 3a4eebe28534..7554b2e60f04 100644 --- a/sys/arch/amiga/dev/par.c +++ b/sys/arch/amiga/dev/par.c @@ -1,4 +1,4 @@ -/* $NetBSD: par.c,v 1.28 2002/10/02 04:55:52 thorpej Exp $ */ +/* $NetBSD: par.c,v 1.29 2002/10/23 09:10:35 jdolecek Exp $ */ /* * Copyright (c) 1982, 1990 The Regents of the University of California. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: par.c,v 1.28 2002/10/02 04:55:52 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: par.c,v 1.29 2002/10/23 09:10:35 jdolecek Exp $"); /* * parallel port interface @@ -119,7 +119,7 @@ dev_type_ioctl(parioctl); const struct cdevsw par_cdevsw = { paropen, parclose, parread, parwrite, parioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; /*ARGSUSED*/ diff --git a/sys/arch/amiga/dev/ser.c b/sys/arch/amiga/dev/ser.c index 68bd335b9e83..a1b7b9adb39d 100644 --- a/sys/arch/amiga/dev/ser.c +++ b/sys/arch/amiga/dev/ser.c @@ -1,4 +1,4 @@ -/* $NetBSD: ser.c,v 1.67 2002/10/02 04:55:52 thorpej Exp $ */ +/* $NetBSD: ser.c,v 1.68 2002/10/23 09:10:36 jdolecek Exp $ */ /* * Copyright (c) 1982, 1986, 1990 The Regents of the University of California. @@ -44,7 +44,7 @@ #include "opt_kgdb.h" #include -__KERNEL_RCSID(0, "$NetBSD: ser.c,v 1.67 2002/10/02 04:55:52 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ser.c,v 1.68 2002/10/23 09:10:36 jdolecek Exp $"); #include #include @@ -95,7 +95,7 @@ dev_type_poll(serpoll); const struct cdevsw ser_cdevsw = { seropen, serclose, serread, serwrite, serioctl, - serstop, sertty, serpoll, nommap, D_TTY + serstop, sertty, serpoll, nommap, ttykqfilter, D_TTY }; #ifndef SEROBUF_SIZE diff --git a/sys/arch/amiga/dev/view.c b/sys/arch/amiga/dev/view.c index 3dfb6a001852..05eb21537813 100644 --- a/sys/arch/amiga/dev/view.c +++ b/sys/arch/amiga/dev/view.c @@ -1,4 +1,4 @@ -/* $NetBSD: view.c,v 1.23 2002/10/10 22:33:15 jdolecek Exp $ */ +/* $NetBSD: view.c,v 1.24 2002/10/23 09:10:37 jdolecek Exp $ */ /* * Copyright (c) 1994 Christian E. Hopps @@ -38,7 +38,7 @@ * a interface to graphics. */ #include -__KERNEL_RCSID(0, "$NetBSD: view.c,v 1.23 2002/10/10 22:33:15 jdolecek Exp $"); +__KERNEL_RCSID(0, "$NetBSD: view.c,v 1.24 2002/10/23 09:10:37 jdolecek Exp $"); #include #include @@ -81,7 +81,7 @@ dev_type_mmap(viewmmap); const struct cdevsw view_cdevsw = { viewopen, viewclose, nullread, nullwrite, viewioctl, - nostop, notty, nopoll, viewmmap, + nostop, notty, nopoll, viewmmap, nokqfilter, }; /* diff --git a/sys/arch/arc/dev/opms.c b/sys/arch/arc/dev/opms.c index 480db7246725..29abb029b6d1 100644 --- a/sys/arch/arc/dev/opms.c +++ b/sys/arch/arc/dev/opms.c @@ -1,4 +1,4 @@ -/* $NetBSD: opms.c,v 1.4 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: opms.c,v 1.5 2002/10/23 09:10:38 jdolecek Exp $ */ /* $OpenBSD: pccons.c,v 1.22 1999/01/30 22:39:37 imp Exp $ */ /* NetBSD: pms.c,v 1.21 1995/04/18 02:25:18 mycroft Exp */ @@ -101,7 +101,7 @@ dev_type_poll(opmspoll); const struct cdevsw opms_cdevsw = { opmsopen, opmsclose, opmsread, nowrite, opmsioctl, - nostop, notty, opmspoll, nommap, + nostop, notty, opmspoll, nommap, opmskqfilter, }; static __inline void pms_dev_cmd __P((u_char)); @@ -396,7 +396,7 @@ opmsintr(arg) sc->sc_state &= ~PMS_ASLP; wakeup((caddr_t)sc); } - selwakeup(&sc->sc_rsel); + selnotify(&sc->sc_rsel, 0); } break; @@ -424,3 +424,52 @@ opmspoll(dev, events, p) splx(s); return (revents); } + +static void +filt_opmsrdetach(struct knote *kn) +{ + struct opms_softc *sc = kn->kn_hook; + int s; + + s = spltty(); + SLIST_REMOVE(&sc->sc_rsel.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_opmsread(struct knote *kn, long hint) +{ + struct opms_softc *sc = kn->kn_hook; + + kn->kn_data = sc->sc_q.c_cc; + return (kn->kn_data > 0); +} + +static const struct filterops opmsread_filtops = + { 1, NULL, filt_opmsrdetach, filt_opmsread }; + +int +opmskqfilter(dev_t dev, struct knote *kn) +{ + struct opms_softc *sc = opms_cd.cd_devs[PMSUNIT(dev)]; + struct klist *klist; + int s; + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &sc->sc_rsel.si_klist; + kn->kn_fop = &opmsread_filtops; + break; + + default: + return (1); + } + + kn->kn_hook = sc; + + s = spltty(); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + splx(s); + + return (0); +} diff --git a/sys/arch/arc/dev/pccons.c b/sys/arch/arc/dev/pccons.c index 31e579a21b9a..8b1a9a96fd91 100644 --- a/sys/arch/arc/dev/pccons.c +++ b/sys/arch/arc/dev/pccons.c @@ -1,4 +1,4 @@ -/* $NetBSD: pccons.c,v 1.30 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: pccons.c,v 1.31 2002/10/23 09:10:38 jdolecek Exp $ */ /* $OpenBSD: pccons.c,v 1.22 1999/01/30 22:39:37 imp Exp $ */ /* NetBSD: pccons.c,v 1.89 1995/05/04 19:35:20 cgd Exp */ @@ -152,7 +152,7 @@ dev_type_mmap(pcmmap); const struct cdevsw pc_cdevsw = { pcopen, pcclose, pcread, pcwrite, pcioctl, - nostop, pctty, pcpoll, pcmmap, D_TTY + nostop, pctty, pcpoll, pcmmap, ttykqfilter, D_TTY }; #define CHR 2 diff --git a/sys/arch/arc/jazz/fd.c b/sys/arch/arc/jazz/fd.c index 13bab5896ec5..be693193024d 100644 --- a/sys/arch/arc/jazz/fd.c +++ b/sys/arch/arc/jazz/fd.c @@ -1,4 +1,4 @@ -/* $NetBSD: fd.c,v 1.7 2002/10/02 04:59:48 thorpej Exp $ */ +/* $NetBSD: fd.c,v 1.8 2002/10/23 09:10:40 jdolecek Exp $ */ /* $OpenBSD: fd.c,v 1.6 1998/10/03 21:18:57 millert Exp $ */ /* NetBSD: fd.c,v 1.78 1995/07/04 07:23:09 mycroft Exp */ @@ -197,7 +197,7 @@ const struct bdevsw fd_bdevsw = { const struct cdevsw fd_cdevsw = { fdopen, fdclose, fdread, fdwrite, fdioctl, - nostop, notty, nopoll, nommap, D_DISK + nostop, notty, nopoll, nommap, nokqfilter, D_DISK }; void fdgetdisklabel(struct fd_softc *); diff --git a/sys/arch/arm/arm32/mem.c b/sys/arch/arm/arm32/mem.c index 60a26e9a2813..418ca49a44f5 100644 --- a/sys/arch/arm/arm32/mem.c +++ b/sys/arch/arm/arm32/mem.c @@ -1,4 +1,4 @@ -/* $NetBSD: mem.c,v 1.7 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: mem.c,v 1.8 2002/10/23 09:10:40 jdolecek Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -43,7 +43,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.7 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.8 2002/10/23 09:10:40 jdolecek Exp $"); #include #include @@ -68,7 +68,7 @@ dev_type_mmap(mmmmap); const struct cdevsw mem_cdevsw = { nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, mmmmap, + nostop, notty, nopoll, mmmmap, nokqfilter, }; /*ARGSUSED*/ diff --git a/sys/arch/arm/footbridge/footbridge_com.c b/sys/arch/arm/footbridge/footbridge_com.c index 2ace4dc808b7..feb1c9f135d1 100644 --- a/sys/arch/arm/footbridge/footbridge_com.c +++ b/sys/arch/arm/footbridge/footbridge_com.c @@ -1,4 +1,4 @@ -/* $NetBSD: footbridge_com.c,v 1.8 2002/10/02 05:02:30 thorpej Exp $ */ +/* $NetBSD: footbridge_com.c,v 1.9 2002/10/23 09:10:41 jdolecek Exp $ */ /*- * Copyright (c) 1997 Mark Brinicombe @@ -129,7 +129,7 @@ dev_type_poll(fcompoll); const struct cdevsw fcom_cdevsw = { fcomopen, fcomclose, fcomread, fcomwrite, fcomioctl, - nostop, fcomtty, fcompoll, nommap, D_TTY + nostop, fcomtty, fcompoll, nommap, ttykqfilter, D_TTY }; void fcominit __P((bus_space_tag_t, bus_space_handle_t, int, int)); diff --git a/sys/arch/arm/iomd/beep.c b/sys/arch/arm/iomd/beep.c index aeff9c29940f..1208a17cc1d4 100644 --- a/sys/arch/arm/iomd/beep.c +++ b/sys/arch/arm/iomd/beep.c @@ -1,4 +1,4 @@ -/* $NetBSD: beep.c,v 1.15 2002/10/02 15:45:11 thorpej Exp $ */ +/* $NetBSD: beep.c,v 1.16 2002/10/23 09:10:42 jdolecek Exp $ */ /* * Copyright (c) 1995 Mark Brinicombe @@ -42,7 +42,7 @@ #include -__KERNEL_RCSID(0, "$NetBSD: beep.c,v 1.15 2002/10/02 15:45:11 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: beep.c,v 1.16 2002/10/23 09:10:42 jdolecek Exp $"); #include #include @@ -99,7 +99,7 @@ dev_type_ioctl(beepioctl); const struct cdevsw beep_cdevsw = { beepopen, beepclose, noread, nowrite, beepioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; int diff --git a/sys/arch/arm/iomd/console/console.c b/sys/arch/arm/iomd/console/console.c index c9d1d5ecb0cd..059e55cb5364 100644 --- a/sys/arch/arm/iomd/console/console.c +++ b/sys/arch/arm/iomd/console/console.c @@ -1,4 +1,4 @@ -/* $NetBSD: console.c,v 1.9 2002/10/08 08:57:52 jdolecek Exp $ */ +/* $NetBSD: console.c,v 1.10 2002/10/23 09:10:44 jdolecek Exp $ */ /* * Copyright (c) 1994-1995 Melvyn Tang-Richardson @@ -145,7 +145,7 @@ dev_type_mmap(physconmmap); const struct cdevsw physcon_cdevsw = { physconopen, physconclose, physconread, physconwrite, physconioctl, - nostop, physcontty, physconpoll, physconmmap, D_TTY + nostop, physcontty, physconpoll, physconmmap, ttykqfilter, D_TTY }; /* diff --git a/sys/arch/arm/iomd/console/vidcconsole.c b/sys/arch/arm/iomd/console/vidcconsole.c index d7224a298ea1..eab4a5de66ce 100644 --- a/sys/arch/arm/iomd/console/vidcconsole.c +++ b/sys/arch/arm/iomd/console/vidcconsole.c @@ -1,4 +1,4 @@ -/* $NetBSD: vidcconsole.c,v 1.8 2002/10/05 17:16:37 chs Exp $ */ +/* $NetBSD: vidcconsole.c,v 1.9 2002/10/23 09:10:45 jdolecek Exp $ */ /* * Copyright (c) 1996 Mark Brinicombe @@ -114,7 +114,7 @@ dev_type_mmap(vidcconsolemmap); const struct cdevsw vidcconsole_cdevsw = { vidcconsoleopen, vidcconsoleclose, noread, nowrite, vidcconsoleioctl, - nostop, notty, nopoll, vidcconsolemmap, + nostop, notty, nopoll, vidcconsolemmap, nokqfilter, }; int diff --git a/sys/arch/arm/iomd/iic.c b/sys/arch/arm/iomd/iic.c index f6bdabef1967..5939dbb96691 100644 --- a/sys/arch/arm/iomd/iic.c +++ b/sys/arch/arm/iomd/iic.c @@ -1,4 +1,4 @@ -/* $NetBSD: iic.c,v 1.5 2002/09/27 03:17:44 thorpej Exp $ */ +/* $NetBSD: iic.c,v 1.6 2002/10/23 09:10:42 jdolecek Exp $ */ /* * Copyright (c) 1994-1996 Mark Brinicombe. @@ -51,6 +51,7 @@ #include #include #include +#include #include #include @@ -86,7 +87,7 @@ dev_type_close(iicclose); const struct cdevsw iic_cdevsw = { iicopen, iicclose, noread, nowrite, noioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; /* diff --git a/sys/arch/arm/iomd/kbd.c b/sys/arch/arm/iomd/kbd.c index ff2b31a579d4..85392aac5ea2 100644 --- a/sys/arch/arm/iomd/kbd.c +++ b/sys/arch/arm/iomd/kbd.c @@ -1,4 +1,4 @@ -/* $NetBSD: kbd.c,v 1.4 2002/10/22 20:20:35 jdolecek Exp $ */ +/* $NetBSD: kbd.c,v 1.5 2002/10/23 09:10:42 jdolecek Exp $ */ /* * Copyright (c) 1994-1997 Mark Brinicombe. @@ -156,7 +156,7 @@ dev_type_ioctl(kbdioctl); const struct cdevsw kbd_cdevsw = { kbdopen, kbdclose, kbdread, nowrite, kbdioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; /* keyboard commands */ diff --git a/sys/arch/arm/iomd/opms.c b/sys/arch/arm/iomd/opms.c index 730ca2d39573..59352d2c7f65 100644 --- a/sys/arch/arm/iomd/opms.c +++ b/sys/arch/arm/iomd/opms.c @@ -1,4 +1,4 @@ -/* $NetBSD: opms.c,v 1.2 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: opms.c,v 1.3 2002/10/23 09:10:43 jdolecek Exp $ */ /*- * Copyright (c) 1996 D.C. Tsen @@ -41,7 +41,7 @@ #include -__RCSID("$NetBSD: opms.c,v 1.2 2002/09/06 13:18:43 gehenna Exp $"); +__RCSID("$NetBSD: opms.c,v 1.3 2002/10/23 09:10:43 jdolecek Exp $"); #include #include @@ -94,10 +94,11 @@ dev_type_close(opmsclose); dev_type_read(opmsread); dev_type_ioctl(opmsioctl); dev_type_poll(opmspoll); +dev_type_kqfilter(opmskqfilter); const struct cdevsw opms_cdevsw = { opmsopen, opmsclose, opmsread, nowrite, opmsioctl, - nostop, notty, opmspoll, nommap, + nostop, notty, opmspoll, nommap, opmskqfilter, }; /* opms device driver structure */ @@ -657,6 +658,54 @@ opmspoll(dev, events, p) return (revents); } +static void +filt_opmsrdetach(struct knote *kn) +{ + struct opms_softc *sc = kn->kn_hook; + int s; + + s = spltty(); + SLIST_REMOVE(&sc->sc_rsel.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_opmsread(struct knote *kn, long hint) +{ + struct opms_softc *sc = kn->kn_hook; + + kn->kn_data = sc->sc_q.c_cc; + return (kn->kn_data > 0); +} + +static const struct filterops opmsread_filtops = + { 1, NULL, filt_opmsrdetach, filt_opmsread }; + +int +opmskqfilter(dev_t dev, struct knote *kn) +{ + struct opms_softc *sc = opms_cd.cd_devs[PMSUNIT(dev)]; + struct klist *klist; + int s; + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &sc->sc_rsel.si_klist; + kn->kn_fop = &opmsread_filtops; + break; + + default: + return (1); + } + + kn->kn_hook = sc; + + s = spltty(); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + splx(s); + + return (0); +} void opmswatchdog(arg) diff --git a/sys/arch/arm/iomd/qms.c b/sys/arch/arm/iomd/qms.c index 4d4dfd2363e3..84618f729017 100644 --- a/sys/arch/arm/iomd/qms.c +++ b/sys/arch/arm/iomd/qms.c @@ -1,4 +1,4 @@ -/* $NetBSD: qms.c,v 1.2 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: qms.c,v 1.3 2002/10/23 09:10:43 jdolecek Exp $ */ /* * Copyright (c) Scott Stevens 1995 All rights reserved @@ -72,10 +72,11 @@ dev_type_close(qmsclose); dev_type_read(qmsread); dev_type_ioctl(qmsioctl); dev_type_poll(qmspoll); +dev_type_kqfilter(qmskqfilter); const struct cdevsw qms_cdevsw = { qmsopen, qmsclose, qmsread, nowrite, qmsioctl, - nostop, notty, qmspoll, nommap, + nostop, notty, qmspoll, nommap, qmskqfilter, }; /* qms device structure */ @@ -477,4 +478,54 @@ qmsputbuffer(sc, buffer) } #endif +/* XXXLUKEM (jdolecek) kqueue hooks not tested */ +static void +filt_qmsrdetach(struct knote *kn) +{ + struct qms_softc *sc = kn->kn_hook; + int s; + + s = spltty(); + SLIST_REMOVE(&sc->sc_rsel.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_qmsread(struct knote *kn, long hint) +{ + struct qms_softc *sc = kn->kn_hook; + + kn->kn_data = sc->sc_buffer.c_cc; + return (kn->kn_data > 0); +} + +static const struct filterops qmsread_filtops = + { 1, NULL, filt_qmsrdetach, filt_qmsread }; + +int +qmskqfilter(dev_t dev, struct knote *kn) +{ + struct qms_softc *sc = qms_cd.cd_devs[minor(dev)]; + struct klist *klist; + int s; + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &sc->sc_rsel.si_klist; + kn->kn_fop = &qmsread_filtops; + break; + + default: + return (1); + } + + kn->kn_hook = sc; + + s = spltty(); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + splx(s); + + return (0); +} + /* End of qms.c */ diff --git a/sys/arch/arm/iomd/rtc.c b/sys/arch/arm/iomd/rtc.c index 5e227ed19bbe..88aba5faa7e6 100644 --- a/sys/arch/arm/iomd/rtc.c +++ b/sys/arch/arm/iomd/rtc.c @@ -1,4 +1,4 @@ -/* $NetBSD: rtc.c,v 1.8 2002/10/02 15:45:13 thorpej Exp $ */ +/* $NetBSD: rtc.c,v 1.9 2002/10/23 09:10:43 jdolecek Exp $ */ /* * Copyright (c) 1994-1996 Mark Brinicombe. @@ -50,6 +50,7 @@ #include #include #include +#include #include #include #include @@ -260,7 +261,7 @@ dev_type_write(rtcwrite); const struct cdevsw rtc_cdevsw = { rtcopen, rtcclose, rtcread, rtcwrite, noioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; /* diff --git a/sys/arch/arm/ixp12x0/ixp12x0_com.c b/sys/arch/arm/ixp12x0/ixp12x0_com.c index 83344d19faaf..715173855ca3 100644 --- a/sys/arch/arm/ixp12x0/ixp12x0_com.c +++ b/sys/arch/arm/ixp12x0/ixp12x0_com.c @@ -1,4 +1,4 @@ -/* $NetBSD: ixp12x0_com.c,v 1.6 2002/10/09 00:06:57 thorpej Exp $ */ +/* $NetBSD: ixp12x0_com.c,v 1.7 2002/10/23 09:10:46 jdolecek Exp $ */ /* * Copyright (c) 1998, 1999, 2001, 2002 The NetBSD Foundation, Inc. * All rights reserved. @@ -154,7 +154,7 @@ dev_type_poll(ixpcompoll); const struct cdevsw ixpcom_cdevsw = { ixpcomopen, ixpcomclose, ixpcomread, ixpcomwrite, nullioctl, - ixpcomstop, ixpcomtty, ixpcompoll, nommap, D_TTY + ixpcomstop, ixpcomtty, ixpcompoll, nommap, ttykqfilter, D_TTY }; struct consdev ixpcomcons = { diff --git a/sys/arch/arm/sa11x0/sa11x0_com.c b/sys/arch/arm/sa11x0/sa11x0_com.c index feba28a5a2f6..f28459e1898c 100644 --- a/sys/arch/arm/sa11x0/sa11x0_com.c +++ b/sys/arch/arm/sa11x0/sa11x0_com.c @@ -1,4 +1,4 @@ -/* $NetBSD: sa11x0_com.c,v 1.11 2002/10/05 17:12:10 chs Exp $ */ +/* $NetBSD: sa11x0_com.c,v 1.12 2002/10/23 09:10:47 jdolecek Exp $ */ /*- * Copyright (c) 1998, 1999, 2001 The NetBSD Foundation, Inc. @@ -122,7 +122,7 @@ dev_type_poll(sacompoll); const struct cdevsw sacom_cdevsw = { sacomopen, sacomclose, sacomread, sacomwrite, sacomioctl, - sacomstop, sacomtty, sacompoll, nommap, D_TTY + sacomstop, sacomtty, sacompoll, nommap, ttykqfilter, D_TTY }; static int sacom_match(struct device *, struct cfdata *, void *); diff --git a/sys/arch/atari/atari/mem.c b/sys/arch/atari/atari/mem.c index e723b851762b..195c7abf4fda 100644 --- a/sys/arch/atari/atari/mem.c +++ b/sys/arch/atari/atari/mem.c @@ -1,4 +1,4 @@ -/* $NetBSD: mem.c,v 1.26 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: mem.c,v 1.27 2002/10/23 09:10:48 jdolecek Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -70,7 +70,7 @@ dev_type_ioctl(mmioctl); const struct cdevsw mem_cdevsw = { nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; /*ARGSUSED*/ diff --git a/sys/arch/atari/dev/clock.c b/sys/arch/atari/dev/clock.c index a5d5b2f35baa..389e64fea132 100644 --- a/sys/arch/atari/dev/clock.c +++ b/sys/arch/atari/dev/clock.c @@ -1,4 +1,4 @@ -/* $NetBSD: clock.c,v 1.30 2002/10/02 05:04:25 thorpej Exp $ */ +/* $NetBSD: clock.c,v 1.31 2002/10/23 09:10:48 jdolecek Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -48,6 +48,7 @@ #include #include #include +#include #include @@ -103,7 +104,7 @@ extern struct cfdriver clock_cd; const struct cdevsw rtc_cdevsw = { rtcopen, rtcclose, rtcread, rtcwrite, noioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; void statintr __P((struct clockframe)); diff --git a/sys/arch/atari/dev/event.c b/sys/arch/atari/dev/event.c index ab34a54d4aa3..f2eb936fef67 100644 --- a/sys/arch/atari/dev/event.c +++ b/sys/arch/atari/dev/event.c @@ -1,4 +1,4 @@ -/* $NetBSD: event.c,v 1.5 1996/10/08 23:40:40 thorpej Exp $ */ +/* $NetBSD: event.c,v 1.6 2002/10/23 09:10:49 jdolecek Exp $ */ /* * Copyright (c) 1992, 1993 @@ -166,3 +166,61 @@ ev_poll(ev, events, p) splx(s); return (revents); } + +static void +filt_evrdetach(struct knote *kn) +{ + struct evvar *ev = kn->kn_hook; + int s; + + s = splev(); + SLIST_REMOVE(&ev->ev_sel.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_evread(struct knote *kn, long hint) +{ + struct evvar *ev = kn->kn_hook; + + if (ev->ev_get == ev->ev_put) + return (0); + + if (ev->ev_get < ev->ev_put) + kn->kn_data = ev->ev_put - ev->ev_get; + else + kn->kn_data = (EV_QSIZE - ev->ev_get) + + ev->ev_put; + + kn->kn_data *= sizeof(struct firm_event); + + return (1); +} + +static const struct filterops ev_filtops = + { 1, NULL, filt_evrdetach, filt_evread }; + +int +ev_kqfilter(struct evvar *ev, struct knote *kn) +{ + struct klist *klist; + int s; + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &ev->ev_sel.si_klist; + kn->kn_fop = &ev_filtops; + break; + + default: + return (1); + } + + kn->kn_hook = ev; + + s = splev(); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + splx(s); + + return (0); +} diff --git a/sys/arch/atari/dev/event_var.h b/sys/arch/atari/dev/event_var.h index f543609a30d9..a230bb4aa2e9 100644 --- a/sys/arch/atari/dev/event_var.h +++ b/sys/arch/atari/dev/event_var.h @@ -1,4 +1,4 @@ -/* $NetBSD: event_var.h,v 1.2 1996/09/25 15:03:40 leo Exp $ */ +/* $NetBSD: event_var.h,v 1.3 2002/10/23 09:10:50 jdolecek Exp $ */ /* * Copyright (c) 1992, 1993 @@ -68,7 +68,7 @@ struct evvar { #define splev() spltty() #define EV_WAKEUP(ev) { \ - selwakeup(&(ev)->ev_sel); \ + selnotify(&(ev)->ev_sel, 0); \ if ((ev)->ev_wanted) { \ (ev)->ev_wanted = 0; \ wakeup((caddr_t)(ev)); \ @@ -81,6 +81,7 @@ void ev_init __P((struct evvar *)); void ev_fini __P((struct evvar *)); int ev_read __P((struct evvar *, struct uio *, int)); int ev_poll __P((struct evvar *, int, struct proc *)); +int ev_kqfilter __P((struct evvar *, struct knote *)); /* * PEVENT is set just above PSOCK, which is just above TTIPRI, on the diff --git a/sys/arch/atari/dev/fd.c b/sys/arch/atari/dev/fd.c index 76a7bcb17890..f15150da75a4 100644 --- a/sys/arch/atari/dev/fd.c +++ b/sys/arch/atari/dev/fd.c @@ -1,4 +1,4 @@ -/* $NetBSD: fd.c,v 1.42 2002/10/02 05:04:25 thorpej Exp $ */ +/* $NetBSD: fd.c,v 1.43 2002/10/23 09:10:50 jdolecek Exp $ */ /* * Copyright (c) 1995 Leo Weppelman. @@ -276,7 +276,7 @@ const struct bdevsw fd_bdevsw = { const struct cdevsw fd_cdevsw = { fdopen, fdclose, fdread, fdwrite, fdioctl, - nostop, notty, nopoll, nommap, D_DISK + nostop, notty, nopoll, nommap, nokqfilter, D_DISK }; static int diff --git a/sys/arch/atari/dev/grf.c b/sys/arch/atari/dev/grf.c index 00a7e2fd0975..82ccb5b71059 100644 --- a/sys/arch/atari/dev/grf.c +++ b/sys/arch/atari/dev/grf.c @@ -1,4 +1,4 @@ -/* $NetBSD: grf.c,v 1.30 2002/10/10 22:33:15 jdolecek Exp $ */ +/* $NetBSD: grf.c,v 1.31 2002/10/23 09:10:51 jdolecek Exp $ */ /* * Copyright (c) 1995 Leo Weppelman @@ -110,7 +110,7 @@ dev_type_mmap(grfmmap); const struct cdevsw grf_cdevsw = { grfopen, grfclose, noread, nowrite, grfioctl, - nostop, notty, nopoll, grfmmap, + nostop, notty, nopoll, grfmmap, nokqfilter, }; /* diff --git a/sys/arch/atari/dev/hdfd.c b/sys/arch/atari/dev/hdfd.c index 587a430545e5..7b7c7fba7198 100644 --- a/sys/arch/atari/dev/hdfd.c +++ b/sys/arch/atari/dev/hdfd.c @@ -1,4 +1,4 @@ -/* $NetBSD: hdfd.c,v 1.33 2002/10/02 05:04:25 thorpej Exp $ */ +/* $NetBSD: hdfd.c,v 1.34 2002/10/23 09:10:51 jdolecek Exp $ */ /*- * Copyright (c) 1996 Leo Weppelman @@ -258,7 +258,7 @@ const struct bdevsw fd_bdevsw = { const struct cdevsw fd_cdevsw = { fdopen, fdclose, fdread, fdwrite, fdioctl, - nostop, notty, nopoll, nommap, D_DISK + nostop, notty, nopoll, nommap, nokqfilter, D_DISK }; void fdstart __P((struct fd_softc *)); diff --git a/sys/arch/atari/dev/ite.c b/sys/arch/atari/dev/ite.c index f94a1021e2de..60b6afcbf885 100644 --- a/sys/arch/atari/dev/ite.c +++ b/sys/arch/atari/dev/ite.c @@ -1,4 +1,4 @@ -/* $NetBSD: ite.c,v 1.38 2002/10/02 05:04:25 thorpej Exp $ */ +/* $NetBSD: ite.c,v 1.39 2002/10/23 09:10:52 jdolecek Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -164,7 +164,7 @@ dev_type_poll(itepoll); const struct cdevsw ite_cdevsw = { iteopen, iteclose, iteread, itewrite, iteioctl, - nostop, itetty, itepoll, nommap, D_TTY + nostop, itetty, itepoll, nommap, ttykqfilter, D_TTY }; /* diff --git a/sys/arch/atari/dev/kbd.c b/sys/arch/atari/dev/kbd.c index d9271e5b7169..b8a2e868f255 100644 --- a/sys/arch/atari/dev/kbd.c +++ b/sys/arch/atari/dev/kbd.c @@ -1,4 +1,4 @@ -/* $NetBSD: kbd.c,v 1.21 2002/10/02 05:04:26 thorpej Exp $ */ +/* $NetBSD: kbd.c,v 1.22 2002/10/23 09:10:52 jdolecek Exp $ */ /* * Copyright (c) 1995 Leo Weppelman @@ -76,6 +76,7 @@ dev_type_close(kbdclose); dev_type_read(kbdread); dev_type_ioctl(kbdioctl); dev_type_poll(kbdpoll); +dev_type_kqfilter(kbdkqfilter); /* Interrupt handler */ void kbdintr __P((int)); @@ -92,7 +93,7 @@ CFATTACH_DECL(kbd, sizeof(struct device), const struct cdevsw kbd_cdevsw = { kbdopen, kbdclose, kbdread, nowrite, kbdioctl, - nostop, notty, kbdpoll, nommap, + nostop, notty, kbdpoll, nommap, kbdkqfilter, }; /*ARGSUSED*/ @@ -266,6 +267,13 @@ kbdpoll (dev_t dev, int events, struct proc *p) return ev_poll (&kbd_softc.k_events, events, p); } +int +kbdkqfilter(dev_t dev, struct knote *kn) +{ + + return (ev_kqfilter(&kbd_softc.k_events, kn)); +} + /* * Keyboard interrupt handler called straight from MFP at spl6. */ diff --git a/sys/arch/atari/dev/lpt.c b/sys/arch/atari/dev/lpt.c index 1d15547e1ace..652ae0ce1408 100644 --- a/sys/arch/atari/dev/lpt.c +++ b/sys/arch/atari/dev/lpt.c @@ -1,4 +1,4 @@ -/* $NetBSD: lpt.c,v 1.21 2002/10/02 05:04:26 thorpej Exp $ */ +/* $NetBSD: lpt.c,v 1.22 2002/10/23 09:10:52 jdolecek Exp $ */ /* * Copyright (c) 1996 Leo Weppelman @@ -134,7 +134,7 @@ extern struct cfdriver lp_cd; const struct cdevsw lp_cdevsw = { lpopen, lpclose, noread, lpwrite, lpioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; /*ARGSUSED*/ diff --git a/sys/arch/atari/dev/ms.c b/sys/arch/atari/dev/ms.c index 76aa4ec088f4..6441a5e430f7 100644 --- a/sys/arch/atari/dev/ms.c +++ b/sys/arch/atari/dev/ms.c @@ -1,4 +1,4 @@ -/* $NetBSD: ms.c,v 1.11 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: ms.c,v 1.12 2002/10/23 09:10:53 jdolecek Exp $ */ /* * Copyright (c) 1995 Leo Weppelman. @@ -89,10 +89,11 @@ dev_type_close(msclose); dev_type_read(msread); dev_type_ioctl(msioctl); dev_type_poll(mspoll); +dev_type_kqfilter(mskqfilter); const struct cdevsw ms_cdevsw = { msopen, msclose, msread, nowrite, msioctl, - nostop, notty, mspoll, nommap, + nostop, notty, mspoll, nommap, mskqfilter, }; static void ms_3b_delay __P((struct ms_softc *)); @@ -424,4 +425,13 @@ struct proc *p; ms = &ms_softc[minor(dev)]; return(ev_poll(&ms->ms_events, events, p)); } + +int +mskqfilter(dev_t dev, struct knote *kn) +{ + struct ms_softc *ms; + + ms = &ms_softc[minor(dev)]; + return (ev_kqfilter(&ms->ms_events, kn)); +} #endif /* NMOUSE > 0 */ diff --git a/sys/arch/atari/dev/ser.c b/sys/arch/atari/dev/ser.c index 7b273f44c642..64fe68f4b11c 100644 --- a/sys/arch/atari/dev/ser.c +++ b/sys/arch/atari/dev/ser.c @@ -1,4 +1,4 @@ -/* $NetBSD: ser.c,v 1.20 2002/10/02 05:04:26 thorpej Exp $ */ +/* $NetBSD: ser.c,v 1.21 2002/10/23 09:10:53 jdolecek Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -274,7 +274,7 @@ dev_type_poll(serpoll); const struct cdevsw ser_cdevsw = { seropen, serclose, serread, serwrite, serioctl, - serstop, sertty, serpoll, nommap, D_TTY + serstop, sertty, serpoll, nommap, ttykqfilter, D_TTY }; /*ARGSUSED*/ diff --git a/sys/arch/atari/dev/view.c b/sys/arch/atari/dev/view.c index b49a6b299497..bb06ad25b5f9 100644 --- a/sys/arch/atari/dev/view.c +++ b/sys/arch/atari/dev/view.c @@ -1,4 +1,4 @@ -/* $NetBSD: view.c,v 1.20 2002/10/10 22:33:16 jdolecek Exp $ */ +/* $NetBSD: view.c,v 1.21 2002/10/23 09:10:54 jdolecek Exp $ */ /* * Copyright (c) 1994 Christian E. Hopps @@ -74,7 +74,7 @@ dev_type_mmap(viewmmap); const struct cdevsw view_cdevsw = { viewopen, viewclose, nullread, nullwrite, viewioctl, - nostop, notty, nopoll, viewmmap, + nostop, notty, nopoll, viewmmap, nokqfilter, }; /* diff --git a/sys/arch/atari/dev/zs.c b/sys/arch/atari/dev/zs.c index a88830faf8a0..f5c7f7c4df5d 100644 --- a/sys/arch/atari/dev/zs.c +++ b/sys/arch/atari/dev/zs.c @@ -1,4 +1,4 @@ -/* $NetBSD: zs.c,v 1.38 2002/10/02 05:04:26 thorpej Exp $ */ +/* $NetBSD: zs.c,v 1.39 2002/10/23 09:10:54 jdolecek Exp $ */ /* * Copyright (c) 1995 L. Weppelman (Atari modifications) @@ -208,7 +208,7 @@ dev_type_poll(zspoll); const struct cdevsw zs_cdevsw = { zsopen, zsclose, zsread, zswrite, zsioctl, - zsstop, zstty, zspoll, nommap, D_TTY + zsstop, zstty, zspoll, nommap, ttykqfilter, D_TTY }; /* Interrupt handlers. */ diff --git a/sys/arch/atari/vme/et4000.c b/sys/arch/atari/vme/et4000.c index 403004c71f99..ac80bdf03bca 100644 --- a/sys/arch/atari/vme/et4000.c +++ b/sys/arch/atari/vme/et4000.c @@ -1,4 +1,4 @@ -/* $NetBSD: et4000.c,v 1.9 2002/10/02 05:04:27 thorpej Exp $ */ +/* $NetBSD: et4000.c,v 1.10 2002/10/23 09:10:55 jdolecek Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. * All rights reserved. @@ -58,6 +58,7 @@ #include #include #include +#include #include #include @@ -142,7 +143,7 @@ dev_type_mmap(etmmap); const struct cdevsw et_cdevsw = { etopen, etclose, etread, etwrite, etioctl, - nostop, notty, nopoll, etmmap, + nostop, notty, nopoll, etmmap, nokqfilter, }; /* diff --git a/sys/arch/atari/vme/leo.c b/sys/arch/atari/vme/leo.c index 1fe664745e22..ed8091f3dc6f 100644 --- a/sys/arch/atari/vme/leo.c +++ b/sys/arch/atari/vme/leo.c @@ -1,4 +1,4 @@ -/* $NetBSD: leo.c,v 1.7 2002/10/02 05:04:27 thorpej Exp $ */ +/* $NetBSD: leo.c,v 1.8 2002/10/23 09:10:55 jdolecek Exp $ */ /*- * Copyright (c) 1997 maximum entropy @@ -113,7 +113,7 @@ dev_type_mmap(leommap); const struct cdevsw leo_cdevsw = { leoopen, leoclose, leomove, leomove, leoioctl, - nostop, notty, nopoll, leommap, + nostop, notty, nopoll, leommap, nokqfilter, }; static int diff --git a/sys/arch/bebox/isa/lms.c b/sys/arch/bebox/isa/lms.c index 0519b9337ba3..008ea2a4b1d9 100644 --- a/sys/arch/bebox/isa/lms.c +++ b/sys/arch/bebox/isa/lms.c @@ -1,4 +1,4 @@ -/* $NetBSD: lms.c,v 1.8 2002/10/02 05:05:29 thorpej Exp $ */ +/* $NetBSD: lms.c,v 1.9 2002/10/23 09:10:56 jdolecek Exp $ */ /*- * Copyright (c) 1993, 1994 Charles M. Hannum. @@ -85,10 +85,11 @@ dev_type_close(lmsclose); dev_type_read(lmsread); dev_type_ioctl(lmsioctl); dev_type_poll(lmspoll); +dev_type_kqfilter(lmsqkfilter); const struct cdevsw lms_cdevsw = { lmsopen, lmsclose, lmsread, nowrite, lmsioctl, - nostop, notty, lmspoll, nommap, + nostop, notty, lmspoll, nommap, lmskqfilter, }; #define LMSUNIT(dev) (minor(dev)) @@ -364,7 +365,7 @@ lmsintr(arg) sc->sc_state &= ~LMS_ASLP; wakeup((caddr_t)sc); } - selwakeup(&sc->sc_rsel); + selnotify(&sc->sc_rsel, 0); } return -1; @@ -389,3 +390,52 @@ lmspoll(dev, events, p) splx(s); return (revents); } + +static void +filt_lmsrdetach(struct knote *kn) +{ + struct lms_softc *sc = kn->kn_hook; + int s; + + s = spltty(); + SLIST_REMOVE(&sc->sc_rsel.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_lmsread(struct knote *kn, long hint) +{ + struct lms_softc *sc = kn->kn_hook; + + kn->kn_data = sc->sc_q.c_cc; + return (kn->kn_data > 0); +} + +static const struct filterops lmsread_filtops = + { 1, NULL, filt_lmsrdetach, filt_lmsread }; + +int +lmskqfilter(dev_t dev, struct knote *kn) +{ + struct lms_softc *sc = lms_cd.cd_devs[LMSUNIT(dev)]; + struct klist *klist; + int s; + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &sc->sc_rsel.si_klist; + kn->kn_fop = &lmsread_filtops; + break; + + default: + return (1); + } + + kn->kn_hook = sc; + + s = spltty(); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + splx(s); + + return (0); +} diff --git a/sys/arch/bebox/isa/mms.c b/sys/arch/bebox/isa/mms.c index 7c6641186106..e7068bb7bd2c 100644 --- a/sys/arch/bebox/isa/mms.c +++ b/sys/arch/bebox/isa/mms.c @@ -1,4 +1,4 @@ -/* $NetBSD: mms.c,v 1.9 2002/10/02 05:05:29 thorpej Exp $ */ +/* $NetBSD: mms.c,v 1.10 2002/10/23 09:10:56 jdolecek Exp $ */ /*- * Copyright (c) 1993, 1994 Charles M. Hannum. @@ -81,10 +81,11 @@ dev_type_close(mmsclose); dev_type_read(mmsread); dev_type_ioctl(mmsioctl); dev_type_poll(mmspoll); +dev_type_kqfilter(mmskqfilter); const struct cdevsw mms_cdevsw = { mmsopen, mmsclose, mmsread, nowrite, mmsioctl, - nostop, notty, mmspoll, nommap, + nostop, notty, mmspoll, nommap, mmskqfilter, }; #define MMSUNIT(dev) (minor(dev)) @@ -341,7 +342,7 @@ mmsintr(arg) sc->sc_state &= ~MMS_ASLP; wakeup((caddr_t)sc); } - selwakeup(&sc->sc_rsel); + selnotify(&sc->sc_rsel, 0); } return -1; @@ -366,3 +367,52 @@ mmspoll(dev, events, p) splx(s); return (revents); } + +static void +filt_mmsrdetach(struct knote *kn) +{ + struct mms_softc *sc = kn->kn_hook; + int s; + + s = spltty(); + SLIST_REMOVE(&sc->sc_rsel.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_mmsread(struct knote *kn, long hint) +{ + struct mms_softc *sc = kn->kn_hook; + + kn->kn_data = sc->sc_q.c_cc; + return (kn->kn_data > 0); +} + +static const struct filterops mmsread_filtops = + { 1, NULL, filt_mmsrdetach, filt_mmsread }; + +int +mmskqfilter(dev_t dev, struct knote *kn) +{ + struct mms_softc *sc = mms_cd.cd_devs[LMSUNIT(dev)]; + struct klist *klist; + int s; + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &sc->sc_rsel.si_klist; + kn->kn_fop = &mmsread_filtops; + break; + + default: + return (1); + } + + kn->kn_hook = sc; + + s = spltty(); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + splx(s); + + return (0); +} diff --git a/sys/arch/bebox/isa/pccons.c b/sys/arch/bebox/isa/pccons.c index bea83a19671b..264ab820175b 100644 --- a/sys/arch/bebox/isa/pccons.c +++ b/sys/arch/bebox/isa/pccons.c @@ -1,4 +1,4 @@ -/* $NetBSD: pccons.c,v 1.25 2002/10/02 05:05:29 thorpej Exp $ */ +/* $NetBSD: pccons.c,v 1.26 2002/10/23 09:10:57 jdolecek Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -193,7 +193,7 @@ dev_type_mmap(pcmmap); const struct cdevsw pc_cdevsw = { pcopen, pcclose, pcread, pcwrite, pcioctl, - pcstop, pctty, pcpoll, pcmmap, D_TTY + pcstop, pctty, pcpoll, pcmmap, ttykqfilter, D_TTY }; #define COL 80 diff --git a/sys/arch/bebox/isa/spkr.c b/sys/arch/bebox/isa/spkr.c index 990609b478e6..940d7facd6ef 100644 --- a/sys/arch/bebox/isa/spkr.c +++ b/sys/arch/bebox/isa/spkr.c @@ -1,4 +1,4 @@ -/* $NetBSD: spkr.c,v 1.11 2002/10/02 05:05:29 thorpej Exp $ */ +/* $NetBSD: spkr.c,v 1.12 2002/10/23 09:10:57 jdolecek Exp $ */ /* * spkr.c -- device driver for console speaker on 80386 @@ -52,7 +52,7 @@ dev_type_ioctl(spkrioctl); const struct cdevsw spkr_cdevsw = { spkropen, spkrclose, noread, spkrwrite, spkrioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; /**************** MACHINE DEPENDENT PART STARTS HERE ************************* diff --git a/sys/arch/cesfic/cesfic/mem.c b/sys/arch/cesfic/cesfic/mem.c index 3f3d71eb3cfe..af66e619bf85 100644 --- a/sys/arch/cesfic/cesfic/mem.c +++ b/sys/arch/cesfic/cesfic/mem.c @@ -1,4 +1,4 @@ -/* $NetBSD: mem.c,v 1.4 2002/10/05 16:25:34 chs Exp $ */ +/* $NetBSD: mem.c,v 1.5 2002/10/23 09:10:58 jdolecek Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -66,7 +66,7 @@ dev_type_mmap(mmmmap); const struct cdevsw mem_cdevsw = { nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, mmmmap, + nostop, notty, nopoll, mmmmap, nokqfilter, }; /*ARGSUSED*/ diff --git a/sys/arch/dreamcast/dev/gdrom.c b/sys/arch/dreamcast/dev/gdrom.c index e1c02f80ffad..6fd6a1244dff 100644 --- a/sys/arch/dreamcast/dev/gdrom.c +++ b/sys/arch/dreamcast/dev/gdrom.c @@ -1,4 +1,4 @@ -/* $NetBSD: gdrom.c,v 1.13 2002/10/02 05:11:19 thorpej Exp $ */ +/* $NetBSD: gdrom.c,v 1.14 2002/10/23 09:10:59 jdolecek Exp $ */ /*- * Copyright (c) 2001 Marcus Comstedt @@ -66,7 +66,7 @@ const struct bdevsw gdrom_bdevsw = { const struct cdevsw gdrom_cdevsw = { gdromopen, gdromclose, gdromread, gdromwrite, gdromioctl, - nostop, notty, nopoll, nommap, D_DISK + nostop, notty, nopoll, nommap, nokqfilter, D_DISK }; struct gdrom_softc { diff --git a/sys/arch/dreamcast/dev/maple/maple.c b/sys/arch/dreamcast/dev/maple/maple.c index 85c9b18ce2b9..4156f395374f 100644 --- a/sys/arch/dreamcast/dev/maple/maple.c +++ b/sys/arch/dreamcast/dev/maple/maple.c @@ -1,4 +1,4 @@ -/* $NetBSD: maple.c,v 1.19 2002/10/02 15:45:16 thorpej Exp $ */ +/* $NetBSD: maple.c,v 1.20 2002/10/23 09:11:00 jdolecek Exp $ */ /*- * Copyright (c) 2001 Marcus Comstedt @@ -103,7 +103,7 @@ dev_type_ioctl(mapleioctl); const struct cdevsw maple_cdevsw = { mapleopen, mapleclose, noread, nowrite, mapleioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; static int diff --git a/sys/arch/evbarm/dev/plcom.c b/sys/arch/evbarm/dev/plcom.c index 54d3738416c9..948bf61459a0 100644 --- a/sys/arch/evbarm/dev/plcom.c +++ b/sys/arch/evbarm/dev/plcom.c @@ -1,4 +1,4 @@ -/* $NetBSD: plcom.c,v 1.4 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: plcom.c,v 1.5 2002/10/23 09:11:01 jdolecek Exp $ */ /*- * Copyright (c) 2001 ARM Ltd @@ -209,7 +209,7 @@ extern struct cfdriver plcom_cd; const struct cdevsw plcom_cdevsw = { plcomopen, plcomclose, plcomread, plcomwrite, plcomioctl, - plcomstop, plcomtty, plcompoll, nommap, D_TTY + plcomstop, plcomtty, plcompoll, nommap, ttykqfilter, D_TTY }; /* diff --git a/sys/arch/hp300/dev/ac.c b/sys/arch/hp300/dev/ac.c index 1fe0c0196a28..5eba92c4f7d0 100644 --- a/sys/arch/hp300/dev/ac.c +++ b/sys/arch/hp300/dev/ac.c @@ -1,4 +1,4 @@ -/* $NetBSD: ac.c,v 1.17 2002/10/02 05:15:48 thorpej Exp $ */ +/* $NetBSD: ac.c,v 1.18 2002/10/23 09:11:02 jdolecek Exp $ */ /*- * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. @@ -88,7 +88,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ac.c,v 1.17 2002/10/02 05:15:48 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ac.c,v 1.18 2002/10/23 09:11:02 jdolecek Exp $"); #include #include @@ -99,6 +99,7 @@ __KERNEL_RCSID(0, "$NetBSD: ac.c,v 1.17 2002/10/02 05:15:48 thorpej Exp $"); #include #include #include +#include #include #include @@ -119,7 +120,7 @@ dev_type_ioctl(acioctl); const struct cdevsw ac_cdevsw = { acopen, acclose, noread, nowrite, acioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; void acstart __P((void *)); diff --git a/sys/arch/hp300/dev/apci.c b/sys/arch/hp300/dev/apci.c index 3a149d1cb406..09457d71db9f 100644 --- a/sys/arch/hp300/dev/apci.c +++ b/sys/arch/hp300/dev/apci.c @@ -1,4 +1,4 @@ -/* $NetBSD: apci.c,v 1.20 2002/10/02 05:15:48 thorpej Exp $ */ +/* $NetBSD: apci.c,v 1.21 2002/10/23 09:11:02 jdolecek Exp $ */ /*- * Copyright (c) 1996, 1997, 1999 The NetBSD Foundation, Inc. @@ -93,7 +93,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: apci.c,v 1.20 2002/10/02 05:15:48 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: apci.c,v 1.21 2002/10/23 09:11:02 jdolecek Exp $"); #include #include @@ -156,7 +156,7 @@ dev_type_poll(apcipoll); const struct cdevsw apci_cdevsw = { apciopen, apciclose, apciread, apciwrite, apciioctl, - apcistop, apcitty, apcipoll, nommap, D_TTY + apcistop, apcitty, apcipoll, nommap, ttykqfilter, D_TTY }; int apciintr __P((void *)); diff --git a/sys/arch/hp300/dev/ct.c b/sys/arch/hp300/dev/ct.c index 69dc82820531..9c5bf0e930fb 100644 --- a/sys/arch/hp300/dev/ct.c +++ b/sys/arch/hp300/dev/ct.c @@ -1,4 +1,4 @@ -/* $NetBSD: ct.c,v 1.32 2002/10/02 05:15:48 thorpej Exp $ */ +/* $NetBSD: ct.c,v 1.33 2002/10/23 09:11:02 jdolecek Exp $ */ /*- * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. @@ -86,7 +86,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ct.c,v 1.32 2002/10/02 05:15:48 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ct.c,v 1.33 2002/10/23 09:11:02 jdolecek Exp $"); #include #include @@ -168,7 +168,7 @@ const struct bdevsw ct_bdevsw = { const struct cdevsw ct_cdevsw = { ctopen, ctclose, ctread, ctwrite, ctioctl, - nostop, notty, nopoll, nommap, D_TAPE + nostop, notty, nopoll, nommap, nokqfilter, D_TAPE }; int ctident __P((struct device *, struct ct_softc *, diff --git a/sys/arch/hp300/dev/dca.c b/sys/arch/hp300/dev/dca.c index bdc4a061aae3..c0a4e3242247 100644 --- a/sys/arch/hp300/dev/dca.c +++ b/sys/arch/hp300/dev/dca.c @@ -1,4 +1,4 @@ -/* $NetBSD: dca.c,v 1.52 2002/10/02 05:15:48 thorpej Exp $ */ +/* $NetBSD: dca.c,v 1.53 2002/10/23 09:11:03 jdolecek Exp $ */ /*- * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. @@ -84,7 +84,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: dca.c,v 1.52 2002/10/02 05:15:48 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dca.c,v 1.53 2002/10/23 09:11:03 jdolecek Exp $"); #include "opt_ddb.h" #include "opt_kgdb.h" @@ -149,7 +149,7 @@ dev_type_poll(dcapoll); const struct cdevsw dca_cdevsw = { dcaopen, dcaclose, dcaread, dcawrite, dcaioctl, - dcastop, dcatty, dcapoll, nommap, D_TTY + dcastop, dcatty, dcapoll, nommap, ttykqfilter, D_TTY }; int dcaintr __P((void *)); diff --git a/sys/arch/hp300/dev/dcm.c b/sys/arch/hp300/dev/dcm.c index 0bbaa4ac0895..f74f851a04cd 100644 --- a/sys/arch/hp300/dev/dcm.c +++ b/sys/arch/hp300/dev/dcm.c @@ -1,4 +1,4 @@ -/* $NetBSD: dcm.c,v 1.55 2002/10/20 06:26:39 gmcgarry Exp $ */ +/* $NetBSD: dcm.c,v 1.56 2002/10/23 09:11:03 jdolecek Exp $ */ /*- * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. @@ -89,7 +89,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: dcm.c,v 1.55 2002/10/20 06:26:39 gmcgarry Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dcm.c,v 1.56 2002/10/23 09:11:03 jdolecek Exp $"); #include "opt_kgdb.h" @@ -329,7 +329,7 @@ dev_type_poll(dcmpoll); const struct cdevsw dcm_cdevsw = { dcmopen, dcmclose, dcmread, dcmwrite, dcmioctl, - dcmstop, dcmtty, dcmpoll, nommap, D_TTY + dcmstop, dcmtty, dcmpoll, nommap, ttykqfilter, D_TTY }; int diff --git a/sys/arch/hp300/dev/grf.c b/sys/arch/hp300/dev/grf.c index 187ee9c4c554..3a8fe6c2e5df 100644 --- a/sys/arch/hp300/dev/grf.c +++ b/sys/arch/hp300/dev/grf.c @@ -1,4 +1,4 @@ -/* $NetBSD: grf.c,v 1.47 2002/10/10 22:33:16 jdolecek Exp $ */ +/* $NetBSD: grf.c,v 1.48 2002/10/23 09:11:05 jdolecek Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -49,7 +49,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: grf.c,v 1.47 2002/10/10 22:33:16 jdolecek Exp $"); +__KERNEL_RCSID(0, "$NetBSD: grf.c,v 1.48 2002/10/23 09:11:05 jdolecek Exp $"); #include "opt_compat_hpux.h" @@ -104,7 +104,7 @@ dev_type_mmap(grfmmap); const struct cdevsw grf_cdevsw = { grfopen, grfclose, nullread, nullwrite, grfioctl, - nostop, notty, nopoll, grfmmap, + nostop, notty, nopoll, grfmmap, nokqfilter, }; int grfprint __P((void *, const char *)); diff --git a/sys/arch/hp300/dev/hil.c b/sys/arch/hp300/dev/hil.c index 31876de50e9e..0e4b3f07b7df 100644 --- a/sys/arch/hp300/dev/hil.c +++ b/sys/arch/hp300/dev/hil.c @@ -1,4 +1,4 @@ -/* $NetBSD: hil.c,v 1.51 2002/10/02 05:15:51 thorpej Exp $ */ +/* $NetBSD: hil.c,v 1.52 2002/10/23 09:11:05 jdolecek Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -43,7 +43,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: hil.c,v 1.51 2002/10/02 05:15:51 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: hil.c,v 1.52 2002/10/23 09:11:05 jdolecek Exp $"); #include "opt_compat_hpux.h" #include "rnd.h" @@ -111,10 +111,11 @@ dev_type_close(hilclose); dev_type_read(hilread); dev_type_ioctl(hilioctl); dev_type_poll(hilpoll); +dev_type_kqfilter(hilkqfilter); const struct cdevsw hil_cdevsw = { hilopen, hilclose, hilread, nullwrite, hilioctl, - nostop, notty, hilpoll, nommap, + nostop, notty, hilpoll, nommap, hilkqfilter, }; void hilattach_deferred __P((struct device *)); @@ -837,6 +838,109 @@ hilpoll(dev, events, p) return (revents); } +static void +filt_hilrdetach(struct knote *kn) +{ + dev_t dev = (intptr_t) kn->kn_hook; + struct hil_softc *hilp = hil_cd.cd_devs[HILLOOP(dev)]; + struct hilloopdev *dptr = &hilp->hl_device[HILUNIT(dev)]; + int s; + + s = splhil(); + SLIST_REMOVE(&dptr->hd_selr.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_hilread(struct knote *kn, long hint) +{ + dev_t dev = (intptr_t) kn->kn_hook; + int device = HILUNIT(dev); + struct hil_softc *hilp = hil_cd.cd_devs[HILLOOP(dev)]; + struct hilloopdev *dptr = &hilp->hl_device[device]; + struct hiliqueue *qp; + int mask; + + if (dptr->hd_flags & HIL_READIN) { + kn->kn_data = dptr->hd_queue.c_cc; + return (kn->kn_data > 0); + } + + /* + * Make sure device is alive and real (or the loop device). + * Note that we do not do this for the read interface. + * This is primarily to be consistant with HP-UX. + */ + if (device && (dptr->hd_flags & (HIL_ALIVE|HIL_PSEUDO)) != HIL_ALIVE) { + kn->kn_data = 0; /* XXXLUKEM (thorpej): what to put here? */ + return (1); + } + + /* + * Select on loop device is special. + * Check to see if there are any data for any loop device + * provided it is associated with a queue belonging to this user. + */ + if (device == 0) + mask = -1; + else + mask = hildevmask(device); + /* + * Must check everybody with interrupts blocked to prevent races. + * (Interrupts are already blocked.) + */ + for (qp = hilp->hl_queue; qp < &hilp->hl_queue[NHILQ]; qp++) { + /* XXXLUKEM (thorpej): PROCESS CHECK! */ + if (/*qp->hq_procp == p &&*/ (mask & qp->hq_devmask) && + qp->hq_eventqueue->hil_evqueue.head != + qp->hq_eventqueue->hil_evqueue.tail) { + /* XXXLUKEM (thorpej): what to put here? */ + kn->kn_data = 0; + return (1); + } + } + + return (0); +} + +static const struct filterops hilread_filtops = + { 1, NULL, filt_hilrdetach, filt_hilread }; + +static const struct filterops hil_seltrue_filtops = + { 1, NULL, filt_hilrdetach, filt_seltrue }; + +int +hilkqfilter(dev_t dev, struct knote *kn) +{ + struct hil_softc *hilp = hil_cd.cd_devs[HILLOOP(dev)]; + struct hilloopdev *dptr = &hilp->hl_device[HILUNIT(dev)]; + struct klist *klist; + int s; + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &dptr->hd_selr.si_klist; + kn->kn_fop = &hilread_filtops; + break; + + case EVFILT_WRITE: + klist = &dptr->hd_selr.si_klist; + kn->kn_fop = &hil_seltrue_filtops; + break; + + default: + return (1); + } + + kn->kn_hook = (void *)(intptr_t) dev; /* XXX yuck */ + + s = splhil(); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + splx(s); + + return (0); +} + /*ARGSUSED*/ int hilint(v) @@ -1027,9 +1131,9 @@ hilevent(hilp) /* * Wake up anyone selecting on this device or the loop itself */ - selwakeup(&dptr->hd_selr); + selnotify(&dptr->hd_selr, 0); dptr = &hilp->hl_device[HILLOOPDEV]; - selwakeup(&dptr->hd_selr); + selnotify(&dptr->hd_selr, 0); } #undef HQFULL @@ -1072,7 +1176,7 @@ hpuxhilevent(hilp, dptr) dptr->hd_flags &= ~HIL_ASLEEP; wakeup((caddr_t)dptr); } - selwakeup(&dptr->hd_selr); + selnotify(&dptr->hd_selr, 0); } /* diff --git a/sys/arch/hp300/dev/ite.c b/sys/arch/hp300/dev/ite.c index 62fe5a46802e..fac22f49625a 100644 --- a/sys/arch/hp300/dev/ite.c +++ b/sys/arch/hp300/dev/ite.c @@ -1,4 +1,4 @@ -/* $NetBSD: ite.c,v 1.56 2002/10/02 05:15:53 thorpej Exp $ */ +/* $NetBSD: ite.c,v 1.57 2002/10/23 09:11:06 jdolecek Exp $ */ /*- * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. @@ -85,7 +85,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ite.c,v 1.56 2002/10/02 05:15:53 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ite.c,v 1.57 2002/10/23 09:11:06 jdolecek Exp $"); #include "hil.h" @@ -142,7 +142,7 @@ dev_type_poll(itepoll); const struct cdevsw ite_cdevsw = { iteopen, iteclose, iteread, itewrite, iteioctl, - nostop, itetty, itepoll, nommap, D_TTY + nostop, itetty, itepoll, nommap, ttykqfilter, D_TTY }; /* diff --git a/sys/arch/hp300/dev/mt.c b/sys/arch/hp300/dev/mt.c index 2b2c8ff93fa7..15245acda7c9 100644 --- a/sys/arch/hp300/dev/mt.c +++ b/sys/arch/hp300/dev/mt.c @@ -1,4 +1,4 @@ -/* $NetBSD: mt.c,v 1.20 2002/10/02 05:15:53 thorpej Exp $ */ +/* $NetBSD: mt.c,v 1.21 2002/10/23 09:11:07 jdolecek Exp $ */ /*- * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. @@ -67,7 +67,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: mt.c,v 1.20 2002/10/02 05:15:53 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mt.c,v 1.21 2002/10/23 09:11:07 jdolecek Exp $"); #include #include @@ -154,7 +154,7 @@ const struct bdevsw mt_bdevsw = { const struct cdevsw mt_cdevsw = { mtopen, mtclose, mtread, mtwrite, mtioctl, - nostop, notty, nopoll, nommap, D_TAPE + nostop, notty, nopoll, nommap, nokqfilter, D_TAPE }; int mtident __P((struct mt_softc *, struct hpibbus_attach_args *)); diff --git a/sys/arch/hp300/dev/ppi.c b/sys/arch/hp300/dev/ppi.c index d8efc404ef52..189663746cf6 100644 --- a/sys/arch/hp300/dev/ppi.c +++ b/sys/arch/hp300/dev/ppi.c @@ -1,4 +1,4 @@ -/* $NetBSD: ppi.c,v 1.23 2002/10/02 05:15:54 thorpej Exp $ */ +/* $NetBSD: ppi.c,v 1.24 2002/10/23 09:11:07 jdolecek Exp $ */ /*- * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. @@ -76,7 +76,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ppi.c,v 1.23 2002/10/02 05:15:54 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ppi.c,v 1.24 2002/10/23 09:11:07 jdolecek Exp $"); #include #include @@ -129,7 +129,7 @@ dev_type_ioctl(ppiioctl); const struct cdevsw ppi_cdevsw = { ppiopen, ppiclose, ppiread, ppiwrite, ppiioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; void ppistart __P((void *)); diff --git a/sys/arch/hp300/dev/rd.c b/sys/arch/hp300/dev/rd.c index bee9fc3f9bbc..e65b58f13a26 100644 --- a/sys/arch/hp300/dev/rd.c +++ b/sys/arch/hp300/dev/rd.c @@ -1,4 +1,4 @@ -/* $NetBSD: rd.c,v 1.53 2002/10/02 05:15:54 thorpej Exp $ */ +/* $NetBSD: rd.c,v 1.54 2002/10/23 09:11:08 jdolecek Exp $ */ /*- * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. @@ -83,7 +83,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: rd.c,v 1.53 2002/10/02 05:15:54 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rd.c,v 1.54 2002/10/23 09:11:08 jdolecek Exp $"); #include "opt_useleds.h" #include "rnd.h" @@ -300,7 +300,7 @@ const struct bdevsw rd_bdevsw = { const struct cdevsw rd_cdevsw = { rdopen, rdclose, rdread, rdwrite, rdioctl, - nostop, notty, nopoll, nommap, D_DISK + nostop, notty, nopoll, nommap, nokqfilter, D_DISK }; int diff --git a/sys/arch/hp300/dev/sd.c b/sys/arch/hp300/dev/sd.c index 940d428f05d5..13524be30801 100644 --- a/sys/arch/hp300/dev/sd.c +++ b/sys/arch/hp300/dev/sd.c @@ -1,4 +1,4 @@ -/* $NetBSD: sd.c,v 1.55 2002/10/02 05:15:55 thorpej Exp $ */ +/* $NetBSD: sd.c,v 1.56 2002/10/23 09:11:09 jdolecek Exp $ */ /*- * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. @@ -79,7 +79,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: sd.c,v 1.55 2002/10/02 05:15:55 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sd.c,v 1.56 2002/10/23 09:11:09 jdolecek Exp $"); #include "rnd.h" #include "opt_useleds.h" @@ -132,7 +132,7 @@ const struct bdevsw sd_bdevsw = { const struct cdevsw sd_cdevsw = { sdopen, sdclose, sdread, sdwrite, sdioctl, - nostop, notty, nopoll, nommap, D_DISK + nostop, notty, nopoll, nommap, nokqfilter, D_DISK }; #ifdef DEBUG diff --git a/sys/arch/hp300/dev/st.c b/sys/arch/hp300/dev/st.c index cb27a94071cf..0f6997e617a6 100644 --- a/sys/arch/hp300/dev/st.c +++ b/sys/arch/hp300/dev/st.c @@ -1,4 +1,4 @@ -/* $NetBSD: st.c,v 1.35 2002/10/02 05:15:55 thorpej Exp $ */ +/* $NetBSD: st.c,v 1.36 2002/10/23 09:11:10 jdolecek Exp $ */ /*- * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. @@ -111,7 +111,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: st.c,v 1.35 2002/10/02 05:15:55 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: st.c,v 1.36 2002/10/23 09:11:10 jdolecek Exp $"); #include #include @@ -229,7 +229,7 @@ const struct bdevsw st_bdevsw = { const struct cdevsw st_cdevsw = { stopen, stclose, stread, stwrite, stioctl, - nostop, notty, nopoll, nommap, D_TAPE + nostop, notty, nopoll, nommap, nokqfilter, D_TAPE }; static int diff --git a/sys/arch/hp300/hp300/mem.c b/sys/arch/hp300/hp300/mem.c index 9fd7c2803269..8b81f6f3eaf8 100644 --- a/sys/arch/hp300/hp300/mem.c +++ b/sys/arch/hp300/hp300/mem.c @@ -1,4 +1,4 @@ -/* $NetBSD: mem.c,v 1.37 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: mem.c,v 1.38 2002/10/23 09:11:11 jdolecek Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -45,7 +45,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.37 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.38 2002/10/23 09:11:11 jdolecek Exp $"); #include #include @@ -69,7 +69,7 @@ dev_type_mmap(mmmmap); const struct cdevsw mem_cdevsw = { nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, mmmmap, + nostop, notty, nopoll, mmmmap, nokqfilter, }; /*ARGSUSED*/ diff --git a/sys/arch/hp700/dev/pdc.c b/sys/arch/hp700/dev/pdc.c index 04fc2848d185..a1d52aa254df 100644 --- a/sys/arch/hp700/dev/pdc.c +++ b/sys/arch/hp700/dev/pdc.c @@ -1,4 +1,4 @@ -/* $NetBSD: pdc.c,v 1.7 2002/10/02 05:17:48 thorpej Exp $ */ +/* $NetBSD: pdc.c,v 1.8 2002/10/23 09:11:14 jdolecek Exp $ */ /* $OpenBSD: pdc.c,v 1.14 2001/04/29 21:05:43 mickey Exp $ */ @@ -82,7 +82,7 @@ dev_type_poll(pdcpoll); const struct cdevsw pdc_cdevsw = { pdcopen, pdcclose, pdcread, pdcwrite, pdcioctl, - pdcstop, pdctty, pdcpoll, nommap, D_TTY + pdcstop, pdctty, pdcpoll, nommap, ttykqfilter, D_TTY }; void pdcstart __P((struct tty *tp)); diff --git a/sys/arch/hpcarm/dev/apm.c b/sys/arch/hpcarm/dev/apm.c index 5a7936b8e1ed..0584ba8a891e 100644 --- a/sys/arch/hpcarm/dev/apm.c +++ b/sys/arch/hpcarm/dev/apm.c @@ -1,4 +1,4 @@ -/* $NetBSD: apm.c,v 1.4 2002/10/07 21:32:10 jdolecek Exp $ */ +/* $NetBSD: apm.c,v 1.5 2002/10/23 09:11:15 jdolecek Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -39,7 +39,7 @@ #include "apm.h" #include -__KERNEL_RCSID(0, "$NetBSD: apm.c,v 1.4 2002/10/07 21:32:10 jdolecek Exp $"); +__KERNEL_RCSID(0, "$NetBSD: apm.c,v 1.5 2002/10/23 09:11:15 jdolecek Exp $"); #include #include @@ -73,7 +73,7 @@ CFATTACH_DECL(apm, sizeof(struct apm_softc), const struct cdevsw apm_cdevsw = { apmopen, apmclose, noread, nowrite, apmioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; diff --git a/sys/arch/hpcmips/dev/apm/apmdev.c b/sys/arch/hpcmips/dev/apm/apmdev.c index 9a2247016dc2..d2bcef2f12f2 100644 --- a/sys/arch/hpcmips/dev/apm/apmdev.c +++ b/sys/arch/hpcmips/dev/apm/apmdev.c @@ -1,4 +1,4 @@ -/* $NetBSD: apmdev.c,v 1.12 2002/10/14 13:34:09 takemura Exp $ */ +/* $NetBSD: apmdev.c,v 1.13 2002/10/23 09:11:17 jdolecek Exp $ */ /*- * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. @@ -154,10 +154,11 @@ dev_type_open(apmdevopen); dev_type_close(apmdevclose); dev_type_ioctl(apmdevioctl); dev_type_poll(apmdevpoll); +dev_type_kqfilter(apmdevkqfilter); const struct cdevsw apmdev_cdevsw = { apmdevopen, apmdevclose, noread, nowrite, apmdevioctl, - nostop, notty, apmdevpoll, nommap, + nostop, notty, apmdevpoll, nommap, apmdevkqfilter, }; /* configurable variables */ @@ -410,7 +411,7 @@ apm_record_event(struct apm_softc *sc, u_int event_type) sc->event_ptr %= APM_NEVENTS; evp->type = event_type; evp->index = ++apm_evindex; - selwakeup(&sc->sc_rsel); + selnotify(&sc->sc_rsel, 0); return (sc->sc_flags & SCFLAG_OWRITE) ? 0 : 1; /* user may handle */ } @@ -933,3 +934,50 @@ apmdevpoll(dev_t dev, int events, struct proc *p) return (revents); } + +static void +filt_apmrdetach(struct knote *kn) +{ + struct apm_softc *sc = kn->kn_hook; + + APM_LOCK(sc); + SLIST_REMOVE(&sc->sc_rsel.si_klist, kn, knote, kn_selnext); + APM_UNLOCK(sc); +} + +static int +filt_apmread(struct knote *kn, long hint) +{ + struct apm_softc *sc = kn->kn_hook; + + kn->kn_data = sc->event_count; + return (kn->kn_data > 0); +} + +static const struct filterops apmread_filtops = + { 1, NULL, filt_apmrdetach, filt_apmread }; + +int +apmdevkqfilter(dev_t dev, struct knote *kn) +{ + struct apm_softc *sc = apmdev_cd.cd_devs[APMUNIT(dev)]; + struct klist *klist; + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &sc->sc_rsel.si_klist; + kn->kn_fop = &apmread_filtops; + break; + + default: + return (1); + } + + kn->kn_hook = sc; + + APM_LOCK(sc); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + APM_UNLOCK(sc); + + return (0); +} diff --git a/sys/arch/hpcmips/dev/ucbsnd.c b/sys/arch/hpcmips/dev/ucbsnd.c index dc047c8e868f..a2c615e18a21 100644 --- a/sys/arch/hpcmips/dev/ucbsnd.c +++ b/sys/arch/hpcmips/dev/ucbsnd.c @@ -1,4 +1,4 @@ -/* $NetBSD: ucbsnd.c,v 1.13 2002/10/10 22:36:09 jdolecek Exp $ */ +/* $NetBSD: ucbsnd.c,v 1.14 2002/10/23 09:11:16 jdolecek Exp $ */ /*- * Copyright (c) 2000 The NetBSD Foundation, Inc. @@ -182,7 +182,7 @@ dev_type_write(ucbsndwrite); const struct cdevsw ucbsnd_cdevsw = { ucbsndopen, ucbsndclose, ucbsndread, ucbsndwrite, nullioctl, - nostop, notty, nopoll, nullmmap, + nostop, notty, nopoll, nullmmap, nokqfilter, }; int diff --git a/sys/arch/hpcmips/tx/txcom.c b/sys/arch/hpcmips/tx/txcom.c index c3108ba5b3c5..7c23e7ce2255 100644 --- a/sys/arch/hpcmips/tx/txcom.c +++ b/sys/arch/hpcmips/tx/txcom.c @@ -1,4 +1,4 @@ -/* $NetBSD: txcom.c,v 1.19 2002/10/02 05:26:51 thorpej Exp $ */ +/* $NetBSD: txcom.c,v 1.20 2002/10/23 09:11:18 jdolecek Exp $ */ /*- * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc. @@ -185,7 +185,7 @@ dev_type_poll(txcompoll); const struct cdevsw txcom_cdevsw = { txcomopen, txcomclose, txcomread, txcomwrite, txcomioctl, - txcomstop, txcomtty, txcompoll, nommap, D_TTY + txcomstop, txcomtty, txcompoll, nommap, ttykqfilter, D_TTY }; int diff --git a/sys/arch/i386/i386/apm.c b/sys/arch/i386/i386/apm.c index b29421059258..8b5f83222807 100644 --- a/sys/arch/i386/i386/apm.c +++ b/sys/arch/i386/i386/apm.c @@ -1,4 +1,4 @@ -/* $NetBSD: apm.c,v 1.73 2002/10/02 05:47:08 thorpej Exp $ */ +/* $NetBSD: apm.c,v 1.74 2002/10/23 09:11:19 jdolecek Exp $ */ /*- * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: apm.c,v 1.73 2002/10/02 05:47:08 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: apm.c,v 1.74 2002/10/23 09:11:19 jdolecek Exp $"); #include "apm.h" #if NAPM > 1 @@ -184,10 +184,11 @@ dev_type_open(apmopen); dev_type_close(apmclose); dev_type_ioctl(apmioctl); dev_type_poll(apmpoll); +dev_type_kqfilter(apmkqfilter); const struct cdevsw apm_cdevsw = { apmopen, apmclose, noread, nowrite, apmioctl, - nostop, notty, apmpoll, nommap, + nostop, notty, apmpoll, nommap, apmkqfilter, }; /* configurable variables */ @@ -613,7 +614,7 @@ apm_record_event(sc, event_type) sc->event_ptr %= APM_NEVENTS; evp->type = event_type; evp->index = ++apm_evindex; - selwakeup(&sc->sc_rsel); + selnotify(&sc->sc_rsel, 0); return (sc->sc_flags & SCFLAG_OWRITE) ? 0 : 1; /* user may handle */ } @@ -1816,3 +1817,50 @@ apmpoll(dev, events, p) return (revents); } + +static void +filt_apmrdetach(struct knote *kn) +{ + struct apm_softc *sc = kn->kn_hook; + + APM_LOCK(sc); + SLIST_REMOVE(&sc->sc_rsel.si_klist, kn, knote, kn_selnext); + APM_UNLOCK(sc); +} + +static int +filt_apmread(struct knote *kn, long hint) +{ + struct apm_softc *sc = kn->kn_hook; + + kn->kn_data = sc->event_count; + return (kn->kn_data > 0); +} + +static const struct filterops apmread_filtops = + { 1, NULL, filt_apmrdetach, filt_apmread }; + +int +apmkqfilter(dev_t dev, struct knote *kn) +{ + struct apm_softc *sc = apm_cd.cd_devs[APMUNIT(dev)]; + struct klist *klist; + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &sc->sc_rsel.si_klist; + kn->kn_fop = &apmread_filtops; + break; + + default: + return (1); + } + + kn->kn_hook = sc; + + APM_LOCK(sc); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + APM_UNLOCK(sc); + + return (0); +} diff --git a/sys/arch/i386/i386/mem.c b/sys/arch/i386/i386/mem.c index 80a3b16087da..5ce1dadb54ee 100644 --- a/sys/arch/i386/i386/mem.c +++ b/sys/arch/i386/i386/mem.c @@ -1,4 +1,4 @@ -/* $NetBSD: mem.c,v 1.53 2002/10/01 12:56:57 fvdl Exp $ */ +/* $NetBSD: mem.c,v 1.54 2002/10/23 09:11:21 jdolecek Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -45,7 +45,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.53 2002/10/01 12:56:57 fvdl Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.54 2002/10/23 09:11:21 jdolecek Exp $"); #include "opt_compat_netbsd.h" @@ -74,7 +74,7 @@ dev_type_mmap(mmmmap); const struct cdevsw mem_cdevsw = { mmopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, mmmmap, + nostop, notty, nopoll, mmmmap, nokqfilter, }; diff --git a/sys/arch/i386/isa/olms.c b/sys/arch/i386/isa/olms.c index 4ad47b10bbc7..6d08f748489c 100644 --- a/sys/arch/i386/isa/olms.c +++ b/sys/arch/i386/isa/olms.c @@ -1,4 +1,4 @@ -/* $NetBSD: olms.c,v 1.8 2002/10/02 05:47:13 thorpej Exp $ */ +/* $NetBSD: olms.c,v 1.9 2002/10/23 09:11:21 jdolecek Exp $ */ /*- * Copyright (c) 1993, 1994 Charles M. Hannum. @@ -24,7 +24,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: olms.c,v 1.8 2002/10/02 05:47:13 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: olms.c,v 1.9 2002/10/23 09:11:21 jdolecek Exp $"); #include #include @@ -88,10 +88,11 @@ dev_type_close(lmsclose); dev_type_read(lmsread); dev_type_ioctl(lmsioctl); dev_type_poll(lmspoll); +dev_type_kqfilter(lmskqfilter); const struct cdevsw olms_cdevsw = { lmsopen, lmsclose, lmsread, nowrite, lmsioctl, - nostop, notty, lmspoll, nommap, + nostop, notty, lmspoll, nommap, lmskqfilter, }; #define LMSUNIT(dev) (minor(dev)) @@ -386,7 +387,7 @@ olmsintr(arg) sc->sc_state &= ~LMS_ASLP; wakeup((caddr_t)sc); } - selwakeup(&sc->sc_rsel); + selnotify(&sc->sc_rsel, 0); } return -1; @@ -412,3 +413,52 @@ lmspoll(dev, events, p) splx(s); return (revents); } + +static void +filt_lmsrdetach(struct knote *kn) +{ + struct olms_softc *sc = kn->kn_hook; + int s; + + s = spltty(); + SLIST_REMOVE(&sc->sc_rsel.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_lmsread(struct knote *kn, long hint) +{ + struct olms_softc *sc = kn->kn_hook; + + kn->kn_data = sc->sc_q.c_cc; + return (kn->kn_data > 0); +} + +static const struct filterops lmsread_filtops = + { 1, NULL, filt_lmsrdetach, filt_lmsread }; + +int +lmskqfilter(dev_t dev, struct knote *kn) +{ + struct olms_softc *sc = olms_cd.cd_devs[LMSUNIT(dev)]; + struct klist *klist; + int s; + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &sc->sc_rsel.si_klist; + kn->kn_fop = &lmsread_filtops; + break; + + default: + return (1); + } + + kn->kn_hook = sc; + + s = spltty(); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + splx(s); + + return (0); +} diff --git a/sys/arch/i386/isa/omms.c b/sys/arch/i386/isa/omms.c index 09693a7ceac6..6d645168b781 100644 --- a/sys/arch/i386/isa/omms.c +++ b/sys/arch/i386/isa/omms.c @@ -1,4 +1,4 @@ -/* $NetBSD: omms.c,v 1.8 2002/10/02 05:47:14 thorpej Exp $ */ +/* $NetBSD: omms.c,v 1.9 2002/10/23 09:11:22 jdolecek Exp $ */ /*- * Copyright (c) 1993, 1994 Charles M. Hannum. @@ -24,7 +24,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: omms.c,v 1.8 2002/10/02 05:47:14 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: omms.c,v 1.9 2002/10/23 09:11:22 jdolecek Exp $"); #include #include @@ -86,10 +86,11 @@ dev_type_close(mmsclose); dev_type_read(mmsread); dev_type_ioctl(mmsioctl); dev_type_poll(mmspoll); +dev_type_kqfilter(mmskqfilter); const struct cdevsw omms_cdevsw = { mmsopen, mmsclose, mmsread, nowrite, mmsioctl, - nostop, notty, mmspoll, nommap, + nostop, notty, mmspoll, nommap, mmskqfilter, }; @@ -382,7 +383,7 @@ ommsintr(arg) sc->sc_state &= ~MMS_ASLP; wakeup((caddr_t)sc); } - selwakeup(&sc->sc_rsel); + selnotify(&sc->sc_rsel, 0); } return -1; @@ -408,3 +409,52 @@ mmspoll(dev, events, p) splx(s); return (revents); } + +static void +filt_mmsrdetach(struct knote *kn) +{ + struct omms_softc *sc = kn->kn_hook; + int s; + + s = spltty(); + SLIST_REMOVE(&sc->sc_rsel.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_mmsread(struct knote *kn, long hint) +{ + struct omms_softc *sc = kn->kn_hook; + + kn->kn_data = sc->sc_q.c_cc; + return (kn->kn_data > 0); +} + +static const struct filterops mmsread_filtops = + { 1, NULL, filt_mmsrdetach, filt_mmsread }; + +int +mmskqfilter(dev_t dev, struct knote *kn) +{ + struct omms_softc *sc = omms_cd.cd_devs[MMSUNIT(dev)]; + struct klist *klist; + int s; + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &sc->sc_rsel.si_klist; + kn->kn_fop = &mmsread_filtops; + break; + + default: + return (1); + } + + kn->kn_hook = sc; + + s = spltty(); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + splx(s); + + return (0); +} diff --git a/sys/arch/i386/isa/pccons.c b/sys/arch/i386/isa/pccons.c index 1d7a60ab9abd..7b8ed5261589 100644 --- a/sys/arch/i386/isa/pccons.c +++ b/sys/arch/i386/isa/pccons.c @@ -1,4 +1,4 @@ -/* $NetBSD: pccons.c,v 1.158 2002/10/02 15:52:22 thorpej Exp $ */ +/* $NetBSD: pccons.c,v 1.159 2002/10/23 09:11:23 jdolecek Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -83,7 +83,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pccons.c,v 1.158 2002/10/02 15:52:22 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pccons.c,v 1.159 2002/10/23 09:11:23 jdolecek Exp $"); #include "opt_ddb.h" #include "opt_xserver.h" @@ -242,7 +242,7 @@ dev_type_mmap(pcmmap); const struct cdevsw pc_cdevsw = { pcopen, pcclose, pcread, pcwrite, pcioctl, - pcstop, pctty, pcpoll, pcmmap, D_TTY + pcstop, pctty, pcpoll, pcmmap, ttykqfilter, D_TTY }; #define COL 80 diff --git a/sys/arch/luna68k/dev/siotty.c b/sys/arch/luna68k/dev/siotty.c index cbd16de72cc2..27c8ba41c82c 100644 --- a/sys/arch/luna68k/dev/siotty.c +++ b/sys/arch/luna68k/dev/siotty.c @@ -1,4 +1,4 @@ -/* $NetBSD: siotty.c,v 1.11 2002/10/02 05:31:46 thorpej Exp $ */ +/* $NetBSD: siotty.c,v 1.12 2002/10/23 09:11:25 jdolecek Exp $ */ /*- * Copyright (c) 2000 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ #include /* RCS ID & Copyright macro defns */ -__KERNEL_RCSID(0, "$NetBSD: siotty.c,v 1.11 2002/10/02 05:31:46 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: siotty.c,v 1.12 2002/10/23 09:11:25 jdolecek Exp $"); #include "opt_ddb.h" @@ -110,7 +110,7 @@ dev_type_poll(siopoll); const struct cdevsw siotty_cdevsw = { sioopen, sioclose, sioread, siowrite, sioioctl, - siostop, siotty, siopoll, nommap, D_TTY + siostop, siotty, siopoll, nommap, ttykqfilter, D_TTY }; static int diff --git a/sys/arch/luna68k/luna68k/mem.c b/sys/arch/luna68k/luna68k/mem.c index ae36fcf7be90..4812d501dca2 100644 --- a/sys/arch/luna68k/luna68k/mem.c +++ b/sys/arch/luna68k/luna68k/mem.c @@ -1,4 +1,4 @@ -/* $NetBSD: mem.c,v 1.7 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: mem.c,v 1.8 2002/10/23 09:11:26 jdolecek Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -42,7 +42,7 @@ #include /* RCS ID & Copyright macro defns */ -__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.7 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.8 2002/10/23 09:11:26 jdolecek Exp $"); /* * Memory special file @@ -69,7 +69,7 @@ dev_type_mmap(mmmmap); const struct cdevsw mem_cdevsw = { nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, mmmmap, + nostop, notty, nopoll, mmmmap, nokqfilter, }; /*ARGSUSED*/ diff --git a/sys/arch/mac68k/dev/aed.c b/sys/arch/mac68k/dev/aed.c index f92ea382c59a..5a50a931c970 100644 --- a/sys/arch/mac68k/dev/aed.c +++ b/sys/arch/mac68k/dev/aed.c @@ -1,4 +1,4 @@ -/* $NetBSD: aed.c,v 1.14 2002/10/02 05:36:37 thorpej Exp $ */ +/* $NetBSD: aed.c,v 1.15 2002/10/23 09:11:28 jdolecek Exp $ */ /* * Copyright (C) 1994 Bradley A. Grantham @@ -79,10 +79,11 @@ dev_type_close(aedclose); dev_type_read(aedread); dev_type_ioctl(aedioctl); dev_type_poll(aedpoll); +dev_type_kqfilter(aedkqfilter); const struct cdevsw aed_cdevsw = { aedopen, aedclose, aedread, nullwrite, aedioctl, - nostop, notty, aedpoll, nommap, + nostop, notty, aedpoll, nommap, aedkqfilter, }; static int @@ -408,7 +409,7 @@ aed_enqevent(event) AED_MAX_EVENTS] = *event; aed_sc->sc_evq_len++; - selwakeup(&aed_sc->sc_selinfo); + selnotify(&aed_sc->sc_selinfo, 0); if (aed_sc->sc_ioproc) psignal(aed_sc->sc_ioproc, SIGIO); @@ -600,3 +601,57 @@ aedpoll(dev, events, p) return (revents); } + +static void +filt_aedrdetach(struct knote *kn) +{ + int s; + + s = spladb(); + SLIST_REMOVE(&aed_sc->sc_selinfo.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_aedread(struct knote *kn, long hint) +{ + + kn->kn_data = aed_sc->sc_evq_len * sizeof(adb_event_t); + return (kn->kn_data > 0); +} + +static const struct filterops aedread_filtops = + { 1, NULL, filt_aedrdetach, filt_aedread }; + +static const struct filterops aed_seltrue_filtops = + { 1, NULL, filt_aedrdetach, filt_seltrue }; + +int +aedkqfilter(dev_t dev, struct knote *kn) +{ + struct klist *klist; + int s; + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &aed_sc->sc_selinfo.si_klist; + kn->kn_fop = &aedread_filtops; + break; + + case EVFILT_WRITE: + klist = &aed_sc->sc_selinfo.si_klist; + kn->kn_fop = &aed_seltrue_filtops; + break; + + default: + return (1); + } + + kn->kn_hook = NULL; + + s = spladb(); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + splx(s); + + return (0); +} diff --git a/sys/arch/mac68k/dev/grf_compat.c b/sys/arch/mac68k/dev/grf_compat.c index 39ff126fb1d3..82a420a517e6 100644 --- a/sys/arch/mac68k/dev/grf_compat.c +++ b/sys/arch/mac68k/dev/grf_compat.c @@ -1,4 +1,4 @@ -/* $NetBSD: grf_compat.c,v 1.9 2002/10/10 22:33:16 jdolecek Exp $ */ +/* $NetBSD: grf_compat.c,v 1.10 2002/10/23 09:11:28 jdolecek Exp $ */ /* * Copyright (C) 1999 Scott Reynolds @@ -64,7 +64,7 @@ dev_type_mmap(grfmmap); const struct cdevsw grf_cdevsw = { grfopen, grfclose, noread, nowrite, grfioctl, - nostop, notty, nopoll, grfmmap, + nostop, notty, nopoll, grfmmap, nokqfilter, }; void grf_scinit __P((struct grf_softc *, const char *, int)); diff --git a/sys/arch/mac68k/dev/ite_compat.c b/sys/arch/mac68k/dev/ite_compat.c index fadc18bcc37b..220c80b7c713 100644 --- a/sys/arch/mac68k/dev/ite_compat.c +++ b/sys/arch/mac68k/dev/ite_compat.c @@ -1,4 +1,4 @@ -/* $NetBSD: ite_compat.c,v 1.5 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: ite_compat.c,v 1.6 2002/10/23 09:11:28 jdolecek Exp $ */ /* * Copyright (C) 2000 Scott Reynolds @@ -57,10 +57,11 @@ dev_type_write(itewrite); dev_type_ioctl(iteioctl); dev_type_tty(itetty); dev_type_poll(itepoll); +dev_type_kqfilter(itekqfilter); const struct cdevsw ite_cdevsw = { iteopen, iteclose, iteread, itewrite, iteioctl, - nostop, itetty, itepoll, nommap, D_TTY + nostop, itetty, itepoll, nommap, itekqfilter, D_TTY }; #if NWSDISPLAY > 0 @@ -209,3 +210,12 @@ itepoll(dev, events, p) return ite_initted ? (*wsdisplay_cdevsw.d_poll)(cn_tab->cn_dev, events, p) : (ENXIO); } + +int +itekqfilter(dev, kn) + dev_t dev; + struct knote *kn; +{ + return ite_initted ? + (*wsdisplay_cdevsw.d_kqfilter)(cn_tab->cn_dev, kn) : (ENXIO); +} diff --git a/sys/arch/mac68k/mac68k/mem.c b/sys/arch/mac68k/mac68k/mem.c index 9f740adb47e6..16549d3e98e0 100644 --- a/sys/arch/mac68k/mac68k/mem.c +++ b/sys/arch/mac68k/mac68k/mem.c @@ -1,4 +1,4 @@ -/* $NetBSD: mem.c,v 1.31 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: mem.c,v 1.32 2002/10/23 09:11:29 jdolecek Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -65,7 +65,7 @@ dev_type_mmap(mmmmap); const struct cdevsw mem_cdevsw = { nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, mmmmap, + nostop, notty, nopoll, mmmmap, nokqfilter, }; /*ARGSUSED*/ diff --git a/sys/arch/mac68k/obio/asc.c b/sys/arch/mac68k/obio/asc.c index 930b281ac542..b9322df39114 100644 --- a/sys/arch/mac68k/obio/asc.c +++ b/sys/arch/mac68k/obio/asc.c @@ -1,4 +1,4 @@ -/* $NetBSD: asc.c,v 1.43 2002/10/10 22:33:16 jdolecek Exp $ */ +/* $NetBSD: asc.c,v 1.44 2002/10/23 09:11:30 jdolecek Exp $ */ /* * Copyright (C) 1997 Scott Reynolds @@ -120,7 +120,7 @@ dev_type_mmap(ascmmap); const struct cdevsw asc_cdevsw = { ascopen, ascclose, ascread, ascwrite, ascioctl, - nostop, notty, nopoll, ascmmap, + nostop, notty, nopoll, ascmmap, nokqfilter, }; static int diff --git a/sys/arch/mac68k/obio/iwm_fd.c b/sys/arch/mac68k/obio/iwm_fd.c index 184a9df65e4e..082ce0169d2a 100644 --- a/sys/arch/mac68k/obio/iwm_fd.c +++ b/sys/arch/mac68k/obio/iwm_fd.c @@ -1,4 +1,4 @@ -/* $NetBSD: iwm_fd.c,v 1.17 2002/10/02 20:35:28 jdolecek Exp $ */ +/* $NetBSD: iwm_fd.c,v 1.18 2002/10/23 09:11:30 jdolecek Exp $ */ /* * Copyright (c) 1997, 1998 Hauke Fath. All rights reserved. @@ -40,6 +40,7 @@ #include #include #include +#include #define FSTYPENAMES #define DKTYPENAMES @@ -241,7 +242,7 @@ const struct bdevsw fd_bdevsw = { const struct cdevsw fd_cdevsw = { fdopen, fdclose, fdread, fdwrite, fdioctl, - nostop, notty, nopoll, nommap, D_DISK + nostop, notty, nopoll, nommap, nokqfilter, D_DISK }; /* disk(9) framework device switch */ diff --git a/sys/arch/macppc/dev/aed.c b/sys/arch/macppc/dev/aed.c index 0dd6cdb63b1c..219cc4e931ec 100644 --- a/sys/arch/macppc/dev/aed.c +++ b/sys/arch/macppc/dev/aed.c @@ -1,4 +1,4 @@ -/* $NetBSD: aed.c,v 1.9 2002/10/02 05:30:38 thorpej Exp $ */ +/* $NetBSD: aed.c,v 1.10 2002/10/23 09:11:32 jdolecek Exp $ */ /* * Copyright (C) 1994 Bradley A. Grantham @@ -83,10 +83,11 @@ dev_type_close(aedclose); dev_type_read(aedread); dev_type_ioctl(aedioctl); dev_type_poll(aedpoll); +dev_type_kqfilter(aedkqfilter); const struct cdevsw aed_cdevsw = { aedopen, aedclose, aedread, nullwrite, aedioctl, - nostop, notty, aedpoll, nommap, + nostop, notty, aedpoll, nommap, aedkqfilter, }; static int @@ -409,7 +410,7 @@ aed_enqevent(event) AED_MAX_EVENTS] = *event; aed_sc->sc_evq_len++; - selwakeup(&aed_sc->sc_selinfo); + selnotify(&aed_sc->sc_selinfo, 0); if (aed_sc->sc_ioproc) psignal(aed_sc->sc_ioproc, SIGIO); @@ -601,3 +602,57 @@ aedpoll(dev, events, p) return (revents); } + +static void +filt_aedrdetach(struct knote *kn) +{ + int s; + + s = spladb(); + SLIST_REMOVE(&aed_sc->sc_selinfo.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_aedread(struct knote *kn, long hint) +{ + + kn->kn_data = aed_sc->sc_evq_len * sizeof(adb_event_t); + return (kn->kn_data > 0); +} + +static const struct filterops aedread_filtops = + { 1, NULL, filt_aedrdetach, filt_aedread }; + +static const struct filterops aed_seltrue_filtops = + { 1, NULL, filt_aedrdetach, filt_seltrue }; + +int +aedkqfilter(dev_t dev, struct knote *kn) +{ + struct klist *klist; + int s; + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &aed_sc->sc_selinfo.si_klist; + kn->kn_fop = &aedread_filtops; + break; + + case EVFILT_WRITE: + klist = &aed_sc->sc_selinfo.si_klist; + kn->kn_fop = &aed_seltrue_filtops; + break; + + default: + return (1); + } + + kn->kn_hook = NULL; + + s = spladb(); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + splx(s); + + return (0); +} diff --git a/sys/arch/macppc/dev/apm.c b/sys/arch/macppc/dev/apm.c index f831801fe0e8..2247ecaeb1d3 100644 --- a/sys/arch/macppc/dev/apm.c +++ b/sys/arch/macppc/dev/apm.c @@ -1,4 +1,4 @@ -/* $NetBSD: apm.c,v 1.4 2002/10/02 05:30:39 thorpej Exp $ */ +/* $NetBSD: apm.c,v 1.5 2002/10/23 09:11:32 jdolecek Exp $ */ /* $OpenBSD: apm.c,v 1.5 2002/06/07 07:13:59 miod Exp $ */ /*- @@ -128,10 +128,11 @@ dev_type_open(apmopen); dev_type_close(apmclose); dev_type_ioctl(apmioctl); dev_type_poll(apmpoll); +dev_type_kqfilter(apmkqfilter); const struct cdevsw apm_cdevsw = { apmopen, apmclose, noread, nowrite, apmioctl, - nostop, notty, apmpoll, nommap, + nostop, notty, apmpoll, nommap, apmkqfilter, }; #endif @@ -142,15 +143,6 @@ int apm_evindex; #define APMDEV_NORMAL 0 #define APMDEV_CTL 8 -#ifdef __OpenBSD__ -void filt_apmrdetach(struct knote *kn); -int filt_apmread(struct knote *kn, long hint); -int apmkqfilter(dev_t dev, struct knote *kn); - -struct filterops apmread_filtops = - { 1, NULL, filt_apmrdetach, filt_apmread}; -#endif - /* * Flags to control kernel display * SCFLAG_NOPRINT: do not output APM power messages due to @@ -431,51 +423,50 @@ apmpoll(dev, events, p) } #endif -#ifdef __OpenBSD__ -void -filt_apmrdetach(kn) - struct knote *kn; +static void +filt_apmrdetach(struct knote *kn) { struct apm_softc *sc = (struct apm_softc *)kn->kn_hook; - SLIST_REMOVE(&sc->sc_note, kn, knote, kn_selnext); + APM_LOCK(sc); + SLIST_REMOVE(&sc->sc_rsel.si_klist, kn, knote, kn_selnext); + APM_UNLOCK(sc); } -int -filt_apmread(kn, hint) - struct knote *kn; - long hint; +static int +filt_apmread(struct knote *kn, long hint) { - /* XXX weird kqueue_scan() semantics */ - if (hint && !kn->kn_data) - kn->kn_data = (int)hint; + struct apm_softc *sc = kn->kn_hook; - return (1); + kn->kn_data = sc->event_count; + return (kn->kn_data > 0); } +static struct filterops apmread_filtops = + { 1, NULL, filt_apmrdetach, filt_apmread}; + int apmkqfilter(dev, kn) dev_t dev; struct knote *kn; { - struct apm_softc *sc; - - /* apm0 only */ - if (!apm_cd.cd_ndevs || APMUNIT(dev) != 0 || - !(sc = apm_cd.cd_devs[APMUNIT(dev)])) - return ENXIO; + struct apm_softc *sc = apm_cd.cd_devs[APMUNIT(dev)]; + struct klist *klist; switch (kn->kn_filter) { case EVFILT_READ: + klist = &sc->sc_rsel.si_klist; kn->kn_fop = &apmread_filtops; break; default: return (1); } - kn->kn_hook = (caddr_t)sc; - SLIST_INSERT_HEAD(&sc->sc_note, kn, kn_selnext); + kn->kn_hook = sc; + + APM_LOCK(sc); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + APM_UNLOCK(sc); return (0); } -#endif diff --git a/sys/arch/macppc/dev/nvram.c b/sys/arch/macppc/dev/nvram.c index a081c4cedd38..5d4ee8ada821 100644 --- a/sys/arch/macppc/dev/nvram.c +++ b/sys/arch/macppc/dev/nvram.c @@ -1,4 +1,4 @@ -/* $NetBSD: nvram.c,v 1.7 2002/10/02 05:30:42 thorpej Exp $ */ +/* $NetBSD: nvram.c,v 1.8 2002/10/23 09:11:33 jdolecek Exp $ */ /*- * Copyright (C) 1998 Internet Research Institute, Inc. @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -70,7 +71,7 @@ dev_type_mmap(nvrammmap); const struct cdevsw nvram_cdevsw = { nullopen, nullclose, nvramread, nvramwrite, noioctl, - nostop, notty, nopoll, nvrammmap, + nostop, notty, nopoll, nvrammmap, nokqfilter, }; int diff --git a/sys/arch/macppc/dev/ofcons.c b/sys/arch/macppc/dev/ofcons.c index 3ab6014d3fc0..39c16ba80253 100644 --- a/sys/arch/macppc/dev/ofcons.c +++ b/sys/arch/macppc/dev/ofcons.c @@ -1,4 +1,4 @@ -/* $NetBSD: ofcons.c,v 1.11 2002/10/02 05:30:43 thorpej Exp $ */ +/* $NetBSD: ofcons.c,v 1.12 2002/10/23 09:11:33 jdolecek Exp $ */ /* * Copyright (C) 1995, 1996 Wolfgang Solfrank. @@ -79,7 +79,7 @@ dev_type_poll(ofcpoll); const struct cdevsw macofcons_cdevsw = { ofcopen, ofcclose, ofcread, ofcwrite, ofcioctl, - nostop, ofctty, ofcpoll, nommap, D_TTY + nostop, ofctty, ofcpoll, nommap, ttykqfilter, D_TTY }; /* For polled ADB mode */ diff --git a/sys/arch/macppc/dev/z8530tty.c b/sys/arch/macppc/dev/z8530tty.c index 5f7ed11c4ed2..ed3ce058e2da 100644 --- a/sys/arch/macppc/dev/z8530tty.c +++ b/sys/arch/macppc/dev/z8530tty.c @@ -1,4 +1,4 @@ -/* $NetBSD: z8530tty.c,v 1.15 2002/10/02 05:30:44 thorpej Exp $ */ +/* $NetBSD: z8530tty.c,v 1.16 2002/10/23 09:11:33 jdolecek Exp $ */ /*- * Copyright (c) 1993, 1994, 1995, 1996, 1997, 1998, 1999 @@ -210,7 +210,7 @@ dev_type_poll(zspoll); const struct cdevsw zstty_cdevsw = { zsopen, zsclose, zsread, zswrite, zsioctl, - zsstop, zstty, zspoll, nommap, D_TTY + zsstop, zstty, zspoll, nommap, ttykqfilter, D_TTY }; struct zsops zsops_tty; diff --git a/sys/arch/mips/alchemy/dev/aucom.c b/sys/arch/mips/alchemy/dev/aucom.c index 91ef0a0dae39..0be485975fd4 100644 --- a/sys/arch/mips/alchemy/dev/aucom.c +++ b/sys/arch/mips/alchemy/dev/aucom.c @@ -1,6 +1,6 @@ #define AU1x00_UART /* XXX */ -/* $NetBSD: aucom.c,v 1.2 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: aucom.c,v 1.3 2002/10/23 09:11:34 jdolecek Exp $ */ /*- * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc. @@ -80,7 +80,7 @@ * XXX: hacked to work with almost 16550-alike Alchemy Au1X00 on-chip uarts */ #include -__KERNEL_RCSID(0, "$NetBSD: aucom.c,v 1.2 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: aucom.c,v 1.3 2002/10/23 09:11:34 jdolecek Exp $"); #include "opt_com.h" #include "opt_ddb.h" @@ -244,7 +244,7 @@ dev_type_poll(compoll); const struct cdevsw com_cdevsw = { comopen, comclose, comread, comwrite, comioctl, - comstop, comtty, compoll, nommap, D_TTY + comstop, comtty, compoll, nommap, ttykqfilter, D_TTY }; /* diff --git a/sys/arch/mips/mips/mem.c b/sys/arch/mips/mips/mem.c index 810fb1bd0673..7985bc85a65c 100644 --- a/sys/arch/mips/mips/mem.c +++ b/sys/arch/mips/mips/mem.c @@ -1,4 +1,4 @@ -/* $NetBSD: mem.c,v 1.25 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: mem.c,v 1.26 2002/10/23 09:11:36 jdolecek Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -64,13 +64,13 @@ dev_type_ioctl(mmioctl); const struct cdevsw mem_cdevsw = { nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; #if defined(pmax) const struct cdevsw mem_ultrix_cdevsw = { nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; #endif /* defined(pmax) */ diff --git a/sys/arch/mips/sibyte/dev/sbjcn.c b/sys/arch/mips/sibyte/dev/sbjcn.c index 34d465ed4086..2b94aadb6ccf 100644 --- a/sys/arch/mips/sibyte/dev/sbjcn.c +++ b/sys/arch/mips/sibyte/dev/sbjcn.c @@ -1,4 +1,4 @@ -/* $NetBSD: sbjcn.c,v 1.4 2002/10/02 15:52:25 thorpej Exp $ */ +/* $NetBSD: sbjcn.c,v 1.5 2002/10/23 09:11:37 jdolecek Exp $ */ /* * Copyright 2000, 2001 @@ -184,7 +184,7 @@ dev_type_tty(sbjcntty); const struct cdevsw sbjcn_cdevsw = { sbjcnopen, sbjcnclose, sbjcnread, sbjcnwrite, sbjcnioctl, - sbjcnstop, sbjcntty, nopoll, nommap, D_TTY + sbjcnstop, sbjcntty, nopoll, nommap, ttykqfilter, D_TTY }; #define integrate static inline diff --git a/sys/arch/mips/sibyte/dev/sbscn.c b/sys/arch/mips/sibyte/dev/sbscn.c index d3ba31ba852b..369ddd7ac658 100644 --- a/sys/arch/mips/sibyte/dev/sbscn.c +++ b/sys/arch/mips/sibyte/dev/sbscn.c @@ -1,4 +1,4 @@ -/* $NetBSD: sbscn.c,v 1.4 2002/10/02 15:52:26 thorpej Exp $ */ +/* $NetBSD: sbscn.c,v 1.5 2002/10/23 09:11:38 jdolecek Exp $ */ /* * Copyright 2000, 2001 @@ -196,7 +196,7 @@ dev_type_poll(sbscnpoll); const struct cdevsw sbscn_cdevsw = { sbscnopen, sbscnclose, sbscnread, sbscnwrite, sbscnioctl, - sbscnstop, sbscntty, sbscnpoll, nommap, D_TTY + sbscnstop, sbscntty, sbscnpoll, nommap, ttykqfilter, D_TTY }; #define integrate static inline diff --git a/sys/arch/mipsco/obio/i82072.c b/sys/arch/mipsco/obio/i82072.c index 9cf2ffa26a64..95762906c4c4 100644 --- a/sys/arch/mipsco/obio/i82072.c +++ b/sys/arch/mipsco/obio/i82072.c @@ -1,4 +1,4 @@ -/* $NetBSD: i82072.c,v 1.6 2002/10/02 05:38:10 thorpej Exp $ */ +/* $NetBSD: i82072.c,v 1.7 2002/10/23 09:11:39 jdolecek Exp $ */ /*- * Copyright (c) 2000 The NetBSD Foundation, Inc. * All rights reserved. @@ -42,6 +42,7 @@ #include #include #include +#include #include #include @@ -57,7 +58,7 @@ const struct bdevsw fd_bdevsw = { const struct cdevsw fd_cdevsw = { fdopen, nullclose, noread, nowrite, noioctl, - nostop, notty, nopoll, nommap, D_DISK + nostop, notty, nopoll, nommap, nokqfilter, D_DISK }; #define I82072_STATUS 0x000003 diff --git a/sys/arch/mvme68k/mvme68k/mem.c b/sys/arch/mvme68k/mvme68k/mem.c index bcdd7b09341f..eb790ab9458f 100644 --- a/sys/arch/mvme68k/mvme68k/mem.c +++ b/sys/arch/mvme68k/mvme68k/mem.c @@ -1,4 +1,4 @@ -/* $NetBSD: mem.c,v 1.19 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: mem.c,v 1.20 2002/10/23 09:11:39 jdolecek Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -65,7 +65,7 @@ dev_type_mmap(mmmmap); const struct cdevsw mem_cdevsw = { nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, mmmmap, + nostop, notty, nopoll, mmmmap, nokqfilter, }; /*ARGSUSED*/ diff --git a/sys/arch/news68k/news68k/mem.c b/sys/arch/news68k/news68k/mem.c index c51c6b3824ef..a5f372aba50f 100644 --- a/sys/arch/news68k/news68k/mem.c +++ b/sys/arch/news68k/news68k/mem.c @@ -1,4 +1,4 @@ -/* $NetBSD: mem.c,v 1.11 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: mem.c,v 1.12 2002/10/23 09:11:40 jdolecek Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -64,7 +64,7 @@ dev_type_mmap(mmmmap); const struct cdevsw mem_cdevsw = { nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, mmmmap, + nostop, notty, nopoll, mmmmap, nokqfilter, }; /*ARGSUSED*/ diff --git a/sys/arch/next68k/next68k/mem.c b/sys/arch/next68k/next68k/mem.c index 900f51e05f59..4da975671610 100644 --- a/sys/arch/next68k/next68k/mem.c +++ b/sys/arch/next68k/next68k/mem.c @@ -1,4 +1,4 @@ -/* $NetBSD: mem.c,v 1.17 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: mem.c,v 1.18 2002/10/23 09:11:42 jdolecek Exp $ */ /* * This file was taken from mvme68k/mvme68k/mem.c @@ -72,7 +72,7 @@ dev_type_mmap(mmmmap); const struct cdevsw mem_cdevsw = { nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, mmmmap, + nostop, notty, nopoll, mmmmap, nokqfilter, }; /*ARGSUSED*/ diff --git a/sys/arch/pc532/dev/lpt.c b/sys/arch/pc532/dev/lpt.c index 98a720553b48..1c5e24482209 100644 --- a/sys/arch/pc532/dev/lpt.c +++ b/sys/arch/pc532/dev/lpt.c @@ -1,4 +1,4 @@ -/* $NetBSD: lpt.c,v 1.37 2002/10/02 04:18:56 thorpej Exp $ */ +/* $NetBSD: lpt.c,v 1.38 2002/10/23 09:11:43 jdolecek Exp $ */ /* * Copyright (c) 1994 Matthias Pfaller. @@ -217,7 +217,7 @@ dev_type_ioctl(lptioctl); const struct cdevsw lpt_cdevsw = { lptopen, lptclose, noread, lptwrite, lptioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; static int diff --git a/sys/arch/pc532/dev/scn.c b/sys/arch/pc532/dev/scn.c index eb3b318603cb..8d9d0de73fcc 100644 --- a/sys/arch/pc532/dev/scn.c +++ b/sys/arch/pc532/dev/scn.c @@ -1,4 +1,4 @@ -/* $NetBSD: scn.c,v 1.56 2002/10/02 04:18:57 thorpej Exp $ */ +/* $NetBSD: scn.c,v 1.57 2002/10/23 09:11:44 jdolecek Exp $ */ /* * Copyright (c) 1996, 1997 Philip L. Budne. @@ -106,7 +106,7 @@ dev_type_poll(scnpoll); const struct cdevsw scn_cdevsw = { scnopen, scnclose, scnread, scnwrite, scnioctl, - scnstop, scntty, scnpoll, nommap, D_TTY + scnstop, scntty, scnpoll, nommap, ttykqfilter, D_TTY }; #ifndef CONSOLE_SPEED diff --git a/sys/arch/pc532/pc532/mem.c b/sys/arch/pc532/pc532/mem.c index 32bef2ba238a..776f37cf42d9 100644 --- a/sys/arch/pc532/pc532/mem.c +++ b/sys/arch/pc532/pc532/mem.c @@ -1,4 +1,4 @@ -/* $NetBSD: mem.c,v 1.31 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: mem.c,v 1.32 2002/10/23 09:11:45 jdolecek Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -65,7 +65,7 @@ dev_type_mmap(mmmmap); const struct cdevsw mem_cdevsw = { nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, mmmmap, + nostop, notty, nopoll, mmmmap, nokqfilter, }; /*ARGSUSED*/ diff --git a/sys/arch/pmax/dev/dc.c b/sys/arch/pmax/dev/dc.c index 7279b6a1ac0a..2becee1daea9 100644 --- a/sys/arch/pmax/dev/dc.c +++ b/sys/arch/pmax/dev/dc.c @@ -1,4 +1,4 @@ -/* $NetBSD: dc.c,v 1.70 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: dc.c,v 1.71 2002/10/23 09:11:46 jdolecek Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -39,7 +39,7 @@ */ #include /* RCS ID & Copyright macro defns */ -__KERNEL_RCSID(0, "$NetBSD: dc.c,v 1.70 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dc.c,v 1.71 2002/10/23 09:11:46 jdolecek Exp $"); /* * devDC7085.c -- @@ -108,7 +108,7 @@ dev_type_poll(dcpoll); const struct cdevsw dc_cdevsw = { dcopen, dcclose, dcread, dcwrite, dcioctl, - dcstop, dctty, dcpoll, nommap, D_TTY + dcstop, dctty, dcpoll, nommap, ttykqfilter, D_TTY }; /* diff --git a/sys/arch/pmax/dev/dtop.c b/sys/arch/pmax/dev/dtop.c index 5e7cdcf3dfaf..f13035ba5512 100644 --- a/sys/arch/pmax/dev/dtop.c +++ b/sys/arch/pmax/dev/dtop.c @@ -1,4 +1,4 @@ -/* $NetBSD: dtop.c,v 1.61 2002/10/02 04:15:07 thorpej Exp $ */ +/* $NetBSD: dtop.c,v 1.62 2002/10/23 09:11:48 jdolecek Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -94,7 +94,7 @@ SOFTWARE. ********************************************************/ #include /* RCS ID & Copyright macro defns */ -__KERNEL_RCSID(0, "$NetBSD: dtop.c,v 1.61 2002/10/02 04:15:07 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dtop.c,v 1.62 2002/10/23 09:11:48 jdolecek Exp $"); #include "opt_ddb.h" #include "rasterconsole.h" @@ -242,7 +242,7 @@ dev_type_poll(dtoppoll); const struct cdevsw dtop_cdevsw = { dtopopen, dtopclose, dtopread, dtopwrite, dtopioctl, - dtopstop, dtoptty, dtoppoll, nommap, D_TTY + dtopstop, dtoptty, dtoppoll, nommap, ttykqfilter, D_TTY }; /* QVSS-compatible in-kernel X input event parser, pointer tracker */ diff --git a/sys/arch/pmax/dev/fb_usrreq.c b/sys/arch/pmax/dev/fb_usrreq.c index d8c8548edd46..76ddb6cadea5 100644 --- a/sys/arch/pmax/dev/fb_usrreq.c +++ b/sys/arch/pmax/dev/fb_usrreq.c @@ -1,4 +1,4 @@ -/* $NetBSD: fb_usrreq.c,v 1.23 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: fb_usrreq.c,v 1.24 2002/10/23 09:11:49 jdolecek Exp $ */ #include @@ -7,10 +7,11 @@ dev_type_close(fbclose); dev_type_ioctl(fbioctl); dev_type_poll(fbpoll); dev_type_mmap(fbmmap); +dev_type_kqfilter(fbkqfilter); const struct cdevsw fb_cdevsw = { fbopen, fbclose, noread, nowrite, fbioctl, - nostop, notty, fbpoll, fbmmap, + nostop, notty, fbpoll, fbmmap, fbkqfilter, }; /*ARGSUSED*/ @@ -267,6 +268,57 @@ fbpoll(dev, events, p) return (revents); } +static void +filt_fbrdetach(struct knote *kn) +{ + struct fbinfo *fi = kn->kn_hook; + int s; + + s = spltty(); + SLIST_REMOVE(&fi->fi_selp.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_fbread(struct knote *kn, long hint) +{ + struct fbinfo *fi = kn->kn_hook; + + if (fi->fi_fbu->scrInfo.qe.eHead == fi->fi_fbu->scrInfo.qe.eTail) + return (0); + + kn->kn_data = 0; /* XXXLUKEM (thorpej): what to put here? */ + return (1); +} + +static const struct filterops fbread_filtops = + { 1, NULL, filt_fbrdetach, filt_fbread }; + +int +fbkqfilter(dev_t dev, struct knote *kn) +{ + struct fbinfo *fi = fbdevs[minor(dev)]; + struct klist *klist; + int s; + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &fi->fi_selp.si_klist; + kn->kn_fop = &fbread_filtops; + break; + + default: + return (1); + } + + kn->kn_hook = fi; + + s = spltty(); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + splx(s); + + return (0); +} /* * Return the physical page number that corresponds to byte offset 'off'. diff --git a/sys/arch/pmax/dev/px.c b/sys/arch/pmax/dev/px.c index 6976125aaa04..76f4c31d7ba3 100644 --- a/sys/arch/pmax/dev/px.c +++ b/sys/arch/pmax/dev/px.c @@ -1,4 +1,4 @@ -/* $NetBSD: px.c,v 1.42 2002/10/02 04:15:07 thorpej Exp $ */ +/* $NetBSD: px.c,v 1.43 2002/10/23 09:11:50 jdolecek Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -43,7 +43,7 @@ #endif #include -__KERNEL_RCSID(0, "$NetBSD: px.c,v 1.42 2002/10/02 04:15:07 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: px.c,v 1.43 2002/10/23 09:11:50 jdolecek Exp $"); /* * px.c: driver for the DEC TURBOchannel 2D and 3D accelerated framebuffers @@ -125,10 +125,11 @@ dev_type_close(pxclose); dev_type_ioctl(pxioctl); dev_type_poll(pxpoll); dev_type_mmap(pxmmap); +dev_type_kqfilter(pxkqfilter); const struct cdevsw px_cdevsw = { pxopen, pxclose, noread, nowrite, pxioctl, - nostop, notty, pxpoll, pxmmap, + nostop, notty, pxpoll, pxmmap, pxkqfilter, }; /* The different types of card that we support, for px_match(). */ @@ -1882,6 +1883,58 @@ pxpoll(dev, events, p) return (revents); } +static void +filt_pxrdetach(struct knote *kn) +{ + struct fbinfo *fi = kn->kn_hook; + int s; + + s = spltty(); + SLIST_REMOVE(&fi->fi_selp.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_pxread(struct knote *kn, long hint) +{ + struct fbinfo *fi = kn->kn_hook; + + if (fi->fi_fbu->scrInfo.qe.eHead == fi->fi_fbu->scrInfo.qe.eTail) + return (0); + + kn->kn_data = 0; /* XXXLUKEM (thorpej): what to put here? */ + return (1); +} + +static const struct filterops pxread_filtops = + { 1, NULL, filt_pxrdetach, filt_pxread }; + +int +pxkqfilter(dev_t dev, struct knote *kn) +{ + struct fbinfo *fi = &px_unit[minor(dev)]->pxi_fbinfo; + struct klist *klist; + int s; + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &fi->fi_selp.si_klist; + kn->kn_fop = &pxread_filtops; + break; + + default: + return (1); + } + + kn->kn_hook = fi; + + s = spltty(); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + splx(s); + + return (0);; +} + paddr_t pxmmap(dev, off, prot) dev_t dev; diff --git a/sys/arch/pmax/dev/qvss_compat.c b/sys/arch/pmax/dev/qvss_compat.c index 1d0136a3427f..2bb83dc8ef86 100644 --- a/sys/arch/pmax/dev/qvss_compat.c +++ b/sys/arch/pmax/dev/qvss_compat.c @@ -1,4 +1,4 @@ -/* $NetBSD: qvss_compat.c,v 1.30 2002/09/27 15:36:35 provos Exp $ */ +/* $NetBSD: qvss_compat.c,v 1.31 2002/10/23 09:11:51 jdolecek Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -228,7 +228,7 @@ fbKbdEvent(ch, fi) eventPtr->time = TO_MS(time); eventPtr->key = ch; fbu->scrInfo.qe.eTail = i; - selwakeup(&fi->fi_selp); + selnotify(&fi->fi_selp, 0); } /* @@ -349,7 +349,7 @@ fbMouseEvent(newRepPtr, fi) eventPtr->y = fbu->scrInfo.mouse.y; eventPtr->device = MOUSE_DEVICE; fbu->scrInfo.qe.eTail = PM_EVROUND(fbu->scrInfo.qe.eTail + 1); - selwakeup(&fi->fi_selp); + selnotify(&fi->fi_selp, 0); } /* @@ -428,7 +428,7 @@ fbMouseButtons(newRepPtr, fi) eventPtr->y = fbu->scrInfo.mouse.y; fbu->scrInfo.qe.eTail = i; } - selwakeup(&fi->fi_selp); + selnotify(&fi->fi_selp, 0); lastRep = *newRepPtr; fbu->scrInfo.mswitches = newSwitch; diff --git a/sys/arch/pmax/dev/rcons.c b/sys/arch/pmax/dev/rcons.c index 821e41d5a622..118873d95db6 100644 --- a/sys/arch/pmax/dev/rcons.c +++ b/sys/arch/pmax/dev/rcons.c @@ -1,4 +1,4 @@ -/* $NetBSD: rcons.c,v 1.54 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: rcons.c,v 1.55 2002/10/23 09:11:51 jdolecek Exp $ */ /* * Copyright (c) 1995 @@ -94,7 +94,7 @@ dev_type_poll(rconspoll); const struct cdevsw rcons_cdevsw = { rconsopen, rconsclose, rconsread, rconswrite, rconsioctl, - nostop, rconstty, rconspoll, nommap, D_TTY + nostop, rconstty, rconspoll, nommap, ttykqfilter, D_TTY }; /* diff --git a/sys/arch/pmax/tc/scc.c b/sys/arch/pmax/tc/scc.c index aa50ce222938..20d3c678ae5e 100644 --- a/sys/arch/pmax/tc/scc.c +++ b/sys/arch/pmax/tc/scc.c @@ -1,4 +1,4 @@ -/* $NetBSD: scc.c,v 1.75 2002/10/02 04:15:10 thorpej Exp $ */ +/* $NetBSD: scc.c,v 1.76 2002/10/23 09:11:52 jdolecek Exp $ */ /* * Copyright (c) 1991,1990,1989,1994,1995,1996 Carnegie Mellon University @@ -66,7 +66,7 @@ */ #include /* RCS ID & Copyright macro defns */ -__KERNEL_RCSID(0, "$NetBSD: scc.c,v 1.75 2002/10/02 04:15:10 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: scc.c,v 1.76 2002/10/23 09:11:52 jdolecek Exp $"); /* * Intel 82530 dual usart chip driver. Supports the serial port(s) on the @@ -223,7 +223,7 @@ dev_type_poll(sccpoll); const struct cdevsw scc_cdevsw = { sccopen, sccclose, sccread, sccwrite, sccioctl, - sccstop, scctty, sccpoll, nommap, D_TTY + sccstop, scctty, sccpoll, nommap, ttykqfilter, D_TTY }; /* QVSS-compatible in-kernel X input event parser, pointer tracker */ diff --git a/sys/arch/powerpc/powerpc/mem.c b/sys/arch/powerpc/powerpc/mem.c index f97043cf2e65..4f3e315942e2 100644 --- a/sys/arch/powerpc/powerpc/mem.c +++ b/sys/arch/powerpc/powerpc/mem.c @@ -1,4 +1,4 @@ -/* $NetBSD: mem.c,v 1.16 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: mem.c,v 1.17 2002/10/23 09:11:54 jdolecek Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -61,7 +61,7 @@ dev_type_mmap(mmmmap); const struct cdevsw mem_cdevsw = { nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, mmmmap, + nostop, notty, nopoll, mmmmap, nokqfilter, }; /*ARGSUSED*/ diff --git a/sys/arch/sh3/dev/sci.c b/sys/arch/sh3/dev/sci.c index cb988f115986..4bdcac407d04 100644 --- a/sys/arch/sh3/dev/sci.c +++ b/sys/arch/sh3/dev/sci.c @@ -1,4 +1,4 @@ -/* $NetBSD: sci.c,v 1.32 2002/10/02 15:52:34 thorpej Exp $ */ +/* $NetBSD: sci.c,v 1.33 2002/10/23 09:11:55 jdolecek Exp $ */ /*- * Copyright (C) 1999 T.Horiuchi and SAITOH Masanobu. All rights reserved. @@ -273,7 +273,7 @@ dev_type_poll(scipoll); const struct cdevsw sci_cdevsw = { sciopen, sciclose, sciread, sciwrite, sciioctl, - scistop, scitty, scipoll, nommap, D_TTY + scistop, scitty, scipoll, nommap, ttykqfilter, D_TTY }; void InitializeSci (unsigned int); diff --git a/sys/arch/sh3/dev/scif.c b/sys/arch/sh3/dev/scif.c index 7acadb1359a8..942c2d90f293 100644 --- a/sys/arch/sh3/dev/scif.c +++ b/sys/arch/sh3/dev/scif.c @@ -1,4 +1,4 @@ -/* $NetBSD: scif.c,v 1.32 2002/10/02 15:52:34 thorpej Exp $ */ +/* $NetBSD: scif.c,v 1.33 2002/10/23 09:11:56 jdolecek Exp $ */ /*- * Copyright (C) 1999 T.Horiuchi and SAITOH Masanobu. All rights reserved. @@ -280,7 +280,7 @@ dev_type_poll(scifpoll); const struct cdevsw scif_cdevsw = { scifopen, scifclose, scifread, scifwrite, scifioctl, - scifstop, sciftty, scifpoll, nommap, D_TTY + scifstop, sciftty, scifpoll, nommap, ttykqfilter, D_TTY }; void InitializeScif (unsigned int); diff --git a/sys/arch/sh3/dev/wdog.c b/sys/arch/sh3/dev/wdog.c index cf600e6ebede..d92241c5a202 100644 --- a/sys/arch/sh3/dev/wdog.c +++ b/sys/arch/sh3/dev/wdog.c @@ -1,4 +1,4 @@ -/* $NetBSD: wdog.c,v 1.11 2002/10/02 15:52:35 thorpej Exp $ */ +/* $NetBSD: wdog.c,v 1.12 2002/10/23 09:11:57 jdolecek Exp $ */ /*- * Copyright (C) 2000 SAITOH Masanobu. All rights reserved. @@ -67,7 +67,7 @@ dev_type_ioctl(wdogioctl); const struct cdevsw wdog_cdevsw = { wdogopen, wdogclose, noread, nowrite, wdogioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; void diff --git a/sys/arch/sh3/sh3/mem.c b/sys/arch/sh3/sh3/mem.c index 04e489b0b9af..c6f69be99e24 100644 --- a/sys/arch/sh3/sh3/mem.c +++ b/sys/arch/sh3/sh3/mem.c @@ -1,4 +1,4 @@ -/* $NetBSD: mem.c,v 1.12 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: mem.c,v 1.13 2002/10/23 09:11:58 jdolecek Exp $ */ /* * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -64,7 +64,7 @@ dev_type_mmap(mmmmap); const struct cdevsw mem_cdevsw = { nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, mmmmap, + nostop, notty, nopoll, mmmmap, nokqfilter, }; /*ARGSUSED*/ diff --git a/sys/arch/sh5/dev/scif.c b/sys/arch/sh5/dev/scif.c index d26acfd9a636..3e200f2acc18 100644 --- a/sys/arch/sh5/dev/scif.c +++ b/sys/arch/sh5/dev/scif.c @@ -1,4 +1,4 @@ -/* $NetBSD: scif.c,v 1.8 2002/10/19 08:43:33 scw Exp $ */ +/* $NetBSD: scif.c,v 1.9 2002/10/23 09:11:59 jdolecek Exp $ */ /*- * Copyright (C) 1999 T.Horiuchi and SAITOH Masanobu. All rights reserved. @@ -274,7 +274,7 @@ dev_type_poll(scifpoll); const struct cdevsw scif_cdevsw = { scifopen, scifclose, scifread, scifwrite, scifioctl, - scifstop, sciftty, scifpoll, nommap, D_TTY + scifstop, sciftty, scifpoll, nommap, ttykqfilter, D_TTY }; void InitializeScif(bus_space_tag_t, bus_space_handle_t, unsigned int); diff --git a/sys/arch/sh5/sh5/mem.c b/sys/arch/sh5/sh5/mem.c index cfa2e845b76f..d05860f5e78e 100644 --- a/sys/arch/sh5/sh5/mem.c +++ b/sys/arch/sh5/sh5/mem.c @@ -1,4 +1,4 @@ -/* $NetBSD: mem.c,v 1.3 2002/10/07 15:05:58 scw Exp $ */ +/* $NetBSD: mem.c,v 1.4 2002/10/23 09:11:59 jdolecek Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -44,7 +44,7 @@ #include -__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.3 2002/10/07 15:05:58 scw Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.4 2002/10/23 09:11:59 jdolecek Exp $"); #include #include @@ -69,7 +69,7 @@ dev_type_mmap(mmmmap); const struct cdevsw mem_cdevsw = { nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, mmmmap, + nostop, notty, nopoll, mmmmap, nokqfilter, }; /*ARGSUSED*/ diff --git a/sys/arch/shark/ofw/ofrom.c b/sys/arch/shark/ofw/ofrom.c index 5f26eb9f94d1..66cb7792a854 100644 --- a/sys/arch/shark/ofw/ofrom.c +++ b/sys/arch/shark/ofw/ofrom.c @@ -1,4 +1,4 @@ -/* $NetBSD: ofrom.c,v 1.8 2002/10/02 15:52:39 thorpej Exp $ */ +/* $NetBSD: ofrom.c,v 1.9 2002/10/23 09:12:00 jdolecek Exp $ */ /* * Copyright 1998 @@ -69,7 +69,7 @@ dev_type_mmap(ofrommmap); const struct cdevsw ofrom_cdevsw = { ofromopen, nullclose, ofromrw, ofromrw, noioctl, - nostop, notty, nopoll, ofrommmap, + nostop, notty, nopoll, ofrommmap, nokqfilter, }; int diff --git a/sys/arch/shark/shark/opms.c b/sys/arch/shark/shark/opms.c index ecc22b994733..5002eb84b8c3 100644 --- a/sys/arch/shark/shark/opms.c +++ b/sys/arch/shark/shark/opms.c @@ -1,4 +1,4 @@ -/* $NetBSD: opms.c,v 1.6 2002/10/02 15:52:40 thorpej Exp $ */ +/* $NetBSD: opms.c,v 1.7 2002/10/23 09:12:01 jdolecek Exp $ */ /* * Copyright 1997 @@ -202,10 +202,11 @@ dev_type_close(opmsclose); dev_type_read(opmsread); dev_type_ioctl(opmsioctl); dev_type_poll(opmspoll); +dev_type_kqfilter(opmskqfilter); const struct cdevsw opms_cdevsw = { opmsopen, opmsclose, opmsread, nowrite, opmsioctl, - nostop, notty, opmspoll, nommap, + nostop, notty, opmspoll, nommap, opmskqfilter, }; /* variable to control which debugs printed if kernel compiled with @@ -986,3 +987,51 @@ opmspoll(dev, events, p) return (revents); } /* End opmspoll */ +static void +filt_opmsrdetach(struct knote *kn) +{ + struct opms_softc *sc = kn->kn_hook; + int s; + + s = spltty(); + SLIST_REMOVE(&sc->sc_rsel.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_opmsread(struct knote *kn, long hint) +{ + struct opms_softc *sc = kn->kn_hook; + + kn->kn_data = sc->sc_q.c_cc; + return (kn->kn_data > 0); +} + +static const struct filterops opmsread_filtops = + { 1, NULL, filt_opmsrdetach, filt_opmsread }; + +int +opmskqfilter(dev_t dev, struct knote *kn) +{ + struct opms_softc *sc = opms_cd.cd_devs[PMSUNIT(dev)]; + struct klist *klist; + int s; + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &sc->sc_rsel.si_klist; + kn->kn_fop = &opmsread_filtops; + break; + + default: + return (1); + } + + kn->kn_hook = sc; + + s = spltty(); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + splx(s); + + return (0); +} diff --git a/sys/arch/shark/shark/pccons.c b/sys/arch/shark/shark/pccons.c index 6029c7036217..890b33a929d6 100644 --- a/sys/arch/shark/shark/pccons.c +++ b/sys/arch/shark/shark/pccons.c @@ -1,4 +1,4 @@ -/* $NetBSD: pccons.c,v 1.12 2002/10/05 17:01:51 chs Exp $ */ +/* $NetBSD: pccons.c,v 1.13 2002/10/23 09:12:02 jdolecek Exp $ */ /* * Copyright 1997 @@ -375,7 +375,7 @@ dev_type_mmap(pcmmap); const struct cdevsw pc_cdevsw = { pcopen, pcclose, pcread, pcwrite, pcioctl, - nostop, pctty, pcpoll, pcmmap, D_TTY + nostop, pctty, pcpoll, pcmmap, ttykqfilter, D_TTY }; static unsigned int addr_6845 = MONO_BASE; diff --git a/sys/arch/shark/shark/profile.c b/sys/arch/shark/shark/profile.c index 7f2f397952ad..91d7b610a361 100644 --- a/sys/arch/shark/shark/profile.c +++ b/sys/arch/shark/shark/profile.c @@ -1,4 +1,4 @@ -/* $NetBSD: profile.c,v 1.4 2002/09/27 15:36:44 provos Exp $ */ +/* $NetBSD: profile.c,v 1.5 2002/10/23 09:12:03 jdolecek Exp $ */ /* * Copyright 1997 @@ -116,7 +116,7 @@ dev_type_ioctl(profioctl); const struct cdevsw prof_cdevsw = { profopen, profclose, profread, nowrite, profioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; void diff --git a/sys/arch/shark/shark/scr.c b/sys/arch/shark/shark/scr.c index 2cf29e95936f..bb57d0b881fd 100644 --- a/sys/arch/shark/shark/scr.c +++ b/sys/arch/shark/shark/scr.c @@ -1,4 +1,4 @@ -/* $NetBSD: scr.c,v 1.7 2002/10/02 15:52:41 thorpej Exp $ */ +/* $NetBSD: scr.c,v 1.8 2002/10/23 09:12:03 jdolecek Exp $ */ /* * Copyright 1997 @@ -661,7 +661,7 @@ dev_type_ioctl(scrioctl); const struct cdevsw scr_cdevsw = { scropen, scrclose, noread, nowrite, scrioctl, - nostop, notty, nopoll, nommap, D_TTY + nostop, notty, nopoll, nommap, nokqfilter, D_TTY }; /* diff --git a/sys/arch/sparc/dev/cgeight.c b/sys/arch/sparc/dev/cgeight.c index ed93ae206d13..20c8f936ad4a 100644 --- a/sys/arch/sparc/dev/cgeight.c +++ b/sys/arch/sparc/dev/cgeight.c @@ -1,4 +1,4 @@ -/* $NetBSD: cgeight.c,v 1.30 2002/10/02 16:02:13 thorpej Exp $ */ +/* $NetBSD: cgeight.c,v 1.31 2002/10/23 09:12:05 jdolecek Exp $ */ /*- * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. @@ -140,14 +140,14 @@ dev_type_mmap(cgeightmmap); const struct cdevsw cgeight_cdevsw = { cgeightopen, nullclose, noread, nowrite, cgeightioctl, - nostop, notty, nopoll, cgeightmmap, + nostop, notty, nopoll, cgeightmmap, nokqfilter }; #if defined(SUN4) /* frame buffer generic driver */ static struct fbdriver cgeightfbdriver = { cgeightunblank, cgeightopen, nullclose, cgeightioctl, - nopoll, cgeightmmap + nopoll, cgeightmmap, nokqfilter }; static void cgeightloadcmap __P((struct cgeight_softc *, int, int)); diff --git a/sys/arch/sparc/dev/cgfour.c b/sys/arch/sparc/dev/cgfour.c index 9f6fe7505bc0..1ca621451915 100644 --- a/sys/arch/sparc/dev/cgfour.c +++ b/sys/arch/sparc/dev/cgfour.c @@ -1,4 +1,4 @@ -/* $NetBSD: cgfour.c,v 1.30 2002/10/02 16:02:13 thorpej Exp $ */ +/* $NetBSD: cgfour.c,v 1.31 2002/10/23 09:12:06 jdolecek Exp $ */ /*- * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. @@ -144,14 +144,14 @@ dev_type_mmap(cgfourmmap); const struct cdevsw cgfour_cdevsw = { cgfouropen, nullclose, noread, nowrite, cgfourioctl, - nostop, notty, nopoll, cgfourmmap, + nostop, notty, nopoll, cgfourmmap, nokqfilter, }; #if defined(SUN4) /* frame buffer generic driver */ static struct fbdriver cgfourfbdriver = { cgfourunblank, cgfouropen, nullclose, cgfourioctl, nopoll, - cgfourmmap + cgfourmmap, nokqfilter }; static void cgfourloadcmap __P((struct cgfour_softc *, int, int)); diff --git a/sys/arch/sparc/dev/cgfourteen.c b/sys/arch/sparc/dev/cgfourteen.c index aa81c5a46107..f517cfad1ea7 100644 --- a/sys/arch/sparc/dev/cgfourteen.c +++ b/sys/arch/sparc/dev/cgfourteen.c @@ -1,4 +1,4 @@ -/* $NetBSD: cgfourteen.c,v 1.30 2002/10/02 16:02:13 thorpej Exp $ */ +/* $NetBSD: cgfourteen.c,v 1.31 2002/10/23 09:12:07 jdolecek Exp $ */ /* * Copyright (c) 1996 @@ -117,13 +117,13 @@ dev_type_mmap(cgfourteenmmap); const struct cdevsw cgfourteen_cdevsw = { cgfourteenopen, cgfourteenclose, noread, nowrite, cgfourteenioctl, - nostop, notty, nopoll, cgfourteenmmap, + nostop, notty, nopoll, cgfourteenmmap, nokqfilter, }; /* frame buffer generic driver */ static struct fbdriver cgfourteenfbdriver = { cgfourteenunblank, cgfourteenopen, cgfourteenclose, cgfourteenioctl, - nopoll, cgfourteenmmap + nopoll, cgfourteenmmap, nokqfilter }; static void cg14_set_video __P((struct cgfourteen_softc *, int)); diff --git a/sys/arch/sparc/dev/cgtwo.c b/sys/arch/sparc/dev/cgtwo.c index 2810725e8d84..eae5b87d8f07 100644 --- a/sys/arch/sparc/dev/cgtwo.c +++ b/sys/arch/sparc/dev/cgtwo.c @@ -1,4 +1,4 @@ -/* $NetBSD: cgtwo.c,v 1.40 2002/10/02 16:02:14 thorpej Exp $ */ +/* $NetBSD: cgtwo.c,v 1.41 2002/10/23 09:12:07 jdolecek Exp $ */ /* * Copyright (c) 1992, 1993 @@ -105,12 +105,13 @@ dev_type_mmap(cgtwommap); const struct cdevsw cgtwo_cdevsw = { cgtwoopen, nullclose, noread, nowrite, cgtwoioctl, - nostop, notty, nopoll, cgtwommap, + nostop, notty, nopoll, cgtwommap, nokqfilter, }; /* frame buffer generic driver */ static struct fbdriver cgtwofbdriver = { - cgtwounblank, cgtwoopen, nullclose, cgtwoioctl, nopoll, cgtwommap + cgtwounblank, cgtwoopen, nullclose, cgtwoioctl, nopoll, cgtwommap, + nokqfilter }; /* diff --git a/sys/arch/sparc/dev/fd.c b/sys/arch/sparc/dev/fd.c index 10068e5c40d1..074ee79f820c 100644 --- a/sys/arch/sparc/dev/fd.c +++ b/sys/arch/sparc/dev/fd.c @@ -1,4 +1,4 @@ -/* $NetBSD: fd.c,v 1.94 2002/10/02 16:02:14 thorpej Exp $ */ +/* $NetBSD: fd.c,v 1.95 2002/10/23 09:12:08 jdolecek Exp $ */ /*- * Copyright (c) 2000 The NetBSD Foundation, Inc. @@ -279,7 +279,7 @@ const struct bdevsw fd_bdevsw = { const struct cdevsw fd_cdevsw = { fdopen, fdclose, fdread, fdwrite, fdioctl, - nostop, notty, nopoll, nommap, D_DISK + nostop, notty, nopoll, nommap, nokqfilter, D_DISK }; void fdgetdisklabel __P((dev_t)); diff --git a/sys/arch/sparc/dev/kd.c b/sys/arch/sparc/dev/kd.c index 384cbb9e3471..876f5b69776d 100644 --- a/sys/arch/sparc/dev/kd.c +++ b/sys/arch/sparc/dev/kd.c @@ -1,4 +1,4 @@ -/* $NetBSD: kd.c,v 1.22 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: kd.c,v 1.23 2002/10/23 09:12:09 jdolecek Exp $ */ /*- * Copyright (c) 1996 The NetBSD Foundation, Inc. @@ -110,7 +110,7 @@ dev_type_poll(kdpoll); const struct cdevsw kd_cdevsw = { kdopen, kdclose, kdread, kdwrite, kdioctl, - nostop, kdtty, kdpoll, nommap, D_TTY + nostop, kdtty, kdpoll, nommap, ttykqfilter, D_TTY }; /* diff --git a/sys/arch/sparc/dev/tctrl.c b/sys/arch/sparc/dev/tctrl.c index 368564bc4dd2..b22f45d4ffaf 100644 --- a/sys/arch/sparc/dev/tctrl.c +++ b/sys/arch/sparc/dev/tctrl.c @@ -1,4 +1,4 @@ -/* $NetBSD: tctrl.c,v 1.19 2002/10/14 02:08:39 takemura Exp $ */ +/* $NetBSD: tctrl.c,v 1.20 2002/10/23 09:12:10 jdolecek Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -70,10 +70,11 @@ dev_type_open(tctrlopen); dev_type_close(tctrlclose); dev_type_ioctl(tctrlioctl); dev_type_poll(tctrlpoll); +dev_type_kqfilter(tctrlkqfilter); const struct cdevsw tctrl_cdevsw = { tctrlopen, tctrlclose, noread, nowrite, tctrlioctl, - nostop, notty, tctrlpoll, nommap, + nostop, notty, tctrlpoll, nommap, tctrlkqfilter, }; static const char *tctrl_ext_statuses[16] = { @@ -671,7 +672,7 @@ tctrl_apm_record_event(sc, event_type) sc->sc_event_ptr %= APM_NEVENTS; evp->type = event_type; evp->index = ++tctrl_apm_evindex; - selwakeup(&sc->sc_rsel); + selnotify(&sc->sc_rsel, 0); return(sc->sc_flags & TCTRL_APM_CTLOPEN) ? 0 : 1; } return(1); @@ -1210,6 +1211,56 @@ tctrlpoll(dev, events, p) return (revents); } + +static void +filt_tctrlrdetach(struct knote *kn) +{ + struct tctrl_softc *sc = kn->kn_hook; + int s; + + s = splts102(); + SLIST_REMOVE(&sc->sc_rsel.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_tctrlread(struct knote *kn, long hint) +{ + struct tctrl_softc *sc = kn->kn_hook; + + kn->kn_data = sc->sc_event_count; + return (kn->kn_data > 0); +} + +static const struct filterops tctrlread_filtops = + { 1, NULL, filt_tctrlrdetach, filt_tctrlread }; + +int +tctrlkqfilter(dev_t dev, struct knote *kn) +{ + struct tctrl_softc *sc = tctrl_cd.cd_devs[TCTRL_STD_DEV]; + struct klist *klist; + int s; + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &sc->sc_rsel.si_klist; + kn->kn_fop = &tctrlread_filtops; + break; + + default: + return (1); + } + + kn->kn_hook = sc; + + s = splts102(); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + splx(s); + + return (0); +} + /* DO NOT SET THIS OPTION */ #ifdef TADPOLE_BLINK void diff --git a/sys/arch/sparc/sparc/mem.c b/sys/arch/sparc/sparc/mem.c index b392625579e6..4b82b4e0e5fb 100644 --- a/sys/arch/sparc/sparc/mem.c +++ b/sys/arch/sparc/sparc/mem.c @@ -1,4 +1,4 @@ -/* $NetBSD: mem.c,v 1.31 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: mem.c,v 1.32 2002/10/23 09:12:11 jdolecek Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -67,7 +67,7 @@ dev_type_ioctl(mmioctl); const struct cdevsw mem_cdevsw = { nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; /*ARGSUSED*/ diff --git a/sys/arch/sparc/sparc/openprom.c b/sys/arch/sparc/sparc/openprom.c index 0fa7827a94f3..a3f9adc34c4a 100644 --- a/sys/arch/sparc/sparc/openprom.c +++ b/sys/arch/sparc/sparc/openprom.c @@ -1,4 +1,4 @@ -/* $NetBSD: openprom.c,v 1.13 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: openprom.c,v 1.14 2002/10/23 09:12:12 jdolecek Exp $ */ /* * Copyright (c) 1992, 1993 @@ -53,6 +53,7 @@ #include #include #include +#include #include #include @@ -63,7 +64,7 @@ dev_type_ioctl(openpromioctl); const struct cdevsw openprom_cdevsw = { openpromopen, nullclose, noread, nowrite, openpromioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; static int lastnode; /* speed hack */ diff --git a/sys/arch/sparc64/dev/kd.c b/sys/arch/sparc64/dev/kd.c index 6554fbdf2e53..e22bbc1fdadb 100644 --- a/sys/arch/sparc64/dev/kd.c +++ b/sys/arch/sparc64/dev/kd.c @@ -1,4 +1,4 @@ -/* $NetBSD: kd.c,v 1.23 2002/10/10 10:12:00 jdolecek Exp $ */ +/* $NetBSD: kd.c,v 1.24 2002/10/23 09:12:13 jdolecek Exp $ */ /*- * Copyright (c) 1996 The NetBSD Foundation, Inc. @@ -83,7 +83,7 @@ dev_type_poll(kdpoll); const struct cdevsw kd_cdevsw = { kdopen, kdclose, kdread, kdwrite, kdioctl, - nostop, kdtty, kdpoll, nommap, D_TTY + nostop, kdtty, kdpoll, nommap, ttykqfilter, D_TTY }; struct tty *fbconstty = 0; /* tty structure for frame buffer console */ diff --git a/sys/arch/sparc64/dev/pcons.c b/sys/arch/sparc64/dev/pcons.c index aaa2f81278fd..34a5c3dfff87 100644 --- a/sys/arch/sparc64/dev/pcons.c +++ b/sys/arch/sparc64/dev/pcons.c @@ -1,4 +1,4 @@ -/* $NetBSD: pcons.c,v 1.13 2002/10/02 16:02:18 thorpej Exp $ */ +/* $NetBSD: pcons.c,v 1.14 2002/10/23 09:12:14 jdolecek Exp $ */ /*- * Copyright (c) 2000 Eduardo E. Horvath @@ -75,7 +75,7 @@ dev_type_poll(pconspoll); const struct cdevsw pcons_cdevsw = { pconsopen, pconsclose, pconsread, pconswrite, pconsioctl, - nostop, pconstty, pconspoll, nommap, D_TTY + nostop, pconstty, pconspoll, nommap, ttykqfilter, D_TTY }; static struct cnm_state pcons_cnm_state; diff --git a/sys/arch/sparc64/dev/sab.c b/sys/arch/sparc64/dev/sab.c index e582e5efb23a..c62b6edee3a5 100644 --- a/sys/arch/sparc64/dev/sab.c +++ b/sys/arch/sparc64/dev/sab.c @@ -1,4 +1,4 @@ -/* $NetBSD: sab.c,v 1.6 2002/10/02 16:02:19 thorpej Exp $ */ +/* $NetBSD: sab.c,v 1.7 2002/10/23 09:12:15 jdolecek Exp $ */ /* $OpenBSD: sab.c,v 1.7 2002/04/08 17:49:42 jason Exp $ */ /* @@ -168,7 +168,7 @@ dev_type_poll(sabpoll); const struct cdevsw sabtty_cdevsw = { sabopen, sabclose, sabread, sabwrite, sabioctl, - sabstop, sabtty, sabpoll, nommap, D_TTY + sabstop, sabtty, sabpoll, nommap, ttykqfilter, D_TTY }; struct sabtty_rate { diff --git a/sys/arch/sparc64/sparc64/mem.c b/sys/arch/sparc64/sparc64/mem.c index 7cad216b71c8..9f6b0dbe3e91 100644 --- a/sys/arch/sparc64/sparc64/mem.c +++ b/sys/arch/sparc64/sparc64/mem.c @@ -1,4 +1,4 @@ -/* $NetBSD: mem.c,v 1.22 2002/09/22 07:19:50 chs Exp $ */ +/* $NetBSD: mem.c,v 1.23 2002/10/23 09:12:16 jdolecek Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -67,7 +67,7 @@ dev_type_ioctl(mmioctl); const struct cdevsw mem_cdevsw = { nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; /*ARGSUSED*/ diff --git a/sys/arch/sparc64/sparc64/openprom.c b/sys/arch/sparc64/sparc64/openprom.c index e72056119903..b42af7f1463f 100644 --- a/sys/arch/sparc64/sparc64/openprom.c +++ b/sys/arch/sparc64/sparc64/openprom.c @@ -1,4 +1,4 @@ -/* $NetBSD: openprom.c,v 1.7 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: openprom.c,v 1.8 2002/10/23 09:12:16 jdolecek Exp $ */ /* * Copyright (c) 1992, 1993 @@ -52,6 +52,7 @@ #include #include #include +#include #include #include @@ -64,7 +65,7 @@ dev_type_ioctl(openpromioctl); const struct cdevsw openprom_cdevsw = { openpromopen, nullclose, noread, nowrite, openpromioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; static int lastnode; /* speed hack */ diff --git a/sys/arch/sun2/dev/kd.c b/sys/arch/sun2/dev/kd.c index c3465c6a0c8c..7041c4bd3de1 100644 --- a/sys/arch/sun2/dev/kd.c +++ b/sys/arch/sun2/dev/kd.c @@ -1,4 +1,4 @@ -/* $NetBSD: kd.c,v 1.3 2002/10/10 00:22:19 martin Exp $ */ +/* $NetBSD: kd.c,v 1.4 2002/10/23 09:12:19 jdolecek Exp $ */ /*- * Copyright (c) 1996 The NetBSD Foundation, Inc. @@ -111,7 +111,7 @@ dev_type_poll(kdpoll); const struct cdevsw kd_cdevsw = { kdopen, kdclose, kdread, kdwrite, kdioctl, - nostop, kdtty, kdpoll, nommap, D_TTY + nostop, kdtty, kdpoll, nommap, ttykqfilter, D_TTY }; /* diff --git a/sys/arch/sun2/dev/pcons.c b/sys/arch/sun2/dev/pcons.c index 9ea772db7fb1..c4236fe28d68 100644 --- a/sys/arch/sun2/dev/pcons.c +++ b/sys/arch/sun2/dev/pcons.c @@ -1,4 +1,4 @@ -/* $NetBSD: pcons.c,v 1.5 2002/10/02 16:02:23 thorpej Exp $ */ +/* $NetBSD: pcons.c,v 1.6 2002/10/23 09:12:20 jdolecek Exp $ */ /*- * Copyright (c) 2000 Eduardo E. Horvath @@ -78,7 +78,7 @@ dev_type_poll(pconspoll); const struct cdevsw pcons_cdevsw = { pconsopen, pconsclose, pconsread, pconswrite, pconsioctl, - nostop, pconstty, pconspoll, nommap, D_TTY + nostop, pconstty, pconspoll, nommap, ttykqfilter, D_TTY }; static int diff --git a/sys/arch/sun2/sun2/mem.c b/sys/arch/sun2/sun2/mem.c index dc6a942fc2f6..0b5a61a4d1cf 100644 --- a/sys/arch/sun2/sun2/mem.c +++ b/sys/arch/sun2/sun2/mem.c @@ -1,4 +1,4 @@ -/* $NetBSD: mem.c,v 1.8 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: mem.c,v 1.9 2002/10/23 09:12:22 jdolecek Exp $ */ /* * Copyright (c) 1994, 1995 Gordon W. Ross @@ -78,7 +78,7 @@ dev_type_mmap(mmmmap); const struct cdevsw mem_cdevsw = { nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, mmmmap, + nostop, notty, nopoll, mmmmap, nokqfilter, }; /*ARGSUSED*/ diff --git a/sys/arch/sun3/dev/bw2.c b/sys/arch/sun3/dev/bw2.c index 29552ce1147c..6082b9e35dab 100644 --- a/sys/arch/sun3/dev/bw2.c +++ b/sys/arch/sun3/dev/bw2.c @@ -1,4 +1,4 @@ -/* $NetBSD: bw2.c,v 1.22 2002/10/02 16:02:24 thorpej Exp $ */ +/* $NetBSD: bw2.c,v 1.23 2002/10/23 09:12:23 jdolecek Exp $ */ /* * Copyright (c) 1992, 1993 @@ -97,7 +97,7 @@ dev_type_mmap(bw2mmap); const struct cdevsw bwtwo_cdevsw = { bw2open, nullclose, noread, nowrite, bw2ioctl, - nostop, notty, nopoll, bw2mmap, + nostop, notty, nopoll, bw2mmap, nokqfilter, }; /* XXX we do not handle frame buffer interrupts */ @@ -106,7 +106,7 @@ static int bw2gvideo __P((struct fbdevice *, void *)); static int bw2svideo __P((struct fbdevice *, void *)); static struct fbdriver bw2fbdriver = { - bw2open, nullclose, bw2mmap, + bw2open, nullclose, bw2mmap, nokqfilter, fb_noioctl, bw2gvideo, bw2svideo, fb_noioctl, fb_noioctl, }; diff --git a/sys/arch/sun3/dev/cg2.c b/sys/arch/sun3/dev/cg2.c index 1b11e72d15d4..2898bb8266c2 100644 --- a/sys/arch/sun3/dev/cg2.c +++ b/sys/arch/sun3/dev/cg2.c @@ -1,4 +1,4 @@ -/* $NetBSD: cg2.c,v 1.21 2002/10/02 16:02:24 thorpej Exp $ */ +/* $NetBSD: cg2.c,v 1.22 2002/10/23 09:12:24 jdolecek Exp $ */ /* * Copyright (c) 1992, 1993 @@ -108,7 +108,7 @@ dev_type_mmap(cg2mmap); const struct cdevsw cgtwo_cdevsw = { cg2open, nullclose, noread, nowrite, cg2ioctl, - nostop, notty, nopoll, cg2mmap, + nostop, notty, nopoll, cg2mmap, nokqfilter, }; static int cg2gattr __P((struct fbdevice *, void *)); @@ -118,7 +118,7 @@ static int cg2getcmap __P((struct fbdevice *, void *)); static int cg2putcmap __P((struct fbdevice *, void *)); static struct fbdriver cg2fbdriver = { - cg2open, nullclose, cg2mmap, cg2gattr, + cg2open, nullclose, cg2mmap, nokqfilter, cg2gattr, cg2gvideo, cg2svideo, cg2getcmap, cg2putcmap }; diff --git a/sys/arch/sun3/dev/cg4.c b/sys/arch/sun3/dev/cg4.c index c3f46b84e9ef..e4eea479ecd5 100644 --- a/sys/arch/sun3/dev/cg4.c +++ b/sys/arch/sun3/dev/cg4.c @@ -1,4 +1,4 @@ -/* $NetBSD: cg4.c,v 1.28 2002/10/02 16:02:24 thorpej Exp $ */ +/* $NetBSD: cg4.c,v 1.29 2002/10/23 09:12:25 jdolecek Exp $ */ /* * Copyright (c) 1992, 1993 @@ -129,7 +129,7 @@ dev_type_mmap(cg4mmap); const struct cdevsw cgfour_cdevsw = { cg4open, nullclose, noread, nowrite, cg4ioctl, - nostop, notty, nopoll, cg4mmap, + nostop, notty, nopoll, cg4mmap, nokqfilter, }; static int cg4gattr __P((struct fbdevice *, void *)); @@ -147,7 +147,7 @@ static void cg4b_init __P((struct cg4_softc *)); static void cg4b_ldcmap __P((struct cg4_softc *)); static struct fbdriver cg4_fbdriver = { - cg4open, nullclose, cg4mmap, cg4gattr, + cg4open, nullclose, cg4mmap, nokqfilter, cg4gattr, cg4gvideo, cg4svideo, cg4getcmap, cg4putcmap }; diff --git a/sys/arch/sun3/dev/fb.c b/sys/arch/sun3/dev/fb.c index 16f1a9b4fa6d..cf746339e885 100644 --- a/sys/arch/sun3/dev/fb.c +++ b/sys/arch/sun3/dev/fb.c @@ -1,4 +1,4 @@ -/* $NetBSD: fb.c,v 1.8 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: fb.c,v 1.9 2002/10/23 09:12:25 jdolecek Exp $ */ /* * Copyright (c) 1992, 1993 @@ -68,7 +68,7 @@ dev_type_mmap(fbmmap); const struct cdevsw fb_cdevsw = { fbopen, fbclose, noread, nowrite, fbioctl, - nostop, notty, nopoll, fbmmap, + nostop, notty, nopoll, fbmmap, nokqfilter, }; static struct fbdevice *devfb; diff --git a/sys/arch/sun3/dev/fbvar.h b/sys/arch/sun3/dev/fbvar.h index f384881e3883..f35c4206449d 100644 --- a/sys/arch/sun3/dev/fbvar.h +++ b/sys/arch/sun3/dev/fbvar.h @@ -1,4 +1,4 @@ -/* $NetBSD: fbvar.h,v 1.6 2000/06/26 04:56:12 simonb Exp $ */ +/* $NetBSD: fbvar.h,v 1.7 2002/10/23 09:12:26 jdolecek Exp $ */ /* * Copyright (c) 1992, 1993 @@ -44,6 +44,8 @@ * @(#)fbvar.h 8.1 (Berkeley) 6/11/93 */ +#include /* for struct knote */ + /* * Frame buffer variables. All frame buffer drivers must provide the * following in order to participate. @@ -77,6 +79,7 @@ struct fbdriver { int (*fbd_open) __P((dev_t, int, int, struct proc *)); int (*fbd_close) __P((dev_t, int, int, struct proc *)); paddr_t (*fbd_mmap) __P((dev_t, off_t, int)); + int (*fbd_kqfilter) __P((dev_t, struct knote *)); /* These are the internal ioctl functions */ int (*fbd_gattr) __P((struct fbdevice *, void *)); int (*fbd_gvideo) __P((struct fbdevice *, void *)); diff --git a/sys/arch/sun3/dev/fd.c b/sys/arch/sun3/dev/fd.c index e33e30fc6d5d..b4151309cdaa 100644 --- a/sys/arch/sun3/dev/fd.c +++ b/sys/arch/sun3/dev/fd.c @@ -1,4 +1,4 @@ -/* $NetBSD: fd.c,v 1.31 2002/10/02 16:02:25 thorpej Exp $ */ +/* $NetBSD: fd.c,v 1.32 2002/10/23 09:12:26 jdolecek Exp $ */ /*- * Copyright (c) 1993, 1994, 1995 Charles M. Hannum. @@ -245,7 +245,7 @@ const struct bdevsw fd_bdevsw = { const struct cdevsw fd_cdevsw = { fdopen, fdclose, fdread, fdwrite, fdioctl, - nostop, notty, nopoll, nommap, D_DISK + nostop, notty, nopoll, nommap, nokqfilter, D_DISK }; void fdgetdisklabel __P((dev_t)); diff --git a/sys/arch/sun3/dev/kd.c b/sys/arch/sun3/dev/kd.c index d89d1ef9cfa9..2bd11e2ece20 100644 --- a/sys/arch/sun3/dev/kd.c +++ b/sys/arch/sun3/dev/kd.c @@ -1,4 +1,4 @@ -/* $NetBSD: kd.c,v 1.39 2002/10/10 00:22:20 martin Exp $ */ +/* $NetBSD: kd.c,v 1.40 2002/10/23 09:12:27 jdolecek Exp $ */ /*- * Copyright (c) 1996 The NetBSD Foundation, Inc. @@ -100,7 +100,7 @@ dev_type_poll(kdpoll); const struct cdevsw kd_cdevsw = { kdopen, kdclose, kdread, kdwrite, kdioctl, - nostop, kdtty, kdpoll, nommap, D_TTY + nostop, kdtty, kdpoll, nommap, ttykqfilter, D_TTY }; /* diff --git a/sys/arch/sun3/dev/xd.c b/sys/arch/sun3/dev/xd.c index f7abf7d8ba5a..267ea6e57f04 100644 --- a/sys/arch/sun3/dev/xd.c +++ b/sys/arch/sun3/dev/xd.c @@ -1,4 +1,4 @@ -/* $NetBSD: xd.c,v 1.39 2002/10/02 16:02:27 thorpej Exp $ */ +/* $NetBSD: xd.c,v 1.40 2002/10/23 09:12:27 jdolecek Exp $ */ /* * @@ -284,7 +284,7 @@ const struct bdevsw xd_bdevsw = { const struct cdevsw xd_cdevsw = { xdopen, xdclose, xdread, xdwrite, xdioctl, - nostop, notty, nopoll, nommap, D_DISK + nostop, notty, nopoll, nommap, nokqfilter, D_DISK }; /* diff --git a/sys/arch/sun3/dev/xy.c b/sys/arch/sun3/dev/xy.c index d0fa4c156dca..5ec0373053eb 100644 --- a/sys/arch/sun3/dev/xy.c +++ b/sys/arch/sun3/dev/xy.c @@ -1,4 +1,4 @@ -/* $NetBSD: xy.c,v 1.41 2002/10/02 16:02:27 thorpej Exp $ */ +/* $NetBSD: xy.c,v 1.42 2002/10/23 09:12:29 jdolecek Exp $ */ /* * @@ -223,7 +223,7 @@ const struct bdevsw xy_bdevsw = { const struct cdevsw xy_cdevsw = { xyopen, xyclose, xyread, xywrite, xyioctl, - nostop, notty, nopoll, nommap, D_DISK + nostop, notty, nopoll, nommap, nokqfilter, D_DISK }; /* diff --git a/sys/arch/sun3/sun3/mem.c b/sys/arch/sun3/sun3/mem.c index 3e7fea2761cb..d6dfc95cbc5c 100644 --- a/sys/arch/sun3/sun3/mem.c +++ b/sys/arch/sun3/sun3/mem.c @@ -1,4 +1,4 @@ -/* $NetBSD: mem.c,v 1.43 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: mem.c,v 1.44 2002/10/23 09:12:30 jdolecek Exp $ */ /* * Copyright (c) 1994, 1995 Gordon W. Ross @@ -84,7 +84,7 @@ dev_type_mmap(mmmmap); const struct cdevsw mem_cdevsw = { nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, mmmmap, + nostop, notty, nopoll, mmmmap, nokqfilter, }; /*ARGSUSED*/ diff --git a/sys/arch/sun3/sun3x/mem.c b/sys/arch/sun3/sun3x/mem.c index 4ec9843b8ffb..a0505c66b825 100644 --- a/sys/arch/sun3/sun3x/mem.c +++ b/sys/arch/sun3/sun3x/mem.c @@ -1,4 +1,4 @@ -/* $NetBSD: mem.c,v 1.25 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: mem.c,v 1.26 2002/10/23 09:12:32 jdolecek Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -84,7 +84,7 @@ dev_type_mmap(mmmmap); const struct cdevsw mem_cdevsw = { nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, mmmmap, + nostop, notty, nopoll, mmmmap, nokqfilter, }; /*ARGSUSED*/ diff --git a/sys/arch/vax/mba/hp.c b/sys/arch/vax/mba/hp.c index e04b0730f59b..ff20fc7d5007 100644 --- a/sys/arch/vax/mba/hp.c +++ b/sys/arch/vax/mba/hp.c @@ -1,4 +1,4 @@ -/* $NetBSD: hp.c,v 1.29 2002/10/02 16:02:33 thorpej Exp $ */ +/* $NetBSD: hp.c,v 1.30 2002/10/23 09:12:33 jdolecek Exp $ */ /* * Copyright (c) 1996 Ludd, University of Lule}, Sweden. * All rights reserved. @@ -53,6 +53,7 @@ #include #include #include +#include #include #include @@ -99,7 +100,7 @@ const struct bdevsw hp_bdevsw = { const struct cdevsw hp_cdevsw = { hpopen, hpclose, hpread, hpwrite, hpioctl, - nostop, notty, nopoll, nommap, D_DISK + nostop, notty, nopoll, nommap, nokqfilter, D_DISK }; #define HP_WCSR(reg, val) \ diff --git a/sys/arch/vax/uba/qv.c b/sys/arch/vax/uba/qv.c index dad5bd4acb5d..fd2ea867ad67 100644 --- a/sys/arch/vax/uba/qv.c +++ b/sys/arch/vax/uba/qv.c @@ -1,4 +1,4 @@ -/* $NetBSD: qv.c,v 1.10 2002/09/25 22:21:28 thorpej Exp $ */ +/* $NetBSD: qv.c,v 1.11 2002/10/23 09:12:34 jdolecek Exp $ */ /*- * Copyright (c) 1988 @@ -280,10 +280,11 @@ dev_type_write(qvwrite); dev_type_ioctl(qvioctl); dev_type_stop(qvstop); dev_type_poll(qvpoll); +dev_type_kqfilter(qvkqfilter); const struct cdevsw qv_cdevsw = { qvopen, qvclose, qvread, qvwrite, qvioctl, - qvstop, notty, qvpoll, nommap, + qvstop, notty, qvpoll, nommap, qvkqfilter, }; /* diff --git a/sys/arch/vax/uba/ts.c b/sys/arch/vax/uba/ts.c index 52aef0b95a8a..c1d496e1bd49 100644 --- a/sys/arch/vax/uba/ts.c +++ b/sys/arch/vax/uba/ts.c @@ -1,4 +1,4 @@ -/* $NetBSD: ts.c,v 1.23 2002/10/02 16:02:33 thorpej Exp $ */ +/* $NetBSD: ts.c,v 1.24 2002/10/23 09:12:34 jdolecek Exp $ */ /*- * Copyright (c) 1991 The Regents of the University of California. @@ -212,7 +212,7 @@ const struct bdevsw ts_bdevsw = { const struct cdevsw ts_cdevsw = { tsopen, tsclose, tsread, tswrite, tsioctl, - nostop, notty, nopoll, nommap, D_TAPE + nostop, notty, nopoll, nommap, nokqfilter, D_TAPE }; #define ST_INVALID 0 /* uninitialized, before probe */ diff --git a/sys/arch/vax/vax/cfl.c b/sys/arch/vax/vax/cfl.c index a025e782074c..a434aa40d97f 100644 --- a/sys/arch/vax/vax/cfl.c +++ b/sys/arch/vax/vax/cfl.c @@ -1,4 +1,4 @@ -/* $NetBSD: cfl.c,v 1.8 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: cfl.c,v 1.9 2002/10/23 09:12:36 jdolecek Exp $ */ /*- * Copyright (c) 1996 Ludd, University of Lule}, Sweden. * Copyright (c) 1982, 1986 The Regents of the University of California. @@ -94,7 +94,7 @@ dev_type_read(cflrw); const struct cdevsw cfl_cdevsw = { cflopen, cflclose, cflrw, cflrw, noioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; /*ARGSUSED*/ diff --git a/sys/arch/vax/vax/crl.c b/sys/arch/vax/vax/crl.c index 7cc47a46bfc5..9467aa6de65b 100644 --- a/sys/arch/vax/vax/crl.c +++ b/sys/arch/vax/vax/crl.c @@ -1,4 +1,4 @@ -/* $NetBSD: crl.c,v 1.12 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: crl.c,v 1.13 2002/10/23 09:12:36 jdolecek Exp $ */ /*- * Copyright (c) 1982, 1986 The Regents of the University of California. * All rights reserved. @@ -76,7 +76,7 @@ dev_type_read(crlrw); const struct cdevsw crl_cdevsw = { crlopen, crlclose, crlrw, crlrw, noioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; struct ivec_dsp crl_intr; diff --git a/sys/arch/vax/vax/crx.c b/sys/arch/vax/vax/crx.c index f4f603b6c068..f887a121bfa7 100644 --- a/sys/arch/vax/vax/crx.c +++ b/sys/arch/vax/vax/crx.c @@ -1,4 +1,4 @@ -/* $NetBSD: crx.c,v 1.6 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: crx.c,v 1.7 2002/10/23 09:12:37 jdolecek Exp $ */ /* * Copyright (c) 1988 Regents of the University of California. * All rights reserved. @@ -61,7 +61,7 @@ dev_type_read(crxrw); const struct cdevsw crx_cdevsw = { crxopen, crxclose, crxrw, crxrw, noioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; extern struct rx50device *rx50device_ptr; diff --git a/sys/arch/vax/vax/ctu.c b/sys/arch/vax/vax/ctu.c index f0198132aeab..cdae80db4735 100644 --- a/sys/arch/vax/vax/ctu.c +++ b/sys/arch/vax/vax/ctu.c @@ -1,4 +1,4 @@ -/* $NetBSD: ctu.c,v 1.17 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: ctu.c,v 1.18 2002/10/23 09:12:37 jdolecek Exp $ */ /* * Copyright (c) 1996 Ludd, University of Lule}, Sweden. * All rights reserved. @@ -102,7 +102,7 @@ const struct bdevsw ctu_bdevsw = { #if 0 /* not yet */ const struct cdevsw ctu_cdevsw = { ctuopen, ctuclose, cturead, ctuwrite, noioctl, - nostop, notty, nopoll, nommap, D_TAPE + nostop, notty, nopoll, nommap, nokqfilter, D_TAPE }; #endif diff --git a/sys/arch/vax/vax/gencons.c b/sys/arch/vax/vax/gencons.c index 79496e60acc9..7fb08c655240 100644 --- a/sys/arch/vax/vax/gencons.c +++ b/sys/arch/vax/vax/gencons.c @@ -1,4 +1,4 @@ -/* $NetBSD: gencons.c,v 1.38 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: gencons.c,v 1.39 2002/10/23 09:12:38 jdolecek Exp $ */ /* * Copyright (c) 1994 Gordon W. Ross @@ -86,7 +86,7 @@ dev_type_poll(gencnpoll); const struct cdevsw gen_cdevsw = { gencnopen, gencnclose, gencnread, gencnwrite, gencnioctl, - nostop, gencntty, gencnpoll, nommap, D_TTY + nostop, gencntty, gencnpoll, nommap, ttykqfilter, D_TTY }; int diff --git a/sys/arch/vax/vax/mem.c b/sys/arch/vax/vax/mem.c index 37a6130df4f5..1c17bb639110 100644 --- a/sys/arch/vax/vax/mem.c +++ b/sys/arch/vax/vax/mem.c @@ -1,4 +1,4 @@ -/* $NetBSD: mem.c,v 1.23 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: mem.c,v 1.24 2002/10/23 09:12:39 jdolecek Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -68,7 +68,7 @@ dev_type_ioctl(mmioctl); const struct cdevsw mem_cdevsw = { nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; /*ARGSUSED*/ diff --git a/sys/arch/vax/vsa/hdc9224.c b/sys/arch/vax/vsa/hdc9224.c index 6e04150ca54a..eb9e8d88538a 100644 --- a/sys/arch/vax/vsa/hdc9224.c +++ b/sys/arch/vax/vsa/hdc9224.c @@ -1,4 +1,4 @@ -/* $NetBSD: hdc9224.c,v 1.23 2002/10/02 16:02:37 thorpej Exp $ */ +/* $NetBSD: hdc9224.c,v 1.24 2002/10/23 09:12:40 jdolecek Exp $ */ /* * Copyright (c) 1996 Ludd, University of Lule}, Sweden. * All rights reserved. @@ -201,7 +201,7 @@ const struct bdevsw rd_bdevsw = { const struct cdevsw rd_cdevsw = { rdopen, rdclose, rdread, rdwrite, rdioctl, - nostop, notty, nopoll, nommap, D_DISK + nostop, notty, nopoll, nommap, nokqfilter, D_DISK }; /* At least 0.7 uS between register accesses */ diff --git a/sys/arch/x68k/dev/com.c b/sys/arch/x68k/dev/com.c index 046284174439..ff18031b572f 100644 --- a/sys/arch/x68k/dev/com.c +++ b/sys/arch/x68k/dev/com.c @@ -1,4 +1,4 @@ -/* $NetBSD: com.c,v 1.29 2002/10/02 16:02:39 thorpej Exp $ */ +/* $NetBSD: com.c,v 1.30 2002/10/23 09:12:41 jdolecek Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -180,7 +180,7 @@ dev_type_poll(compoll); const struct cdevsw xcom_cdevsw = { comopen, comclose, comread, comwrite, comioctl, - comstop, comtty, compoll, nommap, D_TTY + comstop, comtty, compoll, nommap, ttykqfilter, D_TTY }; #define outb(addr, val) *(u_char *)(addr) = (val) diff --git a/sys/arch/x68k/dev/event.c b/sys/arch/x68k/dev/event.c index 57c157c2146f..9a86bc297e04 100644 --- a/sys/arch/x68k/dev/event.c +++ b/sys/arch/x68k/dev/event.c @@ -1,4 +1,4 @@ -/* $NetBSD: event.c,v 1.5 2001/12/27 02:23:24 wiz Exp $ */ +/* $NetBSD: event.c,v 1.6 2002/10/23 09:12:42 jdolecek Exp $ */ /* * Copyright (c) 1992, 1993 @@ -165,3 +165,61 @@ ev_poll(ev, events, p) splx(s); return (revents); } + +static void +filt_evrdetach(struct knote *kn) +{ + struct evvar *ev = kn->kn_hook; + int s; + + s = splev(); + SLIST_REMOVE(&ev->ev_sel.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_evread(struct knote *kn, long hint) +{ + struct evvar *ev = kn->kn_hook; + + if (ev->ev_get == ev->ev_put) + return (0); + + if (ev->ev_get < ev->ev_put) + kn->kn_data = ev->ev_put - ev->ev_get; + else + kn->kn_data = (EV_QSIZE - ev->ev_get) + + ev->ev_put; + + kn->kn_data *= sizeof(struct firm_event); + + return (1); +} + +static const struct filterops ev_filtops = + { 1, NULL, filt_evrdetach, filt_evread }; + +int +ev_kqfilter(struct evvar *ev, struct knote *kn) +{ + struct klist *klist; + int s; + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &ev->ev_sel.si_klist; + kn->kn_fop = &ev_filtops; + break; + + default: + return (1); + } + + kn->kn_hook = ev; + + s = splev(); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + splx(s); + + return (0); +} diff --git a/sys/arch/x68k/dev/event_var.h b/sys/arch/x68k/dev/event_var.h index da65d1b2dc10..4a2c16630d67 100644 --- a/sys/arch/x68k/dev/event_var.h +++ b/sys/arch/x68k/dev/event_var.h @@ -1,4 +1,4 @@ -/* $NetBSD: event_var.h,v 1.2 1997/10/10 12:54:02 oki Exp $ */ +/* $NetBSD: event_var.h,v 1.3 2002/10/23 09:12:42 jdolecek Exp $ */ /* * Copyright (c) 1992, 1993 @@ -66,7 +66,7 @@ struct evvar { #define splev() spltty() #define EV_WAKEUP(ev) { \ - selwakeup(&(ev)->ev_sel); \ + selnotify(&(ev)->ev_sel, 0); \ if ((ev)->ev_wanted) { \ (ev)->ev_wanted = 0; \ wakeup((caddr_t)(ev)); \ @@ -80,6 +80,7 @@ void ev_fini __P((struct evvar *)); int ev_read __P((struct evvar *, struct uio *, int)); int ev_select __P((struct evvar *, int, struct proc *)); int ev_poll __P((struct evvar *, int, struct proc *)); +int ev_kqfilter __P((struct evvar *, struct knote *)); /* * PEVENT is set just above PSOCK, which is just above TTIPRI, on the diff --git a/sys/arch/x68k/dev/fd.c b/sys/arch/x68k/dev/fd.c index 67c4f3ac5e81..ab588efa57f9 100644 --- a/sys/arch/x68k/dev/fd.c +++ b/sys/arch/x68k/dev/fd.c @@ -1,4 +1,4 @@ -/* $NetBSD: fd.c,v 1.49 2002/10/20 02:33:08 isaki Exp $ */ +/* $NetBSD: fd.c,v 1.50 2002/10/23 09:12:43 jdolecek Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -277,7 +277,7 @@ const struct bdevsw fd_bdevsw = { const struct cdevsw fd_cdevsw = { fdopen, fdclose, fdread, fdwrite, fdioctl, - nostop, notty, nopoll, nommap, D_DISK + nostop, notty, nopoll, nommap, nokqfilter, D_DISK }; void fdstart __P((struct fd_softc *fd)); diff --git a/sys/arch/x68k/dev/grf.c b/sys/arch/x68k/dev/grf.c index 7e56e6c8ac75..0a4360032d8b 100644 --- a/sys/arch/x68k/dev/grf.c +++ b/sys/arch/x68k/dev/grf.c @@ -1,4 +1,4 @@ -/* $NetBSD: grf.c,v 1.23 2002/10/10 22:33:15 jdolecek Exp $ */ +/* $NetBSD: grf.c,v 1.24 2002/10/23 09:12:44 jdolecek Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -109,7 +109,7 @@ dev_type_mmap(grfmmap); const struct cdevsw grf_cdevsw = { grfopen, grfclose, nullread, nullwrite, grfioctl, - nostop, notty, nopoll, grfmmap, + nostop, notty, nopoll, grfmmap, nokqfilter, }; /*ARGSUSED*/ diff --git a/sys/arch/x68k/dev/ite.c b/sys/arch/x68k/dev/ite.c index be5f278541e6..863de230e1e6 100644 --- a/sys/arch/x68k/dev/ite.c +++ b/sys/arch/x68k/dev/ite.c @@ -1,4 +1,4 @@ -/* $NetBSD: ite.c,v 1.32 2002/10/02 16:02:41 thorpej Exp $ */ +/* $NetBSD: ite.c,v 1.33 2002/10/23 09:12:44 jdolecek Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -169,7 +169,7 @@ dev_type_poll(itepoll); const struct cdevsw ite_cdevsw = { iteopen, iteclose, iteread, itewrite, iteioctl, - nostop, itetty, itepoll, nommap, D_TTY + nostop, itetty, itepoll, nommap, ttykqfilter, D_TTY }; int diff --git a/sys/arch/x68k/dev/kbd.c b/sys/arch/x68k/dev/kbd.c index f955b27af75d..46fcc6afc6a2 100644 --- a/sys/arch/x68k/dev/kbd.c +++ b/sys/arch/x68k/dev/kbd.c @@ -1,4 +1,4 @@ -/* $NetBSD: kbd.c,v 1.15 2002/10/02 16:02:41 thorpej Exp $ */ +/* $NetBSD: kbd.c,v 1.16 2002/10/23 09:12:45 jdolecek Exp $ */ /* * Copyright (c) 1982, 1986, 1990 The Regents of the University of California. @@ -90,10 +90,11 @@ dev_type_close(kbdclose); dev_type_read(kbdread); dev_type_ioctl(kbdioctl); dev_type_poll(kbdpoll); +dev_type_kqfilter(kbdkqfilter); const struct cdevsw kbd_cdevsw = { kbdopen, kbdclose, kbdread, nowrite, kbdioctl, - nostop, notty, kbdpoll, nommap, + nostop, notty, kbdpoll, nommap, kbdkqfilter, }; static int @@ -308,6 +309,14 @@ kbdpoll(dev, events, p) return (ev_poll(&k->sc_events, events, p)); } +int +kbdkqfilter(dev_t dev, struct knote *kn) +{ + struct kbd_softc *k; + + k = kbd_cd.cd_devs[minor(dev)]; + return (ev_kqfilter(&k->sc_events, kn)); +} #define KBDBUFMASK 63 #define KBDBUFSIZ 64 diff --git a/sys/arch/x68k/dev/ms.c b/sys/arch/x68k/dev/ms.c index dc40f4fada9f..fc15b20471d8 100644 --- a/sys/arch/x68k/dev/ms.c +++ b/sys/arch/x68k/dev/ms.c @@ -1,4 +1,4 @@ -/* $NetBSD: ms.c,v 1.15 2002/10/02 16:02:42 thorpej Exp $ */ +/* $NetBSD: ms.c,v 1.16 2002/10/23 09:12:46 jdolecek Exp $ */ /* * Copyright (c) 1992, 1993 @@ -150,10 +150,11 @@ dev_type_close(msclose); dev_type_read(msread); dev_type_ioctl(msioctl); dev_type_poll(mspoll); +dev_type_kqfilter(mskqfilter); const struct cdevsw ms_cdevsw ={ msopen, msclose, msread, nowrite, msioctl, - nostop, notty, mspoll, nommap, + nostop, notty, mspoll, nommap, mskqfilter, }; /* @@ -335,6 +336,14 @@ mspoll(dev, events, p) return (ev_poll(&ms->ms_events, events, p)); } +int +mskqfilter(dev_t dev, struct knote *kn) +{ + struct ms_softc *ms; + + ms = ms_cd.cd_devs[minor(dev)]; + return (ev_kqfilter(&ms->ms_events, kn)); +} /**************************************************************** * Middle layer (translator) diff --git a/sys/arch/x68k/dev/opmbell.c b/sys/arch/x68k/dev/opmbell.c index 99c5a5245fe8..8701c2a1584f 100644 --- a/sys/arch/x68k/dev/opmbell.c +++ b/sys/arch/x68k/dev/opmbell.c @@ -1,4 +1,4 @@ -/* $NetBSD: opmbell.c,v 1.9 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: opmbell.c,v 1.10 2002/10/23 09:12:46 jdolecek Exp $ */ /* * Copyright (c) 1995 MINOURA Makoto, Takuya Harakawa. @@ -55,6 +55,7 @@ #include #include #include +#include #include #include @@ -112,7 +113,7 @@ dev_type_ioctl(bellioctl); const struct cdevsw bell_cdevsw = { bellopen, bellclose, noread, nowrite, bellioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; void diff --git a/sys/arch/x68k/dev/par.c b/sys/arch/x68k/dev/par.c index b57140fc8239..277c539a2217 100644 --- a/sys/arch/x68k/dev/par.c +++ b/sys/arch/x68k/dev/par.c @@ -1,4 +1,4 @@ -/* $NetBSD: par.c,v 1.16 2002/10/02 16:02:42 thorpej Exp $ */ +/* $NetBSD: par.c,v 1.17 2002/10/23 09:12:47 jdolecek Exp $ */ /* * Copyright (c) 1982, 1990 The Regents of the University of California. @@ -124,7 +124,7 @@ dev_type_ioctl(parioctl); const struct cdevsw par_cdevsw = { paropen, parclose, noread, parwrite, parioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; int diff --git a/sys/arch/x68k/dev/pow.c b/sys/arch/x68k/dev/pow.c index 7e99db4b1a47..53f6c30f149f 100644 --- a/sys/arch/x68k/dev/pow.c +++ b/sys/arch/x68k/dev/pow.c @@ -1,4 +1,4 @@ -/* $NetBSD: pow.c,v 1.9 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: pow.c,v 1.10 2002/10/23 09:12:47 jdolecek Exp $ */ /* * Copyright (c) 1995 MINOURA Makoto. @@ -69,7 +69,7 @@ dev_type_ioctl(powioctl); const struct cdevsw pow_cdevsw = { powopen, powclose, noread, nowrite, powioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; /* ARGSUSED */ diff --git a/sys/arch/x68k/dev/sram.c b/sys/arch/x68k/dev/sram.c index 2568a18e53f6..99225d5f4317 100644 --- a/sys/arch/x68k/dev/sram.c +++ b/sys/arch/x68k/dev/sram.c @@ -1,4 +1,4 @@ -/* $NetBSD: sram.c,v 1.8 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: sram.c,v 1.9 2002/10/23 09:12:48 jdolecek Exp $ */ /* * Copyright (c) 1994 Kazuhisa Shimizu. @@ -60,7 +60,7 @@ dev_type_ioctl(sramioctl); const struct cdevsw sram_cdevsw = { sramopen, sramclose, noread, nowrite, sramioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; /* diff --git a/sys/arch/x68k/x68k/mem.c b/sys/arch/x68k/x68k/mem.c index 71b94744c9c7..a3bde6411619 100644 --- a/sys/arch/x68k/x68k/mem.c +++ b/sys/arch/x68k/x68k/mem.c @@ -1,4 +1,4 @@ -/* $NetBSD: mem.c,v 1.28 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: mem.c,v 1.29 2002/10/23 09:12:48 jdolecek Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -67,7 +67,7 @@ dev_type_mmap(mmmmap); const struct cdevsw mem_cdevsw = { nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, mmmmap, + nostop, notty, nopoll, mmmmap, nokqfilter }; /*ARGSUSED*/ diff --git a/sys/arch/x86_64/isa/pccons.c b/sys/arch/x86_64/isa/pccons.c index 5969542c3aa2..bcbd5b3566e5 100644 --- a/sys/arch/x86_64/isa/pccons.c +++ b/sys/arch/x86_64/isa/pccons.c @@ -1,4 +1,4 @@ -/* $NetBSD: pccons.c,v 1.9 2002/10/02 16:02:45 thorpej Exp $ */ +/* $NetBSD: pccons.c,v 1.10 2002/10/23 09:12:49 jdolecek Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -237,7 +237,7 @@ dev_type_mmap(pcmmap); const struct cdevsw pc_cdevsw = { pcopen, pcclose, pcread, pcwrite, pcioctl, - pcstop, pctty, pcpoll, pcmmap, D_TTY + pcstop, pctty, pcpoll, pcmmap, ttykqfilter, D_TTY }; #define COL 80 diff --git a/sys/arch/x86_64/x86_64/mem.c b/sys/arch/x86_64/x86_64/mem.c index cf798f15b467..75dc85f96ee5 100644 --- a/sys/arch/x86_64/x86_64/mem.c +++ b/sys/arch/x86_64/x86_64/mem.c @@ -1,4 +1,4 @@ -/* $NetBSD: mem.c,v 1.4 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: mem.c,v 1.5 2002/10/23 09:12:51 jdolecek Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -69,7 +69,7 @@ dev_type_mmap(mmmmap); const struct cdevsw mem_cdevsw = { nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, mmmmap, + nostop, notty, nopoll, mmmmap, nokqfilter }; /*ARGSUSED*/ diff --git a/sys/coda/coda_psdev.c b/sys/coda/coda_psdev.c index 6216c3dcc2d4..209c3892c577 100644 --- a/sys/coda/coda_psdev.c +++ b/sys/coda/coda_psdev.c @@ -1,4 +1,4 @@ -/* $NetBSD: coda_psdev.c,v 1.20 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: coda_psdev.c,v 1.21 2002/10/23 09:12:52 jdolecek Exp $ */ /* * @@ -52,7 +52,7 @@ /* These routines are the device entry points for Venus. */ #include -__KERNEL_RCSID(0, "$NetBSD: coda_psdev.c,v 1.20 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: coda_psdev.c,v 1.21 2002/10/23 09:12:52 jdolecek Exp $"); extern int coda_nc_initialized; /* Set if cache has been initialized */ @@ -102,10 +102,11 @@ dev_type_read(vc_nb_read); dev_type_write(vc_nb_write); dev_type_ioctl(vc_nb_ioctl); dev_type_poll(vc_nb_poll); +dev_type_kqfilter(vc_nb_kqfilter); const struct cdevsw vcoda_cdevsw = { vc_nb_open, vc_nb_close, vc_nb_read, vc_nb_write, vc_nb_ioctl, - nostop, notty, vc_nb_poll, nommap, + nostop, notty, vc_nb_poll, nommap, vc_nb_kqfilter, }; struct vmsg { @@ -493,6 +494,62 @@ vc_nb_poll(dev, events, p) return(0); } +static void +filt_vc_nb_detach(struct knote *kn) +{ + struct vcomm *vcp = kn->kn_hook; + + SLIST_REMOVE(&vcp->vc_selproc.si_klist, kn, knote, kn_selnext); +} + +static int +filt_vc_nb_read(struct knote *kn, long hint) +{ + struct vcomm *vcp = kn->kn_hook; + struct vmsg *vmp; + + if (EMPTY(vcp->vc_requests)) + return (0); + + vmp = (struct vmsg *)GETNEXT(vcp->vc_requests); + + kn->kn_data = vmp->vm_inSize; + return (1); +} + +static const struct filterops vc_nb_read_filtops = + { 1, NULL, filt_vc_nb_detach, filt_vc_nb_read }; + +int +vc_nb_kqfilter(dev_t dev, struct knote *kn) +{ + struct vcomm *vcp; + struct klist *klist; + + ENTRY; + + if (minor(dev) >= NVCODA || minor(dev) < 0) + return(ENXIO); + + vcp = &coda_mnttbl[minor(dev)].mi_vcomm; + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &vcp->vc_selproc.si_klist; + kn->kn_fop = &vc_nb_read_filtops; + break; + + default: + return (1); + } + + kn->kn_hook = vcp; + + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + + return (0); +} + /* * Statistics */ @@ -551,7 +608,7 @@ coda_call(mntinfo, inSize, outSize, buffer) /* Append msg to request queue and poke Venus. */ INSQUE(vmp->vm_chain, vcp->vc_requests); - selwakeup(&(vcp->vc_selproc)); + selnotify(&(vcp->vc_selproc), 0); /* We can be interrupted while we wait for Venus to process * our request. If the interrupt occurs before Venus has read @@ -674,7 +731,7 @@ coda_call(mntinfo, inSize, outSize, buffer) /* insert at head of queue! */ INSQUE(svmp->vm_chain, vcp->vc_requests); - selwakeup(&(vcp->vc_selproc)); + selnotify(&(vcp->vc_selproc), 0); } } diff --git a/sys/compat/irix/irix_kmem.c b/sys/compat/irix/irix_kmem.c index ea93cf8f6af3..5bf955c12651 100644 --- a/sys/compat/irix/irix_kmem.c +++ b/sys/compat/irix/irix_kmem.c @@ -1,4 +1,4 @@ -/* $NetBSD: irix_kmem.c,v 1.3 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: irix_kmem.c,v 1.4 2002/10/23 09:12:53 jdolecek Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: irix_kmem.c,v 1.3 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: irix_kmem.c,v 1.4 2002/10/23 09:12:53 jdolecek Exp $"); #include #include @@ -74,7 +74,7 @@ dev_type_write(irix_kmemwrite); const struct cdevsw irix_kmem_cdevsw = { irix_kmemopen, irix_kmemclose, irix_kmemread, irix_kmemwrite, - noioctl, nostop, notty, nopoll, nommap, + noioctl, nostop, notty, nopoll, nommap, nokqfilter, }; void diff --git a/sys/compat/irix/irix_usema.c b/sys/compat/irix/irix_usema.c index d49dba2bfbac..f1518d9ded92 100644 --- a/sys/compat/irix/irix_usema.c +++ b/sys/compat/irix/irix_usema.c @@ -1,4 +1,4 @@ -/* $NetBSD: irix_usema.c,v 1.7 2002/10/11 20:07:48 jdolecek Exp $ */ +/* $NetBSD: irix_usema.c,v 1.8 2002/10/23 09:12:54 jdolecek Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: irix_usema.c,v 1.7 2002/10/11 20:07:48 jdolecek Exp $"); +__KERNEL_RCSID(0, "$NetBSD: irix_usema.c,v 1.8 2002/10/23 09:12:54 jdolecek Exp $"); #include #include @@ -71,7 +71,7 @@ __KERNEL_RCSID(0, "$NetBSD: irix_usema.c,v 1.7 2002/10/11 20:07:48 jdolecek Exp const struct cdevsw irix_usema_cdevsw = { nullopen, nullclose, noread, nowrite, - noioctl, nostop, notty, nopoll, nommap, + noioctl, nostop, notty, nopoll, nommap, nokqfilter, }; /* diff --git a/sys/compat/svr4/svr4_net.c b/sys/compat/svr4/svr4_net.c index cf21f5409634..c538b1e6b612 100644 --- a/sys/compat/svr4/svr4_net.c +++ b/sys/compat/svr4/svr4_net.c @@ -1,4 +1,4 @@ -/* $NetBSD: svr4_net.c,v 1.29 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: svr4_net.c,v 1.30 2002/10/23 09:12:55 jdolecek Exp $ */ /*- * Copyright (c) 1994 The NetBSD Foundation, Inc. @@ -41,7 +41,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: svr4_net.c,v 1.29 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: svr4_net.c,v 1.30 2002/10/23 09:12:55 jdolecek Exp $"); #define COMPAT_SVR4 1 @@ -84,7 +84,7 @@ dev_type_open(svr4_netopen); const struct cdevsw svr4_net_cdevsw = { svr4_netopen, noclose, noread, nowrite, noioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; /* @@ -110,7 +110,7 @@ int svr4_ptm_alloc __P((struct proc *)); static struct fileops svr4_netops = { soo_read, soo_write, soo_ioctl, soo_fcntl, soo_poll, - soo_stat, svr4_soo_close + soo_stat, svr4_soo_close, soo_kqfilter }; diff --git a/sys/conf/files b/sys/conf/files index 5e03c584bb89..cd6e9e2b6352 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -1,4 +1,4 @@ -# $NetBSD: files,v 1.573 2002/10/18 14:31:10 junyoung Exp $ +# $NetBSD: files,v 1.574 2002/10/23 09:12:56 jdolecek Exp $ # @(#)files.newconf 7.5 (Berkeley) 5/10/93 @@ -1019,6 +1019,7 @@ file kern/kern_acct.c file kern/kern_allocsys.c file kern/kern_clock.c file kern/kern_descrip.c +file kern/kern_event.c file kern/kern_exec.c file kern/kern_exit.c file kern/kern_fork.c diff --git a/sys/dev/arcbios/arcbios_tty.c b/sys/dev/arcbios/arcbios_tty.c index 218d7cb19f27..20c527b8e4f2 100644 --- a/sys/dev/arcbios/arcbios_tty.c +++ b/sys/dev/arcbios/arcbios_tty.c @@ -1,4 +1,4 @@ -/* $NetBSD: arcbios_tty.c,v 1.5 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: arcbios_tty.c,v 1.6 2002/10/23 09:13:06 jdolecek Exp $ */ /* * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University. @@ -28,7 +28,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: arcbios_tty.c,v 1.5 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: arcbios_tty.c,v 1.6 2002/10/23 09:13:06 jdolecek Exp $"); #include #include @@ -66,7 +66,7 @@ dev_type_poll(arcbios_ttypoll); const struct cdevsw arcbios_cdevsw = { arcbios_ttyopen, arcbios_ttyclose, arcbios_ttyread, arcbios_ttywrite, arcbios_ttyioctl, arcbios_ttystop, arcbios_ttytty, arcbios_ttypoll, - nommap, D_TTY, + nommap, ttykqfilter, D_TTY, }; int diff --git a/sys/dev/ata/wd.c b/sys/dev/ata/wd.c index 62269d1412eb..c57e67c82028 100644 --- a/sys/dev/ata/wd.c +++ b/sys/dev/ata/wd.c @@ -1,4 +1,4 @@ -/* $NetBSD: wd.c,v 1.230 2002/10/18 14:31:13 junyoung Exp $ */ +/* $NetBSD: wd.c,v 1.231 2002/10/23 09:13:07 jdolecek Exp $ */ /* * Copyright (c) 1998, 2001 Manuel Bouyer. All rights reserved. @@ -66,7 +66,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: wd.c,v 1.230 2002/10/18 14:31:13 junyoung Exp $"); +__KERNEL_RCSID(0, "$NetBSD: wd.c,v 1.231 2002/10/23 09:13:07 jdolecek Exp $"); #ifndef WDCDEBUG #define WDCDEBUG @@ -204,7 +204,7 @@ const struct bdevsw wd_bdevsw = { const struct cdevsw wd_cdevsw = { wdopen, wdclose, wdread, wdwrite, wdioctl, - nostop, notty, nopoll, nommap, D_DISK + nostop, notty, nopoll, nommap, nokqfilter, D_DISK }; /* diff --git a/sys/dev/audio.c b/sys/dev/audio.c index eeb7bdd2ec87..885fd4c9232f 100644 --- a/sys/dev/audio.c +++ b/sys/dev/audio.c @@ -1,4 +1,4 @@ -/* $NetBSD: audio.c,v 1.166 2002/10/16 21:07:08 jdolecek Exp $ */ +/* $NetBSD: audio.c,v 1.167 2002/10/23 09:12:58 jdolecek Exp $ */ /* * Copyright (c) 1991-1993 Regents of the University of California. @@ -61,7 +61,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.166 2002/10/16 21:07:08 jdolecek Exp $"); +__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.167 2002/10/23 09:12:58 jdolecek Exp $"); #include "audio.h" #if NAUDIO > 0 @@ -109,6 +109,7 @@ int audio_read(struct audio_softc *, struct uio *, int); int audio_write(struct audio_softc *, struct uio *, int); int audio_ioctl(struct audio_softc *, u_long, caddr_t, int, struct proc *); int audio_poll(struct audio_softc *, int, struct proc *); +int audio_kqfilter(struct audio_softc *, struct knote *); paddr_t audio_mmap(struct audio_softc *, off_t, int); int mixer_open(dev_t, struct audio_softc *, int, int, struct proc *); @@ -188,10 +189,11 @@ dev_type_write(audiowrite); dev_type_ioctl(audioioctl); dev_type_poll(audiopoll); dev_type_mmap(audiommap); +dev_type_kqfilter(audiokqfilter); const struct cdevsw audio_cdevsw = { audioopen, audioclose, audioread, audiowrite, audioioctl, - nostop, notty, audiopoll, audiommap, + nostop, notty, audiopoll, audiommap, audiokqfilter, }; /* The default audio mode: 8 kHz mono ulaw */ @@ -716,6 +718,34 @@ audiopoll(dev_t dev, int events, struct proc *p) return (error); } +int +audiokqfilter(dev_t dev, struct knote *kn) +{ + int unit = AUDIOUNIT(dev); + struct audio_softc *sc = audio_cd.cd_devs[unit]; + int rv; + + if (sc->sc_dying) + return (1); + + sc->sc_refcnt++; + switch (AUDIODEV(dev)) { + case SOUND_DEVICE: + case AUDIO_DEVICE: + rv = audio_kqfilter(sc, kn); + break; + case AUDIOCTL_DEVICE: + case MIXER_DEVICE: + rv = 1; + break; + default: + rv = 1; + } + if (--sc->sc_refcnt < 0) + wakeup(&sc->sc_refcnt); + return (rv); +} + paddr_t audiommap(dev_t dev, off_t off, int prot) { @@ -1946,6 +1976,97 @@ audio_poll(struct audio_softc *sc, int events, struct proc *p) return (revents); } +static void +filt_audiordetach(struct knote *kn) +{ + struct audio_softc *sc = kn->kn_hook; + int s; + + s = splaudio(); + SLIST_REMOVE(&sc->sc_rsel.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_audioread(struct knote *kn, long hint) +{ + struct audio_softc *sc = kn->kn_hook; + int s; + + /* XXXLUKEM (thorpej): please make sure this is right */ + + s = splaudio(); + if (sc->sc_mode & AUMODE_PLAY) + kn->kn_data = sc->sc_pr.stamp - sc->sc_wstamp; + else + kn->kn_data = sc->sc_rr.used - sc->sc_rr.usedlow; + splx(s); + + return (kn->kn_data > 0); +} + +static const struct filterops audioread_filtops = + { 1, NULL, filt_audiordetach, filt_audioread }; + +static void +filt_audiowdetach(struct knote *kn) +{ + struct audio_softc *sc = kn->kn_hook; + int s; + + s = splaudio(); + SLIST_REMOVE(&sc->sc_wsel.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_audiowrite(struct knote *kn, long hint) +{ + struct audio_softc *sc = kn->kn_hook; + int s; + + /* XXXLUKEM (thorpej): please make sure this is right */ + + s = splaudio(); + kn->kn_data = sc->sc_pr.usedlow - sc->sc_pr.used; + splx(s); + + return (kn->kn_data > 0); +} + +static const struct filterops audiowrite_filtops = + { 1, NULL, filt_audiowdetach, filt_audiowrite }; + +int +audio_kqfilter(struct audio_softc *sc, struct knote *kn) +{ + struct klist *klist; + int s; + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &sc->sc_rsel.si_klist; + kn->kn_fop = &audioread_filtops; + break; + + case EVFILT_WRITE: + klist = &sc->sc_wsel.si_klist; + kn->kn_fop = &audiowrite_filtops; + break; + + default: + return (1); + } + + kn->kn_hook = sc; + + s = splaudio(); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + splx(s); + + return (0); +} + paddr_t audio_mmap(struct audio_softc *sc, off_t off, int prot) { @@ -2217,7 +2338,7 @@ audio_pint(void *v) if ((sc->sc_mode & AUMODE_PLAY) && !cb->pause) { if (cb->used <= cb->usedlow) { audio_wakeup(&sc->sc_wchan); - selwakeup(&sc->sc_wsel); + selnotify(&sc->sc_wsel, 0); if (sc->sc_async_audio) { DPRINTFN(3, ("audio_pint: sending SIGIO %p\n", sc->sc_async_audio)); @@ -2229,7 +2350,7 @@ audio_pint(void *v) /* Possible to return one or more "phantom blocks" now. */ if (!sc->sc_full_duplex && sc->sc_rchan) { audio_wakeup(&sc->sc_rchan); - selwakeup(&sc->sc_rsel); + selnotify(&sc->sc_rsel, 0); if (sc->sc_async_audio) psignal(sc->sc_async_audio, SIGIO); } @@ -2329,7 +2450,7 @@ audio_rint(void *v) } audio_wakeup(&sc->sc_rchan); - selwakeup(&sc->sc_rsel); + selnotify(&sc->sc_rsel, 0); if (sc->sc_async_audio) psignal(sc->sc_async_audio, SIGIO); } diff --git a/sys/dev/bluetooth/bthci.c b/sys/dev/bluetooth/bthci.c index f2c5ba8b6a4d..a052f40b7639 100644 --- a/sys/dev/bluetooth/bthci.c +++ b/sys/dev/bluetooth/bthci.c @@ -1,4 +1,4 @@ -/* $NetBSD: bthci.c,v 1.8 2002/10/02 16:33:39 thorpej Exp $ */ +/* $NetBSD: bthci.c,v 1.9 2002/10/23 09:13:08 jdolecek Exp $ */ /* * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -81,10 +81,11 @@ extern struct cfdriver bthci_cd; dev_type_open(bthciopen); dev_type_close(bthciclose); dev_type_poll(bthcipoll); +dev_type_kqfilter(bthcikqfilter); const struct cdevsw bthci_cdevsw = { bthciopen, bthciclose, noread, nowrite, noioctl, - nostop, notty, bthcipoll, nommap, + nostop, notty, bthcipoll, nommap, bthcikqfilter, }; #define BTHCIUNIT(dev) (minor(dev)) @@ -109,7 +110,8 @@ bthci_attach(struct device *parent, struct device *self, void *aux) #ifdef DIAGNOSTIC_XXX if (sc->sc_methods->bt_read == NULL || sc->sc_methods->bt_write == NULL || - sc->sc_methods->bt_poll == NULL) + sc->sc_methods->bt_poll == NULL || + sc->sc_methods->bt_kqfilter == NULL) panic("%s: missing methods", sc->sc_dev.dv_xname); #endif @@ -290,3 +292,16 @@ bthcipoll(dev_t dev, int events, struct proc *p) return (sc->sc_methods->bt_poll(sc->sc_handle, events, p)); } +int +bthcikqfilter(dev_t dev, struct knote *kn) +{ + struct bthci_softc *sc; + + sc = device_lookup(&bthci_cd, BTHCIUNIT(dev)); + if (sc == NULL) + return (ENXIO); + if ((sc->sc_dev.dv_flags & DVF_ACTIVE) == 0 || !sc->sc_open) + return (EIO); + + return (sc->sc_methods->bt_kqfilter(sc->sc_handle, events, p)); +} diff --git a/sys/dev/bluetooth/bthcivar.h b/sys/dev/bluetooth/bthcivar.h index 1fbf3db781ce..63fbd090ff37 100644 --- a/sys/dev/bluetooth/bthcivar.h +++ b/sys/dev/bluetooth/bthcivar.h @@ -1,4 +1,4 @@ -/* $NetBSD: bthcivar.h,v 1.1 2002/08/24 17:30:13 augustss Exp $ */ +/* $NetBSD: bthcivar.h,v 1.2 2002/10/23 09:13:09 jdolecek Exp $ */ /* * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -42,6 +42,7 @@ struct bthci_methods { int (*bt_read)(void *h, struct uio *uio, int flag); int (*bt_write)(void *h, struct uio *uio, int flag); int (*bt_poll)(void *h, int events, struct proc *p); + int (*bt_kqfilter)(void *h, struct knote *kn); }; struct bthci_softc { diff --git a/sys/dev/ccd.c b/sys/dev/ccd.c index 7e07d315be78..85e91ecf3227 100644 --- a/sys/dev/ccd.c +++ b/sys/dev/ccd.c @@ -1,4 +1,4 @@ -/* $NetBSD: ccd.c,v 1.78 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: ccd.c,v 1.79 2002/10/23 09:12:59 jdolecek Exp $ */ /*- * Copyright (c) 1996, 1997, 1998, 1999 The NetBSD Foundation, Inc. @@ -90,7 +90,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ccd.c,v 1.78 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ccd.c,v 1.79 2002/10/23 09:12:59 jdolecek Exp $"); #include #include @@ -179,7 +179,7 @@ const struct bdevsw ccd_bdevsw = { const struct cdevsw ccd_cdevsw = { ccdopen, ccdclose, ccdread, ccdwrite, ccdioctl, - nostop, notty, nopoll, nommap, D_DISK + nostop, notty, nopoll, nommap, nokqfilter, D_DISK }; #ifdef DEBUG diff --git a/sys/dev/clockctl.c b/sys/dev/clockctl.c index 6a0c86f3d015..2c3caec8ba19 100644 --- a/sys/dev/clockctl.c +++ b/sys/dev/clockctl.c @@ -1,4 +1,4 @@ -/* $NetBSD: clockctl.c,v 1.8 2002/09/23 05:51:10 simonb Exp $ */ +/* $NetBSD: clockctl.c,v 1.9 2002/10/23 09:13:00 jdolecek Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: clockctl.c,v 1.8 2002/09/23 05:51:10 simonb Exp $"); +__KERNEL_RCSID(0, "$NetBSD: clockctl.c,v 1.9 2002/10/23 09:13:00 jdolecek Exp $"); #include "opt_ntp.h" @@ -57,7 +57,7 @@ dev_type_ioctl(clockctlioctl); const struct cdevsw clockctl_cdevsw = { nullopen, nullclose, noread, nowrite, clockctlioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; void diff --git a/sys/dev/cons.c b/sys/dev/cons.c index b272b1e4fb19..db3ff38fc41c 100644 --- a/sys/dev/cons.c +++ b/sys/dev/cons.c @@ -1,4 +1,4 @@ -/* $NetBSD: cons.c,v 1.44 2002/09/27 15:37:08 provos Exp $ */ +/* $NetBSD: cons.c,v 1.45 2002/10/23 09:13:01 jdolecek Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -43,7 +43,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cons.c,v 1.44 2002/09/27 15:37:08 provos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cons.c,v 1.45 2002/10/23 09:13:01 jdolecek Exp $"); #include #include @@ -64,10 +64,11 @@ dev_type_read(cnread); dev_type_write(cnwrite); dev_type_ioctl(cnioctl); dev_type_poll(cnpoll); +dev_type_kqfilter(cnkqfilter); const struct cdevsw cons_cdevsw = { cnopen, cnclose, cnread, cnwrite, cnioctl, - nostop, notty, cnpoll, nommap, D_TTY + nostop, notty, cnpoll, nommap, cnkqfilter, D_TTY }; struct tty *constty = NULL; /* virtual console output device */ @@ -269,6 +270,31 @@ cnpoll(dev, events, p) return ((*cdev->d_poll)(dev, events, p)); } +/*ARGSUSED*/ +int +cnkqfilter(dev, kn) + dev_t dev; + struct knote *kn; +{ + const struct cdevsw *cdev; + + /* + * Redirect the kqfilter, if that's appropriate. + * I don't want to think of the possible side effects + * of console redirection here. + */ + if (constty != NULL && (cn_tab == NULL || cn_tab->cn_pri != CN_REMOTE)) + dev = constty->t_dev; + else if (cn_tab == NULL) + return ENXIO; + else + dev = cn_tab->cn_dev; + cdev = cdevsw_lookup(dev); + if (cdev == NULL) + return (ENXIO); + return ((*cdev->d_kqfilter)(dev, kn)); +} + int cngetc() { diff --git a/sys/dev/dec/dz.c b/sys/dev/dec/dz.c index f77aa27da28d..68084501dbe6 100644 --- a/sys/dev/dec/dz.c +++ b/sys/dev/dec/dz.c @@ -1,4 +1,4 @@ -/* $NetBSD: dz.c,v 1.8 2002/09/25 22:21:36 thorpej Exp $ */ +/* $NetBSD: dz.c,v 1.9 2002/10/23 09:13:09 jdolecek Exp $ */ /* * Copyright (c) 1996 Ken C. Wellsch. All rights reserved. * Copyright (c) 1992, 1993 @@ -37,7 +37,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: dz.c,v 1.8 2002/09/25 22:21:36 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dz.c,v 1.9 2002/10/23 09:13:09 jdolecek Exp $"); #include "opt_ddb.h" @@ -116,7 +116,7 @@ dev_type_poll(dzpoll); const struct cdevsw dz_cdevsw = { dzopen, dzclose, dzread, dzwrite, dzioctl, - dzstop, dztty, dzpoll, nommap, D_TTY + dzstop, dztty, dzpoll, nommap, ttykqfilter, D_TTY }; /* diff --git a/sys/dev/dmover/dmover_io.c b/sys/dev/dmover/dmover_io.c index ee829ac840e3..562ba03e0c4d 100644 --- a/sys/dev/dmover/dmover_io.c +++ b/sys/dev/dmover/dmover_io.c @@ -1,4 +1,4 @@ -/* $NetBSD: dmover_io.c,v 1.5 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: dmover_io.c,v 1.6 2002/10/23 09:13:10 jdolecek Exp $ */ /* * Copyright (c) 2002 Wasabi Systems, Inc. @@ -55,7 +55,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: dmover_io.c,v 1.5 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dmover_io.c,v 1.6 2002/10/23 09:13:10 jdolecek Exp $"); #include #include @@ -109,7 +109,7 @@ dev_type_open(dmoverioopen); const struct cdevsw dmoverio_cdevsw = { dmoverioopen, noclose, noread, nowrite, noioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; /* diff --git a/sys/dev/hpc/biconsdev.c b/sys/dev/hpc/biconsdev.c index 6cfbff904d79..a2a40da3d56d 100644 --- a/sys/dev/hpc/biconsdev.c +++ b/sys/dev/hpc/biconsdev.c @@ -1,4 +1,4 @@ -/* $NetBSD: biconsdev.c,v 1.6 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: biconsdev.c,v 1.7 2002/10/23 09:13:11 jdolecek Exp $ */ /*- * Copyright (c) 1999-2001 @@ -71,7 +71,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: biconsdev.c,v 1.6 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: biconsdev.c,v 1.7 2002/10/23 09:13:11 jdolecek Exp $"); #include "biconsdev.h" #include @@ -100,7 +100,8 @@ dev_type_poll(biconsdevpoll); const struct cdevsw biconsdev_cdevsw = { biconsdevopen, biconsdevclose, biconsdevread, biconsdevwrite, - biconsdevioctl, nostop, biconsdevtty, biconsdevpoll, nommap, D_TTY + biconsdevioctl, nostop, biconsdevtty, biconsdevpoll, nommap, + ttykqfilter, D_TTY }; void diff --git a/sys/dev/hpc/btnmgr.c b/sys/dev/hpc/btnmgr.c index 118175fee7ab..7653d60aeac7 100644 --- a/sys/dev/hpc/btnmgr.c +++ b/sys/dev/hpc/btnmgr.c @@ -1,4 +1,4 @@ -/* $NetBSD: btnmgr.c,v 1.10 2002/10/02 16:33:49 thorpej Exp $ */ +/* $NetBSD: btnmgr.c,v 1.11 2002/10/23 09:13:11 jdolecek Exp $ */ /*- * Copyright (c) 1999 @@ -35,7 +35,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: btnmgr.c,v 1.10 2002/10/02 16:33:49 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: btnmgr.c,v 1.11 2002/10/23 09:13:11 jdolecek Exp $"); #define BTNMGRDEBUG @@ -101,7 +101,7 @@ dev_type_ioctl(btnmgrioctl); const struct cdevsw btnmgr_cdevsw = { btnmgropen, btnmgrclose, btnmgrread, btnmgrwrite, btnmgrioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; #endif /* notyet */ diff --git a/sys/dev/i2o/dpti.c b/sys/dev/i2o/dpti.c index 3d51f46c6821..8ba537cf9a11 100644 --- a/sys/dev/i2o/dpti.c +++ b/sys/dev/i2o/dpti.c @@ -1,4 +1,4 @@ -/* $NetBSD: dpti.c,v 1.8 2002/10/02 16:33:51 thorpej Exp $ */ +/* $NetBSD: dpti.c,v 1.9 2002/10/23 09:13:12 jdolecek Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -64,7 +64,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: dpti.c,v 1.8 2002/10/02 16:33:51 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dpti.c,v 1.9 2002/10/23 09:13:12 jdolecek Exp $"); #include "opt_i2o.h" @@ -147,7 +147,7 @@ dev_type_ioctl(dptiioctl); const struct cdevsw dpti_cdevsw = { dptiopen, nullclose, noread, nowrite, dptiioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; extern struct cfdriver dpti_cd; diff --git a/sys/dev/i2o/iop.c b/sys/dev/i2o/iop.c index 3df239ad019b..08f435dfbe3a 100644 --- a/sys/dev/i2o/iop.c +++ b/sys/dev/i2o/iop.c @@ -1,4 +1,4 @@ -/* $NetBSD: iop.c,v 1.27 2002/10/22 13:42:33 ad Exp $ */ +/* $NetBSD: iop.c,v 1.28 2002/10/23 09:13:12 jdolecek Exp $ */ /*- * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc. @@ -41,7 +41,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: iop.c,v 1.27 2002/10/22 13:42:33 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: iop.c,v 1.28 2002/10/23 09:13:12 jdolecek Exp $"); #include "opt_i2o.h" #include "iop.h" @@ -113,7 +113,7 @@ dev_type_ioctl(iopioctl); const struct cdevsw iop_cdevsw = { iopopen, iopclose, noread, nowrite, iopioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; #define IC_CONFIGURE 0x01 diff --git a/sys/dev/ic/cd18xx.c b/sys/dev/ic/cd18xx.c index 34aad99d0c30..80804790d9b7 100644 --- a/sys/dev/ic/cd18xx.c +++ b/sys/dev/ic/cd18xx.c @@ -1,4 +1,4 @@ -/* $NetBSD: cd18xx.c,v 1.4 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: cd18xx.c,v 1.5 2002/10/23 09:13:13 jdolecek Exp $ */ /* * Copyright (c) 1998, 2001 Matthew R. Green @@ -105,7 +105,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cd18xx.c,v 1.4 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cd18xx.c,v 1.5 2002/10/23 09:13:13 jdolecek Exp $"); #include #include @@ -155,7 +155,7 @@ dev_type_poll(cdttypoll); const struct cdevsw cdtty_cdevsw = { cdttyopen, cdttyclose, cdttyread, cdttywrite, cdttyioctl, - cdttystop, cdttytty, cdttypoll, nommap, D_TTY + cdttystop, cdttytty, cdttypoll, nommap, ttykqfilter, D_TTY }; static void cdtty_shutdown(struct cd18xx_softc *, struct cdtty_port*); diff --git a/sys/dev/ic/clmpcc.c b/sys/dev/ic/clmpcc.c index 18d021a9a8c2..07619751499e 100644 --- a/sys/dev/ic/clmpcc.c +++ b/sys/dev/ic/clmpcc.c @@ -1,4 +1,4 @@ -/* $NetBSD: clmpcc.c,v 1.21 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: clmpcc.c,v 1.22 2002/10/23 09:13:14 jdolecek Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -41,7 +41,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: clmpcc.c,v 1.21 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: clmpcc.c,v 1.22 2002/10/23 09:13:14 jdolecek Exp $"); #include "opt_ddb.h" @@ -109,7 +109,7 @@ dev_type_poll(clmpccpoll); const struct cdevsw clmpcc_cdevsw = { clmpccopen, clmpccclose, clmpccread, clmpccwrite, clmpccioctl, - clmpccstop, clmpcctty, clmpccpoll, nommap, D_TTY + clmpccstop, clmpcctty, clmpccpoll, nommap, ttykqfilter, D_TTY }; /* diff --git a/sys/dev/ic/com.c b/sys/dev/ic/com.c index 8cd3c1804e8b..8cb1bbf18e1d 100644 --- a/sys/dev/ic/com.c +++ b/sys/dev/ic/com.c @@ -1,4 +1,4 @@ -/* $NetBSD: com.c,v 1.199 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: com.c,v 1.200 2002/10/23 09:13:15 jdolecek Exp $ */ /*- * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc. @@ -77,7 +77,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: com.c,v 1.199 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: com.c,v 1.200 2002/10/23 09:13:15 jdolecek Exp $"); #include "opt_com.h" #include "opt_ddb.h" @@ -192,7 +192,7 @@ dev_type_poll(compoll); const struct cdevsw com_cdevsw = { comopen, comclose, comread, comwrite, comioctl, - comstop, comtty, compoll, nommap, D_TTY + comstop, comtty, compoll, nommap, ttykqfilter, D_TTY }; /* diff --git a/sys/dev/ic/cy.c b/sys/dev/ic/cy.c index 80c0e006f69a..e9233c5d40a7 100644 --- a/sys/dev/ic/cy.c +++ b/sys/dev/ic/cy.c @@ -1,4 +1,4 @@ -/* $NetBSD: cy.c,v 1.27 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: cy.c,v 1.28 2002/10/23 09:13:16 jdolecek Exp $ */ /* * cy.c @@ -16,7 +16,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cy.c,v 1.27 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cy.c,v 1.28 2002/10/23 09:13:16 jdolecek Exp $"); #include #include @@ -65,7 +65,7 @@ dev_type_poll(cypoll); const struct cdevsw cy_cdevsw = { cyopen, cyclose, cyread, cywrite, cyioctl, - cystop, cytty, cypoll, nommap, D_TTY + cystop, cytty, cypoll, nommap, ttykqfilter, D_TTY }; static int cy_open = 0; diff --git a/sys/dev/ic/joy.c b/sys/dev/ic/joy.c index 0683cc593ada..259cbf0a79ae 100644 --- a/sys/dev/ic/joy.c +++ b/sys/dev/ic/joy.c @@ -1,4 +1,4 @@ -/* $NetBSD: joy.c,v 1.3 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: joy.c,v 1.4 2002/10/23 09:13:17 jdolecek Exp $ */ /*- * Copyright (c) 1995 Jean-Marc Zucconi @@ -32,7 +32,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: joy.c,v 1.3 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: joy.c,v 1.4 2002/10/23 09:13:17 jdolecek Exp $"); #include #include @@ -40,6 +40,7 @@ __KERNEL_RCSID(0, "$NetBSD: joy.c,v 1.3 2002/09/06 13:18:43 gehenna Exp $"); #include #include #include +#include #include @@ -86,7 +87,7 @@ dev_type_ioctl(joyioctl); const struct cdevsw joy_cdevsw = { joyopen, joyclose, joyread, nowrite, joyioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; void diff --git a/sys/dev/ic/lpt.c b/sys/dev/ic/lpt.c index 2557f70df845..a49df6f57470 100644 --- a/sys/dev/ic/lpt.c +++ b/sys/dev/ic/lpt.c @@ -1,4 +1,4 @@ -/* $NetBSD: lpt.c,v 1.59 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: lpt.c,v 1.60 2002/10/23 09:13:17 jdolecek Exp $ */ /* * Copyright (c) 1993, 1994 Charles M. Hannum. @@ -54,7 +54,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: lpt.c,v 1.59 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: lpt.c,v 1.60 2002/10/23 09:13:17 jdolecek Exp $"); #include #include @@ -98,7 +98,7 @@ dev_type_ioctl(lptioctl); const struct cdevsw lpt_cdevsw = { lptopen, lptclose, noread, lptwrite, lptioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; #define LPTUNIT(s) (minor(s) & 0x1f) diff --git a/sys/dev/ic/mlx.c b/sys/dev/ic/mlx.c index 09ab8c430d95..4add55056cdc 100644 --- a/sys/dev/ic/mlx.c +++ b/sys/dev/ic/mlx.c @@ -1,4 +1,4 @@ -/* $NetBSD: mlx.c,v 1.24 2002/10/08 12:51:20 ad Exp $ */ +/* $NetBSD: mlx.c,v 1.25 2002/10/23 09:13:17 jdolecek Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -74,7 +74,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: mlx.c,v 1.24 2002/10/08 12:51:20 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mlx.c,v 1.25 2002/10/23 09:13:17 jdolecek Exp $"); #include "ld.h" @@ -141,7 +141,7 @@ dev_type_ioctl(mlxioctl); const struct cdevsw mlx_cdevsw = { mlxopen, mlxclose, noread, nowrite, mlxioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; extern struct cfdriver mlx_cd; diff --git a/sys/dev/ic/rrunner.c b/sys/dev/ic/rrunner.c index ab63615b0aaa..5535998e7b56 100644 --- a/sys/dev/ic/rrunner.c +++ b/sys/dev/ic/rrunner.c @@ -1,4 +1,4 @@ -/* $NetBSD: rrunner.c,v 1.33 2002/09/23 03:20:51 itojun Exp $ */ +/* $NetBSD: rrunner.c,v 1.34 2002/10/23 09:13:18 jdolecek Exp $ */ /* * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. @@ -42,7 +42,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: rrunner.c,v 1.33 2002/09/23 03:20:51 itojun Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rrunner.c,v 1.34 2002/10/23 09:13:18 jdolecek Exp $"); #include "opt_inet.h" #include "opt_ns.h" @@ -140,6 +140,7 @@ const struct cdevsw esh_cdevsw = { #else nommap, #endif + nullkqfilter, }; /* General routines, not externally visable */ diff --git a/sys/dev/ic/z8530tty.c b/sys/dev/ic/z8530tty.c index af425f33cf07..8a003bca44e7 100644 --- a/sys/dev/ic/z8530tty.c +++ b/sys/dev/ic/z8530tty.c @@ -1,4 +1,4 @@ -/* $NetBSD: z8530tty.c,v 1.84 2002/10/02 16:33:34 thorpej Exp $ */ +/* $NetBSD: z8530tty.c,v 1.85 2002/10/23 09:13:19 jdolecek Exp $ */ /*- * Copyright (c) 1993, 1994, 1995, 1996, 1997, 1998, 1999 @@ -99,7 +99,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: z8530tty.c,v 1.84 2002/10/02 16:33:34 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: z8530tty.c,v 1.85 2002/10/23 09:13:19 jdolecek Exp $"); #include "opt_kgdb.h" @@ -231,7 +231,7 @@ dev_type_poll(zspoll); const struct cdevsw zstty_cdevsw = { zsopen, zsclose, zsread, zswrite, zsioctl, - zsstop, zstty, zspoll, nommap, D_TTY + zsstop, zstty, zspoll, nommap, ttykqfilter, D_TTY }; struct zsops zsops_tty; diff --git a/sys/dev/ir/cir.c b/sys/dev/ir/cir.c index 612d9dde7f51..a9f4fce3bc72 100644 --- a/sys/dev/ir/cir.c +++ b/sys/dev/ir/cir.c @@ -1,4 +1,4 @@ -/* $NetBSD: cir.c,v 1.7 2002/10/02 16:33:56 thorpej Exp $ */ +/* $NetBSD: cir.c,v 1.8 2002/10/23 09:13:20 jdolecek Exp $ */ /* * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -56,10 +56,11 @@ dev_type_read(cirread); dev_type_write(cirwrite); dev_type_ioctl(cirioctl); dev_type_poll(cirpoll); +dev_type_kqfilter(cirkqfilter); const struct cdevsw cir_cdevsw = { ciropen, circlose, cirread, cirwrite, cirioctl, - nostop, notty, cirpoll, nommap, + nostop, notty, cirpoll, nommap, cirkqfilter, }; int cir_match(struct device *parent, struct cfdata *match, void *aux); diff --git a/sys/dev/ir/irframe.c b/sys/dev/ir/irframe.c index 95eccb951379..d0baa8140581 100644 --- a/sys/dev/ir/irframe.c +++ b/sys/dev/ir/irframe.c @@ -1,4 +1,4 @@ -/* $NetBSD: irframe.c,v 1.22 2002/10/02 15:29:35 thorpej Exp $ */ +/* $NetBSD: irframe.c,v 1.23 2002/10/23 09:13:21 jdolecek Exp $ */ /* * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -68,10 +68,11 @@ dev_type_read(irframeread); dev_type_write(irframewrite); dev_type_ioctl(irframeioctl); dev_type_poll(irframepoll); +dev_type_kqfilter(irframekqfilter); const struct cdevsw irframe_cdevsw = { irframeopen, irframeclose, irframeread, irframewrite, irframeioctl, - nostop, notty, irframepoll, nommap, + nostop, notty, irframepoll, nommap, irframekqfilter, }; int irframe_match(struct device *parent, struct cfdata *match, void *aux); @@ -117,6 +118,7 @@ irframe_attach(struct device *parent, struct device *self, void *aux) if (sc->sc_methods->im_read == NULL || sc->sc_methods->im_write == NULL || sc->sc_methods->im_poll == NULL || + sc->sc_methods->im_kqfilter == NULL || sc->sc_methods->im_set_params == NULL || sc->sc_methods->im_get_speeds == NULL || sc->sc_methods->im_get_turnarounds == NULL) @@ -389,6 +391,19 @@ irframepoll(dev_t dev, int events, struct proc *p) return (sc->sc_methods->im_poll(sc->sc_handle, events, p)); } +int +irframekqfilter(dev_t dev, struct knote *kn) +{ + struct irframe_softc *sc; + + sc = device_lookup(&irframe_cd, IRFRAMEUNIT(dev)); + if ((sc->sc_dev.dv_flags & DVF_ACTIVE) == 0 || !sc->sc_open) + return (1); + + return (sc->sc_methods->im_kqfilter(sc->sc_handle, kn)); +} + + /*********/ diff --git a/sys/dev/ir/irframe_tty.c b/sys/dev/ir/irframe_tty.c index 731a77843fd6..259fb8a231b3 100644 --- a/sys/dev/ir/irframe_tty.c +++ b/sys/dev/ir/irframe_tty.c @@ -1,4 +1,4 @@ -/* $NetBSD: irframe_tty.c,v 1.21 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: irframe_tty.c,v 1.22 2002/10/23 09:13:21 jdolecek Exp $ */ /* * TODO @@ -122,6 +122,8 @@ struct irframet_softc { u_int sc_frameo; struct frame sc_frames[MAXFRAMES]; struct selinfo sc_rsel; + /* XXXJRT Nothing selnotify's sc_wsel */ + struct selinfo sc_wsel; }; /* line discipline methods */ @@ -141,6 +143,7 @@ Static int irframet_close(void *h, int flag, int mode, struct proc *p); Static int irframet_read(void *h, struct uio *uio, int flag); Static int irframet_write(void *h, struct uio *uio, int flag); Static int irframet_poll(void *h, int events, struct proc *p); +Static int irframet_kqfilter(void *h, struct knote *kn); Static int irframet_set_params(void *h, struct irda_params *params); Static int irframet_get_speeds(void *h, int *speeds); Static int irframet_get_turnarounds(void *h, int *times); @@ -157,7 +160,7 @@ Static void irt_delay(struct tty *tp, u_int delay); Static const struct irframe_methods irframet_methods = { irframet_open, irframet_close, irframet_read, irframet_write, - irframet_poll, irframet_set_params, + irframet_poll, irframet_kqfilter, irframet_set_params, irframet_get_speeds, irframet_get_turnarounds }; @@ -356,7 +359,7 @@ irt_frame(struct irframet_softc *sc, u_char *buf, u_int len) DPRINTF(("%s: waking up reader\n", __FUNCTION__)); wakeup(sc->sc_frames); } - selwakeup(&sc->sc_rsel); + selnotify(&sc->sc_rsel, 0); } void @@ -661,6 +664,91 @@ irframet_poll(void *h, int events, struct proc *p) return (revents); } +static void +filt_irframetrdetach(struct knote *kn) +{ + struct tty *tp = kn->kn_hook; + struct irframet_softc *sc = (struct irframet_softc *)tp->t_sc; + int s; + + s = splir(); + SLIST_REMOVE(&sc->sc_rsel.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_irframetread(struct knote *kn, long hint) +{ + struct tty *tp = kn->kn_hook; + struct irframet_softc *sc = (struct irframet_softc *)tp->t_sc; + + kn->kn_data = sc->sc_nframes; + return (kn->kn_data > 0); +} + +static void +filt_irframetwdetach(struct knote *kn) +{ + struct tty *tp = kn->kn_hook; + struct irframet_softc *sc = (struct irframet_softc *)tp->t_sc; + int s; + + s = splir(); + SLIST_REMOVE(&sc->sc_wsel.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_irframetwrite(struct knote *kn, long hint) +{ + struct tty *tp = kn->kn_hook; + + /* XXX double-check this */ + + if (tp->t_outq.c_cc <= tp->t_lowat) { + kn->kn_data = tp->t_lowat - tp->t_outq.c_cc; + return (1); + } + + kn->kn_data = 0; + return (0); +} + +static const struct filterops irframetread_filtops = + { 1, NULL, filt_irframetrdetach, filt_irframetread }; +static const struct filterops irframetwrite_filtops = + { 1, NULL, filt_irframetwdetach, filt_irframetwrite }; + +int +irframet_kqfilter(void *h, struct knote *kn) +{ + struct tty *tp = h; + struct irframet_softc *sc = (struct irframet_softc *)tp->t_sc; + struct klist *klist; + int s; + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &sc->sc_rsel.si_klist; + kn->kn_fop = &irframetread_filtops; + break; + case EVFILT_WRITE: + klist = &sc->sc_wsel.si_klist; + kn->kn_fop = &irframetwrite_filtops; + break; + default: + return (1); + } + + kn->kn_hook = tp; + + s = splir(); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + splx(s); + + return (0); +} + int irframet_set_params(void *h, struct irda_params *p) { diff --git a/sys/dev/ir/irframevar.h b/sys/dev/ir/irframevar.h index 08dd45357cbb..1c0bc0482214 100644 --- a/sys/dev/ir/irframevar.h +++ b/sys/dev/ir/irframevar.h @@ -1,4 +1,4 @@ -/* $NetBSD: irframevar.h,v 1.8 2001/12/13 15:09:07 augustss Exp $ */ +/* $NetBSD: irframevar.h,v 1.9 2002/10/23 09:13:22 jdolecek Exp $ */ /* * Copyright (c) 2000 The NetBSD Foundation, Inc. @@ -42,6 +42,7 @@ struct irframe_methods { int (*im_read)(void *h, struct uio *uio, int flag); int (*im_write)(void *h, struct uio *uio, int flag); int (*im_poll)(void *h, int events, struct proc *p); + int (*im_kqfilter)(void *h, struct knote *kn); int (*im_set_params)(void *h, struct irda_params *params); int (*im_get_speeds)(void *h, int *speeds); int (*im_get_turnarounds)(void *h, int *times); diff --git a/sys/dev/isa/fd.c b/sys/dev/isa/fd.c index a7145b49a725..dba87c5dc468 100644 --- a/sys/dev/isa/fd.c +++ b/sys/dev/isa/fd.c @@ -1,4 +1,4 @@ -/* $NetBSD: fd.c,v 1.29 2002/10/02 03:10:46 thorpej Exp $ */ +/* $NetBSD: fd.c,v 1.30 2002/10/23 09:13:22 jdolecek Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -92,7 +92,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: fd.c,v 1.29 2002/10/02 03:10:46 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: fd.c,v 1.30 2002/10/23 09:13:22 jdolecek Exp $"); #include "rnd.h" #include "opt_ddb.h" @@ -285,7 +285,7 @@ const struct bdevsw fd_bdevsw = { const struct cdevsw fd_cdevsw = { fdopen, fdclose, fdread, fdwrite, fdioctl, - nostop, notty, nopoll, nommap, D_DISK + nostop, notty, nopoll, nommap, nokqfilter, D_DISK }; void fdgetdisklabel __P((struct fd_softc *)); diff --git a/sys/dev/isa/mcd.c b/sys/dev/isa/mcd.c index 85f51914ae8d..f9313f337fcc 100644 --- a/sys/dev/isa/mcd.c +++ b/sys/dev/isa/mcd.c @@ -1,4 +1,4 @@ -/* $NetBSD: mcd.c,v 1.79 2002/10/02 03:10:49 thorpej Exp $ */ +/* $NetBSD: mcd.c,v 1.80 2002/10/23 09:13:23 jdolecek Exp $ */ /* * Copyright (c) 1993, 1994, 1995 Charles M. Hannum. All rights reserved. @@ -56,7 +56,7 @@ /*static char COPYRIGHT[] = "mcd-driver (C)1993 by H.Veit & B.Moore";*/ #include -__KERNEL_RCSID(0, "$NetBSD: mcd.c,v 1.79 2002/10/02 03:10:49 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mcd.c,v 1.80 2002/10/23 09:13:23 jdolecek Exp $"); #include #include @@ -211,7 +211,7 @@ const struct bdevsw mcd_bdevsw = { const struct cdevsw mcd_cdevsw = { mcdopen, mcdclose, mcdread, mcdwrite, mcdioctl, - nostop, notty, nopoll, nommap, D_DISK + nostop, notty, nopoll, nommap, nokqfilter, D_DISK }; void mcdgetdefaultlabel __P((struct mcd_softc *, struct disklabel *)); diff --git a/sys/dev/isa/satlink.c b/sys/dev/isa/satlink.c index 71356f8609e6..1a7e8f7260c6 100644 --- a/sys/dev/isa/satlink.c +++ b/sys/dev/isa/satlink.c @@ -1,4 +1,4 @@ -/* $NetBSD: satlink.c,v 1.19 2002/10/02 03:10:50 thorpej Exp $ */ +/* $NetBSD: satlink.c,v 1.20 2002/10/23 09:13:24 jdolecek Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -45,7 +45,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: satlink.c,v 1.19 2002/10/02 03:10:50 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: satlink.c,v 1.20 2002/10/23 09:13:24 jdolecek Exp $"); #include #include @@ -114,10 +114,11 @@ dev_type_close(satlinkclose); dev_type_read(satlinkread); dev_type_ioctl(satlinkioctl); dev_type_poll(satlinkpoll); +dev_type_kqfilter(satlinkkqfilter); const struct cdevsw satlink_cdevsw = { satlinkopen, satlinkclose, satlinkread, nowrite, satlinkioctl, - nostop, notty, satlinkpoll, nommap, + nostop, notty, satlinkpoll, nommap, satlinkkqfilter, }; int @@ -426,6 +427,70 @@ satlinkpoll(dev, events, p) return (revents); } +static void +filt_satlinkrdetach(struct knote *kn) +{ + struct satlink_softc *sc = kn->kn_hook; + int s; + + s = splsoftclock(); + SLIST_REMOVE(&sc->sc_selq.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_satlinkread(struct knote *kn, long hint) +{ + struct satlink_softc *sc = kn->kn_hook; + + if (sc->sc_uptr == sc->sc_sptr) + return (0); + + if (sc->sc_sptr > sc->sc_uptr) + kn->kn_data = sc->sc_sptr - sc->sc_uptr; + else + kn->kn_data = (sc->sc_bufsize - sc->sc_uptr) + + sc->sc_sptr; + return (1); +} + +static const struct filterops satlinkread_filtops = + { 1, NULL, filt_satlinkrdetach, filt_satlinkread }; + +static const struct filterops satlink_seltrue_filtops = + { 1, NULL, filt_satlinkrdetach, filt_seltrue }; + +int +satlinkkqfilter(dev_t dev, struct knote *kn) +{ + struct satlink_softc *sc = device_lookup(&satlink_cd, minor(dev)); + struct klist *klist; + int s; + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &sc->sc_selq.si_klist; + kn->kn_fop = &satlinkread_filtops; + break; + + case EVFILT_WRITE: + klist = &sc->sc_selq.si_klist; + kn->kn_fop = &satlink_seltrue_filtops; + break; + + default: + return (1); + } + + kn->kn_hook = sc; + + s = splsoftclock(); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + splx(s); + + return (0); +} + void satlinktimeout(arg) void *arg; @@ -458,7 +523,7 @@ satlinktimeout(arg) } /* Wake up anyone blocked in poll... */ - selwakeup(&sc->sc_selq); + selnotify(&sc->sc_selq, 0); out: callout_reset(&sc->sc_ch, SATLINK_TIMEOUT, satlinktimeout, sc); diff --git a/sys/dev/isa/spkr.c b/sys/dev/isa/spkr.c index dd347a889675..a25f9c97a338 100644 --- a/sys/dev/isa/spkr.c +++ b/sys/dev/isa/spkr.c @@ -1,4 +1,4 @@ -/* $NetBSD: spkr.c,v 1.11 2002/10/02 06:51:59 itojun Exp $ */ +/* $NetBSD: spkr.c,v 1.12 2002/10/23 09:13:25 jdolecek Exp $ */ /* * Copyright (c) 1990 Eric S. Raymond (esr@snark.thyrsus.com) @@ -43,7 +43,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: spkr.c,v 1.11 2002/10/02 06:51:59 itojun Exp $"); +__KERNEL_RCSID(0, "$NetBSD: spkr.c,v 1.12 2002/10/23 09:13:25 jdolecek Exp $"); #include #include @@ -77,7 +77,7 @@ dev_type_ioctl(spkrioctl); const struct cdevsw spkr_cdevsw = { spkropen, spkrclose, noread, spkrwrite, spkrioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; static pcppi_tag_t ppicookie; diff --git a/sys/dev/isa/wt.c b/sys/dev/isa/wt.c index 38a9b443e0f7..2c1c8c977671 100644 --- a/sys/dev/isa/wt.c +++ b/sys/dev/isa/wt.c @@ -1,4 +1,4 @@ -/* $NetBSD: wt.c,v 1.58 2002/10/02 03:10:51 thorpej Exp $ */ +/* $NetBSD: wt.c,v 1.59 2002/10/23 09:13:25 jdolecek Exp $ */ /* * Streamer tape driver. @@ -51,7 +51,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: wt.c,v 1.58 2002/10/02 03:10:51 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: wt.c,v 1.59 2002/10/23 09:13:25 jdolecek Exp $"); #include #include @@ -162,7 +162,7 @@ const struct bdevsw wt_bdevsw = { const struct cdevsw wt_cdevsw = { wtopen, wtclose, wtread, wtwrite, wtioctl, - nostop, notty, nopoll, nommap, D_TAPE + nostop, notty, nopoll, nommap, nokqfilter, D_TAPE }; int wtwait __P((struct wt_softc *sc, int catch, char *msg)); diff --git a/sys/dev/kttcp.c b/sys/dev/kttcp.c index ab560f26784c..3e19659dd123 100644 --- a/sys/dev/kttcp.c +++ b/sys/dev/kttcp.c @@ -1,4 +1,4 @@ -/* $NetBSD: kttcp.c,v 1.5 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: kttcp.c,v 1.6 2002/10/23 09:13:01 jdolecek Exp $ */ /* * Copyright (c) 2002 Wasabi Systems, Inc. @@ -95,7 +95,7 @@ dev_type_ioctl(kttcpioctl); const struct cdevsw kttcp_cdevsw = { nullopen, nullclose, noread, nowrite, kttcpioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; void diff --git a/sys/dev/ld.c b/sys/dev/ld.c index d1088e625da2..c4b2ece052d8 100644 --- a/sys/dev/ld.c +++ b/sys/dev/ld.c @@ -1,4 +1,4 @@ -/* $NetBSD: ld.c,v 1.16 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: ld.c,v 1.17 2002/10/23 09:13:02 jdolecek Exp $ */ /*- * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc. @@ -41,7 +41,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ld.c,v 1.16 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ld.c,v 1.17 2002/10/23 09:13:02 jdolecek Exp $"); #include "rnd.h" @@ -93,7 +93,7 @@ const struct bdevsw ld_bdevsw = { const struct cdevsw ld_cdevsw = { ldopen, ldclose, ldread, ldwrite, ldioctl, - nostop, notty, nopoll, nommap, D_DISK + nostop, notty, nopoll, nommap, nokqfilter, D_DISK }; static struct dkdriver lddkdriver = { ldstrategy }; diff --git a/sys/dev/mca/ed_mca.c b/sys/dev/mca/ed_mca.c index 7891400b866f..1d936aea4ed5 100644 --- a/sys/dev/mca/ed_mca.c +++ b/sys/dev/mca/ed_mca.c @@ -1,4 +1,4 @@ -/* $NetBSD: ed_mca.c,v 1.17 2002/10/02 16:34:06 thorpej Exp $ */ +/* $NetBSD: ed_mca.c,v 1.18 2002/10/23 09:13:26 jdolecek Exp $ */ /* * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ed_mca.c,v 1.17 2002/10/02 16:34:06 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ed_mca.c,v 1.18 2002/10/23 09:13:26 jdolecek Exp $"); #include "rnd.h" #include "locators.h" @@ -112,7 +112,7 @@ const struct bdevsw ed_bdevsw = { const struct cdevsw ed_cdevsw = { edmcaopen, edmcaclose, edmcaread, edmcawrite, edmcaioctl, - nostop, notty, nopoll, nommap, D_DISK + nostop, notty, nopoll, nommap, nokqfilter, D_DISK }; static struct dkdriver eddkdriver = { edmcastrategy }; diff --git a/sys/dev/md.c b/sys/dev/md.c index d7895c89c2d4..110fde45245e 100644 --- a/sys/dev/md.c +++ b/sys/dev/md.c @@ -1,4 +1,4 @@ -/* $NetBSD: md.c,v 1.31 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: md.c,v 1.32 2002/10/23 09:13:03 jdolecek Exp $ */ /* * Copyright (c) 1995 Gordon W. Ross, Leo Weppelman. @@ -46,7 +46,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: md.c,v 1.31 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: md.c,v 1.32 2002/10/23 09:13:03 jdolecek Exp $"); #include "opt_md.h" @@ -109,7 +109,7 @@ const struct bdevsw md_bdevsw = { const struct cdevsw md_cdevsw = { mdopen, mdclose, mdread, mdwrite, mdioctl, - nostop, notty, nopoll, nommap, D_DISK + nostop, notty, nopoll, nommap, nokqfilter, D_DISK }; struct dkdriver mddkdriver = { mdstrategy }; diff --git a/sys/dev/midi.c b/sys/dev/midi.c index 3b639a232afb..d8a78f3378ba 100644 --- a/sys/dev/midi.c +++ b/sys/dev/midi.c @@ -1,4 +1,4 @@ -/* $NetBSD: midi.c,v 1.29 2002/10/02 16:33:30 thorpej Exp $ */ +/* $NetBSD: midi.c,v 1.30 2002/10/23 09:13:03 jdolecek Exp $ */ /* * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: midi.c,v 1.29 2002/10/02 16:33:30 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: midi.c,v 1.30 2002/10/23 09:13:03 jdolecek Exp $"); #include "midi.h" #include "sequencer.h" @@ -97,10 +97,11 @@ dev_type_read(midiread); dev_type_write(midiwrite); dev_type_ioctl(midiioctl); dev_type_poll(midipoll); +dev_type_kqfilter(midikqfilter); const struct cdevsw midi_cdevsw = { midiopen, midiclose, midiread, midiwrite, midiioctl, - nostop, notty, midipoll, nommap, + nostop, notty, midipoll, nommap, midikqfilter, }; CFATTACH_DECL(midi, sizeof(struct midi_softc), @@ -361,7 +362,7 @@ deliver: mb->used++; } midi_wakeup(&sc->rchan); - selwakeup(&sc->rsel); + selnotify(&sc->rsel, 0); if (sc->async) psignal(sc->async, SIGIO); } @@ -559,7 +560,7 @@ midi_start_output(struct midi_softc *sc, int intr) break; } midi_wakeup(&sc->wchan); - selwakeup(&sc->wsel); + selnotify(&sc->wsel, 0); if (sc->async) psignal(sc->async, SIGIO); if (!(sc->props & MIDI_PROP_OUT_INTR) || error==EINPROGRESS) { @@ -769,6 +770,88 @@ midipoll(dev_t dev, int events, struct proc *p) return revents; } +static void +filt_midirdetach(struct knote *kn) +{ + struct midi_softc *sc = kn->kn_hook; + int s; + + s = splaudio(); + SLIST_REMOVE(&sc->rsel.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_midiread(struct knote *kn, long hint) +{ + struct midi_softc *sc = kn->kn_hook; + + /* XXXLUKEM (thorpej): please make sure this is correct. */ + + kn->kn_data = sc->inbuf.used; + return (kn->kn_data > 0); +} + +static const struct filterops midiread_filtops = + { 1, NULL, filt_midirdetach, filt_midiread }; + +static void +filt_midiwdetach(struct knote *kn) +{ + struct midi_softc *sc = kn->kn_hook; + int s; + + s = splaudio(); + SLIST_REMOVE(&sc->wsel.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_midiwrite(struct knote *kn, long hint) +{ + struct midi_softc *sc = kn->kn_hook; + + /* XXXLUKEM (thorpej): please make sure this is correct. */ + + kn->kn_data = sc->outbuf.usedhigh - sc->outbuf.used; + return (kn->kn_data > 0); +} + +static const struct filterops midiwrite_filtops = + { 1, NULL, filt_midiwdetach, filt_midiwrite }; + +int +midikqfilter(dev_t dev, struct knote *kn) +{ + int unit = MIDIUNIT(dev); + struct midi_softc *sc = midi_cd.cd_devs[unit]; + struct klist *klist; + int s; + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &sc->rsel.si_klist; + kn->kn_fop = &midiread_filtops; + break; + + case EVFILT_WRITE: + klist = &sc->wsel.si_klist; + kn->kn_fop = &midiwrite_filtops; + break; + + default: + return (1); + } + + kn->kn_hook = sc; + + s = splaudio(); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + splx(s); + + return (0); +} + void midi_getinfo(dev_t dev, struct midi_info *mi) { diff --git a/sys/dev/mscp/mscp_disk.c b/sys/dev/mscp/mscp_disk.c index 18a9bc4f206d..5804fdba849f 100644 --- a/sys/dev/mscp/mscp_disk.c +++ b/sys/dev/mscp/mscp_disk.c @@ -1,4 +1,4 @@ -/* $NetBSD: mscp_disk.c,v 1.36 2002/10/02 16:34:23 thorpej Exp $ */ +/* $NetBSD: mscp_disk.c,v 1.37 2002/10/23 09:13:27 jdolecek Exp $ */ /* * Copyright (c) 1996 Ludd, University of Lule}, Sweden. * Copyright (c) 1988 Regents of the University of California. @@ -49,7 +49,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: mscp_disk.c,v 1.36 2002/10/02 16:34:23 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mscp_disk.c,v 1.37 2002/10/23 09:13:27 jdolecek Exp $"); #include #include @@ -121,7 +121,7 @@ const struct bdevsw ra_bdevsw = { const struct cdevsw ra_cdevsw = { raopen, raclose, raread, rawrite, raioctl, - nostop, notty, nopoll, nommap, D_DISK + nostop, notty, nopoll, nommap, nokqfilter, D_DISK }; /* @@ -537,7 +537,7 @@ const struct bdevsw rx_bdevsw = { const struct cdevsw rx_cdevsw = { rxopen, nullclose, rxread, rxwrite, rxioctl, - nostop, notty, nopoll, nommap, D_DISK + nostop, notty, nopoll, nommap, nokqfilter, D_DISK }; /* diff --git a/sys/dev/mscp/mscp_tape.c b/sys/dev/mscp/mscp_tape.c index 8cb99acaf0dd..a84a945acd49 100644 --- a/sys/dev/mscp/mscp_tape.c +++ b/sys/dev/mscp/mscp_tape.c @@ -1,4 +1,4 @@ -/* $NetBSD: mscp_tape.c,v 1.20 2002/10/02 16:34:25 thorpej Exp $ */ +/* $NetBSD: mscp_tape.c,v 1.21 2002/10/23 09:13:28 jdolecek Exp $ */ /* * Copyright (c) 1996 Ludd, University of Lule}, Sweden. * All rights reserved. @@ -41,7 +41,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: mscp_tape.c,v 1.20 2002/10/02 16:34:25 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mscp_tape.c,v 1.21 2002/10/23 09:13:28 jdolecek Exp $"); #include #include @@ -128,7 +128,7 @@ const struct bdevsw mt_bdevsw = { const struct cdevsw mt_cdevsw = { mtopen, mtclose, mtread, mtwrite, mtioctl, - nostop, notty, nopoll, nommap, D_TAPE + nostop, notty, nopoll, nommap, nokqfilter, D_TAPE }; /* diff --git a/sys/dev/mvme/lpt_mvme.c b/sys/dev/mvme/lpt_mvme.c index cfdbe9268417..27f4b4a14462 100644 --- a/sys/dev/mvme/lpt_mvme.c +++ b/sys/dev/mvme/lpt_mvme.c @@ -1,4 +1,4 @@ -/* $NetBSD: lpt_mvme.c,v 1.2 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: lpt_mvme.c,v 1.3 2002/10/23 09:13:28 jdolecek Exp $ */ /*- * Copyright (c) 1999, 2002 The NetBSD Foundation, Inc. @@ -136,7 +136,7 @@ dev_type_ioctl(lptioctl); const struct cdevsw lpt_cdevsw = { lptopen, lptclose, noread, lptwrite, lptioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; void diff --git a/sys/dev/ofw/ofcons.c b/sys/dev/ofw/ofcons.c index ff16c8128fb9..847e49db3d57 100644 --- a/sys/dev/ofw/ofcons.c +++ b/sys/dev/ofw/ofcons.c @@ -1,4 +1,4 @@ -/* $NetBSD: ofcons.c,v 1.20 2002/10/02 16:34:33 thorpej Exp $ */ +/* $NetBSD: ofcons.c,v 1.21 2002/10/23 09:13:29 jdolecek Exp $ */ /* * Copyright (C) 1995, 1996 Wolfgang Solfrank. @@ -32,7 +32,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ofcons.c,v 1.20 2002/10/02 16:34:33 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ofcons.c,v 1.21 2002/10/23 09:13:29 jdolecek Exp $"); #include #include @@ -79,7 +79,7 @@ dev_type_poll(ofcons_poll); const struct cdevsw ofcons_cdevsw = { ofcons_open, ofcons_close, ofcons_read, ofcons_write, ofcons_ioctl, - nostop, ofcons_tty, ofcons_poll, nommap, D_TTY + nostop, ofcons_tty, ofcons_poll, nommap, ttykqfilter, D_TTY }; static int ofcons_probe __P((void)); diff --git a/sys/dev/ofw/ofdisk.c b/sys/dev/ofw/ofdisk.c index ad7efddd9def..4c6485090628 100644 --- a/sys/dev/ofw/ofdisk.c +++ b/sys/dev/ofw/ofdisk.c @@ -1,4 +1,4 @@ -/* $NetBSD: ofdisk.c,v 1.23 2002/10/02 16:34:33 thorpej Exp $ */ +/* $NetBSD: ofdisk.c,v 1.24 2002/10/23 09:13:29 jdolecek Exp $ */ /* * Copyright (C) 1995, 1996 Wolfgang Solfrank. @@ -32,7 +32,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ofdisk.c,v 1.23 2002/10/02 16:34:33 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ofdisk.c,v 1.24 2002/10/23 09:13:29 jdolecek Exp $"); #include #include @@ -87,7 +87,7 @@ const struct bdevsw ofdisk_bdevsw = { const struct cdevsw ofdisk_cdevsw = { ofdisk_open, ofdisk_close, ofdisk_read, ofdisk_write, ofdisk_ioctl, - nostop, notty, nopoll, nommap, D_DISK + nostop, notty, nopoll, nommap, nokqfilter, D_DISK }; struct dkdriver ofdisk_dkdriver = { ofdisk_strategy }; diff --git a/sys/dev/ofw/ofrtc.c b/sys/dev/ofw/ofrtc.c index cef7a74312b9..1161a8cab10b 100644 --- a/sys/dev/ofw/ofrtc.c +++ b/sys/dev/ofw/ofrtc.c @@ -1,4 +1,4 @@ -/* $NetBSD: ofrtc.c,v 1.14 2002/10/02 16:34:34 thorpej Exp $ */ +/* $NetBSD: ofrtc.c,v 1.15 2002/10/23 09:13:30 jdolecek Exp $ */ /* * Copyright (C) 1996 Wolfgang Solfrank. @@ -32,12 +32,13 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ofrtc.c,v 1.14 2002/10/02 16:34:34 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ofrtc.c,v 1.15 2002/10/23 09:13:30 jdolecek Exp $"); #include #include #include #include +#include #include @@ -61,7 +62,7 @@ dev_type_write(ofrtc_write); const struct cdevsw ofrtc_cdevsw = { ofrtc_open, nullclose, ofrtc_read, ofrtc_write, noioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; static int diff --git a/sys/dev/ofw/openfirmio.c b/sys/dev/ofw/openfirmio.c index 53430b81c901..6d2a651b268a 100644 --- a/sys/dev/ofw/openfirmio.c +++ b/sys/dev/ofw/openfirmio.c @@ -1,4 +1,4 @@ -/* $NetBSD: openfirmio.c,v 1.4 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: openfirmio.c,v 1.5 2002/10/23 09:13:30 jdolecek Exp $ */ /* * Copyright (c) 1992, 1993 @@ -45,7 +45,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: openfirmio.c,v 1.4 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: openfirmio.c,v 1.5 2002/10/23 09:13:30 jdolecek Exp $"); #include #include @@ -55,6 +55,7 @@ __KERNEL_RCSID(0, "$NetBSD: openfirmio.c,v 1.4 2002/09/06 13:18:43 gehenna Exp $ #include #include #include +#include #include #include @@ -70,7 +71,7 @@ dev_type_ioctl(openfirmioctl); const struct cdevsw openfirm_cdevsw = { nullopen, nullclose, noread, nowrite, openfirmioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; void diff --git a/sys/dev/pci/agp.c b/sys/dev/pci/agp.c index db0386efba52..296b6806fac1 100644 --- a/sys/dev/pci/agp.c +++ b/sys/dev/pci/agp.c @@ -1,4 +1,4 @@ -/* $NetBSD: agp.c,v 1.21 2002/10/02 16:51:00 thorpej Exp $ */ +/* $NetBSD: agp.c,v 1.22 2002/10/23 09:13:31 jdolecek Exp $ */ /*- * Copyright (c) 2000 Doug Rabson @@ -65,7 +65,7 @@ #include -__KERNEL_RCSID(0, "$NetBSD: agp.c,v 1.21 2002/10/02 16:51:00 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: agp.c,v 1.22 2002/10/23 09:13:31 jdolecek Exp $"); #include #include @@ -100,7 +100,7 @@ dev_type_mmap(agpmmap); const struct cdevsw agp_cdevsw = { agpopen, agpclose, noread, nowrite, agpioctl, - nostop, notty, nopoll, agpmmap, + nostop, notty, nopoll, agpmmap, nokqfilter, }; int agpmatch(struct device *, struct cfdata *, void *); diff --git a/sys/dev/pci/bktr/bktr_os.c b/sys/dev/pci/bktr/bktr_os.c index f5e4fa2e06d8..b1c89597e4bc 100644 --- a/sys/dev/pci/bktr/bktr_os.c +++ b/sys/dev/pci/bktr/bktr_os.c @@ -1,4 +1,4 @@ -/* $NetBSD: bktr_os.c,v 1.32 2002/10/02 16:52:02 thorpej Exp $ */ +/* $NetBSD: bktr_os.c,v 1.33 2002/10/23 09:13:34 jdolecek Exp $ */ /* FreeBSD: src/sys/dev/bktr/bktr_os.c,v 1.20 2000/10/20 08:16:53 roger Exp */ @@ -50,7 +50,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: bktr_os.c,v 1.32 2002/10/02 16:52:02 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: bktr_os.c,v 1.33 2002/10/23 09:13:34 jdolecek Exp $"); #ifdef __FreeBSD__ #include "bktr.h" @@ -180,7 +180,7 @@ dev_type_mmap(bktr_mmap); const struct cdevsw bktr_cdevsw = { bktr_open, bktr_close, bktr_read, bktr_write, bktr_ioctl, - nostop, notty, nopoll, bktr_mmap, + nostop, notty, nopoll, bktr_mmap, nokqfilter, }; #endif /* __NetBSD __ */ diff --git a/sys/dev/pci/cz.c b/sys/dev/pci/cz.c index fe38c022a521..82dae45deeda 100644 --- a/sys/dev/pci/cz.c +++ b/sys/dev/pci/cz.c @@ -1,4 +1,4 @@ -/* $NetBSD: cz.c,v 1.23 2002/10/02 16:51:08 thorpej Exp $ */ +/* $NetBSD: cz.c,v 1.24 2002/10/23 09:13:31 jdolecek Exp $ */ /*- * Copyright (c) 2000 Zembu Labs, Inc. @@ -73,7 +73,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cz.c,v 1.23 2002/10/02 16:51:08 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cz.c,v 1.24 2002/10/23 09:13:31 jdolecek Exp $"); #include #include @@ -206,7 +206,7 @@ dev_type_poll(czttypoll); const struct cdevsw cz_cdevsw = { czttyopen, czttyclose, czttyread, czttywrite, czttyioctl, - czttystop, czttytty, czttypoll, nommap, D_TTY + czttystop, czttytty, czttypoll, nommap, ttykqfilter, D_TTY }; /* Macros to clear/set/test flags. */ diff --git a/sys/dev/pci/mly.c b/sys/dev/pci/mly.c index bbf959b205a7..b1f0898220c3 100644 --- a/sys/dev/pci/mly.c +++ b/sys/dev/pci/mly.c @@ -1,4 +1,4 @@ -/* $NetBSD: mly.c,v 1.14 2002/10/02 16:51:44 thorpej Exp $ */ +/* $NetBSD: mly.c,v 1.15 2002/10/23 09:13:32 jdolecek Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -77,7 +77,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: mly.c,v 1.14 2002/10/02 16:51:44 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mly.c,v 1.15 2002/10/23 09:13:32 jdolecek Exp $"); #include #include @@ -172,7 +172,7 @@ dev_type_ioctl(mlyioctl); const struct cdevsw mly_cdevsw = { mlyopen, mlyclose, noread, nowrite, mlyioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; struct mly_ident { diff --git a/sys/dev/pci/oboe.c b/sys/dev/pci/oboe.c index 376472c2e154..387d171447fd 100644 --- a/sys/dev/pci/oboe.c +++ b/sys/dev/pci/oboe.c @@ -1,4 +1,4 @@ -/* $NetBSD: oboe.c,v 1.8 2002/10/02 16:51:47 thorpej Exp $ */ +/* $NetBSD: oboe.c,v 1.9 2002/10/23 09:13:33 jdolecek Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -78,6 +78,7 @@ int oboe_set_params(void *h, struct irda_params *params); int oboe_get_speeds(void *h, int *speeds); int oboe_get_turnarounds(void *h, int *times); int oboe_poll(void *h, int events, struct proc *p); +int oboe_kqfilter(void *h, struct knote *kn); #ifdef OBOE_DEBUG #define DPRINTF(x) if (oboedebug) printf x @@ -99,6 +100,7 @@ struct oboe_softc { bus_space_handle_t sc_ioh; bus_dma_tag_t sc_dmatag; struct selinfo sc_rsel; + struct selinfo sc_wsel; int sc_state; #define OBOE_RSLP 0x01 /* waiting for data (read) */ @@ -155,8 +157,8 @@ CFATTACH_DECL(oboe, sizeof(struct oboe_softc), oboe_match, oboe_attach, oboe_detach, oboe_activate); struct irframe_methods oboe_methods = { - oboe_open, oboe_close, oboe_read, oboe_write, oboe_poll, - oboe_set_params, oboe_get_speeds, oboe_get_turnarounds + oboe_open, oboe_close, oboe_read, oboe_write, oboe_poll, + oboe_kqfilter, oboe_set_params, oboe_get_speeds, oboe_get_turnarounds }; int @@ -478,6 +480,70 @@ oboe_poll(void *h, int events, struct proc *p) return (revents); } +static void +filt_oboerdetach(struct knote *kn) +{ + struct oboe_softc *sc = kn->kn_hook; + int s; + + s = splir(); + SLIST_REMOVE(&sc->sc_rsel.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_oboeread(struct knote *kn, long hint) +{ + struct oboe_softc *sc = kn->kn_hook; + + kn->kn_data = sc->sc_saved; + return (kn->kn_data > 0); +} + +static void +filt_oboewdetach(struct knote *kn) +{ + struct oboe_softc *sc = kn->kn_hook; + int s; + + s = splir(); + SLIST_REMOVE(&sc->sc_wsel.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static const struct filterops oboeread_filtops = + { 1, NULL, filt_oboerdetach, filt_oboeread }; +static const struct filterops oboewrite_filtops = + { 1, NULL, filt_oboewdetach, filt_seltrue }; + +int +oboe_kqfilter(void *h, struct knote *kn) +{ + struct oboe_softc *sc = h; + struct klist *klist; + int s; + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &sc->sc_rsel.si_klist; + kn->kn_fop = &oboeread_filtops; + break; + case EVFILT_WRITE: + klist = &sc->sc_wsel.si_klist; + kn->kn_fop = &oboewrite_filtops; + break; + default: + return (1); + } + + kn->kn_hook = sc; + + s = splir(); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + splx(s); + + return (0); +} static int oboe_reset(struct oboe_softc *sc) @@ -536,7 +602,7 @@ oboe_intr(void *p) DPRINTF(("oboe_intr: waking up reader\n")); wakeup(&sc->sc_rxs); } - selwakeup(&sc->sc_rsel); + selnotify(&sc->sc_rsel, 0); DPRINTF(("oboe_intr returning\n")); } if (irqstat & OBOE_ISR_TXDONE) { @@ -555,6 +621,7 @@ oboe_intr(void *p) DPRINTF(("oboe_intr: waking up writer\n")); wakeup(&sc->sc_txs); } + selnotify(&sc->sc_wsel, 0); } return (1); } diff --git a/sys/dev/pci/pci_usrreq.c b/sys/dev/pci/pci_usrreq.c index c859275ea986..702c913639f6 100644 --- a/sys/dev/pci/pci_usrreq.c +++ b/sys/dev/pci/pci_usrreq.c @@ -1,4 +1,4 @@ -/* $NetBSD: pci_usrreq.c,v 1.5 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: pci_usrreq.c,v 1.6 2002/10/23 09:13:33 jdolecek Exp $ */ /* * Copyright 2001 Wasabi Systems, Inc. @@ -40,7 +40,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pci_usrreq.c,v 1.5 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pci_usrreq.c,v 1.6 2002/10/23 09:13:33 jdolecek Exp $"); #include #include @@ -61,7 +61,7 @@ dev_type_mmap(pcimmap); const struct cdevsw pci_cdevsw = { pciopen, nullclose, noread, nowrite, pciioctl, - nostop, notty, nopoll, pcimmap, + nostop, notty, nopoll, pcimmap, nokqfilter, }; int diff --git a/sys/dev/qbus/dhu.c b/sys/dev/qbus/dhu.c index 21c98c423889..5420fee20bc2 100644 --- a/sys/dev/qbus/dhu.c +++ b/sys/dev/qbus/dhu.c @@ -1,4 +1,4 @@ -/* $NetBSD: dhu.c,v 1.31 2002/10/02 16:52:25 thorpej Exp $ */ +/* $NetBSD: dhu.c,v 1.32 2002/10/23 09:13:35 jdolecek Exp $ */ /* * Copyright (c) 1996 Ken C. Wellsch. All rights reserved. * Copyright (c) 1992, 1993 @@ -37,7 +37,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: dhu.c,v 1.31 2002/10/02 16:52:25 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dhu.c,v 1.32 2002/10/23 09:13:35 jdolecek Exp $"); #include #include @@ -161,7 +161,7 @@ dev_type_poll(dhupoll); const struct cdevsw dhu_cdevsw = { dhuopen, dhuclose, dhuread, dhuwrite, dhuioctl, - dhustop, dhutty, dhupoll, nommap, D_TTY + dhustop, dhutty, dhupoll, nommap, ttykqfilter, D_TTY }; /* Autoconfig handles: setup the controller to interrupt, */ diff --git a/sys/dev/qbus/dl.c b/sys/dev/qbus/dl.c index 5221a80cca40..3bd81afc7548 100644 --- a/sys/dev/qbus/dl.c +++ b/sys/dev/qbus/dl.c @@ -1,4 +1,4 @@ -/* $NetBSD: dl.c,v 1.25 2002/10/02 16:52:25 thorpej Exp $ */ +/* $NetBSD: dl.c,v 1.26 2002/10/23 09:13:36 jdolecek Exp $ */ /*- * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. @@ -81,7 +81,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: dl.c,v 1.25 2002/10/02 16:52:25 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dl.c,v 1.26 2002/10/23 09:13:36 jdolecek Exp $"); #include #include @@ -135,7 +135,7 @@ dev_type_poll(dlpoll); const struct cdevsw dl_cdevsw = { dlopen, dlclose, dlread, dlwrite, dlioctl, - dlstop, dltty, dlpoll, nommap, D_TTY + dlstop, dltty, dlpoll, nommap, ttykqfilter, D_TTY }; #define DL_READ_WORD(reg) \ diff --git a/sys/dev/qbus/qd.c b/sys/dev/qbus/qd.c index 34709cdf0871..10550bb91eb0 100644 --- a/sys/dev/qbus/qd.c +++ b/sys/dev/qbus/qd.c @@ -1,4 +1,4 @@ -/* $NetBSD: qd.c,v 1.28 2002/10/02 16:52:29 thorpej Exp $ */ +/* $NetBSD: qd.c,v 1.29 2002/10/23 09:13:36 jdolecek Exp $ */ /*- * Copyright (c) 1988 Regents of the University of California. @@ -62,7 +62,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: qd.c,v 1.28 2002/10/02 16:52:29 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: qd.c,v 1.29 2002/10/23 09:13:36 jdolecek Exp $"); #include "opt_ddb.h" @@ -141,12 +141,6 @@ struct qd_softc { #define MAPSCR 0x08 /* scroll param area mapped */ #define MAPCOLOR 0x10 /* color map writing buffer mapped */ -/* - * bit definitions for 'selmask' member of qdflag structure - */ -#define SEL_READ 0x01 /* read select is active */ -#define SEL_WRITE 0x02 /* write select is active */ - /* * constants used in shared memory operations */ @@ -355,10 +349,11 @@ dev_type_write(qdwrite); dev_type_ioctl(qdioctl); dev_type_stop(qdstop); dev_type_poll(qdpoll); +dev_type_kqfilter(qdkqfilter); const struct cdevsw qd_cdevsw = { qdopen, qdclose, qdread, qdwrite, qdioctl, - qdstop, notty, qdpoll, nommap, + qdstop, notty, qdpoll, nommap, qdkqfilter, }; /* @@ -1543,15 +1538,11 @@ qdpoll(dev, events, p) revents |= events & (POLLOUT | POLLWRNORM); if (revents == 0) { - if (events & (POLLIN | POLLRDNORM)) { + if (events & (POLLIN | POLLRDNORM)) selrecord(p, &qdrsel[unit]); - qdflags[unit].selmask |= SEL_READ; - } - if (events & (POLLOUT | POLLWRNORM)) { + if (events & (POLLOUT | POLLWRNORM)) selrecord(p, &qdrsel[unit]); - qdflags[unit].selmask |= SEL_WRITE; - } } } else { /* @@ -1565,6 +1556,88 @@ qdpoll(dev, events, p) return (revents); } /* qdpoll() */ +static void +filt_qdrdetach(struct knote *kn) +{ + dev_t dev = (intptr_t) kn->kn_hook; + u_int minor_dev = minor(dev); + int unit = minor_dev >> 2; + int s; + + s = spl5(); + SLIST_REMOVE(&qdrsel[unit].si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_qdread(struct knote *kn, long hint) +{ + dev_t dev = (intptr_t) kn->kn_hook; + u_int minor_dev = minor(dev); + int unit = minor_dev >> 2; + + if (ISEMPTY(eq_header[unit])) + return (0); + + kn->kn_data = 0; /* XXXLUKEM (thorpej): what to put here? */ + return (1); +} + +static int +filt_qdwrite(struct knote *kn, long hint) +{ + dev_t dev = (intptr_t) kn->kn_hook; + u_int minor_dev = minor(dev); + int unit = minor_dev >> 2; + + if (! DMA_ISEMPTY(DMAheader[unit])) + return (0); + + kn->kn_data = 0; /* XXXLUKEM (thorpej): what to put here? */ + return (1); +} + +static const struct filterops qdread_filtops = + { 1, NULL, filt_qdrdetach, filt_qdread }; + +static const struct filterops qdwrite_filtops = + { 1, NULL, filt_qdrdetach, filt_qdwrite }; + +int +qdkqfilter(dev_t dev, struct knote *kn) +{ + struct klist *klist; + u_int minor_dev = minor(dev); + int s, unit = minor_dev >> 2; + + if ((minor_dev & 0x03) != 2) { + /* TTY device. */ + return (ttykqfilter(dev, kn)); + } + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &qdrsel[unit].si_klist; + kn->kn_fop = &qdread_filtops; + break; + + case EVFILT_WRITE: + klist = &qdrsel[unit].si_klist; + kn->kn_fop = &qdwrite_filtops; + break; + + default: + return (1); + } + + kn->kn_hook = (void *)(intptr_t) dev; + + s = spl5(); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + splx(s); + + return (0); +} void qd_strategy(struct buf *bp); @@ -2051,11 +2124,7 @@ qddint(arg) header->newest = header->oldest; header->used = 0; - if (qdrsel[dv->dv_unit].si_pid && qdflags[dv->dv_unit].selmask & SEL_WRITE) { - selwakeup(&qdrsel[dv->dv_unit]); - qdrsel[dv->dv_unit].si_pid = 0; - qdflags[dv->dv_unit].selmask &= ~SEL_WRITE; - } + selnotify(&qdrsel[dv->dv_unit], 0); if (dga->bytcnt_lo != 0) { dga->bytcnt_lo = 0; @@ -2070,11 +2139,7 @@ qddint(arg) * wakeup "select" client. */ if (DMA_ISFULL(header)) { - if (qdrsel[dv->dv_unit].si_pid && qdflags[dv->dv_unit].selmask & SEL_WRITE) { - selwakeup(&qdrsel[dv->dv_unit]); - qdrsel[dv->dv_unit].si_pid = 0; - qdflags[dv->dv_unit].selmask &= ~SEL_WRITE; - } + selnotify(&qdrsel[dv->dv_unit], 0); } header->DMAreq[header->oldest].DMAdone |= REQUEST_DONE; @@ -2090,11 +2155,7 @@ qddint(arg) * if no more DMA pending, wake up "select" client and exit */ if (DMA_ISEMPTY(header)) { - if (qdrsel[dv->dv_unit].si_pid && qdflags[dv->dv_unit].selmask & SEL_WRITE) { - selwakeup(&qdrsel[dv->dv_unit]); - qdrsel[dv->dv_unit].si_pid = 0; - qdflags[dv->dv_unit].selmask &= ~SEL_WRITE; - } + selnotify(&qdrsel[dv->dv_unit], 0); DMA_CLRACTIVE(header); /* flag DMA done */ return; } @@ -2723,10 +2784,8 @@ GET_TBUTTON: /* * do select wakeup */ - if (qdrsel[dv->dv_unit].si_pid && do_wakeup && qdflags[dv->dv_unit].selmask & SEL_READ) { - selwakeup(&qdrsel[dv->dv_unit]); - qdrsel[dv->dv_unit].si_pid = 0; - qdflags[dv->dv_unit].selmask &= ~SEL_READ; + if (do_wakeup) { + selnotify(&qdrsel[dv->dv_unit], 0); do_wakeup = 0; } } else { diff --git a/sys/dev/qbus/rl.c b/sys/dev/qbus/rl.c index a2b15ff40b40..2f7a276190b7 100644 --- a/sys/dev/qbus/rl.c +++ b/sys/dev/qbus/rl.c @@ -1,4 +1,4 @@ -/* $NetBSD: rl.c,v 1.16 2002/10/02 16:52:30 thorpej Exp $ */ +/* $NetBSD: rl.c,v 1.17 2002/10/23 09:13:37 jdolecek Exp $ */ /* * Copyright (c) 2000 Ludd, University of Lule}, Sweden. All rights reserved. @@ -43,7 +43,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: rl.c,v 1.16 2002/10/02 16:52:30 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rl.c,v 1.17 2002/10/23 09:13:37 jdolecek Exp $"); #include #include @@ -55,6 +55,7 @@ __KERNEL_RCSID(0, "$NetBSD: rl.c,v 1.16 2002/10/02 16:52:30 thorpej Exp $"); #include #include #include +#include #include #include @@ -99,7 +100,7 @@ const struct bdevsw rl_bdevsw = { const struct cdevsw rl_cdevsw = { rlopen, rlclose, rlread, rlwrite, rlioctl, - nostop, notty, nopoll, nommap, D_DISK + nostop, notty, nopoll, nommap, nokqfilter, D_DISK }; #define MAXRLXFER (RL_BPS * RL_SPT) diff --git a/sys/dev/qbus/ts.c b/sys/dev/qbus/ts.c index ed034c209a45..0fa222706260 100644 --- a/sys/dev/qbus/ts.c +++ b/sys/dev/qbus/ts.c @@ -1,4 +1,4 @@ -/* $NetBSD: ts.c,v 1.9 2002/10/02 16:52:30 thorpej Exp $ */ +/* $NetBSD: ts.c,v 1.10 2002/10/23 09:13:38 jdolecek Exp $ */ /*- * Copyright (c) 1991 The Regents of the University of California. @@ -70,7 +70,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ts.c,v 1.9 2002/10/02 16:52:30 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ts.c,v 1.10 2002/10/23 09:13:38 jdolecek Exp $"); #undef TSDEBUG @@ -185,7 +185,7 @@ const struct bdevsw ts_bdevsw = { const struct cdevsw ts_cdevsw = { tsopen, tsclose, tsread, tswrite, tsioctl, - nostop, notty, nopoll, nommap, D_TAPE + nostop, notty, nopoll, nommap, nokqfilter, D_TAPE }; /* Bits in minor device */ diff --git a/sys/dev/radio.c b/sys/dev/radio.c index ae1fe53031f4..4b969042f5d8 100644 --- a/sys/dev/radio.c +++ b/sys/dev/radio.c @@ -1,4 +1,4 @@ -/* $NetBSD: radio.c,v 1.7 2002/10/02 16:33:30 thorpej Exp $ */ +/* $NetBSD: radio.c,v 1.8 2002/10/23 09:13:04 jdolecek Exp $ */ /* $OpenBSD: radio.c,v 1.2 2001/12/05 10:27:06 mickey Exp $ */ /* $RuOBSD: radio.c,v 1.7 2001/12/04 06:03:05 tm Exp $ */ @@ -30,7 +30,7 @@ /* This is the /dev/radio driver from OpenBSD */ #include -__KERNEL_RCSID(0, "$NetBSD: radio.c,v 1.7 2002/10/02 16:33:30 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: radio.c,v 1.8 2002/10/23 09:13:04 jdolecek Exp $"); #include #include @@ -60,7 +60,7 @@ dev_type_ioctl(radioioctl); const struct cdevsw radio_cdevsw = { radioopen, radioclose, noread, nowrite, radioioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; extern struct cfdriver radio_cd; diff --git a/sys/dev/raidframe/rf_netbsdkintf.c b/sys/dev/raidframe/rf_netbsdkintf.c index b713566eb4d6..ca6ee6cd7836 100644 --- a/sys/dev/raidframe/rf_netbsdkintf.c +++ b/sys/dev/raidframe/rf_netbsdkintf.c @@ -1,4 +1,4 @@ -/* $NetBSD: rf_netbsdkintf.c,v 1.143 2002/10/04 20:05:14 oster Exp $ */ +/* $NetBSD: rf_netbsdkintf.c,v 1.144 2002/10/23 09:13:40 jdolecek Exp $ */ /*- * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc. * All rights reserved. @@ -114,7 +114,7 @@ ***********************************************************/ #include -__KERNEL_RCSID(0, "$NetBSD: rf_netbsdkintf.c,v 1.143 2002/10/04 20:05:14 oster Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rf_netbsdkintf.c,v 1.144 2002/10/23 09:13:40 jdolecek Exp $"); #include #include @@ -196,7 +196,7 @@ const struct bdevsw raid_bdevsw = { const struct cdevsw raid_cdevsw = { raidopen, raidclose, raidread, raidwrite, raidioctl, - nostop, notty, nopoll, nommap, D_DISK + nostop, notty, nopoll, nommap, nokqfilter, D_DISK }; /* diff --git a/sys/dev/rnd.c b/sys/dev/rnd.c index 074e9d76a413..fbcc3dc026f5 100644 --- a/sys/dev/rnd.c +++ b/sys/dev/rnd.c @@ -1,4 +1,4 @@ -/* $NetBSD: rnd.c,v 1.35 2002/10/09 14:48:58 dan Exp $ */ +/* $NetBSD: rnd.c,v 1.36 2002/10/23 09:13:04 jdolecek Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: rnd.c,v 1.35 2002/10/09 14:48:58 dan Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rnd.c,v 1.36 2002/10/23 09:13:04 jdolecek Exp $"); #include #include @@ -161,10 +161,11 @@ dev_type_read(rndread); dev_type_write(rndwrite); dev_type_ioctl(rndioctl); dev_type_poll(rndpoll); +dev_type_kqfilter(rndkqfilter); const struct cdevsw rnd_cdevsw = { rndopen, nullclose, rndread, rndwrite, rndioctl, - nostop, notty, rndpoll, nommap, + nostop, notty, rndpoll, nommap, rndkqfilter, }; static inline void rnd_wakeup_readers(void); @@ -218,7 +219,7 @@ rnd_wakeup_readers(void) rnd_status &= ~RND_READWAITING; wakeup(&rnd_selq); } - selwakeup(&rnd_selq); + selnotify(&rnd_selq, 0); #ifdef RND_VERBOSE if (!rnd_have_entropy) @@ -706,6 +707,68 @@ rndpoll(dev_t dev, int events, struct proc *p) return (revents); } +static void +filt_rnddetach(struct knote *kn) +{ + int s; + + s = splsoftclock(); + SLIST_REMOVE(&rnd_selq.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_rndread(struct knote *kn, long hint) +{ + uint32_t entcnt; + + entcnt = rndpool_get_entropy_count(&rnd_pool); + if (entcnt >= RND_ENTROPY_THRESHOLD * 8) { + kn->kn_data = RND_TEMP_BUFFER_SIZE; + return (1); + } + return (0); +} + +static const struct filterops rnd_seltrue_filtops = + { 1, NULL, filt_rnddetach, filt_seltrue }; + +static const struct filterops rndread_filtops = + { 1, NULL, filt_rnddetach, filt_rndread }; + +int +rndkqfilter(dev_t dev, struct knote *kn) +{ + struct klist *klist; + int s; + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &rnd_selq.si_klist; + if (minor(dev) == RND_DEV_URANDOM) + kn->kn_fop = &rnd_seltrue_filtops; + else + kn->kn_fop = &rndread_filtops; + break; + + case EVFILT_WRITE: + klist = &rnd_selq.si_klist; + kn->kn_fop = &rnd_seltrue_filtops; + break; + + default: + return (1); + } + + kn->kn_hook = NULL; + + s = splsoftclock(); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + splx(s); + + return (0); +} + static rnd_sample_t * rnd_sample_allocate(rndsource_t *source) { diff --git a/sys/dev/sbus/bpp.c b/sys/dev/sbus/bpp.c index 0d99aea18ad7..1db2089b2e16 100644 --- a/sys/dev/sbus/bpp.c +++ b/sys/dev/sbus/bpp.c @@ -1,4 +1,4 @@ -/* $NetBSD: bpp.c,v 1.16 2002/10/02 16:52:32 thorpej Exp $ */ +/* $NetBSD: bpp.c,v 1.17 2002/10/23 09:13:42 jdolecek Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: bpp.c,v 1.16 2002/10/02 16:52:32 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: bpp.c,v 1.17 2002/10/23 09:13:42 jdolecek Exp $"); #include #include @@ -129,10 +129,11 @@ dev_type_close(bppclose); dev_type_write(bppwrite); dev_type_ioctl(bppioctl); dev_type_poll(bpppoll); +dev_type_kqfilter(bppkqfilter); const struct cdevsw bpp_cdevsw = { bppopen, bppclose, noread, bppwrite, bppioctl, - nostop, notty, bpppoll, nommap, + nostop, notty, bpppoll, nommap, bppkqfilter, }; #define BPPUNIT(dev) (minor(dev)) @@ -503,6 +504,84 @@ bpppoll(dev, events, p) return (revents); } +static void +filt_bpprdetach(struct knote *kn) +{ + struct bpp_softc *sc = kn->kn_hook; + int s; + + s = splbpp(); + SLIST_REMOVE(&sc->sc_rsel.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_bppread(struct knote *kn, long hint) +{ + /* XXX Read not yet implemented. */ + return (0); +} + +static const struct filterops bppread_filtops = + { 1, NULL, filt_bpprdetach, filt_bppread }; + +static void +filt_bppwdetach(struct knote *kn) +{ + struct bpp_softc *sc = kn->kn_hook; + int s; + + s = splbpp(); + SLIST_REMOVE(&sc->sc_wsel.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_bpfwrite(struct knote *kn, long hint) +{ + struct bpp_softc *sc = kn->kn_hook; + + if (sc->sc_flags & BPP_LOCKED) + return (0); + + kn->kn_data = 0; /* XXXLUKEM (thorpej): what to put here? */ + return (1); +} + +static const struct filterops bppwrite_filtops = + { 1, NULL, filt_bppwdetach, filt_bpfwrite }; + +int +bppkqfilter(dev_t dev, struct knote *kn) +{ + struct bpp_softc *sc = bpp_cd.cd_devs[BPPUNIT(dev)]; + struct klist *klist; + int s; + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &sc->sc_rsel.si_klist; + kn->kn_fop = &bppread_filtops; + break; + + case EVFILT_WRITE: + klist = &sc->sc_wsel.si_klist; + kn->kn_fop = &bppwrite_filtops; + break; + + default: + return (1); + } + + kn->kn_hook = sc; + + s = splbpp(); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + splx(s); + + return (0); +} + int bppintr(arg) void *arg; @@ -531,7 +610,7 @@ bppintr(arg) sc->sc_flags &= ~BPP_WANT; wakeup(sc->sc_buf); } else { - selwakeup(&sc->sc_wsel); + selnotify(&sc->sc_wsel, 0); if (sc->sc_asyncproc != NULL) psignal(sc->sc_asyncproc, SIGIO); } diff --git a/sys/dev/sbus/magma.c b/sys/dev/sbus/magma.c index 4369d80dfc67..2b8971c8fadc 100644 --- a/sys/dev/sbus/magma.c +++ b/sys/dev/sbus/magma.c @@ -1,4 +1,4 @@ -/* $NetBSD: magma.c,v 1.20 2002/10/02 16:52:41 thorpej Exp $ */ +/* $NetBSD: magma.c,v 1.21 2002/10/23 09:13:42 jdolecek Exp $ */ /* * magma.c * @@ -38,7 +38,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: magma.c,v 1.20 2002/10/02 16:52:41 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: magma.c,v 1.21 2002/10/23 09:13:42 jdolecek Exp $"); #if 0 #define MAGMA_DEBUG @@ -209,7 +209,7 @@ dev_type_poll(mttypoll); const struct cdevsw mtty_cdevsw = { mttyopen, mttyclose, mttyread, mttywrite, mttyioctl, - mttystop, mttytty, mttypoll, nommap, D_TTY + mttystop, mttytty, mttypoll, nommap, ttykqfilter, D_TTY }; dev_type_open(mbppopen); @@ -219,7 +219,7 @@ dev_type_ioctl(mbppioctl); const struct cdevsw mbpp_cdevsw = { mbppopen, mbppclose, mbpp_rw, mbpp_rw, mbppioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; /************************************************************************ diff --git a/sys/dev/sbus/p9100.c b/sys/dev/sbus/p9100.c index ca19aadc0952..bbe5746d4b25 100644 --- a/sys/dev/sbus/p9100.c +++ b/sys/dev/sbus/p9100.c @@ -1,4 +1,4 @@ -/* $NetBSD: p9100.c,v 1.13 2002/10/02 16:52:41 thorpej Exp $ */ +/* $NetBSD: p9100.c,v 1.14 2002/10/23 09:13:43 jdolecek Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -45,7 +45,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: p9100.c,v 1.13 2002/10/02 16:52:41 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: p9100.c,v 1.14 2002/10/23 09:13:43 jdolecek Exp $"); #include #include @@ -133,13 +133,13 @@ dev_type_mmap(p9100mmap); const struct cdevsw pnozz_cdevsw = { p9100open, nullclose, noread, nowrite, p9100ioctl, - nostop, notty, nopoll, p9100mmap, + nostop, notty, nopoll, p9100mmap, nokqfilter, }; /* frame buffer generic driver */ static struct fbdriver p9100fbdriver = { p9100unblank, p9100open, nullclose, p9100ioctl, nopoll, - p9100mmap + p9100mmap, nokqfilter }; static void p9100loadcmap(struct p9100_softc *, int, int); diff --git a/sys/dev/sbus/tcx.c b/sys/dev/sbus/tcx.c index ac3c9cf02380..87526ad53159 100644 --- a/sys/dev/sbus/tcx.c +++ b/sys/dev/sbus/tcx.c @@ -1,4 +1,4 @@ -/* $NetBSD: tcx.c,v 1.12 2002/10/02 16:52:45 thorpej Exp $ */ +/* $NetBSD: tcx.c,v 1.13 2002/10/23 09:13:43 jdolecek Exp $ */ /* * Copyright (c) 1996,1998 The NetBSD Foundation, Inc. @@ -45,7 +45,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: tcx.c,v 1.12 2002/10/02 16:52:45 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tcx.c,v 1.13 2002/10/23 09:13:43 jdolecek Exp $"); /* * define for cg8 emulation on S24 (24-bit version of tcx) for the SS5; @@ -129,12 +129,13 @@ dev_type_mmap(tcxmmap); const struct cdevsw tcx_cdevsw = { tcxopen, tcxclose, noread, nowrite, tcxioctl, - nostop, notty, nopoll, tcxmmap, + nostop, notty, nopoll, tcxmmap, nokqfilter, }; /* frame buffer generic driver */ static struct fbdriver tcx_fbdriver = { - tcx_unblank, tcxopen, tcxclose, tcxioctl, nopoll, tcxmmap + tcx_unblank, tcxopen, tcxclose, tcxioctl, nopoll, tcxmmap, + nokqfilter }; static void tcx_reset __P((struct tcx_softc *)); diff --git a/sys/dev/scsipi/cd.c b/sys/dev/scsipi/cd.c index 14029a1c9d85..703aa8c8f8b9 100644 --- a/sys/dev/scsipi/cd.c +++ b/sys/dev/scsipi/cd.c @@ -1,4 +1,4 @@ -/* $NetBSD: cd.c,v 1.167 2002/09/18 01:46:23 chs Exp $ */ +/* $NetBSD: cd.c,v 1.168 2002/10/23 09:13:44 jdolecek Exp $ */ /*- * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc. @@ -54,7 +54,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cd.c,v 1.167 2002/09/18 01:46:23 chs Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cd.c,v 1.168 2002/10/23 09:13:44 jdolecek Exp $"); #include "rnd.h" @@ -155,7 +155,7 @@ const struct bdevsw cd_bdevsw = { const struct cdevsw cd_cdevsw = { cdopen, cdclose, cdread, cdwrite, cdioctl, - nostop, notty, nopoll, nommap, D_DISK + nostop, notty, nopoll, nommap, nokqfilter, D_DISK }; struct dkdriver cddkdriver = { cdstrategy }; diff --git a/sys/dev/scsipi/ch.c b/sys/dev/scsipi/ch.c index 055b2835d1b0..d10dcb6eb955 100644 --- a/sys/dev/scsipi/ch.c +++ b/sys/dev/scsipi/ch.c @@ -1,4 +1,4 @@ -/* $NetBSD: ch.c,v 1.53 2002/10/02 16:52:49 thorpej Exp $ */ +/* $NetBSD: ch.c,v 1.54 2002/10/23 09:13:46 jdolecek Exp $ */ /*- * Copyright (c) 1996, 1997, 1998, 1999 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ch.c,v 1.53 2002/10/02 16:52:49 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ch.c,v 1.54 2002/10/23 09:13:46 jdolecek Exp $"); #include #include @@ -124,10 +124,11 @@ dev_type_close(chclose); dev_type_read(chread); dev_type_ioctl(chioctl); dev_type_poll(chpoll); +dev_type_kqfilter(chkqfilter); const struct cdevsw ch_cdevsw = { chopen, chclose, chread, nowrite, chioctl, - nostop, notty, chpoll, nommap, + nostop, notty, chpoll, nommap, chkqfilter, }; /* SCSI glue */ @@ -479,6 +480,59 @@ chpoll(dev, events, p) return (revents); } +static void +filt_chdetach(struct knote *kn) +{ + struct ch_softc *sc = kn->kn_hook; + + SLIST_REMOVE(&sc->sc_selq.si_klist, kn, knote, kn_selnext); +} + +static int +filt_chread(struct knote *kn, long hint) +{ + struct ch_softc *sc = kn->kn_hook; + + if (sc->sc_events == 0) + return (0); + kn->kn_data = CHANGER_EVENT_SIZE; + return (1); +} + +static const struct filterops chread_filtops = + { 1, NULL, filt_chdetach, filt_chread }; + +static const struct filterops chwrite_filtops = + { 1, NULL, filt_chdetach, filt_seltrue }; + +int +chkqfilter(dev_t dev, struct knote *kn) +{ + struct ch_softc *sc = ch_cd.cd_devs[CHUNIT(dev)]; + struct klist *klist; + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &sc->sc_selq.si_klist; + kn->kn_fop = &chread_filtops; + break; + + case EVFILT_WRITE: + klist = &sc->sc_selq.si_klist; + kn->kn_fop = &chwrite_filtops; + break; + + default: + return (1); + } + + kn->kn_hook = sc; + + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + + return (0); +} + int ch_interpret_sense(xs) struct scsipi_xfer *xs; @@ -547,7 +601,7 @@ ch_event(sc, event) { sc->sc_events |= event; - selwakeup(&sc->sc_selq); + selnotify(&sc->sc_selq, 0); } int diff --git a/sys/dev/scsipi/if_se.c b/sys/dev/scsipi/if_se.c index ebb182cad665..45a8c5860786 100644 --- a/sys/dev/scsipi/if_se.c +++ b/sys/dev/scsipi/if_se.c @@ -1,4 +1,4 @@ -/* $NetBSD: if_se.c,v 1.43 2002/10/02 16:52:51 thorpej Exp $ */ +/* $NetBSD: if_se.c,v 1.44 2002/10/23 09:13:47 jdolecek Exp $ */ /* * Copyright (c) 1997 Ian W. Dall @@ -59,7 +59,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_se.c,v 1.43 2002/10/02 16:52:51 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_se.c,v 1.44 2002/10/23 09:13:47 jdolecek Exp $"); #include "opt_inet.h" #include "opt_atalk.h" @@ -253,7 +253,7 @@ dev_type_ioctl(seioctl); const struct cdevsw se_cdevsw = { seopen, seclose, noread, nowrite, seioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; const struct scsipi_periphsw se_switch = { diff --git a/sys/dev/scsipi/scsiconf.c b/sys/dev/scsipi/scsiconf.c index 0486a808a992..4fa51e39d4e2 100644 --- a/sys/dev/scsipi/scsiconf.c +++ b/sys/dev/scsipi/scsiconf.c @@ -1,4 +1,4 @@ -/* $NetBSD: scsiconf.c,v 1.193 2002/10/04 17:53:33 soren Exp $ */ +/* $NetBSD: scsiconf.c,v 1.194 2002/10/23 09:13:47 jdolecek Exp $ */ /*- * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc. @@ -55,7 +55,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.193 2002/10/04 17:53:33 soren Exp $"); +__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.194 2002/10/23 09:13:47 jdolecek Exp $"); #include #include @@ -112,7 +112,7 @@ dev_type_ioctl(scsibusioctl); const struct cdevsw scsibus_cdevsw = { scsibusopen, scsibusclose, noread, nowrite, scsibusioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; int scsibusprint __P((void *, const char *)); diff --git a/sys/dev/scsipi/sd.c b/sys/dev/scsipi/sd.c index 9e386b95c3f9..aec49c442d44 100644 --- a/sys/dev/scsipi/sd.c +++ b/sys/dev/scsipi/sd.c @@ -1,4 +1,4 @@ -/* $NetBSD: sd.c,v 1.189 2002/10/18 14:31:15 junyoung Exp $ */ +/* $NetBSD: sd.c,v 1.190 2002/10/23 09:13:48 jdolecek Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -54,7 +54,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: sd.c,v 1.189 2002/10/18 14:31:15 junyoung Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sd.c,v 1.190 2002/10/23 09:13:48 jdolecek Exp $"); #include "opt_scsi.h" #include "opt_bufq.h" @@ -125,7 +125,7 @@ const struct bdevsw sd_bdevsw = { const struct cdevsw sd_cdevsw = { sdopen, sdclose, sdread, sdwrite, sdioctl, - nostop, notty, nopoll, nommap, D_DISK + nostop, notty, nopoll, nommap, nokqfilter, D_DISK }; struct dkdriver sddkdriver = { sdstrategy }; diff --git a/sys/dev/scsipi/ses.c b/sys/dev/scsipi/ses.c index b91933d3ae6f..66ccf7653861 100644 --- a/sys/dev/scsipi/ses.c +++ b/sys/dev/scsipi/ses.c @@ -1,4 +1,4 @@ -/* $NetBSD: ses.c,v 1.17 2002/10/02 16:52:55 thorpej Exp $ */ +/* $NetBSD: ses.c,v 1.18 2002/10/23 09:13:50 jdolecek Exp $ */ /* * Copyright (C) 2000 National Aeronautics & Space Administration * All rights reserved. @@ -26,7 +26,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ses.c,v 1.17 2002/10/02 16:52:55 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ses.c,v 1.18 2002/10/23 09:13:50 jdolecek Exp $"); #include "opt_scsi.h" @@ -138,7 +138,7 @@ dev_type_ioctl(sesioctl); const struct cdevsw ses_cdevsw = { sesopen, sesclose, noread, nowrite, sesioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; static int ses_runcmd __P((struct ses_softc *, char *, int, char *, int *)); diff --git a/sys/dev/scsipi/ss.c b/sys/dev/scsipi/ss.c index 3e8e963de123..ee77aba24dd9 100644 --- a/sys/dev/scsipi/ss.c +++ b/sys/dev/scsipi/ss.c @@ -1,4 +1,4 @@ -/* $NetBSD: ss.c,v 1.44 2002/10/02 16:52:55 thorpej Exp $ */ +/* $NetBSD: ss.c,v 1.45 2002/10/23 09:13:50 jdolecek Exp $ */ /* * Copyright (c) 1995 Kenneth Stailey. All rights reserved. @@ -31,7 +31,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ss.c,v 1.44 2002/10/02 16:52:55 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ss.c,v 1.45 2002/10/23 09:13:50 jdolecek Exp $"); #include #include @@ -85,7 +85,7 @@ dev_type_ioctl(ssioctl); const struct cdevsw ss_cdevsw = { ssopen, ssclose, ssread, nowrite, ssioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; void ssstrategy __P((struct buf *)); diff --git a/sys/dev/scsipi/st.c b/sys/dev/scsipi/st.c index 395ad6c92df4..7d21621dce55 100644 --- a/sys/dev/scsipi/st.c +++ b/sys/dev/scsipi/st.c @@ -1,4 +1,4 @@ -/* $NetBSD: st.c,v 1.157 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: st.c,v 1.158 2002/10/23 09:13:51 jdolecek Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. * All rights reserved. @@ -56,7 +56,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: st.c,v 1.157 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: st.c,v 1.158 2002/10/23 09:13:51 jdolecek Exp $"); #include "opt_scsi.h" @@ -113,7 +113,7 @@ const struct bdevsw st_bdevsw = { const struct cdevsw st_cdevsw = { stopen, stclose, stread, stwrite, stioctl, - nostop, notty, nopoll, nommap, D_TAPE + nostop, notty, nopoll, nommap, nokqfilter, D_TAPE }; /* diff --git a/sys/dev/scsipi/uk.c b/sys/dev/scsipi/uk.c index 8e988a347018..a2b56428c051 100644 --- a/sys/dev/scsipi/uk.c +++ b/sys/dev/scsipi/uk.c @@ -1,4 +1,4 @@ -/* $NetBSD: uk.c,v 1.37 2002/10/02 16:52:57 thorpej Exp $ */ +/* $NetBSD: uk.c,v 1.38 2002/10/23 09:13:52 jdolecek Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -42,7 +42,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: uk.c,v 1.37 2002/10/02 16:52:57 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uk.c,v 1.38 2002/10/23 09:13:52 jdolecek Exp $"); #include #include @@ -85,7 +85,7 @@ dev_type_ioctl(ukioctl); const struct cdevsw uk_cdevsw = { ukopen, ukclose, noread, nowrite, ukioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; int diff --git a/sys/dev/sequencer.c b/sys/dev/sequencer.c index 44f87f2c5a47..af6a41ee0235 100644 --- a/sys/dev/sequencer.c +++ b/sys/dev/sequencer.c @@ -1,4 +1,4 @@ -/* $NetBSD: sequencer.c,v 1.20 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: sequencer.c,v 1.21 2002/10/23 09:13:05 jdolecek Exp $ */ /* * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: sequencer.c,v 1.20 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sequencer.c,v 1.21 2002/10/23 09:13:05 jdolecek Exp $"); #include "sequencer.h" @@ -155,10 +155,12 @@ dev_type_read(sequencerread); dev_type_write(sequencerwrite); dev_type_ioctl(sequencerioctl); dev_type_poll(sequencerpoll); +dev_type_kqfilter(sequencerkqfilter); const struct cdevsw sequencer_cdevsw = { sequenceropen, sequencerclose, sequencerread, sequencerwrite, sequencerioctl, nostop, notty, sequencerpoll, nommap, + sequencerkqfilter, }; void @@ -295,7 +297,7 @@ seq_timeout(addr) seq_startoutput(sc); if (SEQ_QLEN(&sc->outq) < sc->lowat) { seq_wakeup(&sc->wchan); - selwakeup(&sc->wsel); + selnotify(&sc->wsel, 0); if (sc->async) psignal(sc->async, SIGIO); } @@ -358,7 +360,7 @@ seq_input_event(sc, cmd) return (ENOMEM); SEQ_QPUT(q, *cmd); seq_wakeup(&sc->rchan); - selwakeup(&sc->rsel); + selnotify(&sc->rsel, 0); if (sc->async) psignal(sc->async, SIGIO); return 0; @@ -672,6 +674,91 @@ sequencerpoll(dev, events, p) return revents; } +static void +filt_sequencerrdetach(struct knote *kn) +{ + struct sequencer_softc *sc = kn->kn_hook; + int s; + + s = splaudio(); + SLIST_REMOVE(&sc->rsel.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_sequencerread(struct knote *kn, long hint) +{ + struct sequencer_softc *sc = kn->kn_hook; + + /* XXXLUKEM (thorpej): make sure this is correct */ + + if (SEQ_QEMPTY(&sc->inq)) + return (0); + kn->kn_data = sizeof(seq_event_rec); + return (1); +} + +static const struct filterops sequencerread_filtops = + { 1, NULL, filt_sequencerrdetach, filt_sequencerread }; + +static void +filt_sequencerwdetach(struct knote *kn) +{ + struct sequencer_softc *sc = kn->kn_hook; + int s; + + s = splaudio(); + SLIST_REMOVE(&sc->wsel.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_sequencerwrite(struct knote *kn, long hint) +{ + struct sequencer_softc *sc = kn->kn_hook; + + /* XXXLUKEM (thorpej): make sure this is correct */ + + if (SEQ_QLEN(&sc->outq) >= sc->lowat) + return (0); + kn->kn_data = sizeof(seq_event_rec); + return (1); +} + +static const struct filterops sequencerwrite_filtops = + { 1, NULL, filt_sequencerwdetach, filt_sequencerwrite }; + +int +sequencerkqfilter(dev_t dev, struct knote *kn) +{ + struct sequencer_softc *sc = &seqdevs[SEQUENCERUNIT(dev)]; + struct klist *klist; + int s; + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &sc->rsel.si_klist; + kn->kn_fop = &sequencerread_filtops; + break; + + case EVFILT_WRITE: + klist = &sc->wsel.si_klist; + kn->kn_fop = &sequencerwrite_filtops; + break; + + default: + return (1); + } + + kn->kn_hook = sc; + + s = splaudio(); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + splx(s); + + return (0); +} + void seq_reset(sc) struct sequencer_softc *sc; diff --git a/sys/dev/sun/bwtwo.c b/sys/dev/sun/bwtwo.c index 8ccba5860a15..d58b452a1fbe 100644 --- a/sys/dev/sun/bwtwo.c +++ b/sys/dev/sun/bwtwo.c @@ -1,4 +1,4 @@ -/* $NetBSD: bwtwo.c,v 1.5 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: bwtwo.c,v 1.6 2002/10/23 09:13:53 jdolecek Exp $ */ /*- * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. @@ -90,7 +90,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: bwtwo.c,v 1.5 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: bwtwo.c,v 1.6 2002/10/23 09:13:53 jdolecek Exp $"); #include #include @@ -119,7 +119,7 @@ dev_type_mmap(bwtwommap); const struct cdevsw bwtwo_cdevsw = { bwtwoopen, nullclose, noread, nowrite, bwtwoioctl, - nostop, notty, nopoll, bwtwommap, + nostop, notty, nopoll, bwtwommap, nokqfilter, }; /* XXX we do not handle frame buffer interrupts (do not know how) */ @@ -127,7 +127,8 @@ static void bwtwounblank(struct device *); /* frame buffer generic driver */ static struct fbdriver bwtwofbdriver = { - bwtwounblank, bwtwoopen, nullclose, bwtwoioctl, nopoll, bwtwommap + bwtwounblank, bwtwoopen, nullclose, bwtwoioctl, nopoll, bwtwommap, + nokqfilter }; int diff --git a/sys/dev/sun/cgsix.c b/sys/dev/sun/cgsix.c index 95df8b4e658d..a9b5eba31b68 100644 --- a/sys/dev/sun/cgsix.c +++ b/sys/dev/sun/cgsix.c @@ -1,4 +1,4 @@ -/* $NetBSD: cgsix.c,v 1.8 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: cgsix.c,v 1.9 2002/10/23 09:13:53 jdolecek Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -89,7 +89,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cgsix.c,v 1.8 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cgsix.c,v 1.9 2002/10/23 09:13:53 jdolecek Exp $"); #include #include @@ -135,12 +135,13 @@ dev_type_mmap(cgsixmmap); const struct cdevsw cgsix_cdevsw = { cgsixopen, cgsixclose, noread, nowrite, cgsixioctl, - nostop, notty, nopoll, cgsixmmap, + nostop, notty, nopoll, cgsixmmap, nokqfilter, }; /* frame buffer generic driver */ static struct fbdriver cg6_fbdriver = { - cg6_unblank, cgsixopen, cgsixclose, cgsixioctl, nopoll, cgsixmmap + cg6_unblank, cgsixopen, cgsixclose, cgsixioctl, nopoll, cgsixmmap, + nokqfilter }; static void cg6_reset (struct cgsix_softc *); diff --git a/sys/dev/sun/cgthree.c b/sys/dev/sun/cgthree.c index b6fdb2c6269e..6e3d41b7fae5 100644 --- a/sys/dev/sun/cgthree.c +++ b/sys/dev/sun/cgthree.c @@ -1,4 +1,4 @@ -/* $NetBSD: cgthree.c,v 1.5 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: cgthree.c,v 1.6 2002/10/23 09:13:54 jdolecek Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -45,7 +45,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cgthree.c,v 1.5 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cgthree.c,v 1.6 2002/10/23 09:13:54 jdolecek Exp $"); #include #include @@ -81,13 +81,13 @@ dev_type_mmap(cgthreemmap); const struct cdevsw cgthree_cdevsw = { cgthreeopen, nullclose, noread, nowrite, cgthreeioctl, - nostop, notty, nopoll, cgthreemmap, + nostop, notty, nopoll, cgthreemmap, nokqfilter }; /* frame buffer generic driver */ static struct fbdriver cgthreefbdriver = { cgthreeunblank, cgthreeopen, nullclose, cgthreeioctl, nopoll, - cgthreemmap + cgthreemmap, nokqfilter }; /* Video control parameters */ diff --git a/sys/dev/sun/event.c b/sys/dev/sun/event.c index ea48e7785b36..09448e73704c 100644 --- a/sys/dev/sun/event.c +++ b/sys/dev/sun/event.c @@ -1,4 +1,4 @@ -/* $NetBSD: event.c,v 1.10 2002/10/21 15:22:03 uwe Exp $ */ +/* $NetBSD: event.c,v 1.11 2002/10/23 09:13:54 jdolecek Exp $ */ /* * Copyright (c) 1992, 1993 @@ -49,7 +49,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: event.c,v 1.10 2002/10/21 15:22:03 uwe Exp $"); +__KERNEL_RCSID(0, "$NetBSD: event.c,v 1.11 2002/10/23 09:13:54 jdolecek Exp $"); #include #include @@ -175,3 +175,61 @@ ev_poll(ev, events, p) splx(s); return (revents); } + +static void +filt_evrdetach(struct knote *kn) +{ + struct evvar *ev = kn->kn_hook; + int s; + + s = splev(); + SLIST_REMOVE(&ev->ev_sel.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_evread(struct knote *kn, long hint) +{ + struct evvar *ev = kn->kn_hook; + + if (ev->ev_get == ev->ev_put) + return (0); + + if (ev->ev_get < ev->ev_put) + kn->kn_data = ev->ev_put - ev->ev_get; + else + kn->kn_data = (EV_QSIZE - ev->ev_get) + + ev->ev_put; + + kn->kn_data *= sizeof(struct firm_event); + + return (1); +} + +static const struct filterops ev_filtops = + { 1, NULL, filt_evrdetach, filt_evread }; + +int +ev_kqfilter(struct evvar *ev, struct knote *kn) +{ + struct klist *klist; + int s; + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &ev->ev_sel.si_klist; + kn->kn_fop = &ev_filtops; + break; + + default: + return (1); + } + + kn->kn_hook = ev; + + s = splev(); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + splx(s); + + return (0); +} diff --git a/sys/dev/sun/event_var.h b/sys/dev/sun/event_var.h index 4cba4b7325eb..d5020a83f5f4 100644 --- a/sys/dev/sun/event_var.h +++ b/sys/dev/sun/event_var.h @@ -1,4 +1,4 @@ -/* $NetBSD: event_var.h,v 1.3 2001/06/07 17:52:52 mrg Exp $ */ +/* $NetBSD: event_var.h,v 1.4 2002/10/23 09:13:54 jdolecek Exp $ */ /* * Copyright (c) 1992, 1993 @@ -67,7 +67,7 @@ struct evvar { #define splev() spltty() #define EV_WAKEUP(ev) { \ - selwakeup(&(ev)->ev_sel); \ + selnotify(&(ev)->ev_sel, 0); \ if ((ev)->ev_wanted) { \ (ev)->ev_wanted = 0; \ wakeup((caddr_t)(ev)); \ @@ -80,6 +80,7 @@ void ev_init __P((struct evvar *)); void ev_fini __P((struct evvar *)); int ev_read __P((struct evvar *, struct uio *, int)); int ev_poll __P((struct evvar *, int, struct proc *)); +int ev_kqfilter __P((struct evvar *, struct knote *)); /* * Hook for 32-bit compatibility on a 64-bit kernel. diff --git a/sys/dev/sun/fb.c b/sys/dev/sun/fb.c index d04e0c766a6d..3d2db058ae60 100644 --- a/sys/dev/sun/fb.c +++ b/sys/dev/sun/fb.c @@ -1,4 +1,4 @@ -/* $NetBSD: fb.c,v 1.9 2002/10/03 16:13:25 uwe Exp $ */ +/* $NetBSD: fb.c,v 1.10 2002/10/23 09:13:55 jdolecek Exp $ */ /* * Copyright (c) 1992, 1993 @@ -50,7 +50,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: fb.c,v 1.9 2002/10/03 16:13:25 uwe Exp $"); +__KERNEL_RCSID(0, "$NetBSD: fb.c,v 1.10 2002/10/23 09:13:55 jdolecek Exp $"); #include #include @@ -76,10 +76,11 @@ dev_type_close(fbclose); dev_type_ioctl(fbioctl); dev_type_poll(fbpoll); dev_type_mmap(fbmmap); +dev_type_kqfilter(fbkqfilter); const struct cdevsw fb_cdevsw = { fbopen, fbclose, noread, nowrite, fbioctl, - nostop, notty, fbpoll, fbmmap, + nostop, notty, fbpoll, fbmmap, fbkqfilter, }; void @@ -252,6 +253,15 @@ fbpoll(dev, events, p) return (devfb->fb_driver->fbd_poll)(dev, events, p); } +int +fbkqfilter(dev, kn) + dev_t dev; + struct knote *kn; +{ + + return (devfb->fb_driver->fbd_kqfilter)(dev, kn); +} + paddr_t fbmmap(dev, off, prot) dev_t dev; diff --git a/sys/dev/sun/fbvar.h b/sys/dev/sun/fbvar.h index 1a860c1865f8..5c8091b7aa22 100644 --- a/sys/dev/sun/fbvar.h +++ b/sys/dev/sun/fbvar.h @@ -1,4 +1,4 @@ -/* $NetBSD: fbvar.h,v 1.3 2000/08/23 12:02:47 pk Exp $ */ +/* $NetBSD: fbvar.h,v 1.4 2002/10/23 09:13:55 jdolecek Exp $ */ /* * Copyright (c) 1992, 1993 @@ -49,6 +49,8 @@ * following in order to participate. */ +#include + #ifdef RASTERCONSOLE #include #include @@ -63,6 +65,7 @@ struct fbdriver { int (*fbd_ioctl)(dev_t, u_long, caddr_t, int, struct proc *); int (*fbd_poll)(dev_t, int, struct proc *); paddr_t (*fbd_mmap)(dev_t, off_t, int); + int (*fbd_kqfilter)(dev_t, struct knote *); #ifdef notyet /* * XXX redundant idea? these can hook into rasops on a per-device diff --git a/sys/dev/sun/kbd.c b/sys/dev/sun/kbd.c index 617ab4b14c67..5ab777f3d34f 100644 --- a/sys/dev/sun/kbd.c +++ b/sys/dev/sun/kbd.c @@ -1,4 +1,4 @@ -/* $NetBSD: kbd.c,v 1.33 2002/10/21 15:36:35 uwe Exp $ */ +/* $NetBSD: kbd.c,v 1.34 2002/10/23 09:13:56 jdolecek Exp $ */ /* * Copyright (c) 1992, 1993 @@ -51,7 +51,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kbd.c,v 1.33 2002/10/21 15:36:35 uwe Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kbd.c,v 1.34 2002/10/23 09:13:56 jdolecek Exp $"); #include #include @@ -85,10 +85,11 @@ dev_type_close(kbdclose); dev_type_read(kbdread); dev_type_ioctl(kbdioctl); dev_type_poll(kbdpoll); +dev_type_kqfilter(kbdkqfilter); const struct cdevsw kbd_cdevsw = { kbdopen, kbdclose, kbdread, nowrite, kbdioctl, - nostop, notty, kbdpoll, nommap, + nostop, notty, kbdpoll, nommap, kbdkqfilter }; @@ -229,6 +230,16 @@ kbdpoll(dev, events, p) return (ev_poll(&k->k_events, events, p)); } +int +kbdkqfilter(dev, kn) + dev_t dev; + struct knote *kn; +{ + struct kbd_softc *k; + + k = kbd_cd.cd_devs[minor(dev)]; + return (ev_kqfilter(&k->k_events, kn)); +} int kbdioctl(dev, cmd, data, flag, p) diff --git a/sys/dev/sun/ms.c b/sys/dev/sun/ms.c index 91b69f2b30e7..5d873247310a 100644 --- a/sys/dev/sun/ms.c +++ b/sys/dev/sun/ms.c @@ -1,4 +1,4 @@ -/* $NetBSD: ms.c,v 1.22 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: ms.c,v 1.23 2002/10/23 09:13:56 jdolecek Exp $ */ /* * Copyright (c) 1992, 1993 @@ -56,7 +56,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ms.c,v 1.22 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ms.c,v 1.23 2002/10/23 09:13:56 jdolecek Exp $"); #include #include @@ -88,10 +88,11 @@ dev_type_close(msclose); dev_type_read(msread); dev_type_ioctl(msioctl); dev_type_poll(mspoll); +dev_type_kqfilter(mskqfilter); const struct cdevsw ms_cdevsw = { msopen, msclose, msread, nowrite, msioctl, - nostop, notty, mspoll, nommap, + nostop, notty, mspoll, nommap, mskqfilter, }; /**************************************************************** @@ -217,6 +218,16 @@ mspoll(dev, events, p) return (ev_poll(&ms->ms_events, events, p)); } +int +mskqfilter(dev, kn) + dev_t dev; + struct knote *kn; +{ + struct ms_softc *ms; + + ms = ms_cd.cd_devs[minor(dev)]; + return (ev_kqfilter(&ms->ms_events, kn)); +} /**************************************************************** * Middle layer (translator) diff --git a/sys/dev/sysmon/sysmon.c b/sys/dev/sysmon/sysmon.c index 09175c174fdf..e98ee255e5e3 100644 --- a/sys/dev/sysmon/sysmon.c +++ b/sys/dev/sysmon/sysmon.c @@ -1,4 +1,4 @@ -/* $NetBSD: sysmon.c,v 1.6 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: sysmon.c,v 1.7 2002/10/23 09:13:57 jdolecek Exp $ */ /*- * Copyright (c) 2000 Zembu Labs, Inc. @@ -39,7 +39,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: sysmon.c,v 1.6 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sysmon.c,v 1.7 2002/10/23 09:13:57 jdolecek Exp $"); #include #include @@ -60,7 +60,7 @@ dev_type_ioctl(sysmonioctl); const struct cdevsw sysmon_cdevsw = { sysmonopen, sysmonclose, noread, nowrite, sysmonioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; /* diff --git a/sys/dev/tc/stic.c b/sys/dev/tc/stic.c index a76eb75ae40e..9610188e09cc 100644 --- a/sys/dev/tc/stic.c +++ b/sys/dev/tc/stic.c @@ -1,4 +1,4 @@ -/* $NetBSD: stic.c,v 1.21 2002/09/27 15:37:33 provos Exp $ */ +/* $NetBSD: stic.c,v 1.22 2002/10/23 09:13:58 jdolecek Exp $ */ /*- * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc. @@ -73,7 +73,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: stic.c,v 1.21 2002/09/27 15:37:33 provos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: stic.c,v 1.22 2002/10/23 09:13:58 jdolecek Exp $"); #include #include @@ -191,7 +191,7 @@ dev_type_mmap(sticmmap); const struct cdevsw stic_cdevsw = { sticopen, sticclose, noread, nowrite, noioctl, - nostop, notty, nopoll, sticmmap, + nostop, notty, nopoll, sticmmap, nokqfilter, }; /* Colormap for wscons, matching WSCOL_*. Upper 8 are high-intensity. */ diff --git a/sys/dev/usb/ucom.c b/sys/dev/usb/ucom.c index 4641dc0e43e0..a8e574d2bb16 100644 --- a/sys/dev/usb/ucom.c +++ b/sys/dev/usb/ucom.c @@ -1,4 +1,4 @@ -/* $NetBSD: ucom.c,v 1.46 2002/09/27 03:18:21 thorpej Exp $ */ +/* $NetBSD: ucom.c,v 1.47 2002/10/23 09:13:59 jdolecek Exp $ */ /* * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc. @@ -41,7 +41,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ucom.c,v 1.46 2002/09/27 03:18:21 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ucom.c,v 1.47 2002/10/23 09:13:59 jdolecek Exp $"); #include #include @@ -144,7 +144,7 @@ dev_type_poll(ucompoll); const struct cdevsw ucom_cdevsw = { ucomopen, ucomclose, ucomread, ucomwrite, ucomioctl, - ucomstop, ucomtty, ucompoll, nommap, D_TTY + ucomstop, ucomtty, ucompoll, nommap, ttykqfilter, D_TTY }; Static void ucom_cleanup(struct ucom_softc *); diff --git a/sys/dev/usb/ugen.c b/sys/dev/usb/ugen.c index 58006bce2007..8e5a21df76a2 100644 --- a/sys/dev/usb/ugen.c +++ b/sys/dev/usb/ugen.c @@ -1,4 +1,4 @@ -/* $NetBSD: ugen.c,v 1.61 2002/09/23 05:51:20 simonb Exp $ */ +/* $NetBSD: ugen.c,v 1.62 2002/10/23 09:13:59 jdolecek Exp $ */ /* $FreeBSD: src/sys/dev/usb/ugen.c,v 1.26 1999/11/17 22:33:41 n_hibma Exp $ */ /* @@ -40,7 +40,7 @@ #include -__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.61 2002/09/23 05:51:20 simonb Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.62 2002/10/23 09:13:59 jdolecek Exp $"); #include #include @@ -129,10 +129,11 @@ dev_type_read(ugenread); dev_type_write(ugenwrite); dev_type_ioctl(ugenioctl); dev_type_poll(ugenpoll); +dev_type_kqfilter(ugenkqfilter); const struct cdevsw ugen_cdevsw = { ugenopen, ugenclose, ugenread, ugenwrite, ugenioctl, - nostop, notty, ugenpoll, nommap, + nostop, notty, ugenpoll, nommap, ugenkqfilter, }; #elif defined(__OpenBSD__) cdev_decl(ugen); @@ -848,7 +849,7 @@ ugenintr(usbd_xfer_handle xfer, usbd_private_handle addr, usbd_status status) DPRINTFN(5, ("ugen_intr: waking %p\n", sce)); wakeup(sce); } - selwakeup(&sce->rsel); + selnotify(&sce->rsel, 0); } Static void @@ -907,7 +908,7 @@ ugen_isoc_rintr(usbd_xfer_handle xfer, usbd_private_handle addr, DPRINTFN(5, ("ugen_isoc_rintr: waking %p\n", sce)); wakeup(sce); } - selwakeup(&sce->rsel); + selnotify(&sce->rsel, 0); } Static usbd_status @@ -1356,6 +1357,127 @@ ugenpoll(dev_t dev, int events, usb_proc_ptr p) return (revents); } +static void +filt_ugenrdetach(struct knote *kn) +{ + struct ugen_endpoint *sce = kn->kn_hook; + int s; + + s = splusb(); + SLIST_REMOVE(&sce->rsel.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_ugenread_intr(struct knote *kn, long hint) +{ + struct ugen_endpoint *sce = kn->kn_hook; + + kn->kn_data = sce->q.c_cc; + return (kn->kn_data > 0); +} + +static int +filt_ugenread_isoc(struct knote *kn, long hint) +{ + struct ugen_endpoint *sce = kn->kn_hook; + + if (sce->cur == sce->fill) + return (0); + + if (sce->cur < sce->fill) + kn->kn_data = sce->fill - sce->cur; + else + kn->kn_data = (sce->limit - sce->cur) + + (sce->fill - sce->ibuf); + + return (1); +} + +static const struct filterops ugenread_intr_filtops = + { 1, NULL, filt_ugenrdetach, filt_ugenread_intr }; + +static const struct filterops ugenread_isoc_filtops = + { 1, NULL, filt_ugenrdetach, filt_ugenread_isoc }; + +static const struct filterops ugen_seltrue_filtops = + { 1, NULL, filt_ugenrdetach, filt_seltrue }; + +int +ugenkqfilter(dev_t dev, struct knote *kn) +{ + struct ugen_softc *sc; + struct ugen_endpoint *sce; + struct klist *klist; + int s; + + USB_GET_SC(ugen, UGENUNIT(dev), sc); + + if (sc->sc_dying) + return (1); + + /* XXX always IN */ + sce = &sc->sc_endpoints[UGENENDPOINT(dev)][IN]; + if (sce == NULL) + return (1); + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &sce->rsel.si_klist; + switch (sce->edesc->bmAttributes & UE_XFERTYPE) { + case UE_INTERRUPT: + kn->kn_fop = &ugenread_intr_filtops; + break; + case UE_ISOCHRONOUS: + kn->kn_fop = &ugenread_isoc_filtops; + break; + case UE_BULK: + /* + * We have no easy way of determining if a read will + * yield any data or a write will happen. + * So, emulate "seltrue". + */ + kn->kn_fop = &ugen_seltrue_filtops; + break; + default: + return (1); + } + break; + + case EVFILT_WRITE: + klist = &sce->rsel.si_klist; + switch (sce->edesc->bmAttributes & UE_XFERTYPE) { + case UE_INTERRUPT: + case UE_ISOCHRONOUS: + /* XXX poll doesn't support this */ + return (1); + + case UE_BULK: + /* + * We have no easy way of determining if a read will + * yield any data or a write will happen. + * So, emulate "seltrue". + */ + kn->kn_fop = &ugen_seltrue_filtops; + break; + default: + return (1); + } + break; + + default: + return (1); + } + + kn->kn_hook = sce; + + s = splusb(); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + splx(s); + + return (0); +} + #if defined(__FreeBSD__) DRIVER_MODULE(ugen, uhub, ugen_driver, ugen_devclass, usbd_driver_load, 0); #endif diff --git a/sys/dev/usb/uhid.c b/sys/dev/usb/uhid.c index bf80015c4f31..598370440823 100644 --- a/sys/dev/usb/uhid.c +++ b/sys/dev/usb/uhid.c @@ -1,4 +1,4 @@ -/* $NetBSD: uhid.c,v 1.54 2002/09/23 05:51:21 simonb Exp $ */ +/* $NetBSD: uhid.c,v 1.55 2002/10/23 09:14:00 jdolecek Exp $ */ /* * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -42,7 +42,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: uhid.c,v 1.54 2002/09/23 05:51:21 simonb Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uhid.c,v 1.55 2002/10/23 09:14:00 jdolecek Exp $"); #include #include @@ -109,10 +109,11 @@ dev_type_read(uhidread); dev_type_write(uhidwrite); dev_type_ioctl(uhidioctl); dev_type_poll(uhidpoll); +dev_type_kqfilter(uhidkqfilter); const struct cdevsw uhid_cdevsw = { uhidopen, uhidclose, uhidread, uhidwrite, uhidioctl, - nostop, notty, uhidpoll, nommap, + nostop, notty, uhidpoll, nommap, uhidkqfilter, }; Static void uhid_intr(struct uhidev *, void *, u_int len); @@ -242,7 +243,7 @@ uhid_intr(struct uhidev *addr, void *data, u_int len) DPRINTFN(5, ("uhid_intr: waking %p\n", &sc->sc_q)); wakeup(&sc->sc_q); } - selwakeup(&sc->sc_rsel); + selnotify(&sc->sc_rsel, 0); if (sc->sc_async != NULL) { DPRINTFN(3, ("uhid_intr: sending SIGIO %p\n", sc->sc_async)); psignal(sc->sc_async, SIGIO); @@ -564,3 +565,65 @@ uhidpoll(dev_t dev, int events, usb_proc_ptr p) splx(s); return (revents); } + +static void +filt_uhidrdetach(struct knote *kn) +{ + struct uhid_softc *sc = kn->kn_hook; + int s; + + s = splusb(); + SLIST_REMOVE(&sc->sc_rsel.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_uhidread(struct knote *kn, long hint) +{ + struct uhid_softc *sc = kn->kn_hook; + + kn->kn_data = sc->sc_q.c_cc; + return (kn->kn_data > 0); +} + +static const struct filterops uhidread_filtops = + { 1, NULL, filt_uhidrdetach, filt_uhidread }; + +static const struct filterops uhid_seltrue_filtops = + { 1, NULL, filt_uhidrdetach, filt_seltrue }; + +int +uhidkqfilter(dev_t dev, struct knote *kn) +{ + struct uhid_softc *sc; + struct klist *klist; + int s; + + USB_GET_SC(uhid, UHIDUNIT(dev), sc); + + if (sc->sc_dying) + return (EIO); + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &sc->sc_rsel.si_klist; + kn->kn_fop = &uhidread_filtops; + break; + + case EVFILT_WRITE: + klist = &sc->sc_rsel.si_klist; + kn->kn_fop = &uhid_seltrue_filtops; + break; + + default: + return (1); + } + + kn->kn_hook = sc; + + s = splusb(); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + splx(s); + + return (0); +} diff --git a/sys/dev/usb/uirda.c b/sys/dev/usb/uirda.c index e7ea7e8ce331..047676255ecd 100644 --- a/sys/dev/usb/uirda.c +++ b/sys/dev/usb/uirda.c @@ -1,4 +1,4 @@ -/* $NetBSD: uirda.c,v 1.12 2002/08/22 09:57:13 augustss Exp $ */ +/* $NetBSD: uirda.c,v 1.13 2002/10/23 09:14:01 jdolecek Exp $ */ /* * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: uirda.c,v 1.12 2002/08/22 09:57:13 augustss Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uirda.c,v 1.13 2002/10/23 09:14:01 jdolecek Exp $"); #include #include @@ -215,6 +215,7 @@ struct uirda_softc { usbd_xfer_handle sc_wr_xfer; usbd_pipe_handle sc_wr_pipe; int sc_wr_hdr; + struct selinfo sc_wr_sel; struct device *sc_child; struct irda_params sc_params; @@ -234,10 +235,12 @@ int uirda_set_params(void *h, struct irda_params *params); int uirda_get_speeds(void *h, int *speeds); int uirda_get_turnarounds(void *h, int *times); int uirda_poll(void *h, int events, usb_proc_ptr p); +int uirda_kqfilter(void *h, struct knote *kn); struct irframe_methods uirda_methods = { uirda_open, uirda_close, uirda_read, uirda_write, uirda_poll, - uirda_set_params, uirda_get_speeds, uirda_get_turnarounds + uirda_kqfilter, uirda_set_params, uirda_get_speeds, + uirda_get_turnarounds }; void uirda_rd_cb(usbd_xfer_handle xfer, usbd_private_handle priv, @@ -679,6 +682,71 @@ uirda_poll(void *h, int events, usb_proc_ptr p) return (revents); } +static void +filt_uirdardetach(struct knote *kn) +{ + struct uirda_softc *sc = kn->kn_hook; + int s; + + s = splusb(); + SLIST_REMOVE(&sc->sc_rd_sel.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_uirdaread(struct knote *kn, long hint) +{ + struct uirda_softc *sc = kn->kn_hook; + + kn->kn_data = sc->sc_rd_count; + return (kn->kn_data > 0); +} + +static void +filt_uirdawdetach(struct knote *kn) +{ + struct uirda_softc *sc = kn->kn_hook; + int s; + + s = splusb(); + SLIST_REMOVE(&sc->sc_wr_sel.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static const struct filterops uirdaread_filtops = + { 1, NULL, filt_uirdardetach, filt_uirdaread }; +static const struct filterops uirdawrite_filtops = + { 1, NULL, filt_uirdawdetach, filt_seltrue }; + +int +uirda_kqfilter(void *h, struct knote *kn) +{ + struct uirda_softc *sc = kn->kn_hook; + struct klist *klist; + int s; + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &sc->sc_rd_sel.si_klist; + kn->kn_fop = &uirdaread_filtops; + break; + case EVFILT_WRITE: + klist = &sc->sc_wr_sel.si_klist; + kn->kn_fop = &uirdawrite_filtops; + break; + default: + return (1); + } + + kn->kn_hook = sc; + + s = splusb(); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + splx(s); + + return (0); +} + int uirda_set_params(void *h, struct irda_params *p) { @@ -866,7 +934,7 @@ uirda_rd_cb(usbd_xfer_handle xfer, usbd_private_handle priv, sc->sc_rd_err)); sc->sc_rd_count = size; wakeup(&sc->sc_rd_count); /* XXX should use flag */ - selwakeup(&sc->sc_rd_sel); + selnotify(&sc->sc_rd_sel, 0); } usbd_status diff --git a/sys/dev/usb/ulpt.c b/sys/dev/usb/ulpt.c index 556e0d136f6c..99a32e9aafed 100644 --- a/sys/dev/usb/ulpt.c +++ b/sys/dev/usb/ulpt.c @@ -1,4 +1,4 @@ -/* $NetBSD: ulpt.c,v 1.54 2002/09/27 15:37:37 provos Exp $ */ +/* $NetBSD: ulpt.c,v 1.55 2002/10/23 09:14:01 jdolecek Exp $ */ /* $FreeBSD: src/sys/dev/usb/ulpt.c,v 1.24 1999/11/17 22:33:44 n_hibma Exp $ */ /* @@ -43,7 +43,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ulpt.c,v 1.54 2002/09/27 15:37:37 provos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ulpt.c,v 1.55 2002/10/23 09:14:01 jdolecek Exp $"); #include #include @@ -133,7 +133,7 @@ dev_type_ioctl(ulptioctl); const struct cdevsw ulpt_cdevsw = { ulptopen, ulptclose, noread, ulptwrite, ulptioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; #elif defined(__OpenBSD__) cdev_decl(ulpt); diff --git a/sys/dev/usb/urio.c b/sys/dev/usb/urio.c index 93fca4563cb2..95281dc1f798 100644 --- a/sys/dev/usb/urio.c +++ b/sys/dev/usb/urio.c @@ -1,4 +1,4 @@ -/* $NetBSD: urio.c,v 1.14 2002/10/11 20:29:30 jdolecek Exp $ */ +/* $NetBSD: urio.c,v 1.15 2002/10/23 09:14:02 jdolecek Exp $ */ /* * Copyright (c) 2000 The NetBSD Foundation, Inc. @@ -43,7 +43,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: urio.c,v 1.14 2002/10/11 20:29:30 jdolecek Exp $"); +__KERNEL_RCSID(0, "$NetBSD: urio.c,v 1.15 2002/10/23 09:14:02 jdolecek Exp $"); #include #include @@ -93,7 +93,7 @@ dev_type_ioctl(urioioctl); const struct cdevsw urio_cdevsw = { urioopen, urioclose, urioread, uriowrite, urioioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; #elif defined(__OpenBSD__) cdev_decl(urio); diff --git a/sys/dev/usb/usb.c b/sys/dev/usb/usb.c index 733e95b4f640..74ebfd1e8ca3 100644 --- a/sys/dev/usb/usb.c +++ b/sys/dev/usb/usb.c @@ -1,4 +1,4 @@ -/* $NetBSD: usb.c,v 1.73 2002/09/23 05:51:19 simonb Exp $ */ +/* $NetBSD: usb.c,v 1.74 2002/10/23 09:14:02 jdolecek Exp $ */ /* * Copyright (c) 1998, 2002 The NetBSD Foundation, Inc. @@ -44,7 +44,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.73 2002/09/23 05:51:19 simonb Exp $"); +__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.74 2002/10/23 09:14:02 jdolecek Exp $"); #include #include @@ -109,10 +109,11 @@ dev_type_close(usbclose); dev_type_read(usbread); dev_type_ioctl(usbioctl); dev_type_poll(usbpoll); +dev_type_kqfilter(usbkqfilter); const struct cdevsw usb_cdevsw = { usbopen, usbclose, usbread, nowrite, usbioctl, - nostop, notty, usbpoll, nommap, + nostop, notty, usbpoll, nommap, usbkqfilter, }; Static void usb_discover(void *); @@ -593,6 +594,57 @@ usbpoll(dev_t dev, int events, usb_proc_ptr p) } } +static void +filt_usbrdetach(struct knote *kn) +{ + int s; + + s = splusb(); + SLIST_REMOVE(&usb_selevent.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_usbread(struct knote *kn, long hint) +{ + + if (usb_nevents == 0) + return (0); + + kn->kn_data = sizeof(struct usb_event); + return (1); +} + +static const struct filterops usbread_filtops = + { 1, NULL, filt_usbrdetach, filt_usbread }; + +int +usbkqfilter(dev_t dev, struct knote *kn) +{ + struct klist *klist; + int s; + + switch (kn->kn_filter) { + case EVFILT_READ: + if (minor(dev) != USB_DEV_MINOR) + return (1); + klist = &usb_selevent.si_klist; + kn->kn_fop = &usbread_filtops; + break; + + default: + return (1); + } + + kn->kn_hook = NULL; + + s = splusb(); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + splx(s); + + return (0); +} + /* Explore device tree from the root. */ Static void usb_discover(void *v) @@ -689,7 +741,7 @@ usb_add_event(int type, struct usb_event *uep) } SIMPLEQ_INSERT_TAIL(&usb_events, ueq, next); wakeup(&usb_events); - selwakeup(&usb_selevent); + selnotify(&usb_selevent, 0); if (usb_async_proc != NULL) psignal(usb_async_proc, SIGIO); splx(s); diff --git a/sys/dev/usb/uscanner.c b/sys/dev/usb/uscanner.c index cba5ed0a0e5e..eb54d8184572 100644 --- a/sys/dev/usb/uscanner.c +++ b/sys/dev/usb/uscanner.c @@ -1,4 +1,4 @@ -/* $NetBSD: uscanner.c,v 1.33 2002/09/23 05:51:24 simonb Exp $ */ +/* $NetBSD: uscanner.c,v 1.34 2002/10/23 09:14:03 jdolecek Exp $ */ /* * Copyright (c) 2000 The NetBSD Foundation, Inc. @@ -39,7 +39,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: uscanner.c,v 1.33 2002/09/23 05:51:24 simonb Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uscanner.c,v 1.34 2002/10/23 09:14:03 jdolecek Exp $"); #include #include @@ -230,6 +230,8 @@ struct uscanner_softc { int sc_bulkout_bufferlen; int sc_bulkout_datalen; + struct selinfo sc_selq; + u_char sc_state; #define USCANNER_OPEN 0x01 /* opened */ @@ -244,10 +246,11 @@ dev_type_read(uscannerread); dev_type_write(uscannerwrite); dev_type_ioctl(uscannerioctl); dev_type_poll(uscannerpoll); +dev_type_kqfilter(uscannerkqfilter); const struct cdevsw uscanner_cdevsw = { uscanneropen, uscannerclose, uscannerread, uscannerwrite, - uscannerioctl, nostop, notty, uscannerpoll, nommap, + uscannerioctl, nostop, notty, uscannerpoll, nommap, uscannerkqfilter, }; #elif defined(__OpenBSD__) cdev_decl(uscanner); @@ -703,6 +706,51 @@ uscannerpoll(dev_t dev, int events, usb_proc_ptr p) return (revents); } +static void +filt_uscannerdetach(struct knote *kn) +{ + struct uscanner_softc *sc = kn->kn_hook; + + SLIST_REMOVE(&sc->sc_selq.si_klist, kn, knote, kn_selnext); +} + +static const struct filterops uscanner_seltrue_filtops = + { 1, NULL, filt_uscannerdetach, filt_seltrue }; + +int +uscannerkqfilter(dev_t dev, struct knote *kn) +{ + struct uscanner_softc *sc; + struct klist *klist; + + USB_GET_SC(uscanner, USCANNERUNIT(dev), sc); + + if (sc->sc_dying) + return (1); + + switch (kn->kn_filter) { + case EVFILT_READ: + case EVFILT_WRITE: + /* + * We have no easy way of determining if a read will + * yield any data or a write will happen. + * Pretend they will. + */ + klist = &sc->sc_selq.si_klist; + kn->kn_fop = &uscanner_seltrue_filtops; + break; + + default: + return (1); + } + + kn->kn_hook = sc; + + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + + return (0); +} + int uscannerioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, usb_proc_ptr p) { diff --git a/sys/dev/usb/ustir.c b/sys/dev/usb/ustir.c index 44908039c065..0d6798872f84 100644 --- a/sys/dev/usb/ustir.c +++ b/sys/dev/usb/ustir.c @@ -1,4 +1,4 @@ -/* $NetBSD: ustir.c,v 1.3 2002/07/08 17:46:25 augustss Exp $ */ +/* $NetBSD: ustir.c,v 1.4 2002/10/23 09:14:03 jdolecek Exp $ */ /* * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ustir.c,v 1.3 2002/07/08 17:46:25 augustss Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ustir.c,v 1.4 2002/10/23 09:14:03 jdolecek Exp $"); #include #include @@ -216,6 +216,7 @@ Static int ustir_set_params(void *h, struct irda_params *params); Static int ustir_get_speeds(void *h, int *speeds); Static int ustir_get_turnarounds(void *h, int *times); Static int ustir_poll(void *h, int events, usb_proc_ptr p); +Static int ustir_kqfilter(void *h, struct knote *kn); #ifdef USTIR_DEBUG_IOCTLS Static int ustir_ioctl(void *h, u_long cmd, caddr_t addr, int flag, usb_proc_ptr p); @@ -223,7 +224,8 @@ Static int ustir_ioctl(void *h, u_long cmd, caddr_t addr, int flag, usb_proc_ptr Static struct irframe_methods const ustir_methods = { ustir_open, ustir_close, ustir_read, ustir_write, ustir_poll, - ustir_set_params, ustir_get_speeds, ustir_get_turnarounds, + ustir_kqfilter, ustir_set_params, ustir_get_speeds, + ustir_get_turnarounds, #ifdef USTIR_DEBUG_IOCTLS ustir_ioctl #endif @@ -559,7 +561,7 @@ deframe_rd_ur(struct ustir_softc *sc) case FR_FRAMEOK: sc->sc_ur_framelen = sc->sc_framestate.bufindex; wakeup(&sc->sc_ur_framelen); /* XXX should use flag */ - selwakeup(&sc->sc_rd_sel); + selnotify(&sc->sc_rd_sel, 0); return 1; } } @@ -769,7 +771,7 @@ ustir_rd_cb(usbd_xfer_handle xfer, usbd_private_handle priv, /* Wake up for possible output */ wakeup(&sc->sc_wr_buf); - selwakeup(&sc->sc_wr_sel); + selnotify(&sc->sc_wr_sel, 0); } } @@ -1174,6 +1176,80 @@ ustir_poll(void *h, int events, usb_proc_ptr p) return revents; } +static void +filt_ustirrdetach(struct knote *kn) +{ + struct ustir_softc *sc = kn->kn_hook; + int s; + + s = splusb(); + SLIST_REMOVE(&sc->sc_rd_sel.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_ustirread(struct knote *kn, long hint) +{ + struct ustir_softc *sc = kn->kn_hook; + + kn->kn_data = sc->sc_ur_framelen; + return (kn->kn_data > 0); +} + +static void +filt_ustirwdetach(struct knote *kn) +{ + struct ustir_softc *sc = kn->kn_hook; + int s; + + s = splusb(); + SLIST_REMOVE(&sc->sc_wr_sel.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_ustirwrite(struct knote *kn, long hint) +{ + struct ustir_softc *sc = kn->kn_hook; + + kn->kn_data = 0; + return (sc->sc_direction != udir_input); +} + +static const struct filterops ustirread_filtops = + { 1, NULL, filt_ustirrdetach, filt_ustirread }; +static const struct filterops ustirwrite_filtops = + { 1, NULL, filt_ustirwdetach, filt_ustirwrite }; + +Static int +ustir_kqfilter(void *h, struct knote *kn) +{ + struct ustir_softc *sc = h; + struct klist *klist; + int s; + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &sc->sc_rd_sel.si_klist; + kn->kn_fop = &ustirread_filtops; + break; + case EVFILT_WRITE: + klist = &sc->sc_wr_sel.si_klist; + kn->kn_fop = &ustirwrite_filtops; + break; + default: + return (1); + } + + kn->kn_hook = sc; + + s = splusb(); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + splx(s); + + return (0); +} + #ifdef USTIR_DEBUG_IOCTLS Static int ustir_ioctl(void *h, u_long cmd, caddr_t addr, int flag, usb_proc_ptr p) { diff --git a/sys/dev/vme/xd.c b/sys/dev/vme/xd.c index da5a603222a7..281a1796b247 100644 --- a/sys/dev/vme/xd.c +++ b/sys/dev/vme/xd.c @@ -1,4 +1,4 @@ -/* $NetBSD: xd.c,v 1.45 2002/10/02 16:53:14 thorpej Exp $ */ +/* $NetBSD: xd.c,v 1.46 2002/10/23 09:14:04 jdolecek Exp $ */ /* * @@ -51,7 +51,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: xd.c,v 1.45 2002/10/02 16:53:14 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: xd.c,v 1.46 2002/10/23 09:14:04 jdolecek Exp $"); #undef XDC_DEBUG /* full debug */ #define XDC_DIAG /* extra sanity checks */ @@ -301,7 +301,7 @@ const struct bdevsw xd_bdevsw = { const struct cdevsw xd_cdevsw = { xdopen, xdclose, xdread, xdwrite, xdioctl, - nostop, notty, nopoll, nommap, D_DISK + nostop, notty, nopoll, nommap, nokqfilter, D_DISK }; struct xdc_attach_args { /* this is the "aux" args to xdattach */ diff --git a/sys/dev/vme/xy.c b/sys/dev/vme/xy.c index e7447543d098..0cd0ca25fb23 100644 --- a/sys/dev/vme/xy.c +++ b/sys/dev/vme/xy.c @@ -1,4 +1,4 @@ -/* $NetBSD: xy.c,v 1.45 2002/10/02 16:53:15 thorpej Exp $ */ +/* $NetBSD: xy.c,v 1.46 2002/10/23 09:14:05 jdolecek Exp $ */ /* * @@ -51,7 +51,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: xy.c,v 1.45 2002/10/02 16:53:15 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: xy.c,v 1.46 2002/10/23 09:14:05 jdolecek Exp $"); #undef XYC_DEBUG /* full debug */ #undef XYC_DIAG /* extra sanity checks */ @@ -216,7 +216,7 @@ const struct bdevsw xy_bdevsw = { const struct cdevsw xy_cdevsw = { xyopen, xyclose, xyread, xywrite, xyioctl, - nostop, notty, nopoll, nommap, D_DISK + nostop, notty, nopoll, nommap, nokqfilter, D_DISK }; struct xyc_attach_args { /* this is the "aux" args to xyattach */ diff --git a/sys/dev/vnd.c b/sys/dev/vnd.c index e3a1a93b2ff8..9f0b8d06dc71 100644 --- a/sys/dev/vnd.c +++ b/sys/dev/vnd.c @@ -1,4 +1,4 @@ -/* $NetBSD: vnd.c,v 1.86 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: vnd.c,v 1.87 2002/10/23 09:13:05 jdolecek Exp $ */ /*- * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc. @@ -98,7 +98,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: vnd.c,v 1.86 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vnd.c,v 1.87 2002/10/23 09:13:05 jdolecek Exp $"); #if defined(_KERNEL_OPT) #include "fs_nfs.h" @@ -198,7 +198,7 @@ const struct bdevsw vnd_bdevsw = { const struct cdevsw vnd_cdevsw = { vndopen, vndclose, vndread, vndwrite, vndioctl, - nostop, notty, nopoll, nommap, D_DISK + nostop, notty, nopoll, nommap, nokqfilter, D_DISK }; void diff --git a/sys/dev/wscons/wsdisplay.c b/sys/dev/wscons/wsdisplay.c index f1cd53189a14..3144c00b9fb1 100644 --- a/sys/dev/wscons/wsdisplay.c +++ b/sys/dev/wscons/wsdisplay.c @@ -1,4 +1,4 @@ -/* $NetBSD: wsdisplay.c,v 1.69 2002/10/02 16:53:17 thorpej Exp $ */ +/* $NetBSD: wsdisplay.c,v 1.70 2002/10/23 09:14:06 jdolecek Exp $ */ /* * Copyright (c) 1996, 1997 Christopher G. Demetriou. All rights reserved. @@ -31,7 +31,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: wsdisplay.c,v 1.69 2002/10/02 16:53:17 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: wsdisplay.c,v 1.70 2002/10/23 09:14:06 jdolecek Exp $"); #include "opt_wsdisplay_compat.h" #include "opt_compat_netbsd.h" @@ -158,11 +158,12 @@ dev_type_stop(wsdisplaystop); dev_type_tty(wsdisplaytty); dev_type_poll(wsdisplaypoll); dev_type_mmap(wsdisplaymmap); +dev_type_kqfilter(wsdisplaykqfilter); const struct cdevsw wsdisplay_cdevsw = { wsdisplayopen, wsdisplayclose, wsdisplayread, wsdisplaywrite, wsdisplayioctl, wsdisplaystop, wsdisplaytty, wsdisplaypoll, - wsdisplaymmap, D_TTY + wsdisplaymmap, wsdisplaykqfilter, D_TTY }; static void wsdisplaystart(struct tty *); @@ -869,6 +870,26 @@ wsdisplaypoll(dev_t dev, int events, struct proc *p) return ((*tp->t_linesw->l_poll)(tp, events, p)); } +int +wsdisplaykqfilter(dev, kn) + dev_t dev; + struct knote *kn; +{ + struct wsdisplay_softc *sc = + device_lookup(&wsdisplay_cd, WSDISPLAYUNIT(dev)); + struct wsscreen *scr; + + if (ISWSDISPLAYCTL(dev)) + return (1); + + scr = sc->sc_scr[WSDISPLAYSCREEN(dev)]; + + if (WSSCREEN_HAS_TTY(scr)) + return (ttykqfilter(dev, kn)); + else + return (1); +} + struct tty * wsdisplaytty(dev_t dev) { diff --git a/sys/dev/wscons/wsevent.c b/sys/dev/wscons/wsevent.c index 3005ce3b10df..982060eea62e 100644 --- a/sys/dev/wscons/wsevent.c +++ b/sys/dev/wscons/wsevent.c @@ -1,4 +1,4 @@ -/* $NetBSD: wsevent.c,v 1.10 2002/01/12 16:41:02 tsutsui Exp $ */ +/* $NetBSD: wsevent.c,v 1.11 2002/10/23 09:14:07 jdolecek Exp $ */ /* * Copyright (c) 1996, 1997 Christopher G. Demetriou. All rights reserved. @@ -79,7 +79,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: wsevent.c,v 1.10 2002/01/12 16:41:02 tsutsui Exp $"); +__KERNEL_RCSID(0, "$NetBSD: wsevent.c,v 1.11 2002/10/23 09:14:07 jdolecek Exp $"); #include #include @@ -197,3 +197,61 @@ wsevent_poll(struct wseventvar *ev, int events, struct proc *p) splx(s); return (revents); } + +static void +filt_wseventrdetach(struct knote *kn) +{ + struct wseventvar *ev = kn->kn_hook; + int s; + + s = splwsevent(); + SLIST_REMOVE(&ev->sel.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_wseventread(struct knote *kn, long hint) +{ + struct wseventvar *ev = kn->kn_hook; + + if (ev->get == ev->put) + return (0); + + if (ev->get < ev->put) + kn->kn_data = ev->put - ev->get; + else + kn->kn_data = (WSEVENT_QSIZE - ev->get) + + ev->put; + + kn->kn_data *= sizeof(struct wscons_event); + + return (1); +} + +static const struct filterops wsevent_filtops = + { 1, NULL, filt_wseventrdetach, filt_wseventread }; + +int +wsevent_kqfilter(struct wseventvar *ev, struct knote *kn) +{ + struct klist *klist; + int s; + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &ev->sel.si_klist; + kn->kn_fop = &wsevent_filtops; + break; + + default: + return (1); + } + + kn->kn_hook = ev; + + s = splwsevent(); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + splx(s); + + return (0); +} diff --git a/sys/dev/wscons/wseventvar.h b/sys/dev/wscons/wseventvar.h index 5b69ea6e929e..f019f61c3fb6 100644 --- a/sys/dev/wscons/wseventvar.h +++ b/sys/dev/wscons/wseventvar.h @@ -1,4 +1,4 @@ -/* $NetBSD: wseventvar.h,v 1.4 2001/10/25 14:46:41 augustss Exp $ */ +/* $NetBSD: wseventvar.h,v 1.5 2002/10/23 09:14:07 jdolecek Exp $ */ /* * Copyright (c) 1996, 1997 Christopher G. Demetriou. All rights reserved. @@ -96,7 +96,7 @@ struct wseventvar { #define splwsevent() spltty() #define WSEVENT_WAKEUP(ev) { \ - selwakeup(&(ev)->sel); \ + selnotify(&(ev)->sel, 0); \ if ((ev)->wanted) { \ (ev)->wanted = 0; \ wakeup((ev)); \ @@ -109,6 +109,7 @@ void wsevent_init(struct wseventvar *); void wsevent_fini(struct wseventvar *); int wsevent_read(struct wseventvar *, struct uio *, int); int wsevent_poll(struct wseventvar *, int, struct proc *); +int wsevent_kqfilter(struct wseventvar *ev, struct knote *kn); /* * PWSEVENT is set just above PSOCK, which is just above TTIPRI, on the diff --git a/sys/dev/wscons/wskbd.c b/sys/dev/wscons/wskbd.c index af1bef9adcc7..471898836054 100644 --- a/sys/dev/wscons/wskbd.c +++ b/sys/dev/wscons/wskbd.c @@ -1,4 +1,4 @@ -/* $NetBSD: wskbd.c,v 1.65 2002/10/02 16:53:18 thorpej Exp $ */ +/* $NetBSD: wskbd.c,v 1.66 2002/10/23 09:14:08 jdolecek Exp $ */ /* * Copyright (c) 1996, 1997 Christopher G. Demetriou. All rights reserved. @@ -83,7 +83,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: wskbd.c,v 1.65 2002/10/02 16:53:18 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: wskbd.c,v 1.66 2002/10/23 09:14:08 jdolecek Exp $"); #include "opt_ddb.h" #include "opt_kgdb.h" @@ -246,10 +246,11 @@ dev_type_close(wskbdclose); dev_type_read(wskbdread); dev_type_ioctl(wskbdioctl); dev_type_poll(wskbdpoll); +dev_type_kqfilter(wskbdkqfilter); const struct cdevsw wskbd_cdevsw = { wskbdopen, wskbdclose, wskbdread, nowrite, wskbdioctl, - nostop, notty, wskbdpoll, nommap, + nostop, notty, wskbdpoll, nommap, wskbdkqfilter, }; #ifndef WSKBD_DEFAULT_BELL_PITCH @@ -1090,6 +1091,16 @@ wskbdpoll(dev_t dev, int events, struct proc *p) return (wsevent_poll(sc->sc_base.me_evp, events, p)); } +int +wskbdkqfilter(dev_t dev, struct knote *kn) +{ + struct wskbd_softc *sc = wskbd_cd.cd_devs[minor(dev)]; + + if (sc->sc_base.me_evp == NULL) + return (1); + return (wsevent_kqfilter(sc->sc_base.me_evp, kn)); +} + #if NWSDISPLAY > 0 int diff --git a/sys/dev/wscons/wsmouse.c b/sys/dev/wscons/wsmouse.c index f44ae2c840c6..bab8ff163cba 100644 --- a/sys/dev/wscons/wsmouse.c +++ b/sys/dev/wscons/wsmouse.c @@ -1,4 +1,4 @@ -/* $NetBSD: wsmouse.c,v 1.27 2002/10/02 16:53:19 thorpej Exp $ */ +/* $NetBSD: wsmouse.c,v 1.28 2002/10/23 09:14:08 jdolecek Exp $ */ /* * Copyright (c) 1996, 1997 Christopher G. Demetriou. All rights reserved. @@ -79,7 +79,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: wsmouse.c,v 1.27 2002/10/02 16:53:19 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: wsmouse.c,v 1.28 2002/10/23 09:14:08 jdolecek Exp $"); #include "wsmouse.h" #include "wsdisplay.h" @@ -164,10 +164,11 @@ dev_type_close(wsmouseclose); dev_type_read(wsmouseread); dev_type_ioctl(wsmouseioctl); dev_type_poll(wsmousepoll); +dev_type_kqfilter(wsmousekqfilter); const struct cdevsw wsmouse_cdevsw = { wsmouseopen, wsmouseclose, wsmouseread, nowrite, wsmouseioctl, - nostop, notty, wsmousepoll, nommap, + nostop, notty, wsmousepoll, nommap, wsmousekqfilter, }; #if NWSMUX > 0 @@ -613,6 +614,16 @@ wsmousepoll(dev_t dev, int events, struct proc *p) return (wsevent_poll(sc->sc_base.me_evp, events, p)); } +int +wsmousekqfilter(dev_t dev, struct knote *kn) +{ + struct wsmouse_softc *sc = wsmouse_cd.cd_devs[minor(dev)]; + + if (sc->sc_base.me_evp == NULL) + return (1); + return (wsevent_kqfilter(sc->sc_base.me_evp, kn)); +} + #if NWSMUX > 0 int wsmouse_mux_open(struct wsevsrc *me, struct wseventvar *evp) diff --git a/sys/dev/wscons/wsmux.c b/sys/dev/wscons/wsmux.c index fb49a270ce9e..de4693c114f2 100644 --- a/sys/dev/wscons/wsmux.c +++ b/sys/dev/wscons/wsmux.c @@ -1,4 +1,4 @@ -/* $NetBSD: wsmux.c,v 1.30 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: wsmux.c,v 1.31 2002/10/23 09:14:09 jdolecek Exp $ */ /* * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -44,7 +44,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: wsmux.c,v 1.30 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: wsmux.c,v 1.31 2002/10/23 09:14:09 jdolecek Exp $"); #include "wsdisplay.h" #include "wsmux.h" @@ -123,10 +123,11 @@ dev_type_close(wsmuxclose); dev_type_read(wsmuxread); dev_type_ioctl(wsmuxioctl); dev_type_poll(wsmuxpoll); +dev_type_kqfilter(wsmuxkqfilter); const struct cdevsw wsmux_cdevsw = { wsmuxopen, wsmuxclose, wsmuxread, nowrite, wsmuxioctl, - nostop, notty, wsmuxpoll, nommap, + nostop, notty, wsmuxpoll, nommap, wsmuxkqfilter, }; struct wssrcops wsmux_srcops = { @@ -574,6 +575,30 @@ wsmuxpoll(dev_t dev, int events, struct proc *p) return (wsevent_poll(sc->sc_base.me_evp, events, p)); } +/* + * kqfilter() of the pseudo device from device table. + */ +int +wsmuxkqfilter(dev_t dev, struct knote *kn) +{ + int minr = minor(dev); + struct wsmux_softc *sc = wsmuxdevs[WSMUXDEV(minr)]; + + if (WSMUXCTL(minr)) { + /* control device */ + return (1); + } + + if (sc->sc_base.me_evp == NULL) { +#ifdef DIAGNOSTIC + printf("wsmuxkqfilter: not open\n"); +#endif + return (1); + } + + return (wsevent_kqfilter(sc->sc_base.me_evp, kn)); +} + /* * Add mux unit as a child to muxsc. */ diff --git a/sys/dev/wsfont/wsfontdev.c b/sys/dev/wsfont/wsfontdev.c index e58e7751c31b..48d07bd9ab33 100644 --- a/sys/dev/wsfont/wsfontdev.c +++ b/sys/dev/wsfont/wsfontdev.c @@ -1,4 +1,4 @@ -/* $NetBSD: wsfontdev.c,v 1.5 2002/09/23 05:51:18 simonb Exp $ */ +/* $NetBSD: wsfontdev.c,v 1.6 2002/10/23 09:14:10 jdolecek Exp $ */ /* * Copyright (c) 2001 @@ -27,13 +27,14 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: wsfontdev.c,v 1.5 2002/09/23 05:51:18 simonb Exp $"); +__KERNEL_RCSID(0, "$NetBSD: wsfontdev.c,v 1.6 2002/10/23 09:14:10 jdolecek Exp $"); #include #include #include #include #include +#include #include #include /* XXX */ @@ -46,7 +47,7 @@ dev_type_ioctl(wsfontioctl); const struct cdevsw wsfont_cdevsw = { wsfontopen, wsfontclose, noread, nowrite, wsfontioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; static int wsfont_isopen; diff --git a/sys/filecorefs/filecore_vnops.c b/sys/filecorefs/filecore_vnops.c index bf3934ab912a..54644fac28a5 100644 --- a/sys/filecorefs/filecore_vnops.c +++ b/sys/filecorefs/filecore_vnops.c @@ -1,4 +1,4 @@ -/* $NetBSD: filecore_vnops.c,v 1.16 2001/11/12 23:04:11 lukem Exp $ */ +/* $NetBSD: filecore_vnops.c,v 1.17 2002/10/23 09:14:10 jdolecek Exp $ */ /*- * Copyright (c) 1998 Andrew McMurry @@ -37,7 +37,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: filecore_vnops.c,v 1.16 2001/11/12 23:04:11 lukem Exp $"); +__KERNEL_RCSID(0, "$NetBSD: filecore_vnops.c,v 1.17 2002/10/23 09:14:10 jdolecek Exp $"); #include #include @@ -544,6 +544,7 @@ const struct vnodeopv_entry_desc filecore_vnodeop_entries[] = { { &vop_fcntl_desc, filecore_fcntl }, /* fcntl */ { &vop_ioctl_desc, filecore_ioctl }, /* ioctl */ { &vop_poll_desc, filecore_poll }, /* poll */ + { &vop_kqfilter_desc, genfs_kqfilter }, /* kqfilter */ { &vop_revoke_desc, filecore_revoke }, /* revoke */ { &vop_mmap_desc, filecore_mmap }, /* mmap */ { &vop_fsync_desc, filecore_fsync }, /* fsync */ diff --git a/sys/isofs/cd9660/cd9660_vnops.c b/sys/isofs/cd9660/cd9660_vnops.c index 24fa6f3c8e43..3ef90696a90d 100644 --- a/sys/isofs/cd9660/cd9660_vnops.c +++ b/sys/isofs/cd9660/cd9660_vnops.c @@ -1,4 +1,4 @@ -/* $NetBSD: cd9660_vnops.c,v 1.71 2001/11/17 18:56:46 perry Exp $ */ +/* $NetBSD: cd9660_vnops.c,v 1.72 2002/10/23 09:14:11 jdolecek Exp $ */ /*- * Copyright (c) 1994 @@ -41,7 +41,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cd9660_vnops.c,v 1.71 2001/11/17 18:56:46 perry Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cd9660_vnops.c,v 1.72 2002/10/23 09:14:11 jdolecek Exp $"); #include #include @@ -973,6 +973,7 @@ const struct vnodeopv_entry_desc cd9660_specop_entries[] = { { &vop_fcntl_desc, genfs_fcntl }, /* fcntl */ { &vop_ioctl_desc, spec_ioctl }, /* ioctl */ { &vop_poll_desc, spec_poll }, /* poll */ + { &vop_kqfilter_desc, spec_kqfilter }, /* kqfilter */ { &vop_revoke_desc, spec_revoke }, /* revoke */ { &vop_mmap_desc, spec_mmap }, /* mmap */ { &vop_fsync_desc, spec_fsync }, /* fsync */ @@ -1026,6 +1027,7 @@ const struct vnodeopv_entry_desc cd9660_fifoop_entries[] = { { &vop_fcntl_desc, genfs_fcntl }, /* fcntl */ { &vop_ioctl_desc, fifo_ioctl }, /* ioctl */ { &vop_poll_desc, fifo_poll }, /* poll */ + { &vop_kqfilter_desc, fifo_kqfilter }, /* kqfilter */ { &vop_revoke_desc, fifo_revoke }, /* revoke */ { &vop_mmap_desc, fifo_mmap }, /* mmap */ { &vop_fsync_desc, fifo_fsync }, /* fsync */ diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c index 0717964c20a1..8c67e992ee3c 100644 --- a/sys/kern/init_main.c +++ b/sys/kern/init_main.c @@ -1,4 +1,4 @@ -/* $NetBSD: init_main.c,v 1.208 2002/10/01 18:11:58 thorpej Exp $ */ +/* $NetBSD: init_main.c,v 1.209 2002/10/23 09:14:12 jdolecek Exp $ */ /* * Copyright (c) 1995 Christopher G. Demetriou. All rights reserved. @@ -42,7 +42,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.208 2002/10/01 18:11:58 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.209 2002/10/23 09:14:12 jdolecek Exp $"); #include "fs_nfs.h" #include "opt_nfsserver.h" @@ -81,6 +81,7 @@ __KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.208 2002/10/01 18:11:58 thorpej Exp #include #include #include +#include #ifdef SYSVSHM #include #endif @@ -212,6 +213,9 @@ main(void) */ mbinit(); + /* Initialize kqueues. */ + kqueue_init(); + /* Initialize sockets. */ soinit(); diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index 6b8c1e406e33..5f03449a136f 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -1,4 +1,4 @@ -/* $NetBSD: kern_descrip.c,v 1.95 2002/09/23 04:19:16 simonb Exp $ */ +/* $NetBSD: kern_descrip.c,v 1.96 2002/10/23 09:14:13 jdolecek Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1991, 1993 @@ -41,7 +41,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_descrip.c,v 1.95 2002/09/23 04:19:16 simonb Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_descrip.c,v 1.96 2002/10/23 09:14:13 jdolecek Exp $"); #include #include @@ -62,6 +62,7 @@ __KERNEL_RCSID(0, "$NetBSD: kern_descrip.c,v 1.95 2002/09/23 04:19:16 simonb Exp #include #include #include +#include #include #include @@ -84,7 +85,7 @@ dev_type_open(filedescopen); const struct cdevsw filedesc_cdevsw = { filedescopen, noclose, noread, nowrite, noioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; static __inline void @@ -463,6 +464,8 @@ finishdup(struct proc *p, int old, int new, register_t *retval) if (delfp != NULL) { FILE_USE(delfp); + if (new < fdp->fd_knlistsize) + knote_fdclose(p, new); (void) closef(delfp, p); } return (0); @@ -492,6 +495,8 @@ fdrelease(struct proc *p, int fd) *fpp = NULL; fdp->fd_ofileflags[fd] = 0; + if (fd < fdp->fd_knlistsize) + knote_fdclose(p, fd); fd_unused(fdp, fd); return (closef(fp, p)); } @@ -593,6 +598,10 @@ sys_fpathconf(struct proc *p, void *v, register_t *retval) error = VOP_PATHCONF(vp, SCARG(uap, name), retval); break; + case DTYPE_KQUEUE: + error = EINVAL; + break; + default: error = EOPNOTSUPP; break; @@ -884,6 +893,7 @@ fdinit1(struct filedesc0 *newfdp) newfdp->fd_fd.fd_ofiles = newfdp->fd_dfiles; newfdp->fd_fd.fd_ofileflags = newfdp->fd_dfileflags; newfdp->fd_fd.fd_nfiles = NDFILE; + newfdp->fd_fd.fd_knlistsize = -1; } /* @@ -968,6 +978,20 @@ fdcopy(struct proc *p) newfdp->fd_nfiles = i; memcpy(newfdp->fd_ofiles, fdp->fd_ofiles, i * sizeof(struct file **)); memcpy(newfdp->fd_ofileflags, fdp->fd_ofileflags, i * sizeof(char)); + /* + * kq descriptors cannot be copied. + */ + if (newfdp->fd_knlistsize != -1) { + fpp = newfdp->fd_ofiles; + for (i = newfdp->fd_lastfile; i-- >= 0; fpp++) { + if (*fpp != NULL && (*fpp)->f_type == DTYPE_KQUEUE) + *fpp = NULL; + } + newfdp->fd_knlist = NULL; + newfdp->fd_knlistsize = -1; + newfdp->fd_knhash = NULL; + newfdp->fd_knhashmask = 0; + } fpp = newfdp->fd_ofiles; for (i = newfdp->fd_lastfile; i >= 0; i--, fpp++) if (*fpp != NULL) @@ -994,12 +1018,18 @@ fdfree(struct proc *p) if (fp != NULL) { *fpp = NULL; FILE_USE(fp); + if (i < fdp->fd_knlistsize) + knote_fdclose(p, fdp->fd_lastfile - i); (void) closef(fp, p); } } p->p_fd = NULL; if (fdp->fd_nfiles > NDFILE) free(fdp->fd_ofiles, M_FILEDESC); + if (fdp->fd_knlist) + free(fdp->fd_knlist, M_KEVENT); + if (fdp->fd_knhash) + hashdone(fdp->fd_knhash, M_KEVENT); pool_put(&filedesc0_pool, fdp); } diff --git a/sys/kern/kern_event.c b/sys/kern/kern_event.c new file mode 100644 index 000000000000..36ecfef35f35 --- /dev/null +++ b/sys/kern/kern_event.c @@ -0,0 +1,1319 @@ +/* $NetBSD: kern_event.c,v 1.3 2002/10/23 09:14:14 jdolecek Exp $ */ +/*- + * Copyright (c) 1999,2000,2001 Jonathan Lemon + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: src/sys/kern/kern_event.c,v 1.27 2001/07/05 17:10:44 rwatson Exp $ + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static int kqueue_scan(struct file *fp, size_t maxevents, + struct kevent *ulistp, const struct timespec *timeout, + struct proc *p, register_t *retval); +static void kqueue_wakeup(struct kqueue *kq); + +static int kqueue_read(struct file *fp, off_t *offset, struct uio *uio, + struct ucred *cred, int flags); +static int kqueue_write(struct file *fp, off_t *offset, struct uio *uio, + struct ucred *cred, int flags); +static int kqueue_ioctl(struct file *fp, u_long com, caddr_t data, + struct proc *p); +static int kqueue_fcntl(struct file *fp, u_int com, caddr_t data, + struct proc *p); +static int kqueue_poll(struct file *fp, int events, struct proc *p); +static int kqueue_kqfilter(struct file *fp, struct knote *kn); +static int kqueue_stat(struct file *fp, struct stat *sp, struct proc *p); +static int kqueue_close(struct file *fp, struct proc *p); + +static struct fileops kqueueops = { + kqueue_read, kqueue_write, kqueue_ioctl, kqueue_fcntl, kqueue_poll, + kqueue_stat, kqueue_close, kqueue_kqfilter +}; + +static void knote_attach(struct knote *kn, struct filedesc *fdp); +static void knote_drop(struct knote *kn, struct proc *p, + struct filedesc *fdp); +static void knote_enqueue(struct knote *kn); +static void knote_dequeue(struct knote *kn); + +static void filt_kqdetach(struct knote *kn); +static int filt_kqueue(struct knote *kn, long hint); +static int filt_procattach(struct knote *kn); +static void filt_procdetach(struct knote *kn); +static int filt_proc(struct knote *kn, long hint); +static int filt_fileattach(struct knote *kn); + +static const struct filterops kqread_filtops = + { 1, NULL, filt_kqdetach, filt_kqueue }; +static const struct filterops proc_filtops = + { 0, filt_procattach, filt_procdetach, filt_proc }; +static const struct filterops file_filtops = + { 1, filt_fileattach, NULL, NULL }; + +struct pool kqueue_pool; +struct pool knote_pool; + +#define KNOTE_ACTIVATE(kn) \ +do { \ + kn->kn_status |= KN_ACTIVE; \ + if ((kn->kn_status & (KN_QUEUED | KN_DISABLED)) == 0) \ + knote_enqueue(kn); \ +} while(0) + +#define KN_HASHSIZE 64 /* XXX should be tunable */ +#define KN_HASH(val, mask) (((val) ^ (val >> 8)) & (mask)) + +extern const struct filterops sig_filtops; + +/* + * Table for for all system-defined filters. + * These should be listed in the numeric order of the EVFILT_* defines. + * If filtops is NULL, the filter isn't implemented in NetBSD. + * End of list is when name is NULL. + */ +struct kfilter { + const char *name; /* name of filter */ + uint32_t filter; /* id of filter */ + const struct filterops *filtops;/* operations for filter */ +}; + + /* System defined filters */ +static const struct kfilter sys_kfilters[] = { + { "EVFILT_READ", EVFILT_READ, &file_filtops }, + { "EVFILT_WRITE", EVFILT_WRITE, &file_filtops }, + { "EVFILT_AIO", EVFILT_AIO, NULL }, + { "EVFILT_VNODE", EVFILT_VNODE, &file_filtops }, + { "EVFILT_PROC", EVFILT_PROC, &proc_filtops }, + { "EVFILT_SIGNAL", EVFILT_SIGNAL, &sig_filtops }, + { NULL, 0, NULL }, /* end of list */ +}; + + /* User defined kfilters */ +static struct kfilter *user_kfilters; /* array */ +static int user_kfilterc; /* current offset */ +static int user_kfiltermaxc; /* max size so far */ + +/* + * kqueue_init: + * + * Initialize the kqueue/knote facility. + */ +void +kqueue_init(void) +{ + + pool_init(&kqueue_pool, sizeof(struct kqueue), 0, 0, 0, "kqueuepl", + NULL); + pool_init(&knote_pool, sizeof(struct knote), 0, 0, 0, "knotepl", + NULL); +} + +/* + * Find kfilter entry by name, or NULL if not found. + */ +static const struct kfilter * +kfilter_byname_sys(const char *name) +{ + int i; + + for (i = 0; sys_kfilters[i].name != NULL; i++) { + if (strcmp(name, sys_kfilters[i].name) == 0) + return (&sys_kfilters[i]); + } + return (NULL); +} + +static struct kfilter * +kfilter_byname_user(const char *name) +{ + int i; + + /* user_kfilters[] could be NULL if no filters were registered */ + if (!user_kfilters) + return (NULL); + + for (i = 0; user_kfilters[i].name != NULL; i++) { + if (user_kfilters[i].name != '\0' && + strcmp(name, user_kfilters[i].name) == 0) + return (&user_kfilters[i]); + } + return (NULL); +} + +static const struct kfilter * +kfilter_byname(const char *name) +{ + const struct kfilter *kfilter; + + if ((kfilter = kfilter_byname_sys(name)) != NULL) + return (kfilter); + + return (kfilter_byname_user(name)); +} + +/* + * Find kfilter entry by filter id, or NULL if not found. + * Assumes entries are indexed in filter id order, for speed. + */ +static const struct kfilter * +kfilter_byfilter(uint32_t filter) +{ + const struct kfilter *kfilter; + + if (filter < EVFILT_SYSCOUNT) /* it's a system filter */ + kfilter = &sys_kfilters[filter]; + else if (user_kfilters != NULL && + filter < EVFILT_SYSCOUNT + user_kfilterc) + /* it's a user filter */ + kfilter = &user_kfilters[filter - EVFILT_SYSCOUNT]; + else + return (NULL); /* out of range */ + KASSERT(kfilter->filter == filter); /* sanity check! */ + return (kfilter); +} + +/* + * Register a new kfilter. Stores the entry in user_kfilters. + * Returns 0 if operation succeeded, or an appropriate errno(2) otherwise. + * If retfilter != NULL, the new filterid is returned in it. + */ +int +kfilter_register(const char *name, const struct filterops *filtops, + int *retfilter) +{ + struct kfilter *kfilter; + void *space; + int len; + + if (name == NULL || name[0] == '\0' || filtops == NULL) + return (EINVAL); /* invalid args */ + if (kfilter_byname(name) != NULL) + return (EEXIST); /* already exists */ + if (user_kfilterc > 0xffffffff - EVFILT_SYSCOUNT) + return (EINVAL); /* too many */ + + /* check if need to grow user_kfilters */ + if (user_kfilterc + 1 > user_kfiltermaxc) { + /* + * Grow in KFILTER_EXTENT chunks. Use malloc(9), because we + * want to traverse user_kfilters as an array. + */ + user_kfiltermaxc += KFILTER_EXTENT; + kfilter = malloc(user_kfiltermaxc * sizeof(struct filter *), + M_KEVENT, M_WAITOK); + + /* copy existing user_kfilters */ + if (user_kfilters != NULL) + memcpy((caddr_t)kfilter, (caddr_t)user_kfilters, + user_kfilterc * sizeof(struct kfilter *)); + /* zero new sections */ + memset((caddr_t)kfilter + + user_kfilterc * sizeof(struct kfilter *), 0, + (user_kfiltermaxc - user_kfilterc) * + sizeof(struct kfilter *)); + /* switch to new kfilter */ + if (user_kfilters != NULL) + free(user_kfilters, M_KEVENT); + user_kfilters = kfilter; + } + len = strlen(name) + 1; /* copy name */ + space = malloc(len, M_KEVENT, M_WAITOK); + memcpy(space, name, len); + user_kfilters[user_kfilterc].name = space; + + user_kfilters[user_kfilterc].filter = user_kfilterc + EVFILT_SYSCOUNT; + + len = sizeof(struct filterops); /* copy filtops */ + space = malloc(len, M_KEVENT, M_WAITOK); + memcpy(space, filtops, len); + user_kfilters[user_kfilterc].filtops = space; + + if (retfilter != NULL) + *retfilter = user_kfilters[user_kfilterc].filter; + user_kfilterc++; /* finally, increment count */ + return (0); +} + +/* + * Unregister a kfilter previously registered with kfilter_register. + * This retains the filter id, but clears the name and frees filtops (filter + * operations), so that the number isn't reused during a boot. + * Returns 0 if operation succeeded, or an appropriate errno(2) otherwise. + */ +int +kfilter_unregister(const char *name) +{ + struct kfilter *kfilter; + + if (name == NULL || name[0] == '\0') + return (EINVAL); /* invalid name */ + + if (kfilter_byname_sys(name) != NULL) + return (EINVAL); /* can't detach system filters */ + + kfilter = kfilter_byname_user(name); + if (kfilter == NULL) /* not found */ + return (ENOENT); + + if (kfilter->name[0] != '\0') { + /* XXX Cast away const (but we know it's safe. */ + free((void *) kfilter->name, M_KEVENT); + kfilter->name = ""; /* mark as `not implemented' */ + } + if (kfilter->filtops != NULL) { + /* XXX Cast away const (but we know it's safe. */ + free((void *) kfilter->filtops, M_KEVENT); + kfilter->filtops = NULL; /* mark as `not implemented' */ + } + return (0); +} + + +/* + * Filter attach method for EVFILT_READ and EVFILT_WRITE on normal file + * descriptors. Calls struct fileops kqfilter method for given file descriptor. + */ +static int +filt_fileattach(struct knote *kn) +{ + struct file *fp; + + fp = kn->kn_fp; + return ((*fp->f_ops->fo_kqfilter)(fp, kn)); +} + +/* + * Filter detach method for EVFILT_READ on kqueue descriptor. + */ +static void +filt_kqdetach(struct knote *kn) +{ + struct kqueue *kq; + + kq = (struct kqueue *)kn->kn_fp->f_data; + SLIST_REMOVE(&kq->kq_sel.si_klist, kn, knote, kn_selnext); +} + +/* + * Filter event method for EVFILT_READ on kqueue descriptor. + */ +/*ARGSUSED*/ +static int +filt_kqueue(struct knote *kn, long hint) +{ + struct kqueue *kq; + + kq = (struct kqueue *)kn->kn_fp->f_data; + kn->kn_data = kq->kq_count; + return (kn->kn_data > 0); +} + +/* + * Filter attach method for EVFILT_PROC. + */ +static int +filt_procattach(struct knote *kn) +{ + struct proc *p; + + p = pfind(kn->kn_id); + if (p == NULL) + return (ESRCH); + + /* + * Fail if it's not owned by you, or the last exec gave us + * setuid/setgid privs (unless you're root). + */ + if ((p->p_cred->p_ruid != curproc->p_cred->p_ruid || + (p->p_flag & P_SUGID)) + && suser(curproc->p_ucred, &curproc->p_acflag) != 0) + return (EACCES); + + kn->kn_ptr.p_proc = p; + kn->kn_flags |= EV_CLEAR; /* automatically set */ + + /* + * internal flag indicating registration done by kernel + */ + if (kn->kn_flags & EV_FLAG1) { + kn->kn_data = kn->kn_sdata; /* ppid */ + kn->kn_fflags = NOTE_CHILD; + kn->kn_flags &= ~EV_FLAG1; + } + + /* XXXSMP lock the process? */ + SLIST_INSERT_HEAD(&p->p_klist, kn, kn_selnext); + + return (0); +} + +/* + * Filter detach method for EVFILT_PROC. + * + * The knote may be attached to a different process, which may exit, + * leaving nothing for the knote to be attached to. So when the process + * exits, the knote is marked as DETACHED and also flagged as ONESHOT so + * it will be deleted when read out. However, as part of the knote deletion, + * this routine is called, so a check is needed to avoid actually performing + * a detach, because the original process might not exist any more. + */ +static void +filt_procdetach(struct knote *kn) +{ + struct proc *p; + + if (kn->kn_status & KN_DETACHED) + return; + + p = kn->kn_ptr.p_proc; + KASSERT(p->p_stat == SDEAD || pfind(kn->kn_id) == p); + + /* XXXSMP lock the process? */ + SLIST_REMOVE(&p->p_klist, kn, knote, kn_selnext); +} + +/* + * Filter event method for EVFILT_PROC. + */ +static int +filt_proc(struct knote *kn, long hint) +{ + u_int event; + + /* + * mask off extra data + */ + event = (u_int)hint & NOTE_PCTRLMASK; + + /* + * if the user is interested in this event, record it. + */ + if (kn->kn_sfflags & event) + kn->kn_fflags |= event; + + /* + * process is gone, so flag the event as finished. + */ + if (event == NOTE_EXIT) { + /* + * Detach the knote from watched process and mark + * it as such. We can't leave this to kqueue_scan(), + * since the process might not exist by then. And we + * have to do this now, since psignal KNOTE() is called + * also for zombies and we might end up reading freed + * memory if the kevent would already be picked up + * and knote g/c'ed. + */ + kn->kn_fop->f_detach(kn); + kn->kn_status |= KN_DETACHED; + + /* Mark as ONESHOT, so that the knote it g/c'ed when read */ + kn->kn_flags |= (EV_EOF | EV_ONESHOT); + return (1); + } + + /* + * process forked, and user wants to track the new process, + * so attach a new knote to it, and immediately report an + * event with the parent's pid. + */ + if ((event == NOTE_FORK) && (kn->kn_sfflags & NOTE_TRACK)) { + struct kevent kev; + int error; + + /* + * register knote with new process. + */ + kev.ident = hint & NOTE_PDATAMASK; /* pid */ + kev.filter = kn->kn_filter; + kev.flags = kn->kn_flags | EV_ADD | EV_ENABLE | EV_FLAG1; + kev.fflags = kn->kn_sfflags; + kev.data = kn->kn_id; /* parent */ + kev.udata = kn->kn_kevent.udata; /* preserve udata */ + error = kqueue_register(kn->kn_kq, &kev, NULL); + if (error) + kn->kn_fflags |= NOTE_TRACKERR; + } + + return (kn->kn_fflags != 0); +} + +/* + * filt_seltrue: + * + * This filter "event" routine simulates seltrue(). + */ +int +filt_seltrue(struct knote *kn, long hint) +{ + + /* + * We don't know how much data can be read/written, + * but we know that it *can* be. This is about as + * good as select/poll does as well. + */ + kn->kn_data = 0; + return (1); +} + +/* + * This provides full kqfilter entry for device switch tables, which + * has same effect as filter using filt_seltrue() as filter method. + */ +static void +filt_seltruedetach(struct knote *kn) +{ + /* Nothing to do */ +} + +static const struct filterops seltrue_filtops = + { 1, NULL, filt_seltruedetach, filt_seltrue }; + +int +seltrue_kqfilter(dev_t dev, struct knote *kn) +{ + switch (kn->kn_filter) { + case EVFILT_READ: + case EVFILT_WRITE: + kn->kn_fop = &seltrue_filtops; + break; + default: + return (1); + } + + /* Nothing more to do */ + return (0); +} + +/* + * kqueue(2) system call. + */ +int +sys_kqueue(struct proc *p, void *v, register_t *retval) +{ + struct filedesc *fdp; + struct kqueue *kq; + struct file *fp; + int fd, error; + + fdp = p->p_fd; + error = falloc(p, &fp, &fd); /* setup a new file descriptor */ + if (error) + return (error); + fp->f_flag = FREAD | FWRITE; + fp->f_type = DTYPE_KQUEUE; + fp->f_ops = &kqueueops; + kq = pool_get(&kqueue_pool, PR_WAITOK); + memset((char *)kq, 0, sizeof(struct kqueue)); + TAILQ_INIT(&kq->kq_head); + fp->f_data = (caddr_t)kq; /* store the kqueue with the fp */ + *retval = fd; + if (fdp->fd_knlistsize < 0) + fdp->fd_knlistsize = 0; /* this process has a kq */ + kq->kq_fdp = fdp; + FILE_SET_MATURE(fp); + FILE_UNUSE(fp, p); /* falloc() does FILE_USE() */ + return (error); +} + +/* + * kevent(2) system call. + */ +int +sys_kevent(struct proc *p, void *v, register_t *retval) +{ + struct sys_kevent_args /* { + syscallarg(int) fd; + syscallarg(const struct kevent *) changelist; + syscallarg(size_t) nchanges; + syscallarg(struct kevent *) eventlist; + syscallarg(size_t) nevents; + syscallarg(const struct timespec *) timeout; + } */ *uap = v; + struct kevent *kevp; + struct kqueue *kq; + struct file *fp; + struct timespec ts; + size_t i, n; + int nerrors, error; + + /* check that we're dealing with a kq */ + fp = fd_getfile(p->p_fd, SCARG(uap, fd)); + if (!fp || fp->f_type != DTYPE_KQUEUE) + return (EBADF); + + FILE_USE(fp); + + if (SCARG(uap, timeout) != NULL) { + error = copyin(SCARG(uap, timeout), &ts, sizeof(ts)); + if (error) + goto done; + SCARG(uap, timeout) = &ts; + } + + kq = (struct kqueue *)fp->f_data; + nerrors = 0; + + /* traverse list of events to register */ + while (SCARG(uap, nchanges) > 0) { + /* copyin a maximum of KQ_EVENTS at each pass */ + n = MIN(SCARG(uap, nchanges), KQ_NEVENTS); + error = copyin(SCARG(uap, changelist), kq->kq_kev, + n * sizeof(struct kevent)); + if (error) + goto done; + for (i = 0; i < n; i++) { + kevp = &kq->kq_kev[i]; + kevp->flags &= ~EV_SYSFLAGS; + /* register each knote */ + error = kqueue_register(kq, kevp, p); + if (error) { + if (SCARG(uap, nevents) != 0) { + kevp->flags = EV_ERROR; + kevp->data = error; + error = copyout((caddr_t)kevp, + (caddr_t)SCARG(uap, eventlist), + sizeof(*kevp)); + if (error) + goto done; + SCARG(uap, eventlist)++; + SCARG(uap, nevents)--; + nerrors++; + } else { + goto done; + } + } + } + SCARG(uap, nchanges) -= n; /* update the results */ + SCARG(uap, changelist) += n; + } + if (nerrors) { + *retval = nerrors; + error = 0; + goto done; + } + + /* actually scan through the events */ + error = kqueue_scan(fp, SCARG(uap, nevents), SCARG(uap, eventlist), + SCARG(uap, timeout), p, retval); + done: + FILE_UNUSE(fp, p); + return (error); +} + +/* + * Register a given kevent kev onto the kqueue + */ +int +kqueue_register(struct kqueue *kq, struct kevent *kev, struct proc *p) +{ + const struct kfilter *kfilter; + struct filedesc *fdp; + struct file *fp; + struct knote *kn; + int s, error; + + fdp = kq->kq_fdp; + fp = NULL; + kn = NULL; + error = 0; + kfilter = kfilter_byfilter(kev->filter); + if (kfilter == NULL || kfilter->filtops == NULL) { + /* filter not found nor implemented */ + return (EINVAL); + } + + /* search if knote already exists */ + if (kfilter->filtops->f_isfd) { + /* monitoring a file descriptor */ + if ((fp = fd_getfile(fdp, kev->ident)) == NULL) + return (EBADF); /* validate descriptor */ + FILE_USE(fp); + + if (kev->ident < fdp->fd_knlistsize) { + SLIST_FOREACH(kn, &fdp->fd_knlist[kev->ident], kn_link) + if (kq == kn->kn_kq && + kev->filter == kn->kn_filter) + break; + } + } else { + /* + * not monitoring a file descriptor, so + * lookup knotes in internal hash table + */ + if (fdp->fd_knhashmask != 0) { + struct klist *list; + + list = &fdp->fd_knhash[ + KN_HASH((u_long)kev->ident, fdp->fd_knhashmask)]; + SLIST_FOREACH(kn, list, kn_link) + if (kev->ident == kn->kn_id && + kq == kn->kn_kq && + kev->filter == kn->kn_filter) + break; + } + } + + if (kn == NULL && ((kev->flags & EV_ADD) == 0)) { + error = ENOENT; /* filter not found */ + goto done; + } + + /* + * kn now contains the matching knote, or NULL if no match + */ + if (kev->flags & EV_ADD) { + /* add knote */ + + if (kn == NULL) { + /* create new knote */ + kn = pool_get(&knote_pool, PR_WAITOK); + if (kn == NULL) { + error = ENOMEM; + goto done; + } + kn->kn_fp = fp; + kn->kn_kq = kq; + kn->kn_fop = kfilter->filtops; + + /* + * apply reference count to knote structure, and + * do not release it at the end of this routine. + */ + fp = NULL; + + kn->kn_sfflags = kev->fflags; + kn->kn_sdata = kev->data; + kev->fflags = 0; + kev->data = 0; + kn->kn_kevent = *kev; + + knote_attach(kn, fdp); + if ((error = kfilter->filtops->f_attach(kn)) != 0) { + knote_drop(kn, p, fdp); + goto done; + } + } else { + /* modify existing knote */ + + /* + * The user may change some filter values after the + * initial EV_ADD, but doing so will not reset any + * filter which have already been triggered. + */ + kn->kn_sfflags = kev->fflags; + kn->kn_sdata = kev->data; + kn->kn_kevent.udata = kev->udata; + } + + s = splhigh(); + if (kn->kn_fop->f_event(kn, 0)) + KNOTE_ACTIVATE(kn); + splx(s); + + } else if (kev->flags & EV_DELETE) { /* delete knote */ + kn->kn_fop->f_detach(kn); + knote_drop(kn, p, fdp); + goto done; + } + + /* disable knote */ + if ((kev->flags & EV_DISABLE) && + ((kn->kn_status & KN_DISABLED) == 0)) { + s = splhigh(); + kn->kn_status |= KN_DISABLED; + splx(s); + } + + /* enable knote */ + if ((kev->flags & EV_ENABLE) && (kn->kn_status & KN_DISABLED)) { + s = splhigh(); + kn->kn_status &= ~KN_DISABLED; + if ((kn->kn_status & KN_ACTIVE) && + ((kn->kn_status & KN_QUEUED) == 0)) + knote_enqueue(kn); + splx(s); + } + + done: + if (fp != NULL) + FILE_UNUSE(fp, p); + return (error); +} + +/* + * Scan through the list of events on fp (for a maximum of maxevents), + * returning the results in to ulistp. Timeout is determined by tsp; if + * NULL, wait indefinitely, if 0 valued, perform a poll, otherwise wait + * as appropriate. + */ +static int +kqueue_scan(struct file *fp, size_t maxevents, struct kevent *ulistp, + const struct timespec *tsp, struct proc *p, register_t *retval) +{ + struct kqueue *kq; + struct kevent *kevp; + struct timeval atv; + struct knote *kn, marker; + size_t count, nkev; + int s, timeout, error; + + kq = (struct kqueue *)fp->f_data; + count = maxevents; + nkev = error = 0; + if (count == 0) + goto done; + + if (tsp != NULL) { /* timeout supplied */ + TIMESPEC_TO_TIMEVAL(&atv, tsp); + if (itimerfix(&atv)) { + error = EINVAL; + goto done; + } + s = splclock(); + timeradd(&atv, &time, &atv); /* calc. time to wait until */ + splx(s); + if (tsp->tv_sec == 0 && tsp->tv_nsec == 0) + timeout = -1; /* perform a poll */ + else + timeout = hzto(&atv); /* calculate hz till timeout */ + } else { + atv.tv_sec = 0; /* no timeout, wait forever */ + atv.tv_usec = 0; + timeout = 0; + } + goto start; + + retry: + if (atv.tv_sec || atv.tv_usec) { /* timeout requested */ + s = splclock(); + if (timercmp(&time, &atv, >=)) { + splx(s); + goto done; /* timeout reached */ + } + splx(s); + timeout = hzto(&atv); /* recalc. timeout remaining */ + } + + start: + kevp = kq->kq_kev; + s = splhigh(); + if (kq->kq_count == 0) { + if (timeout < 0) { + error = EWOULDBLOCK; + } else { + kq->kq_state |= KQ_SLEEP; + error = tsleep(kq, PSOCK | PCATCH, "kqread", timeout); + } + splx(s); + if (error == 0) + goto retry; + /* don't restart after signals... */ + if (error == ERESTART) + error = EINTR; + else if (error == EWOULDBLOCK) + error = 0; + goto done; + } + + /* mark end of knote list */ + TAILQ_INSERT_TAIL(&kq->kq_head, &marker, kn_tqe); + + while (count) { /* while user wants data ... */ + kn = TAILQ_FIRST(&kq->kq_head); /* get next knote */ + TAILQ_REMOVE(&kq->kq_head, kn, kn_tqe); + if (kn == &marker) { /* if it's our marker, stop */ + splx(s); + if (count == maxevents) + goto retry; + goto done; + } + if (kn->kn_status & KN_DISABLED) { + /* don't want disabled events */ + kn->kn_status &= ~KN_QUEUED; + kq->kq_count--; + continue; + } + if ((kn->kn_flags & EV_ONESHOT) == 0 && + kn->kn_fop->f_event(kn, 0) == 0) { + /* + * non-ONESHOT event that hasn't + * triggered again, so de-queue. + */ + kn->kn_status &= ~(KN_QUEUED | KN_ACTIVE); + kq->kq_count--; + continue; + } + *kevp = kn->kn_kevent; + kevp++; + nkev++; + if (kn->kn_flags & EV_ONESHOT) { + /* delete ONESHOT events after retrieval */ + kn->kn_status &= ~KN_QUEUED; + kq->kq_count--; + splx(s); + kn->kn_fop->f_detach(kn); + knote_drop(kn, p, p->p_fd); + s = splhigh(); + } else if (kn->kn_flags & EV_CLEAR) { + /* clear state after retrieval */ + kn->kn_data = 0; + kn->kn_fflags = 0; + kn->kn_status &= ~(KN_QUEUED | KN_ACTIVE); + kq->kq_count--; + } else { + /* add event back on list */ + TAILQ_INSERT_TAIL(&kq->kq_head, kn, kn_tqe); + } + count--; + if (nkev == KQ_NEVENTS) { + /* do copyouts in KQ_NEVENTS chunks */ + splx(s); + error = copyout((caddr_t)&kq->kq_kev, (caddr_t)ulistp, + sizeof(struct kevent) * nkev); + ulistp += nkev; + nkev = 0; + kevp = kq->kq_kev; + s = splhigh(); + if (error) + break; + } + } + + /* remove marker */ + TAILQ_REMOVE(&kq->kq_head, &marker, kn_tqe); + splx(s); + done: + if (nkev != 0) { + /* copyout remaining events */ + error = copyout((caddr_t)&kq->kq_kev, (caddr_t)ulistp, + sizeof(struct kevent) * nkev); + } + *retval = maxevents - count; + + return (error); +} + +/* + * struct fileops read method for a kqueue descriptor. + * Not implemented. + * XXX: This could be expanded to call kqueue_scan, if desired. + */ +/*ARGSUSED*/ +static int +kqueue_read(struct file *fp, off_t *offset, struct uio *uio, + struct ucred *cred, int flags) +{ + + return (ENXIO); +} + +/* + * struct fileops write method for a kqueue descriptor. + * Not implemented. + */ +/*ARGSUSED*/ +static int +kqueue_write(struct file *fp, off_t *offset, struct uio *uio, + struct ucred *cred, int flags) +{ + + return (ENXIO); +} + +/* + * struct fileops ioctl method for a kqueue descriptor. + * + * Two ioctls are currently supported. They both use struct kfilter_mapping: + * KFILTER_BYNAME find name for filter, and return result in + * name, which is of size len. + * KFILTER_BYFILTER find filter for name. len is ignored. + */ +/*ARGSUSED*/ +static int +kqueue_ioctl(struct file *fp, u_long com, caddr_t data, struct proc *p) +{ + struct kfilter_mapping *km; + const struct kfilter *kfilter; + char *name; + int error; + + km = (struct kfilter_mapping *)data; + error = 0; + + switch (com) { + case KFILTER_BYFILTER: /* convert filter -> name */ + kfilter = kfilter_byfilter(km->filter); + if (kfilter != NULL) + error = copyoutstr(kfilter->name, km->name, km->len, + NULL); + else + error = ENOENT; + break; + + case KFILTER_BYNAME: /* convert name -> filter */ + MALLOC(name, char *, KFILTER_MAXNAME, M_KEVENT, M_WAITOK); + error = copyinstr(km->name, name, KFILTER_MAXNAME, NULL); + if (error) { + FREE(name, M_KEVENT); + break; + } + kfilter = kfilter_byname(name); + if (kfilter != NULL) + km->filter = kfilter->filter; + else + error = ENOENT; + FREE(name, M_KEVENT); + break; + + default: + error = ENOTTY; + + } + return (error); +} + +/* + * struct fileops fcntl method for a kqueue descriptor. + * Not implemented. + */ +/*ARGSUSED*/ +static int +kqueue_fcntl(struct file *fp, u_int com, caddr_t data, struct proc *p) +{ + + return (ENOTTY); +} + +/* + * struct fileops poll method for a kqueue descriptor. + * Determine if kqueue has events pending. + */ +static int +kqueue_poll(struct file *fp, int events, struct proc *p) +{ + struct kqueue *kq; + int revents; + + kq = (struct kqueue *)fp->f_data; + revents = 0; + if (events & (POLLIN | POLLRDNORM)) { + if (kq->kq_count) { + revents |= events & (POLLIN | POLLRDNORM); + } else { + selrecord(p, &kq->kq_sel); + } + } + return (revents); +} + +/* + * struct fileops stat method for a kqueue descriptor. + * Returns dummy info, with st_size being number of events pending. + */ +static int +kqueue_stat(struct file *fp, struct stat *st, struct proc *p) +{ + struct kqueue *kq; + + kq = (struct kqueue *)fp->f_data; + memset((void *)st, 0, sizeof(*st)); + st->st_size = kq->kq_count; + st->st_blksize = sizeof(struct kevent); + st->st_mode = S_IFIFO; + return (0); +} + +/* + * struct fileops close method for a kqueue descriptor. + * Cleans up kqueue. + */ +static int +kqueue_close(struct file *fp, struct proc *p) +{ + struct kqueue *kq; + struct filedesc *fdp; + struct knote **knp, *kn, *kn0; + int i; + + kq = (struct kqueue *)fp->f_data; + fdp = p->p_fd; + for (i = 0; i < fdp->fd_knlistsize; i++) { + knp = &SLIST_FIRST(&fdp->fd_knlist[i]); + kn = *knp; + while (kn != NULL) { + kn0 = SLIST_NEXT(kn, kn_link); + if (kq == kn->kn_kq) { + kn->kn_fop->f_detach(kn); + FILE_UNUSE(kn->kn_fp, p); + pool_put(&knote_pool, kn); + *knp = kn0; + } else { + knp = &SLIST_NEXT(kn, kn_link); + } + kn = kn0; + } + } + if (fdp->fd_knhashmask != 0) { + for (i = 0; i < fdp->fd_knhashmask + 1; i++) { + knp = &SLIST_FIRST(&fdp->fd_knhash[i]); + kn = *knp; + while (kn != NULL) { + kn0 = SLIST_NEXT(kn, kn_link); + if (kq == kn->kn_kq) { + kn->kn_fop->f_detach(kn); + /* XXX non-fd release of kn->kn_ptr */ + pool_put(&knote_pool, kn); + *knp = kn0; + } else { + knp = &SLIST_NEXT(kn, kn_link); + } + kn = kn0; + } + } + } + pool_put(&kqueue_pool, kq); + fp->f_data = NULL; + + return (0); +} + +/* + * wakeup a kqueue + */ +static void +kqueue_wakeup(struct kqueue *kq) +{ + + if (kq->kq_state & KQ_SLEEP) { /* if currently sleeping ... */ + kq->kq_state &= ~KQ_SLEEP; + wakeup(kq); /* ... wakeup */ + } + + /* Notify select/poll and kevent. */ + selnotify(&kq->kq_sel, 0); +} + +/* + * struct fileops kqfilter method for a kqueue descriptor. + * Event triggered when monitored kqueue changes. + */ +/*ARGSUSED*/ +static int +kqueue_kqfilter(struct file *fp, struct knote *kn) +{ + struct kqueue *kq; + + KASSERT(fp == kn->kn_fp); + kq = (struct kqueue *)kn->kn_fp->f_data; + if (kn->kn_filter != EVFILT_READ) + return (1); + kn->kn_fop = &kqread_filtops; + SLIST_INSERT_HEAD(&kq->kq_sel.si_klist, kn, kn_selnext); + return (0); +} + + +/* + * Walk down a list of knotes, activating them if their event has triggered. + */ +void +knote(struct klist *list, long hint) +{ + struct knote *kn; + + SLIST_FOREACH(kn, list, kn_selnext) + if (kn->kn_fop->f_event(kn, hint)) + KNOTE_ACTIVATE(kn); +} + +/* + * Remove all knotes from a specified klist + */ +void +knote_remove(struct proc *p, struct klist *list) +{ + struct knote *kn; + + while ((kn = SLIST_FIRST(list)) != NULL) { + kn->kn_fop->f_detach(kn); + knote_drop(kn, p, p->p_fd); + } +} + +/* + * Remove all knotes referencing a specified fd + */ +void +knote_fdclose(struct proc *p, int fd) +{ + struct filedesc *fdp; + struct klist *list; + + fdp = p->p_fd; + list = &fdp->fd_knlist[fd]; + knote_remove(p, list); +} + +/* + * Attach a new knote to a file descriptor + */ +static void +knote_attach(struct knote *kn, struct filedesc *fdp) +{ + struct klist *list; + int size; + + if (! kn->kn_fop->f_isfd) { + /* if knote is not on an fd, store on internal hash table */ + if (fdp->fd_knhashmask == 0) + fdp->fd_knhash = hashinit(KN_HASHSIZE, HASH_LIST, + M_KEVENT, M_WAITOK, &fdp->fd_knhashmask); + list = &fdp->fd_knhash[KN_HASH(kn->kn_id, fdp->fd_knhashmask)]; + goto done; + } + + /* + * otherwise, knote is on an fd. + * knotes are stored in fd_knlist indexed by kn->kn_id. + */ + if (fdp->fd_knlistsize <= kn->kn_id) { + /* expand list, it's too small */ + size = fdp->fd_knlistsize; + while (size <= kn->kn_id) { + /* grow in KQ_EXTENT chunks */ + size += KQ_EXTENT; + } + list = malloc(size * sizeof(struct klist *), M_KEVENT,M_WAITOK); + if (fdp->fd_knlist) { + /* copy existing knlist */ + memcpy((caddr_t)list, (caddr_t)fdp->fd_knlist, + fdp->fd_knlistsize * sizeof(struct klist *)); + } + /* + * Zero new memory. Stylistically, SLIST_INIT() should be + * used here, but that does same thing as the memset() anyway. + */ + memset(&list[fdp->fd_knlistsize], 0, + (size - fdp->fd_knlistsize) * sizeof(struct klist *)); + + /* switch to new knlist */ + if (fdp->fd_knlist != NULL) + free(fdp->fd_knlist, M_KEVENT); + fdp->fd_knlistsize = size; + fdp->fd_knlist = list; + } + + /* get list head for this fd */ + list = &fdp->fd_knlist[kn->kn_id]; + done: + /* add new knote */ + SLIST_INSERT_HEAD(list, kn, kn_link); + kn->kn_status = 0; +} + +/* + * Drop knote. + * Should be called at spl == 0, since we don't want to hold spl + * while calling FILE_UNUSE and free. + */ +static void +knote_drop(struct knote *kn, struct proc *p, struct filedesc *fdp) +{ + struct klist *list; + + if (kn->kn_fop->f_isfd) + list = &fdp->fd_knlist[kn->kn_id]; + else + list = &fdp->fd_knhash[KN_HASH(kn->kn_id, fdp->fd_knhashmask)]; + + SLIST_REMOVE(list, kn, knote, kn_link); + if (kn->kn_status & KN_QUEUED) + knote_dequeue(kn); + if (kn->kn_fop->f_isfd) + FILE_UNUSE(kn->kn_fp, p); + pool_put(&knote_pool, kn); +} + + +/* + * Queue new event for knote. + */ +static void +knote_enqueue(struct knote *kn) +{ + struct kqueue *kq; + int s; + + kq = kn->kn_kq; + s = splhigh(); + KASSERT((kn->kn_status & KN_QUEUED) == 0); + + TAILQ_INSERT_TAIL(&kq->kq_head, kn, kn_tqe); + kn->kn_status |= KN_QUEUED; + kq->kq_count++; + splx(s); + kqueue_wakeup(kq); +} + +/* + * Dequeue event for knote. + */ +static void +knote_dequeue(struct knote *kn) +{ + struct kqueue *kq; + int s; + + kq = kn->kn_kq; + s = splhigh(); + KASSERT(kn->kn_status & KN_QUEUED); + + TAILQ_REMOVE(&kq->kq_head, kn, kn_tqe); + kn->kn_status &= ~KN_QUEUED; + kq->kq_count--; + splx(s); +} diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c index bc89b0f8178b..b0828139d2d5 100644 --- a/sys/kern/kern_exec.c +++ b/sys/kern/kern_exec.c @@ -1,4 +1,4 @@ -/* $NetBSD: kern_exec.c,v 1.158 2002/10/08 15:50:11 junyoung Exp $ */ +/* $NetBSD: kern_exec.c,v 1.159 2002/10/23 09:14:15 jdolecek Exp $ */ /*- * Copyright (C) 1993, 1994, 1996 Christopher G. Demetriou @@ -33,7 +33,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.158 2002/10/08 15:50:11 junyoung Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.159 2002/10/23 09:14:15 jdolecek Exp $"); #include "opt_ktrace.h" #include "opt_syscall_debug.h" @@ -668,6 +668,9 @@ sys_execve(struct proc *p, void *v, register_t *retval) VOP_CLOSE(pack.ep_vp, FREAD, cred, p); vput(pack.ep_vp); + /* notify others that we exec'd */ + KNOTE(&p->p_klist, NOTE_EXEC); + /* setup new registers and do misc. setup. */ (*pack.ep_es->es_emul->e_setregs)(p, &pack, (u_long) stack); if (pack.ep_es->es_setregs) diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c index 30227b088b31..bd8543a8cf37 100644 --- a/sys/kern/kern_exit.c +++ b/sys/kern/kern_exit.c @@ -1,4 +1,4 @@ -/* $NetBSD: kern_exit.c,v 1.102 2002/09/25 22:21:41 thorpej Exp $ */ +/* $NetBSD: kern_exit.c,v 1.103 2002/10/23 09:14:16 jdolecek Exp $ */ /*- * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc. @@ -78,7 +78,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.102 2002/09/25 22:21:41 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.103 2002/10/23 09:14:16 jdolecek Exp $"); #include "opt_ktrace.h" #include "opt_perfctrs.h" @@ -301,6 +301,11 @@ exit1(struct proc *p, int rv) calcru(p, &p->p_ru->ru_utime, &p->p_ru->ru_stime, NULL); ruadd(p->p_ru, &p->p_stats->p_cru); + /* + * Notify interested parties of our demise. + */ + KNOTE(&p->p_klist, NOTE_EXIT); + #if PERFCTRS /* * Save final PMC information in parent process & clean up. diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c index dcd229ab4bb4..57878ff18f42 100644 --- a/sys/kern/kern_fork.c +++ b/sys/kern/kern_fork.c @@ -1,4 +1,4 @@ -/* $NetBSD: kern_fork.c,v 1.95 2002/10/21 17:37:53 christos Exp $ */ +/* $NetBSD: kern_fork.c,v 1.96 2002/10/23 09:14:17 jdolecek Exp $ */ /*- * Copyright (c) 1999, 2001 The NetBSD Foundation, Inc. @@ -78,7 +78,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.95 2002/10/21 17:37:53 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.96 2002/10/23 09:14:17 jdolecek Exp $"); #include "opt_ktrace.h" #include "opt_systrace.h" @@ -485,6 +485,11 @@ fork1(struct proc *p1, int flags, int exitsig, void *stack, size_t stacksize, */ PRELE(p1); + /* + * Notify any interested parties about the new process. + */ + KNOTE(&p1->p_klist, NOTE_FORK | p2->p_pid); + /* * Update stats now that we know the fork was successful. */ diff --git a/sys/kern/kern_ktrace.c b/sys/kern/kern_ktrace.c index 1afe5d5f6b5f..10336682f9ee 100644 --- a/sys/kern/kern_ktrace.c +++ b/sys/kern/kern_ktrace.c @@ -1,4 +1,4 @@ -/* $NetBSD: kern_ktrace.c,v 1.58 2002/06/28 01:59:36 itojun Exp $ */ +/* $NetBSD: kern_ktrace.c,v 1.59 2002/10/23 09:14:18 jdolecek Exp $ */ /* * Copyright (c) 1989, 1993 @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_ktrace.c,v 1.58 2002/06/28 01:59:36 itojun Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_ktrace.c,v 1.59 2002/10/23 09:14:18 jdolecek Exp $"); #include "opt_ktrace.h" @@ -89,6 +89,11 @@ ktrderef(struct proc *p) if (fp == NULL) return; FILE_USE(fp); + + /* + * ktrace file descriptor can't be watched (are not visible to + * userspace), so no kqueue stuff here + */ closef(fp, NULL); p->p_tracep = NULL; diff --git a/sys/kern/kern_lkm.c b/sys/kern/kern_lkm.c index 957f3ce7d3c3..ea602e301842 100644 --- a/sys/kern/kern_lkm.c +++ b/sys/kern/kern_lkm.c @@ -1,4 +1,4 @@ -/* $NetBSD: kern_lkm.c,v 1.60 2002/09/18 22:59:36 lha Exp $ */ +/* $NetBSD: kern_lkm.c,v 1.61 2002/10/23 09:14:19 jdolecek Exp $ */ /* * Copyright (c) 1994 Christopher G. Demetriou @@ -41,7 +41,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_lkm.c,v 1.60 2002/09/18 22:59:36 lha Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_lkm.c,v 1.61 2002/10/23 09:14:19 jdolecek Exp $"); #include "opt_ddb.h" @@ -115,7 +115,7 @@ dev_type_ioctl(lkmioctl); const struct cdevsw lkm_cdevsw = { lkmopen, lkmclose, noread, nowrite, lkmioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; /*ARGSUSED*/ diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c index d39580d37eff..1e40655f4014 100644 --- a/sys/kern/kern_sig.c +++ b/sys/kern/kern_sig.c @@ -1,4 +1,4 @@ -/* $NetBSD: kern_sig.c,v 1.125 2002/09/22 05:36:48 gmcgarry Exp $ */ +/* $NetBSD: kern_sig.c,v 1.126 2002/10/23 09:14:20 jdolecek Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1991, 1993 @@ -41,7 +41,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.125 2002/09/22 05:36:48 gmcgarry Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.126 2002/10/23 09:14:20 jdolecek Exp $"); #include "opt_ktrace.h" #include "opt_compat_sunos.h" @@ -781,6 +781,11 @@ psignal1(struct proc *p, int signum, else SCHED_ASSERT_LOCKED(); #endif + /* + * Notify any interested parties in the signal. + */ + KNOTE(&p->p_klist, NOTE_SIGNAL | signum); + prop = sigprop[signum]; /* @@ -1501,3 +1506,47 @@ sigismasked(struct proc *p, int sig) return (sigismember(&p->p_sigctx.ps_sigignore, sig) || sigismember(&p->p_sigctx.ps_sigmask, sig)); } + +static int +filt_sigattach(struct knote *kn) +{ + struct proc *p = curproc; + + kn->kn_ptr.p_proc = p; + kn->kn_flags |= EV_CLEAR; /* automatically set */ + + SLIST_INSERT_HEAD(&p->p_klist, kn, kn_selnext); + + return (0); +} + +static void +filt_sigdetach(struct knote *kn) +{ + struct proc *p = kn->kn_ptr.p_proc; + + SLIST_REMOVE(&p->p_klist, kn, knote, kn_selnext); +} + +/* + * signal knotes are shared with proc knotes, so we apply a mask to + * the hint in order to differentiate them from process hints. This + * could be avoided by using a signal-specific knote list, but probably + * isn't worth the trouble. + */ +static int +filt_signal(struct knote *kn, long hint) +{ + + if (hint & NOTE_SIGNAL) { + hint &= ~NOTE_SIGNAL; + + if (kn->kn_id == hint) + kn->kn_data++; + } + return (kn->kn_data != 0); +} + +const struct filterops sig_filtops = { + 0, filt_sigattach, filt_sigdetach, filt_signal +}; diff --git a/sys/kern/kern_systrace.c b/sys/kern/kern_systrace.c index 5c8fb5274315..ce69811dbc0c 100644 --- a/sys/kern/kern_systrace.c +++ b/sys/kern/kern_systrace.c @@ -1,4 +1,4 @@ -/* $NetBSD: kern_systrace.c,v 1.18 2002/10/11 21:54:57 provos Exp $ */ +/* $NetBSD: kern_systrace.c,v 1.19 2002/10/23 09:14:21 jdolecek Exp $ */ /* * Copyright 2002 Niels Provos @@ -31,7 +31,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_systrace.c,v 1.18 2002/10/11 21:54:57 provos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_systrace.c,v 1.19 2002/10/23 09:14:21 jdolecek Exp $"); #include "opt_systrace.h" @@ -86,8 +86,8 @@ int systracef_poll(struct file *, int, struct proc *); int systracef_read(struct file *, off_t *, struct uio *, struct ucred *); int systracef_write(struct file *, off_t *, struct uio *, struct ucred *); int systracef_select(struct file *, int, struct proc *); -int systracef_kqfilter(struct file *, struct knote *); #endif +int systracef_kqfilter(struct file *, struct knote *); int systracef_ioctl(struct file *, u_long, caddr_t, struct proc *); int systracef_stat(struct file *, struct stat *, struct proc *); int systracef_close(struct file *, struct proc *); @@ -187,6 +187,9 @@ static struct fileops systracefops = { #endif systracef_stat, systracef_close +#ifdef __NetBSD__ + , systracef_kqfilter +#endif }; struct pool systr_proc_pl; @@ -198,7 +201,7 @@ struct lock systrace_lck; #ifdef __NetBSD__ const struct cdevsw systrace_cdevsw = { systraceopen, noclose, noread, nowrite, noioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; #endif @@ -468,14 +471,12 @@ systracef_select(struct file *fp, int which, struct proc *p) } #endif /* __NetBSD__ */ -#ifndef __NetBSD__ /* ARGSUSED */ int systracef_kqfilter(struct file *fp, struct knote *kn) { return (1); } -#endif /* ARGSUSED */ diff --git a/sys/kern/subr_log.c b/sys/kern/subr_log.c index 2fafdbe3345f..208bdc9a7d48 100644 --- a/sys/kern/subr_log.c +++ b/sys/kern/subr_log.c @@ -1,4 +1,4 @@ -/* $NetBSD: subr_log.c,v 1.23 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: subr_log.c,v 1.24 2002/10/23 09:14:22 jdolecek Exp $ */ /* * Copyright (c) 1982, 1986, 1993 @@ -40,7 +40,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: subr_log.c,v 1.23 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_log.c,v 1.24 2002/10/23 09:14:22 jdolecek Exp $"); #include #include @@ -76,10 +76,11 @@ dev_type_close(logclose); dev_type_read(logread); dev_type_ioctl(logioctl); dev_type_poll(logpoll); +dev_type_kqfilter(logkqfilter); const struct cdevsw log_cdevsw = { logopen, logclose, logread, nowrite, logioctl, - nostop, notty, logpoll, nommap, + nostop, notty, logpoll, nommap, logkqfilter, }; void @@ -223,6 +224,60 @@ logpoll(dev, events, p) return (revents); } +static void +filt_logrdetach(struct knote *kn) +{ + int s; + + s = splhigh(); + SLIST_REMOVE(&logsoftc.sc_selp.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_logread(struct knote *kn, long hint) +{ + + if (msgbufp->msg_bufr == msgbufp->msg_bufx) + return (0); + + if (msgbufp->msg_bufr < msgbufp->msg_bufx) + kn->kn_data = msgbufp->msg_bufx - msgbufp->msg_bufr; + else + kn->kn_data = (msgbufp->msg_bufs - msgbufp->msg_bufr) + + msgbufp->msg_bufx; + + return (1); +} + +static const struct filterops logread_filtops = + { 1, NULL, filt_logrdetach, filt_logread }; + +int +logkqfilter(dev_t dev, struct knote *kn) +{ + struct klist *klist; + int s; + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &logsoftc.sc_selp.si_klist; + kn->kn_fop = &logread_filtops; + break; + + default: + return (1); + } + + kn->kn_hook = NULL; + + s = splhigh(); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + splx(s); + + return (0); +} + void logwakeup() { @@ -230,7 +285,7 @@ logwakeup() if (!log_open) return; - selwakeup(&logsoftc.sc_selp); + selnotify(&logsoftc.sc_selp, 0); if (logsoftc.sc_state & LOG_ASYNC) { if (logsoftc.sc_pgid < 0) gsignal(-logsoftc.sc_pgid, SIGIO); diff --git a/sys/kern/sys_pipe.c b/sys/kern/sys_pipe.c index 0412bc4f1777..02eab112113b 100644 --- a/sys/kern/sys_pipe.c +++ b/sys/kern/sys_pipe.c @@ -1,4 +1,4 @@ -/* $NetBSD: sys_pipe.c,v 1.26 2002/08/25 23:16:39 thorpej Exp $ */ +/* $NetBSD: sys_pipe.c,v 1.27 2002/10/23 09:14:22 jdolecek Exp $ */ /* * Copyright (c) 1996 John S. Dyson @@ -58,7 +58,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: sys_pipe.c,v 1.26 2002/08/25 23:16:39 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sys_pipe.c,v 1.27 2002/10/23 09:14:22 jdolecek Exp $"); #include #include @@ -98,6 +98,10 @@ __KERNEL_RCSID(0, "$NetBSD: sys_pipe.c,v 1.26 2002/08/25 23:16:39 thorpej Exp $" * is atomic. */ #define vfs_timestamp(tv) (*(tv) = time) + +/* we call it si_klist */ +#define si_note si_klist + #endif /* @@ -127,15 +131,6 @@ static struct fileops pipeops = { pipe_stat, pipe_close }; -static void filt_pipedetach(struct knote *kn); -static int filt_piperead(struct knote *kn, long hint); -static int filt_pipewrite(struct knote *kn, long hint); - -static struct filterops pipe_rfiltops = - { 1, NULL, filt_pipedetach, filt_piperead }; -static struct filterops pipe_wfiltops = - { 1, NULL, filt_pipedetach, filt_pipewrite }; - #define PIPE_GET_GIANT(pipe) \ do { \ PIPE_UNLOCK(wpipe); \ @@ -159,12 +154,13 @@ static int pipe_close(struct file *fp, struct proc *p); static int pipe_poll(struct file *fp, int events, struct proc *p); static int pipe_fcntl(struct file *fp, u_int com, caddr_t data, struct proc *p); +static int pipe_kqfilter(struct file *fp, struct knote *kn); static int pipe_stat(struct file *fp, struct stat *sb, struct proc *p); static int pipe_ioctl(struct file *fp, u_long cmd, caddr_t data, struct proc *p); static struct fileops pipeops = { pipe_read, pipe_write, pipe_ioctl, pipe_fcntl, pipe_poll, - pipe_stat, pipe_close }; + pipe_stat, pipe_close, pipe_kqfilter }; /* XXXSMP perhaps use spinlocks & KERNEL_PROC_(UN)LOCK() ? just clear now */ #define PIPE_GET_GIANT(pipe) @@ -563,19 +559,21 @@ static __inline void pipeselwakeup(selp, sigp) struct pipe *selp, *sigp; { + +#ifdef __FreeBSD__ if (selp->pipe_state & PIPE_SEL) { selp->pipe_state &= ~PIPE_SEL; selwakeup(&selp->pipe_sel); } -#ifdef __FreeBSD__ if (sigp && (sigp->pipe_state & PIPE_ASYNC) && sigp->pipe_sigio) pgsigio(sigp->pipe_sigio, SIGIO, 0); KNOTE(&selp->pipe_sel.si_note, 0); #endif #ifdef __NetBSD__ - if (sigp && (sigp->pipe_state & PIPE_ASYNC) - && sigp->pipe_pgid != NO_PID){ + selnotify(&selp->pipe_sel, 0); + if (sigp && (sigp->pipe_state & PIPE_ASYNC) && + sigp->pipe_pgid != NO_PID) { struct proc *p; if (sigp->pipe_pgid < 0) @@ -1867,38 +1865,30 @@ pipeclose(cpipe) #endif } -#ifdef __FreeBSD__ -/*ARGSUSED*/ -static int -pipe_kqfilter(struct file *fp, struct knote *kn) -{ - struct pipe *cpipe; - - cpipe = (struct pipe *)kn->kn_fp->f_data; - switch (kn->kn_filter) { - case EVFILT_READ: - kn->kn_fop = &pipe_rfiltops; - break; - case EVFILT_WRITE: - kn->kn_fop = &pipe_wfiltops; - cpipe = cpipe->pipe_peer; - break; - default: - return (1); - } - kn->kn_hook = (caddr_t)cpipe; - - PIPE_LOCK(cpipe); - SLIST_INSERT_HEAD(&cpipe->pipe_sel.si_note, kn, kn_selnext); - PIPE_UNLOCK(cpipe); - return (0); -} - static void filt_pipedetach(struct knote *kn) { struct pipe *cpipe = (struct pipe *)kn->kn_fp->f_data; + switch(kn->kn_filter) { + case EVFILT_WRITE: + /* need the peer structure, not our own */ + cpipe = cpipe->pipe_peer; + + /* if reader end already closed, just return */ + if (!cpipe) + return; + + break; + default: + /* nothing to do */ + } + +#ifdef DIAGNOSTIC + if (kn->kn_hook != cpipe) + panic("filt_pipedetach: inconsistent knote"); +#endif + PIPE_LOCK(cpipe); SLIST_REMOVE(&cpipe->pipe_sel.si_note, kn, knote, kn_selnext); PIPE_UNLOCK(cpipe); @@ -1947,7 +1937,41 @@ filt_pipewrite(struct knote *kn, long hint) PIPE_UNLOCK(rpipe); return (kn->kn_data >= PIPE_BUF); } -#endif /* FreeBSD */ + +static const struct filterops pipe_rfiltops = + { 1, NULL, filt_pipedetach, filt_piperead }; +static const struct filterops pipe_wfiltops = + { 1, NULL, filt_pipedetach, filt_pipewrite }; + +/*ARGSUSED*/ +static int +pipe_kqfilter(struct file *fp, struct knote *kn) +{ + struct pipe *cpipe; + + cpipe = (struct pipe *)kn->kn_fp->f_data; + switch (kn->kn_filter) { + case EVFILT_READ: + kn->kn_fop = &pipe_rfiltops; + break; + case EVFILT_WRITE: + kn->kn_fop = &pipe_wfiltops; + cpipe = cpipe->pipe_peer; + if (cpipe == NULL) { + /* other end of pipe has been closed */ + return (EBADF); + } + break; + default: + return (1); + } + kn->kn_hook = cpipe; + + PIPE_LOCK(cpipe); + SLIST_INSERT_HEAD(&cpipe->pipe_sel.si_note, kn, kn_selnext); + PIPE_UNLOCK(cpipe); + return (0); +} #ifdef __NetBSD__ static int diff --git a/sys/kern/sys_socket.c b/sys/kern/sys_socket.c index ae298275a75c..9c4dc0088975 100644 --- a/sys/kern/sys_socket.c +++ b/sys/kern/sys_socket.c @@ -1,4 +1,4 @@ -/* $NetBSD: sys_socket.c,v 1.32 2001/11/12 15:25:25 lukem Exp $ */ +/* $NetBSD: sys_socket.c,v 1.33 2002/10/23 09:14:23 jdolecek Exp $ */ /* * Copyright (c) 1982, 1986, 1990, 1993 @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: sys_socket.c,v 1.32 2001/11/12 15:25:25 lukem Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sys_socket.c,v 1.33 2002/10/23 09:14:23 jdolecek Exp $"); #include #include @@ -53,8 +53,10 @@ __KERNEL_RCSID(0, "$NetBSD: sys_socket.c,v 1.32 2001/11/12 15:25:25 lukem Exp $" #include #include -struct fileops socketops = - { soo_read, soo_write, soo_ioctl, soo_fcntl, soo_poll, soo_stat, soo_close}; +struct fileops socketops = { + soo_read, soo_write, soo_ioctl, soo_fcntl, soo_poll, + soo_stat, soo_close, soo_kqfilter +}; /* ARGSUSED */ int diff --git a/sys/kern/syscalls.master b/sys/kern/syscalls.master index e805404e79ab..6589f3324b29 100644 --- a/sys/kern/syscalls.master +++ b/sys/kern/syscalls.master @@ -1,4 +1,4 @@ - $NetBSD: syscalls.master,v 1.115 2002/09/04 07:45:41 jdolecek Exp $ + $NetBSD: syscalls.master,v 1.116 2002/10/23 09:14:24 jdolecek Exp $ ; @(#)syscalls.master 8.2 (Berkeley) 1/13/94 @@ -656,5 +656,8 @@ 341 STD { int sys_pmc_get_info(int ctr, int op, void *args); } 342 STD { int sys_pmc_control(int ctr, int op, void *args); } 343 STD { int sys_rasctl(caddr_t addr, size_t len, int op); } -344 UNIMPL kqueue -345 UNIMPL kevent +344 STD { int sys_kqueue(void); } +345 STD { int sys_kevent(int fd, \ + const struct kevent *changelist, size_t nchanges, \ + struct kevent *eventlist, size_t nevents, \ + const struct timespec *timeout); } diff --git a/sys/kern/tty.c b/sys/kern/tty.c index 166de8ddcdff..ed8511f03fdc 100644 --- a/sys/kern/tty.c +++ b/sys/kern/tty.c @@ -1,4 +1,4 @@ -/* $NetBSD: tty.c,v 1.142 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: tty.c,v 1.143 2002/10/23 09:14:25 jdolecek Exp $ */ /*- * Copyright (c) 1982, 1986, 1990, 1991, 1993 @@ -41,7 +41,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: tty.c,v 1.142 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tty.c,v 1.143 2002/10/23 09:14:25 jdolecek Exp $"); #include "opt_uconsole.h" @@ -1069,6 +1069,89 @@ ttpoll(struct tty *tp, int events, struct proc *p) return (revents); } +static void +filt_ttyrdetach(struct knote *kn) +{ + struct tty *tp; + int s; + + tp = kn->kn_hook; + s = spltty(); + SLIST_REMOVE(&tp->t_rsel.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_ttyread(struct knote *kn, long hint) +{ + struct tty *tp; + + tp = kn->kn_hook; + kn->kn_data = ttnread(tp); + return (kn->kn_data > 0); +} + +static void +filt_ttywdetach(struct knote *kn) +{ + struct tty *tp; + int s; + + tp = kn->kn_hook; + s = spltty(); + SLIST_REMOVE(&tp->t_wsel.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_ttywrite(struct knote *kn, long hint) +{ + struct tty *tp; + + tp = kn->kn_hook; + kn->kn_data = tp->t_outq.c_cn - tp->t_outq.c_cc; + return (tp->t_outq.c_cc <= tp->t_lowat && CONNECTED(tp)); +} + +static const struct filterops ttyread_filtops = + { 1, NULL, filt_ttyrdetach, filt_ttyread }; +static const struct filterops ttywrite_filtops = + { 1, NULL, filt_ttywdetach, filt_ttywrite }; + +int +ttykqfilter(dev_t dev, struct knote *kn) +{ + struct tty *tp; + struct klist *klist; + int s; + const struct cdevsw *cdev; + + cdev = cdevsw_lookup(dev); + if (cdev == NULL) + return (ENXIO); + tp = (*cdev->d_tty)(dev); + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &tp->t_rsel.si_klist; + kn->kn_fop = &ttyread_filtops; + break; + case EVFILT_WRITE: + klist = &tp->t_wsel.si_klist; + kn->kn_fop = &ttywrite_filtops; + break; + default: + return (1); + } + + kn->kn_hook = tp; + + s = spltty(); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + splx(s); + + return (0); +} + static int ttnread(struct tty *tp) { @@ -1145,7 +1228,7 @@ ttyflush(struct tty *tp, int rw) (*cdev->d_stop)(tp, rw); FLUSHQ(&tp->t_outq); wakeup((caddr_t)&tp->t_outq); - selwakeup(&tp->t_wsel); + selnotify(&tp->t_wsel, 0); } splx(s); } @@ -1883,7 +1966,7 @@ void ttwakeup(struct tty *tp) { - selwakeup(&tp->t_rsel); + selnotify(&tp->t_rsel, 0); if (ISSET(tp->t_state, TS_ASYNC)) pgsignal(tp->t_pgrp, SIGIO, 1); wakeup((caddr_t)&tp->t_rawq); diff --git a/sys/kern/tty_pty.c b/sys/kern/tty_pty.c index fdb742cdd4ec..5b89883826d8 100644 --- a/sys/kern/tty_pty.c +++ b/sys/kern/tty_pty.c @@ -1,4 +1,4 @@ -/* $NetBSD: tty_pty.c,v 1.64 2002/09/22 18:13:38 jdolecek Exp $ */ +/* $NetBSD: tty_pty.c,v 1.65 2002/10/23 09:14:26 jdolecek Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1993 @@ -41,7 +41,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: tty_pty.c,v 1.64 2002/09/22 18:13:38 jdolecek Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tty_pty.c,v 1.65 2002/10/23 09:14:26 jdolecek Exp $"); #include "opt_compat_sunos.h" @@ -106,6 +106,7 @@ dev_type_close(ptcclose); dev_type_read(ptcread); dev_type_write(ptcwrite); dev_type_poll(ptcpoll); +dev_type_kqfilter(ptckqfilter); dev_type_open(ptsopen); dev_type_close(ptsclose); @@ -119,23 +120,23 @@ dev_type_tty(ptytty); const struct cdevsw ptc_cdevsw = { ptcopen, ptcclose, ptcread, ptcwrite, ptyioctl, - nullstop, ptytty, ptcpoll, nommap, D_TTY + nullstop, ptytty, ptcpoll, nommap, ptckqfilter, D_TTY }; const struct cdevsw pts_cdevsw = { ptsopen, ptsclose, ptsread, ptswrite, ptyioctl, - ptsstop, ptytty, ptspoll, nommap, D_TTY + ptsstop, ptytty, ptspoll, nommap, ttykqfilter, D_TTY }; #if defined(pmax) const struct cdevsw ptc_ultrix_cdevsw = { ptcopen, ptcclose, ptcread, ptcwrite, ptyioctl, - nullstop, ptytty, ptcpoll, nommap, D_TTY + nullstop, ptytty, ptcpoll, nommap, ptckqfilter, D_TTY }; const struct cdevsw pts_ultrix_cdevsw = { ptsopen, ptsclose, ptsread, ptswrite, ptyioctl, - ptsstop, ptytty, ptspoll, nommap, D_TTY + ptsstop, ptytty, ptspoll, nommap, ttykqfilter, D_TTY }; #endif /* defined(pmax) */ @@ -495,11 +496,11 @@ ptcwakeup(tp, flag) struct pt_softc *pti = pt_softc[minor(tp->t_dev)]; if (flag & FREAD) { - selwakeup(&pti->pt_selr); + selnotify(&pti->pt_selr, 0); wakeup((caddr_t)&tp->t_outq.c_cf); } if (flag & FWRITE) { - selwakeup(&pti->pt_selw); + selnotify(&pti->pt_selw, 0); wakeup((caddr_t)&tp->t_rawq.c_cf); } } @@ -612,7 +613,7 @@ ptcread(dev, uio, flag) CLR(tp->t_state, TS_ASLEEP); wakeup((caddr_t)&tp->t_outq); } - selwakeup(&tp->t_wsel); + selnotify(&tp->t_wsel, 0); } return (error); } @@ -749,6 +750,124 @@ ptcpoll(dev, events, p) return (revents); } +static void +filt_ptcrdetach(struct knote *kn) +{ + struct pt_softc *pti; + int s; + + pti = kn->kn_hook; + s = spltty(); + SLIST_REMOVE(&pti->pt_selr.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_ptcread(struct knote *kn, long hint) +{ + struct pt_softc *pti; + struct tty *tp; + int canread; + + pti = kn->kn_hook; + tp = pti->pt_tty; + + canread = (ISSET(tp->t_state, TS_ISOPEN) && + ((tp->t_outq.c_cc > 0 && !ISSET(tp->t_state, TS_TTSTOP)) || + ((pti->pt_flags & PF_PKT) && pti->pt_send) || + ((pti->pt_flags & PF_UCNTL) && pti->pt_ucntl))); + + if (canread) { + /* + * c_cc is number of characters after output post-processing; + * the amount of data actually read(2) depends on + * setting of input flags for the terminal. + */ + kn->kn_data = tp->t_outq.c_cc; + if (((pti->pt_flags & PF_PKT) && pti->pt_send) || + ((pti->pt_flags & PF_UCNTL) && pti->pt_ucntl)) + kn->kn_data++; + } + + return (canread); +} + +static void +filt_ptcwdetach(struct knote *kn) +{ + struct pt_softc *pti; + int s; + + pti = kn->kn_hook; + s = spltty(); + SLIST_REMOVE(&pti->pt_selw.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_ptcwrite(struct knote *kn, long hint) +{ + struct pt_softc *pti; + struct tty *tp; + int canwrite; + int nwrite; + + pti = kn->kn_hook; + tp = pti->pt_tty; + + canwrite = (ISSET(tp->t_state, TS_ISOPEN) && + ((pti->pt_flags & PF_REMOTE) ? + (tp->t_canq.c_cc == 0) : + ((tp->t_rawq.c_cc + tp->t_canq.c_cc < TTYHOG-2) || + (tp->t_canq.c_cc == 0 && ISSET(tp->t_lflag, ICANON))))); + + if (canwrite) { + if (pti->pt_flags & PF_REMOTE) + nwrite = tp->t_canq.c_cn; + else { + /* this is guaranteed to be > 0 due to above check */ + nwrite = tp->t_canq.c_cn + - (tp->t_rawq.c_cc + tp->t_canq.c_cc); + } + kn->kn_data = nwrite; + } + + return (canwrite); +} + +static const struct filterops ptcread_filtops = + { 1, NULL, filt_ptcrdetach, filt_ptcread }; +static const struct filterops ptcwrite_filtops = + { 1, NULL, filt_ptcwdetach, filt_ptcwrite }; + +int +ptckqfilter(dev_t dev, struct knote *kn) +{ + struct pt_softc *pti = pt_softc[minor(dev)]; + struct klist *klist; + int s; + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &pti->pt_selr.si_klist; + kn->kn_fop = &ptcread_filtops; + break; + case EVFILT_WRITE: + klist = &pti->pt_selw.si_klist; + kn->kn_fop = &ptcwrite_filtops; + break; + default: + return (1); + } + + kn->kn_hook = pti; + + s = spltty(); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + splx(s); + + return (0); +} struct tty * ptytty(dev) diff --git a/sys/kern/tty_tty.c b/sys/kern/tty_tty.c index e804ef8d1e03..444a56045a81 100644 --- a/sys/kern/tty_tty.c +++ b/sys/kern/tty_tty.c @@ -1,4 +1,4 @@ -/* $NetBSD: tty_tty.c,v 1.18 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: tty_tty.c,v 1.19 2002/10/23 09:14:27 jdolecek Exp $ */ /*- * Copyright (c) 1982, 1986, 1991, 1993, 1995 @@ -40,7 +40,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: tty_tty.c,v 1.18 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tty_tty.c,v 1.19 2002/10/23 09:14:27 jdolecek Exp $"); #include #include @@ -59,10 +59,11 @@ dev_type_read(cttyread); dev_type_write(cttywrite); dev_type_ioctl(cttyioctl); dev_type_poll(cttypoll); +dev_type_kqfilter(cttykqfilter); const struct cdevsw ctty_cdevsw = { cttyopen, nullclose, cttyread, cttywrite, cttyioctl, - nullstop, notty, cttypoll, nommap, D_TTY + nullstop, notty, cttypoll, nommap, cttykqfilter, D_TTY }; /*ARGSUSED*/ @@ -170,3 +171,17 @@ cttypoll(dev, events, p) return (seltrue(dev, events, p)); return (VOP_POLL(ttyvp, events, p)); } + +int +cttykqfilter(dev, kn) + dev_t dev; + struct knote *kn; +{ + /* This is called from filt_fileattach() by the attaching process. */ + struct proc *p = curproc; + struct vnode *ttyvp = cttyvp(p); + + if (ttyvp == NULL) + return (1); + return (VOP_KQFILTER(ttyvp, kn)); +} diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index ef43d928b5be..7ab08fb620e0 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_socket.c,v 1.71 2002/08/21 05:13:37 thorpej Exp $ */ +/* $NetBSD: uipc_socket.c,v 1.72 2002/10/23 09:14:28 jdolecek Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -72,7 +72,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.71 2002/08/21 05:13:37 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.72 2002/10/23 09:14:28 jdolecek Exp $"); #include "opt_sock_counters.h" #include "opt_sosend_loan.h" @@ -91,6 +91,7 @@ __KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.71 2002/08/21 05:13:37 thorpej Exp #include #include #include +#include #include @@ -1468,3 +1469,119 @@ sohasoutofband(struct socket *so) psignal(p, SIGURG); selwakeup(&so->so_rcv.sb_sel); } + +static void +filt_sordetach(struct knote *kn) +{ + struct socket *so; + + so = (struct socket *)kn->kn_fp->f_data; + SLIST_REMOVE(&so->so_rcv.sb_sel.si_klist, kn, knote, kn_selnext); + if (SLIST_EMPTY(&so->so_rcv.sb_sel.si_klist)) + so->so_rcv.sb_flags &= ~SB_KNOTE; +} + +/*ARGSUSED*/ +static int +filt_soread(struct knote *kn, long hint) +{ + struct socket *so; + + so = (struct socket *)kn->kn_fp->f_data; + kn->kn_data = so->so_rcv.sb_cc; + if (so->so_state & SS_CANTRCVMORE) { + kn->kn_flags |= EV_EOF; + kn->kn_fflags = so->so_error; + return (1); + } + if (so->so_error) /* temporary udp error */ + return (1); + if (kn->kn_sfflags & NOTE_LOWAT) + return (kn->kn_data >= kn->kn_sdata); + return (kn->kn_data >= so->so_rcv.sb_lowat); +} + +static void +filt_sowdetach(struct knote *kn) +{ + struct socket *so; + + so = (struct socket *)kn->kn_fp->f_data; + SLIST_REMOVE(&so->so_snd.sb_sel.si_klist, kn, knote, kn_selnext); + if (SLIST_EMPTY(&so->so_snd.sb_sel.si_klist)) + so->so_snd.sb_flags &= ~SB_KNOTE; +} + +/*ARGSUSED*/ +static int +filt_sowrite(struct knote *kn, long hint) +{ + struct socket *so; + + so = (struct socket *)kn->kn_fp->f_data; + kn->kn_data = sbspace(&so->so_snd); + if (so->so_state & SS_CANTSENDMORE) { + kn->kn_flags |= EV_EOF; + kn->kn_fflags = so->so_error; + return (1); + } + if (so->so_error) /* temporary udp error */ + return (1); + if (((so->so_state & SS_ISCONNECTED) == 0) && + (so->so_proto->pr_flags & PR_CONNREQUIRED)) + return (0); + if (kn->kn_sfflags & NOTE_LOWAT) + return (kn->kn_data >= kn->kn_sdata); + return (kn->kn_data >= so->so_snd.sb_lowat); +} + +/*ARGSUSED*/ +static int +filt_solisten(struct knote *kn, long hint) +{ + struct socket *so; + + so = (struct socket *)kn->kn_fp->f_data; + + /* + * Set kn_data to number of incoming connections, not + * counting partial (incomplete) connections. + */ + kn->kn_data = so->so_qlen; + return (kn->kn_data > 0); +} + +static const struct filterops solisten_filtops = + { 1, NULL, filt_sordetach, filt_solisten }; +static const struct filterops soread_filtops = + { 1, NULL, filt_sordetach, filt_soread }; +static const struct filterops sowrite_filtops = + { 1, NULL, filt_sowdetach, filt_sowrite }; + +int +soo_kqfilter(struct file *fp, struct knote *kn) +{ + struct socket *so; + struct sockbuf *sb; + + so = (struct socket *)kn->kn_fp->f_data; + switch (kn->kn_filter) { + case EVFILT_READ: + if (so->so_options & SO_ACCEPTCONN) + kn->kn_fop = &solisten_filtops; + else + kn->kn_fop = &soread_filtops; + sb = &so->so_rcv; + break; + case EVFILT_WRITE: + kn->kn_fop = &sowrite_filtops; + sb = &so->so_snd; + break; + default: + return (1); + } + SLIST_INSERT_HEAD(&sb->sb_sel.si_klist, kn, kn_selnext); + sb->sb_flags |= SB_KNOTE; + return (0); +} + diff --git a/sys/kern/uipc_socket2.c b/sys/kern/uipc_socket2.c index dc020896f1c3..6c8231bdb6dd 100644 --- a/sys/kern/uipc_socket2.c +++ b/sys/kern/uipc_socket2.c @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_socket2.c,v 1.47 2002/09/27 15:37:47 provos Exp $ */ +/* $NetBSD: uipc_socket2.c,v 1.48 2002/10/23 09:14:29 jdolecek Exp $ */ /* * Copyright (c) 1982, 1986, 1988, 1990, 1993 @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: uipc_socket2.c,v 1.47 2002/09/27 15:37:47 provos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_socket2.c,v 1.48 2002/10/23 09:14:29 jdolecek Exp $"); #include #include @@ -301,7 +301,7 @@ sowakeup(struct socket *so, struct sockbuf *sb) { struct proc *p; - selwakeup(&sb->sb_sel); + selnotify(&sb->sb_sel, 0); sb->sb_flags &= ~SB_SEL; if (sb->sb_flags & SB_WAIT) { sb->sb_flags &= ~SB_WAIT; diff --git a/sys/kern/uipc_syscalls.c b/sys/kern/uipc_syscalls.c index 76e18cbb2514..cc69b1f1ab41 100644 --- a/sys/kern/uipc_syscalls.c +++ b/sys/kern/uipc_syscalls.c @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_syscalls.c,v 1.70 2002/09/04 01:32:44 matt Exp $ */ +/* $NetBSD: uipc_syscalls.c,v 1.71 2002/10/23 09:14:29 jdolecek Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1990, 1993 @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.70 2002/09/04 01:32:44 matt Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.71 2002/10/23 09:14:29 jdolecek Exp $"); #include "opt_ktrace.h" #include "opt_pipe.h" @@ -57,6 +57,7 @@ __KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.70 2002/09/04 01:32:44 matt Exp #ifdef KTRACE #include #endif +#include #include #include @@ -216,6 +217,10 @@ sys_accept(struct proc *p, void *v, register_t *retval) return (error); } *retval = fd; + + /* connection has been removed from the listen queue */ + KNOTE(&so->so_rcv.sb_sel.si_klist, 0); + { struct socket *aso = TAILQ_FIRST(&so->so_q); if (soqremque(aso, 1) == 0) panic("accept"); diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c index 8ddb26c8f759..ebf0f94f6961 100644 --- a/sys/kern/vfs_subr.c +++ b/sys/kern/vfs_subr.c @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_subr.c,v 1.180 2002/10/23 06:45:49 gmcgarry Exp $ */ +/* $NetBSD: vfs_subr.c,v 1.181 2002/10/23 09:14:30 jdolecek Exp $ */ /*- * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. @@ -82,7 +82,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.180 2002/10/23 06:45:49 gmcgarry Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.181 2002/10/23 09:14:30 jdolecek Exp $"); #include "opt_ddb.h" #include "opt_compat_netbsd.h" @@ -94,6 +94,7 @@ __KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.180 2002/10/23 06:45:49 gmcgarry Exp #include #include #include +#include #include #include #include @@ -1580,6 +1581,7 @@ vclean(vp, flags, p) vp->v_op = dead_vnodeop_p; vp->v_tag = VT_NON; simple_lock(&vp->v_interlock); + VN_KNOTE(vp, NOTE_REVOKE); /* FreeBSD has this in vn_pollgone() */ vp->v_flag &= ~VXLOCK; if (vp->v_flag & VXWANT) { vp->v_flag &= ~VXWANT; diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c index 41330f3ed3e6..5b80ee97a024 100644 --- a/sys/kern/vfs_vnops.c +++ b/sys/kern/vfs_vnops.c @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_vnops.c,v 1.56 2002/10/14 04:18:57 gmcgarry Exp $ */ +/* $NetBSD: vfs_vnops.c,v 1.57 2002/10/23 09:14:32 jdolecek Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1993 @@ -41,7 +41,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: vfs_vnops.c,v 1.56 2002/10/14 04:18:57 gmcgarry Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_vnops.c,v 1.57 2002/10/23 09:14:32 jdolecek Exp $"); #include "fs_union.h" @@ -77,7 +77,7 @@ static int vn_ioctl(struct file *fp, u_long com, caddr_t data, struct proc *p); struct fileops vnops = { vn_read, vn_write, vn_ioctl, vn_fcntl, vn_poll, - vn_statfile, vn_closefile + vn_statfile, vn_closefile, vn_kqfilter }; /* @@ -620,6 +620,18 @@ vn_poll(fp, events, p) return (VOP_POLL(((struct vnode *)fp->f_data), events, p)); } +/* + * File table vnode kqfilter routine. + */ +int +vn_kqfilter(fp, kn) + struct file *fp; + struct knote *kn; +{ + + return (VOP_KQFILTER((struct vnode *)fp->f_data, kn)); +} + /* * Check that the vnode is still valid, and if so * acquire requested lock. diff --git a/sys/kern/vnode_if.src b/sys/kern/vnode_if.src index 565ea0094f16..20891591090b 100644 --- a/sys/kern/vnode_if.src +++ b/sys/kern/vnode_if.src @@ -1,4 +1,4 @@ -# $NetBSD: vnode_if.src,v 1.30 2001/09/15 20:36:37 chs Exp $ +# $NetBSD: vnode_if.src,v 1.31 2002/10/23 09:14:32 jdolecek Exp $ # # Copyright (c) 1992, 1993 # The Regents of the University of California. All rights reserved. @@ -227,6 +227,14 @@ vop_poll { IN struct proc *p; }; +# +#% kqfilter vp U U U +# +vop_kqfilter { + IN struct vnode *vp; + IN struct knote *kn; +}; + # #% revoke vp U U U # diff --git a/sys/miscfs/fdesc/fdesc_vnops.c b/sys/miscfs/fdesc/fdesc_vnops.c index a247cfe744f9..56c72e16a052 100644 --- a/sys/miscfs/fdesc/fdesc_vnops.c +++ b/sys/miscfs/fdesc/fdesc_vnops.c @@ -1,4 +1,4 @@ -/* $NetBSD: fdesc_vnops.c,v 1.70 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: fdesc_vnops.c,v 1.71 2002/10/23 09:14:33 jdolecek Exp $ */ /* * Copyright (c) 1992, 1993 @@ -45,7 +45,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: fdesc_vnops.c,v 1.70 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: fdesc_vnops.c,v 1.71 2002/10/23 09:14:33 jdolecek Exp $"); #include #include @@ -100,6 +100,7 @@ int fdesc_read __P((void *)); int fdesc_write __P((void *)); int fdesc_ioctl __P((void *)); int fdesc_poll __P((void *)); +int fdesc_kqfilter __P((void *)); #define fdesc_mmap genfs_eopnotsupp #define fdesc_fcntl genfs_fcntl #define fdesc_fsync genfs_nullop @@ -150,6 +151,7 @@ const struct vnodeopv_entry_desc fdesc_vnodeop_entries[] = { { &vop_ioctl_desc, fdesc_ioctl }, /* ioctl */ { &vop_fcntl_desc, fdesc_fcntl }, /* fcntl */ { &vop_poll_desc, fdesc_poll }, /* poll */ + { &vop_kqfilter_desc, fdesc_kqfilter }, /* kqfilter */ { &vop_revoke_desc, fdesc_revoke }, /* revoke */ { &vop_mmap_desc, fdesc_mmap }, /* mmap */ { &vop_fsync_desc, fdesc_fsync }, /* fsync */ @@ -944,6 +946,41 @@ fdesc_poll(v) return (revents); } +int +fdesc_kqfilter(v) + void *v; +{ + struct vop_kqfilter_args /* { + struct vnode *a_vp; + struct knote *a_kn; + } */ *ap = v; + int error; + struct proc *p; + struct file *fp; + + switch (VTOFDESC(ap->a_vp)->fd_type) { + case Fctty: + error = (*ctty_cdevsw.d_kqfilter)(devctty, ap->a_kn); + break; + + case Fdesc: + /* just invoke kqfilter for the underlying descriptor */ + p = curproc; /* XXX hopefully ok to use curproc here */ + if ((fp = fd_getfile(p->p_fd, VTOFDESC(ap->a_vp)->fd_fd)) == NULL) + return (1); + + FILE_USE(fp); + error = (*fp->f_ops->fo_kqfilter)(fp, ap->a_kn); + FILE_UNUSE(fp, p); + break; + + default: + return (genfs_kqfilter(v)); + } + + return (error); +} + int fdesc_inactive(v) void *v; diff --git a/sys/miscfs/fifofs/fifo.h b/sys/miscfs/fifofs/fifo.h index bf3bd57aad0c..dc55498c1150 100644 --- a/sys/miscfs/fifofs/fifo.h +++ b/sys/miscfs/fifofs/fifo.h @@ -1,4 +1,4 @@ -/* $NetBSD: fifo.h,v 1.18 2001/12/06 04:27:41 chs Exp $ */ +/* $NetBSD: fifo.h,v 1.19 2002/10/23 09:14:35 jdolecek Exp $ */ /* * Copyright (c) 1991, 1993 @@ -51,6 +51,7 @@ int fifo_write __P((void *)); #define fifo_lease_check genfs_nullop int fifo_ioctl __P((void *)); int fifo_poll __P((void *)); +int fifo_kqfilter __P((void *)); #define fifo_revoke genfs_revoke #define fifo_mmap genfs_badop #define fifo_fsync genfs_nullop diff --git a/sys/miscfs/fifofs/fifo_vnops.c b/sys/miscfs/fifofs/fifo_vnops.c index ed4831e48da6..2ad2e5934c4e 100644 --- a/sys/miscfs/fifofs/fifo_vnops.c +++ b/sys/miscfs/fifofs/fifo_vnops.c @@ -1,4 +1,4 @@ -/* $NetBSD: fifo_vnops.c,v 1.35 2002/08/26 01:29:53 thorpej Exp $ */ +/* $NetBSD: fifo_vnops.c,v 1.36 2002/10/23 09:14:35 jdolecek Exp $ */ /* * Copyright (c) 1990, 1993, 1995 @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: fifo_vnops.c,v 1.35 2002/08/26 01:29:53 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: fifo_vnops.c,v 1.36 2002/10/23 09:14:35 jdolecek Exp $"); #include #include @@ -53,6 +53,7 @@ __KERNEL_RCSID(0, "$NetBSD: fifo_vnops.c,v 1.35 2002/08/26 01:29:53 thorpej Exp #include #include #include +#include #include #include @@ -85,6 +86,7 @@ const struct vnodeopv_entry_desc fifo_vnodeop_entries[] = { { &vop_lease_desc, fifo_lease_check }, /* lease */ { &vop_ioctl_desc, fifo_ioctl }, /* ioctl */ { &vop_poll_desc, fifo_poll }, /* poll */ + { &vop_kqfilter_desc, fifo_kqfilter }, /* kqfilter */ { &vop_revoke_desc, fifo_revoke }, /* revoke */ { &vop_mmap_desc, fifo_mmap }, /* mmap */ { &vop_fsync_desc, fifo_fsync }, /* fsync */ @@ -510,3 +512,92 @@ fifo_pathconf(void *v) } /* NOTREACHED */ } + +static void +filt_fifordetach(struct knote *kn) +{ + struct socket *so; + + so = (struct socket *)kn->kn_hook; + SLIST_REMOVE(&so->so_rcv.sb_sel.si_klist, kn, knote, kn_selnext); + if (SLIST_EMPTY(&so->so_rcv.sb_sel.si_klist)) + so->so_rcv.sb_flags &= ~SB_KNOTE; +} + +static int +filt_fiforead(struct knote *kn, long hint) +{ + struct socket *so; + + so = (struct socket *)kn->kn_hook; + kn->kn_data = so->so_rcv.sb_cc; + if (so->so_state & SS_CANTRCVMORE) { + kn->kn_flags |= EV_EOF; + return (1); + } + kn->kn_flags &= ~EV_EOF; + return (kn->kn_data > 0); +} + +static void +filt_fifowdetach(struct knote *kn) +{ + struct socket *so; + + so = (struct socket *)kn->kn_hook; + SLIST_REMOVE(&so->so_snd.sb_sel.si_klist, kn, knote, kn_selnext); + if (SLIST_EMPTY(&so->so_snd.sb_sel.si_klist)) + so->so_snd.sb_flags &= ~SB_KNOTE; +} + +static int +filt_fifowrite(struct knote *kn, long hint) +{ + struct socket *so; + + so = (struct socket *)kn->kn_hook; + kn->kn_data = sbspace(&so->so_snd); + if (so->so_state & SS_CANTSENDMORE) { + kn->kn_flags |= EV_EOF; + return (1); + } + kn->kn_flags &= ~EV_EOF; + return (kn->kn_data >= so->so_snd.sb_lowat); +} + +static const struct filterops fiforead_filtops = + { 1, NULL, filt_fifordetach, filt_fiforead }; +static const struct filterops fifowrite_filtops = + { 1, NULL, filt_fifowdetach, filt_fifowrite }; + +/* ARGSUSED */ +int +fifo_kqfilter(void *v) +{ + struct vop_kqfilter_args /* { + struct vnode *a_vp; + struct knote *a_kn; + } */ *ap = v; + struct socket *so; + struct sockbuf *sb; + + so = (struct socket *)ap->a_vp->v_fifoinfo->fi_readsock; + switch (ap->a_kn->kn_filter) { + case EVFILT_READ: + ap->a_kn->kn_fop = &fiforead_filtops; + sb = &so->so_rcv; + break; + case EVFILT_WRITE: + ap->a_kn->kn_fop = &fifowrite_filtops; + sb = &so->so_snd; + break; + default: + return (1); + } + + ap->a_kn->kn_hook = so; + + SLIST_INSERT_HEAD(&sb->sb_sel.si_klist, ap->a_kn, kn_selnext); + sb->sb_flags |= SB_KNOTE; + return (0); +} diff --git a/sys/miscfs/genfs/genfs.h b/sys/miscfs/genfs/genfs.h index 712182cd72f8..5b04c7004912 100644 --- a/sys/miscfs/genfs/genfs.h +++ b/sys/miscfs/genfs/genfs.h @@ -1,4 +1,4 @@ -/* $NetBSD: genfs.h,v 1.15 2001/12/18 07:49:36 chs Exp $ */ +/* $NetBSD: genfs.h,v 1.16 2002/10/23 09:14:36 jdolecek Exp $ */ int genfs_badop __P((void *)); int genfs_nullop __P((void *)); @@ -13,6 +13,7 @@ int genfs_noislocked __P((void *)); int genfs_nounlock __P((void *)); int genfs_poll __P((void *)); +int genfs_kqfilter __P((void *)); int genfs_fcntl __P((void *)); int genfs_fsync __P((void *)); int genfs_seek __P((void *)); diff --git a/sys/miscfs/genfs/genfs_vnops.c b/sys/miscfs/genfs/genfs_vnops.c index 3bc38b10cff0..4a2c976953c6 100644 --- a/sys/miscfs/genfs/genfs_vnops.c +++ b/sys/miscfs/genfs/genfs_vnops.c @@ -1,4 +1,4 @@ -/* $NetBSD: genfs_vnops.c,v 1.65 2002/10/21 15:21:35 fvdl Exp $ */ +/* $NetBSD: genfs_vnops.c,v 1.66 2002/10/23 09:14:36 jdolecek Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1993 @@ -35,7 +35,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: genfs_vnops.c,v 1.65 2002/10/21 15:21:35 fvdl Exp $"); +__KERNEL_RCSID(0, "$NetBSD: genfs_vnops.c,v 1.66 2002/10/23 09:14:36 jdolecek Exp $"); #include "opt_nfsserver.h" @@ -50,6 +50,7 @@ __KERNEL_RCSID(0, "$NetBSD: genfs_vnops.c,v 1.65 2002/10/21 15:21:35 fvdl Exp $" #include #include #include +#include #include #include @@ -1647,3 +1648,80 @@ genfs_compat_gop_write(struct vnode *vp, struct vm_page **pgs, int npages, uvm_aio_aiodone(bp); return (error); } + +static void +filt_genfsdetach(struct knote *kn) +{ + struct vnode *vp = (struct vnode *)kn->kn_hook; + + /* XXXLUKEM lock the struct? */ + SLIST_REMOVE(&vp->v_klist, kn, knote, kn_selnext); +} + +static int +filt_genfsread(struct knote *kn, long hint) +{ + struct vnode *vp = (struct vnode *)kn->kn_hook; + + /* + * filesystem is gone, so set the EOF flag and schedule + * the knote for deletion. + */ + if (hint == NOTE_REVOKE) { + kn->kn_flags |= (EV_EOF | EV_ONESHOT); + return (1); + } + + /* XXXLUKEM lock the struct? */ + kn->kn_data = vp->v_size - kn->kn_fp->f_offset; + return (kn->kn_data != 0); +} + +static int +filt_genfsvnode(struct knote *kn, long hint) +{ + + if (kn->kn_sfflags & hint) + kn->kn_fflags |= hint; + if (hint == NOTE_REVOKE) { + kn->kn_flags |= EV_EOF; + return (1); + } + return (kn->kn_fflags != 0); +} + +static const struct filterops genfsread_filtops = + { 1, NULL, filt_genfsdetach, filt_genfsread }; +static const struct filterops genfsvnode_filtops = + { 1, NULL, filt_genfsdetach, filt_genfsvnode }; + +int +genfs_kqfilter(void *v) +{ + struct vop_kqfilter_args /* { + struct vnode *a_vp; + struct knote *a_kn; + } */ *ap = v; + struct vnode *vp; + struct knote *kn; + + vp = ap->a_vp; + kn = ap->a_kn; + switch (kn->kn_filter) { + case EVFILT_READ: + kn->kn_fop = &genfsread_filtops; + break; + case EVFILT_VNODE: + kn->kn_fop = &genfsvnode_filtops; + break; + default: + return (1); + } + + kn->kn_hook = vp; + + /* XXXLUKEM lock the struct? */ + SLIST_INSERT_HEAD(&vp->v_klist, kn, kn_selnext); + + return (0); +} diff --git a/sys/miscfs/specfs/spec_vnops.c b/sys/miscfs/specfs/spec_vnops.c index cfe847bbd2fe..bc1d677bbdd3 100644 --- a/sys/miscfs/specfs/spec_vnops.c +++ b/sys/miscfs/specfs/spec_vnops.c @@ -1,4 +1,4 @@ -/* $NetBSD: spec_vnops.c,v 1.64 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: spec_vnops.c,v 1.65 2002/10/23 09:14:38 jdolecek Exp $ */ /* * Copyright (c) 1989, 1993 @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: spec_vnops.c,v 1.64 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: spec_vnops.c,v 1.65 2002/10/23 09:14:38 jdolecek Exp $"); #include #include @@ -95,6 +95,7 @@ const struct vnodeopv_entry_desc spec_vnodeop_entries[] = { { &vop_fcntl_desc, spec_fcntl }, /* fcntl */ { &vop_ioctl_desc, spec_ioctl }, /* ioctl */ { &vop_poll_desc, spec_poll }, /* poll */ + { &vop_kqfilter_desc, spec_kqfilter }, /* kqfilter */ { &vop_revoke_desc, spec_revoke }, /* revoke */ { &vop_mmap_desc, spec_mmap }, /* mmap */ { &vop_fsync_desc, spec_fsync }, /* fsync */ @@ -503,6 +504,36 @@ spec_poll(v) return (genfs_poll(v)); } } + +/* ARGSUSED */ +int +spec_kqfilter(v) + void *v; +{ + struct vop_kqfilter_args /* { + struct vnode *a_vp; + struct proc *a_kn; + } */ *ap = v; + const struct cdevsw *cdev; + dev_t dev; + + switch (ap->a_vp->v_type) { + + case VCHR: + dev = ap->a_vp->v_rdev; + cdev = cdevsw_lookup(dev); + if (cdev == NULL) + return (ENXIO); + return (*cdev->d_kqfilter)(dev, ap->a_kn); + default: + /* + * Block devices don't support kqfilter, and refuse it + * for any other files (like those vflush()ed) too. + */ + return (EOPNOTSUPP); + } +} + /* * Synch buffers associated with a block device */ diff --git a/sys/miscfs/specfs/specdev.h b/sys/miscfs/specfs/specdev.h index 264c870346c1..9233c3271463 100644 --- a/sys/miscfs/specfs/specdev.h +++ b/sys/miscfs/specfs/specdev.h @@ -1,4 +1,4 @@ -/* $NetBSD: specdev.h,v 1.21 2002/05/12 20:42:03 matt Exp $ */ +/* $NetBSD: specdev.h,v 1.22 2002/10/23 09:14:38 jdolecek Exp $ */ /* * Copyright (c) 1990, 1993 @@ -93,6 +93,7 @@ int spec_write __P((void *)); #define spec_fcntl genfs_fcntl int spec_ioctl __P((void *)); int spec_poll __P((void *)); +int spec_kqfilter __P((void *)); #define spec_revoke genfs_revoke #define spec_mmap genfs_mmap int spec_fsync __P((void *)); diff --git a/sys/msdosfs/msdosfs_vnops.c b/sys/msdosfs/msdosfs_vnops.c index c46d3d251762..65c251a2a19f 100644 --- a/sys/msdosfs/msdosfs_vnops.c +++ b/sys/msdosfs/msdosfs_vnops.c @@ -1,4 +1,4 @@ -/* $NetBSD: msdosfs_vnops.c,v 1.122 2002/09/27 15:37:49 provos Exp $ */ +/* $NetBSD: msdosfs_vnops.c,v 1.123 2002/10/23 09:14:39 jdolecek Exp $ */ /*- * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank. @@ -48,7 +48,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: msdosfs_vnops.c,v 1.122 2002/09/27 15:37:49 provos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: msdosfs_vnops.c,v 1.123 2002/10/23 09:14:39 jdolecek Exp $"); #include #include @@ -161,6 +161,7 @@ msdosfs_create(v) goto bad; if ((cnp->cn_flags & SAVESTART) == 0) PNBUF_PUT(cnp->cn_pnbuf); + VN_KNOTE(ap->a_dvp, NOTE_WRITE); vput(ap->a_dvp); *ap->a_vpp = DETOV(dep); return (0); @@ -438,9 +439,10 @@ msdosfs_setattr(v) de_changed = 1; } - if (de_changed) + if (de_changed) { + VN_KNOTE(vp, NOTE_ATTRIB); return (deupdat(dep, 1)); - else + } else return (0); } @@ -563,6 +565,7 @@ msdosfs_write(v) struct msdosfsmount *pmp = dep->de_pmp; struct ucred *cred = ap->a_cred; boolean_t async; + int extended=0; #ifdef MSDOSFS_DEBUG printf("msdosfs_write(vp %p, uio %p, ioflag %x, cred %p\n", @@ -631,6 +634,7 @@ msdosfs_write(v) if (dep->de_FileSize < uio->uio_offset + resid) { dep->de_FileSize = uio->uio_offset + resid; uvm_vnp_setsize(vp, dep->de_FileSize); + extended = 1; } do { @@ -667,6 +671,8 @@ msdosfs_write(v) * to the size it was before the write was attempted. */ errexit: + if (resid > uio->uio_resid) + VN_KNOTE(vp, NOTE_WRITE | (extended ? NOTE_EXTEND : 0)); if (error) { detrunc(dep, osize, ioflag & IO_SYNC, NOCRED, NULL); uio->uio_offset -= resid - uio->uio_resid; @@ -746,6 +752,8 @@ msdosfs_remove(v) printf("msdosfs_remove(), dep %p, v_usecount %d\n", dep, ap->a_vp->v_usecount); #endif + VN_KNOTE(ap->a_vp, NOTE_DELETE); + VN_KNOTE(ap->a_dvp, NOTE_WRITE); if (ddep == dep) vrele(ap->a_vp); else @@ -923,6 +931,7 @@ abortit: ip->de_flag |= DE_RENAME; doingdirectory++; } + VN_KNOTE(fdvp, NOTE_WRITE); /* XXXLUKEM/XXX: right place? */ /* * When the target exists, both the directory @@ -991,6 +1000,8 @@ abortit: } if ((error = removede(dp, xp)) != 0) goto bad; + VN_KNOTE(tdvp, NOTE_WRITE); + VN_KNOTE(tvp, NOTE_DELETE); cache_purge(tvp); vput(tvp); xp = NULL; @@ -1133,6 +1144,7 @@ abortit: } } + VN_KNOTE(fvp, NOTE_RENAME); VOP_UNLOCK(fvp, 0); bad: if (xp) @@ -1279,6 +1291,7 @@ msdosfs_mkdir(v) goto bad; if ((cnp->cn_flags & SAVESTART) == 0) PNBUF_PUT(cnp->cn_pnbuf); + VN_KNOTE(ap->a_dvp, NOTE_WRITE | NOTE_LINK); vput(ap->a_dvp); *ap->a_vpp = DETOV(dep); return (0); @@ -1343,6 +1356,7 @@ msdosfs_rmdir(v) * directory. Since dos filesystems don't do this we just purge * the name cache and let go of the parent directory denode. */ + VN_KNOTE(dvp, NOTE_WRITE | NOTE_LINK); cache_purge(dvp); vput(dvp); dvp = NULL; @@ -1352,6 +1366,7 @@ msdosfs_rmdir(v) error = detrunc(ip, (u_long)0, IO_SYNC, cnp->cn_cred, cnp->cn_proc); cache_purge(vp); out: + VN_KNOTE(vp, NOTE_DELETE); if (dvp) vput(dvp); vput(vp); @@ -1844,6 +1859,7 @@ const struct vnodeopv_entry_desc msdosfs_vnodeop_entries[] = { { &vop_fcntl_desc, genfs_fcntl }, /* fcntl */ { &vop_ioctl_desc, msdosfs_ioctl }, /* ioctl */ { &vop_poll_desc, msdosfs_poll }, /* poll */ + { &vop_kqfilter_desc, genfs_kqfilter }, /* kqfilter */ { &vop_revoke_desc, msdosfs_revoke }, /* revoke */ { &vop_mmap_desc, msdosfs_mmap }, /* mmap */ { &vop_fsync_desc, msdosfs_fsync }, /* fsync */ diff --git a/sys/net/bpf.c b/sys/net/bpf.c index f90a6c4f37f8..6a4b2c432a62 100644 --- a/sys/net/bpf.c +++ b/sys/net/bpf.c @@ -1,4 +1,4 @@ -/* $NetBSD: bpf.c,v 1.74 2002/09/25 22:21:46 thorpej Exp $ */ +/* $NetBSD: bpf.c,v 1.75 2002/10/23 09:14:41 jdolecek Exp $ */ /* * Copyright (c) 1990, 1991, 1993 @@ -43,7 +43,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.74 2002/09/25 22:21:46 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.75 2002/10/23 09:14:41 jdolecek Exp $"); #include "bpfilter.h" @@ -124,10 +124,11 @@ dev_type_read(bpfread); dev_type_write(bpfwrite); dev_type_ioctl(bpfioctl); dev_type_poll(bpfpoll); +dev_type_kqfilter(bpfkqfilter); const struct cdevsw bpf_cdevsw = { bpfopen, bpfclose, bpfread, bpfwrite, bpfioctl, - nostop, notty, bpfpoll, nommap, + nostop, notty, bpfpoll, nommap, bpfkqfilter, }; static int @@ -533,7 +534,7 @@ bpf_wakeup(d) psignal (p, SIGIO); } - selwakeup(&d->bd_sel); + selnotify(&d->bd_sel, 0); /* XXX */ d->bd_sel.si_pid = 0; } @@ -1059,6 +1060,59 @@ bpfpoll(dev, events, p) return (revents); } +static void +filt_bpfrdetach(struct knote *kn) +{ + struct bpf_d *d = kn->kn_hook; + int s; + + s = splnet(); + SLIST_REMOVE(&d->bd_sel.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_bpfread(struct knote *kn, long hint) +{ + struct bpf_d *d = kn->kn_hook; + + kn->kn_data = d->bd_hlen; + if (d->bd_immediate) + kn->kn_data += d->bd_slen; + return (kn->kn_data > 0); +} + +static const struct filterops bpfread_filtops = + { 1, NULL, filt_bpfrdetach, filt_bpfread }; + +int +bpfkqfilter(dev, kn) + dev_t dev; + struct knote *kn; +{ + struct bpf_d *d = &bpf_dtab[minor(dev)]; + struct klist *klist; + int s; + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &d->bd_sel.si_klist; + kn->kn_fop = &bpfread_filtops; + break; + + default: + return (1); + } + + kn->kn_hook = d; + + s = splnet(); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + splx(s); + + return (0); +} + /* * Incoming linkage from device drivers. Process the packet pkt, of length * pktlen, which is stored in a contiguous buffer. The packet is parsed diff --git a/sys/net/if_tun.c b/sys/net/if_tun.c index 950d07696a91..a1c90a29c685 100644 --- a/sys/net/if_tun.c +++ b/sys/net/if_tun.c @@ -1,4 +1,4 @@ -/* $NetBSD: if_tun.c,v 1.55 2002/09/23 05:51:11 simonb Exp $ */ +/* $NetBSD: if_tun.c,v 1.56 2002/10/23 09:14:42 jdolecek Exp $ */ /* * Copyright (c) 1988, Julian Onions @@ -15,7 +15,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.55 2002/09/23 05:51:11 simonb Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.56 2002/10/23 09:14:42 jdolecek Exp $"); #include "tun.h" @@ -97,10 +97,11 @@ dev_type_read(tunread); dev_type_write(tunwrite); dev_type_ioctl(tunioctl); dev_type_poll(tunpoll); +dev_type_kqfilter(tunkqfilter); const struct cdevsw tun_cdevsw = { tunopen, tunclose, tunread, tunwrite, tunioctl, - nostop, notty, tunpoll, nommap, + nostop, notty, tunpoll, nommap, tunkqfilter, }; void @@ -314,7 +315,7 @@ tunclose(dev, flag, mode, p) splx(s); } tp->tun_pgrp = 0; - selwakeup(&tp->tun_rsel); + selnotify(&tp->tun_rsel, 0); TUNDEBUG ("%s: closed\n", ifp->if_xname); simple_unlock(&tp->tun_lock); @@ -518,7 +519,7 @@ tun_output(ifp, m0, dst, rt) else if ((p = pfind(-tp->tun_pgrp)) != NULL) psignal(p, SIGIO); } - selwakeup(&tp->tun_rsel); + selnotify(&tp->tun_rsel, 0); simple_unlock(&tp->tun_lock); return (0); } @@ -923,3 +924,73 @@ tunpoll(dev, events, p) simple_unlock(&tp->tun_lock); return (revents); } + +static void +filt_tunrdetach(struct knote *kn) +{ + struct tun_softc *tp = kn->kn_hook; + int s; + + s = splnet(); + SLIST_REMOVE(&tp->tun_rsel.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_tunread(struct knote *kn, long hint) +{ + struct tun_softc *tp = kn->kn_hook; + struct ifnet *ifp = &tp->tun_if; + struct mbuf *m; + int s; + + s = splnet(); + IF_POLL(&ifp->if_snd, m); + if (m == NULL) { + splx(s); + return (0); + } + + for (kn->kn_data = 0; m != NULL; m = m->m_next) + kn->kn_data += m->m_len; + + splx(s); + return (1); +} + +static const struct filterops tunread_filtops = + { 1, NULL, filt_tunrdetach, filt_tunread }; + +static const struct filterops tun_seltrue_filtops = + { 1, NULL, filt_tunrdetach, filt_seltrue }; + +int +tunkqfilter(dev_t dev, struct knote *kn) +{ + struct tun_softc *tp = tun_find_unit(dev); + struct klist *klist; + int s; + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &tp->tun_rsel.si_klist; + kn->kn_fop = &tunread_filtops; + break; + + case EVFILT_WRITE: + klist = &tp->tun_rsel.si_klist; + kn->kn_fop = &tun_seltrue_filtops; + break; + + default: + return (1); + } + + kn->kn_hook = tp; + + s = splnet(); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + splx(s); + + return (0); +} diff --git a/sys/netinet/ip_fil.c b/sys/netinet/ip_fil.c index cafed52a1ea8..440202f68028 100644 --- a/sys/netinet/ip_fil.c +++ b/sys/netinet/ip_fil.c @@ -1,4 +1,4 @@ -/* $NetBSD: ip_fil.c,v 1.86 2002/09/19 08:12:47 martti Exp $ */ +/* $NetBSD: ip_fil.c,v 1.87 2002/10/23 09:14:43 jdolecek Exp $ */ /* * Copyright (C) 1993-2001 by Darren Reed. @@ -123,7 +123,7 @@ extern int ip_optcopy __P((struct ip *, struct ip *)); #if !defined(lint) #if defined(__NetBSD__) #include -__KERNEL_RCSID(0, "$NetBSD: ip_fil.c,v 1.86 2002/09/19 08:12:47 martti Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ip_fil.c,v 1.87 2002/10/23 09:14:43 jdolecek Exp $"); #else static const char sccsid[] = "@(#)ip_fil.c 2.41 6/5/96 (C) 1993-2000 Darren Reed"; static const char rcsid[] = "@(#)Id: ip_fil.c,v 2.42.2.60 2002/08/28 12:40:39 darrenr Exp"; @@ -202,9 +202,11 @@ toid_t ipfr_slowtimer_ch; #if defined(__NetBSD__) && (__NetBSD_Version__ >= 106080000) && \ defined(_KERNEL) #include +#include + const struct cdevsw ipl_cdevsw = { iplopen, iplclose, iplread, nowrite, iplioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; #endif diff --git a/sys/netisdn/i4b_ctl.c b/sys/netisdn/i4b_ctl.c index 108d641625e9..c808f78532c6 100644 --- a/sys/netisdn/i4b_ctl.c +++ b/sys/netisdn/i4b_ctl.c @@ -27,7 +27,7 @@ * i4b_ctl.c - i4b system control port driver * ------------------------------------------ * - * $Id: i4b_ctl.c,v 1.10 2002/09/06 13:18:43 gehenna Exp $ + * $Id: i4b_ctl.c,v 1.11 2002/10/23 09:14:44 jdolecek Exp $ * * $FreeBSD$ * @@ -36,7 +36,7 @@ *---------------------------------------------------------------------------*/ #include -__KERNEL_RCSID(0, "$NetBSD: i4b_ctl.c,v 1.10 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: i4b_ctl.c,v 1.11 2002/10/23 09:14:44 jdolecek Exp $"); #include "isdnctl.h" @@ -156,7 +156,7 @@ int isdnctlioctl __P((dev_t dev, u_long cmd, caddr_t data, int flag, struct proc #ifdef __NetBSD__ const struct cdevsw isdnctl_cdevsw = { isdnctlopen, isdnctlclose, noread, nowrite, isdnctlioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; #endif /* __NetBSD__ */ diff --git a/sys/netisdn/i4b_i4bdrv.c b/sys/netisdn/i4b_i4bdrv.c index ebb074cba3ad..feed725b1465 100644 --- a/sys/netisdn/i4b_i4bdrv.c +++ b/sys/netisdn/i4b_i4bdrv.c @@ -27,7 +27,7 @@ * i4b_i4bdrv.c - i4b userland interface driver * -------------------------------------------- * - * $Id: i4b_i4bdrv.c,v 1.20 2002/09/06 13:18:43 gehenna Exp $ + * $Id: i4b_i4bdrv.c,v 1.21 2002/10/23 09:14:45 jdolecek Exp $ * * $FreeBSD$ * @@ -36,7 +36,7 @@ *---------------------------------------------------------------------------*/ #include -__KERNEL_RCSID(0, "$NetBSD: i4b_i4bdrv.c,v 1.20 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: i4b_i4bdrv.c,v 1.21 2002/10/23 09:14:45 jdolecek Exp $"); #include "isdn.h" @@ -118,6 +118,7 @@ PDEVSTATIC int isdnioctl __P((dev_t dev, u_long cmd, caddr_t data, int flag, str #ifdef OS_USES_POLL PDEVSTATIC int isdnpoll __P((dev_t dev, int events, struct proc *p)); +PDEVSTATIC int isdnkqfilter __P((dev_t dev, struct knote *kn)); #else PDEVSTATIC int isdnselect __P((dev_t dev, int rw, struct proc *p)); #endif @@ -196,7 +197,7 @@ SYSINIT(i4bdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,i4b_drvinit,NULL) #ifdef __NetBSD__ const struct cdevsw isdn_cdevsw = { isdnopen, isdnclose, isdnread, nowrite, isdnioctl, - nostop, notty, isdnpoll, nommap, + nostop, notty, isdnpoll, nommap, isdnkqfilter, }; #endif /* __NetBSD__ */ @@ -942,6 +943,66 @@ isdnpoll(dev_t dev, int events, struct proc *p) return(0); } +static void +filt_i4brdetach(struct knote *kn) +{ + int s; + + s = splnet(); + SLIST_REMOVE(&select_rd_info.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_i4bread(struct knote *kn, long hint) +{ + struct mbuf *m; + + if (IF_QEMPTY(&i4b_rdqueue)) + return (0); + + IF_POLL(&i4b_rdqueue, m); + + kn->kn_data = m->m_len; + return (1); +} + +static const struct filterops i4bread_filtops = + { 1, NULL, filt_i4brdetach, filt_i4bread }; + +static const struct filterops i4b_seltrue_filtops = + { 1, NULL, filt_i4brdetach, filt_seltrue }; + +int +isdnkqfilter(dev_t dev, struct knote *kn) +{ + struct klist *klist; + int s; + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &select_rd_info.si_klist; + kn->kn_fop = &i4bread_filtops; + break; + + case EVFILT_WRITE: + klist = &select_rd_info.si_klist; + kn->kn_fop = &i4b_seltrue_filtops; + break; + + default: + return (1); + } + + kn->kn_hook = NULL; + + s = splnet(); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + splx(s); + + return (0); +} + #endif /* OS_USES_SELECT */ /*---------------------------------------------------------------------------* @@ -981,7 +1042,7 @@ i4bputqueue(struct mbuf *m) if(selflag) { selflag = 0; - selwakeup(&select_rd_info); + selnotify(&select_rd_info, 0); } } @@ -1022,7 +1083,7 @@ i4bputqueue_hipri(struct mbuf *m) if(selflag) { selflag = 0; - selwakeup(&select_rd_info); + selnotify(&select_rd_info, 0); } } diff --git a/sys/netisdn/i4b_rbch.c b/sys/netisdn/i4b_rbch.c index 7b9a5cd1370f..7e0152bd0c1b 100644 --- a/sys/netisdn/i4b_rbch.c +++ b/sys/netisdn/i4b_rbch.c @@ -27,7 +27,7 @@ * i4b_rbch.c - device driver for raw B channel data * --------------------------------------------------- * - * $Id: i4b_rbch.c,v 1.10 2002/09/06 13:18:43 gehenna Exp $ + * $Id: i4b_rbch.c,v 1.11 2002/10/23 09:14:45 jdolecek Exp $ * * $FreeBSD$ * @@ -36,7 +36,7 @@ *---------------------------------------------------------------------------*/ #include -__KERNEL_RCSID(0, "$NetBSD: i4b_rbch.c,v 1.10 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: i4b_rbch.c,v 1.11 2002/10/23 09:14:45 jdolecek Exp $"); #include "isdnbchan.h" @@ -183,6 +183,7 @@ int isdnbchanwrite __P((dev_t dev, struct uio *uio, int ioflag)); int isdnbchanioctl __P((dev_t dev, IOCTL_CMD_T cmd, caddr_t arg, int flag, struct proc* pr)); #ifdef OS_USES_POLL int isdnbchanpoll __P((dev_t dev, int events, struct proc *p)); +int isdnbchankqfilter __P((dev_t dev, struct knote *kn)); #else PDEVSTATIC int isdnbchanselect __P((dev_t dev, int rw, struct proc *p)); #endif @@ -796,6 +797,90 @@ isdnbchanpoll(dev_t dev, int events, struct proc *p) return(revents); } +static void +filt_i4brbchdetach(struct knote *kn) +{ + struct rbch_softc *sc = kn->kn_hook; + int s; + + s = splhigh(); + SLIST_REMOVE(&sc->selp.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_i4brbchread(struct knote *kn, long hint) +{ + struct rbch_softc *sc = kn->kn_hook; + struct ifqueue *iqp; + + if ((sc->sc_devstate & ST_CONNECTED) == 0) + return (0); + + if (sc->sc_bprot == BPROT_RHDLC) + iqp = &sc->sc_hdlcq; + else + iqp = sc->sc_ilt->rx_queue; + + if (IF_QEMPTY(iqp)) + return (0); + + kn->kn_data = 0; /* XXXLUKEM (thorpej): what to put here? */ + return (1); +} + +static const struct filterops i4brbchread_filtops = + { 1, NULL, filt_i4brbchdetach, filt_i4brbchread }; + +static int +filt_i4brbchwrite(struct knote *kn, long hint) +{ + struct rbch_softc *sc = kn->kn_hook; + + if ((sc->sc_devstate & ST_CONNECTED) == 0) + return (0); + + if (IF_QFULL(sc->sc_ilt->tx_queue)) + return (0); + + kn->kn_data = 0; /* XXXLUKEM (thorpej): what to put here? */ + return (1); +} + +static const struct filterops i4brbchwrite_filtops = + { 1, NULL, filt_i4brbchdetach, filt_i4brbchwrite }; + +int +isdnbchankqfilter(dev_t dev, struct knote *kn) +{ + struct rbch_softc *sc = &rbch_softc[minor(dev)]; + struct klist *klist; + int s; + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &sc->selp.si_klist; + kn->kn_fop = &i4brbchread_filtops; + break; + + case EVFILT_WRITE: + klist = &sc->selp.si_klist; + kn->kn_fop = &i4brbchwrite_filtops; + break; + + default: + return (1); + } + + kn->kn_hook = sc; + + s = splhigh(); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + splx(s); + + return (0); +} + #else /* OS_USES_POLL */ /*---------------------------------------------------------------------------* @@ -1031,7 +1116,7 @@ rbch_rx_data_rdy(void *softc) { NDBGL4(L4_RBCHDBG, "(minor=%d) NO wakeup", sc->sc_unit); } - selwakeup(&sc->selp); + selnotify(&sc->selp, 0); } /*---------------------------------------------------------------------------* @@ -1054,7 +1139,7 @@ rbch_tx_queue_empty(void *softc) { NDBGL4(L4_RBCHDBG, "(minor=%d) NO wakeup", sc->sc_unit); } - selwakeup(&sc->selp); + selnotify(&sc->selp, 0); } /*---------------------------------------------------------------------------* @@ -1068,7 +1153,7 @@ rbch_activity(void *softc, int rxtx) if (sc->sc_cd) sc->sc_cd->last_active_time = SECOND; - selwakeup(&sc->selp); + selnotify(&sc->selp, 0); } /*---------------------------------------------------------------------------* diff --git a/sys/netisdn/i4b_tel.c b/sys/netisdn/i4b_tel.c index c020aefc3cb0..26bd5b8f6e33 100644 --- a/sys/netisdn/i4b_tel.c +++ b/sys/netisdn/i4b_tel.c @@ -27,7 +27,7 @@ * i4b_tel.c - device driver for ISDN telephony * -------------------------------------------- * - * $Id: i4b_tel.c,v 1.10 2002/09/06 13:18:43 gehenna Exp $ + * $Id: i4b_tel.c,v 1.11 2002/10/23 09:14:46 jdolecek Exp $ * * $FreeBSD$ * @@ -36,7 +36,7 @@ *---------------------------------------------------------------------------*/ #include -__KERNEL_RCSID(0, "$NetBSD: i4b_tel.c,v 1.10 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: i4b_tel.c,v 1.11 2002/10/23 09:14:46 jdolecek Exp $"); #include "isdntel.h" @@ -188,6 +188,7 @@ int isdntelwrite __P((dev_t dev, struct uio * uio, int ioflag)); #ifdef OS_USES_POLL int isdntelpoll __P((dev_t dev, int events, struct proc *p)); +int isdntelkqfilter __P((dev_t dev, struct knote *kn)); #else int isdntelsel __P((dev_t dev, int rw, struct proc *p)); #endif @@ -197,7 +198,7 @@ int isdntelsel __P((dev_t dev, int rw, struct proc *p)); #ifdef __NetBSD__ const struct cdevsw isdntel_cdevsw = { isdntelopen, isdntelclose, isdntelread, isdntelwrite, isdntelioctl, - nostop, notty, isdntelpoll, nommap, + nostop, notty, isdntelpoll, nommap, isdntelkqfilter, }; #endif /* __NetBSD__ */ @@ -939,6 +940,117 @@ isdntelpoll(dev_t dev, int events, struct proc *p) return(revents); } +static void +filt_i4btel_detach(struct knote *kn) +{ + tel_sc_t *sc = kn->kn_hook; + int s; + + s = splhigh(); + SLIST_REMOVE(&sc->selp.si_klist, kn, knote, kn_selnext); + splx(s); +} + +static int +filt_i4btel_telread(struct knote *kn, long hint) +{ + tel_sc_t *sc = kn->kn_hook; + + if ((sc->devstate & ST_CONNECTED) == 0) + return (0); + if (sc->isdn_linktab == NULL) + return (0); + if (IF_QEMPTY(sc->isdn_linktab->rx_queue)) + return (0); + + kn->kn_data = 0; /* XXXLUKEM (thorpej): what to put here? */ + return (1); +} + +static const struct filterops i4btel_telread_filtops = + { 1, NULL, filt_i4btel_detach, filt_i4btel_telread }; + +static int +filt_i4btel_telwrite(struct knote *kn, long hint) +{ + tel_sc_t *sc = kn->kn_hook; + + if ((sc->devstate & ST_CONNECTED) == 0) + return (0); + if (sc->isdn_linktab == NULL) + return (0); + if (IF_QFULL(sc->isdn_linktab->tx_queue)) + return (0); + + kn->kn_data = 0; /* XXXLUKEM (thorpej): what to put here? */ + return (1); +} + +static const struct filterops i4btel_telwrite_filtops = + { 1, NULL, filt_i4btel_detach, filt_i4btel_telwrite }; + +static int +filt_i4btel_dialread(struct knote *kn, long hint) +{ + tel_sc_t *sc = kn->kn_hook; + + if (sc->result == 0) + return (0); + + kn->kn_data = 0; /* XXXLUKEM (thorpej): what to put here? */ + return (1); +} + +static const struct filterops i4btel_dialread_filtops = + { 1, NULL, filt_i4btel_detach, filt_i4btel_dialread }; + +static const struct filterops i4btel_seltrue_filtops = + { 1, NULL, filt_i4btel_detach, filt_seltrue }; + +int +isdntelkqfilter(dev_t dev, struct knote *kn) +{ + int s; + int unit = UNIT(dev); + int func = FUNC(dev); + + struct klist *klist; + tel_sc_t *sc = &tel_sc[unit][func]; + + switch (kn->kn_filter) { + case EVFILT_READ: + klist = &sc->selp.si_klist; + if (func == FUNCTEL) + kn->kn_fop = &i4btel_telread_filtops; + else if (func == FUNCDIAL) + kn->kn_fop = &i4btel_dialread_filtops; + else + return (1); + break; + + case EVFILT_WRITE: + klist = &sc->selp.si_klist; + if (func == FUNCTEL) + kn->kn_fop = &i4btel_telwrite_filtops; + else if (func == FUNCDIAL) + kn->kn_fop = &i4btel_seltrue_filtops; + else + return (1); + break; + + default: + return (1); + } + + kn->kn_hook = sc; + + s = splhigh(); + SLIST_INSERT_HEAD(klist, kn, kn_selnext); + splx(s); + + return (0); +} + #else /* OS_USES_POLL */ /*---------------------------------------------------------------------------* @@ -1049,7 +1161,7 @@ tel_connect(void *softc, void *cdp) sc->devstate &= ~ST_RDWAITDATA; wakeup((caddr_t) &sc->result); } - selwakeup(&sc->selp); + selnotify(&sc->selp, 0); } } @@ -1090,7 +1202,7 @@ tel_disconnect(void *softc, void *cdp) sc->devstate &= ~ST_RDWAITDATA; wakeup((caddr_t) &sc->result); } - selwakeup(&sc->selp); + selnotify(&sc->selp, 0); if (sc->devstate & ST_TONE) { sc->devstate &= ~ST_TONE; @@ -1118,7 +1230,7 @@ tel_dialresponse(void *softc, int status, cause_t cause) sc->devstate &= ~ST_RDWAITDATA; wakeup((caddr_t) &sc->result); } - selwakeup(&sc->selp); + selnotify(&sc->selp, 0); } } @@ -1145,7 +1257,7 @@ tel_rx_data_rdy(void *softc) sc->devstate &= ~ST_RDWAITDATA; wakeup((caddr_t) &sc->isdn_linktab->rx_queue); } - selwakeup(&sc->selp); + selnotify(&sc->selp, 0); } /*---------------------------------------------------------------------------* @@ -1166,7 +1278,7 @@ tel_tx_queue_empty(void *softc) if(sc->devstate & ST_TONE) { tel_tone(sc); } else { - selwakeup(&sc->selp); + selnotify(&sc->selp, 0); } } diff --git a/sys/netisdn/i4b_trace.c b/sys/netisdn/i4b_trace.c index f933b4e5eb50..068d55cce17f 100644 --- a/sys/netisdn/i4b_trace.c +++ b/sys/netisdn/i4b_trace.c @@ -27,7 +27,7 @@ * i4btrc - device driver for trace data read device * --------------------------------------------------- * - * $Id: i4b_trace.c,v 1.11 2002/09/06 13:18:43 gehenna Exp $ + * $Id: i4b_trace.c,v 1.12 2002/10/23 09:14:46 jdolecek Exp $ * * last edit-date: [Fri Jan 5 11:33:47 2001] * @@ -35,7 +35,7 @@ *---------------------------------------------------------------------------*/ #include -__KERNEL_RCSID(0, "$NetBSD: i4b_trace.c,v 1.11 2002/09/06 13:18:43 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: i4b_trace.c,v 1.12 2002/10/23 09:14:46 jdolecek Exp $"); #include "isdntrc.h" @@ -90,7 +90,7 @@ int isdntrcioctl __P((dev_t dev, u_long cmd, caddr_t data, int flag, struct proc #ifdef __NetBSD__ const struct cdevsw isdntrc_cdevsw = { isdntrcopen, isdntrcclose, isdntrcread, nowrite, isdntrcioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter, }; #endif /* __NetBSD__ */ diff --git a/sys/netsmb/smb_dev.c b/sys/netsmb/smb_dev.c index fcfb282a95a5..7b43e637d949 100644 --- a/sys/netsmb/smb_dev.c +++ b/sys/netsmb/smb_dev.c @@ -1,4 +1,4 @@ -/* $NetBSD: smb_dev.c,v 1.8 2002/10/11 21:35:42 jdolecek Exp $ */ +/* $NetBSD: smb_dev.c,v 1.9 2002/10/23 09:14:47 jdolecek Exp $ */ /* * Copyright (c) 2000-2001 Boris Popov @@ -107,7 +107,7 @@ dev_type_ioctl(nsmb_dev_ioctl); const struct cdevsw netsmb_cdevsw = { nsmb_dev_open, nsmb_dev_close, noread, nowrite, - nsmb_dev_ioctl, nostop, notty, nopoll, nommap, + nsmb_dev_ioctl, nostop, notty, nopoll, nommap, nokqfilter, }; #else static struct cdevsw nsmb_cdevsw = { diff --git a/sys/nfs/files.nfs b/sys/nfs/files.nfs index 8944b03915a0..0d5ac63f331c 100644 --- a/sys/nfs/files.nfs +++ b/sys/nfs/files.nfs @@ -1,4 +1,4 @@ -# $NetBSD: files.nfs,v 1.1 2002/04/16 23:14:09 thorpej Exp $ +# $NetBSD: files.nfs,v 1.2 2002/10/23 09:14:48 jdolecek Exp $ deffs fs_nfs.h NFS @@ -17,6 +17,7 @@ file nfs/nfs_bio.c nfs file nfs/nfs_boot.c nfs file nfs/nfs_bootdhcp.c nfs & (nfs_boot_bootp | nfs_boot_dhcp) file nfs/nfs_bootparam.c nfs & nfs_boot_bootparam +file nfs/nfs_kq.c nfs file nfs/nfs_node.c nfs file nfs/nfs_nqlease.c nfsserver | nfs file nfs/nfs_serv.c nfsserver diff --git a/sys/nfs/nfs_bio.c b/sys/nfs/nfs_bio.c index 429d23f26d49..856f4fe534e1 100644 --- a/sys/nfs/nfs_bio.c +++ b/sys/nfs/nfs_bio.c @@ -1,4 +1,4 @@ -/* $NetBSD: nfs_bio.c,v 1.83 2002/10/21 12:52:32 yamt Exp $ */ +/* $NetBSD: nfs_bio.c,v 1.84 2002/10/23 09:14:48 jdolecek Exp $ */ /* * Copyright (c) 1989, 1993 @@ -39,7 +39,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: nfs_bio.c,v 1.83 2002/10/21 12:52:32 yamt Exp $"); +__KERNEL_RCSID(0, "$NetBSD: nfs_bio.c,v 1.84 2002/10/23 09:14:48 jdolecek Exp $"); #include "opt_nfs.h" #include "opt_ddb.h" @@ -521,6 +521,7 @@ nfs_write(v) voff_t oldoff, origoff; vsize_t bytelen; int error = 0, iomode, must_commit; + int extended = 0, wrotedta = 0; #ifdef DIAGNOSTIC if (uio->uio_rw != UIO_WRITE) @@ -633,6 +634,7 @@ nfs_write(v) if (error) { break; } + wrotedta = 1; /* * update UVM's notion of the size now that we've @@ -641,6 +643,7 @@ nfs_write(v) if (vp->v_size < uio->uio_offset) { uvm_vnp_setsize(vp, uio->uio_offset); + extended = 1; } if ((oldoff & ~(nmp->nm_wsize - 1)) != @@ -652,6 +655,8 @@ nfs_write(v) ~(nmp->nm_wsize - 1)), PGO_CLEANIT); } } while (uio->uio_resid > 0); + if (wrotedta) + VN_KNOTE(vp, NOTE_WRITE | (extended ? NOTE_EXTEND : 0)); if ((np->n_flag & NQNFSNONCACHE) || (ioflag & IO_SYNC)) { simple_lock(&vp->v_interlock); error = VOP_PUTPAGES(vp, diff --git a/sys/nfs/nfs_kq.c b/sys/nfs/nfs_kq.c new file mode 100644 index 000000000000..7427e944167f --- /dev/null +++ b/sys/nfs/nfs_kq.c @@ -0,0 +1,328 @@ +/* $NetBSD: nfs_kq.c,v 1.2 2002/10/23 09:14:49 jdolecek Exp $ */ + +/*- + * Copyright (c) 2002 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jaromir Dolecek. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__KERNEL_RCSID(0, "$NetBSD: nfs_kq.c,v 1.2 2002/10/23 09:14:49 jdolecek Exp $"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +struct kevq { + SLIST_ENTRY(kevq) kev_link; + struct vnode *vp; + u_int usecount; + u_int flags; +#define KEVQ_BUSY 0x01 /* currently being processed */ +#define KEVQ_WANT 0x02 /* want to change this entry */ + struct timespec omtime; /* old modification time */ + struct timespec octime; /* old change time */ + nlink_t onlink; /* old number of references to file */ +}; +SLIST_HEAD(kevqlist, kevq); + +static struct lock nfskevq_lock; +static struct proc *pnfskq; +static struct kevqlist kevlist = SLIST_HEAD_INITIALIZER(kevlist); + +void +nfs_kqinit(void) +{ + lockinit(&nfskevq_lock, PSOCK, "nfskqlck", 0, 0); +} + +/* + * This quite simplistic routine periodically checks for server changes + * of any of the watched files every NFS_MINATTRTIME/2 seconds. + * Only changes in size, modification time, change time and nlinks + * are being checked, everything else is ignored. + * The routine only calls VOP_GETATTR() when it's likely it would get + * some new data, i.e. when the vnode expires from attrcache. This + * should give same result as periodically running stat(2) from userland, + * while keeping CPU/network usage low, and still provide proper kevent + * semantics. + * The poller thread is created when first vnode is added to watch list, + * and exits when the watch list is empty. The overhead of thread creation + * isn't really important, neither speed of attach and detach of knote. + */ +/* ARGSUSED */ +static void +nfs_kqpoll(void *arg) +{ + struct kevq *ke; + struct vattr attr; + int error; + struct proc *p = pnfskq; + u_quad_t osize; + + for(;;) { + lockmgr(&nfskevq_lock, LK_EXCLUSIVE, NULL); + SLIST_FOREACH(ke, &kevlist, kev_link) { + /* skip if still in attrcache */ + if (nfs_getattrcache(ke->vp, &attr) != ENOENT) + continue; + + /* + * Mark entry busy, release lock and check + * for changes. + */ + ke->flags |= KEVQ_BUSY; + lockmgr(&nfskevq_lock, LK_RELEASE, NULL); + + /* save v_size, nfs_getattr() updates it */ + osize = ke->vp->v_size; + + error = VOP_GETATTR(ke->vp, &attr, p->p_ucred, p); + + /* following is a bit fragile, but about best + * we can get */ + if (attr.va_size != osize) { + int extended = (attr.va_size > osize); + VN_KNOTE(ke->vp, NOTE_WRITE + | (extended ? NOTE_EXTEND : 0)); + ke->omtime = attr.va_mtime; + } else if (attr.va_mtime.tv_sec != ke->omtime.tv_sec + || attr.va_mtime.tv_nsec != ke->omtime.tv_nsec) { + VN_KNOTE(ke->vp, NOTE_WRITE); + ke->omtime = attr.va_mtime; + } + + if (attr.va_ctime.tv_sec != ke->octime.tv_sec + || attr.va_ctime.tv_nsec != ke->octime.tv_nsec) { + VN_KNOTE(ke->vp, NOTE_ATTRIB); + ke->octime = attr.va_ctime; + } + + if (attr.va_nlink != ke->onlink) { + VN_KNOTE(ke->vp, NOTE_LINK); + ke->onlink = attr.va_nlink; + } + + lockmgr(&nfskevq_lock, LK_EXCLUSIVE, NULL); + ke->flags &= ~KEVQ_BUSY; + if (ke->flags & KEVQ_WANT) { + ke->flags &= ~KEVQ_WANT; + wakeup(ke); + } + } + + if (SLIST_EMPTY(&kevlist)) { + /* Nothing more to watch, exit */ + pnfskq = NULL; + lockmgr(&nfskevq_lock, LK_RELEASE, NULL); + kthread_exit(0); + } + lockmgr(&nfskevq_lock, LK_RELEASE, NULL); + + /* wait a while before checking for changes again */ + tsleep(pnfskq, PSOCK, "nfskqpw", + NFS_MINATTRTIMO * hz / 2); + + } +} + +static void +filt_nfsdetach(struct knote *kn) +{ + struct vnode *vp = (struct vnode *)kn->kn_hook; + struct kevq *ke; + + /* XXXLUKEM lock the struct? */ + SLIST_REMOVE(&vp->v_klist, kn, knote, kn_selnext); + + /* Remove the vnode from watch list */ + lockmgr(&nfskevq_lock, LK_EXCLUSIVE, NULL); + SLIST_FOREACH(ke, &kevlist, kev_link) { + if (ke->vp == vp) { + while (ke->flags & KEVQ_BUSY) { + ke->flags |= KEVQ_WANT; + lockmgr(&nfskevq_lock, LK_RELEASE, NULL); + (void) tsleep(ke, PSOCK, "nfskqdet", 0); + lockmgr(&nfskevq_lock, LK_EXCLUSIVE, NULL); + } + + if (ke->usecount > 1) { + /* keep, other kevents need this */ + ke->usecount--; + } else { + /* last user, g/c */ + SLIST_REMOVE(&kevlist, ke, kevq, kev_link); + FREE(ke, M_KEVENT); + } + break; + } + } + lockmgr(&nfskevq_lock, LK_RELEASE, NULL); +} + +static int +filt_nfsread(struct knote *kn, long hint) +{ + struct vnode *vp = (struct vnode *)kn->kn_hook; + + /* + * filesystem is gone, so set the EOF flag and schedule + * the knote for deletion. + */ + if (hint == NOTE_REVOKE) { + kn->kn_flags |= (EV_EOF | EV_ONESHOT); + return (1); + } + + /* XXXLUKEM lock the struct? */ + kn->kn_data = vp->v_size - kn->kn_fp->f_offset; + return (kn->kn_data != 0); +} + +static int +filt_nfsvnode(struct knote *kn, long hint) +{ + + if (kn->kn_sfflags & hint) + kn->kn_fflags |= hint; + if (hint == NOTE_REVOKE) { + kn->kn_flags |= EV_EOF; + return (1); + } + return (kn->kn_fflags != 0); +} + +static const struct filterops nfsread_filtops = + { 1, NULL, filt_nfsdetach, filt_nfsread }; +static const struct filterops nfsvnode_filtops = + { 1, NULL, filt_nfsdetach, filt_nfsvnode }; + +int +nfs_kqfilter(void *v) +{ + struct vop_kqfilter_args /* { + struct vnode *a_vp; + struct knote *a_kn; + } */ *ap = v; + struct vnode *vp; + struct knote *kn; + struct kevq *ke; + int error = 0; + struct vattr attr; + struct proc *p = curproc; /* XXX */ + + vp = ap->a_vp; + kn = ap->a_kn; + switch (kn->kn_filter) { + case EVFILT_READ: + kn->kn_fop = &nfsread_filtops; + break; + case EVFILT_VNODE: + kn->kn_fop = &nfsvnode_filtops; + break; + default: + return (1); + } + + kn->kn_hook = vp; + + /* XXXLUKEM lock the struct? */ + SLIST_INSERT_HEAD(&vp->v_klist, kn, kn_selnext); + + /* + * Put the vnode to watched list. + */ + + /* + * Fetch current attributes. It's only needed when the vnode + * is not watched yet, but we need to do this without lock + * held. This is likely cheap due to attrcache, so do it now. + */ + memset(&attr, 0, sizeof(attr)); + (void) VOP_GETATTR(vp, &attr, p->p_ucred, p); + + lockmgr(&nfskevq_lock, LK_EXCLUSIVE, NULL); + + /* ensure the poller is running */ + if (!pnfskq) { + error = kthread_create1(nfs_kqpoll, NULL, &pnfskq, + "nfskqpoll"); + if (error) + goto out; + } + + SLIST_FOREACH(ke, &kevlist, kev_link) { + if (ke->vp == vp) + break; + } + + if (ke) { + /* already watched, so just bump usecount */ + ke->usecount++; + } else { + /* need a new one */ + MALLOC(ke, struct kevq *, sizeof(struct kevq), M_KEVENT, + M_WAITOK); + ke->vp = vp; + ke->usecount = 1; + ke->flags = 0; + ke->omtime = attr.va_mtime; + ke->octime = attr.va_ctime; + ke->onlink = attr.va_nlink; + SLIST_INSERT_HEAD(&kevlist, ke, kev_link); + } + + /* kick the poller */ + wakeup(pnfskq); + + out: + lockmgr(&nfskevq_lock, LK_RELEASE, NULL); + + return (error); +} diff --git a/sys/nfs/nfs_subs.c b/sys/nfs/nfs_subs.c index 7f5b1dd8bdc3..0c04784623c4 100644 --- a/sys/nfs/nfs_subs.c +++ b/sys/nfs/nfs_subs.c @@ -1,4 +1,4 @@ -/* $NetBSD: nfs_subs.c,v 1.105 2002/10/21 12:52:33 yamt Exp $ */ +/* $NetBSD: nfs_subs.c,v 1.106 2002/10/23 09:14:50 jdolecek Exp $ */ /* * Copyright (c) 1989, 1993 @@ -74,7 +74,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: nfs_subs.c,v 1.105 2002/10/21 12:52:33 yamt Exp $"); +__KERNEL_RCSID(0, "$NetBSD: nfs_subs.c,v 1.106 2002/10/23 09:14:50 jdolecek Exp $"); #include "fs_nfs.h" #include "opt_nfs.h" @@ -1487,6 +1487,11 @@ nfs_init() */ TAILQ_INIT(&nfs_reqq); nfs_timer(NULL); + +#ifdef NFS + /* Initialize the kqueue structures */ + nfs_kqinit(); +#endif } #ifdef NFS diff --git a/sys/nfs/nfs_var.h b/sys/nfs/nfs_var.h index dc709a5d5c63..91cc0149b49b 100644 --- a/sys/nfs/nfs_var.h +++ b/sys/nfs/nfs_var.h @@ -1,4 +1,4 @@ -/* $NetBSD: nfs_var.h,v 1.24 2002/10/21 12:52:34 yamt Exp $ */ +/* $NetBSD: nfs_var.h,v 1.25 2002/10/23 09:14:51 jdolecek Exp $ */ /*- * Copyright (c) 1996 The NetBSD Foundation, Inc. @@ -80,6 +80,9 @@ int nfs_doio __P((struct buf *, struct proc *)); /* nfs_boot.c */ /* see nfsdiskless.h */ +/* nfs_kq.c */ +void nfs_kqinit __P((void)); + /* nfs_node.c */ void nfs_nhinit __P((void)); void nfs_nhreinit __P((void)); diff --git a/sys/nfs/nfs_vnops.c b/sys/nfs/nfs_vnops.c index 3c31692da5f6..7debe3781240 100644 --- a/sys/nfs/nfs_vnops.c +++ b/sys/nfs/nfs_vnops.c @@ -1,4 +1,4 @@ -/* $NetBSD: nfs_vnops.c,v 1.155 2002/10/22 10:10:28 yamt Exp $ */ +/* $NetBSD: nfs_vnops.c,v 1.156 2002/10/23 09:14:51 jdolecek Exp $ */ /* * Copyright (c) 1989, 1993 @@ -43,7 +43,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: nfs_vnops.c,v 1.155 2002/10/22 10:10:28 yamt Exp $"); +__KERNEL_RCSID(0, "$NetBSD: nfs_vnops.c,v 1.156 2002/10/23 09:14:51 jdolecek Exp $"); #include "opt_nfs.h" #include "opt_uvmhist.h" @@ -112,6 +112,7 @@ const struct vnodeopv_entry_desc nfsv2_vnodeop_entries[] = { { &vop_fcntl_desc, genfs_fcntl }, /* fcntl */ { &vop_ioctl_desc, nfs_ioctl }, /* ioctl */ { &vop_poll_desc, nfs_poll }, /* poll */ + { &vop_kqfilter_desc, nfs_kqfilter }, /* kqfilter */ { &vop_revoke_desc, nfs_revoke }, /* revoke */ { &vop_mmap_desc, nfs_mmap }, /* mmap */ { &vop_fsync_desc, nfs_fsync }, /* fsync */ @@ -169,6 +170,7 @@ const struct vnodeopv_entry_desc spec_nfsv2nodeop_entries[] = { { &vop_fcntl_desc, genfs_fcntl }, /* fcntl */ { &vop_ioctl_desc, spec_ioctl }, /* ioctl */ { &vop_poll_desc, spec_poll }, /* poll */ + { &vop_kqfilter_desc, spec_kqfilter }, /* kqfilter */ { &vop_revoke_desc, spec_revoke }, /* revoke */ { &vop_mmap_desc, spec_mmap }, /* mmap */ { &vop_fsync_desc, spec_fsync }, /* fsync */ @@ -223,6 +225,7 @@ const struct vnodeopv_entry_desc fifo_nfsv2nodeop_entries[] = { { &vop_fcntl_desc, genfs_fcntl }, /* fcntl */ { &vop_ioctl_desc, fifo_ioctl }, /* ioctl */ { &vop_poll_desc, fifo_poll }, /* poll */ + { &vop_kqfilter_desc, fifo_kqfilter }, /* kqfilter */ { &vop_revoke_desc, fifo_revoke }, /* revoke */ { &vop_mmap_desc, fifo_mmap }, /* mmap */ { &vop_fsync_desc, nfs_fsync }, /* fsync */ @@ -720,6 +723,7 @@ nfs_setattr(v) np->n_size = np->n_vattr->va_size = tsize; uvm_vnp_setsize(vp, np->n_size); } + VN_KNOTE(vp, NOTE_ATTRIB); return (error); } @@ -1413,6 +1417,7 @@ nfs_mknod(v) int error; error = nfs_mknodrpc(ap->a_dvp, ap->a_vpp, ap->a_cnp, ap->a_vap); + VN_KNOTE(ap->a_dvp, NOTE_WRITE); return (error); } @@ -1519,6 +1524,7 @@ again: VTONFS(dvp)->n_flag |= NMODIFIED; if (!wccflag) VTONFS(dvp)->n_attrstamp = 0; + VN_KNOTE(ap->a_dvp, NOTE_WRITE); vput(dvp); return (error); } @@ -1591,6 +1597,8 @@ nfs_remove(v) error = nfs_sillyrename(dvp, vp, cnp); PNBUF_PUT(cnp->cn_pnbuf); np->n_attrstamp = 0; + VN_KNOTE(vp, NOTE_DELETE); + VN_KNOTE(dvp, NOTE_WRITE); if (dvp == vp) vrele(vp); else @@ -1686,6 +1694,7 @@ nfs_rename(v) */ if (tvp && tvp->v_usecount > 1 && !VTONFS(tvp)->n_sillyrename && tvp->v_type != VDIR && !nfs_sillyrename(tdvp, tvp, tcnp)) { + VN_KNOTE(tvp, NOTE_DELETE); vput(tvp); tvp = NULL; } @@ -1694,6 +1703,8 @@ nfs_rename(v) tdvp, tcnp->cn_nameptr, tcnp->cn_namelen, tcnp->cn_cred, tcnp->cn_proc); + VN_KNOTE(fdvp, NOTE_WRITE); + VN_KNOTE(tdvp, NOTE_WRITE); if (fvp->v_type == VDIR) { if (tvp != NULL && tvp->v_type == VDIR) cache_purge(tdvp); @@ -1840,6 +1851,8 @@ nfs_link(v) VTONFS(dvp)->n_attrstamp = 0; if (dvp != vp) VOP_UNLOCK(vp, 0); + VN_KNOTE(vp, NOTE_LINK); + VN_KNOTE(dvp, NOTE_WRITE); vput(dvp); /* * Kludge: Map EEXIST => 0 assuming that it is a reply to a retry. @@ -1925,6 +1938,7 @@ nfs_symlink(v) VTONFS(dvp)->n_flag |= NMODIFIED; if (!wccflag) VTONFS(dvp)->n_attrstamp = 0; + VN_KNOTE(dvp, NOTE_WRITE); vput(dvp); return (error); } @@ -2005,6 +2019,7 @@ nfs_mkdir(v) if (newvp) vput(newvp); } else { + VN_KNOTE(dvp, NOTE_WRITE | NOTE_LINK); if (cnp->cn_flags & MAKEENTRY) cache_enter(dvp, newvp, cnp); *ap->a_vpp = newvp; @@ -2056,6 +2071,8 @@ nfs_rmdir(v) VTONFS(dvp)->n_flag |= NMODIFIED; if (!wccflag) VTONFS(dvp)->n_attrstamp = 0; + VN_KNOTE(dvp, NOTE_WRITE | NOTE_LINK); + VN_KNOTE(vp, NOTE_DELETE); cache_purge(dvp); cache_purge(vp); vput(vp); diff --git a/sys/nfs/nfsnode.h b/sys/nfs/nfsnode.h index fec5ca0ae904..8bf6beeb85f7 100644 --- a/sys/nfs/nfsnode.h +++ b/sys/nfs/nfsnode.h @@ -1,4 +1,4 @@ -/* $NetBSD: nfsnode.h,v 1.35 2002/10/21 12:52:36 yamt Exp $ */ +/* $NetBSD: nfsnode.h,v 1.36 2002/10/23 09:14:52 jdolecek Exp $ */ /* * Copyright (c) 1989, 1993 @@ -244,6 +244,7 @@ int nfs_update __P((void *)); int nfs_getpages __P((void *)); int nfs_putpages __P((void *)); int nfs_gop_write(struct vnode *, struct vm_page **, int, int); +int nfs_kqfilter __P((void *)); extern int (**nfsv2_vnodeop_p) __P((void *)); diff --git a/sys/ntfs/ntfs_vnops.c b/sys/ntfs/ntfs_vnops.c index f03ec4a8e070..23b88cce71f2 100644 --- a/sys/ntfs/ntfs_vnops.c +++ b/sys/ntfs/ntfs_vnops.c @@ -1,4 +1,4 @@ -/* $NetBSD: ntfs_vnops.c,v 1.40 2001/12/18 07:51:16 chs Exp $ */ +/* $NetBSD: ntfs_vnops.c,v 1.41 2002/10/23 09:14:53 jdolecek Exp $ */ /* * Copyright (c) 1992, 1993 @@ -40,7 +40,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ntfs_vnops.c,v 1.40 2001/12/18 07:51:16 chs Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ntfs_vnops.c,v 1.41 2002/10/23 09:14:53 jdolecek Exp $"); #include #include @@ -948,6 +948,7 @@ const struct vnodeopv_entry_desc ntfs_vnodeop_entries[] = { { &vop_fcntl_desc, genfs_fcntl }, /* fcntl */ { &vop_ioctl_desc, genfs_enoioctl }, /* ioctl */ { &vop_poll_desc, genfs_poll }, /* poll */ + { &vop_kqfilter_desc, genfs_kqfilter }, /* kqfilter */ { &vop_revoke_desc, genfs_revoke }, /* revoke */ { &vop_mmap_desc, genfs_mmap }, /* mmap */ { &vop_fsync_desc, genfs_fsync }, /* fsync */ diff --git a/sys/sys/conf.h b/sys/sys/conf.h index 6d6a820a4f2e..12c078f5eaa4 100644 --- a/sys/sys/conf.h +++ b/sys/sys/conf.h @@ -1,4 +1,4 @@ -/* $NetBSD: conf.h,v 1.105 2002/09/06 13:18:43 gehenna Exp $ */ +/* $NetBSD: conf.h,v 1.106 2002/10/23 09:14:54 jdolecek Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -48,6 +48,7 @@ */ struct buf; +struct knote; struct proc; struct tty; struct uio; @@ -86,6 +87,7 @@ struct cdevsw { struct tty * (*d_tty)(dev_t); int (*d_poll)(dev_t, int, struct proc *); paddr_t (*d_mmap)(dev_t, off_t, int); + int (*d_kqfilter)(dev_t dev, struct knote *kn); int d_type; }; @@ -112,6 +114,7 @@ int cdevsw_lookup_major(const struct cdevsw *); #define dev_type_strategy(n) void n (struct buf *) #define dev_type_dump(n) int n (dev_t, daddr_t, caddr_t, size_t) #define dev_type_size(n) int n (dev_t) +#define dev_type_kqfilter(n) int n (dev_t, struct knote *) #define noopen ((dev_type_open((*)))enodev) #define noclose ((dev_type_close((*)))enodev) @@ -124,6 +127,7 @@ int cdevsw_lookup_major(const struct cdevsw *); #define nommap ((dev_type_mmap((*)))enodev) #define nodump ((dev_type_dump((*)))enodev) #define nosize NULL +#define nokqfilter seltrue_kqfilter #define nullopen ((dev_type_open((*)))nullop) #define nullclose ((dev_type_close((*)))nullop) @@ -134,6 +138,7 @@ int cdevsw_lookup_major(const struct cdevsw *); #define nullpoll ((dev_type_poll((*)))nullop) #define nullmmap ((dev_type_mmap((*)))nullop) #define nulldump ((dev_type_dump((*)))nullop) +#define nullkqfilter ((dev_type_kqfilter((*)))eopnotsupp) /* symbolic sleep message strings */ extern const char devopn[], devio[], devwait[], devin[], devout[]; diff --git a/sys/sys/event.h b/sys/sys/event.h new file mode 100644 index 000000000000..ee82ce678867 --- /dev/null +++ b/sys/sys/event.h @@ -0,0 +1,222 @@ +/* $NetBSD: event.h,v 1.3 2002/10/23 09:14:55 jdolecek Exp $ */ +/*- + * Copyright (c) 1999,2000,2001 Jonathan Lemon + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: src/sys/sys/event.h,v 1.12 2001/02/24 01:44:03 jlemon Exp $ + */ + +#ifndef _SYS_EVENT_H_ +#define _SYS_EVENT_H_ + +#include /* for uintptr_t */ +#include /* for NULL */ + +#define EVFILT_READ 0 +#define EVFILT_WRITE 1 +#define EVFILT_AIO 2 /* attached to aio requests */ +#define EVFILT_VNODE 3 /* attached to vnodes */ +#define EVFILT_PROC 4 /* attached to struct proc */ +#define EVFILT_SIGNAL 5 /* attached to struct proc */ +#define EVFILT_SYSCOUNT 6 /* number of filters */ + +#define EV_SET(kevp, a, b, c, d, e, f) \ +do { \ + (kevp)->ident = (a); \ + (kevp)->filter = (b); \ + (kevp)->flags = (c); \ + (kevp)->fflags = (d); \ + (kevp)->data = (e); \ + (kevp)->udata = (f); \ +} while (/* CONSTCOND */ 0) + + +struct kevent { + uintptr_t ident; /* identifier for this event */ + uint32_t filter; /* filter for event */ + uint32_t flags; /* action flags for kqueue */ + uint32_t fflags; /* filter flag value */ + int64_t data; /* filter data value */ + intptr_t udata; /* opaque user data identifier */ +}; + +/* actions */ +#define EV_ADD 0x0001 /* add event to kq (implies ENABLE) */ +#define EV_DELETE 0x0002 /* delete event from kq */ +#define EV_ENABLE 0x0004 /* enable event */ +#define EV_DISABLE 0x0008 /* disable event (not reported) */ + +/* flags */ +#define EV_ONESHOT 0x0010 /* only report one occurrence */ +#define EV_CLEAR 0x0020 /* clear event state after reporting */ + +#define EV_SYSFLAGS 0xF000 /* reserved by system */ +#define EV_FLAG1 0x2000 /* filter-specific flag */ + +/* returned values */ +#define EV_EOF 0x8000 /* EOF detected */ +#define EV_ERROR 0x4000 /* error, data contains errno */ + +/* + * data/hint flags for EVFILT_{READ|WRITE}, shared with userspace + */ +#define NOTE_LOWAT 0x0001 /* low water mark */ + +/* + * data/hint flags for EVFILT_VNODE, shared with userspace + */ +#define NOTE_DELETE 0x0001 /* vnode was removed */ +#define NOTE_WRITE 0x0002 /* data contents changed */ +#define NOTE_EXTEND 0x0004 /* size increased */ +#define NOTE_ATTRIB 0x0008 /* attributes changed */ +#define NOTE_LINK 0x0010 /* link count changed */ +#define NOTE_RENAME 0x0020 /* vnode was renamed */ +#define NOTE_REVOKE 0x0040 /* vnode access was revoked */ + +/* + * data/hint flags for EVFILT_PROC, shared with userspace + */ +#define NOTE_EXIT 0x80000000 /* process exited */ +#define NOTE_FORK 0x40000000 /* process forked */ +#define NOTE_EXEC 0x20000000 /* process exec'd */ +#define NOTE_PCTRLMASK 0xf0000000 /* mask for hint bits */ +#define NOTE_PDATAMASK 0x000fffff /* mask for pid */ + +/* additional flags for EVFILT_PROC */ +#define NOTE_TRACK 0x00000001 /* follow across forks */ +#define NOTE_TRACKERR 0x00000002 /* could not track child */ +#define NOTE_CHILD 0x00000004 /* am a child process */ + +/* + * This is currently visible to userland to work around broken + * programs which pull in or . + */ +#include +struct knote; +SLIST_HEAD(klist, knote); + + +/* + * ioctl(2)s supported on kqueue descriptors. + */ +#include + +struct kfilter_mapping { + char *name; /* name to lookup or return */ + size_t len; /* length of name */ + uint32_t filter; /* filter to lookup or return */ +}; + +/* map filter to name (max size len) */ +#define KFILTER_BYFILTER _IOWR('k', 0, struct kfilter_mapping) +/* map name to filter (len ignored) */ +#define KFILTER_BYNAME _IOWR('k', 1, struct kfilter_mapping) + +#ifdef _KERNEL + +#define KNOTE(list, hint) if (!SLIST_EMPTY(list)) knote(list, hint) + +/* + * Flag indicating hint is a signal. Used by EVFILT_SIGNAL, and also + * shared by EVFILT_PROC (all knotes attached to p->p_klist) + */ +#define NOTE_SIGNAL 0x08000000 + +/* + * Callback methods for each filter type. + */ +struct filterops { + int f_isfd; /* true if ident == filedescriptor */ + int (*f_attach) __P((struct knote *kn)); + /* called when knote is ADDed */ + void (*f_detach) __P((struct knote *kn)); + /* called when knote is DELETEd */ + int (*f_event) __P((struct knote *kn, long hint)); + /* called when event is triggered */ +}; + +struct knote { + SLIST_ENTRY(knote) kn_link; /* for fd */ + SLIST_ENTRY(knote) kn_selnext; /* for struct selinfo */ + TAILQ_ENTRY(knote) kn_tqe; + struct kqueue *kn_kq; /* which queue we are on */ + struct kevent kn_kevent; + uint32_t kn_status; + uint32_t kn_sfflags; /* saved filter flags */ + uintptr_t kn_sdata; /* saved data field */ + union { + struct file *p_fp; /* file data pointer */ + struct proc *p_proc; /* proc pointer */ + void *p_opaque; /* opaque/misc pointer */ + } kn_ptr; + const struct filterops *kn_fop; + void *kn_hook; + +#define KN_ACTIVE 0x01 /* event has been triggered */ +#define KN_QUEUED 0x02 /* event is on queue */ +#define KN_DISABLED 0x04 /* event is disabled */ +#define KN_DETACHED 0x08 /* knote is detached */ + +#define kn_id kn_kevent.ident +#define kn_filter kn_kevent.filter +#define kn_flags kn_kevent.flags +#define kn_fflags kn_kevent.fflags +#define kn_data kn_kevent.data +#define kn_fp kn_ptr.p_fp +}; + +struct proc; + +void kqueue_init(void); + +void knote(struct klist *list, long hint); +void knote_remove(struct proc *p, struct klist *list); +void knote_fdclose(struct proc *p, int fd); +int kqueue_register(struct kqueue *kq, + struct kevent *kev, struct proc *p); + +int kfilter_register(const char *name, + const struct filterops *filtops, int *retfilter); +int kfilter_unregister(const char *name); + +int filt_seltrue(struct knote *kn, long hint); +int seltrue_kqfilter(dev_t dev, struct knote *kn); + +#else /* !_KERNEL */ + +#include +struct timespec; + +__BEGIN_DECLS +#if !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE) +int kqueue __P((void)); +int kevent __P((int kq, const struct kevent *changelist, size_t nchanges, + struct kevent *eventlist, size_t nevents, + const struct timespec *timeout)); +#endif /* !_POSIX_C_SOURCE */ +__END_DECLS + +#endif /* !_KERNEL */ + +#endif /* !_SYS_EVENT_H_ */ diff --git a/sys/sys/eventvar.h b/sys/sys/eventvar.h new file mode 100644 index 000000000000..57af6dc6b15a --- /dev/null +++ b/sys/sys/eventvar.h @@ -0,0 +1,48 @@ +/* $NetBSD: eventvar.h,v 1.3 2002/10/23 09:14:56 jdolecek Exp $ */ +/*- + * Copyright (c) 1999,2000 Jonathan Lemon + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: src/sys/sys/eventvar.h,v 1.4 2000/07/18 19:31:48 jlemon Exp $ + */ + +#ifndef _SYS_EVENTVAR_H_ +#define _SYS_EVENTVAR_H_ + +#define KQ_NEVENTS 8 /* minimize copy{in,out} calls */ +#define KQ_EXTENT 256 /* linear growth by this amount */ +#define KFILTER_MAXNAME 256 /* maximum size of a filter name */ +#define KFILTER_EXTENT 8 /* grow user_kfilters by this amt */ + +struct kqueue { + TAILQ_HEAD(kqlist, knote) kq_head; /* list of pending event */ + int kq_count; /* number of pending events */ + struct selinfo kq_sel; + struct filedesc *kq_fdp; + int kq_state; +#define KQ_SLEEP 0x01 + struct kevent kq_kev[KQ_NEVENTS]; +}; + +#endif /* !_SYS_EVENTVAR_H_ */ diff --git a/sys/sys/file.h b/sys/sys/file.h index 9fd39bae453d..d7018f166b0e 100644 --- a/sys/sys/file.h +++ b/sys/sys/file.h @@ -1,4 +1,4 @@ -/* $NetBSD: file.h,v 1.33 2002/07/16 16:40:55 thorpej Exp $ */ +/* $NetBSD: file.h,v 1.34 2002/10/23 09:14:57 jdolecek Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1993 @@ -48,6 +48,7 @@ struct proc; struct uio; struct iovec; struct stat; +struct knote; /* * Kernel descriptor table. @@ -60,6 +61,7 @@ struct file { #define DTYPE_VNODE 1 /* file */ #define DTYPE_SOCKET 2 /* communications endpoint */ #define DTYPE_PIPE 3 /* pipe */ +#define DTYPE_KQUEUE 4 /* event queue */ #define DTYPE_MISC 5 /* misc file descriptor type */ int f_type; /* descriptor type */ u_int f_count; /* reference count */ @@ -82,6 +84,7 @@ struct file { int (*fo_stat) (struct file *fp, struct stat *sp, struct proc *p); int (*fo_close) (struct file *fp, struct proc *p); + int (*fo_kqfilter) (struct file *fp, struct knote *kn); } *f_ops; off_t f_offset; caddr_t f_data; /* descriptor data, e.g. vnode/socket */ diff --git a/sys/sys/filedesc.h b/sys/sys/filedesc.h index e1fd4a088a92..63c9bea93fac 100644 --- a/sys/sys/filedesc.h +++ b/sys/sys/filedesc.h @@ -1,4 +1,4 @@ -/* $NetBSD: filedesc.h,v 1.24 2002/04/23 15:11:26 christos Exp $ */ +/* $NetBSD: filedesc.h,v 1.25 2002/10/23 09:14:58 jdolecek Exp $ */ /* * Copyright (c) 1990, 1993 @@ -62,6 +62,17 @@ struct filedesc { int fd_lastfile; /* high-water mark of fd_ofiles */ int fd_freefile; /* approx. next free file */ int fd_refcnt; /* reference count */ + + int fd_knlistsize; /* size of fd_knlist */ + struct klist *fd_knlist; /* + * list of attached fd knotes, + * indexed by fd number + */ + u_long fd_knhashmask; /* size of fd_knhash */ + struct klist *fd_knhash; /* + * hash table for attached + * non-fd knotes + */ }; struct cwdinfo { diff --git a/sys/sys/malloc.h b/sys/sys/malloc.h index e413aa1661cf..8a18401dae6c 100644 --- a/sys/sys/malloc.h +++ b/sys/sys/malloc.h @@ -1,4 +1,4 @@ -/* $NetBSD: malloc.h,v 1.79 2002/07/05 13:05:14 abs Exp $ */ +/* $NetBSD: malloc.h,v 1.80 2002/10/23 09:14:58 jdolecek Exp $ */ /* * Copyright (c) 1987, 1993 @@ -190,7 +190,8 @@ #define M_SMBFSDATA 131 /* SMBFS private data */ #define M_SMBFSHASH 132 /* SMBFS hash table */ #define M_SA 133 /* Scheduler activations */ -#define M_LAST 134 /* Must be last type + 1 */ +#define M_KEVENT 134 /* kevents/knotes */ +#define M_LAST 135 /* Must be last type + 1 */ /* added something? don't forget to update malloc.9 */ @@ -329,7 +330,8 @@ "smbfsdata", /* 131 M_SMBFSDATA */ \ "smbfshash", /* 132 M_SMBFSHASH */ \ "sa", /* 133 M_SA */ \ - NULL, /* 134 */ \ + "kevent", /* 134 M_KEVENT */ \ + NULL, /* 135 */ \ } struct kmemstats { diff --git a/sys/sys/proc.h b/sys/sys/proc.h index 0841ba843f37..8ea4e36daa95 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -1,4 +1,4 @@ -/* $NetBSD: proc.h,v 1.146 2002/09/22 05:36:49 gmcgarry Exp $ */ +/* $NetBSD: proc.h,v 1.147 2002/10/23 09:14:59 jdolecek Exp $ */ /*- * Copyright (c) 1986, 1989, 1991, 1993 @@ -56,6 +56,7 @@ #include #include #include +#include /* * One structure allocated per session. @@ -220,6 +221,7 @@ struct proc { * Malloc type M_EMULDATA */ const struct execsw *p_execsw; /* Exec package information */ + struct klist p_klist; /* Knotes attached to this process */ /* * End area that is zeroed on creation diff --git a/sys/sys/select.h b/sys/sys/select.h index 10efb7e0b71a..b32e9083d278 100644 --- a/sys/sys/select.h +++ b/sys/sys/select.h @@ -1,4 +1,4 @@ -/* $NetBSD: select.h,v 1.12 2002/06/10 10:31:48 tron Exp $ */ +/* $NetBSD: select.h,v 1.13 2002/10/23 09:15:00 jdolecek Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -39,6 +39,7 @@ #define _SYS_SELECT_H_ #include +#include /* for struct klist */ /* * Used to maintain information about processes that wish to be @@ -46,6 +47,7 @@ */ struct selinfo { pid_t si_pid; /* process to be notified */ + struct klist si_klist; /* knotes attached to this selinfo */ short si_flags; /* see below */ }; #define SI_COLL 0x0001 /* collision occurred */ @@ -55,6 +57,15 @@ struct proc; void selrecord(struct proc *selector, struct selinfo *); void selwakeup(struct selinfo *); + +static __inline void +selnotify(struct selinfo *sip, long knhint) +{ + + if (sip->si_pid != 0) + selwakeup(sip); + KNOTE(&sip->si_klist, knhint); +} #endif #endif /* !_SYS_SELECT_H_ */ diff --git a/sys/sys/socketvar.h b/sys/sys/socketvar.h index 865bc9c897e2..4e3b33cd29dd 100644 --- a/sys/sys/socketvar.h +++ b/sys/sys/socketvar.h @@ -1,4 +1,4 @@ -/* $NetBSD: socketvar.h,v 1.54 2002/07/03 21:39:40 thorpej Exp $ */ +/* $NetBSD: socketvar.h,v 1.55 2002/10/23 09:15:01 jdolecek Exp $ */ /*- * Copyright (c) 1982, 1986, 1990, 1993 @@ -112,6 +112,8 @@ struct socket { #define SB_ASYNC 0x10 /* ASYNC I/O, need signals */ #define SB_UPCALL 0x20 /* someone wants an upcall */ #define SB_NOINTR 0x40 /* operations not interruptible */ + /* XXXLUKEM: 0x80 left for FreeBSD's SB_AIO */ +#define SB_KNOTE 0x100 /* kernel note attached */ void *so_internal; /* Space for svr4 stream data */ void (*so_upcall) __P((struct socket *so, caddr_t arg, @@ -166,7 +168,7 @@ do { \ * Do we need to notify the other side when I/O is possible? */ #define sb_notify(sb) (((sb)->sb_flags & \ - (SB_WAIT | SB_SEL | SB_ASYNC | SB_UPCALL)) != 0) + (SB_WAIT | SB_SEL | SB_ASYNC | SB_UPCALL | SB_KNOTE)) != 0) /* * How much space is there in a socket buffer (so->so_snd or so->so_rcv)? @@ -260,6 +262,7 @@ struct sockaddr; struct proc; struct msghdr; struct stat; +struct knote; /* * File operations on sockets. @@ -271,6 +274,7 @@ int soo_write(struct file *fp, off_t *offset, struct uio *uio, int soo_fcntl(struct file *fp, u_int cmd, caddr_t data, struct proc *p); int soo_ioctl(struct file *fp, u_long cmd, caddr_t data, struct proc *p); int soo_poll(struct file *fp, int events, struct proc *p); +int soo_kqfilter(struct file *fp, struct knote *kn); int soo_close(struct file *fp, struct proc *p); int soo_stat(struct file *fp, struct stat *ub, struct proc *p); int uipc_usrreq(struct socket *, int , struct mbuf *, diff --git a/sys/sys/tty.h b/sys/sys/tty.h index a783fbab9548..f8701c5c5c12 100644 --- a/sys/sys/tty.h +++ b/sys/sys/tty.h @@ -1,4 +1,4 @@ -/* $NetBSD: tty.h,v 1.52 2001/06/08 15:43:34 mrg Exp $ */ +/* $NetBSD: tty.h,v 1.53 2002/10/23 09:15:01 jdolecek Exp $ */ /*- * Copyright (c) 1982, 1986, 1993 @@ -230,6 +230,7 @@ void ttyinfo __P((struct tty *tp)); int ttyinput __P((int c, struct tty *tp)); int ttylclose __P((struct tty *tp, int flag)); int ttylopen __P((dev_t device, struct tty *tp)); +int ttykqfilter __P((dev_t device, struct knote *)); int ttymodem __P((struct tty *tp, int flag)); int ttyopen __P((struct tty *tp, int dialout, int nonblock)); int ttyoutput __P((int c, struct tty *tp)); diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h index 2c4704a93e1e..18ac77f1d7f0 100644 --- a/sys/sys/vnode.h +++ b/sys/sys/vnode.h @@ -1,4 +1,4 @@ -/* $NetBSD: vnode.h,v 1.98 2002/10/23 06:45:51 gmcgarry Exp $ */ +/* $NetBSD: vnode.h,v 1.99 2002/10/23 09:15:02 jdolecek Exp $ */ /* * Copyright (c) 1989, 1993 @@ -38,6 +38,7 @@ #ifndef _SYS_VNODE_H_ #define _SYS_VNODE_H_ +#include #include #include @@ -111,6 +112,7 @@ struct vnode { struct lock v_lock; /* lock for this vnode */ struct lock *v_vnlock; /* pointer to lock */ void *v_data; /* private data for fs */ + struct klist v_klist; /* knotes attached to vnode */ }; #define v_mountedhere v_un.vu_mountedhere #define v_socket v_un.vu_socket @@ -314,6 +316,8 @@ vref(struct vnode *vp) #define NULLVP ((struct vnode *)NULL) +#define VN_KNOTE(vp, b) KNOTE(&vp->v_klist, (b)) + /* * Global vnode data. */ @@ -529,6 +533,7 @@ int vn_readdir(struct file *fp, char *buf, int segflg, u_int count, void vn_restorerecurse(struct vnode *vp, u_int flags); u_int vn_setrecurse(struct vnode *vp); int vn_stat(struct vnode *vp, struct stat *sb, struct proc *p); +int vn_kqfilter(struct file *fp, struct knote *kn); int vn_writechk(struct vnode *vp); /* initialise global vnode management */ diff --git a/sys/ufs/ext2fs/ext2fs_readwrite.c b/sys/ufs/ext2fs/ext2fs_readwrite.c index ee1e9f2b7cb9..7d75f970d6b1 100644 --- a/sys/ufs/ext2fs/ext2fs_readwrite.c +++ b/sys/ufs/ext2fs/ext2fs_readwrite.c @@ -1,4 +1,4 @@ -/* $NetBSD: ext2fs_readwrite.c,v 1.25 2002/09/22 19:32:56 jdolecek Exp $ */ +/* $NetBSD: ext2fs_readwrite.c,v 1.26 2002/10/23 09:15:04 jdolecek Exp $ */ /*- * Copyright (c) 1997 Manuel Bouyer. @@ -38,7 +38,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ext2fs_readwrite.c,v 1.25 2002/09/22 19:32:56 jdolecek Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ext2fs_readwrite.c,v 1.26 2002/10/23 09:15:04 jdolecek Exp $"); #include #include @@ -212,6 +212,7 @@ ext2fs_write(v) void *win; off_t oldoff; boolean_t async; + int extended=0; ioflag = ap->a_ioflag; uio = ap->a_uio; @@ -292,6 +293,7 @@ ext2fs_write(v) if (vp->v_size < uio->uio_offset) { uvm_vnp_setsize(vp, uio->uio_offset); + extended = 1; } /* @@ -340,6 +342,7 @@ ext2fs_write(v) if (vp->v_size < uio->uio_offset) { uvm_vnp_setsize(vp, uio->uio_offset); + extended = 1; } if (ioflag & IO_SYNC) @@ -362,6 +365,8 @@ out: ip->i_flag |= IN_CHANGE | IN_UPDATE; if (resid > uio->uio_resid && ap->a_cred && ap->a_cred->cr_uid != 0) ip->i_e2fs_mode &= ~(ISUID | ISGID); + if (resid > uio->uio_resid) + VN_KNOTE(vp, NOTE_WRITE | (extended ? NOTE_EXTEND : 0)); if (error) { (void) VOP_TRUNCATE(vp, osize, ioflag & IO_SYNC, ap->a_cred, uio->uio_procp); diff --git a/sys/ufs/ext2fs/ext2fs_vnops.c b/sys/ufs/ext2fs/ext2fs_vnops.c index fe4ce3b20359..4a2aca47c749 100644 --- a/sys/ufs/ext2fs/ext2fs_vnops.c +++ b/sys/ufs/ext2fs/ext2fs_vnops.c @@ -1,4 +1,4 @@ -/* $NetBSD: ext2fs_vnops.c,v 1.41 2002/09/22 19:32:56 jdolecek Exp $ */ +/* $NetBSD: ext2fs_vnops.c,v 1.42 2002/10/23 09:15:05 jdolecek Exp $ */ /* * Copyright (c) 1997 Manuel Bouyer. @@ -43,7 +43,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ext2fs_vnops.c,v 1.41 2002/09/22 19:32:56 jdolecek Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ext2fs_vnops.c,v 1.42 2002/10/23 09:15:05 jdolecek Exp $"); #include #include @@ -110,9 +110,16 @@ ext2fs_create(v) struct componentname *a_cnp; struct vattr *a_vap; } */ *ap = v; - return ext2fs_makeinode(MAKEIMODE(ap->a_vap->va_type, - ap->a_vap->va_mode), - ap->a_dvp, ap->a_vpp, ap->a_cnp); + int error; + + error = + ext2fs_makeinode(MAKEIMODE(ap->a_vap->va_type, ap->a_vap->va_mode), + ap->a_dvp, ap->a_vpp, ap->a_cnp); + + if (error) + return (error); + VN_KNOTE(ap->a_dvp, NOTE_WRITE); + return (0); } /* @@ -139,6 +146,7 @@ ext2fs_mknod(v) if ((error = ext2fs_makeinode(MAKEIMODE(vap->va_type, vap->va_mode), ap->a_dvp, vpp, ap->a_cnp)) != 0) return (error); + VN_KNOTE(ap->a_dvp, NOTE_WRITE); ip = VTOI(*vpp); mp = (*vpp)->v_mount; ino = ip->i_number; @@ -401,6 +409,7 @@ ext2fs_setattr(v) return (EROFS); error = ext2fs_chmod(vp, (int)vap->va_mode, cred, p); } + VN_KNOTE(vp, NOTE_ATTRIB); return (error); } @@ -504,6 +513,8 @@ ext2fs_remove(v) ip->i_flag |= IN_CHANGE; } out: + VN_KNOTE(vp, NOTE_DELETE); + VN_KNOTE(dvp, NOTE_WRITE); if (dvp == vp) vrele(vp); else @@ -573,6 +584,8 @@ out1: if (dvp != vp) VOP_UNLOCK(vp, 0); out2: + VN_KNOTE(vp, NOTE_LINK); + VN_KNOTE(dvp, NOTE_WRITE); vput(dvp); return (error); } @@ -721,6 +734,7 @@ abortit: oldparent = dp->i_number; doingdirectory++; } + VN_KNOTE(fdvp, NOTE_WRITE); /* XXXLUKEM/XXX: right place? */ vrele(fdvp); /* @@ -811,6 +825,7 @@ abortit: } goto bad; } + VN_KNOTE(tdvp, NOTE_WRITE); vput(tdvp); } else { if (xp->i_dev != dp->i_dev || xp->i_dev != ip->i_dev) @@ -865,6 +880,7 @@ abortit: dp->i_e2fs_nlink--; dp->i_flag |= IN_CHANGE; } + VN_KNOTE(tdvp, NOTE_WRITE); vput(tdvp); /* * Adjust the link count of the target to @@ -884,6 +900,7 @@ abortit: tcnp->cn_cred, tcnp->cn_proc); } xp->i_flag |= IN_CHANGE; + VN_KNOTE(tvp, NOTE_DELETE); vput(tvp); xp = NULL; } @@ -962,6 +979,7 @@ abortit: } xp->i_flag &= ~IN_RENAME; } + VN_KNOTE(fvp, NOTE_RENAME); if (dp) vput(fdvp); if (xp) @@ -1093,8 +1111,10 @@ bad: ip->i_e2fs_nlink = 0; ip->i_flag |= IN_CHANGE; vput(tvp); - } else + } else { + VN_KNOTE(dvp, NOTE_WRITE | NOTE_LINK); *ap->a_vpp = tvp; + } out: PNBUF_PUT(cnp->cn_pnbuf); vput(dvp); @@ -1157,6 +1177,7 @@ ext2fs_rmdir(v) goto out; dp->i_e2fs_nlink--; dp->i_flag |= IN_CHANGE; + VN_KNOTE(dvp, NOTE_WRITE | NOTE_LINK); cache_purge(dvp); vput(dvp); dvp = NULL; @@ -1176,6 +1197,7 @@ ext2fs_rmdir(v) cnp->cn_proc); cache_purge(ITOV(ip)); out: + VN_KNOTE(vp, NOTE_DELETE); if (dvp) vput(dvp); vput(vp); @@ -1204,6 +1226,7 @@ ext2fs_symlink(v) vpp, ap->a_cnp); if (error) return (error); + VN_KNOTE(ap->a_dvp, NOTE_WRITE); vp = *vpp; len = strlen(ap->a_target); if (len < vp->v_mount->mnt_maxsymlinklen) { @@ -1444,6 +1467,7 @@ const struct vnodeopv_entry_desc ext2fs_vnodeop_entries[] = { { &vop_ioctl_desc, ufs_ioctl }, /* ioctl */ { &vop_fcntl_desc, ufs_fcntl }, /* fcntl */ { &vop_poll_desc, ufs_poll }, /* poll */ + { &vop_kqfilter_desc, genfs_kqfilter }, /* kqfilter */ { &vop_revoke_desc, ufs_revoke }, /* revoke */ { &vop_mmap_desc, ufs_mmap }, /* mmap */ { &vop_fsync_desc, ext2fs_fsync }, /* fsync */ @@ -1497,6 +1521,7 @@ const struct vnodeopv_entry_desc ext2fs_specop_entries[] = { { &vop_ioctl_desc, spec_ioctl }, /* ioctl */ { &vop_fcntl_desc, ufs_fcntl }, /* fcntl */ { &vop_poll_desc, spec_poll }, /* poll */ + { &vop_kqfilter_desc, spec_kqfilter }, /* kqfilter */ { &vop_revoke_desc, spec_revoke }, /* revoke */ { &vop_mmap_desc, spec_mmap }, /* mmap */ { &vop_fsync_desc, ext2fs_fsync }, /* fsync */ @@ -1550,6 +1575,7 @@ const struct vnodeopv_entry_desc ext2fs_fifoop_entries[] = { { &vop_ioctl_desc, fifo_ioctl }, /* ioctl */ { &vop_fcntl_desc, ufs_fcntl }, /* fcntl */ { &vop_poll_desc, fifo_poll }, /* poll */ + { &vop_kqfilter_desc, fifo_kqfilter }, /* kqfilter */ { &vop_revoke_desc, fifo_revoke }, /* revoke */ { &vop_mmap_desc, fifo_mmap }, /* mmap */ { &vop_fsync_desc, ext2fs_fsync }, /* fsync */ diff --git a/sys/ufs/ffs/ffs_vnops.c b/sys/ufs/ffs/ffs_vnops.c index ccfc3daeea32..8709bc231a64 100644 --- a/sys/ufs/ffs/ffs_vnops.c +++ b/sys/ufs/ffs/ffs_vnops.c @@ -1,4 +1,4 @@ -/* $NetBSD: ffs_vnops.c,v 1.49 2002/05/05 17:00:06 chs Exp $ */ +/* $NetBSD: ffs_vnops.c,v 1.50 2002/10/23 09:15:06 jdolecek Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1993 @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ffs_vnops.c,v 1.49 2002/05/05 17:00:06 chs Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ffs_vnops.c,v 1.50 2002/10/23 09:15:06 jdolecek Exp $"); #include #include @@ -45,6 +45,7 @@ __KERNEL_RCSID(0, "$NetBSD: ffs_vnops.c,v 1.49 2002/05/05 17:00:06 chs Exp $"); #include #include #include +#include #include #include #include @@ -86,6 +87,7 @@ const struct vnodeopv_entry_desc ffs_vnodeop_entries[] = { { &vop_ioctl_desc, ufs_ioctl }, /* ioctl */ { &vop_fcntl_desc, ufs_fcntl }, /* fcntl */ { &vop_poll_desc, ufs_poll }, /* poll */ + { &vop_kqfilter_desc, genfs_kqfilter }, /* kqfilter */ { &vop_revoke_desc, ufs_revoke }, /* revoke */ { &vop_mmap_desc, ufs_mmap }, /* mmap */ { &vop_fsync_desc, ffs_fsync }, /* fsync */ @@ -141,6 +143,7 @@ const struct vnodeopv_entry_desc ffs_specop_entries[] = { { &vop_ioctl_desc, spec_ioctl }, /* ioctl */ { &vop_fcntl_desc, ufs_fcntl }, /* fcntl */ { &vop_poll_desc, spec_poll }, /* poll */ + { &vop_kqfilter_desc, spec_kqfilter }, /* kqfilter */ { &vop_revoke_desc, spec_revoke }, /* revoke */ { &vop_mmap_desc, spec_mmap }, /* mmap */ { &vop_fsync_desc, ffs_fsync }, /* fsync */ @@ -195,6 +198,7 @@ const struct vnodeopv_entry_desc ffs_fifoop_entries[] = { { &vop_ioctl_desc, fifo_ioctl }, /* ioctl */ { &vop_fcntl_desc, ufs_fcntl }, /* fcntl */ { &vop_poll_desc, fifo_poll }, /* poll */ + { &vop_kqfilter_desc, fifo_kqfilter }, /* kqfilter */ { &vop_revoke_desc, fifo_revoke }, /* revoke */ { &vop_mmap_desc, fifo_mmap }, /* mmap */ { &vop_fsync_desc, ffs_fsync }, /* fsync */ diff --git a/sys/ufs/lfs/lfs_vnops.c b/sys/ufs/lfs/lfs_vnops.c index 017817bd00d1..3373bb80b3fe 100644 --- a/sys/ufs/lfs/lfs_vnops.c +++ b/sys/ufs/lfs/lfs_vnops.c @@ -1,4 +1,4 @@ -/* $NetBSD: lfs_vnops.c,v 1.67 2002/09/27 15:38:08 provos Exp $ */ +/* $NetBSD: lfs_vnops.c,v 1.68 2002/10/23 09:15:07 jdolecek Exp $ */ /*- * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc. @@ -71,7 +71,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.67 2002/09/27 15:38:08 provos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.68 2002/10/23 09:15:07 jdolecek Exp $"); #include #include @@ -119,6 +119,7 @@ const struct vnodeopv_entry_desc lfs_vnodeop_entries[] = { { &vop_ioctl_desc, ufs_ioctl }, /* ioctl */ { &vop_fcntl_desc, ufs_fcntl }, /* fcntl */ { &vop_poll_desc, ufs_poll }, /* poll */ + { &vop_kqfilter_desc, genfs_kqfilter }, /* kqfilter */ { &vop_revoke_desc, ufs_revoke }, /* revoke */ { &vop_mmap_desc, ufs_mmap }, /* mmap */ { &vop_fsync_desc, lfs_fsync }, /* fsync */ @@ -173,6 +174,7 @@ const struct vnodeopv_entry_desc lfs_specop_entries[] = { { &vop_ioctl_desc, spec_ioctl }, /* ioctl */ { &vop_fcntl_desc, ufs_fcntl }, /* fcntl */ { &vop_poll_desc, spec_poll }, /* poll */ + { &vop_kqfilter_desc, spec_kqfilter }, /* kqfilter */ { &vop_revoke_desc, spec_revoke }, /* revoke */ { &vop_mmap_desc, spec_mmap }, /* mmap */ { &vop_fsync_desc, spec_fsync }, /* fsync */ @@ -226,6 +228,7 @@ const struct vnodeopv_entry_desc lfs_fifoop_entries[] = { { &vop_ioctl_desc, fifo_ioctl }, /* ioctl */ { &vop_fcntl_desc, ufs_fcntl }, /* fcntl */ { &vop_poll_desc, fifo_poll }, /* poll */ + { &vop_kqfilter_desc, fifo_kqfilter }, /* kqfilter */ { &vop_revoke_desc, fifo_revoke }, /* revoke */ { &vop_mmap_desc, fifo_mmap }, /* mmap */ { &vop_fsync_desc, fifo_fsync }, /* fsync */ diff --git a/sys/ufs/ufs/ufs_readwrite.c b/sys/ufs/ufs/ufs_readwrite.c index 8f4488526939..44090f1e86da 100644 --- a/sys/ufs/ufs/ufs_readwrite.c +++ b/sys/ufs/ufs/ufs_readwrite.c @@ -1,4 +1,4 @@ -/* $NetBSD: ufs_readwrite.c,v 1.43 2002/10/18 01:05:52 yamt Exp $ */ +/* $NetBSD: ufs_readwrite.c,v 1.44 2002/10/23 09:15:08 jdolecek Exp $ */ /*- * Copyright (c) 1993 @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(1, "$NetBSD: ufs_readwrite.c,v 1.43 2002/10/18 01:05:52 yamt Exp $"); +__KERNEL_RCSID(1, "$NetBSD: ufs_readwrite.c,v 1.44 2002/10/23 09:15:08 jdolecek Exp $"); #ifdef LFS_READWRITE #define BLKSIZE(a, b, c) blksize(a, b, c) @@ -206,6 +206,7 @@ WRITE(void *v) int blkoffset, error, flags, ioflag, resid, size, xfersize; int bsize, aflag; int ubc_alloc_flags; + int extended=0; void *win; vsize_t bytelen; boolean_t async; @@ -372,6 +373,7 @@ WRITE(void *v) newoff = oldoff + bytelen; if (vp->v_size < newoff) { uvm_vnp_setsize(vp, newoff); + extended = 1; } if (error) { @@ -421,6 +423,7 @@ WRITE(void *v) if (uio->uio_offset + xfersize > ip->i_ffs_size) { ip->i_ffs_size = uio->uio_offset + xfersize; uvm_vnp_setsize(vp, ip->i_ffs_size); + extended = 1; } size = BLKSIZE(fs, ip, lbn) - bp->b_resid; if (xfersize > size) @@ -464,6 +467,8 @@ out: ip->i_flag |= IN_CHANGE | IN_UPDATE; if (resid > uio->uio_resid && ap->a_cred && ap->a_cred->cr_uid != 0) ip->i_ffs_mode &= ~(ISUID | ISGID); + if (resid > uio->uio_resid) + VN_KNOTE(vp, NOTE_WRITE | (extended ? NOTE_EXTEND : 0)); if (error) { (void) VOP_TRUNCATE(vp, osize, ioflag & IO_SYNC, ap->a_cred, uio->uio_procp); diff --git a/sys/ufs/ufs/ufs_vnops.c b/sys/ufs/ufs/ufs_vnops.c index c5257859d526..985529328603 100644 --- a/sys/ufs/ufs/ufs_vnops.c +++ b/sys/ufs/ufs/ufs_vnops.c @@ -1,4 +1,4 @@ -/* $NetBSD: ufs_vnops.c,v 1.87 2002/09/28 20:11:09 dbj Exp $ */ +/* $NetBSD: ufs_vnops.c,v 1.88 2002/10/23 09:15:09 jdolecek Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1993, 1995 @@ -41,7 +41,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ufs_vnops.c,v 1.87 2002/09/28 20:11:09 dbj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ufs_vnops.c,v 1.88 2002/10/23 09:15:09 jdolecek Exp $"); #include "opt_quota.h" #include "fs_lfs.h" @@ -118,10 +118,15 @@ ufs_create(void *v) struct componentname *a_cnp; struct vattr *a_vap; } */ *ap = v; + int error; - return + error = ufs_makeinode(MAKEIMODE(ap->a_vap->va_type, ap->a_vap->va_mode), ap->a_dvp, ap->a_vpp, ap->a_cnp); + if (error) + return (error); + VN_KNOTE(ap->a_dvp, NOTE_WRITE); + return (0); } /* @@ -150,6 +155,7 @@ ufs_mknod(void *v) ufs_makeinode(MAKEIMODE(vap->va_type, vap->va_mode), ap->a_dvp, vpp, ap->a_cnp)) != 0) return (error); + VN_KNOTE(ap->a_dvp, NOTE_WRITE); ip = VTOI(*vpp); mp = (*vpp)->v_mount; ino = ip->i_number; @@ -457,6 +463,7 @@ ufs_setattr(void *v) return (EROFS); error = ufs_chmod(vp, (int)vap->va_mode, cred, p); } + VN_KNOTE(vp, NOTE_ATTRIB); return (error); } @@ -608,6 +615,8 @@ ufs_remove(void *v) error = EPERM; else error = ufs_dirremove(dvp, ip, ap->a_cnp->cn_flags, 0); + VN_KNOTE(vp, NOTE_DELETE); + VN_KNOTE(dvp, NOTE_WRITE); if (dvp == vp) vrele(vp); else @@ -687,6 +696,8 @@ ufs_link(void *v) if (dvp != vp) VOP_UNLOCK(vp, 0); out2: + VN_KNOTE(vp, NOTE_LINK); + VN_KNOTE(dvp, NOTE_WRITE); vput(dvp); return (error); } @@ -892,6 +903,7 @@ ufs_rename(void *v) oldparent = dp->i_number; doingdirectory = 1; } + VN_KNOTE(fdvp, NOTE_WRITE); /* XXXLUKEM/XXX: right place? */ /* vrele(fdvp); */ /* @@ -1000,6 +1012,7 @@ ufs_rename(void *v) } goto bad; } + VN_KNOTE(tdvp, NOTE_WRITE); vput(tdvp); } else { if (xp->i_dev != dp->i_dev || xp->i_dev != ip->i_dev) @@ -1077,7 +1090,9 @@ ufs_rename(void *v) tcnp->cn_cred, tcnp->cn_proc))) goto bad; } + VN_KNOTE(tdvp, NOTE_WRITE); vput(tdvp); + VN_KNOTE(tvp, NOTE_DELETE); vput(tvp); xp = NULL; } @@ -1130,6 +1145,7 @@ ufs_rename(void *v) error = ufs_dirremove(fdvp, xp, fcnp->cn_flags, 0); xp->i_flag &= ~IN_RENAME; } + VN_KNOTE(fvp, NOTE_RENAME); if (dp) vput(fdvp); if (xp) @@ -1309,6 +1325,7 @@ ufs_mkdir(void *v) error = ufs_direnter(dvp, tvp, &newdir, cnp, bp); bad: if (error == 0) { + VN_KNOTE(dvp, NOTE_WRITE | NOTE_LINK); *ap->a_vpp = tvp; } else { dp->i_ffs_effnlink--; @@ -1410,6 +1427,7 @@ ufs_rmdir(void *v) } goto out; } + VN_KNOTE(dvp, NOTE_WRITE | NOTE_LINK); cache_purge(dvp); /* * Truncate inode. The only stuff left in the directory is "." and @@ -1428,6 +1446,7 @@ ufs_rmdir(void *v) } cache_purge(vp); out: + VN_KNOTE(vp, NOTE_DELETE); vput(dvp); vput(vp); return (error); @@ -1455,6 +1474,7 @@ ufs_symlink(void *v) vpp, ap->a_cnp); if (error) return (error); + VN_KNOTE(ap->a_dvp, NOTE_WRITE); vp = *vpp; len = strlen(ap->a_target); if (len < vp->v_mount->mnt_maxsymlinklen) { diff --git a/sys/uvm/uvm_swap.c b/sys/uvm/uvm_swap.c index cdcca357e0ae..58877afd7047 100644 --- a/sys/uvm/uvm_swap.c +++ b/sys/uvm/uvm_swap.c @@ -1,4 +1,4 @@ -/* $NetBSD: uvm_swap.c,v 1.70 2002/09/27 15:38:09 provos Exp $ */ +/* $NetBSD: uvm_swap.c,v 1.71 2002/10/23 09:15:10 jdolecek Exp $ */ /* * Copyright (c) 1995, 1996, 1997 Matthew R. Green @@ -32,7 +32,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: uvm_swap.c,v 1.70 2002/09/27 15:38:09 provos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uvm_swap.c,v 1.71 2002/10/23 09:15:10 jdolecek Exp $"); #include "fs_nfs.h" #include "opt_uvmhist.h" @@ -243,7 +243,7 @@ const struct bdevsw swap_bdevsw = { const struct cdevsw swap_cdevsw = { nullopen, nullclose, swread, swwrite, noioctl, - nostop, notty, nopoll, nommap, + nostop, notty, nopoll, nommap, nokqfilter }; /*