Function nc::mkdirat

source ·
pub unsafe fn mkdirat<P: AsRef<Path>>(
    dirfd: i32,
    filename: P,
    mode: mode_t
) -> Result<(), Errno>
Expand description

Create a directory.

§Example

let path = "/tmp/nc-mkdir";
let ret = unsafe { nc::mkdirat(nc::AT_FDCWD, path, 0o755) };
assert!(ret.is_ok());
let ret = unsafe { nc::unlinkat(nc::AT_FDCWD, path, nc::AT_REMOVEDIR) };
assert!(ret.is_ok());
Examples found in repository?
examples/mount.rs (line 7)
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());
}