主题 : 驱动程序的读写与应用程序的读写? 复制链接 | 浏览器收藏 | 打印
级别: 侠客
UID: 25552
精华: 0
发帖: 64
金钱: 320 两
威望: 64 点
综合积分: 128 分
注册时间: 2010-07-26
最后登录: 2011-01-04
楼主  发表于: 2010-08-07 08:40

 驱动程序的读写与应用程序的读写?

驱动程序的读写和应用程序的读写是怎么联系起来的,参数都对应不起来?
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
1楼  发表于: 2010-08-07 10:06
通过一个叫"系统调用"的东西
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
级别: 侠客
UID: 25552
精华: 0
发帖: 64
金钱: 320 两
威望: 64 点
综合积分: 128 分
注册时间: 2010-07-26
最后登录: 2011-01-04
2楼  发表于: 2010-08-07 10:49
能详细的说明下吗,或者哪本书对这个讲得比较详细的!
谢了
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
3楼  发表于: 2010-08-07 15:04
引用第2楼0o龙i魂o0于2010-08-07 10:49发表的  :
能详细的说明下吗,或者哪本书对这个讲得比较详细的!
谢了

基本上设备驱动相关的系统调用(open(), close(), read(), write(), lseek(), ioctl() ...)和你的设备所属的驱动的file_operations结构里的成员函数指针是一一对应的。比如系统调用ssize_t read(int fd, void *buf, size_t count)和驱动file_operations里的ssize_t (*read) struct file * file, char __user * buf, size_t count, loff_t *ppos),基本上,void *buf <--> char __user *buf, size_t count <-->size_t count。loff_t *ppos是由lseek()系统调用指定的文件pos。

要深入理解系统调用和内核的关系,建议你看一下"Understanding the Linux Kernel, 3rd edition"的第10章“System Calls”
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
级别: 侠客
UID: 25552
精华: 0
发帖: 64
金钱: 320 两
威望: 64 点
综合积分: 128 分
注册时间: 2010-07-26
最后登录: 2011-01-04
4楼  发表于: 2010-08-08 10:12

 回 3楼(kasim) 的帖子

谢了