]> git.ipfire.org Git - thirdparty/kmod.git/blame - libkmod/libkmod-private.h
ELF: initial support for modinfo and strip of modversions and vermagic.
[thirdparty/kmod.git] / libkmod / libkmod-private.h
CommitLineData
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 12static __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 39void 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
43struct list_node {
44 struct list_node *next, *prev;
45};
46
47struct kmod_list {
48 struct list_node node;
49 void *data;
50};
51
12d9419d
GSB
52struct kmod_list *kmod_list_append(struct kmod_list *list, const void *data) __must_check __attribute__((nonnull(2)));
53struct kmod_list *kmod_list_prepend(struct kmod_list *list, const void *data) __must_check __attribute__((nonnull(2)));
54struct kmod_list *kmod_list_remove(struct kmod_list *list) __must_check;
6924e47a 55struct kmod_list *kmod_list_remove_data(struct kmod_list *list,
12d9419d 56 const void *data) __must_check __attribute__((nonnull(2)));
62be7995
LDM
57struct kmod_list *kmod_list_remove_n_latest(struct kmod_list *list,
58 unsigned int n) __must_check;
86e87885 59struct kmod_list *kmod_list_insert_after(struct kmod_list *list, const void *data) __attribute__((nonnull(2)));
b91a1c6d 60struct kmod_list *kmod_list_insert_before(struct kmod_list *list, const void *data) __attribute__((nonnull(2)));
1965029c 61struct 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 78const char *kmod_get_dirname(const struct kmod_ctx *ctx) __attribute__((nonnull(1)));
fd186ae9 79
12d9419d
GSB
80int kmod_lookup_alias_from_config(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3)));
81int kmod_lookup_alias_from_symbols_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3)));
82int kmod_lookup_alias_from_aliases_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3)));
83int kmod_lookup_alias_from_moddep_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3)));
f4fc5523 84int kmod_lookup_alias_from_commands(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3)));
fd186ae9 85
671d4894 86char *kmod_search_moddep(struct kmod_ctx *ctx, const char *name) __attribute__((nonnull(1,2)));
221631d5 87
8bdeca11
LDM
88struct kmod_module *kmod_pool_get_module(struct kmod_ctx *ctx, const char *key) __attribute__((nonnull(1,2)));
89void kmod_pool_add_module(struct kmod_ctx *ctx, struct kmod_module *mod, const char *key) __attribute__((nonnull(1,2, 3)));
90void kmod_pool_del_module(struct kmod_ctx *ctx, struct kmod_module *mod, const char *key) __attribute__((nonnull(1,2, 3)));
fd186ae9 91
bd3f5535
GSB
92const struct kmod_list *kmod_get_options(const struct kmod_ctx *ctx) __must_check __attribute__((nonnull(1)));
93const struct kmod_list *kmod_get_install_commands(const struct kmod_ctx *ctx) __must_check __attribute__((nonnull(1)));
94const struct kmod_list *kmod_get_remove_commands(const struct kmod_ctx *ctx) __must_check __attribute__((nonnull(1)));
1c522600 95const 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 99struct 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 108int kmod_config_new(struct kmod_ctx *ctx, struct kmod_config **config, const char * const *config_paths) __attribute__((nonnull(1, 2,3)));
d13e606f 109void kmod_config_free(struct kmod_config *config) __attribute__((nonnull(1)));
12d9419d
GSB
110const char *kmod_alias_get_name(const struct kmod_list *l) __attribute__((nonnull(1)));
111const char *kmod_alias_get_modname(const struct kmod_list *l) __attribute__((nonnull(1)));
bd3f5535
GSB
112const char *kmod_option_get_options(const struct kmod_list *l) __attribute__((nonnull(1)));
113const char *kmod_option_get_modname(const struct kmod_list *l) __attribute__((nonnull(1)));
114const char *kmod_command_get_command(const struct kmod_list *l) __attribute__((nonnull(1)));
115const char *kmod_command_get_modname(const struct kmod_list *l) __attribute__((nonnull(1)));
116
1c522600
GSB
117const char *kmod_softdep_get_name(const struct kmod_list *l) __attribute__((nonnull(1)));
118const char * const *kmod_softdep_get_pre(const struct kmod_list *l, unsigned int *count) __attribute__((nonnull(1, 2)));
119const char * const *kmod_softdep_get_post(const struct kmod_list *l, unsigned int *count);
120
7c2ab358 121
7636e72b 122/* libkmod-module.c */
6ad5f263 123int kmod_module_new_from_alias(struct kmod_ctx *ctx, const char *alias, const char *name, struct kmod_module **mod);
d917f274 124char *modname_normalize(const char *modname, char buf[NAME_MAX], size_t *len) __attribute__((nonnull(1, 2)));
671d4894 125int kmod_module_parse_depline(struct kmod_module *mod, char *line) __attribute__((nonnull(1, 2)));
f4fc5523
LDM
126void kmod_module_set_install_commands(struct kmod_module *mod, const char *cmd) __attribute__((nonnull(1)));
127void kmod_module_set_remove_commands(struct kmod_module *mod, const char *cmd) __attribute__((nonnull(1)));
7636e72b 128
7db08652
GSB
129/* libkmod-hash.c */
130struct kmod_hash;
131struct kmod_hash *kmod_hash_new(unsigned int n_buckets, void (*free_value)(void *value));
132void kmod_hash_free(struct kmod_hash *hash);
133int kmod_hash_add(struct kmod_hash *hash, const char *key, const void *value);
134int kmod_hash_del(struct kmod_hash *hash, const char *key);
135void *kmod_hash_find(const struct kmod_hash *hash, const char *key);
136
3d8226ed
GSB
137/* libkmod-file.c */
138struct kmod_file *kmod_file_open(const char *filename) __must_check __attribute__((nonnull(1)));
139void *kmod_file_get_contents(const struct kmod_file *file) __must_check __attribute__((nonnull(1)));
140off_t kmod_file_get_size(const struct kmod_file *file) __must_check __attribute__((nonnull(1)));
141void kmod_file_unref(struct kmod_file *file) __attribute__((nonnull(1)));
142
708624a4
GSB
143/* libkmod-elf.c */
144struct kmod_elf;
145struct kmod_modversion {
146 uint64_t crc;
147 char *symbol;
148};
149
150struct kmod_elf *kmod_elf_new(const void *memory, off_t size) __must_check __attribute__((nonnull(1)));
151void kmod_elf_unref(struct kmod_elf *elf) __attribute__((nonnull(1)));
152const void *kmod_elf_get_memory(const struct kmod_elf *elf) __must_check __attribute__((nonnull(1)));
153int kmod_elf_get_strings(const struct kmod_elf *elf, const char *section, char ***array) __must_check __attribute__((nonnull(1,2,3)));
154int kmod_elf_get_modversions(const struct kmod_elf *elf, struct kmod_modversion **array) __must_check __attribute__((nonnull(1,2)));
155int kmod_elf_strip_section(struct kmod_elf *elf, const char *section) __must_check __attribute__((nonnull(1,2)));
156int kmod_elf_strip_vermagic(struct kmod_elf *elf) __must_check __attribute__((nonnull(1)));
7db08652 157
60aa4d8b 158/* util functions */
ad5555b2 159char *getline_wrapped(FILE *fp, unsigned int *linenum) __attribute__((nonnull(1)));
12d9419d 160char *underscores(struct kmod_ctx *ctx, char *s) __attribute__((nonnull(1, 2)));
44a5460f 161#define streq(a, b) (strcmp((a), (b)) == 0)
12d9419d 162bool startswith(const char *s, const char *prefix) __attribute__((nonnull(1, 2)));
32c328d2 163void *memdup(const void *p, size_t n) __attribute__((nonnull(1)));
4462c4ac 164
f12ae3c4
GSB
165ssize_t read_str_safe(int fd, char *buf, size_t buflen) __must_check __attribute__((nonnull(2)));
166int read_str_long(int fd, long *value, int base) __must_check __attribute__((nonnull(2)));
167int read_str_ulong(int fd, unsigned long *value, int base) __must_check __attribute__((nonnull(2)));
afca7801 168char *strchr_replace(char *s, int c, char r);
3a468809 169bool path_is_absolute(const char *p) __must_check __attribute__((nonnull(1)));
06363cc1 170char *path_make_absolute_cwd(const char *p) __must_check __attribute__((nonnull(1)));
b148b860 171int 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