2011-11-21 23:35:35 +07:00
|
|
|
#ifndef _LIBKMOD_PRIVATE_H_
|
|
|
|
#define _LIBKMOD_PRIVATE_H_
|
|
|
|
|
|
|
|
#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-11-23 21:23:46 +07:00
|
|
|
#include "macro.h"
|
2011-11-21 23:35:35 +07:00
|
|
|
#include "libkmod.h"
|
|
|
|
|
2011-11-23 21:21:29 +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) \
|
|
|
|
kmod_log(ctx, prio, __FILE__, __LINE__, __FUNCTION__, ## arg);\
|
|
|
|
} 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")))
|
|
|
|
|
|
|
|
void kmod_log(struct kmod_ctx *ctx,
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2011-12-03 05:34:58 +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,
|
2011-12-03 05:34:58 +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,
|
|
|
|
unsigned int n) __must_check;
|
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-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)));
|
2011-11-25 01:41:01 +07:00
|
|
|
|
2011-12-01 03:57:38 +07:00
|
|
|
/* libkmod-config.c */
|
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-11-30 03:07:43 +07:00
|
|
|
};
|
2011-12-03 06:40:22 +07:00
|
|
|
int kmod_config_new(struct kmod_ctx *ctx, struct kmod_config **config) __attribute__((nonnull(1)));
|
|
|
|
void kmod_config_free(struct kmod_config *config) __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-11-30 03:07:43 +07:00
|
|
|
|
2011-12-02 02:56:03 +07:00
|
|
|
/* libkmod-module.c */
|
2011-12-03 05:34:58 +07:00
|
|
|
int kmod_module_parse_dep(struct kmod_module *mod, char *line) __attribute__((nonnull(1, 2)));
|
2011-12-02 02:56:03 +07:00
|
|
|
|
2011-12-01 03:57:38 +07:00
|
|
|
/* util functions */
|
2011-12-03 12:53:10 +07:00
|
|
|
char *getline_wrapped(FILE *fp, unsigned int *linenum) __attribute__((nonnull(1)));
|
2011-12-03 05:34:58 +07:00
|
|
|
char *underscores(struct kmod_ctx *ctx, char *s) __attribute__((nonnull(1, 2)));
|
2011-11-30 23:36:46 +07:00
|
|
|
#define streq(a, b) (strcmp((a), (b)) == 0)
|
2011-12-03 05:34:58 +07:00
|
|
|
bool startswith(const char *s, const char *prefix) __attribute__((nonnull(1, 2)));
|
2011-12-04 23:18:19 +07:00
|
|
|
void *memdup(const void *p, size_t n) __attribute__((nonnull(1)));
|
2011-11-30 03:05:43 +07:00
|
|
|
|
2011-12-04 21:40:00 +07:00
|
|
|
ssize_t read_str_safe(int fd, char *buf, size_t buflen) __must_check __attribute__((nonnull(2)));
|
|
|
|
int read_str_long(int fd, long *value, int base) __must_check __attribute__((nonnull(2)));
|
|
|
|
int read_str_ulong(int fd, unsigned long *value, int base) __must_check __attribute__((nonnull(2)));
|
|
|
|
|
|
|
|
|
2011-11-21 23:35:35 +07:00
|
|
|
#endif
|