X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=draft%2Fman7%2Finotify.7;h=c15071b575b9eb0d3943a2facaed93e895f8103e;hb=90d8a48b943d734f68321865d283319edfcafcdd;hp=7acc719b317d899f112f66fc03a86bd70e688700;hpb=ce024239a1d8e74a7a44f7c24cee4375cb13b3ef;p=linuxjm%2FLDP_man-pages.git diff --git a/draft/man7/inotify.7 b/draft/man7/inotify.7 index 7acc719b..c15071b5 100644 --- a/draft/man7/inotify.7 +++ b/draft/man7/inotify.7 @@ -1,8 +1,7 @@ -'\" t -.\" Hey Emacs! This file is -*- nroff -*- source. -.\" -.\" Copyright (C) 2006 Michael Kerrisk +.\" t +.\" Copyright (C) 2006, 2014 Michael Kerrisk .\" +.\" %%%LICENSE_START(VERBATIM) .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. @@ -22,6 +21,13 @@ .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. +.\" %%%LICENSE_END +.\" +.\"******************************************************************* +.\" +.\" This file was generated with po4a. Translate the source file. +.\" +.\"******************************************************************* .\" .\" Japanese Version Copyright (c) 2006 Yuichi SATO .\" and Copyright (c) 2007-2008 Akihiro MOTOKI @@ -30,150 +36,63 @@ .\" Updated 2007-06-13, Akihiro MOTOKI , LDP v2.55 .\" Updated 2008-08-10, Akihiro MOTOKI, LDP v3.05 .\" Updated 2008-09-19, Akihiro MOTOKI, LDP v3.08 +.\" Updated 2012-04-30, Akihiro MOTOKI +.\" Updated 2012-05-01, Akihiro MOTOKI +.\" Updated 2013-03-26, Akihiro MOTOKI +.\" Updated 2013-07-22, Akihiro MOTOKI +.\" Updated 2013-08-21, Akihiro MOTOKI , LDP v3.53 .\" -.TH INOTIFY 7 2008-11-18 "Linux" "Linux Programmer's Manual" -.\"O .SH NAME +.TH INOTIFY 7 2014\-04\-01 Linux "Linux Programmer's Manual" .SH 名前 -.\"O inotify \- monitoring file system events inotify \- ファイルシステムイベントを監視する -.\"O .SH DESCRIPTION .SH 説明 -.\"O The -.\"O .I inotify -.\"O API provides a mechanism for monitoring file system events. -.I inotify -API はファイルシステムイベントを監視するための機構を提供する。 -.\"O Inotify can be used to monitor individual files, -.\"O or to monitor directories. -inotify は個々のファイルやディレクトリを監視するのに使える。 -.\"O When a directory is monitored, inotify will return events -.\"O for the directory itself, and for files inside the directory. -ディレクトリを監視する場合、inotify はディレクトリ自身と +\fIinotify\fP API はファイルシステムイベントを監視するための機構を提供する。 inotify +は個々のファイルやディレクトリを監視するのに使える。 ディレクトリを監視する場合、inotify はディレクトリ自身と ディレクトリ内のファイルのイベントを返す。 -.\"O The following system calls are used with this API: -.\"O .BR inotify_init (2) -.\"O (or -.\"O .BR inotify_init1 (2)), -.\"O .BR inotify_add_watch (2), -.\"O .BR inotify_rm_watch (2), -.\"O .BR read (2), -.\"O and -.\"O .BR close (2). -以下のシステムコールがこの API と共に使用される: -.BR inotify_init (2) -(や -.BR inotify_init1 (2)), -.BR inotify_add_watch (2), -.BR inotify_rm_watch (2), -.BR read (2), -.BR close (2). - -.\"O .BR inotify_init (2) -.\"O creates an inotify instance and returns a file descriptor -.\"O referring to the inotify instance. -.\"O The more recent -.\"O .BR inotify_init1 (2) -.\"O is like -.\"O .BR inotify_init (2), -.\"O but provides some extra functionality. -.BR inotify_init (2) -は inotify インスタンスを作成し、inotify インスタンスを参照する -ファイルディスクリプタを返す。 -もっと新しい -.BR inotify_init1 (2) -も -.BR inotify_init (2) -と同様だが、いくつかの追加の機能が提供されている。 +この API では以下のシステムコールが使用される。 +.IP * 3 +\fBinotify_init\fP(2) は inotify インスタンスを作成し、inotify インスタンスを参照する ファイルディスクリプタを返す。 +もっと新しい \fBinotify_init1\fP(2) も \fBinotify_init\fP(2) と同様だが、いくつかの追加の機能を利用するための +\fIflags\fP 引き数を持っている。 +.IP * +\fBinotify_add_watch\fP(2) は inotify インスタンスに関連づけられた「監視対象 (watch) リスト」を操作する。 +監視対象リストの各アイテム ("watch") は、 ファイルまたはディレクトリのパス名と、 そのパス名で参照されるファイルに対して +カーネルが監視する複数のイベントの集合を指定する。 \fBinotify_add_watch\fP(2) +は新しい監視アイテムの作成や既存の監視対象の変更ができる。 各監視対象は一意の「監視対象ディスクリプタ」を持つ。 これは監視対象を作成したときに +\fBinotify_add_watch\fP(2) から返される整数である。 +.IP * +When events occur for monitored files and directories, those events are made +available to the application as structured data that can be read from the +inotify file descriptor using \fBread\fP(2) (see below). +.IP * +\fBinotify_rm_watch\fP(2) は inotify の監視対象リストからアイテムを削除する。 +.IP * +inotify インスタンスを指している 全てのファイルディスクリプタが (\fBclose\fP(2) を使って) クローズされた場合、 +その下層にあるオブジェクトとそのリソースは、 カーネルで再利用するために解放される。 関連が切られた監視対象は自動的に解放される。 -.\"O .BR inotify_add_watch (2) -.\"O manipulates the "watch list" associated with an inotify instance. -.BR inotify_add_watch (2) -は inotify インスタンスに関連づけられた「監視対象 (watch) リスト」を操作する。 -.\"O Each item ("watch") in the watch list specifies the pathname of -.\"O a file or directory, -.\"O along with some set of events that the kernel should monitor for the -.\"O file referred to by that pathname. -監視対象リストの各アイテム ("watch") は、 -ファイルまたはディレクトリのパス名と、 -そのパス名で参照されるファイルに対して -カーネルが監視する複数のイベントの集合を指定する。 -.\"O .BR inotify_add_watch (2) -.\"O either creates a new watch item, or modifies an existing watch. -.BR inotify_add_watch (2) -は新しい監視アイテムの作成や既存の監視対象の変更ができる。 -.\"O Each watch has a unique "watch descriptor", an integer -.\"O returned by -.\"O .BR inotify_add_watch (2) -.\"O when the watch is created. -各監視対象は一意の「監視対象ディスクリプタ」を持つ。 -これは監視対象を作成したときに -.BR inotify_add_watch (2) -から返される整数である。 +With careful programming, an application can use inotify to efficiently +monitor and cache the state of a set of filesystem objects. However, robust +applications should allow for the fact that bugs in the monitoring logic or +races of the kind described below may leave the cache inconsistent with the +filesystem state. It is probably wise to to do some consistency checking, +and rebuild the cache when inconsistencies are detected. +.SS "inotify ファイルディスクリプタからのイベントの読み出し" +どのようなイベントが起こっていたかを知るには、 アプリケーションで inotify ファイルディスクリプタを \fBread\fP(2) すればよい。 +これまでに何もイベントが起こっていない場合、 停止 (blocking) モードのファイルディスクリプタであれば、 少なくとも 1 +つのイベントが起こるまで \fBread\fP(2) は停止する (シグナルにより割り込まれなかった場合。 +シグナルによる割り込みがあった場合、呼び出しはエラー \fBEINTR\fP で失敗する。 \fBsignal\fP(7) 参照)。 -.\"O .BR inotify_rm_watch (2) -.\"O removes an item from an inotify watch list. -.BR inotify_rm_watch (2) -は inotify の監視対象リストからアイテムを削除する。 - -.\"O When all file descriptors referring to an inotify -.\"O instance have been closed, -.\"O the underlying object and its resources are -.\"O freed for reuse by the kernel; -.\"O all associated watches are automatically freed. -inotify インスタンスを指している -全てのファイルディスクリプタがクローズされた場合、 -その下層にあるオブジェクトとそのリソースは、 -カーネルで再利用するために解放される。 -関連が切られた監視対象は自動的に解放される。 - -.\"O To determine what events have occurred, an application -.\"O .BR read (2)s -.\"O from the inotify file descriptor. -どのようなイベントが起こっていたかを知るには、 -アプリケーションで inotify ファイルディスクリプタを -.BR read (2) -すればよい。 -.\"O If no events have so far occurred, then, -.\"O assuming a blocking file descriptor, -.\"O .BR read (2) -.\"O will block until at least one event occurs -.\"O (unless interrupted by a signal, -.\"O in which case the call fails with the error -.\"O .BR EINTR ; -.\"O see -.\"O .BR signal (7)). -これまでに何もイベントが起こっていない場合、 -停止 (blocking) モードのファイルディスクリプタであれば、 -少なくとも 1 つのイベントが起こるまで -.BR read (2) -は停止する (シグナルにより割り込まれなかった場合。 -シグナルによる割り込みがあった場合、呼び出しはエラー -.BR EINTR -で失敗する。 -.BR signal (7) -参照)。 - -.\"O Each successful -.\"O .BR read (2) -.\"O returns a buffer containing one or more of the following structures: -.BR read (2) -が成功すると、以下の構造体を 1 つ以上含むバッファが返される: +\fBread\fP(2) が成功すると、以下の構造体を 1 つ以上含むバッファが返される: .in +4n .nf -struct inotify_event { -.\"O int wd; /* Watch descriptor */ - int wd; /* 監視対象ディスクリプタ */ .\" FIXME . The type of the 'wd' field should probably be "int32_t". .\" I submitted a patch to fix this. See the LKML thread .\" "[patch] Fix type errors in inotify interfaces", 18 Nov 2008 .\" Glibc bug filed: http://sources.redhat.com/bugzilla/show_bug.cgi?id=7040 -.\"O uint32_t mask; /* Mask of events */ -.\"O uint32_t cookie; /* Unique cookie associating related -.\"O events (for rename(2)) */ -.\"O uint32_t len; /* Size of \(aqname\(aq field */ -.\"O char name[]; /* Optional null-terminated name */ +struct inotify_event { + int wd; /* 監視対象ディスクリプタ */ uint32_t mask; /* イベントのマスク */ uint32_t cookie; /* 関連するイベント群を関連づける 一意なクッキー (rename(2) 用) */ @@ -183,516 +102,336 @@ struct inotify_event { .fi .in -.\"O .I wd -.\"O identifies the watch for which this event occurs. -.\"O It is one of the watch descriptors returned by a previous call to -.\"O .BR inotify_add_watch (2). -.I wd -はイベント発生の監視対象を指定する。 -これは、前もって行われた -.BR inotify_add_watch (2) +\fIwd\fP はイベント発生の監視対象を指定する。 これは、前もって行われた \fBinotify_add_watch\fP(2) 呼び出しで返された監視対象ディスクリプタのうちの 1 つである。 -.\"O .I mask -.\"O contains bits that describe the event that occurred (see below). -.I mask -には発生したイベント (下記参照) を記述するためのビットが含まれる。 +\fImask\fP には発生したイベント (下記参照) を記述するためのビットが含まれる。 -.\"O .I cookie -.\"O is a unique integer that connects related events. -.I cookie -は関連するイベントを関連づけるための一意な整数である。 -.\"O Currently this is only used for rename events, and -.\"O allows the resulting pair of -.\"O .B IN_MOVE_FROM -.\"O and -.\"O .B IN_MOVE_TO -.\"O events to be connected by the application. +\fIcookie\fP は関連するイベントを関連づけるための一意な整数である。 現在のところ、この値は rename イベントに対してのみ使われており、 -結果のペアである -.B IN_MOVE_FROM -と -.B IN_MOVE_TO -イベントをアプリケーションで関連づけることができる。 +結果のペアである \fBIN_MOVED_FROM\fP と \fBIN_MOVED_TO\fP イベントを +アプリケーションで関連づけることができる。 +他のイベント種別の場合には、 \fIcookie\fP は 0 に設定する。 + +\fIname\fP フィールドは監視しているディレクトリ内のファイルに対して イベントが返される場合のためにだけ存在する。 +監視するディレクトリからのファイルの相対パス名を表す。 このパス名は NULL で終端され、 その後の読み込みで適切なアドレス境界に調整するために、 +さらに NULL バイト (\(aq\e0\(aq) が含まれる場合もある。 -.\"O The -.\"O .I name -.\"O field is only present when an event is returned -.\"O for a file inside a watched directory; -.\"O it identifies the file pathname relative to the watched directory. -.I name -フィールドは監視しているディレクトリ内のファイルに対して -イベントが返される場合のためにだけ存在する。 -監視するディレクトリからのファイルの相対パス名を表す。 -.\"O This pathname is null-terminated, -.\"O and may include further null bytes to align subsequent reads to a -.\"O suitable address boundary. -このパス名は NULL で終端され、 -その後の読み込みで適切なアドレス境界に調整するために、 -さらに NULL バイトが含まれる場合もある。 +\fIlen\fP フィールドは NULL バイトを含む \fIname\fP の全てのバイト数を表す。 +よって、 \fIinotify_event\fP 構造体のサイズは +\fIsizeof(struct inotify_event)+len\fP である。 -.\"O The -.\"O .I len -.\"O field counts all of the bytes in -.\"O .IR name , -.\"O including the null bytes; -.\"O the length of each -.\"O .I inotify_event -.\"O structure is thus -.\"O .IR "sizeof(inotify_event)+len" . -.I len -フィールドは NULL バイトを含む -.I name -の全てのバイト数を表す。 -よって、 -.I inotify_event -構造体のサイズは -.I "sizeof(inotify_event)+len" -である。 +\fBread\fP(2) に渡されたバッファが小さすぎて次のイベントに関する情報を返せ +ない場合の動作はカーネルのバージョンにより異なる。 2.6.21 より前のカー +ネルでは、 \fBread\fP(2) は 0 を返す。 2.6.21 以降のカーネルでは、 +\fBread\fP(2) はエラー \fBEINVAL\fP で失敗する。 +バッファサイズとして -.\"O The behavior when the buffer given to -.\"O .BR read (2) -.\"O is too small to return information about the next event depends -.\"O on the kernel version: in kernels before 2.6.21, -.\"O .BR read (2) -.\"O returns 0; since kernel 2.6.21, -.\"O .BR read (2) -.\"O fails with the error -.\"O .BR EINVAL . -.BR read (2) -に渡されたバッファが小さすぎて次のイベントに関する情報を返せない -場合の動作はカーネルのバージョンにより異なる。 -2.6.21 より前のカーネルでは、 -.BR read (2) -は 0 を返す。 -2.6.21 以降のカーネルでは、 -.BR read (2) -はエラー -.B EINVAL -で失敗する。 -.\"O .SS inotify events -.SS inotify イベント -.\"O The -.\"O .BR inotify_add_watch (2) -.\"O .I mask -.\"O argument and the -.\"O .I mask -.\"O field of the -.\"O .I inotify_event -.\"O structure returned when -.\"O .BR read (2)ing -.\"O an inotify file descriptor are both bit masks identifying -.\"O inotify events. -.BR inotify_add_watch (2) -の -.I mask -引き数と、inotify ファイル構造体を -.BR read (2) -したときに返される -.I inotify_event -構造体の -.I mask -フィールドは、ともに inotify イベントを識別するための -ビットマスクである。 -.\"O The following bits can be specified in -.\"O .I mask -.\"O when calling -.\"O .BR inotify_add_watch (2) -.\"O and may be returned in the -.\"O .I mask -.\"O field returned by -.\"O .BR read (2): -以下のビットが -.BR inotify_add_watch (2) -を呼ぶときの -.I mask -に指定可能であり、 -.BR read (2) -で返される -.I mask -フィールドで返される: + sizeof(struct inotify_event) + NAME_MAX + 1 + +を指定すれば、少なくとも 1 イベントで読み出しを行うには十分である。 +.SS "inotify イベント" +\fBinotify_add_watch\fP(2) の \fImask\fP 引き数と、inotify ファイル構造体を \fBread\fP(2) +したときに返される \fIinotify_event\fP 構造体の \fImask\fP フィールドは、ともに inotify イベントを識別するための +ビットマスクである。 以下のビットが \fBinotify_add_watch\fP(2) を呼ぶときの \fImask\fP に指定可能であり、 +\fBread\fP(2) で返される \fImask\fP フィールドで返される: .RS 4 -.sp -.PD 0 -.TP 18 -.B IN_ACCESS -.\"O File was accessed (read) (*). -ファイルがアクセス (read) された。(*) -.TP -.B IN_ATTRIB -.\"O Metadata changed, e.g., permissions, timestamps, extended attributes, -.\"O link count (since Linux 2.6.25), UID, GID, etc. (*). -メタデータが変更された。 -メタデータとは、例えば、許可 (permission)、タイムスタンプ、拡張属性、 -リンクカウント (Linux 2.6.25 以降)、UID、GID などである。(*) -.TP -.B IN_CLOSE_WRITE -.\"O File opened for writing was closed (*). -書き込みのためにオープンされたファイルがクローズされた。(*) -.TP -.B IN_CLOSE_NOWRITE -.\"O File not opened for writing was closed (*). -書き込み以外のためにオープンされたファイルがクローズされた。(*) -.TP -.B IN_CREATE -.\"O File/directory created in watched directory (*). -監視対象ディレクトリ内でファイルやディレクトリが作成された。(*) -.TP -.B IN_DELETE -.\"O File/directory deleted from watched directory (*). -監視対象ディレクトリ内でファイルやディレクトリが削除された。(*) -.TP -.B IN_DELETE_SELF -.\"O Watched file/directory was itself deleted. -監視対象のディレクトリまたはファイル自身が削除された。 -.TP -.B IN_MODIFY -.\"O File was modified (*). -ファイルが修正された。(*) -.TP -.B IN_MOVE_SELF -.\"O Watched file/directory was itself moved. +.TP +\fBIN_ACCESS\fP (*) +(\fBread\fP(2), \fBexecve\fP(2) などで) ファイルがアクセスされた。 +.TP +\fBIN_ATTRIB\fP (*) +メタデータが変更された。 メタデータとは、例えば、アクセス許可 (\fBchmod\fP(2))、タイムスタンプ (\fButimensat\fP(2) +など)、拡張属性 (\fBsetxattr\fP(2))、 リンクカウント (Linux 2.6.25 以降; \fBlink\fP(2) のリンク先や +\fBunlink\fP(2) など)、ユーザー/グループ ID (\fBchown\fP(2) など) などである。 +.TP +\fBIN_CLOSE_WRITE\fP (*) +書き込みのためにオープンされたファイルがクローズされた。 +.TP +\fBIN_CLOSE_NOWRITE\fP (*) +書き込み以外のためにオープンされたファイルがクローズされた。 +.TP +\fBIN_CREATE\fP (*) +監視対象ディレクトリ内でファイルやディレクトリが作成された (\fBopen\fP(2) \fBO_CREAT\fP, \fBmkdir\fP(2), +\fBlink\fP(2), \fBsymlink\fP(2), UNIX ドメインソケットに対する \fBbind\fP(2) など)。 +.TP +\fBIN_DELETE\fP (*) +監視対象ディレクトリ内でファイルやディレクトリが削除された。 +.TP +\fBIN_DELETE_SELF\fP +Watched file/directory was itself deleted. (This event also occurs if an +object is moved to another filesystem, since \fBmv\fP(1) in effect copies the +file to the other filesystem and then deletes it from the original +filesystem.) In addition, an \fBIN_IGNORED\fP event will subsequently be +generated for the watch descriptor. +.TP +\fBIN_MODIFY\fP (*) +ファイルが変更された (\fBwrite\fP(2), \fBtruncate\fP(2) など)。 +.TP +\fBIN_MOVE_SELF\fP 監視対象のディレクトリまたはファイル自身が移動された。 -.TP -.B IN_MOVED_FROM -.\"O File moved out of watched directory (*). -ファイルが監視対象ディレクトリ外へ移動された。(*) -.TP -.B IN_MOVED_TO -.\"O File moved into watched directory (*). -ファイルが監視対象ディレクトリ内へ移動された。(*) -.TP -.B IN_OPEN -.\"O File was opened (*). -ファイルがオープンされた。(*) -.PD +.TP +\fBIN_MOVED_FROM\fP (*) +ファイル名の変更を行った際に変更前のファイル名が含まれるディレクトリに対して生成される。 +.TP +\fBIN_MOVED_TO\fP (*) +ファイル名の変更を行った際に新しいファイル名が含まれるディレクトリに対して生成される。 +.TP +\fBIN_OPEN\fP (*) +ファイルがオープンされた。 .RE .PP -.\"O When monitoring a directory, -.\"O the events marked with an asterisk (*) above can occur for -.\"O files in the directory, in which case the -.\"O .I name -.\"O field in the returned -.\"O .I inotify_event -.\"O structure identifies the name of the file within the directory. -ディレクトリを監視する場合、 -上記でアスタリスク (*) を付けたイベントは、 -そのディレクトリ内のファイルに対して発生する。 -このとき -.I inotify_event -構造体で返される -.I name -フィールドは、ディレクトリ内のファイル名を表す。 +ディレクトリを監視する場合、 上記でアスタリスク (*) を付けたイベントは、 そのディレクトリ内のファイルに対して発生する。 このとき +\fIinotify_event\fP 構造体で返される \fIname\fP フィールドは、ディレクトリ内のファイル名を表す。 .PP -.\"O The -.\"O .B IN_ALL_EVENTS -.\"O macro is defined as a bit mask of all of the above events. -.\"O This macro can be used as the -.\"O .I mask -.\"O argument when calling -.\"O .BR inotify_add_watch (2). -.B IN_ALL_EVENTS -マクロは上記のイベント全てのマスクとして定義される。 -このマクロは -.BR inotify_add_watch (2) -を呼び出すときの -.I mask -引き数として使える。 +\fBIN_ALL_EVENTS\fP マクロは上記のイベント全てのマスクとして定義される。 このマクロは \fBinotify_add_watch\fP(2) +を呼び出すときの \fImask\fP 引き数として使える。 -.\"O Two additional convenience macros are -.\"O .BR IN_MOVE , -.\"O which equates to -.\"O IN_MOVED_FROM|IN_MOVED_TO, -.\"O and -.\"O .B IN_CLOSE -.\"O which equates to -.\"O IN_CLOSE_WRITE|IN_CLOSE_NOWRITE. -さらに 2 つの便利なマクロがある。 -.B IN_MOVE -は -IN_MOVED_FROM|IN_MOVED_TO -と等しく、 -.B IN_CLOSE -は -IN_CLOSE_WRITE|IN_CLOSE_NOWRITE -と等しい。 +以下の 2 つの便利なマクロが定義されている。 +.RS 4 +.TP +\fBIN_MOVE\fP +\fBIN_MOVED_FROM | IN_MOVED_TO\fP と等価。 +.TP +\fBIN_CLOSE\fP +\fBIN_CLOSE_WRITE | IN_CLOSE_NOWRITE\fP と等価。 +.RE .PP -.\"O The following further bits can be specified in -.\"O .I mask -.\"O when calling -.\"O .BR inotify_add_watch (2): -その他にも以下のビットを -.BR inotify_add_watch (2) -を呼ぶときの -.I mask -に指定できる: +その他にも以下のビットを \fBinotify_add_watch\fP(2) を呼ぶときの \fImask\fP に指定できる: .RS 4 -.sp -.PD 0 -.TP 18 -.B IN_DONT_FOLLOW -.\"O Don't dereference \fIpathname\fP if it is a symbolic link -.\"O (since Linux 2.6.15). -\fIpathname\fP がシンボリックリンクである場合に辿らない。 -(Linux 2.6.15 以降) -.TP -.B IN_MASK_ADD -.\"O Add (OR) events to watch mask for this pathname if -.\"O it already exists (instead of replacing mask). -\fIpathname\fP に対する監視マスクが既に存在する場合、 -(マスクの置き換えではなく) イベントを追加 (OR) する。 -.TP -.B IN_ONESHOT -.\"O Monitor \fIpathname\fP for one event, then remove from -.\"O watch list. -1 つのイベントについて \fIpathname\fP を監視し、 -イベントが発生したら監視対象リストから削除する。 -.TP -.\"O .BR IN_ONLYDIR " (since Linux 2.6.15)" -.BR IN_ONLYDIR " (Linux 2.6.15 以降)" -.\"O Only watch \fIpathname\fP if it is a directory. +.TP +\fBIN_DONT_FOLLOW\fP (Linux 2.6.15 以降) +\fIpathname\fP がシンボリックリンクである場合に辿らない。 (Linux 2.6.15 以降) +.TP +\fBIN_EXCL_UNLINK\fP (Linux 2.6.36 以降) +.\" commit 8c1934c8d70b22ca8333b216aec6c7d09fdbd6a6 +デフォルトでは、あるディレクトリの子ファイルに関するイベントを監視 (watch) した際、ディレクトリからその子ファイルが削除 (unlink) +された場合であってもその子ファイルに対してイベントが生成される。このことは、アプリケーションによってはあまり興味のないイベントが大量に発生することにつながる +(例えば、\fI/tmp\fP を監視している場合、たくさんのアプリケーションが、すぐにその名前が削除される一時ファイルをそのディレクトリに作成する)。 +\fBIN_EXCL_UNLINK\fP +を指定するとこのデフォルトの動作を変更でき、監視対象のディレクトリから子ファイルが削除された後に子ファイルに関するイベントが生成されなくなる。 +.TP +\fBIN_MASK_ADD\fP +\fIpathname\fP に対する監視マスクが既に存在する場合、 (マスクの置き換えではなく) イベントを追加 (OR) する。 +.TP +\fBIN_ONESHOT\fP +1 つのイベントについて \fIpathname\fP を監視し、 イベントが発生したら監視対象リストから削除する。 +.TP +\fBIN_ONLYDIR\fP (Linux 2.6.15 以降) \fIpathname\fP がディレクトリの場合にのみ監視する。 -.PD .RE .PP -.\"O The following bits may be set in the -.\"O .I mask -.\"O field returned by -.\"O .BR read (2): -以下のビットが -.BR read (2) -で返される -.I mask -フィールドに設定される: +以下のビットが \fBread\fP(2) で返される \fImask\fP フィールドに設定される: .RS 4 -.sp -.PD 0 -.TP 18 -.B IN_IGNORED -.\"O Watch was removed explicitly (\fBinotify_rm_watch\fP(2)) -.\"O or automatically (file was deleted, or file system was unmounted). -監視対象が (\fBinotify_rm_watch\fP(2) により) 明示的に -削除された。もしくは (ファイルの削除、またはファイル -システムのアンマウントにより) 自動的に削除された。 -.TP -.B IN_ISDIR -.\"O Subject of this event is a directory. +.TP +\fBIN_IGNORED\fP +監視対象が (\fBinotify_rm_watch\fP(2) により) 明示的に 削除された。もしくは (ファイルの削除、またはファイル +システムのアンマウントにより) 自動的に削除された。「バグ」も参照のこと。 +.TP +\fBIN_ISDIR\fP このイベントの対象がディレクトリである。 -.TP -.B IN_Q_OVERFLOW -.\"O Event queue overflowed (\fIwd\fP is \-1 for this event). +.TP +\fBIN_Q_OVERFLOW\fP イベントキューが溢れた (このイベントの場合、\fIwd\fP は \-1 である)。 -.TP -.B IN_UNMOUNT -.\"O File system containing watched object was unmounted. -監視対象オブジェクトを含むファイルシステムがアンマウントされた。 -.PD +.TP +\fBIN_UNMOUNT\fP +監視対象オブジェクトを含むファイルシステムがアンマウントされた。さらに、この監視対象ディスクリプタに対して \fBIN_IGNORED\fP +イベントが生成される。 +.RE +.SS 例 +Suppose an application is watching the directory \fIdir\fP and the file +\fIdir/myfile\fP for all events. The examples below show some events that will +be generated for these two objects. +.RS 4 +.TP +fd = open("dir/myfile", O_RDWR); +\fIdir\fP と \fIdir/myfile\fP の両方に対して \fBIN_OPEN\fP イベントが生成される。 +.TP +read(fd, buf, count); +\fIdir\fP と \fIdir/myfile\fP の両方に対して \fBIN_ACCESS\fP イベントが生成される +.TP +write(fd, buf, count); +\fIdir\fP と \fIdir/myfile\fP の両方に対して \fBIN_MODIFY\fP イベントが生成される +.TP +fchmod(fd, mode); +\fIdir\fP と \fIdir/myfile\fP の両方に対して \fBIN_ATTRIB\fP イベントが生成される +.TP +close(fd); +\fIdir\fP と \fIdir/myfile\fP の両方に対して \fBIN_CLOSE_WRITE\fP イベントが生成される .RE -.\"O .SS /proc interfaces -.SS /proc インターフェース -.\"O The following interfaces can be used to limit the amount of -.\"O kernel memory consumed by inotify: -以下のインターフェースは、inotify で消費される -カーネルメモリの総量を制限するのに使用できる: -.TP -.I /proc/sys/fs/inotify/max_queued_events -.\"O The value in this file is used when an application calls -.\"O .BR inotify_init (2) -.\"O to set an upper limit on the number of events that can be -.\"O queued to the corresponding inotify instance. -このファイルの値は、アプリケーションが -.BR inotify_init (2) -を呼び出すときに使用され、対応する inotify インスタンスについて -キューに入れられるイベントの数の上限を設定する。 -.\"O Events in excess of this limit are dropped, but an -.\"O .B IN_Q_OVERFLOW -.\"O event is always generated. -この制限を超えたイベントは破棄されるが、 -.B IN_Q_OVERFLOW -イベントが常に生成される。 -.TP -.I /proc/sys/fs/inotify/max_user_instances -.\"O This specifies an upper limit on the number of inotify instances -.\"O that can be created per real user ID. -1 つの実ユーザ ID に対して生成できる -inotify インスタンスの数の上限を指定する。 -.TP -.I /proc/sys/fs/inotify/max_user_watches -.\"O This specifies an upper limit on the number of watches -.\"O that can be created per real user ID. +.PP +Suppose an application is watching the directories \fIdir1\fP and \fIdir\fP, and +the file \fIdir1/myfile\fP. The following examples show some events that may +be generated. +.RS 4 +.TP +link("dir/myfile", "dir2/new"); +\fImyfile\fP に対して \fBIN_ATTRIB\fP イベントが生成され、 \fIdir2\fP に対して \fBIN_CREATE\fP イベントが生成される。 +.TP +rename("dir1/myfile", "dir2/myfile"); +\fIdir1\fP に対してイベント \fBIN_MOVED_FROM\fP が、 \fIdir2\fP に対してイベント \fBIN_MOVED_TO\fP が、 +\fImyfile\fP に対してイベント \fBIN_MOVE_SELF\fP が生成される。この際 イベント \fBIN_MOVED_FROM\fP と +\fBIN_MOVED_TO\fP は同じ \fIcookie\fP 値を持つ。 +.RE +.PP +Suppose that \fIdir1/xx\fP and \fIdir2/yy\fP are (the only) links to the same +file, and an application is watching \fIdir1\fP, \fIdir2\fP, \fIdir1/xx\fP, and +\fIdir2/yy\fP. Executing the following calls in the order given below will +generate the following events: +.RS 4 +.TP +unlink("dir2/yy"); +Generates \fBIN_ATTRIB\fP event for \fIxx\fP (because its link count changes) and +an \fBIN_DELETE\fP event for \fIdir2\fP. +.TP +unlink("dir1/xx"); +Generates \fBIN_ATTRIB\fP, \fBIN_DELETE_SELF\fP, and \fBIN_IGNORED\fP events for +\fIxx\fP, and an \fBIN_DELETE\fP for \fIdir1\fP. +.RE +.PP +Suppose an application is watching the directory \fIdir\fP and (the empty) +directory \fIdir/subdir\fP. The following examples show some events that may +be generated. +.RS 4 +.TP +mkdir("dir/new", mode); +Generates an \fBIN_CREATE | IN_ISDIR\fP event for \fIdir\fP. +.TP +rmdir("dir/sub"); +Generates \fBIN_DELETE_SELF\fP and \fBIN_IGNORED\fP events for \fIsubdir\fP, and an +\fBIN_DELETE | IN_ISDIR\fP event for \fIdir\fP. +.RE +.SS "/proc インターフェース" +以下のインターフェースは、inotify で消費される カーネルメモリの総量を制限するのに使用できる: +.TP +\fI/proc/sys/fs/inotify/max_queued_events\fP +このファイルの値は、アプリケーションが \fBinotify_init\fP(2) を呼び出すときに使用され、対応する inotify インスタンスについて +キューに入れられるイベントの数の上限を設定する。 この制限を超えたイベントは破棄されるが、 \fBIN_Q_OVERFLOW\fP イベントが常に生成される。 +.TP +\fI/proc/sys/fs/inotify/max_user_instances\fP +1 つの実ユーザ ID に対して生成できる inotify インスタンスの数の上限を指定する。 +.TP +\fI/proc/sys/fs/inotify/max_user_watches\fP 作成可能な監視対象の数の実 UID 単位の上限を指定する。 -.\"O .SH "VERSIONS" .SH バージョン -.\"O Inotify was merged into the 2.6.13 Linux kernel. -.\"O The required library interfaces were added to glibc in version 2.4. -.\"O .RB ( IN_DONT_FOLLOW , -.\"O .BR IN_MASK_ADD , -.\"O and -.\"O .B IN_ONLYDIR -.\"O were only added in version 2.5.) -inotify は 2.6.13 の Linux カーネルに組込まれた。 -これに必要なライブラリのインターフェースは、 -glibc のバージョン 2.4 に追加された -.RB ( IN_DONT_FOLLOW , -.BR IN_MASK_ADD , -.B IN_ONLYDIR -だけはバージョン 2.5 で追加された)。 -.\"O .SH "CONFORMING TO" +inotify は 2.6.13 の Linux カーネルに組込まれた。 これに必要なライブラリのインターフェースは、 glibc のバージョン 2.4 +に追加された (\fBIN_DONT_FOLLOW\fP, \fBIN_MASK_ADD\fP, \fBIN_ONLYDIR\fP は glibc バージョン 2.5 +で追加された)。 .SH 準拠 -.\"O The inotify API is Linux-specific. inotify API は Linux 独自のものである。 -.\"O .SH "NOTES" .SH 注意 -.\"O Inotify file descriptors can be monitored using -.\"O .BR select (2), -.\"O .BR poll (2), -.\"O and -.\"O .BR epoll (7). -inotify ファイルディスクリプタは -.BR select (2), -.BR poll (2), -.BR epoll (7) -を使って監視できる。 -.\"O When an event is available, the file descriptor indicates as readable. +inotify ファイルディスクリプタは \fBselect\fP(2), \fBpoll\fP(2), \fBepoll\fP(7) を使って監視できる。 イベントがある場合、ファイルディスクリプタは読み込み可能と通知する。 -.\"O Since Linux 2.6.25, -.\"O signal-driven I/O notification is available for inotify file descriptors; -.\"O see the discussion of -.\"O .B F_SETFL -.\"O (for setting the -.\"O .B O_ASYNC -.\"O flag), -.\"O .BR F_SETOWN , -.\"O and -.\"O .B F_SETSIG -.\"O in -.\"O .BR fcntl (2). -Linux 2.6.25 以降では、シグナル駆動 (signal-driven) I/O の通知が -inotify ファイルディスクリプタについて利用可能である。 -.BR fcntl (2) -に書かれている -.RB ( O_ASYNC -フラグを設定するための) -.BR F_SETFL , -.BR F_SETOWN , -.B F_SETSIG -の議論を参照のこと。 -.\"O The -.\"O .I siginfo_t -.\"O structure (described in -.\"O .BR sigaction (2)) -.\"O that is passed to the signal handler has the following fields set: -.\"O .IR si_fd -.\"O is set to the inotify file descriptor number; -.\"O .IR si_signo -.\"O is set to the signal number; -.\"O .IR si_code -.\"O is set to -.\"O .BR POLL_IN ; -.\"O and -.\"O .B POLLIN -.\"O is set in -.\"O .IR si_band . -シグナルハンドラに渡される -.I siginfo_t -構造体は、以下のフィールドが設定される -.RI ( siginfo_t -は -.BR sigaction (2) -で説明されている)。 -.I si_fd -には inotify ファイルディスクリプタ番号が、 -.I si_signo -にはシグナル番号が、 -.I si_code -には -.BR POLL_IN -が、 -.I si_band -には -.B POLLIN -が設定される。 +Linux 2.6.25 以降では、シグナル駆動 (signal\-driven) I/O の通知が inotify +ファイルディスクリプタについて利用可能である。 \fBfcntl\fP(2) に書かれている (\fBO_ASYNC\fP フラグを設定するための) +\fBF_SETFL\fP, \fBF_SETOWN\fP, \fBF_SETSIG\fP の議論を参照のこと。 シグナルハンドラに渡される \fIsiginfo_t\fP +構造体は、以下のフィールドが設定される (\fIsiginfo_t\fP は \fBsigaction\fP(2) で説明されている)。 \fIsi_fd\fP には +inotify ファイルディスクリプタ番号が、 \fIsi_signo\fP にはシグナル番号が、 \fIsi_code\fP には \fBPOLL_IN\fP が、 +\fIsi_band\fP には \fBPOLLIN\fP が設定される。 -.\"O If successive output inotify events produced on the -.\"O inotify file descriptor are identical (same -.\"O .IR wd , -.\"O .IR mask , -.\"O .IR cookie , -.\"O and -.\"O .IR name ) -.\"O then they are coalesced into a single event if the -.\"O older event has not yet been read (but see BUGS). -inotify ファイルディスクリプタに対して -連続して生成される出力 inotify イベントが同一の場合 -.RI ( wd , -.IR mask , -.IR cookie , -.I name -が等しい場合)、 -前のイベントがまだ読み込まれていなければ、 -連続するイベントが 1 つのイベントにまとめられる -(ただし「バグ」の節も参照のこと)。 +If successive output inotify events produced on the inotify file descriptor +are identical (same \fIwd\fP, \fImask\fP, \fIcookie\fP, and \fIname\fP), then they are +coalesced into a single event if the older event has not yet been read (but +see BUGS). This reduces the amount of kernel memory required for the event +queue, but also means that an application can't use inotify to reliably +count file events. -.\"O The events returned by reading from an inotify file descriptor -.\"O form an ordered queue. -.\"O Thus, for example, it is guaranteed that when renaming from -.\"O one directory to another, events will be produced in the -.\"O correct order on the inotify file descriptor. -.\"Osato: -.\"Osato: 以下の訳が上手くできていない気がする。 -.\"Osato: -inotify ファイルディスクリプタの読み込みで返されるイベントは、 -順序付けられたキューになる。 -従って、たとえば、あるディレクトリの名前を別の名前に変更した場合、 -inotify ファイルディスクリプタについての正しい順番で +inotify ファイルディスクリプタの読み込みで返されるイベントは、 順序付けられたキューになる。 +従って、たとえば、あるディレクトリの名前を別の名前に変更した場合、 inotify ファイルディスクリプタについての正しい順番で イベントが生成されることが保証される。 -.\"O The -.\"O .B FIONREAD -.\"O .BR ioctl (2) -.\"O returns the number of bytes available to read from an -.\"O inotify file descriptor. -.B FIONREAD -.BR ioctl (2) -は inotify ファイルディスクリプタから何バイト読み込めるかを返す。 +\fBFIONREAD\fP \fBioctl\fP(2) は inotify ファイルディスクリプタから何バイト読み込めるかを返す。 +.SS 制限と警告 +inotify API では、inotify イベントが発生するきっかけとなったユーザやプロセスに関する情報は提供されない。とりわけ、inotify +経由でイベントを監視しているプロセスが、自分自身がきっかけとなったイベントと他のプロセスがきっかけとなったイベントを区別する簡単な手段はない。 + +Inotify reports only events that a user\-space program triggers through the +filesystem API. As a result, it does not catch remote events that occur on +network filesystems. (Applications must fall back to polling the filesystem +to catch such events.) Furthermore, various pseudo\-filesystems such as +\fI/proc\fP, \fI/sys\fP, and \fI/dev/pts\fP are not monitorable with inotify. + +The inotify API does not report file accesses and modifications that may +occur because of \fBmmap\fP(2) and \fBmsync\fP(2). + +inotify API では影響が受けるファイルをファイル名で特定する。 +しかしながら、アプリケーションが inotify イベントを処理する時点では、 +そのファイル名がすでに削除されたり変更されたりしている可能性がある。 -.\"O Inotify monitoring of directories is not recursive: -.\"O to monitor subdirectories under a directory, -.\"O additional watches must be created. -inotify によるディレクトリの監視は再帰的に行われない: -あるディレクトリ以下のサブディレクトリを監視する場合、 -監視対象を追加で作成しなければならない。 -.\"O .SH "BUGS" +The inotify API identifies events via watch descriptors. It is the +application's responsibility to cache a mapping (if one is needed) between +watch descriptors and pathnames. Be aware that directory renamings may +affect multiple cached pathnames. + +inotify によるディレクトリの監視は再帰的に行われない: あるディレクトリ以下の +サブディレクトリを監視する場合、 監視対象を追加で作成しなければならない。 +大きなディレクトリツリーの場合には、この作業にかなり時間がかかることがある。 + +If monitoring an entire directory subtree, and a new subdirectory is created +in that tree or an existing directory is renamed into that tree, be aware +that by the time you create a watch for the new subdirectory, new files (and +subdirectories) may already exist inside the subdirectory. Therefore, you +may want to scan the contents of the subdirectory immediately after adding +the watch (and, if desired, recursively add watches for any subdirectories +that it contains). + +Note that the event queue can overflow. In this case, events are lost. +Robust applications should handle the possibility of lost events +gracefully. For example, it may be necessary to rebuild part or all of the +application cache. (One simple, but possibly expensive, approach is to +close the inotify file descriptor, empty the cache, create a new inotify +file descriptor, and then re\-create watches and cache entries for the +objects to be monitored.) +.SS "rename() イベントの取り扱い" +As noted above, the \fBIN_MOVED_FROM\fP and \fBIN_MOVED_TO\fP event pair that is +generated by \fBrename\fP(2) can be matched up via their shared cookie value. +However, the task of matching has some challenges. + +These two events are usually consecutive in the event stream available when +reading from the inotify file descriptor. However, this is not guaranteed. +If multiple processes are triggering events for monitored objects, then (on +rare occasions) an arbitrary number of other events may appear between the +\fBIN_MOVED_FROM\fP and \fBIN_MOVED_TO\fP events. + +Matching up the \fBIN_MOVED_FROM\fP and \fBIN_MOVED_TO\fP event pair generated by +\fBrename\fP(2) is thus inherently racy. (Don't forget that if an object is +renamed outside of a monitored directory, there may not even be an +\fBIN_MOVED_TO\fP event.) Heuristic approaches (e.g., assume the events are +always consecutive) can be used to ensure a match in most cases, but will +inevitably miss some cases, causing the application to perceive the +\fBIN_MOVED_FROM\fP and \fBIN_MOVED_TO\fP events as being unrelated. If watch +descriptors are destroyed and re\-created as a result, then those watch +descriptors will be inconsistent with the watch descriptors in any pending +events. (Re\-creating the inotify file descriptor and rebuilding the cache +may be useful to deal with this scenario.) + +Applications should also allow for the possibility that the \fBIN_MOVED_FROM\fP +event was the last event that could fit in the buffer returned by the +current call to \fBread\fP(2), and the accompanying \fBIN_MOVED_TO\fP event might +be fetched only on the next \fBread\fP(2). .SH バグ -.\"O In kernels before 2.6.16, the -.\"O .B IN_ONESHOT -.\"O .I mask -.\"O flag does not work. -2.6.16 以前のカーネルでは -.B IN_ONESHOT -.I mask -フラグが働かない。 +.\" FIXME kernel commit 611da04f7a31b2208e838be55a42c7a1310ae321 +.\" implies that unmount events were buggy 2.6.11 to 2.6.36 +.\" +2.6.16 以前のカーネルでは \fBIN_ONESHOT\fP \fImask\fP フラグが働かない。 -.\"O Before kernel 2.6.25, -.\"O the kernel code that was intended to coalesce successive identical events -.\"O (i.e., the two most recent events could potentially be coalesced -.\"O if the older had not yet been read) -.\"O instead checked if the most recent event could be coalesced with the -.\"O .I oldest -.\"O unread event. -カーネル 2.6.25 より前では、 -連続する同一のイベントを一つにまとめることを意図したコード -(古い方のイベントがまだ読み込まれていない場合に、 -最新の 2 つのイベントを一つにまとめられる可能性がある) が、 -最新のイベントが「最も古い」読み込まれていないイベントとまとめられるか +As originally designed and implemented, the \fBIN_ONESHOT\fP flag did not cause +an \fBIN_IGNORED\fP event to be generated when the watch was dropped after one +event. However, as an unintended effect of other changes, since Linux +2.6.36, an \fBIN_IGNORED\fP event is generated in this case. + +.\" commit 1c17d18e3775485bf1e0ce79575eb637a94494a2 +カーネル 2.6.25 より前では、 連続する同一のイベントを一つにまとめることを意図したコード (古い方のイベントがまだ読み込まれていない場合に、 +最新の 2 つのイベントを一つにまとめられる可能性がある) が、 最新のイベントが「最も古い」読み込まれていないイベントとまとめられるか をチェックするようになっていた。 -.\"O .SH "SEE ALSO" .SH 関連項目 -.BR inotify_add_watch (2), -.BR inotify_init (2), -.BR inotify_init1 (2), -.BR inotify_rm_watch (2), -.BR read (2), -.BR stat (2), -.IR Documentation/filesystems/inotify.txt . +\fBinotifywait\fP(1), \fBinotifywatch\fP(1), \fBinotify_add_watch\fP(2), +\fBinotify_init\fP(2), \fBinotify_init1\fP(2), \fBinotify_rm_watch\fP(2), \fBread\fP(2), +\fBstat\fP(2) + +Linux カーネルソース内の \fIDocumentation/filesystems/inotify.txt\fP +.SH この文書について +この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.64 の一部 +である。プロジェクトの説明とバグ報告に関する情報は +http://www.kernel.org/doc/man\-pages/ に書かれている。