1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use crate::platform::{FilesystemType, Mountflags};
use crate::string::unix_str::UnixStr;
use crate::Result;
use sc::syscall;
/// Mount a device.
/// Attempt to mount a device from `source` to `target` specifying a `FilesystemType` and `flags`.
/// Some filesystems allow providing additional data, which goes in `data`.
/// See the [linux docs for details](https://man7.org/linux/man-pages/man2/mount.2.html).
/// # Errors
/// See above
pub fn mount(
source: &UnixStr,
target: &UnixStr,
fs_type: FilesystemType,
flags: Mountflags,
data: Option<&UnixStr>,
) -> Result<()> {
unsafe {
if let Some(data) = data {
let res = syscall!(
MOUNT,
source.as_ptr(),
target.as_ptr(),
fs_type.0,
flags.bits(),
data.as_ptr()
);
bail_on_below_zero!(res, "`MOUNT` syscall failed");
} else {
let res = syscall!(
MOUNT,
source.as_ptr(),
target.as_ptr(),
fs_type.0,
flags.bits(),
0
);
bail_on_below_zero!(res, "`MOUNT` syscall failed");
}
}
Ok(())
}
/// Unmount a device.
/// Attempts to unmount the device at `target`.
/// See the [linux docs for details](https://man7.org/linux/man-pages/man2/umount.2.html).
/// # Errors
/// See above.
pub fn unmount(target: &UnixStr) -> Result<()> {
unsafe {
let res = syscall!(UMOUNT2, target.as_ptr(), 0);
bail_on_below_zero!(res, "`UNMOUNT2` syscall failed");
}
Ok(())
}