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 #pragma once 21 22 #include <signal.h> 23 #include <stdint.h> 24 #include <stdbool.h> 25 26 #include "libudev.h" 27 #include "macro.h" 28 #include "util.h" 29 #include "mkdir.h" 30 #include "strxcpyx.h" 31 32 #define READ_END 0 33 #define WRITE_END 1 34 35 /* libudev.c */ 36 int udev_get_rules_path(struct udev *udev, char **path[], usec_t *ts_usec[]); 37 38 /* libudev-device.c */ 39 struct udev_device *udev_device_new_from_nulstr(struct udev *udev, char *nulstr, ssize_t buflen); 40 struct udev_device *udev_device_new_from_synthetic_event(struct udev *udev, const char *syspath, const char *action); 41 struct udev_device *udev_device_shallow_clone(struct udev_device *old_device); 42 struct udev_device *udev_device_clone_with_db(struct udev_device *old_device); 43 int udev_device_copy_properties(struct udev_device *dst, struct udev_device *src); 44 mode_t udev_device_get_devnode_mode(struct udev_device *udev_device); 45 uid_t udev_device_get_devnode_uid(struct udev_device *udev_device); 46 gid_t udev_device_get_devnode_gid(struct udev_device *udev_device); 47 int udev_device_rename(struct udev_device *udev_device, const char *new_name); 48 int udev_device_add_devlink(struct udev_device *udev_device, const char *devlink); 49 void udev_device_cleanup_devlinks_list(struct udev_device *udev_device); 50 int udev_device_add_property(struct udev_device *udev_device, const char *key, const char *value); 51 char **udev_device_get_properties_envp(struct udev_device *udev_device); 52 ssize_t udev_device_get_properties_monitor_buf(struct udev_device *udev_device, const char **buf); 53 const char *udev_device_get_devpath_old(struct udev_device *udev_device); 54 const char *udev_device_get_id_filename(struct udev_device *udev_device); 55 void udev_device_set_is_initialized(struct udev_device *udev_device); 56 int udev_device_add_tag(struct udev_device *udev_device, const char *tag); 57 void udev_device_remove_tag(struct udev_device *udev_device, const char *tag); 58 void udev_device_cleanup_tags_list(struct udev_device *udev_device); 59 usec_t udev_device_get_usec_initialized(struct udev_device *udev_device); 60 void udev_device_ensure_usec_initialized(struct udev_device *udev_device, struct udev_device *old_device); 61 int udev_device_get_devlink_priority(struct udev_device *udev_device); 62 int udev_device_set_devlink_priority(struct udev_device *udev_device, int prio); 63 int udev_device_get_watch_handle(struct udev_device *udev_device); 64 int udev_device_set_watch_handle(struct udev_device *udev_device, int handle); 65 int udev_device_get_ifindex(struct udev_device *udev_device); 66 void udev_device_set_info_loaded(struct udev_device *device); 67 bool udev_device_get_db_persist(struct udev_device *udev_device); 68 void udev_device_set_db_persist(struct udev_device *udev_device); 69 70 /* libudev-device-private.c */ 71 int udev_device_update_db(struct udev_device *udev_device); 72 int udev_device_delete_db(struct udev_device *udev_device); 73 int udev_device_tag_index(struct udev_device *dev, struct udev_device *dev_old, bool add); 74 75 /* libudev-monitor.c - netlink/unix socket communication */ 76 int udev_monitor_disconnect(struct udev_monitor *udev_monitor); 77 int udev_monitor_allow_unicast_sender(struct udev_monitor *udev_monitor, struct udev_monitor *sender); 78 int udev_monitor_send_device(struct udev_monitor *udev_monitor, 79 struct udev_monitor *destination, struct udev_device *udev_device); 80 struct udev_monitor *udev_monitor_new_from_netlink_fd(struct udev *udev, const char *name, int fd); 81 82 /* libudev-list.c */ 83 struct udev_list_node { 84 struct udev_list_node *next, *prev; 85 }; 86 struct udev_list { 87 struct udev *udev; 88 struct udev_list_node node; 89 struct udev_list_entry **entries; 90 unsigned int entries_cur; 91 unsigned int entries_max; 92 bool unique; 93 }; 94 #define UDEV_LIST(list) struct udev_list_node list = { &(list), &(list) } 95 void udev_list_node_init(struct udev_list_node *list); 96 int udev_list_node_is_empty(struct udev_list_node *list); 97 void udev_list_node_append(struct udev_list_node *new, struct udev_list_node *list); 98 void udev_list_node_remove(struct udev_list_node *entry); 99 #define udev_list_node_foreach(node, list) \ 100 for (node = (list)->next; \ 101 node != list; \ 102 node = (node)->next) 103 #define udev_list_node_foreach_safe(node, tmp, list) \ 104 for (node = (list)->next, tmp = (node)->next; \ 105 node != list; \ 106 node = tmp, tmp = (tmp)->next) 107 void udev_list_init(struct udev *udev, struct udev_list *list, bool unique); 108 void udev_list_cleanup(struct udev_list *list); 109 struct udev_list_entry *udev_list_get_entry(struct udev_list *list); 110 struct udev_list_entry *udev_list_entry_add(struct udev_list *list, const char *name, const char *value); 111 void udev_list_entry_delete(struct udev_list_entry *entry); 112 int udev_list_entry_get_num(struct udev_list_entry *list_entry); 113 void udev_list_entry_set_num(struct udev_list_entry *list_entry, int num); 114 #define udev_list_entry_foreach_safe(entry, tmp, first) \ 115 for (entry = first, tmp = udev_list_entry_get_next(entry); \ 116 entry != NULL; \ 117 entry = tmp, tmp = udev_list_entry_get_next(tmp)) 118 119 /* libudev-queue.c */ 120 unsigned long long int udev_get_kernel_seqnum(struct udev *udev); 121 int udev_queue_read_seqnum(FILE *queue_file, unsigned long long int *seqnum); 122 ssize_t udev_queue_read_devpath(FILE *queue_file, char *devpath, size_t size); 123 ssize_t udev_queue_skip_devpath(FILE *queue_file); 124 125 /* libudev-queue-private.c */ 126 struct udev_queue_export *udev_queue_export_new(struct udev *udev); 127 struct udev_queue_export *udev_queue_export_unref(struct udev_queue_export *udev_queue_export); 128 void udev_queue_export_cleanup(struct udev_queue_export *udev_queue_export); 129 int udev_queue_export_device_queued(struct udev_queue_export *udev_queue_export, struct udev_device *udev_device); 130 int udev_queue_export_device_finished(struct udev_queue_export *udev_queue_export, struct udev_device *udev_device); 131 132 /* libudev-hwdb.c */ 133 bool udev_hwdb_validate(struct udev_hwdb *hwdb); 134 135 /* libudev-util.c */ 136 #define UTIL_PATH_SIZE 1024 137 #define UTIL_NAME_SIZE 512 138 #define UTIL_LINE_SIZE 16384 139 #define UDEV_ALLOWED_CHARS_INPUT "/ $%?," 140 ssize_t util_get_sys_core_link_value(struct udev *udev, const char *slink, const char *syspath, char *value, size_t size); 141 int util_resolve_sys_link(struct udev *udev, char *syspath, size_t size); 142 int util_log_priority(const char *priority); 143 size_t util_path_encode(const char *src, char *dest, size_t size); 144 void util_remove_trailing_chars(char *path, char c); 145 int util_replace_whitespace(const char *str, char *to, size_t len); 146 int util_replace_chars(char *str, const char *white); 147 unsigned int util_string_hash32(const char *key); 148 uint64_t util_string_bloom64(const char *str); 149 150 /* libudev-util-private.c */ 151 int util_resolve_subsys_kernel(struct udev *udev, const char *string, char *result, size_t maxsize, int read_value); 152