Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 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 | |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 14 | #include <linux/fsnotify_backend.h> |
Amy Griffis | 73241cc | 2005-11-03 16:00:25 +0000 | [diff] [blame] | 15 | #include <linux/audit.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 16 | #include <linux/slab.h> |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 17 | |
| 18 | /* |
Nick Piggin | c32ccd8 | 2006-03-25 03:07:09 -0800 | [diff] [blame] | 19 | * fsnotify_d_instantiate - instantiate a dentry for inode |
| 20 | * Called with dcache_lock held. |
| 21 | */ |
Eric Paris | e61ce86 | 2009-12-17 21:24:24 -0500 | [diff] [blame] | 22 | static inline void fsnotify_d_instantiate(struct dentry *dentry, |
| 23 | struct inode *inode) |
Nick Piggin | c32ccd8 | 2006-03-25 03:07:09 -0800 | [diff] [blame] | 24 | { |
Eric Paris | e61ce86 | 2009-12-17 21:24:24 -0500 | [diff] [blame] | 25 | __fsnotify_d_instantiate(dentry, inode); |
Nick Piggin | c32ccd8 | 2006-03-25 03:07:09 -0800 | [diff] [blame] | 26 | } |
| 27 | |
Eric Paris | c28f7e5 | 2009-05-21 17:01:29 -0400 | [diff] [blame] | 28 | /* Notify this dentry's parent about a child's events. */ |
Andreas Gruenbacher | 72acc85 | 2009-12-17 21:24:24 -0500 | [diff] [blame] | 29 | static inline void fsnotify_parent(struct path *path, struct dentry *dentry, __u32 mask) |
Eric Paris | c28f7e5 | 2009-05-21 17:01:29 -0400 | [diff] [blame] | 30 | { |
Andreas Gruenbacher | 72acc85 | 2009-12-17 21:24:24 -0500 | [diff] [blame] | 31 | if (!dentry) |
| 32 | dentry = path->dentry; |
Eric Paris | 28c60e3 | 2009-12-17 21:24:21 -0500 | [diff] [blame] | 33 | |
Andreas Gruenbacher | 72acc85 | 2009-12-17 21:24:24 -0500 | [diff] [blame] | 34 | __fsnotify_parent(path, dentry, mask); |
Eric Paris | c28f7e5 | 2009-05-21 17:01:29 -0400 | [diff] [blame] | 35 | } |
| 36 | |
Nick Piggin | c32ccd8 | 2006-03-25 03:07:09 -0800 | [diff] [blame] | 37 | /* |
Eric Paris | e61ce86 | 2009-12-17 21:24:24 -0500 | [diff] [blame] | 38 | * fsnotify_d_move - dentry has been moved |
| 39 | * Called with dcache_lock and dentry->d_lock held. |
Nick Piggin | c32ccd8 | 2006-03-25 03:07:09 -0800 | [diff] [blame] | 40 | */ |
Eric Paris | e61ce86 | 2009-12-17 21:24:24 -0500 | [diff] [blame] | 41 | static inline void fsnotify_d_move(struct dentry *dentry) |
Nick Piggin | c32ccd8 | 2006-03-25 03:07:09 -0800 | [diff] [blame] | 42 | { |
Eric Paris | c28f7e5 | 2009-05-21 17:01:29 -0400 | [diff] [blame] | 43 | /* |
Eric Paris | e61ce86 | 2009-12-17 21:24:24 -0500 | [diff] [blame] | 44 | * On move we need to update dentry->d_flags to indicate if the new parent |
| 45 | * cares about events from this dentry. |
Eric Paris | c28f7e5 | 2009-05-21 17:01:29 -0400 | [diff] [blame] | 46 | */ |
Eric Paris | e61ce86 | 2009-12-17 21:24:24 -0500 | [diff] [blame] | 47 | __fsnotify_update_dcache_flags(dentry); |
Nick Piggin | c32ccd8 | 2006-03-25 03:07:09 -0800 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | /* |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 51 | * fsnotify_link_count - inode's link count changed |
| 52 | */ |
| 53 | static inline void fsnotify_link_count(struct inode *inode) |
| 54 | { |
Eric Paris | 47882c6 | 2009-05-21 17:01:47 -0400 | [diff] [blame] | 55 | fsnotify(inode, FS_ATTRIB, inode, FSNOTIFY_EVENT_INODE, NULL, 0); |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | /* |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 59 | * fsnotify_move - file old_name at old_dir was moved to new_name at new_dir |
| 60 | */ |
| 61 | static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir, |
Al Viro | 123df29 | 2009-12-25 04:57:57 -0500 | [diff] [blame] | 62 | const char *old_name, |
Al Viro | 5a190ae | 2007-06-07 12:19:32 -0400 | [diff] [blame] | 63 | int isdir, struct inode *target, struct dentry *moved) |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 64 | { |
Al Viro | 5a190ae | 2007-06-07 12:19:32 -0400 | [diff] [blame] | 65 | struct inode *source = moved->d_inode; |
Eric Paris | 47882c6 | 2009-05-21 17:01:47 -0400 | [diff] [blame] | 66 | u32 fs_cookie = fsnotify_get_cookie(); |
Eric Paris | ff52cc2 | 2009-06-11 11:09:47 -0400 | [diff] [blame] | 67 | __u32 old_dir_mask = (FS_EVENT_ON_CHILD | FS_MOVED_FROM); |
| 68 | __u32 new_dir_mask = (FS_EVENT_ON_CHILD | FS_MOVED_TO); |
Al Viro | 123df29 | 2009-12-25 04:57:57 -0500 | [diff] [blame] | 69 | const char *new_name = moved->d_name.name; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 70 | |
Eric Paris | ff52cc2 | 2009-06-11 11:09:47 -0400 | [diff] [blame] | 71 | if (old_dir == new_dir) |
| 72 | old_dir_mask |= FS_DN_RENAME; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 73 | |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 74 | if (isdir) { |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 75 | old_dir_mask |= FS_IN_ISDIR; |
| 76 | new_dir_mask |= FS_IN_ISDIR; |
| 77 | } |
| 78 | |
Eric Paris | 47882c6 | 2009-05-21 17:01:47 -0400 | [diff] [blame] | 79 | fsnotify(old_dir, old_dir_mask, old_dir, FSNOTIFY_EVENT_INODE, old_name, fs_cookie); |
| 80 | fsnotify(new_dir, new_dir_mask, new_dir, FSNOTIFY_EVENT_INODE, new_name, fs_cookie); |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 81 | |
Eric Paris | 2dfc1ca | 2009-12-17 20:30:52 -0500 | [diff] [blame] | 82 | if (target) |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 83 | fsnotify_link_count(target); |
John McCutchan | 89204c4 | 2005-08-15 12:13:28 -0400 | [diff] [blame] | 84 | |
Eric Paris | 2dfc1ca | 2009-12-17 20:30:52 -0500 | [diff] [blame] | 85 | if (source) |
Eric Paris | 47882c6 | 2009-05-21 17:01:47 -0400 | [diff] [blame] | 86 | fsnotify(source, FS_MOVE_SELF, moved->d_inode, FSNOTIFY_EVENT_INODE, NULL, 0); |
Al Viro | cccc6bb | 2009-12-25 05:07:33 -0500 | [diff] [blame] | 87 | audit_inode_child(moved, new_dir); |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | /* |
Eric Paris | 3be25f4 | 2009-05-21 17:01:26 -0400 | [diff] [blame] | 91 | * fsnotify_inode_delete - and inode is being evicted from cache, clean up is needed |
| 92 | */ |
| 93 | static inline void fsnotify_inode_delete(struct inode *inode) |
| 94 | { |
| 95 | __fsnotify_inode_delete(inode); |
| 96 | } |
| 97 | |
| 98 | /* |
Andreas Gruenbacher | ca9c726 | 2009-12-17 21:24:27 -0500 | [diff] [blame] | 99 | * fsnotify_vfsmount_delete - a vfsmount is being destroyed, clean up is needed |
| 100 | */ |
| 101 | static inline void fsnotify_vfsmount_delete(struct vfsmount *mnt) |
| 102 | { |
| 103 | __fsnotify_vfsmount_delete(mnt); |
| 104 | } |
| 105 | |
| 106 | /* |
John McCutchan | 7a91bf7 | 2005-08-08 13:52:16 -0400 | [diff] [blame] | 107 | * fsnotify_nameremove - a filename was removed from a directory |
| 108 | */ |
| 109 | static inline void fsnotify_nameremove(struct dentry *dentry, int isdir) |
| 110 | { |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 111 | __u32 mask = FS_DELETE; |
| 112 | |
John McCutchan | 7a91bf7 | 2005-08-08 13:52:16 -0400 | [diff] [blame] | 113 | if (isdir) |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 114 | mask |= FS_IN_ISDIR; |
Eric Paris | c28f7e5 | 2009-05-21 17:01:29 -0400 | [diff] [blame] | 115 | |
Eric Paris | 28c60e3 | 2009-12-17 21:24:21 -0500 | [diff] [blame] | 116 | fsnotify_parent(NULL, dentry, mask); |
John McCutchan | 7a91bf7 | 2005-08-08 13:52:16 -0400 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | /* |
| 120 | * fsnotify_inoderemove - an inode is going away |
| 121 | */ |
| 122 | static inline void fsnotify_inoderemove(struct inode *inode) |
| 123 | { |
Eric Paris | 47882c6 | 2009-05-21 17:01:47 -0400 | [diff] [blame] | 124 | fsnotify(inode, FS_DELETE_SELF, inode, FSNOTIFY_EVENT_INODE, NULL, 0); |
Eric Paris | 3be25f4 | 2009-05-21 17:01:26 -0400 | [diff] [blame] | 125 | __fsnotify_inode_delete(inode); |
Jan Kara | ece9591 | 2008-02-06 01:37:13 -0800 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | /* |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 129 | * fsnotify_create - 'name' was linked in |
| 130 | */ |
Amy Griffis | f38aa94 | 2005-11-03 15:57:06 +0000 | [diff] [blame] | 131 | static inline void fsnotify_create(struct inode *inode, struct dentry *dentry) |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 132 | { |
Al Viro | cccc6bb | 2009-12-25 05:07:33 -0500 | [diff] [blame] | 133 | audit_inode_child(dentry, inode); |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 134 | |
Eric Paris | 47882c6 | 2009-05-21 17:01:47 -0400 | [diff] [blame] | 135 | fsnotify(inode, FS_CREATE, dentry->d_inode, FSNOTIFY_EVENT_INODE, dentry->d_name.name, 0); |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | /* |
Jan Kara | ece9591 | 2008-02-06 01:37:13 -0800 | [diff] [blame] | 139 | * fsnotify_link - new hardlink in 'inode' directory |
| 140 | * Note: We have to pass also the linked inode ptr as some filesystems leave |
| 141 | * new_dentry->d_inode NULL and instantiate inode pointer later |
| 142 | */ |
| 143 | static inline void fsnotify_link(struct inode *dir, struct inode *inode, struct dentry *new_dentry) |
| 144 | { |
Jan Kara | ece9591 | 2008-02-06 01:37:13 -0800 | [diff] [blame] | 145 | fsnotify_link_count(inode); |
Al Viro | cccc6bb | 2009-12-25 05:07:33 -0500 | [diff] [blame] | 146 | audit_inode_child(new_dentry, dir); |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 147 | |
Eric Paris | 47882c6 | 2009-05-21 17:01:47 -0400 | [diff] [blame] | 148 | fsnotify(dir, FS_CREATE, inode, FSNOTIFY_EVENT_INODE, new_dentry->d_name.name, 0); |
Jan Kara | ece9591 | 2008-02-06 01:37:13 -0800 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | /* |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 152 | * fsnotify_mkdir - directory 'name' was created |
| 153 | */ |
Amy Griffis | f38aa94 | 2005-11-03 15:57:06 +0000 | [diff] [blame] | 154 | static inline void fsnotify_mkdir(struct inode *inode, struct dentry *dentry) |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 155 | { |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 156 | __u32 mask = (FS_CREATE | FS_IN_ISDIR); |
| 157 | struct inode *d_inode = dentry->d_inode; |
| 158 | |
Al Viro | cccc6bb | 2009-12-25 05:07:33 -0500 | [diff] [blame] | 159 | audit_inode_child(dentry, inode); |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 160 | |
Eric Paris | 47882c6 | 2009-05-21 17:01:47 -0400 | [diff] [blame] | 161 | fsnotify(inode, mask, d_inode, FSNOTIFY_EVENT_INODE, dentry->d_name.name, 0); |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | /* |
| 165 | * fsnotify_access - file was read |
| 166 | */ |
Eric Paris | 2a12a9d | 2009-12-17 21:24:21 -0500 | [diff] [blame] | 167 | static inline void fsnotify_access(struct file *file) |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 168 | { |
Andreas Gruenbacher | 72acc85 | 2009-12-17 21:24:24 -0500 | [diff] [blame] | 169 | struct path *path = &file->f_path; |
| 170 | struct inode *inode = path->dentry->d_inode; |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 171 | __u32 mask = FS_ACCESS; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 172 | |
| 173 | if (S_ISDIR(inode->i_mode)) |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 174 | mask |= FS_IN_ISDIR; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 175 | |
Eric Paris | ecf081d | 2009-12-17 21:24:25 -0500 | [diff] [blame] | 176 | if (!(file->f_mode & FMODE_NONOTIFY)) { |
| 177 | fsnotify_parent(path, NULL, mask); |
| 178 | fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0); |
| 179 | } |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | /* |
| 183 | * fsnotify_modify - file was modified |
| 184 | */ |
Eric Paris | 2a12a9d | 2009-12-17 21:24:21 -0500 | [diff] [blame] | 185 | static inline void fsnotify_modify(struct file *file) |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 186 | { |
Andreas Gruenbacher | 72acc85 | 2009-12-17 21:24:24 -0500 | [diff] [blame] | 187 | struct path *path = &file->f_path; |
| 188 | struct inode *inode = path->dentry->d_inode; |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 189 | __u32 mask = FS_MODIFY; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 190 | |
| 191 | if (S_ISDIR(inode->i_mode)) |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 192 | mask |= FS_IN_ISDIR; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 193 | |
Eric Paris | ecf081d | 2009-12-17 21:24:25 -0500 | [diff] [blame] | 194 | if (!(file->f_mode & FMODE_NONOTIFY)) { |
| 195 | fsnotify_parent(path, NULL, mask); |
| 196 | fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0); |
| 197 | } |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | /* |
| 201 | * fsnotify_open - file was opened |
| 202 | */ |
Eric Paris | 2a12a9d | 2009-12-17 21:24:21 -0500 | [diff] [blame] | 203 | static inline void fsnotify_open(struct file *file) |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 204 | { |
Andreas Gruenbacher | 72acc85 | 2009-12-17 21:24:24 -0500 | [diff] [blame] | 205 | struct path *path = &file->f_path; |
| 206 | struct inode *inode = path->dentry->d_inode; |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 207 | __u32 mask = FS_OPEN; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 208 | |
| 209 | if (S_ISDIR(inode->i_mode)) |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 210 | mask |= FS_IN_ISDIR; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 211 | |
Eric Paris | ecf081d | 2009-12-17 21:24:25 -0500 | [diff] [blame] | 212 | if (!(file->f_mode & FMODE_NONOTIFY)) { |
| 213 | fsnotify_parent(path, NULL, mask); |
| 214 | fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0); |
| 215 | } |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | /* |
| 219 | * fsnotify_close - file was closed |
| 220 | */ |
| 221 | static inline void fsnotify_close(struct file *file) |
| 222 | { |
Andreas Gruenbacher | 72acc85 | 2009-12-17 21:24:24 -0500 | [diff] [blame] | 223 | struct path *path = &file->f_path; |
Eric Paris | 28c60e3 | 2009-12-17 21:24:21 -0500 | [diff] [blame] | 224 | struct inode *inode = file->f_path.dentry->d_inode; |
Al Viro | aeb5d72 | 2008-09-02 15:28:45 -0400 | [diff] [blame] | 225 | fmode_t mode = file->f_mode; |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 226 | __u32 mask = (mode & FMODE_WRITE) ? FS_CLOSE_WRITE : FS_CLOSE_NOWRITE; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 227 | |
| 228 | if (S_ISDIR(inode->i_mode)) |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 229 | mask |= FS_IN_ISDIR; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 230 | |
Eric Paris | ecf081d | 2009-12-17 21:24:25 -0500 | [diff] [blame] | 231 | if (!(file->f_mode & FMODE_NONOTIFY)) { |
| 232 | fsnotify_parent(path, NULL, mask); |
| 233 | fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0); |
| 234 | } |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | /* |
| 238 | * fsnotify_xattr - extended attributes were changed |
| 239 | */ |
| 240 | static inline void fsnotify_xattr(struct dentry *dentry) |
| 241 | { |
| 242 | struct inode *inode = dentry->d_inode; |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 243 | __u32 mask = FS_ATTRIB; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 244 | |
| 245 | if (S_ISDIR(inode->i_mode)) |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 246 | mask |= FS_IN_ISDIR; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 247 | |
Eric Paris | 28c60e3 | 2009-12-17 21:24:21 -0500 | [diff] [blame] | 248 | fsnotify_parent(NULL, dentry, mask); |
Eric Paris | 47882c6 | 2009-05-21 17:01:47 -0400 | [diff] [blame] | 249 | fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0); |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | /* |
| 253 | * fsnotify_change - notify_change event. file was modified and/or metadata |
| 254 | * was changed. |
| 255 | */ |
| 256 | static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid) |
| 257 | { |
| 258 | struct inode *inode = dentry->d_inode; |
Eric Paris | 3c5119c | 2009-05-21 17:01:33 -0400 | [diff] [blame] | 259 | __u32 mask = 0; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 260 | |
Eric Paris | 3c5119c | 2009-05-21 17:01:33 -0400 | [diff] [blame] | 261 | if (ia_valid & ATTR_UID) |
| 262 | mask |= FS_ATTRIB; |
| 263 | if (ia_valid & ATTR_GID) |
| 264 | mask |= FS_ATTRIB; |
| 265 | if (ia_valid & ATTR_SIZE) |
| 266 | mask |= FS_MODIFY; |
| 267 | |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 268 | /* both times implies a utime(s) call */ |
| 269 | if ((ia_valid & (ATTR_ATIME | ATTR_MTIME)) == (ATTR_ATIME | ATTR_MTIME)) |
Eric Paris | 3c5119c | 2009-05-21 17:01:33 -0400 | [diff] [blame] | 270 | mask |= FS_ATTRIB; |
| 271 | else if (ia_valid & ATTR_ATIME) |
| 272 | mask |= FS_ACCESS; |
| 273 | else if (ia_valid & ATTR_MTIME) |
| 274 | mask |= FS_MODIFY; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 275 | |
Eric Paris | 3c5119c | 2009-05-21 17:01:33 -0400 | [diff] [blame] | 276 | if (ia_valid & ATTR_MODE) |
| 277 | mask |= FS_ATTRIB; |
| 278 | |
| 279 | if (mask) { |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 280 | if (S_ISDIR(inode->i_mode)) |
Eric Paris | 3c5119c | 2009-05-21 17:01:33 -0400 | [diff] [blame] | 281 | mask |= FS_IN_ISDIR; |
Eric Paris | 28c60e3 | 2009-12-17 21:24:21 -0500 | [diff] [blame] | 282 | |
| 283 | fsnotify_parent(NULL, dentry, mask); |
Eric Paris | 47882c6 | 2009-05-21 17:01:47 -0400 | [diff] [blame] | 284 | fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0); |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 285 | } |
| 286 | } |
| 287 | |
Eric Paris | 2dfc1ca | 2009-12-17 20:30:52 -0500 | [diff] [blame] | 288 | #if defined(CONFIG_FSNOTIFY) /* notify helpers */ |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 289 | |
| 290 | /* |
| 291 | * fsnotify_oldname_init - save off the old filename before we change it |
| 292 | */ |
| 293 | static inline const char *fsnotify_oldname_init(const char *name) |
| 294 | { |
| 295 | return kstrdup(name, GFP_KERNEL); |
| 296 | } |
| 297 | |
| 298 | /* |
| 299 | * fsnotify_oldname_free - free the name we got from fsnotify_oldname_init |
| 300 | */ |
| 301 | static inline void fsnotify_oldname_free(const char *old_name) |
| 302 | { |
| 303 | kfree(old_name); |
| 304 | } |
| 305 | |
Eric Paris | 28c60e3 | 2009-12-17 21:24:21 -0500 | [diff] [blame] | 306 | #else /* CONFIG_FSNOTIFY */ |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 307 | |
| 308 | static inline const char *fsnotify_oldname_init(const char *name) |
| 309 | { |
| 310 | return NULL; |
| 311 | } |
| 312 | |
| 313 | static inline void fsnotify_oldname_free(const char *old_name) |
| 314 | { |
| 315 | } |
| 316 | |
Eric Paris | 28c60e3 | 2009-12-17 21:24:21 -0500 | [diff] [blame] | 317 | #endif /* CONFIG_FSNOTIFY */ |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 318 | |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 319 | #endif /* _LINUX_FS_NOTIFY_H */ |