Chinaunix首页 | 论坛 | 博客
  • 博客访问: 366665
  • 博文数量: 181
  • 博客积分: 215
  • 博客等级: 民兵
  • 技术积分: 313
  • 用 户 组: 普通用户
  • 注册时间: 2012-05-17 19:39
个人简介

王的男人

文章分类

全部博文(181)

文章存档

2016年(2)

2015年(35)

2014年(17)

2013年(84)

2012年(49)

我的朋友

分类: LINUX

2013-03-29 04:25:35

truct 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;
};
*索引节点对象由inode结构体表示,定义文件在linux/fs.h中
*/
struct inode {
        struct hlist_node       i_hash;              /* 哈希表 */
        struct list_head        i_list;              /* 索引节点链表 */
        struct list_head        i_dentry;            /* 目录项链表 */
        unsigned long           i_ino;               /* 节点号 */
        atomic_t                i_count;             /* 引用记数 */
        umode_t                 i_mode;              /* 访问权限控制 */
        unsigned int            i_nlink;             /* 硬链接数 */
        uid_t                   i_uid;               /* 使用者id */
        gid_t                   i_gid;               /* 使用者id组 */
        kdev_t                  i_rdev;              /* 实设备标识符 */                                对于字符串设备驱动程序来说有意义
        loff_t                  i_size;              /* 以字节为单位的文件大小 */
        struct timespec         i_atime;             /* 最后访问时间 */
        struct timespec         i_mtime;             /* 最后修改(modify)时间 */
        struct timespec         i_ctime;             /* 最后改变(change)时间 */
        unsigned int            i_blkbits;           /* 以位为单位的块大小 */
        unsigned long           i_blksize;           /* 以字节为单位的块大小 */
        unsigned long           i_version;           /* 版本号 */
        unsigned long           i_blocks;            /* 文件的块数 */
        unsigned short          i_bytes;             /* 使用的字节数 */
        spinlock_t              i_lock;              /* 自旋锁 */
        struct rw_semaphore     i_alloc_sem;         /* 索引节点信号量 */
        struct inode_operations *i_op;               /* 索引节点操作表 */
        struct file_operations  *i_fop;              /* 默认的索引节点操作 */
        struct super_block      *i_sb;               /* 相关的超级块 */
        struct file_lock        *i_flock;            /* 文件锁链表 */
        struct address_space    *i_mapping;          /* 相关的地址映射 */
        struct address_space    i_data;              /* 设备地址映射 */
        struct dquot            *i_dquot[MAXQUOTAS]; /* 节点的磁盘限额 */
        struct list_head        i_devices;           /* 块设备链表 */
        struct pipe_inode_info  *i_pipe;             /* 管道信息 */
        struct block_device     *i_bdev;             /* 块设备驱动 */
        unsigned long           i_dnotify_mask;      /* 目录通知掩码 */
        struct dnotify_struct   *i_dnotify;          /* 目录通知 */
        unsigned long           i_state;             /* 状态标志 */
        unsigned long           dirtied_when;        /* 首次修改时间 */
        unsigned int            i_flags;             /* 文件系统标志 */
        unsigned char           i_sock;              /* 可能是个套接字吧 */
        atomic_t                i_writecount;        /* 写者记数 */
        void                    *i_security;         /* 安全模块 */
        __u32                   i_generation;        /* 索引节点版本号 */
        union {
                void            *generic_ip;         /* 文件特殊信息 */
        } u;
};

阅读(359) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~