inotify_add_watch

Section: System Calls (2)
Updated: 2026-02-08
Index JM Home Page roff page
 

名前

inotify_add_watch - 初期化済み inotify インスタンスに監視対象を追加する  

ライブラリ

標準 C ライブラリ (libc,~-lc)  

書式

#include <sys/inotify.h>

int inotify_add_watch(int fd, const char *path, uint32_t mask);
 

説明

inotify_add_watch() adds a new watch, or modifies an existing watch, for the file whose location is specified in path; the caller must have read permission for this file. The fd argument is a file descriptor referring to the inotify instance whose watch list is to be modified. The events to be monitored for path are specified in the mask bit-mask argument. See inotify(7) for a description of the bits that can be set in mask.

A successful call to inotify_add_watch() returns a unique watch descriptor for this inotify instance, for the filesystem object (inode) that corresponds to path. If the filesystem object was not previously being watched by this inotify instance, then the watch descriptor is newly allocated. If the filesystem object was already being watched (perhaps via a different link to the same object), then the descriptor for the existing watch is returned.

これ以降に inotify ファイルディスクリプターから read(2) を行うと、監視対象ディスクリプターが返される。 これらの read() を行うと、ファイルシステムイベントを示す inotify_event 構造体が読み出される (inotify(7) 参照)。この構造体内の監視対象ディスクリプターにより、 どのオブジェクトでそのイベントが発生したかを特定できる。  

返り値

On success, inotify_add_watch() returns a watch descriptor (a nonnegative integer). On error, -1 is returned and errno is set to indicate the error.  

エラー

EACCES
指定されたファイルに対する読み出しアクセスが許可されていない。
EBADF
指定されたファイルディスクリプターが有効ではない。
EEXIST
mask contains IN_MASK_CREATE and path refers to a file already being watched by the same fd.
EFAULT
path が指すアドレスがプロセスがアクセスできるアドレス空間外である。
EINVAL
The given event mask contains no valid events; or mask contains both IN_MASK_ADD and IN_MASK_CREATE; or fd is not an inotify file descriptor.
ENAMETOOLONG
path が長過ぎる。
ENOENT
path のディレクトリ部分の構成要素が、存在しないか、リンク切れのシンボリックリンクである。
ENOMEM
カーネルメモリーが十分になかった。
ENOSPC
inotify 監視対象の総数がユーザーが追加できる上限に達していた。 もしくは、必要な資源の割り当てにカーネルが失敗した。
ENOTDIR
mask contains IN_ONLYDIR and path is not a directory.
 

標準規格

Linux.  

歴史

Linux 2.6.13.  

例

inotify(7) 参照。  

関連項目

inotify_init(2), inotify_rm_watch(2), inotify(7)


 

Index

名前
ライブラリ
書式
説明
返り値
エラー
標準規格
歴史
例
関連項目

This document was created by man2html, using the manual pages.