Debian Codegraph @

debian/rust-vendor/rustix/src/mount/fsopen.rs

raw
1 //! `fsopen` and related functions in Linux's `mount` API.
2
3 use crate::backend::mount::types::{
4 FsMountFlags, FsOpenFlags, FsPickFlags, MountAttrFlags, MoveMountFlags, OpenTreeFlags,
5 };
6 use crate::fd::{AsFd, OwnedFd};
7 use crate::{backend, io, path};
8
9 /// `fsopen(fs_name, flags)`
10 ///
11 /// # References
12 /// - [Unfinished draft]
13 ///
14 /// [Unfinished draft]: https://github.com/sunfishcode/linux-mount-api-documentation/blob/main/fsopen.md
15 #[inline]
16 pub fn fsopen<Fs: path::Arg>(fs_name: Fs, flags: FsOpenFlags) -> io::Result<OwnedFd> {
17 fs_name.into_with_c_str(|fs_name| backend::mount::syscalls::fsopen(fs_name, flags))
18 }
19
20 /// `fsmount(fs_fd, flags, attr_flags)`
21 ///
22 /// # References
23 /// - [Unfinished draft]
24 ///
25 /// [Unfinished draft]: https://github.com/sunfishcode/linux-mount-api-documentation/blob/main/fsmount.md
26 #[inline]
27 pub fn fsmount<Fd: AsFd>(
28 fs_fd: Fd,
29 flags: FsMountFlags,
30 attr_flags: MountAttrFlags,
31 ) -> io::Result<OwnedFd> {
32 backend::mount::syscalls::fsmount(fs_fd.as_fd(), flags, attr_flags)
33 }
34
35 /// `move_mount(from_dfd, from_pathname, to_dfd, to_pathname, flags)`
36 ///
37 /// This is not the same as `mount` with the `MS_MOVE` flag. If you want to
38 /// use that, use [`mount_move`] instead.
39 ///
40 /// # References
41 /// - [Unfinished draft]
42 ///
43 /// [`mount_move`]: crate::mount::mount_move
44 /// [Unfinished draft]: https://github.com/sunfishcode/linux-mount-api-documentation/blob/main/move_mount.md
45 #[inline]
46 pub fn move_mount<From: path::Arg, To: path::Arg, FromFd: AsFd, ToFd: AsFd>(
47 from_dfd: FromFd,
48 from_pathname: From,
49 to_dfd: ToFd,
50 to_pathname: To,
51 flags: MoveMountFlags,
52 ) -> io::Result<()> {
53 let from_dfd = from_dfd.as_fd();
54 let to_dfd = to_dfd.as_fd();
55 from_pathname.into_with_c_str(|from_pathname| {
56 to_pathname.into_with_c_str(|to_pathname| {
57 backend::mount::syscalls::move_mount(
58 from_dfd,
59 from_pathname,
60 to_dfd,
61 to_pathname,
62 flags,
63 )
64 })
65 })
66 }
67
68 /// `open_tree(dfd, filename, flags)`
69 ///
70 /// # References
71 /// - [Unfinished draft]
72 ///
73 /// [Unfinished draft]: https://github.com/sunfishcode/linux-mount-api-documentation/blob/main/open_tree.md
74 #[inline]
75 pub fn open_tree<Path: path::Arg, Fd: AsFd>(
76 dfd: Fd,
77 filename: Path,
78 flags: OpenTreeFlags,
79 ) -> io::Result<OwnedFd> {
80 let dfd = dfd.as_fd();
81 filename.into_with_c_str(|filename| backend::mount::syscalls::open_tree(dfd, filename, flags))
82 }
83
84 /// `fspick(dfd, path, flags)`
85 ///
86 /// # References
87 /// - [Unfinished draft]
88 ///
89 /// [Unfinished draft]: https://github.com/sunfishcode/linux-mount-api-documentation/blob/main/fspick.md
90 #[inline]
91 pub fn fspick<Path: path::Arg, Fd: AsFd>(
92 dfd: Fd,
93 path: Path,
94 flags: FsPickFlags,
95 ) -> io::Result<OwnedFd> {
96 let dfd = dfd.as_fd();
97 path.into_with_c_str(|path| backend::mount::syscalls::fspick(dfd, path, flags))
98 }
99
100 /// `fsconfig(fs_fd, FSCONFIG_SET_FLAG, key, NULL, 0)`
101 ///
102 /// # References
103 /// - [Unfinished draft]
104 ///
105 /// [Unfinished draft]: https://github.com/sunfishcode/linux-mount-api-documentation/blob/main/fsconfig.md
106 #[inline]
107 #[doc(alias = "fsconfig")]
108 pub fn fsconfig_set_flag<Key: path::Arg, Fd: AsFd>(fs_fd: Fd, key: Key) -> io::Result<()> {
109 let fs_fd = fs_fd.as_fd();
110 key.into_with_c_str(|key| backend::mount::syscalls::fsconfig_set_flag(fs_fd, key))
111 }
112
113 /// `fsconfig(fs_fd, FSCONFIG_SET_STRING, key, value, 0)`
114 ///
115 /// # References
116 /// - [Unfinished draft]
117 ///
118 /// [Unfinished draft]: https://github.com/sunfishcode/linux-mount-api-documentation/blob/main/fsconfig.md
119 #[inline]
120 #[doc(alias = "fsconfig")]
121 pub fn fsconfig_set_string<Key: path::Arg, Value: path::Arg, Fd: AsFd>(
122 fs_fd: Fd,
123 key: Key,
124 value: Value,
125 ) -> io::Result<()> {
126 let fs_fd = fs_fd.as_fd();
127 key.into_with_c_str(|key| {
128 value.into_with_c_str(|value| {
129 backend::mount::syscalls::fsconfig_set_string(fs_fd, key, value)
130 })
131 })
132 }
133
134 /// `fsconfig(fs_fd, FSCONFIG_SET_BINARY, key, value, value.len())`
135 ///
136 /// # References
137 /// - [Unfinished draft]
138 ///
139 /// [Unfinished draft]: https://github.com/sunfishcode/linux-mount-api-documentation/blob/main/fsconfig.md
140 #[inline]
141 #[doc(alias = "fsconfig")]
142 pub fn fsconfig_set_binary<Key: path::Arg, Fd: AsFd>(
143 fs_fd: Fd,
144 key: Key,
145 value: &[u8],
146 ) -> io::Result<()> {
147 let fs_fd = fs_fd.as_fd();
148 key.into_with_c_str(|key| backend::mount::syscalls::fsconfig_set_binary(fs_fd, key, value))
149 }
150
151 /// `fsconfig(fs_fd, FSCONFIG_SET_PATH, key, path, fd)`
152 ///
153 /// # References
154 /// - [Unfinished draft]
155 ///
156 /// [Unfinished draft]: https://github.com/sunfishcode/linux-mount-api-documentation/blob/main/fsconfig.md
157 #[inline]
158 #[doc(alias = "fsconfig")]
159 pub fn fsconfig_set_path<Key: path::Arg, Path: path::Arg, Fd: AsFd, AuxFd: AsFd>(
160 fs_fd: Fd,
161 key: Key,
162 path: Path,
163 fd: AuxFd,
164 ) -> io::Result<()> {
165 let fs_fd = fs_fd.as_fd();
166 let fd = fd.as_fd();
167 key.into_with_c_str(|key| {
168 path.into_with_c_str(|path| {
169 backend::mount::syscalls::fsconfig_set_path(fs_fd, key, path, fd)
170 })
171 })
172 }
173
174 /// `fsconfig(fs_fd, FSCONFIG_SET_PATH_EMPTY, key, "", fd)`
175 ///
176 /// # References
177 /// - [Unfinished draft]
178 ///
179 /// [Unfinished draft]: https://github.com/sunfishcode/linux-mount-api-documentation/blob/main/fsconfig.md
180 #[inline]
181 #[doc(alias = "fsconfig")]
182 pub fn fsconfig_set_path_empty<Key: path::Arg, Fd: AsFd, AuxFd: AsFd>(
183 fs_fd: Fd,
184 key: Key,
185 fd: AuxFd,
186 ) -> io::Result<()> {
187 let fs_fd = fs_fd.as_fd();
188 let fd = fd.as_fd();
189 key.into_with_c_str(|key| backend::mount::syscalls::fsconfig_set_path_empty(fs_fd, key, fd))
190 }
191
192 /// `fsconfig(fs_fd, FSCONFIG_SET_FD, key, NULL, fd)`
193 ///
194 /// # References
195 /// - [Unfinished draft]
196 ///
197 /// [Unfinished draft]: https://github.com/sunfishcode/linux-mount-api-documentation/blob/main/fsconfig.md
198 #[inline]
199 #[doc(alias = "fsconfig")]
200 pub fn fsconfig_set_fd<Key: path::Arg, Fd: AsFd, AuxFd: AsFd>(
201 fs_fd: Fd,
202 key: Key,
203 fd: AuxFd,
204 ) -> io::Result<()> {
205 let fs_fd = fs_fd.as_fd();
206 let fd = fd.as_fd();
207 key.into_with_c_str(|key| backend::mount::syscalls::fsconfig_set_fd(fs_fd, key, fd))
208 }
209
210 /// `fsconfig(fs_fd, FSCONFIG_CMD_CREATE, key, NULL, 0)`
211 ///
212 /// # References
213 /// - [Unfinished draft]
214 ///
215 /// [Unfinished draft]: https://github.com/sunfishcode/linux-mount-api-documentation/blob/main/fsconfig.md
216 #[inline]
217 #[doc(alias = "fsconfig")]
218 pub fn fsconfig_create<Fd: AsFd>(fs_fd: Fd) -> io::Result<()> {
219 backend::mount::syscalls::fsconfig_create(fs_fd.as_fd())
220 }
221
222 /// `fsconfig(fs_fd, FSCONFIG_CMD_RECONFIGURE, key, NULL, 0)`
223 ///
224 /// # References
225 /// - [Unfinished draft]
226 ///
227 /// [Unfinished draft]: https://github.com/sunfishcode/linux-mount-api-documentation/blob/main/fsconfig.md
228 #[inline]
229 #[doc(alias = "fsconfig")]
230 pub fn fsconfig_reconfigure<Fd: AsFd>(fs_fd: Fd) -> io::Result<()> {
231 backend::mount::syscalls::fsconfig_reconfigure(fs_fd.as_fd())
232 }
233
234 /// `fsconfig(fs_fd, FSCONFIG_CMD_CREATE_EXCL, key, NULL, 0)`
235 ///
236 /// This function was added in Linux 6.6.
237 ///
238 /// # References
239 /// - [Unfinished draft]
240 ///
241 /// [Unfinished draft]: https://github.com/sunfishcode/linux-mount-api-documentation/blob/main/fsconfig.md
242 #[inline]
243 #[doc(alias = "fsconfig")]
244 pub fn fsconfig_create_exclusive<Fd: AsFd>(fs_fd: Fd) -> io::Result<()> {
245 backend::mount::syscalls::fsconfig_create_excl(fs_fd.as_fd())
246 }