Merge branches 'release' and 'menlo' into release
[deliverable/linux.git] / include / linux / fsnotify.h
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
14 #ifdef __KERNEL__
15
16 #include <linux/dnotify.h>
17 #include <linux/inotify.h>
18 #include <linux/audit.h>
19
20 /*
21 * fsnotify_d_instantiate - instantiate a dentry for inode
22 * Called with dcache_lock held.
23 */
24 static inline void fsnotify_d_instantiate(struct dentry *entry,
25 struct inode *inode)
26 {
27 inotify_d_instantiate(entry, inode);
28 }
29
30 /*
31 * fsnotify_d_move - entry has been moved
32 * Called with dcache_lock and entry->d_lock held.
33 */
34 static inline void fsnotify_d_move(struct dentry *entry)
35 {
36 inotify_d_move(entry);
37 }
38
39 /*
40 * fsnotify_move - file old_name at old_dir was moved to new_name at new_dir
41 */
42 static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir,
43 const char *old_name, const char *new_name,
44 int isdir, struct inode *target, struct dentry *moved)
45 {
46 struct inode *source = moved->d_inode;
47 u32 cookie = inotify_get_cookie();
48
49 if (old_dir == new_dir)
50 inode_dir_notify(old_dir, DN_RENAME);
51 else {
52 inode_dir_notify(old_dir, DN_DELETE);
53 inode_dir_notify(new_dir, DN_CREATE);
54 }
55
56 if (isdir)
57 isdir = IN_ISDIR;
58 inotify_inode_queue_event(old_dir, IN_MOVED_FROM|isdir,cookie,old_name,
59 source);
60 inotify_inode_queue_event(new_dir, IN_MOVED_TO|isdir, cookie, new_name,
61 source);
62
63 if (target) {
64 inotify_inode_queue_event(target, IN_DELETE_SELF, 0, NULL, NULL);
65 inotify_inode_is_dead(target);
66 }
67
68 if (source) {
69 inotify_inode_queue_event(source, IN_MOVE_SELF, 0, NULL, NULL);
70 }
71 audit_inode_child(new_name, moved, new_dir);
72 }
73
74 /*
75 * fsnotify_nameremove - a filename was removed from a directory
76 */
77 static inline void fsnotify_nameremove(struct dentry *dentry, int isdir)
78 {
79 if (isdir)
80 isdir = IN_ISDIR;
81 dnotify_parent(dentry, DN_DELETE);
82 inotify_dentry_parent_queue_event(dentry, IN_DELETE|isdir, 0, dentry->d_name.name);
83 }
84
85 /*
86 * fsnotify_inoderemove - an inode is going away
87 */
88 static inline void fsnotify_inoderemove(struct inode *inode)
89 {
90 inotify_inode_queue_event(inode, IN_DELETE_SELF, 0, NULL, NULL);
91 inotify_inode_is_dead(inode);
92 }
93
94 /*
95 * fsnotify_link_count - inode's link count changed
96 */
97 static inline void fsnotify_link_count(struct inode *inode)
98 {
99 inotify_inode_queue_event(inode, IN_ATTRIB, 0, NULL, NULL);
100 }
101
102 /*
103 * fsnotify_create - 'name' was linked in
104 */
105 static inline void fsnotify_create(struct inode *inode, struct dentry *dentry)
106 {
107 inode_dir_notify(inode, DN_CREATE);
108 inotify_inode_queue_event(inode, IN_CREATE, 0, dentry->d_name.name,
109 dentry->d_inode);
110 audit_inode_child(dentry->d_name.name, dentry, inode);
111 }
112
113 /*
114 * fsnotify_link - new hardlink in 'inode' directory
115 * Note: We have to pass also the linked inode ptr as some filesystems leave
116 * new_dentry->d_inode NULL and instantiate inode pointer later
117 */
118 static inline void fsnotify_link(struct inode *dir, struct inode *inode, struct dentry *new_dentry)
119 {
120 inode_dir_notify(dir, DN_CREATE);
121 inotify_inode_queue_event(dir, IN_CREATE, 0, new_dentry->d_name.name,
122 inode);
123 fsnotify_link_count(inode);
124 audit_inode_child(new_dentry->d_name.name, new_dentry, dir);
125 }
126
127 /*
128 * fsnotify_mkdir - directory 'name' was created
129 */
130 static inline void fsnotify_mkdir(struct inode *inode, struct dentry *dentry)
131 {
132 inode_dir_notify(inode, DN_CREATE);
133 inotify_inode_queue_event(inode, IN_CREATE | IN_ISDIR, 0,
134 dentry->d_name.name, dentry->d_inode);
135 audit_inode_child(dentry->d_name.name, dentry, inode);
136 }
137
138 /*
139 * fsnotify_access - file was read
140 */
141 static inline void fsnotify_access(struct dentry *dentry)
142 {
143 struct inode *inode = dentry->d_inode;
144 u32 mask = IN_ACCESS;
145
146 if (S_ISDIR(inode->i_mode))
147 mask |= IN_ISDIR;
148
149 dnotify_parent(dentry, DN_ACCESS);
150 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
151 inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
152 }
153
154 /*
155 * fsnotify_modify - file was modified
156 */
157 static inline void fsnotify_modify(struct dentry *dentry)
158 {
159 struct inode *inode = dentry->d_inode;
160 u32 mask = IN_MODIFY;
161
162 if (S_ISDIR(inode->i_mode))
163 mask |= IN_ISDIR;
164
165 dnotify_parent(dentry, DN_MODIFY);
166 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
167 inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
168 }
169
170 /*
171 * fsnotify_open - file was opened
172 */
173 static inline void fsnotify_open(struct dentry *dentry)
174 {
175 struct inode *inode = dentry->d_inode;
176 u32 mask = IN_OPEN;
177
178 if (S_ISDIR(inode->i_mode))
179 mask |= IN_ISDIR;
180
181 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
182 inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
183 }
184
185 /*
186 * fsnotify_close - file was closed
187 */
188 static inline void fsnotify_close(struct file *file)
189 {
190 struct dentry *dentry = file->f_path.dentry;
191 struct inode *inode = dentry->d_inode;
192 const char *name = dentry->d_name.name;
193 mode_t mode = file->f_mode;
194 u32 mask = (mode & FMODE_WRITE) ? IN_CLOSE_WRITE : IN_CLOSE_NOWRITE;
195
196 if (S_ISDIR(inode->i_mode))
197 mask |= IN_ISDIR;
198
199 inotify_dentry_parent_queue_event(dentry, mask, 0, name);
200 inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
201 }
202
203 /*
204 * fsnotify_xattr - extended attributes were changed
205 */
206 static inline void fsnotify_xattr(struct dentry *dentry)
207 {
208 struct inode *inode = dentry->d_inode;
209 u32 mask = IN_ATTRIB;
210
211 if (S_ISDIR(inode->i_mode))
212 mask |= IN_ISDIR;
213
214 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
215 inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
216 }
217
218 /*
219 * fsnotify_change - notify_change event. file was modified and/or metadata
220 * was changed.
221 */
222 static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
223 {
224 struct inode *inode = dentry->d_inode;
225 int dn_mask = 0;
226 u32 in_mask = 0;
227
228 if (ia_valid & ATTR_UID) {
229 in_mask |= IN_ATTRIB;
230 dn_mask |= DN_ATTRIB;
231 }
232 if (ia_valid & ATTR_GID) {
233 in_mask |= IN_ATTRIB;
234 dn_mask |= DN_ATTRIB;
235 }
236 if (ia_valid & ATTR_SIZE) {
237 in_mask |= IN_MODIFY;
238 dn_mask |= DN_MODIFY;
239 }
240 /* both times implies a utime(s) call */
241 if ((ia_valid & (ATTR_ATIME | ATTR_MTIME)) == (ATTR_ATIME | ATTR_MTIME))
242 {
243 in_mask |= IN_ATTRIB;
244 dn_mask |= DN_ATTRIB;
245 } else if (ia_valid & ATTR_ATIME) {
246 in_mask |= IN_ACCESS;
247 dn_mask |= DN_ACCESS;
248 } else if (ia_valid & ATTR_MTIME) {
249 in_mask |= IN_MODIFY;
250 dn_mask |= DN_MODIFY;
251 }
252 if (ia_valid & ATTR_MODE) {
253 in_mask |= IN_ATTRIB;
254 dn_mask |= DN_ATTRIB;
255 }
256
257 if (dn_mask)
258 dnotify_parent(dentry, dn_mask);
259 if (in_mask) {
260 if (S_ISDIR(inode->i_mode))
261 in_mask |= IN_ISDIR;
262 inotify_inode_queue_event(inode, in_mask, 0, NULL, NULL);
263 inotify_dentry_parent_queue_event(dentry, in_mask, 0,
264 dentry->d_name.name);
265 }
266 }
267
268 #ifdef CONFIG_INOTIFY /* inotify helpers */
269
270 /*
271 * fsnotify_oldname_init - save off the old filename before we change it
272 */
273 static inline const char *fsnotify_oldname_init(const char *name)
274 {
275 return kstrdup(name, GFP_KERNEL);
276 }
277
278 /*
279 * fsnotify_oldname_free - free the name we got from fsnotify_oldname_init
280 */
281 static inline void fsnotify_oldname_free(const char *old_name)
282 {
283 kfree(old_name);
284 }
285
286 #else /* CONFIG_INOTIFY */
287
288 static inline const char *fsnotify_oldname_init(const char *name)
289 {
290 return NULL;
291 }
292
293 static inline void fsnotify_oldname_free(const char *old_name)
294 {
295 }
296
297 #endif /* ! CONFIG_INOTIFY */
298
299 #endif /* __KERNEL__ */
300
301 #endif /* _LINUX_FS_NOTIFY_H */
This page took 0.039426 seconds and 6 git commands to generate.