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 |
11 | extern "C" { |
12 | #endif |
13 | |
14 | /* |
15 | * udev - library context |
16 | * |
17 | * reads the udev config and system environment |
18 | * allows custom logging |
19 | */ |
20 | struct udev; |
21 | struct udev *udev_ref(struct udev *udev); |
22 | struct udev *udev_unref(struct udev *udev); |
23 | struct udev *udev_new(void); |
24 | void 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__)); |
28 | int udev_get_log_priority(struct udev *udev) __attribute__((__deprecated__)); |
29 | void udev_set_log_priority(struct udev *udev, int priority) __attribute__((__deprecated__)); |
30 | void *udev_get_userdata(struct udev *udev); |
31 | void udev_set_userdata(struct udev *udev, void *userdata); |
32 | |
33 | /* |
34 | * udev_list |
35 | * |
36 | * access to libudev generated lists |
37 | */ |
38 | struct udev_list_entry; |
39 | struct udev_list_entry *udev_list_entry_get_next(struct udev_list_entry *list_entry); |
40 | struct udev_list_entry *udev_list_entry_get_by_name(struct udev_list_entry *list_entry, const char *name); |
41 | const char *udev_list_entry_get_name(struct udev_list_entry *list_entry); |
42 | const 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 | */ |
60 | struct udev_device; |
61 | struct udev_device *udev_device_ref(struct udev_device *udev_device); |
62 | struct udev_device *udev_device_unref(struct udev_device *udev_device); |
63 | struct udev *udev_device_get_udev(struct udev_device *udev_device); |
64 | struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *syspath); |
65 | struct udev_device *udev_device_new_from_devnum(struct udev *udev, char type, dev_t devnum); |
66 | struct udev_device *udev_device_new_from_subsystem_sysname(struct udev *udev, const char *subsystem, const char *sysname); |
67 | struct udev_device *udev_device_new_from_device_id(struct udev *udev, const char *id); |
68 | struct 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 */ |
70 | struct udev_device *udev_device_get_parent(struct udev_device *udev_device); |
71 | struct 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 */ |
74 | const char *udev_device_get_devpath(struct udev_device *udev_device); |
75 | const char *udev_device_get_subsystem(struct udev_device *udev_device); |
76 | const char *udev_device_get_devtype(struct udev_device *udev_device); |
77 | const char *udev_device_get_syspath(struct udev_device *udev_device); |
78 | const char *udev_device_get_sysname(struct udev_device *udev_device); |
79 | const char *udev_device_get_sysnum(struct udev_device *udev_device); |
80 | const char *udev_device_get_devnode(struct udev_device *udev_device); |
81 | int udev_device_get_is_initialized(struct udev_device *udev_device); |
82 | struct udev_list_entry *udev_device_get_devlinks_list_entry(struct udev_device *udev_device); |
83 | struct udev_list_entry *udev_device_get_properties_list_entry(struct udev_device *udev_device); |
84 | struct udev_list_entry *udev_device_get_tags_list_entry(struct udev_device *udev_device); |
85 | struct udev_list_entry *udev_device_get_current_tags_list_entry(struct udev_device *udev_device); |
86 | struct udev_list_entry *udev_device_get_sysattr_list_entry(struct udev_device *udev_device); |
87 | const char *udev_device_get_property_value(struct udev_device *udev_device, const char *key); |
88 | const char *udev_device_get_driver(struct udev_device *udev_device); |
89 | dev_t udev_device_get_devnum(struct udev_device *udev_device); |
90 | const char *udev_device_get_action(struct udev_device *udev_device); |
91 | unsigned long long int udev_device_get_seqnum(struct udev_device *udev_device); |
92 | unsigned long long int udev_device_get_usec_since_initialized(struct udev_device *udev_device); |
93 | const char *udev_device_get_sysattr_value(struct udev_device *udev_device, const char *sysattr); |
94 | int udev_device_set_sysattr_value(struct udev_device *udev_device, const char *sysattr, const char *value); |
95 | int udev_device_has_tag(struct udev_device *udev_device, const char *tag); |
96 | int 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 | */ |
103 | struct udev_monitor; |
104 | struct udev_monitor *udev_monitor_ref(struct udev_monitor *udev_monitor); |
105 | struct udev_monitor *udev_monitor_unref(struct udev_monitor *udev_monitor); |
106 | struct udev *udev_monitor_get_udev(struct udev_monitor *udev_monitor); |
107 | /* kernel and udev generated events over netlink */ |
108 | struct udev_monitor *udev_monitor_new_from_netlink(struct udev *udev, const char *name); |
109 | /* bind socket */ |
110 | int udev_monitor_enable_receiving(struct udev_monitor *udev_monitor); |
111 | int udev_monitor_set_receive_buffer_size(struct udev_monitor *udev_monitor, int size); |
112 | int udev_monitor_get_fd(struct udev_monitor *udev_monitor); |
113 | struct 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 */ |
115 | int udev_monitor_filter_add_match_subsystem_devtype(struct udev_monitor *udev_monitor, |
116 | const char *subsystem, const char *devtype); |
117 | int udev_monitor_filter_add_match_tag(struct udev_monitor *udev_monitor, const char *tag); |
118 | int udev_monitor_filter_update(struct udev_monitor *udev_monitor); |
119 | int 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 | */ |
126 | struct udev_enumerate; |
127 | struct udev_enumerate *udev_enumerate_ref(struct udev_enumerate *udev_enumerate); |
128 | struct udev_enumerate *udev_enumerate_unref(struct udev_enumerate *udev_enumerate); |
129 | struct udev *udev_enumerate_get_udev(struct udev_enumerate *udev_enumerate); |
130 | struct udev_enumerate *udev_enumerate_new(struct udev *udev); |
131 | /* device properties filter */ |
132 | int udev_enumerate_add_match_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem); |
133 | int udev_enumerate_add_nomatch_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem); |
134 | int udev_enumerate_add_match_sysattr(struct udev_enumerate *udev_enumerate, const char *sysattr, const char *value); |
135 | int udev_enumerate_add_nomatch_sysattr(struct udev_enumerate *udev_enumerate, const char *sysattr, const char *value); |
136 | int udev_enumerate_add_match_property(struct udev_enumerate *udev_enumerate, const char *property, const char *value); |
137 | int udev_enumerate_add_match_sysname(struct udev_enumerate *udev_enumerate, const char *sysname); |
138 | int udev_enumerate_add_match_tag(struct udev_enumerate *udev_enumerate, const char *tag); |
139 | int udev_enumerate_add_match_parent(struct udev_enumerate *udev_enumerate, struct udev_device *parent); |
140 | int udev_enumerate_add_match_is_initialized(struct udev_enumerate *udev_enumerate); |
141 | int udev_enumerate_add_syspath(struct udev_enumerate *udev_enumerate, const char *syspath); |
142 | /* run enumeration with active filters */ |
143 | int udev_enumerate_scan_devices(struct udev_enumerate *udev_enumerate); |
144 | int udev_enumerate_scan_subsystems(struct udev_enumerate *udev_enumerate); |
145 | /* return device list */ |
146 | struct 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 | */ |
153 | struct udev_queue; |
154 | struct udev_queue *udev_queue_ref(struct udev_queue *udev_queue); |
155 | struct udev_queue *udev_queue_unref(struct udev_queue *udev_queue); |
156 | struct udev *udev_queue_get_udev(struct udev_queue *udev_queue); |
157 | struct udev_queue *udev_queue_new(struct udev *udev); |
158 | unsigned long long int udev_queue_get_kernel_seqnum(struct udev_queue *udev_queue) __attribute__((__deprecated__)); |
159 | unsigned long long int udev_queue_get_udev_seqnum(struct udev_queue *udev_queue) __attribute__((__deprecated__)); |
160 | int udev_queue_get_udev_is_active(struct udev_queue *udev_queue); |
161 | int udev_queue_get_queue_is_empty(struct udev_queue *udev_queue); |
162 | int udev_queue_get_seqnum_is_finished(struct udev_queue *udev_queue, unsigned long long int seqnum) __attribute__((__deprecated__)); |
163 | int 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__)); |
165 | int udev_queue_get_fd(struct udev_queue *udev_queue); |
166 | int udev_queue_flush(struct udev_queue *udev_queue); |
167 | struct 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 | */ |
174 | struct udev_hwdb; |
175 | struct udev_hwdb *udev_hwdb_new(struct udev *udev); |
176 | struct udev_hwdb *udev_hwdb_ref(struct udev_hwdb *hwdb); |
177 | struct udev_hwdb *udev_hwdb_unref(struct udev_hwdb *hwdb); |
178 | struct 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 | */ |
185 | int 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 | |