static struct file_operations my_fops =
{
.unlocked_ioctl = my_ioctl, error is here. I can not fix this.
};
注意:请忽略我的所有print_k。
请帮我解决这个问题。我感谢你们所有人。
这里是我的代码:
static long my_ioctl(struct file *f,unsigned int cm,unsigned long arg[b])
{
int re;
unsigned long arg[3];
switch (cm)
{
case H_ADD:
arg[2] = arg[0] + arg[1];
print_k("Driver:Calculating is complete,Result = %d \n",arg[2]);
break;
case H_SUB:
print_k ("Driver: Start ...\n");
arg[2] = arg[0] - arg[1];
print_k("Driver:Calculating is complete,Result = %d \n",arg[2]);
break;
case H_MULL:
print_k ("Driver: Start ...\n");
arg[2] = arg[0] * arg[1];
print_k("Driver:Calculating is complete,Result = %d \n",arg[2]);
break;
case H_DIV:
print_k ("Driver: Start ...\n");
arg[2] = arg[0]/arg[1];
print_k("Driver:Calculating is complete,Result = %d \n",arg[2]);
break;
default:
print_k ("Driver: I don't have this operation!\n");
re = -Er;
break;
}
return re;
}
static struct file_operations my_fops =
{
.unlocked_ioctl = my_ioctl,
};
+1
'static long my_ioctl(struct file * f,unsigned int cm,unsigned long arg [b])'是错误的。最后一个参数必须是'unsigned long arg'而不是'arg [b]'。如果你的最后一个参数被设计成一个指向某种数组的指针,你需要在*你的函数中相应地转换它*。 –
+3
我已修复格式(使代码可读) –
+1
嗨@BronislavElizavetin谢谢你的回答。我对最后一个论点感到抱歉。这是一个错误。它是unsigned long arg [],我做了一些测试,它的工作原理比内核版本4.8低。不幸的是,它不适用于我自己的Linux内核版本4.8 -64位。 –