linux虚拟文件系统

来源:互联网 发布:ubuntu移动文件 编辑:程序博客网 时间:2024/05/10 07:52

先看一下VFS在linux中处于什么样的位置:
VFS
再引用http://www.cnblogs.com/wang_yb/p/3144291.html
中提到的《linux内核的设计于实现》中对VFS的描述,看代码和代码注释更有利于理解VFS是如何调用各个不同的文件系统的:
虚拟文件系统(VFS)是linux内核和存储设备之间的抽象层
- 简化了新文件系统加入内核的过程:新文件系统只要实现VFS的各个接口即可,不需要修改内核部分。
VFS 统一了文件系统的实现框架,使得在linux上实现新文件系统的工作变得简单。
目前linux内核中已经支持60多种文件系统,具体支持的文件系统可以查看 内核源码 fs 文件夹下的内容。
VFS中有2个专门针对文件系统的2个对象,

  • struct file_system_type: 用来描述文件系统的类型(比如ext3,ntfs等等)

  • struct vfsmount : 描述一个安装文件系统的实例

file_system_type 结构体位于:

struct file_system_type {    const char *name;   /* 文件系统名称 */    int fs_flags;       /* 文件系统类型标志 */    /* 从磁盘中读取超级块,并且在文件系统被安装时,在内存中组装超级块对象 */    int (*get_sb) (struct file_system_type *, int,               const char *, void *, struct vfsmount *);    /* 终止访问超级块 */    void (*kill_sb) (struct super_block *);    struct module *owner;           /* 文件系统模块 */    struct file_system_type * next; /* 链表中下一个文件系统类型 */    struct list_head fs_supers;     /* 超级块对象链表 */    /* 下面都是运行时的锁 */    struct lock_class_key s_lock_key;    struct lock_class_key s_umount_key;    struct lock_class_key i_lock_key;    struct lock_class_key i_mutex_key;    struct lock_class_key i_mutex_dir_key;    struct lock_class_key i_alloc_sem_key;};

每种文件系统,不管由多少个实例安装到系统中,还是根本没有安装到系统中,都只有一个 file_system_type 结构。

当文件系统被实际安装时,会在安装点创建一个 vfsmount 结构体。

结构体代表文件系统的实例,也就是文件系统被安装几次,就会创建几个 vfsmount

vfsmount 的定义参见:

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;        /* 子文件系统链表 */    int mnt_flags;                  /* 安装标志 */    /* 4 bytes hole on 64bits arches */    const char *mnt_devname;        /* 设备文件名 e.g. /dev/dsk/hda1 */    struct list_head mnt_list;      /* 描述符链表 */    struct list_head mnt_expire;    /* 到期链表的入口 */    struct list_head mnt_share;        /* 共享安装链表的入口 */    struct list_head mnt_slave_list;/* 从安装链表 */    struct list_head mnt_slave;        /* 从安装链表的入口 */    struct vfsmount *mnt_master;    /* 从安装链表的主人 */    struct mnt_namespace *mnt_ns;    /* 相关的命名空间 */    int mnt_id;            /* 安装标识符 */    int mnt_group_id;        /* 组标识符 */    /*     * We put mnt_count & mnt_expiry_mark at the end of struct vfsmount     * to let these frequently modified fields in a separate cache line     * (so that reads of mnt_flags wont ping-pong on SMP machines)     */    atomic_t mnt_count;         /* 使用计数 */    int mnt_expiry_mark;        /* 如果标记为到期,则为 True */    int mnt_pinned;             /* "钉住"进程计数 */    int mnt_ghosts;             /* "镜像"引用计数 */#ifdef CONFIG_SMP    int *mnt_writers;           /* 写者引用计数 */#else    int mnt_writers;            /* 写者引用计数 */#endif};
0 0
原创粉丝点击