From afe6b0d5d59c90b3765914eb771ad8237d40a90f Mon Sep 17 00:00:00 2001 From: namilsk Date: Wed, 31 Dec 2025 17:31:34 +0300 Subject: Started work on vigil init system --- init/src/mounts/rescue.rs | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 init/src/mounts/rescue.rs (limited to 'init/src/mounts/rescue.rs') diff --git a/init/src/mounts/rescue.rs b/init/src/mounts/rescue.rs new file mode 100644 index 0000000..ba058f4 --- /dev/null +++ b/init/src/mounts/rescue.rs @@ -0,0 +1,50 @@ +use libc::{self}; +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(()) +} -- cgit v1.2.3