博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
linux字符设备驱动之file_operations结构体知识详解
阅读量:2433 次
发布时间:2019-05-10

本文共 1582 字,大约阅读时间需要 5 分钟。

struct file_operations在fs.h这个文件里面被定义的

struct super_operations {    struct inode *(*alloc_inode)(struct super_block *sb);    void (*destroy_inode)(struct inode *);    void (*dirty_inode) (struct inode *, int flags);    int (*write_inode) (struct inode *, struct writeback_control *wbc);    int (*drop_inode) (struct inode *);    void (*evict_inode) (struct inode *);    void (*put_super) (struct super_block *);    void (*write_super) (struct super_block *);    int (*sync_fs)(struct super_block *sb, int wait);    int (*freeze_fs) (struct super_block *);    int (*unfreeze_fs) (struct super_block *);    int (*statfs) (struct dentry *, struct kstatfs *);    int (*remount_fs) (struct super_block *, int *, char *);    void (*umount_begin) (struct super_block *);    int (*show_options)(struct seq_file *, struct vfsmount *);    int (*show_devname)(struct seq_file *, struct vfsmount *);    int (*show_path)(struct seq_file *, struct vfsmount *);    int (*show_stats)(struct seq_file *, struct vfsmount *);#ifdef CONFIG_QUOTA    ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t);    ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t);#endif    int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);};

Linux使用file_operations结构访问驱动程序的函数,这个结构的每一个成员的名字都对应着一个调用。

用户进程利用在对设备文件进行诸如read/write操作的时候,系统调用通过设备文件的主设备号找到相应的设备驱动程序,然后读取这个数据结构相应的函数指针,接着把控制权交给该函数,这是Linux的设备驱动程序工作的基本原理。
下面是各成员解析:
1、struct module *owner
第一个 file_operations 成员根本不是一个操作,它是一个指向拥有这个结构的模块的指针。
这个成员用来在它的操作还在被使用时阻止模块被卸载. 几乎所有时间中, 它被简单初始化为 THIS_MODULE, 一个在

转载地址:http://dxomb.baihongyu.com/

你可能感兴趣的文章
opencv阈值法分割图像
查看>>
OpenCV资料
查看>>
极阅和微精
查看>>
Outbrain
查看>>
智能Web算法第二版前言和译者序
查看>>
RPC实践(二)JsonRPC实践
查看>>
RPC实践(三)Hessian实践
查看>>
Zookeeper实践(四)zookeeper的WEB客户端zkui使用
查看>>
RPC实践(五)Dubbo实践-服务集群
查看>>
java单元测试Junit实践(一) Junit基础
查看>>
Webservice实践(二)Webservice 客户端开发
查看>>
Webservice实践(三)基于JDK的jax ws进行服务端开发
查看>>
Webservice实践(四)基于AXIS2的服务端开发
查看>>
Ubuntu12.04下安装eclipse C/C++开发环境
查看>>
Eclipse中10个最有用的快捷键组合
查看>>
Routing
查看>>
json相关学习
查看>>
linux下access函数的应用
查看>>
linux系统调用之文件:递归删除非空目录
查看>>
linux下获取系统时间的方法
查看>>