aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/filesystems
diff options
context:
space:
mode:
Diffstat (limited to 'Documentation/filesystems')
-rw-r--r--Documentation/filesystems/00-INDEX2
-rw-r--r--Documentation/filesystems/dnotify.txt99
2 files changed, 101 insertions, 0 deletions
diff --git a/Documentation/filesystems/00-INDEX b/Documentation/filesystems/00-INDEX
index 1de155e2dc36..632fe3f376eb 100644
--- a/Documentation/filesystems/00-INDEX
+++ b/Documentation/filesystems/00-INDEX
@@ -32,6 +32,8 @@ directory-locking
32 - info about the locking scheme used for directory operations. 32 - info about the locking scheme used for directory operations.
33dlmfs.txt 33dlmfs.txt
34 - info on the userspace interface to the OCFS2 DLM. 34 - info on the userspace interface to the OCFS2 DLM.
35dnotify.txt
36 - info about directory notification in Linux.
35ecryptfs.txt 37ecryptfs.txt
36 - docs on eCryptfs: stacked cryptographic filesystem for Linux. 38 - docs on eCryptfs: stacked cryptographic filesystem for Linux.
37ext2.txt 39ext2.txt
diff --git a/Documentation/filesystems/dnotify.txt b/Documentation/filesystems/dnotify.txt
new file mode 100644
index 000000000000..9f5d338ddbb8
--- /dev/null
+++ b/Documentation/filesystems/dnotify.txt
@@ -0,0 +1,99 @@
1 Linux Directory Notification
2 ============================
3
4 Stephen Rothwell <sfr@canb.auug.org.au>
5
6The intention of directory notification is to allow user applications
7to be notified when a directory, or any of the files in it, are changed.
8The basic mechanism involves the application registering for notification
9on a directory using a fcntl(2) call and the notifications themselves
10being delivered using signals.
11
12The application decides which "events" it wants to be notified about.
13The currently defined events are:
14
15 DN_ACCESS A file in the directory was accessed (read)
16 DN_MODIFY A file in the directory was modified (write,truncate)
17 DN_CREATE A file was created in the directory
18 DN_DELETE A file was unlinked from directory
19 DN_RENAME A file in the directory was renamed
20 DN_ATTRIB A file in the directory had its attributes
21 changed (chmod,chown)
22
23Usually, the application must reregister after each notification, but
24if DN_MULTISHOT is or'ed with the event mask, then the registration will
25remain until explicitly removed (by registering for no events).
26
27By default, SIGIO will be delivered to the process and no other useful
28information. However, if the F_SETSIG fcntl(2) call is used to let the
29kernel know which signal to deliver, a siginfo structure will be passed to
30the signal handler and the si_fd member of that structure will contain the
31file descriptor associated with the directory in which the event occurred.
32
33Preferably the application will choose one of the real time signals
34(SIGRTMIN + <n>) so that the notifications may be queued. This is
35especially important if DN_MULTISHOT is specified. Note that SIGRTMIN
36is often blocked, so it is better to use (at least) SIGRTMIN + 1.
37
38Implementation expectations (features and bugs :-))
39---------------------------
40
41The notification should work for any local access to files even if the
42actual file system is on a remote server. This implies that remote
43access to files served by local user mode servers should be notified.
44Also, remote accesses to files served by a local kernel NFS server should
45be notified.
46
47In order to make the impact on the file system code as small as possible,
48the problem of hard links to files has been ignored. So if a file (x)
49exists in two directories (a and b) then a change to the file using the
50name "a/x" should be notified to a program expecting notifications on
51directory "a", but will not be notified to one expecting notifications on
52directory "b".
53
54Also, files that are unlinked, will still cause notifications in the
55last directory that they were linked to.
56
57Configuration
58-------------
59
60Dnotify is controlled via the CONFIG_DNOTIFY configuration option. When
61disabled, fcntl(fd, F_NOTIFY, ...) will return -EINVAL.
62
63Example
64-------
65
66 #define _GNU_SOURCE /* needed to get the defines */
67 #include <fcntl.h> /* in glibc 2.2 this has the needed
68 values defined */
69 #include <signal.h>
70 #include <stdio.h>
71 #include <unistd.h>
72
73 static volatile int event_fd;
74
75 static void handler(int sig, siginfo_t *si, void *data)
76 {
77 event_fd = si->si_fd;
78 }
79
80 int main(void)
81 {
82 struct sigaction act;
83 int fd;
84
85 act.sa_sigaction = handler;
86 sigemptyset(&act.sa_mask);
87 act.sa_flags = SA_SIGINFO;
88 sigaction(SIGRTMIN + 1, &act, NULL);
89
90 fd = open(".", O_RDONLY);
91 fcntl(fd, F_SETSIG, SIGRTMIN + 1);
92 fcntl(fd, F_NOTIFY, DN_MODIFY|DN_CREATE|DN_MULTISHOT);
93 /* we will now be notified if any of the files
94 in "." is modified or new files are created */
95 while (1) {
96 pause();
97 printf("Got event on fd=%d\n", event_fd);
98 }
99 }