31#define MODULE_DIR "/usr/lib/modules"
33extern int pedigree_module_is_loaded(
char* name);
35int main(
int argc,
char** argv) {
36 int listAll = 0, listLoaded = 0, listUnloaded = 0, c = 0, err = 0;
37 while ((c = getopt(argc, argv,
"aluh")) != -1) {
40 if (listLoaded || listUnloaded)
46 if (listAll || listUnloaded)
52 if (listAll || listLoaded)
58 fprintf(stderr,
"usage: modlist [-a] [-l] [-u]\n");
59 fprintf(stderr,
"-a%-16slist all modules and show their status\n",
"");
60 fprintf(stderr,
"-l%-16slist all already-loaded modules\n",
"");
61 fprintf(stderr,
"-u%-16slist all modules that are not loaded\n",
"");
62 fprintf(stderr,
"-h%-16sshow this usage information\n",
"");
63 fprintf(stderr,
"\n");
65 "modlist without arguments defaults to listing all "
66 "modules with their status\n");
70 fprintf(stderr,
"Unrecognized option: -%c\n", optopt);
75 if (!listAll && !listLoaded && !listUnloaded)
80 fprintf(stderr,
"Only one action (-a, -l, or -u) can be specified\n");
86 DIR* dp = opendir(MODULE_DIR);
88 printf(
"Couldn't open the directory %s: %s.\n", MODULE_DIR, strerror(errno));
93 while ((ep = readdir(dp))) {
94 char* filename = ep->d_name;
96 char* lastPeriod = strrchr(filename,
'.');
97 char* suffix = lastPeriod + 1;
98 if (lastPeriod && !strcasecmp(suffix,
"o")) {
101 printf(
"%-32s%s\n", filename, pedigree_module_is_loaded(filename) ?
"[loaded]" :
"");
102 }
else if (listLoaded) {
103 if (pedigree_module_is_loaded(filename)) {
104 printf(
"%s\n", filename);
106 }
else if (listUnloaded) {
107 if (!pedigree_module_is_loaded(filename)) {
108 printf(
"%s\n", filename);