/* modinfo.c - Display module info * * Copyright 2012 Andre Renaud * * TODO: cleanup USE_MODINFO(NEWTOY(modinfo, "<1b:k:F:0", TOYFLAG_SBIN)) config MODINFO bool "modinfo" default y help usage: modinfo [-0] [-b basedir] [-k kernrelease] [-F field] [modulename...] Display module fields for all specified modules, looking in /lib/modules// (kernrelease defaults to uname -r). */ #define FOR_modinfo #include "toys.h" GLOBALS( char *F, *k, *b; long mod; ) static void output_field(char *field, char *value) { if (!TT.F) xprintf("%s:%*c", field, 15-(int)strlen(field), ' '); else if (strcmp(TT.F, field)) return; xprintf("%s", value); xputc((toys.optflags & FLAG_0) ? 0 : '\n'); } static void modinfo_file(char *full_name) { int fd, len, i; char *buf = 0, *pos, *modinfo_tags[] = { "alias", "license", "description", "author", "firmware", "vermagic", "srcversion", "intree", "depends", "parm", "parmtype", }; if (-1 != (fd = open(full_name, O_RDONLY))) { len = fdlength(fd); buf = xmmap(0, len, PROT_READ, MAP_SHARED, fd, 0); close(fd); } if (!buf) { perror_msg_raw(full_name); return; } output_field("filename", full_name); for (pos = buf; pos < buf+len; pos++) { if (*pos) continue; for (i=0; iname[len] == '_') continue; if (s[len] == '_' && new->name[len] == '-') continue; if (s[len] != new->name[len]) break; } if (s[len] || strcmp(new->name+len, ".ko")) break; modinfo_file(s = dirtree_path(new, 0)); free(s); return DIRTREE_ABORT; } } return DIRTREE_RECURSE; } void modinfo_main(void) { for(TT.mod = 0; TT.mod= sizeof(toybuf)) perror_exit("basedir/kernrelease too long"); dirtree_read(toybuf, check_module); } } }