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
8787 */
8888 static inline void fsnotify_link_count(struct inode *inode)
8989 {
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);
9196 }
9297
9398 /*
@@ -95,12 +100,14 @@ static inline void fsnotify_link_count(struct inode *inode) · 1 unmodified line
95100 */
96101 static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir,
97102 const unsigned char *old_name,
98− int isdir, struct inode *target, struct dentry *moved)
103+ int isdir, struct inode *target,
104+ struct dentry *moved)
99105 {
100106 struct inode *source = moved->d_inode;
101107 u32 fs_cookie = fsnotify_get_cookie();
102108 __u32 old_dir_mask = FS_MOVED_FROM;
103109 __u32 new_dir_mask = FS_MOVED_TO;
110+ __u32 mask = FS_MOVE_SELF;
104111 const unsigned char *new_name = moved->d_name.name;
105112
106113 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
109116 if (isdir) {
110117 old_dir_mask |= FS_ISDIR;
111118 new_dir_mask |= FS_ISDIR;
119+ mask |= FS_ISDIR;
112120 }
113121
114122 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
120128 fsnotify_link_count(target);
121129
122130 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);
124132 audit_inode_child(new_dir, moved, AUDIT_TYPE_CHILD_CREATE);
125133 }
126134
@@ -178,7 +186,12 @@ static inline void fsnotify_nameremove(struct dentry *dentry, int isdir) · 51 unmodified lines
178186 */
179187 static inline void fsnotify_inoderemove(struct inode *inode)
180188 {
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);
182195 __fsnotify_inode_delete(inode);
183196 }
184197

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