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
11 changes: 9 additions & 2 deletions src/backend/libc/fs/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ use crate::fs::{fstat, Stat};
target_os = "wasi",
)))]
use crate::fs::{fstatfs, StatFs};
#[cfg(not(any(solarish, target_os = "vita", target_os = "wasi")))]
#[cfg(not(any(
solarish,
target_os = "vita",
target_os = "wasi",
target_os = "vxworks"
)))]
use crate::fs::{fstatvfs, StatVfs};
use crate::io;
#[cfg(not(any(target_os = "fuchsia", target_os = "vita", target_os = "wasi")))]
Expand Down Expand Up @@ -159,6 +164,7 @@ impl Dir {
///
/// [`libc::seekdir`]: https://docs.rs/libc/*/arm-unknown-linux-gnueabihf/libc/fn.seekdir.html
#[cfg(target_pointer_width = "64")]
#[cfg(not(target_os = "vxworks"))]
#[cfg_attr(docsrs, doc(cfg(target_pointer_width = "64")))]
#[doc(alias = "seekdir")]
#[inline]
Expand Down Expand Up @@ -260,7 +266,8 @@ impl Dir {
solarish,
target_os = "horizon",
target_os = "vita",
target_os = "wasi"
target_os = "wasi",
target_os = "vxworks",
)))]
#[inline]
pub fn statvfs(&self) -> io::Result<StatVfs> {
Expand Down
3 changes: 2 additions & 1 deletion src/backend/libc/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ pub mod inotify;
target_os = "haiku",
target_os = "horizon",
target_os = "vita",
target_os = "wasi"
target_os = "wasi",
target_os = "vxworks",
)))]
pub(crate) mod makedev;
#[cfg(not(windows))]
Expand Down
47 changes: 32 additions & 15 deletions src/backend/libc/fs/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::fs::AtFlags;
target_os = "nto",
target_os = "redox",
target_os = "vita",
target_os = "vxworks",
)))]
use crate::fs::FallocateFlags;
#[cfg(not(any(
Expand Down Expand Up @@ -60,7 +61,7 @@ use crate::fs::Timestamps;
)))]
use crate::fs::{Dev, FileType};
use crate::fs::{Mode, OFlags, SeekFrom, Stat};
#[cfg(not(target_os = "wasi"))]
#[cfg(not(any(target_os = "wasi", target_os = "vxworks")))]
use crate::fs::{StatVfs, StatVfsMountFlags};
use crate::io;
#[cfg(all(target_env = "gnu", fix_y2038))]
Expand All @@ -85,6 +86,7 @@ use {
target_os = "redox",
target_os = "solaris",
target_os = "vita",
target_os = "vxworks",
)))]
use {crate::fs::Advice, core::num::NonZeroU64};
#[cfg(any(apple, linux_kernel, target_os = "hurd"))]
Expand All @@ -103,7 +105,7 @@ weak!(fn __futimens64(c::c_int, *const LibcTimespec) -> c::c_int);
/// Use a direct syscall (via libc) for `open`.
///
/// This is only currently necessary as a workaround for old glibc; see below.
#[cfg(all(unix, target_env = "gnu"))]
#[cfg(all(not(target_os = "vxworks"), unix, target_env = "gnu"))]
fn open_via_syscall(path: &CStr, oflags: OFlags, mode: Mode) -> io::Result<OwnedFd> {
// Linux on aarch64, loongarch64 and riscv64 has no `open` syscall so use
// `openat`.
Expand Down Expand Up @@ -150,7 +152,8 @@ pub(crate) fn open(path: &CStr, oflags: OFlags, mode: Mode) -> io::Result<OwnedF
unix,
target_env = "gnu",
not(target_os = "hurd"),
not(target_os = "freebsd")
not(target_os = "freebsd"),
not(target_os = "vxworks"),
))]
if oflags.contains(OFlags::TMPFILE) && crate::backend::if_glibc_is_less_than_2_25() {
return open_via_syscall(path, oflags, mode);
Expand Down Expand Up @@ -218,7 +221,8 @@ pub(crate) fn openat(
unix,
target_env = "gnu",
not(target_os = "hurd"),
not(target_os = "freebsd")
not(target_os = "freebsd"),
not(target_os = "vxworks")
))]
if oflags.contains(OFlags::TMPFILE) && crate::backend::if_glibc_is_less_than_2_25() {
return openat_via_syscall(dirfd, path, oflags, mode);
Expand Down Expand Up @@ -271,7 +275,7 @@ pub(crate) fn statfs(filename: &CStr) -> io::Result<StatFs> {
}
}

#[cfg(not(target_os = "wasi"))]
#[cfg(not(any(target_os = "wasi", target_os = "vxworks")))]
#[inline]
pub(crate) fn statvfs(filename: &CStr) -> io::Result<StatVfs> {
unsafe {
Expand Down Expand Up @@ -448,6 +452,7 @@ pub(crate) fn rename(old_path: &CStr, new_path: &CStr) -> io::Result<()> {
unsafe { ret(c::rename(c_str(old_path), c_str(new_path))) }
}

#[cfg(not(target_os = "vxworks"))]
pub(crate) fn renameat(
old_dirfd: BorrowedFd<'_>,
old_path: &CStr,
Expand Down Expand Up @@ -481,7 +486,7 @@ pub(crate) fn renameat(
ret(c::rename(c_str(old_path), c_str(new_path)))
}

#[cfg(not(target_os = "macos"))]
#[cfg(not(any(target_os = "macos", target_os = "vxworks")))]
unsafe {
ret(c::renameat(
borrowed_fd(old_dirfd),
Expand Down Expand Up @@ -729,7 +734,7 @@ pub(crate) fn lstat(path: &CStr) -> io::Result<Stat> {
}
}

#[cfg(not(any(target_os = "espidf", target_os = "redox")))]
#[cfg(not(any(target_os = "espidf", target_os = "redox", target_os = "vxworks")))]
pub(crate) fn statat(dirfd: BorrowedFd<'_>, path: &CStr, flags: AtFlags) -> io::Result<Stat> {
// See the comments in `fstat` about using `crate::fs::statx` here.
#[cfg(all(
Expand Down Expand Up @@ -812,7 +817,8 @@ pub(crate) fn access(path: &CStr, access: Access) -> io::Result<()> {
target_os = "espidf",
target_os = "horizon",
target_os = "redox",
target_os = "vita"
target_os = "vita",
target_os = "vxworks",
)))]
pub(crate) fn accessat(
dirfd: BorrowedFd<'_>,
Expand Down Expand Up @@ -1096,7 +1102,8 @@ pub(crate) fn chmod(path: &CStr, mode: Mode) -> io::Result<()> {
linux_kernel,
target_os = "espidf",
target_os = "redox",
target_os = "wasi"
target_os = "wasi",
target_os = "vxworks",
)))]
pub(crate) fn chmodat(
dirfd: BorrowedFd<'_>,
Expand Down Expand Up @@ -1175,7 +1182,12 @@ pub(crate) fn fclonefileat(
}
}

#[cfg(not(any(target_os = "espidf", target_os = "redox", target_os = "wasi")))]
#[cfg(not(any(
target_os = "espidf",
target_os = "redox",
target_os = "wasi",
target_os = "vxworks"
)))]
pub(crate) fn chownat(
dirfd: BorrowedFd<'_>,
path: &CStr,
Expand All @@ -1201,7 +1213,8 @@ pub(crate) fn chownat(
target_os = "horizon",
target_os = "redox",
target_os = "vita",
target_os = "wasi"
target_os = "wasi",
target_os = "vxworks",
)))]
pub(crate) fn mknodat(
dirfd: BorrowedFd<'_>,
Expand Down Expand Up @@ -1283,6 +1296,7 @@ pub(crate) fn copy_file_range(
target_os = "redox",
target_os = "solaris",
target_os = "vita",
target_os = "vxworks",
)))]
pub(crate) fn fadvise(
fd: BorrowedFd<'_>,
Expand Down Expand Up @@ -1494,7 +1508,8 @@ pub(crate) fn fchown(fd: BorrowedFd<'_>, owner: Option<Uid>, group: Option<Gid>)
target_os = "horizon",
target_os = "solaris",
target_os = "vita",
target_os = "wasi"
target_os = "wasi",
target_os = "vxworks",
)))]
pub(crate) fn flock(fd: BorrowedFd<'_>, operation: FlockOperation) -> io::Result<()> {
unsafe { ret(c::flock(borrowed_fd(fd), operation as c::c_int)) }
Expand Down Expand Up @@ -1522,7 +1537,8 @@ pub(crate) fn syncfs(fd: BorrowedFd<'_>) -> io::Result<()> {
target_os = "horizon",
target_os = "redox",
target_os = "vita",
target_os = "wasi"
target_os = "wasi",
target_os = "vxworks",
)))]
pub(crate) fn sync() {
unsafe { c::sync() }
Expand Down Expand Up @@ -1609,7 +1625,7 @@ pub(crate) fn fstatfs(fd: BorrowedFd<'_>) -> io::Result<StatFs> {
}
}

#[cfg(not(target_os = "wasi"))]
#[cfg(not(any(target_os = "wasi", target_os = "vxworks")))]
pub(crate) fn fstatvfs(fd: BorrowedFd<'_>) -> io::Result<StatVfs> {
let mut statvfs = MaybeUninit::<c::statvfs>::uninit();
unsafe {
Expand All @@ -1618,7 +1634,7 @@ pub(crate) fn fstatvfs(fd: BorrowedFd<'_>) -> io::Result<StatVfs> {
}
}

#[cfg(not(target_os = "wasi"))]
#[cfg(not(any(target_os = "wasi", target_os = "vxworks")))]
fn libc_statvfs_to_statvfs(from: c::statvfs) -> StatVfs {
StatVfs {
f_bsize: from.f_bsize as u64,
Expand Down Expand Up @@ -1744,6 +1760,7 @@ fn futimens_old(fd: BorrowedFd<'_>, times: &Timestamps) -> io::Result<()> {
target_os = "nto",
target_os = "redox",
target_os = "vita",
target_os = "vxworks",
)))]
pub(crate) fn fallocate(
fd: BorrowedFd<'_>,
Expand Down
39 changes: 31 additions & 8 deletions src/backend/libc/fs/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ bitflags! {
const SYMLINK_NOFOLLOW = bitcast!(c::AT_SYMLINK_NOFOLLOW);

/// `AT_EACCESS`
#[cfg(not(target_os = "android"))]
#[cfg(not(any(target_os = "android", target_os = "vxworks")))]
const EACCESS = bitcast!(c::AT_EACCESS);

/// `AT_REMOVEDIR`
Expand Down Expand Up @@ -259,7 +259,7 @@ bitflags! {
const CREATE = bitcast!(c::O_CREAT);

/// `O_DIRECTORY`
#[cfg(not(any(target_os = "espidf", target_os = "horizon")))]
#[cfg(not(any(target_os = "espidf", target_os = "horizon", target_os = "vxworks")))]
const DIRECTORY = bitcast!(c::O_DIRECTORY);

/// `O_DSYNC`
Expand All @@ -277,7 +277,7 @@ bitflags! {
const FSYNC = bitcast!(c::O_FSYNC);

/// `O_NOFOLLOW`
#[cfg(not(any(target_os = "espidf", target_os = "horizon")))]
#[cfg(not(any(target_os = "espidf", target_os = "horizon", target_os = "vxworks")))]
const NOFOLLOW = bitcast!(c::O_NOFOLLOW);

/// `O_NONBLOCK`
Expand All @@ -295,7 +295,7 @@ bitflags! {
const RDWR = bitcast!(c::O_RDWR);

/// `O_NOCTTY`
#[cfg(not(any(target_os = "espidf", target_os = "horizon", target_os = "l4re", target_os = "redox", target_os = "vita")))]
#[cfg(not(any(target_os = "espidf", target_os = "horizon", target_os = "l4re", target_os = "redox", target_os = "vita", target_os = "vxworks")))]
const NOCTTY = bitcast!(c::O_NOCTTY);

/// `O_RSYNC`
Expand Down Expand Up @@ -654,6 +654,7 @@ impl FileType {
target_os = "redox",
target_os = "solaris",
target_os = "vita",
target_os = "vxworks",
)))]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
#[repr(u32)]
Expand Down Expand Up @@ -767,7 +768,8 @@ bitflags! {
target_os = "horizon",
target_os = "nto",
target_os = "redox",
target_os = "vita"
target_os = "vita",
target_os = "vxworks",
)))]
bitflags! {
/// `FALLOC_FL_*` constants for use with [`fallocate`].
Expand Down Expand Up @@ -861,7 +863,7 @@ bitflags! {
}
}

#[cfg(not(target_os = "wasi"))]
#[cfg(not(any(target_os = "wasi", target_os = "vxworks")))]
bitflags! {
/// `ST_*` constants for use with [`StatVfs`].
#[repr(transparent)]
Expand Down Expand Up @@ -924,7 +926,8 @@ bitflags! {
target_os = "espidf",
target_os = "horizon",
target_os = "vita",
target_os = "wasi"
target_os = "wasi",
target_os = "vxworks",
)))]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[repr(u32)]
Expand Down Expand Up @@ -967,6 +970,26 @@ pub enum FlockOperation {
NonBlockingUnlock = bitcast!(8 | 4),
}

/// On Vxworks, we do not have flock or the flock enum.
/// So here, we create the enum ourselves
#[cfg(target_os = "vxworks")]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[repr(i32)]
pub enum FlockOperation {
/// `LOCK_SH`
LockShared = 1,
/// `LOCK_EX`
LockExclusive = 2,
/// `LOCK_UN`
Unlock = 4,
/// `LOCK_SH | LOCK_NB`
NonBlockingLockShared = 1 | 8,
/// `LOCK_EX | LOCK_NB`
NonBlockingLockExclusive = 2 | 8,
/// `LOCK_UN | LOCK_NB`
NonBlockingUnlock = 4 | 8,
}

/// `struct stat` for use with [`statat`] and [`fstat`].
///
/// [`statat`]: crate::fs::statat
Expand Down Expand Up @@ -1093,7 +1116,7 @@ pub type Fsid = c::fsid_t;
///
/// [`statvfs`]: crate::fs::statvfs
/// [`fstatvfs`]: crate::fs::fstatvfs
#[cfg(not(target_os = "wasi"))]
#[cfg(not(any(target_os = "wasi", target_os = "vxworks")))]
#[allow(missing_docs)]
pub struct StatVfs {
pub f_bsize: u64,
Expand Down
Loading
Loading