OpenSource For You

Module parameters

-

(__ ksymtab), kernel string table (__ kstrtab), and kernel CRC table (__ kcrctab) sections, marking it to be globally accessible. Figure 1 shows a filtered snippet of the / proc/kallsyms kernel window, before and after loading the module our_glob_syms.ko, which has been compiled using the usual driver Makefile.

The following code shows the supporting header file ( our_glob_syms.h), to be included by modules using the exported symbols cool_cl and get_cool_cl: Being aware of passing command-line arguments to an applicatio­n, it would be natural to ask if something similar can be done with a module—and the answer is, yes, it can. Parameters can be passed to a module while loading it, for instance, when using insmod. Interestin­gly enough, and in contrast to the command-line arguments to an applicatio­n, these can be modified even later, through sysfs interactio­ns.

The module parameters are set up using the following macro (defined in <linux/modulepara­m.h>, included through <linux/module.h>): module_param(name, type, perm)

Here, name is the parameter name, type is the type of the parameter, and perm refers to the permission­s of the sysfs file correspond­ing to this parameter. The supported type values are: byte, short, ushort, int, uint, long, ulong, charp ( character pointer), bool or invbool ( inverted Boolean). The following module code ( module_ param. c) demonstrat­es a module parameter: #include <linux/module.h> #include <linux/kernel.h> static int cfg_value = 3; module_param(cfg_value, int, 0764); static int __init mod_par_init(void) { PRINTK(KERN_INFO “Loaded with %d\n”, cfg_value); return 0;

 ??  ?? Figure 3: Experiment­s with the module parameter (as root)
Figure 3: Experiment­s with the module parameter (as root)

Newspapers in English

Newspapers from India