Linux虚拟文件系统(概述)

字体大小: 中小 标准 ->行高大小: 标准
Linux虚拟文件系统是一个内核软件层,用来处理与UNIX标准文件系统相关的所有系统调用。其健壮性表现在能为各种文件系统提供一个通用的接口。

Linux虚拟文件系统支持的文件系统可以划分为三种主要的类型:

磁盘文件系统

这些文件系统管理在本地磁盘分区中可用的磁盘空间或者其他可以起到磁盘作用的设备(比如说一个USB闪存)。

网络文件系统

这些文件系统允许访问属于其他网络计算机的文件系统所包含的文件。

特殊文件系统

这些文件系统不管理本地或者远程磁盘空间

通用文件模型

虚拟文件系统所隐含的主要思想是引入一个通用的文件模型,这个模型可以支持所有的文件系统类型。

下图为VFS在系统中所处的位置。

可以把这里的通用文件模型看作是面型对象的。在这里,对象是一个软件结构,其中定义了数据结构也定义了其上的操作方法。处于效率上的考虑,Linux的编码并为采用面向对象的程序设计(比如C++编程)。因此对象作为普通的C数据结构来实现,数据结构中指向函数的字段就对应于对象的方法。

VFS与进程关系

进程描述符中与VFS相关的部分:

[cpp]
  1. struct task_struct {       ……  
  2. /* filesystem information */       struct fs_struct *fs;  
  3. /* open file information */       struct files_struct *files;  
  4. /* namespaces */       struct nsproxy *nsproxy;  
  5.     ……   };  

通用文件系统模型与进程关系架构

通用文件系统模型数据结构组成

通用文件系统模型由下列对象组成:

超级块对象

存放已安装文件系统的有关信息。对基于磁盘的文件系统,这类对象通常对应于存放在磁盘上的文件系统控制块。

[cpp]
  1. /*存放已安装文件系统的有关信息,通常对应于存放在磁盘上的文件系统控制块  每挂载一个文件系统对应一个超级块对象*/  
  2. struct super_block {       struct list_head    s_list;/*指向超级块链表的指针*//* Keep this first */  
  3.     dev_t           s_dev;/*设备标识符*//* search index; _not_ kdev_t */       unsigned long       s_blocksize;/*以字节为单位的块大小*/  
  4.     unsigned char       s_blocksize_bits;/*以位为单位的块大小*/       unsigned char       s_dirt;/*修改标志*/  
  5.     loff_t          s_maxbytes;/*文件的最长长度*/  /* Max file size */       struct file_system_type *s_type;/*文件系统类型*/  
  6.     const struct super_operations   *s_op;/*超级快方法*/       const struct dquot_operations   *dq_op;/*磁盘限额方法*/  
  7.     const struct quotactl_ops   *s_qcop;/*磁盘限额管理方法*/       const struct export_operations *s_export_op;/*网络文件系统使用的输出方法*/  
  8.     unsigned long       s_flags;/*安装标识*/       unsigned long       s_magic;/*文件系统的魔术*/  
  9.     struct dentry       *s_root;/*文件系统根目录的目录项对象*/       struct rw_semaphore s_umount;/*卸载用的信号量*/  
  10.     struct mutex        s_lock;/*超级块信号量*/       int         s_count;/*引用计数*/  
  11.     int         s_need_sync;/*表示对超级快的索引节点进行同步标志*/       atomic_t        s_active;/*次级引用计数*/  
  12. #ifdef CONFIG_SECURITY        void                    *s_security;/*指向超级安全数据结构的指针*/  
  13. #endif        struct xattr_handler    **s_xattr;/*执行超级快扩展数据结构的指针*/  
  14.        struct list_head    s_inodes;/*所有索引节点的链表*/  /* all inodes */  
  15.     struct hlist_head   s_anon;/*用于处理网络文件系统的匿名目录项的链表*/      /*   anonymous dentries for (nfs) exporting */  
  16.     struct list_head    s_files;/*文件对象的链表*/       /* s_dentry_lru and s_nr_dentry_unused are protected by dcache_lock */  
  17.     struct list_head    s_dentry_lru;/* /* unused dentry lru */       int         s_nr_dentry_unused; /* # of dentry on lru */  
  18.        struct block_device *s_bdev;/*指向块设备驱动程序描述符的指针*/  
  19.     struct backing_dev_info *s_bdi;/* */       struct mtd_info     *s_mtd;/**/  
  20.     struct list_head    s_instances;/*用于指定文件系统类型的超级快对象链表指针*/       struct quota_info   s_dquot;/*磁盘限额的描述符*/    /* Diskquota specific options  
  21. */     
  22.     int         s_frozen;/*冻结文件系统时使用的标志*/       wait_queue_head_t   s_wait_unfrozen;/*进程挂起的等待队列,直到文件系统被冻结*/  
  23.        char s_id[32];/*包含超级快的块设备名称*/               /* Informational name */  
  24.        void            *s_fs_info;/*指向特定文件系统的超级快信息的指针*/    /* Filesystem  
  25. private info */       fmode_t         s_mode;/**/  
  26.        /* 
  27.      * The next field is for VFS *only*. No filesystems have any business       * even looking at it. You had been warned. 
  28.      */       struct mutex s_vfs_rename_mutex;/*当VFS通过目录命名文件时使用的互斥变量*/    /*  
  29. Kludge */     
  30.     /* Granularity of c/m/atime in ns.         Cannot be worse than a second */  
  31.     u32        s_time_gran;/*时间戳的粒度*/     
  32.     /*       * Filesystem subtype.  If non-empty the filesystem type field 
  33.      * in /proc/mounts will be "type.subtype"       */  
  34.     char *s_subtype;/**/     
  35.     /*       * Saved mount options for lazy filesystems using 
  36.      * generic_show_options()       */  
  37.     char *s_options;   };  

此文章由 http://www.ositren.com 收集整理 ,地址为: http://www.ositren.com/htmls/57857.html