diff options
Diffstat (limited to 'include/linux/fsnotify.h')
-rw-r--r-- | include/linux/fsnotify.h | 199 |
1 files changed, 120 insertions, 79 deletions
diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index 00fbd5b245c9..936f9aa8bb97 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h | |||
@@ -13,6 +13,7 @@ | |||
13 | 13 | ||
14 | #include <linux/dnotify.h> | 14 | #include <linux/dnotify.h> |
15 | #include <linux/inotify.h> | 15 | #include <linux/inotify.h> |
16 | #include <linux/fsnotify_backend.h> | ||
16 | #include <linux/audit.h> | 17 | #include <linux/audit.h> |
17 | 18 | ||
18 | /* | 19 | /* |
@@ -22,19 +23,45 @@ | |||
22 | static inline void fsnotify_d_instantiate(struct dentry *entry, | 23 | static inline void fsnotify_d_instantiate(struct dentry *entry, |
23 | struct inode *inode) | 24 | struct inode *inode) |
24 | { | 25 | { |
26 | __fsnotify_d_instantiate(entry, inode); | ||
27 | |||
25 | inotify_d_instantiate(entry, inode); | 28 | inotify_d_instantiate(entry, inode); |
26 | } | 29 | } |
27 | 30 | ||
31 | /* Notify this dentry's parent about a child's events. */ | ||
32 | static inline void fsnotify_parent(struct dentry *dentry, __u32 mask) | ||
33 | { | ||
34 | __fsnotify_parent(dentry, mask); | ||
35 | |||
36 | inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name); | ||
37 | } | ||
38 | |||
28 | /* | 39 | /* |
29 | * fsnotify_d_move - entry has been moved | 40 | * fsnotify_d_move - entry has been moved |
30 | * Called with dcache_lock and entry->d_lock held. | 41 | * Called with dcache_lock and entry->d_lock held. |
31 | */ | 42 | */ |
32 | static inline void fsnotify_d_move(struct dentry *entry) | 43 | static inline void fsnotify_d_move(struct dentry *entry) |
33 | { | 44 | { |
45 | /* | ||
46 | * On move we need to update entry->d_flags to indicate if the new parent | ||
47 | * cares about events from this entry. | ||
48 | */ | ||
49 | __fsnotify_update_dcache_flags(entry); | ||
50 | |||
34 | inotify_d_move(entry); | 51 | inotify_d_move(entry); |
35 | } | 52 | } |
36 | 53 | ||
37 | /* | 54 | /* |
55 | * fsnotify_link_count - inode's link count changed | ||
56 | */ | ||
57 | static inline void fsnotify_link_count(struct inode *inode) | ||
58 | { | ||
59 | inotify_inode_queue_event(inode, IN_ATTRIB, 0, NULL, NULL); | ||
60 | |||
61 | fsnotify(inode, FS_ATTRIB, inode, FSNOTIFY_EVENT_INODE, NULL, 0); | ||
62 | } | ||
63 | |||
64 | /* | ||
38 | * fsnotify_move - file old_name at old_dir was moved to new_name at new_dir | 65 | * fsnotify_move - file old_name at old_dir was moved to new_name at new_dir |
39 | */ | 66 | */ |
40 | static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir, | 67 | static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir, |
@@ -42,42 +69,62 @@ static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir, | |||
42 | int isdir, struct inode *target, struct dentry *moved) | 69 | int isdir, struct inode *target, struct dentry *moved) |
43 | { | 70 | { |
44 | struct inode *source = moved->d_inode; | 71 | struct inode *source = moved->d_inode; |
45 | u32 cookie = inotify_get_cookie(); | 72 | u32 in_cookie = inotify_get_cookie(); |
73 | u32 fs_cookie = fsnotify_get_cookie(); | ||
74 | __u32 old_dir_mask = (FS_EVENT_ON_CHILD | FS_MOVED_FROM); | ||
75 | __u32 new_dir_mask = (FS_EVENT_ON_CHILD | FS_MOVED_TO); | ||
46 | 76 | ||
47 | if (old_dir == new_dir) | 77 | if (old_dir == new_dir) |
48 | inode_dir_notify(old_dir, DN_RENAME); | 78 | old_dir_mask |= FS_DN_RENAME; |
49 | else { | ||
50 | inode_dir_notify(old_dir, DN_DELETE); | ||
51 | inode_dir_notify(new_dir, DN_CREATE); | ||
52 | } | ||
53 | 79 | ||
54 | if (isdir) | 80 | if (isdir) { |
55 | isdir = IN_ISDIR; | 81 | isdir = IN_ISDIR; |
56 | inotify_inode_queue_event(old_dir, IN_MOVED_FROM|isdir,cookie,old_name, | 82 | old_dir_mask |= FS_IN_ISDIR; |
83 | new_dir_mask |= FS_IN_ISDIR; | ||
84 | } | ||
85 | |||
86 | inotify_inode_queue_event(old_dir, IN_MOVED_FROM|isdir, in_cookie, old_name, | ||
57 | source); | 87 | source); |
58 | inotify_inode_queue_event(new_dir, IN_MOVED_TO|isdir, cookie, new_name, | 88 | inotify_inode_queue_event(new_dir, IN_MOVED_TO|isdir, in_cookie, new_name, |
59 | source); | 89 | source); |
60 | 90 | ||
91 | fsnotify(old_dir, old_dir_mask, old_dir, FSNOTIFY_EVENT_INODE, old_name, fs_cookie); | ||
92 | fsnotify(new_dir, new_dir_mask, new_dir, FSNOTIFY_EVENT_INODE, new_name, fs_cookie); | ||
93 | |||
61 | if (target) { | 94 | if (target) { |
62 | inotify_inode_queue_event(target, IN_DELETE_SELF, 0, NULL, NULL); | 95 | inotify_inode_queue_event(target, IN_DELETE_SELF, 0, NULL, NULL); |
63 | inotify_inode_is_dead(target); | 96 | inotify_inode_is_dead(target); |
97 | |||
98 | /* this is really a link_count change not a removal */ | ||
99 | fsnotify_link_count(target); | ||
64 | } | 100 | } |
65 | 101 | ||
66 | if (source) { | 102 | if (source) { |
67 | inotify_inode_queue_event(source, IN_MOVE_SELF, 0, NULL, NULL); | 103 | inotify_inode_queue_event(source, IN_MOVE_SELF, 0, NULL, NULL); |
104 | fsnotify(source, FS_MOVE_SELF, moved->d_inode, FSNOTIFY_EVENT_INODE, NULL, 0); | ||
68 | } | 105 | } |
69 | audit_inode_child(new_name, moved, new_dir); | 106 | audit_inode_child(new_name, moved, new_dir); |
70 | } | 107 | } |
71 | 108 | ||
72 | /* | 109 | /* |
110 | * fsnotify_inode_delete - and inode is being evicted from cache, clean up is needed | ||
111 | */ | ||
112 | static inline void fsnotify_inode_delete(struct inode *inode) | ||
113 | { | ||
114 | __fsnotify_inode_delete(inode); | ||
115 | } | ||
116 | |||
117 | /* | ||
73 | * fsnotify_nameremove - a filename was removed from a directory | 118 | * fsnotify_nameremove - a filename was removed from a directory |
74 | */ | 119 | */ |
75 | static inline void fsnotify_nameremove(struct dentry *dentry, int isdir) | 120 | static inline void fsnotify_nameremove(struct dentry *dentry, int isdir) |
76 | { | 121 | { |
122 | __u32 mask = FS_DELETE; | ||
123 | |||
77 | if (isdir) | 124 | if (isdir) |
78 | isdir = IN_ISDIR; | 125 | mask |= FS_IN_ISDIR; |
79 | dnotify_parent(dentry, DN_DELETE); | 126 | |
80 | inotify_dentry_parent_queue_event(dentry, IN_DELETE|isdir, 0, dentry->d_name.name); | 127 | fsnotify_parent(dentry, mask); |
81 | } | 128 | } |
82 | 129 | ||
83 | /* | 130 | /* |
@@ -87,14 +134,9 @@ static inline void fsnotify_inoderemove(struct inode *inode) | |||
87 | { | 134 | { |
88 | inotify_inode_queue_event(inode, IN_DELETE_SELF, 0, NULL, NULL); | 135 | inotify_inode_queue_event(inode, IN_DELETE_SELF, 0, NULL, NULL); |
89 | inotify_inode_is_dead(inode); | 136 | inotify_inode_is_dead(inode); |
90 | } | ||
91 | 137 | ||
92 | /* | 138 | fsnotify(inode, FS_DELETE_SELF, inode, FSNOTIFY_EVENT_INODE, NULL, 0); |
93 | * fsnotify_link_count - inode's link count changed | 139 | __fsnotify_inode_delete(inode); |
94 | */ | ||
95 | static inline void fsnotify_link_count(struct inode *inode) | ||
96 | { | ||
97 | inotify_inode_queue_event(inode, IN_ATTRIB, 0, NULL, NULL); | ||
98 | } | 140 | } |
99 | 141 | ||
100 | /* | 142 | /* |
@@ -102,10 +144,11 @@ static inline void fsnotify_link_count(struct inode *inode) | |||
102 | */ | 144 | */ |
103 | static inline void fsnotify_create(struct inode *inode, struct dentry *dentry) | 145 | static inline void fsnotify_create(struct inode *inode, struct dentry *dentry) |
104 | { | 146 | { |
105 | inode_dir_notify(inode, DN_CREATE); | ||
106 | inotify_inode_queue_event(inode, IN_CREATE, 0, dentry->d_name.name, | 147 | inotify_inode_queue_event(inode, IN_CREATE, 0, dentry->d_name.name, |
107 | dentry->d_inode); | 148 | dentry->d_inode); |
108 | audit_inode_child(dentry->d_name.name, dentry, inode); | 149 | audit_inode_child(dentry->d_name.name, dentry, inode); |
150 | |||
151 | fsnotify(inode, FS_CREATE, dentry->d_inode, FSNOTIFY_EVENT_INODE, dentry->d_name.name, 0); | ||
109 | } | 152 | } |
110 | 153 | ||
111 | /* | 154 | /* |
@@ -115,11 +158,12 @@ static inline void fsnotify_create(struct inode *inode, struct dentry *dentry) | |||
115 | */ | 158 | */ |
116 | static inline void fsnotify_link(struct inode *dir, struct inode *inode, struct dentry *new_dentry) | 159 | static inline void fsnotify_link(struct inode *dir, struct inode *inode, struct dentry *new_dentry) |
117 | { | 160 | { |
118 | inode_dir_notify(dir, DN_CREATE); | ||
119 | inotify_inode_queue_event(dir, IN_CREATE, 0, new_dentry->d_name.name, | 161 | inotify_inode_queue_event(dir, IN_CREATE, 0, new_dentry->d_name.name, |
120 | inode); | 162 | inode); |
121 | fsnotify_link_count(inode); | 163 | fsnotify_link_count(inode); |
122 | audit_inode_child(new_dentry->d_name.name, new_dentry, dir); | 164 | audit_inode_child(new_dentry->d_name.name, new_dentry, dir); |
165 | |||
166 | fsnotify(dir, FS_CREATE, inode, FSNOTIFY_EVENT_INODE, new_dentry->d_name.name, 0); | ||
123 | } | 167 | } |
124 | 168 | ||
125 | /* | 169 | /* |
@@ -127,10 +171,13 @@ static inline void fsnotify_link(struct inode *dir, struct inode *inode, struct | |||
127 | */ | 171 | */ |
128 | static inline void fsnotify_mkdir(struct inode *inode, struct dentry *dentry) | 172 | static inline void fsnotify_mkdir(struct inode *inode, struct dentry *dentry) |
129 | { | 173 | { |
130 | inode_dir_notify(inode, DN_CREATE); | 174 | __u32 mask = (FS_CREATE | FS_IN_ISDIR); |
131 | inotify_inode_queue_event(inode, IN_CREATE | IN_ISDIR, 0, | 175 | struct inode *d_inode = dentry->d_inode; |
132 | dentry->d_name.name, dentry->d_inode); | 176 | |
177 | inotify_inode_queue_event(inode, mask, 0, dentry->d_name.name, d_inode); | ||
133 | audit_inode_child(dentry->d_name.name, dentry, inode); | 178 | audit_inode_child(dentry->d_name.name, dentry, inode); |
179 | |||
180 | fsnotify(inode, mask, d_inode, FSNOTIFY_EVENT_INODE, dentry->d_name.name, 0); | ||
134 | } | 181 | } |
135 | 182 | ||
136 | /* | 183 | /* |
@@ -139,14 +186,15 @@ static inline void fsnotify_mkdir(struct inode *inode, struct dentry *dentry) | |||
139 | static inline void fsnotify_access(struct dentry *dentry) | 186 | static inline void fsnotify_access(struct dentry *dentry) |
140 | { | 187 | { |
141 | struct inode *inode = dentry->d_inode; | 188 | struct inode *inode = dentry->d_inode; |
142 | u32 mask = IN_ACCESS; | 189 | __u32 mask = FS_ACCESS; |
143 | 190 | ||
144 | if (S_ISDIR(inode->i_mode)) | 191 | if (S_ISDIR(inode->i_mode)) |
145 | mask |= IN_ISDIR; | 192 | mask |= FS_IN_ISDIR; |
146 | 193 | ||
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); | 194 | inotify_inode_queue_event(inode, mask, 0, NULL, NULL); |
195 | |||
196 | fsnotify_parent(dentry, mask); | ||
197 | fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0); | ||
150 | } | 198 | } |
151 | 199 | ||
152 | /* | 200 | /* |
@@ -155,14 +203,15 @@ static inline void fsnotify_access(struct dentry *dentry) | |||
155 | static inline void fsnotify_modify(struct dentry *dentry) | 203 | static inline void fsnotify_modify(struct dentry *dentry) |
156 | { | 204 | { |
157 | struct inode *inode = dentry->d_inode; | 205 | struct inode *inode = dentry->d_inode; |
158 | u32 mask = IN_MODIFY; | 206 | __u32 mask = FS_MODIFY; |
159 | 207 | ||
160 | if (S_ISDIR(inode->i_mode)) | 208 | if (S_ISDIR(inode->i_mode)) |
161 | mask |= IN_ISDIR; | 209 | mask |= FS_IN_ISDIR; |
162 | 210 | ||
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); | 211 | inotify_inode_queue_event(inode, mask, 0, NULL, NULL); |
212 | |||
213 | fsnotify_parent(dentry, mask); | ||
214 | fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0); | ||
166 | } | 215 | } |
167 | 216 | ||
168 | /* | 217 | /* |
@@ -171,13 +220,15 @@ static inline void fsnotify_modify(struct dentry *dentry) | |||
171 | static inline void fsnotify_open(struct dentry *dentry) | 220 | static inline void fsnotify_open(struct dentry *dentry) |
172 | { | 221 | { |
173 | struct inode *inode = dentry->d_inode; | 222 | struct inode *inode = dentry->d_inode; |
174 | u32 mask = IN_OPEN; | 223 | __u32 mask = FS_OPEN; |
175 | 224 | ||
176 | if (S_ISDIR(inode->i_mode)) | 225 | if (S_ISDIR(inode->i_mode)) |
177 | mask |= IN_ISDIR; | 226 | mask |= FS_IN_ISDIR; |
178 | 227 | ||
179 | inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name); | ||
180 | inotify_inode_queue_event(inode, mask, 0, NULL, NULL); | 228 | inotify_inode_queue_event(inode, mask, 0, NULL, NULL); |
229 | |||
230 | fsnotify_parent(dentry, mask); | ||
231 | fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0); | ||
181 | } | 232 | } |
182 | 233 | ||
183 | /* | 234 | /* |
@@ -187,15 +238,16 @@ static inline void fsnotify_close(struct file *file) | |||
187 | { | 238 | { |
188 | struct dentry *dentry = file->f_path.dentry; | 239 | struct dentry *dentry = file->f_path.dentry; |
189 | struct inode *inode = dentry->d_inode; | 240 | struct inode *inode = dentry->d_inode; |
190 | const char *name = dentry->d_name.name; | ||
191 | fmode_t mode = file->f_mode; | 241 | fmode_t mode = file->f_mode; |
192 | u32 mask = (mode & FMODE_WRITE) ? IN_CLOSE_WRITE : IN_CLOSE_NOWRITE; | 242 | __u32 mask = (mode & FMODE_WRITE) ? FS_CLOSE_WRITE : FS_CLOSE_NOWRITE; |
193 | 243 | ||
194 | if (S_ISDIR(inode->i_mode)) | 244 | if (S_ISDIR(inode->i_mode)) |
195 | mask |= IN_ISDIR; | 245 | mask |= FS_IN_ISDIR; |
196 | 246 | ||
197 | inotify_dentry_parent_queue_event(dentry, mask, 0, name); | ||
198 | inotify_inode_queue_event(inode, mask, 0, NULL, NULL); | 247 | inotify_inode_queue_event(inode, mask, 0, NULL, NULL); |
248 | |||
249 | fsnotify_parent(dentry, mask); | ||
250 | fsnotify(inode, mask, file, FSNOTIFY_EVENT_FILE, NULL, 0); | ||
199 | } | 251 | } |
200 | 252 | ||
201 | /* | 253 | /* |
@@ -204,13 +256,15 @@ static inline void fsnotify_close(struct file *file) | |||
204 | static inline void fsnotify_xattr(struct dentry *dentry) | 256 | static inline void fsnotify_xattr(struct dentry *dentry) |
205 | { | 257 | { |
206 | struct inode *inode = dentry->d_inode; | 258 | struct inode *inode = dentry->d_inode; |
207 | u32 mask = IN_ATTRIB; | 259 | __u32 mask = FS_ATTRIB; |
208 | 260 | ||
209 | if (S_ISDIR(inode->i_mode)) | 261 | if (S_ISDIR(inode->i_mode)) |
210 | mask |= IN_ISDIR; | 262 | mask |= FS_IN_ISDIR; |
211 | 263 | ||
212 | inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name); | ||
213 | inotify_inode_queue_event(inode, mask, 0, NULL, NULL); | 264 | inotify_inode_queue_event(inode, mask, 0, NULL, NULL); |
265 | |||
266 | fsnotify_parent(dentry, mask); | ||
267 | fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0); | ||
214 | } | 268 | } |
215 | 269 | ||
216 | /* | 270 | /* |
@@ -220,50 +274,37 @@ static inline void fsnotify_xattr(struct dentry *dentry) | |||
220 | static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid) | 274 | static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid) |
221 | { | 275 | { |
222 | struct inode *inode = dentry->d_inode; | 276 | struct inode *inode = dentry->d_inode; |
223 | int dn_mask = 0; | 277 | __u32 mask = 0; |
224 | u32 in_mask = 0; | 278 | |
279 | if (ia_valid & ATTR_UID) | ||
280 | mask |= FS_ATTRIB; | ||
281 | if (ia_valid & ATTR_GID) | ||
282 | mask |= FS_ATTRIB; | ||
283 | if (ia_valid & ATTR_SIZE) | ||
284 | mask |= FS_MODIFY; | ||
225 | 285 | ||
226 | if (ia_valid & ATTR_UID) { | ||
227 | in_mask |= IN_ATTRIB; | ||
228 | dn_mask |= DN_ATTRIB; | ||
229 | } | ||
230 | if (ia_valid & ATTR_GID) { | ||
231 | in_mask |= IN_ATTRIB; | ||
232 | dn_mask |= DN_ATTRIB; | ||
233 | } | ||
234 | if (ia_valid & ATTR_SIZE) { | ||
235 | in_mask |= IN_MODIFY; | ||
236 | dn_mask |= DN_MODIFY; | ||
237 | } | ||
238 | /* both times implies a utime(s) call */ | 286 | /* both times implies a utime(s) call */ |
239 | if ((ia_valid & (ATTR_ATIME | ATTR_MTIME)) == (ATTR_ATIME | ATTR_MTIME)) | 287 | if ((ia_valid & (ATTR_ATIME | ATTR_MTIME)) == (ATTR_ATIME | ATTR_MTIME)) |
240 | { | 288 | mask |= FS_ATTRIB; |
241 | in_mask |= IN_ATTRIB; | 289 | else if (ia_valid & ATTR_ATIME) |
242 | dn_mask |= DN_ATTRIB; | 290 | mask |= FS_ACCESS; |
243 | } else if (ia_valid & ATTR_ATIME) { | 291 | else if (ia_valid & ATTR_MTIME) |
244 | in_mask |= IN_ACCESS; | 292 | mask |= FS_MODIFY; |
245 | dn_mask |= DN_ACCESS; | 293 | |
246 | } else if (ia_valid & ATTR_MTIME) { | 294 | if (ia_valid & ATTR_MODE) |
247 | in_mask |= IN_MODIFY; | 295 | mask |= FS_ATTRIB; |
248 | dn_mask |= DN_MODIFY; | ||
249 | } | ||
250 | if (ia_valid & ATTR_MODE) { | ||
251 | in_mask |= IN_ATTRIB; | ||
252 | dn_mask |= DN_ATTRIB; | ||
253 | } | ||
254 | 296 | ||
255 | if (dn_mask) | 297 | if (mask) { |
256 | dnotify_parent(dentry, dn_mask); | ||
257 | if (in_mask) { | ||
258 | if (S_ISDIR(inode->i_mode)) | 298 | if (S_ISDIR(inode->i_mode)) |
259 | in_mask |= IN_ISDIR; | 299 | mask |= FS_IN_ISDIR; |
260 | inotify_inode_queue_event(inode, in_mask, 0, NULL, NULL); | 300 | inotify_inode_queue_event(inode, mask, 0, NULL, NULL); |
261 | inotify_dentry_parent_queue_event(dentry, in_mask, 0, | 301 | |
262 | dentry->d_name.name); | 302 | fsnotify_parent(dentry, mask); |
303 | fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0); | ||
263 | } | 304 | } |
264 | } | 305 | } |
265 | 306 | ||
266 | #ifdef CONFIG_INOTIFY /* inotify helpers */ | 307 | #if defined(CONFIG_INOTIFY) || defined(CONFIG_FSNOTIFY) /* notify helpers */ |
267 | 308 | ||
268 | /* | 309 | /* |
269 | * fsnotify_oldname_init - save off the old filename before we change it | 310 | * fsnotify_oldname_init - save off the old filename before we change it |
@@ -281,7 +322,7 @@ static inline void fsnotify_oldname_free(const char *old_name) | |||
281 | kfree(old_name); | 322 | kfree(old_name); |
282 | } | 323 | } |
283 | 324 | ||
284 | #else /* CONFIG_INOTIFY */ | 325 | #else /* CONFIG_INOTIFY || CONFIG_FSNOTIFY */ |
285 | 326 | ||
286 | static inline const char *fsnotify_oldname_init(const char *name) | 327 | static inline const char *fsnotify_oldname_init(const char *name) |
287 | { | 328 | { |