-
Notifications
You must be signed in to change notification settings - Fork 17.3k
Expand file tree
/
Copy pathmount.rs
More file actions
62 lines (57 loc) · 1.57 KB
/
mount.rs
File metadata and controls
62 lines (57 loc) · 1.57 KB
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
57
58
59
60
61
62
use crate::{FsPath, LibcReturn};
use libc::c_ulong;
use std::ptr;
impl FsPath {
pub fn bind_mount_to(&self, path: &FsPath) -> std::io::Result<()> {
unsafe {
libc::mount(
self.as_ptr(),
path.as_ptr(),
ptr::null(),
libc::MS_BIND,
ptr::null(),
)
.as_os_err()
}
}
pub fn remount_with_flags(&self, flags: c_ulong) -> std::io::Result<()> {
unsafe {
libc::mount(
ptr::null(),
self.as_ptr(),
ptr::null(),
libc::MS_BIND | libc::MS_REMOUNT | flags,
ptr::null(),
)
.as_os_err()
}
}
pub fn move_mount_to(&self, path: &FsPath) -> std::io::Result<()> {
unsafe {
libc::mount(
self.as_ptr(),
path.as_ptr(),
ptr::null(),
libc::MS_MOVE,
ptr::null(),
)
.as_os_err()
}
}
pub fn unmount(&self) -> std::io::Result<()> {
unsafe { libc::umount2(self.as_ptr(), libc::MNT_DETACH).as_os_err() }
}
pub fn set_mount_private(&self, recursive: bool) -> std::io::Result<()> {
let flag = if recursive { libc::MS_REC } else { 0 };
unsafe {
libc::mount(
ptr::null(),
self.as_ptr(),
ptr::null(),
libc::MS_PRIVATE | flag,
ptr::null(),
)
.as_os_err()
}
}
}