ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/Linux-Inotify2/README
Revision: 1.2
Committed: Mon Aug 22 10:00:10 2005 UTC (18 years, 10 months ago) by root
Branch: MAIN
Changes since 1.1: +147 -194 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 NAME
2 root 1.2 Linux::Inotify2 - scalable directory/file change notification
3 root 1.1
4     SYNOPSIS
5 root 1.2 use Linux::Inotify2;
6 root 1.1
7     DESCRIPTION
8 root 1.2 The Linux::Inotify2 Class
9     This module implements an interface to the linux inotify file/directory
10     change notification sytem.
11    
12     It has a number of advantages over the Linux::Inotfy module:
13    
14     - it is portable (Linux::Inotify only works on x86)
15     - the equivalent of fullname works correctly
16     - it is better documented
17     - it has callback-style interface, which is better suited for
18     integration.
19    
20     my $inotify = new Linux::Inotify2
21     Create a new notify object and return it. A notify object is kind of
22     a container that stores watches on filesystem names and is
23     responsible for handling event data.
24    
25     On error, "undef" is returned and $! will be set accordingly. The
26     followign errors are documented:
27    
28     ENFILE The system limit on the total number of file descriptors has been reached.
29     EMFILE The user limit on the total number of inotify instances has been reached.
30     ENOMEM Insufficient kernel memory is available.
31    
32     $watch = $inotify2->watch ($name, $mask, $cb)
33     Add a new watcher to the given notifier. The watcher will create
34     events on the pathname $name as given in $mask, which can be any of
35     the following constants (all exported by default) ORed together:
36    
37     IN_ACCESS File was accessed
38     IN_MODIFY File was modified
39     IN_ATTRIB Metadata changed
40     IN_CLOSE_WRITE Writtable file was closed
41     IN_CLOSE_NOWRITE Unwrittable file closed
42     IN_OPEN File was opened
43     IN_MOVED_FROM File was moved from X
44     IN_MOVED_TO File was moved to Y
45     IN_CREATE Subfile was created
46     IN_DELETE Subfile was deleted
47     IN_DELETE_SELF Self was deleted
48     IN_ONESHOT only send event once
49     IN_ALL_EVENTS All of the above events
50    
51     IN_CLOSE Same as IN_CLOSE_WRITE | IN_CLOSE_NOWRITE
52     IN_MOVE Same as IN_MOVED_FROM | IN_MOVED_TO
53    
54     $cb is a perl code reference that is called for each event. It
55     receives a "Linux::Inotify2::Event" object.
56    
57     The returned $watch object is of class "Linux::Inotify2::Watch".
58    
59     On error, "undef" is returned and $! will be set accordingly. The
60     following errors are documented:
61    
62     EBADF The given file descriptor is not valid.
63     EINVAL The given event mask contains no legal events.
64     ENOMEM Insufficient kernel memory was available.
65     ENOSPC The user limit on the total number of inotify watches was reached or the kernel failed to allocate a needed resource.
66     EACCESS Read access to the given file is not permitted.
67    
68     Example, show when "/etc/passwd" gets accessed and/or modified once:
69    
70     $inotify->watch ("/etc/passwd", IN_ACCESS | IN_MODIFY, sub {
71     my $e = shift;
72     print "$e->{w}{name} was accessed\n" if $e->IN_ACCESS;
73     print "$e->{w}{name} was modified\n" if $e->IN_MODIFY;
74     print "$e->{w}{name} is no longer mounted\n" if $e->IN_UNMOUNT;
75     print "events for $e->{w}{name} have been lost\n" if $e->IN_Q_OVERFLOW;
76    
77     $e->w->cancel;
78     });
79    
80     $inotify2->fileno
81     Returns the fileno for this notify object. You are responsible for
82     calling the "poll" method when this fileno becomes ready for
83     reading.
84    
85     $count = $inotify2->poll
86     Reads events from the kernel and handles them. If the notify fileno
87     is blocking (the default), then this method waits for at least one
88     event. Otherwise it returns immediately when no pending events could
89     be read.
90    
91     Returns the count of events that have been handled.
92    
93     The Linux::Inotify2::Event Class
94     Objects of this class are handed as first argument to the watch
95     callback. It has the following members and methods:
96    
97     $event->w
98     $event->{w}
99     The watcher object for this event.
100    
101     $event->name
102     $event->{name}
103     The path of the filesystem object, relative to the watch name.
104    
105     $watch->fullname
106     Returns the "full" name of the relevant object, i.e. including the
107     "name" component of the watcher.
108    
109     $event->mask
110     $event->{mask}
111     The received event mask. In addition the the events described for
112     "$inotify-"watch>, the following flags (exported by default) can be
113     set:
114    
115     IN_ISDIR event occurred against dir
116    
117     IN_UNMOUNT Backing fs was unmounted
118     IN_Q_OVERFLOW Event queued overflowed
119     IN_IGNORED File was ignored (no more events will be delivered)
120    
121     $event->IN_xxx
122     Returns a boolean that returns true if the event mask matches the
123     event. All of the "IN_xxx" constants can be used as methods.
124    
125     $event->cookie
126     $event->{cookie}
127     The event cookie, can be used to synchronize two related events.
128    
129     The Linux::Inotify2::Watch Class
130     Watch objects are created by calling the "watch" method of a notifier.
131    
132     It has the following members and methods:
133    
134     $watch->name
135     $watch->{name}
136     The name as specified in the "watch" call. For the object itself, this
137     is the empty string. For directory watches, this is the name of the
138     entry without leading path elements.
139    
140     $watch->mask
141     $watch->{mask}
142     The mask as specified in the "watch" call.
143    
144     $watch->cb ([new callback])
145     $watch->{cb}
146     The callback as specified in the "watch" call. Can optionally be
147     changed.
148    
149     $watch->cancel
150     Cancels/removes this watch. Future events, even if already queued
151     queued, will not be handled and resources will be freed.
152 root 1.1
153     SEE ALSO
154 root 1.2 Linux::Inotify.
155 root 1.1
156     AUTHOR
157     Marc Lehmann <schmorp@schmorp.de>
158     http://home.schmorp.de/
159