use crate::log::log_success; use std::ffi::CString; use std::fs::create_dir; pub fn mount_system() -> Result<(), Box> { let mounts: &[(&str, &str, Option<&str>)] = &[ ("/proc", "proc", None), ("/sys", "sysfs", None), ("/dev", "devtmpfs", Some("devtmpfs")), ("/tmp", "tmpfs", None), ("/run", "tmpfs", None), ]; unsafe { for &(target, fstype, source) in mounts { let target_c = CString::new(target)?; let fstype_c = CString::new(fstype)?; let source_c = source.map(|s| CString::new(s).unwrap()); let _ = create_dir(target); let source_ptr = source_c.as_ref().map_or(std::ptr::null(), |s| s.as_ptr()); let ret = libc::syscall( libc::SYS_mount, source_ptr, target_c.as_ptr(), fstype_c.as_ptr(), 0 as libc::c_ulong, std::ptr::null::(), ); if ret != 0 { return Err(format!( "Failed to mount {}: {}", target, std::io::Error::last_os_error() ) .into()); } log_success(&format!("Mounting {}...", target)); } } Ok(()) }