some notes about inotify
Here i am going to publish some related informations about inotify(), maybe being useful for developers.
I played a bit with inotify while developing rhttpd - a tiny webserver.
With inotify (introduced in linux 2.6;
glibc 2.4)
it is possible to watch modifications on a inode.
If you're new in handling inotify you may read http://kerneltrap.org/node/3847 or
google.
some facts
- Only existing inodes will be able to watch.
This is important to know when building a stat() cache or something similar.
However, it is possible to watch the parent folder for changes.
But this may be a bad idea because the requested filename maybe somewhere
inside a not yet existent sub-...-sub directory.
- In contrast to the file descriptors (fd) the watch descriptors (wd) returned by
inotify_add_watch() are always incrementing.
- When reading something from the fd returned by inotify_init()
be warned that the filename of the triggered wd is not always (very seldom) returned.
The idea from kernels point of view is to safe time with copying memory into user space.
However, the wd is always returned so it may be easy to find out what
filename was modified by finding this wd inside an array.
- While reading from inotify's fd into a buffer the length of each
struct inotify_event
bucket is: sizeof(struct inotify_event) + ino_event->len
.
This is important because a read()
from this fd may return more then one struct inotify_event
.
Currently i dont know if read() from this fd may block and should read() again from the previous offset.
Thanks to some guys from irc.german-elite.net / #linux for english translation.