Function nc::mount

source ·
pub unsafe fn mount<P: AsRef<Path>>(
    dev_name: P,
    dir_name: P,
    fs_type: P,
    flags: usize,
    data: usize
) -> Result<(), Errno>
Expand description

Mount filesystem.

§Example

let target_dir = "/tmp/nc-mount";
let ret = unsafe { nc::mkdirat(nc::AT_FDCWD, target_dir, 0o755) };
assert!(ret.is_ok());

let src_dir = "/etc";
let fs_type = "";
let mount_flags = nc::MS_BIND | nc::MS_RDONLY;
let data = 0;
let ret = unsafe { nc::mount(src_dir, target_dir, fs_type, mount_flags, data) };
assert!(ret.is_err());
assert_eq!(ret, Err(nc::EPERM));

let ret = unsafe { nc::unlinkat(nc::AT_FDCWD, target_dir, nc::AT_REMOVEDIR) };
assert!(ret.is_ok());
Examples found in repository?
examples/mount.rs (line 14)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
fn main() {
    let target_dir = "/tmp/nc-mount";
    let ret = unsafe { nc::mkdirat(nc::AT_FDCWD, target_dir, 0o755) };
    assert!(ret.is_ok());

    let src_dir = "/etc";
    let fs_type = "";
    let mount_flags = nc::MS_BIND | nc::MS_RDONLY;
    let data = 0;
    let ret = unsafe { nc::mount(src_dir, target_dir, fs_type, mount_flags, data) };
    assert!(ret.is_ok());
    let flags = 0;
    let ret = unsafe { nc::umount2(target_dir, flags) };
    assert!(ret.is_ok());
    let ret = unsafe { nc::unlinkat(nc::AT_FDCWD, target_dir, nc::AT_REMOVEDIR) };
    assert!(ret.is_ok());
}