博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
struct--file_operations
阅读量:7223 次
发布时间:2019-06-29

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

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 被内核用来代表一个文件,注意和struct file的区别,struct inode一个是代表文件,struct file一个是代表打开的文件
struct inode包括很重要的二个成员:
dev_t       i_rdev   设备文件的设备号
struct cdev *i_cdev 代表字符设备的数据结构
struct inode结构是用来在内核内部表示文件的.同一个文件可以被打开好多次,所以可以对应很多struct file,但是只对应一个struct inode.

转载于:https://www.cnblogs.com/sidely/p/struct-FileOperations.html

你可能感兴趣的文章
教你快速入门ES6
查看>>
Python 爬虫十六式 - 第六式:JQuery的假兄弟-pyquery
查看>>
宜昌a货翡翠,包头a货翡翠
查看>>
【微信事业群】趣味面试算法题
查看>>
保守的国美再一次进击社交电商,前途未卜?
查看>>
git
查看>>
Python学习教程(Python学习路线):Python 3—手动创建迭代器
查看>>
说说如何在 Virtual Box 中新建 CentOS 虚拟机
查看>>
Cordova + Vue 实现点击两次退出应用
查看>>
JAVA 多用户商城系统b2b2c-Spring Cloud Stream 介绍
查看>>
spring cloud构建互联网分布式微服务云平台-SpringCloud集成项目简介
查看>>
基于房源的画像分析
查看>>
80% UI 初学者走过的弯路,你走了几条?
查看>>
文档和元素的几何滚动
查看>>
php 设计模式
查看>>
Java springcloud B2B2C o2o多用户商城 springcloud架构(八)springboot整合mongodb
查看>>
3年工作经验的Java程序员面试经过
查看>>
Mysql 批量写入数据,对于这类性能问题,你是如何优化的
查看>>
MySQL无法启动几种常见问题小结
查看>>
阿里CTO:阿里所有技术和产品输出都将必须通过阿里云进行
查看>>