Skip to content

Commit

Permalink
Rename fanotify OFlags to EventFFlags
Browse files Browse the repository at this point in the history
  • Loading branch information
ad0 committed Nov 20, 2023
1 parent db46b2e commit 8d6d0d2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ aio = ["pin-utils"]
dir = ["fs"]
env = []
event = []
fanotify = []
fanotify = ["fs"]
feature = []
fs = []
hostname = []
Expand Down
19 changes: 17 additions & 2 deletions src/sys/fanotify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use crate::{NixPath, Result};
use crate::errno::Errno;
use crate::fcntl::OFlag;
use crate::unistd::{read, write};
use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, OwnedFd, RawFd};
use std::mem::{MaybeUninit, size_of};
Expand Down Expand Up @@ -102,7 +103,7 @@ libc_bitflags! {

libc_bitflags! {
/// File status flags for fanotify events file descriptors.
pub struct OFlags: libc::c_uint {
pub struct EventFFlags: libc::c_uint {
/// Read only access.
O_RDONLY as libc::c_uint;
/// Write only access.
Expand All @@ -126,6 +127,20 @@ libc_bitflags! {
}
}

impl TryFrom<OFlag> for EventFFlags {
type Error = Errno;

fn try_from(o_flag: OFlag) -> Result<Self> {
EventFFlags::from_bits(o_flag.bits() as u32).ok_or(Errno::EINVAL)
}
}

impl From<EventFFlags> for OFlag {
fn from(event_f_flags: EventFFlags) -> Self {
OFlag::from_bits_retain(event_f_flags.bits() as i32)
}
}

libc_bitflags! {
/// Configuration options for [`fanotify_mark`](fn.fanotify_mark.html).
pub struct MarkFlags: libc::c_uint {
Expand Down Expand Up @@ -223,7 +238,7 @@ impl Fanotify {
/// Returns a Result containing a Fanotify instance.
///
/// For more information, see [fanotify_init(2)](https://man7.org/linux/man-pages/man7/fanotify_init.2.html).
pub fn init(flags: InitFlags, event_f_flags: OFlags) -> Result<Fanotify> {
pub fn init(flags: InitFlags, event_f_flags: EventFFlags) -> Result<Fanotify> {
let res = Errno::result(unsafe {
libc::fanotify_init(flags.bits(), event_f_flags.bits())
});
Expand Down
8 changes: 5 additions & 3 deletions test/sys/test_fanotify.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::*;
use nix::sys::fanotify::{
Fanotify, FanotifyResponse, InitFlags, MarkFlags, MaskFlags, OFlags,
EventFFlags, Fanotify, FanotifyResponse, InitFlags, MarkFlags, MaskFlags,
Response,
};
use std::fs::{read_link, File, OpenOptions};
Expand All @@ -20,7 +20,8 @@ pub fn test_fanotify() {

fn test_fanotify_notifications() {
let group =
Fanotify::init(InitFlags::FAN_CLASS_NOTIF, OFlags::O_RDONLY).unwrap();
Fanotify::init(InitFlags::FAN_CLASS_NOTIF, EventFFlags::O_RDONLY)
.unwrap();
let tempdir = tempfile::tempdir().unwrap();

group
Expand Down Expand Up @@ -88,7 +89,8 @@ fn test_fanotify_notifications() {

fn test_fanotify_responses() {
let group =
Fanotify::init(InitFlags::FAN_CLASS_CONTENT, OFlags::O_RDONLY).unwrap();
Fanotify::init(InitFlags::FAN_CLASS_CONTENT, EventFFlags::O_RDONLY)
.unwrap();
let tempdir = tempfile::tempdir().unwrap();

group
Expand Down

0 comments on commit 8d6d0d2

Please sign in to comment.