1 #ifndef _LINUX_FS_NOTIFY_H
2 #define _LINUX_FS_NOTIFY_H
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
16 #include <linux/dnotify.h>
17 #include <linux/inotify.h>
18 #include <linux/audit.h>
21 * fsnotify_d_instantiate - instantiate a dentry for inode
22 * Called with dcache_lock held.
24 static inline void fsnotify_d_instantiate(struct dentry
*entry
,
27 inotify_d_instantiate(entry
, inode
);
31 * fsnotify_d_move - entry has been moved
32 * Called with dcache_lock and entry->d_lock held.
34 static inline void fsnotify_d_move(struct dentry
*entry
)
36 inotify_d_move(entry
);
40 * fsnotify_move - file old_name at old_dir was moved to new_name at new_dir
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
)
46 struct inode
*source
= moved
->d_inode
;
47 u32 cookie
= inotify_get_cookie();
49 if (old_dir
== new_dir
)
50 inode_dir_notify(old_dir
, DN_RENAME
);
52 inode_dir_notify(old_dir
, DN_DELETE
);
53 inode_dir_notify(new_dir
, DN_CREATE
);
58 inotify_inode_queue_event(old_dir
, IN_MOVED_FROM
|isdir
,cookie
,old_name
,
60 inotify_inode_queue_event(new_dir
, IN_MOVED_TO
|isdir
, cookie
, new_name
,
64 inotify_inode_queue_event(target
, IN_DELETE_SELF
, 0, NULL
, NULL
);
65 inotify_inode_is_dead(target
);
69 inotify_inode_queue_event(source
, IN_MOVE_SELF
, 0, NULL
, NULL
);
71 audit_inode_child(new_name
, moved
, new_dir
);
75 * fsnotify_nameremove - a filename was removed from a directory
77 static inline void fsnotify_nameremove(struct dentry
*dentry
, int isdir
)
81 dnotify_parent(dentry
, DN_DELETE
);
82 inotify_dentry_parent_queue_event(dentry
, IN_DELETE
|isdir
, 0, dentry
->d_name
.name
);
86 * fsnotify_inoderemove - an inode is going away
88 static inline void fsnotify_inoderemove(struct inode
*inode
)
90 inotify_inode_queue_event(inode
, IN_DELETE_SELF
, 0, NULL
, NULL
);
91 inotify_inode_is_dead(inode
);
95 * fsnotify_link_count - inode's link count changed
97 static inline void fsnotify_link_count(struct inode
*inode
)
99 inotify_inode_queue_event(inode
, IN_ATTRIB
, 0, NULL
, NULL
);
103 * fsnotify_create - 'name' was linked in
105 static inline void fsnotify_create(struct inode
*inode
, struct dentry
*dentry
)
107 inode_dir_notify(inode
, DN_CREATE
);
108 inotify_inode_queue_event(inode
, IN_CREATE
, 0, dentry
->d_name
.name
,
110 audit_inode_child(dentry
->d_name
.name
, dentry
, inode
);
114 * fsnotify_link - new hardlink in 'inode' directory
115 * Note: We have to pass also the linked inode ptr as some filesystems leave
116 * new_dentry->d_inode NULL and instantiate inode pointer later
118 static inline void fsnotify_link(struct inode
*dir
, struct inode
*inode
, struct dentry
*new_dentry
)
120 inode_dir_notify(dir
, DN_CREATE
);
121 inotify_inode_queue_event(dir
, IN_CREATE
, 0, new_dentry
->d_name
.name
,
123 fsnotify_link_count(inode
);
124 audit_inode_child(new_dentry
->d_name
.name
, new_dentry
, dir
);
128 * fsnotify_mkdir - directory 'name' was created
130 static inline void fsnotify_mkdir(struct inode
*inode
, struct dentry
*dentry
)
132 inode_dir_notify(inode
, DN_CREATE
);
133 inotify_inode_queue_event(inode
, IN_CREATE
| IN_ISDIR
, 0,
134 dentry
->d_name
.name
, dentry
->d_inode
);
135 audit_inode_child(dentry
->d_name
.name
, dentry
, inode
);
139 * fsnotify_access - file was read
141 static inline void fsnotify_access(struct dentry
*dentry
)
143 struct inode
*inode
= dentry
->d_inode
;
144 u32 mask
= IN_ACCESS
;
146 if (S_ISDIR(inode
->i_mode
))
149 dnotify_parent(dentry
, DN_ACCESS
);
150 inotify_dentry_parent_queue_event(dentry
, mask
, 0, dentry
->d_name
.name
);
151 inotify_inode_queue_event(inode
, mask
, 0, NULL
, NULL
);
155 * fsnotify_modify - file was modified
157 static inline void fsnotify_modify(struct dentry
*dentry
)
159 struct inode
*inode
= dentry
->d_inode
;
160 u32 mask
= IN_MODIFY
;
162 if (S_ISDIR(inode
->i_mode
))
165 dnotify_parent(dentry
, DN_MODIFY
);
166 inotify_dentry_parent_queue_event(dentry
, mask
, 0, dentry
->d_name
.name
);
167 inotify_inode_queue_event(inode
, mask
, 0, NULL
, NULL
);
171 * fsnotify_open - file was opened
173 static inline void fsnotify_open(struct dentry
*dentry
)
175 struct inode
*inode
= dentry
->d_inode
;
178 if (S_ISDIR(inode
->i_mode
))
181 inotify_dentry_parent_queue_event(dentry
, mask
, 0, dentry
->d_name
.name
);
182 inotify_inode_queue_event(inode
, mask
, 0, NULL
, NULL
);
186 * fsnotify_close - file was closed
188 static inline void fsnotify_close(struct file
*file
)
190 struct dentry
*dentry
= file
->f_path
.dentry
;
191 struct inode
*inode
= dentry
->d_inode
;
192 const char *name
= dentry
->d_name
.name
;
193 mode_t mode
= file
->f_mode
;
194 u32 mask
= (mode
& FMODE_WRITE
) ? IN_CLOSE_WRITE
: IN_CLOSE_NOWRITE
;
196 if (S_ISDIR(inode
->i_mode
))
199 inotify_dentry_parent_queue_event(dentry
, mask
, 0, name
);
200 inotify_inode_queue_event(inode
, mask
, 0, NULL
, NULL
);
204 * fsnotify_xattr - extended attributes were changed
206 static inline void fsnotify_xattr(struct dentry
*dentry
)
208 struct inode
*inode
= dentry
->d_inode
;
209 u32 mask
= IN_ATTRIB
;
211 if (S_ISDIR(inode
->i_mode
))
214 inotify_dentry_parent_queue_event(dentry
, mask
, 0, dentry
->d_name
.name
);
215 inotify_inode_queue_event(inode
, mask
, 0, NULL
, NULL
);
219 * fsnotify_change - notify_change event. file was modified and/or metadata
222 static inline void fsnotify_change(struct dentry
*dentry
, unsigned int ia_valid
)
224 struct inode
*inode
= dentry
->d_inode
;
228 if (ia_valid
& ATTR_UID
) {
229 in_mask
|= IN_ATTRIB
;
230 dn_mask
|= DN_ATTRIB
;
232 if (ia_valid
& ATTR_GID
) {
233 in_mask
|= IN_ATTRIB
;
234 dn_mask
|= DN_ATTRIB
;
236 if (ia_valid
& ATTR_SIZE
) {
237 in_mask
|= IN_MODIFY
;
238 dn_mask
|= DN_MODIFY
;
240 /* both times implies a utime(s) call */
241 if ((ia_valid
& (ATTR_ATIME
| ATTR_MTIME
)) == (ATTR_ATIME
| ATTR_MTIME
))
243 in_mask
|= IN_ATTRIB
;
244 dn_mask
|= DN_ATTRIB
;
245 } else if (ia_valid
& ATTR_ATIME
) {
246 in_mask
|= IN_ACCESS
;
247 dn_mask
|= DN_ACCESS
;
248 } else if (ia_valid
& ATTR_MTIME
) {
249 in_mask
|= IN_MODIFY
;
250 dn_mask
|= DN_MODIFY
;
252 if (ia_valid
& ATTR_MODE
) {
253 in_mask
|= IN_ATTRIB
;
254 dn_mask
|= DN_ATTRIB
;
258 dnotify_parent(dentry
, dn_mask
);
260 if (S_ISDIR(inode
->i_mode
))
262 inotify_inode_queue_event(inode
, in_mask
, 0, NULL
, NULL
);
263 inotify_dentry_parent_queue_event(dentry
, in_mask
, 0,
264 dentry
->d_name
.name
);
268 #ifdef CONFIG_INOTIFY /* inotify helpers */
271 * fsnotify_oldname_init - save off the old filename before we change it
273 static inline const char *fsnotify_oldname_init(const char *name
)
275 return kstrdup(name
, GFP_KERNEL
);
279 * fsnotify_oldname_free - free the name we got from fsnotify_oldname_init
281 static inline void fsnotify_oldname_free(const char *old_name
)
286 #else /* CONFIG_INOTIFY */
288 static inline const char *fsnotify_oldname_init(const char *name
)
293 static inline void fsnotify_oldname_free(const char *old_name
)
297 #endif /* ! CONFIG_INOTIFY */
299 #endif /* __KERNEL__ */
301 #endif /* _LINUX_FS_NOTIFY_H */