> For example, on Linux you could check /etc/mtab and maybe
> /proc/filesystems to find out on what mount type the watched file resides,
> and, if it's a file system like NFS, fall back to polling for changes.
However,
> that opens up a race window: another process can remount the file system
in
> the time between reading /etc/mtab and creating the watcher.
You could use fstatfs() the file it to find out without racing. Obviously
the user can still remount after inotify has been set up; I don't know what
will happen then.
> Knowing what file systems will and won't report events is another hard
> problem. Some won't work at all, others only partially or unreliably.
> I would take a conservative approach here and use a whitelist (ext3, ext4,
> xfs, jfs) and fall back to polling for everything else. That approach
won't work
> for file systems like /proc however, because the inode changes on every
> stat. (inotify on the other hand doesn't work at all on procfs...)
Libev also uses a whitelist approach:
```c
struct statfs sfs;
/* now local changes will be tracked by inotify, but remote changes
won't */
/* unless the filesystem is known to be local, we therefore still poll
*/
/* also do poll on <2.6.25, but with normal frequency */
if (!fs_2625)
w->timer.repeat = w->interval ? w->interval : DEF_STAT_INTERVAL;
else if (!statfs (w->path, &sfs)
&& (sfs.f_type == 0x1373 /* devfs */
|| sfs.f_type == 0xEF53 /* ext2/3 */
|| sfs.f_type == 0x3153464a /* jfs */
|| sfs.f_type == 0x52654973 /* reiser3 */
|| sfs.f_type == 0x01021994 /* tempfs */
|| sfs.f_type == 0x58465342 /* xfs */))
w->timer.repeat = 0.; /* filesystem is local, kernel new enough */
else
w->timer.repeat = w->interval ? w->interval : NFS_STAT_INTERVAL; /*
remote, use reduced frequency */
```
> And that's just Linux. Other platforms have similar (or completely
> different) issues. :-)
You should define clearly what is supposed to happen. For example, if the
user renames a file, do we follow it or do we keep watching/polling the old
filename?
Also, we'd need to think about if and how we could monitor directories.
- Bert