gpt4 book ai didi

linux - lsmod 显示模块被-2使用

转载 作者:太空宇宙 更新时间:2023-11-04 11:09:47 25 4
gpt4 key购买 nike

我正在尝试使用以下代码传递命令行参数

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/moduleparam.h>

static int nilvar=0;
static int nilvar2=0;
int rollcalls[5];// = {0};
char classname[10];// = "math";

module_param_named (var,nilvar2,int,0644);
module_param (nilvar,int,0644);
module_param_array_named(present,rollcalls,int,5,0644);
module_param_string(subject,classname,10,0644);

int init_module(void)
{
printk(KERN_INFO"1) nilvar = %d\n 2) nilvar2 = %d",nilvar,nilvar2);
printk(KERN_INFO/*NOTICE*/"ROLLCALLS = %d ,%d ,%d ,%d",rollcalls[0],rollcalls[1],rollcalls[2],rollcalls[3]);
printk(KERN_INFO/*DEBUG*/"classname = %s",classname);
return 0;
}

void cleanup_module(void)
{
printk(KERN_INFO "Bye....\n");
}

MODULE_LICENSE("GPL");

在 make 之后,我正在传递我的论点

insmod module1.ko var=5 nilvar=6 present=1 2 3 4 subject=physics

我不知道到底发生了什么,但现在 lsmod 显示了 -2 使用的模块。(实际上没有模块依赖这个模块)

所以我哪里错了?如果我们想将所有这些变量修改为结构元素,那么如何使用 module_param() 宏呢?

最佳答案

@user3452214,而不是 module_param_array_named(present, rollcalls, int, **5**, 0644); 使用 module_param_array_named(present, rollcalls, int, **&count**, 0644); 又添加了一个变量,即 static unsigned int count,它对写入数组的数字进行计数。我们需要按照 moduleparam.h 中的说明传递指针,因此不能为该参数传递数值。它工作正常!希望它能解决您的问题。

/**
* module_param_array_named - renamed parameter which is an array of some type
* @name: a valid C identifier which is the parameter name
* @array: the name of the array variable
* @type: the type, as per module_param()
* @nump: optional pointer filled in with the number written
* @perm: visibility in sysfs
*
* This exposes a different name than the actual variable name. See
* module_param_named() for why this might be necessary.
*/
#define module_param_array_named(name, array, type, nump, perm)

关于linux - lsmod 显示模块被-2使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23723972/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com