Skip to content

Commit be39d50

Browse files
committed
Fix build on riscv32
RISCV32 libc does not have these defines so use them from linux_raw_sys crate ioctl() signare does not match between musl and glibc ioctl is called the glibc way with ioctl(int, unsigned long int, ...), musl/POSIX has ioctl(int, int, ...) so address this as well
1 parent cb01fbe commit be39d50

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/fs/ioctl.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ use {
1111

1212
use bitflags::bitflags;
1313

14+
/// The datatype used for the ioctl number
15+
#[cfg(any(target_os = "android", target_env = "musl"))]
16+
#[doc(hidden)]
17+
pub type ioctl_num_type = c::c_int;
18+
#[cfg(not(any(target_os = "android", target_env = "musl")))]
19+
#[doc(hidden)]
20+
pub type ioctl_num_type = c::c_ulong;
21+
1422
#[cfg(all(linux_kernel, not(any(target_arch = "sparc", target_arch = "sparc64"))))]
1523
use crate::fd::{AsRawFd as _, BorrowedFd};
1624

@@ -79,7 +87,7 @@ unsafe impl ioctl::Ioctl for Ficlone<'_> {
7987
const IS_MUTATING: bool = false;
8088

8189
fn opcode(&self) -> ioctl::Opcode {
82-
c::FICLONE as ioctl::Opcode
90+
linux_raw_sys::ioctl::FICLONE as ioctl::Opcode
8391
}
8492

8593
fn as_ptr(&mut self) -> *mut c::c_void {
@@ -141,7 +149,9 @@ bitflags! {
141149
#[doc(alias = "FS_IOC_GETFLAGS")]
142150
pub fn ioctl_getflags<Fd: AsFd>(fd: Fd) -> io::Result<IFlags> {
143151
unsafe {
144-
#[cfg(target_pointer_width = "32")]
152+
#[cfg(target_arch = "riscv32")]
153+
let ctl = ioctl::Getter::<{ linux_raw_sys::ioctl::FS_IOC32_GETFLAGS as ioctl_num_type }, u32>::new();
154+
#[cfg(all(target_pointer_width = "32", not(target_arch = "riscv32")))]
145155
let ctl = ioctl::Getter::<{ c::FS_IOC32_GETFLAGS }, u32>::new();
146156
#[cfg(target_pointer_width = "64")]
147157
let ctl = ioctl::Getter::<{ c::FS_IOC_GETFLAGS }, u32>::new();
@@ -158,7 +168,9 @@ pub fn ioctl_getflags<Fd: AsFd>(fd: Fd) -> io::Result<IFlags> {
158168
#[doc(alias = "FS_IOC_SETFLAGS")]
159169
pub fn ioctl_setflags<Fd: AsFd>(fd: Fd, flags: IFlags) -> io::Result<()> {
160170
unsafe {
161-
#[cfg(target_pointer_width = "32")]
171+
#[cfg(target_arch = "riscv32")]
172+
let ctl = ioctl::Setter::<{ linux_raw_sys::ioctl::FS_IOC32_SETFLAGS as ioctl_num_type }, u32>::new(flags.bits());
173+
#[cfg(all(target_pointer_width = "32", not(target_arch = "riscv32")))]
162174
let ctl = ioctl::Setter::<{ c::FS_IOC32_SETFLAGS }, u32>::new(flags.bits());
163175

164176
#[cfg(target_pointer_width = "64")]

0 commit comments

Comments
 (0)