Skip to main content

endpoint_sec/event/
event_mount.rs

1//! [`EventMount`]
2
3use endpoint_sec_sys::{es_event_mount_t, statfs};
4#[cfg(feature = "macos_15_0_0")]
5use endpoint_sec_sys::es_mount_disposition_t;
6
7/// Mount a file system event.
8#[doc(alias = "es_event_mount_t")]
9#[cfg_attr(not(feature = "macos_15_0_0"), allow(dead_code))]
10pub struct EventMount<'a> {
11    /// Raw event
12    pub(crate) raw: &'a es_event_mount_t,
13    /// Message version
14    pub(crate) version: u32,
15}
16
17impl<'a> EventMount<'a> {
18    /// The file system stats for the file system being mounted.
19    #[inline(always)]
20    pub fn statfs(&self) -> &'a statfs {
21        // Safety: 'a tied to self, object obtained through ES
22        unsafe { self.raw.statfs() }
23    }
24
25    /// The disposition of the device being mounted.
26    ///
27    /// Note: only available if message version >= 8.
28    #[inline(always)]
29    #[cfg(feature = "macos_15_0_0")]
30    pub fn disposition(&self) -> Option<es_mount_disposition_t> {
31        (self.version >= 8).then_some(self.raw.disposition)
32    }
33}
34
35// Safety: safe to send across threads: does not contain any interior mutability nor depend on current thread state
36unsafe impl Send for EventMount<'_> {}
37// Safety: safe to share across threads: does not contain any interior mutability nor depend on current thread state
38unsafe impl Sync for EventMount<'_> {}
39
40impl_debug_eq_hash_with_functions!(EventMount<'a>; statfs, #[cfg(feature = "macos_15_0_0")] disposition);