2 * kmod-lsmod - list modules from linux kernel using libkmod.
4 * Copyright (C) 2011-2013 ProFUSION embedded systems
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 #include <libkmod/libkmod.h>
31 static int do_lsmod(int argc, char *argv[])
34 const char *null_config = NULL;
35 struct kmod_list *list, *itr;
39 fprintf(stderr, "Usage: %s\n", argv[0]);
43 ctx = kmod_new(NULL, &null_config);
45 fputs("Error: kmod_new() failed!\n", stderr);
49 err = kmod_module_new_from_loaded(ctx, &list);
51 fprintf(stderr, "Error: could not get list of modules: %s\n",
57 puts("Module Size Used by");
59 kmod_list_foreach(itr, list) {
60 struct kmod_module *mod = kmod_module_get_module(itr);
61 const char *name = kmod_module_get_name(mod);
62 int use_count = kmod_module_get_refcnt(mod);
63 long size = kmod_module_get_size(mod);
64 struct kmod_list *holders, *hitr;
67 printf("%-19s %8ld %d", name, size, use_count);
68 holders = kmod_module_get_holders(mod);
69 kmod_list_foreach(hitr, holders) {
70 struct kmod_module *hm = kmod_module_get_module(hitr);
79 fputs(kmod_module_get_name(hm), stdout);
80 kmod_module_unref(hm);
83 kmod_module_unref_list(holders);
84 kmod_module_unref(mod);
86 kmod_module_unref_list(list);
92 const struct kmod_cmd kmod_cmd_compat_lsmod = {
95 .help = "compat lsmod command",
98 const struct kmod_cmd kmod_cmd_list = {
101 .help = "list currently loaded modules",