forked from fuse4x/kext
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fuse_knote.c
131 lines (107 loc) · 2.71 KB
/
fuse_knote.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
* Copyright (C) 2007 Google. All Rights Reserved.
* Amit Singh <singh@>
*/
#include "fuse.h"
#if M_FUSE4X_ENABLE_KQUEUE
#include "fuse_knote.h"
#include "fuse_node.h"
struct filterops fuseread_filtops =
{ 1, NULL, filt_fusedetach, filt_fuseread };
struct filterops fusewrite_filtops =
{ 1, NULL, filt_fusedetach, filt_fusewrite };
struct filterops fusevnode_filtops =
{ 1, NULL, filt_fusedetach, filt_fusevnode };
/* Like HFS+ ... */
void
filt_fusedetach(struct knote *kn)
{
struct vnode *vp;
vp = (struct vnode *)kn->kn_hook;
if (vnode_getwithvid(vp, kn->kn_hookid)) {
return;
}
if (1) { /* !KNDETACH_VNLOCKED */
if (/* take exclusive lock */ 1) {
(void)KNOTE_DETACH(&VTOFUD(vp)->c_knotes, kn);
/* release lock */
}
}
vnode_put(vp);
}
int
filt_fuseread(struct knote *kn, long hint)
{
vnode_t vp = (vnode_t)kn->kn_hook;
int dropvp = 0;
int result = 0;
if (hint == 0) {
if ((vnode_getwithvid(vp, kn->kn_hookid) != 0)) {
hint = NOTE_REVOKE;
} else {
dropvp = 1;
}
}
if (hint == NOTE_REVOKE) {
/*
* filesystem is gone, so set the EOF flag and schedule
* the knote for deletion.
*/
kn->kn_flags |= (EV_EOF | EV_ONESHOT);
return 1;
}
/* poll(2) semantics dictate always saying there is data */
if (kn->kn_flags & EV_POLL) {
kn->kn_data = 1;
result = 1;
} else {
/* I'm not going to look inside kn_fp now... to hell with it. */
kn->kn_data = 1;
result = 1;
}
if (dropvp) {
vnode_put(vp);
}
return (kn->kn_data != 0);
}
int
filt_fusewrite(struct knote *kn, long hint)
{
if (hint == 0) {
if ((vnode_getwithvid((vnode_t)kn->kn_hook, kn->kn_hookid) != 0)) {
hint = NOTE_REVOKE;
} else
vnode_put((vnode_t)kn->kn_hook);
}
if (hint == NOTE_REVOKE) {
/*
* filesystem is gone, so set the EOF flag and schedule
* the knote for deletion.
*/
kn->kn_data = 0;
kn->kn_flags |= (EV_EOF | EV_ONESHOT);
return 1;
}
kn->kn_data = 0;
return 1;
}
int
filt_fusevnode(struct knote *kn, long hint)
{
if (hint == 0) {
if ((vnode_getwithvid((vnode_t)kn->kn_hook, kn->kn_hookid) != 0)) {
hint = NOTE_REVOKE;
} else {
vnode_put((vnode_t)kn->kn_hook);
}
}
if (kn->kn_sfflags & hint) {
kn->kn_fflags |= (int)hint;
}
if ((hint == NOTE_REVOKE)) {
kn->kn_flags |= (EV_EOF | EV_ONESHOT);
return 1;
}
return (kn->kn_fflags != 0);
}
#endif /* M_FUSE4X_ENABLE_KQUEUE */