chore: cargo fmt
This commit is contained in:
@ -24,7 +24,9 @@ extern "C" fn interrupt_handler(_: i32) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, clap::Parser)]
|
#[derive(Debug, clap::Parser)]
|
||||||
#[clap(about="fanotify demo", long_about="
|
#[clap(
|
||||||
|
about = "fanotify demo",
|
||||||
|
long_about = "
|
||||||
monitor filesystem changes demo
|
monitor filesystem changes demo
|
||||||
|
|
||||||
to use as storage provider:
|
to use as storage provider:
|
||||||
@ -35,7 +37,8 @@ to use as storage provider:
|
|||||||
--mask-flags FAN_ACCESS_PERM setup permission notification
|
--mask-flags FAN_ACCESS_PERM setup permission notification
|
||||||
--mask-flags FAN_ON_DIR create events for directories itself
|
--mask-flags FAN_ON_DIR create events for directories itself
|
||||||
--mask-flags FAN_EVENT_ON_CHILD create events for direct children
|
--mask-flags FAN_EVENT_ON_CHILD create events for direct children
|
||||||
")]
|
"
|
||||||
|
)]
|
||||||
struct Args {
|
struct Args {
|
||||||
#[clap(required(true))]
|
#[clap(required(true))]
|
||||||
path: Vec<String>,
|
path: Vec<String>,
|
||||||
@ -146,7 +149,7 @@ fn main() -> Result<(), Error> {
|
|||||||
|
|
||||||
let whitelist = args.whitelist;
|
let whitelist = args.whitelist;
|
||||||
let storage_provider = args.providers;
|
let storage_provider = args.providers;
|
||||||
|
|
||||||
let mut ready = HashSet::new();
|
let mut ready = HashSet::new();
|
||||||
let mut bufferdfds: HashMap<std::path::PathBuf, Vec<OwnedFd>> = HashMap::new();
|
let mut bufferdfds: HashMap<std::path::PathBuf, Vec<OwnedFd>> = HashMap::new();
|
||||||
let mut arg0map = HashMap::new();
|
let mut arg0map = HashMap::new();
|
||||||
@ -233,9 +236,7 @@ fn main() -> Result<(), Error> {
|
|||||||
// is a directory or filled with content
|
// is a directory or filled with content
|
||||||
metadata.is_dir() || ready.contains(&path)
|
metadata.is_dir() || ready.contains(&path)
|
||||||
}
|
}
|
||||||
Err(error) => {
|
Err(error) => error.kind() == std::io::ErrorKind::NotFound,
|
||||||
error.kind() == std::io::ErrorKind::NotFound
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
if allowed || whitelist.contains(&arg0) || storage_provider.contains(&arg0) {
|
if allowed || whitelist.contains(&arg0) || storage_provider.contains(&arg0) {
|
||||||
info!("<<<<< {} allowed", fd.as_raw_fd());
|
info!("<<<<< {} allowed", fd.as_raw_fd());
|
||||||
@ -252,7 +253,6 @@ fn main() -> Result<(), Error> {
|
|||||||
} else {
|
} else {
|
||||||
bufferdfds.insert(path, vec![fd]);
|
bufferdfds.insert(path, vec![fd]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MaskFlags::FAN_CLOSE_WRITE => {
|
MaskFlags::FAN_CLOSE_WRITE => {
|
||||||
|
@ -12,7 +12,7 @@ impl Errno {
|
|||||||
Self { raw_errno: errno }
|
Self { raw_errno: errno }
|
||||||
}
|
}
|
||||||
pub fn errno() -> Self {
|
pub fn errno() -> Self {
|
||||||
Self::new(unsafe { *libc::__errno_location() } )
|
Self::new(unsafe { *libc::__errno_location() })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +96,8 @@ impl Fanotify {
|
|||||||
// (long)(meta) ->event_len >= (long)FAN_FAN_EVENT_METADATA_LEN && // struct contains valid size (not implemented)
|
// (long)(meta) ->event_len >= (long)FAN_FAN_EVENT_METADATA_LEN && // struct contains valid size (not implemented)
|
||||||
// (long)(meta) ->event_len <= (long)(len) // struct does not read over buffer boundary (not implemented)
|
// (long)(meta) ->event_len <= (long)(len) // struct does not read over buffer boundary (not implemented)
|
||||||
while offset + EVENT_SIZE <= nread {
|
while offset + EVENT_SIZE <= nread {
|
||||||
let mut uninited: MaybeUninit<libc::fanotify_event_metadata> = MaybeUninit::uninit();
|
let mut uninited: MaybeUninit<libc::fanotify_event_metadata> =
|
||||||
|
MaybeUninit::uninit();
|
||||||
std::ptr::copy(
|
std::ptr::copy(
|
||||||
buffer.as_ptr().add(offset),
|
buffer.as_ptr().add(offset),
|
||||||
uninited.as_mut_ptr().cast(),
|
uninited.as_mut_ptr().cast(),
|
||||||
@ -108,7 +109,7 @@ impl Fanotify {
|
|||||||
// meta = FAN_EVENT_NEXT(meta, len) translate to:
|
// meta = FAN_EVENT_NEXT(meta, len) translate to:
|
||||||
// len -= meta->event_len; // shrink rest length
|
// len -= meta->event_len; // shrink rest length
|
||||||
// , // comma operator, evaluate first express, but not using its result
|
// , // comma operator, evaluate first express, but not using its result
|
||||||
//
|
//
|
||||||
// meta = (struct fanotify_event_metadata*) ( // cast pointer back to metadata type
|
// meta = (struct fanotify_event_metadata*) ( // cast pointer back to metadata type
|
||||||
// ((char*)(meta)) // discard metadata type to increase pointer by 1
|
// ((char*)(meta)) // discard metadata type to increase pointer by 1
|
||||||
// + (meta) -> event_len // add event_len to move to next
|
// + (meta) -> event_len // add event_len to move to next
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod macros;
|
mod macros;
|
||||||
|
|
||||||
|
pub mod consts;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod fanotify;
|
pub mod fanotify;
|
||||||
pub mod consts;
|
|
||||||
|
|
||||||
pub use bitflags;
|
pub use bitflags;
|
||||||
|
|
||||||
pub use fanotify::{Fanotify, Error, Response, Response as FanotifyResponse, Event};
|
pub use fanotify::{Error, Event, Fanotify, Response, Response as FanotifyResponse};
|
||||||
|
@ -37,7 +37,7 @@ macro_rules! fa_bitflags {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// from nix: input: accept a list of pub struct
|
// from nix: input: accept a list of pub struct
|
||||||
(
|
(
|
||||||
// first
|
// first
|
||||||
$(#[$outer:meta])*
|
$(#[$outer:meta])*
|
||||||
@ -72,4 +72,4 @@ macro_rules! fa_bitflags {
|
|||||||
|
|
||||||
// modified part: empty block don't produce anything.
|
// modified part: empty block don't produce anything.
|
||||||
() => {}
|
() => {}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user