设备管理与模块机制ppt.ppt
《设备管理与模块机制ppt.ppt》由会员分享,可在线阅读,更多相关《设备管理与模块机制ppt.ppt(26页珍藏版)》请在三一文库上搜索。
1、Linux Device & Module,设备管理与模块机制,基本概念 传统方式的设备注册与管理 devfs注册与管理 块设备的请求队列 网络设备 模块机制,Linux Device & Module,基本概念,字符设备、块设备、网络设备 字符设备以字节为单位进行数据处理,通常只允许按顺序访问 块设备将数据按可寻址的块为单位进行处理,可以随机访问,利用缓冲技术 网络设备是一类特殊的设备,每块网卡有名字但没有设备文件与之对应 查看系统中的设备:/proc/devices 主设备号和次设备号 major number:相同的设备使用相同的驱动程序 minor number:用来区分具体设备的实例
2、 查看设备及其类型“ls -l /dev” 设备文件系统devfs /dev目录过于庞大,很多设备文件没有对应系统中的设备 devfs根据系统中的实际设备构建设备文件,并按目录存放,如/dev/disk,/dev/pts,Linux Device & Module,基本概念,Linux Device & Module,基本概念,建立设备: #mknod /dev/dev_name type major_number minor_number,Linux Device & Module,VFS中的文件,include/linux/fs.h struct file struct file_oper
3、ations *f_op; ; struct file_operations loff_t (*llseek)(struct file *,loff_t,int); ssize_t (*read)(struct file *,char *,size_t,loff_t *); ssize_t (*write)(struct file *,const char *,size_t,loff_t *); int(*ioctl) (struct inode *,struct file *,unsigned int,unsigned long); int(*mmap) (struct file *,str
4、uct vm_area_struct *); int(*open) (struct inode *,struct file *); int(*release) (struct inode *,struct file *); int(*fsync) (struct file *,struct dentry *,int datasync); int(*fasync) (int,struct file *,int); ;,Linux Device & Module,(1) llseek(file, offset, whence):修改文件的读写指针。 (2) read(file, buf, coun
5、t, offset):从设备文件的offset 处开始读出count个字节,然后增加*offset的值。 (3) write(file, buf, count, offset):从设备文件的offset处写入count个字节,然后增加*offset的值。 (4) ioctl(inode, file, cmd, arg):向一个硬件设备发命令,对设备进行控制。 (5) mmap(file, vma):将设备空间映射到进程地址空间。 (6) open(inode, file):打开并初始化设备。 (7) release(inode, file):关闭设备并释放资源。 (8) fsync(file,
6、 dentry):实现内存与设备之间的同步通信。 (9) fasync(file, on):实现内存与设备之间的异步通信。,Linux Device & Module,fs/devices.c struct device_struct const char * name; struct file_operations * fops; ; static struct device_struct chrdevsMAX_CHRDEV; 注册与注销函数: int register_chrdev(unsigned int major, const char * name, struct file_ope
7、rations *fops) int unregister_chrdev(unsigned int major, const char * name); 注:major即设备的主设备号,注册后就是访问数组chrdevs的索引(下标)。,字符设备的注册与管理,Linux Device & Module,PCI设备(驱动实现见word文档),Linux内核启动时会对所有PCI设备进行扫描、登录和分配资源等初始化操作,建立起系统中所有PCI设备的拓扑结构 此后当内核欲初始化某设备时,调用module_init加载该设备的驱动程序,Linux Device & Module,块设备,fs/block_
8、dev.c static struct const char *name; struct block_device_operations *bdops; blkdevsMAX_BLKDEV;,Linux Device & Module,块设备注册,fs/block_dev.c register_blkdev(unsigned int major,const char *name, struct block_device_operations *bdops) int unregister_blkdev(unsigned int major, const char * name),Linux De
9、vice & Module,块设备的操作block_device_operations,struct block_device_operations int (*open) (struct inode *, struct file *); int (*release) (struct inode *, struct file *); int (*ioctl) (struct inode *, struct file *, unsigned, unsigned long); int (*check_media_change) (kdev_t); int (*revalidate) (kdev_t
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 设备管理 模块 机制 ppt
链接地址:https://www.31doc.com/p-3497723.html