nhmk/示例/0-hello/hello-5.c

68 lines
1.9 KiB
C
Raw Normal View History

2024-09-03 14:48:19 +08:00
/*
* hello-5.c -
*/
#include <linux/init.h>
#include <linux/kernel.h> /* 引入 ARRAY_SIZE() */
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/printk.h>
#include <linux/stat.h>
MODULE_LICENSE("GPL");
static short int myshort = 1;
static int myint = 420;
static long int mylong = 9999;
static char *mystring = "寻觅";
static int myintarray[2] = { 420, 420 };
static int arr_argc = 0;
/* module_param(foo, int, 0000)
* foo:
* int:
* 0000: , sysfs中的参数()
*/
module_param(myshort, short, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
MODULE_PARM_DESC(myshort, "一个短整数");
module_param(myint, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
MODULE_PARM_DESC(myint, "一个整数");
module_param(mylong, long, S_IRUSR);
MODULE_PARM_DESC(mylong, "一个长整数");
module_param(mystring, charp, 0000);
MODULE_PARM_DESC(mystring, "一个字符");
/* module_param_array(name, type, num, perm);
* name:
* type:
* num: ,
* perm:
*/
module_param_array(myintarray, int, &arr_argc, 0000);
MODULE_PARM_DESC(myintarray, "一组整数数组");
static int __init hello_5_init(void)
{
int i;
pr_info("你好 5\n=============\n");
pr_info("myshort是一个短整数: %hd\n", myshort);
pr_info("myint是一个整数: %d\n", myint);
pr_info("mylong是一个长整数: %ld\n", mylong);
pr_info("mystring是一个字符: %s\n", mystring);
for (i = 0; i < ARRAY_SIZE(myintarray); i++)
pr_info("myintarray[%d] = %d\n", i, myintarray[i]);
pr_info("从 myintarray 中获得 %d 个参数\n", arr_argc);
return 0;
}
static void __exit hello_5_exit(void)
{
pr_info("再见 5\n");
}
module_init(hello_5_init);
module_exit(hello_5_exit);