NAME |SYNOPSIS |DESCRIPTION |RETURN VALUE |HISTORY |SEE ALSO |COLOPHON | |
UDEV_DEV..._SYSPATH(3) udev_device_new_from_syspathUDEV_DEV..._SYSPATH(3)udev_device_new_from_syspath, udev_device_new_from_devnum, udev_device_new_from_subsystem_sysname, udev_device_new_from_device_id, udev_device_new_from_environment, udev_device_ref, udev_device_unref - Create, acquire and release a udev device object
#include <libudev.h>struct udev_device*udev_device_new_from_syspath(struct udev *udev,const char *syspath);struct udev_device *udev_device_new_from_devnum(struct udev *udev,chartype,dev_tdevnum);struct udev_device*udev_device_new_from_subsystem_sysname(struct udev *udev,const char *subsystem,const char *sysname);struct udev_device*udev_device_new_from_device_id(struct udev *udev,const char *id);struct udev_device*udev_device_new_from_environment(struct udev *udev);struct udev_device*udev_device_ref(struct udev_device *udev_device);struct udev_device*udev_device_unref(struct udev_device *udev_device);
udev_device_new_from_syspath(),udev_device_new_from_devnum(),udev_device_new_from_subsystem_sysname(),udev_device_new_from_device_id(), andudev_device_new_from_environment()allocate a new udev device object and returns a pointer to it. This object is opaque and must not be accessed by the caller via different means than functions provided by libudev. Initially, the reference count of the device is 1. You can acquire further references, and drop gained references viaudev_device_ref()andudev_device_unref(). Once the reference count hits 0, the device object is destroyed and freed.udev_device_new_from_syspath(),udev_device_new_from_devnum(),udev_device_new_from_subsystem_sysname(), andudev_device_new_from_device_id()create the device object based on information found in /sys/, annotated with properties from the udev-internal device database. A syspath is any subdirectory of /sys/, with the restriction that a subdirectory of /sys/devices (or a symlink to one) represents a real device and as such must contain a uevent file.udev_device_new_from_devnum()takes a device type, which can bebfor block devices orcfor character devices, as well as a devnum (seemakedev(3)).udev_device_new_from_subsystem_sysname()looks up devices based on the provided subsystem and sysname (seeudev_device_get_subsystem(3) andudev_device_get_sysname(3)) andudev_device_new_from_device_id()looks up devices based on the provided device ID, which is a special string in one of the following four forms:Table 1. Device ID strings ┌───────────────┬──────────────────────────┐ │Example│Explanation│ ├───────────────┼──────────────────────────┤ │b8:2 │ block device major:minor │ ├───────────────┼──────────────────────────┤ │c128:1 │ char device major:minor │ ├───────────────┼──────────────────────────┤ │n3 │ network device ifindex │ ├───────────────┼──────────────────────────┤ │+sound:card29 │ kernel driver core │ │ │ subsystem:device name │ └───────────────┴──────────────────────────┘udev_device_new_from_environment()creates a device from the current environment (seeenviron(7)). Each key-value pair is interpreted in the same way as if it was received in an uevent (seeudev_monitor_receive_device(3)). The keysDEVPATH,SUBSYSTEM,ACTION, andSEQNUMare mandatory.
On success,udev_device_new_from_syspath(),udev_device_new_from_devnum(),udev_device_new_from_subsystem_sysname(),udev_device_new_from_device_id()andudev_device_new_from_environment()return a pointer to the allocated udev device. On failure,NULLis returned, anderrno is set appropriately.udev_device_ref()returns the argument that it was passed, unmodified.udev_device_unref()always returnsNULL.
udev_device_new_from_syspath(),udev_device_new_from_devnum(),udev_device_new_from_subsystem_sysname(),udev_device_new_from_device_id(),udev_device_new_from_environment(),udev_device_ref(), andudev_device_unref()were added in version 221.
udev_new(3),udev_device_get_syspath(3),udev_device_has_tag(3),udev_enumerate_new(3),udev_monitor_new_from_netlink(3),udev_list_entry(3),systemd(1)
This page is part of thesystemd (systemd system and service manager) project. Information about the project can be found at ⟨http://www.freedesktop.org/wiki/Software/systemd⟩. If you have a bug report for this manual page, see ⟨http://www.freedesktop.org/wiki/Software/systemd/#bugreports⟩. This page was obtained from the project's upstream Git repository ⟨https://github.com/systemd/systemd.git⟩ on 2025-08-11. (At that time, the date of the most recent commit that was found in the repository was 2025-08-11.) If you discover any rendering problems in this HTML version of the page, or you believe there is a better or more up-to-date source for the page, or you have corrections or improvements to the information in this COLOPHON (which isnot part of the original manual page), send a mail to man-pages@man7.orgsystemd 258~rc2UDEV_DEV..._SYSPATH(3)Pages that refer to this page:libudev(3), udev_device_get_syspath(3), udev_device_has_tag(3), udev_enumerate_add_match_subsystem(3), udev_enumerate_new(3), udev_enumerate_scan_devices(3), udev_list_entry(3), udev_monitor_filter_update(3), udev_monitor_new_from_netlink(3), udev_monitor_receive_device(3), systemd.directives(7), systemd.index(7)
HTML rendering created 2025-09-06 byMichael Kerrisk, author ofThe Linux Programming Interface. For details of in-depthLinux/UNIX system programming training courses that I teach, lookhere. Hosting byjambit GmbH. | ![]() |