DEVICE_GET_STATE(9)

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

πŸ’– DEVICE_GET_STATE(9) πŸ’– β€” like, the manual page bestie you didn't know you needed

Hey bestie! So this is the DEVICE_GET_STATE(9) page from the Kernel Developer's Manual, and it's literally all about how to manipulate device state. I'm gonna break it down so it's giving main character energy and you actually get it. No cap. 🫢


🌸 NAME 🌸

So like, these are the functions: device_get_state, device_busy, device_unbusy, device_is_alive, device_is_attached β€” and their whole vibe is to manipulate device state. Slay. πŸ’…

✨ SYNOPSIS ✨

Here's the exact code, bestie β€” don't @ me if you typo it:

#include <sys/param.h>
#include <sys/bus.h>

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 πŸ¦‹

Okay so, like, the current state of a device? You get that by calling device_get_state(). It returns one of these: DS_NOTPRESENT, DS_ALIVE, DS_ATTACHED, or DS_BUSY (all described in device(9)). Iconic. πŸ‘‘

To check if a device was successfully probed, you call device_is_alive(). That one just returns if the state is greater or equal to DS_ALIVE. Simple. ✨

To check if a device was successfully attached, you call device_is_attached(). That returns if the state is greater or equal to DS_ATTACHED. Easy peasy. πŸ“

Now, every device has a busy count. It gets incremented when you call device_busy() and decremented when you call device_unbusy(). But β€” and this is important, bestie β€” both routines return an error if the device state is less than DS_ATTACHED. So like, don't try to busy a device that's not attached yet. It will not slay. 😭

When you call device_busy() on a device that's in the DS_ATTACHED state, the device changes to the DS_BUSY state. And when you call device_unbusy() and after decrementing, the busy count for the device is zero, it changes back to DS_ATTACHED. It's giving state transitions, we love to see it. πŸ”₯


🌈 SEE ALSO 🌈

  • device(9) β€” literally the only other thing you need to look at. Go read it. πŸ’œ

πŸ‘‘ AUTHORS πŸ‘‘

This manual page was written by Doug Rabson. Respect the legend. πŸ™Œ


πŸ’‘ Just a lil aside: these state transitions are lowkey important, so don't skip over the DS_ATTACHED check. Your future self will thank you. 🧚

That's it, bestie! This page is from the Debian crew, dated June 16, 1998, and it's the DEVICE_GET_STATE(9) manual page. Now go forth and manipulate device state like the icon you are! πŸ’…βœ¨πŸŒˆ

πŸ“¦ where this page comes from