Skip to content

Commit

Permalink
Merge branch 'bytecodealliance:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
arctic-alpaca authored Jan 11, 2024
2 parents f3bd608 + c4ac6b6 commit e87ede3
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ once_cell = { version = "1.5.2", optional = true }
[target.'cfg(all(not(rustix_use_libc), not(miri), target_os = "linux", target_endian = "little", any(target_arch = "arm", all(target_arch = "aarch64", target_pointer_width = "64"), target_arch = "riscv64", all(rustix_use_experimental_asm, target_arch = "powerpc64"), all(rustix_use_experimental_asm, target_arch = "mips"), all(rustix_use_experimental_asm, target_arch = "mips32r6"), all(rustix_use_experimental_asm, target_arch = "mips64"), all(rustix_use_experimental_asm, target_arch = "mips64r6"), target_arch = "x86", all(target_arch = "x86_64", target_pointer_width = "64"))))'.dependencies]
linux-raw-sys = { version = "0.4.11", default-features = false, features = ["general", "errno", "ioctl", "no_std", "elf"] }
libc_errno = { package = "errno", version = "0.3.8", default-features = false, optional = true }
libc = { version = "0.2.150", default-features = false, features = ["extra_traits"], optional = true }
libc = { version = "0.2.151", default-features = false, features = ["extra_traits"], optional = true }

# Dependencies for platforms where only libc is supported:
#
Expand Down
27 changes: 18 additions & 9 deletions src/backend/libc/fs/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2272,15 +2272,24 @@ pub(crate) fn lgetxattr(path: &CStr, name: &CStr, value: &mut [u8]) -> io::Resul
}

#[cfg(apple)]
unsafe {
ret_usize(c::getxattr(
path.as_ptr(),
name.as_ptr(),
value_ptr.cast::<c::c_void>(),
value.len(),
0,
c::XATTR_NOFOLLOW,
))
{
// Passing an empty to slice to getxattr leads to ERANGE on macOS. Pass null instead.
let ptr = if value.is_empty() {
core::ptr::null_mut()
} else {
value_ptr.cast::<c::c_void>()
};

unsafe {
ret_usize(c::getxattr(
path.as_ptr(),
name.as_ptr(),
ptr,
value.len(),
0,
c::XATTR_NOFOLLOW,
))
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/backend/linux_raw/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ pub(crate) use linux_raw_sys::general::{
};

pub(crate) use linux_raw_sys::ioctl::{BLKPBSZGET, BLKSSZGET, FICLONE};
#[cfg(target_pointer_width = "32")]
pub(crate) use linux_raw_sys::ioctl::{FS_IOC32_GETFLAGS, FS_IOC32_SETFLAGS};
#[cfg(target_pointer_width = "64")]
pub(crate) use linux_raw_sys::ioctl::{FS_IOC_GETFLAGS, FS_IOC_SETFLAGS};

#[cfg(feature = "io_uring")]
pub(crate) use linux_raw_sys::{general::open_how, io_uring::*};
Expand Down
73 changes: 73 additions & 0 deletions src/fs/ioctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use {
backend::c,
};

use bitflags::bitflags;

#[cfg(all(linux_kernel, not(any(target_arch = "sparc", target_arch = "sparc64"))))]
use crate::fd::{AsRawFd, BorrowedFd};

Expand Down Expand Up @@ -90,3 +92,74 @@ unsafe impl ioctl::Ioctl for Ficlone<'_> {
Ok(())
}
}

#[cfg(linux_kernel)]
bitflags! {
/// `FS_*` constants for use with [`ioctl_getflags`][crate::io::ioctl::ioctl_getflags].
pub struct IFlags: c::c_uint {
/// `FS_APPEND_FL`
const APPEND = linux_raw_sys::general::FS_APPEND_FL;
/// `FS_COMPR_FL`
const COMPRESSED = linux_raw_sys::general::FS_COMPR_FL;
/// `FS_DIRSYNC_FL`
const DIRSYNC = linux_raw_sys::general::FS_DIRSYNC_FL;
/// `FS_IMMUTABLE_FL`
const IMMUTABLE = linux_raw_sys::general::FS_IMMUTABLE_FL;
/// `FS_JOURNAL_DATA_FL`
const JOURNALING = linux_raw_sys::general::FS_JOURNAL_DATA_FL;
/// `FS_NOATIME_FL`
const NOATIME = linux_raw_sys::general::FS_NOATIME_FL;
/// `FS_NOCOW_FL`
const NOCOW = linux_raw_sys::general::FS_NOCOW_FL;
/// `FS_NODUMP_FL`
const NODUMP = linux_raw_sys::general::FS_NODUMP_FL;
/// `FS_NOTAIL_FL`
const NOTAIL = linux_raw_sys::general::FS_NOTAIL_FL;
/// `FS_PROJINHERIT_FL`
const PROJECT_INHERIT = linux_raw_sys::general::FS_PROJINHERIT_FL;
/// `FS_SECRM_FL`
const SECURE_REMOVAL = linux_raw_sys::general::FS_SECRM_FL;
/// `FS_SYNC_FL`
const SYNC = linux_raw_sys::general::FS_SYNC_FL;
/// `FS_TOPDIR_FL`
const TOPDIR = linux_raw_sys::general::FS_TOPDIR_FL;
/// `FS_UNRM_FL`
const UNRM = linux_raw_sys::general::FS_UNRM_FL;
}
}

/// `ioctl(fd, FS_IOC_GETFLAGS)`—Returns the [inode flags] attributes
///
/// [inode flags]: https://man7.org/linux/man-pages/man2/ioctl_iflags.2.html
#[cfg(linux_kernel)]
#[inline]
#[doc(alias = "FS_IOC_GETFLAGS")]
pub fn ioctl_getflags<Fd: AsFd>(fd: Fd) -> io::Result<IFlags> {
unsafe {
#[cfg(target_pointer_width = "32")]
let ctl = ioctl::Getter::<ioctl::BadOpcode<{ c::FS_IOC32_GETFLAGS }>, u32>::new();
#[cfg(target_pointer_width = "64")]
let ctl = ioctl::Getter::<ioctl::BadOpcode<{ c::FS_IOC_GETFLAGS }>, u32>::new();

ioctl::ioctl(fd, ctl).map(IFlags::from_bits_retain)
}
}

/// `ioctl(fd, FS_IOC_SETFLAGS)`—Modify the [inode flags] attributes
///
/// [inode flags]: https://man7.org/linux/man-pages/man2/ioctl_iflags.2.html
#[cfg(linux_kernel)]
#[inline]
#[doc(alias = "FS_IOC_SETFLAGS")]
pub fn ioctl_setflags<Fd: AsFd>(fd: Fd, flags: IFlags) -> io::Result<()> {
unsafe {
#[cfg(target_pointer_width = "32")]
let ctl =
ioctl::Setter::<ioctl::BadOpcode<{ c::FS_IOC32_SETFLAGS }>, u32>::new(flags.bits());

#[cfg(target_pointer_width = "64")]
let ctl = ioctl::Setter::<ioctl::BadOpcode<{ c::FS_IOC_SETFLAGS }>, u32>::new(flags.bits());

ioctl::ioctl(fd, ctl)
}
}

0 comments on commit e87ede3

Please sign in to comment.