diff options
author | Eric Andersen <andersen@codepoet.org> | 2000-08-21 19:25:16 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2000-08-21 19:25:16 +0000 |
commit | be0dc0d06a730bd3a9e7567af6918a673d5135ee (patch) | |
tree | 502706beed7931e673ea0436e912873e84ba2577 | |
parent | b2fc5a06479bb0fcf0f39bea756a5994cbca72b8 (diff) | |
download | busybox-be0dc0d06a730bd3a9e7567af6918a673d5135ee.tar.gz |
lsmod now uses the query_module syscall, rather then /proc
-Erik
-rw-r--r-- | Changelog | 1 | ||||
-rw-r--r-- | lsmod.c | 82 | ||||
-rw-r--r-- | modutils/lsmod.c | 82 |
3 files changed, 145 insertions, 20 deletions
@@ -11,6 +11,7 @@ cleaner too, thanks to Allen Soard <esp-software@mail.hypermart.net> * Add optional ls file sorting, thanks to a patch from Sterling Huxley <sterling@europa.com> + * lsmod now uses the query_module syscall, rather then /proc -Erik Andersen @@ -22,19 +22,81 @@ */ #include "internal.h" +#include <stdlib.h> #include <stdio.h> +#include <stddef.h> +#include <errno.h> +#include <unistd.h> +#include <dirent.h> +#include <ctype.h> +#include <assert.h> +#include <getopt.h> +#include <sys/utsname.h> + + + +struct module_info +{ + unsigned long addr; + unsigned long size; + unsigned long flags; + long usecount; +}; + + +int query_module(const char *name, int which, void *buf, size_t bufsize, + size_t *ret); + +/* Values for query_module's which. */ +#define QM_MODULES 1 +#define QM_DEPS 2 +#define QM_REFS 3 +#define QM_SYMBOLS 4 +#define QM_INFO 5 + extern int lsmod_main(int argc, char **argv) { -#if defined BB_FEATURE_USE_DEVPS_PATCH - char *filename = "/dev/modules"; -#else -#if ! defined BB_FEATURE_USE_PROCFS -#error Sorry, I depend on the /proc filesystem right now. -#endif - char *filename = "/proc/modules"; -#endif - - return(print_file_by_name(filename)); + struct module_info info; + char *module_names, *mn, *deps, *dn; + size_t bufsize, nmod, count, i, j; + + module_names = xmalloc(bufsize = 256); + deps = xmalloc(bufsize); + if (query_module(NULL, QM_MODULES, module_names, bufsize, &nmod)) { + fatalError("QM_MODULES: %s\n", strerror(errno)); + } + + printf("Module Size Used by\n"); + for (i = 0, mn = module_names; i < nmod; mn += strlen(mn) + 1, i++) { + if (query_module(mn, QM_INFO, &info, sizeof(info), &count)) { + if (errno == ENOENT) { + /* The module was removed out from underneath us. */ + continue; + } + /* else choke */ + fatalError("module %s: QM_INFO: %s\n", mn, strerror(errno)); + } + while (query_module(mn, QM_REFS, deps, bufsize, &count)) { + if (errno == ENOENT) { + /* The module was removed out from underneath us. */ + continue; + } + if (errno != ENOSPC) { + fatalError("module %s: QM_REFS: %s", mn, strerror(errno)); + } + deps = xrealloc(deps, bufsize = count); + } + printf("%-20s%8lu%4ld ", mn, info.size, info.usecount); + if (count) printf("["); + for (j = 0, dn = deps; j < count; dn += strlen(dn) + 1, j++) { + printf("%s%s", dn, (j==count-1)? "":" "); + } + if (count) printf("]"); + printf("\n"); + } + + + return( 0); } diff --git a/modutils/lsmod.c b/modutils/lsmod.c index 6eb9c56b8..2a238cd23 100644 --- a/modutils/lsmod.c +++ b/modutils/lsmod.c @@ -22,19 +22,81 @@ */ #include "internal.h" +#include <stdlib.h> #include <stdio.h> +#include <stddef.h> +#include <errno.h> +#include <unistd.h> +#include <dirent.h> +#include <ctype.h> +#include <assert.h> +#include <getopt.h> +#include <sys/utsname.h> + + + +struct module_info +{ + unsigned long addr; + unsigned long size; + unsigned long flags; + long usecount; +}; + + +int query_module(const char *name, int which, void *buf, size_t bufsize, + size_t *ret); + +/* Values for query_module's which. */ +#define QM_MODULES 1 +#define QM_DEPS 2 +#define QM_REFS 3 +#define QM_SYMBOLS 4 +#define QM_INFO 5 + extern int lsmod_main(int argc, char **argv) { -#if defined BB_FEATURE_USE_DEVPS_PATCH - char *filename = "/dev/modules"; -#else -#if ! defined BB_FEATURE_USE_PROCFS -#error Sorry, I depend on the /proc filesystem right now. -#endif - char *filename = "/proc/modules"; -#endif - - return(print_file_by_name(filename)); + struct module_info info; + char *module_names, *mn, *deps, *dn; + size_t bufsize, nmod, count, i, j; + + module_names = xmalloc(bufsize = 256); + deps = xmalloc(bufsize); + if (query_module(NULL, QM_MODULES, module_names, bufsize, &nmod)) { + fatalError("QM_MODULES: %s\n", strerror(errno)); + } + + printf("Module Size Used by\n"); + for (i = 0, mn = module_names; i < nmod; mn += strlen(mn) + 1, i++) { + if (query_module(mn, QM_INFO, &info, sizeof(info), &count)) { + if (errno == ENOENT) { + /* The module was removed out from underneath us. */ + continue; + } + /* else choke */ + fatalError("module %s: QM_INFO: %s\n", mn, strerror(errno)); + } + while (query_module(mn, QM_REFS, deps, bufsize, &count)) { + if (errno == ENOENT) { + /* The module was removed out from underneath us. */ + continue; + } + if (errno != ENOSPC) { + fatalError("module %s: QM_REFS: %s", mn, strerror(errno)); + } + deps = xrealloc(deps, bufsize = count); + } + printf("%-20s%8lu%4ld ", mn, info.size, info.usecount); + if (count) printf("["); + for (j = 0, dn = deps; j < count; dn += strlen(dn) + 1, j++) { + printf("%s%s", dn, (j==count-1)? "":" "); + } + if (count) printf("]"); + printf("\n"); + } + + + return( 0); } |