1
2
3
4
5
6
7#ifndef __LINUX_FSNOTIFY_BACKEND_H
8#define __LINUX_FSNOTIFY_BACKEND_H
9
10#ifdef __KERNEL__
11
12#include <linux/idr.h>
13#include <linux/fs.h>
14#include <linux/list.h>
15#include <linux/path.h>
16#include <linux/spinlock.h>
17#include <linux/types.h>
18#include <linux/atomic.h>
19
20
21
22
23
24
25
26#define FS_ACCESS 0x00000001
27#define FS_MODIFY 0x00000002
28#define FS_ATTRIB 0x00000004
29#define FS_CLOSE_WRITE 0x00000008
30#define FS_CLOSE_NOWRITE 0x00000010
31#define FS_OPEN 0x00000020
32#define FS_MOVED_FROM 0x00000040
33#define FS_MOVED_TO 0x00000080
34#define FS_CREATE 0x00000100
35#define FS_DELETE 0x00000200
36#define FS_DELETE_SELF 0x00000400
37#define FS_MOVE_SELF 0x00000800
38
39#define FS_UNMOUNT 0x00002000
40#define FS_Q_OVERFLOW 0x00004000
41#define FS_IN_IGNORED 0x00008000
42
43#define FS_OPEN_PERM 0x00010000
44#define FS_ACCESS_PERM 0x00020000
45
46#define FS_EXCL_UNLINK 0x04000000
47#define FS_ISDIR 0x40000000
48#define FS_IN_ONESHOT 0x80000000
49
50#define FS_DN_RENAME 0x10000000
51#define FS_DN_MULTISHOT 0x20000000
52
53
54
55#define FS_EVENT_ON_CHILD 0x08000000
56
57
58
59#define FS_EVENTS_POSS_ON_CHILD (FS_ACCESS | FS_MODIFY | FS_ATTRIB |\
60 FS_CLOSE_WRITE | FS_CLOSE_NOWRITE | FS_OPEN |\
61 FS_MOVED_FROM | FS_MOVED_TO | FS_CREATE |\
62 FS_DELETE | FS_OPEN_PERM | FS_ACCESS_PERM)
63
64#define FS_MOVE (FS_MOVED_FROM | FS_MOVED_TO)
65
66#define ALL_FSNOTIFY_PERM_EVENTS (FS_OPEN_PERM | FS_ACCESS_PERM)
67
68#define ALL_FSNOTIFY_EVENTS (FS_ACCESS | FS_MODIFY | FS_ATTRIB | \
69 FS_CLOSE_WRITE | FS_CLOSE_NOWRITE | FS_OPEN | \
70 FS_MOVED_FROM | FS_MOVED_TO | FS_CREATE | \
71 FS_DELETE | FS_DELETE_SELF | FS_MOVE_SELF | \
72 FS_UNMOUNT | FS_Q_OVERFLOW | FS_IN_IGNORED | \
73 FS_OPEN_PERM | FS_ACCESS_PERM | FS_EXCL_UNLINK | \
74 FS_ISDIR | FS_IN_ONESHOT | FS_DN_RENAME | \
75 FS_DN_MULTISHOT | FS_EVENT_ON_CHILD)
76
77struct fsnotify_group;
78struct fsnotify_event;
79struct fsnotify_mark;
80struct fsnotify_event_private_data;
81struct fsnotify_fname;
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96struct fsnotify_ops {
97 int (*handle_event)(struct fsnotify_group *group,
98 struct inode *inode,
99 struct fsnotify_mark *inode_mark,
100 struct fsnotify_mark *vfsmount_mark,
101 u32 mask, void *data, int data_type,
102 const unsigned char *file_name, u32 cookie);
103 void (*free_group_priv)(struct fsnotify_group *group);
104 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
105 void (*free_event)(struct fsnotify_event *event);
106};
107
108
109
110
111
112
113struct fsnotify_event {
114 struct list_head list;
115
116 struct inode *inode;
117 u32 mask;
118};
119
120
121
122
123
124
125
126struct fsnotify_group {
127
128
129
130
131
132
133
134
135 atomic_t refcnt;
136
137 const struct fsnotify_ops *ops;
138
139
140 struct mutex notification_mutex;
141 struct list_head notification_list;
142 wait_queue_head_t notification_waitq;
143 unsigned int q_len;
144 unsigned int max_events;
145
146
147
148
149 #define FS_PRIO_0 0
150 #define FS_PRIO_1 1
151 #define FS_PRIO_2 2
152 unsigned int priority;
153
154
155 struct mutex mark_mutex;
156 atomic_t num_marks;
157
158
159 struct list_head marks_list;
160
161 struct fasync_struct *fsn_fa;
162
163 struct fsnotify_event *overflow_event;
164
165
166
167
168 union {
169 void *private;
170#ifdef CONFIG_INOTIFY_USER
171 struct inotify_group_private_data {
172 spinlock_t idr_lock;
173 struct idr idr;
174 struct user_struct *user;
175 } inotify_data;
176#endif
177#ifdef CONFIG_FANOTIFY
178 struct fanotify_group_private_data {
179#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
180
181 spinlock_t access_lock;
182 struct list_head access_list;
183 wait_queue_head_t access_waitq;
184 atomic_t bypass_perm;
185#endif
186 int f_flags;
187 unsigned int max_marks;
188 struct user_struct *user;
189 } fanotify_data;
190#endif
191 };
192};
193
194
195#define FSNOTIFY_EVENT_NONE 0
196#define FSNOTIFY_EVENT_PATH 1
197#define FSNOTIFY_EVENT_INODE 2
198
199
200
201
202struct fsnotify_inode_mark {
203 struct inode *inode;
204 struct hlist_node i_list;
205 struct list_head free_i_list;
206};
207
208
209
210
211struct fsnotify_vfsmount_mark {
212 struct vfsmount *mnt;
213 struct hlist_node m_list;
214 struct list_head free_m_list;
215};
216
217
218
219
220
221
222
223
224
225
226
227struct fsnotify_mark {
228 __u32 mask;
229
230
231 atomic_t refcnt;
232 struct fsnotify_group *group;
233 struct list_head g_list;
234 spinlock_t lock;
235 union {
236 struct fsnotify_inode_mark i;
237 struct fsnotify_vfsmount_mark m;
238 };
239 __u32 ignored_mask;
240#define FSNOTIFY_MARK_FLAG_INODE 0x01
241#define FSNOTIFY_MARK_FLAG_VFSMOUNT 0x02
242#define FSNOTIFY_MARK_FLAG_OBJECT_PINNED 0x04
243#define FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY 0x08
244#define FSNOTIFY_MARK_FLAG_ALIVE 0x10
245 unsigned int flags;
246 struct list_head destroy_list;
247 void (*free_mark)(struct fsnotify_mark *mark);
248};
249
250#ifdef CONFIG_FSNOTIFY
251
252
253
254
255extern int fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is,
256 const unsigned char *name, u32 cookie);
257extern int __fsnotify_parent(struct path *path, struct dentry *dentry, __u32 mask);
258extern void __fsnotify_inode_delete(struct inode *inode);
259extern void __fsnotify_vfsmount_delete(struct vfsmount *mnt);
260extern u32 fsnotify_get_cookie(void);
261
262static inline int fsnotify_inode_watches_children(struct inode *inode)
263{
264
265 if (!(inode->i_fsnotify_mask & FS_EVENT_ON_CHILD))
266 return 0;
267
268
269 return inode->i_fsnotify_mask & FS_EVENTS_POSS_ON_CHILD;
270}
271
272
273
274
275
276static inline void __fsnotify_update_dcache_flags(struct dentry *dentry)
277{
278 struct dentry *parent;
279
280 assert_spin_locked(&dentry->d_lock);
281
282
283
284
285
286
287
288
289 parent = dentry->d_parent;
290 if (parent->d_inode && fsnotify_inode_watches_children(parent->d_inode))
291 dentry->d_flags |= DCACHE_FSNOTIFY_PARENT_WATCHED;
292 else
293 dentry->d_flags &= ~DCACHE_FSNOTIFY_PARENT_WATCHED;
294}
295
296
297
298
299static inline void __fsnotify_d_instantiate(struct dentry *dentry, struct inode *inode)
300{
301 if (!inode)
302 return;
303
304 spin_lock(&dentry->d_lock);
305 __fsnotify_update_dcache_flags(dentry);
306 spin_unlock(&dentry->d_lock);
307}
308
309
310
311
312extern struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops);
313
314extern void fsnotify_get_group(struct fsnotify_group *group);
315
316extern void fsnotify_put_group(struct fsnotify_group *group);
317
318extern void fsnotify_destroy_group(struct fsnotify_group *group);
319
320extern int fsnotify_fasync(int fd, struct file *file, int on);
321
322extern void fsnotify_destroy_event(struct fsnotify_group *group,
323 struct fsnotify_event *event);
324
325extern int fsnotify_add_notify_event(struct fsnotify_group *group,
326 struct fsnotify_event *event,
327 int (*merge)(struct list_head *,
328 struct fsnotify_event *));
329
330extern bool fsnotify_notify_queue_is_empty(struct fsnotify_group *group);
331
332extern struct fsnotify_event *fsnotify_peek_notify_event(struct fsnotify_group *group);
333
334extern struct fsnotify_event *fsnotify_remove_notify_event(struct fsnotify_group *group);
335
336
337
338
339extern void fsnotify_recalc_vfsmount_mask(struct vfsmount *mnt);
340
341extern void fsnotify_recalc_inode_mask(struct inode *inode);
342extern void fsnotify_init_mark(struct fsnotify_mark *mark, void (*free_mark)(struct fsnotify_mark *mark));
343
344extern struct fsnotify_mark *fsnotify_find_inode_mark(struct fsnotify_group *group, struct inode *inode);
345
346extern struct fsnotify_mark *fsnotify_find_vfsmount_mark(struct fsnotify_group *group, struct vfsmount *mnt);
347
348extern void fsnotify_duplicate_mark(struct fsnotify_mark *new, struct fsnotify_mark *old);
349
350extern void fsnotify_set_mark_ignored_mask_locked(struct fsnotify_mark *mark, __u32 mask);
351
352extern void fsnotify_set_mark_mask_locked(struct fsnotify_mark *mark, __u32 mask);
353
354extern int fsnotify_add_mark(struct fsnotify_mark *mark, struct fsnotify_group *group,
355 struct inode *inode, struct vfsmount *mnt, int allow_dups);
356extern int fsnotify_add_mark_locked(struct fsnotify_mark *mark, struct fsnotify_group *group,
357 struct inode *inode, struct vfsmount *mnt, int allow_dups);
358
359extern void fsnotify_destroy_mark(struct fsnotify_mark *mark,
360 struct fsnotify_group *group);
361extern void fsnotify_destroy_mark_locked(struct fsnotify_mark *mark,
362 struct fsnotify_group *group);
363
364extern void fsnotify_clear_vfsmount_marks_by_group(struct fsnotify_group *group);
365
366extern void fsnotify_clear_inode_marks_by_group(struct fsnotify_group *group);
367
368extern void fsnotify_clear_marks_by_group_flags(struct fsnotify_group *group, unsigned int flags);
369
370extern void fsnotify_clear_marks_by_group(struct fsnotify_group *group);
371extern void fsnotify_get_mark(struct fsnotify_mark *mark);
372extern void fsnotify_put_mark(struct fsnotify_mark *mark);
373extern void fsnotify_unmount_inodes(struct list_head *list);
374
375
376extern void fsnotify_init_event(struct fsnotify_event *event,
377 struct inode *to_tell, u32 mask);
378
379#else
380
381static inline int fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is,
382 const unsigned char *name, u32 cookie)
383{
384 return 0;
385}
386
387static inline int __fsnotify_parent(struct path *path, struct dentry *dentry, __u32 mask)
388{
389 return 0;
390}
391
392static inline void __fsnotify_inode_delete(struct inode *inode)
393{}
394
395static inline void __fsnotify_vfsmount_delete(struct vfsmount *mnt)
396{}
397
398static inline void __fsnotify_update_dcache_flags(struct dentry *dentry)
399{}
400
401static inline void __fsnotify_d_instantiate(struct dentry *dentry, struct inode *inode)
402{}
403
404static inline u32 fsnotify_get_cookie(void)
405{
406 return 0;
407}
408
409static inline void fsnotify_unmount_inodes(struct list_head *list)
410{}
411
412#endif
413
414#endif
415
416#endif
417