From 9dc3dd48f4e381e262328a24e404dbe7cb8cf615 Mon Sep 17 00:00:00 2001 From: jsg Date: Sun, 10 Aug 2014 09:23:06 +0000 Subject: [PATCH] fix kqueue read/write filters for msdosfs and fusefs ok tedu@ --- sys/miscfs/fuse/fuse_vnops.c | 43 ++++++++++++++++++++++++++++++------ sys/msdosfs/msdosfs_vnops.c | 41 ++++++++++++++++++++++++++++------ 2 files changed, 70 insertions(+), 14 deletions(-) diff --git a/sys/miscfs/fuse/fuse_vnops.c b/sys/miscfs/fuse/fuse_vnops.c index 6d6c20d5c5e..81bf7a23ca6 100644 --- a/sys/miscfs/fuse/fuse_vnops.c +++ b/sys/miscfs/fuse/fuse_vnops.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fuse_vnops.c,v 1.19 2014/07/12 18:43:52 tedu Exp $ */ +/* $OpenBSD: fuse_vnops.c,v 1.20 2014/08/10 09:23:06 jsg Exp $ */ /* * Copyright (c) 2012-2013 Sylvestre Gallon * @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -65,7 +66,8 @@ int fusefs_islocked(void *); int fusefs_advlock(void *); /* Prototypes for fusefs kqfilter */ -int filt_fusefsreadwrite(struct knote *, long); +int filt_fusefsread(struct knote *, long); +int filt_fusefswrite(struct knote *, long); int filt_fusefsvnode(struct knote *, long); void filt_fusefsdetach(struct knote *); @@ -105,8 +107,10 @@ struct vops fusefs_vops = { .vop_advlock = fusefs_advlock, }; -struct filterops fusefsreadwrite_filtops = - { 1, NULL, filt_fusefsdetach, filt_fusefsreadwrite }; +struct filterops fusefsread_filtops = + { 1, NULL, filt_fusefsdetach, filt_fusefsread }; +struct filterops fusefswrite_filtops = + { 1, NULL, filt_fusefsdetach, filt_fusefswrite }; struct filterops fusefsvnode_filtops = { 1, NULL, filt_fusefsdetach, filt_fusefsvnode }; @@ -119,10 +123,10 @@ fusefs_kqfilter(void *v) switch (kn->kn_filter) { case EVFILT_READ: - kn->kn_fop = &fusefsreadwrite_filtops; + kn->kn_fop = &fusefsread_filtops; break; case EVFILT_WRITE: - kn->kn_fop = &fusefsreadwrite_filtops; + kn->kn_fop = &fusefswrite_filtops; break; case EVFILT_VNODE: kn->kn_fop = &fusefsvnode_filtops; @@ -147,8 +151,11 @@ filt_fusefsdetach(struct knote *kn) } int -filt_fusefsreadwrite(struct knote *kn, long hint) +filt_fusefsread(struct knote *kn, long hint) { + struct vnode *vp = (struct vnode *)kn->kn_hook; + struct fusefs_node *ip = VTOI(vp); + /* * filesystem is gone, so set the EOF flag and schedule * the knote for deletion @@ -158,9 +165,31 @@ filt_fusefsreadwrite(struct knote *kn, long hint) return (1); } + kn->kn_data = ip->filesize - kn->kn_fp->f_offset; + if (kn->kn_data == 0 && kn->kn_sfflags & NOTE_EOF) { + kn->kn_fflags |= NOTE_EOF; + return (1); + } + return (kn->kn_data != 0); } +int +filt_fusefswrite(struct knote *kn, long hint) +{ + /* + * 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); + } + + kn->kn_data = 0; + return (1); +} + int filt_fusefsvnode(struct knote *kn, long int hint) { diff --git a/sys/msdosfs/msdosfs_vnops.c b/sys/msdosfs/msdosfs_vnops.c index e376b567a71..214ed16b6c6 100644 --- a/sys/msdosfs/msdosfs_vnops.c +++ b/sys/msdosfs/msdosfs_vnops.c @@ -1,4 +1,4 @@ -/* $OpenBSD: msdosfs_vnops.c,v 1.94 2014/07/08 17:19:25 deraadt Exp $ */ +/* $OpenBSD: msdosfs_vnops.c,v 1.95 2014/08/10 09:23:06 jsg Exp $ */ /* $NetBSD: msdosfs_vnops.c,v 1.63 1997/10/17 11:24:19 ws Exp $ */ /*- @@ -77,7 +77,8 @@ static uint32_t fileidhash(uint64_t); int msdosfs_kqfilter(void *); -int filt_msdosfsreadwrite(struct knote *, long); +int filt_msdosfsread(struct knote *, long); +int filt_msdosfswrite(struct knote *, long); int filt_msdosfsvnode(struct knote *, long); void filt_msdosfsdetach(struct knote *); @@ -1939,8 +1940,10 @@ struct vops msdosfs_vops = { .vop_revoke = vop_generic_revoke, }; -struct filterops msdosfsreadwrite_filtops = - { 1, NULL, filt_msdosfsdetach, filt_msdosfsreadwrite }; +struct filterops msdosfsread_filtops = + { 1, NULL, filt_msdosfsdetach, filt_msdosfsread }; +struct filterops msdosfswrite_filtops = + { 1, NULL, filt_msdosfsdetach, filt_msdosfswrite }; struct filterops msdosfsvnode_filtops = { 1, NULL, filt_msdosfsdetach, filt_msdosfsvnode }; @@ -1953,10 +1956,10 @@ msdosfs_kqfilter(void *v) switch (kn->kn_filter) { case EVFILT_READ: - kn->kn_fop = &msdosfsreadwrite_filtops; + kn->kn_fop = &msdosfsread_filtops; break; case EVFILT_WRITE: - kn->kn_fop = &msdosfsreadwrite_filtops; + kn->kn_fop = &msdosfswrite_filtops; break; case EVFILT_VNODE: kn->kn_fop = &msdosfsvnode_filtops; @@ -1981,8 +1984,11 @@ filt_msdosfsdetach(struct knote *kn) } int -filt_msdosfsreadwrite(struct knote *kn, long hint) +filt_msdosfsread(struct knote *kn, long hint) { + struct vnode *vp = (struct vnode *)kn->kn_hook; + struct denode *dep = VTODE(vp); + /* * filesystem is gone, so set the EOF flag and schedule * the knote for deletion. @@ -1992,9 +1998,30 @@ filt_msdosfsreadwrite(struct knote *kn, long hint) return (1); } + kn->kn_data = dep->de_FileSize - kn->kn_fp->f_offset; + if (kn->kn_data == 0 && kn->kn_sfflags & NOTE_EOF) { + kn->kn_fflags |= NOTE_EOF; + return (1); + } return (kn->kn_data != 0); } +int +filt_msdosfswrite(struct knote *kn, long hint) +{ + /* + * 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); + } + + kn->kn_data = 0; + return (1); +} + int filt_msdosfsvnode(struct knote *kn, long hint) { -- 2.20.1