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 { let errno = errno::errno().0; return Err(format!( "Failed to mount {}: {}", target, std::io::Error::from_raw_os_error(errno) ) .into()); } println!("\x1b[32m * \x1b[0m Mounting {}...", target); } } Ok(()) }