Module ioctl

Source
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§

IoctlReqConstArg
Implementation of IoctlReq with a fixed cmd and passing a constant int as the argument, then returning the kernel’s result value.
IoctlReqNoArgs
Implementation of IoctlReq with a fixed cmd and passing no arguments at all, just returning the kernel’s result value.
IoctlReqRead
Implementation of IoctlReq with a fixed cmd value and passing a pointer to a zeroed memory block of type Result directly through to the underlying system call and then returnin a copy of that memory.
IoctlReqWrite
Implementation of IoctlReq with a fixed cmd value and passing a pointer to an argument value in memory.
IoctlReqWriteRead
IoctlReqWriteVal
Implementation of IoctlReq with a fixed cmd value and passing a direct value from memory, without pointer indirection.

Traits§

FromIoctlResult
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.
IoctlReq
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 parameter Parent.

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 to ioctl 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 to ioctl 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.