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 | |
Amir Goldstein | 5f02a87 | 2019-01-10 19:04:28 +0200 | [diff] [blame] | 20 | /* |
| 21 | * Notify this @dir inode about a change in the directory entry @dentry. |
| 22 | * |
| 23 | * Unlike fsnotify_parent(), the event will be reported regardless of the |
| 24 | * FS_EVENT_ON_CHILD mask on the parent inode. |
| 25 | */ |
| 26 | static inline int fsnotify_dirent(struct inode *dir, struct dentry *dentry, |
| 27 | __u32 mask) |
| 28 | { |
| 29 | return fsnotify(dir, mask, d_inode(dentry), FSNOTIFY_EVENT_INODE, |
Al Viro | 25b229d | 2019-04-26 13:37:25 -0400 | [diff] [blame] | 30 | &dentry->d_name, 0); |
Amir Goldstein | 5f02a87 | 2019-01-10 19:04:28 +0200 | [diff] [blame] | 31 | } |
| 32 | |
Eric Paris | c28f7e5 | 2009-05-21 17:01:29 -0400 | [diff] [blame] | 33 | /* Notify this dentry's parent about a child's events. */ |
Amir Goldstein | 5f02a87 | 2019-01-10 19:04:28 +0200 | [diff] [blame] | 34 | static inline int fsnotify_parent(const struct path *path, |
| 35 | struct dentry *dentry, __u32 mask) |
Eric Paris | c28f7e5 | 2009-05-21 17:01:29 -0400 | [diff] [blame] | 36 | { |
Andreas Gruenbacher | 72acc85 | 2009-12-17 21:24:24 -0500 | [diff] [blame] | 37 | if (!dentry) |
Linus Torvalds | 2069601 | 2010-08-12 14:23:04 -0700 | [diff] [blame] | 38 | dentry = path->dentry; |
Eric Paris | 28c60e3 | 2009-12-17 21:24:21 -0500 | [diff] [blame] | 39 | |
Eric Paris | 5242039 | 2010-10-28 17:21:56 -0400 | [diff] [blame] | 40 | return __fsnotify_parent(path, dentry, mask); |
Eric Paris | c28f7e5 | 2009-05-21 17:01:29 -0400 | [diff] [blame] | 41 | } |
| 42 | |
Matthew Bobrowski | a704bba | 2018-11-08 14:10:03 +1100 | [diff] [blame] | 43 | /* |
| 44 | * Simple wrapper to consolidate calls fsnotify_parent()/fsnotify() when |
| 45 | * an event is on a path. |
| 46 | */ |
| 47 | static inline int fsnotify_path(struct inode *inode, const struct path *path, |
| 48 | __u32 mask) |
| 49 | { |
| 50 | int ret = fsnotify_parent(path, NULL, mask); |
| 51 | |
| 52 | if (ret) |
| 53 | return ret; |
| 54 | return fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0); |
| 55 | } |
| 56 | |
Matthew Bobrowski | 66917a3 | 2018-11-08 14:12:44 +1100 | [diff] [blame] | 57 | /* Simple call site for access decisions */ |
Eric Paris | c4ec54b | 2009-12-17 21:24:34 -0500 | [diff] [blame] | 58 | static inline int fsnotify_perm(struct file *file, int mask) |
| 59 | { |
Matthew Bobrowski | 66917a3 | 2018-11-08 14:12:44 +1100 | [diff] [blame] | 60 | int ret; |
Al Viro | 40212d5 | 2016-11-20 20:24:41 -0500 | [diff] [blame] | 61 | const struct path *path = &file->f_path; |
Miklos Szeredi | 573e178 | 2018-07-18 15:44:44 +0200 | [diff] [blame] | 62 | struct inode *inode = file_inode(file); |
Eric Paris | fb1cfb8 | 2010-05-12 11:42:29 -0400 | [diff] [blame] | 63 | __u32 fsnotify_mask = 0; |
Eric Paris | c4ec54b | 2009-12-17 21:24:34 -0500 | [diff] [blame] | 64 | |
| 65 | if (file->f_mode & FMODE_NONOTIFY) |
| 66 | return 0; |
| 67 | if (!(mask & (MAY_READ | MAY_OPEN))) |
| 68 | return 0; |
Matthew Bobrowski | 66917a3 | 2018-11-08 14:12:44 +1100 | [diff] [blame] | 69 | if (mask & MAY_OPEN) { |
Eric Paris | c4ec54b | 2009-12-17 21:24:34 -0500 | [diff] [blame] | 70 | fsnotify_mask = FS_OPEN_PERM; |
Matthew Bobrowski | 66917a3 | 2018-11-08 14:12:44 +1100 | [diff] [blame] | 71 | |
| 72 | if (file->f_flags & __FMODE_EXEC) { |
| 73 | ret = fsnotify_path(inode, path, FS_OPEN_EXEC_PERM); |
| 74 | |
| 75 | if (ret) |
| 76 | return ret; |
| 77 | } |
| 78 | } else if (mask & MAY_READ) { |
Eric Paris | fb1cfb8 | 2010-05-12 11:42:29 -0400 | [diff] [blame] | 79 | fsnotify_mask = FS_ACCESS_PERM; |
Matthew Bobrowski | 66917a3 | 2018-11-08 14:12:44 +1100 | [diff] [blame] | 80 | } |
Eric Paris | c4ec54b | 2009-12-17 21:24:34 -0500 | [diff] [blame] | 81 | |
Amir Goldstein | 0321e03 | 2019-01-10 19:04:41 +0200 | [diff] [blame] | 82 | if (S_ISDIR(inode->i_mode)) |
| 83 | fsnotify_mask |= FS_ISDIR; |
| 84 | |
Matthew Bobrowski | a704bba | 2018-11-08 14:10:03 +1100 | [diff] [blame] | 85 | return fsnotify_path(inode, path, fsnotify_mask); |
Eric Paris | c4ec54b | 2009-12-17 21:24:34 -0500 | [diff] [blame] | 86 | } |
| 87 | |
Nick Piggin | c32ccd8 | 2006-03-25 03:07:09 -0800 | [diff] [blame] | 88 | /* |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 89 | * fsnotify_link_count - inode's link count changed |
| 90 | */ |
| 91 | static inline void fsnotify_link_count(struct inode *inode) |
| 92 | { |
Amir Goldstein | 0a20df7 | 2019-01-10 19:04:40 +0200 | [diff] [blame] | 93 | __u32 mask = FS_ATTRIB; |
| 94 | |
| 95 | if (S_ISDIR(inode->i_mode)) |
| 96 | mask |= FS_ISDIR; |
| 97 | |
| 98 | fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0); |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | /* |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 102 | * fsnotify_move - file old_name at old_dir was moved to new_name at new_dir |
| 103 | */ |
| 104 | static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir, |
Al Viro | f4ec3a3 | 2019-04-26 13:21:24 -0400 | [diff] [blame] | 105 | const struct qstr *old_name, |
Amir Goldstein | 0a20df7 | 2019-01-10 19:04:40 +0200 | [diff] [blame] | 106 | int isdir, struct inode *target, |
| 107 | struct dentry *moved) |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 108 | { |
Al Viro | 5a190ae | 2007-06-07 12:19:32 -0400 | [diff] [blame] | 109 | struct inode *source = moved->d_inode; |
Eric Paris | 47882c6 | 2009-05-21 17:01:47 -0400 | [diff] [blame] | 110 | u32 fs_cookie = fsnotify_get_cookie(); |
Amir Goldstein | 5f02a87 | 2019-01-10 19:04:28 +0200 | [diff] [blame] | 111 | __u32 old_dir_mask = FS_MOVED_FROM; |
| 112 | __u32 new_dir_mask = FS_MOVED_TO; |
Amir Goldstein | 0a20df7 | 2019-01-10 19:04:40 +0200 | [diff] [blame] | 113 | __u32 mask = FS_MOVE_SELF; |
Al Viro | 25b229d | 2019-04-26 13:37:25 -0400 | [diff] [blame] | 114 | const struct qstr *new_name = &moved->d_name; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 115 | |
Eric Paris | ff52cc2 | 2009-06-11 11:09:47 -0400 | [diff] [blame] | 116 | if (old_dir == new_dir) |
| 117 | old_dir_mask |= FS_DN_RENAME; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 118 | |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 119 | if (isdir) { |
Eric Paris | b29866a | 2010-10-28 17:21:58 -0400 | [diff] [blame] | 120 | old_dir_mask |= FS_ISDIR; |
| 121 | new_dir_mask |= FS_ISDIR; |
Amir Goldstein | 0a20df7 | 2019-01-10 19:04:40 +0200 | [diff] [blame] | 122 | mask |= FS_ISDIR; |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 123 | } |
| 124 | |
Al Viro | 25b229d | 2019-04-26 13:37:25 -0400 | [diff] [blame] | 125 | fsnotify(old_dir, old_dir_mask, source, FSNOTIFY_EVENT_INODE, old_name, |
Jan Kara | 6ee8e25 | 2015-02-10 14:08:32 -0800 | [diff] [blame] | 126 | fs_cookie); |
| 127 | fsnotify(new_dir, new_dir_mask, source, FSNOTIFY_EVENT_INODE, new_name, |
| 128 | fs_cookie); |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 129 | |
Eric Paris | 2dfc1ca | 2009-12-17 20:30:52 -0500 | [diff] [blame] | 130 | if (target) |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 131 | fsnotify_link_count(target); |
John McCutchan | 89204c4 | 2005-08-15 12:13:28 -0400 | [diff] [blame] | 132 | |
Eric Paris | 2dfc1ca | 2009-12-17 20:30:52 -0500 | [diff] [blame] | 133 | if (source) |
Amir Goldstein | 0a20df7 | 2019-01-10 19:04:40 +0200 | [diff] [blame] | 134 | fsnotify(source, mask, source, FSNOTIFY_EVENT_INODE, NULL, 0); |
Jeff Layton | 4fa6b5e | 2012-10-10 15:25:25 -0400 | [diff] [blame] | 135 | audit_inode_child(new_dir, moved, AUDIT_TYPE_CHILD_CREATE); |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | /* |
Eric Paris | 3be25f4 | 2009-05-21 17:01:26 -0400 | [diff] [blame] | 139 | * fsnotify_inode_delete - and inode is being evicted from cache, clean up is needed |
| 140 | */ |
| 141 | static inline void fsnotify_inode_delete(struct inode *inode) |
| 142 | { |
| 143 | __fsnotify_inode_delete(inode); |
| 144 | } |
| 145 | |
| 146 | /* |
Andreas Gruenbacher | ca9c726 | 2009-12-17 21:24:27 -0500 | [diff] [blame] | 147 | * fsnotify_vfsmount_delete - a vfsmount is being destroyed, clean up is needed |
| 148 | */ |
| 149 | static inline void fsnotify_vfsmount_delete(struct vfsmount *mnt) |
| 150 | { |
| 151 | __fsnotify_vfsmount_delete(mnt); |
| 152 | } |
| 153 | |
| 154 | /* |
John McCutchan | 7a91bf7 | 2005-08-08 13:52:16 -0400 | [diff] [blame] | 155 | * fsnotify_inoderemove - an inode is going away |
| 156 | */ |
| 157 | static inline void fsnotify_inoderemove(struct inode *inode) |
| 158 | { |
Amir Goldstein | 0a20df7 | 2019-01-10 19:04:40 +0200 | [diff] [blame] | 159 | __u32 mask = FS_DELETE_SELF; |
| 160 | |
| 161 | if (S_ISDIR(inode->i_mode)) |
| 162 | mask |= FS_ISDIR; |
| 163 | |
| 164 | fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0); |
Eric Paris | 3be25f4 | 2009-05-21 17:01:26 -0400 | [diff] [blame] | 165 | __fsnotify_inode_delete(inode); |
Jan Kara | ece9591 | 2008-02-06 01:37:13 -0800 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | /* |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 169 | * fsnotify_create - 'name' was linked in |
| 170 | */ |
Amy Griffis | f38aa94 | 2005-11-03 15:57:06 +0000 | [diff] [blame] | 171 | static inline void fsnotify_create(struct inode *inode, struct dentry *dentry) |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 172 | { |
Jeff Layton | 4fa6b5e | 2012-10-10 15:25:25 -0400 | [diff] [blame] | 173 | audit_inode_child(inode, dentry, AUDIT_TYPE_CHILD_CREATE); |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 174 | |
Amir Goldstein | 5f02a87 | 2019-01-10 19:04:28 +0200 | [diff] [blame] | 175 | fsnotify_dirent(inode, dentry, FS_CREATE); |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | /* |
Jan Kara | ece9591 | 2008-02-06 01:37:13 -0800 | [diff] [blame] | 179 | * fsnotify_link - new hardlink in 'inode' directory |
| 180 | * Note: We have to pass also the linked inode ptr as some filesystems leave |
| 181 | * new_dentry->d_inode NULL and instantiate inode pointer later |
| 182 | */ |
| 183 | static inline void fsnotify_link(struct inode *dir, struct inode *inode, struct dentry *new_dentry) |
| 184 | { |
Jan Kara | ece9591 | 2008-02-06 01:37:13 -0800 | [diff] [blame] | 185 | fsnotify_link_count(inode); |
Jeff Layton | 4fa6b5e | 2012-10-10 15:25:25 -0400 | [diff] [blame] | 186 | audit_inode_child(dir, new_dentry, AUDIT_TYPE_CHILD_CREATE); |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 187 | |
Al Viro | 25b229d | 2019-04-26 13:37:25 -0400 | [diff] [blame] | 188 | fsnotify(dir, FS_CREATE, inode, FSNOTIFY_EVENT_INODE, &new_dentry->d_name, 0); |
Jan Kara | ece9591 | 2008-02-06 01:37:13 -0800 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | /* |
Amir Goldstein | 116b973 | 2019-05-26 17:34:02 +0300 | [diff] [blame] | 192 | * fsnotify_unlink - 'name' was unlinked |
| 193 | * |
| 194 | * Caller must make sure that dentry->d_name is stable. |
| 195 | */ |
| 196 | static inline void fsnotify_unlink(struct inode *dir, struct dentry *dentry) |
| 197 | { |
| 198 | /* Expected to be called before d_delete() */ |
| 199 | WARN_ON_ONCE(d_is_negative(dentry)); |
| 200 | |
Amir Goldstein | 7377f5b | 2019-05-26 17:34:11 +0300 | [diff] [blame] | 201 | fsnotify_dirent(dir, dentry, FS_DELETE); |
Amir Goldstein | 116b973 | 2019-05-26 17:34:02 +0300 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | /* |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 205 | * fsnotify_mkdir - directory 'name' was created |
| 206 | */ |
Amy Griffis | f38aa94 | 2005-11-03 15:57:06 +0000 | [diff] [blame] | 207 | static inline void fsnotify_mkdir(struct inode *inode, struct dentry *dentry) |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 208 | { |
Jeff Layton | 4fa6b5e | 2012-10-10 15:25:25 -0400 | [diff] [blame] | 209 | audit_inode_child(inode, dentry, AUDIT_TYPE_CHILD_CREATE); |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 210 | |
Amir Goldstein | 5f02a87 | 2019-01-10 19:04:28 +0200 | [diff] [blame] | 211 | fsnotify_dirent(inode, dentry, FS_CREATE | FS_ISDIR); |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | /* |
Amir Goldstein | 116b973 | 2019-05-26 17:34:02 +0300 | [diff] [blame] | 215 | * fsnotify_rmdir - directory 'name' was removed |
| 216 | * |
| 217 | * Caller must make sure that dentry->d_name is stable. |
| 218 | */ |
| 219 | static inline void fsnotify_rmdir(struct inode *dir, struct dentry *dentry) |
| 220 | { |
| 221 | /* Expected to be called before d_delete() */ |
| 222 | WARN_ON_ONCE(d_is_negative(dentry)); |
| 223 | |
Amir Goldstein | 7377f5b | 2019-05-26 17:34:11 +0300 | [diff] [blame] | 224 | fsnotify_dirent(dir, dentry, FS_DELETE | FS_ISDIR); |
Amir Goldstein | 116b973 | 2019-05-26 17:34:02 +0300 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | /* |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 228 | * fsnotify_access - file was read |
| 229 | */ |
Eric Paris | 2a12a9d | 2009-12-17 21:24:21 -0500 | [diff] [blame] | 230 | static inline void fsnotify_access(struct file *file) |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 231 | { |
Al Viro | 40212d5 | 2016-11-20 20:24:41 -0500 | [diff] [blame] | 232 | const struct path *path = &file->f_path; |
Miklos Szeredi | 573e178 | 2018-07-18 15:44:44 +0200 | [diff] [blame] | 233 | struct inode *inode = file_inode(file); |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 234 | __u32 mask = FS_ACCESS; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 235 | |
| 236 | if (S_ISDIR(inode->i_mode)) |
Eric Paris | b29866a | 2010-10-28 17:21:58 -0400 | [diff] [blame] | 237 | mask |= FS_ISDIR; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 238 | |
Matthew Bobrowski | a704bba | 2018-11-08 14:10:03 +1100 | [diff] [blame] | 239 | if (!(file->f_mode & FMODE_NONOTIFY)) |
| 240 | fsnotify_path(inode, path, mask); |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | /* |
| 244 | * fsnotify_modify - file was modified |
| 245 | */ |
Eric Paris | 2a12a9d | 2009-12-17 21:24:21 -0500 | [diff] [blame] | 246 | static inline void fsnotify_modify(struct file *file) |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 247 | { |
Al Viro | 40212d5 | 2016-11-20 20:24:41 -0500 | [diff] [blame] | 248 | const struct path *path = &file->f_path; |
Miklos Szeredi | 573e178 | 2018-07-18 15:44:44 +0200 | [diff] [blame] | 249 | struct inode *inode = file_inode(file); |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 250 | __u32 mask = FS_MODIFY; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 251 | |
| 252 | if (S_ISDIR(inode->i_mode)) |
Eric Paris | b29866a | 2010-10-28 17:21:58 -0400 | [diff] [blame] | 253 | mask |= FS_ISDIR; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 254 | |
Matthew Bobrowski | a704bba | 2018-11-08 14:10:03 +1100 | [diff] [blame] | 255 | if (!(file->f_mode & FMODE_NONOTIFY)) |
| 256 | fsnotify_path(inode, path, mask); |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | /* |
| 260 | * fsnotify_open - file was opened |
| 261 | */ |
Eric Paris | 2a12a9d | 2009-12-17 21:24:21 -0500 | [diff] [blame] | 262 | static inline void fsnotify_open(struct file *file) |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 263 | { |
Al Viro | 40212d5 | 2016-11-20 20:24:41 -0500 | [diff] [blame] | 264 | const struct path *path = &file->f_path; |
Miklos Szeredi | 573e178 | 2018-07-18 15:44:44 +0200 | [diff] [blame] | 265 | struct inode *inode = file_inode(file); |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 266 | __u32 mask = FS_OPEN; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 267 | |
| 268 | if (S_ISDIR(inode->i_mode)) |
Eric Paris | b29866a | 2010-10-28 17:21:58 -0400 | [diff] [blame] | 269 | mask |= FS_ISDIR; |
Matthew Bobrowski | 9b076f1 | 2018-11-08 14:07:14 +1100 | [diff] [blame] | 270 | if (file->f_flags & __FMODE_EXEC) |
| 271 | mask |= FS_OPEN_EXEC; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 272 | |
Matthew Bobrowski | a704bba | 2018-11-08 14:10:03 +1100 | [diff] [blame] | 273 | fsnotify_path(inode, path, mask); |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | /* |
| 277 | * fsnotify_close - file was closed |
| 278 | */ |
| 279 | static inline void fsnotify_close(struct file *file) |
| 280 | { |
Al Viro | 40212d5 | 2016-11-20 20:24:41 -0500 | [diff] [blame] | 281 | const struct path *path = &file->f_path; |
Miklos Szeredi | 573e178 | 2018-07-18 15:44:44 +0200 | [diff] [blame] | 282 | struct inode *inode = file_inode(file); |
Al Viro | aeb5d72 | 2008-09-02 15:28:45 -0400 | [diff] [blame] | 283 | fmode_t mode = file->f_mode; |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 284 | __u32 mask = (mode & FMODE_WRITE) ? FS_CLOSE_WRITE : FS_CLOSE_NOWRITE; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 285 | |
| 286 | if (S_ISDIR(inode->i_mode)) |
Eric Paris | b29866a | 2010-10-28 17:21:58 -0400 | [diff] [blame] | 287 | mask |= FS_ISDIR; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 288 | |
Matthew Bobrowski | a704bba | 2018-11-08 14:10:03 +1100 | [diff] [blame] | 289 | if (!(file->f_mode & FMODE_NONOTIFY)) |
| 290 | fsnotify_path(inode, path, mask); |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | /* |
| 294 | * fsnotify_xattr - extended attributes were changed |
| 295 | */ |
| 296 | static inline void fsnotify_xattr(struct dentry *dentry) |
| 297 | { |
| 298 | struct inode *inode = dentry->d_inode; |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 299 | __u32 mask = FS_ATTRIB; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 300 | |
| 301 | if (S_ISDIR(inode->i_mode)) |
Eric Paris | b29866a | 2010-10-28 17:21:58 -0400 | [diff] [blame] | 302 | mask |= FS_ISDIR; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 303 | |
Eric Paris | 28c60e3 | 2009-12-17 21:24:21 -0500 | [diff] [blame] | 304 | fsnotify_parent(NULL, 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 | /* |
| 309 | * fsnotify_change - notify_change event. file was modified and/or metadata |
| 310 | * was changed. |
| 311 | */ |
| 312 | static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid) |
| 313 | { |
| 314 | struct inode *inode = dentry->d_inode; |
Eric Paris | 3c5119c | 2009-05-21 17:01:33 -0400 | [diff] [blame] | 315 | __u32 mask = 0; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 316 | |
Eric Paris | 3c5119c | 2009-05-21 17:01:33 -0400 | [diff] [blame] | 317 | if (ia_valid & ATTR_UID) |
| 318 | mask |= FS_ATTRIB; |
| 319 | if (ia_valid & ATTR_GID) |
| 320 | mask |= FS_ATTRIB; |
| 321 | if (ia_valid & ATTR_SIZE) |
| 322 | mask |= FS_MODIFY; |
| 323 | |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 324 | /* both times implies a utime(s) call */ |
| 325 | if ((ia_valid & (ATTR_ATIME | ATTR_MTIME)) == (ATTR_ATIME | ATTR_MTIME)) |
Eric Paris | 3c5119c | 2009-05-21 17:01:33 -0400 | [diff] [blame] | 326 | mask |= FS_ATTRIB; |
| 327 | else if (ia_valid & ATTR_ATIME) |
| 328 | mask |= FS_ACCESS; |
| 329 | else if (ia_valid & ATTR_MTIME) |
| 330 | mask |= FS_MODIFY; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 331 | |
Eric Paris | 3c5119c | 2009-05-21 17:01:33 -0400 | [diff] [blame] | 332 | if (ia_valid & ATTR_MODE) |
| 333 | mask |= FS_ATTRIB; |
| 334 | |
| 335 | if (mask) { |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 336 | if (S_ISDIR(inode->i_mode)) |
Eric Paris | b29866a | 2010-10-28 17:21:58 -0400 | [diff] [blame] | 337 | mask |= FS_ISDIR; |
Eric Paris | 28c60e3 | 2009-12-17 21:24:21 -0500 | [diff] [blame] | 338 | |
| 339 | fsnotify_parent(NULL, dentry, mask); |
Eric Paris | 47882c6 | 2009-05-21 17:01:47 -0400 | [diff] [blame] | 340 | fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0); |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 341 | } |
| 342 | } |
| 343 | |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 344 | #endif /* _LINUX_FS_NOTIFY_H */ |