Chinaunix首页 | 论坛 | 博客
  • 博客访问: 181460
  • 博文数量: 22
  • 博客积分: 1069
  • 博客等级: 准尉
  • 技术积分: 240
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-01 13:40
文章分类

全部博文(22)

文章存档

2015年(4)

2011年(2)

2010年(12)

2009年(4)

我的朋友

分类: LINUX

2010-01-16 17:37:00

一、file结构体  linux/include/linux/fs.h
struct file {
    /*
     * fu_list becomes invalid after file_free is called and queued via
     * fu_rcuhead for RCU freeing
     */
    union {
    struct list_head  fu_list;
    // linux/include/linux/list.h:
    // struct list_head {
    //   struct list_head *next, *prev;
    // };
    struct rcu_head   fu_rcuhead; 
    // linux/include/linux/rcupdate.h:
    // struct rcu_head {
    //   struct rcu_head *next;
    //   void (*func)(struct rcu_head *head);
    // };
    } f_u;
    struct path     f_path;
    // linux/include/linux/namei.h:
    // struct path {
    //   struct vfsmount *mnt;
    //   struct dentry *dentry;
    // };
#define f_dentry    f_path.dentry  //与文件关联的目录入口(dentry)结构
    //
#define f_vfsmnt    f_path.mnt     //已安装的文件系统
    //
    const struct file_operations    *f_op; //和文件关联的操作
    atomic_t        f_count; //记录对文件对象的引用计数
    //typedef struct { volatile int counter; } atomic_t;
    unsigned int    f_flags; //文件标志,如:O_RDONLY、O_NONBLOCK、O_SYNC
    mode_t          f_mode;  //文件读/写模式,如:FMODE_READ和FMODE_WRITE
    // typedef unsigned int __kernel_mode_t;
    // typedef __kernel_mode_t mode_t;
    loff_t          f_pos;   //当前读写位置
    // typedef long long __kernel_loff_t;
    // typedef __kernel_loff_t loff_t;
    struct fown_struct    f_owner;
    // struct fown_struct {
    //   rwlock_t lock;          /* protects pid, uid, euid fields */
    //   struct pid *pid;        /* pid or -pgrp where SIGIO should be sent */
    //   enum pid_type pid_type; /* Kind of process group SIGIO should be sent to*/
    //   uid_t uid, euid;        /* uid/euid of process setting the owner */
    //   int signum;             /* posix.1b rt signal to be delivered on IO */ 694
    // };
    unsigned int          f_uid, f_gid;
    struct file_ra_state  f_ra;
    //struct file_ra_state {  //新版的结构体会有不同
    //  pgoff_t start;            /* where readahead started */
    //  unsigned long size;       /* # of readahead pages */
    //  unsigned long async_size; /* do asynchronous readahead when there are only # of pages ahead */
    //  unsigned long ra_pages;   /* Maximum readahead window */
    //  unsigned long mmap_hit;   /* Cache hit stat for mmap accesses */
    //  unsigned long mmap_miss;  /* Cache miss stat for mmap accesses */
    //  unsigned long prev_index; /* Cache last read() position */
    //  unsigned int prev_offset; /* Offset where last read() ended in a page */710
    // };
    unsigned long         f_version;
#ifdef CONFIG_SECURITY
    void            *f_security;
#endif
    /* needed for tty driver, and maybe others */
    void            *private_data; //文件私有指针,一般指向设备驱动自定义的描述设备的结构体
#ifdef CONFIG_EPOLL
    /* Used by fs/eventpoll.c to link all the hooks to this file */
    struct list_head    f_ep_links;  //f_ep_lock是保护f_ep_links链表的自旋锁。
    spinlock_t          f_ep_lock;
    // typedef struct {
    //   raw_spinlock_t raw_lock;
    // #ifdef CONFIG_GENERIC_LOCKBREAK
    //   unsigned int break_lock;
    // #endif
    // } spinlock_t;
    // typedef struct {
    //   volatile unsigned int lock;
    // } raw_spinlock_t;
#endif /* #ifdef CONFIG_EPOLL */
    struct address_space    *f_mapping;  //映射的地址空间
    // struct address_space {
    //   struct inode            *host;          /* owner: inode, block_device */
    //   struct radix_tree_root  page_tree;      /* radix tree of all pages */
    //   spinlock_t              tree_lock;      /* and lock protecting it */
    //   unsigned int            i_mmap_writable;/* count VM_SHARED mappings */
    //   struct prio_tree_root   i_mmap;         /* tree of private and shared mappings */
    //   struct list_head        i_mmap_nonlinear;/*list VM_NONLINEAR mappings */
    //   spinlock_t              i_mmap_lock;    /* protect tree, count, list */
    //   unsigned int            truncate_count; /* Cover race condition with truncate */
    //   unsigned long           nrpages;        /* number of total pages */
    //   pgoff_t                 writeback_index;/* writeback starts here */
    //   const struct address_space_operations *a_ops;   /* methods */
    //   unsigned long           flags;          /* error bits/gfp mask */
    //   struct backing_dev_info *backing_dev_info; /* device readahead, etc */
    //   spinlock_t              private_lock;   /* for use by the address_space */
    //   struct list_head        private_list;   /* ditto */
    //   struct address_space    *assoc_mapping; /* ditto */
    // } __attribute__((aligned(sizeof(long))));
};
文件结构体代表一个打开的文件,系统中每个打开的文件在内核空间都有一个关联的struct file。
它由内核打开文件时创建,并传递给在文件上进行操作的任何函数。
阅读(3814) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~