DEVICE_PROBE_AND_ATTACH(9)
π DEVICE_PROBE_AND_ATTACH β a.k.a. the Kernel Developer's Manual, bestie edition β¨
okay so this is the device_probe_and_attach(9) page from the FreeBSD/BSD kernel dev manual, and it's literally about how a device and a device driver get into a whole committed relationship π«Ά (plus how they break up, which is device_detach, and yes it's giving main character breakup energy π).
πΈ NAME πΈ
device_attach, device_detach, device_probe, device_probe_and_attach β manage device's connection to a device driver. like, the whole situationship between a device and its driver, no cap π
π SYNOPSIS π
#include <sys/param.h>
#include <sys/bus.h>
int
device_attach(device_t dev);
int
device_detach(device_t dev);
int
device_probe(device_t dev);
int
device_probe_and_attach(device_t dev);
β¨ DESCRIPTION β¨
So these functions manage the relationship between a device and device drivers. it's giving matchmaking, honestly π
device_probe() invokes the DEVICE_PROBE(9) method of each suitable driver and to find the driver with the best match for dev. If a matching driver is found, dev is set to the DS_ALIVE state and zero is returned. If dev is already attached to a device driver or has been disabled via device_disable(9), then it will not be probed and -1 is returned. lowkey it just says "nope, already taken" π
device_attach() fully attaches a device driver to dev. This function prints a description of the device and invokes the DEVICE_ATTACH(9) method. If the DEVICE_ATTACH(9) method succeeds, dev is set to the DS_ATTACHED state and zero is returned. If the DEVICE_ATTACH(9) method fails, BUS_CHILD_DETACHED(9) is called and an error value is returned. it's giving "we tried, it didn't work out, and we called the cleanup crew" π
If the device name and unit are disabled by a hint, device_attach() disables the device, demotes it to the DS_NOTPRESENT state, and returns ENXIO. The device retains its device name and unit and can be re-enabled via devctl(8). so it's not gone forever, it's just on a break, iykyk π¦
device_probe_and_attach() is a wrapper function around device_probe() and device_attach() that fully initialises a device. If dev is already attached or disabled, device_probe_and_attach() leaves the device unchanged and returns zero. Otherwise, device_probe() is used to identify a device driver for dev and device_attach() finalizes attaching the driver to dev. Device drivers should generally use this function to initialize a device rather than direct calls to device_probe() and device_attach(). bestie, this is the one-stop shop, the "just use the combo function, please" of it all ππ₯
device_detach() detaches the device driver from dev. This function invokes the DEVICE_DETACH(9) method to tear down device driver state for dev. If the method fails, its error value is returned and dev remains attached. If the method succeeds, otherwise, BUS_CHILD_DETACHED(9) is called, the device is set to the DS_NOTPRESENT state, and zero is returned. If a device is busy, device_detach() fails with EBUSY and leaving dev unchanged. busy means busy, she's not available, respectfully π
β οΈ real talk: if a device is busy you get EBUSY and dev stays exactly as it was. no sneaky partial detach, fr fr.
β RETURN VALUES β
Zero is returned on success, otherwise an appropriate error is returned. In addition, device_probe() returns -1 if dev is disabled or already attached. that's the whole vibe check right there π
π¦ SEE ALSO π¦
devctl(8)BUS_CHILD_DETACHED(9)device(9)DEVICE_ATTACH(9)DEVICE_DETACH(9)DEVICE_PROBE(9)driver(9)
πΈ AUTHORS πΈ
This manual page was written by Doug Rabson. ty Doug, iconic behaviour honestly π«Άπ
and that's the page!! this one's from the Debian packaging, dated February 5, 2025, and it's DEVICE_PROBE_AND_ATTACH(9) β go forth and attach responsibly bestie πβ¨
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- Copyright (c) 1998 Doug Rabson
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms