dnotify.txt 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. Linux Directory Notification
  2. ============================
  3. Stephen Rothwell <sfr@canb.auug.org.au>
  4. The intention of directory notification is to allow user applications
  5. to be notified when a directory, or any of the files in it, are changed.
  6. The basic mechanism involves the application registering for notification
  7. on a directory using a fcntl(2) call and the notifications themselves
  8. being delivered using signals.
  9. The application decides which "events" it wants to be notified about.
  10. The currently defined events are:
  11. DN_ACCESS A file in the directory was accessed (read)
  12. DN_MODIFY A file in the directory was modified (write,truncate)
  13. DN_CREATE A file was created in the directory
  14. DN_DELETE A file was unlinked from directory
  15. DN_RENAME A file in the directory was renamed
  16. DN_ATTRIB A file in the directory had its attributes
  17. changed (chmod,chown)
  18. Usually, the application must reregister after each notification, but
  19. if DN_MULTISHOT is or'ed with the event mask, then the registration will
  20. remain until explicitly removed (by registering for no events).
  21. By default, SIGIO will be delivered to the process and no other useful
  22. information. However, if the F_SETSIG fcntl(2) call is used to let the
  23. kernel know which signal to deliver, a siginfo structure will be passed to
  24. the signal handler and the si_fd member of that structure will contain the
  25. file descriptor associated with the directory in which the event occurred.
  26. Preferably the application will choose one of the real time signals
  27. (SIGRTMIN + <n>) so that the notifications may be queued. This is
  28. especially important if DN_MULTISHOT is specified. Note that SIGRTMIN
  29. is often blocked, so it is better to use (at least) SIGRTMIN + 1.
  30. Implementation expectations (features and bugs :-))
  31. ---------------------------
  32. The notification should work for any local access to files even if the
  33. actual file system is on a remote server. This implies that remote
  34. access to files served by local user mode servers should be notified.
  35. Also, remote accesses to files served by a local kernel NFS server should
  36. be notified.
  37. In order to make the impact on the file system code as small as possible,
  38. the problem of hard links to files has been ignored. So if a file (x)
  39. exists in two directories (a and b) then a change to the file using the
  40. name "a/x" should be notified to a program expecting notifications on
  41. directory "a", but will not be notified to one expecting notifications on
  42. directory "b".
  43. Also, files that are unlinked, will still cause notifications in the
  44. last directory that they were linked to.
  45. Configuration
  46. -------------
  47. Dnotify is controlled via the CONFIG_DNOTIFY configuration option. When
  48. disabled, fcntl(fd, F_NOTIFY, ...) will return -EINVAL.
  49. Example
  50. -------
  51. See Documentation/filesystems/dnotify_test.c for an example.
  52. NOTE
  53. ----
  54. Beginning with Linux 2.6.13, dnotify has been replaced by inotify.
  55. See Documentation/filesystems/inotify.txt for more information on it.