fanotify: use merge argument to determine actual event added to queue
[deliverable/linux.git] / include / linux / fsnotify.h
CommitLineData
0eeca283
RL
1#ifndef _LINUX_FS_NOTIFY_H
2#define _LINUX_FS_NOTIFY_H
3
4/*
5 * include/linux/fsnotify.h - generic hooks for filesystem notification, to
6 * reduce in-source duplication from both dnotify and inotify.
7 *
8 * We don't compile any of this away in some complicated menagerie of ifdefs.
9 * Instead, we rely on the code inside to optimize away as needed.
10 *
11 * (C) Copyright 2005 Robert Love
12 */
13
90586523 14#include <linux/fsnotify_backend.h>
73241ccc 15#include <linux/audit.h>
5a0e3ad6 16#include <linux/slab.h>
0eeca283 17
c32ccd87
NP
18/*
19 * fsnotify_d_instantiate - instantiate a dentry for inode
20 * Called with dcache_lock held.
21 */
e61ce867
EP
22static inline void fsnotify_d_instantiate(struct dentry *dentry,
23 struct inode *inode)
c32ccd87 24{
e61ce867 25 __fsnotify_d_instantiate(dentry, inode);
c32ccd87
NP
26}
27
c28f7e56 28/* Notify this dentry's parent about a child's events. */
72acc854 29static inline void fsnotify_parent(struct path *path, struct dentry *dentry, __u32 mask)
c28f7e56 30{
72acc854
AG
31 if (!dentry)
32 dentry = path->dentry;
28c60e37 33
72acc854 34 __fsnotify_parent(path, dentry, mask);
c28f7e56
EP
35}
36
c32ccd87 37/*
e61ce867
EP
38 * fsnotify_d_move - dentry has been moved
39 * Called with dcache_lock and dentry->d_lock held.
c32ccd87 40 */
e61ce867 41static inline void fsnotify_d_move(struct dentry *dentry)
c32ccd87 42{
c28f7e56 43 /*
e61ce867
EP
44 * On move we need to update dentry->d_flags to indicate if the new parent
45 * cares about events from this dentry.
c28f7e56 46 */
e61ce867 47 __fsnotify_update_dcache_flags(dentry);
c32ccd87
NP
48}
49
90586523
EP
50/*
51 * fsnotify_link_count - inode's link count changed
52 */
53static inline void fsnotify_link_count(struct inode *inode)
54{
47882c6f 55 fsnotify(inode, FS_ATTRIB, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
90586523
EP
56}
57
0eeca283
RL
58/*
59 * fsnotify_move - file old_name at old_dir was moved to new_name at new_dir
60 */
61static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir,
123df294 62 const char *old_name,
5a190ae6 63 int isdir, struct inode *target, struct dentry *moved)
0eeca283 64{
5a190ae6 65 struct inode *source = moved->d_inode;
47882c6f 66 u32 fs_cookie = fsnotify_get_cookie();
ff52cc21
EP
67 __u32 old_dir_mask = (FS_EVENT_ON_CHILD | FS_MOVED_FROM);
68 __u32 new_dir_mask = (FS_EVENT_ON_CHILD | FS_MOVED_TO);
123df294 69 const char *new_name = moved->d_name.name;
0eeca283 70
ff52cc21
EP
71 if (old_dir == new_dir)
72 old_dir_mask |= FS_DN_RENAME;
0eeca283 73
90586523 74 if (isdir) {
90586523
EP
75 old_dir_mask |= FS_IN_ISDIR;
76 new_dir_mask |= FS_IN_ISDIR;
77 }
78
47882c6f
EP
79 fsnotify(old_dir, old_dir_mask, old_dir, FSNOTIFY_EVENT_INODE, old_name, fs_cookie);
80 fsnotify(new_dir, new_dir_mask, new_dir, FSNOTIFY_EVENT_INODE, new_name, fs_cookie);
90586523 81
2dfc1cae 82 if (target)
90586523 83 fsnotify_link_count(target);
89204c40 84
2dfc1cae 85 if (source)
47882c6f 86 fsnotify(source, FS_MOVE_SELF, moved->d_inode, FSNOTIFY_EVENT_INODE, NULL, 0);
cccc6bba 87 audit_inode_child(moved, new_dir);
0eeca283
RL
88}
89
3be25f49
EP
90/*
91 * fsnotify_inode_delete - and inode is being evicted from cache, clean up is needed
92 */
93static inline void fsnotify_inode_delete(struct inode *inode)
94{
95 __fsnotify_inode_delete(inode);
96}
97
ca9c726e
AG
98/*
99 * fsnotify_vfsmount_delete - a vfsmount is being destroyed, clean up is needed
100 */
101static inline void fsnotify_vfsmount_delete(struct vfsmount *mnt)
102{
103 __fsnotify_vfsmount_delete(mnt);
104}
105
7a91bf7f
JM
106/*
107 * fsnotify_nameremove - a filename was removed from a directory
108 */
109static inline void fsnotify_nameremove(struct dentry *dentry, int isdir)
110{
90586523
EP
111 __u32 mask = FS_DELETE;
112
7a91bf7f 113 if (isdir)
90586523 114 mask |= FS_IN_ISDIR;
c28f7e56 115
28c60e37 116 fsnotify_parent(NULL, dentry, mask);
7a91bf7f
JM
117}
118
119/*
120 * fsnotify_inoderemove - an inode is going away
121 */
122static inline void fsnotify_inoderemove(struct inode *inode)
123{
47882c6f 124 fsnotify(inode, FS_DELETE_SELF, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
3be25f49 125 __fsnotify_inode_delete(inode);
ece95912
JK
126}
127
0eeca283
RL
128/*
129 * fsnotify_create - 'name' was linked in
130 */
f38aa942 131static inline void fsnotify_create(struct inode *inode, struct dentry *dentry)
0eeca283 132{
cccc6bba 133 audit_inode_child(dentry, inode);
90586523 134
47882c6f 135 fsnotify(inode, FS_CREATE, dentry->d_inode, FSNOTIFY_EVENT_INODE, dentry->d_name.name, 0);
0eeca283
RL
136}
137
ece95912
JK
138/*
139 * fsnotify_link - new hardlink in 'inode' directory
140 * Note: We have to pass also the linked inode ptr as some filesystems leave
141 * new_dentry->d_inode NULL and instantiate inode pointer later
142 */
143static inline void fsnotify_link(struct inode *dir, struct inode *inode, struct dentry *new_dentry)
144{
ece95912 145 fsnotify_link_count(inode);
cccc6bba 146 audit_inode_child(new_dentry, dir);
90586523 147
47882c6f 148 fsnotify(dir, FS_CREATE, inode, FSNOTIFY_EVENT_INODE, new_dentry->d_name.name, 0);
ece95912
JK
149}
150
0eeca283
RL
151/*
152 * fsnotify_mkdir - directory 'name' was created
153 */
f38aa942 154static inline void fsnotify_mkdir(struct inode *inode, struct dentry *dentry)
0eeca283 155{
90586523
EP
156 __u32 mask = (FS_CREATE | FS_IN_ISDIR);
157 struct inode *d_inode = dentry->d_inode;
158
cccc6bba 159 audit_inode_child(dentry, inode);
90586523 160
47882c6f 161 fsnotify(inode, mask, d_inode, FSNOTIFY_EVENT_INODE, dentry->d_name.name, 0);
0eeca283
RL
162}
163
164/*
165 * fsnotify_access - file was read
166 */
2a12a9d7 167static inline void fsnotify_access(struct file *file)
0eeca283 168{
72acc854
AG
169 struct path *path = &file->f_path;
170 struct inode *inode = path->dentry->d_inode;
90586523 171 __u32 mask = FS_ACCESS;
0eeca283
RL
172
173 if (S_ISDIR(inode->i_mode))
90586523 174 mask |= FS_IN_ISDIR;
0eeca283 175
ecf081d1
EP
176 if (!(file->f_mode & FMODE_NONOTIFY)) {
177 fsnotify_parent(path, NULL, mask);
178 fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
179 }
0eeca283
RL
180}
181
182/*
183 * fsnotify_modify - file was modified
184 */
2a12a9d7 185static inline void fsnotify_modify(struct file *file)
0eeca283 186{
72acc854
AG
187 struct path *path = &file->f_path;
188 struct inode *inode = path->dentry->d_inode;
90586523 189 __u32 mask = FS_MODIFY;
0eeca283
RL
190
191 if (S_ISDIR(inode->i_mode))
90586523 192 mask |= FS_IN_ISDIR;
0eeca283 193
ecf081d1
EP
194 if (!(file->f_mode & FMODE_NONOTIFY)) {
195 fsnotify_parent(path, NULL, mask);
196 fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
197 }
0eeca283
RL
198}
199
200/*
201 * fsnotify_open - file was opened
202 */
2a12a9d7 203static inline void fsnotify_open(struct file *file)
0eeca283 204{
72acc854
AG
205 struct path *path = &file->f_path;
206 struct inode *inode = path->dentry->d_inode;
90586523 207 __u32 mask = FS_OPEN;
0eeca283
RL
208
209 if (S_ISDIR(inode->i_mode))
90586523 210 mask |= FS_IN_ISDIR;
0eeca283 211
ecf081d1
EP
212 if (!(file->f_mode & FMODE_NONOTIFY)) {
213 fsnotify_parent(path, NULL, mask);
214 fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
215 }
0eeca283
RL
216}
217
218/*
219 * fsnotify_close - file was closed
220 */
221static inline void fsnotify_close(struct file *file)
222{
72acc854 223 struct path *path = &file->f_path;
28c60e37 224 struct inode *inode = file->f_path.dentry->d_inode;
aeb5d727 225 fmode_t mode = file->f_mode;
90586523 226 __u32 mask = (mode & FMODE_WRITE) ? FS_CLOSE_WRITE : FS_CLOSE_NOWRITE;
0eeca283
RL
227
228 if (S_ISDIR(inode->i_mode))
90586523 229 mask |= FS_IN_ISDIR;
0eeca283 230
ecf081d1
EP
231 if (!(file->f_mode & FMODE_NONOTIFY)) {
232 fsnotify_parent(path, NULL, mask);
233 fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
234 }
0eeca283
RL
235}
236
237/*
238 * fsnotify_xattr - extended attributes were changed
239 */
240static inline void fsnotify_xattr(struct dentry *dentry)
241{
242 struct inode *inode = dentry->d_inode;
90586523 243 __u32 mask = FS_ATTRIB;
0eeca283
RL
244
245 if (S_ISDIR(inode->i_mode))
90586523 246 mask |= FS_IN_ISDIR;
0eeca283 247
28c60e37 248 fsnotify_parent(NULL, dentry, mask);
47882c6f 249 fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
0eeca283
RL
250}
251
252/*
253 * fsnotify_change - notify_change event. file was modified and/or metadata
254 * was changed.
255 */
256static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
257{
258 struct inode *inode = dentry->d_inode;
3c5119c0
EP
259 __u32 mask = 0;
260
261 if (ia_valid & ATTR_UID)
262 mask |= FS_ATTRIB;
263 if (ia_valid & ATTR_GID)
264 mask |= FS_ATTRIB;
265 if (ia_valid & ATTR_SIZE)
266 mask |= FS_MODIFY;
0eeca283 267
0eeca283
RL
268 /* both times implies a utime(s) call */
269 if ((ia_valid & (ATTR_ATIME | ATTR_MTIME)) == (ATTR_ATIME | ATTR_MTIME))
3c5119c0
EP
270 mask |= FS_ATTRIB;
271 else if (ia_valid & ATTR_ATIME)
272 mask |= FS_ACCESS;
273 else if (ia_valid & ATTR_MTIME)
274 mask |= FS_MODIFY;
275
276 if (ia_valid & ATTR_MODE)
277 mask |= FS_ATTRIB;
0eeca283 278
3c5119c0 279 if (mask) {
0eeca283 280 if (S_ISDIR(inode->i_mode))
3c5119c0 281 mask |= FS_IN_ISDIR;
28c60e37
EP
282
283 fsnotify_parent(NULL, dentry, mask);
47882c6f 284 fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
0eeca283
RL
285 }
286}
287
2dfc1cae 288#if defined(CONFIG_FSNOTIFY) /* notify helpers */
0eeca283
RL
289
290/*
291 * fsnotify_oldname_init - save off the old filename before we change it
292 */
293static inline const char *fsnotify_oldname_init(const char *name)
294{
295 return kstrdup(name, GFP_KERNEL);
296}
297
298/*
299 * fsnotify_oldname_free - free the name we got from fsnotify_oldname_init
300 */
301static inline void fsnotify_oldname_free(const char *old_name)
302{
303 kfree(old_name);
304}
305
28c60e37 306#else /* CONFIG_FSNOTIFY */
0eeca283
RL
307
308static inline const char *fsnotify_oldname_init(const char *name)
309{
310 return NULL;
311}
312
313static inline void fsnotify_oldname_free(const char *old_name)
314{
315}
316
28c60e37 317#endif /* CONFIG_FSNOTIFY */
0eeca283 318
0eeca283 319#endif /* _LINUX_FS_NOTIFY_H */
This page took 0.665672 seconds and 5 git commands to generate.