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 inode
*source
)
46 u32 cookie
= inotify_get_cookie();
48 if (old_dir
== new_dir
)
49 inode_dir_notify(old_dir
, DN_RENAME
);
51 inode_dir_notify(old_dir
, DN_DELETE
);
52 inode_dir_notify(new_dir
, DN_CREATE
);
57 inotify_inode_queue_event(old_dir
, IN_MOVED_FROM
|isdir
,cookie
,old_name
);
58 inotify_inode_queue_event(new_dir
, IN_MOVED_TO
|isdir
, cookie
, new_name
);
61 inotify_inode_queue_event(target
, IN_DELETE_SELF
, 0, NULL
);
62 inotify_inode_is_dead(target
);
66 inotify_inode_queue_event(source
, IN_MOVE_SELF
, 0, NULL
);
68 audit_inode_child(old_name
, source
, old_dir
->i_ino
);
69 audit_inode_child(new_name
, target
, new_dir
->i_ino
);
73 * fsnotify_nameremove - a filename was removed from a directory
75 static inline void fsnotify_nameremove(struct dentry
*dentry
, int 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
);
89 inotify_inode_is_dead(inode
);
93 * fsnotify_create - 'name' was linked in
95 static inline void fsnotify_create(struct inode
*inode
, struct dentry
*dentry
)
97 inode_dir_notify(inode
, DN_CREATE
);
98 inotify_inode_queue_event(inode
, IN_CREATE
, 0, dentry
->d_name
.name
);
99 audit_inode_child(dentry
->d_name
.name
, dentry
->d_inode
, inode
->i_ino
);
103 * fsnotify_mkdir - directory 'name' was created
105 static inline void fsnotify_mkdir(struct inode
*inode
, struct dentry
*dentry
)
107 inode_dir_notify(inode
, DN_CREATE
);
108 inotify_inode_queue_event(inode
, IN_CREATE
| IN_ISDIR
, 0,
109 dentry
->d_name
.name
);
110 audit_inode_child(dentry
->d_name
.name
, dentry
->d_inode
, inode
->i_ino
);
114 * fsnotify_access - file was read
116 static inline void fsnotify_access(struct dentry
*dentry
)
118 struct inode
*inode
= dentry
->d_inode
;
119 u32 mask
= IN_ACCESS
;
121 if (S_ISDIR(inode
->i_mode
))
124 dnotify_parent(dentry
, DN_ACCESS
);
125 inotify_dentry_parent_queue_event(dentry
, mask
, 0, dentry
->d_name
.name
);
126 inotify_inode_queue_event(inode
, mask
, 0, NULL
);
130 * fsnotify_modify - file was modified
132 static inline void fsnotify_modify(struct dentry
*dentry
)
134 struct inode
*inode
= dentry
->d_inode
;
135 u32 mask
= IN_MODIFY
;
137 if (S_ISDIR(inode
->i_mode
))
140 dnotify_parent(dentry
, DN_MODIFY
);
141 inotify_dentry_parent_queue_event(dentry
, mask
, 0, dentry
->d_name
.name
);
142 inotify_inode_queue_event(inode
, mask
, 0, NULL
);
146 * fsnotify_open - file was opened
148 static inline void fsnotify_open(struct dentry
*dentry
)
150 struct inode
*inode
= dentry
->d_inode
;
153 if (S_ISDIR(inode
->i_mode
))
156 inotify_dentry_parent_queue_event(dentry
, mask
, 0, dentry
->d_name
.name
);
157 inotify_inode_queue_event(inode
, mask
, 0, NULL
);
161 * fsnotify_close - file was closed
163 static inline void fsnotify_close(struct file
*file
)
165 struct dentry
*dentry
= file
->f_dentry
;
166 struct inode
*inode
= dentry
->d_inode
;
167 const char *name
= dentry
->d_name
.name
;
168 mode_t mode
= file
->f_mode
;
169 u32 mask
= (mode
& FMODE_WRITE
) ? IN_CLOSE_WRITE
: IN_CLOSE_NOWRITE
;
171 if (S_ISDIR(inode
->i_mode
))
174 inotify_dentry_parent_queue_event(dentry
, mask
, 0, name
);
175 inotify_inode_queue_event(inode
, mask
, 0, NULL
);
179 * fsnotify_xattr - extended attributes were changed
181 static inline void fsnotify_xattr(struct dentry
*dentry
)
183 struct inode
*inode
= dentry
->d_inode
;
184 u32 mask
= IN_ATTRIB
;
186 if (S_ISDIR(inode
->i_mode
))
189 inotify_dentry_parent_queue_event(dentry
, mask
, 0, dentry
->d_name
.name
);
190 inotify_inode_queue_event(inode
, mask
, 0, NULL
);
194 * fsnotify_change - notify_change event. file was modified and/or metadata
197 static inline void fsnotify_change(struct dentry
*dentry
, unsigned int ia_valid
)
199 struct inode
*inode
= dentry
->d_inode
;
203 if (ia_valid
& ATTR_UID
) {
204 in_mask
|= IN_ATTRIB
;
205 dn_mask
|= DN_ATTRIB
;
207 if (ia_valid
& ATTR_GID
) {
208 in_mask
|= IN_ATTRIB
;
209 dn_mask
|= DN_ATTRIB
;
211 if (ia_valid
& ATTR_SIZE
) {
212 in_mask
|= IN_MODIFY
;
213 dn_mask
|= DN_MODIFY
;
215 /* both times implies a utime(s) call */
216 if ((ia_valid
& (ATTR_ATIME
| ATTR_MTIME
)) == (ATTR_ATIME
| ATTR_MTIME
))
218 in_mask
|= IN_ATTRIB
;
219 dn_mask
|= DN_ATTRIB
;
220 } else if (ia_valid
& ATTR_ATIME
) {
221 in_mask
|= IN_ACCESS
;
222 dn_mask
|= DN_ACCESS
;
223 } else if (ia_valid
& ATTR_MTIME
) {
224 in_mask
|= IN_MODIFY
;
225 dn_mask
|= DN_MODIFY
;
227 if (ia_valid
& ATTR_MODE
) {
228 in_mask
|= IN_ATTRIB
;
229 dn_mask
|= DN_ATTRIB
;
233 dnotify_parent(dentry
, dn_mask
);
235 if (S_ISDIR(inode
->i_mode
))
237 inotify_inode_queue_event(inode
, in_mask
, 0, NULL
);
238 inotify_dentry_parent_queue_event(dentry
, in_mask
, 0,
239 dentry
->d_name
.name
);
243 #ifdef CONFIG_INOTIFY /* inotify helpers */
246 * fsnotify_oldname_init - save off the old filename before we change it
248 static inline const char *fsnotify_oldname_init(const char *name
)
250 return kstrdup(name
, GFP_KERNEL
);
254 * fsnotify_oldname_free - free the name we got from fsnotify_oldname_init
256 static inline void fsnotify_oldname_free(const char *old_name
)
261 #else /* CONFIG_INOTIFY */
263 static inline const char *fsnotify_oldname_init(const char *name
)
268 static inline void fsnotify_oldname_free(const char *old_name
)
272 #endif /* ! CONFIG_INOTIFY */
274 #endif /* __KERNEL__ */
276 #endif /* _LINUX_FS_NOTIFY_H */