pub unsafe fn ioctl<F: AsFd, I: Ioctl>(fd: F, ioctl: I) -> Result<I::Output>
Expand description
Perform an ioctl
call.
ioctl
was originally intended to act as a way of modifying the behavior
of files, but has since been adopted as a general purpose system call for
making calls into the kernel. In addition to the default calls exposed by
generic file descriptors, many drivers expose their own ioctl
calls for
controlling their behavior, some of which are proprietary.
This crate exposes many other ioctl
interfaces with safe and idiomatic
wrappers, like ioctl_fionbio
and ioctl_fionread
. It is recommended
to use those instead of this function, as they are safer and more
idiomatic. For other cases, implement the Ioctl
API and pass it to this
function.
See documentation for Ioctl
for more information.
§Safety
While Ioctl
takes much of the unsafety out of ioctl
calls, callers
must still ensure that the opcode value, operand type, and data access
correctly reflect what’s in the device driver servicing the call. ioctl
calls form a protocol between the userspace ioctl
callers and the device
drivers in the kernel, and safety depends on both sides agreeing and
upholding the expectations of the other.
And, ioctl
calls can read and write arbitrary memory and have arbitrary
side effects. Callers must ensure that any memory accesses and side effects
are compatible with Rust language invariants.