struct--file_operations
-----------------------------------------
    struct file_operations是一个字符设备把驱动的操作和设备号联系在一起的纽带,是一系列指针的集合,每个被打开的文件都对应于一系列的操作,这就是file_operations,用来执行一系列的系统调用。

linux-2.6.22/include/linux/fs.h
struct file_operations {
        struct module *owner;    //防止模块还在被使用的时候被卸载
        loff_t        (*llseek) ();
        ssize_t       (*read) ();
        ssize_t       (*write) ();
        ssize_t       (*aio_read) ();
        ssize_t       (*aio_write) ();
        int           (*readdir) ();
        unsigned int (*poll) ();
        int           (*ioctl) ();
        long          (*unlocked_ioctl) ();
        long          (*compat_ioctl) ();
        int           (*mmap) ();
        int           (*open) ();
        int           (*flush) ();
        int           (*release) ();
        int           (*fsync) ();
        int           (*aio_fsync) ();
        int           (*fasync) ();
        int           (*lock) ();
        ssize_t       (*sendfile) ();
        ssize_t       (*sendpage) ();
        unsigned long (*get_unmapped_area) ();
        int           (*check_flags) ();
        int           (*dir_notify) ();
        int           (*flock) ();
        ssize_t       (*splice_write) ();
        ssize_t       (*splice_read) ();
};

struct--file
-----------------------------------------
    struct file代表一个打开的文件,在执行file_operation中的open操作时被创建,这里需要注意的是与用户空间file指针的区别,一个在内核,而file指针在用户空间,由c库来定义。

linux-2.6.22/include/linux/fs.h
struct file {
        union {
                struct list_head        fu_list;
                struct rcu_head         fu_rcuhead;
        } f_u;
        struct path                     f_path;
#define f_dentry                        f_path.dentry
#define f_vfsmnt                        f_path.mnt
        const struct file_operations    *f_op;
        atomic_t                        f_count;
        unsigned int                    f_flags;
        mode_t                          f_mode;    //文件是否可读、可写
        loff_t                          f_pos;     //当前读写位置
        struct fown_struct              f_owner;
        unsigned int                    f_uid, f_gid;
        struct file_ra_state            f_ra;
        unsigned long                   f_version;
        void                            *f_security;
        void                            *private_data;
        struct list_head                f_ep_links;
        spinlock_t                      f_ep_lock;
        struct address_space            *f_mapping;
};

struct inode被内核用来代表一个文件,注意和struct file的区别,struct inode一个是代表文件,struct file一个是代表打开的文件
struct inode包括很重要的二个成员:
dev_t       i_rdev   设备文件的设备号
struct cdev *i_cdev 代表字符设备的数据结构

struct inode结构是用来在内核内部表示文件的.同一个文件可以被打开好多次,所以可以对应很多struct file,但是只对应一个struct inode.

struct--file_operations的更多相关文章

  1. 字符驱动之二操作方法(struct file_operations)【转】

    转自:http://blog.chinaunix.net/uid-26837113-id-3157515.html 从上一篇我们看到了字符驱动的三个重要结构,那我现在跟大家详细的说说 struct f ...

  2. 驱动笔记 - file_operations

    #include <linux/fs.h> struct file_operations { struct module *owner; loff_t (*llseek) (struct ...

  3. cdev成员结构体file_operations文件操作结构的分析

    struct file_operations{ struct module *owner; // 指向拥有该结构的模块的指针,避免正在操作时被卸载,一般为初始化为THIS_MODULES loff_t ...

  4. struct inode 和 struct file

    1.struct inode──字符设备驱动相关的重要结构介绍 内核中用inode结构表示具体的文件,而用file结构表示打开的文件描述符.Linux2.6.27内核中,inode结构体具体定义如下: ...

  5. platform_driver与file_operations两种方法开发led驱动

    下面是两个LED灯的驱动程序 一个用platform_driver 另一个用file_operations #include <linux/kernel.h> #include <l ...

  6. file_operations结构体解析 1

    注:学了这么长时间了,还没有好好看看 file_operations机构体,这其中还有很多的东西,当你学着学着的时候,就会用到这里面的一些系统调用对应的函数了,我在网上搜索之后,记录如下,一边将来查看 ...

  7. file_operations结构2

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

  8. Linux字符设备驱动file_operations

    struct _file_operations struct _file_operations在Fs.h这个文件里面被定义的,如下所示: struct file_operations { struct ...

  9. 设备文件三大结构:inode,file,file_operations

    驱动程序就是向下控制硬件,向上提供接口,这里的向上提供的接口最终对应到应用层有三种方式:设备文件,/proc,/sys,其中最常用的就是使用设备文件,而Linux设备中用的最多的就是字符设备,本文就以 ...

  10. VFS四大对象之四-struct file

    继上一篇文章: http://www.cnblogs.com/linhaostudy/p/7428971.html 四.file结构体 文件对象:注意文件对象描述的是进程已经打开的文件.因为一个文件可 ...

随机推荐

  1. RHEL6中ulimit的nproc限制

    http://blog.csdn.net/kumu_linux/article/details/8301760 当前shell下更改用户可打开进程数 修改limits.conf配置文件生效 [root ...

  2. C# 之 Excel 导入一列中既有汉字又有数字:数字可以正常导入,汉字导入为空

    今天在做一个Excel导入功能,一切开发就绪,数据可以成功导入.导入后检查数据库发现有一列既有汉字又有数字,数字正常导入,汉字为空.但是前面同样既有汉字又有数字的列可以导入成功. 查看excel 源文 ...

  3. java常用的包的简介

    java常用的包: java.lang:包含java语言的核心类,如String.math.system和thread类等,使用这个包下的类无需import导入,系统会自动导入这个包下的所有类.   ...

  4. Java基础知识强化之网络编程笔记21:Android网络通信之 Android常用OAuth登录(获取令牌信息)

    1. 首先我们去下载开发相关SDK(Android): 下载百度使用OAuth的SDK(Android),如下: 下载链接为:http://developer.baidu.com/wiki/index ...

  5. Wireshark 过滤条件

    做应用识别这一块经常要对应用产生的数据流量进行分析. 抓包采用wireshark,提取特征时,要对session进行过滤,找到关键的stream,这里总结了wireshark过滤的基本语法,供自己以后 ...

  6. 关于git的打patch的功能

    UNIX世界的软件开发大多都是协作式的,因此,Patch(补丁)是一个相当重要的东西,因为几乎所有的大型UNIX项目的普通贡献者,都是通过 Patch来提交代码的.作为最重要的开源项目之一,Linux ...

  7. 【C语言】5-结构体

    一.什么是结构体 * 在实际应用中,我们通常需要由不同类型的数据来构成一个整体,比如学生这个整体可以由姓名.年龄.身高等数据构成,这些数据都具有不同的类型,姓名可以是字符串类型,年龄可以是整型,身高可 ...

  8. HTML5拖拽功能drag

    1.创建拖拽对象 给需要拖拽的元素设置draggable属性,它有三个值: true:元素可以被拖拽:false:元素不能被拖拽:auto: 浏览器自己判断元素是否能被拖拽. 2.处理拖拽事件当我们拖 ...

  9. Microsoft JScript 运行时错误: Sys.WebForms.PageRequestManagerParserErrorException无法分析从服务器收到的消息。之所以出现此错误,

    Microsoft JScript 运行时错误: Sys.WebForms.PageRequestManagerParserErrorException: 无法分析从服务器收到的消息.之所以出现此错误 ...

  10. 20160502-struts2入门--ognl表达式

    一.OGNL表达式语言 OGNL是Object Graphic Navigation Language(对象图导航语言)的缩写,它是一个开源项目. Struts 2框架使用OGNL作为默认的表达式语言 ...