mm-only debug patch...
[mmotm.git] / include / linux / fsnotify.h
blobc0de28b217c9810365b92ce5e4e4b3a6c118c273
1 #ifndef _LINUX_FS_NOTIFY_H
2 #define _LINUX_FS_NOTIFY_H
4 /*
5 * include/linux/fsnotify.h - generic hooks for filesystem notification, to
6 * reduce in-source duplication from both dnotify and inotify.
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.
11 * (C) Copyright 2005 Robert Love
14 #include <linux/dnotify.h>
15 #include <linux/inotify.h>
16 #include <linux/fsnotify_backend.h>
17 #include <linux/audit.h>
20 * fsnotify_d_instantiate - instantiate a dentry for inode
21 * Called with dcache_lock held.
23 static inline void fsnotify_d_instantiate(struct dentry *entry,
24 struct inode *inode)
26 __fsnotify_d_instantiate(entry, inode);
28 inotify_d_instantiate(entry, inode);
31 /* Notify this dentry's parent about a child's events. */
32 static inline void fsnotify_parent(struct file *file, struct dentry *dentry, __u32 mask)
34 BUG_ON(file && dentry);
36 if (file)
37 dentry = file->f_path.dentry;
39 __fsnotify_parent(file, dentry, mask);
41 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
45 * fsnotify_d_move - entry has been moved
46 * Called with dcache_lock and entry->d_lock held.
48 static inline void fsnotify_d_move(struct dentry *entry)
51 * On move we need to update entry->d_flags to indicate if the new parent
52 * cares about events from this entry.
54 __fsnotify_update_dcache_flags(entry);
56 inotify_d_move(entry);
60 * fsnotify_link_count - inode's link count changed
62 static inline void fsnotify_link_count(struct inode *inode)
64 inotify_inode_queue_event(inode, IN_ATTRIB, 0, NULL, NULL);
66 fsnotify(inode, FS_ATTRIB, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
70 * fsnotify_move - file old_name at old_dir was moved to new_name at new_dir
72 static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir,
73 const char *old_name, const char *new_name,
74 int isdir, struct inode *target, struct dentry *moved)
76 struct inode *source = moved->d_inode;
77 u32 in_cookie = inotify_get_cookie();
78 u32 fs_cookie = fsnotify_get_cookie();
79 __u32 old_dir_mask = (FS_EVENT_ON_CHILD | FS_MOVED_FROM);
80 __u32 new_dir_mask = (FS_EVENT_ON_CHILD | FS_MOVED_TO);
82 if (old_dir == new_dir)
83 old_dir_mask |= FS_DN_RENAME;
85 if (isdir) {
86 isdir = IN_ISDIR;
87 old_dir_mask |= FS_IN_ISDIR;
88 new_dir_mask |= FS_IN_ISDIR;
91 inotify_inode_queue_event(old_dir, IN_MOVED_FROM|isdir, in_cookie, old_name,
92 source);
93 inotify_inode_queue_event(new_dir, IN_MOVED_TO|isdir, in_cookie, new_name,
94 source);
96 fsnotify(old_dir, old_dir_mask, old_dir, FSNOTIFY_EVENT_INODE, old_name, fs_cookie);
97 fsnotify(new_dir, new_dir_mask, new_dir, FSNOTIFY_EVENT_INODE, new_name, fs_cookie);
99 if (target) {
100 inotify_inode_queue_event(target, IN_DELETE_SELF, 0, NULL, NULL);
101 inotify_inode_is_dead(target);
103 /* this is really a link_count change not a removal */
104 fsnotify_link_count(target);
107 if (source) {
108 inotify_inode_queue_event(source, IN_MOVE_SELF, 0, NULL, NULL);
109 fsnotify(source, FS_MOVE_SELF, moved->d_inode, FSNOTIFY_EVENT_INODE, NULL, 0);
111 audit_inode_child(new_name, moved, new_dir);
115 * fsnotify_inode_delete - and inode is being evicted from cache, clean up is needed
117 static inline void fsnotify_inode_delete(struct inode *inode)
119 __fsnotify_inode_delete(inode);
123 * fsnotify_nameremove - a filename was removed from a directory
125 static inline void fsnotify_nameremove(struct dentry *dentry, int isdir)
127 __u32 mask = FS_DELETE;
129 if (isdir)
130 mask |= FS_IN_ISDIR;
132 fsnotify_parent(NULL, dentry, mask);
136 * fsnotify_inoderemove - an inode is going away
138 static inline void fsnotify_inoderemove(struct inode *inode)
140 inotify_inode_queue_event(inode, IN_DELETE_SELF, 0, NULL, NULL);
141 inotify_inode_is_dead(inode);
143 fsnotify(inode, FS_DELETE_SELF, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
144 __fsnotify_inode_delete(inode);
148 * fsnotify_create - 'name' was linked in
150 static inline void fsnotify_create(struct inode *inode, struct dentry *dentry)
152 inotify_inode_queue_event(inode, IN_CREATE, 0, dentry->d_name.name,
153 dentry->d_inode);
154 audit_inode_child(dentry->d_name.name, dentry, inode);
156 fsnotify(inode, FS_CREATE, dentry->d_inode, FSNOTIFY_EVENT_INODE, dentry->d_name.name, 0);
160 * fsnotify_link - new hardlink in 'inode' directory
161 * Note: We have to pass also the linked inode ptr as some filesystems leave
162 * new_dentry->d_inode NULL and instantiate inode pointer later
164 static inline void fsnotify_link(struct inode *dir, struct inode *inode, struct dentry *new_dentry)
166 inotify_inode_queue_event(dir, IN_CREATE, 0, new_dentry->d_name.name,
167 inode);
168 fsnotify_link_count(inode);
169 audit_inode_child(new_dentry->d_name.name, new_dentry, dir);
171 fsnotify(dir, FS_CREATE, inode, FSNOTIFY_EVENT_INODE, new_dentry->d_name.name, 0);
175 * fsnotify_mkdir - directory 'name' was created
177 static inline void fsnotify_mkdir(struct inode *inode, struct dentry *dentry)
179 __u32 mask = (FS_CREATE | FS_IN_ISDIR);
180 struct inode *d_inode = dentry->d_inode;
182 inotify_inode_queue_event(inode, mask, 0, dentry->d_name.name, d_inode);
183 audit_inode_child(dentry->d_name.name, dentry, inode);
185 fsnotify(inode, mask, d_inode, FSNOTIFY_EVENT_INODE, dentry->d_name.name, 0);
189 * fsnotify_access - file was read
191 static inline void fsnotify_access(struct file *file)
193 struct inode *inode = file->f_path.dentry->d_inode;
194 __u32 mask = FS_ACCESS;
196 if (S_ISDIR(inode->i_mode))
197 mask |= FS_IN_ISDIR;
199 inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
201 fsnotify_parent(file, NULL, mask);
202 fsnotify(inode, mask, file, FSNOTIFY_EVENT_FILE, NULL, 0);
206 * fsnotify_modify - file was modified
208 static inline void fsnotify_modify(struct file *file)
210 struct inode *inode = file->f_path.dentry->d_inode;
211 __u32 mask = FS_MODIFY;
213 if (S_ISDIR(inode->i_mode))
214 mask |= FS_IN_ISDIR;
216 inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
218 fsnotify_parent(file, NULL, mask);
219 fsnotify(inode, mask, file, FSNOTIFY_EVENT_FILE, NULL, 0);
223 * fsnotify_open - file was opened
225 static inline void fsnotify_open(struct file *file)
227 struct inode *inode = file->f_path.dentry->d_inode;
228 __u32 mask = FS_OPEN;
230 if (S_ISDIR(inode->i_mode))
231 mask |= FS_IN_ISDIR;
233 inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
235 fsnotify_parent(file, NULL, mask);
236 fsnotify(inode, mask, file, FSNOTIFY_EVENT_FILE, NULL, 0);
240 * fsnotify_close - file was closed
242 static inline void fsnotify_close(struct file *file)
244 struct inode *inode = file->f_path.dentry->d_inode;
245 fmode_t mode = file->f_mode;
246 __u32 mask = (mode & FMODE_WRITE) ? FS_CLOSE_WRITE : FS_CLOSE_NOWRITE;
248 if (S_ISDIR(inode->i_mode))
249 mask |= FS_IN_ISDIR;
251 inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
253 fsnotify_parent(file, NULL, mask);
254 fsnotify(inode, mask, file, FSNOTIFY_EVENT_FILE, NULL, 0);
258 * fsnotify_xattr - extended attributes were changed
260 static inline void fsnotify_xattr(struct dentry *dentry)
262 struct inode *inode = dentry->d_inode;
263 __u32 mask = FS_ATTRIB;
265 if (S_ISDIR(inode->i_mode))
266 mask |= FS_IN_ISDIR;
268 inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
270 fsnotify_parent(NULL, dentry, mask);
271 fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
275 * fsnotify_change - notify_change event. file was modified and/or metadata
276 * was changed.
278 static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
280 struct inode *inode = dentry->d_inode;
281 __u32 mask = 0;
283 if (ia_valid & ATTR_UID)
284 mask |= FS_ATTRIB;
285 if (ia_valid & ATTR_GID)
286 mask |= FS_ATTRIB;
287 if (ia_valid & ATTR_SIZE)
288 mask |= FS_MODIFY;
290 /* both times implies a utime(s) call */
291 if ((ia_valid & (ATTR_ATIME | ATTR_MTIME)) == (ATTR_ATIME | ATTR_MTIME))
292 mask |= FS_ATTRIB;
293 else if (ia_valid & ATTR_ATIME)
294 mask |= FS_ACCESS;
295 else if (ia_valid & ATTR_MTIME)
296 mask |= FS_MODIFY;
298 if (ia_valid & ATTR_MODE)
299 mask |= FS_ATTRIB;
301 if (mask) {
302 if (S_ISDIR(inode->i_mode))
303 mask |= FS_IN_ISDIR;
304 inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
306 fsnotify_parent(NULL, dentry, mask);
307 fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
311 #if defined(CONFIG_INOTIFY) || defined(CONFIG_FSNOTIFY) /* notify helpers */
314 * fsnotify_oldname_init - save off the old filename before we change it
316 static inline const char *fsnotify_oldname_init(const char *name)
318 return kstrdup(name, GFP_KERNEL);
322 * fsnotify_oldname_free - free the name we got from fsnotify_oldname_init
324 static inline void fsnotify_oldname_free(const char *old_name)
326 kfree(old_name);
329 #else /* CONFIG_INOTIFY || CONFIG_FSNOTIFY */
331 static inline const char *fsnotify_oldname_init(const char *name)
333 return NULL;
336 static inline void fsnotify_oldname_free(const char *old_name)
340 #endif /* ! CONFIG_INOTIFY */
342 #endif /* _LINUX_FS_NOTIFY_H */