FreeBSD/sys/kern/kern_linker.c
/*
 * Find a file which contains given module and load it, if "parent" is not
 * NULL, register a reference to it.
 */
Find a file which contains given module and load it, if "parent" is not
NULL, register a reference to it.
Find a file which contains given module and load it if " parent " is not NULL register a reference to it .
static int
linker_load_module(const char *kldname, const char *modname,
    struct linker_file *parent, const struct mod_depend *verinfo,
    struct linker_file **lfpp)
{
	linker_file_t lfdep;
	const char *filename;
	char *pathname;
	int error;
	sx_assert(&kld_sx, SA_XLOCKED);
	if (modname == NULL) {
		KASSERT(verinfo == NULL, ("linker_load_module: verinfo"
		    " is not NULL"));
		pathname = linker_search_kld(kldname);
	} else {
		if (modlist_lookup2(modname, verinfo) != NULL)
			return (EEXIST);
		if (kldname != NULL)
			pathname = strdup(kldname, M_LINKER);
		else if (rootvnode == NULL)
			pathname = NULL;
		else
			pathname = linker_search_module(modname,
			    strlen(modname), verinfo);
	}
	if (pathname == NULL)
		return (ENOENT);
	filename = linker_basename(pathname);
	if (linker_find_file_by_name(filename))
		error = EEXIST;
	else do {
		error = linker_load_file(pathname, &lfdep);
		if (error)
			break;
		if (modname && verinfo &&
		    modlist_lookup2(modname, verinfo) == NULL) {
			linker_file_unload(lfdep, LINKER_UNLOAD_FORCE);
			error = ENOENT;
			break;
		}
		if (parent) {
			error = linker_file_add_dependency(parent, lfdep);
			if (error)
				break;
		}
		if (lfpp)
			*lfpp = lfdep;
	} while (0);
	free(pathname, M_LINKER);
	return (error);
}
static int linker_load_module ( const char * kldname , const char * modname , struct linker_file * parent , const struct mod_depend * verinfo , struct linker_file * * lfpp ) { linker_file_t lfdep ; const char * filename ; char * pathname ; int error ; sx_assert ( & kld_sx , SA_XLOCKED ) ; if ( modname == NULL ) { KASSERT ( verinfo == NULL , ( " " " " ) ) ; pathname = linker_search_kld ( kldname ) ; } else { if ( modlist_lookup2 ( modname , verinfo ) != NULL ) return ( EEXIST ) ; if ( kldname != NULL ) pathname = strdup ( kldname , M_LINKER ) ; else if ( rootvnode == NULL ) pathname = NULL ; else pathname = linker_search_module ( modname , strlen ( modname ) , verinfo ) ; } if ( pathname == NULL ) return ( ENOENT ) ; filename = linker_basename ( pathname ) ; if ( linker_find_file_by_name ( filename ) ) error = EEXIST ; else do { error = linker_load_file ( pathname , & lfdep ) ; if ( error ) break ; if ( modname && verinfo && modlist_lookup2 ( modname , verinfo ) == NULL ) { linker_file_unload ( lfdep , LINKER_UNLOAD_FORCE ) ; error = ENOENT ; break ; } if ( parent ) { error = linker_file_add_dependency ( parent , lfdep ) ; if ( error ) break ; } if ( lfpp ) * lfpp = lfdep ; } while ( 0 ) ; free ( pathname , M_LINKER ) ; return ( error ) ; }
Find a file which contains given module and load it, if "parent" is not
 NULL, register a reference to it.
Find a file which contains given module and load it if " parent " is not NULL register a reference to it .
/*
 		 * We have to load KLD
 		 */ /*
			 * Need to find a KLD with required module
			 */ /*
	 * Can't load more than one file with the same basename XXX:
	 * Actually it should be possible to have multiple KLDs with
	 * the same basename but different path because they can
	 * provide different versions of the same modules.
	 */