歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Linux虛擬文件系統(概述)

Linux虛擬文件系統(概述)

日期:2017/2/28 15:57:20   编辑: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. struct list_head s_inodes;/*所有索引節點的鏈表*/ /* all inodes */
  28. struct hlist_head s_anon;/*用於處理網絡文件系統的匿名目錄項的鏈表*/ /*
  29. anonymous dentries for (nfs) exporting */
  30. struct list_head s_files;/*文件對象的鏈表*/
  31. /* s_dentry_lru and s_nr_dentry_unused are protected by dcache_lock */
  32. struct list_head s_dentry_lru;/* /* unused dentry lru */
  33. int s_nr_dentry_unused; /* # of dentry on lru */
  34. struct block_device *s_bdev;/*指向塊設備驅動程序描述符的指針*/
  35. struct backing_dev_info *s_bdi;/* */
  36. struct mtd_info *s_mtd;/**/
  37. struct list_head s_instances;/*用於指定文件系統類型的超級快對象鏈表指針*/
  38. struct quota_info s_dquot;/*磁盤限額的描述符*/ /* Diskquota specific options
  39. */
  40. int s_frozen;/*凍結文件系統時使用的標志*/
  41. wait_queue_head_t s_wait_unfrozen;/*進程掛起的等待隊列,直到文件系統被凍結*/
  42. char s_id[32];/*包含超級快的塊設備名稱*/ /* Informational name */
  43. void *s_fs_info;/*指向特定文件系統的超級快信息的指針*/ /* Filesystem
  44. private info */
  45. fmode_t s_mode;/**/
  46. /*
  47. * The next field is for VFS *only*. No filesystems have any business
  48. * even looking at it. You had been warned.
  49. */
  50. struct mutex s_vfs_rename_mutex;/*當VFS通過目錄命名文件時使用的互斥變量*/ /*
  51. Kludge */
  52. /* Granularity of c/m/atime in ns.
  53. Cannot be worse than a second */
  54. u32 s_time_gran;/*時間戳的粒度*/
  55. /*
  56. * Filesystem subtype. If non-empty the filesystem type field
  57. * in /proc/mounts will be "type.subtype"
  58. */
  59. char *s_subtype;/**/
  60. /*
  61. * Saved mount options for lazy filesystems using
  62. * generic_show_options()
  63. */
  64. char *s_options;
  65. };
Copyright © Linux教程網 All Rights Reserved