从文件 I/O 看 Linux 的虚拟文件系统

豆豆网   技术应用频道   2008年04月15日  【字号: 收藏本文

内容摘要:本文在简要介绍 VFS 的相关数据结构后,以文件 I/O 为切入点深入 Linux 内核源代码,追踪了 sys_open 和 sys_read 两个系统调用的代码结构,并在追踪的过程中理清了跨文件系统的文件操作的基本原理和“一切皆是文件”的口号得以实现的根本。

  2.2.5 其他VFS对象

  2.2.5.1 和文件系统相关

  根据文件系统所在的物理介质和数据在物理介质上的组织方式来区分不同的文件系统类型的。 file_system_type结构用于描述具体的文件系统的类型信息。被Linux支持的文件系统,都有且仅有一个file_system_type结构而不管它有零个或多个实例被安装到系统中。

  而与此对应的是每当一个文件系统被实际安装,就有一个vfsmount结构体被创建,这个结构体对应一个安装点。

  清单5. 和文件系统相关

struct file_system_type {
    const char *name;        /*文件系统的名字*/
    struct subsystem subsys;     /*sysfs子系统对象*/
    int fs_flags;          /*文件系统类型标志*/
    /*在文件系统被安装时,从磁盘中读取超级块,在内存中组装超级块对象*/
    struct super_block *(*get_sb) (struct file_system_type*,
                    int, const char*, void *);
     
    void (*kill_sb) (struct super_block *); /*终止访问超级块*/      
    struct module *owner;          /*文件系统模块*/
    struct file_system_type * next;     /*链表中的下一个文件系统类型*/
    struct list_head fs_supers;       /*具有同一种文件系统类型的超级块对象链表*/
};
struct vfsmount
{
    struct list_head mnt_hash;        /*散列表*/
    struct vfsmount *mnt_parent;       /*父文件系统*/
    struct dentry *mnt_mountpoint;      /*安装点的目录项对象*/
    struct dentry *mnt_root;         /*该文件系统的根目录项对象*/
    struct super_block *mnt_sb;       /*该文件系统的超级块*/
    struct list_head mnt_mounts;       /*子文件系统链表*/
    struct list_head mnt_child;       /*子文件系统链表*/
    atomic_t mnt_count;           /*使用计数*/
    int mnt_flags;              /*安装标志*/
    char *mnt_devname;            /*设备文件名*/
    struct list_head mnt_list;        /*描述符链表*/
    struct list_head mnt_fslink;       /*具体文件系统的到期列表*/
    struct namespace *mnt_namespace;     /*相关的名字空间*/
};

来源:ibm    作者:吴美清    责编:豆豆技术应用

正在加载评论...