1From 267eb85d72adb51cb9a891f302fc7d56eb0f9ef6 Mon Sep 17 00:00:00 2001 2From: Marcin Radomski <[email protected]> 3Date: Fri, 15 Mar 2024 23:21:48 +0100 4Subject: [PATCH 3/3] Make fs feature compile without linux-raw-sys 5 6See b/331344966 for status of the efforts to upstream this. 7 8This makes some features unavailable: 9 10- ext4_ioc_resize_fs 11- ioctl_getflags 12- ioctl_setflags 13- RawDir 14 15But also features fs, shm, param and pty become partially usable without 16linux-raw-sys. 17 18Tested with: 19 20 cargo build --no-default-features --features \ 21 use-libc,use-libc-auxv,std,event,mount,time,pipe,rand,stdio,mm,shm,param,pty 22--- 23 src/backend/libc/fs/mod.rs | 4 ++-- 24 src/backend/libc/fs/syscalls.rs | 11 +++++++++-- 25 src/fs/ioctl.rs | 8 ++++---- 26 src/fs/mod.rs | 8 ++++---- 27 4 files changed, 19 insertions(+), 12 deletions(-) 28 29diff --git a/src/backend/libc/fs/mod.rs b/src/backend/libc/fs/mod.rs 30index c17e8636..d342f3a2 100644 31--- a/src/backend/libc/fs/mod.rs 32+++ b/src/backend/libc/fs/mod.rs 33@@ -15,9 +15,9 @@ pub(crate) mod syscalls; 34 pub(crate) mod types; 35 36 // TODO: Fix linux-raw-sys to define ioctl codes for sparc. 37-#[cfg(all(linux_kernel, any(target_arch = "sparc", target_arch = "sparc64")))] 38+#[cfg(all(feature = "linux-raw-sys", any(target_arch = "sparc", target_arch = "sparc64")))] 39 pub(crate) const EXT4_IOC_RESIZE_FS: crate::ioctl::RawOpcode = 0x8008_6610; 40 41-#[cfg(all(linux_kernel, not(any(target_arch = "sparc", target_arch = "sparc64"))))] 42+#[cfg(all(feature = "linux-raw-sys", not(any(target_arch = "sparc", target_arch = "sparc64"))))] 43 pub(crate) const EXT4_IOC_RESIZE_FS: crate::ioctl::RawOpcode = 44 linux_raw_sys::ioctl::EXT4_IOC_RESIZE_FS as crate::ioctl::RawOpcode; 45diff --git a/src/backend/libc/fs/syscalls.rs b/src/backend/libc/fs/syscalls.rs 46index 593b234a..134d66ff 100644 47--- a/src/backend/libc/fs/syscalls.rs 48+++ b/src/backend/libc/fs/syscalls.rs 49@@ -1729,7 +1729,7 @@ pub(crate) fn memfd_create(name: &CStr, flags: MemfdFlags) -> io::Result<OwnedFd 50 unsafe { ret_owned_fd(memfd_create(c_str(name), bitflags_bits!(flags))) } 51 } 52 53-#[cfg(linux_kernel)] 54+#[cfg(feature = "linux-raw-sys")] 55 pub(crate) fn openat2( 56 dirfd: BorrowedFd<'_>, 57 path: &CStr, 58@@ -1946,8 +1946,15 @@ pub(crate) fn statx( 59 // [it's deprecated]: https://patchwork.kernel.org/project/linux-fsdevel/patch/[email protected]/ 60 #[cfg(not(any(target_os = "android", target_env = "musl")))] 61 const STATX__RESERVED: u32 = c::STATX__RESERVED as u32; 62- #[cfg(any(target_os = "android", target_env = "musl"))] 63+ #[cfg(all( 64+ any(target_os = "android", target_env = "musl"), 65+ feature = "linux-raw-sys", 66+ ))] 67 const STATX__RESERVED: u32 = linux_raw_sys::general::STATX__RESERVED; 68+ #[cfg(any( 69+ not(any(target_os = "android", target_env = "musl")), 70+ feature = "linux-raw-sys", 71+ ))] 72 if (mask.bits() & STATX__RESERVED) == STATX__RESERVED { 73 return Err(io::Errno::INVAL); 74 } 75diff --git a/src/fs/ioctl.rs b/src/fs/ioctl.rs 76index 490f183f..ad2fe4fa 100644 77--- a/src/fs/ioctl.rs 78+++ b/src/fs/ioctl.rs 79@@ -58,7 +58,7 @@ pub fn ioctl_ficlone<Fd: AsFd, SrcFd: AsFd>(fd: Fd, src_fd: SrcFd) -> io::Result 80 } 81 82 /// `ioctl(fd, EXT4_IOC_RESIZE_FS, blocks)`—Resize ext4 filesystem on fd. 83-#[cfg(linux_kernel)] 84+#[cfg(feature = "linux-raw-sys")] 85 #[inline] 86 #[doc(alias = "EXT4_IOC_RESIZE_FS")] 87 pub fn ext4_ioc_resize_fs<Fd: AsFd>(fd: Fd, blocks: u64) -> io::Result<()> { 88@@ -93,7 +93,7 @@ unsafe impl ioctl::Ioctl for Ficlone<'_> { 89 } 90 } 91 92-#[cfg(linux_kernel)] 93+#[cfg(feature = "linux-raw-sys")] 94 bitflags! { 95 /// `FS_*` constants for use with [`ioctl_getflags`][crate::io::ioctl::ioctl_getflags]. 96 pub struct IFlags: c::c_uint { 97@@ -131,7 +131,7 @@ bitflags! { 98 /// `ioctl(fd, FS_IOC_GETFLAGS)`—Returns the [inode flags] attributes 99 /// 100 /// [inode flags]: https://man7.org/linux/man-pages/man2/ioctl_iflags.2.html 101-#[cfg(linux_kernel)] 102+#[cfg(feature = "linux-raw-sys")] 103 #[inline] 104 #[doc(alias = "FS_IOC_GETFLAGS")] 105 pub fn ioctl_getflags<Fd: AsFd>(fd: Fd) -> io::Result<IFlags> { 106@@ -148,7 +148,7 @@ pub fn ioctl_getflags<Fd: AsFd>(fd: Fd) -> io::Result<IFlags> { 107 /// `ioctl(fd, FS_IOC_SETFLAGS)`—Modify the [inode flags] attributes 108 /// 109 /// [inode flags]: https://man7.org/linux/man-pages/man2/ioctl_iflags.2.html 110-#[cfg(linux_kernel)] 111+#[cfg(feature = "linux-raw-sys")] 112 #[inline] 113 #[doc(alias = "FS_IOC_SETFLAGS")] 114 pub fn ioctl_setflags<Fd: AsFd>(fd: Fd, flags: IFlags) -> io::Result<()> { 115diff --git a/src/fs/mod.rs b/src/fs/mod.rs 116index 27d35701..b14ac803 100644 117--- a/src/fs/mod.rs 118+++ b/src/fs/mod.rs 119@@ -47,9 +47,9 @@ mod memfd_create; 120 #[cfg(linux_kernel)] 121 #[cfg(feature = "fs")] 122 mod mount; 123-#[cfg(linux_kernel)] 124+#[cfg(feature = "linux-raw-sys")] 125 mod openat2; 126-#[cfg(linux_kernel)] 127+#[cfg(feature = "linux-raw-sys")] 128 mod raw_dir; 129 mod seek_from; 130 #[cfg(target_os = "linux")] 131@@ -115,9 +115,9 @@ pub use memfd_create::memfd_create; 132 #[cfg(linux_kernel)] 133 #[cfg(feature = "fs")] 134 pub use mount::*; 135-#[cfg(linux_kernel)] 136+#[cfg(feature = "linux-raw-sys")] 137 pub use openat2::openat2; 138-#[cfg(linux_kernel)] 139+#[cfg(feature = "linux-raw-sys")] 140 pub use raw_dir::{RawDir, RawDirEntry}; 141 pub use seek_from::SeekFrom; 142 #[cfg(target_os = "linux")] 143-- 1442.44.0.291.gc1ea87d7ee-goog 145 146