/* 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 kernel] [-F field] [module|file...] Display module fields for modules specified by name or .ko path. -F Only show the given field -0 Separate fields with NUL rather than newline -b Use as root for /lib/modules/ -k Look in given directory under /lib/modules/ */ #define FOR_modinfo #include "toys.h" GLOBALS( char *F, *k, *b; long mod; int count; ) 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(FLAG(0) ? 0 : '\n'); } static void modinfo_file(char *full_name) { int fd, flen, i; char *buf = 0, *end, *modinfo_tags[] = { "license", "author", "description", "firmware", "alias", "srcversion", "depends", "retpoline", "intree", "name", "vermagic", "parm", "parmtype", }; if (-1 != (fd = open(full_name, O_RDONLY))) { flen = fdlength(fd); buf = xmmap(0, flen, PROT_READ, MAP_SHARED, fd, 0); end = buf + flen; close(fd); } if (!buf) { perror_msg_raw(full_name); return; } TT.count++; output_field("filename", full_name); for (i=0; i