Deleted Added
full compact
26c26
< * $Id: module.c,v 1.2 1998/08/31 21:10:42 msmith Exp $
---
> * $Id: module.c,v 1.3 1998/09/03 02:10:08 msmith Exp $
31,33d30
< *
< * XXX need a 'searchmodule' function that takes a name and
< * traverses a search path.
42a40
> static char *mod_searchfile(char *name);
46c44
< /* XXX load address should be tweaked by first module loaded (kernel) */
---
> /* load address should be tweaked by first module loaded (kernel) */
48a47,48
> static char *default_searchpath ="/;/boot";
>
234,236c234,240
< /* Try to come up with a fully-qualified name if we don't have one */
< if ((cp = mod_searchmodule(name)) != NULL)
< name = cp;
---
> /* locate the file on the load path */
> cp = mod_searchfile(name);
> if (cp == NULL) {
> sprintf(command_errbuf, "can't find '%s'", name);
> return(CMD_ERROR);
> }
> name = cp;
285,287c289,296
< /* Try to come up with a fully-qualified name if we don't have one */
< if ((cp = mod_searchmodule(name)) != NULL)
< name = cp;
---
> /* locate the module on the search path */
> cp = mod_searchmodule(name);
> if (cp == NULL) {
> sprintf(command_errbuf, "can't find '%s'", name);
> return(NULL);
> }
> name = cp;
>
425c434
< * Attempt to locate a kernel module file for the module (name).
---
> * Attempt to find the file (name) on the module searchpath.
435c444
< mod_searchmodule(char *name)
---
> mod_searchfile(char *name)
438c447
< static char *defpath = "/boot", *path;
---
> char *path;
461c470
< cp = defpath;
---
> cp = default_searchpath;
470,472c479,486
< result = malloc(strlen(cp) + strlen(name) + 2);
< sprintf(result, "%s/%s", cp, name);
< if (stat(result, &sb) == 0)
---
> result = malloc(strlen(cp) + strlen(name) + 5);
> strcpy(result, cp);
> if (cp[strlen(cp) - 1] != '/')
> strcat(result, "/");
> strcat(result, name);
> /* printf("search '%s'\n", result); */
> if ((stat(result, &sb) == 0) &&
> S_ISREG(sb.st_mode))
481a496,517
> * Attempt to locate the file containing the module (name)
> */
> static char *
> mod_searchmodule(char *name)
> {
> char *tn, *result;
>
> /* Look for (name).ko */
> tn = malloc(strlen(name) + 3);
> strcpy(tn, name);
> strcat(tn, ".ko");
> result = mod_searchfile(tn);
> free(tn);
> /* Look for just (name) (useful for finding kernels) */
> if (result == NULL)
> result = mod_searchfile(name);
>
> return(result);
> }
>
>
> /*
489,500c525,538
< while (mp->m_metadata != NULL) {
< md = mp->m_metadata;
< mp->m_metadata = mp->m_metadata->md_next;
< free(md);
< }
< if (mp->m_name != NULL)
< free(mp->m_name);
< if (mp->m_type != NULL)
< free(mp->m_type);
< if (mp->m_args != NULL)
< free(mp->m_args);
< free(mp);
---
> if (mp != NULL) {
> while (mp->m_metadata != NULL) {
> md = mp->m_metadata;
> mp->m_metadata = mp->m_metadata->md_next;
> free(md);
> }
> if (mp->m_name != NULL)
> free(mp->m_name);
> if (mp->m_type != NULL)
> free(mp->m_type);
> if (mp->m_args != NULL)
> free(mp->m_args);
> free(mp);
> }
503a542,557
> * Allocate a new module; must be used instead of malloc()
> * to ensure safe initialisation.
> */
> struct loaded_module *
> mod_allocmodule(void)
> {
> struct loaded_module *mp;
>
> if ((mp = malloc(sizeof(struct loaded_module))) != NULL) {
> bzero(mp, sizeof(struct loaded_module));
> }
> return(mp);
> }
>
>
> /*