Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F153621822
D51807.id160006.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D51807.id160006.diff
View Options
diff --git a/sys/dev/null/null.c b/sys/dev/null/null.c
--- a/sys/dev/null/null.c
+++ b/sys/dev/null/null.c
@@ -4,6 +4,7 @@
* Copyright (c) 2000 Mark R. V. Murray & Jeroen C. van Gelderen
* Copyright (c) 2001-2004 Mark R. V. Murray
* Copyright (c) 2014 Eitan Adler
+ * Copyright (c) 2025 Pietro Cerutti
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -39,6 +40,7 @@
#include <sys/disk.h>
#include <sys/bus.h>
#include <sys/filio.h>
+#include <sys/event.h>
#include <machine/bus.h>
#include <machine/vmparam.h>
@@ -53,12 +55,27 @@
static d_ioctl_t null_ioctl;
static d_ioctl_t zero_ioctl;
static d_read_t zero_read;
+static d_kqfilter_t full_kqfilter;
+static d_kqfilter_t null_kqfilter;
+static int immediate_event(struct knote *kn, long hint);
+static int never_event(struct knote *kn, long hint);
+
+static const struct filterops immediate_filterops = {
+ .f_isfd = 1,
+ .f_event = immediate_event
+};
+
+static const struct filterops never_filterops = {
+ .f_isfd = 1,
+ .f_event = never_event
+};
static struct cdevsw full_cdevsw = {
.d_version = D_VERSION,
.d_read = zero_read,
.d_write = full_write,
.d_ioctl = zero_ioctl,
+ .d_kqfilter = null_kqfilter,
.d_name = "full",
};
@@ -67,6 +84,7 @@
.d_read = (d_read_t *)nullop,
.d_write = null_write,
.d_ioctl = null_ioctl,
+ .d_kqfilter = null_kqfilter,
.d_name = "null",
};
@@ -75,6 +93,7 @@
.d_read = zero_read,
.d_write = null_write,
.d_ioctl = zero_ioctl,
+ .d_kqfilter = null_kqfilter,
.d_name = "zero",
.d_flags = D_MMAP_ANON,
};
@@ -197,5 +216,47 @@
return (0);
}
+static int
+immediate_event(struct knote *kn, long hint)
+{
+ return 1;
+}
+
+static int
+never_event(struct knote *kn, long hint)
+{
+ return 0;
+}
+
+static int
+full_kqfilter(struct cdev *dev, struct knote *kn)
+{
+ switch (kn->kn_filter)
+ {
+ case EVFILT_READ:
+ kn->kn_fop = &immediate_filterops;
+ return (0);
+ case EVFILT_WRITE:
+ kn->kn_fop = &never_filterops;
+ return (0);
+ default:
+ return(EOPNOTSUPP);
+ }
+}
+
+static int
+null_kqfilter(struct cdev *dev, struct knote *kn)
+{
+ switch (kn->kn_filter)
+ {
+ case EVFILT_READ:
+ case EVFILT_WRITE:
+ kn->kn_fop = &immediate_filterops;
+ return (0);
+ default:
+ return(EOPNOTSUPP);
+ }
+}
+
DEV_MODULE(null, null_modevent, NULL);
MODULE_VERSION(null, 1);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Apr 23, 10:06 AM (8 h, 5 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
32022975
Default Alt Text
D51807.id160006.diff (2 KB)
Attached To
Mode
D51807: null: support EVFILT_READ/EVFILT_WRITE kevent filters
Attached
Detach File
Event Timeline
Log In to Comment