1/* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3#ifndef _LIBUDEV_H_
4#define _LIBUDEV_H_
5
6#include <stdarg.h>
7#include <sys/sysmacros.h>
8#include <sys/types.h>
9
10#ifdef __cplusplus
11extern "C" {
12#endif
13
14/*
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);
32
33/*
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);
43/**
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))
54
55/*
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_current_tags_list_entry(struct udev_device *udev_device);
86struct udev_list_entry *udev_device_get_sysattr_list_entry(struct udev_device *udev_device);
87const char *udev_device_get_property_value(struct udev_device *udev_device, const char *key);
88const char *udev_device_get_driver(struct udev_device *udev_device);
89dev_t udev_device_get_devnum(struct udev_device *udev_device);
90const char *udev_device_get_action(struct udev_device *udev_device);
91unsigned long long int udev_device_get_seqnum(struct udev_device *udev_device);
92unsigned long long int udev_device_get_usec_since_initialized(struct udev_device *udev_device);
93const char *udev_device_get_sysattr_value(struct udev_device *udev_device, const char *sysattr);
94int udev_device_set_sysattr_value(struct udev_device *udev_device, const char *sysattr, const char *value);
95int udev_device_has_tag(struct udev_device *udev_device, const char *tag);
96int udev_device_has_current_tag(struct udev_device *udev_device, const char *tag);
97
98/*
99 * udev_monitor
100 *
101 * access to kernel uevents and udev events
102 */
103struct udev_monitor;
104struct udev_monitor *udev_monitor_ref(struct udev_monitor *udev_monitor);
105struct udev_monitor *udev_monitor_unref(struct udev_monitor *udev_monitor);
106struct udev *udev_monitor_get_udev(struct udev_monitor *udev_monitor);
107/* kernel and udev generated events over netlink */
108struct udev_monitor *udev_monitor_new_from_netlink(struct udev *udev, const char *name);
109/* bind socket */
110int udev_monitor_enable_receiving(struct udev_monitor *udev_monitor);
111int udev_monitor_set_receive_buffer_size(struct udev_monitor *udev_monitor, int size);
112int udev_monitor_get_fd(struct udev_monitor *udev_monitor);
113struct udev_device *udev_monitor_receive_device(struct udev_monitor *udev_monitor);
114/* in-kernel socket filters to select messages that get delivered to a listener */
115int udev_monitor_filter_add_match_subsystem_devtype(struct udev_monitor *udev_monitor,
116 const char *subsystem, const char *devtype);
117int udev_monitor_filter_add_match_tag(struct udev_monitor *udev_monitor, const char *tag);
118int udev_monitor_filter_update(struct udev_monitor *udev_monitor);
119int udev_monitor_filter_remove(struct udev_monitor *udev_monitor);
120
121/*
122 * udev_enumerate
123 *
124 * search sysfs for specific devices and provide a sorted list
125 */
126struct udev_enumerate;
127struct udev_enumerate *udev_enumerate_ref(struct udev_enumerate *udev_enumerate);
128struct udev_enumerate *udev_enumerate_unref(struct udev_enumerate *udev_enumerate);
129struct udev *udev_enumerate_get_udev(struct udev_enumerate *udev_enumerate);
130struct udev_enumerate *udev_enumerate_new(struct udev *udev);
131/* device properties filter */
132int udev_enumerate_add_match_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem);
133int udev_enumerate_add_nomatch_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem);
134int udev_enumerate_add_match_sysattr(struct udev_enumerate *udev_enumerate, const char *sysattr, const char *value);
135int udev_enumerate_add_nomatch_sysattr(struct udev_enumerate *udev_enumerate, const char *sysattr, const char *value);
136int udev_enumerate_add_match_property(struct udev_enumerate *udev_enumerate, const char *property, const char *value);
137int udev_enumerate_add_match_sysname(struct udev_enumerate *udev_enumerate, const char *sysname);
138int udev_enumerate_add_match_tag(struct udev_enumerate *udev_enumerate, const char *tag);
139int udev_enumerate_add_match_parent(struct udev_enumerate *udev_enumerate, struct udev_device *parent);
140int udev_enumerate_add_match_is_initialized(struct udev_enumerate *udev_enumerate);
141int udev_enumerate_add_syspath(struct udev_enumerate *udev_enumerate, const char *syspath);
142/* run enumeration with active filters */
143int udev_enumerate_scan_devices(struct udev_enumerate *udev_enumerate);
144int udev_enumerate_scan_subsystems(struct udev_enumerate *udev_enumerate);
145/* return device list */
146struct udev_list_entry *udev_enumerate_get_list_entry(struct udev_enumerate *udev_enumerate);
147
148/*
149 * udev_queue
150 *
151 * access to the currently running udev events
152 */
153struct udev_queue;
154struct udev_queue *udev_queue_ref(struct udev_queue *udev_queue);
155struct udev_queue *udev_queue_unref(struct udev_queue *udev_queue);
156struct udev *udev_queue_get_udev(struct udev_queue *udev_queue);
157struct udev_queue *udev_queue_new(struct udev *udev);
158unsigned long long int udev_queue_get_kernel_seqnum(struct udev_queue *udev_queue) __attribute__((__deprecated__));
159unsigned long long int udev_queue_get_udev_seqnum(struct udev_queue *udev_queue) __attribute__((__deprecated__));
160int udev_queue_get_udev_is_active(struct udev_queue *udev_queue);
161int udev_queue_get_queue_is_empty(struct udev_queue *udev_queue);
162int udev_queue_get_seqnum_is_finished(struct udev_queue *udev_queue, unsigned long long int seqnum) __attribute__((__deprecated__));
163int udev_queue_get_seqnum_sequence_is_finished(struct udev_queue *udev_queue,
164 unsigned long long int start, unsigned long long int end) __attribute__((__deprecated__));
165int udev_queue_get_fd(struct udev_queue *udev_queue);
166int udev_queue_flush(struct udev_queue *udev_queue);
167struct udev_list_entry *udev_queue_get_queued_list_entry(struct udev_queue *udev_queue) __attribute__((__deprecated__));
168
169/*
170 * udev_hwdb
171 *
172 * access to the static hardware properties database
173 */
174struct udev_hwdb;
175struct udev_hwdb *udev_hwdb_new(struct udev *udev);
176struct udev_hwdb *udev_hwdb_ref(struct udev_hwdb *hwdb);
177struct udev_hwdb *udev_hwdb_unref(struct udev_hwdb *hwdb);
178struct udev_list_entry *udev_hwdb_get_properties_list_entry(struct udev_hwdb *hwdb, const char *modalias, unsigned flags);
179
180/*
181 * udev_util
182 *
183 * udev specific utilities
184 */
185int udev_util_encode_string(const char *str, char *str_enc, size_t len);
186
187#ifdef __cplusplus
188} /* extern "C" */
189#endif
190
191#endif
192

source code of include/libudev.h