HSI: omap_ssi_port: avoid calling runtime_pm_*_sync inside spinlock
[linux-2.6/btrfs-unstable.git] / include / linux / fsnotify.h
blob0141f257d67b6ae0f17890e11cef31f7ac6056f8
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 #include <linux/fsnotify_backend.h>
15 #include <linux/audit.h>
16 #include <linux/slab.h>
17 #include <linux/bug.h>
19 /* Notify this dentry's parent about a child's events. */
20 static inline int fsnotify_parent(struct path *path, struct dentry *dentry, __u32 mask)
22 if (!dentry)
23 dentry = path->dentry;
25 return __fsnotify_parent(path, dentry, mask);
28 /* simple call site for access decisions */
29 static inline int fsnotify_perm(struct file *file, int mask)
31 struct path *path = &file->f_path;
32 struct inode *inode = file_inode(file);
33 __u32 fsnotify_mask = 0;
34 int ret;
36 if (file->f_mode & FMODE_NONOTIFY)
37 return 0;
38 if (!(mask & (MAY_READ | MAY_OPEN)))
39 return 0;
40 if (mask & MAY_OPEN)
41 fsnotify_mask = FS_OPEN_PERM;
42 else if (mask & MAY_READ)
43 fsnotify_mask = FS_ACCESS_PERM;
44 else
45 BUG();
47 ret = fsnotify_parent(path, NULL, fsnotify_mask);
48 if (ret)
49 return ret;
51 return fsnotify(inode, fsnotify_mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
55 * fsnotify_d_move - dentry has been moved
57 static inline void fsnotify_d_move(struct dentry *dentry)
60 * On move we need to update dentry->d_flags to indicate if the new parent
61 * cares about events from this dentry.
63 __fsnotify_update_dcache_flags(dentry);
67 * fsnotify_link_count - inode's link count changed
69 static inline void fsnotify_link_count(struct inode *inode)
71 fsnotify(inode, FS_ATTRIB, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
75 * fsnotify_move - file old_name at old_dir was moved to new_name at new_dir
77 static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir,
78 const unsigned char *old_name,
79 int isdir, struct inode *target, struct dentry *moved)
81 struct inode *source = moved->d_inode;
82 u32 fs_cookie = fsnotify_get_cookie();
83 __u32 old_dir_mask = (FS_EVENT_ON_CHILD | FS_MOVED_FROM);
84 __u32 new_dir_mask = (FS_EVENT_ON_CHILD | FS_MOVED_TO);
85 const unsigned char *new_name = moved->d_name.name;
87 if (old_dir == new_dir)
88 old_dir_mask |= FS_DN_RENAME;
90 if (isdir) {
91 old_dir_mask |= FS_ISDIR;
92 new_dir_mask |= FS_ISDIR;
95 fsnotify(old_dir, old_dir_mask, source, FSNOTIFY_EVENT_INODE, old_name,
96 fs_cookie);
97 fsnotify(new_dir, new_dir_mask, source, FSNOTIFY_EVENT_INODE, new_name,
98 fs_cookie);
100 if (target)
101 fsnotify_link_count(target);
103 if (source)
104 fsnotify(source, FS_MOVE_SELF, moved->d_inode, FSNOTIFY_EVENT_INODE, NULL, 0);
105 audit_inode_child(new_dir, moved, AUDIT_TYPE_CHILD_CREATE);
109 * fsnotify_inode_delete - and inode is being evicted from cache, clean up is needed
111 static inline void fsnotify_inode_delete(struct inode *inode)
113 __fsnotify_inode_delete(inode);
117 * fsnotify_vfsmount_delete - a vfsmount is being destroyed, clean up is needed
119 static inline void fsnotify_vfsmount_delete(struct vfsmount *mnt)
121 __fsnotify_vfsmount_delete(mnt);
125 * fsnotify_nameremove - a filename was removed from a directory
127 static inline void fsnotify_nameremove(struct dentry *dentry, int isdir)
129 __u32 mask = FS_DELETE;
131 if (isdir)
132 mask |= FS_ISDIR;
134 fsnotify_parent(NULL, dentry, mask);
138 * fsnotify_inoderemove - an inode is going away
140 static inline void fsnotify_inoderemove(struct inode *inode)
142 fsnotify(inode, FS_DELETE_SELF, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
143 __fsnotify_inode_delete(inode);
147 * fsnotify_create - 'name' was linked in
149 static inline void fsnotify_create(struct inode *inode, struct dentry *dentry)
151 audit_inode_child(inode, dentry, AUDIT_TYPE_CHILD_CREATE);
153 fsnotify(inode, FS_CREATE, dentry->d_inode, FSNOTIFY_EVENT_INODE, dentry->d_name.name, 0);
157 * fsnotify_link - new hardlink in 'inode' directory
158 * Note: We have to pass also the linked inode ptr as some filesystems leave
159 * new_dentry->d_inode NULL and instantiate inode pointer later
161 static inline void fsnotify_link(struct inode *dir, struct inode *inode, struct dentry *new_dentry)
163 fsnotify_link_count(inode);
164 audit_inode_child(dir, new_dentry, AUDIT_TYPE_CHILD_CREATE);
166 fsnotify(dir, FS_CREATE, inode, FSNOTIFY_EVENT_INODE, new_dentry->d_name.name, 0);
170 * fsnotify_mkdir - directory 'name' was created
172 static inline void fsnotify_mkdir(struct inode *inode, struct dentry *dentry)
174 __u32 mask = (FS_CREATE | FS_ISDIR);
175 struct inode *d_inode = dentry->d_inode;
177 audit_inode_child(inode, dentry, AUDIT_TYPE_CHILD_CREATE);
179 fsnotify(inode, mask, d_inode, FSNOTIFY_EVENT_INODE, dentry->d_name.name, 0);
183 * fsnotify_access - file was read
185 static inline void fsnotify_access(struct file *file)
187 struct path *path = &file->f_path;
188 struct inode *inode = file_inode(file);
189 __u32 mask = FS_ACCESS;
191 if (S_ISDIR(inode->i_mode))
192 mask |= FS_ISDIR;
194 if (!(file->f_mode & FMODE_NONOTIFY)) {
195 fsnotify_parent(path, NULL, mask);
196 fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
201 * fsnotify_modify - file was modified
203 static inline void fsnotify_modify(struct file *file)
205 struct path *path = &file->f_path;
206 struct inode *inode = file_inode(file);
207 __u32 mask = FS_MODIFY;
209 if (S_ISDIR(inode->i_mode))
210 mask |= FS_ISDIR;
212 if (!(file->f_mode & FMODE_NONOTIFY)) {
213 fsnotify_parent(path, NULL, mask);
214 fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
219 * fsnotify_open - file was opened
221 static inline void fsnotify_open(struct file *file)
223 struct path *path = &file->f_path;
224 struct inode *inode = file_inode(file);
225 __u32 mask = FS_OPEN;
227 if (S_ISDIR(inode->i_mode))
228 mask |= FS_ISDIR;
230 fsnotify_parent(path, NULL, mask);
231 fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
235 * fsnotify_close - file was closed
237 static inline void fsnotify_close(struct file *file)
239 struct path *path = &file->f_path;
240 struct inode *inode = file_inode(file);
241 fmode_t mode = file->f_mode;
242 __u32 mask = (mode & FMODE_WRITE) ? FS_CLOSE_WRITE : FS_CLOSE_NOWRITE;
244 if (S_ISDIR(inode->i_mode))
245 mask |= FS_ISDIR;
247 if (!(file->f_mode & FMODE_NONOTIFY)) {
248 fsnotify_parent(path, NULL, mask);
249 fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
254 * fsnotify_xattr - extended attributes were changed
256 static inline void fsnotify_xattr(struct dentry *dentry)
258 struct inode *inode = dentry->d_inode;
259 __u32 mask = FS_ATTRIB;
261 if (S_ISDIR(inode->i_mode))
262 mask |= FS_ISDIR;
264 fsnotify_parent(NULL, dentry, mask);
265 fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
269 * fsnotify_change - notify_change event. file was modified and/or metadata
270 * was changed.
272 static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
274 struct inode *inode = dentry->d_inode;
275 __u32 mask = 0;
277 if (ia_valid & ATTR_UID)
278 mask |= FS_ATTRIB;
279 if (ia_valid & ATTR_GID)
280 mask |= FS_ATTRIB;
281 if (ia_valid & ATTR_SIZE)
282 mask |= FS_MODIFY;
284 /* both times implies a utime(s) call */
285 if ((ia_valid & (ATTR_ATIME | ATTR_MTIME)) == (ATTR_ATIME | ATTR_MTIME))
286 mask |= FS_ATTRIB;
287 else if (ia_valid & ATTR_ATIME)
288 mask |= FS_ACCESS;
289 else if (ia_valid & ATTR_MTIME)
290 mask |= FS_MODIFY;
292 if (ia_valid & ATTR_MODE)
293 mask |= FS_ATTRIB;
295 if (mask) {
296 if (S_ISDIR(inode->i_mode))
297 mask |= FS_ISDIR;
299 fsnotify_parent(NULL, dentry, mask);
300 fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
304 #if defined(CONFIG_FSNOTIFY) /* notify helpers */
307 * fsnotify_oldname_init - save off the old filename before we change it
309 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
311 return kstrdup(name, GFP_KERNEL);
315 * fsnotify_oldname_free - free the name we got from fsnotify_oldname_init
317 static inline void fsnotify_oldname_free(const unsigned char *old_name)
319 kfree(old_name);
322 #else /* CONFIG_FSNOTIFY */
324 static inline const char *fsnotify_oldname_init(const unsigned char *name)
326 return NULL;
329 static inline void fsnotify_oldname_free(const unsigned char *old_name)
333 #endif /* CONFIG_FSNOTIFY */
335 #endif /* _LINUX_FS_NOTIFY_H */