ACPI: thinkpad-acpi: preserve radio state across shutdown
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / include / linux / fsnotify.h
bloba89513188ce7a85c076f11e512d994b0447b384e
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/dnotify.h>
15 #include <linux/inotify.h>
16 #include <linux/audit.h>
19 * fsnotify_d_instantiate - instantiate a dentry for inode
20 * Called with dcache_lock held.
22 static inline void fsnotify_d_instantiate(struct dentry *entry,
23 struct inode *inode)
25 inotify_d_instantiate(entry, inode);
29 * fsnotify_d_move - entry has been moved
30 * Called with dcache_lock and entry->d_lock held.
32 static inline void fsnotify_d_move(struct dentry *entry)
34 inotify_d_move(entry);
38 * fsnotify_move - file old_name at old_dir was moved to new_name at new_dir
40 static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir,
41 const char *old_name, const char *new_name,
42 int isdir, struct inode *target, struct dentry *moved)
44 struct inode *source = moved->d_inode;
45 u32 cookie = inotify_get_cookie();
47 if (old_dir == new_dir)
48 inode_dir_notify(old_dir, DN_RENAME);
49 else {
50 inode_dir_notify(old_dir, DN_DELETE);
51 inode_dir_notify(new_dir, DN_CREATE);
54 if (isdir)
55 isdir = IN_ISDIR;
56 inotify_inode_queue_event(old_dir, IN_MOVED_FROM|isdir,cookie,old_name,
57 source);
58 inotify_inode_queue_event(new_dir, IN_MOVED_TO|isdir, cookie, new_name,
59 source);
61 if (target) {
62 inotify_inode_queue_event(target, IN_DELETE_SELF, 0, NULL, NULL);
63 inotify_inode_is_dead(target);
66 if (source) {
67 inotify_inode_queue_event(source, IN_MOVE_SELF, 0, NULL, NULL);
69 audit_inode_child(new_name, moved, new_dir);
73 * fsnotify_nameremove - a filename was removed from a directory
75 static inline void fsnotify_nameremove(struct dentry *dentry, int isdir)
77 if (isdir)
78 isdir = IN_ISDIR;
79 dnotify_parent(dentry, DN_DELETE);
80 inotify_dentry_parent_queue_event(dentry, IN_DELETE|isdir, 0, dentry->d_name.name);
84 * fsnotify_inoderemove - an inode is going away
86 static inline void fsnotify_inoderemove(struct inode *inode)
88 inotify_inode_queue_event(inode, IN_DELETE_SELF, 0, NULL, NULL);
89 inotify_inode_is_dead(inode);
93 * fsnotify_link_count - inode's link count changed
95 static inline void fsnotify_link_count(struct inode *inode)
97 inotify_inode_queue_event(inode, IN_ATTRIB, 0, NULL, NULL);
101 * fsnotify_create - 'name' was linked in
103 static inline void fsnotify_create(struct inode *inode, struct dentry *dentry)
105 inode_dir_notify(inode, DN_CREATE);
106 inotify_inode_queue_event(inode, IN_CREATE, 0, dentry->d_name.name,
107 dentry->d_inode);
108 audit_inode_child(dentry->d_name.name, dentry, inode);
112 * fsnotify_link - new hardlink in 'inode' directory
113 * Note: We have to pass also the linked inode ptr as some filesystems leave
114 * new_dentry->d_inode NULL and instantiate inode pointer later
116 static inline void fsnotify_link(struct inode *dir, struct inode *inode, struct dentry *new_dentry)
118 inode_dir_notify(dir, DN_CREATE);
119 inotify_inode_queue_event(dir, IN_CREATE, 0, new_dentry->d_name.name,
120 inode);
121 fsnotify_link_count(inode);
122 audit_inode_child(new_dentry->d_name.name, new_dentry, dir);
126 * fsnotify_mkdir - directory 'name' was created
128 static inline void fsnotify_mkdir(struct inode *inode, struct dentry *dentry)
130 inode_dir_notify(inode, DN_CREATE);
131 inotify_inode_queue_event(inode, IN_CREATE | IN_ISDIR, 0,
132 dentry->d_name.name, dentry->d_inode);
133 audit_inode_child(dentry->d_name.name, dentry, inode);
137 * fsnotify_access - file was read
139 static inline void fsnotify_access(struct dentry *dentry)
141 struct inode *inode = dentry->d_inode;
142 u32 mask = IN_ACCESS;
144 if (S_ISDIR(inode->i_mode))
145 mask |= IN_ISDIR;
147 dnotify_parent(dentry, DN_ACCESS);
148 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
149 inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
153 * fsnotify_modify - file was modified
155 static inline void fsnotify_modify(struct dentry *dentry)
157 struct inode *inode = dentry->d_inode;
158 u32 mask = IN_MODIFY;
160 if (S_ISDIR(inode->i_mode))
161 mask |= IN_ISDIR;
163 dnotify_parent(dentry, DN_MODIFY);
164 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
165 inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
169 * fsnotify_open - file was opened
171 static inline void fsnotify_open(struct dentry *dentry)
173 struct inode *inode = dentry->d_inode;
174 u32 mask = IN_OPEN;
176 if (S_ISDIR(inode->i_mode))
177 mask |= IN_ISDIR;
179 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
180 inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
184 * fsnotify_close - file was closed
186 static inline void fsnotify_close(struct file *file)
188 struct dentry *dentry = file->f_path.dentry;
189 struct inode *inode = dentry->d_inode;
190 const char *name = dentry->d_name.name;
191 mode_t mode = file->f_mode;
192 u32 mask = (mode & FMODE_WRITE) ? IN_CLOSE_WRITE : IN_CLOSE_NOWRITE;
194 if (S_ISDIR(inode->i_mode))
195 mask |= IN_ISDIR;
197 inotify_dentry_parent_queue_event(dentry, mask, 0, name);
198 inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
202 * fsnotify_xattr - extended attributes were changed
204 static inline void fsnotify_xattr(struct dentry *dentry)
206 struct inode *inode = dentry->d_inode;
207 u32 mask = IN_ATTRIB;
209 if (S_ISDIR(inode->i_mode))
210 mask |= IN_ISDIR;
212 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
213 inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
217 * fsnotify_change - notify_change event. file was modified and/or metadata
218 * was changed.
220 static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
222 struct inode *inode = dentry->d_inode;
223 int dn_mask = 0;
224 u32 in_mask = 0;
226 if (ia_valid & ATTR_UID) {
227 in_mask |= IN_ATTRIB;
228 dn_mask |= DN_ATTRIB;
230 if (ia_valid & ATTR_GID) {
231 in_mask |= IN_ATTRIB;
232 dn_mask |= DN_ATTRIB;
234 if (ia_valid & ATTR_SIZE) {
235 in_mask |= IN_MODIFY;
236 dn_mask |= DN_MODIFY;
238 /* both times implies a utime(s) call */
239 if ((ia_valid & (ATTR_ATIME | ATTR_MTIME)) == (ATTR_ATIME | ATTR_MTIME))
241 in_mask |= IN_ATTRIB;
242 dn_mask |= DN_ATTRIB;
243 } else if (ia_valid & ATTR_ATIME) {
244 in_mask |= IN_ACCESS;
245 dn_mask |= DN_ACCESS;
246 } else if (ia_valid & ATTR_MTIME) {
247 in_mask |= IN_MODIFY;
248 dn_mask |= DN_MODIFY;
250 if (ia_valid & ATTR_MODE) {
251 in_mask |= IN_ATTRIB;
252 dn_mask |= DN_ATTRIB;
255 if (dn_mask)
256 dnotify_parent(dentry, dn_mask);
257 if (in_mask) {
258 if (S_ISDIR(inode->i_mode))
259 in_mask |= IN_ISDIR;
260 inotify_inode_queue_event(inode, in_mask, 0, NULL, NULL);
261 inotify_dentry_parent_queue_event(dentry, in_mask, 0,
262 dentry->d_name.name);
266 #ifdef CONFIG_INOTIFY /* inotify helpers */
269 * fsnotify_oldname_init - save off the old filename before we change it
271 static inline const char *fsnotify_oldname_init(const char *name)
273 return kstrdup(name, GFP_KERNEL);
277 * fsnotify_oldname_free - free the name we got from fsnotify_oldname_init
279 static inline void fsnotify_oldname_free(const char *old_name)
281 kfree(old_name);
284 #else /* CONFIG_INOTIFY */
286 static inline const char *fsnotify_oldname_init(const char *name)
288 return NULL;
291 static inline void fsnotify_oldname_free(const char *old_name)
295 #endif /* ! CONFIG_INOTIFY */
297 #endif /* _LINUX_FS_NOTIFY_H */