Skip to content

Commit 8cc3b1c

Browse files
amir73iljankara
authored andcommitted
fanotify: wire up FAN_RENAME event
FAN_RENAME is the successor of FAN_MOVED_FROM and FAN_MOVED_TO and can be used to get the old and new parent+name information in a single event. FAN_MOVED_FROM and FAN_MOVED_TO are still supported for backward compatibility, but it makes little sense to use them together with FAN_RENAME in the same group. FAN_RENAME uses special info type records to report the old and new parent+name, so reporting only old and new parent id is less useful and was not implemented. Therefore, FAN_REANAME requires a group with flag FAN_REPORT_NAME. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Amir Goldstein <[email protected]> Signed-off-by: Jan Kara <[email protected]>
1 parent 7326e38 commit 8cc3b1c

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

fs/notify/fanotify/fanotify.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ static int fanotify_handle_event(struct fsnotify_group *group, u32 mask,
930930
BUILD_BUG_ON(FAN_FS_ERROR != FS_ERROR);
931931
BUILD_BUG_ON(FAN_RENAME != FS_RENAME);
932932

933-
BUILD_BUG_ON(HWEIGHT32(ALL_FANOTIFY_EVENT_BITS) != 20);
933+
BUILD_BUG_ON(HWEIGHT32(ALL_FANOTIFY_EVENT_BITS) != 21);
934934

935935
mask = fanotify_group_event_mask(group, iter_info, &match_mask,
936936
mask, data, data_type, dir);

fs/notify/fanotify/fanotify_user.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,6 +1586,14 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask,
15861586
(!fid_mode || mark_type == FAN_MARK_MOUNT))
15871587
goto fput_and_out;
15881588

1589+
/*
1590+
* FAN_RENAME uses special info type records to report the old and
1591+
* new parent+name. Reporting only old and new parent id is less
1592+
* useful and was not implemented.
1593+
*/
1594+
if (mask & FAN_RENAME && !(fid_mode & FAN_REPORT_NAME))
1595+
goto fput_and_out;
1596+
15891597
if (flags & FAN_MARK_FLUSH) {
15901598
ret = 0;
15911599
if (mark_type == FAN_MARK_MOUNT)

include/linux/fanotify.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ extern struct ctl_table fanotify_table[]; /* for sysctl */
8282
* Directory entry modification events - reported only to directory
8383
* where entry is modified and not to a watching parent.
8484
*/
85-
#define FANOTIFY_DIRENT_EVENTS (FAN_MOVE | FAN_CREATE | FAN_DELETE)
85+
#define FANOTIFY_DIRENT_EVENTS (FAN_MOVE | FAN_CREATE | FAN_DELETE | \
86+
FAN_RENAME)
8687

8788
/* Events that can be reported with event->fd */
8889
#define FANOTIFY_FD_EVENTS (FANOTIFY_PATH_EVENTS | FANOTIFY_PERM_EVENTS)

0 commit comments

Comments
 (0)