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_d_instantiate - instantiate a dentry for inode
21 * Called with dcache_lock held.
23 static inline void fsnotify_d_instantiate(struct dentry *entry,
26 inotify_d_instantiate(entry, inode);
30 * fsnotify_d_move - entry has been moved
31 * Called with dcache_lock and entry->d_lock held.
33 static inline void fsnotify_d_move(struct dentry *entry)
35 inotify_d_move(entry);
39 * fsnotify_move - file old_name at old_dir was moved to new_name at new_dir
41 static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir,
42 const char *old_name, const char *new_name,
43 int isdir, struct inode *target, struct inode *source)
45 u32 cookie = inotify_get_cookie();
47 if (old_dir == new_dir)
48 inode_dir_notify(old_dir, DN_RENAME);
50 inode_dir_notify(old_dir, DN_DELETE);
51 inode_dir_notify(new_dir, DN_CREATE);
56 inotify_inode_queue_event(old_dir, IN_MOVED_FROM|isdir,cookie,old_name);
57 inotify_inode_queue_event(new_dir, IN_MOVED_TO|isdir, cookie, new_name);
60 inotify_inode_queue_event(target, IN_DELETE_SELF, 0, NULL);
61 inotify_inode_is_dead(target);
65 inotify_inode_queue_event(source, IN_MOVE_SELF, 0, NULL);
70 * fsnotify_nameremove - a filename was removed from a directory
72 static inline void fsnotify_nameremove(struct dentry *dentry, int isdir)
76 dnotify_parent(dentry, DN_DELETE);
77 inotify_dentry_parent_queue_event(dentry, IN_DELETE|isdir, 0, dentry->d_name.name);
81 * fsnotify_inoderemove - an inode is going away
83 static inline void fsnotify_inoderemove(struct inode *inode)
85 inotify_inode_queue_event(inode, IN_DELETE_SELF, 0, NULL);
86 inotify_inode_is_dead(inode);
90 * fsnotify_create - 'name' was linked in
92 static inline void fsnotify_create(struct inode *inode, const char *name)
94 inode_dir_notify(inode, DN_CREATE);
95 inotify_inode_queue_event(inode, IN_CREATE, 0, name);
99 * fsnotify_mkdir - directory 'name' was created
101 static inline void fsnotify_mkdir(struct inode *inode, const char *name)
103 inode_dir_notify(inode, DN_CREATE);
104 inotify_inode_queue_event(inode, IN_CREATE | IN_ISDIR, 0, name);
108 * fsnotify_access - file was read
110 static inline void fsnotify_access(struct dentry *dentry)
112 struct inode *inode = dentry->d_inode;
113 u32 mask = IN_ACCESS;
115 if (S_ISDIR(inode->i_mode))
118 dnotify_parent(dentry, DN_ACCESS);
119 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
120 inotify_inode_queue_event(inode, mask, 0, NULL);
124 * fsnotify_modify - file was modified
126 static inline void fsnotify_modify(struct dentry *dentry)
128 struct inode *inode = dentry->d_inode;
129 u32 mask = IN_MODIFY;
131 if (S_ISDIR(inode->i_mode))
134 dnotify_parent(dentry, DN_MODIFY);
135 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
136 inotify_inode_queue_event(inode, mask, 0, NULL);
140 * fsnotify_open - file was opened
142 static inline void fsnotify_open(struct dentry *dentry)
144 struct inode *inode = dentry->d_inode;
147 if (S_ISDIR(inode->i_mode))
150 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
151 inotify_inode_queue_event(inode, mask, 0, NULL);
155 * fsnotify_close - file was closed
157 static inline void fsnotify_close(struct file *file)
159 struct dentry *dentry = file->f_dentry;
160 struct inode *inode = dentry->d_inode;
161 const char *name = dentry->d_name.name;
162 mode_t mode = file->f_mode;
163 u32 mask = (mode & FMODE_WRITE) ? IN_CLOSE_WRITE : IN_CLOSE_NOWRITE;
165 if (S_ISDIR(inode->i_mode))
168 inotify_dentry_parent_queue_event(dentry, mask, 0, name);
169 inotify_inode_queue_event(inode, mask, 0, NULL);
173 * fsnotify_xattr - extended attributes were changed
175 static inline void fsnotify_xattr(struct dentry *dentry)
177 struct inode *inode = dentry->d_inode;
178 u32 mask = IN_ATTRIB;
180 if (S_ISDIR(inode->i_mode))
183 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
184 inotify_inode_queue_event(inode, mask, 0, NULL);
188 * fsnotify_change - notify_change event. file was modified and/or metadata
191 static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
193 struct inode *inode = dentry->d_inode;
197 if (ia_valid & ATTR_UID) {
198 in_mask |= IN_ATTRIB;
199 dn_mask |= DN_ATTRIB;
201 if (ia_valid & ATTR_GID) {
202 in_mask |= IN_ATTRIB;
203 dn_mask |= DN_ATTRIB;
205 if (ia_valid & ATTR_SIZE) {
206 in_mask |= IN_MODIFY;
207 dn_mask |= DN_MODIFY;
209 /* both times implies a utime(s) call */
210 if ((ia_valid & (ATTR_ATIME | ATTR_MTIME)) == (ATTR_ATIME | ATTR_MTIME))
212 in_mask |= IN_ATTRIB;
213 dn_mask |= DN_ATTRIB;
214 } else if (ia_valid & ATTR_ATIME) {
215 in_mask |= IN_ACCESS;
216 dn_mask |= DN_ACCESS;
217 } else if (ia_valid & ATTR_MTIME) {
218 in_mask |= IN_MODIFY;
219 dn_mask |= DN_MODIFY;
221 if (ia_valid & ATTR_MODE) {
222 in_mask |= IN_ATTRIB;
223 dn_mask |= DN_ATTRIB;
227 dnotify_parent(dentry, dn_mask);
229 if (S_ISDIR(inode->i_mode))
231 inotify_inode_queue_event(inode, in_mask, 0, NULL);
232 inotify_dentry_parent_queue_event(dentry, in_mask, 0,
233 dentry->d_name.name);
237 #ifdef CONFIG_INOTIFY /* inotify helpers */
240 * fsnotify_oldname_init - save off the old filename before we change it
242 static inline const char *fsnotify_oldname_init(const char *name)
244 return kstrdup(name, GFP_KERNEL);
248 * fsnotify_oldname_free - free the name we got from fsnotify_oldname_init
250 static inline void fsnotify_oldname_free(const char *old_name)
255 #else /* CONFIG_INOTIFY */
257 static inline const char *fsnotify_oldname_init(const char *name)
262 static inline void fsnotify_oldname_free(const char *old_name)
266 #endif /* ! CONFIG_INOTIFY */
268 #endif /* __KERNEL__ */
270 #endif /* _LINUX_FS_NOTIFY_H */