]>
Commit | Line | Data |
---|---|---|
586fc304 LDM |
1 | #ifndef _LIBKMOD_PRIVATE_H_ |
2 | #define _LIBKMOD_PRIVATE_H_ | |
3 | ||
4 | #include <stdbool.h> | |
4462c4ac | 5 | #include <stdio.h> |
586fc304 | 6 | #include <syslog.h> |
d917f274 | 7 | #include <limits.h> |
586fc304 | 8 | |
88e9c12e | 9 | #include "macro.h" |
586fc304 LDM |
10 | #include "libkmod.h" |
11 | ||
f87081b4 | 12 | static __always_inline __printf_format(2, 3) void |
586fc304 LDM |
13 | kmod_log_null(struct kmod_ctx *ctx, const char *format, ...) {} |
14 | ||
15 | #define kmod_log_cond(ctx, prio, arg...) \ | |
16 | do { \ | |
17 | if (kmod_get_log_priority(ctx) >= prio) \ | |
18 | kmod_log(ctx, prio, __FILE__, __LINE__, __FUNCTION__, ## arg);\ | |
19 | } while (0) | |
20 | ||
21 | #ifdef ENABLE_LOGGING | |
22 | # ifdef ENABLE_DEBUG | |
ae6df84a | 23 | # define DBG(ctx, arg...) kmod_log_cond(ctx, LOG_DEBUG, ## arg) |
586fc304 | 24 | # else |
ae6df84a | 25 | # define DBG(ctx, arg...) kmod_log_null(ctx, ## arg) |
586fc304 | 26 | # endif |
ae6df84a LDM |
27 | # define INFO(ctx, arg...) kmod_log_cond(ctx, LOG_INFO, ## arg) |
28 | # define ERR(ctx, arg...) kmod_log_cond(ctx, LOG_ERR, ## arg) | |
586fc304 | 29 | #else |
ae6df84a LDM |
30 | # define DBG(ctx, arg...) kmod_log_null(ctx, ## arg) |
31 | # define INFO(ctx, arg...) kmod_log_null(ctx, ## arg) | |
32 | # define ERR(ctx, arg...) kmod_log_null(ctx, ## arg) | |
586fc304 LDM |
33 | #endif |
34 | ||
35 | #define KMOD_EXPORT __attribute__ ((visibility("default"))) | |
36 | ||
1684e440 LDM |
37 | #define KCMD_LINE_SIZE 4096 |
38 | ||
1bdd951e | 39 | void kmod_log(const struct kmod_ctx *ctx, |
586fc304 | 40 | int priority, const char *file, int line, const char *fn, |
12d9419d | 41 | const char *format, ...) __attribute__((format(printf, 6, 7))) __attribute__((nonnull(1, 3, 5))); |
586fc304 | 42 | |
6924e47a LDM |
43 | struct list_node { |
44 | struct list_node *next, *prev; | |
45 | }; | |
46 | ||
47 | struct kmod_list { | |
48 | struct list_node node; | |
49 | void *data; | |
50 | }; | |
51 | ||
12d9419d GSB |
52 | struct kmod_list *kmod_list_append(struct kmod_list *list, const void *data) __must_check __attribute__((nonnull(2))); |
53 | struct kmod_list *kmod_list_prepend(struct kmod_list *list, const void *data) __must_check __attribute__((nonnull(2))); | |
54 | struct kmod_list *kmod_list_remove(struct kmod_list *list) __must_check; | |
6924e47a | 55 | struct kmod_list *kmod_list_remove_data(struct kmod_list *list, |
12d9419d | 56 | const void *data) __must_check __attribute__((nonnull(2))); |
62be7995 LDM |
57 | struct kmod_list *kmod_list_remove_n_latest(struct kmod_list *list, |
58 | unsigned int n) __must_check; | |
86e87885 | 59 | struct kmod_list *kmod_list_insert_after(struct kmod_list *list, const void *data) __attribute__((nonnull(2))); |
b91a1c6d | 60 | struct kmod_list *kmod_list_insert_before(struct kmod_list *list, const void *data) __attribute__((nonnull(2))); |
1965029c | 61 | struct kmod_list *kmod_list_append_list(struct kmod_list *list1, struct kmod_list *list2) __must_check; |
86e87885 | 62 | |
cf91579b LDM |
63 | #undef kmod_list_foreach |
64 | #define kmod_list_foreach(list_entry, first_entry) \ | |
d2d648df | 65 | for (list_entry = ((first_entry) == NULL) ? NULL : (first_entry); \ |
cf91579b | 66 | list_entry != NULL; \ |
d2d648df | 67 | list_entry = (list_entry->node.next == &((first_entry)->node)) ? NULL : \ |
cf91579b | 68 | container_of(list_entry->node.next, struct kmod_list, node)) |
60aa4d8b | 69 | |
d6b55b7d GSB |
70 | #undef kmod_list_foreach_reverse |
71 | #define kmod_list_foreach_reverse(list_entry, first_entry) \ | |
72 | for (list_entry = (((first_entry) == NULL) ? NULL : container_of(first_entry->node.prev, struct kmod_list, node)); \ | |
73 | list_entry != NULL; \ | |
74 | list_entry = ((list_entry == first_entry) ? NULL : \ | |
75 | container_of(list_entry->node.prev, struct kmod_list, node))) | |
76 | ||
60aa4d8b | 77 | /* libkmod.c */ |
1ce08a56 | 78 | const char *kmod_get_dirname(const struct kmod_ctx *ctx) __attribute__((nonnull(1))); |
fd186ae9 | 79 | |
12d9419d GSB |
80 | int kmod_lookup_alias_from_config(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3))); |
81 | int kmod_lookup_alias_from_symbols_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3))); | |
82 | int kmod_lookup_alias_from_aliases_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3))); | |
83 | int kmod_lookup_alias_from_moddep_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3))); | |
f4fc5523 | 84 | int kmod_lookup_alias_from_commands(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3))); |
fd186ae9 | 85 | |
671d4894 | 86 | char *kmod_search_moddep(struct kmod_ctx *ctx, const char *name) __attribute__((nonnull(1,2))); |
221631d5 | 87 | |
8bdeca11 LDM |
88 | struct kmod_module *kmod_pool_get_module(struct kmod_ctx *ctx, const char *key) __attribute__((nonnull(1,2))); |
89 | void kmod_pool_add_module(struct kmod_ctx *ctx, struct kmod_module *mod, const char *key) __attribute__((nonnull(1,2, 3))); | |
90 | void kmod_pool_del_module(struct kmod_ctx *ctx, struct kmod_module *mod, const char *key) __attribute__((nonnull(1,2, 3))); | |
fd186ae9 | 91 | |
bd3f5535 GSB |
92 | const struct kmod_list *kmod_get_options(const struct kmod_ctx *ctx) __must_check __attribute__((nonnull(1))); |
93 | const struct kmod_list *kmod_get_install_commands(const struct kmod_ctx *ctx) __must_check __attribute__((nonnull(1))); | |
94 | const struct kmod_list *kmod_get_remove_commands(const struct kmod_ctx *ctx) __must_check __attribute__((nonnull(1))); | |
1c522600 | 95 | const struct kmod_list *kmod_get_softdeps(const struct kmod_ctx *ctx) __must_check __attribute__((nonnull(1))); |
bd3f5535 | 96 | |
fd186ae9 | 97 | |
60aa4d8b | 98 | /* libkmod-config.c */ |
7c2ab358 | 99 | struct kmod_config { |
d13e606f | 100 | struct kmod_ctx *ctx; |
7c2ab358 | 101 | struct kmod_list *aliases; |
81cf2060 | 102 | struct kmod_list *blacklists; |
615c42be | 103 | struct kmod_list *options; |
a5cce6d6 LDM |
104 | struct kmod_list *remove_commands; |
105 | struct kmod_list *install_commands; | |
1c522600 | 106 | struct kmod_list *softdeps; |
7c2ab358 | 107 | }; |
cb8d4d3e | 108 | int kmod_config_new(struct kmod_ctx *ctx, struct kmod_config **config, const char * const *config_paths) __attribute__((nonnull(1, 2,3))); |
d13e606f | 109 | void kmod_config_free(struct kmod_config *config) __attribute__((nonnull(1))); |
12d9419d GSB |
110 | const char *kmod_alias_get_name(const struct kmod_list *l) __attribute__((nonnull(1))); |
111 | const char *kmod_alias_get_modname(const struct kmod_list *l) __attribute__((nonnull(1))); | |
bd3f5535 GSB |
112 | const char *kmod_option_get_options(const struct kmod_list *l) __attribute__((nonnull(1))); |
113 | const char *kmod_option_get_modname(const struct kmod_list *l) __attribute__((nonnull(1))); | |
114 | const char *kmod_command_get_command(const struct kmod_list *l) __attribute__((nonnull(1))); | |
115 | const char *kmod_command_get_modname(const struct kmod_list *l) __attribute__((nonnull(1))); | |
116 | ||
1c522600 GSB |
117 | const char *kmod_softdep_get_name(const struct kmod_list *l) __attribute__((nonnull(1))); |
118 | const char * const *kmod_softdep_get_pre(const struct kmod_list *l, unsigned int *count) __attribute__((nonnull(1, 2))); | |
119 | const char * const *kmod_softdep_get_post(const struct kmod_list *l, unsigned int *count); | |
120 | ||
7c2ab358 | 121 | |
7636e72b | 122 | /* libkmod-module.c */ |
6ad5f263 | 123 | int kmod_module_new_from_alias(struct kmod_ctx *ctx, const char *alias, const char *name, struct kmod_module **mod); |
d917f274 | 124 | char *modname_normalize(const char *modname, char buf[NAME_MAX], size_t *len) __attribute__((nonnull(1, 2))); |
671d4894 | 125 | int kmod_module_parse_depline(struct kmod_module *mod, char *line) __attribute__((nonnull(1, 2))); |
f4fc5523 LDM |
126 | void kmod_module_set_install_commands(struct kmod_module *mod, const char *cmd) __attribute__((nonnull(1))); |
127 | void kmod_module_set_remove_commands(struct kmod_module *mod, const char *cmd) __attribute__((nonnull(1))); | |
7636e72b | 128 | |
7db08652 GSB |
129 | /* libkmod-hash.c */ |
130 | struct kmod_hash; | |
131 | struct kmod_hash *kmod_hash_new(unsigned int n_buckets, void (*free_value)(void *value)); | |
132 | void kmod_hash_free(struct kmod_hash *hash); | |
133 | int kmod_hash_add(struct kmod_hash *hash, const char *key, const void *value); | |
134 | int kmod_hash_del(struct kmod_hash *hash, const char *key); | |
135 | void *kmod_hash_find(const struct kmod_hash *hash, const char *key); | |
136 | ||
3d8226ed GSB |
137 | /* libkmod-file.c */ |
138 | struct kmod_file *kmod_file_open(const char *filename) __must_check __attribute__((nonnull(1))); | |
139 | void *kmod_file_get_contents(const struct kmod_file *file) __must_check __attribute__((nonnull(1))); | |
140 | off_t kmod_file_get_size(const struct kmod_file *file) __must_check __attribute__((nonnull(1))); | |
141 | void kmod_file_unref(struct kmod_file *file) __attribute__((nonnull(1))); | |
142 | ||
708624a4 GSB |
143 | /* libkmod-elf.c */ |
144 | struct kmod_elf; | |
145 | struct kmod_modversion { | |
146 | uint64_t crc; | |
147 | char *symbol; | |
148 | }; | |
149 | ||
150 | struct kmod_elf *kmod_elf_new(const void *memory, off_t size) __must_check __attribute__((nonnull(1))); | |
151 | void kmod_elf_unref(struct kmod_elf *elf) __attribute__((nonnull(1))); | |
152 | const void *kmod_elf_get_memory(const struct kmod_elf *elf) __must_check __attribute__((nonnull(1))); | |
153 | int kmod_elf_get_strings(const struct kmod_elf *elf, const char *section, char ***array) __must_check __attribute__((nonnull(1,2,3))); | |
154 | int kmod_elf_get_modversions(const struct kmod_elf *elf, struct kmod_modversion **array) __must_check __attribute__((nonnull(1,2))); | |
155 | int kmod_elf_strip_section(struct kmod_elf *elf, const char *section) __must_check __attribute__((nonnull(1,2))); | |
156 | int kmod_elf_strip_vermagic(struct kmod_elf *elf) __must_check __attribute__((nonnull(1))); | |
7db08652 | 157 | |
60aa4d8b | 158 | /* util functions */ |
ad5555b2 | 159 | char *getline_wrapped(FILE *fp, unsigned int *linenum) __attribute__((nonnull(1))); |
12d9419d | 160 | char *underscores(struct kmod_ctx *ctx, char *s) __attribute__((nonnull(1, 2))); |
44a5460f | 161 | #define streq(a, b) (strcmp((a), (b)) == 0) |
12d9419d | 162 | bool startswith(const char *s, const char *prefix) __attribute__((nonnull(1, 2))); |
32c328d2 | 163 | void *memdup(const void *p, size_t n) __attribute__((nonnull(1))); |
4462c4ac | 164 | |
f12ae3c4 GSB |
165 | ssize_t read_str_safe(int fd, char *buf, size_t buflen) __must_check __attribute__((nonnull(2))); |
166 | int read_str_long(int fd, long *value, int base) __must_check __attribute__((nonnull(2))); | |
167 | int read_str_ulong(int fd, unsigned long *value, int base) __must_check __attribute__((nonnull(2))); | |
afca7801 | 168 | char *strchr_replace(char *s, int c, char r); |
3a468809 | 169 | bool path_is_absolute(const char *p) __must_check __attribute__((nonnull(1))); |
06363cc1 | 170 | char *path_make_absolute_cwd(const char *p) __must_check __attribute__((nonnull(1))); |
b148b860 | 171 | int alias_normalize(const char *alias, char buf[NAME_MAX], size_t *len) __must_check __attribute__((nonnull(1,2))); |
f12ae3c4 GSB |
172 | |
173 | ||
586fc304 | 174 | #endif |