|
file_operations结构体中定义的函数ssize_t(*read) (struct file *, char __user *, size_t, loff_t *);
但在实际驱动定义的函数为static int xxx_read(struct file *filp, int __user *buff, size_t count, loff_t *offp)
(请注意:函数的第二个参数类型不一样,一个char,另一个int)。
在驱动xxx_read这个函数中将某一整型数据拷贝到用户空间buff中去,如下:
err = copy_to_user(buff,&values, min(sizeof(key_values), count));
上面实际编译中会出现警告如passing argument 2 of 'copy_to_user' discards qualifiers from pointer target type
warning: initialization from incompatible pointer type
忽略上面信息。。。
应用程序调用read函数,将相应的第二个参数定义为int型。。然后进行测试。。
通过printf可以查看内核驱动回传的数据。。。通过实验可以看到回传数据正确。。
如通过copy_to_user函数将0x183写入buff中,应用程序打印出来为0x183..
现有一个疑问:file_operations结构体定义的函数,其参数类型没有限制吗? |
|