V4L/DVB: Saa7134: rename dmasound_{init,exit}
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / include / linux / fsnotify.h
blob03b8e7932b830a3f1bfffcc531ec4ee9b1662b1e
1 #ifndef _LINUX_FS_NOTIFY_H
2 #define _LINUX_FS_NOTIFY_H
4 /*
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 #ifdef __KERNEL__
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);
30 else {
31 inode_dir_notify(old_dir, DN_DELETE);
32 inode_dir_notify(new_dir, DN_CREATE);
35 if (isdir)
36 isdir = IN_ISDIR;
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);
40 if (target) {
41 inotify_inode_queue_event(target, IN_DELETE_SELF, 0, NULL);
42 inotify_inode_is_dead(target);
45 if (source) {
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)
55 if (isdir)
56 isdir = IN_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, const char *name)
75 inode_dir_notify(inode, DN_CREATE);
76 inotify_inode_queue_event(inode, IN_CREATE, 0, name);
80 * fsnotify_mkdir - directory 'name' was created
82 static inline void fsnotify_mkdir(struct inode *inode, const char *name)
84 inode_dir_notify(inode, DN_CREATE);
85 inotify_inode_queue_event(inode, IN_CREATE | IN_ISDIR, 0, name);
89 * fsnotify_access - file was read
91 static inline void fsnotify_access(struct dentry *dentry)
93 struct inode *inode = dentry->d_inode;
94 u32 mask = IN_ACCESS;
96 if (S_ISDIR(inode->i_mode))
97 mask |= IN_ISDIR;
99 dnotify_parent(dentry, DN_ACCESS);
100 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
101 inotify_inode_queue_event(inode, mask, 0, NULL);
105 * fsnotify_modify - file was modified
107 static inline void fsnotify_modify(struct dentry *dentry)
109 struct inode *inode = dentry->d_inode;
110 u32 mask = IN_MODIFY;
112 if (S_ISDIR(inode->i_mode))
113 mask |= IN_ISDIR;
115 dnotify_parent(dentry, DN_MODIFY);
116 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
117 inotify_inode_queue_event(inode, mask, 0, NULL);
121 * fsnotify_open - file was opened
123 static inline void fsnotify_open(struct dentry *dentry)
125 struct inode *inode = dentry->d_inode;
126 u32 mask = IN_OPEN;
128 if (S_ISDIR(inode->i_mode))
129 mask |= IN_ISDIR;
131 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
132 inotify_inode_queue_event(inode, mask, 0, NULL);
136 * fsnotify_close - file was closed
138 static inline void fsnotify_close(struct file *file)
140 struct dentry *dentry = file->f_dentry;
141 struct inode *inode = dentry->d_inode;
142 const char *name = dentry->d_name.name;
143 mode_t mode = file->f_mode;
144 u32 mask = (mode & FMODE_WRITE) ? IN_CLOSE_WRITE : IN_CLOSE_NOWRITE;
146 if (S_ISDIR(inode->i_mode))
147 mask |= IN_ISDIR;
149 inotify_dentry_parent_queue_event(dentry, mask, 0, name);
150 inotify_inode_queue_event(inode, mask, 0, NULL);
154 * fsnotify_xattr - extended attributes were changed
156 static inline void fsnotify_xattr(struct dentry *dentry)
158 struct inode *inode = dentry->d_inode;
159 u32 mask = IN_ATTRIB;
161 if (S_ISDIR(inode->i_mode))
162 mask |= IN_ISDIR;
164 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
165 inotify_inode_queue_event(inode, mask, 0, NULL);
169 * fsnotify_change - notify_change event. file was modified and/or metadata
170 * was changed.
172 static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
174 struct inode *inode = dentry->d_inode;
175 int dn_mask = 0;
176 u32 in_mask = 0;
178 if (ia_valid & ATTR_UID) {
179 in_mask |= IN_ATTRIB;
180 dn_mask |= DN_ATTRIB;
182 if (ia_valid & ATTR_GID) {
183 in_mask |= IN_ATTRIB;
184 dn_mask |= DN_ATTRIB;
186 if (ia_valid & ATTR_SIZE) {
187 in_mask |= IN_MODIFY;
188 dn_mask |= DN_MODIFY;
190 /* both times implies a utime(s) call */
191 if ((ia_valid & (ATTR_ATIME | ATTR_MTIME)) == (ATTR_ATIME | ATTR_MTIME))
193 in_mask |= IN_ATTRIB;
194 dn_mask |= DN_ATTRIB;
195 } else if (ia_valid & ATTR_ATIME) {
196 in_mask |= IN_ACCESS;
197 dn_mask |= DN_ACCESS;
198 } else if (ia_valid & ATTR_MTIME) {
199 in_mask |= IN_MODIFY;
200 dn_mask |= DN_MODIFY;
202 if (ia_valid & ATTR_MODE) {
203 in_mask |= IN_ATTRIB;
204 dn_mask |= DN_ATTRIB;
207 if (dn_mask)
208 dnotify_parent(dentry, dn_mask);
209 if (in_mask) {
210 if (S_ISDIR(inode->i_mode))
211 in_mask |= IN_ISDIR;
212 inotify_inode_queue_event(inode, in_mask, 0, NULL);
213 inotify_dentry_parent_queue_event(dentry, in_mask, 0,
214 dentry->d_name.name);
218 #ifdef CONFIG_INOTIFY /* inotify helpers */
221 * fsnotify_oldname_init - save off the old filename before we change it
223 static inline const char *fsnotify_oldname_init(const char *name)
225 return kstrdup(name, GFP_KERNEL);
229 * fsnotify_oldname_free - free the name we got from fsnotify_oldname_init
231 static inline void fsnotify_oldname_free(const char *old_name)
233 kfree(old_name);
236 #else /* CONFIG_INOTIFY */
238 static inline const char *fsnotify_oldname_init(const char *name)
240 return NULL;
243 static inline void fsnotify_oldname_free(const char *old_name)
247 #endif /* ! CONFIG_INOTIFY */
249 #endif /* __KERNEL__ */
251 #endif /* _LINUX_FS_NOTIFY_H */