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