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, struct inode *source)
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);
46 inotify_inode_queue_event(source, IN_MOVE_SELF, 0, NULL);
51 * fsnotify_nameremove - a filename was removed from a directory
53 static inline void fsnotify_nameremove(struct dentry *dentry, int isdir)
57 dnotify_parent(dentry, DN_DELETE);
58 inotify_dentry_parent_queue_event(dentry, IN_DELETE|isdir, 0, dentry->d_name.name);
62 * fsnotify_inoderemove - an inode is going away
64 static inline void fsnotify_inoderemove(struct inode *inode)
66 inotify_inode_queue_event(inode, IN_DELETE_SELF, 0, NULL);
67 inotify_inode_is_dead(inode);
71 * fsnotify_create - 'name' was linked in
73 static inline void fsnotify_create(struct inode *inode, struct dentry *dentry)
75 inode_dir_notify(inode, DN_CREATE);
76 inotify_inode_queue_event(inode, IN_CREATE, 0, dentry->d_name.name);
80 * fsnotify_mkdir - directory 'name' was created
82 static inline void fsnotify_mkdir(struct inode *inode, struct dentry *dentry)
84 inode_dir_notify(inode, DN_CREATE);
85 inotify_inode_queue_event(inode, IN_CREATE | IN_ISDIR, 0,
90 * fsnotify_access - file was read
92 static inline void fsnotify_access(struct dentry *dentry)
94 struct inode *inode = dentry->d_inode;
97 if (S_ISDIR(inode->i_mode))
100 dnotify_parent(dentry, DN_ACCESS);
101 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
102 inotify_inode_queue_event(inode, mask, 0, NULL);
106 * fsnotify_modify - file was modified
108 static inline void fsnotify_modify(struct dentry *dentry)
110 struct inode *inode = dentry->d_inode;
111 u32 mask = IN_MODIFY;
113 if (S_ISDIR(inode->i_mode))
116 dnotify_parent(dentry, DN_MODIFY);
117 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
118 inotify_inode_queue_event(inode, mask, 0, NULL);
122 * fsnotify_open - file was opened
124 static inline void fsnotify_open(struct dentry *dentry)
126 struct inode *inode = dentry->d_inode;
129 if (S_ISDIR(inode->i_mode))
132 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
133 inotify_inode_queue_event(inode, mask, 0, NULL);
137 * fsnotify_close - file was closed
139 static inline void fsnotify_close(struct file *file)
141 struct dentry *dentry = file->f_dentry;
142 struct inode *inode = dentry->d_inode;
143 const char *name = dentry->d_name.name;
144 mode_t mode = file->f_mode;
145 u32 mask = (mode & FMODE_WRITE) ? IN_CLOSE_WRITE : IN_CLOSE_NOWRITE;
147 if (S_ISDIR(inode->i_mode))
150 inotify_dentry_parent_queue_event(dentry, mask, 0, name);
151 inotify_inode_queue_event(inode, mask, 0, NULL);
155 * fsnotify_xattr - extended attributes were changed
157 static inline void fsnotify_xattr(struct dentry *dentry)
159 struct inode *inode = dentry->d_inode;
160 u32 mask = IN_ATTRIB;
162 if (S_ISDIR(inode->i_mode))
165 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
166 inotify_inode_queue_event(inode, mask, 0, NULL);
170 * fsnotify_change - notify_change event. file was modified and/or metadata
173 static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
175 struct inode *inode = dentry->d_inode;
179 if (ia_valid & ATTR_UID) {
180 in_mask |= IN_ATTRIB;
181 dn_mask |= DN_ATTRIB;
183 if (ia_valid & ATTR_GID) {
184 in_mask |= IN_ATTRIB;
185 dn_mask |= DN_ATTRIB;
187 if (ia_valid & ATTR_SIZE) {
188 in_mask |= IN_MODIFY;
189 dn_mask |= DN_MODIFY;
191 /* both times implies a utime(s) call */
192 if ((ia_valid & (ATTR_ATIME | ATTR_MTIME)) == (ATTR_ATIME | ATTR_MTIME))
194 in_mask |= IN_ATTRIB;
195 dn_mask |= DN_ATTRIB;
196 } else if (ia_valid & ATTR_ATIME) {
197 in_mask |= IN_ACCESS;
198 dn_mask |= DN_ACCESS;
199 } else if (ia_valid & ATTR_MTIME) {
200 in_mask |= IN_MODIFY;
201 dn_mask |= DN_MODIFY;
203 if (ia_valid & ATTR_MODE) {
204 in_mask |= IN_ATTRIB;
205 dn_mask |= DN_ATTRIB;
209 dnotify_parent(dentry, dn_mask);
211 if (S_ISDIR(inode->i_mode))
213 inotify_inode_queue_event(inode, in_mask, 0, NULL);
214 inotify_dentry_parent_queue_event(dentry, in_mask, 0,
215 dentry->d_name.name);
219 #ifdef CONFIG_INOTIFY /* inotify helpers */
222 * fsnotify_oldname_init - save off the old filename before we change it
224 static inline const char *fsnotify_oldname_init(const char *name)
226 return kstrdup(name, GFP_KERNEL);
230 * fsnotify_oldname_free - free the name we got from fsnotify_oldname_init
232 static inline void fsnotify_oldname_free(const char *old_name)
237 #else /* CONFIG_INOTIFY */
239 static inline const char *fsnotify_oldname_init(const char *name)
244 static inline void fsnotify_oldname_free(const char *old_name)
248 #endif /* ! CONFIG_INOTIFY */
250 #endif /* __KERNEL__ */
252 #endif /* _LINUX_FS_NOTIFY_H */