1/* SPDX-License-Identifier: LGPL-2.1+ */
3#ifndef _LIBUDEV_H_
4#define _LIBUDEV_H_
6#include <stdarg.h>
7#include <sys/sysmacros.h>
8#include <sys/types.h>
10#ifdef __cplusplus
11extern "C" {
15 * udev - library context
16 *
17 * reads the udev config and system environment
18 * allows custom logging
19 */
20struct udev;
21struct udev *udev_ref(struct udev *udev);
22struct udev *udev_unref(struct udev *udev);
23struct udev *udev_new(void);
24void udev_set_log_fn(struct udev *udev,
25 void (*log_fn)(struct udev *udev,
26 int priority, const char *file, int line, const char *fn,
27 const char *format, va_list args)) __attribute__((__deprecated__));
28int udev_get_log_priority(struct udev *udev) __attribute__((__deprecated__));
29void udev_set_log_priority(struct udev *udev, int priority) __attribute__((__deprecated__));
30void *udev_get_userdata(struct udev *udev);
31void udev_set_userdata(struct udev *udev, void *userdata);
34 * udev_list
35 *
36 * access to libudev generated lists
37 */
38struct udev_list_entry;
39struct udev_list_entry *udev_list_entry_get_next(struct udev_list_entry *list_entry);
40struct udev_list_entry *udev_list_entry_get_by_name(struct udev_list_entry *list_entry, const char *name);
41const char *udev_list_entry_get_name(struct udev_list_entry *list_entry);
42const char *udev_list_entry_get_value(struct udev_list_entry *list_entry);
44 * udev_list_entry_foreach:
45 * @list_entry: entry to store the current position
46 * @first_entry: first entry to start with
47 *
48 * Helper to iterate over all entries of a list.
49 */
50#define udev_list_entry_foreach(list_entry, first_entry) \
51 for (list_entry = first_entry; \
52 list_entry; \
53 list_entry = udev_list_entry_get_next(list_entry))
56 * udev_device
57 *
58 * access to sysfs/kernel devices
59 */
60struct udev_device;
61struct udev_device *udev_device_ref(struct udev_device *udev_device);
62struct udev_device *udev_device_unref(struct udev_device *udev_device);
63struct udev *udev_device_get_udev(struct udev_device *udev_device);
64struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *syspath);
65struct udev_device *udev_device_new_from_devnum(struct udev *udev, char type, dev_t devnum);
66struct udev_device *udev_device_new_from_subsystem_sysname(struct udev *udev, const char *subsystem, const char *sysname);
67struct udev_device *udev_device_new_from_device_id(struct udev *udev, const char *id);
68struct udev_device *udev_device_new_from_environment(struct udev *udev);
69/* udev_device_get_parent_*() does not take a reference on the returned device, it is automatically unref'd with the parent */
70struct udev_device *udev_device_get_parent(struct udev_device *udev_device);
71struct udev_device *udev_device_get_parent_with_subsystem_devtype(struct udev_device *udev_device,
72 const char *subsystem, const char *devtype);
73/* retrieve device properties */
74const char *udev_device_get_devpath(struct udev_device *udev_device);
75const char *udev_device_get_subsystem(struct udev_device *udev_device);
76const char *udev_device_get_devtype(struct udev_device *udev_device);
77const char *udev_device_get_syspath(struct udev_device *udev_device);
78const char *udev_device_get_sysname(struct udev_device *udev_device);
79const char *udev_device_get_sysnum(struct udev_device *udev_device);
80const char *udev_device_get_devnode(struct udev_device *udev_device);
81int udev_device_get_is_initialized(struct udev_device *udev_device);
82struct udev_list_entry *udev_device_get_devlinks_list_entry(struct udev_device *udev_device);
83struct udev_list_entry *udev_device_get_properties_list_entry(struct udev_device *udev_device);
84struct udev_list_entry *udev_device_get_tags_list_entry(struct udev_device *udev_device);
85struct udev_list_entry *udev_device_get_sysattr_list_entry(struct udev_device *udev_device);
86const char *udev_device_get_property_value(struct udev_device *udev_device, const char *key);
87const char *udev_device_get_driver(struct udev_device *udev_device);
88dev_t udev_device_get_devnum(struct udev_device *udev_device);
89const char *udev_device_get_action(struct udev_device *udev_device);
90unsigned long long int udev_device_get_seqnum(struct udev_device *udev_device);
91unsigned long long int udev_device_get_usec_since_initialized(struct udev_device *udev_device);
92const char *udev_device_get_sysattr_value(struct udev_device *udev_device, const char *sysattr);
93int udev_device_set_sysattr_value(struct udev_device *udev_device, const char *sysattr, const char *value);
94int udev_device_has_tag(struct udev_device *udev_device, const char *tag);
97 * udev_monitor
98 *
99 * access to kernel uevents and udev events
100 */
101struct udev_monitor;
102struct udev_monitor *udev_monitor_ref(struct udev_monitor *udev_monitor);
103struct udev_monitor *udev_monitor_unref(struct udev_monitor *udev_monitor);
104struct udev *udev_monitor_get_udev(struct udev_monitor *udev_monitor);
105/* kernel and udev generated events over netlink */
106struct udev_monitor *udev_monitor_new_from_netlink(struct udev *udev, const char *name);
107/* bind socket */
108int udev_monitor_enable_receiving(struct udev_monitor *udev_monitor);
109int udev_monitor_set_receive_buffer_size(struct udev_monitor *udev_monitor, int size);
110int udev_monitor_get_fd(struct udev_monitor *udev_monitor);
111struct udev_device *udev_monitor_receive_device(struct udev_monitor *udev_monitor);
112/* in-kernel socket filters to select messages that get delivered to a listener */
113int udev_monitor_filter_add_match_subsystem_devtype(struct udev_monitor *udev_monitor,
114 const char *subsystem, const char *devtype);
115int udev_monitor_filter_add_match_tag(struct udev_monitor *udev_monitor, const char *tag);
116int udev_monitor_filter_update(struct udev_monitor *udev_monitor);
117int udev_monitor_filter_remove(struct udev_monitor *udev_monitor);
120 * udev_enumerate
121 *
122 * search sysfs for specific devices and provide a sorted list
123 */
124struct udev_enumerate;
125struct udev_enumerate *udev_enumerate_ref(struct udev_enumerate *udev_enumerate);
126struct udev_enumerate *udev_enumerate_unref(struct udev_enumerate *udev_enumerate);
127struct udev *udev_enumerate_get_udev(struct udev_enumerate *udev_enumerate);
128struct udev_enumerate *udev_enumerate_new(struct udev *udev);
129/* device properties filter */
130int udev_enumerate_add_match_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem);
131int udev_enumerate_add_nomatch_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem);
132int udev_enumerate_add_match_sysattr(struct udev_enumerate *udev_enumerate, const char *sysattr, const char *value);
133int udev_enumerate_add_nomatch_sysattr(struct udev_enumerate *udev_enumerate, const char *sysattr, const char *value);
134int udev_enumerate_add_match_property(struct udev_enumerate *udev_enumerate, const char *property, const char *value);
135int udev_enumerate_add_match_sysname(struct udev_enumerate *udev_enumerate, const char *sysname);
136int udev_enumerate_add_match_tag(struct udev_enumerate *udev_enumerate, const char *tag);
137int udev_enumerate_add_match_parent(struct udev_enumerate *udev_enumerate, struct udev_device *parent);
138int udev_enumerate_add_match_is_initialized(struct udev_enumerate *udev_enumerate);
139int udev_enumerate_add_syspath(struct udev_enumerate *udev_enumerate, const char *syspath);
140/* run enumeration with active filters */
141int udev_enumerate_scan_devices(struct udev_enumerate *udev_enumerate);
142int udev_enumerate_scan_subsystems(struct udev_enumerate *udev_enumerate);
143/* return device list */
144struct udev_list_entry *udev_enumerate_get_list_entry(struct udev_enumerate *udev_enumerate);
147 * udev_queue
148 *
149 * access to the currently running udev events
150 */
151struct udev_queue;
152struct udev_queue *udev_queue_ref(struct udev_queue *udev_queue);
153struct udev_queue *udev_queue_unref(struct udev_queue *udev_queue);
154struct udev *udev_queue_get_udev(struct udev_queue *udev_queue);
155struct udev_queue *udev_queue_new(struct udev *udev);
156unsigned long long int udev_queue_get_kernel_seqnum(struct udev_queue *udev_queue) __attribute__((__deprecated__));
157 unsigned long long int udev_queue_get_udev_seqnum(struct udev_queue *udev_queue) __attribute__((__deprecated__));
158int udev_queue_get_udev_is_active(struct udev_queue *udev_queue);
159int udev_queue_get_queue_is_empty(struct udev_queue *udev_queue);
160int udev_queue_get_seqnum_is_finished(struct udev_queue *udev_queue, unsigned long long int seqnum) __attribute__((__deprecated__));
161int udev_queue_get_seqnum_sequence_is_finished(struct udev_queue *udev_queue,
162 unsigned long long int start, unsigned long long int end) __attribute__((__deprecated__));
163int udev_queue_get_fd(struct udev_queue *udev_queue);
164int udev_queue_flush(struct udev_queue *udev_queue);
165struct udev_list_entry *udev_queue_get_queued_list_entry(struct udev_queue *udev_queue) __attribute__((__deprecated__));
168 * udev_hwdb
169 *
170 * access to the static hardware properties database
171 */
172struct udev_hwdb;
173struct udev_hwdb *udev_hwdb_new(struct udev *udev);
174struct udev_hwdb *udev_hwdb_ref(struct udev_hwdb *hwdb);
175struct udev_hwdb *udev_hwdb_unref(struct udev_hwdb *hwdb);
176struct udev_list_entry *udev_hwdb_get_properties_list_entry(struct udev_hwdb *hwdb, const char *modalias, unsigned flags);
179 * udev_util
180 *
181 * udev specific utilities
182 */
183int udev_util_encode_string(const char *str, char *str_enc, size_t len);
185#ifdef __cplusplus
186} /* extern "C" */