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 *dentry,
25 __fsnotify_d_instantiate(dentry, inode);
28 /* Notify this dentry's parent about a child's events. */
29 static inline void fsnotify_parent(struct path *path, struct dentry *dentry, __u32 mask)
32 dentry = path->dentry;
34 __fsnotify_parent(path, dentry, mask);
38 * fsnotify_d_move - dentry has been moved
39 * Called with dcache_lock and dentry->d_lock held.
41 static inline void fsnotify_d_move(struct dentry *dentry)
44 * On move we need to update dentry->d_flags to indicate if the new parent
45 * cares about events from this dentry.
47 __fsnotify_update_dcache_flags(dentry);
51 * fsnotify_link_count - inode's link count changed
53 static inline void fsnotify_link_count(struct inode *inode)
55 fsnotify(inode, FS_ATTRIB, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
59 * fsnotify_move - file old_name at old_dir was moved to new_name at new_dir
61 static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir,
62 const unsigned char *old_name,
63 int isdir, struct inode *target, struct dentry *moved)
65 struct inode *source = moved->d_inode;
66 u32 fs_cookie = fsnotify_get_cookie();
67 __u32 old_dir_mask = (FS_EVENT_ON_CHILD | FS_MOVED_FROM);
68 __u32 new_dir_mask = (FS_EVENT_ON_CHILD | FS_MOVED_TO);
69 const unsigned char *new_name = moved->d_name.name;
71 if (old_dir == new_dir)
72 old_dir_mask |= FS_DN_RENAME;
75 old_dir_mask |= FS_IN_ISDIR;
76 new_dir_mask |= FS_IN_ISDIR;
79 fsnotify(old_dir, old_dir_mask, old_dir, FSNOTIFY_EVENT_INODE, old_name, fs_cookie);
80 fsnotify(new_dir, new_dir_mask, new_dir, FSNOTIFY_EVENT_INODE, new_name, fs_cookie);
83 fsnotify_link_count(target);
86 fsnotify(source, FS_MOVE_SELF, moved->d_inode, FSNOTIFY_EVENT_INODE, NULL, 0);
87 audit_inode_child(moved, new_dir);
91 * fsnotify_inode_delete - and inode is being evicted from cache, clean up is needed
93 static inline void fsnotify_inode_delete(struct inode *inode)
95 __fsnotify_inode_delete(inode);
99 * fsnotify_vfsmount_delete - a vfsmount is being destroyed, clean up is needed
101 static inline void fsnotify_vfsmount_delete(struct vfsmount *mnt)
103 __fsnotify_vfsmount_delete(mnt);
107 * fsnotify_nameremove - a filename was removed from a directory
109 static inline void fsnotify_nameremove(struct dentry *dentry, int isdir)
111 __u32 mask = FS_DELETE;
116 fsnotify_parent(NULL, dentry, mask);
120 * fsnotify_inoderemove - an inode is going away
122 static inline void fsnotify_inoderemove(struct inode *inode)
124 fsnotify(inode, FS_DELETE_SELF, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
125 __fsnotify_inode_delete(inode);
129 * fsnotify_create - 'name' was linked in
131 static inline void fsnotify_create(struct inode *inode, struct dentry *dentry)
133 audit_inode_child(dentry, inode);
135 fsnotify(inode, FS_CREATE, dentry->d_inode, FSNOTIFY_EVENT_INODE, dentry->d_name.name, 0);
139 * fsnotify_link - new hardlink in 'inode' directory
140 * Note: We have to pass also the linked inode ptr as some filesystems leave
141 * new_dentry->d_inode NULL and instantiate inode pointer later
143 static inline void fsnotify_link(struct inode *dir, struct inode *inode, struct dentry *new_dentry)
145 fsnotify_link_count(inode);
146 audit_inode_child(new_dentry, dir);
148 fsnotify(dir, FS_CREATE, inode, FSNOTIFY_EVENT_INODE, new_dentry->d_name.name, 0);
152 * fsnotify_mkdir - directory 'name' was created
154 static inline void fsnotify_mkdir(struct inode *inode, struct dentry *dentry)
156 __u32 mask = (FS_CREATE | FS_IN_ISDIR);
157 struct inode *d_inode = dentry->d_inode;
159 audit_inode_child(dentry, inode);
161 fsnotify(inode, mask, d_inode, FSNOTIFY_EVENT_INODE, dentry->d_name.name, 0);
165 * fsnotify_access - file was read
167 static inline void fsnotify_access(struct file *file)
169 struct path *path = &file->f_path;
170 struct inode *inode = path->dentry->d_inode;
171 __u32 mask = FS_ACCESS;
173 if (S_ISDIR(inode->i_mode))
176 if (!(file->f_mode & FMODE_NONOTIFY)) {
177 fsnotify_parent(path, NULL, mask);
178 fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
183 * fsnotify_modify - file was modified
185 static inline void fsnotify_modify(struct file *file)
187 struct path *path = &file->f_path;
188 struct inode *inode = path->dentry->d_inode;
189 __u32 mask = FS_MODIFY;
191 if (S_ISDIR(inode->i_mode))
194 if (!(file->f_mode & FMODE_NONOTIFY)) {
195 fsnotify_parent(path, NULL, mask);
196 fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
201 * fsnotify_open - file was opened
203 static inline void fsnotify_open(struct file *file)
205 struct path *path = &file->f_path;
206 struct inode *inode = path->dentry->d_inode;
207 __u32 mask = FS_OPEN;
209 if (S_ISDIR(inode->i_mode))
212 if (!(file->f_mode & FMODE_NONOTIFY)) {
213 fsnotify_parent(path, NULL, mask);
214 fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
219 * fsnotify_close - file was closed
221 static inline void fsnotify_close(struct file *file)
223 struct path *path = &file->f_path;
224 struct inode *inode = file->f_path.dentry->d_inode;
225 fmode_t mode = file->f_mode;
226 __u32 mask = (mode & FMODE_WRITE) ? FS_CLOSE_WRITE : FS_CLOSE_NOWRITE;
228 if (S_ISDIR(inode->i_mode))
231 if (!(file->f_mode & FMODE_NONOTIFY)) {
232 fsnotify_parent(path, NULL, mask);
233 fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
238 * fsnotify_xattr - extended attributes were changed
240 static inline void fsnotify_xattr(struct dentry *dentry)
242 struct inode *inode = dentry->d_inode;
243 __u32 mask = FS_ATTRIB;
245 if (S_ISDIR(inode->i_mode))
248 fsnotify_parent(NULL, dentry, mask);
249 fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
253 * fsnotify_change - notify_change event. file was modified and/or metadata
256 static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
258 struct inode *inode = dentry->d_inode;
261 if (ia_valid & ATTR_UID)
263 if (ia_valid & ATTR_GID)
265 if (ia_valid & ATTR_SIZE)
268 /* both times implies a utime(s) call */
269 if ((ia_valid & (ATTR_ATIME | ATTR_MTIME)) == (ATTR_ATIME | ATTR_MTIME))
271 else if (ia_valid & ATTR_ATIME)
273 else if (ia_valid & ATTR_MTIME)
276 if (ia_valid & ATTR_MODE)
280 if (S_ISDIR(inode->i_mode))
283 fsnotify_parent(NULL, dentry, mask);
284 fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
288 #if defined(CONFIG_FSNOTIFY) /* notify helpers */
291 * fsnotify_oldname_init - save off the old filename before we change it
293 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
295 return kstrdup(name, GFP_KERNEL);
299 * fsnotify_oldname_free - free the name we got from fsnotify_oldname_init
301 static inline void fsnotify_oldname_free(const unsigned char *old_name)
306 #else /* CONFIG_FSNOTIFY */
308 static inline const char *fsnotify_oldname_init(const unsigned char *name)
313 static inline void fsnotify_oldname_free(const unsigned char *old_name)
317 #endif /* CONFIG_FSNOTIFY */
319 #endif /* _LINUX_FS_NOTIFY_H */