| Main index | Section 9 | Options |
#include <sys/param.h>
#include <sys/bus.h>
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.
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.
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).
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().
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.
| DEVICE_PROBE_AND_ATTACH (9) | February 5, 2025 |
| Main index | Section 9 | Options |
Please direct any comments about this manual page service to Ben Bullock. Privacy policy.
| “ | Our grievance is not just against Unix itself, but against the cult of Unix zealots who defend and nurture it. They take the heat, disease, and pestilence as givens, and, as ancient shamans did, display their wounds, some self-inflicted, as proof of their power and wizardry. We aim, through bluntness and humor, to show them that they pray to a tin god, and that science, not religion, is the path to useful and friendly technology. | ” |
| — The Unix Haters' handbook | ||