DEVCTL(4)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1, nixpkgs unstable

πŸ’– DEVCTL(4) β€” devctl: device event reporting and device control interface πŸ’–

okay bestie, welcome to DEVCTL(4) from the Kernel Interfaces Manual 🫢. This is basically the group chat for kernel device events β€” join/leave notifications and link-state drama, but make it Unix. πŸ’…

🌸 NAME 🌸

devctl β€” device event reporting and device control interface.

✨ SYNOPSIS ✨

The devctl driver is automatically included in the kernel. No loading, no setup arc β€” it’s just there. ✨

πŸ¦‹ DESCRIPTION πŸ¦‹

The devctl device is used to report device events from the kernel. Future versions will allow for some device control as well. So rn it’s mostly the event-reporting main character. πŸ‘‘

πŸŽ€ IMPLEMENTATION NOTES πŸŽ€

This design allows only one reader for /dev/devctl. That’s not desirable in the long run, but it will get a lot of hair out of this implementation. Maybe we should make this device a clonable device. πŸ’€

Also note: we specifically do not attach a device to the device_t tree to avoid potential chicken and egg problems. One could argue that all of this belongs to the root node. One could also further argue that the sysctl(3) interface that we have now might more properly be an ioctl(2) interface. iykyk. 🧚

SIGIO support is included in the driver. However, the author is not sure that the SIGIO support is done correctly. It was copied from a driver that had SIGIO support that likely has not been tested since FreeBSD 3.4 or FreeBSD 2.2.8! 😭

The read channel for this device is used to report changes to userland in realtime. We return one record at a time. If you try to read this device a character at a time, you will lose the rest of the data. Listening programs are expected to cope. No cap: read it in record-sized bites, not tiny nibbles. πŸ“

The sysctl hw.bus.devctl_queue can be used to control queue length. It is set to 0 to disable devctl when no devd(8) is running. πŸ”₯

🌈 PROTOCOL 🌈

The devctl device uses an ASCII protocol. The driver returns one record at a time to its readers. Each record is terminated with a newline. The first character of the record is the event type. Slay, simple. πŸ’…

  • ! β€” a notify event, such as a link state change.
  • + β€” device node in tree attached.
  • - β€” device node in tree detached.
  • ? β€” unknown device detected.

πŸ’œ Message Formats πŸ’œ

Except for the first character in the record, attach and detach messages have the same format.

Tdev at parent on location

Here’s the part-by-part vibe check:

  • T β€” + or -.
  • dev β€” the device name that was attached/detached.
  • parent β€” the device name of the parent bus that attached the device.
  • location β€” bus specific location information.

The nomatch messages can be used to load devices driver. If you load a device driver, then one of two things can happen. If the device driver attaches to something, you will get a device attached message. If it does not, then nothing will happen. πŸ™ˆ

The attach and detach messages arrive after the event. This means one cannot use the attach message to load an alternate driver. The attach message driver has already claimed this device. One cannot use the detach messages to flush data to the device. The device is already gone. So don’t try to use them like a time machine, bestie. ⏳

All values passed back are of the form key=value or key="value". When the latter, the string value must have any internal backslashes doubled. It must also have any internal double quote characters " preceded by a backslash. All other characters should be passed through. Periodt. πŸ’–

🫢 SEE ALSO 🫢

devd(8) β€” that’s the one.


πŸ’Œ Cute sign-off: this page is from Debian, dated September 21, 2020. mwah, byeee! πŸŽ€

πŸ“¦ where this page comes from