Skip to main content

mount/
mount.rs

1// Copyright (c) 2020 Xu Shaohua <shaohua@biofan.org>. All rights reserved.
2// Use of this source is governed by Apache-2.0 License that can be found
3// in the LICENSE file.
4
5fn main() {
6    let target_dir = "/tmp/nc-mount";
7    let ret = unsafe { nc::mkdirat(nc::AT_FDCWD, target_dir, 0o755) };
8    assert!(ret.is_ok());
9
10    let src_dir = "/etc";
11    let fs_type = "";
12    let mount_flags = nc::MS_BIND | nc::MS_RDONLY;
13    let data = std::ptr::null_mut();
14    let ret = unsafe { nc::mount(src_dir, target_dir, fs_type, mount_flags, data) };
15    assert!(ret.is_ok());
16    let ret = unsafe { nc::umount2(target_dir, nc::UMOUNT_NOFOLLOW) };
17    assert!(ret.is_ok());
18    let ret = unsafe { nc::unlinkat(nc::AT_FDCWD, target_dir, nc::AT_REMOVEDIR) };
19    assert!(ret.is_ok());
20}