1//! linux_raw syscalls supporting `rustix::mount`.
2//!
3//! # Safety
4//!
5//! See the `rustix::backend` module documentation for details.
6#![allow(unsafe_code)]
7#![allow(clippy::undocumented_unsafe_blocks)]
8
9use crate::backend::conv::ret;
10#[cfg(feature = "mount")]
11use crate::backend::conv::{ret_owned_fd, slice, zero};
12#[cfg(feature = "mount")]
13use crate::fd::{BorrowedFd, OwnedFd};
14use crate::ffi::CStr;
15use crate::io;
16
17#[inline]
18pub(crate) fn mount(
19 source: Option<&CStr>,
20 target: &CStr,
21 file_system_type: Option<&CStr>,
22 flags: super::types::MountFlagsArg,
23 data: Option<&CStr>,
24) -> io::Result<()> {
25 unsafe {
26 ret(raw:syscall_readonly!(
27 __NR_mount,
28 source,
29 target,
30 file_system_type,
31 flags,
32 data
33 ))
34 }
35}
36
37#[inline]
38pub(crate) fn unmount(target: &CStr, flags: super::types::UnmountFlags) -> io::Result<()> {
39 unsafe { ret(raw:syscall_readonly!(__NR_umount2, target, flags)) }
40}
41
42#[cfg(feature = "mount")]
43#[inline]
44pub(crate) fn fsopen(fs_name: &CStr, flags: super::types::FsOpenFlags) -> io::Result<OwnedFd> {
45 unsafe { ret_owned_fd(syscall_readonly!(__NR_fsopen, fs_name, flags)) }
46}
47
48#[cfg(feature = "mount")]
49#[inline]
50pub(crate) fn fsmount(
51 fs_fd: BorrowedFd<'_>,
52 flags: super::types::FsMountFlags,
53 attr_flags: super::types::MountAttrFlags,
54) -> io::Result<OwnedFd> {
55 unsafe { ret_owned_fd(syscall_readonly!(__NR_fsmount, fs_fd, flags, attr_flags)) }
56}
57
58#[cfg(feature = "mount")]
59#[inline]
60pub(crate) fn move_mount(
61 from_dfd: BorrowedFd<'_>,
62 from_pathname: &CStr,
63 to_dfd: BorrowedFd<'_>,
64 to_pathname: &CStr,
65 flags: super::types::MoveMountFlags,
66) -> io::Result<()> {
67 unsafe {
68 ret(syscall_readonly!(
69 __NR_move_mount,
70 from_dfd,
71 from_pathname,
72 to_dfd,
73 to_pathname,
74 flags
75 ))
76 }
77}
78
79#[cfg(feature = "mount")]
80#[inline]
81pub(crate) fn open_tree(
82 dfd: BorrowedFd<'_>,
83 filename: &CStr,
84 flags: super::types::OpenTreeFlags,
85) -> io::Result<OwnedFd> {
86 unsafe { ret_owned_fd(syscall_readonly!(__NR_open_tree, dfd, filename, flags)) }
87}
88
89#[cfg(feature = "mount")]
90#[inline]
91pub(crate) fn fspick(
92 dfd: BorrowedFd<'_>,
93 path: &CStr,
94 flags: super::types::FsPickFlags,
95) -> io::Result<OwnedFd> {
96 unsafe { ret_owned_fd(syscall_readonly!(__NR_fspick, dfd, path, flags)) }
97}
98
99#[cfg(feature = "mount")]
100#[inline]
101pub(crate) fn fsconfig_set_flag(fs_fd: BorrowedFd<'_>, key: &CStr) -> io::Result<()> {
102 unsafe {
103 ret(syscall_readonly!(
104 __NR_fsconfig,
105 fs_fd,
106 super::types::FsConfigCmd::SetFlag,
107 key,
108 zero(),
109 zero()
110 ))
111 }
112}
113
114#[cfg(feature = "mount")]
115#[inline]
116pub(crate) fn fsconfig_set_string(
117 fs_fd: BorrowedFd<'_>,
118 key: &CStr,
119 value: &CStr,
120) -> io::Result<()> {
121 unsafe {
122 ret(syscall_readonly!(
123 __NR_fsconfig,
124 fs_fd,
125 super::types::FsConfigCmd::SetString,
126 key,
127 value,
128 zero()
129 ))
130 }
131}
132
133#[cfg(feature = "mount")]
134#[inline]
135pub(crate) fn fsconfig_set_binary(
136 fs_fd: BorrowedFd<'_>,
137 key: &CStr,
138 value: &[u8],
139) -> io::Result<()> {
140 let (value_addr, value_len) = slice(value);
141 unsafe {
142 ret(syscall_readonly!(
143 __NR_fsconfig,
144 fs_fd,
145 super::types::FsConfigCmd::SetBinary,
146 key,
147 value_addr,
148 value_len
149 ))
150 }
151}
152
153#[cfg(feature = "mount")]
154#[inline]
155pub(crate) fn fsconfig_set_fd(
156 fs_fd: BorrowedFd<'_>,
157 key: &CStr,
158 fd: BorrowedFd<'_>,
159) -> io::Result<()> {
160 unsafe {
161 ret(syscall_readonly!(
162 __NR_fsconfig,
163 fs_fd,
164 super::types::FsConfigCmd::SetFd,
165 key,
166 zero(),
167 fd
168 ))
169 }
170}
171
172#[cfg(feature = "mount")]
173#[inline]
174pub(crate) fn fsconfig_set_path(
175 fs_fd: BorrowedFd<'_>,
176 key: &CStr,
177 path: &CStr,
178 fd: BorrowedFd<'_>,
179) -> io::Result<()> {
180 unsafe {
181 ret(syscall_readonly!(
182 __NR_fsconfig,
183 fs_fd,
184 super::types::FsConfigCmd::SetPath,
185 key,
186 path,
187 fd
188 ))
189 }
190}
191
192#[cfg(feature = "mount")]
193#[inline]
194pub(crate) fn fsconfig_set_path_empty(
195 fs_fd: BorrowedFd<'_>,
196 key: &CStr,
197 fd: BorrowedFd<'_>,
198) -> io::Result<()> {
199 unsafe {
200 ret(syscall_readonly!(
201 __NR_fsconfig,
202 fs_fd,
203 super::types::FsConfigCmd::SetPathEmpty,
204 key,
205 cstr!(""),
206 fd
207 ))
208 }
209}
210
211#[cfg(feature = "mount")]
212#[inline]
213pub(crate) fn fsconfig_create(fs_fd: BorrowedFd<'_>) -> io::Result<()> {
214 unsafe {
215 ret(syscall_readonly!(
216 __NR_fsconfig,
217 fs_fd,
218 super::types::FsConfigCmd::Create,
219 zero(),
220 zero(),
221 zero()
222 ))
223 }
224}
225
226#[cfg(feature = "mount")]
227#[inline]
228pub(crate) fn fsconfig_reconfigure(fs_fd: BorrowedFd<'_>) -> io::Result<()> {
229 unsafe {
230 ret(syscall_readonly!(
231 __NR_fsconfig,
232 fs_fd,
233 super::types::FsConfigCmd::Reconfigure,
234 zero(),
235 zero(),
236 zero()
237 ))
238 }
239}
240