History

fanotify: report name info for FAN_DIR_MODIFY event

Report event FAN_DIR_MODIFY with name in a variable length record similar to how fid's are reported. With name info reporting implemented, setting FAN_DIR_MODIFY in mark mask is now allowed. When events are reported with name, the reported fid identifies the directory and the name follows the fid. The info record type for this event info is FAN_EVENT_INFO_TYPE_DFID_NAME. For now, all reported events have at most one info record which is either FAN_EVENT_INFO_TYPE_FID or FAN_EVENT_INFO_TYPE_DFID_NAME (for FAN_DIR_MODIFY). Later on, events "on child" will report both records. There are several ways that an application can use this information: 1. When watching a single directory, the name is always relative to the watched directory, so application need to fstatat(2) the name relative to the watched directory. 2. When watching a set of directories, the application could keep a map of dirfd for all watched directories and hash the map by fid obtained with name_to_handle_at(2). When getting a name event, the fid in the event info could be used to lookup the base dirfd in the map and then call fstatat(2) with that dirfd. 3. When watching a filesystem (FAN_MARK_FILESYSTEM) or a large set of directories, the application could use open_by_handle_at(2) with the fid in event info to obtain dirfd for the directory where event happened and call fstatat(2) with this dirfd. The last option scales better for a large number of watched directories. The first two options may be available in the future also for non privileged fanotify watchers, because open_by_handle_at(2) requires the CAP_DAC_READ_SEARCH capability.

Amir Goldstein committed 6 years ago

Commit 44d705b1 parent cacfb954 files · +100 −30Browse files

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

Unified · Split

include/uapi/linux/fanotify.h+7−1
@@ -117,6 +117,7 @@ struct fanotify_event_metadata { · 116 unmodified lines
117117 };
118118
119119 #define FAN_EVENT_INFO_TYPE_FID 1
120+#define FAN_EVENT_INFO_TYPE_DFID_NAME 2
120121
121122 /* Variable length info record following event metadata */
122123 struct fanotify_event_info_header {
@@ -125,7 +126,12 @@ struct fanotify_event_info_header { · 2 unmodified lines
125126 __u16 len;
126127 };
127128
128−/* Unique file identifier info record */
129+/*
130+ * Unique file identifier info record. This is used both for
131+ * FAN_EVENT_INFO_TYPE_FID records and for FAN_EVENT_INFO_TYPE_DFID_NAME
132+ * records. For FAN_EVENT_INFO_TYPE_DFID_NAME there is additionally a null
133+ * terminated name immediately after the file handle.
134+ */
129135 struct fanotify_event_info_fid {
130136 struct fanotify_event_info_header hdr;
131137 __kernel_fsid_t fsid;