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 | |
Matthew Bobrowski | 66917a3 | 2018-11-08 14:12:44 +1100 | [diff] [blame^] | 43 | /* Simple call site for access decisions */ |
Eric Paris | c4ec54b | 2009-12-17 21:24:34 -0500 | [diff] [blame] | 44 | static inline int fsnotify_perm(struct file *file, int mask) |
| 45 | { |
Matthew Bobrowski | 66917a3 | 2018-11-08 14:12:44 +1100 | [diff] [blame^] | 46 | int ret; |
Al Viro | 40212d53 | 2016-11-20 20:24:41 -0500 | [diff] [blame] | 47 | const struct path *path = &file->f_path; |
Miklos Szeredi | 573e178 | 2018-07-18 15:44:44 +0200 | [diff] [blame] | 48 | struct inode *inode = file_inode(file); |
Eric Paris | fb1cfb8 | 2010-05-12 11:42:29 -0400 | [diff] [blame] | 49 | __u32 fsnotify_mask = 0; |
Eric Paris | c4ec54b | 2009-12-17 21:24:34 -0500 | [diff] [blame] | 50 | |
| 51 | if (file->f_mode & FMODE_NONOTIFY) |
| 52 | return 0; |
| 53 | if (!(mask & (MAY_READ | MAY_OPEN))) |
| 54 | return 0; |
Matthew Bobrowski | 66917a3 | 2018-11-08 14:12:44 +1100 | [diff] [blame^] | 55 | if (mask & MAY_OPEN) { |
Eric Paris | c4ec54b | 2009-12-17 21:24:34 -0500 | [diff] [blame] | 56 | fsnotify_mask = FS_OPEN_PERM; |
Matthew Bobrowski | 66917a3 | 2018-11-08 14:12:44 +1100 | [diff] [blame^] | 57 | |
| 58 | if (file->f_flags & __FMODE_EXEC) { |
| 59 | ret = fsnotify_path(inode, path, FS_OPEN_EXEC_PERM); |
| 60 | |
| 61 | if (ret) |
| 62 | return ret; |
| 63 | } |
| 64 | } else if (mask & MAY_READ) { |
Eric Paris | fb1cfb8 | 2010-05-12 11:42:29 -0400 | [diff] [blame] | 65 | fsnotify_mask = FS_ACCESS_PERM; |
Matthew Bobrowski | 66917a3 | 2018-11-08 14:12:44 +1100 | [diff] [blame^] | 66 | } |
Eric Paris | c4ec54b | 2009-12-17 21:24:34 -0500 | [diff] [blame] | 67 | |
Matthew Bobrowski | a704bba | 2018-11-08 14:10:03 +1100 | [diff] [blame] | 68 | return fsnotify_path(inode, path, fsnotify_mask); |
Eric Paris | c4ec54b | 2009-12-17 21:24:34 -0500 | [diff] [blame] | 69 | } |
| 70 | |
Nick Piggin | c32ccd8 | 2006-03-25 03:07:09 -0800 | [diff] [blame] | 71 | /* |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 72 | * fsnotify_link_count - inode's link count changed |
| 73 | */ |
| 74 | static inline void fsnotify_link_count(struct inode *inode) |
| 75 | { |
Eric Paris | 47882c6 | 2009-05-21 17:01:47 -0400 | [diff] [blame] | 76 | fsnotify(inode, FS_ATTRIB, inode, FSNOTIFY_EVENT_INODE, NULL, 0); |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | /* |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 80 | * fsnotify_move - file old_name at old_dir was moved to new_name at new_dir |
| 81 | */ |
| 82 | 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] | 83 | const unsigned char *old_name, |
Al Viro | 5a190ae | 2007-06-07 12:19:32 -0400 | [diff] [blame] | 84 | int isdir, struct inode *target, struct dentry *moved) |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 85 | { |
Al Viro | 5a190ae | 2007-06-07 12:19:32 -0400 | [diff] [blame] | 86 | struct inode *source = moved->d_inode; |
Eric Paris | 47882c6 | 2009-05-21 17:01:47 -0400 | [diff] [blame] | 87 | u32 fs_cookie = fsnotify_get_cookie(); |
Eric Paris | ff52cc2 | 2009-06-11 11:09:47 -0400 | [diff] [blame] | 88 | __u32 old_dir_mask = (FS_EVENT_ON_CHILD | FS_MOVED_FROM); |
| 89 | __u32 new_dir_mask = (FS_EVENT_ON_CHILD | FS_MOVED_TO); |
Eric Paris | 59b0df2 | 2010-02-08 12:53:52 -0500 | [diff] [blame] | 90 | const unsigned char *new_name = moved->d_name.name; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 91 | |
Eric Paris | ff52cc2 | 2009-06-11 11:09:47 -0400 | [diff] [blame] | 92 | if (old_dir == new_dir) |
| 93 | old_dir_mask |= FS_DN_RENAME; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 94 | |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 95 | if (isdir) { |
Eric Paris | b29866a | 2010-10-28 17:21:58 -0400 | [diff] [blame] | 96 | old_dir_mask |= FS_ISDIR; |
| 97 | new_dir_mask |= FS_ISDIR; |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 98 | } |
| 99 | |
Jan Kara | 6ee8e25 | 2015-02-10 14:08:32 -0800 | [diff] [blame] | 100 | fsnotify(old_dir, old_dir_mask, source, FSNOTIFY_EVENT_INODE, old_name, |
| 101 | fs_cookie); |
| 102 | fsnotify(new_dir, new_dir_mask, source, FSNOTIFY_EVENT_INODE, new_name, |
| 103 | fs_cookie); |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 104 | |
Eric Paris | 2dfc1ca | 2009-12-17 20:30:52 -0500 | [diff] [blame] | 105 | if (target) |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 106 | fsnotify_link_count(target); |
John McCutchan | 89204c4 | 2005-08-15 12:13:28 -0400 | [diff] [blame] | 107 | |
Eric Paris | 2dfc1ca | 2009-12-17 20:30:52 -0500 | [diff] [blame] | 108 | if (source) |
Eric Paris | 47882c6 | 2009-05-21 17:01:47 -0400 | [diff] [blame] | 109 | 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] | 110 | audit_inode_child(new_dir, moved, AUDIT_TYPE_CHILD_CREATE); |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | /* |
Eric Paris | 3be25f4 | 2009-05-21 17:01:26 -0400 | [diff] [blame] | 114 | * fsnotify_inode_delete - and inode is being evicted from cache, clean up is needed |
| 115 | */ |
| 116 | static inline void fsnotify_inode_delete(struct inode *inode) |
| 117 | { |
| 118 | __fsnotify_inode_delete(inode); |
| 119 | } |
| 120 | |
| 121 | /* |
Andreas Gruenbacher | ca9c726 | 2009-12-17 21:24:27 -0500 | [diff] [blame] | 122 | * fsnotify_vfsmount_delete - a vfsmount is being destroyed, clean up is needed |
| 123 | */ |
| 124 | static inline void fsnotify_vfsmount_delete(struct vfsmount *mnt) |
| 125 | { |
| 126 | __fsnotify_vfsmount_delete(mnt); |
| 127 | } |
| 128 | |
| 129 | /* |
John McCutchan | 7a91bf7 | 2005-08-08 13:52:16 -0400 | [diff] [blame] | 130 | * fsnotify_nameremove - a filename was removed from a directory |
| 131 | */ |
| 132 | static inline void fsnotify_nameremove(struct dentry *dentry, int isdir) |
| 133 | { |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 134 | __u32 mask = FS_DELETE; |
| 135 | |
John McCutchan | 7a91bf7 | 2005-08-08 13:52:16 -0400 | [diff] [blame] | 136 | if (isdir) |
Eric Paris | b29866a | 2010-10-28 17:21:58 -0400 | [diff] [blame] | 137 | mask |= FS_ISDIR; |
Eric Paris | c28f7e5 | 2009-05-21 17:01:29 -0400 | [diff] [blame] | 138 | |
Eric Paris | 28c60e3 | 2009-12-17 21:24:21 -0500 | [diff] [blame] | 139 | fsnotify_parent(NULL, dentry, mask); |
John McCutchan | 7a91bf7 | 2005-08-08 13:52:16 -0400 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | /* |
| 143 | * fsnotify_inoderemove - an inode is going away |
| 144 | */ |
| 145 | static inline void fsnotify_inoderemove(struct inode *inode) |
| 146 | { |
Eric Paris | 47882c6 | 2009-05-21 17:01:47 -0400 | [diff] [blame] | 147 | fsnotify(inode, FS_DELETE_SELF, inode, FSNOTIFY_EVENT_INODE, NULL, 0); |
Eric Paris | 3be25f4 | 2009-05-21 17:01:26 -0400 | [diff] [blame] | 148 | __fsnotify_inode_delete(inode); |
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_create - 'name' was linked in |
| 153 | */ |
Amy Griffis | f38aa94 | 2005-11-03 15:57:06 +0000 | [diff] [blame] | 154 | static inline void fsnotify_create(struct inode *inode, struct dentry *dentry) |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 155 | { |
Jeff Layton | 4fa6b5e | 2012-10-10 15:25:25 -0400 | [diff] [blame] | 156 | audit_inode_child(inode, dentry, AUDIT_TYPE_CHILD_CREATE); |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 157 | |
Eric Paris | 47882c6 | 2009-05-21 17:01:47 -0400 | [diff] [blame] | 158 | 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] | 159 | } |
| 160 | |
| 161 | /* |
Jan Kara | ece9591 | 2008-02-06 01:37:13 -0800 | [diff] [blame] | 162 | * fsnotify_link - new hardlink in 'inode' directory |
| 163 | * Note: We have to pass also the linked inode ptr as some filesystems leave |
| 164 | * new_dentry->d_inode NULL and instantiate inode pointer later |
| 165 | */ |
| 166 | static inline void fsnotify_link(struct inode *dir, struct inode *inode, struct dentry *new_dentry) |
| 167 | { |
Jan Kara | ece9591 | 2008-02-06 01:37:13 -0800 | [diff] [blame] | 168 | fsnotify_link_count(inode); |
Jeff Layton | 4fa6b5e | 2012-10-10 15:25:25 -0400 | [diff] [blame] | 169 | audit_inode_child(dir, new_dentry, AUDIT_TYPE_CHILD_CREATE); |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 170 | |
Eric Paris | 47882c6 | 2009-05-21 17:01:47 -0400 | [diff] [blame] | 171 | 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] | 172 | } |
| 173 | |
| 174 | /* |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 175 | * fsnotify_mkdir - directory 'name' was created |
| 176 | */ |
Amy Griffis | f38aa94 | 2005-11-03 15:57:06 +0000 | [diff] [blame] | 177 | static inline void fsnotify_mkdir(struct inode *inode, struct dentry *dentry) |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 178 | { |
Eric Paris | b29866a | 2010-10-28 17:21:58 -0400 | [diff] [blame] | 179 | __u32 mask = (FS_CREATE | FS_ISDIR); |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 180 | struct inode *d_inode = dentry->d_inode; |
| 181 | |
Jeff Layton | 4fa6b5e | 2012-10-10 15:25:25 -0400 | [diff] [blame] | 182 | audit_inode_child(inode, dentry, AUDIT_TYPE_CHILD_CREATE); |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 183 | |
Eric Paris | 47882c6 | 2009-05-21 17:01:47 -0400 | [diff] [blame] | 184 | 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] | 185 | } |
| 186 | |
| 187 | /* |
| 188 | * fsnotify_access - file was read |
| 189 | */ |
Eric Paris | 2a12a9d | 2009-12-17 21:24:21 -0500 | [diff] [blame] | 190 | static inline void fsnotify_access(struct file *file) |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 191 | { |
Al Viro | 40212d53 | 2016-11-20 20:24:41 -0500 | [diff] [blame] | 192 | const struct path *path = &file->f_path; |
Miklos Szeredi | 573e178 | 2018-07-18 15:44:44 +0200 | [diff] [blame] | 193 | struct inode *inode = file_inode(file); |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 194 | __u32 mask = FS_ACCESS; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 195 | |
| 196 | if (S_ISDIR(inode->i_mode)) |
Eric Paris | b29866a | 2010-10-28 17:21:58 -0400 | [diff] [blame] | 197 | mask |= FS_ISDIR; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 198 | |
Matthew Bobrowski | a704bba | 2018-11-08 14:10:03 +1100 | [diff] [blame] | 199 | if (!(file->f_mode & FMODE_NONOTIFY)) |
| 200 | fsnotify_path(inode, path, mask); |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | /* |
| 204 | * fsnotify_modify - file was modified |
| 205 | */ |
Eric Paris | 2a12a9d | 2009-12-17 21:24:21 -0500 | [diff] [blame] | 206 | static inline void fsnotify_modify(struct file *file) |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 207 | { |
Al Viro | 40212d53 | 2016-11-20 20:24:41 -0500 | [diff] [blame] | 208 | const struct path *path = &file->f_path; |
Miklos Szeredi | 573e178 | 2018-07-18 15:44:44 +0200 | [diff] [blame] | 209 | struct inode *inode = file_inode(file); |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 210 | __u32 mask = FS_MODIFY; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 211 | |
| 212 | if (S_ISDIR(inode->i_mode)) |
Eric Paris | b29866a | 2010-10-28 17:21:58 -0400 | [diff] [blame] | 213 | mask |= FS_ISDIR; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 214 | |
Matthew Bobrowski | a704bba | 2018-11-08 14:10:03 +1100 | [diff] [blame] | 215 | if (!(file->f_mode & FMODE_NONOTIFY)) |
| 216 | fsnotify_path(inode, path, mask); |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | /* |
| 220 | * fsnotify_open - file was opened |
| 221 | */ |
Eric Paris | 2a12a9d | 2009-12-17 21:24:21 -0500 | [diff] [blame] | 222 | static inline void fsnotify_open(struct file *file) |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 223 | { |
Al Viro | 40212d53 | 2016-11-20 20:24:41 -0500 | [diff] [blame] | 224 | const struct path *path = &file->f_path; |
Miklos Szeredi | 573e178 | 2018-07-18 15:44:44 +0200 | [diff] [blame] | 225 | struct inode *inode = file_inode(file); |
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 | b29866a | 2010-10-28 17:21:58 -0400 | [diff] [blame] | 229 | mask |= FS_ISDIR; |
Matthew Bobrowski | 9b076f1 | 2018-11-08 14:07:14 +1100 | [diff] [blame] | 230 | if (file->f_flags & __FMODE_EXEC) |
| 231 | mask |= FS_OPEN_EXEC; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 232 | |
Matthew Bobrowski | a704bba | 2018-11-08 14:10:03 +1100 | [diff] [blame] | 233 | fsnotify_path(inode, path, mask); |
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 | { |
Al Viro | 40212d53 | 2016-11-20 20:24:41 -0500 | [diff] [blame] | 241 | const struct path *path = &file->f_path; |
Miklos Szeredi | 573e178 | 2018-07-18 15:44:44 +0200 | [diff] [blame] | 242 | struct inode *inode = file_inode(file); |
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 | b29866a | 2010-10-28 17:21:58 -0400 | [diff] [blame] | 247 | mask |= FS_ISDIR; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 248 | |
Matthew Bobrowski | a704bba | 2018-11-08 14:10:03 +1100 | [diff] [blame] | 249 | if (!(file->f_mode & FMODE_NONOTIFY)) |
| 250 | fsnotify_path(inode, path, mask); |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | /* |
| 254 | * fsnotify_xattr - extended attributes were changed |
| 255 | */ |
| 256 | static inline void fsnotify_xattr(struct dentry *dentry) |
| 257 | { |
| 258 | struct inode *inode = dentry->d_inode; |
Eric Paris | 9058652 | 2009-05-21 17:01:20 -0400 | [diff] [blame] | 259 | __u32 mask = FS_ATTRIB; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 260 | |
| 261 | if (S_ISDIR(inode->i_mode)) |
Eric Paris | b29866a | 2010-10-28 17:21:58 -0400 | [diff] [blame] | 262 | mask |= FS_ISDIR; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 263 | |
Eric Paris | 28c60e3 | 2009-12-17 21:24:21 -0500 | [diff] [blame] | 264 | fsnotify_parent(NULL, dentry, mask); |
Eric Paris | 47882c6 | 2009-05-21 17:01:47 -0400 | [diff] [blame] | 265 | fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0); |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | /* |
| 269 | * fsnotify_change - notify_change event. file was modified and/or metadata |
| 270 | * was changed. |
| 271 | */ |
| 272 | static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid) |
| 273 | { |
| 274 | struct inode *inode = dentry->d_inode; |
Eric Paris | 3c5119c | 2009-05-21 17:01:33 -0400 | [diff] [blame] | 275 | __u32 mask = 0; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 276 | |
Eric Paris | 3c5119c | 2009-05-21 17:01:33 -0400 | [diff] [blame] | 277 | if (ia_valid & ATTR_UID) |
| 278 | mask |= FS_ATTRIB; |
| 279 | if (ia_valid & ATTR_GID) |
| 280 | mask |= FS_ATTRIB; |
| 281 | if (ia_valid & ATTR_SIZE) |
| 282 | mask |= FS_MODIFY; |
| 283 | |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 284 | /* both times implies a utime(s) call */ |
| 285 | if ((ia_valid & (ATTR_ATIME | ATTR_MTIME)) == (ATTR_ATIME | ATTR_MTIME)) |
Eric Paris | 3c5119c | 2009-05-21 17:01:33 -0400 | [diff] [blame] | 286 | mask |= FS_ATTRIB; |
| 287 | else if (ia_valid & ATTR_ATIME) |
| 288 | mask |= FS_ACCESS; |
| 289 | else if (ia_valid & ATTR_MTIME) |
| 290 | mask |= FS_MODIFY; |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 291 | |
Eric Paris | 3c5119c | 2009-05-21 17:01:33 -0400 | [diff] [blame] | 292 | if (ia_valid & ATTR_MODE) |
| 293 | mask |= FS_ATTRIB; |
| 294 | |
| 295 | if (mask) { |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 296 | if (S_ISDIR(inode->i_mode)) |
Eric Paris | b29866a | 2010-10-28 17:21:58 -0400 | [diff] [blame] | 297 | mask |= FS_ISDIR; |
Eric Paris | 28c60e3 | 2009-12-17 21:24:21 -0500 | [diff] [blame] | 298 | |
| 299 | fsnotify_parent(NULL, dentry, mask); |
Eric Paris | 47882c6 | 2009-05-21 17:01:47 -0400 | [diff] [blame] | 300 | fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0); |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 301 | } |
| 302 | } |
| 303 | |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 304 | #endif /* _LINUX_FS_NOTIFY_H */ |