2 * Common modutils related functions for busybox
4 * Copyright (C) 2008 by Timo Teras <timo.teras@iki.fi>
6 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
11 extern int init_module(void *module, unsigned long len, const char *options);
12 extern int delete_module(const char *module, unsigned int flags);
14 # include <sys/syscall.h>
15 # define init_module(mod, len, opts) syscall(__NR_init_module, mod, len, opts)
16 # define delete_module(mod, flags) syscall(__NR_delete_module, mod, flags)
19 void FAST_FUNC replace(char *s, char what, char with)
28 char * FAST_FUNC replace_underscores(char *s)
34 int FAST_FUNC string_to_llist(char *string, llist_t **llist, const char *delim)
39 while ((tok = strsep(&string, delim)) != NULL) {
42 llist_add_to_end(llist, xstrdup(tok));
48 char * FAST_FUNC filename2modname(const char *filename, char *modname)
56 modname = xmalloc(MODULE_NAME_LEN);
57 from = bb_get_last_path_component_nostrip(filename);
58 for (i = 0; i < (MODULE_NAME_LEN-1) && from[i] != '\0' && from[i] != '.'; i++)
59 modname[i] = (from[i] == '-') ? '_' : from[i];
65 const char * FAST_FUNC moderror(int err)
69 return "no such module";
71 return "invalid module format";
73 return "unknown symbol in module, or unknown parameter";
75 return "module has wrong symbol version";
77 return "kernel does not support requested operation";
83 char * FAST_FUNC parse_cmdline_module_options(char **argv)
91 options = xrealloc(options, optlen + 2 + strlen(*argv) + 2);
92 /* Spaces handled by "" pairs, but no way of escaping quotes */
93 optlen += sprintf(options + optlen, (strchr(*argv, ' ') ? "\"%s\" " : "%s "), *argv);
98 int FAST_FUNC bb_init_module(const char *filename, const char *options)
107 #if ENABLE_FEATURE_2_4_MODULES
108 if (get_linux_version_code() < KERNEL_VERSION(2,6,0))
109 return bb_init_module_24(filename, options);
112 /* Use the 2.6 way */
113 len = INT_MAX - 4095;
115 image = xmalloc_open_zipped_read_close(filename, &len);
118 if (init_module(image, len, options) != 0)
126 int FAST_FUNC bb_delete_module(const char *module, unsigned int flags)
128 return delete_module(module, flags);