Add the ability to load klds from a floppy as part of the installation.

Submitted by:	"Daniel O'Connor" <doconnor@gsoft.com.au>
MFC after:	2 weeks
This commit is contained in:
Jordan K. Hubbard 2001-10-12 22:39:02 +00:00
parent 2bab9ad217
commit 513cce4025
5 changed files with 142 additions and 0 deletions

View file

@ -698,6 +698,16 @@ DMenu MenuNetworkDevice = {
{ { NULL } },
};
/* Prototype KLD load menu */
DMenu MenuKLD = {
DMENU_NORMAL_TYPE,
"KLD Menu",
"Load a KLD from a floppy\n",
NULL,
NULL,
{ { NULL } },
};
/* The media selection menu */
DMenu MenuMedia = {
DMENU_NORMAL_TYPE | DMENU_SELECTION_RETURNS,
@ -1263,6 +1273,8 @@ DMenu MenuConfigure = {
NULL, configXDesktop },
{ " HTML Docs", "Go to the HTML documentation menu (post-install)",
NULL, docBrowser },
{ " Load KLD", "Load a KLD from a floppy",
NULL, kldBrowser },
{ NULL } },
};

View file

@ -371,6 +371,7 @@ extern DMenu MenuFTPOptions; /* FTP Installation options */
extern DMenu MenuIndex; /* Index menu */
extern DMenu MenuOptions; /* Installation options */
extern DMenu MenuOptionsLanguage; /* Language options menu */
extern DMenu MenuKLD; /* Prototype KLD menu */
extern DMenu MenuMedia; /* Media type menu */
extern DMenu MenuMouse; /* Mouse type menu */
extern DMenu MenuMediaCDROM; /* CDROM media menu */
@ -674,6 +675,7 @@ extern char *sstrncpy(char *dst, const char *src, int size);
/* modules.c */
extern void moduleInitialize(void);
extern int kldBrowser(dialogMenuItem *self);
/* mouse.c */
extern int mousedTest(dialogMenuItem *self);

View file

@ -698,6 +698,16 @@ DMenu MenuNetworkDevice = {
{ { NULL } },
};
/* Prototype KLD load menu */
DMenu MenuKLD = {
DMENU_NORMAL_TYPE,
"KLD Menu",
"Load a KLD from a floppy\n",
NULL,
NULL,
{ { NULL } },
};
/* The media selection menu */
DMenu MenuMedia = {
DMENU_NORMAL_TYPE | DMENU_SELECTION_RETURNS,
@ -1263,6 +1273,8 @@ DMenu MenuConfigure = {
NULL, configXDesktop },
{ " HTML Docs", "Go to the HTML documentation menu (post-install)",
NULL, docBrowser },
{ " Load KLD", "Load a KLD from a floppy",
NULL, kldBrowser },
{ NULL } },
};

View file

@ -34,8 +34,14 @@
#include <sys/linker.h>
#include <fcntl.h>
#include <dirent.h>
#include <fcntl.h>
#include <fnmatch.h>
/* Prototypes */
static int kldModuleFire(dialogMenuItem *self);
#define MODULESDIR "/stand/modules"
#define DISTMOUNT "/dist"
void
moduleInitialize(void)
@ -89,3 +95,111 @@ moduleInitialize(void)
closedir(dirp);
}
}
int
kldBrowser(dialogMenuItem *self)
{
DMenu *menu;
int i, what = DITEM_SUCCESS, msize, count;
DIR *dir;
struct dirent *de;
char *err;
err = NULL;
if (DITEM_STATUS(mediaSetFloppy(NULL)) == DITEM_FAILURE) {
msgConfirm("Unable to set media device to floppy.");
what |= DITEM_FAILURE;
mediaClose();
return what;
}
if (!DEVICE_INIT(mediaDevice)) {
msgConfirm("Unable to mount floppy filesystem.");
what |= DITEM_FAILURE;
mediaClose();
return what;
}
msize = sizeof(DMenu) + (sizeof(dialogMenuItem) * 2);
count = 0;
if ((menu = malloc(msize)) == NULL) {
err = "Failed to allocate memory for menu";
goto errout;
}
bcopy(&MenuKLD, menu, sizeof(DMenu));
bzero(&menu->items[count], sizeof(menu->items[0]));
menu->items[count].prompt = strdup("X Exit");
menu->items[count].title = strdup("Exit this menu (returning to previous)");
menu->items[count].fire = dmenuExit;
count++;
if ((dir = opendir(DISTMOUNT)) == NULL) {
err = "Couldn't open directory";
goto errout;
}
while ((de = readdir(dir)) != NULL) {
if (fnmatch("*.ko", de->d_name, FNM_CASEFOLD))
continue;
msize += sizeof(dialogMenuItem);
if ((menu = realloc(menu, msize)) == NULL) {
err = "Failed to allocate memory for menu item";
goto errout;
}
bzero(&menu->items[count], sizeof(menu->items[0]));
menu->items[count].fire = kldModuleFire;
menu->items[count].prompt = strdup(de->d_name);
menu->items[count].title = menu->items[count].prompt;
count++;
}
closedir(dir);
menu->items[count].prompt = NULL;
menu->items[count].title = NULL;
dmenuOpenSimple(menu, FALSE);
mediaClose();
deviceRescan();
errout:
for (i = 0; i < count; i++)
free(menu->items[i].prompt);
free(menu);
if (err != NULL) {
what |= DITEM_FAILURE;
if (!variable_get(VAR_NO_ERROR))
msgConfirm(err);
}
return (what);
}
static int
kldModuleFire(dialogMenuItem *self) {
char fname[256];
bzero(fname, sizeof(fname));
snprintf(fname, sizeof(fname), "%s/%s", DISTMOUNT, self->prompt);
if (kldload(fname) < 0) {
if (!variable_get(VAR_NO_ERROR))
msgConfirm("Loading module %s failed\n", fname);
} else {
if (!variable_get(VAR_NO_ERROR))
msgConfirm("Loaded module %s OK", fname);
}
return(0);
}

View file

@ -371,6 +371,7 @@ extern DMenu MenuFTPOptions; /* FTP Installation options */
extern DMenu MenuIndex; /* Index menu */
extern DMenu MenuOptions; /* Installation options */
extern DMenu MenuOptionsLanguage; /* Language options menu */
extern DMenu MenuKLD; /* Prototype KLD menu */
extern DMenu MenuMedia; /* Media type menu */
extern DMenu MenuMouse; /* Mouse type menu */
extern DMenu MenuMediaCDROM; /* CDROM media menu */
@ -674,6 +675,7 @@ extern char *sstrncpy(char *dst, const char *src, int size);
/* modules.c */
extern void moduleInitialize(void);
extern int kldBrowser(dialogMenuItem *self);
/* mouse.c */
extern int mousedTest(dialogMenuItem *self);