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