Expand description
A safer abstraction for ioctl
.
The ioctl
system call is very open-ended, supporting a variety of
different operations with different argument and result types, with the
valid operations varying drastically based on which underlying driver or
type of device the file represents. Passing the wrong kind of value to the
wrong request can cause memory corruption.
To make ioctl
a little safer to use, this module provides the building
blocks for request constants that also include information about the
argument and result types, so that the super::File::ioctl
method can
then provide a type-safe interface as long as these constants are defined
correctly. IoctlReq
implementations can be defined in other crates that
provide support for particular device types or device drivers.
Structs§
- Ioctl
ReqConst Arg - Implementation of
IoctlReq
with a fixedcmd
and passing a constant int as the argument, then returning the kernel’s result value. - Ioctl
ReqNo Args - Implementation of
IoctlReq
with a fixedcmd
and passing no arguments at all, just returning the kernel’s result value. - Ioctl
ReqRead - Implementation of
IoctlReq
with a fixedcmd
value and passing a pointer to a zeroed memory block of typeResult
directly through to the underlying system call and then returnin a copy of that memory. - Ioctl
ReqWrite - Implementation of
IoctlReq
with a fixedcmd
value and passing a pointer to an argument value in memory. - Ioctl
ReqWrite Read - Ioctl
ReqWrite Val - Implementation of
IoctlReq
with a fixedcmd
value and passing a direct value from memory, without pointer indirection.
Traits§
- From
Ioctl Result - Trait for types that can be constructed automatically from
ioctl
results from requests with a given argument type and temporary value type. - IoDevice
- Represents a device type that can have
ioctl
requests implemented for it. - Ioctl
Req - Represents a particular request that can be issue with the
ioctl
system call. - SubDevice
- Implemented by
IoDevice
implementations that are “sub-devices” of another device, specified as type parameterParent
.
Functions§
- _IO
- Equivalent to the kernel macro
_IO
for defining ioctl request numbers that neither read nor write within the standard numbering scheme. - _IOR
- Equivalent to the kernel macro
_IOR
for defining ioctl request numbers where userspace reads data from the kernel. - _IOW
- Equivalent to the kernel macro
_IOW
for defining ioctl request numbers where userspace writes data to the kernel. - _IOWR
- Equivalent to the kernel macro
_IOWR
for defining ioctl request numbers where userspace writes data to the kernel and the kernel returns data back to userspace. - ioctl_
const_ ⚠arg - Constructs a new read-only
IoctlReq
with a fixed request code that passes a constant integer toioctl
and returns its result in the system call return value. - ioctl_
no_ ⚠arg - Constructs a new read-only
IoctlReq
with a fixed request code that passes no payload toioctl
and returns its result in the system call return value. - ioctl_
read ⚠ - Constructs a new read-only
IoctlReq
with a fixed request code and a result type that maps directly to the data the kernel will provide. - ioctl_
write ⚠ - Constructs a new write-only
IoctlReq
with a fixed request code and an argument type that maps directly to the data the kernel expects to receive a pointer to. - ioctl_
write_ ⚠val - Constructs a new write-only
IoctlReq
with a fixed request code and an argument type that the data the kernel expects to recieve directly as its argument, without any pointer indirection. - ioctl_
writeread ⚠ - Constructs a new write/read
IoctlReq
with a fixed request code and an argument type that maps directly to the data the kernel expects to recieve a pointer to.