lx 0.4.0

A no_std crate to use Linux system calls
Documentation
use core::{
    ffi::CStr,
    ptr,
};

use super::abi::*;
use crate::unit_result_from_value;

pub const MS_RDONLY: u32 = 0x1;
pub const MS_NOSUID: u32 = 0x2;
pub const MS_NODEV: u32 = 0x4;
pub const MS_NOEXEC: u32 = 0x8;
pub const MS_SYNCHRONOUS: u32 = 0x10;
pub const MS_REMOUNT: u32 = 0x20;
pub const MS_MANDLOCK: u32 = 0x40;
pub const MS_DIRSYNC: u32 = 0x80;
pub const MS_NOSYMFOLLOW: u32 = 0x100;
pub const MS_NOATIME: u32 = 0x400;
pub const MS_NODIRATIME: u32 = 0x800;
pub const MS_BIND: u32 = 0x1000;
pub const MS_MOVE: u32 = 0x2000;
pub const MS_REC: u32 = 0x4000;
pub const MS_SILENT: u32 = 0x8000;
pub const MS_POSIXACL: u32 = 0x10000;
pub const MS_UNBINDABLE: u32 = 0x20000;
pub const MS_PRIVATE: u32 = 0x40000;
pub const MS_SLAVE: u32 = 0x80000;
pub const MS_SHARED: u32 = 0x100000;
pub const MS_RELATIME: u32 = 0x200000;
pub const MS_KERNMOUNT: u32 = 0x400000;
pub const MS_I_VERSION: u32 = 0x800000;
pub const MS_STRICTATIME: u32 = 0x1000000;
pub const MS_LAZYTIME: u32 = 0x2000000;
pub const MS_NOREMOTELOCK: u32 = 0x8000000;
pub const MS_NOSEC: u32 = 0x10000000;
pub const MS_BORN: u32 = 0x20000000;
pub const MS_ACTIVE: u32 = 0x40000000;
pub const MS_NOUSER: u32 = 0x80000000;

pub const MNT_FORCE: i32 = 0x1;
pub const MNT_DETACH: i32 = 0x2;
pub const MNT_EXPIRE: i32 = 0x4;

#[inline]
pub fn mount(
    dev_name: &CStr,
    dir_name: &CStr,
    fs_type: Option<&CStr>,
    flags: u32,
    data: Option<&CStr>,
) -> crate::Result<()> {
    let data = match data {
        Some(v) => v.as_ptr(),
        None => ptr::null(),
    };
    let fs_type = match fs_type {
        Some(v) => v.as_ptr(),
        None => ptr::null(),
    };
    let ret = unsafe {
        syscall_5(
            165,
            dev_name.as_ptr() as usize,
            dir_name.as_ptr() as usize,
            fs_type as usize,
            flags as usize,
            data as usize,
        ) as i32
    };
    unit_result_from_value(ret)
}

#[inline]
pub fn umount2(name: &CStr, flags: i32) -> crate::Result<()> {
    let ret = unsafe { syscall_2(166, name.as_ptr() as usize, flags as usize) as i32 };
    unit_result_from_value(ret)
}