Skip to content

Commit 755c66d

Browse files
authored
Add fanotify API wrappers (#2194)
* Add fanotify API wrappers * Review/fix enum comments * Rename has_compile_version to check_version * Fix lint unsafe_block_in_unsafe_fn * Rename fanotify OFlags to EventFFlags * Use existing function at_rawfd from fcntl * Add missing feature guard for docs * Change FanotifyEvent struct to a simple wrapper over libc structure * Change FanotifyResponse struct to a simple wrapper over libc structure * Cast pointer with function 'cast' instead of 'as' * Add FAN_REPORT_PIDFD and FAN_REPORT_TID fanotify init flags
1 parent 7e16e32 commit 755c66d

File tree

8 files changed

+586
-3
lines changed

8 files changed

+586
-3
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ aio = ["pin-utils"]
4242
dir = ["fs"]
4343
env = []
4444
event = []
45+
fanotify = []
4546
feature = []
4647
fs = []
4748
hostname = []

changelog/2194.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added new fanotify API: wrappers for `fanotify_init` and `fanotify_mark`

src/fcntl.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,14 @@ libc_bitflags! {
6464
}
6565
}
6666

67-
#[cfg(any(feature = "fs", feature = "term"))]
67+
#[cfg(any(
68+
feature = "fs",
69+
feature = "term",
70+
all(feature = "fanotify", target_os = "linux")
71+
))]
6872
libc_bitflags!(
6973
/// Configuration options for opened files.
70-
#[cfg_attr(docsrs, doc(cfg(any(feature = "fs", feature = "term"))))]
74+
#[cfg_attr(docsrs, doc(cfg(any(feature = "fs", feature = "term", all(feature = "fanotify", target_os = "linux")))))]
7175
pub struct OFlag: c_int {
7276
/// Mask for the access mode of the file.
7377
O_ACCMODE;
@@ -194,7 +198,8 @@ libc_bitflags!(
194198
/// Computes the raw fd consumed by a function of the form `*at`.
195199
#[cfg(any(
196200
all(feature = "fs", not(target_os = "redox")),
197-
all(feature = "process", any(target_os = "android", target_os = "linux"))
201+
all(feature = "process", any(target_os = "android", target_os = "linux")),
202+
all(feature = "fanotify", target_os = "linux")
198203
))]
199204
pub(crate) fn at_rawfd(fd: Option<RawFd>) -> raw::c_int {
200205
fd.unwrap_or(libc::AT_FDCWD)

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//! * `dir` - Stuff relating to directory iteration
1313
//! * `env` - Manipulate environment variables
1414
//! * `event` - Event-driven APIs, like `kqueue` and `epoll`
15+
//! * `fanotify` - Linux's `fanotify` filesystem events monitoring API
1516
//! * `feature` - Query characteristics of the OS at runtime
1617
//! * `fs` - File system functionality
1718
//! * `hostname` - Get and set the system's hostname
@@ -53,6 +54,7 @@
5354
feature = "dir",
5455
feature = "env",
5556
feature = "event",
57+
feature = "fanotify",
5658
feature = "feature",
5759
feature = "fs",
5860
feature = "hostname",

0 commit comments

Comments
 (0)