2012-07-18 20:19:48 +07:00
|
|
|
#pragma once
|
2011-11-21 23:35:35 +07:00
|
|
|
|
|
|
|
#include <stdbool.h>
|
2011-11-30 03:05:43 +07:00
|
|
|
#include <stdio.h>
|
2011-11-21 23:35:35 +07:00
|
|
|
#include <syslog.h>
|
2011-12-11 06:00:19 +07:00
|
|
|
#include <limits.h>
|
2011-11-21 23:35:35 +07:00
|
|
|
|
2013-04-09 14:00:20 +07:00
|
|
|
#include "missing.h"
|
2011-11-23 21:23:46 +07:00
|
|
|
#include "macro.h"
|
2011-11-21 23:35:35 +07:00
|
|
|
#include "libkmod.h"
|
|
|
|
|
2012-05-24 06:27:23 +07:00
|
|
|
static _always_inline_ _printf_format_(2, 3) void
|
2011-11-21 23:35:35 +07:00
|
|
|
kmod_log_null(struct kmod_ctx *ctx, const char *format, ...) {}
|
|
|
|
|
|
|
|
#define kmod_log_cond(ctx, prio, arg...) \
|
|
|
|
do { \
|
|
|
|
if (kmod_get_log_priority(ctx) >= prio) \
|
2011-12-20 22:27:40 +07:00
|
|
|
kmod_log(ctx, prio, __FILE__, __LINE__, __func__, ## arg);\
|
2011-11-21 23:35:35 +07:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#ifdef ENABLE_LOGGING
|
|
|
|
# ifdef ENABLE_DEBUG
|
2011-11-25 10:05:30 +07:00
|
|
|
# define DBG(ctx, arg...) kmod_log_cond(ctx, LOG_DEBUG, ## arg)
|
2011-11-21 23:35:35 +07:00
|
|
|
# else
|
2011-11-25 10:05:30 +07:00
|
|
|
# define DBG(ctx, arg...) kmod_log_null(ctx, ## arg)
|
2011-11-21 23:35:35 +07:00
|
|
|
# endif
|
2011-11-25 10:05:30 +07:00
|
|
|
# define INFO(ctx, arg...) kmod_log_cond(ctx, LOG_INFO, ## arg)
|
|
|
|
# define ERR(ctx, arg...) kmod_log_cond(ctx, LOG_ERR, ## arg)
|
2011-11-21 23:35:35 +07:00
|
|
|
#else
|
2011-11-25 10:05:30 +07:00
|
|
|
# define DBG(ctx, arg...) kmod_log_null(ctx, ## arg)
|
|
|
|
# define INFO(ctx, arg...) kmod_log_null(ctx, ## arg)
|
|
|
|
# define ERR(ctx, arg...) kmod_log_null(ctx, ## arg)
|
2011-11-21 23:35:35 +07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define KMOD_EXPORT __attribute__ ((visibility("default")))
|
|
|
|
|
2011-12-15 02:19:19 +07:00
|
|
|
#define KCMD_LINE_SIZE 4096
|
|
|
|
|
2013-02-12 01:07:52 +07:00
|
|
|
#ifndef HAVE_SECURE_GETENV
|
|
|
|
# ifdef HAVE___SECURE_GETENV
|
|
|
|
# define secure_getenv __secure_getenv
|
|
|
|
# else
|
|
|
|
# warning neither secure_getenv nor __secure_getenv is available
|
|
|
|
# define secure_getenv getenv
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2011-12-08 22:47:55 +07:00
|
|
|
void kmod_log(const struct kmod_ctx *ctx,
|
2011-11-21 23:35:35 +07:00
|
|
|
int priority, const char *file, int line, const char *fn,
|
2011-12-03 05:34:58 +07:00
|
|
|
const char *format, ...) __attribute__((format(printf, 6, 7))) __attribute__((nonnull(1, 3, 5)));
|
2011-11-21 23:35:35 +07:00
|
|
|
|
2011-11-22 14:38:28 +07:00
|
|
|
struct list_node {
|
|
|
|
struct list_node *next, *prev;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct kmod_list {
|
|
|
|
struct list_node node;
|
|
|
|
void *data;
|
|
|
|
};
|
|
|
|
|
2012-05-24 06:27:23 +07:00
|
|
|
struct kmod_list *kmod_list_append(struct kmod_list *list, const void *data) _must_check_ __attribute__((nonnull(2)));
|
|
|
|
struct kmod_list *kmod_list_prepend(struct kmod_list *list, const void *data) _must_check_ __attribute__((nonnull(2)));
|
|
|
|
struct kmod_list *kmod_list_remove(struct kmod_list *list) _must_check_;
|
2011-11-22 14:38:28 +07:00
|
|
|
struct kmod_list *kmod_list_remove_data(struct kmod_list *list,
|
2012-05-24 06:27:23 +07:00
|
|
|
const void *data) _must_check_ __attribute__((nonnull(2)));
|
2011-12-02 00:27:42 +07:00
|
|
|
struct kmod_list *kmod_list_remove_n_latest(struct kmod_list *list,
|
2012-05-24 06:27:23 +07:00
|
|
|
unsigned int n) _must_check_;
|
2011-12-06 08:41:14 +07:00
|
|
|
struct kmod_list *kmod_list_insert_after(struct kmod_list *list, const void *data) __attribute__((nonnull(2)));
|
2011-12-06 08:53:56 +07:00
|
|
|
struct kmod_list *kmod_list_insert_before(struct kmod_list *list, const void *data) __attribute__((nonnull(2)));
|
2012-05-24 06:27:23 +07:00
|
|
|
struct kmod_list *kmod_list_append_list(struct kmod_list *list1, struct kmod_list *list2) _must_check_;
|
2011-12-06 08:41:14 +07:00
|
|
|
|
2011-12-05 20:33:15 +07:00
|
|
|
#undef kmod_list_foreach
|
|
|
|
#define kmod_list_foreach(list_entry, first_entry) \
|
2011-12-06 10:44:08 +07:00
|
|
|
for (list_entry = ((first_entry) == NULL) ? NULL : (first_entry); \
|
2011-12-05 20:33:15 +07:00
|
|
|
list_entry != NULL; \
|
2011-12-06 10:44:08 +07:00
|
|
|
list_entry = (list_entry->node.next == &((first_entry)->node)) ? NULL : \
|
2011-12-05 20:33:15 +07:00
|
|
|
container_of(list_entry->node.next, struct kmod_list, node))
|
2011-12-01 03:57:38 +07:00
|
|
|
|
2011-12-17 07:33:08 +07:00
|
|
|
#undef kmod_list_foreach_reverse
|
|
|
|
#define kmod_list_foreach_reverse(list_entry, first_entry) \
|
|
|
|
for (list_entry = (((first_entry) == NULL) ? NULL : container_of(first_entry->node.prev, struct kmod_list, node)); \
|
|
|
|
list_entry != NULL; \
|
|
|
|
list_entry = ((list_entry == first_entry) ? NULL : \
|
|
|
|
container_of(list_entry->node.prev, struct kmod_list, node)))
|
|
|
|
|
2011-12-01 03:57:38 +07:00
|
|
|
/* libkmod.c */
|
2011-12-03 05:24:07 +07:00
|
|
|
const char *kmod_get_dirname(const struct kmod_ctx *ctx) __attribute__((nonnull(1)));
|
2011-12-06 12:38:37 +07:00
|
|
|
|
2011-12-03 05:34:58 +07:00
|
|
|
int kmod_lookup_alias_from_config(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3)));
|
|
|
|
int kmod_lookup_alias_from_symbols_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3)));
|
|
|
|
int kmod_lookup_alias_from_aliases_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3)));
|
|
|
|
int kmod_lookup_alias_from_moddep_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3)));
|
2012-02-17 05:43:16 +07:00
|
|
|
int kmod_lookup_alias_from_builtin_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3)));
|
2011-12-16 12:57:12 +07:00
|
|
|
int kmod_lookup_alias_from_commands(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3)));
|
2012-01-18 10:26:44 +07:00
|
|
|
void kmod_set_modules_visited(struct kmod_ctx *ctx, bool visited) __attribute__((nonnull((1))));
|
2011-12-06 12:38:37 +07:00
|
|
|
|
2011-12-06 05:23:05 +07:00
|
|
|
char *kmod_search_moddep(struct kmod_ctx *ctx, const char *name) __attribute__((nonnull(1,2)));
|
2011-11-25 01:41:01 +07:00
|
|
|
|
2011-12-15 22:11:51 +07:00
|
|
|
struct kmod_module *kmod_pool_get_module(struct kmod_ctx *ctx, const char *key) __attribute__((nonnull(1,2)));
|
2013-04-30 22:34:55 +07:00
|
|
|
void kmod_pool_add_module(struct kmod_ctx *ctx, struct kmod_module *mod, const char *key) __attribute__((nonnull(1, 2, 3)));
|
|
|
|
void kmod_pool_del_module(struct kmod_ctx *ctx, struct kmod_module *mod, const char *key) __attribute__((nonnull(1, 2, 3)));
|
2011-12-06 12:38:37 +07:00
|
|
|
|
2012-06-12 11:43:46 +07:00
|
|
|
const struct kmod_config *kmod_get_config(const struct kmod_ctx *ctx) __attribute__((nonnull(1)));
|
2011-12-06 12:38:37 +07:00
|
|
|
|
2011-12-01 03:57:38 +07:00
|
|
|
/* libkmod-config.c */
|
2012-01-01 03:48:05 +07:00
|
|
|
struct kmod_config_path {
|
|
|
|
unsigned long long stamp;
|
|
|
|
char path[];
|
|
|
|
};
|
|
|
|
|
2011-11-30 03:07:43 +07:00
|
|
|
struct kmod_config {
|
2011-12-03 06:40:22 +07:00
|
|
|
struct kmod_ctx *ctx;
|
2011-11-30 03:07:43 +07:00
|
|
|
struct kmod_list *aliases;
|
2011-11-30 03:48:02 +07:00
|
|
|
struct kmod_list *blacklists;
|
2011-12-07 12:18:57 +07:00
|
|
|
struct kmod_list *options;
|
2011-12-07 20:31:28 +07:00
|
|
|
struct kmod_list *remove_commands;
|
|
|
|
struct kmod_list *install_commands;
|
2011-12-17 06:18:10 +07:00
|
|
|
struct kmod_list *softdeps;
|
2012-01-01 03:48:05 +07:00
|
|
|
|
|
|
|
struct kmod_list *paths;
|
2011-11-30 03:07:43 +07:00
|
|
|
};
|
2012-01-01 03:48:05 +07:00
|
|
|
|
2011-12-12 05:37:01 +07:00
|
|
|
int kmod_config_new(struct kmod_ctx *ctx, struct kmod_config **config, const char * const *config_paths) __attribute__((nonnull(1, 2,3)));
|
2011-12-03 06:40:22 +07:00
|
|
|
void kmod_config_free(struct kmod_config *config) __attribute__((nonnull(1)));
|
2011-12-24 19:50:47 +07:00
|
|
|
const char *kmod_blacklist_get_modname(const struct kmod_list *l) __attribute__((nonnull(1)));
|
2011-12-03 05:34:58 +07:00
|
|
|
const char *kmod_alias_get_name(const struct kmod_list *l) __attribute__((nonnull(1)));
|
|
|
|
const char *kmod_alias_get_modname(const struct kmod_list *l) __attribute__((nonnull(1)));
|
2011-12-11 05:47:01 +07:00
|
|
|
const char *kmod_option_get_options(const struct kmod_list *l) __attribute__((nonnull(1)));
|
|
|
|
const char *kmod_option_get_modname(const struct kmod_list *l) __attribute__((nonnull(1)));
|
|
|
|
const char *kmod_command_get_command(const struct kmod_list *l) __attribute__((nonnull(1)));
|
|
|
|
const char *kmod_command_get_modname(const struct kmod_list *l) __attribute__((nonnull(1)));
|
|
|
|
|
2011-12-17 06:18:10 +07:00
|
|
|
const char *kmod_softdep_get_name(const struct kmod_list *l) __attribute__((nonnull(1)));
|
|
|
|
const char * const *kmod_softdep_get_pre(const struct kmod_list *l, unsigned int *count) __attribute__((nonnull(1, 2)));
|
|
|
|
const char * const *kmod_softdep_get_post(const struct kmod_list *l, unsigned int *count);
|
|
|
|
|
2011-11-30 03:07:43 +07:00
|
|
|
|
2011-12-02 02:56:03 +07:00
|
|
|
/* libkmod-module.c */
|
2011-12-13 23:12:50 +07:00
|
|
|
int kmod_module_new_from_alias(struct kmod_ctx *ctx, const char *alias, const char *name, struct kmod_module **mod);
|
2011-12-06 05:23:05 +07:00
|
|
|
int kmod_module_parse_depline(struct kmod_module *mod, char *line) __attribute__((nonnull(1, 2)));
|
2011-12-16 12:57:12 +07:00
|
|
|
void kmod_module_set_install_commands(struct kmod_module *mod, const char *cmd) __attribute__((nonnull(1)));
|
|
|
|
void kmod_module_set_remove_commands(struct kmod_module *mod, const char *cmd) __attribute__((nonnull(1)));
|
2012-01-18 10:26:44 +07:00
|
|
|
void kmod_module_set_visited(struct kmod_module *mod, bool visited) __attribute__((nonnull(1)));
|
2012-02-17 05:43:16 +07:00
|
|
|
void kmod_module_set_builtin(struct kmod_module *mod, bool builtin) __attribute__((nonnull((1))));
|
2011-12-02 02:56:03 +07:00
|
|
|
|
2011-12-05 09:17:37 +07:00
|
|
|
/* libkmod-hash.c */
|
2011-12-27 21:26:51 +07:00
|
|
|
|
|
|
|
#include "libkmod-hash.h"
|
2011-12-05 09:17:37 +07:00
|
|
|
|
2011-12-17 01:08:53 +07:00
|
|
|
/* libkmod-file.c */
|
2012-05-24 06:27:23 +07:00
|
|
|
struct kmod_file *kmod_file_open(const struct kmod_ctx *ctx, const char *filename) _must_check_ __attribute__((nonnull(1,2)));
|
2012-10-18 11:36:33 +07:00
|
|
|
struct kmod_elf *kmod_file_get_elf(struct kmod_file *file) __attribute__((nonnull(1)));
|
2012-05-24 06:27:23 +07:00
|
|
|
void *kmod_file_get_contents(const struct kmod_file *file) _must_check_ __attribute__((nonnull(1)));
|
|
|
|
off_t kmod_file_get_size(const struct kmod_file *file) _must_check_ __attribute__((nonnull(1)));
|
2013-02-19 03:02:32 +07:00
|
|
|
bool kmod_file_get_direct(const struct kmod_file *file) _must_check_ __attribute__((nonnull(1)));
|
|
|
|
int kmod_file_get_fd(const struct kmod_file *file) _must_check_ __attribute__((nonnull(1)));
|
2011-12-17 01:08:53 +07:00
|
|
|
void kmod_file_unref(struct kmod_file *file) __attribute__((nonnull(1)));
|
|
|
|
|
2011-12-18 10:25:06 +07:00
|
|
|
/* libkmod-elf.c */
|
|
|
|
struct kmod_elf;
|
|
|
|
struct kmod_modversion {
|
|
|
|
uint64_t crc;
|
2011-12-20 20:54:53 +07:00
|
|
|
enum kmod_symbol_bind bind;
|
2011-12-18 10:25:06 +07:00
|
|
|
char *symbol;
|
|
|
|
};
|
|
|
|
|
2012-05-24 06:27:23 +07:00
|
|
|
struct kmod_elf *kmod_elf_new(const void *memory, off_t size) _must_check_ __attribute__((nonnull(1)));
|
2011-12-18 10:25:06 +07:00
|
|
|
void kmod_elf_unref(struct kmod_elf *elf) __attribute__((nonnull(1)));
|
2012-05-24 06:27:23 +07:00
|
|
|
const void *kmod_elf_get_memory(const struct kmod_elf *elf) _must_check_ __attribute__((nonnull(1)));
|
|
|
|
int kmod_elf_get_strings(const struct kmod_elf *elf, const char *section, char ***array) _must_check_ __attribute__((nonnull(1,2,3)));
|
|
|
|
int kmod_elf_get_modversions(const struct kmod_elf *elf, struct kmod_modversion **array) _must_check_ __attribute__((nonnull(1,2)));
|
|
|
|
int kmod_elf_get_symbols(const struct kmod_elf *elf, struct kmod_modversion **array) _must_check_ __attribute__((nonnull(1,2)));
|
|
|
|
int kmod_elf_get_dependency_symbols(const struct kmod_elf *elf, struct kmod_modversion **array) _must_check_ __attribute__((nonnull(1,2)));
|
|
|
|
int kmod_elf_strip_section(struct kmod_elf *elf, const char *section) _must_check_ __attribute__((nonnull(1,2)));
|
|
|
|
int kmod_elf_strip_vermagic(struct kmod_elf *elf) _must_check_ __attribute__((nonnull(1)));
|
2011-12-05 09:17:37 +07:00
|
|
|
|
2012-01-26 10:21:17 +07:00
|
|
|
/*
|
|
|
|
* Debug mock lib need to find section ".gnu.linkonce.this_module" in order to
|
|
|
|
* get modname
|
|
|
|
*/
|
2012-05-24 06:27:23 +07:00
|
|
|
int 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)));
|
2012-01-26 10:21:17 +07:00
|
|
|
|
2013-01-16 15:52:01 +07:00
|
|
|
/* libkmod-signature.c */
|
|
|
|
struct kmod_signature_info {
|
|
|
|
const char *signer;
|
|
|
|
size_t signer_len;
|
|
|
|
const char *key_id;
|
|
|
|
size_t key_id_len;
|
|
|
|
const char *algo, *hash_algo, *id_type;
|
|
|
|
};
|
|
|
|
bool kmod_module_signature_info(const struct kmod_file *file, struct kmod_signature_info *sig_info) _must_check_ __attribute__((nonnull(1, 2)));
|
2011-12-01 03:57:38 +07:00
|
|
|
/* util functions */
|
2011-12-27 23:38:26 +07:00
|
|
|
#include "libkmod-util.h"
|