/ioctl

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

Primary LanguageGoApache License 2.0Apache-2.0

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.