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 *inode, struct inode *dir)
51 inode_dir_notify(dir, DN_DELETE);
52 inotify_inode_queue_event(dir, IN_DELETE, 0, dentry->d_name.name);
53 inotify_inode_queue_event(inode, IN_DELETE_SELF, 0, NULL);
55 inotify_inode_is_dead(inode);
59 * fsnotify_rmdir - directory was removed
61 static inline void fsnotify_rmdir(struct dentry *dentry, struct inode *inode,
64 inode_dir_notify(dir, DN_DELETE);
65 inotify_inode_queue_event(dir,IN_DELETE|IN_ISDIR,0,dentry->d_name.name);
66 inotify_inode_queue_event(inode, IN_DELETE_SELF | IN_ISDIR, 0, NULL);
67 inotify_inode_is_dead(inode);
71 * fsnotify_nameremove - a filename was removed from a directory
73 static inline void fsnotify_nameremove(struct dentry *dentry, int isdir)
77 dnotify_parent(dentry, DN_DELETE);
78 inotify_dentry_parent_queue_event(dentry, IN_DELETE|isdir, 0, dentry->d_name.name);
82 * fsnotify_inoderemove - an inode is going away
84 static inline void fsnotify_inoderemove(struct inode *inode)
86 inotify_inode_queue_event(inode, IN_DELETE_SELF, 0, NULL);
87 inotify_inode_is_dead(inode);
91 * fsnotify_create - 'name' was linked in
93 static inline void fsnotify_create(struct inode *inode, const char *name)
95 inode_dir_notify(inode, DN_CREATE);
96 inotify_inode_queue_event(inode, IN_CREATE, 0, name);
100 * fsnotify_mkdir - directory 'name' was created
102 static inline void fsnotify_mkdir(struct inode *inode, const char *name)
104 inode_dir_notify(inode, DN_CREATE);
105 inotify_inode_queue_event(inode, IN_CREATE | IN_ISDIR, 0, name);
109 * fsnotify_access - file was read
111 static inline void fsnotify_access(struct dentry *dentry)
113 struct inode *inode = dentry->d_inode;
114 u32 mask = IN_ACCESS;
116 if (S_ISDIR(inode->i_mode))
119 dnotify_parent(dentry, DN_ACCESS);
120 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
121 inotify_inode_queue_event(inode, mask, 0, NULL);
125 * fsnotify_modify - file was modified
127 static inline void fsnotify_modify(struct dentry *dentry)
129 struct inode *inode = dentry->d_inode;
130 u32 mask = IN_MODIFY;
132 if (S_ISDIR(inode->i_mode))
135 dnotify_parent(dentry, DN_MODIFY);
136 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
137 inotify_inode_queue_event(inode, mask, 0, NULL);
141 * fsnotify_open - file was opened
143 static inline void fsnotify_open(struct dentry *dentry)
145 struct inode *inode = dentry->d_inode;
148 if (S_ISDIR(inode->i_mode))
151 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
152 inotify_inode_queue_event(inode, mask, 0, NULL);
156 * fsnotify_close - file was closed
158 static inline void fsnotify_close(struct file *file)
160 struct dentry *dentry = file->f_dentry;
161 struct inode *inode = dentry->d_inode;
162 const char *name = dentry->d_name.name;
163 mode_t mode = file->f_mode;
164 u32 mask = (mode & FMODE_WRITE) ? IN_CLOSE_WRITE : IN_CLOSE_NOWRITE;
166 if (S_ISDIR(inode->i_mode))
169 inotify_dentry_parent_queue_event(dentry, mask, 0, name);
170 inotify_inode_queue_event(inode, mask, 0, NULL);
174 * fsnotify_xattr - extended attributes were changed
176 static inline void fsnotify_xattr(struct dentry *dentry)
178 struct inode *inode = dentry->d_inode;
179 u32 mask = IN_ATTRIB;
181 if (S_ISDIR(inode->i_mode))
184 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
185 inotify_inode_queue_event(inode, mask, 0, NULL);
189 * fsnotify_change - notify_change event. file was modified and/or metadata
192 static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
194 struct inode *inode = dentry->d_inode;
198 if (ia_valid & ATTR_UID) {
199 in_mask |= IN_ATTRIB;
200 dn_mask |= DN_ATTRIB;
202 if (ia_valid & ATTR_GID) {
203 in_mask |= IN_ATTRIB;
204 dn_mask |= DN_ATTRIB;
206 if (ia_valid & ATTR_SIZE) {
207 in_mask |= IN_MODIFY;
208 dn_mask |= DN_MODIFY;
210 /* both times implies a utime(s) call */
211 if ((ia_valid & (ATTR_ATIME | ATTR_MTIME)) == (ATTR_ATIME | ATTR_MTIME))
213 in_mask |= IN_ATTRIB;
214 dn_mask |= DN_ATTRIB;
215 } else if (ia_valid & ATTR_ATIME) {
216 in_mask |= IN_ACCESS;
217 dn_mask |= DN_ACCESS;
218 } else if (ia_valid & ATTR_MTIME) {
219 in_mask |= IN_MODIFY;
220 dn_mask |= DN_MODIFY;
222 if (ia_valid & ATTR_MODE) {
223 in_mask |= IN_ATTRIB;
224 dn_mask |= DN_ATTRIB;
228 dnotify_parent(dentry, dn_mask);
230 if (S_ISDIR(inode->i_mode))
232 inotify_inode_queue_event(inode, in_mask, 0, NULL);
233 inotify_dentry_parent_queue_event(dentry, in_mask, 0,
234 dentry->d_name.name);
238 #ifdef CONFIG_INOTIFY /* inotify helpers */
241 * fsnotify_oldname_init - save off the old filename before we change it
243 static inline const char *fsnotify_oldname_init(const char *name)
245 return kstrdup(name, GFP_KERNEL);
249 * fsnotify_oldname_free - free the name we got from fsnotify_oldname_init
251 static inline void fsnotify_oldname_free(const char *old_name)
256 #else /* CONFIG_INOTIFY */
258 static inline const char *fsnotify_oldname_init(const char *name)
263 static inline void fsnotify_oldname_free(const char *old_name)
267 #endif /* ! CONFIG_INOTIFY */
269 #endif /* __KERNEL__ */
271 #endif /* _LINUX_FS_NOTIFY_H */