UDEV_DEVICE_GET_SYSPATH(3)
π NAME π
okay so bestie, this whole page is the "who even IS this device" starter pack β fourteen little getter functions that go ask a struct udev_device about itself. Manpage-speak version: Query device properties. Here's the entire squad, nobody gets left out:
udev_device_get_syspathudev_device_get_sysnameudev_device_get_sysnumudev_device_get_devpathudev_device_get_devnodeudev_device_get_devnumudev_device_get_devtypeudev_device_get_subsystemudev_device_get_driverudev_device_get_udevudev_device_get_parentudev_device_get_parent_with_subsystem_devtypeudev_device_get_is_initializedudev_device_get_action
β¨ SYNOPSIS β¨
first things first, you gotta tell the compiler you come in peace:
#include <libudev.h>
and then here's the whole roster, handed to you exactly as the page gives it β yes some of those lines are wrapped like that, that's just the manpage being quirky, not a you problem π
const char *udev_device_get_syspath(struct udev_device *udev_device);
const char *udev_device_get_sysname(struct udev_device *udev_device);
const char *udev_device_get_sysnum(struct udev_device *udev_device);
const char *udev_device_get_devpath(struct udev_device *udev_device);
const char *udev_device_get_devnode(struct udev_device *udev_device);
dev_t udev_device_get_devnum(struct udev_device *udev_device);
const char *udev_device_get_devtype(struct udev_device *udev_device);
const char *udev_device_get_subsystem(struct udev_device *udev_device);
const char *udev_device_get_driver(struct udev_device *udev_device);
struct udev *udev_device_get_udev(struct udev_device *udev_device);
struct udev_device
*udev_device_get_parent(struct udev_device *udev_device);
struct udev_device
*udev_device_get_parent_with_subsystem_devtype(struct udev_device *udev_device,
const char *subsystem,
const char *devtype);
int udev_device_get_is_initialized(struct udev_device *udev_device);
const char *udev_device_get_action(struct udev_device *udev_device);
π«Ά RETURN VALUE π«Ά
πΈ the string girlies πΈ
okay so on success, all of these β udev_device_get_syspath(), udev_device_get_sysname(), udev_device_get_sysnum(), udev_device_get_devpath(), udev_device_get_devnode(), udev_device_get_devtype(), udev_device_get_subsystem(), udev_device_get_driver() and udev_device_get_action() β give you back a pointer to a constant string that describes the property you asked for. Slay.
but here's the important part, don't skip it π β the lifetime of that string is bound to the device it was requested on. like, it's not your string, it's the device's string, so don't go freeing it or holding onto it after the device dips.
On failure, each function may return NULL. may. so like, check it, bestie.
π¦ devnum π¦
- On success,
udev_device_get_devnum()returns the device type of the passed device. - On failure, you get a device type with minor and major number set to
0. that's your "nothing to see here" signal.
π the udev context π
udev_device_get_udev() always returns a valid pointer to the udev context that this device belongs to. the way it never fails?? main character energy fr.
π parents π
On success, udev_device_get_parent() and udev_device_get_parent_with_subsystem_devtype() return a pointer to the parent device. and ngl this is the bit people trip on: no additional reference to this device is acquired, but the child device owns a reference to such a parent device. so the parent's alive because the kid's holding it down π«Ά
On failure, NULL is returned.
β is it initialized tho β
On success, udev_device_get_is_initialized() returns either 1 or 0, depending on whether the passed device has already been initialized by udev or not.
On failure, you get a negative error code.
π¨ real talk: devices for which no udev rules are defined are never reported initialized. so a 0 here isn't automatically a bug, iykyk.
π§ HISTORY π§
every single one of these β udev_device_get_syspath(), udev_device_get_sysname(), udev_device_get_sysnum(), udev_device_get_devpath(), udev_device_get_devnode(), udev_device_get_devnum(), udev_device_get_devtype(), udev_device_get_subsystem(), udev_device_get_driver(), udev_device_get_udev(), udev_device_get_parent(), udev_device_get_parent_with_subsystem_devtype(), udev_device_get_is_initialized(), and udev_device_get_action() β was added in version 221. vintage but still iconic π
π SEE ALSO π
go read these next, they're the friend group:
udev_new(3)udev_device_new_from_syspath(3)udev_device_has_tag(3)udev_enumerate_new(3)udev_monitor_new_from_netlink(3)udev_list_entry(3)systemd(1)
and that's the whole vibe check π this page ships with systemd 261.3, and you'll find it filed under UDEV_DEVICE_GET_SYSPATH(3) β go get those properties, bestie, you're gonna ate π¦β¨
π¦ where this page comes from
- ubuntu stonking: libudev-dev 261.3-0ubuntu3 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms