Linux实用教程 Linux设备管理与模块机制.pptxVIP

  • 3
  • 0
  • 约1.6千字
  • 约 26页
  • 2021-10-19 发布于重庆
  • 举报

Linux实用教程 Linux设备管理与模块机制.pptx

设备管理与模块机制;基本概念;基本概念;基本概念;VFS中的文件;(1) llseek(file, offset, whence):修改文件的读写指针。 (2) read(file, buf, count, 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, dentry):实现内存与设备之间的同步通信。 (9) fasync(file, on):实现内存与设备之间的异步通信。;fs/devices.c struct device_struct { const char * name; struct file_operations * fops; }; static struct device_struct chrdevs[MAX_CHRDEV]; 注册与注销函数: int register_chrdev(unsigned int major, const char * name, struct file_operations *fops) int unregister_chrdev(unsigned int major, const char * name); 注:major即设备的主设备号,注册后就是访问数组chrdevs的索引(下标)。;PCI设备(驱动实现见word文档);块设备;块设备注册;块设备的操作block_device_operations;block_device_operations{}并不能完全提供file_operations结构中的所必需的主要函数(例如read、write),所以内核实际上是采用def_blk_fops变量对相关的file_operations{}变量进行了赋值: struct file_operations def_blk_fops ; 除了open、release等函数利用了设备注册时提供的block_device_operations{}结构中的成员变量之外,其他函数都是采用所有块设备通用的操作函数(def_blk_fops{});fs/block_dev.c struct file_operations def_blk_fops = { open: blkdev_open, release: blkdev_close, llseek: block_llseek, read: generic_file_read, write: generic_file_write, mmap: generic_file_mmap, fsync: block_fsync, ioctl: blkdev_ioctl, }; ;block_read与block_write等函数是设备相关的 块设备注册时一个重要的任务就是提供这个设备相关的操作函数给内核;devfs注册与管理;块设备的请求队列;block_read()流程;Linux网络协议栈;重要的数据结构;模块机制(Module);模块的设计;模块的设计;模块设计注意事项;模块调试;/proc/pid/下文件、目录的意义;SGI公司OSS项目的kgdb

文档评论(0)

1亿VIP精品文档

相关文档