Debian Codegraph @

debian/rust-vendor/inotify-sys/src/lib.rs

raw
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. Conflicts with [`IN_MASK_CREATE`].
407 ///
408 /// See [man page] for additional details.
409 ///
410 /// [`inotify_add_watch`]: fn.inotify_add_watch.html
411 /// [`IN_MASK_CREATE`]: constant.IN_MASK_CREATE.html
412 /// [man page]: http://man7.org/linux/man-pages/man7/inotify.7.html
413 pub const IN_MASK_ADD: u32 = 0x20000000;
414
415 /// Only create watches, errors on existing watches.
416 ///
417 /// This bit can be set in [`inotify_add_watch`]'s `mask` parameter, to
418 /// configure the watch. Conflicts with [`IN_MASK_ADD`].
419 ///
420 /// See [man page] for additional details.
421 ///
422 /// [`inotify_add_watch`]: fn.inotify_add_watch.html
423 /// [`IN_MASK_ADD`]: constant.IN_MASK_ADD.html
424 /// [man page]: http://man7.org/linux/man-pages/man7/inotify.7.html
425 pub const IN_MASK_CREATE: u32 = 0x10000000;
426
427 /// Remove watch after one event
428 ///
429 /// This bit can be set in [`inotify_add_watch`]'s `mask` parameter, to
430 /// configure the watch.
431 ///
432 /// See [man page] for additional details.
433 ///
434 /// [`inotify_add_watch`]: fn.inotify_add_watch.html
435 /// [man page]: http://man7.org/linux/man-pages/man7/inotify.7.html
436 pub const IN_ONESHOT: u32 = 0x80000000;
437
438 /// Indicates that the subject of an event is a directory
439 ///
440 /// This constant can be used to check against the [`mask`] field in
441 /// [`inotify_event`].
442 ///
443 /// See [man page] for additional details.
444 ///
445 /// [`mask`]: struct.inotify_event.html#structfield.mask
446 /// [`inotify_event`]: struct.inotify_event.html
447 /// [man page]: http://man7.org/linux/man-pages/man7/inotify.7.html
448 pub const IN_ISDIR: u32 = 0x40000000;
449
450 /// Indicates that file system containing a watched object has been unmounted
451 ///
452 /// An [`IN_IGNORED`] event will be generated subsequently.
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 /// [`IN_IGNORED`]: constant.IN_IGNORED.html
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
463 pub const IN_UNMOUNT: u32 = 0x00002000;
464
465 /// Indicates that the event queue has overflowed
466 ///
467 /// This constant can be used to check against the [`mask`] field in
468 /// [`inotify_event`].
469 ///
470 /// See [man page] for additional details.
471 ///
472 /// [`mask`]: struct.inotify_event.html#structfield.mask
473 /// [`inotify_event`]: struct.inotify_event.html
474 /// [man page]: http://man7.org/linux/man-pages/man7/inotify.7.html
475 pub const IN_Q_OVERFLOW: u32 = 0x00004000;
476
477 /// Indicates that a file system watch was removed
478 ///
479 /// This can occur as a result of [`inotify_rm_watch`], because a watched item
480 /// was deleted, the containing filesystem was unmounted, or after a
481 /// [`IN_ONESHOT`] watch is complete.
482 ///
483 /// This constant can be used to check against the [`mask`] field in
484 /// [`inotify_event`].
485 ///
486 /// See [man page] for additional details.
487 ///
488 /// [`inotify_rm_watch`]: fn.inotify_rm_watch.html
489 /// [`IN_ONESHOT`]: constant.IN_ONESHOT.html
490 /// [`mask`]: struct.inotify_event.html#structfield.mask
491 /// [`inotify_event`]: struct.inotify_event.html
492 /// [man page]: http://man7.org/linux/man-pages/man7/inotify.7.html
493 pub const IN_IGNORED: u32 = 0x00008000;
494
495
496 /// Describes a file system event
497 ///
498 /// From [inotify(7)]:
499 ///
500 /// > To determine what events have occurred, an application [read(2)]s
501 /// > from the inotify file descriptor. If no events have so far occurred,
502 /// > then, assuming a blocking file descriptor, [read(2)] will block until
503 /// > at least one event occurs (unless interrupted by a signal, in which
504 /// > case the call fails with the error EINTR; see [signal(7)]).
505 /// >
506 /// > Each successful [read(2)] returns a buffer containing one or more of
507 /// > this structure.
508 ///
509 /// [inotify(7)]: http://man7.org/linux/man-pages/man7/inotify.7.html
510 /// [read(2)]: http://man7.org/linux/man-pages/man2/read.2.html
511 /// [signal(7)]: http://man7.org/linux/man-pages/man7/signal.7.html
512 #[allow(non_camel_case_types)]
513 #[derive(Clone, Copy, Debug)]
514 #[repr(C)]
515 pub struct inotify_event {
516 /// Identifies the watch for which this event occurs
517 ///
518 /// This is one of the watch descriptors returned by a previous call to
519 /// [`inotify_add_watch()`].
520 ///
521 /// [`inotify_add_watch()`]: fn.inotify_add_watch.html
522 pub wd: c_int,
523
524 /// Describes the type file system event
525 ///
526 /// One of the following bits will be set, to identify the type of event:
527 ///
528 /// - [`IN_ACCESS`]
529 /// - [`IN_ATTRIB`]
530 /// - [`IN_CLOSE_NOWRITE`]
531 /// - [`IN_CLOSE_WRITE`]
532 /// - [`IN_CREATE`]
533 /// - [`IN_DELETE`]
534 /// - [`IN_DELETE_SELF`]
535 /// - [`IN_IGNORED`]
536 /// - [`IN_MODIFY`]
537 /// - [`IN_MOVED_FROM`]
538 /// - [`IN_MOVED_TO`]
539 /// - [`IN_MOVE_SELF`]
540 /// - [`IN_OPEN`]
541 /// - [`IN_Q_OVERFLOW`]
542 /// - [`IN_UNMOUNT`]
543 ///
544 /// Some constants cover multiple bits, and can be used for a less precise
545 /// check of the event type:
546 ///
547 /// - [`IN_CLOSE`]
548 /// - [`IN_MOVE`]
549 ///
550 /// In addition, the [`IN_ISDIR`] bit can be set.
551 ///
552 /// [`IN_ACCESS`]: constant.IN_ACCESS.html
553 /// [`IN_ATTRIB`]: constant.IN_ATTRIB.html
554 /// [`IN_CLOSE`]: constant.IN_CLOSE.html
555 /// [`IN_CLOSE_NOWRITE`]: constant.IN_CLOSE_NOWRITE.html
556 /// [`IN_CLOSE_WRITE`]: constant.IN_CLOSE_WRITE.html
557 /// [`IN_CREATE`]: constant.IN_CREATE.html
558 /// [`IN_DELETE`]: constant.IN_DELETE.html
559 /// [`IN_DELETE_SELF`]: constant.IN_DELETE_SELF.html
560 /// [`IN_IGNORED`]: constant.IN_IGNORED.html
561 /// [`IN_ISDIR`]: constant.IN_ISDIR.html
562 /// [`IN_MODIFY`]: constant.IN_MODIFY.html
563 /// [`IN_MOVE`]: constant.IN_MOVE.html
564 /// [`IN_MOVED_FROM`]: constant.IN_MOVED_FROM.html
565 /// [`IN_MOVED_TO`]: constant.IN_MOVED_TO.html
566 /// [`IN_MOVE_SELF`]: constant.IN_MOVE_SELF.html
567 /// [`IN_OPEN`]: constant.IN_OPEN.html
568 /// [`IN_Q_OVERFLOW`]: constant.IN_Q_OVERFLOW.html
569 /// [`IN_UNMOUNT`]: constant.IN_UNMOUNT.html
570 pub mask: u32,
571
572 /// A number that connects related events
573 ///
574 /// Currently used only for rename events. A related pair of
575 /// [`IN_MOVED_FROM`] and [`IN_MOVED_TO`] events will have the same,
576 /// non-zero, cookie. For all other events, cookie is 0.
577 ///
578 /// [`IN_MOVED_FROM`]: constant.IN_MOVED_FROM.html
579 /// [`IN_MOVED_TO`]: constant.IN_MOVED_TO.html
580 pub cookie: u32,
581
582 /// The length of `name`
583 ///
584 /// Used to determine the size of this structure. When `name`
585 /// isn't present (`name` is only present when an event occurs
586 /// for a file inside a watched directory), it is 0. When `name`
587 /// *is* present, it counts all of `name`'s bytes, including `\0`.
588 ///
589 /// > The `name` field is present only when an event is returned for
590 /// > a file inside a watched directory; it identifies the file
591 /// > pathname relative to the watched directory. This pathname is
592 /// > null-terminated, and may include further null bytes ('\0') to
593 /// > align subsequent reads to a suitable address boundary.
594 ///
595 /// The `name` field has been ommited in this struct's definition.
596 pub len: u32,
597 }
598
599
600 extern {
601 /// Creates an inotify instance
602 ///
603 /// If you need more flexibility, consider using [`inotify_init1`] instead.
604 ///
605 /// Returns `-1`, if an error occured, or an inotify file descriptor
606 /// otherwise.
607 ///
608 /// Please refer to the [man page] for additional details.
609 ///
610 /// [`inotify_init1`]: fn.inotify_init1.html
611 /// [man page]: http://man7.org/linux/man-pages/man2/inotify_init.2.html
612 pub fn inotify_init() -> c_int;
613
614 /// Creates an inotify instance
615 ///
616 /// Takes an argument to configure the new inotify instance. The following
617 /// flags can be set:
618 ///
619 /// - [`IN_CLOEXEC`]
620 /// - [`IN_NONBLOCK`]
621 ///
622 /// Returns `-1`, if an error occured, or an inotify file descriptor
623 /// otherwise.
624 ///
625 /// Please refer to the [man page] for additional details.
626 ///
627 /// [`IN_CLOEXEC`]: constant.IN_CLOEXEC.html
628 /// [`IN_NONBLOCK`]: constant.IN_NONBLOCK.html
629 /// [man page]: http://man7.org/linux/man-pages/man2/inotify_init1.2.html
630 pub fn inotify_init1(flags: c_int) -> c_int;
631
632 /// Adds or updates an inotify watch
633 ///
634 /// Adds an item to the watch list of an inotify instance, or modifies an
635 /// item on that list. This function takes the following arguments:
636 ///
637 /// - `fd` is the file descriptor of the inotify instance (created by
638 /// [`inotify_init`] or [`inotify_init1`])
639 /// - `pathname` is the path of the file or directory watch
640 /// - `mask` defines the behavior of this function and configures the watch
641 ///
642 /// The following flags in `mask` control the type of events to watch for:
643 ///
644 /// - [`IN_ACCESS`]
645 /// - [`IN_ATTRIB`]
646 /// - [`IN_CLOSE_NOWRITE`]
647 /// - [`IN_CLOSE_WRITE`]
648 /// - [`IN_CREATE`]
649 /// - [`IN_DELETE`]
650 /// - [`IN_DELETE_SELF`]
651 /// - [`IN_MODIFY`]
652 /// - [`IN_MOVED_FROM`]
653 /// - [`IN_MOVED_TO`]
654 /// - [`IN_MOVE_SELF`]
655 /// - [`IN_OPEN`]
656 ///
657 /// The following constants can be used as shortcuts to set multiple event
658 /// flags:
659 ///
660 /// - [`IN_ALL_EVENTS`]
661 /// - [`IN_CLOSE`]
662 /// - [`IN_MOVE`]
663 ///
664 /// In addition, the following flags can be set to control the behaviors of
665 /// the watch and this function:
666 ///
667 /// - [`IN_DONT_FOLLOW`]
668 /// - [`IN_EXCL_UNLINK`]
669 /// - [`IN_MASK_ADD`]
670 /// - [`IN_MASK_CREATE`]
671 /// - [`IN_ONESHOT`]
672 /// - [`IN_ONLYDIR`]
673 ///
674 /// The function returns `-1` if an error occured. Otherwise, it returns a
675 /// watch descriptor that can be used to remove the watch using
676 /// [`inotify_rm_watch`] or identify the watch via [`inotify_event`]'s [wd`]
677 /// field.
678 ///
679 /// Please refer to the [man page] for additional details.
680 ///
681 /// [`inotify_init`]: fn.inotify_init.html
682 /// [`inotify_init1`]: fn.inotify_init1.html
683 /// [`IN_ACCESS`]: constant.IN_ACCESS.html
684 /// [`IN_ATTRIB`]: constant.IN_ATTRIB.html
685 /// [`IN_CLOSE_NOWRITE`]: constant.IN_CLOSE_NOWRITE.html
686 /// [`IN_CLOSE_WRITE`]: constant.IN_CLOSE_WRITE.html
687 /// [`IN_CREATE`]: constant.IN_CREATE.html
688 /// [`IN_DELETE`]: constant.IN_DELETE.html
689 /// [`IN_DELETE_SELF`]: constant.IN_DELETE_SELF.html
690 /// [`IN_MODIFY`]: constant.IN_MODIFY.html
691 /// [`IN_MOVED_FROM`]: constant.IN_MOVED_FROM.html
692 /// [`IN_MOVED_TO`]: constant.IN_MOVED_TO.html
693 /// [`IN_MOVE_SELF`]: constant.IN_MOVE_SELF.html
694 /// [`IN_OPEN`]: constant.IN_OPEN.html
695 /// [`IN_ALL_EVENTS`]: constant.IN_ALL_EVENTS.html
696 /// [`IN_CLOSE`]: constant.IN_CLOSE.html
697 /// [`IN_MOVE`]: constant.IN_MOVE.html
698 /// [`IN_DONT_FOLLOW`]: constant.IN_DONT_FOLLOW.html
699 /// [`IN_EXCL_UNLINK`]: constant.IN_EXCL_UNLINK.html
700 /// [`IN_MASK_ADD`]: constant.IN_MASK_ADD.html
701 /// [`IN_MASK_CREATE`]: constant.IN_MASK_CREATE.html
702 /// [`IN_ONESHOT`]: constant.IN_ONESHOT.html
703 /// [`IN_ONLYDIR`]: constant.IN_ONLYDIR.html
704 /// [`inotify_rm_watch`]: fn.inotify_rm_watch.html
705 /// [`inotify_event`]: struct.inotify_event.html
706 /// [`wd`]: struct.inotify_event.html#structfield.wd
707 /// [man page]: http://man7.org/linux/man-pages/man2/inotify_add_watch.2.html
708 pub fn inotify_add_watch(fd: c_int, pathname: *const c_char, mask: u32) -> c_int;
709
710 /// Removes an inotify watch
711 ///
712 /// Removes an item from the watch list of an inotify instance. The inotify
713 /// instance is identified by the `fd` argument. The watch is identified by
714 /// the `wd` argument.
715 ///
716 /// Returns `0` on success, `-1` on failure.
717 ///
718 /// Please refer to the [man page] for additional details.
719 ///
720 /// [man page]: http://man7.org/linux/man-pages/man2/inotify_rm_watch.2.html
721 pub fn inotify_rm_watch(fd: c_int, wd: c_int) -> c_int;
722 }
723
724 pub use libc::{
725 close,
726 read,
727 };