1 //! Linux `mount`.
2
3 use crate::backend::fs::types::{
4 InternalMountFlags, MountFlags, MountFlagsArg, MountPropagationFlags,
5 };
6 use crate::{backend, io, path};
7
8 /// `mount(source, target, filesystemtype, mountflags, data)`
9 ///
10 /// # References
11 /// - [Linux]
12 ///
13 /// [Linux]: https://man7.org/linux/man-pages/man2/mount.2.html
14 #[inline]
mount<Source: path::Arg, Target: path::Arg, Fs: path::Arg, Data: path::Arg>( source: Source, target: Target, file_system_type: Fs, flags: MountFlags, data: Data, ) -> io::Result<()>15 pub fn mount<Source: path::Arg, Target: path::Arg, Fs: path::Arg, Data: path::Arg>(
16 source: Source,
17 target: Target,
18 file_system_type: Fs,
19 flags: MountFlags,
20 data: Data,
21 ) -> io::Result<()> {
22 source.into_with_c_str(|source| {
23 target.into_with_c_str(|target| {
24 file_system_type.into_with_c_str(|file_system_type| {
25 data.into_with_c_str(|data| {
26 backend::fs::syscalls::mount(
27 Some(source),
28 target,
29 Some(file_system_type),
30 MountFlagsArg(flags.bits()),
31 Some(data),
32 )
33 })
34 })
35 })
36 })
37 }
38
39 /// `mount(null, target, null, MS_REMOUNT | mountflags, data)`
40 ///
41 /// # References
42 /// - [Linux]
43 ///
44 /// [Linux]: https://man7.org/linux/man-pages/man2/mount.2.html
45 #[inline]
remount<Target: path::Arg, Data: path::Arg>( target: Target, flags: MountFlags, data: Data, ) -> io::Result<()>46 pub fn remount<Target: path::Arg, Data: path::Arg>(
47 target: Target,
48 flags: MountFlags,
49 data: Data,
50 ) -> io::Result<()> {
51 target.into_with_c_str(|target| {
52 data.into_with_c_str(|data| {
53 backend::fs::syscalls::mount(
54 None,
55 target,
56 None,
57 MountFlagsArg(InternalMountFlags::REMOUNT.bits() | flags.bits()),
58 Some(data),
59 )
60 })
61 })
62 }
63
64 /// `mount(source, target, null, MS_BIND, null)`
65 ///
66 /// # References
67 /// - [Linux]
68 ///
69 /// [Linux]: https://man7.org/linux/man-pages/man2/mount.2.html
70 #[inline]
bind_mount<Source: path::Arg, Target: path::Arg>( source: Source, target: Target, ) -> io::Result<()>71 pub fn bind_mount<Source: path::Arg, Target: path::Arg>(
72 source: Source,
73 target: Target,
74 ) -> io::Result<()> {
75 source.into_with_c_str(|source| {
76 target.into_with_c_str(|target| {
77 backend::fs::syscalls::mount(
78 Some(source),
79 target,
80 None,
81 MountFlagsArg(MountFlags::BIND.bits()),
82 None,
83 )
84 })
85 })
86 }
87
88 /// `mount(source, target, null, MS_BIND | MS_REC, null)`
89 ///
90 /// # References
91 /// - [Linux]
92 ///
93 /// [Linux]: https://man7.org/linux/man-pages/man2/mount.2.html
94 #[inline]
recursive_bind_mount<Source: path::Arg, Target: path::Arg>( source: Source, target: Target, ) -> io::Result<()>95 pub fn recursive_bind_mount<Source: path::Arg, Target: path::Arg>(
96 source: Source,
97 target: Target,
98 ) -> io::Result<()> {
99 source.into_with_c_str(|source| {
100 target.into_with_c_str(|target| {
101 backend::fs::syscalls::mount(
102 Some(source),
103 target,
104 None,
105 MountFlagsArg(MountFlags::BIND.bits() | MountPropagationFlags::REC.bits()),
106 None,
107 )
108 })
109 })
110 }
111
112 /// `mount(null, target, null, mountflags, null)`
113 ///
114 /// # References
115 /// - [Linux]
116 ///
117 /// [Linux]: https://man7.org/linux/man-pages/man2/mount.2.html
118 #[inline]
change_mount<Target: path::Arg>( target: Target, flags: MountPropagationFlags, ) -> io::Result<()>119 pub fn change_mount<Target: path::Arg>(
120 target: Target,
121 flags: MountPropagationFlags,
122 ) -> io::Result<()> {
123 target.into_with_c_str(|target| {
124 backend::fs::syscalls::mount(None, target, None, MountFlagsArg(flags.bits()), None)
125 })
126 }
127
128 /// `mount(source, target, null, MS_MOVE, null)`
129 ///
130 /// # References
131 /// - [Linux]
132 ///
133 /// [Linux]: https://man7.org/linux/man-pages/man2/mount.2.html
134 #[inline]
move_mount<Source: path::Arg, Target: path::Arg>( source: Source, target: Target, ) -> io::Result<()>135 pub fn move_mount<Source: path::Arg, Target: path::Arg>(
136 source: Source,
137 target: Target,
138 ) -> io::Result<()> {
139 source.into_with_c_str(|source| {
140 target.into_with_c_str(|target| {
141 backend::fs::syscalls::mount(
142 Some(source),
143 target,
144 None,
145 MountFlagsArg(InternalMountFlags::MOVE.bits()),
146 None,
147 )
148 })
149 })
150 }
151