summaryrefslogtreecommitdiff
path: root/modutils
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2000-08-21 19:25:16 +0000
committerEric Andersen <andersen@codepoet.org>2000-08-21 19:25:16 +0000
commitbe0dc0d06a730bd3a9e7567af6918a673d5135ee (patch)
tree502706beed7931e673ea0436e912873e84ba2577 /modutils
parentb2fc5a06479bb0fcf0f39bea756a5994cbca72b8 (diff)
downloadbusybox-w32-be0dc0d06a730bd3a9e7567af6918a673d5135ee.tar.gz
busybox-w32-be0dc0d06a730bd3a9e7567af6918a673d5135ee.tar.bz2
busybox-w32-be0dc0d06a730bd3a9e7567af6918a673d5135ee.zip
lsmod now uses the query_module syscall, rather then /proc
-Erik
Diffstat (limited to 'modutils')
-rw-r--r--modutils/lsmod.c82
1 files changed, 72 insertions, 10 deletions
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 @@
22 */ 22 */
23 23
24#include "internal.h" 24#include "internal.h"
25#include <stdlib.h>
25#include <stdio.h> 26#include <stdio.h>
27#include <stddef.h>
28#include <errno.h>
29#include <unistd.h>
30#include <dirent.h>
31#include <ctype.h>
32#include <assert.h>
33#include <getopt.h>
34#include <sys/utsname.h>
35
36
37
38struct module_info
39{
40 unsigned long addr;
41 unsigned long size;
42 unsigned long flags;
43 long usecount;
44};
45
46
47int query_module(const char *name, int which, void *buf, size_t bufsize,
48 size_t *ret);
49
50/* Values for query_module's which. */
51#define QM_MODULES 1
52#define QM_DEPS 2
53#define QM_REFS 3
54#define QM_SYMBOLS 4
55#define QM_INFO 5
56
26 57
27 58
28extern int lsmod_main(int argc, char **argv) 59extern int lsmod_main(int argc, char **argv)
29{ 60{
30#if defined BB_FEATURE_USE_DEVPS_PATCH 61 struct module_info info;
31 char *filename = "/dev/modules"; 62 char *module_names, *mn, *deps, *dn;
32#else 63 size_t bufsize, nmod, count, i, j;
33#if ! defined BB_FEATURE_USE_PROCFS 64
34#error Sorry, I depend on the /proc filesystem right now. 65 module_names = xmalloc(bufsize = 256);
35#endif 66 deps = xmalloc(bufsize);
36 char *filename = "/proc/modules"; 67 if (query_module(NULL, QM_MODULES, module_names, bufsize, &nmod)) {
37#endif 68 fatalError("QM_MODULES: %s\n", strerror(errno));
38 69 }
39 return(print_file_by_name(filename)); 70
71 printf("Module Size Used by\n");
72 for (i = 0, mn = module_names; i < nmod; mn += strlen(mn) + 1, i++) {
73 if (query_module(mn, QM_INFO, &info, sizeof(info), &count)) {
74 if (errno == ENOENT) {
75 /* The module was removed out from underneath us. */
76 continue;
77 }
78 /* else choke */
79 fatalError("module %s: QM_INFO: %s\n", mn, strerror(errno));
80 }
81 while (query_module(mn, QM_REFS, deps, bufsize, &count)) {
82 if (errno == ENOENT) {
83 /* The module was removed out from underneath us. */
84 continue;
85 }
86 if (errno != ENOSPC) {
87 fatalError("module %s: QM_REFS: %s", mn, strerror(errno));
88 }
89 deps = xrealloc(deps, bufsize = count);
90 }
91 printf("%-20s%8lu%4ld ", mn, info.size, info.usecount);
92 if (count) printf("[");
93 for (j = 0, dn = deps; j < count; dn += strlen(dn) + 1, j++) {
94 printf("%s%s", dn, (j==count-1)? "":" ");
95 }
96 if (count) printf("]");
97 printf("\n");
98 }
99
100
101 return( 0);
40} 102}