Man page - fanotify_mark(2)

Packages contains this manual

Available languages:

en fr ja

Manual

FANOTIFY_MARK

名 前
書 式
説 明
返 り 値
エ ラ ー
バ ー ジ ョ ン
準 拠
注 意
FAN_OPEN_EXEC と FAN_OPEN_EXEC_PERM
バ グ
関 連 項 目
こ の 文 書 に つ い て

名 前

fanotify_mark - フ ァ イ ル シ ス テ ム オ ブ ジ ェ ク ト へ の fanotify マ ー ク の 追 加 、 削 除 、 変 更

書 式

#include <sys/fanotify.h>

int fanotify_mark(int fanotify_fd , unsigned int flags ,
uint64_t
mask , int dirfd , const char * pathname );

説 明

fanotify API の 概 要 に つ い て は fanotify (7) を 参 照 。

fanotify_mark () は フ ァ イ ル シ ス テ ム オ ブ ジ ェ ク ト に 対 す る fanotify マ ー ク の 追 加 、 削 除 、 変 更 を 行 う 。 呼 び 出 し 元 は マ ー ク を 付 け る フ ァ イ ル シ ス テ ム オ ブ ジ ェ ク ト に 対 す る 読 み 出 し 許 可 を 持 っ て い な け れ ば な ら な い 。

fanotify_fd 引 数 は fanotify_init (2) で 返 さ れ た フ ァ イ ル デ ィ ス ク リ プ タ ー で あ る 。

flags は 実 行 す る 操 作 内 容 を 示 す ビ ッ ト マ ス ク で あ る 。 以 下 の 値 の い ず れ か 一 つ だ け を 指 定 し な け れ ば な ら な い 。
FAN_MARK_ADD

mask の イ ベ ン ト を mark マ ス ク (も し く は ignore マ ス ク ) に 追 加 す る 。 mask は 空 で あ っ て は い け な い 。 空 の 場 合 は エ ラ ー EINVAL が 発 生 す る 。

FAN_MARK_REMOVE

引 数 mask の イ ベ ン ト を mark マ ス ク (も し く は ignore マ ス ク ) か ら 削 除 す る 。 mask は 空 で あ っ て は い け な い 。 空 の 場 合 は エ ラ ー EINVAL が 発 生 す る 。

FAN_MARK_FLUSH

Remove either all marks for filesystems, all marks for mounts, or all marks for directories and files from the fanotify group. If flags contains FAN_MARK_MOUNT , all marks for mounts are removed from the group. If flags contains FAN_MARK_FILESYSTEM , all marks for filesystems are removed from the group. Otherwise, all marks for directories and files are removed. No flag other than and at most one of the flags FAN_MARK_MOUNT or FAN_MARK_FILESYSTEM can be used in conjunction with FAN_MARK_FLUSH . mask is ignored.

上 記 の ど の 値 も 指 定 さ れ な か っ た 場 合 、 ま た は 2 つ 以 上 の 値 が 指 定 さ れ た 場 合 、 呼 び 出 し は エ ラ ー EINVAL で 失 敗 す る 。

こ れ に 加 え て 、 flags に 以 下 の 値 を 0 個 以 上 ビ ッ ト 単 位 の 論 理 和 (OR) で 指 定 で き る 。
FAN_MARK_DONT_FOLLOW

pathname が シ ン ボ リ ッ ク リ ン ク の 場 合 、 リ ン ク が 参 照 す る フ ァ イ ル で は な く 、 リ ン ク 自 身 に マ ー ク を 付 け る (デ フ ォ ル ト で は fanotify_mark () は pathname が シ ン ボ リ ッ ク リ ン ク の 場 合 シ ン ボ リ ッ ク リ ン ク の 展 開 を 行 う )。

FAN_MARK_ONLYDIR

マ ー ク が 付 け ら れ た フ ァ イ ル シ ス テ ム オ ブ ジ ェ ク ト が デ ィ レ ク ト リ で な い 場 合 、 エ ラ ー ENOTDIR が 発 生 す る 。

FAN_MARK_MOUNT

Mark the mount point specified by pathname . If pathname is not itself a mount point, the mount point containing pathname will be marked. All directories, subdirectories, and the contained files of the mount point will be monitored. The events which require that filesystem objects are identified by file handles, such as FAN_CREATE , FAN_ATTRIB , FAN_MOVE , and FAN_DELETE_SELF , cannot be provided as a mask when flags contains FAN_MARK_MOUNT . Attempting to do so will result in the error EINVAL being returned.

FAN_MARK_FILESYSTEM (Linux 4.20 以 降 )

Mark the filesystem specified by pathname . The filesystem containing pathname will be marked. All the contained files and directories of the filesystem from any mount point will be monitored.

FAN_MARK_IGNORED_MASK

mask の イ ベ ン ト の ignore マ ス ク へ の 追 加 、 も し く は 削 除 を 行 う 。

FAN_MARK_IGNORED_SURV_MODIFY

ignore マ ス ク は 変 更 イ ベ ン ト が 発 生 し て も 残 り 続 け る 。 こ の フ ラ グ が セ ッ ト さ れ て い な い 場 合 、 無 視 す る フ ァ イ ル や デ ィ レ ク ト リ に 対 し て 変 更 イ ベ ン ト が 発 生 し た 際 に ignore マ ス ク は ク リ ア さ れ る 。

mask は ど の イ ベ ン ト に 対 し て 通 知 を 受 け る か (も し く は ど の イ ベ ン ト を 無 視 す る か ) を 定 義 す る 。 以 下 の 値 か ら 構 成 さ れ る ビ ッ ト マ ス ク で あ る 。
FAN_ACCESS

フ ァ イ ル や デ ィ レ ク ト リ へ の ア ク セ ス (読 み 出 し ) が あ っ た 際 に イ ベ ン ト を 作 成 す る (「 バ グ 」 も 参 照 )。

FAN_MODIFY

フ ァ イ ル が 変 更 さ れ た (書 き 込 み ) 際 に イ ベ ン ト を 作 成 す る 。

FAN_CLOSE_WRITE

書 き 込 み 可 能 フ ァ イ ル が ク ロ ー ズ さ れ た 際 に イ ベ ン ト を 作 成 す る 。

FAN_CLOSE_NOWRITE

読 み 出 し 専 用 の フ ァ イ ル や デ ィ レ ク ト リ が ク ロ ー ズ さ れ た 際 に イ ベ ン ト を 作 成 す る 。

FAN_OPEN

フ ァ イ ル や デ ィ レ ク ト リ が オ ー プ ン さ れ た 際 に イ ベ ン ト を 作 成 す る 。

FAN_OPEN_EXEC (Linux 5.0 以 降 )

Create an event when a file is opened with the intent to be executed. See NOTES for additional details.

FAN_ATTRIB (Linux 5.1 以 降 )

Create an event when the metadata for a file or directory has changed. An fanotify group that identifies filesystem objects by file handles is required.

FAN_CREATE (Linux 5.1 以 降 )

Create an event when a file or directory has been created in a marked parent directory. An fanotify group that identifies filesystem objects by file handles is required.

FAN_DELETE (Linux 5.1 以 降 )

Create an event when a file or directory has been deleted in a marked parent directory. An fanotify group that identifies filesystem objects by file handles is required.

FAN_DELETE_SELF (Linux 5.1 以 降 )

Create an event when a marked file or directory itself is deleted. An fanotify group that identifies filesystem objects by file handles is required.

FAN_MOVED_FROM (Linux 5.1 以 降 )

Create an event when a file or directory has been moved from a marked parent directory. An fanotify group that identifies filesystem objects by file handles is required.

FAN_MOVED_TO (Linux 5.1 以 降 )

Create an event when a file or directory has been moved to a marked parent directory. An fanotify group that identifies filesystem objects by file handles is required.

FAN_MOVE_SELF (Linux 5.1 以 降 )

Create an event when a marked file or directory itself has been moved. An fanotify group that identifies filesystem objects by file handles is required.

FAN_OPEN_PERM

フ ァ イ ル や デ ィ レ ク ト リ を オ ー プ ン す る ア ク セ ス 許 可 が 要 求 さ れ た 際 に イ ベ ン ト を 作 成 す る 。 fanotify フ ァ イ ル デ ィ ス ク リ プ タ ー が FAN_CLASS_PRE_CONTENT FAN_CLASS_CONTENT を 指 定 さ れ て 作 成 さ れ て い る 必 要 が あ る 。

FAN_OPEN_EXEC_PERM (since Linux 5.0)

Create an event when a permission to open a file for execution is requested. An fanotify file descriptor created with FAN_CLASS_PRE_CONTENT or FAN_CLASS_CONTENT is required. See NOTES for additional details.

FAN_ACCESS_PERM

フ ァ イ ル や デ ィ レ ク ト リ を 読 み 出 す ア ク セ ス 許 可 が 要 求 さ れ た 際 に イ ベ ン ト を 作 成 す る 。 fanotify フ ァ イ ル デ ィ ス ク リ プ タ ー が FAN_CLASS_PRE_CONTENT FAN_CLASS_CONTENT を 指 定 さ れ て 作 成 さ れ て い る 必 要 が あ る 。

FAN_ONDIR

Create events for directories—for example, when opendir (3), readdir (3) (but see BUGS), and closedir (3) are called. Without this flag, events are created only for files. In the context of directory entry events, such as FAN_CREATE , FAN_DELETE , FAN_MOVED_FROM , and FAN_MOVED_TO , specifying the flag FAN_ONDIR is required in order to create events when subdirectory entries are modified (i.e., mkdir (2)/ rmdir (2)).

FAN_EVENT_ON_CHILD

Events for the immediate children of marked directories shall be created. The flag has no effect when marking mounts and filesystems. Note that events are not generated for children of the subdirectories of marked directories. More specifically, the directory entry modification events FAN_CREATE , FAN_DELETE , FAN_MOVED_FROM , and FAN_MOVED_TO are not generated for any entry modifications performed inside subdirectories of marked directories. Note that the events FAN_DELETE_SELF and FAN_MOVE_SELF are not generated for children of marked directories. To monitor complete directory trees it is necessary to mark the relevant mount or filesystem.

The following composed values are defined:
FAN_CLOSE

フ ァ イ ル が ク ロ ー ズ さ れ た ( FAN_CLOSE_WRITE | FAN_CLOSE_NOWRITE )。

FAN_MOVE

A file or directory has been moved ( FAN_MOVED_FROM | FAN_MOVED_TO ).

マ ー ク を 付 け る フ ァ イ ル シ ス テ ム オ ブ ジ ェ ク ト は 、 フ ァ イ ル デ ィ ス ク リ プ タ ー dirfd pathname で 指 定 さ れ た パ ス 名 か ら 決 定 さ れ る 。

*

pathname が NULL の 場 合 、 dirfd で マ ー ク を 付 け る フ ァ イ ル シ ス テ ム オ ブ ジ ェ ク ト が 定 義 さ れ る 。

*

pathname が NULL で 、 dirfd が 特 別 な 値 AT_FDCWD の 場 合 、 カ レ ン ト ワ ー キ ン グ デ ィ レ ク ト リ が マ ー ク さ れ る 。

*

pathname が 絶 対 パ ス の 場 合 、 そ の パ ス 名 に よ り マ ー ク を 付 け る フ ァ イ ル シ ス テ ム オ ブ ジ ェ ク ト が 定 義 さ れ 、 dirfd は 無 視 さ れ る 。

*

pathname が 相 対 パ ス で 、 dirfd AT_FDCWD で な い 場 合 、 マ ー ク を 付 け る フ ァ イ ル シ ス テ ム オ ブ ジ ェ ク ト は dirfd が 参 照 す る デ ィ レ ク ト リ に 対 す る 相 対 パ ス pathname を 解 釈 し て 決 定 さ れ る 。

*

pathname が 相 対 パ ス で 、 dirfd AT_FDCWD の 場 合 、 マ ー ク を 付 け る フ ァ イ ル シ ス テ ム オ ブ ジ ェ ク ト は カ レ ン ト ワ ー キ ン グ デ ィ レ ク ト リ に 対 す る 相 対 パ ス pathname を 解 釈 し て 決 定 さ れ る 。

返 り 値

成 功 す る と fanotify_mark () は 0 を 返 す 。 エ ラ ー の 場 合 、 -1 を 返 し 、 errno に エ ラ ー の 原 因 を 示 す 値 を 設 定 す る 。

エ ラ ー

EBADF

無 効 な フ ァ イ ル デ ィ ス ク リ プ タ ー が fanotify_fd で 渡 さ れ た 。

EINVAL

無 効 な 値 が flags mask に 指 定 さ れ た か 、 fanotify_fd が fanotify フ ァ イ ル デ ィ ス ク リ プ タ ー で な か っ た 。

EINVAL

The fanotify file descriptor was opened with FAN_CLASS_NOTIF or the fanotify group identifies filesystem objects by file handles and mask contains a flag for permission events ( FAN_OPEN_PERM or FAN_ACCESS_PERM ).

ENODEV

The filesystem object indicated by pathname is not associated with a filesystem that supports fsid (e.g., tmpfs (5)). This error can be returned only with an fanotify group that identifies filesystem objects by file handles.

ENOENT

dirfd pathname で 指 定 さ れ た フ ァ イ ル シ ス テ ム オ ブ ジ ェ ク ト が 存 在 し な い 。 こ の エ ラ ー は マ ー ク さ れ て い な い オ ブ ジ ェ ク ト か ら マ ー ク を 削 除 し よ う と し た 場 合 に も 発 生 す る 。

ENOMEM

必 要 な メ モ リ ー を 割 り 当 て で き な か っ た 。

ENOSPC

マ ー ク の 数 が 8192 の 上 限 を 超 過 し 、 fanotify_init (2) で fanotify フ ァ イ ル デ ィ ス ク リ プ タ ー が 作 成 さ れ た 際 に FAN_UNLIMITED_MARKS フ ラ グ が 指 定 さ れ て い な か っ た 。

ENOSYS

こ の カ ー ネ ル で は fanotify_mark () が 実 装 さ れ て い な い 。 fanotify API が 利 用 で き る の は 、 カ ー ネ ル で CONFIG_FANOTIFY が 有 効 に な っ て い る 場 合 だ け で あ る 。

ENOTDIR

flags FAN_MARK_ONLYDIR が 含 ま れ て い る が 、 dirfd pathname が デ ィ レ ク ト リ を 指 定 し て い な い 。

EOPNOTSUPP

The object indicated by pathname is associated with a filesystem that does not support the encoding of file handles. This error can be returned only with an fanotify group that identifies filesystem objects by file handles.

EXDEV

The filesystem object indicated by pathname resides within a filesystem subvolume (e.g., btrfs (5)) which uses a different fsid than its root superblock. This error can be returned only with an fanotify group that identifies filesystem objects by file handles.

バ ー ジ ョ ン

fanotify_mark () は Linux カ ー ネ ル の バ ー ジ ョ ン 2.6.36 で 導 入 さ れ 、 バ ー ジ ョ ン 2.6.37 で 有 効 に な っ た 。

準 拠

こ の シ ス テ ム コ ー ル は Linux 独 自 で あ る 。

注 意

FAN_OPEN_EXEC と FAN_OPEN_EXEC_PERM

When using either FAN_OPEN_EXEC or FAN_OPEN_EXEC_PERM within the mask , events of these types will be returned only when the direct execution of a program occurs. More specifically, this means that events of these types will be generated for files that are opened using execve (2), execveat (2), or uselib (2). Events of these types will not be raised in the situation where an interpreter is passed (or reads) a file for interpretation.

Additionally, if a mark has also been placed on the Linux dynamic linker, a user should also expect to receive an event for it when an ELF object has been successfully opened using execve (2) or execveat (2).

For example, if the following ELF binary were to be invoked and a FAN_OPEN_EXEC mark has been placed on /:

$ /bin/echo foo

The listening application in this case would receive FAN_OPEN_EXEC events for both the ELF binary and interpreter, respectively:

/bin/echo
/lib64/ld-linux-x86-64.so.2

バ グ

バ ー ジ ョ ン 3.16 よ り 前 の Linux カ ー ネ ル で は 以 下 の バ グ が 存 在 し た 。

*

flags FAN_MARK_FLUSH が 指 定 さ れ て い る 場 合 、 た と え そ の オ ブ ジ ェ ク ト が 使 用 さ れ な い 場 合 で あ っ て も 、 dirfd pathname に は 有 効 な フ ァ イ ル シ ス テ ム オ ブ ジ ェ ク ト を 指 定 し な け れ ば な ら な い 。

*

readdir (2) は FAN_ACCESS イ ベ ン ト を 生 成 し な い 。

*

fanotify_mark () が FAN_MARK_FLUSH 付 き で 呼 び 出 さ れ た 場 合 、 flags の 値 が 無 効 か は チ ェ ッ ク さ れ な い 。

関 連 項 目

fanotify_init (2), fanotify (7)

こ の 文 書 に つ い て

こ の man ペ ー ジ は Linux man-pages プ ロ ジ ェ ク ト の リ リ ー ス 5.10 の 一 部 で あ る 。 プ ロ ジ ェ ク ト の 説 明 と バ グ 報 告 に 関 す る 情 報 は https://www.kernel.org/doc/man-pages/ に 書 か れ て い る 。