• Amir Goldstein's avatar
    fanotify: report name info for FAN_DIR_MODIFY event · 44d705b0
    Amir Goldstein authored
    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.
    
    Link: https://lore.kernel.org/r/20200319151022.31456-15-amir73il@gmail.comSigned-off-by: default avatarAmir Goldstein <amir73il@gmail.com>
    Signed-off-by: default avatarJan Kara <jack@suse.cz>
    44d705b0
fanotify.c 18.1 KB