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