DEVICE_GET_STATE(9)
π DEVICE_GET_STATE π
okay bestie, we're in the Kernel Developer's Manual section 9 and this is your girl's guide to poking at device state. yes it's kernel-adjacent. yes you're gonna slay it. π
β¨ NAME β¨
device_get_state, device_busy, device_unbusy, device_is_alive, device_is_attached β the whole squad that lets you manipulate device state. that's the entire vibe, no cap.
πΈ SYNOPSIS πΈ
like always, you gotta bring your friends along first:
#include <sys/param.h>
#include <sys/bus.h>
then the actual icons:
device_state_t
device_get_state(device_t dev);
void
device_busy(device_t dev);
void
device_unbusy(device_t dev);
int
device_is_alive(device_t dev);
int
device_is_attached(device_t dev);
π¦ DESCRIPTION π¦
so, wanna know what's going on with a device rn? call device_get_state(). she hands you back one of these four:
DS_NOTPRESENTDS_ALIVEDS_ATTACHEDDS_BUSY
(yes all four are described over in device(9), go read that if you need the lore π«Ά)
trying to figure out if a device successfully probed? that's device_is_alive(). she literally just returns true if the state is greater or equal to DS_ALIVE. simple. lowkey elegant.
trying to figure out if a device successfully attached? that's device_is_attached(). same deal β she just returns if the state is greater or equal to DS_ATTACHED. periodt. β¨
okay now here's the juicy part. every device has a busy count π
device_busy()bumps it up β¬οΈdevice_unbusy()brings it down β¬οΈ
π¨ both routines return an error if the device state is less than DS_ATTACHED. do not come for them when they're not ready, bestie.
and the glow-up moments:
- when
device_busy()is called on a device that's in theDS_ATTACHEDstate, the device changes to theDS_BUSYstate. main character transition fr fr. π - when
device_unbusy()is called and β after decrementing β the busy count for the device is zero, the device changes to theDS_ATTACHEDstate. she's back home. π
π SEE ALSO π
π AUTHORS π
this manual page was written by Doug Rabson. thank you king, we are obsessed. π
and that's a wrap, gorgeous! this page came to you from the Debian edition of the Kernel Developer's Manual, dated June 16, 1998 β yes, an elder, and yes, still iconic. go busy some devices responsibly. mwah! ππ¦
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 1998 Doug Rabson
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms