Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions src/backend/libc/fs/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ use crate::fs::StatFs;
#[cfg(not(any(target_os = "espidf", target_os = "vita")))]
use crate::fs::Timestamps;
#[cfg(not(any(
apple,
target_os = "espidf",
target_os = "redox",
target_os = "vita",
Expand Down Expand Up @@ -1196,7 +1195,6 @@ pub(crate) fn chownat(
}

#[cfg(not(any(
apple,
target_os = "espidf",
target_os = "horizon",
target_os = "redox",
Expand All @@ -1210,13 +1208,30 @@ pub(crate) fn mknodat(
mode: Mode,
dev: Dev,
) -> io::Result<()> {
let mode = (mode.bits() | file_type.as_raw_mode()) as c::mode_t;
let dev = dev.try_into().map_err(|_e| io::Errno::PERM)?;

// Older Apple platforms lack `mknodat`.
#[cfg(apple)]
unsafe {
ret(c::mknodat(
borrowed_fd(dirfd),
c_str(path),
(mode.bits() | file_type.as_raw_mode()) as c::mode_t,
dev.try_into().map_err(|_e| io::Errno::PERM)?,
))
weak! {
fn mknodat(
c::c_int,
*const ffi::c_char,
c::mode_t,
c::dev_t
) -> c::c_int
}
// If we have `mknodat`, use it.
if let Some(libc_mknodat) = mknodat.get() {
return ret(libc_mknodat(borrowed_fd(dirfd), c_str(path), mode, dev));
}
Err(io::Errno::NOSYS)
Comment on lines +1225 to +1229
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// If we have `mknodat`, use it.
if let Some(libc_mknodat) = mknodat.get() {
return ret(libc_mknodat(borrowed_fd(dirfd), c_str(path), mode, dev));
}
Err(io::Errno::NOSYS)
let libc_mknodat = mknodat.get().ok_or(io::Errno::NOSYS)?;
ret(libc_mknodat(borrowed_fd(dirfd), c_str(path), mode, dev))

}

#[cfg(not(apple))]
unsafe {
ret(c::mknodat(borrowed_fd(dirfd), c_str(path), mode, dev))
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/fs/at.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::fs::CloneFlags;
use crate::fs::RenameFlags;
#[cfg(not(target_os = "espidf"))]
use crate::fs::Stat;
#[cfg(not(any(apple, target_os = "espidf", target_os = "vita", target_os = "wasi")))]
#[cfg(not(any(target_os = "espidf", target_os = "vita", target_os = "wasi")))]
use crate::fs::{Dev, FileType};
#[cfg(not(any(target_os = "espidf", target_os = "wasi")))]
use crate::fs::{Gid, Uid};
Expand Down Expand Up @@ -460,11 +460,12 @@ pub fn fclonefileat<Fd: AsFd, DstFd: AsFd, P: path::Arg>(
/// # References
/// - [POSIX]
/// - [Linux]
/// - [Apple]
///
/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/mknodat.html
/// [Linux]: https://man7.org/linux/man-pages/man2/mknodat.2.html
/// [Apple]: https://github.com/apple-oss-distributions/xnu/blob/main/bsd/man/man2/mknodat.2
#[cfg(not(any(
apple,
target_os = "espidf",
target_os = "horizon",
target_os = "vita",
Expand All @@ -488,10 +489,11 @@ pub fn mknodat<P: path::Arg, Fd: AsFd>(
///
/// # References
/// - [POSIX]
/// - [Apple]
///
/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/mkfifoat.html
/// [Apple]: https://github.com/apple-oss-distributions/xnu/blob/main/bsd/man/man2/mkfifoat.2
#[cfg(not(any(
apple,
target_os = "espidf",
target_os = "horizon",
target_os = "vita",
Expand Down
Loading