FreeBSD/sys/kern/kern_linker.c
/*
 * This routine is responsible for finding dependencies of userland initiated
 * kldload(2)'s of files.
 */
This routine is responsible for finding dependencies of userland initiated
kldload(2)'s of files.
This routine is responsible for finding dependencies of userland initiated kldload ( 2 ) ' s of files .
int
linker_load_dependencies(linker_file_t lf)
{
	linker_file_t lfdep;
	struct mod_metadata **start, **stop, **mdp, **nmdp;
	struct mod_metadata *mp, *nmp;
	const struct mod_depend *verinfo;
	modlist_t mod;
	const char *modname, *nmodname;
	int ver, error = 0, count;
	sx_assert(&kld_sx, SA_XLOCKED);
	if (linker_kernel_file) {
		linker_kernel_file->refs++;
		error = linker_file_add_dependency(lf, linker_kernel_file);
		if (error)
			return (error);
	}
	if (linker_file_lookup_set(lf, MDT_SETNAME, &start, &stop,
	    &count) != 0)
		return (0);
	for (mdp = start; mdp < stop; mdp++) {
		mp = *mdp;
		if (mp->md_type != MDT_VERSION)
			continue;
		modname = mp->md_cval;
		ver = ((const struct mod_version *)mp->md_data)->mv_version;
		mod = modlist_lookup(modname, ver);
		if (mod != NULL) {
			printf("interface %s.%d already present in the KLD"
			    " '%s'!\n", modname, ver,
			    mod->container->filename);
			return (EEXIST);
		}
	}
	for (mdp = start; mdp < stop; mdp++) {
		mp = *mdp;
		if (mp->md_type != MDT_DEPEND)
			continue;
		modname = mp->md_cval;
		verinfo = mp->md_data;
		nmodname = NULL;
		for (nmdp = start; nmdp < stop; nmdp++) {
			nmp = *nmdp;
			if (nmp->md_type != MDT_VERSION)
				continue;
			nmodname = nmp->md_cval;
			if (strcmp(modname, nmodname) == 0)
				break;
		}
		if (nmdp < stop)
			continue;
		mod = modlist_lookup2(modname, verinfo);
		if (mod) {	
			lfdep = mod->container;
			lfdep->refs++;
			error = linker_file_add_dependency(lf, lfdep);
			if (error)
				break;
			continue;
		}
		error = linker_load_module(NULL, modname, lf, verinfo, NULL);
		if (error) {
			printf("KLD %s: depends on %s - not available or"
			    " version mismatch\n", lf->filename, modname);
			break;
		}
	}
	if (error)
		return (error);
	linker_addmodules(lf, start, stop, 0);
	return (error);
}
int linker_load_dependencies ( linker_file_t lf ) { linker_file_t lfdep ; struct mod_metadata * * start , * * stop , * * mdp , * * nmdp ; struct mod_metadata * mp , * nmp ; const struct mod_depend * verinfo ; modlist_t mod ; const char * modname , * nmodname ; int ver , error = 0 , count ; sx_assert ( & kld_sx , SA_XLOCKED ) ; if ( linker_kernel_file ) { linker_kernel_file -> refs ++ ; error = linker_file_add_dependency ( lf , linker_kernel_file ) ; if ( error ) return ( error ) ; } if ( linker_file_lookup_set ( lf , MDT_SETNAME , & start , & stop , & count ) != 0 ) return ( 0 ) ; for ( mdp = start ; mdp < stop ; mdp ++ ) { mp = * mdp ; if ( mp -> md_type != MDT_VERSION ) continue ; modname = mp -> md_cval ; ver = ( ( const struct mod_version * ) mp -> md_data ) -> mv_version ; mod = modlist_lookup ( modname , ver ) ; if ( mod != NULL ) { printf ( " " " \n " , modname , ver , mod -> container -> filename ) ; return ( EEXIST ) ; } } for ( mdp = start ; mdp < stop ; mdp ++ ) { mp = * mdp ; if ( mp -> md_type != MDT_DEPEND ) continue ; modname = mp -> md_cval ; verinfo = mp -> md_data ; nmodname = NULL ; for ( nmdp = start ; nmdp < stop ; nmdp ++ ) { nmp = * nmdp ; if ( nmp -> md_type != MDT_VERSION ) continue ; nmodname = nmp -> md_cval ; if ( strcmp ( modname , nmodname ) == 0 ) break ; } if ( nmdp < stop ) continue ; mod = modlist_lookup2 ( modname , verinfo ) ; if ( mod ) { lfdep = mod -> container ; lfdep -> refs ++ ; error = linker_file_add_dependency ( lf , lfdep ) ; if ( error ) break ; continue ; } error = linker_load_module ( NULL , modname , lf , verinfo , NULL ) ; if ( error ) { printf ( " " " \n " , lf -> filename , modname ) ; break ; } } if ( error ) return ( error ) ; linker_addmodules ( lf , start , stop , 0 ) ; return ( error ) ; }
This routine is responsible for finding dependencies of userland initiated
 kldload(2)'s of files.
This routine is responsible for finding dependencies of userland initiated kldload ( 2 ) ' s of files .
/*
	 * All files are dependent on /kernel.
	 */ /* early exit, it's a self reference */ /* woohoo, it's loaded already */