use std::path::{Path, PathBuf};
use crate::ffi_utils;
#[derive(Debug)]
pub struct MntEnt {
inner: *mut libmount::mntent,
fs_name: PathBuf,
mount_point: PathBuf,
fs_type: String,
options: String,
backup_frequency: i32,
pass_number: i32,
}
impl MntEnt {
#[doc(hidden)]
#[allow(dead_code)]
pub(crate) fn from_raw_parts(ptr: *mut libmount::mntent) -> MntEnt {
let fs_name = unsafe { ffi_utils::const_c_char_array_to_path_buf((*ptr).mnt_fsname) };
let mount_point = unsafe { ffi_utils::const_c_char_array_to_path_buf((*ptr).mnt_dir) };
let fs_type = unsafe { ffi_utils::c_char_array_to_string((*ptr).mnt_type) };
let options = unsafe { ffi_utils::c_char_array_to_string((*ptr).mnt_opts) };
let backup_frequency = unsafe { (*ptr).mnt_freq };
let pass_number = unsafe { (*ptr).mnt_passno };
Self {
inner: ptr,
fs_name,
mount_point,
fs_type,
options,
backup_frequency,
pass_number,
}
}
pub fn device_name(&self) -> &Path {
&self.fs_name
}
pub fn file_system_type(&self) -> &str {
&self.fs_type
}
pub fn mount_point(&self) -> &Path {
&self.mount_point
}
pub fn mount_options(&self) -> &str {
&self.options
}
pub fn backup_frequency(&self) -> i32 {
self.backup_frequency
}
pub fn pass_number(&self) -> i32 {
self.pass_number
}
}
impl Drop for MntEnt {
fn drop(&mut self) {
log::debug!("MntEnt::drop deallocating `MntEnt` instance");
unsafe { libmount::mnt_free_mntent(self.inner) }
}
}