1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
2 | /*** |
3 | This file is part of systemd. |
4 | |
5 | Copyright 2008-2012 Kay Sievers <kay@vrfy.org> |
6 | |
7 | systemd is free software; you can redistribute it and/or modify it |
8 | under the terms of the GNU Lesser General Public License as published by |
9 | the Free Software Foundation; either version 2.1 of the License, or |
10 | (at your option) any later version. |
11 | |
12 | systemd is distributed in the hope that it will be useful, but |
13 | WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | Lesser General Public License for more details. |
16 | |
17 | You should have received a copy of the GNU Lesser General Public License |
18 | along with systemd; If not, see <http://www.gnu.org/licenses/>. |
19 | ***/ |
20 | |
21 | #ifndef _LIBUDEV_H_ |
22 | #define _LIBUDEV_H_ |
23 | |
24 | #include <stdarg.h> |
25 | #include <sys/sysmacros.h> |
26 | #include <sys/types.h> |
27 | |
28 | #ifdef __cplusplus |
29 | extern "C" { |
30 | #endif |
31 | |
32 | /* |
33 | * udev - library context |
34 | * |
35 | * reads the udev config and system environment |
36 | * allows custom logging |
37 | */ |
38 | struct udev; |
39 | struct udev *udev_ref(struct udev *udev); |
40 | struct udev *udev_unref(struct udev *udev); |
41 | struct udev *udev_new(void); |
42 | void udev_set_log_fn(struct udev *udev, |
43 | void (*log_fn)(struct udev *udev, |
44 | int priority, const char *file, int line, const char *fn, |
45 | const char *format, va_list args)) __attribute__ ((deprecated)); |
46 | int udev_get_log_priority(struct udev *udev) __attribute__ ((deprecated)); |
47 | void udev_set_log_priority(struct udev *udev, int priority) __attribute__ ((deprecated)); |
48 | void *udev_get_userdata(struct udev *udev); |
49 | void udev_set_userdata(struct udev *udev, void *userdata); |
50 | |
51 | /* |
52 | * udev_list |
53 | * |
54 | * access to libudev generated lists |
55 | */ |
56 | struct udev_list_entry; |
57 | struct udev_list_entry *udev_list_entry_get_next(struct udev_list_entry *list_entry); |
58 | struct udev_list_entry *udev_list_entry_get_by_name(struct udev_list_entry *list_entry, const char *name); |
59 | const char *udev_list_entry_get_name(struct udev_list_entry *list_entry); |
60 | const char *udev_list_entry_get_value(struct udev_list_entry *list_entry); |
61 | /** |
62 | * udev_list_entry_foreach: |
63 | * @list_entry: entry to store the current position |
64 | * @first_entry: first entry to start with |
65 | * |
66 | * Helper to iterate over all entries of a list. |
67 | */ |
68 | #define udev_list_entry_foreach(list_entry, first_entry) \ |
69 | for (list_entry = first_entry; \ |
70 | list_entry != NULL; \ |
71 | list_entry = udev_list_entry_get_next(list_entry)) |
72 | |
73 | /* |
74 | * udev_device |
75 | * |
76 | * access to sysfs/kernel devices |
77 | */ |
78 | struct udev_device; |
79 | struct udev_device *udev_device_ref(struct udev_device *udev_device); |
80 | struct udev_device *udev_device_unref(struct udev_device *udev_device); |
81 | struct udev *udev_device_get_udev(struct udev_device *udev_device); |
82 | struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *syspath); |
83 | struct udev_device *udev_device_new_from_devnum(struct udev *udev, char type, dev_t devnum); |
84 | struct udev_device *udev_device_new_from_subsystem_sysname(struct udev *udev, const char *subsystem, const char *sysname); |
85 | struct udev_device *udev_device_new_from_device_id(struct udev *udev, const char *id); |
86 | struct udev_device *udev_device_new_from_environment(struct udev *udev); |
87 | /* udev_device_get_parent_*() does not take a reference on the returned device, it is automatically unref'd with the parent */ |
88 | struct udev_device *udev_device_get_parent(struct udev_device *udev_device); |
89 | struct udev_device *udev_device_get_parent_with_subsystem_devtype(struct udev_device *udev_device, |
90 | const char *subsystem, const char *devtype); |
91 | /* retrieve device properties */ |
92 | const char *udev_device_get_devpath(struct udev_device *udev_device); |
93 | const char *udev_device_get_subsystem(struct udev_device *udev_device); |
94 | const char *udev_device_get_devtype(struct udev_device *udev_device); |
95 | const char *udev_device_get_syspath(struct udev_device *udev_device); |
96 | const char *udev_device_get_sysname(struct udev_device *udev_device); |
97 | const char *udev_device_get_sysnum(struct udev_device *udev_device); |
98 | const char *udev_device_get_devnode(struct udev_device *udev_device); |
99 | int udev_device_get_is_initialized(struct udev_device *udev_device); |
100 | struct udev_list_entry *udev_device_get_devlinks_list_entry(struct udev_device *udev_device); |
101 | struct udev_list_entry *udev_device_get_properties_list_entry(struct udev_device *udev_device); |
102 | struct udev_list_entry *udev_device_get_tags_list_entry(struct udev_device *udev_device); |
103 | struct udev_list_entry *udev_device_get_sysattr_list_entry(struct udev_device *udev_device); |
104 | const char *udev_device_get_property_value(struct udev_device *udev_device, const char *key); |
105 | const char *udev_device_get_driver(struct udev_device *udev_device); |
106 | dev_t udev_device_get_devnum(struct udev_device *udev_device); |
107 | const char *udev_device_get_action(struct udev_device *udev_device); |
108 | unsigned long long int udev_device_get_seqnum(struct udev_device *udev_device); |
109 | unsigned long long int udev_device_get_usec_since_initialized(struct udev_device *udev_device); |
110 | const char *udev_device_get_sysattr_value(struct udev_device *udev_device, const char *sysattr); |
111 | int udev_device_set_sysattr_value(struct udev_device *udev_device, const char *sysattr, char *value); |
112 | int udev_device_has_tag(struct udev_device *udev_device, const char *tag); |
113 | |
114 | /* |
115 | * udev_monitor |
116 | * |
117 | * access to kernel uevents and udev events |
118 | */ |
119 | struct udev_monitor; |
120 | struct udev_monitor *udev_monitor_ref(struct udev_monitor *udev_monitor); |
121 | struct udev_monitor *udev_monitor_unref(struct udev_monitor *udev_monitor); |
122 | struct udev *udev_monitor_get_udev(struct udev_monitor *udev_monitor); |
123 | /* kernel and udev generated events over netlink */ |
124 | struct udev_monitor *udev_monitor_new_from_netlink(struct udev *udev, const char *name); |
125 | /* bind socket */ |
126 | int udev_monitor_enable_receiving(struct udev_monitor *udev_monitor); |
127 | int udev_monitor_set_receive_buffer_size(struct udev_monitor *udev_monitor, int size); |
128 | int udev_monitor_get_fd(struct udev_monitor *udev_monitor); |
129 | struct udev_device *udev_monitor_receive_device(struct udev_monitor *udev_monitor); |
130 | /* in-kernel socket filters to select messages that get delivered to a listener */ |
131 | int udev_monitor_filter_add_match_subsystem_devtype(struct udev_monitor *udev_monitor, |
132 | const char *subsystem, const char *devtype); |
133 | int udev_monitor_filter_add_match_tag(struct udev_monitor *udev_monitor, const char *tag); |
134 | int udev_monitor_filter_update(struct udev_monitor *udev_monitor); |
135 | int udev_monitor_filter_remove(struct udev_monitor *udev_monitor); |
136 | |
137 | /* |
138 | * udev_enumerate |
139 | * |
140 | * search sysfs for specific devices and provide a sorted list |
141 | */ |
142 | struct udev_enumerate; |
143 | struct udev_enumerate *udev_enumerate_ref(struct udev_enumerate *udev_enumerate); |
144 | struct udev_enumerate *udev_enumerate_unref(struct udev_enumerate *udev_enumerate); |
145 | struct udev *udev_enumerate_get_udev(struct udev_enumerate *udev_enumerate); |
146 | struct udev_enumerate *udev_enumerate_new(struct udev *udev); |
147 | /* device properties filter */ |
148 | int udev_enumerate_add_match_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem); |
149 | int udev_enumerate_add_nomatch_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem); |
150 | int udev_enumerate_add_match_sysattr(struct udev_enumerate *udev_enumerate, const char *sysattr, const char *value); |
151 | int udev_enumerate_add_nomatch_sysattr(struct udev_enumerate *udev_enumerate, const char *sysattr, const char *value); |
152 | int udev_enumerate_add_match_property(struct udev_enumerate *udev_enumerate, const char *property, const char *value); |
153 | int udev_enumerate_add_match_sysname(struct udev_enumerate *udev_enumerate, const char *sysname); |
154 | int udev_enumerate_add_match_tag(struct udev_enumerate *udev_enumerate, const char *tag); |
155 | int udev_enumerate_add_match_parent(struct udev_enumerate *udev_enumerate, struct udev_device *parent); |
156 | int udev_enumerate_add_match_is_initialized(struct udev_enumerate *udev_enumerate); |
157 | int udev_enumerate_add_syspath(struct udev_enumerate *udev_enumerate, const char *syspath); |
158 | /* run enumeration with active filters */ |
159 | int udev_enumerate_scan_devices(struct udev_enumerate *udev_enumerate); |
160 | int udev_enumerate_scan_subsystems(struct udev_enumerate *udev_enumerate); |
161 | /* return device list */ |
162 | struct udev_list_entry *udev_enumerate_get_list_entry(struct udev_enumerate *udev_enumerate); |
163 | |
164 | /* |
165 | * udev_queue |
166 | * |
167 | * access to the currently running udev events |
168 | */ |
169 | struct udev_queue; |
170 | struct udev_queue *udev_queue_ref(struct udev_queue *udev_queue); |
171 | struct udev_queue *udev_queue_unref(struct udev_queue *udev_queue); |
172 | struct udev *udev_queue_get_udev(struct udev_queue *udev_queue); |
173 | struct udev_queue *udev_queue_new(struct udev *udev); |
174 | unsigned long long int udev_queue_get_kernel_seqnum(struct udev_queue *udev_queue) __attribute__ ((deprecated)); |
175 | unsigned long long int udev_queue_get_udev_seqnum(struct udev_queue *udev_queue) __attribute__ ((deprecated)); |
176 | int udev_queue_get_udev_is_active(struct udev_queue *udev_queue); |
177 | int udev_queue_get_queue_is_empty(struct udev_queue *udev_queue); |
178 | int udev_queue_get_seqnum_is_finished(struct udev_queue *udev_queue, unsigned long long int seqnum) __attribute__ ((deprecated)); |
179 | int udev_queue_get_seqnum_sequence_is_finished(struct udev_queue *udev_queue, |
180 | unsigned long long int start, unsigned long long int end) __attribute__ ((deprecated)); |
181 | int udev_queue_get_fd(struct udev_queue *udev_queue); |
182 | int udev_queue_flush(struct udev_queue *udev_queue); |
183 | struct udev_list_entry *udev_queue_get_queued_list_entry(struct udev_queue *udev_queue) __attribute__ ((deprecated)); |
184 | |
185 | /* |
186 | * udev_hwdb |
187 | * |
188 | * access to the static hardware properties database |
189 | */ |
190 | struct udev_hwdb; |
191 | struct udev_hwdb *udev_hwdb_new(struct udev *udev); |
192 | struct udev_hwdb *udev_hwdb_ref(struct udev_hwdb *hwdb); |
193 | struct udev_hwdb *udev_hwdb_unref(struct udev_hwdb *hwdb); |
194 | struct udev_list_entry *udev_hwdb_get_properties_list_entry(struct udev_hwdb *hwdb, const char *modalias, unsigned int flags); |
195 | |
196 | /* |
197 | * udev_util |
198 | * |
199 | * udev specific utilities |
200 | */ |
201 | int udev_util_encode_string(const char *str, char *str_enc, size_t len); |
202 | |
203 | |
204 | #ifdef __cplusplus |
205 | } /* extern "C" */ |
206 | #endif |
207 | |
208 | #endif |
209 | |