实验09编写设备驱动程序.ppt

上传人:牧羊曲112 文档编号:6565433 上传时间:2023-11-13 格式:PPT 页数:8 大小:272.65KB
返回 下载 相关 举报
实验09编写设备驱动程序.ppt_第1页
第1页 / 共8页
实验09编写设备驱动程序.ppt_第2页
第2页 / 共8页
实验09编写设备驱动程序.ppt_第3页
第3页 / 共8页
实验09编写设备驱动程序.ppt_第4页
第4页 / 共8页
实验09编写设备驱动程序.ppt_第5页
第5页 / 共8页
点击查看更多>>
资源描述

《实验09编写设备驱动程序.ppt》由会员分享,可在线阅读,更多相关《实验09编写设备驱动程序.ppt(8页珍藏版)》请在三一办公上搜索。

1、实验内容,编写设备驱动程序,文件操作数据结构,struct file_operations int(*seek)(struct inode*,struct file*,off_t,int);int(*read)(struct inode*,struct file*,char,int);int(*write)(struct inode*,struct file*,off_t,int);int(*readdir)(struct inode*,struct file*,struct dirent*,int);int(*select)(struct inode*,struct file*,int,se

2、lect_table*);int(*ioctl)(struct inode*,struct file*,unsined int,unsigned long);int(*mmap)(struct inode*,struct file*,struct vm_area_struct*);int(*open)(struct inode*,struct file*);int(*release)(struct inode*,struct file*);int(*fsync)(struct inode*,struct file*);int(*fasync)(struct inode*,struct file

3、*,int);int(*check_media_change)(struct inode*,struct file*);int(*revalidate)(dev_t dev);,相关说明,这个结构的每一个成员的名字都对应着一个系统调用。用户进程利用系统调用在对设备文件进行诸如read/write操作时,系统调用通过设备文件的主设备号找到相应的设备驱动程序,然后读取这个数据结构相应的函数指针,接着把控制权交给该函数。这是linux的设备驱动程序工作的基本原理。所以,编写设备驱动程序的主要工作就是编写子函数,并填充file_operations的各个域。,mydevice.c程序示例,重新编译内核,把mydevice.c放在相应的字符设备驱动程序所在目录,并修改该目录的Makefile文件。,添加设备文件,mknod/dev/mydevice c 231 0,测试,main()int testdev;int i;char buf10;testdev=open(/dev/mydevice,O_RDWR);if(testdev=-1)printf(Cannt open file n);exit(0);read(testdev,buf,10);for(i=0;i close(testdev);编译运行,看看是不是打印出全1?,小结,

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号