char *buf;
};
-static bool kmod_builtin_info_init(struct kmod_builtin_info *info,
- struct kmod_ctx *ctx)
+static bool kmod_builtin_info_init(struct kmod_builtin_info *info, struct kmod_ctx *ctx)
{
char path[PATH_MAX];
FILE *fp = NULL;
}
static ssize_t get_strings(struct kmod_builtin_info *info, const char *modname,
- struct strbuf *buf)
+ struct strbuf *buf)
{
const size_t modlen = strlen(modname);
ssize_t count, n;
if (dot == NULL) {
count = -EINVAL;
ERR(info->ctx, "get_strings: "
- "unexpected string without modname prefix\n");
+ "unexpected string without modname prefix\n");
return count;
}
if (strncmp(line, modname, modlen) || line[modlen] != '.') {
continue;
break;
}
- if (!strbuf_pushchars(buf, dot + 1) ||
- !strbuf_pushchar(buf, '\0')) {
+ if (!strbuf_pushchars(buf, dot + 1) || !strbuf_pushchar(buf, '\0')) {
count = -errno;
ERR(info->ctx, "get_strings: "
- "failed to append modinfo string\n");
+ "failed to append modinfo string\n");
return count;
}
count++;
if (count == INTPTR_MAX) {
count = -ENOMEM;
ERR(info->ctx, "get_strings: "
- "too many modinfo strings encountered\n");
+ "too many modinfo strings encountered\n");
return count;
}
size_t n;
/* make sure that vector and strings fit into memory constraints */
- if (SIZE_MAX / sizeof(char *) - 1 < count ||
- SIZE_MAX - buf->used < vecsz) {
+ if (SIZE_MAX / sizeof(char *) - 1 < count || SIZE_MAX - buf->used < vecsz) {
errno = ENOMEM;
return NULL;
}
/* array will be allocated with strings in a single malloc, just free *array */
ssize_t kmod_builtin_get_modinfo(struct kmod_ctx *ctx, const char *modname,
- char ***modinfo)
+ char ***modinfo)
{
struct kmod_builtin_info info;
struct strbuf buf;
return l->data;
}
-const char *kmod_alias_get_name(const struct kmod_list *l) {
+const char *kmod_alias_get_name(const struct kmod_list *l)
+{
const struct kmod_alias *alias = l->data;
return alias->name;
}
-const char *kmod_alias_get_modname(const struct kmod_list *l) {
+const char *kmod_alias_get_modname(const struct kmod_list *l)
+{
const struct kmod_alias *alias = l->data;
return alias->modname;
}
-const char *kmod_option_get_options(const struct kmod_list *l) {
+const char *kmod_option_get_options(const struct kmod_list *l)
+{
const struct kmod_options *alias = l->data;
return alias->options;
}
-const char *kmod_option_get_modname(const struct kmod_list *l) {
+const char *kmod_option_get_modname(const struct kmod_list *l)
+{
const struct kmod_options *alias = l->data;
return alias->modname;
}
-const char *kmod_command_get_command(const struct kmod_list *l) {
+const char *kmod_command_get_command(const struct kmod_list *l)
+{
const struct kmod_command *alias = l->data;
return alias->command;
}
-const char *kmod_command_get_modname(const struct kmod_list *l) {
+const char *kmod_command_get_modname(const struct kmod_list *l)
+{
const struct kmod_command *alias = l->data;
return alias->modname;
}
-const char *kmod_softdep_get_name(const struct kmod_list *l) {
+const char *kmod_softdep_get_name(const struct kmod_list *l)
+{
const struct kmod_softdep *dep = l->data;
return dep->name;
}
-const char * const *kmod_softdep_get_pre(const struct kmod_list *l, unsigned int *count) {
+const char *const *kmod_softdep_get_pre(const struct kmod_list *l, unsigned int *count)
+{
const struct kmod_softdep *dep = l->data;
*count = dep->n_pre;
return dep->pre;
}
-const char * const *kmod_softdep_get_post(const struct kmod_list *l, unsigned int *count) {
+const char *const *kmod_softdep_get_post(const struct kmod_list *l, unsigned int *count)
+{
const struct kmod_softdep *dep = l->data;
*count = dep->n_post;
return dep->post;
}
-const char *kmod_weakdep_get_name(const struct kmod_list *l) {
+const char *kmod_weakdep_get_name(const struct kmod_list *l)
+{
const struct kmod_weakdep *dep = l->data;
return dep->name;
}
-const char * const *kmod_weakdep_get_weak(const struct kmod_list *l, unsigned int *count) {
+const char *const *kmod_weakdep_get_weak(const struct kmod_list *l, unsigned int *count)
+{
const struct kmod_weakdep *dep = l->data;
*count = dep->n_weak;
return dep->weak;
}
-static int kmod_config_add_command(struct kmod_config *config,
- const char *modname,
- const char *command,
- const char *command_name,
- struct kmod_list **list)
+static int kmod_config_add_command(struct kmod_config *config, const char *modname,
+ const char *command, const char *command_name,
+ struct kmod_list **list)
{
_cleanup_free_ struct kmod_command *cmd;
struct kmod_list *l;
size_t modnamelen = strlen(modname) + 1;
size_t commandlen = strlen(command) + 1;
- DBG(config->ctx, "modname='%s' cmd='%s %s'\n", modname, command_name,
- command);
+ DBG(config->ctx, "modname='%s' cmd='%s %s'\n", modname, command_name, command);
cmd = malloc(sizeof(*cmd) + modnamelen + commandlen);
if (!cmd)
return 0;
}
-static void kmod_config_free_command(struct kmod_config *config,
- struct kmod_list *l,
- struct kmod_list **list)
+static void kmod_config_free_command(struct kmod_config *config, struct kmod_list *l,
+ struct kmod_list **list)
{
struct kmod_command *cmd = l->data;
*list = kmod_list_remove(l);
}
-static int kmod_config_add_options(struct kmod_config *config,
- const char *modname, const char *options)
+static int kmod_config_add_options(struct kmod_config *config, const char *modname,
+ const char *options)
{
_cleanup_free_ struct kmod_options *opt;
struct kmod_list *list;
return 0;
}
-static void kmod_config_free_options(struct kmod_config *config,
- struct kmod_list *l)
+static void kmod_config_free_options(struct kmod_config *config, struct kmod_list *l)
{
struct kmod_options *opt = l->data;
config->options = kmod_list_remove(l);
}
-static int kmod_config_add_alias(struct kmod_config *config,
- const char *name, const char *modname)
+static int kmod_config_add_alias(struct kmod_config *config, const char *name,
+ const char *modname)
{
_cleanup_free_ struct kmod_alias *alias;
struct kmod_list *list;
return 0;
}
-static void kmod_config_free_alias(struct kmod_config *config,
- struct kmod_list *l)
+static void kmod_config_free_alias(struct kmod_config *config, struct kmod_list *l)
{
struct kmod_alias *alias = l->data;
config->aliases = kmod_list_remove(l);
}
-static int kmod_config_add_blacklist(struct kmod_config *config,
- const char *modname)
+static int kmod_config_add_blacklist(struct kmod_config *config, const char *modname)
{
_cleanup_free_ char *p;
struct kmod_list *list;
return 0;
}
-static void kmod_config_free_blacklist(struct kmod_config *config,
- struct kmod_list *l)
+static void kmod_config_free_blacklist(struct kmod_config *config, struct kmod_list *l)
{
free(l->data);
config->blacklists = kmod_list_remove(l);
}
-static int kmod_config_add_softdep(struct kmod_config *config,
- const char *modname,
- const char *line)
+static int kmod_config_add_softdep(struct kmod_config *config, const char *modname,
+ const char *line)
{
struct kmod_list *list;
struct kmod_softdep *dep;
DBG(config->ctx, "modname=%s\n", modname);
/* analyze and count */
- for (p = s = line; ; s++) {
+ for (p = s = line;; s++) {
size_t plen;
if (*s != '\0') {
plen = s - p;
if (plen == sizeof("pre:") - 1 &&
- memcmp(p, "pre:", sizeof("pre:") - 1) == 0)
+ memcmp(p, "pre:", sizeof("pre:") - 1) == 0)
mode = S_PRE;
else if (plen == sizeof("post:") - 1 &&
- memcmp(p, "post:", sizeof("post:") - 1) == 0)
+ memcmp(p, "post:", sizeof("post:") - 1) == 0)
mode = S_POST;
else if (*s != '\0' || (*s == '\0' && !was_space)) {
if (mode == S_PRE) {
DBG(config->ctx, "%u pre, %u post\n", n_pre, n_post);
dep = malloc(sizeof(struct kmod_softdep) + modnamelen +
- n_pre * sizeof(const char *) +
- n_post * sizeof(const char *) +
+ n_pre * sizeof(const char *) + n_post * sizeof(const char *) +
buflen);
if (dep == NULL) {
ERR(config->ctx, "out-of-memory modname=%s\n", modname);
n_post = 0;
mode = S_NONE;
was_space = false;
- for (p = s = line; ; s++) {
+ for (p = s = line;; s++) {
size_t plen;
if (*s != '\0') {
plen = s - p;
if (plen == sizeof("pre:") - 1 &&
- memcmp(p, "pre:", sizeof("pre:") - 1) == 0)
+ memcmp(p, "pre:", sizeof("pre:") - 1) == 0)
mode = S_PRE;
else if (plen == sizeof("post:") - 1 &&
- memcmp(p, "post:", sizeof("post:") - 1) == 0)
+ memcmp(p, "post:", sizeof("post:") - 1) == 0)
mode = S_POST;
else if (*s != '\0' || (*s == '\0' && !was_space)) {
if (mode == S_PRE) {
return 0;
}
-static int kmod_config_add_weakdep(struct kmod_config *config,
- const char *modname,
- const char *line)
+static int kmod_config_add_weakdep(struct kmod_config *config, const char *modname,
+ const char *line)
{
struct kmod_list *list;
struct kmod_weakdep *dep;
DBG(config->ctx, "modname=%s\n", modname);
/* analyze and count */
- for (p = s = line; ; s++) {
+ for (p = s = line;; s++) {
size_t plen;
if (*s != '\0') {
DBG(config->ctx, "%u weak\n", n_weak);
dep = malloc(sizeof(struct kmod_weakdep) + modnamelen +
- n_weak * sizeof(const char *) +
- buflen);
+ n_weak * sizeof(const char *) + buflen);
if (dep == NULL) {
ERR(config->ctx, "out-of-memory modname=%s\n", modname);
return -ENOMEM;
itr = dep->name + modnamelen;
n_weak = 0;
was_space = false;
- for (p = s = line; ; s++) {
+ for (p = s = line;; s++) {
size_t plen;
if (*s != '\0') {
return 0;
}
-static char *softdep_to_char(struct kmod_softdep *dep) {
+static char *softdep_to_char(struct kmod_softdep *dep)
+{
const size_t sz_preprefix = sizeof("pre: ") - 1;
const size_t sz_postprefix = sizeof("post: ") - 1;
size_t sz = 1; /* at least '\0' */
*/
if (dep->n_pre > 0) {
start = dep->pre[0];
- end = dep->pre[dep->n_pre - 1]
- + strlen(dep->pre[dep->n_pre - 1]);
+ end = dep->pre[dep->n_pre - 1] + strlen(dep->pre[dep->n_pre - 1]);
sz_pre = end - start;
sz += sz_pre + sz_preprefix;
} else
if (dep->n_post > 0) {
start = dep->post[0];
- end = dep->post[dep->n_post - 1]
- + strlen(dep->post[dep->n_post - 1]);
+ end = dep->post[dep->n_post - 1] + strlen(dep->post[dep->n_post - 1]);
sz_post = end - start;
sz += sz_post + sz_postprefix;
} else
return s;
}
-static char *weakdep_to_char(struct kmod_weakdep *dep) {
+static char *weakdep_to_char(struct kmod_weakdep *dep)
+{
size_t sz;
const char *start, *end;
char *s, *itr;
*/
if (dep->n_weak > 0) {
start = dep->weak[0];
- end = dep->weak[dep->n_weak - 1]
- + strlen(dep->weak[dep->n_weak - 1]);
+ end = dep->weak[dep->n_weak - 1] + strlen(dep->weak[dep->n_weak - 1]);
sz = end - start;
} else
sz = 0;
return s;
}
-static void kmod_config_free_softdep(struct kmod_config *config,
- struct kmod_list *l)
+static void kmod_config_free_softdep(struct kmod_config *config, struct kmod_list *l)
{
free(l->data);
config->softdeps = kmod_list_remove(l);
}
-static void kmod_config_free_weakdep(struct kmod_config *config,
- struct kmod_list *l)
+static void kmod_config_free_weakdep(struct kmod_config *config, struct kmod_list *l)
{
free(l->data);
config->weakdeps = kmod_list_remove(l);
}
-static void kcmdline_parse_result(struct kmod_config *config, char *modname,
- char *param, char *value)
+static void kcmdline_parse_result(struct kmod_config *config, char *modname, char *param,
+ char *value)
{
if (modname == NULL || param == NULL)
return;
}
} else {
if (underscores(modname) < 0) {
- ERR(config->ctx, "Ignoring bad option on kernel command line while parsing module name: '%s'\n",
+ ERR(config->ctx,
+ "Ignoring bad option on kernel command line while parsing module name: '%s'\n",
modname);
} else {
kmod_config_add_options(config, modname, param);
{
char buf[KCMD_LINE_SIZE];
int fd, err;
- char *p, *p_quote_start, *modname, *param = NULL, *value = NULL;
+ char *p, *p_quote_start, *modname, *param = NULL, *value = NULL;
bool is_quoted = false, iter = true;
enum state {
STATE_IGNORE,
STATE_COMPLETE,
} state;
- fd = open("/proc/cmdline", O_RDONLY|O_CLOEXEC);
+ fd = open("/proc/cmdline", O_RDONLY | O_CLOEXEC);
if (fd < 0) {
err = -errno;
DBG(config->ctx, "could not open '/proc/cmdline' for reading: %m\n");
close(fd);
if (err < 0) {
ERR(config->ctx, "could not read from '/proc/cmdline': %s\n",
- strerror(-err));
+ strerror(-err));
return err;
}
* vv v v
* "parport\0dyndbg=file drivers/parport/ieee1284_ops.c +mpf" */
memmove(p_quote_start, modname, value - modname);
- value--; modname--; param--;
+ value--;
+ modname--;
+ param--;
*value = '"';
}
kcmdline_parse_result(config, modname, param, value);
* Take an fd and own it. It will be closed on return. filename is used only
* for debug messages
*/
-static int kmod_config_parse(struct kmod_config *config, int fd,
- const char *filename)
+static int kmod_config_parse(struct kmod_config *config, int fd, const char *filename)
{
struct kmod_ctx *ctx = config->ctx;
char *line;
if (underscores(modname) < 0 || installcmd == NULL)
goto syntax_error;
- kmod_config_add_command(config, modname, installcmd,
- cmd, &config->install_commands);
+ kmod_config_add_command(config, modname, installcmd, cmd,
+ &config->install_commands);
} else if (streq(cmd, "remove")) {
char *modname = strtok_r(NULL, "\t ", &saveptr);
char *removecmd = strtok_r(NULL, "\0", &saveptr);
if (underscores(modname) < 0 || removecmd == NULL)
goto syntax_error;
- kmod_config_add_command(config, modname, removecmd,
- cmd, &config->remove_commands);
+ kmod_config_add_command(config, modname, removecmd, cmd,
+ &config->remove_commands);
} else if (streq(cmd, "softdep")) {
char *modname = strtok_r(NULL, "\t ", &saveptr);
char *softdeps = strtok_r(NULL, "\0", &saveptr);
goto syntax_error;
kmod_config_add_weakdep(config, modname, weakdeps);
- } else if (streq(cmd, "include")
- || streq(cmd, "config")) {
+ } else if (streq(cmd, "include") || streq(cmd, "config")) {
ERR(ctx, "%s: command %s is deprecated and not parsed anymore\n",
- filename, cmd);
+ filename, cmd);
} else {
syntax_error:
ERR(ctx, "%s line %u: ignoring bad line starting with '%s'\n",
- filename, linenum, cmd);
+ filename, linenum, cmd);
}
done_next:
while (config->install_commands) {
kmod_config_free_command(config, config->install_commands,
- &config->install_commands);
+ &config->install_commands);
}
while (config->remove_commands) {
kmod_config_free_command(config, config->remove_commands,
- &config->remove_commands);
+ &config->remove_commands);
}
while (config->softdeps)
while (config->weakdeps)
kmod_config_free_weakdep(config, config->weakdeps);
- for (; config->paths != NULL;
- config->paths = kmod_list_remove(config->paths))
+ for (; config->paths != NULL; config->paths = kmod_list_remove(config->paths))
free(config->paths->data);
free(config);
}
-static bool conf_files_filter_out(struct kmod_ctx *ctx, DIR *d,
- const char *path, const char *fn)
+static bool conf_files_filter_out(struct kmod_ctx *ctx, DIR *d, const char *path,
+ const char *fn)
{
size_t len = strlen(fn);
struct stat st;
}
if (S_ISDIR(st.st_mode)) {
- ERR(ctx, "Directories inside directories are not supported: "
- "%s/%s\n", path, fn);
+ ERR(ctx,
+ "Directories inside directories are not supported: "
+ "%s/%s\n",
+ path, fn);
return true;
}
char name[];
};
-static int conf_files_insert_sorted(struct kmod_ctx *ctx,
- struct kmod_list **list,
- const char *path, const char *name)
+static int conf_files_insert_sorted(struct kmod_ctx *ctx, struct kmod_list **list,
+ const char *path, const char *name)
{
struct kmod_list *lpos, *tmp;
struct conf_file *cf;
}
if (cmp == 0) {
- DBG(ctx, "Ignoring duplicate config file: %s/%s\n", path,
- name);
+ DBG(ctx, "Ignoring duplicate config file: %s/%s\n", path, name);
return -EEXIST;
}
* Insert configuration files in @list, ignoring duplicates
*/
static int conf_files_list(struct kmod_ctx *ctx, struct kmod_list **list,
- const char *path,
- unsigned long long *path_stamp)
+ const char *path, unsigned long long *path_stamp)
{
DIR *d;
int err;
}
int kmod_config_new(struct kmod_ctx *ctx, struct kmod_config **p_config,
- const char * const *config_paths)
+ const char *const *config_paths)
{
struct kmod_config *config;
struct kmod_list *list = NULL;
if (cf->is_single) {
fn = cf->path;
- } else if (snprintf(buf, sizeof(buf), "%s/%s",
- cf->path, cf->name) >= (int)sizeof(buf)) {
- ERR(ctx, "Error parsing %s/%s: path too long\n",
- cf->path, cf->name);
+ } else if (snprintf(buf, sizeof(buf), "%s/%s", cf->path, cf->name) >=
+ (int)sizeof(buf)) {
+ ERR(ctx, "Error parsing %s/%s: path too long\n", cf->path,
+ cf->name);
free(cf);
continue;
}
- fd = open(fn, O_RDONLY|O_CLOEXEC);
+ fd = open(fn, O_RDONLY | O_CLOEXEC);
DBG(ctx, "parsing file '%s' fd=%d\n", fn, fd);
if (fd >= 0)
return s;
}
-static struct kmod_config_iter *kmod_config_iter_new(const struct kmod_ctx* ctx,
- enum config_type type)
+static struct kmod_config_iter *kmod_config_iter_new(const struct kmod_ctx *ctx,
+ enum config_type type)
{
struct kmod_config_iter *iter = calloc(1, sizeof(*iter));
const struct kmod_config *config = kmod_get_config(ctx);
struct kmod_config_iter *i = (struct kmod_config_iter *)iter;
free(i->data);
- s = i->data = (void *) iter->get_value(iter->curr);
+ s = i->data = (void *)iter->get_value(iter->curr);
} else
s = iter->get_value(iter->curr);
//#define ENABLE_ELFDBG 1
#if defined(ENABLE_LOGGING) && defined(ENABLE_ELFDBG)
-#define ELFDBG(elf, ...) \
- _elf_dbg(elf, __FILE__, __LINE__, __func__, __VA_ARGS__);
+#define ELFDBG(elf, ...) _elf_dbg(elf, __FILE__, __LINE__, __func__, __VA_ARGS__);
-static inline void _elf_dbg(const struct kmod_elf *elf, const char *fname, unsigned line, const char *func, const char *fmt, ...)
+static inline void _elf_dbg(const struct kmod_elf *elf, const char *fname, unsigned line,
+ const char *func, const char *fmt, ...)
{
va_list args;
- fprintf(stderr, "ELFDBG-%d%c: %s:%u %s() ",
- (elf->class & KMOD_ELF_32) ? 32 : 64,
- (elf->class & KMOD_ELF_MSB) ? 'M' : 'L',
- fname, line, func);
+ fprintf(stderr, "ELFDBG-%d%c: %s:%u %s() ", (elf->class & KMOD_ELF_32) ? 32 : 64,
+ (elf->class & KMOD_ELF_MSB) ? 'M' : 'L', fname, line, func);
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
#define ELFDBG(elf, ...)
#endif
-
static int elf_identify(const void *memory, uint64_t size)
{
const uint8_t *p = memory;
return class;
}
-static inline uint64_t elf_get_uint(const struct kmod_elf *elf, uint64_t offset, uint16_t size)
+static inline uint64_t elf_get_uint(const struct kmod_elf *elf, uint64_t offset,
+ uint16_t size)
{
const uint8_t *p;
uint64_t ret = 0;
assert(size <= sizeof(uint64_t));
assert(offset + size <= elf->size);
if (offset + size > elf->size) {
- ELFDBG(elf, "out of bounds: %"PRIu64" + %"PRIu16" = %"PRIu64"> %"PRIu64" (ELF size)\n",
+ ELFDBG(elf,
+ "out of bounds: %" PRIu64 " + %" PRIu16 " = %" PRIu64 "> %" PRIu64
+ " (ELF size)\n",
offset, size, offset + size, elf->size);
return (uint64_t)-1;
}
ret = (ret << 8) | p[size - i];
}
- ELFDBG(elf, "size=%"PRIu16" offset=%"PRIu64" value=%"PRIu64"\n",
- size, offset, ret);
+ ELFDBG(elf, "size=%" PRIu16 " offset=%" PRIu64 " value=%" PRIu64 "\n", size,
+ offset, ret);
return ret;
}
-static inline int elf_set_uint(struct kmod_elf *elf, uint64_t offset, uint64_t size, uint64_t value)
+static inline int elf_set_uint(struct kmod_elf *elf, uint64_t offset, uint64_t size,
+ uint64_t value)
{
uint8_t *p;
size_t i;
- ELFDBG(elf, "size=%"PRIu16" offset=%"PRIu64" value=%"PRIu64" write memory=%p\n",
+ ELFDBG(elf,
+ "size=%" PRIu16 " offset=%" PRIu64 " value=%" PRIu64 " write memory=%p\n",
size, offset, value, elf->changed);
assert(size <= sizeof(uint64_t));
assert(offset + size <= elf->size);
if (offset + size > elf->size) {
- ELFDBG(elf, "out of bounds: %"PRIu64" + %"PRIu16" = %"PRIu64"> %"PRIu64" (ELF size)\n",
+ ELFDBG(elf,
+ "out of bounds: %" PRIu64 " + %" PRIu16 " = %" PRIu64 "> %" PRIu64
+ " (ELF size)\n",
offset, size, offset + size, elf->size);
return -1;
}
{
assert(offset < elf->size);
if (offset >= elf->size) {
- ELFDBG(elf, "out-of-bounds: %"PRIu64" >= %"PRIu64" (ELF size)\n",
+ ELFDBG(elf, "out-of-bounds: %" PRIu64 " >= %" PRIu64 " (ELF size)\n",
offset, elf->size);
return NULL;
}
assert(idx != SHN_UNDEF);
assert(idx < elf->header.section.count);
if (idx == SHN_UNDEF || idx >= elf->header.section.count) {
- ELFDBG(elf, "invalid section number: %"PRIu16", last=%"PRIu16"\n",
+ ELFDBG(elf, "invalid section number: %" PRIu16 ", last=%" PRIu16 "\n",
idx, elf->header.section.count);
return NULL;
}
return elf_get_mem(elf, elf->header.section.offset +
- (uint64_t)(idx * elf->header.section.entry_size));
+ (uint64_t)(idx * elf->header.section.entry_size));
}
-static inline int elf_get_section_info(const struct kmod_elf *elf, uint16_t idx, uint64_t *offset, uint64_t *size, uint32_t *nameoff)
+static inline int elf_get_section_info(const struct kmod_elf *elf, uint16_t idx,
+ uint64_t *offset, uint64_t *size,
+ uint32_t *nameoff)
{
const uint8_t *p = elf_get_section_header(elf, idx);
uint64_t min_size, off = p - elf->memory;
if (p == NULL) {
- ELFDBG(elf, "no section at %"PRIu16"\n", idx);
+ ELFDBG(elf, "no section at %" PRIu16 "\n", idx);
*offset = 0;
*size = 0;
*nameoff = 0;
}
#undef READV
- if (addu64_overflow(*offset, *size, &min_size)
- || min_size > elf->size) {
- ELFDBG(elf, "out-of-bounds: %"PRIu64" >= %"PRIu64" (ELF size)\n",
+ if (addu64_overflow(*offset, *size, &min_size) || min_size > elf->size) {
+ ELFDBG(elf, "out-of-bounds: %" PRIu64 " >= %" PRIu64 " (ELF size)\n",
min_size, elf->size);
return -EINVAL;
}
- ELFDBG(elf, "section=%"PRIu16" is: offset=%"PRIu64" size=%"PRIu64" nameoff=%"PRIu32"\n",
+ ELFDBG(elf,
+ "section=%" PRIu16 " is: offset=%" PRIu64 " size=%" PRIu64
+ " nameoff=%" PRIu32 "\n",
idx, *offset, *size, *nameoff);
return 0;
elf->size = size;
elf->class = class;
-#define READV(field) \
- elf_get_uint(elf, offsetof(typeof(*hdr), field), sizeof(hdr->field))
+#define READV(field) elf_get_uint(elf, offsetof(typeof(*hdr), field), sizeof(hdr->field))
-#define LOAD_HEADER \
- elf->header.section.offset = READV(e_shoff); \
- elf->header.section.count = READV(e_shnum); \
- elf->header.section.entry_size = READV(e_shentsize); \
- elf->header.strings.section = READV(e_shstrndx); \
+#define LOAD_HEADER \
+ elf->header.section.offset = READV(e_shoff); \
+ elf->header.section.count = READV(e_shnum); \
+ elf->header.section.entry_size = READV(e_shentsize); \
+ elf->header.strings.section = READV(e_shstrndx); \
elf->header.machine = READV(e_machine)
if (elf->class & KMOD_ELF_32) {
const Elf32_Ehdr *hdr _unused_ = elf_get_mem(elf, 0);
#undef LOAD_HEADER
#undef READV
- ELFDBG(elf, "section: offset=%"PRIu64" count=%"PRIu16" entry_size=%"PRIu16" strings index=%"PRIu16"\n",
- elf->header.section.offset,
- elf->header.section.count,
- elf->header.section.entry_size,
- elf->header.strings.section);
+ ELFDBG(elf,
+ "section: offset=%" PRIu64 " count=%" PRIu16 " entry_size=%" PRIu16
+ " strings index=%" PRIu16 "\n",
+ elf->header.section.offset, elf->header.section.count,
+ elf->header.section.entry_size, elf->header.strings.section);
if (elf->header.section.entry_size != shdr_size) {
- ELFDBG(elf, "unexpected section entry size: %"PRIu16", expected %"PRIu16"\n",
+ ELFDBG(elf,
+ "unexpected section entry size: %" PRIu16 ", expected %" PRIu16
+ "\n",
elf->header.section.entry_size, shdr_size);
goto invalid;
}
shdrs_size = shdr_size * elf->header.section.count;
- if (addu64_overflow(shdrs_size, elf->header.section.offset, &min_size)
- || min_size > elf->size) {
+ if (addu64_overflow(shdrs_size, elf->header.section.offset, &min_size) ||
+ min_size > elf->size) {
ELFDBG(elf, "file is too short to hold sections\n");
goto invalid;
}
if (elf_get_section_info(elf, elf->header.strings.section,
- &elf->header.strings.offset,
- &elf->header.strings.size,
- &elf->header.strings.nameoff) < 0) {
+ &elf->header.strings.offset, &elf->header.strings.size,
+ &elf->header.strings.nameoff) < 0) {
ELFDBG(elf, "could not get strings section\n");
goto invalid;
} else {
return -ENODATA;
}
-int kmod_elf_get_section(const struct kmod_elf *elf, const char *section, const void **buf, uint64_t *buf_size)
+int kmod_elf_get_section(const struct kmod_elf *elf, const char *section,
+ const void **buf, uint64_t *buf_size)
{
uint64_t nameslen;
const char *names = elf_get_strings_section(elf, &nameslen);
if (size <= 1)
return 0;
- for (i = 0, count = 0; i < size; ) {
+ for (i = 0, count = 0; i < size;) {
if (strings[i] != '\0') {
i++;
continue;
a[count] = NULL;
a[0] = s;
- for (i = 0, j = 1; j < count && i < size; ) {
+ for (i = 0, j = 1; j < count && i < size;) {
if (s[i] != '\0') {
i++;
continue;
int i, count, err;
#define MODVERSION_SEC_SIZE (sizeof(struct kmod_modversion64))
- assert_cc(sizeof(struct kmod_modversion64) ==
- sizeof(struct kmod_modversion32));
+ assert_cc(sizeof(struct kmod_modversion64) == sizeof(struct kmod_modversion32));
if (elf->class & KMOD_ELF_32)
offcrc = sizeof(uint32_t);
}
len = strlen(s);
- ELFDBG(elf, "clear .modinfo vermagic \"%s\" (%zd bytes)\n",
- s, len);
+ ELFDBG(elf, "clear .modinfo vermagic \"%s\" (%zd bytes)\n", s, len);
memset(elf->changed + off, '\0', len);
return 0;
}
return -ENODATA;
}
-
-static int kmod_elf_get_symbols_symtab(const struct kmod_elf *elf, struct kmod_modversion **array)
+static int kmod_elf_get_symbols_symtab(const struct kmod_elf *elf,
+ struct kmod_modversion **array)
{
uint64_t i, last, size;
const void *buf;
}
}
-static uint64_t kmod_elf_resolve_crc(const struct kmod_elf *elf, uint64_t crc, uint16_t shndx)
+static uint64_t kmod_elf_resolve_crc(const struct kmod_elf *elf, uint64_t crc,
+ uint16_t shndx)
{
int err;
uint64_t off, size;
err = elf_get_section_info(elf, shndx, &off, &size, &nameoff);
if (err < 0) {
- ELFDBG("Could not find section index %"PRIu16" for crc", shndx);
+ ELFDBG("Could not find section index %" PRIu16 " for crc", shndx);
return (uint64_t)-1;
}
if (crc > (size - sizeof(uint32_t))) {
- ELFDBG("CRC offset %"PRIu64" is too big, section %"PRIu16" size is %"PRIu64"\n",
+ ELFDBG("CRC offset %" PRIu64 " is too big, section %" PRIu16
+ " size is %" PRIu64 "\n",
crc, shndx, size);
return (uint64_t)-1;
}
symlen = sizeof(Elf64_Sym);
if (symtablen % symlen != 0) {
- ELFDBG(elf, "unexpected .symtab of length %"PRIu64", not multiple of %"PRIu64" as expected.\n", symtablen, symlen);
+ ELFDBG(elf,
+ "unexpected .symtab of length %" PRIu64
+ ", not multiple of %" PRIu64 " as expected.\n",
+ symtablen, symlen);
goto fallback;
}
const char *name;
uint32_t name_off;
-#define READV(field) \
- elf_get_uint(elf, sym_off + offsetof(typeof(*s), field),\
- sizeof(s->field))
+#define READV(field) \
+ elf_get_uint(elf, sym_off + offsetof(typeof(*s), field), sizeof(s->field))
if (elf->class & KMOD_ELF_32) {
Elf32_Sym *s;
name_off = READV(st_name);
}
#undef READV
if (name_off >= strtablen) {
- ELFDBG(elf, ".strtab is %"PRIu64" bytes, but .symtab entry %d wants to access offset %"PRIu32".\n", strtablen, i, name_off);
+ ELFDBG(elf,
+ ".strtab is %" PRIu64
+ " bytes, but .symtab entry %d wants to access offset %" PRIu32
+ ".\n",
+ strtablen, i, name_off);
goto fallback;
}
uint8_t info, bind;
uint16_t shndx;
-#define READV(field) \
- elf_get_uint(elf, sym_off + offsetof(typeof(*s), field),\
- sizeof(s->field))
+#define READV(field) \
+ elf_get_uint(elf, sym_off + offsetof(typeof(*s), field), sizeof(s->field))
if (elf->class & KMOD_ELF_32) {
Elf32_Sym *s;
name_off = READV(st_name);
return kmod_elf_get_symbols_symtab(elf, array);
}
-static int kmod_elf_crc_find(const struct kmod_elf *elf, const void *versions, uint64_t versionslen, const char *name, uint64_t *crc)
+static int kmod_elf_crc_find(const struct kmod_elf *elf, const void *versions,
+ uint64_t versionslen, const char *name, uint64_t *crc)
{
size_t verlen, crclen, off;
uint64_t i;
/* from module-init-tools:elfops_core.c */
#ifndef STT_REGISTER
-#define STT_REGISTER 13 /* Global register reserved to app. */
+#define STT_REGISTER 13 /* Global register reserved to app. */
#endif
/* array will be allocated with strings in a single malloc, just free *array */
-int kmod_elf_get_dependency_symbols(const struct kmod_elf *elf, struct kmod_modversion **array)
+int kmod_elf_get_dependency_symbols(const struct kmod_elf *elf,
+ struct kmod_modversion **array)
{
uint64_t versionslen, strtablen, symtablen, str_off, sym_off, ver_off;
const void *versions, *strtab, *symtab;
crclen = sizeof(mv->crc);
}
if (versionslen % verlen != 0) {
- ELFDBG(elf, "unexpected __versions of length %"PRIu64", not multiple of %zd as expected.\n", versionslen, verlen);
+ ELFDBG(elf,
+ "unexpected __versions of length %" PRIu64
+ ", not multiple of %zd as expected.\n",
+ versionslen, verlen);
versions = NULL;
versionslen = 0;
}
symlen = sizeof(Elf64_Sym);
if (symtablen % symlen != 0) {
- ELFDBG(elf, "unexpected .symtab of length %"PRIu64", not multiple of %"PRIu64" as expected.\n", symtablen, symlen);
+ ELFDBG(elf,
+ "unexpected .symtab of length %" PRIu64
+ ", not multiple of %" PRIu64 " as expected.\n",
+ symtablen, symlen);
return -EINVAL;
}
return -ENOMEM;
}
- handle_register_symbols = (elf->header.machine == EM_SPARC ||
- elf->header.machine == EM_SPARCV9);
+ handle_register_symbols =
+ (elf->header.machine == EM_SPARC || elf->header.machine == EM_SPARCV9);
symcount = symtablen / symlen;
count = 0;
uint8_t info;
int idx;
-#define READV(field) \
- elf_get_uint(elf, sym_off + offsetof(typeof(*s), field),\
- sizeof(s->field))
+#define READV(field) \
+ elf_get_uint(elf, sym_off + offsetof(typeof(*s), field), sizeof(s->field))
if (elf->class & KMOD_ELF_32) {
Elf32_Sym *s;
name_off = READV(st_name);
}
if (name_off >= strtablen) {
- ELFDBG(elf, ".strtab is %"PRIu64" bytes, but .symtab entry %d wants to access offset %"PRIu32".\n", strtablen, i, name_off);
+ ELFDBG(elf,
+ ".strtab is %" PRIu64
+ " bytes, but .symtab entry %d wants to access offset %" PRIu32
+ ".\n",
+ strtablen, i, name_off);
free(visited_versions);
free(symcrcs);
return -EINVAL;
name = elf_get_mem(elf, str_off + name_off);
if (name[0] == '\0') {
- ELFDBG(elf, "empty symbol name at index %"PRIu64"\n", i);
+ ELFDBG(elf, "empty symbol name at index %" PRIu64 "\n", i);
continue;
}
uint16_t secidx;
uint8_t info, bind;
-#define READV(field) \
- elf_get_uint(elf, sym_off + offsetof(typeof(*s), field),\
- sizeof(s->field))
+#define READV(field) \
+ elf_get_uint(elf, sym_off + offsetof(typeof(*s), field), sizeof(s->field))
if (elf->class & KMOD_ELF_32) {
Elf32_Sym *s;
name_off = READV(st_name);
name = elf_get_mem(elf, str_off + name_off);
if (name[0] == '\0') {
- ELFDBG(elf, "empty symbol name at index %"PRIu64"\n", i);
+ ELFDBG(elf, "empty symbol name at index %" PRIu64 "\n", i);
continue;
}
void *p = NULL;
size_t total = 0;
- strm->avail_in = 0;
- strm->next_out = out_buf;
+ strm->avail_in = 0;
+ strm->next_out = out_buf;
strm->avail_out = sizeof(out_buf);
while (true) {
ret = -errno;
goto out;
}
- strm->next_in = in_buf;
+ strm->next_in = in_buf;
strm->avail_in = rdret;
if (rdret == 0)
action = LZMA_FINISH;
file->memory = p;
file->size = total;
return 0;
- out:
+out:
free(p);
return ret;
}
gzclose(gzf); /* closes the gzfd */
return err;
}
-
#include "libkmod-internal.h"
#include "libkmod-internal-file.h"
-static const char magic_zstd[] = {0x28, 0xB5, 0x2F, 0xFD};
-static const char magic_xz[] = {0xfd, '7', 'z', 'X', 'Z', 0};
-static const char magic_zlib[] = {0x1f, 0x8b};
+static const char magic_zstd[] = { 0x28, 0xB5, 0x2F, 0xFD };
+static const char magic_xz[] = { 0xfd, '7', 'z', 'X', 'Z', 0 };
+static const char magic_zlib[] = { 0x1f, 0x8b };
static int load_reg(struct kmod_file *file)
{
if ((uintmax_t)file->size > SIZE_MAX)
return -ENOMEM;
- file->memory = mmap(NULL, file->size, PROT_READ, MAP_PRIVATE,
- file->fd, 0);
+ file->memory = mmap(NULL, file->size, PROT_READ, MAP_PRIVATE, file->fd, 0);
if (file->memory == MAP_FAILED) {
file->memory = NULL;
return -errno;
return file->elf;
}
-struct kmod_file *kmod_file_open(const struct kmod_ctx *ctx,
- const char *filename)
+struct kmod_file *kmod_file_open(const struct kmod_ctx *ctx, const char *filename)
{
struct kmod_file *file;
char buf[7];
if (file == NULL)
return NULL;
- file->fd = open(filename, O_RDONLY|O_CLOEXEC);
+ file->fd = open(filename, O_RDONLY | O_CLOEXEC);
if (file->fd < 0) {
free(file);
return NULL;
#define INDEX_MAGIC 0xB007F457
#define INDEX_VERSION_MAJOR 0x0002
#define INDEX_VERSION_MINOR 0x0001
-#define INDEX_VERSION ((INDEX_VERSION_MAJOR<<16)|INDEX_VERSION_MINOR)
+#define INDEX_VERSION ((INDEX_VERSION_MAJOR << 16) | INDEX_VERSION_MINOR)
/* The index file maps keys to values. Both keys and values are ASCII strings.
* Each key can have multiple values. Values are sorted by an integer priority.
/* Format of node offsets within index file */
enum node_offset {
- INDEX_NODE_FLAGS = 0xF0000000, /* Flags in high nibble */
- INDEX_NODE_PREFIX = 0x80000000,
+ INDEX_NODE_FLAGS = 0xF0000000, /* Flags in high nibble */
+ INDEX_NODE_PREFIX = 0x80000000,
INDEX_NODE_VALUES = 0x40000000,
- INDEX_NODE_CHILDS = 0x20000000,
+ INDEX_NODE_CHILDS = 0x20000000,
- INDEX_NODE_MASK = 0x0FFFFFFF, /* Offset value */
+ INDEX_NODE_MASK = 0x0FFFFFFF, /* Offset value */
};
void index_values_free(struct index_value *values)
}
}
-static int add_value(struct index_value **values,
- const char *value, unsigned len, unsigned int priority)
+static int add_value(struct index_value **values, const char *value, unsigned len,
+ unsigned int priority)
{
struct index_value *v;
*/
struct index_node_f {
FILE *file;
- char *prefix; /* path compression */
+ char *prefix; /* path compression */
struct index_value *values;
- unsigned char first; /* range of child nodes */
+ unsigned char first; /* range of child nodes */
unsigned char last;
uint32_t children[0];
};
if (node == NULL)
goto err;
- node->first = (unsigned char) first;
- node->last = (unsigned char) last;
+ node->first = (unsigned char)first;
+ node->last = (unsigned char)last;
for (i = 0; i < child_count; i++)
if (read_u32(in, &node->children[i]) < 0)
strbuf_init(&buf);
while (value_count--) {
- if (read_u32(in, &priority) < 0 ||
- buf_freadchars(&buf, in) < 0) {
+ if (read_u32(in, &priority) < 0 || buf_freadchars(&buf, in) < 0) {
strbuf_release(&buf);
goto err;
}
if (read_u32(file, &magic) < 0 || magic != INDEX_MAGIC)
goto err;
- if (read_u32(file, &version) < 0 ||
- version >> 16 != INDEX_VERSION_MAJOR)
+ if (read_u32(file, &version) < 0 || version >> 16 != INDEX_VERSION_MAJOR)
goto err;
new = malloc(sizeof(struct index_file));
return index_read(in->file, in->root_offset);
}
-static struct index_node_f *index_readchild(const struct index_node_f *parent,
- int ch)
+static struct index_node_f *index_readchild(const struct index_node_f *parent, int ch)
{
if (parent->first <= ch && ch <= parent->last) {
- return index_read(parent->file,
- parent->children[ch - parent->first]);
+ return index_read(parent->file, parent->children[ch - parent->first]);
}
return NULL;
}
-static void index_dump_node(struct index_node_f *node, struct strbuf *buf,
- int fd)
+static void index_dump_node(struct index_node_f *node, struct strbuf *buf, int fd)
{
struct index_value *v;
size_t pushed;
int ch;
int j;
- while(node) {
+ while (node) {
for (j = 0; node->prefix[j]; j++) {
ch = node->prefix[j];
- if (ch != key[i+j]) {
+ if (ch != key[i + j]) {
index_close(node);
return NULL;
}
i += j;
if (key[i] == '\0') {
- value = node->values != NULL
- ? strdup(node->values[0].value)
- : NULL;
+ value = node->values != NULL ? strdup(node->values[0].value) :
+ NULL;
index_close(node);
return value;
*/
char *index_search(struct index_file *in, const char *key)
{
-// FIXME: return value by reference instead of strdup
+ // FIXME: return value by reference instead of strdup
struct index_node_f *root;
char *value;
return value;
}
-
-
/* Level 4: add all the values from a matching node */
static void index_searchwild__allvalues(struct index_node_f *node,
struct index_value **out)
* Level 3: traverse a sub-keyspace which starts with a wildcard,
* looking for matches.
*/
-static void index_searchwild__all(struct index_node_f *node, int j,
- struct strbuf *buf,
- const char *subkey,
- struct index_value **out)
+static void index_searchwild__all(struct index_node_f *node, int j, struct strbuf *buf,
+ const char *subkey, struct index_value **out)
{
size_t pushed = 0;
int ch;
}
/* Level 2: descend the tree (until we hit a wildcard) */
-static void index_searchwild__node(struct index_node_f *node,
- struct strbuf *buf,
- const char *key, int i,
- struct index_value **out)
+static void index_searchwild__node(struct index_node_f *node, struct strbuf *buf,
+ const char *key, int i, struct index_value **out)
{
struct index_node_f *child;
int j;
int ch;
- while(node) {
+ while (node) {
for (j = 0; node->prefix[j]; j++) {
ch = node->prefix[j];
if (ch == '*' || ch == '?' || ch == '[') {
- index_searchwild__all(node, j, buf,
- &key[i+j], out);
+ index_searchwild__all(node, j, buf, &key[i + j], out);
return;
}
- if (ch != key[i+j]) {
+ if (ch != key[i + j]) {
index_close(node);
return;
}
uint32_t v;
/* addr may be unalined to uint32_t */
- v = get_unaligned((uint32_t *) addr);
+ v = get_unaligned((uint32_t *)addr);
*p = addr + sizeof(uint32_t);
return ntohl(v);
return addr;
}
-static struct index_mm_node *index_mm_read_node(struct index_mm *idx,
- uint32_t offset) {
+static struct index_mm_node *index_mm_read_node(struct index_mm *idx, uint32_t offset)
+{
void *p = idx->mm;
struct index_mm_node *node;
const char *prefix;
child_count = 0;
}
- children_padding = (sizeof(struct index_mm_node) +
- (sizeof(uint32_t) * child_count)) % sizeof(void *);
+ children_padding =
+ (sizeof(struct index_mm_node) + (sizeof(uint32_t) * child_count)) %
+ sizeof(void *);
if (offset & INDEX_NODE_VALUES)
value_count = read_u32_mm(&p);
else
value_count = 0;
- node = malloc(sizeof(struct index_mm_node)
- + sizeof(uint32_t) * child_count + children_padding
- + sizeof(struct index_mm_value) * value_count);
+ node = malloc(sizeof(struct index_mm_node) + sizeof(uint32_t) * child_count +
+ children_padding + sizeof(struct index_mm_value) * value_count);
if (node == NULL)
return NULL;
if (value_count == 0)
node->values.values = NULL;
else {
- node->values.values = (struct index_mm_value *)
- ((char *)node + sizeof(struct index_mm_node) +
- sizeof(uint32_t) * child_count + children_padding);
+ node->values.values =
+ (struct index_mm_value *)((char *)node +
+ sizeof(struct index_mm_node) +
+ sizeof(uint32_t) * child_count +
+ children_padding);
}
node->values.len = value_count;
node->first = first;
return -ENOMEM;
}
- if ((fd = open(filename, O_RDONLY|O_CLOEXEC)) < 0) {
+ if ((fd = open(filename, O_RDONLY | O_CLOEXEC)) < 0) {
DBG(ctx, "open(%s, O_RDONLY|O_CLOEXEC): %m\n", filename);
err = -errno;
goto fail_open;
}
- if (fstat(fd, &st) < 0 || st.st_size < (off_t) sizeof(hdr)) {
+ if (fstat(fd, &st) < 0 || st.st_size < (off_t)sizeof(hdr)) {
err = -EINVAL;
goto fail_nommap;
}
idx->mm = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
if (idx->mm == MAP_FAILED) {
- ERR(ctx, "mmap(NULL, %"PRIu64", PROT_READ, MAP_PRIVATE, %d, 0): %m\n",
- (uint64_t) st.st_size, fd);
+ ERR(ctx, "mmap(NULL, %" PRIu64 ", PROT_READ, MAP_PRIVATE, %d, 0): %m\n",
+ (uint64_t)st.st_size, fd);
err = -errno;
goto fail_nommap;
}
hdr.root_offset = read_u32_mm(&p);
if (hdr.magic != INDEX_MAGIC) {
- ERR(ctx, "magic check fail: %x instead of %x\n", hdr.magic,
- INDEX_MAGIC);
+ ERR(ctx, "magic check fail: %x instead of %x\n", hdr.magic, INDEX_MAGIC);
err = -EINVAL;
goto fail;
}
if (hdr.version >> 16 != INDEX_VERSION_MAJOR) {
ERR(ctx, "major version check fail: %u instead of %u\n",
- hdr.version >> 16, INDEX_VERSION_MAJOR);
+ hdr.version >> 16, INDEX_VERSION_MAJOR);
err = -EINVAL;
goto fail;
}
return index_mm_read_node(idx, idx->root_offset);
}
-static struct index_mm_node *index_mm_readchild(const struct index_mm_node *parent,
- int ch)
+static struct index_mm_node *index_mm_readchild(const struct index_mm_node *parent, int ch)
{
if (parent->first <= ch && ch <= parent->last) {
return index_mm_read_node(parent->idx,
- parent->children[ch - parent->first]);
+ parent->children[ch - parent->first]);
}
return NULL;
}
-static void index_mm_dump_node(struct index_mm_node *node, struct strbuf *buf,
- int fd)
+static void index_mm_dump_node(struct index_mm_node *node, struct strbuf *buf, int fd)
{
struct index_mm_value *itr, *itr_end;
size_t pushed;
strbuf_release(&buf);
}
-static char *index_mm_search_node(struct index_mm_node *node, const char *key,
- int i)
+static char *index_mm_search_node(struct index_mm_node *node, const char *key, int i)
{
char *value;
struct index_mm_node *child;
int ch;
int j;
- while(node) {
+ while (node) {
for (j = 0; node->prefix[j]; j++) {
ch = node->prefix[j];
- if (ch != key[i+j]) {
+ if (ch != key[i + j]) {
index_mm_free_node(node);
return NULL;
}
i += j;
if (key[i] == '\0') {
- value = node->values.len > 0
- ? strdup(node->values.values[0].value)
- : NULL;
+ value = node->values.len > 0 ?
+ strdup(node->values.values[0].value) :
+ NULL;
index_mm_free_node(node);
return value;
*/
char *index_mm_search(struct index_mm *idx, const char *key)
{
-// FIXME: return value by reference instead of strdup
+ // FIXME: return value by reference instead of strdup
struct index_mm_node *root;
char *value;
/* Level 4: add all the values from a matching node */
static void index_mm_searchwild_allvalues(struct index_mm_node *node,
- struct index_value **out)
+ struct index_value **out)
{
struct index_mm_value *itr, *itr_end;
* Level 3: traverse a sub-keyspace which starts with a wildcard,
* looking for matches.
*/
-static void index_mm_searchwild_all(struct index_mm_node *node, int j,
- struct strbuf *buf,
- const char *subkey,
- struct index_value **out)
+static void index_mm_searchwild_all(struct index_mm_node *node, int j, struct strbuf *buf,
+ const char *subkey, struct index_value **out)
{
size_t pushed = 0;
int ch;
}
/* Level 2: descend the tree (until we hit a wildcard) */
-static void index_mm_searchwild_node(struct index_mm_node *node,
- struct strbuf *buf,
- const char *key, int i,
- struct index_value **out)
+static void index_mm_searchwild_node(struct index_mm_node *node, struct strbuf *buf,
+ const char *key, int i, struct index_value **out)
{
struct index_mm_node *child;
int j;
int ch;
- while(node) {
+ while (node) {
for (j = 0; node->prefix[j]; j++) {
ch = node->prefix[j];
if (ch == '*' || ch == '?' || ch == '[') {
- index_mm_searchwild_all(node, j, buf,
- &key[i+j], out);
+ index_mm_searchwild_all(node, j, buf, &key[i + j], out);
return;
}
- if (ch != key[i+j]) {
+ if (ch != key[i + j]) {
index_mm_free_node(node);
return;
}
#ifdef ENABLE_XZ
int kmod_file_load_xz(struct kmod_file *file);
#else
-static inline int kmod_file_load_xz(struct kmod_file *file) { return -ENOSYS; }
+static inline int kmod_file_load_xz(struct kmod_file *file)
+{
+ return -ENOSYS;
+}
#endif
#ifdef ENABLE_ZLIB
int kmod_file_load_zlib(struct kmod_file *file);
#else
-static inline int kmod_file_load_zlib(struct kmod_file *file) { return -ENOSYS; }
+static inline int kmod_file_load_zlib(struct kmod_file *file)
+{
+ return -ENOSYS;
+}
#endif
#ifdef ENABLE_ZSTD
int kmod_file_load_zstd(struct kmod_file *file);
#else
-static inline int kmod_file_load_zstd(struct kmod_file *file) { return -ENOSYS; }
+static inline int kmod_file_load_zstd(struct kmod_file *file)
+{
+ return -ENOSYS;
+}
#endif
#include "libkmod.h"
-static _always_inline_ _printf_format_(2, 3) void
- kmod_log_null(const 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__, __func__, ## arg);\
+static _always_inline_ _printf_format_(2, 3) void kmod_log_null(const 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__, __func__, ##arg); \
} while (0)
#ifdef ENABLE_LOGGING
-# ifdef ENABLE_DEBUG
-# define DBG(ctx, arg...) kmod_log_cond(ctx, LOG_DEBUG, ## arg)
-# else
-# define DBG(ctx, arg...) kmod_log_null(ctx, ## arg)
-# endif
-# define NOTICE(ctx, arg...) kmod_log_cond(ctx, LOG_NOTICE, ## arg)
-# define INFO(ctx, arg...) kmod_log_cond(ctx, LOG_INFO, ## arg)
-# define ERR(ctx, arg...) kmod_log_cond(ctx, LOG_ERR, ## arg)
+#ifdef ENABLE_DEBUG
+#define DBG(ctx, arg...) kmod_log_cond(ctx, LOG_DEBUG, ##arg)
+#else
+#define DBG(ctx, arg...) kmod_log_null(ctx, ##arg)
+#endif
+#define NOTICE(ctx, arg...) kmod_log_cond(ctx, LOG_NOTICE, ##arg)
+#define INFO(ctx, arg...) kmod_log_cond(ctx, LOG_INFO, ##arg)
+#define ERR(ctx, arg...) kmod_log_cond(ctx, LOG_ERR, ##arg)
#else
-# define DBG(ctx, arg...) kmod_log_null(ctx, ## arg)
-# define NOTICE(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)
+#define DBG(ctx, arg...) kmod_log_null(ctx, ##arg)
+#define NOTICE(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)
#endif
-#define KMOD_EXPORT __attribute__ ((visibility("default")))
+#define KMOD_EXPORT __attribute__((visibility("default")))
#define KCMD_LINE_SIZE 4096
#endif
_printf_format_(6, 7) _nonnull_(1, 3, 5) void kmod_log(const struct kmod_ctx *ctx,
- int priority, const char *file, int line, const char *fn,
- const char *format, ...);
+ int priority, const char *file,
+ int line, const char *fn,
+ const char *format, ...);
struct list_node {
struct list_node *next, *prev;
return node;
}
-static inline void list_node_append(struct list_node *list,
- struct list_node *node)
+static inline void list_node_append(struct list_node *list, struct list_node *node)
{
if (list == NULL) {
list_node_init(node);
return node->next;
}
-static inline void list_node_insert_after(struct list_node *list,
- struct list_node *node)
+static inline void list_node_insert_after(struct list_node *list, struct list_node *node)
{
if (list == NULL) {
list_node_init(node);
list->next = node;
}
-static inline void list_node_insert_before(struct list_node *list,
- struct list_node *node)
+static inline void list_node_insert_before(struct list_node *list, struct list_node *node)
{
if (list == NULL) {
list_node_init(node);
list->prev = node;
}
-static inline void list_node_append_list(struct list_node *list1,
- struct list_node *list2)
+static inline void list_node_append_list(struct list_node *list1, struct list_node *list2)
{
struct list_node *list1_last;
return list ? list : new;
}
-struct kmod_list *kmod_list_insert_after(struct kmod_list *list,
- const void *data)
+struct kmod_list *kmod_list_insert_after(struct kmod_list *list, const void *data)
{
struct kmod_list *new;
return list;
}
-struct kmod_list *kmod_list_insert_before(struct kmod_list *list,
- const void *data)
+struct kmod_list *kmod_list_insert_before(struct kmod_list *list, const void *data)
{
struct kmod_list *new;
return new;
}
-struct kmod_list *kmod_list_append_list(struct kmod_list *list1,
- struct kmod_list *list2)
+struct kmod_list *kmod_list_append_list(struct kmod_list *list1, struct kmod_list *list2)
{
if (list1 == NULL)
return list2;
return container_of(node, struct kmod_list, node);
}
-struct kmod_list *kmod_list_remove_data(struct kmod_list *list,
- const void *data)
+struct kmod_list *kmod_list_remove_data(struct kmod_list *list, const void *data)
{
struct kmod_list *itr;
struct list_node *node;
* n must be greater to or equal the number of elements (we don't check the
* condition)
*/
-struct kmod_list *kmod_list_remove_n_latest(struct kmod_list *list,
- unsigned int n)
+struct kmod_list *kmod_list_remove_n_latest(struct kmod_list *list, unsigned int n)
{
struct kmod_list *l = list;
unsigned int i;
}
KMOD_EXPORT struct kmod_list *kmod_list_prev(const struct kmod_list *list,
- const struct kmod_list *curr)
+ const struct kmod_list *curr)
{
if (list == NULL || curr == NULL)
return NULL;
}
KMOD_EXPORT struct kmod_list *kmod_list_next(const struct kmod_list *list,
- const struct kmod_list *curr)
+ const struct kmod_list *curr)
{
if (list == NULL || curr == NULL)
return NULL;
#include "libkmod-internal.h"
enum kmod_module_builtin {
- KMOD_MODULE_BUILTIN_UNKNOWN,
- KMOD_MODULE_BUILTIN_NO,
- KMOD_MODULE_BUILTIN_YES,
+ KMOD_MODULE_BUILTIN_UNKNOWN,
+ KMOD_MODULE_BUILTIN_NO,
+ KMOD_MODULE_BUILTIN_YES,
};
struct kmod_module {
char *path;
struct kmod_list *dep;
char *options;
- const char *install_commands; /* owned by kmod_config */
- const char *remove_commands; /* owned by kmod_config */
+ const char *install_commands; /* owned by kmod_config */
+ const char *remove_commands; /* owned by kmod_config */
char *alias; /* only set if this module was created from an alias */
struct kmod_file *file;
int n_dep;
bool required : 1;
};
-static inline const char *path_join(const char *path, size_t prefixlen,
- char buf[PATH_MAX])
+static inline const char *path_join(const char *path, size_t prefixlen, char buf[PATH_MAX])
{
size_t pathlen;
{
int state = kmod_module_get_initstate(mod);
- if (state == KMOD_MODULE_LIVE ||
- state == KMOD_MODULE_BUILTIN)
+ if (state == KMOD_MODULE_LIVE || state == KMOD_MODULE_BUILTIN)
return true;
return false;
p++;
for (p = strtok_r(p, " \t", &saveptr); p != NULL;
- p = strtok_r(NULL, " \t", &saveptr)) {
+ p = strtok_r(NULL, " \t", &saveptr)) {
struct kmod_module *depmod = NULL;
const char *path;
path = path_join(p, dirnamelen, buf);
if (path == NULL) {
- ERR(ctx, "could not join path '%s' and '%s'.\n",
- dirname, p);
+ ERR(ctx, "could not join path '%s' and '%s'.\n", dirname, p);
goto fail;
}
err = kmod_module_new_from_path(ctx, path, &depmod);
if (err < 0) {
- ERR(ctx, "ctx=%p path=%s error=%s\n",
- ctx, path, strerror(-err));
+ ERR(ctx, "ctx=%p path=%s error=%s\n", ctx, path, strerror(-err));
goto fail;
}
void kmod_module_set_builtin(struct kmod_module *mod, bool builtin)
{
- mod->builtin =
- builtin ? KMOD_MODULE_BUILTIN_YES : KMOD_MODULE_BUILTIN_NO;
+ mod->builtin = builtin ? KMOD_MODULE_BUILTIN_YES : KMOD_MODULE_BUILTIN_NO;
}
void kmod_module_set_required(struct kmod_module *mod, bool required)
bool kmod_module_is_builtin(struct kmod_module *mod)
{
if (mod->builtin == KMOD_MODULE_BUILTIN_UNKNOWN) {
- kmod_module_set_builtin(mod,
- kmod_lookup_alias_is_builtin(mod->ctx, mod->name));
+ kmod_module_set_builtin(mod, kmod_lookup_alias_is_builtin(mod->ctx,
+ mod->name));
}
return mod->builtin == KMOD_MODULE_BUILTIN_YES;
*
* @key is "name\alias" or "name" (in which case alias == NULL)
*/
-static int kmod_module_new(struct kmod_ctx *ctx, const char *key,
- const char *name, size_t namelen,
- const char *alias, size_t aliaslen,
- struct kmod_module **mod)
+static int kmod_module_new(struct kmod_ctx *ctx, const char *key, const char *name,
+ size_t namelen, const char *alias, size_t aliaslen,
+ struct kmod_module **mod)
{
struct kmod_module *m;
size_t keylen;
return 0;
}
-KMOD_EXPORT int kmod_module_new_from_name(struct kmod_ctx *ctx,
- const char *name,
- struct kmod_module **mod)
+KMOD_EXPORT int kmod_module_new_from_name(struct kmod_ctx *ctx, const char *name,
+ struct kmod_module **mod)
{
size_t namelen;
char name_norm[PATH_MAX];
return kmod_module_new(ctx, name_norm, name_norm, namelen, NULL, 0, mod);
}
-int kmod_module_new_from_alias(struct kmod_ctx *ctx, const char *alias,
- const char *name, struct kmod_module **mod)
+int kmod_module_new_from_alias(struct kmod_ctx *ctx, const char *alias, const char *name,
+ struct kmod_module **mod)
{
int err;
char key[PATH_MAX];
return 0;
}
-KMOD_EXPORT int kmod_module_new_from_path(struct kmod_ctx *ctx,
- const char *path,
- struct kmod_module **mod)
+KMOD_EXPORT int kmod_module_new_from_path(struct kmod_ctx *ctx, const char *path,
+ struct kmod_module **mod)
{
struct kmod_module *m;
int err;
else if (streq(m->path, abspath))
free(abspath);
else {
- ERR(ctx, "kmod_module '%s' already exists with different path: new-path='%s' old-path='%s'\n",
- name, abspath, m->path);
+ ERR(ctx,
+ "kmod_module '%s' already exists with different path: new-path='%s' old-path='%s'\n",
+ name, abspath, m->path);
free(abspath);
return -EEXIST;
}
return mod;
}
-typedef _nonnull_all_ int (*lookup_func)(struct kmod_ctx *ctx, const char *name, struct kmod_list **list);
+typedef _nonnull_all_ int (*lookup_func)(struct kmod_ctx *ctx, const char *name,
+ struct kmod_list **list);
static int __kmod_module_new_from_lookup(struct kmod_ctx *ctx, const lookup_func lookup[],
size_t lookup_count, const char *s,
return 0;
}
-KMOD_EXPORT int kmod_module_new_from_lookup(struct kmod_ctx *ctx,
- const char *given_alias,
- struct kmod_list **list)
+KMOD_EXPORT int kmod_module_new_from_lookup(struct kmod_ctx *ctx, const char *given_alias,
+ struct kmod_list **list)
{
static const lookup_func lookup[] = {
kmod_lookup_alias_from_config,
DBG(ctx, "input alias=%s, normalized=%s\n", given_alias, alias);
- err = __kmod_module_new_from_lookup(ctx, lookup, ARRAY_SIZE(lookup),
- alias, list);
+ err = __kmod_module_new_from_lookup(ctx, lookup, ARRAY_SIZE(lookup), alias, list);
DBG(ctx, "lookup=%s found=%d\n", alias, err >= 0 && *list);
DBG(ctx, "input modname=%s, normalized=%s\n", modname, name_norm);
- err = __kmod_module_new_from_lookup(ctx, lookup, ARRAY_SIZE(lookup),
- name_norm, &list);
+ err = __kmod_module_new_from_lookup(ctx, lookup, ARRAY_SIZE(lookup), name_norm,
+ &list);
DBG(ctx, "lookup=%s found=%d\n", name_norm, err >= 0 && list);
}
KMOD_EXPORT int kmod_module_get_filtered_blacklist(const struct kmod_ctx *ctx,
- const struct kmod_list *input,
- struct kmod_list **output)
+ const struct kmod_list *input,
+ struct kmod_list **output)
{
return kmod_module_apply_filter(ctx, KMOD_FILTER_BLACKLIST, input, output);
}
if (line == NULL)
return NULL;
- kmod_module_parse_depline((struct kmod_module *) mod, line);
+ kmod_module_parse_depline((struct kmod_module *)mod, line);
free(line);
return mod->path;
}
-
extern long delete_module(const char *name, unsigned int flags);
-KMOD_EXPORT int kmod_module_remove_module(struct kmod_module *mod,
- unsigned int flags)
+KMOD_EXPORT int kmod_module_remove_module(struct kmod_module *mod, unsigned int flags)
{
unsigned int libkmod_flags = flags & 0xff;
extern long init_module(const void *mem, unsigned long len, const char *args);
-static int do_finit_module(struct kmod_module *mod, unsigned int flags,
- const char *args)
+static int do_finit_module(struct kmod_module *mod, unsigned int flags, const char *args)
{
enum kmod_file_compression_type compression, kernel_compression;
unsigned int kernel_flags = 0;
return err;
}
-static int do_init_module(struct kmod_module *mod, unsigned int flags,
- const char *args)
+static int do_init_module(struct kmod_module *mod, unsigned int flags, const char *args)
{
struct kmod_elf *elf;
const void *mem;
if (flags & KMOD_INSERT_FORCE_MODVERSION) {
err = kmod_elf_strip_section(elf, "__versions");
if (err < 0)
- INFO(mod->ctx, "Failed to strip modversion: %s\n", strerror(-err));
+ INFO(mod->ctx, "Failed to strip modversion: %s\n",
+ strerror(-err));
}
if (flags & KMOD_INSERT_FORCE_VERMAGIC) {
err = kmod_elf_strip_vermagic(elf);
if (err < 0)
- INFO(mod->ctx, "Failed to strip vermagic: %s\n", strerror(-err));
+ INFO(mod->ctx, "Failed to strip vermagic: %s\n",
+ strerror(-err));
}
mem = kmod_elf_get_memory(elf);
return err;
}
-KMOD_EXPORT int kmod_module_insert_module(struct kmod_module *mod,
- unsigned int flags,
- const char *options)
+KMOD_EXPORT int kmod_module_insert_module(struct kmod_module *mod, unsigned int flags,
+ const char *options)
{
int err;
const char *path;
err = do_init_module(mod, flags, args);
if (err < 0)
- INFO(mod->ctx, "Failed to insert module '%s': %s\n",
- path, strerror(-err));
+ INFO(mod->ctx, "Failed to insert module '%s': %s\n", path, strerror(-err));
return err;
}
}
KMOD_EXPORT int kmod_module_apply_filter(const struct kmod_ctx *ctx,
- enum kmod_filter filter_type,
- const struct kmod_list *input,
- struct kmod_list **output)
+ enum kmod_filter filter_type,
+ const struct kmod_list *input,
+ struct kmod_list **output)
{
const struct kmod_list *li;
struct kmod_module *mod = li->data;
struct kmod_list *node;
- if ((filter_type & KMOD_FILTER_BLACKLIST) &&
- module_is_blacklisted(mod))
+ if ((filter_type & KMOD_FILTER_BLACKLIST) && module_is_blacklisted(mod))
continue;
- if ((filter_type & KMOD_FILTER_BUILTIN)
- && kmod_module_is_builtin(mod))
+ if ((filter_type & KMOD_FILTER_BUILTIN) && kmod_module_is_builtin(mod))
continue;
node = kmod_list_append(*output, mod);
return -ENOMEM;
}
-static int command_do(struct kmod_module *mod, const char *type,
- const char *cmd)
+static int command_do(struct kmod_module *mod, const char *type, const char *cmd)
{
const char *modname = kmod_module_get_name(mod);
int err;
unsetenv("MODPROBE_MODULE");
if (err == -1) {
- ERR(mod->ctx, "Could not run %s command '%s' for module %s: %m\n",
- type, cmd, modname);
+ ERR(mod->ctx, "Could not run %s command '%s' for module %s: %m\n", type,
+ cmd, modname);
return -EINVAL;
}
void *data;
};
-static int module_do_install_commands(struct kmod_module *mod,
- const char *options,
- struct probe_insert_cb *cb)
+static int module_do_install_commands(struct kmod_module *mod, const char *options,
+ struct probe_insert_cb *cb)
{
const char *command = kmod_module_get_install_commands(mod);
char *p;
return r;
}
-static int __kmod_module_get_probe_list(struct kmod_module *mod,
- bool required,
- bool ignorecmd,
- struct kmod_list **list);
+static int __kmod_module_get_probe_list(struct kmod_module *mod, bool required,
+ bool ignorecmd, struct kmod_list **list);
/* re-entrant */
-static int __kmod_module_fill_softdep(struct kmod_module *mod,
- struct kmod_list **list)
+static int __kmod_module_fill_softdep(struct kmod_module *mod, struct kmod_list **list)
{
struct kmod_list *pre = NULL, *post = NULL, *l;
int err;
err = kmod_module_get_softdeps(mod, &pre, &post);
if (err < 0) {
- ERR(mod->ctx, "could not get softdep: %s\n",
- strerror(-err));
+ ERR(mod->ctx, "could not get softdep: %s\n", strerror(-err));
goto fail;
}
}
/* re-entrant */
-static int __kmod_module_get_probe_list(struct kmod_module *mod,
- bool required,
- bool ignorecmd,
- struct kmod_list **list)
+static int __kmod_module_get_probe_list(struct kmod_module *mod, bool required,
+ bool ignorecmd, struct kmod_list **list)
{
struct kmod_list *dep, *l;
int err = 0;
if (mod->visited) {
- DBG(mod->ctx, "Ignore module '%s': already visited\n",
- mod->name);
+ DBG(mod->ctx, "Ignore module '%s': already visited\n", mod->name);
return 0;
}
mod->visited = true;
return err;
}
-static int kmod_module_get_probe_list(struct kmod_module *mod,
- bool ignorecmd,
- struct kmod_list **list)
+static int kmod_module_get_probe_list(struct kmod_module *mod, bool ignorecmd,
+ struct kmod_list **list)
{
int err;
return err;
}
-KMOD_EXPORT int kmod_module_probe_insert_module(struct kmod_module *mod,
- unsigned int flags, const char *extra_options,
- int (*run_install)(struct kmod_module *m,
- const char *cmd, void *data),
- const void *data,
- void (*print_action)(struct kmod_module *m,
- bool install,
- const char *options))
+KMOD_EXPORT int kmod_module_probe_insert_module(
+ struct kmod_module *mod, unsigned int flags, const char *extra_options,
+ int (*run_install)(struct kmod_module *m, const char *cmd, void *data),
+ const void *data,
+ void (*print_action)(struct kmod_module *m, bool install, const char *options))
{
struct kmod_list *list = NULL, *l;
struct probe_insert_cb cb;
if (mod == NULL)
return -ENOENT;
- if (!(flags & KMOD_PROBE_IGNORE_LOADED)
- && module_is_inkernel(mod)) {
+ if (!(flags & KMOD_PROBE_IGNORE_LOADED) && module_is_inkernel(mod)) {
if (flags & KMOD_PROBE_FAIL_ON_LOADED)
return -EEXIST;
else
return KMOD_PROBE_APPLY_BLACKLIST;
}
- err = kmod_module_get_probe_list(mod,
- !!(flags & KMOD_PROBE_IGNORE_COMMAND), &list);
+ err = kmod_module_get_probe_list(mod, !!(flags & KMOD_PROBE_IGNORE_COMMAND),
+ &list);
if (err < 0)
return err;
if (flags & KMOD_PROBE_APPLY_BLACKLIST_ALL) {
struct kmod_list *filtered = NULL;
- err = kmod_module_apply_filter(mod->ctx,
- KMOD_FILTER_BLACKLIST, list, &filtered);
+ err = kmod_module_apply_filter(mod->ctx, KMOD_FILTER_BLACKLIST, list,
+ &filtered);
if (err < 0)
return err;
}
cb.run_install = run_install;
- cb.data = (void *) data;
+ cb.data = (void *)data;
kmod_list_foreach(l, list) {
struct kmod_module *m = l->data;
const char *cmd = kmod_module_get_install_commands(m);
char *options;
- if (!(flags & KMOD_PROBE_IGNORE_LOADED)
- && module_is_inkernel(m)) {
- DBG(mod->ctx, "Ignoring module '%s': already loaded\n",
- m->name);
+ if (!(flags & KMOD_PROBE_IGNORE_LOADED) && module_is_inkernel(m)) {
+ DBG(mod->ctx, "Ignoring module '%s': already loaded\n", m->name);
err = -EEXIST;
goto finish_module;
}
- options = module_options_concat(moptions,
- m == mod ? extra_options : NULL);
+ options =
+ module_options_concat(moptions, m == mod ? extra_options : NULL);
if (cmd != NULL && !m->ignorecmd) {
if (print_action != NULL)
print_action(m, true, options ?: "");
if (!(flags & KMOD_PROBE_DRY_RUN))
- err = module_do_install_commands(m, options,
- &cb);
+ err = module_do_install_commands(m, options, &cb);
} else {
if (print_action != NULL)
print_action(m, false, options ?: "");
if (!(flags & KMOD_PROBE_DRY_RUN))
- err = kmod_module_insert_module(m, flags,
- options);
+ err = kmod_module_insert_module(m, flags, options);
}
free(options);
* been loaded between the check and the moment we try to
* insert it.
*/
- if (err == -EEXIST && m == mod &&
- (flags & KMOD_PROBE_FAIL_ON_LOADED))
+ if (err == -EEXIST && m == mod && (flags & KMOD_PROBE_FAIL_ON_LOADED))
break;
/*
size_t len;
void *tmp;
- DBG(mod->ctx, "modname=%s mod->name=%s mod->alias=%s\n", modname, mod->name, mod->alias);
- if (!(streq(modname, mod->name) || (mod->alias != NULL &&
- streq(modname, mod->alias))))
+ DBG(mod->ctx, "modname=%s mod->name=%s mod->alias=%s\n", modname,
+ mod->name, mod->alias);
+ if (!(streq(modname, mod->name) ||
+ (mod->alias != NULL && streq(modname, mod->alias))))
continue;
- DBG(mod->ctx, "passed = modname=%s mod->name=%s mod->alias=%s\n", modname, mod->name, mod->alias);
+ DBG(mod->ctx, "passed = modname=%s mod->name=%s mod->alias=%s\n",
+ modname, mod->name, mod->alias);
str = kmod_option_get_options(l);
len = strlen(str);
if (len < 1)
mod->install_commands = cmd;
}
-static struct kmod_list *lookup_dep(struct kmod_ctx *ctx, const char * const * array, unsigned int count)
+static struct kmod_list *lookup_dep(struct kmod_ctx *ctx, const char *const *array,
+ unsigned int count)
{
struct kmod_list *ret = NULL;
unsigned i;
err = kmod_module_new_from_lookup(ctx, depname, &lst);
if (err < 0) {
- ERR(ctx, "failed to lookup dependency '%s', continuing anyway.\n", depname);
+ ERR(ctx, "failed to lookup dependency '%s', continuing anyway.\n",
+ depname);
continue;
} else if (lst != NULL)
ret = kmod_list_append_list(ret, lst);
}
KMOD_EXPORT int kmod_module_get_softdeps(const struct kmod_module *mod,
- struct kmod_list **pre,
- struct kmod_list **post)
+ struct kmod_list **pre, struct kmod_list **post)
{
const struct kmod_list *l;
const struct kmod_config *config;
kmod_list_foreach(l, config->softdeps) {
const char *modname = kmod_softdep_get_name(l);
- const char * const *array;
+ const char *const *array;
unsigned count;
if (fnmatch(modname, mod->name, 0) != 0)
}
KMOD_EXPORT int kmod_module_get_weakdeps(const struct kmod_module *mod,
- struct kmod_list **weak)
+ struct kmod_list **weak)
{
const struct kmod_list *l;
const struct kmod_config *config;
kmod_list_foreach(l, config->weakdeps) {
const char *modname = kmod_weakdep_get_name(l);
- const char * const *array;
+ const char *const *array;
unsigned count;
if (fnmatch(modname, mod->name, 0) != 0)
mod->remove_commands = cmd;
}
-KMOD_EXPORT int kmod_module_new_from_loaded(struct kmod_ctx *ctx,
- struct kmod_list **list)
+KMOD_EXPORT int kmod_module_new_from_loaded(struct kmod_ctx *ctx, struct kmod_list **list)
{
struct kmod_list *l = NULL;
FILE *fp;
err = kmod_module_new_from_name(ctx, name, &m);
if (err < 0) {
- ERR(ctx, "could not get module from name '%s': %s\n",
- name, strerror(-err));
+ ERR(ctx, "could not get module from name '%s': %s\n", name,
+ strerror(-err));
goto eat_line;
}
if (kmod_module_is_builtin((struct kmod_module *)mod))
return KMOD_MODULE_BUILTIN;
- pathlen = snprintf(path, sizeof(path),
- "/sys/module/%s/initstate", mod->name);
+ pathlen = snprintf(path, sizeof(path), "/sys/module/%s/initstate", mod->name);
if (pathlen >= (int)sizeof(path)) {
/* Too long path was truncated */
return -ENAMETOOLONG;
}
- fd = open(path, O_RDONLY|O_CLOEXEC);
+ fd = open(path, O_RDONLY | O_CLOEXEC);
if (fd < 0) {
err = -errno;
- DBG(mod->ctx, "could not open '%s': %s\n",
- path, strerror(-err));
+ DBG(mod->ctx, "could not open '%s': %s\n", path, strerror(-err));
if (pathlen > (int)sizeof("/initstate") - 1) {
struct stat st;
return KMOD_MODULE_COMING;
}
- DBG(mod->ctx, "could not open '%s': %s\n",
- path, strerror(-err));
+ DBG(mod->ctx, "could not open '%s': %s\n", path, strerror(-err));
return err;
}
err = read_str_safe(fd, buf, sizeof(buf));
close(fd);
if (err < 0) {
- ERR(mod->ctx, "could not read from '%s': %s\n",
- path, strerror(-err));
+ ERR(mod->ctx, "could not read from '%s': %s\n", path, strerror(-err));
return err;
}
* loaded.
*/
snprintf(line, sizeof(line), "/sys/module/%s", mod->name);
- dfd = open(line, O_RDONLY|O_CLOEXEC);
+ dfd = open(line, O_RDONLY | O_CLOEXEC);
if (dfd < 0)
return -errno;
/* available as of linux 3.3.x */
- cfd = openat(dfd, "coresize", O_RDONLY|O_CLOEXEC);
+ cfd = openat(dfd, "coresize", O_RDONLY | O_CLOEXEC);
if (cfd >= 0) {
if (read_str_long(cfd, &size, 10) < 0)
ERR(mod->ctx, "failed to read coresize from %s\n", line);
fp = fopen("/proc/modules", "re");
if (fp == NULL) {
int err = -errno;
- ERR(mod->ctx,
- "could not open /proc/modules: %s\n", strerror(errno));
+ ERR(mod->ctx, "could not open /proc/modules: %s\n", strerror(errno));
close(dfd);
return err;
}
tok = strtok_r(NULL, " \t", &saveptr);
if (tok == NULL) {
- ERR(mod->ctx,
- "invalid line format at /proc/modules:%d\n", lineno);
+ ERR(mod->ctx, "invalid line format at /proc/modules:%d\n", lineno);
break;
}
value = strtol(tok, &endptr, 10);
if (endptr == tok || *endptr != '\0') {
- ERR(mod->ctx,
- "invalid line format at /proc/modules:%d\n", lineno);
+ ERR(mod->ctx, "invalid line format at /proc/modules:%d\n", lineno);
break;
}
return -ENOENT;
snprintf(path, sizeof(path), "/sys/module/%s/refcnt", mod->name);
- fd = open(path, O_RDONLY|O_CLOEXEC);
+ fd = open(path, O_RDONLY | O_CLOEXEC);
if (fd < 0) {
err = -errno;
- DBG(mod->ctx, "could not open '%s': %s\n",
- path, strerror(errno));
+ DBG(mod->ctx, "could not open '%s': %s\n", path, strerror(errno));
return err;
}
err = read_str_long(fd, &refcnt, 10);
close(fd);
if (err < 0) {
- ERR(mod->ctx, "could not read integer from '%s': '%s'\n",
- path, strerror(-err));
+ ERR(mod->ctx, "could not read integer from '%s': '%s'\n", path,
+ strerror(-err));
return err;
}
d = opendir(dname);
if (d == NULL) {
- ERR(mod->ctx, "could not open '%s': %s\n",
- dname, strerror(errno));
+ ERR(mod->ctx, "could not open '%s': %s\n", dname, strerror(errno));
return NULL;
}
continue;
}
- err = kmod_module_new_from_name(mod->ctx, dent->d_name,
- &holder);
+ err = kmod_module_new_from_name(mod->ctx, dent->d_name, &holder);
if (err < 0) {
ERR(mod->ctx, "could not create module for '%s': %s\n",
- dent->d_name, strerror(-err));
+ dent->d_name, strerror(-err));
goto fail;
}
d = opendir(dname);
if (d == NULL) {
- ERR(mod->ctx, "could not open '%s': %s\n",
- dname, strerror(errno));
+ ERR(mod->ctx, "could not open '%s': %s\n", dname, strerror(errno));
return NULL;
}
continue;
}
- fd = openat(dfd, dent->d_name, O_RDONLY|O_CLOEXEC);
+ fd = openat(dfd, dent->d_name, O_RDONLY | O_CLOEXEC);
if (fd < 0) {
- ERR(mod->ctx, "could not open '%s/%s': %m\n",
- dname, dent->d_name);
+ ERR(mod->ctx, "could not open '%s/%s': %m\n", dname, dent->d_name);
goto fail;
}
err = read_str_ulong(fd, &address, 16);
close(fd);
if (err < 0) {
- ERR(mod->ctx, "could not read long from '%s/%s': %m\n",
- dname, dent->d_name);
+ ERR(mod->ctx, "could not read long from '%s/%s': %m\n", dname,
+ dent->d_name);
goto fail;
}
return NULL;
}
- ((struct kmod_module *)mod)->file = kmod_file_open(mod->ctx,
- path);
+ ((struct kmod_module *)mod)->file = kmod_file_open(mod->ctx, path);
if (mod->file == NULL)
return NULL;
}
char value[];
};
-static struct kmod_module_info *kmod_module_info_new(const char *key, size_t keylen, const char *value, size_t valuelen)
+static struct kmod_module_info *kmod_module_info_new(const char *key, size_t keylen,
+ const char *value, size_t valuelen)
{
struct kmod_module_info *info;
if (info == NULL)
return NULL;
- info->key = (char *)info + sizeof(struct kmod_module_info)
- + valuelen + 1;
+ info->key = (char *)info + sizeof(struct kmod_module_info) + valuelen + 1;
memcpy(info->key, key, keylen);
info->key[keylen] = '\0';
memcpy(info->value, value, valuelen);
free(info);
}
-static struct kmod_list *kmod_module_info_append(struct kmod_list **list, const char *key, size_t keylen, const char *value, size_t valuelen)
+static struct kmod_list *kmod_module_info_append(struct kmod_list **list, const char *key,
+ size_t keylen, const char *value,
+ size_t valuelen)
{
struct kmod_module_info *info;
struct kmod_list *n;
}
static struct kmod_list *kmod_module_info_append_hex(struct kmod_list **list,
- const char *key,
- size_t keylen,
- const char *value,
- size_t valuelen)
+ const char *key, size_t keylen,
+ const char *value, size_t valuelen)
{
char *hex;
struct kmod_list *n;
return NULL;
}
-KMOD_EXPORT int kmod_module_get_info(const struct kmod_module *mod, struct kmod_list **list)
+KMOD_EXPORT int kmod_module_get_info(const struct kmod_module *mod,
+ struct kmod_list **list)
{
struct kmod_elf *elf;
char **strings;
/* remove const: this can only change internal state */
if (kmod_module_is_builtin((struct kmod_module *)mod)) {
- count = kmod_builtin_get_modinfo(mod->ctx,
- kmod_module_get_name(mod),
- &strings);
+ count = kmod_builtin_get_modinfo(mod->ctx, kmod_module_get_name(mod),
+ &strings);
if (count < 0)
return count;
} else {
struct kmod_list *n;
n = kmod_module_info_append(list, "sig_id", strlen("sig_id"),
- sig_info.id_type, strlen(sig_info.id_type));
+ sig_info.id_type, strlen(sig_info.id_type));
if (n == NULL)
goto list_error;
count++;
n = kmod_module_info_append(list, "signer", strlen("signer"),
- sig_info.signer, sig_info.signer_len);
+ sig_info.signer, sig_info.signer_len);
if (n == NULL)
goto list_error;
count++;
-
n = kmod_module_info_append_hex(list, "sig_key", strlen("sig_key"),
- sig_info.key_id,
- sig_info.key_id_len);
+ sig_info.key_id, sig_info.key_id_len);
if (n == NULL)
goto list_error;
count++;
- n = kmod_module_info_append(list,
- "sig_hashalgo", strlen("sig_hashalgo"),
- sig_info.hash_algo, strlen(sig_info.hash_algo));
+ n = kmod_module_info_append(list, "sig_hashalgo", strlen("sig_hashalgo"),
+ sig_info.hash_algo,
+ strlen(sig_info.hash_algo));
if (n == NULL)
goto list_error;
count++;
* Omit sig_info.algo for now, as these
* are currently constant.
*/
- n = kmod_module_info_append_hex(list, "signature",
- strlen("signature"),
- sig_info.sig,
- sig_info.sig_len);
+ n = kmod_module_info_append_hex(list, "signature", strlen("signature"),
+ sig_info.sig, sig_info.sig_len);
if (n == NULL)
goto list_error;
count++;
-
}
ret = count;
char symbol[];
};
-static struct kmod_module_version *kmod_module_versions_new(uint64_t crc, const char *symbol)
+static struct kmod_module_version *kmod_module_versions_new(uint64_t crc,
+ const char *symbol)
{
struct kmod_module_version *mv;
size_t symbollen = strlen(symbol) + 1;
free(version);
}
-KMOD_EXPORT int kmod_module_get_versions(const struct kmod_module *mod, struct kmod_list **list)
+KMOD_EXPORT int kmod_module_get_versions(const struct kmod_module *mod,
+ struct kmod_list **list)
{
struct kmod_elf *elf;
struct kmod_modversion *versions;
free(symbol);
}
-KMOD_EXPORT int kmod_module_get_symbols(const struct kmod_module *mod, struct kmod_list **list)
+KMOD_EXPORT int kmod_module_get_symbols(const struct kmod_module *mod,
+ struct kmod_list **list)
{
struct kmod_elf *elf;
struct kmod_modversion *symbols;
return mv;
}
-static void kmod_module_dependency_symbol_free(struct kmod_module_dependency_symbol *dependency_symbol)
+static void kmod_module_dependency_symbol_free(
+ struct kmod_module_dependency_symbol *dependency_symbol)
{
free(dependency_symbol);
}
-KMOD_EXPORT int kmod_module_get_dependency_symbols(const struct kmod_module *mod, struct kmod_list **list)
+KMOD_EXPORT int kmod_module_get_dependency_symbols(const struct kmod_module *mod,
+ struct kmod_list **list)
{
struct kmod_elf *elf;
struct kmod_modversion *symbols;
struct kmod_module_dependency_symbol *mv;
struct kmod_list *n;
- mv = kmod_module_dependency_symbols_new(symbols[i].crc,
- symbols[i].bind,
+ mv = kmod_module_dependency_symbols_new(symbols[i].crc, symbols[i].bind,
symbols[i].symbol);
if (mv == NULL) {
ret = -errno;
};
static const char *const pkey_algo[PKEY_ALGO__LAST] = {
- [PKEY_ALGO_DSA] = "DSA",
- [PKEY_ALGO_RSA] = "RSA",
+ [PKEY_ALGO_DSA] = "DSA",
+ [PKEY_ALGO_RSA] = "RSA",
};
enum pkey_hash_algo {
};
enum pkey_id_type {
- PKEY_ID_PGP, /* OpenPGP generated key ID */
- PKEY_ID_X509, /* X.509 arbitrary subjectKeyIdentifier */
- PKEY_ID_PKCS7, /* Signature in PKCS#7 message */
+ PKEY_ID_PGP, /* OpenPGP generated key ID */
+ PKEY_ID_X509, /* X.509 arbitrary subjectKeyIdentifier */
+ PKEY_ID_PKCS7, /* Signature in PKCS#7 message */
PKEY_ID_TYPE__LAST,
};
const char *const pkey_id_type[PKEY_ID_TYPE__LAST] = {
- [PKEY_ID_PGP] = "PGP",
- [PKEY_ID_X509] = "X509",
- [PKEY_ID_PKCS7] = "PKCS#7",
+ [PKEY_ID_PGP] = "PGP",
+ [PKEY_ID_X509] = "X509",
+ [PKEY_ID_PKCS7] = "PKCS#7",
};
/*
* Module signature information block.
*/
struct module_signature {
- uint8_t algo; /* Public-key crypto algorithm [enum pkey_algo] */
- uint8_t hash; /* Digest algorithm [enum pkey_hash_algo] */
- uint8_t id_type; /* Key identifier type [enum pkey_id_type] */
- uint8_t signer_len; /* Length of signer's name */
- uint8_t key_id_len; /* Length of key identifier */
+ uint8_t algo; /* Public-key crypto algorithm [enum pkey_algo] */
+ uint8_t hash; /* Digest algorithm [enum pkey_hash_algo] */
+ uint8_t id_type; /* Key identifier type [enum pkey_id_type] */
+ uint8_t signer_len; /* Length of signer's name */
+ uint8_t key_id_len; /* Length of key identifier */
uint8_t __pad[3];
- uint32_t sig_len; /* Length of signature data (big endian) */
+ uint32_t sig_len; /* Length of signature data (big endian) */
};
static bool fill_default(const char *mem, off_t size,
return str;
}
-static bool fill_pkcs7(const char *mem, off_t size,
- const struct module_signature *modsig, size_t sig_len,
- struct kmod_signature_info *sig_info)
+static bool fill_pkcs7(const char *mem, off_t size, const struct module_signature *modsig,
+ size_t sig_len, struct kmod_signature_info *sig_info)
{
const char *pkcs7_raw;
PKCS7 *pkcs7;
- STACK_OF(PKCS7_SIGNER_INFO) *sis;
+ STACK_OF(PKCS7_SIGNER_INFO) * sis;
PKCS7_SIGNER_INFO *si;
PKCS7_ISSUER_AND_SERIAL *is;
X509_NAME *issuer;
#else /* ENABLE OPENSSL */
-static bool fill_pkcs7(const char *mem, off_t size,
- const struct module_signature *modsig, size_t sig_len,
- struct kmod_signature_info *sig_info)
+static bool fill_pkcs7(const char *mem, off_t size, const struct module_signature *modsig,
+ size_t sig_len, struct kmod_signature_info *sig_info)
{
sig_info->hash_algo = "unknown";
sig_info->id_type = pkey_id_type[modsig->id_type];
* [ SIG_MAGIC ]
*/
-bool kmod_module_signature_info(const struct kmod_file *file, struct kmod_signature_info *sig_info)
+bool kmod_module_signature_info(const struct kmod_file *file,
+ struct kmod_signature_info *sig_info)
{
const char *mem;
off_t size;
return false;
size -= sizeof(struct module_signature);
memcpy(&modsig, mem + size, sizeof(struct module_signature));
- if (modsig.algo >= PKEY_ALGO__LAST ||
- modsig.hash >= PKEY_HASH__LAST ||
- modsig.id_type >= PKEY_ID_TYPE__LAST)
+ if (modsig.algo >= PKEY_ALGO__LAST || modsig.hash >= PKEY_HASH__LAST ||
+ modsig.id_type >= PKEY_ID_TYPE__LAST)
return false;
sig_len = be32toh(modsig.sig_len);
if (sig_len == 0 ||
struct kmod_ctx {
int refcount;
int log_priority;
- void (*log_fn)(void *data,
- int priority, const char *file, int line,
- const char *fn, const char *format, va_list args);
+ void (*log_fn)(void *data, int priority, const char *file, int line,
+ const char *fn, const char *format, va_list args);
void *log_data;
const void *userdata;
char *dirname;
unsigned long long indexes_stamp[_KMOD_INDEX_MODULES_SIZE];
};
-void kmod_log(const struct kmod_ctx *ctx,
- int priority, const char *file, int line, const char *fn,
- const char *format, ...)
+void kmod_log(const struct kmod_ctx *ctx, int priority, const char *file, int line,
+ const char *fn, const char *format, ...)
{
va_list args;
va_end(args);
}
-_printf_format_(6, 0)
-static void log_filep(void *data,
- int priority, const char *file, int line,
- const char *fn, const char *format, va_list args)
+_printf_format_(6, 0) static void log_filep(void *data, int priority, const char *file,
+ int line, const char *fn, const char *format,
+ va_list args)
{
FILE *fp = data;
#ifdef ENABLE_DEBUG
int fd;
int err;
- fd = open(path, O_RDONLY|O_CLOEXEC);
+ fd = open(path, O_RDONLY | O_CLOEXEC);
if (fd < 0) {
/* Not having the file is not an error: kernel may be too old */
DBG(ctx, "could not open '%s' for reading: %m\n", path);
err = read_str_safe(fd, buf, sizeof(buf));
close(fd);
if (err < 0) {
- ERR(ctx, "could not read from '%s': %s\n",
- path, strerror(-err));
+ ERR(ctx, "could not read from '%s': %s\n", path, strerror(-err));
return KMOD_FILE_COMPRESSION_NONE;
}
return KMOD_FILE_COMPRESSION_NONE;
}
-KMOD_EXPORT struct kmod_ctx *kmod_new(const char *dirname,
- const char * const *config_paths)
+KMOD_EXPORT struct kmod_ctx *kmod_new(const char *dirname, const char *const *config_paths)
{
const char *env;
struct kmod_ctx *ctx;
}
KMOD_EXPORT void kmod_set_log_fn(struct kmod_ctx *ctx,
- void (*log_fn)(void *data,
- int priority, const char *file,
- int line, const char *fn,
+ void (*log_fn)(void *data, int priority,
+ const char *file, int line, const char *fn,
const char *format, va_list args),
- const void *data)
+ const void *data)
{
if (ctx == NULL)
return;
ctx->log_priority = priority;
}
-struct kmod_module *kmod_pool_get_module(struct kmod_ctx *ctx,
- const char *key)
+struct kmod_module *kmod_pool_get_module(struct kmod_ctx *ctx, const char *key)
{
struct kmod_module *mod;
return mod;
}
-void kmod_pool_add_module(struct kmod_ctx *ctx, struct kmod_module *mod,
- const char *key)
+void kmod_pool_add_module(struct kmod_ctx *ctx, struct kmod_module *mod, const char *key)
{
DBG(ctx, "add %p key='%s'\n", mod, key);
hash_add(ctx->modules_by_name, key, mod);
}
-void kmod_pool_del_module(struct kmod_ctx *ctx, struct kmod_module *mod,
- const char *key)
+void kmod_pool_del_module(struct kmod_ctx *ctx, struct kmod_module *mod, const char *key)
{
DBG(ctx, "del %p key='%s'\n", mod, key);
}
static int kmod_lookup_alias_from_alias_bin(struct kmod_ctx *ctx,
- enum kmod_index index_number,
- const char *name,
- struct kmod_list **list)
+ enum kmod_index index_number,
+ const char *name, struct kmod_list **list)
{
int err, nmatch = 0;
struct index_file *idx;
if (ctx->indexes[index_number] != NULL) {
DBG(ctx, "use mmapped index '%s' for name=%s\n",
- index_files[index_number].fn, name);
- realnames = index_mm_searchwild(ctx->indexes[index_number],
- name);
+ index_files[index_number].fn, name);
+ realnames = index_mm_searchwild(ctx->indexes[index_number], name);
} else {
char fn[PATH_MAX];
snprintf(fn, sizeof(fn), "%s/%s.bin", ctx->dirname,
- index_files[index_number].fn);
+ index_files[index_number].fn);
DBG(ctx, "file=%s name=%s\n", fn, name);
*list = kmod_list_remove_n_latest(*list, nmatch);
index_values_free(realnames);
return err;
-
}
int kmod_lookup_alias_from_symbols_file(struct kmod_ctx *ctx, const char *name,
- struct kmod_list **list)
+ struct kmod_list **list)
{
if (!strstartswith(name, "symbol:"))
return 0;
- return kmod_lookup_alias_from_alias_bin(ctx, KMOD_INDEX_MODULES_SYMBOL,
- name, list);
+ return kmod_lookup_alias_from_alias_bin(ctx, KMOD_INDEX_MODULES_SYMBOL, name,
+ list);
}
int kmod_lookup_alias_from_aliases_file(struct kmod_ctx *ctx, const char *name,
- struct kmod_list **list)
+ struct kmod_list **list)
{
- return kmod_lookup_alias_from_alias_bin(ctx, KMOD_INDEX_MODULES_ALIAS,
- name, list);
+ return kmod_lookup_alias_from_alias_bin(ctx, KMOD_INDEX_MODULES_ALIAS, name, list);
}
static char *lookup_builtin_file(struct kmod_ctx *ctx, const char *name)
if (ctx->indexes[KMOD_INDEX_MODULES_BUILTIN]) {
DBG(ctx, "use mmapped index '%s' modname=%s\n",
- index_files[KMOD_INDEX_MODULES_BUILTIN].fn,
- name);
- line = index_mm_search(ctx->indexes[KMOD_INDEX_MODULES_BUILTIN],
- name);
+ index_files[KMOD_INDEX_MODULES_BUILTIN].fn, name);
+ line = index_mm_search(ctx->indexes[KMOD_INDEX_MODULES_BUILTIN], name);
} else {
struct index_file *idx;
char fn[PATH_MAX];
snprintf(fn, sizeof(fn), "%s/%s.bin", ctx->dirname,
- index_files[KMOD_INDEX_MODULES_BUILTIN].fn);
+ index_files[KMOD_INDEX_MODULES_BUILTIN].fn);
DBG(ctx, "file=%s modname=%s\n", fn, name);
idx = index_file_open(fn);
return line;
}
-int kmod_lookup_alias_from_kernel_builtin_file(struct kmod_ctx *ctx,
- const char *name,
- struct kmod_list **list)
+int kmod_lookup_alias_from_kernel_builtin_file(struct kmod_ctx *ctx, const char *name,
+ struct kmod_list **list)
{
struct kmod_list *l;
int ret;
assert(*list == NULL);
- ret = kmod_lookup_alias_from_alias_bin(ctx,
- KMOD_INDEX_MODULES_BUILTIN_ALIAS,
+ ret = kmod_lookup_alias_from_alias_bin(ctx, KMOD_INDEX_MODULES_BUILTIN_ALIAS,
name, list);
kmod_list_foreach(l, *list) {
}
int kmod_lookup_alias_from_builtin_file(struct kmod_ctx *ctx, const char *name,
- struct kmod_list **list)
+ struct kmod_list **list)
{
char *line;
int err = 0;
err = kmod_module_new_from_name(ctx, name, &mod);
if (err < 0) {
- ERR(ctx, "Could not create module from name %s: %s\n",
- name, strerror(-err));
+ ERR(ctx, "Could not create module from name %s: %s\n", name,
+ strerror(-err));
goto finish;
}
if (ctx->indexes[KMOD_INDEX_MODULES_DEP]) {
DBG(ctx, "use mmapped index '%s' modname=%s\n",
- index_files[KMOD_INDEX_MODULES_DEP].fn, name);
- return index_mm_search(ctx->indexes[KMOD_INDEX_MODULES_DEP],
- name);
+ index_files[KMOD_INDEX_MODULES_DEP].fn, name);
+ return index_mm_search(ctx->indexes[KMOD_INDEX_MODULES_DEP], name);
}
snprintf(fn, sizeof(fn), "%s/%s.bin", ctx->dirname,
- index_files[KMOD_INDEX_MODULES_DEP].fn);
+ index_files[KMOD_INDEX_MODULES_DEP].fn);
DBG(ctx, "file=%s modname=%s\n", fn, name);
}
int kmod_lookup_alias_from_moddep_file(struct kmod_ctx *ctx, const char *name,
- struct kmod_list **list)
+ struct kmod_list **list)
{
char *line;
int n = 0;
n = kmod_module_new_from_name(ctx, name, &mod);
if (n < 0) {
- ERR(ctx, "Could not create module from name %s: %s\n",
- name, strerror(-n));
+ ERR(ctx, "Could not create module from name %s: %s\n", name,
+ strerror(-n));
goto finish;
}
}
int kmod_lookup_alias_from_config(struct kmod_ctx *ctx, const char *name,
- struct kmod_list **list)
+ struct kmod_list **list)
{
struct kmod_config *config = ctx->config;
struct kmod_list *l;
if (fnmatch(aliasname, name, 0) == 0) {
struct kmod_module *mod;
- err = kmod_module_new_from_alias(ctx, aliasname,
- modname, &mod);
+ err = kmod_module_new_from_alias(ctx, aliasname, modname, &mod);
if (err < 0) {
- ERR(ctx, "Could not create module for alias=%s modname=%s: %s\n",
+ ERR(ctx,
+ "Could not create module for alias=%s modname=%s: %s\n",
name, modname, strerror(-err));
goto fail;
}
}
int kmod_lookup_alias_from_commands(struct kmod_ctx *ctx, const char *name,
- struct kmod_list **list)
+ struct kmod_list **list)
{
struct kmod_config *config = ctx->config;
struct kmod_list *l, *node;
if (ctx->indexes[i] == NULL)
continue;
- snprintf(path, sizeof(path), "%s/%s.bin", ctx->dirname,
- index_files[i].fn);
+ snprintf(path, sizeof(path), "%s/%s.bin", ctx->dirname, index_files[i].fn);
if (is_cache_invalid(path, ctx->indexes_stamp[i]))
return KMOD_RESOURCES_MUST_RELOAD;
char path[PATH_MAX];
if (ctx->indexes[i] != NULL) {
- INFO(ctx, "Index %s already loaded\n",
- index_files[i].fn);
+ INFO(ctx, "Index %s already loaded\n", index_files[i].fn);
continue;
}
- snprintf(path, sizeof(path), "%s/%s.bin", ctx->dirname,
- index_files[i].fn);
- ret = index_mm_open(ctx, path, &ctx->indexes_stamp[i],
- &ctx->indexes[i]);
+ snprintf(path, sizeof(path), "%s/%s.bin", ctx->dirname, index_files[i].fn);
+ ret = index_mm_open(ctx, path, &ctx->indexes_stamp[i], &ctx->indexes[i]);
/*
* modules.builtin.alias are considered optional since it's
}
}
-KMOD_EXPORT int kmod_dump_index(struct kmod_ctx *ctx, enum kmod_index type,
- int fd)
+KMOD_EXPORT int kmod_dump_index(struct kmod_ctx *ctx, enum kmod_index type, int fd)
{
if (ctx == NULL)
return -ENOSYS;
if (ctx->indexes[type] != NULL) {
DBG(ctx, "use mmapped index '%s'\n", index_files[type].fn);
- index_mm_dump(ctx->indexes[type], fd,
- index_files[type].prefix);
+ index_mm_dump(ctx->indexes[type], fd, index_files[type].prefix);
} else {
char fn[PATH_MAX];
struct index_file *idx;
- snprintf(fn, sizeof(fn), "%s/%s.bin", ctx->dirname,
- index_files[type].fn);
+ snprintf(fn, sizeof(fn), "%s/%s.bin", ctx->dirname, index_files[type].fn);
DBG(ctx, "file=%s\n", fn);
*
* Since: 1
*/
-struct kmod_ctx *kmod_new(const char *dirname, const char * const *config_paths);
+struct kmod_ctx *kmod_new(const char *dirname, const char *const *config_paths);
/**
* kmod_ref:
*/
struct kmod_ctx *kmod_unref(struct kmod_ctx *ctx);
-
/**
* kmod_load_resources:
* @ctx: kmod library context
*/
int kmod_dump_index(struct kmod_ctx *ctx, enum kmod_index type, int fd);
-
/**
* kmod_set_log_priority:
* @ctx: kmod library context
* Since: 1
*/
void kmod_set_log_fn(struct kmod_ctx *ctx,
- void (*log_fn)(void *log_data,
- int priority, const char *file, int line,
- const char *fn, const char *format,
- va_list args),
- const void *data);
+ void (*log_fn)(void *log_data, int priority, const char *file,
+ int line, const char *fn, const char *format,
+ va_list args),
+ const void *data);
/**
* kmod_set_userdata:
*/
const char *kmod_get_dirname(const struct kmod_ctx *ctx);
-
-
/**
* SECTION:libkmod-list
* @short_description: general purpose list
* Iterate over the list @list.
*/
#define kmod_list_foreach(curr, list) \
- for (curr = list; \
- curr != NULL; \
- curr = kmod_list_next(list, curr))
+ for (curr = list; curr != NULL; curr = kmod_list_next(list, curr))
/**
* kmod_list_foreach_reverse:
* Iterate in reverse over the list @list.
*/
#define kmod_list_foreach_reverse(curr, list) \
- for (curr = kmod_list_last(list); \
- curr != NULL; \
- curr = kmod_list_prev(list, curr))
+ for (curr = kmod_list_last(list); curr != NULL; curr = kmod_list_prev(list, curr))
/**
* kmod_list_last:
* Since: 1
*/
struct kmod_list *kmod_list_next(const struct kmod_list *list,
- const struct kmod_list *curr);
+ const struct kmod_list *curr);
/**
* kmod_list_prev:
* Since: 1
*/
struct kmod_list *kmod_list_prev(const struct kmod_list *list,
- const struct kmod_list *curr);
-
-
+ const struct kmod_list *curr);
/**
* SECTION:libkmod-config
*/
void kmod_config_iter_free_iter(struct kmod_config_iter *iter);
-
/**
* SECTION:libkmod-module
* @short_description: operate on kernel modules
* Since: 1
*/
int kmod_module_new_from_lookup(struct kmod_ctx *ctx, const char *given_alias,
- struct kmod_list **list);
+ struct kmod_list **list);
/**
* kmod_module_new_from_name_lookup:
*
* Since: 30
*/
-int kmod_module_new_from_name_lookup(struct kmod_ctx *ctx,
- const char *modname,
+int kmod_module_new_from_name_lookup(struct kmod_ctx *ctx, const char *modname,
struct kmod_module **mod);
/**
* Since: 1
*/
int kmod_module_new_from_name(struct kmod_ctx *ctx, const char *name,
- struct kmod_module **mod);
+ struct kmod_module **mod);
/**
* kmod_module_new_from_path:
* Since: 1
*/
int kmod_module_new_from_path(struct kmod_ctx *ctx, const char *path,
- struct kmod_module **mod);
-
+ struct kmod_module **mod);
/**
* kmod_module_ref:
*/
int kmod_module_unref_list(struct kmod_list *list);
-
/**
* kmod_insert:
* @KMOD_INSERT_FORCE_VERMAGIC: ignore kernel version magic
* Since: 1
*/
int kmod_module_insert_module(struct kmod_module *mod, unsigned int flags,
- const char *options);
+ const char *options);
/**
* kmod_probe:
* Bitmask which defines the behaviour of kmod_module_probe_insert_module().
*/
enum kmod_probe {
- KMOD_PROBE_FORCE_VERMAGIC = 0x00001,
- KMOD_PROBE_FORCE_MODVERSION = 0x00002,
- KMOD_PROBE_IGNORE_COMMAND = 0x00004,
- KMOD_PROBE_IGNORE_LOADED = 0x00008,
- KMOD_PROBE_DRY_RUN = 0x00010,
- KMOD_PROBE_FAIL_ON_LOADED = 0x00020,
+ KMOD_PROBE_FORCE_VERMAGIC = 0x00001,
+ KMOD_PROBE_FORCE_MODVERSION = 0x00002,
+ KMOD_PROBE_IGNORE_COMMAND = 0x00004,
+ KMOD_PROBE_IGNORE_LOADED = 0x00008,
+ KMOD_PROBE_DRY_RUN = 0x00010,
+ KMOD_PROBE_FAIL_ON_LOADED = 0x00020,
/* codes below can be used in return value, too */
- KMOD_PROBE_APPLY_BLACKLIST_ALL = 0x10000,
- KMOD_PROBE_APPLY_BLACKLIST = 0x20000,
- KMOD_PROBE_APPLY_BLACKLIST_ALIAS_ONLY = 0x40000,
+ KMOD_PROBE_APPLY_BLACKLIST_ALL = 0x10000,
+ KMOD_PROBE_APPLY_BLACKLIST = 0x20000,
+ KMOD_PROBE_APPLY_BLACKLIST_ALIAS_ONLY = 0x40000,
};
/**
*
* Since: 3
*/
-int kmod_module_probe_insert_module(struct kmod_module *mod,
- unsigned int flags, const char *extra_options,
- int (*run_install)(struct kmod_module *m,
- const char *cmdline, void *data),
- const void *data,
- void (*print_action)(struct kmod_module *m, bool install,
- const char *options));
+int kmod_module_probe_insert_module(
+ struct kmod_module *mod, unsigned int flags, const char *extra_options,
+ int (*run_install)(struct kmod_module *m, const char *cmdline, void *data),
+ const void *data,
+ void (*print_action)(struct kmod_module *m, bool install, const char *options));
/**
* kmod_remove:
*/
int kmod_module_remove_module(struct kmod_module *mod, unsigned int flags);
-
/**
* kmod_module_get_module:
* @entry: an entry in a list of kmod modules.
*
* Since: 2
*/
-int kmod_module_get_softdeps(const struct kmod_module *mod,
- struct kmod_list **pre, struct kmod_list **post);
+int kmod_module_get_softdeps(const struct kmod_module *mod, struct kmod_list **pre,
+ struct kmod_list **post);
/**
* kmod_module_get_weakdeps:
*
* Since: 33
*/
-int kmod_module_get_weakdeps(const struct kmod_module *mod,
- struct kmod_list **weak);
+int kmod_module_get_weakdeps(const struct kmod_module *mod, struct kmod_list **weak);
/**
* kmod_filter:
*
* Since: 6
*/
-int kmod_module_apply_filter(const struct kmod_ctx *ctx,
- enum kmod_filter filter_type,
- const struct kmod_list *input,
- struct kmod_list **output);
+int kmod_module_apply_filter(const struct kmod_ctx *ctx, enum kmod_filter filter_type,
+ const struct kmod_list *input, struct kmod_list **output);
/**
* kmod_module_get_filtered_blacklist:
* Since: 1
*/
int kmod_module_get_filtered_blacklist(const struct kmod_ctx *ctx,
- const struct kmod_list *input,
- struct kmod_list **output) __attribute__ ((deprecated));
+ const struct kmod_list *input,
+ struct kmod_list **output)
+ __attribute__((deprecated));
/**
* kmod_module_get_install_commands:
*/
const char *kmod_module_get_path(const struct kmod_module *mod);
-
/**
* kmod_module_get_dependency_symbols:
* @mod: kmod module
*
* Since: 3
*/
-int kmod_module_get_dependency_symbols(const struct kmod_module *mod, struct kmod_list **list);
+int kmod_module_get_dependency_symbols(const struct kmod_module *mod,
+ struct kmod_list **list);
/**
* kmod_symbol_bind:
*/
void kmod_module_dependency_symbols_free_list(struct kmod_list *list);
-
/**
* kmod_module_get_sections:
* @mod: kmod module
*/
void kmod_module_section_free_list(struct kmod_list *list);
-
/**
* kmod_module_get_symbols:
* @mod: kmod module
*/
void kmod_module_symbols_free_list(struct kmod_list *list);
-
/**
* kmod_module_get_versions:
* @mod: kmod module
*/
void kmod_module_versions_free_list(struct kmod_list *list);
-
/**
* kmod_module_get_info:
* @mod: kmod module
*/
void kmod_module_info_free_list(struct kmod_list *list);
-
-
/**
* SECTION:libkmod-loaded
* @short_description: currently loaded modules
*
* Since: 1
*/
-int kmod_module_new_from_loaded(struct kmod_ctx *ctx,
- struct kmod_list **list);
+int kmod_module_new_from_loaded(struct kmod_ctx *ctx, struct kmod_list **list);
/**
* kmod_module_initstate: