Module linux_io::fd::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

  • Implementation of IoctlReq with a fixed cmd and passing no arguments at all, just returning the kernel’s result value.
  • 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.
  • Implementation of IoctlReq with a fixed cmd value and passing a pointer to an argument value in memory.
  • Implementation of IoctlReq with a fixed cmd value and passing a direct value from memory, without pointer indirection.

Traits

  • Trait for types that can be constructed automatically from ioctl results from requests with a given argument type and temporary value type.
  • Represents a device type that can have ioctl requests implemented for it.
  • Represents a particular request that can be issue with the ioctl system call.
  • Implemented by IoDevice implementations that are “sub-devices” of another device, specified as type parameter Parent.

Functions

  • Equivalent to the kernel macro _IO for defining ioctl request numbers that neither read nor write within the standard numbering scheme.
  • Equivalent to the kernel macro _IOR for defining ioctl request numbers where userspace reads data from the kernel.
  • Equivalent to the kernel macro _IOW for defining ioctl request numbers where userspace writes data to the kernel.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.