31 #define MODULE_DIR "root»/system/modules" 33 extern int pedigree_module_is_loaded(
char *name);
35 int main(
int argc,
char **argv)
37 int listAll = 0, listLoaded = 0, listUnloaded = 0, c = 0, err = 0;
38 while ((c = getopt(argc, argv,
"aluh")) != -1)
43 if (listLoaded || listUnloaded)
49 if (listAll || listUnloaded)
55 if (listAll || listLoaded)
61 fprintf(stderr,
"usage: modlist [-a] [-l] [-u]\n");
63 stderr,
"-a%-16slist all modules and show their status\n",
65 fprintf(stderr,
"-l%-16slist all already-loaded modules\n",
"");
67 stderr,
"-u%-16slist all modules that are not loaded\n",
69 fprintf(stderr,
"-h%-16sshow this usage information\n",
"");
70 fprintf(stderr,
"\n");
72 stderr,
"modlist without arguments defaults to listing all " 73 "modules with their status\n");
77 fprintf(stderr,
"Unrecognized option: -%c\n", optopt);
82 if (!listAll && !listLoaded && !listUnloaded)
89 stderr,
"Only one action (-a, -l, or -u) can be specified\n");
95 DIR *dp = opendir(MODULE_DIR);
99 "Couldn't open the directory %s: %s.\n", MODULE_DIR,
105 while ((ep = readdir(dp)))
107 char *filename = ep->d_name;
109 char *lastPeriod = strrchr(filename,
'.');
110 char *suffix = lastPeriod + 1;
111 if (lastPeriod && !strcasecmp(suffix,
"o"))
117 "%-32s%s\n", filename,
118 pedigree_module_is_loaded(filename) ?
"[loaded]" :
"");
122 if (pedigree_module_is_loaded(filename))
124 printf(
"%s\n", filename);
127 else if (listUnloaded)
129 if (!pedigree_module_is_loaded(filename))
131 printf(
"%s\n", filename);