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