History

fsnotify: report FS_ISDIR flag with MOVE_SELF and DELETE_SELF events

We need to report FS_ISDIR flag with MOVE_SELF and DELETE_SELF events for fanotify, because fanotify API requires the user to explicitly request events on directories by FAN_ONDIR flag. inotify never reported IN_ISDIR with those events. It looks like an oversight, but to avoid the risk of breaking existing inotify programs, mask the FS_ISDIR flag out when reprting those events to inotify backend. We also add the FS_ISDIR flag with FS_ATTRIB event in the case of rename over an empty target directory. inotify did not report IN_ISDIR in this case, but it normally does report IN_ISDIR along with IN_ATTRIB event, so in this case, we do not mask out the FS_ISDIR flag. [JK: Simplify the checks in fsnotify_move()]

Amir Goldstein committed 7 years ago

Commit 0a20df71 parent 73072282 files · +26 −4Browse files

Showing the changes to include/linux (1 of 2 files). Show all

Unified · Split

include/linux/fsnotify.h+17−4
@@ -87,7 +87,12 @@ static inline int fsnotify_perm(struct file *file, int mask) · 86 unmodified lines
87 */87 */
88static inline void fsnotify_link_count(struct inode *inode)88static inline void fsnotify_link_count(struct inode *inode)
89{89{
90 fsnotify(inode, FS_ATTRIB, inode, FSNOTIFY_EVENT_INODE, NULL, 0);90 __u32 mask = FS_ATTRIB;
91
92 if (S_ISDIR(inode->i_mode))
93 mask |= FS_ISDIR;
94
95 fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
91}96}
92 97
93/*98/*
@@ -95,12 +100,14 @@ static inline void fsnotify_link_count(struct inode *inode) · 1 unmodified line
95 */100 */
96static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir,101static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir,
97 const unsigned char *old_name,102 const unsigned char *old_name,
98 int isdir, struct inode *target, struct dentry *moved)103 int isdir, struct inode *target,
104 struct dentry *moved)
99{105{
100 struct inode *source = moved->d_inode;106 struct inode *source = moved->d_inode;
101 u32 fs_cookie = fsnotify_get_cookie();107 u32 fs_cookie = fsnotify_get_cookie();
102 __u32 old_dir_mask = FS_MOVED_FROM;108 __u32 old_dir_mask = FS_MOVED_FROM;
103 __u32 new_dir_mask = FS_MOVED_TO;109 __u32 new_dir_mask = FS_MOVED_TO;
110 __u32 mask = FS_MOVE_SELF;
104 const unsigned char *new_name = moved->d_name.name;111 const unsigned char *new_name = moved->d_name.name;
105 112
106 if (old_dir == new_dir)113 if (old_dir == new_dir)
@@ -109,6 +116,7 @@ static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir, · 2 unmodified lines
109 if (isdir) {116 if (isdir) {
110 old_dir_mask |= FS_ISDIR;117 old_dir_mask |= FS_ISDIR;
111 new_dir_mask |= FS_ISDIR;118 new_dir_mask |= FS_ISDIR;
119 mask |= FS_ISDIR;
112 }120 }
113 121
114 fsnotify(old_dir, old_dir_mask, source, FSNOTIFY_EVENT_INODE, old_name,122 fsnotify(old_dir, old_dir_mask, source, FSNOTIFY_EVENT_INODE, old_name,
@@ -120,7 +128,7 @@ static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir, · 5 unmodified lines
120 fsnotify_link_count(target);128 fsnotify_link_count(target);
121 129
122 if (source)130 if (source)
123 fsnotify(source, FS_MOVE_SELF, moved->d_inode, FSNOTIFY_EVENT_INODE, NULL, 0);131 fsnotify(source, mask, source, FSNOTIFY_EVENT_INODE, NULL, 0);
124 audit_inode_child(new_dir, moved, AUDIT_TYPE_CHILD_CREATE);132 audit_inode_child(new_dir, moved, AUDIT_TYPE_CHILD_CREATE);
125}133}
126 134
@@ -178,7 +186,12 @@ static inline void fsnotify_nameremove(struct dentry *dentry, int isdir) · 51 unmodified lines
178 */186 */
179static inline void fsnotify_inoderemove(struct inode *inode)187static inline void fsnotify_inoderemove(struct inode *inode)
180{188{
181 fsnotify(inode, FS_DELETE_SELF, inode, FSNOTIFY_EVENT_INODE, NULL, 0);189 __u32 mask = FS_DELETE_SELF;
190
191 if (S_ISDIR(inode->i_mode))
192 mask |= FS_ISDIR;
193
194 fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
182 __fsnotify_inode_delete(inode);195 __fsnotify_inode_delete(inode);
183}196}
184 197

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t