1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
use crate::backend::c;
use crate::backend::fs::syscalls;
use crate::fd::{BorrowedFd, OwnedFd};
use crate::io;
use bitflags::bitflags;
bitflags! {
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct CreateFlags: c::c_uint {
const CLOEXEC = linux_raw_sys::general::IN_CLOEXEC;
const NONBLOCK = linux_raw_sys::general::IN_NONBLOCK;
}
}
bitflags! {
#[repr(transparent)]
#[derive(Default, Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct WatchFlags: c::c_uint {
const ACCESS = linux_raw_sys::general::IN_ACCESS;
const ATTRIB = linux_raw_sys::general::IN_ATTRIB;
const CLOSE_NOWRITE = linux_raw_sys::general::IN_CLOSE_NOWRITE;
const CLOSE_WRITE = linux_raw_sys::general::IN_CLOSE_WRITE;
const CREATE = linux_raw_sys::general::IN_CREATE;
const DELETE = linux_raw_sys::general::IN_DELETE;
const DELETE_SELF = linux_raw_sys::general::IN_DELETE_SELF;
const MODIFY = linux_raw_sys::general::IN_MODIFY;
const MOVE_SELF = linux_raw_sys::general::IN_MOVE_SELF;
const MOVED_FROM = linux_raw_sys::general::IN_MOVED_FROM;
const MOVED_TO = linux_raw_sys::general::IN_MOVED_TO;
const OPEN = linux_raw_sys::general::IN_OPEN;
const CLOSE = linux_raw_sys::general::IN_CLOSE;
const MOVE = linux_raw_sys::general::IN_MOVE;
const ALL_EVENTS = linux_raw_sys::general::IN_ALL_EVENTS;
const DONT_FOLLOW = linux_raw_sys::general::IN_DONT_FOLLOW;
const EXCL_UNLINK = linux_raw_sys::general::IN_EXCL_UNLINK;
const MASK_ADD = linux_raw_sys::general::IN_MASK_ADD;
const MASK_CREATE = linux_raw_sys::general::IN_MASK_CREATE;
const ONESHOT = linux_raw_sys::general::IN_ONESHOT;
const ONLYDIR = linux_raw_sys::general::IN_ONLYDIR;
}
}
#[doc(alias = "inotify_init1")]
#[inline]
pub fn inotify_init(flags: CreateFlags) -> io::Result<OwnedFd> {
syscalls::inotify_init1(flags)
}
#[inline]
pub fn inotify_add_watch<P: crate::path::Arg>(
inot: BorrowedFd<'_>,
path: P,
flags: WatchFlags,
) -> io::Result<i32> {
let path = path.as_cow_c_str().unwrap();
syscalls::inotify_add_watch(inot, &path, flags)
}
#[doc(alias = "inotify_rm_watch")]
#[inline]
pub fn inotify_remove_watch(inot: BorrowedFd<'_>, wd: i32) -> io::Result<()> {
syscalls::inotify_rm_watch(inot, wd)
}