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_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
  • udev_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:


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