1 | #![deny (missing_docs)] |
2 | |
3 | |
4 | //! # inotify bindings for the Rust programming language |
5 | //! |
6 | //! Please note that these are direct, low-level bindings to C functions that |
7 | //! form the inotify C API. Unless you have a specific reason to use this crate, |
8 | //! [inotify-rs], which is an idiomatic wrapper, is a much better choice. |
9 | //! |
10 | //! ## Usage |
11 | //! |
12 | //! In general, inotify usage follows the following pattern: |
13 | //! |
14 | //! 1. Create an inotify instance using [`inotify_init`] or [`inotify_init1`]. |
15 | //! 2. Manage watches with [`inotify_add_watch`] and [`inotify_rm_watch`]. |
16 | //! 3. Read event using [`read`]. |
17 | //! 4. Close the inotify instance using [`close`], once you're done. |
18 | //! |
19 | //! Please refer to the [inotify man page] and the rest of this documentation |
20 | //! for full details. |
21 | //! |
22 | //! [inotify-rs]: https://crates.io/crates/inotify |
23 | //! [`inotify_init`]: fn.inotify_init.html |
24 | //! [`inotify_init1`]: fn.inotify_init1.html |
25 | //! [`inotify_add_watch`]: fn.inotify_add_watch.html |
26 | //! [`inotify_rm_watch`]: fn.inotify_rm_watch.html |
27 | //! [`read`]: fn.read.html |
28 | //! [`close`]: fn.close.html |
29 | //! [inotify man page]: http://man7.org/linux/man-pages/man7/inotify.7.html |
30 | |
31 | |
32 | extern crate libc; |
33 | |
34 | |
35 | use libc::{ |
36 | c_char, |
37 | c_int, |
38 | }; |
39 | |
40 | |
41 | /// Set the `FD_CLOEXEC` flag for an inotify instance |
42 | /// |
43 | /// Can be passed to [`inotify_init1`] to set the `FD_CLOEXEC` flag for the |
44 | /// inotify instance. This changes the behavior of file descriptor when |
45 | /// [execve(2)]'d. From [fcntl(2)]: |
46 | /// |
47 | /// > If the FD_CLOEXEC bit is 0, the file descriptor will |
48 | /// > remain open across an [execve(2)], otherwise it will be |
49 | /// > closed. |
50 | /// |
51 | /// See [open(2)] and [fcntl(2)] for details. |
52 | /// |
53 | /// [`inotify_init1`]: fn.inotify_init1.html |
54 | /// [execve(2)]: http://man7.org/linux/man-pages/man2/execve.2.html |
55 | /// [open(2)]: http://man7.org/linux/man-pages/man2/open.2.html |
56 | /// [fcntl(2)]: http://man7.org/linux/man-pages/man2/fcntl.2.html |
57 | pub const IN_CLOEXEC: c_int = libc::O_CLOEXEC; |
58 | |
59 | /// Set an inotify instance to non-blocking mode |
60 | /// |
61 | /// Can be passed to [`inotify_init1`] to set the `O_NONBLOCK` flag for the |
62 | /// inotify instance. |
63 | /// |
64 | /// See [open(2)] for details. |
65 | /// |
66 | /// [`inotify_init1`]: fn.inotify_init1.html |
67 | /// [open(2)]: http://man7.org/linux/man-pages/man2/open.2.html |
68 | pub const IN_NONBLOCK: c_int = libc::O_NONBLOCK; |
69 | |
70 | /// Event: File was accessed |
71 | /// |
72 | /// This constant can be passed to [`inotify_add_watch`], to register interest |
73 | /// in this type of event, or it can be used to check (via [`inotify_event`]'s |
74 | /// [`mask`] field) whether an event is of this type. |
75 | /// |
76 | /// When monitoring a directory, this event will be triggered only for files |
77 | /// within the directory. |
78 | /// |
79 | /// See [man page] for additional details. |
80 | /// |
81 | /// [`inotify_add_watch`]: fn.inotify_add_watch.html |
82 | /// [`inotify_event`]: struct.inotify_event.html |
83 | /// [`mask`]: struct.inotify_event.html#structfield.mask |
84 | /// [man page]: http://man7.org/linux/man-pages/man7/inotify.7.html |
85 | pub const IN_ACCESS: u32 = 0x00000001; |
86 | |
87 | /// Event: File was modified |
88 | /// |
89 | /// This constant can be passed to [`inotify_add_watch`], to register interest |
90 | /// in this type of event, or it can be used to check (via [`inotify_event`]'s |
91 | /// [`mask`] field) whether an event is of this type. |
92 | /// |
93 | /// When monitoring a directory, this event will be triggered only for files |
94 | /// within the directory. |
95 | /// |
96 | /// See [man page] for additional details. |
97 | /// |
98 | /// [`inotify_add_watch`]: fn.inotify_add_watch.html |
99 | /// [`inotify_event`]: struct.inotify_event.html |
100 | /// [`mask`]: struct.inotify_event.html#structfield.mask |
101 | /// [man page]: http://man7.org/linux/man-pages/man7/inotify.7.html |
102 | pub const IN_MODIFY: u32 = 0x00000002; |
103 | |
104 | /// Event: Metadata was changed |
105 | /// |
106 | /// This can include e.g. |
107 | /// |
108 | /// - permissions, see [chmod(2)]; |
109 | /// - timestamps, see [utimensat(2)]; |
110 | /// - extended attributes, see [setxattr(2)]; |
111 | /// - link count, see [link(2)] and [unlink(2)]; |
112 | /// - user/group, see [chown(2)]. |
113 | /// |
114 | /// This constant can be passed to [`inotify_add_watch`], to register interest |
115 | /// in this type of event, or it can be used to check (via [`inotify_event`]'s |
116 | /// [`mask`] field) whether an event is of this type. |
117 | /// |
118 | /// When monitoring a directory, this event can be triggered for both for the |
119 | /// directory itself and the files within. |
120 | /// |
121 | /// See [man page] for additional details. |
122 | /// |
123 | /// [chmod(2)]: http://man7.org/linux/man-pages/man2/chmod.2.html |
124 | /// [utimensat(2)]: http://man7.org/linux/man-pages/man2/utimensat.2.html |
125 | /// [setxattr(2)]: http://man7.org/linux/man-pages/man2/fsetxattr.2.html |
126 | /// [link(2)]: http://man7.org/linux/man-pages/man2/link.2.html |
127 | /// [unlink(2)]: http://man7.org/linux/man-pages/man2/unlink.2.html |
128 | /// [chown(2)]: http://man7.org/linux/man-pages/man2/chown.2.html |
129 | /// [`inotify_add_watch`]: fn.inotify_add_watch.html |
130 | /// [`inotify_event`]: struct.inotify_event.html |
131 | /// [`mask`]: struct.inotify_event.html#structfield.mask |
132 | /// [man page]: http://man7.org/linux/man-pages/man7/inotify.7.html |
133 | pub const IN_ATTRIB: u32 = 0x00000004; |
134 | |
135 | /// Event: Writable file was closed |
136 | /// |
137 | /// This constant can be passed to [`inotify_add_watch`], to register interest |
138 | /// in this type of event, or it can be used to check (via [`inotify_event`]'s |
139 | /// [`mask`] field) whether an event is of this type. |
140 | /// |
141 | /// When monitoring a directory, this event will be triggered only for files |
142 | /// within the directory. |
143 | /// |
144 | /// See [man page] for additional details. |
145 | /// |
146 | /// [`inotify_add_watch`]: fn.inotify_add_watch.html |
147 | /// [`inotify_event`]: struct.inotify_event.html |
148 | /// [`mask`]: struct.inotify_event.html#structfield.mask |
149 | /// [man page]: http://man7.org/linux/man-pages/man7/inotify.7.html |
150 | pub const IN_CLOSE_WRITE: u32 = 0x00000008; |
151 | |
152 | /// Event: Non-writable file or directory was closed |
153 | /// |
154 | /// This constant can be passed to [`inotify_add_watch`], to register interest |
155 | /// in this type of event, or it can be used to check (via [`inotify_event`]'s |
156 | /// [`mask`] field) whether an event is of this type. |
157 | /// |
158 | /// When monitoring a directory, this event can be triggered for both for the |
159 | /// directory itself and the files within. |
160 | /// |
161 | /// See [man page] for additional details. |
162 | /// |
163 | /// [`inotify_add_watch`]: fn.inotify_add_watch.html |
164 | /// [`inotify_event`]: struct.inotify_event.html |
165 | /// [`mask`]: struct.inotify_event.html#structfield.mask |
166 | /// [man page]: http://man7.org/linux/man-pages/man7/inotify.7.html |
167 | pub const IN_CLOSE_NOWRITE: u32 = 0x00000010; |
168 | |
169 | /// Event: File or directory was opened |
170 | /// |
171 | /// This constant can be passed to [`inotify_add_watch`], to register interest |
172 | /// in this type of event, or it can be used to check (via [`inotify_event`]'s |
173 | /// [`mask`] field) whether an event is of this type. |
174 | /// |
175 | /// When monitoring a directory, this event can be triggered for both for the |
176 | /// directory itself and the files within. |
177 | /// |
178 | /// See [man page] for additional details. |
179 | /// |
180 | /// [`inotify_add_watch`]: fn.inotify_add_watch.html |
181 | /// [`inotify_event`]: struct.inotify_event.html |
182 | /// [`mask`]: struct.inotify_event.html#structfield.mask |
183 | /// [man page]: http://man7.org/linux/man-pages/man7/inotify.7.html |
184 | pub const IN_OPEN: u32 = 0x00000020; |
185 | |
186 | /// Event: File or directory was moved out of watched directory |
187 | /// |
188 | /// This constant can be passed to [`inotify_add_watch`], to register interest |
189 | /// in this type of event, or it can be used to check (via [`inotify_event`]'s |
190 | /// [`mask`] field) whether an event is of this type. |
191 | /// |
192 | /// When monitoring a directory, this event will be triggered only for files |
193 | /// within the directory. |
194 | /// |
195 | /// [`inotify_add_watch`]: fn.inotify_add_watch.html |
196 | /// [`inotify_event`]: struct.inotify_event.html |
197 | /// [`mask`]: struct.inotify_event.html#structfield.mask |
198 | /// [man page]: http://man7.org/linux/man-pages/man7/inotify.7.html |
199 | pub const IN_MOVED_FROM: u32 = 0x00000040; |
200 | |
201 | /// Event: File or directory was moved into watched directory |
202 | /// |
203 | /// This constant can be passed to [`inotify_add_watch`], to register interest |
204 | /// in this type of event, or it can be used to check (via [`inotify_event`]'s |
205 | /// [`mask`] field) whether an event is of this type. |
206 | /// |
207 | /// When monitoring a directory, this event will be triggered only for files |
208 | /// within the directory. |
209 | /// |
210 | /// See [man page] for additional details. |
211 | /// |
212 | /// [`inotify_add_watch`]: fn.inotify_add_watch.html |
213 | /// [`inotify_event`]: struct.inotify_event.html |
214 | /// [`mask`]: struct.inotify_event.html#structfield.mask |
215 | /// [man page]: http://man7.org/linux/man-pages/man7/inotify.7.html |
216 | pub const IN_MOVED_TO: u32 = 0x00000080; |
217 | |
218 | /// Event: File or directory was created in watched directory |
219 | /// |
220 | /// This may also include hard links, symlinks, and UNIX sockets. |
221 | /// |
222 | /// This constant can be passed to [`inotify_add_watch`], to register interest |
223 | /// in this type of event, or it can be used to check (via [`inotify_event`]'s |
224 | /// [`mask`] field) whether an event is of this type. |
225 | /// |
226 | /// When monitoring a directory, this event will be triggered only for files |
227 | /// within the directory. |
228 | /// |
229 | /// See [man page] for additional details. |
230 | /// |
231 | /// [`inotify_add_watch`]: fn.inotify_add_watch.html |
232 | /// [`inotify_event`]: struct.inotify_event.html |
233 | /// [`mask`]: struct.inotify_event.html#structfield.mask |
234 | /// [man page]: http://man7.org/linux/man-pages/man7/inotify.7.html |
235 | pub const IN_CREATE: u32 = 0x00000100; |
236 | |
237 | /// Event: File or directory in watched directory was deleted |
238 | /// |
239 | /// This may also include hard links, symlinks, and UNIX sockets. |
240 | /// |
241 | /// This constant can be passed to [`inotify_add_watch`], to register interest |
242 | /// in this type of event, or it can be used to check (via [`inotify_event`]'s |
243 | /// [`mask`] field) whether an event is of this type. |
244 | /// |
245 | /// When monitoring a directory, this event will be triggered only for files |
246 | /// within the directory. |
247 | /// |
248 | /// See [man page] for additional details. |
249 | /// |
250 | /// [`inotify_add_watch`]: fn.inotify_add_watch.html |
251 | /// [`inotify_event`]: struct.inotify_event.html |
252 | /// [`mask`]: struct.inotify_event.html#structfield.mask |
253 | /// [man page]: http://man7.org/linux/man-pages/man7/inotify.7.html |
254 | pub const IN_DELETE: u32 = 0x00000200; |
255 | |
256 | /// Event: Watched file or directory was deleted |
257 | /// |
258 | /// This may also occur if the object is moved to another filesystem, since |
259 | /// [mv(1)] in effect copies the file to the other filesystem and then deletes |
260 | /// it from the original. |
261 | /// |
262 | /// An IN_IGNORED event will subsequently be generated. |
263 | /// |
264 | /// This constant can be passed to [`inotify_add_watch`], to register interest |
265 | /// in this type of event, or it can be used to check (via [`inotify_event`]'s |
266 | /// [`mask`] field) whether an event is of this type. |
267 | /// |
268 | /// See [man page] for additional details. |
269 | /// |
270 | /// [mv(1)]: http://man7.org/linux/man-pages/man1/mv.1.html |
271 | /// [`inotify_add_watch`]: fn.inotify_add_watch.html |
272 | /// [`inotify_event`]: struct.inotify_event.html |
273 | /// [`mask`]: struct.inotify_event.html#structfield.mask |
274 | /// [man page]: http://man7.org/linux/man-pages/man7/inotify.7.html |
275 | pub const IN_DELETE_SELF: u32 = 0x00000400; |
276 | |
277 | /// Event: Watched file or directory was moved |
278 | /// |
279 | /// This constant can be passed to [`inotify_add_watch`], to register interest |
280 | /// in this type of event, or it can be used to check (via [`inotify_event`]'s |
281 | /// [`mask`] field) whether an event is of this type. |
282 | /// |
283 | /// See [man page] for additional details. |
284 | /// |
285 | /// [`inotify_add_watch`]: fn.inotify_add_watch.html |
286 | /// [`inotify_event`]: struct.inotify_event.html |
287 | /// [`mask`]: struct.inotify_event.html#structfield.mask |
288 | /// [man page]: http://man7.org/linux/man-pages/man7/inotify.7.html |
289 | pub const IN_MOVE_SELF: u32 = 0x00000800; |
290 | |
291 | /// Event: File or directory within watched directory was moved |
292 | /// |
293 | /// This is a combination of [`IN_MOVED_FROM`] and [`IN_MOVED_TO`]. |
294 | /// |
295 | /// This constant can be passed to [`inotify_add_watch`], to register interest |
296 | /// in this type of event, or it can be used to check (via [`inotify_event`]'s |
297 | /// [`mask`] field) whether an event is of this type. |
298 | /// |
299 | /// See [man page] for additional details. |
300 | /// |
301 | /// [`IN_MOVED_FROM`]: constant.IN_MOVED_FROM.html |
302 | /// [`IN_MOVED_TO`]: constant.IN_MOVED_TO.html |
303 | /// [`inotify_add_watch`]: fn.inotify_add_watch.html |
304 | /// [`inotify_event`]: struct.inotify_event.html |
305 | /// [`mask`]: struct.inotify_event.html#structfield.mask |
306 | /// [man page]: http://man7.org/linux/man-pages/man7/inotify.7.html |
307 | pub const IN_MOVE: u32 = IN_MOVED_FROM | IN_MOVED_TO; |
308 | |
309 | /// Event: File was closed |
310 | /// |
311 | /// This is a combination of [`IN_CLOSE_WRITE`] and [`IN_CLOSE_NOWRITE`]. |
312 | /// |
313 | /// This constant can be passed to [`inotify_add_watch`], to register interest |
314 | /// in this type of event, or it can be used to check (via [`inotify_event`]'s |
315 | /// [`mask`] field) whether an event is of this type. |
316 | /// |
317 | /// See [man page] for additional details. |
318 | /// |
319 | /// [`IN_CLOSE_WRITE`]: constant.IN_CLOSE_WRITE.html |
320 | /// [`IN_CLOSE_NOWRITE`]: constant.IN_CLOSE_NOWRITE.html |
321 | /// [`inotify_add_watch`]: fn.inotify_add_watch.html |
322 | /// [`inotify_event`]: struct.inotify_event.html |
323 | /// [`mask`]: struct.inotify_event.html#structfield.mask |
324 | /// [man page]: http://man7.org/linux/man-pages/man7/inotify.7.html |
325 | pub const IN_CLOSE: u32 = IN_CLOSE_WRITE | IN_CLOSE_NOWRITE; |
326 | |
327 | /// Event: Any event occured |
328 | /// |
329 | /// This is a combination of all the other event constants: |
330 | /// |
331 | /// - [`IN_ACCESS`] |
332 | /// - [`IN_ATTRIB`] |
333 | /// - [`IN_CLOSE_WRITE`] |
334 | /// - [`IN_CLOSE_NOWRITE`] |
335 | /// - [`IN_MODIFY`] |
336 | /// - [`IN_CREATE`] |
337 | /// - [`IN_DELETE`] |
338 | /// - [`IN_DELETE_SELF`] |
339 | /// - [`IN_MODIFY`] |
340 | /// - [`IN_MOVE_SELF`] |
341 | /// - [`IN_MOVED_FROM`] |
342 | /// - [`IN_MOVED_TO`] |
343 | /// - [`IN_OPEN`] |
344 | /// |
345 | /// This constant can be passed to [`inotify_add_watch`], to register interest |
346 | /// in any type of event. |
347 | /// |
348 | /// See [man page] for additional details. |
349 | /// |
350 | /// [`IN_ACCESS`]: constant.IN_ACCESS.html |
351 | /// [`IN_ATTRIB`]: constant.IN_ATTRIB.html |
352 | /// [`IN_CLOSE_WRITE`]: constant.IN_CLOSE_WRITE.html |
353 | /// [`IN_CLOSE_NOWRITE`]: constant.IN_CLOSE_NOWRITE.html |
354 | /// [`IN_MODIFY`]: constant.IN_MODIFY.html |
355 | /// [`IN_CREATE`]: constant.IN_CREATE.html |
356 | /// [`IN_DELETE`]: constant.IN_DELETE.html |
357 | /// [`IN_DELETE_SELF`]: constant.IN_DELETE_SELF.html |
358 | /// [`IN_MODIFY`]: constant.IN_MODIFY.html |
359 | /// [`IN_MOVE_SELF`]: constant.IN_MOVE_SELF.html |
360 | /// [`IN_MOVED_FROM`]: constant.IN_MOVED_FROM.html |
361 | /// [`IN_MOVED_TO`]: constant.IN_MOVED_TO.html |
362 | /// [`IN_OPEN`]: constant.IN_OPEN.html |
363 | /// [`inotify_add_watch`]: fn.inotify_add_watch.html |
364 | /// [man page]: http://man7.org/linux/man-pages/man7/inotify.7.html |
365 | pub const IN_ALL_EVENTS: u32 = |
366 | IN_ACCESS | IN_MODIFY | IN_ATTRIB | IN_CLOSE_WRITE | IN_CLOSE_NOWRITE |
367 | | IN_OPEN | IN_MOVED_FROM | IN_MOVED_TO | IN_CREATE | IN_DELETE |
368 | | IN_DELETE_SELF | IN_MOVE_SELF; |
369 | |
370 | /// Only watch path, if it is a directory |
371 | /// |
372 | /// This bit can be set in [`inotify_add_watch`]'s `mask` parameter, to |
373 | /// configure the watch. |
374 | /// |
375 | /// See [man page] for additional details. |
376 | /// |
377 | /// [`inotify_add_watch`]: fn.inotify_add_watch.html |
378 | /// [man page]: http://man7.org/linux/man-pages/man7/inotify.7.html |
379 | pub const IN_ONLYDIR: u32 = 0x01000000; |
380 | |
381 | /// Don't dereference path, if it is a symbolic link |
382 | /// |
383 | /// This bit can be set in [`inotify_add_watch`]'s `mask` parameter, to |
384 | /// configure the watch. |
385 | /// |
386 | /// See [man page] for additional details. |
387 | /// |
388 | /// [`inotify_add_watch`]: fn.inotify_add_watch.html |
389 | /// [man page]: http://man7.org/linux/man-pages/man7/inotify.7.html |
390 | pub const IN_DONT_FOLLOW: u32 = 0x02000000; |
391 | |
392 | /// Ignore events for children, that have been unlinked from watched directory |
393 | /// |
394 | /// This bit can be set in [`inotify_add_watch`]'s `mask` parameter, to |
395 | /// configure the watch. |
396 | /// |
397 | /// See [man page] for additional details. |
398 | /// |
399 | /// [`inotify_add_watch`]: fn.inotify_add_watch.html |
400 | /// [man page]: http://man7.org/linux/man-pages/man7/inotify.7.html |
401 | pub const IN_EXCL_UNLINK: u32 = 0x04000000; |
402 | |
403 | /// Update existing watch mask, instead of replacing it |
404 | /// |
405 | /// This bit can be set in [`inotify_add_watch`]'s `mask` parameter, to |
406 | /// configure the watch. |
407 | /// |
408 | /// See [man page] for additional details. |
409 | /// |
410 | /// [`inotify_add_watch`]: fn.inotify_add_watch.html |
411 | /// [man page]: http://man7.org/linux/man-pages/man7/inotify.7.html |
412 | pub const IN_MASK_ADD: u32 = 0x20000000; |
413 | |
414 | /// Remove watch after one event |
415 | /// |
416 | /// This bit can be set in [`inotify_add_watch`]'s `mask` parameter, to |
417 | /// configure the watch. |
418 | /// |
419 | /// See [man page] for additional details. |
420 | /// |
421 | /// [`inotify_add_watch`]: fn.inotify_add_watch.html |
422 | /// [man page]: http://man7.org/linux/man-pages/man7/inotify.7.html |
423 | pub const IN_ONESHOT: u32 = 0x80000000; |
424 | |
425 | /// Indicates that the subject of an event is a directory |
426 | /// |
427 | /// This constant can be used to check against the [`mask`] field in |
428 | /// [`inotify_event`]. |
429 | /// |
430 | /// See [man page] for additional details. |
431 | /// |
432 | /// [`mask`]: struct.inotify_event.html#structfield.mask |
433 | /// [`inotify_event`]: struct.inotify_event.html |
434 | /// [man page]: http://man7.org/linux/man-pages/man7/inotify.7.html |
435 | pub const IN_ISDIR: u32 = 0x40000000; |
436 | |
437 | /// Indicates that file system containing a watched object has been unmounted |
438 | /// |
439 | /// An [`IN_IGNORED`] event will be generated subsequently. |
440 | /// |
441 | /// This constant can be used to check against the [`mask`] field in |
442 | /// [`inotify_event`]. |
443 | /// |
444 | /// See [man page] for additional details. |
445 | /// |
446 | /// [`IN_IGNORED`]: constant.IN_IGNORED.html |
447 | /// [`mask`]: struct.inotify_event.html#structfield.mask |
448 | /// [`inotify_event`]: struct.inotify_event.html |
449 | /// [man page]: http://man7.org/linux/man-pages/man7/inotify.7.html |
450 | pub const IN_UNMOUNT: u32 = 0x00002000; |
451 | |
452 | /// Indicates that the event queue has overflowed |
453 | /// |
454 | /// This constant can be used to check against the [`mask`] field in |
455 | /// [`inotify_event`]. |
456 | /// |
457 | /// See [man page] for additional details. |
458 | /// |
459 | /// [`mask`]: struct.inotify_event.html#structfield.mask |
460 | /// [`inotify_event`]: struct.inotify_event.html |
461 | /// [man page]: http://man7.org/linux/man-pages/man7/inotify.7.html |
462 | pub const IN_Q_OVERFLOW: u32 = 0x00004000; |
463 | |
464 | /// Indicates that a file system watch was removed |
465 | /// |
466 | /// This can occur as a result of [`inotify_rm_watch`], because a watched item |
467 | /// was deleted, the containing filesystem was unmounted, or after a |
468 | /// [`IN_ONESHOT`] watch is complete. |
469 | /// |
470 | /// This constant can be used to check against the [`mask`] field in |
471 | /// [`inotify_event`]. |
472 | /// |
473 | /// See [man page] for additional details. |
474 | /// |
475 | /// [`inotify_rm_watch`]: fn.inotify_rm_watch.html |
476 | /// [`IN_ONESHOT`]: constant.IN_ONESHOT.html |
477 | /// [`mask`]: struct.inotify_event.html#structfield.mask |
478 | /// [`inotify_event`]: struct.inotify_event.html |
479 | /// [man page]: http://man7.org/linux/man-pages/man7/inotify.7.html |
480 | pub const IN_IGNORED: u32 = 0x00008000; |
481 | |
482 | |
483 | /// Describes a file system event |
484 | /// |
485 | /// From [inotify(7)]: |
486 | /// |
487 | /// > To determine what events have occurred, an application [read(2)]s |
488 | /// > from the inotify file descriptor. If no events have so far occurred, |
489 | /// > then, assuming a blocking file descriptor, [read(2)] will block until |
490 | /// > at least one event occurs (unless interrupted by a signal, in which |
491 | /// > case the call fails with the error EINTR; see [signal(7)]). |
492 | /// > |
493 | /// > Each successful [read(2)] returns a buffer containing one or more of |
494 | /// > this structure. |
495 | /// |
496 | /// [inotify(7)]: http://man7.org/linux/man-pages/man7/inotify.7.html |
497 | /// [read(2)]: http://man7.org/linux/man-pages/man2/read.2.html |
498 | /// [signal(7)]: http://man7.org/linux/man-pages/man7/signal.7.html |
499 | #[allow (non_camel_case_types)] |
500 | #[derive (Clone, Copy, Debug)] |
501 | #[repr (C)] |
502 | pub struct inotify_event { |
503 | /// Identifies the watch for which this event occurs |
504 | /// |
505 | /// This is one of the watch descriptors returned by a previous call to |
506 | /// [`inotify_add_watch()`]. |
507 | /// |
508 | /// [`inotify_add_watch()`]: fn.inotify_add_watch.html |
509 | pub wd: c_int, |
510 | |
511 | /// Describes the type file system event |
512 | /// |
513 | /// One of the following bits will be set, to identify the type of event: |
514 | /// |
515 | /// - [`IN_ACCESS`] |
516 | /// - [`IN_ATTRIB`] |
517 | /// - [`IN_CLOSE_NOWRITE`] |
518 | /// - [`IN_CLOSE_WRITE`] |
519 | /// - [`IN_CREATE`] |
520 | /// - [`IN_DELETE`] |
521 | /// - [`IN_DELETE_SELF`] |
522 | /// - [`IN_IGNORED`] |
523 | /// - [`IN_MODIFY`] |
524 | /// - [`IN_MOVED_FROM`] |
525 | /// - [`IN_MOVED_TO`] |
526 | /// - [`IN_MOVE_SELF`] |
527 | /// - [`IN_OPEN`] |
528 | /// - [`IN_Q_OVERFLOW`] |
529 | /// - [`IN_UNMOUNT`] |
530 | /// |
531 | /// Some constants cover multiple bits, and can be used for a less precise |
532 | /// check of the event type: |
533 | /// |
534 | /// - [`IN_CLOSE`] |
535 | /// - [`IN_MOVE`] |
536 | /// |
537 | /// In addition, the [`IN_ISDIR`] bit can be set. |
538 | /// |
539 | /// [`IN_ACCESS`]: constant.IN_ACCESS.html |
540 | /// [`IN_ATTRIB`]: constant.IN_ATTRIB.html |
541 | /// [`IN_CLOSE`]: constant.IN_CLOSE.html |
542 | /// [`IN_CLOSE_NOWRITE`]: constant.IN_CLOSE_NOWRITE.html |
543 | /// [`IN_CLOSE_WRITE`]: constant.IN_CLOSE_WRITE.html |
544 | /// [`IN_CREATE`]: constant.IN_CREATE.html |
545 | /// [`IN_DELETE`]: constant.IN_DELETE.html |
546 | /// [`IN_DELETE_SELF`]: constant.IN_DELETE_SELF.html |
547 | /// [`IN_IGNORED`]: constant.IN_IGNORED.html |
548 | /// [`IN_ISDIR`]: constant.IN_ISDIR.html |
549 | /// [`IN_MODIFY`]: constant.IN_MODIFY.html |
550 | /// [`IN_MOVE`]: constant.IN_MOVE.html |
551 | /// [`IN_MOVED_FROM`]: constant.IN_MOVED_FROM.html |
552 | /// [`IN_MOVED_TO`]: constant.IN_MOVED_TO.html |
553 | /// [`IN_MOVE_SELF`]: constant.IN_MOVE_SELF.html |
554 | /// [`IN_OPEN`]: constant.IN_OPEN.html |
555 | /// [`IN_Q_OVERFLOW`]: constant.IN_Q_OVERFLOW.html |
556 | /// [`IN_UNMOUNT`]: constant.IN_UNMOUNT.html |
557 | pub mask: u32, |
558 | |
559 | /// A number that connects related events |
560 | /// |
561 | /// Currently used only for rename events. A related pair of |
562 | /// [`IN_MOVED_FROM`] and [`IN_MOVED_TO`] events will have the same, |
563 | /// non-zero, cookie. For all other events, cookie is 0. |
564 | /// |
565 | /// [`IN_MOVED_FROM`]: constant.IN_MOVED_FROM.html |
566 | /// [`IN_MOVED_TO`]: constant.IN_MOVED_TO.html |
567 | pub cookie: u32, |
568 | |
569 | /// The length of `name` |
570 | /// |
571 | /// Used to determine the size of this structure. When `name` |
572 | /// isn't present (`name` is only present when an event occurs |
573 | /// for a file inside a watched directory), it is 0. When `name` |
574 | /// *is* present, it counts all of `name`'s bytes, including `\0`. |
575 | /// |
576 | /// > The `name` field is present only when an event is returned for |
577 | /// > a file inside a watched directory; it identifies the file |
578 | /// > pathname relative to the watched directory. This pathname is |
579 | /// > null-terminated, and may include further null bytes ('\0') to |
580 | /// > align subsequent reads to a suitable address boundary. |
581 | /// |
582 | /// The `name` field has been ommited in this struct's definition. |
583 | pub len: u32, |
584 | } |
585 | |
586 | |
587 | extern { |
588 | /// Creates an inotify instance |
589 | /// |
590 | /// If you need more flexibility, consider using [`inotify_init1`] instead. |
591 | /// |
592 | /// Returns `-1`, if an error occured, or an inotify file descriptor |
593 | /// otherwise. |
594 | /// |
595 | /// Please refer to the [man page] for additional details. |
596 | /// |
597 | /// [`inotify_init1`]: fn.inotify_init1.html |
598 | /// [man page]: http://man7.org/linux/man-pages/man2/inotify_init.2.html |
599 | pub fn inotify_init() -> c_int; |
600 | |
601 | /// Creates an inotify instance |
602 | /// |
603 | /// Takes an argument to configure the new inotify instance. The following |
604 | /// flags can be set: |
605 | /// |
606 | /// - [`IN_CLOEXEC`] |
607 | /// - [`IN_NONBLOCK`] |
608 | /// |
609 | /// Returns `-1`, if an error occured, or an inotify file descriptor |
610 | /// otherwise. |
611 | /// |
612 | /// Please refer to the [man page] for additional details. |
613 | /// |
614 | /// [`IN_CLOEXEC`]: constant.IN_CLOEXEC.html |
615 | /// [`IN_NONBLOCK`]: constant.IN_NONBLOCK.html |
616 | /// [man page]: http://man7.org/linux/man-pages/man2/inotify_init1.2.html |
617 | pub fn inotify_init1(flags: c_int) -> c_int; |
618 | |
619 | /// Adds or updates an inotify watch |
620 | /// |
621 | /// Adds an item to the watch list of an inotify instance, or modifies an |
622 | /// item on that list. This function takes the following arguments: |
623 | /// |
624 | /// - `fd` is the file descriptor of the inotify instance (created by |
625 | /// [`inotify_init`] or [`inotify_init1`]) |
626 | /// - `pathname` is the path of the file or directory watch |
627 | /// - `mask` defines the behavior of this function and configures the watch |
628 | /// |
629 | /// The following flags in `mask` control the type of events to watch for: |
630 | /// |
631 | /// - [`IN_ACCESS`] |
632 | /// - [`IN_ATTRIB`] |
633 | /// - [`IN_CLOSE_NOWRITE`] |
634 | /// - [`IN_CLOSE_WRITE`] |
635 | /// - [`IN_CREATE`] |
636 | /// - [`IN_DELETE`] |
637 | /// - [`IN_DELETE_SELF`] |
638 | /// - [`IN_MODIFY`] |
639 | /// - [`IN_MOVED_FROM`] |
640 | /// - [`IN_MOVED_TO`] |
641 | /// - [`IN_MOVE_SELF`] |
642 | /// - [`IN_OPEN`] |
643 | /// |
644 | /// The following constants can be used as shortcuts to set multiple event |
645 | /// flags: |
646 | /// |
647 | /// - [`IN_ALL_EVENTS`] |
648 | /// - [`IN_CLOSE`] |
649 | /// - [`IN_MOVE`] |
650 | /// |
651 | /// In addition, the following flags can be set to control the behaviors of |
652 | /// the watch and this function: |
653 | /// |
654 | /// - [`IN_DONT_FOLLOW`] |
655 | /// - [`IN_EXCL_UNLINK`] |
656 | /// - [`IN_MASK_ADD`] |
657 | /// - [`IN_ONESHOT`] |
658 | /// - [`IN_ONLYDIR`] |
659 | /// |
660 | /// The function returns `-1` if an error occured. Otherwise, it returns a |
661 | /// watch descriptor that can be used to remove the watch using |
662 | /// [`inotify_rm_watch`] or identify the watch via [`inotify_event`]'s [wd`] |
663 | /// field. |
664 | /// |
665 | /// Please refer to the [man page] for additional details. |
666 | /// |
667 | /// [`inotify_init`]: fn.inotify_init.html |
668 | /// [`inotify_init1`]: fn.inotify_init1.html |
669 | /// [`IN_ACCESS`]: constant.IN_ACCESS.html |
670 | /// [`IN_ATTRIB`]: constant.IN_ATTRIB.html |
671 | /// [`IN_CLOSE_NOWRITE`]: constant.IN_CLOSE_NOWRITE.html |
672 | /// [`IN_CLOSE_WRITE`]: constant.IN_CLOSE_WRITE.html |
673 | /// [`IN_CREATE`]: constant.IN_CREATE.html |
674 | /// [`IN_DELETE`]: constant.IN_DELETE.html |
675 | /// [`IN_DELETE_SELF`]: constant.IN_DELETE_SELF.html |
676 | /// [`IN_MODIFY`]: constant.IN_MODIFY.html |
677 | /// [`IN_MOVED_FROM`]: constant.IN_MOVED_FROM.html |
678 | /// [`IN_MOVED_TO`]: constant.IN_MOVED_TO.html |
679 | /// [`IN_MOVE_SELF`]: constant.IN_MOVE_SELF.html |
680 | /// [`IN_OPEN`]: constant.IN_OPEN.html |
681 | /// [`IN_ALL_EVENTS`]: constant.IN_ALL_EVENTS.html |
682 | /// [`IN_CLOSE`]: constant.IN_CLOSE.html |
683 | /// [`IN_MOVE`]: constant.IN_MOVE.html |
684 | /// [`IN_DONT_FOLLOW`]: constant.IN_DONT_FOLLOW.html |
685 | /// [`IN_EXCL_UNLINK`]: constant.IN_EXCL_UNLINK.html |
686 | /// [`IN_MASK_ADD`]: constant.IN_MASK_ADD.html |
687 | /// [`IN_ONESHOT`]: constant.IN_ONESHOT.html |
688 | /// [`IN_ONLYDIR`]: constant.IN_ONLYDIR.html |
689 | /// [`inotify_rm_watch`]: fn.inotify_rm_watch.html |
690 | /// [`inotify_event`]: struct.inotify_event.html |
691 | /// [`wd`]: struct.inotify_event.html#structfield.wd |
692 | /// [man page]: http://man7.org/linux/man-pages/man2/inotify_add_watch.2.html |
693 | pub fn inotify_add_watch(fd: c_int, pathname: *const c_char, mask: u32) -> c_int; |
694 | |
695 | /// Removes an inotify watch |
696 | /// |
697 | /// Removes an item from the watch list of an inotify instance. The inotify |
698 | /// instance is identified by the `fd` argument. The watch is identified by |
699 | /// the `wd` argument. |
700 | /// |
701 | /// Returns `0` on success, `-1` on failure. |
702 | /// |
703 | /// Please refer to the [man page] for additional details. |
704 | /// |
705 | /// [man page]: http://man7.org/linux/man-pages/man2/inotify_rm_watch.2.html |
706 | pub fn inotify_rm_watch(fd: c_int, wd: c_int) -> c_int; |
707 | } |
708 | |
709 | pub use libc::{ |
710 | close, |
711 | read, |
712 | }; |
713 | |