struct list* module_get_list(const char *syspath) { struct list *aliases; struct utsname name; char *mapfile; uname(&name); mapfile = concat("/lib/modules/", name.release); mapfile = concat(mapfile, "/modules.alias"); aliases = find_aliases(syspath); return find_modules(mapfile, aliases); }
void pz_modules_init(char *path) { #ifdef IPOD #define MODULEDIR "/opt/Base:/opt/Emulators:/opt/Media:/opt/Tools:/opt/Zillae" #else #define MODULEDIR "modules" #endif /* Used for the progress bar */ TWindow * sliderwin; TWidget * slider; int sliderVal=0; int verbosity = pz_get_int_setting( pz_global_config, VERBOSITY ); #define MAXSLIDERVAL (100) #define SETUPSECTIONS (6) PzModule *last, *cur; int i; int modCount=0; if (module_head) { pz_error (_("modules_init called more than once")); return; } /* set up the screen to show a pretty progress bar */ sliderwin = ttk_new_window(); ttk_window_hide_header(sliderwin); sliderwin->x = sliderwin->y = 0; slider = ttk_new_slider_widget(2, ttk_screen->h/3, ttk_screen->w - 8, 0, MAXSLIDERVAL, &sliderVal, 0); slider->x = (sliderwin->w - slider->w)/2; ttk_add_widget(sliderwin, slider); sliderVal = (MAXSLIDERVAL/SETUPSECTIONS) * 1; updateprogress(sliderwin, slider, sliderVal, _("Scanning For Modules"), NULL); if (!path) path = MODULEDIR; path = strtok(strdupa(path), ":"); while (path) { find_modules (path); path = strtok(NULL, ":"); } sliderVal = (MAXSLIDERVAL/SETUPSECTIONS) * 2; updateprogress(sliderwin, slider, sliderVal, _("Reading Modules"), NULL); for (i = 0; i < __pz_builtin_number_of_init_functions; i++) { int found = 0; const char *name = __pz_builtin_names[i]; cur = module_head; while (cur) { char *p = strrchr (cur->podpath, '/'); if (!p) p = cur->podpath; else p++; if (!strncmp (p, name, strlen (name)) && !isalpha (p[strlen (name)])) { found = 1; break; } cur = cur->next; } if (!found) { if (module_head) { cur = module_head; while (cur->next) cur = cur->next; cur->next = calloc (1, sizeof(PzModule)); cur = cur->next; } else { cur = module_head = calloc (1, sizeof(PzModule)); } cur->podpath = 0; cur->name = strdup (__pz_builtin_names[i]); cur->init = __pz_builtin_init_functions[i]; cur->to_load = -1; cur->ordered = 0; cur->next = 0; } } if (!module_head) { pz_message_title (_("Warning"), _("No modules. podzilla will probably be very boring.")); return; } /* Used to initialize the window + progressbar used in loading the modules*/ cur = module_head; while (cur) { modCount++; cur = cur->next; } sliderVal = (MAXSLIDERVAL/SETUPSECTIONS) * 3; updateprogress(sliderwin, slider, sliderVal, _("Mounting Modules"), NULL); // Mount 'em cur = module_head; last = 0; while (cur) { if (cur->podpath && cur->extracted) { cur->mountpt = strdup (cur->podpath); last = cur; cur = cur->next; } else if (cur->podpath && mount_pod (cur) == -1) { if (last) last->next = cur->next; else module_head = cur->next; free (cur->podpath); free (cur); cur = last? last->next : module_head; } else { last = cur; cur = cur->next; } } sliderVal = (MAXSLIDERVAL/SETUPSECTIONS) * 4; updateprogress(sliderwin, slider, sliderVal, _("Scanning Module Info"), NULL); // Load the module.inf's cur = module_head; while (cur) { load_modinf (cur); cur = cur->next; } sliderVal = (MAXSLIDERVAL/SETUPSECTIONS) * 5; updateprogress(sliderwin, slider, sliderVal, _("Module Dependencies"), NULL); // Figure out the dependencies cur = module_head; last = 0; while (cur) { if (fix_dependencies (cur, 1, SOFTDEP) == -1 || fix_dependencies(cur, 1, HARDDEP) == -1) { if (last) last->next = cur->next; else module_head = cur->next; free_module (cur); cur = last? last->next : module_head; } else { last = cur; cur = cur->next; } } // Check which ones are linked in cur = module_head; last = 0; while (cur) { for (i = 0; i < __pz_builtin_number_of_init_functions; i++) { if (!strcmp (__pz_builtin_names[i], cur->name)) { cur->init = __pz_builtin_init_functions[i]; cur->to_load = -1; cur->ordered = 0; } } cur = cur->next; } // XXX. For now, we use a slow method for deps, and it'll crash // for circular deps. davidc__ is working on a // better solution. cur = module_head; while (cur) { add_deps (cur); cur = cur->next; } sliderVal = (MAXSLIDERVAL/SETUPSECTIONS) * 6; updateprogress(sliderwin, slider, sliderVal, _("Loading Modules"), NULL); struct dep *c = load_order; while (c) { if (c->mod->to_load > 0) { do_load (c->mod); } if( verbosity < VERBOSITY_ERRORS && c->mod->longname ) { updateprogress(sliderwin, slider, sliderVal, _("Loading Modules"), c->mod->longname ); } c = c->next; } c = load_order; sliderVal = 0; updateprogress(sliderwin, slider, sliderVal, _("Initializing Modules"), NULL); /* trigger the sliders to switch to init mode, restting the slider */ sliderVal = 0; /* initialize the modules */ while (c) { sliderVal += MAXSLIDERVAL / modCount; current_module = c->mod; updateprogress(sliderwin, slider, sliderVal, _("Initializing Modules"), (verbosity < 2)? c->mod->longname : NULL ); do_init (c->mod); c = c->next; } sliderVal = MAXSLIDERVAL; updateprogress(sliderwin, slider, sliderVal, _("Finishing Up..."), NULL); // Any modules with unrecoverable errors on loading set mod->to_free. // Oblige them. cur = module_head; last = 0; while (cur) { if (cur->to_free) { if (last) last->next = cur->next; else module_head = cur->next; free_module (cur); cur = last? last->next : module_head; } else { last = cur; cur = cur->next; } } ttk_free_window (sliderwin); }
static void find_modules (const char *dir) { char buf[256]; char *podpath = 0; struct dirent *d; struct stat st; PzModule *cur; DIR *dp; dp = opendir (dir); if (!dp) { pz_perror (dir); return; } while ((d = readdir (dp)) != NULL) { if (d->d_name[0] == '.') continue; podpath = malloc (strlen (dir) + strlen (d->d_name) + 2); sprintf (podpath, "%s/%s", dir, d->d_name); if (stat (podpath, &st) < 0) { pz_perror (podpath); free (podpath); continue; } if (S_ISDIR (st.st_mode)) { // Either a category dir (to search recursively) // or a module dir. Check for the `Module' file. sprintf (buf, "%s/" MODULE_INF_FILE, podpath); if (stat (buf, &st) < 0) { find_modules (podpath); free (podpath); continue; } // Module dir - fall through } else if (strcasecmp (d->d_name + strlen (d->d_name) - 4, ".pod") != 0) { // Non-pod file - ignore it free (podpath); continue; } if (module_head == 0) { cur = module_head = calloc (1, sizeof(PzModule)); } else { cur = module_head; while (cur->next) cur = cur->next; cur->next = calloc (1, sizeof(PzModule)); cur = cur->next; } cur->podpath = podpath; if ((stat (podpath, &st) >= 0) && S_ISDIR (st.st_mode)) cur->extracted = 1; cur->to_load = 1; cur->ordered = 0; cur->next = 0; } closedir (dp); }