]> git.ipfire.org Git - thirdparty/kmod.git/blame - libkmod/libkmod-internal.h
libkmod: keep KMOD_FILE_COMPRESSION_NONE/load_reg in comp_types
[thirdparty/kmod.git] / libkmod / libkmod-internal.h
CommitLineData
e8fd8fec 1#pragma once
586fc304
LDM
2
3#include <stdbool.h>
4462c4ac 4#include <stdio.h>
586fc304 5#include <syslog.h>
d917f274 6#include <limits.h>
586fc304 7
576dd439 8#include <shared/macro.h>
8b7189bc 9#include <shared/missing.h>
576dd439 10
586fc304
LDM
11#include "libkmod.h"
12
a70c1e77 13static _always_inline_ _printf_format_(2, 3) void
95ed3e75 14 kmod_log_null(const struct kmod_ctx *ctx, const char *format, ...) {}
586fc304
LDM
15
16#define kmod_log_cond(ctx, prio, arg...) \
17 do { \
18 if (kmod_get_log_priority(ctx) >= prio) \
87beacc9 19 kmod_log(ctx, prio, __FILE__, __LINE__, __func__, ## arg);\
586fc304
LDM
20 } while (0)
21
22#ifdef ENABLE_LOGGING
23# ifdef ENABLE_DEBUG
ae6df84a 24# define DBG(ctx, arg...) kmod_log_cond(ctx, LOG_DEBUG, ## arg)
586fc304 25# else
ae6df84a 26# define DBG(ctx, arg...) kmod_log_null(ctx, ## arg)
586fc304 27# endif
43bdf97c 28# define NOTICE(ctx, arg...) kmod_log_cond(ctx, LOG_NOTICE, ## arg)
ae6df84a
LDM
29# define INFO(ctx, arg...) kmod_log_cond(ctx, LOG_INFO, ## arg)
30# define ERR(ctx, arg...) kmod_log_cond(ctx, LOG_ERR, ## arg)
586fc304 31#else
ae6df84a 32# define DBG(ctx, arg...) kmod_log_null(ctx, ## arg)
43bdf97c 33# define NOTICE(ctx, arg...) kmod_log_null(ctx, ## arg)
ae6df84a
LDM
34# define INFO(ctx, arg...) kmod_log_null(ctx, ## arg)
35# define ERR(ctx, arg...) kmod_log_null(ctx, ## arg)
586fc304
LDM
36#endif
37
38#define KMOD_EXPORT __attribute__ ((visibility("default")))
39
1684e440
LDM
40#define KCMD_LINE_SIZE 4096
41
41a51c2a
CR
42#ifndef HAVE_SECURE_GETENV
43# ifdef HAVE___SECURE_GETENV
44# define secure_getenv __secure_getenv
45# else
46# warning neither secure_getenv nor __secure_getenv is available
47# define secure_getenv getenv
48# endif
49#endif
50
1bdd951e 51void kmod_log(const struct kmod_ctx *ctx,
586fc304 52 int priority, const char *file, int line, const char *fn,
12d9419d 53 const char *format, ...) __attribute__((format(printf, 6, 7))) __attribute__((nonnull(1, 3, 5)));
586fc304 54
6924e47a
LDM
55struct list_node {
56 struct list_node *next, *prev;
57};
58
59struct kmod_list {
60 struct list_node node;
61 void *data;
62};
63
e5398276
LDM
64enum kmod_file_compression_type {
65 KMOD_FILE_COMPRESSION_NONE = 0,
66 KMOD_FILE_COMPRESSION_ZSTD,
67 KMOD_FILE_COMPRESSION_XZ,
68 KMOD_FILE_COMPRESSION_ZLIB,
69};
70
a70c1e77
LDM
71struct kmod_list *kmod_list_append(struct kmod_list *list, const void *data) _must_check_ __attribute__((nonnull(2)));
72struct kmod_list *kmod_list_prepend(struct kmod_list *list, const void *data) _must_check_ __attribute__((nonnull(2)));
73struct kmod_list *kmod_list_remove(struct kmod_list *list) _must_check_;
6924e47a 74struct kmod_list *kmod_list_remove_data(struct kmod_list *list,
a70c1e77 75 const void *data) _must_check_ __attribute__((nonnull(2)));
62be7995 76struct kmod_list *kmod_list_remove_n_latest(struct kmod_list *list,
a70c1e77 77 unsigned int n) _must_check_;
86e87885 78struct kmod_list *kmod_list_insert_after(struct kmod_list *list, const void *data) __attribute__((nonnull(2)));
b91a1c6d 79struct kmod_list *kmod_list_insert_before(struct kmod_list *list, const void *data) __attribute__((nonnull(2)));
a70c1e77 80struct kmod_list *kmod_list_append_list(struct kmod_list *list1, struct kmod_list *list2) _must_check_;
86e87885 81
cf91579b
LDM
82#undef kmod_list_foreach
83#define kmod_list_foreach(list_entry, first_entry) \
d2d648df 84 for (list_entry = ((first_entry) == NULL) ? NULL : (first_entry); \
cf91579b 85 list_entry != NULL; \
d2d648df 86 list_entry = (list_entry->node.next == &((first_entry)->node)) ? NULL : \
cf91579b 87 container_of(list_entry->node.next, struct kmod_list, node))
60aa4d8b 88
d6b55b7d
GSB
89#undef kmod_list_foreach_reverse
90#define kmod_list_foreach_reverse(list_entry, first_entry) \
91 for (list_entry = (((first_entry) == NULL) ? NULL : container_of(first_entry->node.prev, struct kmod_list, node)); \
92 list_entry != NULL; \
93 list_entry = ((list_entry == first_entry) ? NULL : \
94 container_of(list_entry->node.prev, struct kmod_list, node)))
95
60aa4d8b 96/* libkmod.c */
12d9419d
GSB
97int kmod_lookup_alias_from_config(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3)));
98int kmod_lookup_alias_from_symbols_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3)));
99int kmod_lookup_alias_from_aliases_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3)));
100int kmod_lookup_alias_from_moddep_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3)));
b866b216 101int kmod_lookup_alias_from_kernel_builtin_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3)));
3805274b 102int kmod_lookup_alias_from_builtin_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3)));
fd44a98a 103bool kmod_lookup_alias_is_builtin(struct kmod_ctx *ctx, const char *name) __attribute__((nonnull(1, 2)));
f4fc5523 104int kmod_lookup_alias_from_commands(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3)));
ece09aac 105void kmod_set_modules_visited(struct kmod_ctx *ctx, bool visited) __attribute__((nonnull((1))));
450bd1b4 106void kmod_set_modules_required(struct kmod_ctx *ctx, bool required) __attribute__((nonnull((1))));
fd186ae9 107
671d4894 108char *kmod_search_moddep(struct kmod_ctx *ctx, const char *name) __attribute__((nonnull(1,2)));
221631d5 109
8bdeca11 110struct kmod_module *kmod_pool_get_module(struct kmod_ctx *ctx, const char *key) __attribute__((nonnull(1,2)));
1114e781
LDM
111void kmod_pool_add_module(struct kmod_ctx *ctx, struct kmod_module *mod, const char *key) __attribute__((nonnull(1, 2, 3)));
112void kmod_pool_del_module(struct kmod_ctx *ctx, struct kmod_module *mod, const char *key) __attribute__((nonnull(1, 2, 3)));
fd186ae9 113
e7fc2c86 114const struct kmod_config *kmod_get_config(const struct kmod_ctx *ctx) __attribute__((nonnull(1)));
09c9f8c5 115enum kmod_file_compression_type kmod_get_kernel_compression(const struct kmod_ctx *ctx) __attribute__((nonnull(1)));
fd186ae9 116
60aa4d8b 117/* libkmod-config.c */
b6a4dfb1
LDM
118struct kmod_config_path {
119 unsigned long long stamp;
120 char path[];
121};
122
7c2ab358 123struct kmod_config {
d13e606f 124 struct kmod_ctx *ctx;
7c2ab358 125 struct kmod_list *aliases;
81cf2060 126 struct kmod_list *blacklists;
615c42be 127 struct kmod_list *options;
a5cce6d6
LDM
128 struct kmod_list *remove_commands;
129 struct kmod_list *install_commands;
1c522600 130 struct kmod_list *softdeps;
b6a4dfb1
LDM
131
132 struct kmod_list *paths;
7c2ab358 133};
b6a4dfb1 134
cb8d4d3e 135int kmod_config_new(struct kmod_ctx *ctx, struct kmod_config **config, const char * const *config_paths) __attribute__((nonnull(1, 2,3)));
d13e606f 136void kmod_config_free(struct kmod_config *config) __attribute__((nonnull(1)));
c1c9c446 137const char *kmod_blacklist_get_modname(const struct kmod_list *l) __attribute__((nonnull(1)));
12d9419d
GSB
138const char *kmod_alias_get_name(const struct kmod_list *l) __attribute__((nonnull(1)));
139const char *kmod_alias_get_modname(const struct kmod_list *l) __attribute__((nonnull(1)));
bd3f5535
GSB
140const char *kmod_option_get_options(const struct kmod_list *l) __attribute__((nonnull(1)));
141const char *kmod_option_get_modname(const struct kmod_list *l) __attribute__((nonnull(1)));
142const char *kmod_command_get_command(const struct kmod_list *l) __attribute__((nonnull(1)));
143const char *kmod_command_get_modname(const struct kmod_list *l) __attribute__((nonnull(1)));
144
1c522600
GSB
145const char *kmod_softdep_get_name(const struct kmod_list *l) __attribute__((nonnull(1)));
146const char * const *kmod_softdep_get_pre(const struct kmod_list *l, unsigned int *count) __attribute__((nonnull(1, 2)));
147const char * const *kmod_softdep_get_post(const struct kmod_list *l, unsigned int *count);
148
7c2ab358 149
7636e72b 150/* libkmod-module.c */
6ad5f263 151int kmod_module_new_from_alias(struct kmod_ctx *ctx, const char *alias, const char *name, struct kmod_module **mod);
671d4894 152int kmod_module_parse_depline(struct kmod_module *mod, char *line) __attribute__((nonnull(1, 2)));
f4fc5523
LDM
153void kmod_module_set_install_commands(struct kmod_module *mod, const char *cmd) __attribute__((nonnull(1)));
154void kmod_module_set_remove_commands(struct kmod_module *mod, const char *cmd) __attribute__((nonnull(1)));
ece09aac 155void kmod_module_set_visited(struct kmod_module *mod, bool visited) __attribute__((nonnull(1)));
3805274b 156void kmod_module_set_builtin(struct kmod_module *mod, bool builtin) __attribute__((nonnull((1))));
450bd1b4 157void kmod_module_set_required(struct kmod_module *mod, bool required) __attribute__((nonnull(1)));
fd44a98a 158bool kmod_module_is_builtin(struct kmod_module *mod) __attribute__((nonnull(1)));
7db08652 159
3d8226ed 160/* libkmod-file.c */
a70c1e77 161struct kmod_file *kmod_file_open(const struct kmod_ctx *ctx, const char *filename) _must_check_ __attribute__((nonnull(1,2)));
1eff942e 162struct kmod_elf *kmod_file_get_elf(struct kmod_file *file) __attribute__((nonnull(1)));
81e5c797 163int kmod_file_load_contents(struct kmod_file *file) __attribute__((nonnull(1)));
a70c1e77
LDM
164void *kmod_file_get_contents(const struct kmod_file *file) _must_check_ __attribute__((nonnull(1)));
165off_t kmod_file_get_size(const struct kmod_file *file) _must_check_ __attribute__((nonnull(1)));
09c9f8c5 166enum kmod_file_compression_type kmod_file_get_compression(const struct kmod_file *file) _must_check_ __attribute__((nonnull(1)));
144d1826 167int kmod_file_get_fd(const struct kmod_file *file) _must_check_ __attribute__((nonnull(1)));
3d8226ed
GSB
168void kmod_file_unref(struct kmod_file *file) __attribute__((nonnull(1)));
169
708624a4
GSB
170/* libkmod-elf.c */
171struct kmod_elf;
172struct kmod_modversion {
173 uint64_t crc;
674f8590 174 enum kmod_symbol_bind bind;
708624a4
GSB
175 char *symbol;
176};
177
7a86f129 178struct kmod_elf *kmod_elf_new(const void *memory, off_t size) _must_check_;
708624a4 179void kmod_elf_unref(struct kmod_elf *elf) __attribute__((nonnull(1)));
a70c1e77
LDM
180const void *kmod_elf_get_memory(const struct kmod_elf *elf) _must_check_ __attribute__((nonnull(1)));
181int kmod_elf_get_strings(const struct kmod_elf *elf, const char *section, char ***array) _must_check_ __attribute__((nonnull(1,2,3)));
182int kmod_elf_get_modversions(const struct kmod_elf *elf, struct kmod_modversion **array) _must_check_ __attribute__((nonnull(1,2)));
183int kmod_elf_get_symbols(const struct kmod_elf *elf, struct kmod_modversion **array) _must_check_ __attribute__((nonnull(1,2)));
184int kmod_elf_get_dependency_symbols(const struct kmod_elf *elf, struct kmod_modversion **array) _must_check_ __attribute__((nonnull(1,2)));
185int kmod_elf_strip_section(struct kmod_elf *elf, const char *section) _must_check_ __attribute__((nonnull(1,2)));
186int kmod_elf_strip_vermagic(struct kmod_elf *elf) _must_check_ __attribute__((nonnull(1)));
7db08652 187
ea17e2b0
LDM
188/*
189 * Debug mock lib need to find section ".gnu.linkonce.this_module" in order to
190 * get modname
191 */
a70c1e77 192int kmod_elf_get_section(const struct kmod_elf *elf, const char *section, const void **buf, uint64_t *buf_size) _must_check_ __attribute__((nonnull(1,2,3,4)));
ea17e2b0 193
8fe1681c
MM
194/* libkmod-signature.c */
195struct kmod_signature_info {
196 const char *signer;
197 size_t signer_len;
198 const char *key_id;
199 size_t key_id_len;
200 const char *algo, *hash_algo, *id_type;
e5b6a658
YK
201 const char *sig;
202 size_t sig_len;
391b4714
YK
203 void (*free)(void *);
204 void *private;
8fe1681c
MM
205};
206bool kmod_module_signature_info(const struct kmod_file *file, struct kmod_signature_info *sig_info) _must_check_ __attribute__((nonnull(1, 2)));
391b4714 207void kmod_module_signature_info_free(struct kmod_signature_info *sig_info) __attribute__((nonnull));
60084cf1
AG
208
209/* libkmod-builtin.c */
60084cf1 210ssize_t kmod_builtin_get_modinfo(struct kmod_ctx *ctx, const char *modname, char ***modinfo) __attribute__((nonnull(1, 2, 3)));