From 5363b092986416b4ec99716bb2b309856ff22526 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Thu, 27 Jun 2019 14:37:57 -0700 Subject: modinfo: various small fixes. Improve Android support (see code comments). Remove unnecessary fixed-length limits. Show error if module not found (plus test). Expand help text. Switch to FLAG macro. Stop hard-coding module assumptions in the tests. --- toys/other/modinfo.c | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) (limited to 'toys') diff --git a/toys/other/modinfo.c b/toys/other/modinfo.c index eaf6cb98..286570f1 100644 --- a/toys/other/modinfo.c +++ b/toys/other/modinfo.c @@ -10,10 +10,14 @@ config MODINFO bool "modinfo" default y help - usage: modinfo [-0] [-b basedir] [-k kernrelease] [-F field] [modulename...] + usage: modinfo [-0] [-b basedir] [-k kernel] [-F field] [module|file...] - Display module fields for all specified modules, looking in - /lib/modules// (kernrelease defaults to uname -r). + 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 @@ -23,6 +27,7 @@ GLOBALS( char *F, *k, *b; long mod; + int count; ) static void output_field(char *field, char *value) @@ -30,7 +35,7 @@ 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'); + xputc(FLAG(0) ? 0 : '\n'); } static void modinfo_file(char *full_name) @@ -53,6 +58,7 @@ static void modinfo_file(char *full_name) return; } + TT.count++; output_field("filename", full_name); for (pos = buf; pos < buf+len; pos++) { @@ -100,19 +106,30 @@ static int check_module(struct dirtree *new) void modinfo_main(void) { - for(TT.mod = 0; TT.mod= sizeof(toybuf)) - perror_exit("basedir/kernrelease too long"); - dirtree_read(toybuf, check_module); + char *path = xmprintf("%s/lib/modules/%s", TT.b, TT.k); + + TT.count = 0; + dirtree_read(path, check_module); + if (!TT.count) error_msg("%s: not found", toys.optargs[TT.mod]); + free(path); } } } -- cgit v1.2.3