| 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::{BorrowedFd, 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( |
| 28 |
fs_fd: BorrowedFd<'_>, |
| 29 |
flags: FsMountFlags, |
| 30 |
attr_flags: MountAttrFlags, |
| 31 |
) -> io::Result<OwnedFd> { |
| 32 |
backend::mount::syscalls::fsmount(fs_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>( |
| 47 |
from_dfd: BorrowedFd<'_>, |
| 48 |
from_pathname: From, |
| 49 |
to_dfd: BorrowedFd<'_>, |
| 50 |
to_pathname: To, |
| 51 |
flags: MoveMountFlags, |
| 52 |
) -> io::Result<()> { |
| 53 |
from_pathname.into_with_c_str(|from_pathname| { |
| 54 |
to_pathname.into_with_c_str(|to_pathname| { |
| 55 |
backend::mount::syscalls::move_mount( |
| 56 |
from_dfd, |
| 57 |
from_pathname, |
| 58 |
to_dfd, |
| 59 |
to_pathname, |
| 60 |
flags, |
| 61 |
) |
| 62 |
}) |
| 63 |
}) |
| 64 |
} |
| 65 |
|
| 66 |
/// `open_tree(dfd, filename, flags)` |
| 67 |
/// |
| 68 |
/// # References |
| 69 |
/// - [Unfinished draft] |
| 70 |
/// |
| 71 |
/// [Unfinished draft]: https://github.com/sunfishcode/linux-mount-api-documentation/blob/main/open_tree.md |
| 72 |
#[inline] |
| 73 |
pub fn open_tree<Path: path::Arg>( |
| 74 |
dfd: BorrowedFd<'_>, |
| 75 |
filename: Path, |
| 76 |
flags: OpenTreeFlags, |
| 77 |
) -> io::Result<OwnedFd> { |
| 78 |
filename.into_with_c_str(|filename| backend::mount::syscalls::open_tree(dfd, filename, flags)) |
| 79 |
} |
| 80 |
|
| 81 |
/// `fspick(dfd, path, flags)` |
| 82 |
/// |
| 83 |
/// # References |
| 84 |
/// - [Unfinished draft] |
| 85 |
/// |
| 86 |
/// [Unfinished draft]: https://github.com/sunfishcode/linux-mount-api-documentation/blob/main/fspick.md |
| 87 |
#[inline] |
| 88 |
pub fn fspick<Path: path::Arg>( |
| 89 |
dfd: BorrowedFd<'_>, |
| 90 |
path: Path, |
| 91 |
flags: FsPickFlags, |
| 92 |
) -> io::Result<OwnedFd> { |
| 93 |
path.into_with_c_str(|path| backend::mount::syscalls::fspick(dfd, path, flags)) |
| 94 |
} |
| 95 |
|
| 96 |
/// `fsconfig(fs_fd, FSCONFIG_SET_FLAG, key, NULL, 0)` |
| 97 |
/// |
| 98 |
/// # References |
| 99 |
/// - [Unfinished draft] |
| 100 |
/// |
| 101 |
/// [Unfinished draft]: https://github.com/sunfishcode/linux-mount-api-documentation/blob/main/fsconfig.md |
| 102 |
#[inline] |
| 103 |
#[doc(alias = "fsconfig")] |
| 104 |
pub fn fsconfig_set_flag<Key: path::Arg>(fs_fd: BorrowedFd<'_>, key: Key) -> io::Result<()> { |
| 105 |
key.into_with_c_str(|key| backend::mount::syscalls::fsconfig_set_flag(fs_fd, key)) |
| 106 |
} |
| 107 |
|
| 108 |
/// `fsconfig(fs_fd, FSCONFIG_SET_STRING, key, value, 0)` |
| 109 |
/// |
| 110 |
/// # References |
| 111 |
/// - [Unfinished draft] |
| 112 |
/// |
| 113 |
/// [Unfinished draft]: https://github.com/sunfishcode/linux-mount-api-documentation/blob/main/fsconfig.md |
| 114 |
#[inline] |
| 115 |
#[doc(alias = "fsconfig")] |
| 116 |
pub fn fsconfig_set_string<Key: path::Arg, Value: path::Arg>( |
| 117 |
fs_fd: BorrowedFd<'_>, |
| 118 |
key: Key, |
| 119 |
value: Value, |
| 120 |
) -> io::Result<()> { |
| 121 |
key.into_with_c_str(|key| { |
| 122 |
value.into_with_c_str(|value| { |
| 123 |
backend::mount::syscalls::fsconfig_set_string(fs_fd, key, value) |
| 124 |
}) |
| 125 |
}) |
| 126 |
} |
| 127 |
|
| 128 |
/// `fsconfig(fs_fd, FSCONFIG_SET_BINARY, key, value, value.len())` |
| 129 |
/// |
| 130 |
/// # References |
| 131 |
/// - [Unfinished draft] |
| 132 |
/// |
| 133 |
/// [Unfinished draft]: https://github.com/sunfishcode/linux-mount-api-documentation/blob/main/fsconfig.md |
| 134 |
#[inline] |
| 135 |
#[doc(alias = "fsconfig")] |
| 136 |
pub fn fsconfig_set_binary<Key: path::Arg>( |
| 137 |
fs_fd: BorrowedFd<'_>, |
| 138 |
key: Key, |
| 139 |
value: &[u8], |
| 140 |
) -> io::Result<()> { |
| 141 |
key.into_with_c_str(|key| backend::mount::syscalls::fsconfig_set_binary(fs_fd, key, value)) |
| 142 |
} |
| 143 |
|
| 144 |
/// `fsconfig(fs_fd, FSCONFIG_SET_PATH, key, path, fd)` |
| 145 |
/// |
| 146 |
/// # References |
| 147 |
/// - [Unfinished draft] |
| 148 |
/// |
| 149 |
/// [Unfinished draft]: https://github.com/sunfishcode/linux-mount-api-documentation/blob/main/fsconfig.md |
| 150 |
#[inline] |
| 151 |
#[doc(alias = "fsconfig")] |
| 152 |
pub fn fsconfig_set_path<Key: path::Arg, Path: path::Arg>( |
| 153 |
fs_fd: BorrowedFd<'_>, |
| 154 |
key: Key, |
| 155 |
path: Path, |
| 156 |
fd: BorrowedFd<'_>, |
| 157 |
) -> io::Result<()> { |
| 158 |
key.into_with_c_str(|key| { |
| 159 |
path.into_with_c_str(|path| { |
| 160 |
backend::mount::syscalls::fsconfig_set_path(fs_fd, key, path, fd) |
| 161 |
}) |
| 162 |
}) |
| 163 |
} |
| 164 |
|
| 165 |
/// `fsconfig(fs_fd, FSCONFIG_SET_PATH_EMPTY, key, "", fd)` |
| 166 |
/// |
| 167 |
/// # References |
| 168 |
/// - [Unfinished draft] |
| 169 |
/// |
| 170 |
/// [Unfinished draft]: https://github.com/sunfishcode/linux-mount-api-documentation/blob/main/fsconfig.md |
| 171 |
#[inline] |
| 172 |
#[doc(alias = "fsconfig")] |
| 173 |
pub fn fsconfig_set_path_empty<Key: path::Arg>( |
| 174 |
fs_fd: BorrowedFd<'_>, |
| 175 |
key: Key, |
| 176 |
fd: BorrowedFd<'_>, |
| 177 |
) -> io::Result<()> { |
| 178 |
key.into_with_c_str(|key| backend::mount::syscalls::fsconfig_set_path_empty(fs_fd, key, fd)) |
| 179 |
} |
| 180 |
|
| 181 |
/// `fsconfig(fs_fd, FSCONFIG_SET_FD, key, NULL, fd)` |
| 182 |
/// |
| 183 |
/// # References |
| 184 |
/// - [Unfinished draft] |
| 185 |
/// |
| 186 |
/// [Unfinished draft]: https://github.com/sunfishcode/linux-mount-api-documentation/blob/main/fsconfig.md |
| 187 |
#[inline] |
| 188 |
#[doc(alias = "fsconfig")] |
| 189 |
pub fn fsconfig_set_fd<Key: path::Arg>( |
| 190 |
fs_fd: BorrowedFd<'_>, |
| 191 |
key: Key, |
| 192 |
fd: BorrowedFd<'_>, |
| 193 |
) -> io::Result<()> { |
| 194 |
key.into_with_c_str(|key| backend::mount::syscalls::fsconfig_set_fd(fs_fd, key, fd)) |
| 195 |
} |
| 196 |
|
| 197 |
/// `fsconfig(fs_fd, FSCONFIG_CMD_CREATE, key, NULL, 0)` |
| 198 |
/// |
| 199 |
/// # References |
| 200 |
/// - [Unfinished draft] |
| 201 |
/// |
| 202 |
/// [Unfinished draft]: https://github.com/sunfishcode/linux-mount-api-documentation/blob/main/fsconfig.md |
| 203 |
#[inline] |
| 204 |
#[doc(alias = "fsconfig")] |
| 205 |
pub fn fsconfig_create(fs_fd: BorrowedFd<'_>) -> io::Result<()> { |
| 206 |
backend::mount::syscalls::fsconfig_create(fs_fd) |
| 207 |
} |
| 208 |
|
| 209 |
/// `fsconfig(fs_fd, FSCONFIG_CMD_RECONFIGURE, key, NULL, 0)` |
| 210 |
/// |
| 211 |
/// # References |
| 212 |
/// - [Unfinished draft] |
| 213 |
/// |
| 214 |
/// [Unfinished draft]: https://github.com/sunfishcode/linux-mount-api-documentation/blob/main/fsconfig.md |
| 215 |
#[inline] |
| 216 |
#[doc(alias = "fsconfig")] |
| 217 |
pub fn fsconfig_reconfigure(fs_fd: BorrowedFd<'_>) -> io::Result<()> { |
| 218 |
backend::mount::syscalls::fsconfig_reconfigure(fs_fd) |
| 219 |
} |