Pass a string parameter with space character to kernel module
When you run insmod ./params.ko mystring="Hello World"
your quotes are eaten by the shell and the insmod binary has the string mystring=Hello World
as the parameter. It passes it to the kernel as is, and then it all goes down to the kernel parse_args
function (in kernel/params.c
), which, in turn, calls next_arg
to split the next parameter into name and value.
It definitely can handle spaces, as we see the following comment in the code:
/* You can use " around spaces, but can't escape ". *//* Hyphens and underscores equivalent in parameter names. */
and the following conditional statement:
static char *next_arg(char *args, char **param, char **val){ ... for (i = 0; args[i]; i++) { if (isspace(args[i]) && !in_quote) break; ...}
So the idea is that you need to pass the quotes to the kernel, not to the shell.Don't have a linux box to check the kernel module insertion right now, but I guess the following command will work:
# insmod ./params.ko mystring='"Hello World"'
Here the shell will consume the single quotes, and the parameter for insmod
binary will be mystring="Hello World"
so these quotes will be passed to kernel as is, which will make it possible to parse the value as you expect. Try that, should work.