ioctl的问题:
驱动程序编译时出现error: unknown field 'ioctl' specified in initializer
于是百度,找原因
在linux-2.6.36内核上加载编译驱动时,出现
error:unknown field 'ioctl' specified in initializer
原因是:在2.6.36内核上file_operations发生了重大的改变:
原先的
int (*ioctl)(struct inode*, struct file*, unsigned int, unsigned long);
被改为了
long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
long (*compat_ioctl) (struct file *, unsigned int, unsigned long);
因而在实际驱动中,我们需要将原先的写的ioctl函数头给改成下面的unlocked_ioctl,在file_operations结构体的填充中也是一样。
按上面说的修改驱动中的代码:
static int beep_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
{
//add your src HERE!!!
switch ( cmd ) {
case BEEP_START_CMD: {
beep_start(); break;
}
case BEEP_STOP_CMD: {
beep_stop(); break;
}
default: {
break;
}
}
return 0;
}
static struct file_operations beep_remap_ops = {
.owner = THIS_MODULE,
.open = beep_open,
.release = beep_release,
.read = beep_read,
.write = beep_write,
.ioctl = beep_ioctl,
};
上面两个函数修改成下面的样子:
static int beep_ioctl( struct file *file, unsigned int cmd, unsigned long arg)
{
//add your src HERE!!!
switch ( cmd ) {
case BEEP_START_CMD: {
beep_start(); break;
}
case BEEP_STOP_CMD: {
beep_stop(); break;
}
default: {
break;
}
}
return 0;
}
static struct file_operations beep_remap_ops = {
.owner = THIS_MODULE,
.open = beep_open,
.release = beep_release,
.read = beep_read,
.write = beep_write,
.unlocked_ioctl = beep_ioctl,
};
修改以上红色部分,再次编译就OK了