rustix/backend/linux_raw/fs/
inotify.rs
1use crate::backend::c;
4use crate::backend::fs::syscalls;
5use crate::fd::{BorrowedFd, OwnedFd};
6use crate::io;
7use bitflags::bitflags;
8
9bitflags! {
10 #[repr(transparent)]
14 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
15 pub struct CreateFlags: c::c_uint {
16 const CLOEXEC = linux_raw_sys::general::IN_CLOEXEC;
18 const NONBLOCK = linux_raw_sys::general::IN_NONBLOCK;
20
21 const _ = !0;
23 }
24}
25
26bitflags! {
27 #[repr(transparent)]
31 #[derive(Default, Copy, Clone, Eq, PartialEq, Hash, Debug)]
32 pub struct WatchFlags: c::c_uint {
33 const ACCESS = linux_raw_sys::general::IN_ACCESS;
35 const ATTRIB = linux_raw_sys::general::IN_ATTRIB;
37 const CLOSE_NOWRITE = linux_raw_sys::general::IN_CLOSE_NOWRITE;
39 const CLOSE_WRITE = linux_raw_sys::general::IN_CLOSE_WRITE;
41 const CREATE = linux_raw_sys::general::IN_CREATE;
43 const DELETE = linux_raw_sys::general::IN_DELETE;
45 const DELETE_SELF = linux_raw_sys::general::IN_DELETE_SELF;
47 const MODIFY = linux_raw_sys::general::IN_MODIFY;
49 const MOVE_SELF = linux_raw_sys::general::IN_MOVE_SELF;
51 const MOVED_FROM = linux_raw_sys::general::IN_MOVED_FROM;
53 const MOVED_TO = linux_raw_sys::general::IN_MOVED_TO;
55 const OPEN = linux_raw_sys::general::IN_OPEN;
57
58 const CLOSE = linux_raw_sys::general::IN_CLOSE;
60 const MOVE = linux_raw_sys::general::IN_MOVE;
62 const ALL_EVENTS = linux_raw_sys::general::IN_ALL_EVENTS;
64
65 const DONT_FOLLOW = linux_raw_sys::general::IN_DONT_FOLLOW;
67 const EXCL_UNLINK = linux_raw_sys::general::IN_EXCL_UNLINK;
69 const MASK_ADD = linux_raw_sys::general::IN_MASK_ADD;
71 const MASK_CREATE = linux_raw_sys::general::IN_MASK_CREATE;
73 const ONESHOT = linux_raw_sys::general::IN_ONESHOT;
75 const ONLYDIR = linux_raw_sys::general::IN_ONLYDIR;
77
78 const _ = !0;
80 }
81}
82
83#[doc(alias = "inotify_init1")]
88#[inline]
89pub fn inotify_init(flags: CreateFlags) -> io::Result<OwnedFd> {
90 syscalls::inotify_init1(flags)
91}
92
93#[inline]
102pub fn inotify_add_watch<P: crate::path::Arg>(
103 inot: BorrowedFd<'_>,
104 path: P,
105 flags: WatchFlags,
106) -> io::Result<i32> {
107 path.into_with_c_str(|path| syscalls::inotify_add_watch(inot, path, flags))
108}
109
110#[doc(alias = "inotify_rm_watch")]
115#[inline]
116pub fn inotify_remove_watch(inot: BorrowedFd<'_>, wd: i32) -> io::Result<()> {
117 syscalls::inotify_rm_watch(inot, wd)
118}