| From 267eb85d72adb51cb9a891f302fc7d56eb0f9ef6 Mon Sep 17 00:00:00 2001 |
| From: Marcin Radomski <marcin@mradomski.pl> |
| Date: Fri, 15 Mar 2024 23:21:48 +0100 |
| Subject: [PATCH 3/3] Make fs feature compile without linux-raw-sys |
| |
| See b/331344966 for status of the efforts to upstream this. |
| |
| This makes some features unavailable: |
| |
| - ext4_ioc_resize_fs |
| - ioctl_getflags |
| - ioctl_setflags |
| - RawDir |
| |
| But also features fs, shm, param and pty become partially usable without |
| linux-raw-sys. |
| |
| Tested with: |
| |
| cargo build --no-default-features --features \ |
| use-libc,use-libc-auxv,std,event,mount,time,pipe,rand,stdio,mm,shm,param,pty |
| --- |
| src/backend/libc/fs/mod.rs | 4 ++-- |
| src/backend/libc/fs/syscalls.rs | 11 +++++++++-- |
| src/fs/ioctl.rs | 8 ++++---- |
| src/fs/mod.rs | 8 ++++---- |
| 4 files changed, 19 insertions(+), 12 deletions(-) |
| |
| diff --git a/src/backend/libc/fs/mod.rs b/src/backend/libc/fs/mod.rs |
| index c17e8636..d342f3a2 100644 |
| --- a/src/backend/libc/fs/mod.rs |
| +++ b/src/backend/libc/fs/mod.rs |
| @@ -15,9 +15,9 @@ pub(crate) mod syscalls; |
| pub(crate) mod types; |
| |
| // TODO: Fix linux-raw-sys to define ioctl codes for sparc. |
| -#[cfg(all(linux_kernel, any(target_arch = "sparc", target_arch = "sparc64")))] |
| +#[cfg(all(feature = "linux-raw-sys", any(target_arch = "sparc", target_arch = "sparc64")))] |
| pub(crate) const EXT4_IOC_RESIZE_FS: crate::ioctl::RawOpcode = 0x8008_6610; |
| |
| -#[cfg(all(linux_kernel, not(any(target_arch = "sparc", target_arch = "sparc64"))))] |
| +#[cfg(all(feature = "linux-raw-sys", not(any(target_arch = "sparc", target_arch = "sparc64"))))] |
| pub(crate) const EXT4_IOC_RESIZE_FS: crate::ioctl::RawOpcode = |
| linux_raw_sys::ioctl::EXT4_IOC_RESIZE_FS as crate::ioctl::RawOpcode; |
| diff --git a/src/backend/libc/fs/syscalls.rs b/src/backend/libc/fs/syscalls.rs |
| index 593b234a..134d66ff 100644 |
| --- a/src/backend/libc/fs/syscalls.rs |
| +++ b/src/backend/libc/fs/syscalls.rs |
| @@ -1729,7 +1729,7 @@ pub(crate) fn memfd_create(name: &CStr, flags: MemfdFlags) -> io::Result<OwnedFd |
| unsafe { ret_owned_fd(memfd_create(c_str(name), bitflags_bits!(flags))) } |
| } |
| |
| -#[cfg(linux_kernel)] |
| +#[cfg(feature = "linux-raw-sys")] |
| pub(crate) fn openat2( |
| dirfd: BorrowedFd<'_>, |
| path: &CStr, |
| @@ -1946,8 +1946,15 @@ pub(crate) fn statx( |
| // [it's deprecated]: https://patchwork.kernel.org/project/linux-fsdevel/patch/[email protected]/ |
| #[cfg(not(any(target_os = "android", target_env = "musl")))] |
| const STATX__RESERVED: u32 = c::STATX__RESERVED as u32; |
| - #[cfg(any(target_os = "android", target_env = "musl"))] |
| + #[cfg(all( |
| + any(target_os = "android", target_env = "musl"), |
| + feature = "linux-raw-sys", |
| + ))] |
| const STATX__RESERVED: u32 = linux_raw_sys::general::STATX__RESERVED; |
| + #[cfg(any( |
| + not(any(target_os = "android", target_env = "musl")), |
| + feature = "linux-raw-sys", |
| + ))] |
| if (mask.bits() & STATX__RESERVED) == STATX__RESERVED { |
| return Err(io::Errno::INVAL); |
| } |
| diff --git a/src/fs/ioctl.rs b/src/fs/ioctl.rs |
| index 490f183f..ad2fe4fa 100644 |
| --- a/src/fs/ioctl.rs |
| +++ b/src/fs/ioctl.rs |
| @@ -58,7 +58,7 @@ pub fn ioctl_ficlone<Fd: AsFd, SrcFd: AsFd>(fd: Fd, src_fd: SrcFd) -> io::Result |
| } |
| |
| /// `ioctl(fd, EXT4_IOC_RESIZE_FS, blocks)`—Resize ext4 filesystem on fd. |
| -#[cfg(linux_kernel)] |
| +#[cfg(feature = "linux-raw-sys")] |
| #[inline] |
| #[doc(alias = "EXT4_IOC_RESIZE_FS")] |
| pub fn ext4_ioc_resize_fs<Fd: AsFd>(fd: Fd, blocks: u64) -> io::Result<()> { |
| @@ -93,7 +93,7 @@ unsafe impl ioctl::Ioctl for Ficlone<'_> { |
| } |
| } |
| |
| -#[cfg(linux_kernel)] |
| +#[cfg(feature = "linux-raw-sys")] |
| bitflags! { |
| /// `FS_*` constants for use with [`ioctl_getflags`][crate::io::ioctl::ioctl_getflags]. |
| pub struct IFlags: c::c_uint { |
| @@ -131,7 +131,7 @@ bitflags! { |
| /// `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)] |
| +#[cfg(feature = "linux-raw-sys")] |
| #[inline] |
| #[doc(alias = "FS_IOC_GETFLAGS")] |
| pub fn ioctl_getflags<Fd: AsFd>(fd: Fd) -> io::Result<IFlags> { |
| @@ -148,7 +148,7 @@ pub fn ioctl_getflags<Fd: AsFd>(fd: Fd) -> io::Result<IFlags> { |
| /// `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)] |
| +#[cfg(feature = "linux-raw-sys")] |
| #[inline] |
| #[doc(alias = "FS_IOC_SETFLAGS")] |
| pub fn ioctl_setflags<Fd: AsFd>(fd: Fd, flags: IFlags) -> io::Result<()> { |
| diff --git a/src/fs/mod.rs b/src/fs/mod.rs |
| index 27d35701..b14ac803 100644 |
| --- a/src/fs/mod.rs |
| +++ b/src/fs/mod.rs |
| @@ -47,9 +47,9 @@ mod memfd_create; |
| #[cfg(linux_kernel)] |
| #[cfg(feature = "fs")] |
| mod mount; |
| -#[cfg(linux_kernel)] |
| +#[cfg(feature = "linux-raw-sys")] |
| mod openat2; |
| -#[cfg(linux_kernel)] |
| +#[cfg(feature = "linux-raw-sys")] |
| mod raw_dir; |
| mod seek_from; |
| #[cfg(target_os = "linux")] |
| @@ -115,9 +115,9 @@ pub use memfd_create::memfd_create; |
| #[cfg(linux_kernel)] |
| #[cfg(feature = "fs")] |
| pub use mount::*; |
| -#[cfg(linux_kernel)] |
| +#[cfg(feature = "linux-raw-sys")] |
| pub use openat2::openat2; |
| -#[cfg(linux_kernel)] |
| +#[cfg(feature = "linux-raw-sys")] |
| pub use raw_dir::{RawDir, RawDirEntry}; |
| pub use seek_from::SeekFrom; |
| #[cfg(target_os = "linux")] |
| -- |
| 2.44.0.291.gc1ea87d7ee-goog |
| |