/* modprobe.c: add or remove a module from the kernel, intelligently.
Copyright (C) 2001 Rusty Russell.
Copyright (C) 2002, 2003 Rusty Russell, IBM Corporation.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#define _GNU_SOURCE /* asprintf */
#include <sys/utsname.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <dirent.h>
#include <limits.h>
#include <elf.h>
#include <getopt.h>
#include <fnmatch.h>
#include <asm/unistd.h>
#include <sys/wait.h>
#include <syslog.h>
#define streq(a,b) (strcmp((a),(b)) == 0)
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#include "zlibsupport.h"
#include "list.h"
#include "backwards_compat.c"
extern long init_module(void *, unsigned long, const char *);
extern long delete_module(const char *, unsigned int);
struct module {
struct list_head list;
char *modname;
char filename[0];
};
#ifndef MODULE_DIR
#define MODULE_DIR "/lib/modules"
#endif
typedef void (*errfn_t)(const char *fmt, ...);
/* Do we use syslog or stderr for messages? */
static int log;
static void message(const char *prefix, const char *fmt, va_list *arglist)
{
char *buf, *buf2;
vasprintf(&buf, fmt, *arglist);
asprintf(&buf2, "%s%s", prefix, buf);
if (log)
syslog(LOG_NOTICE, "%s", buf2);
else
fprintf(stderr, "%s", buf2);
free(buf2);
free(buf);
}
static int warned = 0;
static void warn(const char *fmt, ...)
{
va_list arglist;
warned++;
va_start(arglist, fmt);
message("WARNING: ", fmt, &arglist);
va_end(arglist);
}
static void fatal(const char *fmt, ...)
{
va_list arglist;
va_start(arglist, fmt);
message("FATAL: ", fmt, &arglist);
va_end(arglist);
exit(1);
}
static void grammar(const char *cmd, const char *filename, unsigned int line)
{
warn("%s line %u: ignoring bad line starting with '%s'\n",
filename, line, cmd);
}
static void *do_nofail(void *ptr, const char *file, int line, const char *expr)
{
if (!ptr) {
fatal("Memory allocation failure %s line %d: %s.\n",
file, line, expr);
}
return ptr;
}
#define NOFAIL(ptr) do_nofail((ptr), __FILE__, __LINE__, #ptr)
static void print_usage(const char *progname)
{
fprintf(stderr,
"Usage: %s [-v] [-V] [-C config-file] [-n] [-i] [-q] [-b] [-o <modname>] [ --dump-modversions ] <modname> [parameters...]\n"
"%s -r [-n] [-i] [-v] <modulename> ...\n"
"%s -l -t <dirname> [ -a <modulename> ...]\n",
progname, progname, progname);
exit(1);
}
static int fgetc_wrapped(FILE *file, unsigned int *linenum)
{
for (;;) {
int ch = fgetc(file);
if (ch != '\\')
return ch;
ch = fgetc(file);
if (ch != '\n')
return ch;
if (linenum)
(*linenum)++;
}
}
static char *getline_wrapped(FILE *file, unsigned int *linenum)
{
int size = 1024;
int i = 0;
char *buf = NOFAIL(malloc(size));
for(;;) {
int ch = fgetc_wrapped(file, linenum);
if (i == size) {
size *= 2;
buf = NOFAIL(realloc(buf, size));
}
if (ch < 0 && i == 0) {
free(buf);
return NULL;
}
if (ch < 0 || ch == '\n') {
if (linenum)
(*linenum)++;
buf[i] = '\0';
return NOFAIL(realloc(buf, i+1));
}
buf[i++] = ch;
}
}
static struct module *find_module(const char *filename, struct list_head *list)
{
struct module *i;
list_for_each_entry(i, list, list) {
if (strcmp(i->filename, filename) == 0)
return i;
}
return NULL;
}
/* Convert filename to the module name. Works if filename == modname, too. */
static void filename2modname(char *modname, const char *filename)
{
const char *afterslash;
unsigned int i;
afterslash = strrchr(filename, '/');
if (!afterslash)
afterslash = filename;
else
afterslash++;
/* Convert to underscores, stop at first . */
for (i = 0; afterslash[i] && afterslash[i] != '.'; i++) {
if (afterslash[i] == '-')
modname[i] = '_';
else
modname[i] = afterslash[i];
}
modname[i] = '\0';
}
static int lock_file(const char *filename)
{
int fd = open(filename, O_RDWR, 0);
if (fd >= 0) {
struct flock lock;
lock.l_type = F_WRLCK;
lock.l_whence = SEEK_SET;
lock.l_start = 0;
lock.l_len = 1;
fcntl(fd, F_SETLKW, &lock);
} else
/* Read-only filesystem? There goes locking... */
fd = open(filename, O_RDONLY, 0);
return fd;
}
static void unlock_file(int fd)
{
/* Valgrind is picky... */
close(fd);
}
static void add_module(char *filename, int namelen, struct list_head *list)
{
struct module *mod;
/* If it's a duplicate: move it to the end, so it gets
inserted where it is *first* required. */
mod = find_module(filename, list);
if (mod)
list_del(&mod->list);
else {
/* No match. Create a new module. */
mod = NOFAIL(malloc(sizeof(struct module) + namelen + 1));
memcpy(mod->filename, filename, namelen);
mod->filename[namelen] = '\0';
mod->modname = NOFAIL(malloc(namelen + 1));
filename2modname(mod->modname, mod->filename);
}
list_add_tail(&mod->list, list);
}
/* Compare len chars of a to b, with _ and - equivalent. */
static int modname_equal(const char *a, const char *b, unsigned int len)
{
unsigned int i;
if (strlen(b) != len)
return 0;
for (i = 0; i < len; i++) {
if ((a[i] == '_' || a[i] == '-')
&& (b[i] == '_' || b[i] == '-'))
continue;
if (a[i] != b[i])
return 0;
}
return 1;
}
/* Fills in list of modules if this is the line we want. */
static int add_modules_dep_line(char *line,
const char *name,
struct list_head *list)
{
char *ptr;
int len;
char *modname;
/* Ignore lines without : or which start with a # */
ptr = strchr(line, ':');
if (ptr == NULL || line[strspn(line, "\t ")] == '#')
return 0;
/* Is this the module we are looking for? */
*ptr = '\0';
if (strrchr(line, '/'))
modname = strrchr(line, '/') + 1;
else
modname = line;
len = strlen(modname);
if (strchr(modname, '.'))
len = strchr(modname, '.') - modname;
if (!modname_equal(modname, name, len))
return 0;
/* Create the list. */
add_module(line, ptr - line, list);
ptr++;
for(;;) {
char *dep_start;
ptr += strspn(ptr, " \t");
if (*ptr == '\0')
break;
dep_start = ptr;
ptr += strcspn(ptr, " \t");
add_module(dep_start, ptr - dep_start, list);
}
return 1;
}
static void read_depends(const char *dirname,
const char *start_name,
struct list_head *list)
{
char *modules_dep_name;
char *line;
FILE *modules_dep;
int done = 0;
asprintf(&modules_dep_name, "%s/%s", dirname, "modules.dep");
modules_dep = fopen(modules_dep_name, "r");
if (!modules_dep)
fatal("Could not load %s: %s\n",
modules_dep_name, strerror(errno));
/* Stop at first line, as we can have duplicates (eg. symlinks
from boot/ */
while (!done && (line = getline_wrapped(modules_dep, NULL)) != NULL) {
done = add_modules_dep_line(line, start_name, list);
free(line);
}
fclose(modules_dep);
free(modules_dep_name);
}
/* We use error numbers in a loose translation... */
static const char *insert_moderror(int err)
{
switch (err) {
case ENOEXEC:
return "Invalid module format";
case ENOENT:
return "Unknown symbol in module, or unknown parameter (see dmesg)";
case ENOSYS:
return "Kernel does not have module support";
default:
return strerror(err);
}
}
static const char *remove_moder
没有合适的资源?快使用搜索试试~ 我知道了~
module-init-tools-3.4.tar.gz_module-init-tools
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 179 浏览量
2022-09-20
21:30:37
上传
评论
收藏 276KB GZ 举报
温馨提示
共316个文件
ko:162个
sh:68个
c:38个
Linux模块初始化工具3.4版本,用于Linux升级。
资源详情
资源评论
资源推荐
收起资源包目录
module-init-tools-3.4.tar.gz_module-init-tools (316个子文件)
output.0 124KB
traces.0 30KB
output.1 124KB
traces.1 9KB
configure.ac 1KB
Makefile.am 6KB
AUTHORS 108B
modprobe.c 40KB
depmod.c 28KB
tables.c 14KB
modinfo.c 9KB
rmmod.c 7KB
moduleops_core.c 7KB
insmod.c 4KB
input_map_new.c 3KB
input_map.c 2KB
lsmod.c 2KB
zlibsupport.c 2KB
backwards_compat.c 2KB
pnp_map.c 2KB
rename-old.c 2KB
rename-new.c 2KB
ieee1394_map.c 2KB
ccw_map.c 2KB
usb_map.c 1KB
modinfo.c 1KB
of_map.c 1KB
pci_map.c 1KB
export_nodep.c 542B
moduleops.c 526B
complex_c.c 463B
export_dep.c 458B
complex_b.c 456B
complex_d.c 452B
loop1.c 441B
loop2.c 441B
complex_e.c 403B
alias.c 344B
rename-version.c 206B
noexport_doubledep.c 168B
complex_a.c 156B
noexport_dep.c 139B
loop_dep.c 103B
unknown.c 91B
noexport_nodep.c 56B
ChangeLog 17KB
CODING 2KB
generate-modprobe.conf 9KB
configure 124KB
COPYING 18KB
depcomp 16KB
modprobe.devfs 2KB
FAQ 1KB
config.guess 42KB
list.h 6KB
testing.h 6KB
tables.h 5KB
depmod.h 2KB
moduleops.h 701B
zlibsupport.h 351B
HACKING 689B
Makefile.in 33KB
INSTALL 9KB
install-sh 5KB
install-with-care 501B
of_map-64.ko 3KB
of_map-64.ko 3KB
of_map-64.ko 3KB
of_map-32.ko 2KB
of_map-32.ko 2KB
of_map-32.ko 2KB
complex_c-64.ko 2KB
complex_c-64.ko 2KB
pnp_map-64.ko 2KB
pnp_map-64.ko 2KB
input_map_new-64.ko 2KB
input_map_new-64.ko 2KB
pnp_map-64.ko 2KB
input_map-64.ko 2KB
complex_b-64.ko 2KB
input_map-64.ko 2KB
complex_b-64.ko 2KB
export_dep-64.ko 2KB
export_dep-64.ko 2KB
loop1-64.ko 2KB
loop2-64.ko 2KB
loop1-64.ko 2KB
loop2-64.ko 2KB
complex_d-64.ko 2KB
complex_d-64.ko 2KB
input_map_new-64.ko 2KB
input_map-64.ko 2KB
complex_c-64.ko 2KB
modinfo-64.ko 2KB
export_dep-64.ko 2KB
modinfo-64.ko 2KB
modinfo-64.ko 2KB
loop1-64.ko 2KB
loop2-64.ko 2KB
noexport_doubledep-64.ko 2KB
共 316 条
- 1
- 2
- 3
- 4
weixin_42651887
- 粉丝: 79
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0