Categorygithub.com/thediveo/ioctl
modulepackage
0.9.3
Repository: https://github.com/thediveo/ioctl.git
Documentation: pkg.go.dev

# README

ioctl

PkgGoDev GitHub build and test Go Report Card Coverage

A tiny package to help with dealing with constructing Linux ioctl(2) request values that are not already included in the sys/unix standard package.

A good example are ioctl_ns(2) operations on Linux namespaces. For instance, this ioctl operation request value is defined in include/uapi/linux/nsfs.h in the Linux kernel C headers 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)

func main() {
  fd, err := ioctl.RetFd(nsfd, NS_GET_USERNS)
}

Make Targets

  • make: lists all targets.
  • make coverage: runs all tests with coverage and then updates the coverage badge in README.md.
  • make pkgsite: installs x/pkgsite, as well as the browser-sync and nodemon npm packages first, if not already done so. Then runs the pkgsite and hot reloads it whenever the documentation changes.
  • make report: installs @gojp/goreportcard if not yet done so and then runs it on the code base.
  • make test: runs all tests, always.
  • make vuln: installs x/vuln/cmd/govulncheck and then runs it.

Copyright and License

Copyright 2023 Harald Albrecht, licensed under the Apache License, Version 2.0.

# Functions

IO returns an ioctl(2) request value for a request that doesn't have any additional request parameter.
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.
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.
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.
IOW 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.
RetFd issues the specified ioctĺ request and returns the successful result as a file descriptor, or an error.

# Constants

This is ugly ioctl command (request) enconding stuff.
This is ugly ioctl command (request) enconding stuff.
This is ugly ioctl command (request) enconding stuff.
This is ugly ioctl command (request) enconding stuff.
This is ugly ioctl command (request) enconding stuff.
This is ugly ioctl command (request) enconding stuff.
This is ugly ioctl command (request) enconding stuff.
This is ugly ioctl command (request) enconding stuff.
This is ugly ioctl command (request) enconding stuff.
This is ugly ioctl command (request) enconding stuff.