lx 0.4.0

A no_std crate to use Linux system calls
Documentation
use core::ffi::CStr;

use crate::{
    eprintln,
    mount,
    umount2,
};

pub struct AutoUnmount<'a> {
    dir_name: &'a CStr,
    umount_flags: i32,
}

impl<'a> AutoUnmount<'a> {
    pub fn new(
        dev_name: &CStr,
        dir_name: &'a CStr,
        fs_type: Option<&CStr>,
        flags: u32,
        data: Option<&CStr>,
        umount_flags: i32,
    ) -> crate::Result<Self> {
        mount(dev_name, dir_name, fs_type, flags, data)?;
        Ok(Self {
            dir_name,
            umount_flags,
        })
    }
}

impl<'a> Drop for AutoUnmount<'a> {
    fn drop(&mut self) {
        if let Err(e) = umount2(self.dir_name, self.umount_flags) {
            let dir_name = self.dir_name.to_str().unwrap_or("(UTF-8 error)");
            eprintln!(
                "umount2({dir_name}, {flags}): {e}",
                flags = self.umount_flags
            );
        }
    }
}