file结构体

定义在include/linux/fs.h

struct file
{
    union
    {
        struct list_head fu_list; //文件对象链表指针linux/include/linux/list.h
        struct rcu_head fu_rcuhead; //RCU(Read-Copy Update)是Linux 2.6内核中新的锁机制
    } f_u;
    struct path f_path; //包含dentry和mnt两个成员,用于确定文件路径
#define f_dentry f_path.dentry //f_path的成员之一,当前文件的dentry结构
#define f_vfsmnt f_path.mnt //表示当前文件所在文件系统的挂载根目录
    const struct file_operations *f_op; //与该文件相关联的操作函数
    atomic_t f_count; //文件的引用计数(有多少进程打开该文件)
    unsigned int f_flags; //对应于open时指定的flag
    mode_t f_mode; //读写模式:open的mod_t mode参数
    off_t f_pos; //该文件在当前进程中的文件偏移量
    struct fown_struct f_owner; //该结构的作用是通过信号进行I/O时间通知的数据。
    unsigned int f_uid, f_gid; //文件所有者id,所有者组id
    struct file_ra_state f_ra; //在linux/include/linux/fs.h中定义,文件预读相关
    unsigned long f_version;
    #ifdef CONFIG_SECURITY
    void *f_security;
    #endif
    void *private_data;
    #ifdef CONFIG_EPOLL
    struct list_head f_ep_links;
    spinlock_t f_ep_lock;
    #endif
    struct address_space *f_mapping;
};

f_pos:loff_t 在所有平台都是 64 位,驱动可以读这个值,如果它需要知道文件中的当前位置,但是正常地不应该改变它
private_data:驱动调用 open 方法之前,你可自由使用这个成员或者忽略它

原文地址:https://www.cnblogs.com/zhangxuechao/p/11709810.html