#include <dirent.h>
#include <ctype.h>
#include <assert.h>
+#include <getopt.h>
#include <sys/utsname.h>
-#include <sys/syscall.h>
-#include <linux/unistd.h>
//----------------------------------------------------------------------------
//--------modutils module.h, lines 45-242
#ifndef MODUTILS_MODULE_H
#define MODUTILS_MODULE_H 1
-#ident "$Id: insmod.c,v 1.11 2000/06/26 11:16:22 andersen Exp $"
+#ident "$Id: insmod.c,v 1.23 2000/09/22 00:38:07 andersen Exp $"
/* This file contains the structures used by the 2.0 and 2.1 kernels.
We do not use the kernel headers directly because we do not wish
#ifndef MODUTILS_OBJ_H
#define MODUTILS_OBJ_H 1
-#ident "$Id: insmod.c,v 1.11 2000/06/26 11:16:22 andersen Exp $"
+#ident "$Id: insmod.c,v 1.23 2000/09/22 00:38:07 andersen Exp $"
/* The relocatable object is manipulated using elfin types. */
_syscall5(int, old_sys_init_module, const char *, name, char *, code,
unsigned, codesize, struct old_mod_routines *, routines,
struct old_symbol_table *, symtab)
-_syscall5(int, query_module, const char *, name, int, which,
- void *, buf, size_t, bufsize, size_t*, ret);
#ifndef BB_RMMOD
_syscall1(int, delete_module, const char *, name)
#else
#endif
static char m_filename[BUFSIZ + 1] = "\0";
static char m_fullName[BUFSIZ + 1] = "\0";
-static const char insmod_usage[] =
- "insmod [OPTION]... MODULE [symbol=value]...\n"
-#ifndef BB_FEATURE_TRIVIAL_HELP
- "\nLoads the specified kernel modules into the kernel.\n\n"
- "Options:\n"
- "\t-f\tForce module to load into the wrong kernel version.\n"
- "\t-k\tMake module autoclean-able.\n"
- "\t-v\tverbose output\n" "\t-x\tdo not export externs\n"
-#endif
-;
/*======================================================================*/
-void *xrealloc(void *old, size_t size)
-{
- void *ptr = realloc(old, size);
- if (!ptr) {
- perror("Out of memory");
- exit(1);
- }
- return ptr;
-}
-
static int findNamedModule(const char *fileName, struct stat *statbuf,
void *userDate)
tmp++;
if (check_wildcard_match(tmp, fullName) == TRUE) {
/* Stop searching if we find a match */
- memcpy(m_filename, fileName, strlen(fileName));
+ memcpy(m_filename, fileName, strlen(fileName)+1);
return (FALSE);
}
}
/* Don't report an error if the symbol is coming from
the kernel or some external module. */
if (secidx <= SHN_HIRESERVE)
- fprintf(stderr, "%s multiply defined\n", name);
+ errorMsg("%s multiply defined\n", name);
return sym;
}
}
static void add_kernel_symbols(struct obj_file *f)
{
struct external_module *m;
- size_t i, nused = 0;
+ int i, nused = 0;
/* Add module symbols first. */
v = strchr(p, '=');
n = strchr(p, '\0');
if (v) {
- if (v - p == klen && strncmp(p, key, klen) == 0)
+ if (p + klen == v && strncmp(p, key, klen) == 0)
return v + 1;
} else {
- if (n - p == klen && strcmp(p, key) == 0)
+ if (p + klen == n && strcmp(p, key) == 0)
return n;
}
p = n + 1;
/* Also check that the parameter was not resolved from the kernel. */
if (sym == NULL || sym->secidx > SHN_HIRESERVE) {
- fprintf(stderr, "symbol for parameter %s not found\n", p);
+ errorMsg("symbol for parameter %s not found\n", p);
return 0;
}
str = alloca(strlen(q));
for (r = str, q++; *q != '"'; ++q, ++r) {
if (*q == '\0') {
- fprintf(stderr, "improperly terminated string argument for %s\n", p);
+ errorMsg("improperly terminated string argument for %s\n", p);
return 0;
} else if (*q == '\\')
switch (*++q) {
/* Fetch all the symbols and divvy them up as appropriate for the modules. */
-static int old_get_kernel_symbols(void)
+static int old_get_kernel_symbols(const char *m_name)
{
struct old_kernel_sym *ks, *k;
struct new_module_symbol *s;
p = get_modinfo_value(f, key);
key += 5;
if (p == NULL) {
- fprintf(stderr, "invalid parameter %s\n", key);
+ errorMsg("invalid parameter %s\n", key);
return 0;
}
/* Also check that the parameter was not resolved from the kernel. */
if (sym == NULL || sym->secidx > SHN_HIRESERVE) {
- fprintf(stderr, "symbol for parameter %s not found\n", key);
+ errorMsg("symbol for parameter %s not found\n", key);
return 0;
}
str = alloca(strlen(q));
for (r = str, q++; *q != '"'; ++q, ++r) {
if (*q == '\0') {
- fprintf(stderr,
- "improperly terminated string argument for %s\n",
+ errorMsg("improperly terminated string argument for %s\n",
key);
return 0;
} else if (*q == '\\')
loc += tgt_sizeof_char_p;
} else {
/* Array of chars (in fact, matrix !) */
- long charssize; /* size of each member */
+ unsigned long charssize; /* size of each member */
/* Get the size of each member */
/* Probably we should do that outside the loop ? */
if (!isdigit(*(p + 1))) {
- fprintf(stderr,
- "parameter type 'c' for %s must be followed by"
+ errorMsg("parameter type 'c' for %s must be followed by"
" the maximum size\n", key);
return 0;
}
/* Check length */
if (strlen(str) >= charssize) {
- fprintf(stderr,
- "string too long for %s (max %ld)\n", key,
+ errorMsg("string too long for %s (max %ld)\n", key,
charssize - 1);
return 0;
}
break;
default:
- fprintf(stderr, "unknown parameter type '%c' for %s\n",
- *p, key);
+ errorMsg("unknown parameter type '%c' for %s\n", *p, key);
return 0;
}
}
case ',':
if (++n > max) {
- fprintf(stderr, "too many values for %s (max %d)\n",
- key, max);
+ errorMsg("too many values for %s (max %d)\n", key, max);
return 0;
}
++q;
break;
default:
- fprintf(stderr, "invalid argument syntax for %s\n", key);
+ errorMsg("invalid argument syntax for %s\n", key);
return 0;
}
}
end_of_arg:
if (n < min) {
- fprintf(stderr, "too few values for %s (min %d)\n", key, min);
+ errorMsg("too few values for %s (min %d)\n", key, min);
return 0;
}
sym->secidx = SHN_ABS;
sym->value = 0;
} else {
- fprintf(stderr, "unresolved symbol %s\n", sym->name);
+ errorMsg("unresolved symbol %s\n", sym->name);
ret = 0;
}
}
errmsg = "Unhandled relocation";
bad_reloc:
if (extsym) {
- fprintf(stderr, "%s of type %ld for %s\n", errmsg,
+ errorMsg("%s of type %ld for %s\n", errmsg,
(long) ELFW(R_TYPE) (rel->r_info),
strtab + extsym->st_name);
} else {
- fprintf(stderr, "%s of type %ld\n", errmsg,
+ errorMsg("%s of type %ld\n", errmsg,
(long) ELFW(R_TYPE) (rel->r_info));
}
ret = 0;
|| f->header.e_ident[EI_MAG1] != ELFMAG1
|| f->header.e_ident[EI_MAG2] != ELFMAG2
|| f->header.e_ident[EI_MAG3] != ELFMAG3) {
- fprintf(stderr, "not an ELF file\n");
+ errorMsg("not an ELF file\n");
return NULL;
}
if (f->header.e_ident[EI_CLASS] != ELFCLASSM
|| f->header.e_ident[EI_DATA] != ELFDATAM
|| f->header.e_ident[EI_VERSION] != EV_CURRENT
|| !MATCH_MACHINE(f->header.e_machine)) {
- fprintf(stderr, "ELF file not for this architecture\n");
+ errorMsg("ELF file not for this architecture\n");
return NULL;
}
if (f->header.e_type != ET_REL) {
- fprintf(stderr, "ELF file not a relocatable object\n");
+ errorMsg("ELF file not a relocatable object\n");
return NULL;
}
/* Read the section headers. */
if (f->header.e_shentsize != sizeof(ElfW(Shdr))) {
- fprintf(stderr, "section header size mismatch: %lu != %lu\n",
+ errorMsg("section header size mismatch: %lu != %lu\n",
(unsigned long) f->header.e_shentsize,
(unsigned long) sizeof(ElfW(Shdr)));
return NULL;
#if SHT_RELM == SHT_REL
case SHT_RELA:
- fprintf(stderr,
- "RELA relocations not supported on this architecture\n");
+ errorMsg("RELA relocations not supported on this architecture\n");
return NULL;
#else
case SHT_REL:
- fprintf(stderr,
- "REL relocations not supported on this architecture\n");
+ errorMsg("REL relocations not supported on this architecture\n");
return NULL;
#endif
break;
}
- fprintf(stderr, "can't handle sections of type %ld\n",
+ errorMsg("can't handle sections of type %ld\n",
(long) sec->header.sh_type);
return NULL;
}
ElfW(Sym) * sym;
if (sec->header.sh_entsize != sizeof(ElfW(Sym))) {
- fprintf(stderr, "symbol size mismatch: %lu != %lu\n",
+ errorMsg("symbol size mismatch: %lu != %lu\n",
(unsigned long) sec->header.sh_entsize,
(unsigned long) sizeof(ElfW(Sym)));
return NULL;
case SHT_RELM:
if (sec->header.sh_entsize != sizeof(ElfW(RelM))) {
- fprintf(stderr,
- "relocation entry size mismatch: %lu != %lu\n",
+ errorMsg("relocation entry size mismatch: %lu != %lu\n",
(unsigned long) sec->header.sh_entsize,
(unsigned long) sizeof(ElfW(RelM)));
return NULL;
if ((fp = fopen(*argv, "r")) == NULL) {
/* Hmpf. Could not open it. Search through _PATH_MODULES to find a module named m_name */
if (recursiveAction(_PATH_MODULES, TRUE, FALSE, FALSE,
- findNamedModule, 0, m_fullName) == TRUE)
+ findNamedModule, 0, m_fullName) == FALSE)
{
if (m_filename[0] == '\0'
|| ((fp = fopen(m_filename, "r")) == NULL))
errorMsg("No module named '%s' found in '%s'\n", m_fullName, _PATH_MODULES);
exit(FALSE);
}
- }
+ } else
+ fatalError("No module named '%s' found in '%s'\n", m_fullName, _PATH_MODULES);
} else
memcpy(m_filename, *argv, strlen(*argv));
} else {
m_version = old_get_module_version(f, m_strversion);
if (m_version == -1) {
- fprintf(stderr,
- "couldn't find the kernel version the module was compiled for\n");
+ errorMsg("couldn't find the kernel version the module was "
+ "compiled for\n");
goto out;
}
}
if (strncmp(k_strversion, m_strversion, STRVERSIONLEN) != 0) {
if (flag_force_load) {
- fprintf(stderr, "Warning: kernel-module version mismatch\n"
+ errorMsg("Warning: kernel-module version mismatch\n"
"\t%s was compiled for kernel version %s\n"
"\twhile this kernel is version %s\n",
m_filename, m_strversion, k_strversion);
} else {
- fprintf(stderr, "kernel-module version mismatch\n"
+ errorMsg("kernel-module version mismatch\n"
"\t%s was compiled for kernel version %s\n"
"\twhile this kernel is version %s.\n",
m_filename, m_strversion, k_strversion);
goto out;
k_crcs = new_is_kernel_checksummed();
#else
- fprintf(stderr, "Not configured to support new kernels\n");
+ errorMsg("Not configured to support new kernels\n");
goto out;
#endif
} else {
#ifdef BB_FEATURE_INSMOD_OLD_KERNEL
- if (!old_get_kernel_symbols())
+ if (!old_get_kernel_symbols(m_name))
goto out;
k_crcs = old_is_kernel_checksummed();
#else
- fprintf(stderr, "Not configured to support old kernels\n");
+ errorMsg("Not configured to support old kernels\n");
goto out;
#endif
}
case 0:
break;
case EEXIST:
- fprintf(stderr, "A module named %s already exists\n", m_name);
+ errorMsg("A module named %s already exists\n", m_name);
goto out;
case ENOMEM:
- fprintf(stderr,
- "Can't allocate kernel memory for module; needed %lu bytes\n",
+ errorMsg("Can't allocate kernel memory for module; needed %lu bytes\n",
m_size);
goto out;
default: