Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix ioctl set flags
  • Loading branch information
ETKNeil committed Jan 24, 2023
commit aa000ff9bbe7109d8ad3998bf5b07abd20f8a497
8 changes: 0 additions & 8 deletions src/backend/linux_raw/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,14 +683,6 @@ impl<'a, Num: ArgNumber> From<crate::backend::fs::types::UnmountFlags> for ArgRe
}
}

#[cfg(any(target_os = "android", target_os = "linux"))]
impl<'a, Num: ArgNumber> From<crate::backend::io::types::IFlags> for ArgReg<'a, Num> {
#[inline]
fn from(flags: crate::backend::io::types::IFlags) -> Self {
c_uint(flags.bits())
}
}

/// Convert a `usize` returned from a syscall that effectively returns `()` on
/// success.
///
Expand Down
6 changes: 4 additions & 2 deletions src/backend/linux_raw/io/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,13 +385,15 @@ pub(crate) fn ioctl_get_flags(fd: BorrowedFd) -> io::Result<IFlags> {

#[inline]
pub(crate) fn ioctl_set_flags(fd: BorrowedFd, flags: IFlags) -> io::Result<()> {
// ioctl expect a *const c_uint, we thus need to convert it and pass it by reference
let attr = flags.bits();
#[cfg(target_pointer_width = "32")]
unsafe {
ret(syscall_readonly!(
__NR_ioctl,
fd,
c_uint(FS_IOC32_SETFLAGS),
flags
by_ref(&attr)
))
}
#[cfg(target_pointer_width = "64")]
Expand All @@ -400,7 +402,7 @@ pub(crate) fn ioctl_set_flags(fd: BorrowedFd, flags: IFlags) -> io::Result<()> {
__NR_ioctl,
fd,
c_uint(FS_IOC_SETFLAGS),
flags
by_ref(&attr)
))
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/io/ioctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

use crate::{backend, io};
use backend::fd::AsFd;
#[cfg(any(target_os = "android", target_os = "linux"))]
pub use backend::io::types::IFlags;

/// `ioctl(fd, TIOCEXCL)`—Enables exclusive mode on a terminal.
///
Expand Down Expand Up @@ -104,7 +106,7 @@ pub fn ioctl_blkpbszget<Fd: AsFd>(fd: Fd) -> io::Result<u32> {
#[cfg(any(target_os = "android", target_os = "linux"))]
#[inline]
#[doc(alias = "FS_IOC_GETFLAGS")]
pub fn ioctl_getflags<Fd: AsFd>(fd: Fd) -> io::Result<backend::io::types::IFlags> {
pub fn ioctl_getflags<Fd: AsFd>(fd: Fd) -> io::Result<IFlags> {
backend::io::syscalls::ioctl_get_flags(fd.as_fd())
}

Expand All @@ -114,6 +116,6 @@ pub fn ioctl_getflags<Fd: AsFd>(fd: Fd) -> io::Result<backend::io::types::IFlags
#[cfg(any(target_os = "android", target_os = "linux"))]
#[inline]
#[doc(alias = "FS_IOC_GETFLAGS")]
pub fn ioctl_setflags<Fd: AsFd>(fd: Fd, flags: backend::io::types::IFlags) -> io::Result<()> {
pub fn ioctl_setflags<Fd: AsFd>(fd: Fd, flags: IFlags) -> io::Result<()> {
backend::io::syscalls::ioctl_set_flags(fd.as_fd(), flags)
}
2 changes: 2 additions & 0 deletions src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ pub use ioctl::ioctl_fionbio;
#[cfg(not(target_os = "redox"))]
pub use ioctl::ioctl_fionread;
#[cfg(any(target_os = "android", target_os = "linux"))]
pub use ioctl::IFlags;
#[cfg(any(target_os = "android", target_os = "linux"))]
pub use ioctl::{ioctl_blkpbszget, ioctl_blksszget, ioctl_getflags, ioctl_setflags};
#[cfg(not(any(windows, target_os = "haiku", target_os = "redox", target_os = "wasi")))]
pub use ioctl::{ioctl_tiocexcl, ioctl_tiocnxcl};
Expand Down