aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
Diffstat (limited to 'toys')
-rw-r--r--toys/other/modinfo.c43
1 files changed, 30 insertions, 13 deletions
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
- <basedir>/lib/modules/<kernrelease>/ (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 <basedir> 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<toys.optc; TT.mod++) {
+ struct utsname uts;
+
+ // Android (as shipped by Google) currently only has modules on /vendor.
+ // Android does not support multiple sets of modules for different kernels.
+ if (CFG_TOYBOX_ON_ANDROID) {
+ if (!TT.b) TT.b = "/vendor";
+ if (!TT.k) TT.k = "";
+ } else {
+ uname(&uts);
+ if (!TT.b) TT.b = "";
+ if (!TT.k) TT.k = uts.release;
+ }
+
+ for (TT.mod = 0; TT.mod<toys.optc; TT.mod++) {
char *s = strstr(toys.optargs[TT.mod], ".ko");
if (s && !s[3]) modinfo_file(toys.optargs[TT.mod]);
else {
- struct utsname uts;
-
- if (uname(&uts) < 0) perror_exit("bad uname");
- if (snprintf(toybuf, sizeof(toybuf), "%s/lib/modules/%s",
- (toys.optflags & FLAG_b) ? TT.b : "",
- (toys.optflags & FLAG_k) ? TT.k : uts.release) >= 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);
}
}
}