18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci
38c2ecf20Sopenharmony_ci============================
48c2ecf20Sopenharmony_ciLinux Directory Notification
58c2ecf20Sopenharmony_ci============================
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci	   Stephen Rothwell <sfr@canb.auug.org.au>
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ciThe intention of directory notification is to allow user applications
108c2ecf20Sopenharmony_cito be notified when a directory, or any of the files in it, are changed.
118c2ecf20Sopenharmony_ciThe basic mechanism involves the application registering for notification
128c2ecf20Sopenharmony_cion a directory using a fcntl(2) call and the notifications themselves
138c2ecf20Sopenharmony_cibeing delivered using signals.
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ciThe application decides which "events" it wants to be notified about.
168c2ecf20Sopenharmony_ciThe currently defined events are:
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci	=========	=====================================================
198c2ecf20Sopenharmony_ci	DN_ACCESS	A file in the directory was accessed (read)
208c2ecf20Sopenharmony_ci	DN_MODIFY	A file in the directory was modified (write,truncate)
218c2ecf20Sopenharmony_ci	DN_CREATE	A file was created in the directory
228c2ecf20Sopenharmony_ci	DN_DELETE	A file was unlinked from directory
238c2ecf20Sopenharmony_ci	DN_RENAME	A file in the directory was renamed
248c2ecf20Sopenharmony_ci	DN_ATTRIB	A file in the directory had its attributes
258c2ecf20Sopenharmony_ci			changed (chmod,chown)
268c2ecf20Sopenharmony_ci	=========	=====================================================
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ciUsually, the application must reregister after each notification, but
298c2ecf20Sopenharmony_ciif DN_MULTISHOT is or'ed with the event mask, then the registration will
308c2ecf20Sopenharmony_ciremain until explicitly removed (by registering for no events).
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ciBy default, SIGIO will be delivered to the process and no other useful
338c2ecf20Sopenharmony_ciinformation.  However, if the F_SETSIG fcntl(2) call is used to let the
348c2ecf20Sopenharmony_cikernel know which signal to deliver, a siginfo structure will be passed to
358c2ecf20Sopenharmony_cithe signal handler and the si_fd member of that structure will contain the
368c2ecf20Sopenharmony_cifile descriptor associated with the directory in which the event occurred.
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ciPreferably the application will choose one of the real time signals
398c2ecf20Sopenharmony_ci(SIGRTMIN + <n>) so that the notifications may be queued.  This is
408c2ecf20Sopenharmony_ciespecially important if DN_MULTISHOT is specified.  Note that SIGRTMIN
418c2ecf20Sopenharmony_ciis often blocked, so it is better to use (at least) SIGRTMIN + 1.
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ciImplementation expectations (features and bugs :-))
448c2ecf20Sopenharmony_ci---------------------------------------------------
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ciThe notification should work for any local access to files even if the
478c2ecf20Sopenharmony_ciactual file system is on a remote server.  This implies that remote
488c2ecf20Sopenharmony_ciaccess to files served by local user mode servers should be notified.
498c2ecf20Sopenharmony_ciAlso, remote accesses to files served by a local kernel NFS server should
508c2ecf20Sopenharmony_cibe notified.
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ciIn order to make the impact on the file system code as small as possible,
538c2ecf20Sopenharmony_cithe problem of hard links to files has been ignored.  So if a file (x)
548c2ecf20Sopenharmony_ciexists in two directories (a and b) then a change to the file using the
558c2ecf20Sopenharmony_ciname "a/x" should be notified to a program expecting notifications on
568c2ecf20Sopenharmony_cidirectory "a", but will not be notified to one expecting notifications on
578c2ecf20Sopenharmony_cidirectory "b".
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ciAlso, files that are unlinked, will still cause notifications in the
608c2ecf20Sopenharmony_cilast directory that they were linked to.
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ciConfiguration
638c2ecf20Sopenharmony_ci-------------
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ciDnotify is controlled via the CONFIG_DNOTIFY configuration option.  When
668c2ecf20Sopenharmony_cidisabled, fcntl(fd, F_NOTIFY, ...) will return -EINVAL.
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ciExample
698c2ecf20Sopenharmony_ci-------
708c2ecf20Sopenharmony_ciSee tools/testing/selftests/filesystems/dnotify_test.c for an example.
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ciNOTE
738c2ecf20Sopenharmony_ci----
748c2ecf20Sopenharmony_ciBeginning with Linux 2.6.13, dnotify has been replaced by inotify.
758c2ecf20Sopenharmony_ciSee Documentation/filesystems/inotify.rst for more information on it.
76