1 #ifndef _LINUX_FS_NOTIFY_H
2 #define _LINUX_FS_NOTIFY_H
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/fsnotify_backend.h>
15 #include <linux/audit.h>
16 #include <linux/slab.h>
19 * fsnotify_d_instantiate - instantiate a dentry for inode
20 * Called with dcache_lock held.
22 static inline void fsnotify_d_instantiate(struct dentry *entry,
25 __fsnotify_d_instantiate(entry, inode);
28 /* Notify this dentry's parent about a child's events. */
29 static inline void fsnotify_parent(struct dentry *dentry, __u32 mask)
31 __fsnotify_parent(dentry, mask);
35 * fsnotify_d_move - entry has been moved
36 * Called with dcache_lock and entry->d_lock held.
38 static inline void fsnotify_d_move(struct dentry *entry)
41 * On move we need to update entry->d_flags to indicate if the new parent
42 * cares about events from this entry.
44 __fsnotify_update_dcache_flags(entry);
48 * fsnotify_link_count - inode's link count changed
50 static inline void fsnotify_link_count(struct inode *inode)
52 fsnotify(inode, FS_ATTRIB, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
56 * fsnotify_move - file old_name at old_dir was moved to new_name at new_dir
58 static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir,
60 int isdir, struct inode *target, struct dentry *moved)
62 struct inode *source = moved->d_inode;
63 u32 fs_cookie = fsnotify_get_cookie();
64 __u32 old_dir_mask = (FS_EVENT_ON_CHILD | FS_MOVED_FROM);
65 __u32 new_dir_mask = (FS_EVENT_ON_CHILD | FS_MOVED_TO);
66 const char *new_name = moved->d_name.name;
68 if (old_dir == new_dir)
69 old_dir_mask |= FS_DN_RENAME;
72 old_dir_mask |= FS_IN_ISDIR;
73 new_dir_mask |= FS_IN_ISDIR;
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);
80 fsnotify_link_count(target);
83 fsnotify(source, FS_MOVE_SELF, moved->d_inode, FSNOTIFY_EVENT_INODE, NULL, 0);
84 audit_inode_child(moved, new_dir);
88 * fsnotify_inode_delete - and inode is being evicted from cache, clean up is needed
90 static inline void fsnotify_inode_delete(struct inode *inode)
92 __fsnotify_inode_delete(inode);
96 * fsnotify_nameremove - a filename was removed from a directory
98 static inline void fsnotify_nameremove(struct dentry *dentry, int isdir)
100 __u32 mask = FS_DELETE;
105 fsnotify_parent(dentry, mask);
109 * fsnotify_inoderemove - an inode is going away
111 static inline void fsnotify_inoderemove(struct inode *inode)
113 fsnotify(inode, FS_DELETE_SELF, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
114 __fsnotify_inode_delete(inode);
118 * fsnotify_create - 'name' was linked in
120 static inline void fsnotify_create(struct inode *inode, struct dentry *dentry)
122 audit_inode_child(dentry, inode);
124 fsnotify(inode, FS_CREATE, dentry->d_inode, FSNOTIFY_EVENT_INODE, dentry->d_name.name, 0);
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
132 static inline void fsnotify_link(struct inode *dir, struct inode *inode, struct dentry *new_dentry)
134 fsnotify_link_count(inode);
135 audit_inode_child(new_dentry, dir);
137 fsnotify(dir, FS_CREATE, inode, FSNOTIFY_EVENT_INODE, new_dentry->d_name.name, 0);
141 * fsnotify_mkdir - directory 'name' was created
143 static inline void fsnotify_mkdir(struct inode *inode, struct dentry *dentry)
145 __u32 mask = (FS_CREATE | FS_IN_ISDIR);
146 struct inode *d_inode = dentry->d_inode;
148 audit_inode_child(dentry, inode);
150 fsnotify(inode, mask, d_inode, FSNOTIFY_EVENT_INODE, dentry->d_name.name, 0);
154 * fsnotify_access - file was read
156 static inline void fsnotify_access(struct file *file)
158 struct dentry *dentry = file->f_path.dentry;
159 struct inode *inode = dentry->d_inode;
160 __u32 mask = FS_ACCESS;
162 if (S_ISDIR(inode->i_mode))
165 fsnotify_parent(dentry, mask);
166 fsnotify(inode, mask, file, FSNOTIFY_EVENT_FILE, NULL, 0);
170 * fsnotify_modify - file was modified
172 static inline void fsnotify_modify(struct file *file)
174 struct dentry *dentry = file->f_path.dentry;
175 struct inode *inode = dentry->d_inode;
176 __u32 mask = FS_MODIFY;
178 if (S_ISDIR(inode->i_mode))
181 fsnotify_parent(dentry, mask);
182 fsnotify(inode, mask, file, FSNOTIFY_EVENT_FILE, NULL, 0);
186 * fsnotify_open - file was opened
188 static inline void fsnotify_open(struct file *file)
190 struct dentry *dentry = file->f_path.dentry;
191 struct inode *inode = dentry->d_inode;
192 __u32 mask = FS_OPEN;
194 if (S_ISDIR(inode->i_mode))
197 fsnotify_parent(dentry, mask);
198 fsnotify(inode, mask, file, FSNOTIFY_EVENT_FILE, NULL, 0);
202 * fsnotify_close - file was closed
204 static inline void fsnotify_close(struct file *file)
206 struct dentry *dentry = file->f_path.dentry;
207 struct inode *inode = dentry->d_inode;
208 fmode_t mode = file->f_mode;
209 __u32 mask = (mode & FMODE_WRITE) ? FS_CLOSE_WRITE : FS_CLOSE_NOWRITE;
211 if (S_ISDIR(inode->i_mode))
214 fsnotify_parent(dentry, mask);
215 fsnotify(inode, mask, file, FSNOTIFY_EVENT_FILE, NULL, 0);
219 * fsnotify_xattr - extended attributes were changed
221 static inline void fsnotify_xattr(struct dentry *dentry)
223 struct inode *inode = dentry->d_inode;
224 __u32 mask = FS_ATTRIB;
226 if (S_ISDIR(inode->i_mode))
229 fsnotify_parent(dentry, mask);
230 fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
234 * fsnotify_change - notify_change event. file was modified and/or metadata
237 static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
239 struct inode *inode = dentry->d_inode;
242 if (ia_valid & ATTR_UID)
244 if (ia_valid & ATTR_GID)
246 if (ia_valid & ATTR_SIZE)
249 /* both times implies a utime(s) call */
250 if ((ia_valid & (ATTR_ATIME | ATTR_MTIME)) == (ATTR_ATIME | ATTR_MTIME))
252 else if (ia_valid & ATTR_ATIME)
254 else if (ia_valid & ATTR_MTIME)
257 if (ia_valid & ATTR_MODE)
261 if (S_ISDIR(inode->i_mode))
263 fsnotify_parent(dentry, mask);
264 fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
268 #if defined(CONFIG_FSNOTIFY) /* notify helpers */
271 * fsnotify_oldname_init - save off the old filename before we change it
273 static inline const char *fsnotify_oldname_init(const char *name)
275 return kstrdup(name, GFP_KERNEL);
279 * fsnotify_oldname_free - free the name we got from fsnotify_oldname_init
281 static inline void fsnotify_oldname_free(const char *old_name)
286 #else /* CONFIG_INOTIFY || CONFIG_FSNOTIFY */
288 static inline const char *fsnotify_oldname_init(const char *name)
293 static inline void fsnotify_oldname_free(const char *old_name)
297 #endif /* ! CONFIG_INOTIFY */
299 #endif /* _LINUX_FS_NOTIFY_H */