主题 : 请教一下linux驱动的测试程序 复制链接 | 浏览器收藏 | 打印
级别: 侠客
UID: 16283
精华: 0
发帖: 67
金钱: 335 两
威望: 67 点
综合积分: 134 分
注册时间: 2010-03-16
最后登录: 2021-07-28
楼主  发表于: 2012-02-14 14:20

 请教一下linux驱动的测试程序

linux的系统调用是如下格式:
int (*open) (struct inode *, struct file *)而且设备驱动程序中的file_operations中的open对应函数的参数列表也是 (struct inode *, struct file *)
而在研究一个小小的驱动测试程序时,系统调用形式如下:
fd=open("/dev/drvtest",O_RDWR);
这个有点不明白,"/dev/drvtest"是上边的struct inode *参数吗?,
上边的O_RDWR是一个struct file *参数吗?

谢谢!
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
1楼  发表于: 2012-02-14 17:14

 回 楼主(xiaolubk) 的帖子

不是,open系统调用的参数如下(在命令行上用“man 2 open”获取)
int open(const char *pathname, int flags);

内核在处理这个系统调用时,会把从应用程序传进来的pathname,也就是"/dev/drvtest",转换成对应的struct inode结构指针,并且传递并调用驱动中定义的int (*open) (struct inode *, struct file *)回调函数
"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."