Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linux: add fanotify(7) API bindings. #1699

Merged
merged 1 commit into from
Apr 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2258,6 +2258,7 @@ fn test_linux(target: &str) {
"linux/sockios.h",
"linux/vm_sockets.h",
"sys/auxv.h",
"sys/fanotify.h",
}

// note: aio.h must be included before sys/mount.h
Expand Down
11 changes: 11 additions & 0 deletions src/unix/linux_like/linux/align.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ macro_rules! expand_align {
#[doc(hidden)]
size: [u8; ::__SIZEOF_PTHREAD_CONDATTR_T],
}

#[repr(align(8))]
pub struct fanotify_event_metadata {
pub event_len: __u32,
pub vers: __u8,
pub reserved: __u8,
pub metadata_len: __u16,
pub mask: __u64,
pub fd: ::c_int,
pub pid: ::c_int,
}
}

s_no_extra_traits! {
Expand Down
7 changes: 7 additions & 0 deletions src/unix/linux_like/linux/gnu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,13 @@ extern "C" {
len: ::size_t,
flags: ::c_uint,
) -> ::ssize_t;
pub fn fanotify_mark(
fd: ::c_int,
flags: ::c_uint,
mask: u64,
dirfd: ::c_int,
path: *const ::c_char,
) -> ::c_int;
}

#[link(name = "util")]
Expand Down
53 changes: 53 additions & 0 deletions src/unix/linux_like/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,11 @@ s! {
pub len: u32
}

pub struct fanotify_response {
pub fd: ::c_int,
pub response: __u32,
}

pub struct sockaddr_vm {
pub svm_family: ::sa_family_t,
pub svm_reserved1: ::c_ushort,
Expand Down Expand Up @@ -2417,6 +2422,53 @@ pub const IN_ALL_EVENTS: u32 = IN_ACCESS
pub const IN_CLOEXEC: ::c_int = O_CLOEXEC;
pub const IN_NONBLOCK: ::c_int = O_NONBLOCK;

// uapi/linux/fanotify.h
pub const FAN_ACCESS: u64 = 0x0000_0001;
pub const FAN_MODIFY: u64 = 0x0000_0002;
pub const FAN_CLOSE_WRITE: u64 = 0x0000_0008;
pub const FAN_CLOSE_NOWRITE: u64 = 0x0000_0010;
pub const FAN_OPEN: u64 = 0x0000_0020;

pub const FAN_Q_OVERFLOW: u64 = 0x0000_4000;

pub const FAN_OPEN_PERM: u64 = 0x0001_0000;
pub const FAN_ACCESS_PERM: u64 = 0x0002_0000;

pub const FAN_ONDIR: u64 = 0x4000_0000;

pub const FAN_EVENT_ON_CHILD: u64 = 0x0800_0000;

pub const FAN_CLOSE: u64 = FAN_CLOSE_WRITE | FAN_CLOSE_NOWRITE;

pub const FAN_CLOEXEC: ::c_uint = 0x0000_0001;
pub const FAN_NONBLOCK: ::c_uint = 0x0000_0002;

pub const FAN_CLASS_NOTIF: ::c_uint = 0x0000_0000;
pub const FAN_CLASS_CONTENT: ::c_uint = 0x0000_0004;
pub const FAN_CLASS_PRE_CONTENT: ::c_uint = 0x0000_0008;

pub const FAN_UNLIMITED_QUEUE: ::c_uint = 0x0000_0010;
pub const FAN_UNLIMITED_MARKS: ::c_uint = 0x0000_0020;

pub const FAN_MARK_ADD: ::c_uint = 0x0000_0001;
pub const FAN_MARK_REMOVE: ::c_uint = 0x0000_0002;
pub const FAN_MARK_DONT_FOLLOW: ::c_uint = 0x0000_0004;
pub const FAN_MARK_ONLYDIR: ::c_uint = 0x0000_0008;
pub const FAN_MARK_INODE: ::c_uint = 0x0000_0000;
pub const FAN_MARK_MOUNT: ::c_uint = 0x0000_0010;
// NOTE: FAN_MARK_FILESYSTEM requires Linux Kernel >= 4.20.0
pub const FAN_MARK_FILESYSTEM: ::c_uint = 0x0000_0100;
pub const FAN_MARK_IGNORED_MASK: ::c_uint = 0x0000_0020;
pub const FAN_MARK_IGNORED_SURV_MODIFY: ::c_uint = 0x0000_0040;
pub const FAN_MARK_FLUSH: ::c_uint = 0x0000_0080;

pub const FANOTIFY_METADATA_VERSION: u8 = 3;

pub const FAN_ALLOW: u32 = 0x01;
pub const FAN_DENY: u32 = 0x02;

pub const FAN_NOFD: ::c_int = -1;

pub const FUTEX_WAIT: ::c_int = 0;
pub const FUTEX_WAKE: ::c_int = 1;
pub const FUTEX_FD: ::c_int = 2;
Expand Down Expand Up @@ -3304,6 +3356,7 @@ extern "C" {
path: *const ::c_char,
mask: u32,
) -> ::c_int;
pub fn fanotify_init(flags: ::c_uint, event_f_flags: ::c_uint) -> ::c_int;
}

cfg_if! {
Expand Down
10 changes: 10 additions & 0 deletions src/unix/linux_like/linux/musl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,16 @@ extern "C" {
needle: *const ::c_void,
needlelen: ::size_t,
) -> *mut ::c_void;
// Musl targets need the `mask` argument of `fanotify_mark` be specified
// `::c_ulonglong` instead of `u64` or there will be a type mismatch between
// `long long unsigned int` and the expected `uint64_t`.
pub fn fanotify_mark(
fd: ::c_int,
flags: ::c_uint,
mask: ::c_ulonglong,
dirfd: ::c_int,
path: *const ::c_char,
) -> ::c_int;
}

cfg_if! {
Expand Down
11 changes: 11 additions & 0 deletions src/unix/linux_like/linux/no_align.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ macro_rules! expand_align {
__align: [::c_int; 0],
size: [u8; ::__SIZEOF_PTHREAD_CONDATTR_T],
}

pub struct fanotify_event_metadata {
__align: [::c_long; 0],
pub event_len: __u32,
pub vers: __u8,
pub reserved: __u8,
pub metadata_len: __u16,
pub mask: __u64,
pub fd: ::c_int,
pub pid: ::c_int,
}
}

s_no_extra_traits! {
Expand Down