1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
use crate::log::log_success;
use std::ffi::CString;
use std::fs::create_dir;
pub fn mount_system() -> Result<(), Box<dyn std::error::Error>> {
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::<libc::c_void>(),
);
if ret != 0 {
return Err(format!(
"Failed to mount {}: {}",
target,
std::io::Error::last_os_error()
)
.into());
}
log_success(&format!("Mounting {}...", target));
}
}
Ok(())
}
|