Man page - fanotify_init(2)

Packages contains this manual

Available languages:

en fr ja

Manual

FANOTIFY_INIT

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

名 前

fanotify_init - fanotify グ ル ー プ を 作 成 し 、 初 期 化 す る

書 式

#include <fcntl.h>
#include <sys/fanotify.h>

int fanotify_init(unsigned int flags , unsigned int event_f_flags );

説 明

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

fanotify_init () は 新 し い fanotify グ ル ー プ を 初 期 化 し 、 こ の グ ル ー プ に 関 連 付 け ら れ た イ ベ ン ト キ ュ ー に 対 す る フ ァ イ ル デ ィ ス ク リ プ タ ー を 返 す 。

こ の フ ァ イ ル デ ィ ス ク リ プ タ ー は 、 fanotify_mark (2) の 呼 び 出 し で fanotify イ ベ ン ト が 作 成 さ れ る フ ァ イ ル 、 デ ィ レ ク ト リ 、 マ ウ ン ト 、 フ ァ イ ル シ ス テ ム を 指 定 す る の に 使 用 で き る 。 fanotify_mark (2) で 指 定 し た フ ァ イ ル 、 こ れ ら の イ ベ ン ト は 、 こ の フ ァ イ ル デ ィ ス ク リ プ タ ー か ら の 読 み 出 し で 受 信 す る 。 い く つ か の イ ベ ン ト は 、 フ ァ イ ル が ア ク セ ス さ れ た こ と を 示 す 単 な る 情 報 で あ る 。 他 の い く つ か の イ ベ ン ト は 、 別 の ア プ リ ケ ー シ ョ ン が フ ァ イ ル や デ ィ レ ク ト リ に ア ク セ ス す る 許 可 を 与 え る か を 判 定 す る の に 使 用 さ れ る 。 フ ァ イ ル シ ス テ ム オ ブ ジ ェ ク ト へ の ア ク セ ス 許 可 イ ベ ン ト に つ い て は 、 承 認 結 果 を こ の フ ァ イ ル デ ィ ス ク リ プ タ ー に 書 き 込 む 。

複 数 の プ ロ グ ラ ム が 同 時 に fanotify イ ン タ ー フ ェ ー ス を 使 っ て 同 じ フ ァ イ ル を 同 時 に 監 視 す る こ と が で き る 。

現 在 の 実 装 で は 、 ユ ー ザ ー あ た り の fanotify グ ル ー プ 数 は 128 に 制 限 さ れ て い る 。 こ の 制 限 は 上 書 き す る こ と が で き な い 。

fanotify_init () を 呼 び 出 す に は CAP_SYS_ADMIN ケ ー パ ビ リ テ ィ ー が 必 要 で あ る 。 こ の 制 約 は 将 来 の バ ー ジ ョ ン の API で 緩 和 さ れ る 可 能 性 が あ る 。 そ の た め 、 以 下 に 示 す ケ ー パ ビ リ テ ィ ー チ ェ ッ ク の い く つ か が 実 装 さ れ て い る 。

flags 引 数 は 、 イ ベ ン ト を 待 つ ア プ リ ケ ー シ ョ ン の 通 知 ク ラ ス を 定 義 す る 複 数 ビ ッ ト の フ ィ ー ル ド で あ る 。 こ れ に 加 え て 、 こ の フ ァ イ ル デ ィ ス ク リ プ タ ー の 動 作 を 示 す 1 ビ ッ ト の フ ィ ー ル ド が あ る 。

ア ク セ ス 許 可 イ ベ ン ト を 監 視 し て い る プ ロ グ ラ ム が 複 数 い る 場 合 、 通 知 ク ラ ス を 使 っ て 監 視 す る プ ロ グ ラ ム の イ ベ ン ト 受 信 順 序 が 管 理 さ れ る 。

以 下 の 通 知 ク ラ ス の い ず れ か 一 つ だ け を flags に 指 定 で き る 。
FAN_CLASS_PRE_CONTENT

こ の 値 は 、 フ ァ イ ル が ア ク セ ス さ れ た こ と を 通 知 す る イ ベ ン ト と 、 フ ァ イ ル へ の ア ク セ ス す る か の 許 可 の 判 断 を 求 め る イ ベ ン ト を 受 信 す る こ と を 示 す 。 こ れ は イ ベ ン ト 受 信 者 が フ ァ イ ル が 最 終 的 な デ ー タ を 格 納 す る 前 に そ の フ ァ イ ル に ア ク セ ス す る 必 要 が あ る 場 合 に 使 用 さ れ る 。 こ の 通 知 ク ラ ス は 例 え ば 階 層 型 ス ト レ ー ジ 管 理 な ど で 使 用 さ れ る 。

FAN_CLASS_CONTENT

こ の 値 は 、 フ ァ イ ル が ア ク セ ス さ れ た こ と を 通 知 す る イ ベ ン ト と 、 フ ァ イ ル へ の ア ク セ ス す る か の 許 可 の 判 断 を 求 め る イ ベ ン ト を 受 信 す る こ と を 示 す 。 こ れ は イ ベ ン ト 受 信 者 が フ ァ イ ル に 最 終 的 な デ ー タ が 格 納 さ れ た 際 に そ の フ ァ イ ル に ア ク セ ス す る 必 要 が あ る 場 合 に 使 用 さ れ る 。 こ の 通 知 ク ラ ス は 例 え ば ウ イ ル ス 検 知 プ ロ グ ラ ム な ど で 使 用 さ れ る 。

FAN_CLASS_NOTIF

こ れ は デ フ ォ ル ト 値 で あ る 。 こ の 値 を 指 定 す る 必 要 は な い 。 こ の 値 は 、 フ ァ イ ル が ア ク セ ス さ れ た こ と を 通 知 す る イ ベ ン ト の 受 信 だ け を 行 う こ と を 意 味 す る 。 フ ァ イ ル が ア ク セ ス す る 前 に ア ク セ ス 許 可 の 判 定 を 行 う こ と は で き な い 。

異 な る 通 知 ク ラ ス の 受 信 者 は FAN_CLASS_PRE_CONTENT , FAN_CLASS_CONTENT , FAN_CLASS_NOTIF の 順 序 で イ ベ ン ト を 受 信 す る 。 同 じ 通 知 ク ラ ス の 受 信 者 で の 通 知 順 序 は 不 定 で あ る 。

flags に は 以 下 の ビ ッ ト を 追 加 で セ ッ ト す る こ と が で き る 。
FAN_CLOEXEC

close-on-exec フ ラ グ ( FD_CLOEXEC ) を 新 し い フ ァ イ ル デ ィ ス ク リ プ タ ー に セ ッ ト す る 。 open (2) の O_CLOEXEC フ ラ グ の 説 明 を 参 照 。

FAN_NONBLOCK

ノ ン ブ ロ ッ キ ン グ フ ラ グ ( O_NONBLOCK ) を そ の フ ァ イ ル デ ィ ス ク リ プ タ ー で 有 効 に す る 。 こ の フ ァ イ ル デ ィ ス ク リ プ タ ー か ら の 読 み 出 し は 停 止 し な い 。 そ の 代 わ り 、 読 み だ し 可 能 な デ ー タ が 何 も な い 場 合 、 read (2) は エ ラ ー EAGAIN で 失 敗 す る 。

FAN_UNLIMITED_QUEUE

そ の イ ベ ン ト キ ュ ー の 16384 イ ベ ン ト の 上 限 を 削 除 す る 。 こ の フ ラ グ を 使 用 す る に は CAP_SYS_ADMIN ケ ー パ ビ リ テ ィ ー が 必 要 で あ る 。

FAN_UNLIMITED_MARKS

8192 マ ー ク の 上 限 を 削 除 す る 。 こ の フ ラ グ を 使 用 す る に は CAP_SYS_ADMIN ケ ー パ ビ リ テ ィ ー が 必 要 で あ る 。

FAN_REPORT_TID (Linux 4.20 以 降 )

Report thread ID (TID) instead of process ID (PID) in the pid field of the struct fanotify_event_metadata supplied to read (2) (see fanotify (7)).

FAN_REPORT_FID (Linux 5.1 以 降 )

This value allows the receipt of events which contain additional information about the underlying filesystem object correlated to an event. An additional record of type FAN_EVENT_INFO_TYPE_FID encapsulates the information about the object and is included alongside the generic event metadata structure. The file descriptor that is used to represent the object correlated to an event is instead substituted with a file handle. It is intended for applications that may find the use of a file handle to identify an object more suitable than a file descriptor. Additionally, it may be used for applications monitoring a directory or a filesystem that are interested in the directory entry modification events FAN_CREATE , FAN_DELETE , and FAN_MOVE , or in events such as FAN_ATTRIB , FAN_DELETE_SELF , and FAN_MOVE_SELF . All the events above require an fanotify group that identifies filesystem objects by file handles. Note that for the directory entry modification events the reported file handle identifies the modified directory and not the created/deleted/moved child object. The use of FAN_CLASS_CONTENT or FAN_CLASS_PRE_CONTENT is not permitted with this flag and will result in the error EINVAL . See fanotify (7) for additional details.

FAN_REPORT_DIR_FID (Linux 5.9 以 降 )

Events for fanotify groups initialized with this flag will contain (see exceptions below) additional information about a directory object correlated to an event. An additional record of type FAN_EVENT_INFO_TYPE_DFID encapsulates the information about the directory object and is included alongside the generic event metadata structure. For events that occur on a non-directory object, the additional structure includes a file handle that identifies the parent directory filesystem object. Note that there is no guarantee that the directory filesystem object will be found at the location described by the file handle information at the time the event is received. When combined with the flag FAN_REPORT_FID , two records may be reported with events that occur on a non-directory object, one to identify the non-directory object itself and one to identify the parent directory object. Note that in some cases, a filesystem object does not have a parent, for example, when an event occurs on an unlinked but open file. In that case, with the FAN_REPORT_FID flag, the event will be reported with only one record to identify the non-directory object itself, because there is no directory associated with the event. Without the FAN_REPORT_FID flag, no event will be reported. See fanotify (7) for additional details.

FAN_REPORT_NAME (Linux 5.9 以 降 )

Events for fanotify groups initialized with this flag will contain additional information about the name of the directory entry correlated to an event. This flag must be provided in conjunction with the flag FAN_REPORT_DIR_FID . Providing this flag value without FAN_REPORT_DIR_FID will result in the error EINVAL . This flag may be combined with the flag FAN_REPORT_FID . An additional record of type FAN_EVENT_INFO_TYPE_DFID_NAME , which encapsulates the information about the directory entry, is included alongside the generic event metadata structure and substitutes the additional information record of type FAN_EVENT_INFO_TYPE_DFID . The additional record includes a file handle that identifies a directory filesystem object followed by a name that identifies an entry in that directory. For the directory entry modification events FAN_CREATE , FAN_DELETE , and FAN_MOVE , the reported name is that of the created/deleted/moved directory entry. For other events that occur on a directory object, the reported file handle is that of the directory object itself and the reported name is ’.’. For other events that occur on a non-directory object, the reported file handle is that of the parent directory object and the reported name is the name of a directory entry where the object was located at the time of the event. The rationale behind this logic is that the reported directory file handle can be passed to open_by_handle_at (2) to get an open directory file descriptor and that file descriptor along with the reported name can be used to call fstatat (2). The same rule that applies to record type FAN_EVENT_INFO_TYPE_DFID also applies to record type FAN_EVENT_INFO_TYPE_DFID_NAME : if a non-directory object has no parent, either the event will not be reported or it will be reported without the directory entry information. Note that there is no guarantee that the filesystem object will be found at the location described by the directory entry information at the time the event is received. See fanotify (7) for additional details.

FAN_REPORT_DFID_NAME

This is a synonym for ( FAN_REPORT_DIR_FID | FAN_REPORT_NAME ).

event_f_flags 引 数 は fanotify イ ベ ン ト が 作 成 さ れ る オ ー プ ン フ ァ イ ル 記 述 に セ ッ ト さ れ る フ ァ イ ル 状 態 フ ラ グ を 定 義 す る 。 こ れ ら の フ ラ グ の 詳 細 に つ い て は open (2) の flags 値 の 説 明 を 参 照 の こ と 。 event_f_flags に は ア ク セ ス モ ー ド の ビ ッ ト を 複 数 入 れ る こ と が で き る 。 こ の フ ィ ー ル ド に は 以 下 の 値 も 指 定 す る こ と が で き る 。
O_RDONLY

読 み 出 し ア ク セ ス の み を 許 可 す る 。

O_WRONLY

書 き 込 み ア ク セ ス の み を 許 可 す る 。

O_RDWR

読 み 出 し と 書 き 込 み の 両 方 を 許 可 す る 。

他 の ビ ッ ト も event_f_flags も セ ッ ト す る こ と が で き る 。 役 立 つ で あ ろ う 値 は 以 下 で あ る 。
O_LARGEFILE

2 GB を 超 え る フ ァ イ ル の サ ポ ー ト を 有 効 に す る 。 こ の フ ラ グ の セ ッ ト に 失 敗 す る と 、 32 ビ ッ ト シ ス テ ム で fanotify グ ル ー プ が 監 視 す る ラ ー ジ フ ァ イ ル を オ ー プ ン し よ う と し た 際 に EOVERFLOW エ ラ ー と な る 。

O_CLOEXEC (Linux 3.18 以 降 )

こ の フ ァ イ ル デ ィ ス ク リ プ タ ー で close-on-exec フ ラ グ を 有 効 に す る 。 こ の フ ラ グ が 役 立 つ 理 由 に つ い て は open (2) の O_CLOEXEC フ ラ グ の 説 明 を 参 照 。

O_APPEND , O_DSYNC , O_NOATIME , O_NONBLOCK , O_SYNC も 指 定 す る こ と が で き る 。 event_f_flags に こ れ 以 外 の フ ラ グ を 指 定 す る と 、 エ ラ ー EINVAL が 起 こ る (た だ し 、 バ グ を 参 照 )。

返 り 値

成 功 す る と fanotify_init () は 新 し い フ ァ イ ル デ ィ ス ク リ プ タ ー を 返 す 。 エ ラ ー の 場 合 、 -1 を 返 し 、 errno に エ ラ ー を 示 す 値 を 設 定 す る 。

エ ラ ー

EINVAL

An invalid value was passed in flags or event_f_flags . FAN_ALL_INIT_FLAGS (deprecated since Linux kernel version 4.20) defines all allowable bits for flags .

EMFILE

こ の ユ ー ザ ー の fanotify グ ル ー プ 数 が 128 を 超 過 し た 。

EMFILE

The per-process limit on the number of open file descriptors has been reached.

ENOMEM

通 知 グ ル ー プ へ の メ モ リ ー 割 り 当 て が 失 敗 し た 。

ENOSYS

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

EPERM

呼 び 出 し 元 が CAP_SYS_ADMIN ケ ー パ ビ リ テ ィ ー を 持 っ て い な い の で 、 操 作 が 許 可 さ れ な い 。

バ ー ジ ョ ン

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

準 拠

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

バ グ

The following bug was present in Linux kernels before version 3.18:

*

O_CLOEXEC event_f_flags に 指 定 さ れ た 場 合 、 無 視 さ れ る 。

バ ー ジ ョ ン 3.14 よ り 前 の Linux カ ー ネ ル に は 以 下 の バ グ が 存 在 す る 。

*

event_f_flags 引 数 に 無 効 な フ ラ グ が な い か の チ ェ ッ ク が 行 わ れ な い 。 FMODE_EXEC な ど の 内 部 で の 使 用 の み が 意 図 さ れ た フ ラ グ を 指 定 す る こ と が で き 、 そ の 場 合 fanotify フ ァ イ ル デ ィ ス ク リ プ タ ー か ら の 読 み 出 し 時 に 返 さ れ る フ ァ イ ル デ ィ ス ク リ プ タ ー に そ の フ ラ グ が セ ッ ト さ れ る 。

関 連 項 目

fanotify_mark (2), fanotify (7)

こ の 文 書 に つ い て

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