chiark / gitweb /
journal-gatewayd: redirect microhttpd messages to journal
[elogind.git] / src / libudev / libudev-private.h
1 /***
2   This file is part of systemd.
3
4   Copyright 2008-2012 Kay Sievers <kay@vrfy.org>
5
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.
10
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.
15
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/>.
18 ***/
19
20 #ifndef _LIBUDEV_PRIVATE_H_
21 #define _LIBUDEV_PRIVATE_H_
22
23 #include <syslog.h>
24 #include <signal.h>
25 #include <stdint.h>
26 #include <stdbool.h>
27
28 #include "libudev.h"
29 #include "macro.h"
30 #include "util.h"
31 #include "mkdir.h"
32 #include "strxcpyx.h"
33
34 #define READ_END  0
35 #define WRITE_END 1
36
37 /* avoid (sometimes expensive) calculations of parameters for debug output */
38 #define udev_log_cond(udev, prio, arg...) \
39   do { \
40     if (udev_get_log_priority(udev) >= prio) \
41       udev_log(udev, prio, __FILE__, __LINE__, __FUNCTION__, ## arg); \
42   } while (0)
43
44 #define udev_dbg(udev, arg...) udev_log_cond(udev, LOG_DEBUG, ## arg)
45 #define udev_info(udev, arg...) udev_log_cond(udev, LOG_INFO, ## arg)
46 #define udev_err(udev, arg...) udev_log_cond(udev, LOG_ERR, ## arg)
47
48 /* libudev.c */
49 void udev_log(struct udev *udev,
50               int priority, const char *file, int line, const char *fn,
51               const char *format, ...)
52               __attribute__((format(printf, 6, 7)));
53 int udev_get_rules_path(struct udev *udev, char **path[], usec_t *ts_usec[]);
54 struct udev_list_entry *udev_add_property(struct udev *udev, const char *key, const char *value);
55 struct udev_list_entry *udev_get_properties_list_entry(struct udev *udev);
56
57 /* libudev-device.c */
58 struct udev_device *udev_device_new(struct udev *udev);
59 mode_t udev_device_get_devnode_mode(struct udev_device *udev_device);
60 uid_t udev_device_get_devnode_uid(struct udev_device *udev_device);
61 gid_t udev_device_get_devnode_gid(struct udev_device *udev_device);
62 int udev_device_set_subsystem(struct udev_device *udev_device, const char *subsystem);
63 int udev_device_set_syspath(struct udev_device *udev_device, const char *syspath);
64 int udev_device_set_devnode(struct udev_device *udev_device, const char *devnode);
65 int udev_device_add_devlink(struct udev_device *udev_device, const char *devlink);
66 void udev_device_cleanup_devlinks_list(struct udev_device *udev_device);
67 struct udev_list_entry *udev_device_add_property(struct udev_device *udev_device, const char *key, const char *value);
68 void udev_device_add_property_from_string_parse(struct udev_device *udev_device, const char *property);
69 int udev_device_add_property_from_string_parse_finish(struct udev_device *udev_device);
70 char **udev_device_get_properties_envp(struct udev_device *udev_device);
71 ssize_t udev_device_get_properties_monitor_buf(struct udev_device *udev_device, const char **buf);
72 int udev_device_read_db(struct udev_device *udev_device, const char *dbfile);
73 int udev_device_read_uevent_file(struct udev_device *udev_device);
74 int udev_device_set_action(struct udev_device *udev_device, const char *action);
75 const char *udev_device_get_devpath_old(struct udev_device *udev_device);
76 const char *udev_device_get_id_filename(struct udev_device *udev_device);
77 void udev_device_set_is_initialized(struct udev_device *udev_device);
78 int udev_device_add_tag(struct udev_device *udev_device, const char *tag);
79 void udev_device_cleanup_tags_list(struct udev_device *udev_device);
80 usec_t udev_device_get_usec_initialized(struct udev_device *udev_device);
81 void udev_device_set_usec_initialized(struct udev_device *udev_device, usec_t usec_initialized);
82 int udev_device_get_devlink_priority(struct udev_device *udev_device);
83 int udev_device_set_devlink_priority(struct udev_device *udev_device, int prio);
84 int udev_device_get_watch_handle(struct udev_device *udev_device);
85 int udev_device_set_watch_handle(struct udev_device *udev_device, int handle);
86 int udev_device_get_ifindex(struct udev_device *udev_device);
87 void udev_device_set_info_loaded(struct udev_device *device);
88 bool udev_device_get_db_persist(struct udev_device *udev_device);
89 void udev_device_set_db_persist(struct udev_device *udev_device);
90
91 /* libudev-device-private.c */
92 int udev_device_update_db(struct udev_device *udev_device);
93 int udev_device_delete_db(struct udev_device *udev_device);
94 int udev_device_tag_index(struct udev_device *dev, struct udev_device *dev_old, bool add);
95
96 /* libudev-monitor.c - netlink/unix socket communication  */
97 int udev_monitor_disconnect(struct udev_monitor *udev_monitor);
98 int udev_monitor_allow_unicast_sender(struct udev_monitor *udev_monitor, struct udev_monitor *sender);
99 int udev_monitor_send_device(struct udev_monitor *udev_monitor,
100                              struct udev_monitor *destination, struct udev_device *udev_device);
101 struct udev_monitor *udev_monitor_new_from_netlink_fd(struct udev *udev, const char *name, int fd);
102
103 /* libudev-list.c */
104 struct udev_list_node {
105         struct udev_list_node *next, *prev;
106 };
107 struct udev_list {
108         struct udev *udev;
109         struct udev_list_node node;
110         struct udev_list_entry **entries;
111         unsigned int entries_cur;
112         unsigned int entries_max;
113         bool unique;
114 };
115 #define UDEV_LIST(list) struct udev_list_node list = { &(list), &(list) }
116 void udev_list_node_init(struct udev_list_node *list);
117 int udev_list_node_is_empty(struct udev_list_node *list);
118 void udev_list_node_append(struct udev_list_node *new, struct udev_list_node *list);
119 void udev_list_node_remove(struct udev_list_node *entry);
120 #define udev_list_node_foreach(node, list) \
121         for (node = (list)->next; \
122              node != list; \
123              node = (node)->next)
124 #define udev_list_node_foreach_safe(node, tmp, list) \
125         for (node = (list)->next, tmp = (node)->next; \
126              node != list; \
127              node = tmp, tmp = (tmp)->next)
128 void udev_list_init(struct udev *udev, struct udev_list *list, bool unique);
129 void udev_list_cleanup(struct udev_list *list);
130 struct udev_list_entry *udev_list_get_entry(struct udev_list *list);
131 struct udev_list_entry *udev_list_entry_add(struct udev_list *list, const char *name, const char *value);
132 void udev_list_entry_delete(struct udev_list_entry *entry);
133 void udev_list_entry_insert_before(struct udev_list_entry *new, struct udev_list_entry *entry);
134 void udev_list_entry_append(struct udev_list_entry *new, struct udev_list *list);
135 int udev_list_entry_get_num(struct udev_list_entry *list_entry);
136 void udev_list_entry_set_num(struct udev_list_entry *list_entry, int num);
137 #define udev_list_entry_foreach_safe(entry, tmp, first) \
138         for (entry = first, tmp = udev_list_entry_get_next(entry); \
139              entry != NULL; \
140              entry = tmp, tmp = udev_list_entry_get_next(tmp))
141
142 /* libudev-queue.c */
143 unsigned long long int udev_get_kernel_seqnum(struct udev *udev);
144 int udev_queue_read_seqnum(FILE *queue_file, unsigned long long int *seqnum);
145 ssize_t udev_queue_read_devpath(FILE *queue_file, char *devpath, size_t size);
146 ssize_t udev_queue_skip_devpath(FILE *queue_file);
147
148 /* libudev-queue-private.c */
149 struct udev_queue_export *udev_queue_export_new(struct udev *udev);
150 struct udev_queue_export *udev_queue_export_unref(struct udev_queue_export *udev_queue_export);
151 void udev_queue_export_cleanup(struct udev_queue_export *udev_queue_export);
152 int udev_queue_export_device_queued(struct udev_queue_export *udev_queue_export, struct udev_device *udev_device);
153 int udev_queue_export_device_finished(struct udev_queue_export *udev_queue_export, struct udev_device *udev_device);
154
155 /* libudev-hwdb.c */
156 bool udev_hwdb_validate(struct udev_hwdb *hwdb);
157
158 /* libudev-util.c */
159 #define UTIL_PATH_SIZE                      1024
160 #define UTIL_NAME_SIZE                       512
161 #define UTIL_LINE_SIZE                     16384
162 #define UDEV_ALLOWED_CHARS_INPUT        "/ $%?,"
163 ssize_t util_get_sys_core_link_value(struct udev *udev, const char *slink, const char *syspath, char *value, size_t size);
164 int util_resolve_sys_link(struct udev *udev, char *syspath, size_t size);
165 int util_log_priority(const char *priority);
166 size_t util_path_encode(const char *src, char *dest, size_t size);
167 void util_remove_trailing_chars(char *path, char c);
168 int util_replace_whitespace(const char *str, char *to, size_t len);
169 int util_replace_chars(char *str, const char *white);
170 unsigned int util_string_hash32(const char *key);
171 uint64_t util_string_bloom64(const char *str);
172
173 /* libudev-util-private.c */
174 int util_delete_path(struct udev *udev, const char *path);
175 uid_t util_lookup_user(struct udev *udev, const char *user);
176 gid_t util_lookup_group(struct udev *udev, const char *group);
177 int util_resolve_subsys_kernel(struct udev *udev, const char *string, char *result, size_t maxsize, int read_value);
178 ssize_t print_kmsg(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
179 #endif