VFS虚拟文件系统四大对象

VFS使得用户可以直接使用open()、read()等系统调用而无需考虑具体文件系统和实际物理介质。文件系统抽象层四大对象:

超级块

struct super_block {
    struct list_head    s_list;        /* 文件超级块链表头指针 */
    dev_t            s_dev;        /* 文件系统的块设备标识 */
    unsigned long        s_blocksize;        //数据块的大小
    unsigned char        s_blocksize_bits;        //块大小值所占的位数
    unsigned char        s_dirt;        //该值若为1,标识该超级块已被修改
    unsigned long long    s_maxbytes;    /* 文件大小的最大值 */
    struct file_system_type    *s_type;        //已注册文件系统的链表指针
    const struct super_operations    *s_op;        //指向超级块操作函数集的指针
    struct dquot_operations    *dq_op;
     struct quotactl_ops    *s_qcop;
    const struct export_operations *s_export_op;
    unsigned long        s_flags;
    unsigned long        s_magic;
    struct dentry        *s_root;
    struct rw_semaphore    s_umount;
    struct mutex        s_lock;
    int            s_count;
    int            s_need_sync_fs;
    atomic_t        s_active;
#ifdef CONFIG_SECURITY
    void                    *s_security;
#endif
    struct xattr_handler    **s_xattr;
 
    struct list_head    s_inodes;    /* all inodes */
    struct list_head    s_dirty;    /* dirty inodes */
    struct list_head    s_io;        /* parked for writeback */
    struct list_head    s_more_io;    /* parked for more writeback */
    struct hlist_head    s_anon;        /* anonymous dentries for (nfs) exporting */
    struct list_head    s_files;
    /* s_dentry_lru and s_nr_dentry_unused are protected by dcache_lock */
    struct list_head    s_dentry_lru;    /* unused dentry lru */
    int            s_nr_dentry_unused;    /* # of dentry on lru */
 
    struct block_device    *s_bdev;
    struct mtd_info        *s_mtd;
    struct list_head    s_instances;
    struct quota_info    s_dquot;    /* Diskquota specific options */
 
    int            s_frozen;
    wait_queue_head_t    s_wait_unfrozen;
    char s_id[32];                /* Informational name */
 
    void             *s_fs_info;    /* 指向实际文件系统超级块内核信息结构的指针 */
    fmode_t            s_mode;
    struct mutex s_vfs_rename_mutex;    /* Kludge */
    u32           s_time_gran;
    char *s_subtype;
    char *s_options;
    struct list_head s_async_list;
};

目录项:

struct dentry {
    atomic_t d_count;
    unsigned int d_flags;        /* 记录目录项被引用次数的计数器 */
    spinlock_t d_lock;        /* 目录项的标志 */
    int d_mounted;
    struct inode *d_inode;        /* 与文件名相对应的inode */
 
    struct hlist_node d_hash;    /* 目录项形成的散列表 */
    struct dentry *d_parent;    /* 指向父目录项的指针 */
    struct qstr d_name;        //包含文件名的结构
 
    struct list_head d_lru;        /* 已经没有用户使用的目录项的链表 */
    union {
        struct list_head d_child;    /* 父目录的子目录项形成的链表 */
         struct rcu_head d_rcu;
    } d_u;
    struct list_head d_subdirs;    /* i节点别名的链表 */
    struct list_head d_alias;    /* inode alias list */
    unsigned long d_time;        /* used by d_revalidate */
    const struct dentry_operations *d_op;        //指向dentry操作函数集的指针
    struct super_block *d_sb;    /* 目录树的超级块,即本目录项所在目录树的根 */
    void *d_fsdata;            /* 文件系统的特定数据 */
 
    unsigned char d_iname[DNAME_INLINE_LEN_MIN];    /* 短文件名 */
};

索引节点:

struct inode {
    struct hlist_node    i_hash;            //指向散列表的指针
    struct list_head    i_list;            //指向i节点链表的这孩子很
    struct list_head    i_sb_list;
    struct list_head    i_dentry;            //指向dentry链表的指针
    unsigned long        i_ino;            //i节点号
    atomic_t        i_count;            //记录使用本节点进程数目的计数器
    unsigned int        i_nlink;            //节点连接的别名的数目
    uid_t            i_uid;            //文件拥有者的标识号
    gid_t            i_gid;            //文件拥有者所在组的标识号
    dev_t            i_rdev;            //文件设备的标识号
    u64            i_version;
    loff_t            i_size;
#ifdef __NEED_I_SIZE_ORDERED
    seqcount_t        i_size_seqcount;
#endif
    struct timespec        i_atime;
    struct timespec        i_mtime;
    struct timespec        i_ctime;
    unsigned int        i_blkbits;
    blkcnt_t        i_blocks;
    unsigned short          i_bytes;
    umode_t            i_mode;
    spinlock_t        i_lock;    /* i_blocks, i_bytes, maybe i_size */
    struct mutex        i_mutex;
    struct rw_semaphore    i_alloc_sem;
    const struct inode_operations    *i_op;        //指向i节点操作函数集的指针
    const struct file_operations    *i_fop;            /* 指向文件操作函数集的指针 */
    struct super_block    *i_sb;            //指向文件系统超级块的指针
    struct file_lock    *i_flock;
    struct address_space    *i_mapping;        //指向下一个域i_data的指针
    struct address_space    i_data;            //页缓冲区头结构
    void *generic_ip;            //指向实际文件节点信息结构的指针
#ifdef CONFIG_QUOTA
    struct dquot        *i_dquot[MAXQUOTAS];
#endif
    struct list_head    i_devices;
    union {
        struct pipe_inode_info    *i_pipe;
        struct block_device    *i_bdev;
        struct cdev        *i_cdev;
    };
    int            i_cindex;
 
    __u32            i_generation;
 
#ifdef CONFIG_DNOTIFY
    unsigned long        i_dnotify_mask; /* Directory notify events */
    struct dnotify_struct    *i_dnotify; /* for directory notifications */
#endif
 
#ifdef CONFIG_INOTIFY
    struct list_head    inotify_watches; /* watches on this inode */
    struct mutex        inotify_mutex;    /* protects the watches list */
#endif
 
    unsigned long        i_state;
    unsigned long        dirtied_when;    /* jiffies of first dirtying */
 
    unsigned int        i_flags;
 
    atomic_t        i_writecount;
#ifdef CONFIG_SECURITY
    void            *i_security;
#endif
    void            *i_private; /* fs or device private pointer */
};

文件:

struct file {
        struct list_head        f_list;
        struct dentry           *f_dentry;
        struct vfsmount         *f_vfsmnt;
        struct file_operations  *f_op;
        atomic_t                f_count;
        unsigned int            f_flags;
        mode_t                  f_mode;
        loff_t                  f_pos;
        unsigned long           f_reada, f_ramax, f_raend, f_ralen, f_rawin;
        struct fown_struct      f_owner;
        unsigned int            f_uid, f_gid;
        int                     f_error;

        size_t                  f_maxcount;
        unsigned long           f_version;

        /* needed for tty driver, and maybe others */
        void                    *private_data;

        /* preallocated helper kiobuf to speedup O_DIRECT */
        struct kiobuf           *f_iobuf;
        long                    f_iobuf_lock;
};
Last modification:May 18th, 2020 at 07:22 pm
如果觉得我的文章对你有用,请随意赞赏

Leave a Comment

4 comments

  1. 灵异探索网 Firefox 79.0 Windows 10 中国 广东 惠州

    谢谢分享,每日打卡,学生卡~

  2. nbrf Google Chrome 78.0.3904.108 Windows 7 中国 广西 桂林

    快递代发,礼品代发、快递单号网网www.dydanhw.com

  3. bvfe Google Chrome 78.0.3904.108 Windows 7 中国 广西 桂林

    提供快递单号、空包代发有底单、内网www.88danhw.com

  4. jhjh Google Chrome 78.0.3904.108 Windows 7 中国 广西 桂林

    真实单号、快递代发www.kuaidzj.com