Documentation
¶
Overview ¶
Package ioctl is a thin convenience wrapper for working with those ioctl request numbers that are not defined as plain numbers but instead as macros in the Linux kernel header files.
Example ¶
The request values for ioctl_ns(2) operations are defined using C macros in include/uapi/linux/nsfs.h in the Linux kernel header sources as follows:
#define NSIO 0xb7 // Returns a file descriptor that refers to an owning user namespace #define NS_GET_USERNS _IO(NSIO, 0x1)
These definitions can now be applied to Go code as follows:
import "github.com/thediveo/ioctl" const NSIO = 0xb7 var NS_GET_USERNS = ioctl.IO(NSIO, 0x1) fd, err := ioctl.RetFd(nsfd, NS_GET_USERNS)
Index ¶
Constants ¶
const ( IOC_NRBITS = 8 IOC_TYPEBITS = 8 IOC_SIZEBITS = 14 IOC_NRSHIFT = 0 IOC_TYPESHIFT = IOC_NRSHIFT + IOC_NRBITS IOC_SIZESHIFT = IOC_TYPESHIFT + IOC_TYPEBITS IOC_DIRSHIFT = IOC_SIZESHIFT + IOC_SIZEBITS IOC_NONE = uint(0) IOC_WRITE = uint(1) IOC_READ = uint(2) )
This is ugly ioctl command (request) enconding stuff. Requests are 32 bits in total, with the command in the lower 16 bits and the size of the parameter structure taking up the lower 14 bits of the request's upper 16 bits.
ATTENTION: the following definitions follow the kernel's ioctl.h. They hold “only” for the “asm-generic” platforms, such as x86, arm, and others. Currently the only platforms having a different ioctl request field mapping are: alpha, mips, powerpc, and sparc. And alpha isn't even an architecture supported by Go, go figure.
We keep the original C identifiers on purpose (but have to remove the leading “_”) and otherwise don't care about patronizing linters.
Variables ¶
This section is empty.
Functions ¶
func IO ¶ added in v0.9.2
IO returns an ioctl(2) request value for a request that doesn't have any additional request parameter.
func IOC ¶ added in v0.9.2
IOC returns an ioctl(2) request value, calculated from the specific ioctl call properties: parameter in/out direction, type of ioctl, command number, and finally parameter size.
func IOR ¶ added in v0.9.3
IOR returns an ioctl(2) request value for a request that has an additional request parameter that the userland wants to read and the kernel is writing.
func IORW ¶ added in v0.9.3
IORW returns an ioctl(2) request value for a request that has an additional request parameter that the userland first wants to write, the kernel then reads and updates it, and the userland finally wants to read it afterwards.
Types ¶
This section is empty.