You are not logged in.
I am tring to compile a demo device module, here is part of my demo.c:
struct file_operations DEMO_fops = {
.owner = THIS_MODULE,
.llseek = DEMO_llseek,
.read = DEMO_read,
.write = DEMO_write,
.ioctl = DEMO_ioctl,
//.unlocked_ioctl = DEMO_ioctl,
//.compat_ioctl = DEMO_ioctl,
.open = DEMO_open,
.release = DEMO_release,
};And here is the error message:
error: unknown field ‘ioctl’ specified in initializerAfter searching I found this post, so I tried to replace .ioctl with .unlocked_ioctl and .compat_ioctl. Then the compiling succeeded. However, when I try to run the test file:
int main()
{
int fd;
int i;
char data[256];
int len = sizeof(STRING);
int retval;
fd=open("/dev/devdemo",O_RDWR);
if(fd==-1)
{
perror("error open\n");
exit(-1);
}
printf("open /dev/devdemo successfully\n");
retval=ioctl(fd,COMMAND1,0);
if(retval==-1)
{
perror("ioctl error\n");
exit(-1);
}
printf("send command1 successfully\n");
retval=write(fd,STRING,len);
if(retval==-1)
{
perror("write error\n");
exit(-1);
}
retval=lseek(fd,0,0);
if(retval==-1)
{
perror("lseek error\n");
exit(-1);
}
retval=read(fd,data,len);
if(retval==-1)
{
perror("read error\n");
exit(-1);
}
printf("read successfully:%s\n",data);
close(fd);
}Here is the message using .unlocked_ioctl:
ioctl error
: Bad addressAnd here the message using .compat_ioctl:
ioctl error
: Inappropriate ioctl for deviceAt last, I am using Arch Linux with kernel version linux-3.9.4-1-ARCH.
Last edited by Elderry (2013-06-04 13:58:07)
Offline