与 Linux 中的设备对话。写功能
我正在尝试编写一个简单的设备驱动程序,并使用我已经定义的 Dev_Read() 和 Dev_Write() 函数。 我的驱动程序注册了一个与 以这种方式给定主编号
# mknod /dev/mydev c 250 0
然后,
int fd;
if ((fd = open("/dev/mydev", O_RDWR)) < 0)
{
perror("open /dev/mydev");
exit(EXIT_FAILURE);
}
在调用 Read() 函数
int read_bytes = read (fd, buffer, 1);
并成功获取内核空间信息后,从我的用户程序中我以这种方式打开设备,即我的 Dev_Read功能有效。 我的问题是我不明白如何实现我的 Dev_Write 函数。 如何向我的文件写入一些内容,以查看 Dev_Write 函数是否有效? 谢谢您的帮助。
I'm trying to write a simple device driver, and use the Dev_Read() and Dev_Write() functions, which I have already defined.
My driver registers a character device tied to a
given major number this way
# mknod /dev/mydev c 250 0
And then, from my user program I open the device this way
int fd;
if ((fd = open("/dev/mydev", O_RDWR)) < 0)
{
perror("open /dev/mydev");
exit(EXIT_FAILURE);
}
after I invoke the Read() function
int read_bytes = read (fd, buffer, 1);
and successfully get kernel space information, that my Dev_Read function works.
My problem is that I don't understand how to implement my Dev_Write function.
How can I write someting to my file, to see that Dev_Write function works ?
THANK YOU for help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
了解您尝试过哪些方法无效会有所帮助。
需要注意的一件事(不一定直观)是驱动程序的写入函数必须将写入缓冲区从调用者空间复制到内核空间。可以在 http://www.freesoftwaremagazine.com/articles/drivers_linux< 的教程中查看示例。 /a> -
其中
memory_buffer
是您在驱动程序中分配的空间。It would help to know what you've tried which didn't work.
One thing to be aware of, and not necessarily intuitive, is that your driver's write function must copy the write buffer from the caller's space into kernel space. An example of that can be seen in the tutorial at http://www.freesoftwaremagazine.com/articles/drivers_linux -
where
memory_buffer
is space you've allocated within your driver.