Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 2 | #ifndef _LINUX_FS_NOTIFY_H |
| 3 | #define _LINUX_FS_NOTIFY_H |
| 4 | |
| 5 | /* |
| 6 | * include/linux/fsnotify.h - generic hooks for filesystem notification, to |
| 7 | * reduce in-source duplication from both dnotify and inotify. |
| 8 | * |
| 9 | * We don't compile any of this away in some complicated menagerie of ifdefs. |
| 10 | * Instead, we rely on the code inside to optimize away as needed. |
| 11 | * |
| 12 | * (C) Copyright 2005 Robert Love |
| 13 | */ |
| 14 | |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 15 | #include <linux/fsnotify_backend.h> |
Amy Griffis | 73241cc | 2005-11-03 16:00:25 +0000 | [diff] [blame] | 16 | #include <linux/audit.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 17 | #include <linux/slab.h> |
Paul Gortmaker | 187f188 | 2011-11-23 20:12:59 -0500 | [diff] [blame] | 18 | #include <linux/bug.h> |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 19 | |
Eric Paris | c28f7e5 | 2009-05-21 17:01:29 -0400 | [diff] [blame] | 20 | /* Notify this dentry's parent about a child's events. */ |
Al Viro | 12c7f9d | 2016-11-20 20:23:04 -0500 | [diff] [blame] | 21 | static inline int fsnotify_parent(const struct path *path, struct dentry *dentry, __u32 mask) |
Eric Paris | c28f7e5 | 2009-05-21 17:01:29 -0400 | [diff] [blame] | 22 | { |
Andreas Gruenbacher | 72acc85 | 2009-12-17 21:24:24 -0500 | [diff] [blame] | 23 | if (!dentry) |
Linus Torvalds | 2069601 | 2010-08-12 14:23:04 -0700 | [diff] [blame] | 24 | dentry = path->dentry; |
Eric Paris | 28c60e3 | 2009-12-17 21:24:21 -0500 | [diff] [blame] | 25 | |
Eric Paris | 5242039 | 2010-10-28 17:21:56 -0400 | [diff] [blame] | 26 | return __fsnotify_parent(path, dentry, mask); |
Eric Paris | c28f7e5 | 2009-05-21 17:01:29 -0400 | [diff] [blame] | 27 | } |
| 28 | |
Matthew Bobrowski | a704bba | 2018-11-08 14:10:03 +1100 | [diff] [blame^] | 29 | /* |
| 30 | * Simple wrapper to consolidate calls fsnotify_parent()/fsnotify() when |
| 31 | * an event is on a path. |
| 32 | */ |
| 33 | static inline int fsnotify_path(struct inode *inode, const struct path *path, |
| 34 | __u32 mask) |
| 35 | { |
| 36 | int ret = fsnotify_parent(path, NULL, mask); |
| 37 | |
| 38 | if (ret) |
| 39 | return ret; |
| 40 | return fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0); |
| 41 | } |
| 42 | |
Eric Paris | c4ec54b | 2009-12-17 21:24:34 -0500 | [diff] [blame] | 43 | /* simple call site for access decisions */ |
| 44 | static inline int fsnotify_perm(struct file *file, int mask) |
| 45 | { |
Al Viro | 40212d53 | 2016-11-20 20:24:41 -0500 | [diff] [blame] | 46 | const struct path *path = &file->f_path; |
Miklos Szeredi | 573e178 | 2018-07-18 15:44:44 +0200 | [diff] [blame] | 47 | struct inode *inode = file_inode(file); |
Eric Paris | fb1cfb8 | 2010-05-12 11:42:29 -0400 | [diff] [blame] | 48 | __u32 fsnotify_mask = 0; |
Eric Paris | c4ec54b | 2009-12-17 21:24:34 -0500 | [diff] [blame] | 49 | |
| 50 | if (file->f_mode & FMODE_NONOTIFY) |
| 51 | return 0; |
| 52 | if (!(mask & (MAY_READ | MAY_OPEN))) |
| 53 | return 0; |
Eric Paris | c4ec54b | 2009-12-17 21:24:34 -0500 | [diff] [blame] | 54 | if (mask & MAY_OPEN) |
| 55 | fsnotify_mask = FS_OPEN_PERM; |
Eric Paris | fb1cfb8 | 2010-05-12 11:42:29 -0400 | [diff] [blame] | 56 | else if (mask & MAY_READ) |
| 57 | fsnotify_mask = FS_ACCESS_PERM; |
| 58 | else |
| 59 | BUG(); |
Eric Paris | c4ec54b | 2009-12-17 21:24:34 -0500 | [diff] [blame] | 60 | |
Matthew Bobrowski | a704bba | 2018-11-08 14:10:03 +1100 | [diff] [blame^] | 61 | return fsnotify_path(inode, path, fsnotify_mask); |
Eric Paris | c4ec54b | 2009-12-17 21:24:34 -0500 | [diff] [blame] | 62 | } |
| 63 | |
Nick Piggin | c32ccd8 | 2006-03-25 03:07:09 -0800 | [diff] [blame] | 64 | /* |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 65 | * fsnotify_link_count - inode's link count changed |
| 66 | */ |
| 67 | static inline void fsnotify_link_count(struct inode *inode) |
| 68 | { |
Eric Paris | 47882c6 | 2009-05-21 17:01:47 -0400 | [diff] [blame] | 69 | fsnotify(inode, FS_ATTRIB, inode, FSNOTIFY_EVENT_INODE, NULL, 0); |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | /* |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 73 | * fsnotify_move - file old_name at old_dir was moved to new_name at new_dir |
| 74 | */ |
| 75 | static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir, |
Eric Paris | 59b0df2 | 2010-02-08 12:53:52 -0500 | [diff] [blame] | 76 | const unsigned char *old_name, |
Al Viro | 5a190ae | 2007-06-07 12:19:32 -0400 | [diff] [blame] | 77 | int isdir, struct inode *target, struct dentry *moved) |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 78 | { |
Al Viro | 5a190ae | 2007-06-07 12:19:32 -0400 | [diff] [blame] | 79 | struct inode *source = moved->d_inode; |
Eric Paris | 47882c6 | 2009-05-21 17:01:47 -0400 | [diff] [blame] | 80 | u32 fs_cookie = fsnotify_get_cookie(); |
Eric Paris | ff52cc2 | 2009-06-11 11:09:47 -0400 | [diff] [blame] | 81 | __u32 old_dir_mask = (FS_EVENT_ON_CHILD | FS_MOVED_FROM); |
| 82 | __u32 new_dir_mask = (FS_EVENT_ON_CHILD | FS_MOVED_TO); |
Eric Paris | 59b0df2 | 2010-02-08 12:53:52 -0500 | [diff] [blame] | 83 | const unsigned char *new_name = moved->d_name.name; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 84 | |
Eric Paris | ff52cc2 | 2009-06-11 11:09:47 -0400 | [diff] [blame] | 85 | if (old_dir == new_dir) |
| 86 | old_dir_mask |= FS_DN_RENAME; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 87 | |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 88 | if (isdir) { |
Eric Paris | b29866a | 2010-10-28 17:21:58 -0400 | [diff] [blame] | 89 | old_dir_mask |= FS_ISDIR; |
| 90 | new_dir_mask |= FS_ISDIR; |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 91 | } |
| 92 | |
Jan Kara | 6ee8e25 | 2015-02-10 14:08:32 -0800 | [diff] [blame] | 93 | fsnotify(old_dir, old_dir_mask, source, FSNOTIFY_EVENT_INODE, old_name, |
| 94 | fs_cookie); |
| 95 | fsnotify(new_dir, new_dir_mask, source, FSNOTIFY_EVENT_INODE, new_name, |
| 96 | fs_cookie); |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 97 | |
Eric Paris | 2dfc1ca | 2009-12-17 20:30:52 -0500 | [diff] [blame] | 98 | if (target) |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 99 | fsnotify_link_count(target); |
John McCutchan | 89204c4 | 2005-08-15 12:13:28 -0400 | [diff] [blame] | 100 | |
Eric Paris | 2dfc1ca | 2009-12-17 20:30:52 -0500 | [diff] [blame] | 101 | if (source) |
Eric Paris | 47882c6 | 2009-05-21 17:01:47 -0400 | [diff] [blame] | 102 | fsnotify(source, FS_MOVE_SELF, moved->d_inode, FSNOTIFY_EVENT_INODE, NULL, 0); |
Jeff Layton | 4fa6b5e | 2012-10-10 15:25:25 -0400 | [diff] [blame] | 103 | audit_inode_child(new_dir, moved, AUDIT_TYPE_CHILD_CREATE); |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | /* |
Eric Paris | 3be25f4 | 2009-05-21 17:01:26 -0400 | [diff] [blame] | 107 | * fsnotify_inode_delete - and inode is being evicted from cache, clean up is needed |
| 108 | */ |
| 109 | static inline void fsnotify_inode_delete(struct inode *inode) |
| 110 | { |
| 111 | __fsnotify_inode_delete(inode); |
| 112 | } |
| 113 | |
| 114 | /* |
Andreas Gruenbacher | ca9c726 | 2009-12-17 21:24:27 -0500 | [diff] [blame] | 115 | * fsnotify_vfsmount_delete - a vfsmount is being destroyed, clean up is needed |
| 116 | */ |
| 117 | static inline void fsnotify_vfsmount_delete(struct vfsmount *mnt) |
| 118 | { |
| 119 | __fsnotify_vfsmount_delete(mnt); |
| 120 | } |
| 121 | |
| 122 | /* |
John McCutchan | 7a91bf7 | 2005-08-08 13:52:16 -0400 | [diff] [blame] | 123 | * fsnotify_nameremove - a filename was removed from a directory |
| 124 | */ |
| 125 | static inline void fsnotify_nameremove(struct dentry *dentry, int isdir) |
| 126 | { |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 127 | __u32 mask = FS_DELETE; |
| 128 | |
John McCutchan | 7a91bf7 | 2005-08-08 13:52:16 -0400 | [diff] [blame] | 129 | if (isdir) |
Eric Paris | b29866a | 2010-10-28 17:21:58 -0400 | [diff] [blame] | 130 | mask |= FS_ISDIR; |
Eric Paris | c28f7e5 | 2009-05-21 17:01:29 -0400 | [diff] [blame] | 131 | |
Eric Paris | 28c60e3 | 2009-12-17 21:24:21 -0500 | [diff] [blame] | 132 | fsnotify_parent(NULL, dentry, mask); |
John McCutchan | 7a91bf7 | 2005-08-08 13:52:16 -0400 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | /* |
| 136 | * fsnotify_inoderemove - an inode is going away |
| 137 | */ |
| 138 | static inline void fsnotify_inoderemove(struct inode *inode) |
| 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 | { |
Jeff Layton | 4fa6b5e | 2012-10-10 15:25:25 -0400 | [diff] [blame] | 149 | audit_inode_child(inode, dentry, AUDIT_TYPE_CHILD_CREATE); |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 150 | |
Eric Paris | 47882c6 | 2009-05-21 17:01:47 -0400 | [diff] [blame] | 151 | 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] | 152 | } |
| 153 | |
| 154 | /* |
Jan Kara | ece9591 | 2008-02-06 01:37:13 -0800 | [diff] [blame] | 155 | * fsnotify_link - new hardlink in 'inode' directory |
| 156 | * Note: We have to pass also the linked inode ptr as some filesystems leave |
| 157 | * new_dentry->d_inode NULL and instantiate inode pointer later |
| 158 | */ |
| 159 | static inline void fsnotify_link(struct inode *dir, struct inode *inode, struct dentry *new_dentry) |
| 160 | { |
Jan Kara | ece9591 | 2008-02-06 01:37:13 -0800 | [diff] [blame] | 161 | fsnotify_link_count(inode); |
Jeff Layton | 4fa6b5e | 2012-10-10 15:25:25 -0400 | [diff] [blame] | 162 | audit_inode_child(dir, new_dentry, AUDIT_TYPE_CHILD_CREATE); |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 163 | |
Eric Paris | 47882c6 | 2009-05-21 17:01:47 -0400 | [diff] [blame] | 164 | 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] | 165 | } |
| 166 | |
| 167 | /* |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 168 | * fsnotify_mkdir - directory 'name' was created |
| 169 | */ |
Amy Griffis | f38aa94 | 2005-11-03 15:57:06 +0000 | [diff] [blame] | 170 | static inline void fsnotify_mkdir(struct inode *inode, struct dentry *dentry) |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 171 | { |
Eric Paris | b29866a | 2010-10-28 17:21:58 -0400 | [diff] [blame] | 172 | __u32 mask = (FS_CREATE | FS_ISDIR); |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 173 | struct inode *d_inode = dentry->d_inode; |
| 174 | |
Jeff Layton | 4fa6b5e | 2012-10-10 15:25:25 -0400 | [diff] [blame] | 175 | audit_inode_child(inode, dentry, AUDIT_TYPE_CHILD_CREATE); |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 176 | |
Eric Paris | 47882c6 | 2009-05-21 17:01:47 -0400 | [diff] [blame] | 177 | 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] | 178 | } |
| 179 | |
| 180 | /* |
| 181 | * fsnotify_access - file was read |
| 182 | */ |
Eric Paris | 2a12a9d | 2009-12-17 21:24:21 -0500 | [diff] [blame] | 183 | static inline void fsnotify_access(struct file *file) |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 184 | { |
Al Viro | 40212d53 | 2016-11-20 20:24:41 -0500 | [diff] [blame] | 185 | const struct path *path = &file->f_path; |
Miklos Szeredi | 573e178 | 2018-07-18 15:44:44 +0200 | [diff] [blame] | 186 | struct inode *inode = file_inode(file); |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 187 | __u32 mask = FS_ACCESS; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 188 | |
| 189 | if (S_ISDIR(inode->i_mode)) |
Eric Paris | b29866a | 2010-10-28 17:21:58 -0400 | [diff] [blame] | 190 | mask |= FS_ISDIR; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 191 | |
Matthew Bobrowski | a704bba | 2018-11-08 14:10:03 +1100 | [diff] [blame^] | 192 | if (!(file->f_mode & FMODE_NONOTIFY)) |
| 193 | fsnotify_path(inode, path, mask); |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | /* |
| 197 | * fsnotify_modify - file was modified |
| 198 | */ |
Eric Paris | 2a12a9d | 2009-12-17 21:24:21 -0500 | [diff] [blame] | 199 | static inline void fsnotify_modify(struct file *file) |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 200 | { |
Al Viro | 40212d53 | 2016-11-20 20:24:41 -0500 | [diff] [blame] | 201 | const struct path *path = &file->f_path; |
Miklos Szeredi | 573e178 | 2018-07-18 15:44:44 +0200 | [diff] [blame] | 202 | struct inode *inode = file_inode(file); |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 203 | __u32 mask = FS_MODIFY; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 204 | |
| 205 | if (S_ISDIR(inode->i_mode)) |
Eric Paris | b29866a | 2010-10-28 17:21:58 -0400 | [diff] [blame] | 206 | mask |= FS_ISDIR; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 207 | |
Matthew Bobrowski | a704bba | 2018-11-08 14:10:03 +1100 | [diff] [blame^] | 208 | if (!(file->f_mode & FMODE_NONOTIFY)) |
| 209 | fsnotify_path(inode, path, mask); |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | /* |
| 213 | * fsnotify_open - file was opened |
| 214 | */ |
Eric Paris | 2a12a9d | 2009-12-17 21:24:21 -0500 | [diff] [blame] | 215 | static inline void fsnotify_open(struct file *file) |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 216 | { |
Al Viro | 40212d53 | 2016-11-20 20:24:41 -0500 | [diff] [blame] | 217 | const struct path *path = &file->f_path; |
Miklos Szeredi | 573e178 | 2018-07-18 15:44:44 +0200 | [diff] [blame] | 218 | struct inode *inode = file_inode(file); |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 219 | __u32 mask = FS_OPEN; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 220 | |
| 221 | if (S_ISDIR(inode->i_mode)) |
Eric Paris | b29866a | 2010-10-28 17:21:58 -0400 | [diff] [blame] | 222 | mask |= FS_ISDIR; |
Matthew Bobrowski | 9b076f1 | 2018-11-08 14:07:14 +1100 | [diff] [blame] | 223 | if (file->f_flags & __FMODE_EXEC) |
| 224 | mask |= FS_OPEN_EXEC; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 225 | |
Matthew Bobrowski | a704bba | 2018-11-08 14:10:03 +1100 | [diff] [blame^] | 226 | fsnotify_path(inode, path, mask); |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | /* |
| 230 | * fsnotify_close - file was closed |
| 231 | */ |
| 232 | static inline void fsnotify_close(struct file *file) |
| 233 | { |
Al Viro | 40212d53 | 2016-11-20 20:24:41 -0500 | [diff] [blame] | 234 | const struct path *path = &file->f_path; |
Miklos Szeredi | 573e178 | 2018-07-18 15:44:44 +0200 | [diff] [blame] | 235 | struct inode *inode = file_inode(file); |
Al Viro | aeb5d72 | 2008-09-02 15:28:45 -0400 | [diff] [blame] | 236 | fmode_t mode = file->f_mode; |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 237 | __u32 mask = (mode & FMODE_WRITE) ? FS_CLOSE_WRITE : FS_CLOSE_NOWRITE; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 238 | |
| 239 | if (S_ISDIR(inode->i_mode)) |
Eric Paris | b29866a | 2010-10-28 17:21:58 -0400 | [diff] [blame] | 240 | mask |= FS_ISDIR; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 241 | |
Matthew Bobrowski | a704bba | 2018-11-08 14:10:03 +1100 | [diff] [blame^] | 242 | if (!(file->f_mode & FMODE_NONOTIFY)) |
| 243 | fsnotify_path(inode, path, mask); |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | /* |
| 247 | * fsnotify_xattr - extended attributes were changed |
| 248 | */ |
| 249 | static inline void fsnotify_xattr(struct dentry *dentry) |
| 250 | { |
| 251 | struct inode *inode = dentry->d_inode; |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 252 | __u32 mask = FS_ATTRIB; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 253 | |
| 254 | if (S_ISDIR(inode->i_mode)) |
Eric Paris | b29866a | 2010-10-28 17:21:58 -0400 | [diff] [blame] | 255 | mask |= FS_ISDIR; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 256 | |
Eric Paris | 28c60e3 | 2009-12-17 21:24:21 -0500 | [diff] [blame] | 257 | fsnotify_parent(NULL, dentry, mask); |
Eric Paris | 47882c6 | 2009-05-21 17:01:47 -0400 | [diff] [blame] | 258 | fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0); |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | /* |
| 262 | * fsnotify_change - notify_change event. file was modified and/or metadata |
| 263 | * was changed. |
| 264 | */ |
| 265 | static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid) |
| 266 | { |
| 267 | struct inode *inode = dentry->d_inode; |
Eric Paris | 3c5119c | 2009-05-21 17:01:33 -0400 | [diff] [blame] | 268 | __u32 mask = 0; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 269 | |
Eric Paris | 3c5119c | 2009-05-21 17:01:33 -0400 | [diff] [blame] | 270 | if (ia_valid & ATTR_UID) |
| 271 | mask |= FS_ATTRIB; |
| 272 | if (ia_valid & ATTR_GID) |
| 273 | mask |= FS_ATTRIB; |
| 274 | if (ia_valid & ATTR_SIZE) |
| 275 | mask |= FS_MODIFY; |
| 276 | |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 277 | /* both times implies a utime(s) call */ |
| 278 | if ((ia_valid & (ATTR_ATIME | ATTR_MTIME)) == (ATTR_ATIME | ATTR_MTIME)) |
Eric Paris | 3c5119c | 2009-05-21 17:01:33 -0400 | [diff] [blame] | 279 | mask |= FS_ATTRIB; |
| 280 | else if (ia_valid & ATTR_ATIME) |
| 281 | mask |= FS_ACCESS; |
| 282 | else if (ia_valid & ATTR_MTIME) |
| 283 | mask |= FS_MODIFY; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 284 | |
Eric Paris | 3c5119c | 2009-05-21 17:01:33 -0400 | [diff] [blame] | 285 | if (ia_valid & ATTR_MODE) |
| 286 | mask |= FS_ATTRIB; |
| 287 | |
| 288 | if (mask) { |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 289 | if (S_ISDIR(inode->i_mode)) |
Eric Paris | b29866a | 2010-10-28 17:21:58 -0400 | [diff] [blame] | 290 | mask |= FS_ISDIR; |
Eric Paris | 28c60e3 | 2009-12-17 21:24:21 -0500 | [diff] [blame] | 291 | |
| 292 | fsnotify_parent(NULL, dentry, mask); |
Eric Paris | 47882c6 | 2009-05-21 17:01:47 -0400 | [diff] [blame] | 293 | fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0); |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 294 | } |
| 295 | } |
| 296 | |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 297 | #endif /* _LINUX_FS_NOTIFY_H */ |