1#ifndef _LINUX_FS_NOTIFY_H
2#define _LINUX_FS_NOTIFY_H
3
4
5
6
7
8
9
10
11
12
13
14#include <linux/dnotify.h>
15#include <linux/inotify.h>
16#include <linux/audit.h>
17
18
19
20
21
22static inline void fsnotify_d_instantiate(struct dentry *entry,
23 struct inode *inode)
24{
25 inotify_d_instantiate(entry, inode);
26}
27
28
29
30
31
32static inline void fsnotify_d_move(struct dentry *entry)
33{
34 inotify_d_move(entry);
35}
36
37
38
39
40static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir,
41 const char *old_name, const char *new_name,
42 int isdir, struct inode *target, struct dentry *moved)
43{
44 struct inode *source = moved->d_inode;
45 u32 cookie = inotify_get_cookie();
46
47 if (old_dir == new_dir)
48 inode_dir_notify(old_dir, DN_RENAME);
49 else {
50 inode_dir_notify(old_dir, DN_DELETE);
51 inode_dir_notify(new_dir, DN_CREATE);
52 }
53
54 if (isdir)
55 isdir = IN_ISDIR;
56 inotify_inode_queue_event(old_dir, IN_MOVED_FROM|isdir,cookie,old_name,
57 source);
58 inotify_inode_queue_event(new_dir, IN_MOVED_TO|isdir, cookie, new_name,
59 source);
60
61 if (target) {
62 inotify_inode_queue_event(target, IN_DELETE_SELF, 0, NULL, NULL);
63 inotify_inode_is_dead(target);
64 }
65
66 if (source) {
67 inotify_inode_queue_event(source, IN_MOVE_SELF, 0, NULL, NULL);
68 }
69 audit_inode_child(new_name, moved, new_dir);
70}
71
72
73
74
75static inline void fsnotify_nameremove(struct dentry *dentry, int isdir)
76{
77 if (isdir)
78 isdir = IN_ISDIR;
79 dnotify_parent(dentry, DN_DELETE);
80 inotify_dentry_parent_queue_event(dentry, IN_DELETE|isdir, 0, dentry->d_name.name);
81}
82
83
84
85
86static inline void fsnotify_inoderemove(struct inode *inode)
87{
88 inotify_inode_queue_event(inode, IN_DELETE_SELF, 0, NULL, NULL);
89 inotify_inode_is_dead(inode);
90}
91
92
93
94
95static inline void fsnotify_link_count(struct inode *inode)
96{
97 inotify_inode_queue_event(inode, IN_ATTRIB, 0, NULL, NULL);
98}
99
100
101
102
103static inline void fsnotify_create(struct inode *inode, struct dentry *dentry)
104{
105 inode_dir_notify(inode, DN_CREATE);
106 inotify_inode_queue_event(inode, IN_CREATE, 0, dentry->d_name.name,
107 dentry->d_inode);
108 audit_inode_child(dentry->d_name.name, dentry, inode);
109}
110
111
112
113
114
115
116static inline void fsnotify_link(struct inode *dir, struct inode *inode, struct dentry *new_dentry)
117{
118 inode_dir_notify(dir, DN_CREATE);
119 inotify_inode_queue_event(dir, IN_CREATE, 0, new_dentry->d_name.name,
120 inode);
121 fsnotify_link_count(inode);
122 audit_inode_child(new_dentry->d_name.name, new_dentry, dir);
123}
124
125
126
127
128static inline void fsnotify_mkdir(struct inode *inode, struct dentry *dentry)
129{
130 inode_dir_notify(inode, DN_CREATE);
131 inotify_inode_queue_event(inode, IN_CREATE | IN_ISDIR, 0,
132 dentry->d_name.name, dentry->d_inode);
133 audit_inode_child(dentry->d_name.name, dentry, inode);
134}
135
136
137
138
139static inline void fsnotify_access(struct dentry *dentry)
140{
141 struct inode *inode = dentry->d_inode;
142 u32 mask = IN_ACCESS;
143
144 if (S_ISDIR(inode->i_mode))
145 mask |= IN_ISDIR;
146
147 dnotify_parent(dentry, DN_ACCESS);
148 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
149 inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
150}
151
152
153
154
155static inline void fsnotify_modify(struct dentry *dentry)
156{
157 struct inode *inode = dentry->d_inode;
158 u32 mask = IN_MODIFY;
159
160 if (S_ISDIR(inode->i_mode))
161 mask |= IN_ISDIR;
162
163 dnotify_parent(dentry, DN_MODIFY);
164 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
165 inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
166}
167
168
169
170
171static inline void fsnotify_open(struct dentry *dentry)
172{
173 struct inode *inode = dentry->d_inode;
174 u32 mask = IN_OPEN;
175
176 if (S_ISDIR(inode->i_mode))
177 mask |= IN_ISDIR;
178
179 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
180 inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
181}
182
183
184
185
186static inline void fsnotify_close(struct file *file)
187{
188 struct dentry *dentry = file->f_path.dentry;
189 struct inode *inode = dentry->d_inode;
190 const char *name = dentry->d_name.name;
191 mode_t mode = file->f_mode;
192 u32 mask = (mode & FMODE_WRITE) ? IN_CLOSE_WRITE : IN_CLOSE_NOWRITE;
193
194 if (S_ISDIR(inode->i_mode))
195 mask |= IN_ISDIR;
196
197 inotify_dentry_parent_queue_event(dentry, mask, 0, name);
198 inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
199}
200
201
202
203
204static inline void fsnotify_xattr(struct dentry *dentry)
205{
206 struct inode *inode = dentry->d_inode;
207 u32 mask = IN_ATTRIB;
208
209 if (S_ISDIR(inode->i_mode))
210 mask |= IN_ISDIR;
211
212 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
213 inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
214}
215
216
217
218
219
220static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
221{
222 struct inode *inode = dentry->d_inode;
223 int dn_mask = 0;
224 u32 in_mask = 0;
225
226 if (ia_valid & ATTR_UID) {
227 in_mask |= IN_ATTRIB;
228 dn_mask |= DN_ATTRIB;
229 }
230 if (ia_valid & ATTR_GID) {
231 in_mask |= IN_ATTRIB;
232 dn_mask |= DN_ATTRIB;
233 }
234 if (ia_valid & ATTR_SIZE) {
235 in_mask |= IN_MODIFY;
236 dn_mask |= DN_MODIFY;
237 }
238
239 if ((ia_valid & (ATTR_ATIME | ATTR_MTIME)) == (ATTR_ATIME | ATTR_MTIME))
240 {
241 in_mask |= IN_ATTRIB;
242 dn_mask |= DN_ATTRIB;
243 } else if (ia_valid & ATTR_ATIME) {
244 in_mask |= IN_ACCESS;
245 dn_mask |= DN_ACCESS;
246 } else if (ia_valid & ATTR_MTIME) {
247 in_mask |= IN_MODIFY;
248 dn_mask |= DN_MODIFY;
249 }
250 if (ia_valid & ATTR_MODE) {
251 in_mask |= IN_ATTRIB;
252 dn_mask |= DN_ATTRIB;
253 }
254
255 if (dn_mask)
256 dnotify_parent(dentry, dn_mask);
257 if (in_mask) {
258 if (S_ISDIR(inode->i_mode))
259 in_mask |= IN_ISDIR;
260 inotify_inode_queue_event(inode, in_mask, 0, NULL, NULL);
261 inotify_dentry_parent_queue_event(dentry, in_mask, 0,
262 dentry->d_name.name);
263 }
264}
265
266#ifdef CONFIG_INOTIFY
267
268
269
270
271static inline const char *fsnotify_oldname_init(const char *name)
272{
273 return kstrdup(name, GFP_KERNEL);
274}
275
276
277
278
279static inline void fsnotify_oldname_free(const char *old_name)
280{
281 kfree(old_name);
282}
283
284#else
285
286static inline const char *fsnotify_oldname_init(const char *name)
287{
288 return NULL;
289}
290
291static inline void fsnotify_oldname_free(const char *old_name)
292{
293}
294
295#endif
296
297#endif
298