rustix::fs

Module inotify

Source
Available on crate feature fs only.
Expand description

inotify support for working with inotify objects.

§Examples

use rustix::fs::inotify;
use rustix::io;
use std::mem::MaybeUninit;

// Create an inotify object. In this example, we use `NONBLOCK` so that the
// reader fails with `WOULDBLOCK` when no events are ready. Otherwise it
// will block until at least one event is ready.
let inotify = inotify::init(inotify::CreateFlags::NONBLOCK)?;

// Add a directory to watch.
inotify::add_watch(
    &inotify,
    "/path/to/some/directory/to/watch",
    inotify::WatchFlags::ALL_EVENTS,
)?;

// Generate some events in the watched directory…

// Loop over pending events.
let mut buf = [MaybeUninit::uninit(); 512];
let mut iter = inotify::Reader::new(inotify, &mut buf);
loop {
    let entry = match iter.next() {
        // Stop iterating if there are no more events for now.
        Err(io::Errno::WOULDBLOCK) => break,
        Err(e) => return Err(e),
        Ok(entry) => entry,
    };

    // Use `entry`…
}

Structs§

Functions§

  • inotify_add_watch(self, path, flags)—Adds a watch to inotify.
  • inotify_init1(flags)—Creates a new inotify object.
  • inotify_rm_watch(self, wd)—Removes a watch from this inotify.