Merge branch 'for-linus' of git://oss.sgi.com:8090/xfs/xfs-2.6
[deliverable/linux.git] / include / linux / fsnotify.h
1 #ifndef _LINUX_FS_NOTIFY_H
2 #define _LINUX_FS_NOTIFY_H
3
4 /*
5 * include/linux/fsnotify.h - generic hooks for filesystem notification, to
6 * reduce in-source duplication from both dnotify and inotify.
7 *
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.
10 *
11 * (C) Copyright 2005 Robert Love
12 */
13
14 #ifdef __KERNEL__
15
16 #include <linux/dnotify.h>
17 #include <linux/inotify.h>
18 #include <linux/audit.h>
19
20 /*
21 * fsnotify_d_instantiate - instantiate a dentry for inode
22 * Called with dcache_lock held.
23 */
24 static inline void fsnotify_d_instantiate(struct dentry *entry,
25 struct inode *inode)
26 {
27 inotify_d_instantiate(entry, inode);
28 }
29
30 /*
31 * fsnotify_d_move - entry has been moved
32 * Called with dcache_lock and entry->d_lock held.
33 */
34 static inline void fsnotify_d_move(struct dentry *entry)
35 {
36 inotify_d_move(entry);
37 }
38
39 /*
40 * fsnotify_move - file old_name at old_dir was moved to new_name at new_dir
41 */
42 static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir,
43 const char *old_name, const char *new_name,
44 int isdir, struct inode *target, struct dentry *moved)
45 {
46 struct inode *source = moved->d_inode;
47 u32 cookie = inotify_get_cookie();
48
49 if (old_dir == new_dir)
50 inode_dir_notify(old_dir, DN_RENAME);
51 else {
52 inode_dir_notify(old_dir, DN_DELETE);
53 inode_dir_notify(new_dir, DN_CREATE);
54 }
55
56 if (isdir)
57 isdir = IN_ISDIR;
58 inotify_inode_queue_event(old_dir, IN_MOVED_FROM|isdir,cookie,old_name,
59 source);
60 inotify_inode_queue_event(new_dir, IN_MOVED_TO|isdir, cookie, new_name,
61 source);
62
63 if (target) {
64 inotify_inode_queue_event(target, IN_DELETE_SELF, 0, NULL, NULL);
65 inotify_inode_is_dead(target);
66 }
67
68 if (source) {
69 inotify_inode_queue_event(source, IN_MOVE_SELF, 0, NULL, NULL);
70 }
71 audit_inode_child(new_name, moved, new_dir);
72 }
73
74 /*
75 * fsnotify_nameremove - a filename was removed from a directory
76 */
77 static inline void fsnotify_nameremove(struct dentry *dentry, int isdir)
78 {
79 if (isdir)
80 isdir = IN_ISDIR;
81 dnotify_parent(dentry, DN_DELETE);
82 inotify_dentry_parent_queue_event(dentry, IN_DELETE|isdir, 0, dentry->d_name.name);
83 }
84
85 /*
86 * fsnotify_inoderemove - an inode is going away
87 */
88 static inline void fsnotify_inoderemove(struct inode *inode)
89 {
90 inotify_inode_queue_event(inode, IN_DELETE_SELF, 0, NULL, NULL);
91 inotify_inode_is_dead(inode);
92 }
93
94 /*
95 * fsnotify_create - 'name' was linked in
96 */
97 static inline void fsnotify_create(struct inode *inode, struct dentry *dentry)
98 {
99 inode_dir_notify(inode, DN_CREATE);
100 inotify_inode_queue_event(inode, IN_CREATE, 0, dentry->d_name.name,
101 dentry->d_inode);
102 audit_inode_child(dentry->d_name.name, dentry, inode);
103 }
104
105 /*
106 * fsnotify_mkdir - directory 'name' was created
107 */
108 static inline void fsnotify_mkdir(struct inode *inode, struct dentry *dentry)
109 {
110 inode_dir_notify(inode, DN_CREATE);
111 inotify_inode_queue_event(inode, IN_CREATE | IN_ISDIR, 0,
112 dentry->d_name.name, dentry->d_inode);
113 audit_inode_child(dentry->d_name.name, dentry, inode);
114 }
115
116 /*
117 * fsnotify_access - file was read
118 */
119 static inline void fsnotify_access(struct dentry *dentry)
120 {
121 struct inode *inode = dentry->d_inode;
122 u32 mask = IN_ACCESS;
123
124 if (S_ISDIR(inode->i_mode))
125 mask |= IN_ISDIR;
126
127 dnotify_parent(dentry, DN_ACCESS);
128 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
129 inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
130 }
131
132 /*
133 * fsnotify_modify - file was modified
134 */
135 static inline void fsnotify_modify(struct dentry *dentry)
136 {
137 struct inode *inode = dentry->d_inode;
138 u32 mask = IN_MODIFY;
139
140 if (S_ISDIR(inode->i_mode))
141 mask |= IN_ISDIR;
142
143 dnotify_parent(dentry, DN_MODIFY);
144 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
145 inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
146 }
147
148 /*
149 * fsnotify_open - file was opened
150 */
151 static inline void fsnotify_open(struct dentry *dentry)
152 {
153 struct inode *inode = dentry->d_inode;
154 u32 mask = IN_OPEN;
155
156 if (S_ISDIR(inode->i_mode))
157 mask |= IN_ISDIR;
158
159 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
160 inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
161 }
162
163 /*
164 * fsnotify_close - file was closed
165 */
166 static inline void fsnotify_close(struct file *file)
167 {
168 struct dentry *dentry = file->f_path.dentry;
169 struct inode *inode = dentry->d_inode;
170 const char *name = dentry->d_name.name;
171 mode_t mode = file->f_mode;
172 u32 mask = (mode & FMODE_WRITE) ? IN_CLOSE_WRITE : IN_CLOSE_NOWRITE;
173
174 if (S_ISDIR(inode->i_mode))
175 mask |= IN_ISDIR;
176
177 inotify_dentry_parent_queue_event(dentry, mask, 0, name);
178 inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
179 }
180
181 /*
182 * fsnotify_xattr - extended attributes were changed
183 */
184 static inline void fsnotify_xattr(struct dentry *dentry)
185 {
186 struct inode *inode = dentry->d_inode;
187 u32 mask = IN_ATTRIB;
188
189 if (S_ISDIR(inode->i_mode))
190 mask |= IN_ISDIR;
191
192 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
193 inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
194 }
195
196 /*
197 * fsnotify_change - notify_change event. file was modified and/or metadata
198 * was changed.
199 */
200 static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
201 {
202 struct inode *inode = dentry->d_inode;
203 int dn_mask = 0;
204 u32 in_mask = 0;
205
206 if (ia_valid & ATTR_UID) {
207 in_mask |= IN_ATTRIB;
208 dn_mask |= DN_ATTRIB;
209 }
210 if (ia_valid & ATTR_GID) {
211 in_mask |= IN_ATTRIB;
212 dn_mask |= DN_ATTRIB;
213 }
214 if (ia_valid & ATTR_SIZE) {
215 in_mask |= IN_MODIFY;
216 dn_mask |= DN_MODIFY;
217 }
218 /* both times implies a utime(s) call */
219 if ((ia_valid & (ATTR_ATIME | ATTR_MTIME)) == (ATTR_ATIME | ATTR_MTIME))
220 {
221 in_mask |= IN_ATTRIB;
222 dn_mask |= DN_ATTRIB;
223 } else if (ia_valid & ATTR_ATIME) {
224 in_mask |= IN_ACCESS;
225 dn_mask |= DN_ACCESS;
226 } else if (ia_valid & ATTR_MTIME) {
227 in_mask |= IN_MODIFY;
228 dn_mask |= DN_MODIFY;
229 }
230 if (ia_valid & ATTR_MODE) {
231 in_mask |= IN_ATTRIB;
232 dn_mask |= DN_ATTRIB;
233 }
234
235 if (dn_mask)
236 dnotify_parent(dentry, dn_mask);
237 if (in_mask) {
238 if (S_ISDIR(inode->i_mode))
239 in_mask |= IN_ISDIR;
240 inotify_inode_queue_event(inode, in_mask, 0, NULL, NULL);
241 inotify_dentry_parent_queue_event(dentry, in_mask, 0,
242 dentry->d_name.name);
243 }
244 }
245
246 #ifdef CONFIG_INOTIFY /* inotify helpers */
247
248 /*
249 * fsnotify_oldname_init - save off the old filename before we change it
250 */
251 static inline const char *fsnotify_oldname_init(const char *name)
252 {
253 return kstrdup(name, GFP_KERNEL);
254 }
255
256 /*
257 * fsnotify_oldname_free - free the name we got from fsnotify_oldname_init
258 */
259 static inline void fsnotify_oldname_free(const char *old_name)
260 {
261 kfree(old_name);
262 }
263
264 #else /* CONFIG_INOTIFY */
265
266 static inline const char *fsnotify_oldname_init(const char *name)
267 {
268 return NULL;
269 }
270
271 static inline void fsnotify_oldname_free(const char *old_name)
272 {
273 }
274
275 #endif /* ! CONFIG_INOTIFY */
276
277 #endif /* __KERNEL__ */
278
279 #endif /* _LINUX_FS_NOTIFY_H */
This page took 0.03816 seconds and 6 git commands to generate.