当前位置: 首页 > news >正文

file_operations结构2

  对与应用层的每个系统调用,驱动程序都有一个与之对应的函数.对于字符设备驱动程序,这些函数集合在一个file_operations类型的数据结构中,该结构体在Linux内核的include/linux/fs.h文件中定义.

struct file_operations {
      struct module *owner;
      loff_t (*llseek) (struct file *, loff_t, int);
      ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
      ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
      ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t);
      ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t);
      int (*readdir) (struct file *, void *, filldir_t);
      unsigned int (*poll) (struct file *, struct poll_table_struct *);
      int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long);
      long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
      long (*compat_ioctl) (struct file *, unsigned int, unsigned long);
      int (*mmap) (struct file *, struct vm_area_struct *);
      int (*open) (struct inode *, struct file *);
      int (*flush) (struct file *, fl_owner_t id);
      int (*release) (struct inode *, struct file *);
      int (*fsync) (struct file *, struct dentry *, int datasync);
      int (*aio_fsync) (struct kiocb *, int datasync);
      int (*fasync) (int, struct file *, int);
      int (*lock) (struct file *, int, struct file_lock *);
      ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
      unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
      int (*check_flags)(int);
      int (*flock) (struct file *, int, struct file_lock *);
      ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
      ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
      int (*setlease)(struct file *, long, struct file_lock **);
};

      当应用程序使用open、read、write、ioctl等系统调用时,驱动程序的file_operations结构体中的成员函数就会被调用.从这个角度来说,编写字符设备驱动程序就是为具体的硬件的file_operations结构体编写各个函数(并不需要全部实现该结构体中的成员).

      在字符驱动程序中有一个初始化函数,在安装驱动程序时会调用它.在初始化函数中,会将驱动程序的file_operations结构体连同其主设备号一起向内核进行注册.对与字符设备使用如下函数进行注册:

      int register_chrdev(unsigned int major ,const char *name ,struct file_operations *fops)

      这样,内核通过/dev目录下的设备文件名找到该设备的主设备号和file_operations结构体,从而找到了系统调用所对应的驱动函数.因此,当应用层使用系统调用函数时,内核就通过这种方法找到了相应的驱动函数.

转载于:https://www.cnblogs.com/Ph-one/p/4670807.html

相关文章:

  • file_operations结构体解析 1
  • 内核驱动中常见的miscdevice、platform_device、platform_driver
  • rc522 ,pn544区别
  • platform_driver与file_operations两种方法开发led驱动
  • misc_register、 register_chrdev 的区别总结
  • linux设备驱动那点事儿之平台设备理论篇
  • linux多线程驱动中调用udelay()对整个系统造成的影响(by liukun321咕唧咕唧)...
  • udelay、mdelay、ndelay、msleep使用比较说明
  • A8下超级终端调试问题
  • Linux多线程编程(不限Linux)转
  • Linux 线程优先级
  • 男儿当自强
  • JNI编程(一) —— 编写一个最简单的JNI程序
  • JNI编程(二) —— 让C++和Java相互调用(1)
  • JNI编程(二) —— 让C++和Java相互调用(2)
  • @jsonView过滤属性
  • 10个确保微服务与容器安全的最佳实践
  • CentOS7简单部署NFS
  • es6--symbol
  • fetch 从初识到应用
  • golang 发送GET和POST示例
  • Javascripit类型转换比较那点事儿,双等号(==)
  • JSONP原理
  • MySQL几个简单SQL的优化
  • Promise面试题,控制异步流程
  • Redis 懒删除(lazy free)简史
  • Spring Boot MyBatis配置多种数据库
  • Spring思维导图,让Spring不再难懂(mvc篇)
  • vue和cordova项目整合打包,并实现vue调用android的相机的demo
  • Vue全家桶实现一个Web App
  • 百度小程序遇到的问题
  • 关键词挖掘技术哪家强(一)基于node.js技术开发一个关键字查询工具
  • 腾讯大梁:DevOps最后一棒,有效构建海量运营的持续反馈能力
  • 推荐一个React的管理后台框架
  • 阿里云ACE认证之理解CDN技术
  • 专访Pony.ai 楼天城:自动驾驶已经走过了“从0到1”,“规模”是行业的分水岭| 自动驾驶这十年 ...
  • ​MySQL主从复制一致性检测
  • ​Z时代时尚SUV新宠:起亚赛图斯值不值得年轻人买?
  • ​第20课 在Android Native开发中加入新的C++类
  • ​力扣解法汇总946-验证栈序列
  • #define,static,const,三种常量的区别
  • (C语言)球球大作战
  • (done) 两个矩阵 “相似” 是什么意思?
  • (Oracle)SQL优化技巧(一):分页查询
  • (每日持续更新)jdk api之StringBufferInputStream基础、应用、实战
  • (牛客腾讯思维编程题)编码编码分组打印下标(java 版本+ C版本)
  • (转)ABI是什么
  • (转)Linq学习笔记
  • (转)为C# Windows服务添加安装程序
  • .NET Core引入性能分析引导优化
  • .Net Core与存储过程(一)
  • .net mvc 获取url中controller和action
  • .net refrector
  • .net Stream篇(六)
  • .NET 中让 Task 支持带超时的异步等待