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