thinkpad-acpi: handle some new HKEY 0x60xx events
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / include / linux / fsnotify.h
blob2a53f10712b36097b648e4a61cb6323e5a42de84
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>
19 * fsnotify_d_instantiate - instantiate a dentry for inode
21 static inline void fsnotify_d_instantiate(struct dentry *dentry,
22 struct inode *inode)
24 __fsnotify_d_instantiate(dentry, inode);
27 /* Notify this dentry's parent about a child's events. */
28 static inline int fsnotify_parent(struct path *path, struct dentry *dentry, __u32 mask)
30 if (!dentry)
31 dentry = path->dentry;
33 return __fsnotify_parent(path, dentry, mask);
36 /* simple call site for access decisions */
37 static inline int fsnotify_perm(struct file *file, int mask)
39 struct path *path = &file->f_path;
40 struct inode *inode = path->dentry->d_inode;
41 __u32 fsnotify_mask = 0;
42 int ret;
44 if (file->f_mode & FMODE_NONOTIFY)
45 return 0;
46 if (!(mask & (MAY_READ | MAY_OPEN)))
47 return 0;
48 if (mask & MAY_OPEN)
49 fsnotify_mask = FS_OPEN_PERM;
50 else if (mask & MAY_READ)
51 fsnotify_mask = FS_ACCESS_PERM;
52 else
53 BUG();
55 ret = fsnotify_parent(path, NULL, fsnotify_mask);
56 if (ret)
57 return ret;
59 return fsnotify(inode, fsnotify_mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
63 * fsnotify_d_move - dentry has been moved
65 static inline void fsnotify_d_move(struct dentry *dentry)
68 * On move we need to update dentry->d_flags to indicate if the new parent
69 * cares about events from this dentry.
71 __fsnotify_update_dcache_flags(dentry);
75 * fsnotify_link_count - inode's link count changed
77 static inline void fsnotify_link_count(struct inode *inode)
79 fsnotify(inode, FS_ATTRIB, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
83 * fsnotify_move - file old_name at old_dir was moved to new_name at new_dir
85 static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir,
86 const unsigned char *old_name,
87 int isdir, struct inode *target, struct dentry *moved)
89 struct inode *source = moved->d_inode;
90 u32 fs_cookie = fsnotify_get_cookie();
91 __u32 old_dir_mask = (FS_EVENT_ON_CHILD | FS_MOVED_FROM);
92 __u32 new_dir_mask = (FS_EVENT_ON_CHILD | FS_MOVED_TO);
93 const unsigned char *new_name = moved->d_name.name;
95 if (old_dir == new_dir)
96 old_dir_mask |= FS_DN_RENAME;
98 if (isdir) {
99 old_dir_mask |= FS_ISDIR;
100 new_dir_mask |= FS_ISDIR;
103 fsnotify(old_dir, old_dir_mask, old_dir, FSNOTIFY_EVENT_INODE, old_name, fs_cookie);
104 fsnotify(new_dir, new_dir_mask, new_dir, FSNOTIFY_EVENT_INODE, new_name, fs_cookie);
106 if (target)
107 fsnotify_link_count(target);
109 if (source)
110 fsnotify(source, FS_MOVE_SELF, moved->d_inode, FSNOTIFY_EVENT_INODE, NULL, 0);
111 audit_inode_child(moved, new_dir);
115 * fsnotify_inode_delete - and inode is being evicted from cache, clean up is needed
117 static inline void fsnotify_inode_delete(struct inode *inode)
119 __fsnotify_inode_delete(inode);
123 * fsnotify_vfsmount_delete - a vfsmount is being destroyed, clean up is needed
125 static inline void fsnotify_vfsmount_delete(struct vfsmount *mnt)
127 __fsnotify_vfsmount_delete(mnt);
131 * fsnotify_nameremove - a filename was removed from a directory
133 static inline void fsnotify_nameremove(struct dentry *dentry, int isdir)
135 __u32 mask = FS_DELETE;
137 if (isdir)
138 mask |= FS_ISDIR;
140 fsnotify_parent(NULL, dentry, mask);
144 * fsnotify_inoderemove - an inode is going away
146 static inline void fsnotify_inoderemove(struct inode *inode)
148 fsnotify(inode, FS_DELETE_SELF, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
149 __fsnotify_inode_delete(inode);
153 * fsnotify_create - 'name' was linked in
155 static inline void fsnotify_create(struct inode *inode, struct dentry *dentry)
157 audit_inode_child(dentry, inode);
159 fsnotify(inode, FS_CREATE, dentry->d_inode, FSNOTIFY_EVENT_INODE, dentry->d_name.name, 0);
163 * fsnotify_link - new hardlink in 'inode' directory
164 * Note: We have to pass also the linked inode ptr as some filesystems leave
165 * new_dentry->d_inode NULL and instantiate inode pointer later
167 static inline void fsnotify_link(struct inode *dir, struct inode *inode, struct dentry *new_dentry)
169 fsnotify_link_count(inode);
170 audit_inode_child(new_dentry, dir);
172 fsnotify(dir, FS_CREATE, inode, FSNOTIFY_EVENT_INODE, new_dentry->d_name.name, 0);
176 * fsnotify_mkdir - directory 'name' was created
178 static inline void fsnotify_mkdir(struct inode *inode, struct dentry *dentry)
180 __u32 mask = (FS_CREATE | FS_ISDIR);
181 struct inode *d_inode = dentry->d_inode;
183 audit_inode_child(dentry, inode);
185 fsnotify(inode, mask, d_inode, FSNOTIFY_EVENT_INODE, dentry->d_name.name, 0);
189 * fsnotify_access - file was read
191 static inline void fsnotify_access(struct file *file)
193 struct path *path = &file->f_path;
194 struct inode *inode = path->dentry->d_inode;
195 __u32 mask = FS_ACCESS;
197 if (S_ISDIR(inode->i_mode))
198 mask |= FS_ISDIR;
200 if (!(file->f_mode & FMODE_NONOTIFY)) {
201 fsnotify_parent(path, NULL, mask);
202 fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
207 * fsnotify_modify - file was modified
209 static inline void fsnotify_modify(struct file *file)
211 struct path *path = &file->f_path;
212 struct inode *inode = path->dentry->d_inode;
213 __u32 mask = FS_MODIFY;
215 if (S_ISDIR(inode->i_mode))
216 mask |= FS_ISDIR;
218 if (!(file->f_mode & FMODE_NONOTIFY)) {
219 fsnotify_parent(path, NULL, mask);
220 fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
225 * fsnotify_open - file was opened
227 static inline void fsnotify_open(struct file *file)
229 struct path *path = &file->f_path;
230 struct inode *inode = path->dentry->d_inode;
231 __u32 mask = FS_OPEN;
233 if (S_ISDIR(inode->i_mode))
234 mask |= FS_ISDIR;
236 fsnotify_parent(path, NULL, mask);
237 fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
241 * fsnotify_close - file was closed
243 static inline void fsnotify_close(struct file *file)
245 struct path *path = &file->f_path;
246 struct inode *inode = file->f_path.dentry->d_inode;
247 fmode_t mode = file->f_mode;
248 __u32 mask = (mode & FMODE_WRITE) ? FS_CLOSE_WRITE : FS_CLOSE_NOWRITE;
250 if (S_ISDIR(inode->i_mode))
251 mask |= FS_ISDIR;
253 if (!(file->f_mode & FMODE_NONOTIFY)) {
254 fsnotify_parent(path, NULL, mask);
255 fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
260 * fsnotify_xattr - extended attributes were changed
262 static inline void fsnotify_xattr(struct dentry *dentry)
264 struct inode *inode = dentry->d_inode;
265 __u32 mask = FS_ATTRIB;
267 if (S_ISDIR(inode->i_mode))
268 mask |= FS_ISDIR;
270 fsnotify_parent(NULL, dentry, mask);
271 fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
275 * fsnotify_change - notify_change event. file was modified and/or metadata
276 * was changed.
278 static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
280 struct inode *inode = dentry->d_inode;
281 __u32 mask = 0;
283 if (ia_valid & ATTR_UID)
284 mask |= FS_ATTRIB;
285 if (ia_valid & ATTR_GID)
286 mask |= FS_ATTRIB;
287 if (ia_valid & ATTR_SIZE)
288 mask |= FS_MODIFY;
290 /* both times implies a utime(s) call */
291 if ((ia_valid & (ATTR_ATIME | ATTR_MTIME)) == (ATTR_ATIME | ATTR_MTIME))
292 mask |= FS_ATTRIB;
293 else if (ia_valid & ATTR_ATIME)
294 mask |= FS_ACCESS;
295 else if (ia_valid & ATTR_MTIME)
296 mask |= FS_MODIFY;
298 if (ia_valid & ATTR_MODE)
299 mask |= FS_ATTRIB;
301 if (mask) {
302 if (S_ISDIR(inode->i_mode))
303 mask |= FS_ISDIR;
305 fsnotify_parent(NULL, dentry, mask);
306 fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
310 #if defined(CONFIG_FSNOTIFY) /* notify helpers */
313 * fsnotify_oldname_init - save off the old filename before we change it
315 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
317 return kstrdup(name, GFP_KERNEL);
321 * fsnotify_oldname_free - free the name we got from fsnotify_oldname_init
323 static inline void fsnotify_oldname_free(const unsigned char *old_name)
325 kfree(old_name);
328 #else /* CONFIG_FSNOTIFY */
330 static inline const char *fsnotify_oldname_init(const unsigned char *name)
332 return NULL;
335 static inline void fsnotify_oldname_free(const unsigned char *old_name)
339 #endif /* CONFIG_FSNOTIFY */
341 #endif /* _LINUX_FS_NOTIFY_H */