DEVCTL(4)

πŸ’– DEVCTL(4) πŸ’–

okay bestie, so this one lives in the Kernel Interfaces Manual β€” it's DEVCTL(4), the device event reporting and device control interface. buckle up πŸŽ€


✨ NAME ✨

devctl β€” device event reporting and device control interface πŸ¦‹


🌸 DESCRIPTION 🌸

so the devctl device is what the kernel uses to report device events. that's its whole job rn. and like… future versions will allow for some device control too, but that part isn't here yet. it's giving "coming soon" energy ✨


πŸ‘‘ IMPLEMENTATION NOTES πŸ‘‘

okay so this design only allows one reader for /dev/devctl. literally one. and yeah, that's not desirable in the long run, but it will get a lot of hair out of this implementation, so. maybe we should make this device a clonable device?? just a thought πŸ’…

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. we're just saying things, fr fr πŸ™ˆ

SIGIO support is included in the driver. however β€” and this is the tea β€” 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. and listen β€” 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, that's on you 🫢

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. iconic, honestly:

Tdev at parent on location

here's what every piece means:

  • 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. so 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. that's it. that's the whole thing 🀷

⚠️ okay important: the attach and detach messages arrive after the event. which means you cannot use the attach message to load an alternate driver β€” the attach message driver has already claimed this device. and you cannot use the detach messages to flush data to the device either β€” the device is already gone. bye bestie πŸ’€

πŸ¦‹ SEE ALSO πŸ¦‹


and that's the whole page, bestie!! this one's from the Debian crew, dated March 26, 2014 β€” so like, vintage but still serving πŸ’… mwah, go read it again if you forgot something, ily πŸ«ΆπŸ’–βœ¨

πŸ“¦ where this page comes from