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
16 #include <linux/dnotify.h>
17 #include <linux/inotify.h>
20 * fsnotify_move - file old_name at old_dir was moved to new_name at new_dir
22 static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir,
23 const char *old_name, const char *new_name,
24 int isdir, struct inode *target)
26 u32 cookie = inotify_get_cookie();
28 if (old_dir == new_dir)
29 inode_dir_notify(old_dir, DN_RENAME);
31 inode_dir_notify(old_dir, DN_DELETE);
32 inode_dir_notify(new_dir, DN_CREATE);
37 inotify_inode_queue_event(old_dir, IN_MOVED_FROM|isdir,cookie,old_name);
38 inotify_inode_queue_event(new_dir, IN_MOVED_TO|isdir, cookie, new_name);
41 inotify_inode_queue_event(target, IN_DELETE_SELF, 0, NULL);
42 inotify_inode_is_dead(target);
47 * fsnotify_unlink - file was unlinked
49 static inline void fsnotify_unlink(struct dentry *dentry, struct inode *dir)
51 struct inode *inode = dentry->d_inode;
53 inode_dir_notify(dir, DN_DELETE);
54 inotify_inode_queue_event(dir, IN_DELETE, 0, dentry->d_name.name);
55 inotify_inode_queue_event(inode, IN_DELETE_SELF, 0, NULL);
57 inotify_inode_is_dead(inode);
61 * fsnotify_rmdir - directory was removed
63 static inline void fsnotify_rmdir(struct dentry *dentry, struct inode *inode,
66 inode_dir_notify(dir, DN_DELETE);
67 inotify_inode_queue_event(dir,IN_DELETE|IN_ISDIR,0,dentry->d_name.name);
68 inotify_inode_queue_event(inode, IN_DELETE_SELF | IN_ISDIR, 0, NULL);
69 inotify_inode_is_dead(inode);
73 * fsnotify_create - 'name' was linked in
75 static inline void fsnotify_create(struct inode *inode, const char *name)
77 inode_dir_notify(inode, DN_CREATE);
78 inotify_inode_queue_event(inode, IN_CREATE, 0, name);
82 * fsnotify_mkdir - directory 'name' was created
84 static inline void fsnotify_mkdir(struct inode *inode, const char *name)
86 inode_dir_notify(inode, DN_CREATE);
87 inotify_inode_queue_event(inode, IN_CREATE | IN_ISDIR, 0, name);
91 * fsnotify_access - file was read
93 static inline void fsnotify_access(struct dentry *dentry)
95 struct inode *inode = dentry->d_inode;
98 if (S_ISDIR(inode->i_mode))
101 dnotify_parent(dentry, DN_ACCESS);
102 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
103 inotify_inode_queue_event(inode, mask, 0, NULL);
107 * fsnotify_modify - file was modified
109 static inline void fsnotify_modify(struct dentry *dentry)
111 struct inode *inode = dentry->d_inode;
112 u32 mask = IN_MODIFY;
114 if (S_ISDIR(inode->i_mode))
117 dnotify_parent(dentry, DN_MODIFY);
118 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
119 inotify_inode_queue_event(inode, mask, 0, NULL);
123 * fsnotify_open - file was opened
125 static inline void fsnotify_open(struct dentry *dentry)
127 struct inode *inode = dentry->d_inode;
130 if (S_ISDIR(inode->i_mode))
133 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
134 inotify_inode_queue_event(inode, mask, 0, NULL);
138 * fsnotify_close - file was closed
140 static inline void fsnotify_close(struct file *file)
142 struct dentry *dentry = file->f_dentry;
143 struct inode *inode = dentry->d_inode;
144 const char *name = dentry->d_name.name;
145 mode_t mode = file->f_mode;
146 u32 mask = (mode & FMODE_WRITE) ? IN_CLOSE_WRITE : IN_CLOSE_NOWRITE;
148 if (S_ISDIR(inode->i_mode))
151 inotify_dentry_parent_queue_event(dentry, mask, 0, name);
152 inotify_inode_queue_event(inode, mask, 0, NULL);
156 * fsnotify_xattr - extended attributes were changed
158 static inline void fsnotify_xattr(struct dentry *dentry)
160 struct inode *inode = dentry->d_inode;
161 u32 mask = IN_ATTRIB;
163 if (S_ISDIR(inode->i_mode))
166 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
167 inotify_inode_queue_event(inode, mask, 0, NULL);
171 * fsnotify_change - notify_change event. file was modified and/or metadata
174 static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
176 struct inode *inode = dentry->d_inode;
180 if (ia_valid & ATTR_UID) {
181 in_mask |= IN_ATTRIB;
182 dn_mask |= DN_ATTRIB;
184 if (ia_valid & ATTR_GID) {
185 in_mask |= IN_ATTRIB;
186 dn_mask |= DN_ATTRIB;
188 if (ia_valid & ATTR_SIZE) {
189 in_mask |= IN_MODIFY;
190 dn_mask |= DN_MODIFY;
192 /* both times implies a utime(s) call */
193 if ((ia_valid & (ATTR_ATIME | ATTR_MTIME)) == (ATTR_ATIME | ATTR_MTIME))
195 in_mask |= IN_ATTRIB;
196 dn_mask |= DN_ATTRIB;
197 } else if (ia_valid & ATTR_ATIME) {
198 in_mask |= IN_ACCESS;
199 dn_mask |= DN_ACCESS;
200 } else if (ia_valid & ATTR_MTIME) {
201 in_mask |= IN_MODIFY;
202 dn_mask |= DN_MODIFY;
204 if (ia_valid & ATTR_MODE) {
205 in_mask |= IN_ATTRIB;
206 dn_mask |= DN_ATTRIB;
210 dnotify_parent(dentry, dn_mask);
212 if (S_ISDIR(inode->i_mode))
214 inotify_inode_queue_event(inode, in_mask, 0, NULL);
215 inotify_dentry_parent_queue_event(dentry, in_mask, 0,
216 dentry->d_name.name);
220 #ifdef CONFIG_INOTIFY /* inotify helpers */
223 * fsnotify_oldname_init - save off the old filename before we change it
225 static inline const char *fsnotify_oldname_init(const char *name)
227 return kstrdup(name, GFP_KERNEL);
231 * fsnotify_oldname_free - free the name we got from fsnotify_oldname_init
233 static inline void fsnotify_oldname_free(const char *old_name)
238 #else /* CONFIG_INOTIFY */
240 static inline const char *fsnotify_oldname_init(const char *name)
245 static inline void fsnotify_oldname_free(const char *old_name)
249 #endif /* ! CONFIG_INOTIFY */
251 #endif /* __KERNEL__ */
253 #endif /* _LINUX_FS_NOTIFY_H */