From 5542bd31ad4b03bd09d973ddb03a5b35664bbaea Mon Sep 17 00:00:00 2001 From: fjoe Date: Wed, 4 May 2005 12:46:43 +0000 Subject: Add -m option (find module using modfind() and stat it). --- sbin/kldstat/kldstat.8 | 10 +++++++--- sbin/kldstat/kldstat.c | 26 ++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 5 deletions(-) (limited to 'sbin') diff --git a/sbin/kldstat/kldstat.8 b/sbin/kldstat/kldstat.8 index 77d933d..b2b72c2 100644 --- a/sbin/kldstat/kldstat.8 +++ b/sbin/kldstat/kldstat.8 @@ -35,7 +35,9 @@ .Nm .Op Fl v .Op Fl i Ar id -.Op Fl n Ar name +.Op Fl n Ar filename +.Nm +.Op Fl m Ar modname .Sh DESCRIPTION The .Nm @@ -48,8 +50,10 @@ The following options are available: Be more verbose. .It Fl i Ar id Display the status of only the file with this ID. -.It Fl n Ar name -Display the status of only the file with this name. +.It Fl n Ar filename +Display the status of only the file with this filename. +.It Fl m Ar modname +Display the status of only the module with this modname. .El .Sh EXIT STATUS .Ex -std diff --git a/sbin/kldstat/kldstat.c b/sbin/kldstat/kldstat.c index ce5ebf4..fd8f220 100644 --- a/sbin/kldstat/kldstat.c +++ b/sbin/kldstat/kldstat.c @@ -76,7 +76,7 @@ static void printfile(int fileid, int verbose) static void usage(void) { - fprintf(stderr, "usage: kldstat [-v] [-i id] [-n name]\n"); + fprintf(stderr, "usage: kldstat [-v] [-i id] [-n name] [-m name]\n"); exit(1); } @@ -87,15 +87,19 @@ main(int argc, char** argv) int verbose = 0; int fileid = 0; char* filename = NULL; + char* modname = NULL; char* p; - while ((c = getopt(argc, argv, "i:n:v")) != -1) + while ((c = getopt(argc, argv, "i:m:n:v")) != -1) switch (c) { case 'i': fileid = (int)strtoul(optarg, &p, 10); if (*p != '\0') usage(); break; + case 'm': + modname = optarg; + break; case 'n': filename = optarg; break; @@ -111,6 +115,24 @@ main(int argc, char** argv) if (argc != 0) usage(); + if (modname != NULL) { + int modid; + struct module_stat stat; + + if ((modid = modfind(modname)) < 0) + err(1, "can't find module %s", modname); + + stat.version = sizeof(struct module_stat); + if (modstat(modid, &stat) < 0) + warn("can't stat module id %d", modid); + else { + printf("Id Refs Name\n"); + printf("%3d %4d %s\n", stat.id, stat.refs, stat.name); + } + + return 0; + } + if (filename != NULL) { if ((fileid = kldfind(filename)) < 0) err(1, "can't find file %s", filename); -- cgit v1.1