On 9/10/09, Michal Marek <[email protected]> wrote:
> The kernel installs a modules.builtin file listing all builtin
> modules. Let depmod generate a modules.builtin.bin file and use
> this in modprobe: If a module is not found in modules.dep or
> modules.alias, check if the module is builtin and either do nothing,
> or print "builtin <module>" if --show-depends was given.
>
> Signed-off-by: Michal Marek <[email protected]>
> ---
> depmod.c | 46 +++++++++++++++++++++++++++++++++++++++++++++-
> modprobe.c | 31 +++++++++++++++++++++++++++++++
> 2 files changed, 76 insertions(+), 1 deletions(-)
>
> diff --git a/depmod.c b/depmod.c
> index 3ac5070..43ff28f 100644
> --- a/depmod.c
> +++ b/depmod.c
> @@ -825,6 +825,49 @@ static int output_symbols_bin(struct module *unused,
> FILE *out, char *dirname)
> return 1;
> }
>
> +static int output_builtin_bin(struct module *unused, FILE *out, char
> *dirname)
> +{
> + struct index_node *index;
> + char *textfile, *line;
> + unsigned int linenum;
> + FILE *f;
> +
> + nofail_asprintf(&textfile, "%s/modules.builtin", dirname);
> + if (!(f = fopen(textfile, "r"))) {
> + if (errno != ENOENT)
> + fatal("Could not open '%s': %s\n",
> + textfile, strerror(errno));
> + free(textfile);
> + return 0;
> + }
> + free(textfile);
> + index = index_create();
> +
> + while ((line = getline_wrapped(f, &linenum)) != NULL) {
> + char *module = strrchr(line, '/');
> +
> + if (!*line || *line == '#') {
> + free(line);
> + continue;
> + }
> + module = strrchr(line, '/');
this duplicates the assignment in the declaration of module. But I
wonder why this whole chunk of code is needed...
> + if (module)
> + module++;
> + else
> + module = line;
> + if (ends_in(module, ".ko"))
> + module[strlen(module) - 3] = '\0';
> + underscores(module);
...because we already have filename2modname(). I think you can just
do filename2modname(module, module).
> + index_insert(index, module, "", 0);
> + free(line);
> + }
> + fclose(f);
> + index_write(index, out);
> + index_destroy(index);
> +
> + return 1;
> +}
> +
> static int output_aliases(struct module *modules, FILE *out, char *dirname)
> {
> struct module *i;
> @@ -1331,6 +1349,19 @@ int do_modprobe(char *modname,
> modname, 0, flags & mit_remove,
> &modoptions, &commands,
> &aliases, &blacklist);
> + /* builtin module? */
> + if (!aliases && !(flags & mit_remove) &&
> + module_builtin(dirname, modname) == 1) {
> + if (flags & mit_first_time) {
> + error("Module %s already in kernel
> (builtin).\n",
> + modname);
> + return 1;
> + } else if (flags & mit_ignore_loaded) {
> + /* --show-depends given */
> + info("builtin %s\n", modname);
> + }
> + return 0;
> + }
Better.
Let's see, if mit_remove is set, we treat it as a normal module, find
that it is not present, and return success. "modprobe -r --first-time
$builtin-module" will fail as expected... but the error message will
be wrong
"FATAL: Module $builtin-module is not in kernel."
How about this (not tested, may exceed 80 cols):
if (!aliases &&
module_builtin(dirname, modname) == 1) {
if (flags & mit_remove) {
if (flags & mit_first_time)
error("Module %s is builtin\n",
modname);
return 1;
} else if (flags & mit_first_time) {
error("Module %s already in kernel
(builtin).\n",
modname);
return 1;
} else if (flags & mit_ignore_loaded) {
/* --show-depends given */
info("builtin %s\n", modname);
}
return 0;
}
Regards
Alan
--
To unsubscribe from this list: send the line "unsubscribe linux-modules" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html