[IA64] Spinlock optimizations
[linux-2.6/mini2440.git] / include / linux / fsnotify.h
blob602c305c8585fcb6b175bfd27750fe09ca718da8
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)
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);
47 * fsnotify_nameremove - a filename was removed from a directory
49 static inline void fsnotify_nameremove(struct dentry *dentry, int isdir)
51 if (isdir)
52 isdir = IN_ISDIR;
53 dnotify_parent(dentry, DN_DELETE);
54 inotify_dentry_parent_queue_event(dentry, IN_DELETE|isdir, 0, dentry->d_name.name);
58 * fsnotify_inoderemove - an inode is going away
60 static inline void fsnotify_inoderemove(struct inode *inode)
62 inotify_inode_queue_event(inode, IN_DELETE_SELF, 0, NULL);
63 inotify_inode_is_dead(inode);
67 * fsnotify_create - 'name' was linked in
69 static inline void fsnotify_create(struct inode *inode, const char *name)
71 inode_dir_notify(inode, DN_CREATE);
72 inotify_inode_queue_event(inode, IN_CREATE, 0, name);
76 * fsnotify_mkdir - directory 'name' was created
78 static inline void fsnotify_mkdir(struct inode *inode, const char *name)
80 inode_dir_notify(inode, DN_CREATE);
81 inotify_inode_queue_event(inode, IN_CREATE | IN_ISDIR, 0, name);
85 * fsnotify_access - file was read
87 static inline void fsnotify_access(struct dentry *dentry)
89 struct inode *inode = dentry->d_inode;
90 u32 mask = IN_ACCESS;
92 if (S_ISDIR(inode->i_mode))
93 mask |= IN_ISDIR;
95 dnotify_parent(dentry, DN_ACCESS);
96 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
97 inotify_inode_queue_event(inode, mask, 0, NULL);
101 * fsnotify_modify - file was modified
103 static inline void fsnotify_modify(struct dentry *dentry)
105 struct inode *inode = dentry->d_inode;
106 u32 mask = IN_MODIFY;
108 if (S_ISDIR(inode->i_mode))
109 mask |= IN_ISDIR;
111 dnotify_parent(dentry, DN_MODIFY);
112 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
113 inotify_inode_queue_event(inode, mask, 0, NULL);
117 * fsnotify_open - file was opened
119 static inline void fsnotify_open(struct dentry *dentry)
121 struct inode *inode = dentry->d_inode;
122 u32 mask = IN_OPEN;
124 if (S_ISDIR(inode->i_mode))
125 mask |= IN_ISDIR;
127 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
128 inotify_inode_queue_event(inode, mask, 0, NULL);
132 * fsnotify_close - file was closed
134 static inline void fsnotify_close(struct file *file)
136 struct dentry *dentry = file->f_dentry;
137 struct inode *inode = dentry->d_inode;
138 const char *name = dentry->d_name.name;
139 mode_t mode = file->f_mode;
140 u32 mask = (mode & FMODE_WRITE) ? IN_CLOSE_WRITE : IN_CLOSE_NOWRITE;
142 if (S_ISDIR(inode->i_mode))
143 mask |= IN_ISDIR;
145 inotify_dentry_parent_queue_event(dentry, mask, 0, name);
146 inotify_inode_queue_event(inode, mask, 0, NULL);
150 * fsnotify_xattr - extended attributes were changed
152 static inline void fsnotify_xattr(struct dentry *dentry)
154 struct inode *inode = dentry->d_inode;
155 u32 mask = IN_ATTRIB;
157 if (S_ISDIR(inode->i_mode))
158 mask |= IN_ISDIR;
160 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
161 inotify_inode_queue_event(inode, mask, 0, NULL);
165 * fsnotify_change - notify_change event. file was modified and/or metadata
166 * was changed.
168 static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
170 struct inode *inode = dentry->d_inode;
171 int dn_mask = 0;
172 u32 in_mask = 0;
174 if (ia_valid & ATTR_UID) {
175 in_mask |= IN_ATTRIB;
176 dn_mask |= DN_ATTRIB;
178 if (ia_valid & ATTR_GID) {
179 in_mask |= IN_ATTRIB;
180 dn_mask |= DN_ATTRIB;
182 if (ia_valid & ATTR_SIZE) {
183 in_mask |= IN_MODIFY;
184 dn_mask |= DN_MODIFY;
186 /* both times implies a utime(s) call */
187 if ((ia_valid & (ATTR_ATIME | ATTR_MTIME)) == (ATTR_ATIME | ATTR_MTIME))
189 in_mask |= IN_ATTRIB;
190 dn_mask |= DN_ATTRIB;
191 } else if (ia_valid & ATTR_ATIME) {
192 in_mask |= IN_ACCESS;
193 dn_mask |= DN_ACCESS;
194 } else if (ia_valid & ATTR_MTIME) {
195 in_mask |= IN_MODIFY;
196 dn_mask |= DN_MODIFY;
198 if (ia_valid & ATTR_MODE) {
199 in_mask |= IN_ATTRIB;
200 dn_mask |= DN_ATTRIB;
203 if (dn_mask)
204 dnotify_parent(dentry, dn_mask);
205 if (in_mask) {
206 if (S_ISDIR(inode->i_mode))
207 in_mask |= IN_ISDIR;
208 inotify_inode_queue_event(inode, in_mask, 0, NULL);
209 inotify_dentry_parent_queue_event(dentry, in_mask, 0,
210 dentry->d_name.name);
214 #ifdef CONFIG_INOTIFY /* inotify helpers */
217 * fsnotify_oldname_init - save off the old filename before we change it
219 static inline const char *fsnotify_oldname_init(const char *name)
221 return kstrdup(name, GFP_KERNEL);
225 * fsnotify_oldname_free - free the name we got from fsnotify_oldname_init
227 static inline void fsnotify_oldname_free(const char *old_name)
229 kfree(old_name);
232 #else /* CONFIG_INOTIFY */
234 static inline const char *fsnotify_oldname_init(const char *name)
236 return NULL;
239 static inline void fsnotify_oldname_free(const char *old_name)
243 #endif /* ! CONFIG_INOTIFY */
245 #endif /* __KERNEL__ */
247 #endif /* _LINUX_FS_NOTIFY_H */