os_core/linux/
mod.rs

1/// unshare copies resources into a new context that will not affect the other contexts (from other processes and threads)
2/// 
3/// create new namespaces, open-file-tables, virtual-memory mappings, and filesystem information (current directory, root directory, and umask)
4pub fn sys_unshare (flags: i32) -> i32 {
5    unsafe {
6        libc::unshare(flags)
7    }
8}
9
10/// change the root directory for pathname resolution in the calling process
11pub fn sys_chroot(path: &str) -> i32 {
12    let mut path = path.to_owned();
13    path.push('\0');
14
15    let path = (*path).as_ptr() as *const i8;
16    unsafe {
17        libc::chroot(path)
18    }
19}
20
21/// Switch the current root, in the current mount-namespace, to a directory (that must be in a separate mount from the current root)
22/// and then mount the current root (now the previous root) on a directory inside the new root -- should probably unshare the
23/// mount namespace prior
24pub fn sys_pivot_root(newroot: &str, oldroot_mnt_point: &str) -> i32 {
25    let mut newroot = newroot.to_owned();
26    let mut oldroot_mnt_point = oldroot_mnt_point.to_owned();
27
28    newroot.push('\0');
29    oldroot_mnt_point.push('\0');
30
31    unsafe {
32        libc::syscall(libc::SYS_pivot_root, newroot.as_ptr() as *const u8, oldroot_mnt_point.as_ptr() as *const u8) as i32
33    }
34}