xref: /DragonOS/user/apps/test-mount/src/main.rs (revision 4b0170bd6bb374d0e9699a0076cc23b976ad6db7)
1 use core::ffi::{c_char, c_void};
2 use libc::{mount, MS_BIND};
3 use std::fs;
4 use std::path::Path;
5 use std::time;
6 fn main() {
7     let path = Path::new("mnt/tmp");
8     let dir = fs::create_dir_all(path);
9     if dir.is_err() {
10         panic!("mkdir /mnt/tmp fail.");
11     }
12     let clock = time::Instant::now();
13     let source = b"\0".as_ptr() as *const c_char;
14     let target = b"/mnt/tmp\0".as_ptr() as *const c_char;
15     let fstype = b"ramfs\0".as_ptr() as *const c_char;
16     let flags = MS_BIND;
17     let data = std::ptr::null() as *const c_void;
18     let result = unsafe { mount(source, target, fstype, flags, data) };
19     let path = Path::new("mnt/tmp/tmp");
20     let dir = fs::create_dir_all(path);
21     if dir.is_err() {
22         panic!("mkdir /mnt/tmp/tmp fail.");
23     }
24     let target = b"/mnt/tmp/tmp\0".as_ptr() as *const c_char;
25     let result = unsafe { mount(source, target, fstype, flags, data) };
26     if result == 0 {
27         println!("Mount successful");
28     } else {
29         println!("Mount failed");
30     }
31     let dur = clock.elapsed();
32     println!("mount costing time: {} ns", dur.as_nanos());
33 }
34