Provided by: manpages-ja-dev_0.5.0.0.20221215+dfsg-1_all bug

名前

       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_CONTENTFAN_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_CONTENTFAN_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).

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

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

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

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

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

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

返り値

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

エラー

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

       EINVAL 無効な値が flagsmask に指定されたか、 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 dirfdpathname で指定されたファイルシステムオブジェクトが存在しない。  このエラーはマークされて
              いないオブジェクトからマークを削除しようとした場合にも発生する。

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

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

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

       ENOTDIR
              flagsFAN_MARK_ONLYDIR が含まれているが、 dirfdpathname がディレクトリを指定していない。

       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 カーネルでは以下のバグが存在した。

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

       *  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/ に書かれている。