Skip to content

Commit 44feea8

Browse files
committed
Rename fanotify OFlags to EventFFlags
1 parent db46b2e commit 44feea8

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

src/fcntl.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ 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.
7074
#[cfg_attr(docsrs, doc(cfg(any(feature = "fs", feature = "term"))))]

src/sys/fanotify.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
1313
use crate::{NixPath, Result};
1414
use crate::errno::Errno;
15+
use crate::fcntl::OFlag;
1516
use crate::unistd::{read, write};
1617
use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, OwnedFd, RawFd};
1718
use std::mem::{MaybeUninit, size_of};
@@ -102,7 +103,7 @@ libc_bitflags! {
102103

103104
libc_bitflags! {
104105
/// File status flags for fanotify events file descriptors.
105-
pub struct OFlags: libc::c_uint {
106+
pub struct EventFFlags: libc::c_uint {
106107
/// Read only access.
107108
O_RDONLY as libc::c_uint;
108109
/// Write only access.
@@ -126,6 +127,20 @@ libc_bitflags! {
126127
}
127128
}
128129

130+
impl TryFrom<OFlag> for EventFFlags {
131+
type Error = Errno;
132+
133+
fn try_from(o_flag: OFlag) -> Result<Self> {
134+
EventFFlags::from_bits(o_flag.bits() as u32).ok_or(Errno::EINVAL)
135+
}
136+
}
137+
138+
impl From<EventFFlags> for OFlag {
139+
fn from(event_f_flags: EventFFlags) -> Self {
140+
OFlag::from_bits_retain(event_f_flags.bits() as i32)
141+
}
142+
}
143+
129144
libc_bitflags! {
130145
/// Configuration options for [`fanotify_mark`](fn.fanotify_mark.html).
131146
pub struct MarkFlags: libc::c_uint {
@@ -223,7 +238,7 @@ impl Fanotify {
223238
/// Returns a Result containing a Fanotify instance.
224239
///
225240
/// For more information, see [fanotify_init(2)](https://man7.org/linux/man-pages/man7/fanotify_init.2.html).
226-
pub fn init(flags: InitFlags, event_f_flags: OFlags) -> Result<Fanotify> {
241+
pub fn init(flags: InitFlags, event_f_flags: EventFFlags) -> Result<Fanotify> {
227242
let res = Errno::result(unsafe {
228243
libc::fanotify_init(flags.bits(), event_f_flags.bits())
229244
});

test/sys/test_fanotify.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::*;
22
use nix::sys::fanotify::{
3-
Fanotify, FanotifyResponse, InitFlags, MarkFlags, MaskFlags, OFlags,
3+
EventFFlags, Fanotify, FanotifyResponse, InitFlags, MarkFlags, MaskFlags,
44
Response,
55
};
66
use std::fs::{read_link, File, OpenOptions};
@@ -20,7 +20,8 @@ pub fn test_fanotify() {
2020

2121
fn test_fanotify_notifications() {
2222
let group =
23-
Fanotify::init(InitFlags::FAN_CLASS_NOTIF, OFlags::O_RDONLY).unwrap();
23+
Fanotify::init(InitFlags::FAN_CLASS_NOTIF, EventFFlags::O_RDONLY)
24+
.unwrap();
2425
let tempdir = tempfile::tempdir().unwrap();
2526

2627
group
@@ -88,7 +89,8 @@ fn test_fanotify_notifications() {
8889

8990
fn test_fanotify_responses() {
9091
let group =
91-
Fanotify::init(InitFlags::FAN_CLASS_CONTENT, OFlags::O_RDONLY).unwrap();
92+
Fanotify::init(InitFlags::FAN_CLASS_CONTENT, EventFFlags::O_RDONLY)
93+
.unwrap();
9294
let tempdir = tempfile::tempdir().unwrap();
9395

9496
group

0 commit comments

Comments
 (0)