git: ef9ffb8594ee - main - kern: Make fileops and filterops tables const where possible

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Tue, 26 Nov 2024 21:32:39 UTC
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=ef9ffb8594eee294334ced627755bf5b46b48f9f

commit ef9ffb8594eee294334ced627755bf5b46b48f9f
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2024-11-25 22:39:31 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2024-11-26 21:04:21 +0000

    kern: Make fileops and filterops tables const where possible
    
    No functional change intended.
    
    MFC after:      1 week
---
 sys/arm/ti/ti_pruss.c                              |  2 +-
 sys/cam/scsi/scsi_pass.c                           |  2 +-
 sys/cam/scsi/scsi_target.c                         |  2 +-
 sys/compat/linuxkpi/common/include/linux/file.h    |  2 +-
 sys/compat/linuxkpi/common/src/linux_compat.c      |  6 +++---
 sys/dev/beri/beri_ring.c                           |  4 ++--
 sys/dev/cyapa/cyapa.c                              |  2 +-
 sys/dev/evdev/cdev.c                               |  2 +-
 sys/dev/evdev/uinput.c                             |  4 ++--
 sys/dev/gpio/gpioc.c                               |  2 +-
 sys/dev/hid/hidraw.c                               |  2 +-
 sys/dev/netmap/netmap_freebsd.c                    |  4 ++--
 sys/dev/qat/qat_common/adf_freebsd_dev_processes.c |  2 +-
 sys/dev/usb/usb_dev.c                              |  4 ++--
 sys/fs/cuse/cuse.c                                 |  4 ++--
 sys/fs/devfs/devfs_vnops.c                         |  4 ++--
 sys/fs/fuse/fuse_device.c                          |  4 ++--
 sys/geom/geom_dev.c                                |  2 +-
 sys/kern/kern_descrip.c                            |  9 +++++----
 sys/kern/kern_devctl.c                             |  2 +-
 sys/kern/kern_event.c                              | 18 +++++++++---------
 sys/kern/kern_sig.c                                |  2 +-
 sys/kern/subr_log.c                                |  2 +-
 sys/kern/sys_eventfd.c                             |  6 +++---
 sys/kern/sys_pipe.c                                |  8 ++++----
 sys/kern/sys_procdesc.c                            |  4 ++--
 sys/kern/sys_socket.c                              |  2 +-
 sys/kern/sys_timerfd.c                             |  4 ++--
 sys/kern/tty.c                                     |  4 ++--
 sys/kern/tty_pts.c                                 |  6 +++---
 sys/kern/uipc_mqueue.c                             |  8 ++++----
 sys/kern/uipc_sem.c                                |  2 +-
 sys/kern/uipc_shm.c                                |  2 +-
 sys/kern/uipc_socket.c                             |  6 +++---
 sys/kern/vfs_aio.c                                 |  4 ++--
 sys/kern/vfs_subr.c                                |  8 ++++----
 sys/kern/vfs_vnops.c                               |  2 +-
 sys/net/bpf.c                                      |  4 ++--
 sys/net/if_tuntap.c                                |  4 ++--
 sys/security/audit/audit_pipe.c                    |  2 +-
 sys/sys/file.h                                     | 12 ++++++------
 sys/sys/mman.h                                     |  2 +-
 sys/sys/pipe.h                                     |  2 +-
 sys/x86/acpica/acpi_apm.c                          |  2 +-
 44 files changed, 91 insertions(+), 90 deletions(-)

diff --git a/sys/arm/ti/ti_pruss.c b/sys/arm/ti/ti_pruss.c
index b7a04f2cfb42..4e9f2022240c 100644
--- a/sys/arm/ti/ti_pruss.c
+++ b/sys/arm/ti/ti_pruss.c
@@ -789,7 +789,7 @@ ti_pruss_mmap(struct cdev *cdev, vm_ooffset_t offset, vm_paddr_t *paddr,
 	return (0);
 }
 
-static struct filterops ti_pruss_kq_read = {
+static const struct filterops ti_pruss_kq_read = {
 	.f_isfd = 1,
 	.f_detach = ti_pruss_irq_kqread_detach,
 	.f_event = ti_pruss_irq_kqevent,
diff --git a/sys/cam/scsi/scsi_pass.c b/sys/cam/scsi/scsi_pass.c
index 5a24f11e60e2..534ea945a54b 100644
--- a/sys/cam/scsi/scsi_pass.c
+++ b/sys/cam/scsi/scsi_pass.c
@@ -202,7 +202,7 @@ static struct cdevsw pass_cdevsw = {
 	.d_name =	"pass",
 };
 
-static struct filterops passread_filtops = {
+static const struct filterops passread_filtops = {
 	.f_isfd	=	1,
 	.f_detach =	passreadfiltdetach,
 	.f_event =	passreadfilt
diff --git a/sys/cam/scsi/scsi_target.c b/sys/cam/scsi/scsi_target.c
index 034b528b415c..21c78e35dadc 100644
--- a/sys/cam/scsi/scsi_target.c
+++ b/sys/cam/scsi/scsi_target.c
@@ -104,7 +104,7 @@ static d_poll_t		targpoll;
 static d_kqfilter_t	targkqfilter;
 static void		targreadfiltdetach(struct knote *kn);
 static int		targreadfilt(struct knote *kn, long hint);
-static struct filterops targread_filtops = {
+static const struct filterops targread_filtops = {
 	.f_isfd = 1,
 	.f_detach = targreadfiltdetach,
 	.f_event = targreadfilt,
diff --git a/sys/compat/linuxkpi/common/include/linux/file.h b/sys/compat/linuxkpi/common/include/linux/file.h
index f94e3d89ced1..f6e988c2d88e 100644
--- a/sys/compat/linuxkpi/common/include/linux/file.h
+++ b/sys/compat/linuxkpi/common/include/linux/file.h
@@ -43,7 +43,7 @@ struct linux_file;
 
 #undef file
 
-extern struct fileops linuxfileops;
+extern const struct fileops linuxfileops;
 
 static inline struct linux_file *
 linux_fget(unsigned int fd)
diff --git a/sys/compat/linuxkpi/common/src/linux_compat.c b/sys/compat/linuxkpi/common/src/linux_compat.c
index 8f705cd3b2ce..ec3ccb16b47d 100644
--- a/sys/compat/linuxkpi/common/src/linux_compat.c
+++ b/sys/compat/linuxkpi/common/src/linux_compat.c
@@ -1112,13 +1112,13 @@ linux_file_kqfilter_write_event(struct knote *kn, long hint)
 	return ((filp->f_kqflags & LINUX_KQ_FLAG_NEED_WRITE) ? 1 : 0);
 }
 
-static struct filterops linux_dev_kqfiltops_read = {
+static const struct filterops linux_dev_kqfiltops_read = {
 	.f_isfd = 1,
 	.f_detach = linux_file_kqfilter_detach,
 	.f_event = linux_file_kqfilter_read_event,
 };
 
-static struct filterops linux_dev_kqfiltops_write = {
+static const struct filterops linux_dev_kqfiltops_write = {
 	.f_isfd = 1,
 	.f_detach = linux_file_kqfilter_detach,
 	.f_event = linux_file_kqfilter_write_event,
@@ -1737,7 +1737,7 @@ linux_file_kcmp(struct file *fp1, struct file *fp2, struct thread *td)
 	return (kcmp_cmp((uintptr_t)filp1->f_cdev, (uintptr_t)filp2->f_cdev));
 }
 
-struct fileops linuxfileops = {
+const struct fileops linuxfileops = {
 	.fo_read = linux_file_read,
 	.fo_write = linux_file_write,
 	.fo_truncate = invfo_truncate,
diff --git a/sys/dev/beri/beri_ring.c b/sys/dev/beri/beri_ring.c
index 5ff0a74d8b07..2d8f9d85d069 100644
--- a/sys/dev/beri/beri_ring.c
+++ b/sys/dev/beri/beri_ring.c
@@ -365,14 +365,14 @@ beri_kqdetach(struct knote *kn)
 	knlist_remove(&sc->beri_rsel.si_note, kn, 0);
 }
 
-static struct filterops beri_read_filterops = {
+static const struct filterops beri_read_filterops = {
 	.f_isfd =       1,
 	.f_attach =     NULL,
 	.f_detach =     beri_kqdetach,
 	.f_event =      beri_kqread,
 };
 
-static struct filterops beri_write_filterops = {
+static const struct filterops beri_write_filterops = {
 	.f_isfd =       1,
 	.f_attach =     NULL,
 	.f_detach =     beri_kqdetach,
diff --git a/sys/dev/cyapa/cyapa.c b/sys/dev/cyapa/cyapa.c
index 307cd4d35b2e..50fa4faa560a 100644
--- a/sys/dev/cyapa/cyapa.c
+++ b/sys/dev/cyapa/cyapa.c
@@ -1100,7 +1100,7 @@ again:
 static void cyapafiltdetach(struct knote *);
 static int cyapafilt(struct knote *, long);
 
-static struct filterops cyapa_filtops = {
+static const struct filterops cyapa_filtops = {
 	    .f_isfd = 1,
 	    .f_detach = cyapafiltdetach,
 	    .f_event = cyapafilt
diff --git a/sys/dev/evdev/cdev.c b/sys/dev/evdev/cdev.c
index c9a8258a03a9..9fe1299a0937 100644
--- a/sys/dev/evdev/cdev.c
+++ b/sys/dev/evdev/cdev.c
@@ -91,7 +91,7 @@ static struct cdevsw evdev_cdevsw = {
 	.d_name = "evdev",
 };
 
-static struct filterops evdev_cdev_filterops = {
+static const struct filterops evdev_cdev_filterops = {
 	.f_isfd = 1,
 	.f_attach = NULL,
 	.f_detach = evdev_kqdetach,
diff --git a/sys/dev/evdev/uinput.c b/sys/dev/evdev/uinput.c
index 3bf0e91b7360..9ac9fee8a157 100644
--- a/sys/dev/evdev/uinput.c
+++ b/sys/dev/evdev/uinput.c
@@ -93,13 +93,13 @@ static struct cdevsw uinput_cdevsw = {
 
 static struct cdev *uinput_cdev;
 
-static struct evdev_methods uinput_ev_methods = {
+static const struct evdev_methods uinput_ev_methods = {
 	.ev_open = NULL,
 	.ev_close = NULL,
 	.ev_event = uinput_ev_event,
 };
 
-static struct filterops uinput_filterops = {
+static const struct filterops uinput_filterops = {
 	.f_isfd = 1,
 	.f_attach = NULL,
 	.f_detach = uinput_kqdetach,
diff --git a/sys/dev/gpio/gpioc.c b/sys/dev/gpio/gpioc.c
index b9d95338e211..87fed38ebe3e 100644
--- a/sys/dev/gpio/gpioc.c
+++ b/sys/dev/gpio/gpioc.c
@@ -151,7 +151,7 @@ static struct cdevsw gpioc_cdevsw = {
 	.d_name		= "gpioc",
 };
 
-static struct filterops gpioc_read_filterops = {
+static const struct filterops gpioc_read_filterops = {
 	.f_isfd =	true,
 	.f_attach =	NULL,
 	.f_detach =	gpioc_kqdetach,
diff --git a/sys/dev/hid/hidraw.c b/sys/dev/hid/hidraw.c
index ccfdcdddf545..45ef1995063e 100644
--- a/sys/dev/hid/hidraw.c
+++ b/sys/dev/hid/hidraw.c
@@ -172,7 +172,7 @@ static int		hidraw_kqread(struct knote *, long);
 static void		hidraw_kqdetach(struct knote *);
 static void		hidraw_notify(struct hidraw_softc *);
 
-static struct filterops hidraw_filterops_read = {
+static const struct filterops hidraw_filterops_read = {
 	.f_isfd =	1,
 	.f_detach =	hidraw_kqdetach,
 	.f_event =	hidraw_kqread,
diff --git a/sys/dev/netmap/netmap_freebsd.c b/sys/dev/netmap/netmap_freebsd.c
index 215b1f7bd09e..6448fdc74160 100644
--- a/sys/dev/netmap/netmap_freebsd.c
+++ b/sys/dev/netmap/netmap_freebsd.c
@@ -1397,13 +1397,13 @@ netmap_knwrite(struct knote *kn, long hint)
 	return netmap_knrw(kn, hint, POLLOUT);
 }
 
-static struct filterops netmap_rfiltops = {
+static const struct filterops netmap_rfiltops = {
 	.f_isfd = 1,
 	.f_detach = netmap_knrdetach,
 	.f_event = netmap_knread,
 };
 
-static struct filterops netmap_wfiltops = {
+static const struct filterops netmap_wfiltops = {
 	.f_isfd = 1,
 	.f_detach = netmap_knwdetach,
 	.f_event = netmap_knwrite,
diff --git a/sys/dev/qat/qat_common/adf_freebsd_dev_processes.c b/sys/dev/qat/qat_common/adf_freebsd_dev_processes.c
index a70f25d57dcb..661d5bd0f14e 100644
--- a/sys/dev/qat/qat_common/adf_freebsd_dev_processes.c
+++ b/sys/dev/qat/qat_common/adf_freebsd_dev_processes.c
@@ -85,7 +85,7 @@ static struct cdevsw adf_state_cdevsw = {
 	.d_name = ADF_DEV_STATE_NAME,
 };
 
-static struct filterops adf_state_read_filterops = {
+static const struct filterops adf_state_read_filterops = {
 	.f_isfd = 1,
 	.f_attach = NULL,
 	.f_detach = adf_state_kqread_detach,
diff --git a/sys/dev/usb/usb_dev.c b/sys/dev/usb/usb_dev.c
index c58c3b5f64d5..a736a12fc4f4 100644
--- a/sys/dev/usb/usb_dev.c
+++ b/sys/dev/usb/usb_dev.c
@@ -1228,13 +1228,13 @@ usb_filter_read(struct knote *kn, long hint)
 	return (m ? 1 : 0);
 }
 
-static struct filterops usb_filtops_write = {
+static const struct filterops usb_filtops_write = {
 	.f_isfd = 1,
 	.f_detach = usb_filter_detach,
 	.f_event = usb_filter_write,
 };
 
-static struct filterops usb_filtops_read = {
+static const struct filterops usb_filtops_read = {
 	.f_isfd = 1,
 	.f_detach = usb_filter_detach,
 	.f_event = usb_filter_read,
diff --git a/sys/fs/cuse/cuse.c b/sys/fs/cuse/cuse.c
index 9ef234c35427..e32154654386 100644
--- a/sys/fs/cuse/cuse.c
+++ b/sys/fs/cuse/cuse.c
@@ -191,13 +191,13 @@ static void cuse_client_kqfilter_write_detach(struct knote *kn);
 static int cuse_client_kqfilter_read_event(struct knote *kn, long hint);
 static int cuse_client_kqfilter_write_event(struct knote *kn, long hint);
 
-static struct filterops cuse_client_kqfilter_read_ops = {
+static const struct filterops cuse_client_kqfilter_read_ops = {
 	.f_isfd = 1,
 	.f_detach = cuse_client_kqfilter_read_detach,
 	.f_event = cuse_client_kqfilter_read_event,
 };
 
-static struct filterops cuse_client_kqfilter_write_ops = {
+static const struct filterops cuse_client_kqfilter_write_ops = {
 	.f_isfd = 1,
 	.f_detach = cuse_client_kqfilter_write_detach,
 	.f_event = cuse_client_kqfilter_write_event,
diff --git a/sys/fs/devfs/devfs_vnops.c b/sys/fs/devfs/devfs_vnops.c
index 1ab575ec02bd..e55082b49d97 100644
--- a/sys/fs/devfs/devfs_vnops.c
+++ b/sys/fs/devfs/devfs_vnops.c
@@ -66,7 +66,7 @@
 
 static struct vop_vector devfs_vnodeops;
 static struct vop_vector devfs_specops;
-static struct fileops devfs_ops_f;
+static const struct fileops devfs_ops_f;
 
 #include <fs/devfs/devfs.h>
 #include <fs/devfs/devfs_int.h>
@@ -2037,7 +2037,7 @@ devfs_cmp_f(struct file *fp1, struct file *fp2, struct thread *td)
 	return (kcmp_cmp((uintptr_t)fp1->f_data, (uintptr_t)fp2->f_data));
 }
 
-static struct fileops devfs_ops_f = {
+static const struct fileops devfs_ops_f = {
 	.fo_read =	devfs_read_f,
 	.fo_write =	devfs_write_f,
 	.fo_truncate =	devfs_truncate_f,
diff --git a/sys/fs/fuse/fuse_device.c b/sys/fs/fuse/fuse_device.c
index 892793993ecc..087316e86e90 100644
--- a/sys/fs/fuse/fuse_device.c
+++ b/sys/fs/fuse/fuse_device.c
@@ -120,13 +120,13 @@ static int fuse_device_filt_read(struct knote *kn, long hint);
 static int fuse_device_filt_write(struct knote *kn, long hint);
 static void fuse_device_filt_detach(struct knote *kn);
 
-struct filterops fuse_device_rfiltops = {
+static const struct filterops fuse_device_rfiltops = {
 	.f_isfd = 1,
 	.f_detach = fuse_device_filt_detach,
 	.f_event = fuse_device_filt_read,
 };
 
-struct filterops fuse_device_wfiltops = {
+static const struct filterops fuse_device_wfiltops = {
 	.f_isfd = 1,
 	.f_event = fuse_device_filt_write,
 };
diff --git a/sys/geom/geom_dev.c b/sys/geom/geom_dev.c
index 8028ae18e33a..8607f476db20 100644
--- a/sys/geom/geom_dev.c
+++ b/sys/geom/geom_dev.c
@@ -78,7 +78,7 @@ static d_kqfilter_t	g_dev_kqfilter;
 static void		gdev_filter_detach(struct knote *kn);
 static int		gdev_filter_vnode(struct knote *kn, long hint);
 
-static struct filterops gdev_filterops_vnode = {
+static const struct filterops gdev_filterops_vnode = {
 	.f_isfd = 1,
 	.f_detach = gdev_filter_detach,
 	.f_event = gdev_filter_vnode,
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c
index 09eeb158f1f5..10e0b4b142f8 100644
--- a/sys/kern/kern_descrip.c
+++ b/sys/kern/kern_descrip.c
@@ -2859,7 +2859,8 @@ closef_nothread(struct file *fp)
  * called with bad data.
  */
 void
-finit(struct file *fp, u_int flag, short type, void *data, struct fileops *ops)
+finit(struct file *fp, u_int flag, short type, void *data,
+    const struct fileops *ops)
 {
 	fp->f_data = data;
 	fp->f_flag = flag;
@@ -2868,7 +2869,7 @@ finit(struct file *fp, u_int flag, short type, void *data, struct fileops *ops)
 }
 
 void
-finit_vnode(struct file *fp, u_int flag, void *data, struct fileops *ops)
+finit_vnode(struct file *fp, u_int flag, void *data, const struct fileops *ops)
 {
 	fp->f_seqcount[UIO_READ] = 1;
 	fp->f_seqcount[UIO_WRITE] = 1;
@@ -5265,7 +5266,7 @@ badfo_fill_kinfo(struct file *fp, struct kinfo_file *kif, struct filedesc *fdp)
 	return (0);
 }
 
-struct fileops badfileops = {
+const struct fileops badfileops = {
 	.fo_read = badfo_readwrite,
 	.fo_write = badfo_readwrite,
 	.fo_truncate = badfo_truncate,
@@ -5296,7 +5297,7 @@ path_close(struct file *fp, struct thread *td)
 	return (0);
 }
 
-struct fileops path_fileops = {
+const struct fileops path_fileops = {
 	.fo_read = badfo_readwrite,
 	.fo_write = badfo_readwrite,
 	.fo_truncate = badfo_truncate,
diff --git a/sys/kern/kern_devctl.c b/sys/kern/kern_devctl.c
index 602b82105525..d83bc380c2fe 100644
--- a/sys/kern/kern_devctl.c
+++ b/sys/kern/kern_devctl.c
@@ -126,7 +126,7 @@ static struct cdevsw dev_cdevsw = {
 static void	filt_devctl_detach(struct knote *kn);
 static int	filt_devctl_read(struct knote *kn, long hint);
 
-static struct filterops devctl_rfiltops = {
+static const struct filterops devctl_rfiltops = {
 	.f_isfd = 1,
 	.f_detach = filt_devctl_detach,
 	.f_event = filt_devctl_read,
diff --git a/sys/kern/kern_event.c b/sys/kern/kern_event.c
index fa96fbad20ce..dcb2c10ee1f5 100644
--- a/sys/kern/kern_event.c
+++ b/sys/kern/kern_event.c
@@ -127,7 +127,7 @@ static fo_stat_t	kqueue_stat;
 static fo_close_t	kqueue_close;
 static fo_fill_kinfo_t	kqueue_fill_kinfo;
 
-static struct fileops kqueueops = {
+static const struct fileops kqueueops = {
 	.fo_read = invfo_rdwr,
 	.fo_write = invfo_rdwr,
 	.fo_truncate = invfo_truncate,
@@ -173,30 +173,30 @@ static int	filt_user(struct knote *kn, long hint);
 static void	filt_usertouch(struct knote *kn, struct kevent *kev,
 		    u_long type);
 
-static struct filterops file_filtops = {
+static const struct filterops file_filtops = {
 	.f_isfd = 1,
 	.f_attach = filt_fileattach,
 };
-static struct filterops kqread_filtops = {
+static const struct filterops kqread_filtops = {
 	.f_isfd = 1,
 	.f_detach = filt_kqdetach,
 	.f_event = filt_kqueue,
 };
 /* XXX - move to kern_proc.c?  */
-static struct filterops proc_filtops = {
+static const struct filterops proc_filtops = {
 	.f_isfd = 0,
 	.f_attach = filt_procattach,
 	.f_detach = filt_procdetach,
 	.f_event = filt_proc,
 };
-static struct filterops timer_filtops = {
+static const struct filterops timer_filtops = {
 	.f_isfd = 0,
 	.f_attach = filt_timerattach,
 	.f_detach = filt_timerdetach,
 	.f_event = filt_timer,
 	.f_touch = filt_timertouch,
 };
-static struct filterops user_filtops = {
+static const struct filterops user_filtops = {
 	.f_attach = filt_userattach,
 	.f_detach = filt_userdetach,
 	.f_event = filt_user,
@@ -327,14 +327,14 @@ filt_nullattach(struct knote *kn)
 	return (ENXIO);
 };
 
-struct filterops null_filtops = {
+static const struct filterops null_filtops = {
 	.f_isfd = 0,
 	.f_attach = filt_nullattach,
 };
 
 /* XXX - make SYSINIT to add these, and move into respective modules. */
-extern struct filterops sig_filtops;
-extern struct filterops fs_filtops;
+extern const struct filterops sig_filtops;
+extern const struct filterops fs_filtops;
 
 /*
  * Table for all system-defined filters.
diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c
index 96dc5e356ae9..c59bfd035be7 100644
--- a/sys/kern/kern_sig.c
+++ b/sys/kern/kern_sig.c
@@ -117,7 +117,7 @@ static void	sigqueue_start(void);
 static void	sigfastblock_setpend(struct thread *td, bool resched);
 
 static uma_zone_t	ksiginfo_zone = NULL;
-struct filterops sig_filtops = {
+const struct filterops sig_filtops = {
 	.f_isfd = 0,
 	.f_attach = filt_sigattach,
 	.f_detach = filt_sigdetach,
diff --git a/sys/kern/subr_log.c b/sys/kern/subr_log.c
index b1cf0e025f00..f5bfd038a030 100644
--- a/sys/kern/subr_log.c
+++ b/sys/kern/subr_log.c
@@ -74,7 +74,7 @@ static struct cdevsw log_cdevsw = {
 static int	logkqread(struct knote *note, long hint);
 static void	logkqdetach(struct knote *note);
 
-static struct filterops log_read_filterops = {
+static const struct filterops log_read_filterops = {
 	.f_isfd =	1,
 	.f_attach =	NULL,
 	.f_detach =	logkqdetach,
diff --git a/sys/kern/sys_eventfd.c b/sys/kern/sys_eventfd.c
index 4b1230b29b16..a0f10843475c 100644
--- a/sys/kern/sys_eventfd.c
+++ b/sys/kern/sys_eventfd.c
@@ -63,7 +63,7 @@ static fo_stat_t	eventfd_stat;
 static fo_close_t	eventfd_close;
 static fo_fill_kinfo_t	eventfd_fill_kinfo;
 
-static struct fileops eventfdops = {
+static const struct fileops eventfdops = {
 	.fo_read = eventfd_read,
 	.fo_write = eventfd_write,
 	.fo_truncate = invfo_truncate,
@@ -84,13 +84,13 @@ static void	filt_eventfddetach(struct knote *kn);
 static int	filt_eventfdread(struct knote *kn, long hint);
 static int	filt_eventfdwrite(struct knote *kn, long hint);
 
-static struct filterops eventfd_rfiltops = {
+static const struct filterops eventfd_rfiltops = {
 	.f_isfd = 1,
 	.f_detach = filt_eventfddetach,
 	.f_event = filt_eventfdread
 };
 
-static struct filterops eventfd_wfiltops = {
+static const struct filterops eventfd_wfiltops = {
 	.f_isfd = 1,
 	.f_detach = filt_eventfddetach,
 	.f_event = filt_eventfdwrite
diff --git a/sys/kern/sys_pipe.c b/sys/kern/sys_pipe.c
index 6a5d150423bc..b842db44e7f1 100644
--- a/sys/kern/sys_pipe.c
+++ b/sys/kern/sys_pipe.c
@@ -153,7 +153,7 @@ static fo_chmod_t	pipe_chmod;
 static fo_chown_t	pipe_chown;
 static fo_fill_kinfo_t	pipe_fill_kinfo;
 
-struct fileops pipeops = {
+const struct fileops pipeops = {
 	.fo_read = pipe_read,
 	.fo_write = pipe_write,
 	.fo_truncate = pipe_truncate,
@@ -176,17 +176,17 @@ static int	filt_pipenotsup(struct knote *kn, long hint);
 static int	filt_piperead(struct knote *kn, long hint);
 static int	filt_pipewrite(struct knote *kn, long hint);
 
-static struct filterops pipe_nfiltops = {
+static const struct filterops pipe_nfiltops = {
 	.f_isfd = 1,
 	.f_detach = filt_pipedetach_notsup,
 	.f_event = filt_pipenotsup
 };
-static struct filterops pipe_rfiltops = {
+static const struct filterops pipe_rfiltops = {
 	.f_isfd = 1,
 	.f_detach = filt_pipedetach,
 	.f_event = filt_piperead
 };
-static struct filterops pipe_wfiltops = {
+static const struct filterops pipe_wfiltops = {
 	.f_isfd = 1,
 	.f_detach = filt_pipedetach,
 	.f_event = filt_pipewrite
diff --git a/sys/kern/sys_procdesc.c b/sys/kern/sys_procdesc.c
index 90022186d1ff..6acaef9d394d 100644
--- a/sys/kern/sys_procdesc.c
+++ b/sys/kern/sys_procdesc.c
@@ -96,7 +96,7 @@ static fo_close_t	procdesc_close;
 static fo_fill_kinfo_t	procdesc_fill_kinfo;
 static fo_cmp_t		procdesc_cmp;
 
-static struct fileops procdesc_ops = {
+static const struct fileops procdesc_ops = {
 	.fo_read = invfo_rdwr,
 	.fo_write = invfo_rdwr,
 	.fo_truncate = invfo_truncate,
@@ -481,7 +481,7 @@ procdesc_kqops_event(struct knote *kn, long hint)
 	return (kn->kn_fflags != 0);
 }
 
-static struct filterops procdesc_kqops = {
+static const struct filterops procdesc_kqops = {
 	.f_isfd = 1,
 	.f_detach = procdesc_kqops_detach,
 	.f_event = procdesc_kqops_event,
diff --git a/sys/kern/sys_socket.c b/sys/kern/sys_socket.c
index 65d864e4f9f4..9011aa31c44f 100644
--- a/sys/kern/sys_socket.c
+++ b/sys/kern/sys_socket.c
@@ -96,7 +96,7 @@ static fo_aio_queue_t soo_aio_queue;
 
 static void	soo_aio_cancel(struct kaiocb *job);
 
-struct fileops	socketops = {
+const struct fileops socketops = {
 	.fo_read = soo_read,
 	.fo_write = soo_write,
 	.fo_truncate = invfo_truncate,
diff --git a/sys/kern/sys_timerfd.c b/sys/kern/sys_timerfd.c
index 8ac5b845f7ac..ab7e048a2ab1 100644
--- a/sys/kern/sys_timerfd.c
+++ b/sys/kern/sys_timerfd.c
@@ -284,7 +284,7 @@ filt_timerfdread(struct knote *kn, long hint)
 	return (tfd->tfd_count > 0);
 }
 
-static struct filterops timerfd_rfiltops = {
+static const struct filterops timerfd_rfiltops = {
 	.f_isfd = 1,
 	.f_detach = filt_timerfddetach,
 	.f_event = filt_timerfdread,
@@ -359,7 +359,7 @@ timerfd_fill_kinfo(struct file *fp, struct kinfo_file *kif,
 	return (0);
 }
 
-static struct fileops timerfdops = {
+static const struct fileops timerfdops = {
 	.fo_read = timerfd_read,
 	.fo_write = invfo_rdwr,
 	.fo_truncate = invfo_truncate,
diff --git a/sys/kern/tty.c b/sys/kern/tty.c
index b6e300321e9c..b1b3b268d0e9 100644
--- a/sys/kern/tty.c
+++ b/sys/kern/tty.c
@@ -751,13 +751,13 @@ tty_kqops_write_event(struct knote *kn, long hint __unused)
 	}
 }
 
-static struct filterops tty_kqops_read = {
+static const struct filterops tty_kqops_read = {
 	.f_isfd = 1,
 	.f_detach = tty_kqops_read_detach,
 	.f_event = tty_kqops_read_event,
 };
 
-static struct filterops tty_kqops_write = {
+static const struct filterops tty_kqops_write = {
 	.f_isfd = 1,
 	.f_detach = tty_kqops_write_detach,
 	.f_event = tty_kqops_write_event,
diff --git a/sys/kern/tty_pts.c b/sys/kern/tty_pts.c
index 4a3b3d77c89e..d629fa0e7593 100644
--- a/sys/kern/tty_pts.c
+++ b/sys/kern/tty_pts.c
@@ -488,12 +488,12 @@ pts_kqops_write_event(struct knote *kn, long hint)
 	}
 }
 
-static struct filterops pts_kqops_read = {
+static const struct filterops pts_kqops_read = {
 	.f_isfd = 1,
 	.f_detach = pts_kqops_read_detach,
 	.f_event = pts_kqops_read_event,
 };
-static struct filterops pts_kqops_write = {
+static const struct filterops pts_kqops_write = {
 	.f_isfd = 1,
 	.f_detach = pts_kqops_write_detach,
 	.f_event = pts_kqops_write_event,
@@ -597,7 +597,7 @@ ptsdev_fill_kinfo(struct file *fp, struct kinfo_file *kif, struct filedesc *fdp)
 	return (0);
 }
 
-static struct fileops ptsdev_ops = {
+static const struct fileops ptsdev_ops = {
 	.fo_read	= ptsdev_read,
 	.fo_write	= ptsdev_write,
 	.fo_truncate	= invfo_truncate,
diff --git a/sys/kern/uipc_mqueue.c b/sys/kern/uipc_mqueue.c
index c0948d40c47b..54a9eda5a7a7 100644
--- a/sys/kern/uipc_mqueue.c
+++ b/sys/kern/uipc_mqueue.c
@@ -230,7 +230,7 @@ static uma_zone_t		mqueue_zone;
 static uma_zone_t		mvdata_zone;
 static uma_zone_t		mqnoti_zone;
 static struct vop_vector	mqfs_vnodeops;
-static struct fileops		mqueueops;
+static const struct fileops	mqueueops;
 static unsigned			mqfs_osd_jail_slot;
 
 /*
@@ -277,12 +277,12 @@ static void	filt_mqdetach(struct knote *kn);
 static int	filt_mqread(struct knote *kn, long hint);
 static int	filt_mqwrite(struct knote *kn, long hint);
 
-struct filterops mq_rfiltops = {
+static const struct filterops mq_rfiltops = {
 	.f_isfd = 1,
 	.f_detach = filt_mqdetach,
 	.f_event = filt_mqread,
 };
-struct filterops mq_wfiltops = {
+static const struct filterops mq_wfiltops = {
 	.f_isfd = 1,
 	.f_detach = filt_mqdetach,
 	.f_event = filt_mqwrite,
@@ -2681,7 +2681,7 @@ mqf_fill_kinfo(struct file *fp, struct kinfo_file *kif, struct filedesc *fdp)
 	return (0);
 }
 
-static struct fileops mqueueops = {
+static const struct fileops mqueueops = {
 	.fo_read		= invfo_rdwr,
 	.fo_write		= invfo_rdwr,
 	.fo_truncate		= invfo_truncate,
diff --git a/sys/kern/uipc_sem.c b/sys/kern/uipc_sem.c
index b4652e9106ac..35ca9a9fb06e 100644
--- a/sys/kern/uipc_sem.c
+++ b/sys/kern/uipc_sem.c
@@ -140,7 +140,7 @@ static fo_chown_t	ksem_chown;
 static fo_fill_kinfo_t	ksem_fill_kinfo;
 
 /* File descriptor operations. */
-static struct fileops ksem_ops = {
+static const struct fileops ksem_ops = {
 	.fo_read = invfo_rdwr,
 	.fo_write = invfo_rdwr,
 	.fo_truncate = invfo_truncate,
diff --git a/sys/kern/uipc_shm.c b/sys/kern/uipc_shm.c
index 141d386af396..074ca514c77d 100644
--- a/sys/kern/uipc_shm.c
+++ b/sys/kern/uipc_shm.c
@@ -150,7 +150,7 @@ static fo_fallocate_t	shm_fallocate;
 static fo_fspacectl_t	shm_fspacectl;
 
 /* File descriptor operations. */
-struct fileops shm_ops = {
+const struct fileops shm_ops = {
 	.fo_read = shm_read,
 	.fo_write = shm_write,
 	.fo_truncate = shm_truncate,
diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c
index d8878505d511..470a2b3a51e4 100644
--- a/sys/kern/uipc_socket.c
+++ b/sys/kern/uipc_socket.c
@@ -188,17 +188,17 @@ static int	filt_sowrite(struct knote *kn, long hint);
 static int	filt_soempty(struct knote *kn, long hint);
 fo_kqfilter_t	soo_kqfilter;
 
-static struct filterops soread_filtops = {
+static const struct filterops soread_filtops = {
 	.f_isfd = 1,
 	.f_detach = filt_sordetach,
 	.f_event = filt_soread,
 };
-static struct filterops sowrite_filtops = {
+static const struct filterops sowrite_filtops = {
 	.f_isfd = 1,
 	.f_detach = filt_sowdetach,
 	.f_event = filt_sowrite,
 };
-static struct filterops soempty_filtops = {
+static const struct filterops soempty_filtops = {
 	.f_isfd = 1,
 	.f_detach = filt_sowdetach,
 	.f_event = filt_soempty,
diff --git a/sys/kern/vfs_aio.c b/sys/kern/vfs_aio.c
index eb08716fbeda..92c30b48e4f5 100644
--- a/sys/kern/vfs_aio.c
+++ b/sys/kern/vfs_aio.c
@@ -339,13 +339,13 @@ static int	filt_lio(struct knote *kn, long hint);
 static uma_zone_t kaio_zone, aiocb_zone, aiolio_zone;
 
 /* kqueue filters for aio */
-static struct filterops aio_filtops = {
+static const struct filterops aio_filtops = {
 	.f_isfd = 0,
 	.f_attach = filt_aioattach,
 	.f_detach = filt_aiodetach,
 	.f_event = filt_aio,
 };
-static struct filterops lio_filtops = {
+static const struct filterops lio_filtops = {
 	.f_isfd = 0,
 	.f_attach = filt_lioattach,
 	.f_detach = filt_liodetach,
diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c
index f9b2a4fb68d1..8f582eb4ca01 100644
--- a/sys/kern/vfs_subr.c
+++ b/sys/kern/vfs_subr.c
@@ -6475,7 +6475,7 @@ static int	filt_fsattach(struct knote *kn);
 static void	filt_fsdetach(struct knote *kn);
 static int	filt_fsevent(struct knote *kn, long hint);
 
-struct filterops fs_filtops = {
+const struct filterops fs_filtops = {
 	.f_isfd = 0,
 	.f_attach = filt_fsattach,
 	.f_detach = filt_fsdetach,
@@ -6555,17 +6555,17 @@ static int	filt_vfsread(struct knote *kn, long hint);
 static int	filt_vfswrite(struct knote *kn, long hint);
 static int	filt_vfsvnode(struct knote *kn, long hint);
 static void	filt_vfsdetach(struct knote *kn);
-static struct filterops vfsread_filtops = {
+static const struct filterops vfsread_filtops = {
 	.f_isfd = 1,
 	.f_detach = filt_vfsdetach,
 	.f_event = filt_vfsread
 };
-static struct filterops vfswrite_filtops = {
+static const struct filterops vfswrite_filtops = {
 	.f_isfd = 1,
 	.f_detach = filt_vfsdetach,
 	.f_event = filt_vfswrite
 };
-static struct filterops vfsvnode_filtops = {
+static const struct filterops vfsvnode_filtops = {
 	.f_isfd = 1,
 	.f_detach = filt_vfsdetach,
 	.f_event = filt_vfsvnode
diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c
index aff3947f91cd..0d96bdb3acba 100644
--- a/sys/kern/vfs_vnops.c
+++ b/sys/kern/vfs_vnops.c
@@ -106,7 +106,7 @@ static fo_mmap_t	vn_mmap;
 static fo_fallocate_t	vn_fallocate;
 static fo_fspacectl_t	vn_fspacectl;
 
-struct 	fileops vnops = {
+const struct fileops vnops = {
 	.fo_read = vn_io_fault,
 	.fo_write = vn_io_fault,
 	.fo_truncate = vn_truncate,
diff --git a/sys/net/bpf.c b/sys/net/bpf.c
index f5a2d2c0d7a2..657a34827bdb 100644
--- a/sys/net/bpf.c
+++ b/sys/net/bpf.c
@@ -249,13 +249,13 @@ static struct cdevsw bpf_cdevsw = {
 	.d_kqfilter =	bpfkqfilter,
 };
 
-static struct filterops bpfread_filtops = {
+static const struct filterops bpfread_filtops = {
 	.f_isfd = 1,
 	.f_detach = filt_bpfdetach,
 	.f_event = filt_bpfread,
 };
 
-static struct filterops bpfwrite_filtops = {
+static const struct filterops bpfwrite_filtops = {
 	.f_isfd = 1,
 	.f_detach = filt_bpfdetach,
 	.f_event = filt_bpfwrite,
diff --git a/sys/net/if_tuntap.c b/sys/net/if_tuntap.c
index f82480971b10..9ad140dcf58f 100644
--- a/sys/net/if_tuntap.c
+++ b/sys/net/if_tuntap.c
@@ -253,14 +253,14 @@ static int		tunkqread(struct knote *, long);
 static int		tunkqwrite(struct knote *, long);
 static void		tunkqdetach(struct knote *);
 
-static struct filterops tun_read_filterops = {
+static const struct filterops tun_read_filterops = {
 	.f_isfd =	1,
 	.f_attach =	NULL,
 	.f_detach =	tunkqdetach,
 	.f_event =	tunkqread,
 };
 
-static struct filterops tun_write_filterops = {
+static const struct filterops tun_write_filterops = {
 	.f_isfd =	1,
 	.f_attach =	NULL,
 	.f_detach =	tunkqdetach,
diff --git a/sys/security/audit/audit_pipe.c b/sys/security/audit/audit_pipe.c
index 704f9c726803..fb773fd04297 100644
--- a/sys/security/audit/audit_pipe.c
+++ b/sys/security/audit/audit_pipe.c
@@ -238,7 +238,7 @@ static struct cdevsw	audit_pipe_cdevsw = {
 static int	audit_pipe_kqread(struct knote *note, long hint);
 static void	audit_pipe_kqdetach(struct knote *note);
 
-static struct filterops audit_pipe_read_filterops = {
+static const struct filterops audit_pipe_read_filterops = {
 	.f_isfd =	1,
 	.f_attach =	NULL,
 	.f_detach =	audit_pipe_kqdetach,
diff --git a/sys/sys/file.h b/sys/sys/file.h
index a2dc02e523d8..bc7dd7e06ded 100644
--- a/sys/sys/file.h
+++ b/sys/sys/file.h
@@ -249,10 +249,10 @@ struct xfile {
 
 #ifdef _KERNEL
 
-extern struct fileops vnops;
-extern struct fileops badfileops;
-extern struct fileops path_fileops;
-extern struct fileops socketops;
+extern const struct fileops vnops;
+extern const struct fileops badfileops;
+extern const struct fileops path_fileops;
+extern const struct fileops socketops;
 extern int maxfiles;		/* kernel limit on number of open files */
 extern int maxfilesperproc;	/* per process limit on number of open files */
 
@@ -284,8 +284,8 @@ fo_kqfilter_t	vn_kqfilter_opath;
 int vn_fill_kinfo_vnode(struct vnode *vp, struct kinfo_file *kif);
 int file_kcmp_generic(struct file *fp1, struct file *fp2, struct thread *td);
 
-void finit(struct file *, u_int, short, void *, struct fileops *);
-void finit_vnode(struct file *, u_int, void *, struct fileops *);
+void finit(struct file *, u_int, short, void *, const struct fileops *);
+void finit_vnode(struct file *, u_int, void *, const struct fileops *);
 int fgetvp(struct thread *td, int fd, cap_rights_t *rightsp,
     struct vnode **vpp);
 int fgetvp_exec(struct thread *td, int fd, cap_rights_t *rightsp,
diff --git a/sys/sys/mman.h b/sys/sys/mman.h
index d2c7bdf1f022..611c5b4e669f 100644
--- a/sys/sys/mman.h
+++ b/sys/sys/mman.h
@@ -312,7 +312,7 @@ bool	shm_largepage(struct shmfd *shmfd);
 void	shm_remove_prison(struct prison *pr);
 int	shm_get_path(struct vm_object *obj, char *path, size_t sz);
 
-extern struct fileops shm_ops;
+extern const struct fileops shm_ops;
 
 #define	MAP_32BIT_MAX_ADDR	((vm_offset_t)1 << 31)
 
diff --git a/sys/sys/pipe.h b/sys/sys/pipe.h
index 0f35316432eb..a83ea800c677 100644
--- a/sys/sys/pipe.h
+++ b/sys/sys/pipe.h
@@ -52,7 +52,7 @@
  * See sys_pipe.c for info on what these limits mean. 
  */
 extern long	maxpipekva;
-extern struct	fileops pipeops;
+extern const struct fileops pipeops;
 #endif
 
 /*
diff --git a/sys/x86/acpica/acpi_apm.c b/sys/x86/acpica/acpi_apm.c
index fcc1663b9a84..be161cd6171b 100644
--- a/sys/x86/acpica/acpi_apm.c
+++ b/sys/x86/acpica/acpi_apm.c
@@ -60,7 +60,7 @@ static d_poll_t		apmpoll;
 static d_kqfilter_t	apmkqfilter;
 static void		apmreadfiltdetach(struct knote *kn);
 static int		apmreadfilt(struct knote *kn, long hint);
-static struct filterops	apm_readfiltops = {
+static const struct filterops apm_readfiltops = {
 	.f_isfd = 1,
 	.f_detach = apmreadfiltdetach,
 	.f_event = apmreadfilt,