dnotify.rst 3.1 KB

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