私はinotify呼び出しを研究してきましたが、読み取りインターフェイスに関してはまだ少し不安定です。これらは、read(2)を使用してinotifyと適切にインターフェイスする方法に関して私が見つけた最も関連性の高いリソースです。
- http://www.ibm.com/developerworks/linux/library/l-ubuntu-inotify/index.html
- http://www.linuxjournal.com/article/8478
どちらも同じ方法で実装し、最初に次のサイズを定義します。
#define EVENT_SIZE ( sizeof (struct inotify_event) )
#define BUF_LEN ( 1024 * ( EVENT_SIZE + 16 )
そして、彼らはこれらを次のように使用します。
length = read( fd, buffer, BUF_LEN );
if ( length < 0 ) {
perror( "read" );
}
while ( i < length ) {
struct inotify_event *event = ( struct inotify_event * ) &buffer[ i ];
/* some processing */
i += EVENT_SIZE + event->len;
}
struct inotify_event
これで、名前がの一部であり、長さが可変であることがわかりました。では、バッファ内の最後のinotify_eventを切り捨てることはできませんでしたか?
パスが16バイトのinotify_eventsが1023個あり、パスが32バイトのinotify_eventsが10個あるとします。それではどうなりますか?後で切り捨てられますか?または、カーネルはそれがバッファに収まらないことを認識し、すべてをそのままにしますか?