rustix/mount/
mount_unmount.rs1use crate::backend::mount::types::{
4 InternalMountFlags, MountFlags, MountFlagsArg, MountPropagationFlags, UnmountFlags,
5};
6use crate::ffi::CStr;
7use crate::path::{self, option_into_with_c_str};
8use crate::{backend, io};
9
10#[inline]
17pub fn mount<Source: path::Arg, Target: path::Arg, Fs: path::Arg, Data: path::Arg>(
18 source: Source,
19 target: Target,
20 file_system_type: Fs,
21 flags: MountFlags,
22 data: Data,
23) -> io::Result<()> {
24 source.into_with_c_str(|source| {
25 target.into_with_c_str(|target| {
26 file_system_type.into_with_c_str(|file_system_type| {
27 data.into_with_c_str(|data| {
28 backend::mount::syscalls::mount(
29 Some(source),
30 target,
31 Some(file_system_type),
32 MountFlagsArg(flags.bits()),
33 Some(data),
34 )
35 })
36 })
37 })
38 })
39}
40
41#[inline]
52pub fn mount2<Source: path::Arg, Target: path::Arg, Fs: path::Arg>(
53 source: Option<Source>,
54 target: Target,
55 file_system_type: Option<Fs>,
56 flags: MountFlags,
57 data: Option<&CStr>,
58) -> io::Result<()> {
59 option_into_with_c_str(source, |source| {
60 target.into_with_c_str(|target| {
61 option_into_with_c_str(file_system_type, |file_system_type| {
62 backend::mount::syscalls::mount(
63 source,
64 target,
65 file_system_type,
66 MountFlagsArg(flags.bits()),
67 data,
68 )
69 })
70 })
71 })
72}
73
74#[inline]
81#[doc(alias = "mount")]
82#[doc(alias = "MS_REMOUNT")]
83pub fn mount_remount<Target: path::Arg, Data: path::Arg>(
84 target: Target,
85 flags: MountFlags,
86 data: Data,
87) -> io::Result<()> {
88 target.into_with_c_str(|target| {
89 data.into_with_c_str(|data| {
90 backend::mount::syscalls::mount(
91 None,
92 target,
93 None,
94 MountFlagsArg(InternalMountFlags::REMOUNT.bits() | flags.bits()),
95 Some(data),
96 )
97 })
98 })
99}
100
101#[inline]
108#[doc(alias = "mount")]
109#[doc(alias = "MS_BIND")]
110pub fn mount_bind<Source: path::Arg, Target: path::Arg>(
111 source: Source,
112 target: Target,
113) -> io::Result<()> {
114 source.into_with_c_str(|source| {
115 target.into_with_c_str(|target| {
116 backend::mount::syscalls::mount(
117 Some(source),
118 target,
119 None,
120 MountFlagsArg(MountFlags::BIND.bits()),
121 None,
122 )
123 })
124 })
125}
126
127#[inline]
134#[doc(alias = "mount")]
135#[doc(alias = "MS_REC")]
136pub fn mount_recursive_bind<Source: path::Arg, Target: path::Arg>(
137 source: Source,
138 target: Target,
139) -> io::Result<()> {
140 source.into_with_c_str(|source| {
141 target.into_with_c_str(|target| {
142 backend::mount::syscalls::mount(
143 Some(source),
144 target,
145 None,
146 MountFlagsArg(MountFlags::BIND.bits() | MountPropagationFlags::REC.bits()),
147 None,
148 )
149 })
150 })
151}
152
153#[inline]
160#[doc(alias = "mount")]
161pub fn mount_change<Target: path::Arg>(
162 target: Target,
163 flags: MountPropagationFlags,
164) -> io::Result<()> {
165 target.into_with_c_str(|target| {
166 backend::mount::syscalls::mount(None, target, None, MountFlagsArg(flags.bits()), None)
167 })
168}
169
170#[inline]
181#[doc(alias = "mount")]
182#[doc(alias = "MS_MOVE")]
183pub fn mount_move<Source: path::Arg, Target: path::Arg>(
184 source: Source,
185 target: Target,
186) -> io::Result<()> {
187 source.into_with_c_str(|source| {
188 target.into_with_c_str(|target| {
189 backend::mount::syscalls::mount(
190 Some(source),
191 target,
192 None,
193 MountFlagsArg(InternalMountFlags::MOVE.bits()),
194 None,
195 )
196 })
197 })
198}
199
200#[inline]
207#[doc(alias = "umount", alias = "umount2")]
208pub fn unmount<Target: path::Arg>(target: Target, flags: UnmountFlags) -> io::Result<()> {
209 target.into_with_c_str(|target| backend::mount::syscalls::unmount(target, flags))
210}