【发布时间】:2012-11-29 15:47:54
【问题描述】:
我一直在为 linux 内核编写一个字符设备模块,结果有点困惑。
我在网上看到有人谈论使用ioctl() 将命令/数据从用户程序传输到内核空间,反之亦然。但是,用file_operations struct 做已经可以做的事情似乎有些过头了
// structure containing callbacks
static struct file_operations fops =
{
.read = dev_read, // address of dev_read
.open = dev_open, // address of dev_open
.write = dev_write, // address of dev_write
.release = dev_rls, // address of dev_rls
};
使用ioctl() 而不是使用在dev_read() 和dev_write() 定义的函数有什么好处,这些函数只需使用copy_to_user() 和copy_from_user() 将数据块复制到用户空间或从用户空间复制数据块?
【问题讨论】:
标签: c linux-kernel operating-system driver