Lucas De Marchi | 586fc30 | 2011-11-21 14:35:35 -0200 | [diff] [blame] | 1 | #ifndef _LIBKMOD_PRIVATE_H_ |
| 2 | #define _LIBKMOD_PRIVATE_H_ |
| 3 | |
| 4 | #include <stdbool.h> |
Lucas De Marchi | 4462c4a | 2011-11-29 18:05:43 -0200 | [diff] [blame] | 5 | #include <stdio.h> |
Lucas De Marchi | 586fc30 | 2011-11-21 14:35:35 -0200 | [diff] [blame] | 6 | #include <syslog.h> |
| 7 | |
Lucas De Marchi | 88e9c12 | 2011-11-23 12:23:46 -0200 | [diff] [blame] | 8 | #include "macro.h" |
Lucas De Marchi | 586fc30 | 2011-11-21 14:35:35 -0200 | [diff] [blame] | 9 | #include "libkmod.h" |
| 10 | |
Lucas De Marchi | f87081b | 2011-11-23 12:21:29 -0200 | [diff] [blame] | 11 | static __always_inline __printf_format(2, 3) void |
Lucas De Marchi | 586fc30 | 2011-11-21 14:35:35 -0200 | [diff] [blame] | 12 | kmod_log_null(struct kmod_ctx *ctx, const char *format, ...) {} |
| 13 | |
| 14 | #define kmod_log_cond(ctx, prio, arg...) \ |
| 15 | do { \ |
| 16 | if (kmod_get_log_priority(ctx) >= prio) \ |
| 17 | kmod_log(ctx, prio, __FILE__, __LINE__, __FUNCTION__, ## arg);\ |
| 18 | } while (0) |
| 19 | |
| 20 | #ifdef ENABLE_LOGGING |
| 21 | # ifdef ENABLE_DEBUG |
Lucas De Marchi | ae6df84 | 2011-11-25 01:05:30 -0200 | [diff] [blame] | 22 | # define DBG(ctx, arg...) kmod_log_cond(ctx, LOG_DEBUG, ## arg) |
Lucas De Marchi | 586fc30 | 2011-11-21 14:35:35 -0200 | [diff] [blame] | 23 | # else |
Lucas De Marchi | ae6df84 | 2011-11-25 01:05:30 -0200 | [diff] [blame] | 24 | # define DBG(ctx, arg...) kmod_log_null(ctx, ## arg) |
Lucas De Marchi | 586fc30 | 2011-11-21 14:35:35 -0200 | [diff] [blame] | 25 | # endif |
Lucas De Marchi | ae6df84 | 2011-11-25 01:05:30 -0200 | [diff] [blame] | 26 | # define INFO(ctx, arg...) kmod_log_cond(ctx, LOG_INFO, ## arg) |
| 27 | # define ERR(ctx, arg...) kmod_log_cond(ctx, LOG_ERR, ## arg) |
Lucas De Marchi | 586fc30 | 2011-11-21 14:35:35 -0200 | [diff] [blame] | 28 | #else |
Lucas De Marchi | ae6df84 | 2011-11-25 01:05:30 -0200 | [diff] [blame] | 29 | # define DBG(ctx, arg...) kmod_log_null(ctx, ## arg) |
| 30 | # define INFO(ctx, arg...) kmod_log_null(ctx, ## arg) |
| 31 | # define ERR(ctx, arg...) kmod_log_null(ctx, ## arg) |
Lucas De Marchi | 586fc30 | 2011-11-21 14:35:35 -0200 | [diff] [blame] | 32 | #endif |
| 33 | |
| 34 | #define KMOD_EXPORT __attribute__ ((visibility("default"))) |
| 35 | |
| 36 | void kmod_log(struct kmod_ctx *ctx, |
| 37 | int priority, const char *file, int line, const char *fn, |
Gustavo Sverzut Barbieri | 12d9419 | 2011-12-02 20:34:58 -0200 | [diff] [blame] | 38 | const char *format, ...) __attribute__((format(printf, 6, 7))) __attribute__((nonnull(1, 3, 5))); |
Lucas De Marchi | 586fc30 | 2011-11-21 14:35:35 -0200 | [diff] [blame] | 39 | |
Lucas De Marchi | 6924e47 | 2011-11-22 05:38:28 -0200 | [diff] [blame] | 40 | struct list_node { |
| 41 | struct list_node *next, *prev; |
| 42 | }; |
| 43 | |
| 44 | struct kmod_list { |
| 45 | struct list_node node; |
| 46 | void *data; |
| 47 | }; |
| 48 | |
Gustavo Sverzut Barbieri | 12d9419 | 2011-12-02 20:34:58 -0200 | [diff] [blame] | 49 | struct kmod_list *kmod_list_append(struct kmod_list *list, const void *data) __must_check __attribute__((nonnull(2))); |
| 50 | struct kmod_list *kmod_list_prepend(struct kmod_list *list, const void *data) __must_check __attribute__((nonnull(2))); |
| 51 | struct kmod_list *kmod_list_remove(struct kmod_list *list) __must_check; |
Lucas De Marchi | 6924e47 | 2011-11-22 05:38:28 -0200 | [diff] [blame] | 52 | struct kmod_list *kmod_list_remove_data(struct kmod_list *list, |
Gustavo Sverzut Barbieri | 12d9419 | 2011-12-02 20:34:58 -0200 | [diff] [blame] | 53 | const void *data) __must_check __attribute__((nonnull(2))); |
Lucas De Marchi | 62be799 | 2011-12-01 15:27:42 -0200 | [diff] [blame] | 54 | struct kmod_list *kmod_list_remove_n_latest(struct kmod_list *list, |
| 55 | unsigned int n) __must_check; |
Lucas De Marchi | 86e8788 | 2011-12-05 23:41:14 -0200 | [diff] [blame] | 56 | struct kmod_list *kmod_list_insert_after(struct kmod_list *list, const void *data) __attribute__((nonnull(2))); |
Lucas De Marchi | b91a1c6 | 2011-12-05 23:53:56 -0200 | [diff] [blame^] | 57 | struct kmod_list *kmod_list_insert_before(struct kmod_list *list, const void *data) __attribute__((nonnull(2))); |
Lucas De Marchi | 86e8788 | 2011-12-05 23:41:14 -0200 | [diff] [blame] | 58 | |
Lucas De Marchi | cf91579 | 2011-12-05 11:33:15 -0200 | [diff] [blame] | 59 | #undef kmod_list_foreach |
| 60 | #define kmod_list_foreach(list_entry, first_entry) \ |
Lucas De Marchi | d2d648d | 2011-12-06 01:44:08 -0200 | [diff] [blame] | 61 | for (list_entry = ((first_entry) == NULL) ? NULL : (first_entry); \ |
Lucas De Marchi | cf91579 | 2011-12-05 11:33:15 -0200 | [diff] [blame] | 62 | list_entry != NULL; \ |
Lucas De Marchi | d2d648d | 2011-12-06 01:44:08 -0200 | [diff] [blame] | 63 | list_entry = (list_entry->node.next == &((first_entry)->node)) ? NULL : \ |
Lucas De Marchi | cf91579 | 2011-12-05 11:33:15 -0200 | [diff] [blame] | 64 | container_of(list_entry->node.next, struct kmod_list, node)) |
Lucas De Marchi | 60aa4d8 | 2011-11-30 18:57:38 -0200 | [diff] [blame] | 65 | |
| 66 | /* libkmod.c */ |
Gustavo Sverzut Barbieri | 1ce08a5 | 2011-12-02 20:24:07 -0200 | [diff] [blame] | 67 | const char *kmod_get_dirname(const struct kmod_ctx *ctx) __attribute__((nonnull(1))); |
Gustavo Sverzut Barbieri | 12d9419 | 2011-12-02 20:34:58 -0200 | [diff] [blame] | 68 | int kmod_lookup_alias_from_config(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3))); |
| 69 | int kmod_lookup_alias_from_symbols_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3))); |
| 70 | int kmod_lookup_alias_from_aliases_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3))); |
| 71 | int kmod_lookup_alias_from_moddep_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3))); |
Lucas De Marchi | 671d489 | 2011-12-05 20:23:05 -0200 | [diff] [blame] | 72 | char *kmod_search_moddep(struct kmod_ctx *ctx, const char *name) __attribute__((nonnull(1,2))); |
Lucas De Marchi | 221631d | 2011-11-24 16:41:01 -0200 | [diff] [blame] | 73 | |
Lucas De Marchi | 60aa4d8 | 2011-11-30 18:57:38 -0200 | [diff] [blame] | 74 | /* libkmod-config.c */ |
Lucas De Marchi | 7c2ab35 | 2011-11-29 18:07:43 -0200 | [diff] [blame] | 75 | struct kmod_config { |
Gustavo Sverzut Barbieri | d13e606 | 2011-12-02 21:40:22 -0200 | [diff] [blame] | 76 | struct kmod_ctx *ctx; |
Lucas De Marchi | 7c2ab35 | 2011-11-29 18:07:43 -0200 | [diff] [blame] | 77 | struct kmod_list *aliases; |
Lucas De Marchi | 81cf206 | 2011-11-29 18:48:02 -0200 | [diff] [blame] | 78 | struct kmod_list *blacklists; |
Lucas De Marchi | 7c2ab35 | 2011-11-29 18:07:43 -0200 | [diff] [blame] | 79 | }; |
Gustavo Sverzut Barbieri | d13e606 | 2011-12-02 21:40:22 -0200 | [diff] [blame] | 80 | int kmod_config_new(struct kmod_ctx *ctx, struct kmod_config **config) __attribute__((nonnull(1))); |
| 81 | void kmod_config_free(struct kmod_config *config) __attribute__((nonnull(1))); |
Gustavo Sverzut Barbieri | 12d9419 | 2011-12-02 20:34:58 -0200 | [diff] [blame] | 82 | const char *kmod_alias_get_name(const struct kmod_list *l) __attribute__((nonnull(1))); |
| 83 | const char *kmod_alias_get_modname(const struct kmod_list *l) __attribute__((nonnull(1))); |
Lucas De Marchi | 7c2ab35 | 2011-11-29 18:07:43 -0200 | [diff] [blame] | 84 | |
Lucas De Marchi | 7636e72 | 2011-12-01 17:56:03 -0200 | [diff] [blame] | 85 | /* libkmod-module.c */ |
Lucas De Marchi | 671d489 | 2011-12-05 20:23:05 -0200 | [diff] [blame] | 86 | int kmod_module_parse_depline(struct kmod_module *mod, char *line) __attribute__((nonnull(1, 2))); |
Lucas De Marchi | 7636e72 | 2011-12-01 17:56:03 -0200 | [diff] [blame] | 87 | |
Gustavo Sverzut Barbieri | 7db0865 | 2011-12-05 00:17:37 -0200 | [diff] [blame] | 88 | /* libkmod-hash.c */ |
| 89 | struct kmod_hash; |
| 90 | struct kmod_hash *kmod_hash_new(unsigned int n_buckets, void (*free_value)(void *value)); |
| 91 | void kmod_hash_free(struct kmod_hash *hash); |
| 92 | int kmod_hash_add(struct kmod_hash *hash, const char *key, const void *value); |
| 93 | int kmod_hash_del(struct kmod_hash *hash, const char *key); |
| 94 | void *kmod_hash_find(const struct kmod_hash *hash, const char *key); |
| 95 | |
| 96 | |
Lucas De Marchi | 60aa4d8 | 2011-11-30 18:57:38 -0200 | [diff] [blame] | 97 | /* util functions */ |
Lucas De Marchi | ad5555b | 2011-12-03 03:53:10 -0200 | [diff] [blame] | 98 | char *getline_wrapped(FILE *fp, unsigned int *linenum) __attribute__((nonnull(1))); |
Gustavo Sverzut Barbieri | 12d9419 | 2011-12-02 20:34:58 -0200 | [diff] [blame] | 99 | char *underscores(struct kmod_ctx *ctx, char *s) __attribute__((nonnull(1, 2))); |
Lucas De Marchi | 44a5460 | 2011-11-30 14:36:46 -0200 | [diff] [blame] | 100 | #define streq(a, b) (strcmp((a), (b)) == 0) |
Gustavo Sverzut Barbieri | 12d9419 | 2011-12-02 20:34:58 -0200 | [diff] [blame] | 101 | bool startswith(const char *s, const char *prefix) __attribute__((nonnull(1, 2))); |
Gustavo Sverzut Barbieri | 32c328d | 2011-12-04 14:18:19 -0200 | [diff] [blame] | 102 | void *memdup(const void *p, size_t n) __attribute__((nonnull(1))); |
Lucas De Marchi | 4462c4a | 2011-11-29 18:05:43 -0200 | [diff] [blame] | 103 | |
Gustavo Sverzut Barbieri | f12ae3c | 2011-12-04 12:40:00 -0200 | [diff] [blame] | 104 | ssize_t read_str_safe(int fd, char *buf, size_t buflen) __must_check __attribute__((nonnull(2))); |
| 105 | int read_str_long(int fd, long *value, int base) __must_check __attribute__((nonnull(2))); |
| 106 | int read_str_ulong(int fd, unsigned long *value, int base) __must_check __attribute__((nonnull(2))); |
| 107 | |
| 108 | |
Lucas De Marchi | 586fc30 | 2011-11-21 14:35:35 -0200 | [diff] [blame] | 109 | #endif |