1UDEV_DEVICE_NEW_FROM_SYSPAuTdHe(v3_)device_new_from_syUsDpEaVt_hDEVICE_NEW_FROM_SYSPATH(3)
2
3
4
6 udev_device_new_from_syspath, udev_device_new_from_devnum,
7 udev_device_new_from_subsystem_sysname, udev_device_new_from_device_id,
8 udev_device_new_from_environment, udev_device_ref, udev_device_unref -
9 Create, acquire and release a udev device object
10
12 #include <libudev.h>
13
14 struct udev_device *udev_device_new_from_syspath(struct udev *udev,
15 const char *syspath);
16
17 struct udev_device *udev_device_new_from_devnum(struct udev *udev,
18 char type,
19 dev_t devnum);
20
21 struct udev_device
22 *udev_device_new_from_subsystem_sysname(struct udev *udev,
23 const char *subsystem,
24 const char *sysname);
25
26 struct udev_device *udev_device_new_from_device_id(struct udev *udev,
27 const char *id);
28
29 struct udev_device
30 *udev_device_new_from_environment(struct udev *udev);
31
32 struct udev_device *udev_device_ref(struct udev_device *udev_device);
33
34 struct udev_device *udev_device_unref(struct udev_device *udev_device);
35
37 udev_device_new_from_syspath(), udev_device_new_from_devnum(),
38 udev_device_new_from_subsystem_sysname(),
39 udev_device_new_from_device_id(), and
40 udev_device_new_from_environment() allocate a new udev device object
41 and returns a pointer to it. This object is opaque and must not be
42 accessed by the caller via different means than functions provided by
43 libudev. Initially, the reference count of the device is 1. You can
44 acquire further references, and drop gained references via
45 udev_device_ref() and udev_device_unref(). Once the reference count
46 hits 0, the device object is destroyed and freed.
47
48 udev_device_new_from_syspath(), udev_device_new_from_devnum(),
49 udev_device_new_from_subsystem_sysname(), and
50 udev_device_new_from_device_id() create the device object based on
51 information found in /sys/, annotated with properties from the
52 udev-internal device database. A syspath is any subdirectory of /sys/,
53 with the restriction that a subdirectory of /sys/devices (or a symlink
54 to one) represents a real device and as such must contain a uevent
55 file. udev_device_new_from_devnum() takes a device type, which can be
56 b for block devices or c for character devices, as well as a devnum
57 (see makedev(3)). udev_device_new_from_subsystem_sysname() looks up
58 devices based on the provided subsystem and sysname (see
59 udev_device_get_subsystem(3) and udev_device_get_sysname(3)) and
60 udev_device_new_from_device_id() looks up devices based on the provided
61 device ID, which is a special string in one of the following four
62 forms:
63
64 Table 1. Device ID strings
65 ┌──────────────┬──────────────────────────┐
66 │Example │ Explanation │
67 ├──────────────┼──────────────────────────┤
68 │b8:2 │ block device major:minor │
69 ├──────────────┼──────────────────────────┤
70 │c128:1 │ char device major:minor │
71 ├──────────────┼──────────────────────────┤
72 │n3 │ network device ifindex │
73 ├──────────────┼──────────────────────────┤
74 │+sound:card29 │ kernel driver core │
75 │ │ subsystem:device name │
76 └──────────────┴──────────────────────────┘
77
78 udev_device_new_from_environment() creates a device from the current
79 environment (see environ(7)). Each key-value pair is interpreted in the
80 same way as if it was received in an uevent (see
81 udev_monitor_receive_device(3)). The keys DEVPATH, SUBSYSTEM, ACTION,
82 and SEQNUM are mandatory.
83
85 On success, udev_device_new_from_syspath(),
86 udev_device_new_from_devnum(),
87 udev_device_new_from_subsystem_sysname(),
88 udev_device_new_from_device_id() and udev_device_new_from_environment()
89 return a pointer to the allocated udev device. On failure, NULL is
90 returned, and errno is set appropriately. udev_device_ref() returns
91 the argument that it was passed, unmodified. udev_device_unref()
92 always returns NULL.
93
95 udev_new(3), udev_device_get_syspath(3), udev_device_has_tag(3),
96 udev_enumerate_new(3), udev_monitor_new_from_netlink(3),
97 udev_list_entry(3), systemd(1),
98
99
100
101systemd 249 UDEV_DEVICE_NEW_FROM_SYSPATH(3)