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