Linux Module_param ()-Pass parameters to the module

Source: Internet
Author: User

1. Programming in user mode: Pass command-line arguments via main ()

Writing a kernel module: passing command-line arguments via Module_param ()


2. The Module_param macro is new in the Linux 2.6 kernel and is defined in the Include/linux/moduleparam.h file


3. Module_param uses 3 parameters: variable name, its type, and a permission mask to make an auxiliary SYSFS entry

Module_param (name, type, perm);

Name is both the parameter name that the user sees and the variable that accepts the parameter within the module;

Type represents the data type of the parameter, which is one of the following: Byte, short, ushort, int, uint, long, ulong, CHARP, BOOL, invbool;

PERM Specifies the access rights for the corresponding file in the SYSFS. Access permissions are managed in the same way as Linux files love your access rights, such as 0644, or using macros in stat.h such as S_irugo.


4. Before using a macro, you must declare a variable, typically with the following usage:

static unsigned int int_var = 0;

Module_param (Int_var, uint, s_irugo);


5. Declare an array parameter, using Module_param_array (name,type,num,perm);

Name is the array name (also the parameter name).

Type is an array of element types,

num is an integer variable,

Perm is the usual permission value.


6. Example: sudo insmdo module_param.ko who=tiger times=4


Refer:http://www.linuxidc.com/linux/2011-02/32131.htm

Linux Module_param ()-Pass parameters to the module

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.