加入收藏 | 设为首页 | 会员中心 | 我要投稿 新余站长网 (https://www.0790zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 空间 > 正文

Linux 的虚拟文件系统(真正理解“一切皆文件”)

发布时间:2019-06-16 04:35:54 所属栏目:空间 来源:cpp软件架构狮
导读:1,引言 Linux 中允许众多不同的文件系统共存,如 ext2, ext3, vfat 等。通过使用同一套文件 I/O 系统 调用即可对 Linux 中的任意文件进行操作而无需考虑其所在的具体文件系统格式;更进一步,对文件的 操作可以跨文件系统而执行。如图 1 所示,我们可以使

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

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

清单5. 和文件系统相关

  1. struct file_system_type { 
  2.  const char *name; /*文件系统的名字*/ 
  3.  struct subsystem subsys; /*sysfs子系统对象*/ 
  4.  int fs_flags; /*文件系统类型标志*/ 
  5.  /*在文件系统被安装时,从磁盘中读取超级块,在内存中组装超级块对象*/ 
  6.  struct super_block *(*get_sb) (struct file_system_type*,  
  7.  int, const char*, void *); 
  8.   
  9.  void (*kill_sb) (struct super_block *); /*终止访问超级块*/  
  10.  struct module *owner; /*文件系统模块*/ 
  11.  struct file_system_type * next; /*链表中的下一个文件系统类型*/ 
  12.  struct list_head fs_supers; /*具有同一种文件系统类型的超级块对象链表*/ 
  13. }; 
  14. struct vfsmount 
  15.  struct list_head mnt_hash; /*散列表*/ 
  16.  struct vfsmount *mnt_parent; /*父文件系统*/ 
  17.  struct dentry *mnt_mountpoint; /*安装点的目录项对象*/ 
  18.  struct dentry *mnt_root; /*该文件系统的根目录项对象*/ 
  19.  struct super_block *mnt_sb; /*该文件系统的超级块*/ 
  20.  struct list_head mnt_mounts; /*子文件系统链表*/ 
  21.  struct list_head mnt_child; /*子文件系统链表*/ 
  22.  atomic_t mnt_count; /*使用计数*/ 
  23.  int mnt_flags; /*安装标志*/ 
  24.  char *mnt_devname; /*设备文件名*/ 
  25.  struct list_head mnt_list; /*描述符链表*/ 
  26.  struct list_head mnt_fslink; /*具体文件系统的到期列表*/ 
  27.  struct namespace *mnt_namespace; /*相关的名字空间*/ 
  28. }; 

2.2.5.2 和进程相关

清单6. 打开的文件集

  1. struct files_struct {//打开的文件集 
  2.  atomic_t count; /*结构的使用计数*/ 
  3.  …… 
  4.  int max_fds; /*文件对象数的上限*/ 
  5.  int max_fdset; /*文件描述符的上限*/ 
  6.  int next_fd; /*下一个文件描述符*/ 
  7.  struct file ** fd; /*全部文件对象数组*/ 
  8.  …… 
  9.  }; 
  10. struct fs_struct {//建立进程与文件系统的关系 
  11.  atomic_t count; /*结构的使用计数*/ 
  12.  rwlock_t lock; /*保护该结构体的锁*/ 
  13.  int umask; /*默认的文件访问权限*/ 
  14.  struct dentry * root; /*根目录的目录项对象*/ 
  15.  struct dentry * pwd; /*当前工作目录的目录项对象*/ 
  16.  struct dentry * altroot; /*可供选择的根目录的目录项对象*/ 
  17.  struct vfsmount * rootmnt; /*根目录的安装点对象*/ 
  18.  struct vfsmount * pwdmnt; /*pwd的安装点对象*/ 
  19.  struct vfsmount * altrootmnt;/*可供选择的根目录的安装点对象*/ 
  20. }; 

2.2.5.3 和路径查找相关

清单7. 辅助查找

  1. struct nameidata { 
  2.  struct dentry *dentry; /*目录项对象的地址*/ 
  3.  struct vfsmount *mnt; /*安装点的数据*/ 
  4.  struct qstr last; /*路径中的最后一个component*/ 
  5.  unsigned int flags; /*查找标识*/ 
  6.  int last_type; /*路径中的最后一个component的类型*/ 
  7.  unsigned depth; /*当前symbolic link的嵌套深度,不能大于6*/ 
  8.  char *saved_names[MAX_NESTED_LINKS + 1];/ 
  9.  /*和嵌套symbolic link 相关的pathname*/ 
  10.  union { 
  11.  struct open_intent open; /*说明文件该如何访问*/ 
  12.  } intent; /*专用数据*/ 
  13. }; 

2.2.6 对象间的联系

如上的数据结构并不是孤立存在的。正是通过它们的有机联系,VFS才能正常工作。如下的几张图是对它们之间的联系的描述。

(编辑:新余站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

推荐文章
    热点阅读