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>
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
,
26 u32 cookie
= inotify_get_cookie();
28 if (old_dir
== new_dir
)
29 inode_dir_notify(old_dir
, DN_RENAME
);
31 inode_dir_notify(old_dir
, DN_DELETE
);
32 inode_dir_notify(new_dir
, DN_CREATE
);
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
);
42 * fsnotify_unlink - file was unlinked
44 static inline void fsnotify_unlink(struct dentry
*dentry
, struct inode
*dir
)
46 struct inode
*inode
= dentry
->d_inode
;
48 inode_dir_notify(dir
, DN_DELETE
);
49 inotify_inode_queue_event(dir
, IN_DELETE
, 0, dentry
->d_name
.name
);
50 inotify_inode_queue_event(inode
, IN_DELETE_SELF
, 0, NULL
);
52 inotify_inode_is_dead(inode
);
56 * fsnotify_rmdir - directory was removed
58 static inline void fsnotify_rmdir(struct dentry
*dentry
, struct inode
*inode
,
61 inode_dir_notify(dir
, DN_DELETE
);
62 inotify_inode_queue_event(dir
,IN_DELETE
|IN_ISDIR
,0,dentry
->d_name
.name
);
63 inotify_inode_queue_event(inode
, IN_DELETE_SELF
| IN_ISDIR
, 0, NULL
);
64 inotify_inode_is_dead(inode
);
68 * fsnotify_create - 'name' was linked in
70 static inline void fsnotify_create(struct inode
*inode
, const char *name
)
72 inode_dir_notify(inode
, DN_CREATE
);
73 inotify_inode_queue_event(inode
, IN_CREATE
, 0, name
);
77 * fsnotify_mkdir - directory 'name' was created
79 static inline void fsnotify_mkdir(struct inode
*inode
, const char *name
)
81 inode_dir_notify(inode
, DN_CREATE
);
82 inotify_inode_queue_event(inode
, IN_CREATE
| IN_ISDIR
, 0, name
);
86 * fsnotify_access - file was read
88 static inline void fsnotify_access(struct dentry
*dentry
)
90 struct inode
*inode
= dentry
->d_inode
;
93 if (S_ISDIR(inode
->i_mode
))
96 dnotify_parent(dentry
, DN_ACCESS
);
97 inotify_dentry_parent_queue_event(dentry
, mask
, 0, dentry
->d_name
.name
);
98 inotify_inode_queue_event(inode
, mask
, 0, NULL
);
102 * fsnotify_modify - file was modified
104 static inline void fsnotify_modify(struct dentry
*dentry
)
106 struct inode
*inode
= dentry
->d_inode
;
107 u32 mask
= IN_MODIFY
;
109 if (S_ISDIR(inode
->i_mode
))
112 dnotify_parent(dentry
, DN_MODIFY
);
113 inotify_dentry_parent_queue_event(dentry
, mask
, 0, dentry
->d_name
.name
);
114 inotify_inode_queue_event(inode
, mask
, 0, NULL
);
118 * fsnotify_open - file was opened
120 static inline void fsnotify_open(struct dentry
*dentry
)
122 struct inode
*inode
= dentry
->d_inode
;
125 if (S_ISDIR(inode
->i_mode
))
128 inotify_dentry_parent_queue_event(dentry
, mask
, 0, dentry
->d_name
.name
);
129 inotify_inode_queue_event(inode
, mask
, 0, NULL
);
133 * fsnotify_close - file was closed
135 static inline void fsnotify_close(struct file
*file
)
137 struct dentry
*dentry
= file
->f_dentry
;
138 struct inode
*inode
= dentry
->d_inode
;
139 const char *name
= dentry
->d_name
.name
;
140 mode_t mode
= file
->f_mode
;
141 u32 mask
= (mode
& FMODE_WRITE
) ? IN_CLOSE_WRITE
: IN_CLOSE_NOWRITE
;
143 if (S_ISDIR(inode
->i_mode
))
146 inotify_dentry_parent_queue_event(dentry
, mask
, 0, name
);
147 inotify_inode_queue_event(inode
, mask
, 0, NULL
);
151 * fsnotify_xattr - extended attributes were changed
153 static inline void fsnotify_xattr(struct dentry
*dentry
)
155 struct inode
*inode
= dentry
->d_inode
;
156 u32 mask
= IN_ATTRIB
;
158 if (S_ISDIR(inode
->i_mode
))
161 inotify_dentry_parent_queue_event(dentry
, mask
, 0, dentry
->d_name
.name
);
162 inotify_inode_queue_event(inode
, mask
, 0, NULL
);
166 * fsnotify_change - notify_change event. file was modified and/or metadata
169 static inline void fsnotify_change(struct dentry
*dentry
, unsigned int ia_valid
)
171 struct inode
*inode
= dentry
->d_inode
;
175 if (ia_valid
& ATTR_UID
) {
176 in_mask
|= IN_ATTRIB
;
177 dn_mask
|= DN_ATTRIB
;
179 if (ia_valid
& ATTR_GID
) {
180 in_mask
|= IN_ATTRIB
;
181 dn_mask
|= DN_ATTRIB
;
183 if (ia_valid
& ATTR_SIZE
) {
184 in_mask
|= IN_MODIFY
;
185 dn_mask
|= DN_MODIFY
;
187 /* both times implies a utime(s) call */
188 if ((ia_valid
& (ATTR_ATIME
| ATTR_MTIME
)) == (ATTR_ATIME
| ATTR_MTIME
))
190 in_mask
|= IN_ATTRIB
;
191 dn_mask
|= DN_ATTRIB
;
192 } else if (ia_valid
& ATTR_ATIME
) {
193 in_mask
|= IN_ACCESS
;
194 dn_mask
|= DN_ACCESS
;
195 } else if (ia_valid
& ATTR_MTIME
) {
196 in_mask
|= IN_MODIFY
;
197 dn_mask
|= DN_MODIFY
;
199 if (ia_valid
& ATTR_MODE
) {
200 in_mask
|= IN_ATTRIB
;
201 dn_mask
|= DN_ATTRIB
;
205 dnotify_parent(dentry
, dn_mask
);
207 if (S_ISDIR(inode
->i_mode
))
209 inotify_inode_queue_event(inode
, in_mask
, 0, NULL
);
210 inotify_dentry_parent_queue_event(dentry
, in_mask
, 0,
211 dentry
->d_name
.name
);
215 #ifdef CONFIG_INOTIFY /* inotify helpers */
218 * fsnotify_oldname_init - save off the old filename before we change it
220 static inline const char *fsnotify_oldname_init(const char *name
)
222 return kstrdup(name
, GFP_KERNEL
);
226 * fsnotify_oldname_free - free the name we got from fsnotify_oldname_init
228 static inline void fsnotify_oldname_free(const char *old_name
)
233 #else /* CONFIG_INOTIFY */
235 static inline const char *fsnotify_oldname_init(const char *name
)
240 static inline void fsnotify_oldname_free(const char *old_name
)
244 #endif /* ! CONFIG_INOTIFY */
246 #endif /* __KERNEL__ */
248 #endif /* _LINUX_FS_NOTIFY_H */