module name: params.ko
#include <linux/init.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/kernel.h>
#include <linux/stat.h>
MODULE_LICENSE("Dual BSD/GPL");
static char *mystring = "this is my char string";
module_param(mystring, charp, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(mystring, "A char string");
static int __init params_init(void)
{
printk("Driver is loaded\n");
printk(" My char string(mystring): %s\n", mystring);
return 0;
}
static void __exit params_exit(void)
{
printk("Driver is unloaded\n");
}
module_init(params_init);
module_exit(params_exit);
When I use the default setting, I can see the "this is my char string" when the driver is loaded.
However, if I use command line to pass the string with space, it will show up the following error:
Ex1:
# insmod ./params.ko mystring="Hello World"
insmod: error inserting './params.ko': -1 Unknown symbol in module
The dmesg shows up the following information:
params: Unknown parameter 'World'
Ex2:
# insmod ./params.ko mystring="HelloWorld"
If I use "HelloWorld" without space, there is no problem to show the string.
I also tried to use \ or ' ' to see if I can escape that space to ignore the space but in vain.
Would like to consult anyone who knows how to pass a string containing the space to the kernel module?
Thank you and appreciate your help.
# insmod: error inserting './params.ko': -1 Unknown symbol in module
dmesg output:params: Unknown parameter 'World'