1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
//! Linux file system monitoring library that uses
//! [fanotify](https://man7.org/linux/man-pages/man7/fanotify.7.html)
//! underneath.
//!
//! # Installation
//! Run the command in project root directory
//! ```bash
//! cargo add naughtyfy
//! ```
//! Or manually add it to `Cargo.toml`
//! ```toml
//! [dependencies]
//! naughtyfy = "*"
//! ```
//! # Example
//! ```rust
//! use naughtyfy::api::*;
//! use naughtyfy::flags::*;
//! use naughtyfy::errors::*;
//! use naughtyfy::types::*;
//! let fd = fanotify_init(FAN_CLOEXEC | FAN_NONBLOCK | FAN_CLASS_NOTIF ,O_CLOEXEC | O_RDONLY);
//! match fd {
//! Ok(fd) => {
//! assert!(fd >= 0);
//! let m = fanotify_mark(fd, FAN_MARK_ADD | FAN_MARK_MOUNT, FAN_ACCESS, libc::AT_FDCWD, "./");
//! assert!(m.is_ok());
//! }
//! Err(e) => {
//! // This can fail for multiple reason, most common being privileges.
//! assert!(e.code > 0);
//! }
//! }
//! ```
pub mod api;
pub mod errors;
pub mod flags;
pub mod types;
#[cfg(test)]
mod tests {
use super::*;
use flags::*;
#[test]
fn test_consts() {
assert_eq!(FAN_ACCESS, 0x00000001);
assert_eq!(FAN_ACCESS, 0x00000001); /* File was accessed */
assert_eq!(FAN_MODIFY, 0x00000002); /* File was modified */
assert_eq!(FAN_ATTRIB, 0x00000004); /* Metadata changed */
assert_eq!(FAN_CLOSE_WRITE, 0x00000008); /* Writtable file closed */
assert_eq!(FAN_CLOSE_NOWRITE, 0x00000010); /* Unwrittable file closed */
assert_eq!(FAN_OPEN, 0x00000020); /* File was opened */
assert_eq!(FAN_MOVED_FROM, 0x00000040); /* File was moved from X */
assert_eq!(FAN_MOVED_TO, 0x00000080); /* File was moved to Y */
assert_eq!(FAN_CREATE, 0x00000100); /* Subfile was created */
assert_eq!(FAN_DELETE, 0x00000200); /* Subfile was deleted */
assert_eq!(FAN_DELETE_SELF, 0x00000400); /* Self was deleted */
assert_eq!(FAN_MOVE_SELF, 0x00000800); /* Self was moved */
assert_eq!(FAN_OPEN_EXEC, 0x00001000); /* File was opened for exec */
assert_eq!(FAN_Q_OVERFLOW, 0x00004000); /* Event queued overflowed */
assert_eq!(FAN_FS_ERROR, 0x00008000); /* Filesystem error */
assert_eq!(FAN_OPEN_PERM, 0x00010000); /* File open in perm check */
assert_eq!(FAN_ACCESS_PERM, 0x00020000); /* File accessed in perm check */
assert_eq!(FAN_OPEN_EXEC_PERM, 0x00040000); /* File open/exec in perm check */
assert_eq!(FAN_EVENT_ON_CHILD, 0x08000000); /* Interested in child events */
assert_eq!(FAN_RENAME, 0x10000000); /* File was renamed */
assert_eq!(FAN_ONDIR, 0x40000000); /* Event occurred against dir */
/* helper events */
assert_eq!(FAN_CLOSE, (FAN_CLOSE_WRITE | FAN_CLOSE_NOWRITE)); /* close */
assert_eq!(FAN_MOVE, (FAN_MOVED_FROM | FAN_MOVED_TO)); /* moves */
/* flags used for fanotify_init() */
assert_eq!(FAN_CLOEXEC, 0x00000001);
assert_eq!(FAN_NONBLOCK, 0x00000002);
/* These are NOT bitwise flags. Both bits are used together. */
assert_eq!(FAN_CLASS_NOTIF, 0x00000000);
assert_eq!(FAN_CLASS_CONTENT, 0x00000004);
assert_eq!(FAN_CLASS_PRE_CONTENT, 0x00000008);
}
}