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