Linux Kernel module programming source code example-startup parameters-general Linux technology-Linux programming and kernel information, the following is a detailed description.
Startup parameters
In many examples above, we have to hard write something like a kernel module, such as a file name in/proc or the device's master device number, so we can use ioctl for it. This is in conflict with the flexible program spirit that can be customized by users who write Unix and Linux.
Before a program or kernel module can start to work, you can tell it something you need through command line parameters. In the case of kernel modules, we cannot get the replacement of argc and argv. We get better things. We can define global variables in the kernel module and insmod will fill them for us.
In this kernel module, we define two: str1 and str2. All you need to do is compile the kernel module and run it with insmod str1 = xxx str2 = yyy. When the init_module is called, str1 points to the string 'xxx', and str2 points to 'yyy '.
These parameters 2.0 are not checked for type in version 6.1. If the first character of str1 or str2 is a number, the kernel fills the variable with an integer instead of a string pointer. In actual situations, you need to check this.
On the other hand, in version 2.2, you use the macro MACRO_PARM to tell insmod that you expect a parameter, its name and type. This solves the type problem and allows the kernel module to receive strings starting with numbers.
Example: param. c