Skip to content

Commit

Permalink
Add fanotify API wrappers (#2194)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ad0 committed Nov 23, 2023
1 parent 7e16e32 commit 755c66d
Show file tree
Hide file tree
Showing 8 changed files with 586 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ aio = ["pin-utils"]
dir = ["fs"]
env = []
event = []
fanotify = []
feature = []
fs = []
hostname = []
Expand Down
1 change: 1 addition & 0 deletions changelog/2194.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added new fanotify API: wrappers for `fanotify_init` and `fanotify_mark`
11 changes: 8 additions & 3 deletions src/fcntl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,14 @@ libc_bitflags! {
}
}

#[cfg(any(feature = "fs", feature = "term"))]
#[cfg(any(
feature = "fs",
feature = "term",
all(feature = "fanotify", target_os = "linux")
))]
libc_bitflags!(
/// Configuration options for opened files.
#[cfg_attr(docsrs, doc(cfg(any(feature = "fs", feature = "term"))))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "fs", feature = "term", all(feature = "fanotify", target_os = "linux")))))]
pub struct OFlag: c_int {
/// Mask for the access mode of the file.
O_ACCMODE;
Expand Down Expand Up @@ -194,7 +198,8 @@ libc_bitflags!(
/// Computes the raw fd consumed by a function of the form `*at`.
#[cfg(any(
all(feature = "fs", not(target_os = "redox")),
all(feature = "process", any(target_os = "android", target_os = "linux"))
all(feature = "process", any(target_os = "android", target_os = "linux")),
all(feature = "fanotify", target_os = "linux")
))]
pub(crate) fn at_rawfd(fd: Option<RawFd>) -> raw::c_int {
fd.unwrap_or(libc::AT_FDCWD)
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
//! * `dir` - Stuff relating to directory iteration
//! * `env` - Manipulate environment variables
//! * `event` - Event-driven APIs, like `kqueue` and `epoll`
//! * `fanotify` - Linux's `fanotify` filesystem events monitoring API
//! * `feature` - Query characteristics of the OS at runtime
//! * `fs` - File system functionality
//! * `hostname` - Get and set the system's hostname
Expand Down Expand Up @@ -53,6 +54,7 @@
feature = "dir",
feature = "env",
feature = "event",
feature = "fanotify",
feature = "feature",
feature = "fs",
feature = "hostname",
Expand Down
Loading

0 comments on commit 755c66d

Please sign in to comment.