Linux虚拟文件系统(概述)


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

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

磁盘文件系统

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

网络文件系统

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

特殊文件系统

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

通用文件模型

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

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

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

VFS与进程关系

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

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

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

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

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

超级块对象

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

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

相关内容